| 1 | #cxx . . $ `<file>/src/pub_derivation.c`/include <ge.h>cxx . . $ `<file>/ref10/crypto_sign/ge.h`/ |
| 2 | #include <sodium.h> |
| 3 | |
| 4 | #include <xeddsa.h>cxx . . $ `<file>/include/xeddsa.h`/ |
| 5 | #include "utils.c"cxx . . $ `<file>/src/utils.c`/ |
| 6 | |
| 7 | /** |
| 8 | * Derive the Curve25519 public key from a Curve25519/Ed25519 private key. |
| 9 | * |
| 10 | * @param curve25519_pub (out): The Curve25519 public key. |
| 11 | * @param priv (in): The Curve25519/Ed25519 private key. |
| 12 | */ |
| 13 | void priv_to_curve25519_pubcxx . . $ priv_to_curve25519_pub(225f8250db12d4ac).(uint8_tcxx . . $ uint8_t#* curve25519_pub, const uint8_tcxx . . $ uint8_t#* priv) { |
| 14 | uint8_tcxx . . $ uint8_t# priv_clamped[32]; |
| 15 | |
| 16 | // Clamp the private key before using it |
| 17 | sc_clampcxx . . $ sc_clamp(225f8250db12d4ac).(priv_clamped, priv); |
| 18 | |
| 19 | // Calculate the Curve25519 public key from the private key. Note that while the function is declared to |
| 20 | // return an integer, it always returns the constant value of 0, and can thus be treated as a void. |
| 21 | crypto_scalarmult_curve25519_basecxx . . $ crypto_scalarmult_curve25519_base(1ff552b5f61cf5ec).(curve25519_pub, priv_clamped); |
| 22 | |
| 23 | sodium_memzerocxx . . $ sodium_memzero(5500c4293b1bbef0).(priv_clamped, sizeof(priv_clamped)); |
| 24 | sodium_stackzerocxx . . $ sodium_stackzero(2c44cd906ae4e829).(STACKZERO_SIZEcxx . . $ `src/utils.c:14:9`!); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Derive the Ed25519 public key from a Curve25519/Ed25519 private key. |
| 29 | * |
| 30 | * @param ed25519_pub (out): The Ed25519 public key. |
| 31 | * @param priv (in): The Curve25519/Ed25519 private key. |
| 32 | */ |
| 33 | void priv_to_ed25519_pubcxx . . $ priv_to_ed25519_pub(225f8250db12d4ac).(uint8_tcxx . . $ uint8_t#* ed25519_pub, const uint8_tcxx . . $ uint8_t#* priv) { |
| 34 | ge_p3cxx . . $ ge_p3# ed25519_pub_ge; |
| 35 | |
| 36 | uint8_tcxx . . $ uint8_t# priv_clamped[32]; |
| 37 | |
| 38 | // Clamp the private key before using it |
| 39 | sc_clampcxx . . $ sc_clamp(225f8250db12d4ac).(priv_clamped, priv); |
| 40 | |
| 41 | // Calculate the Ed25519 public key from the private key |
| 42 | ge_scalarmult_basecxx . . $ `ref10/crypto_sign/ge.h:73:9`!(&ed25519_pub_ge, priv_clamped); |
| 43 | ge_p3_tobytescxx . . $ `ref10/crypto_sign/ge.h:57:9`!(ed25519_pub, &ed25519_pub_ge); |
| 44 | |
| 45 | sodium_memzerocxx . . $ sodium_memzero(5500c4293b1bbef0).(priv_clamped, sizeof(priv_clamped)); |
| 46 | sodium_stackzerocxx . . $ sodium_stackzero(2c44cd906ae4e829).(STACKZERO_SIZEcxx . . $ `src/utils.c:14:9`!); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Derive the Ed25519 public key from a Curve25519/Ed25519 seed. |
| 51 | * |
| 52 | * @param ed25519_pub (out): The Ed25519 public key. |
| 53 | * @param seed (in): The Curve25519/Ed25519 seed. |
| 54 | */ |
| 55 | void seed_to_ed25519_pubcxx . . $ seed_to_ed25519_pub(225f8250db12d4ac).(uint8_tcxx . . $ uint8_t#* ed25519_pub, const uint8_tcxx . . $ uint8_t#* seed) { |
| 56 | uint8_tcxx . . $ uint8_t# priv[32]; |
| 57 | |
| 58 | seed_to_privcxx . . $ seed_to_priv(225f8250db12d4ac).(priv, seed); |
| 59 | priv_to_ed25519_pubcxx . . $ priv_to_ed25519_pub(225f8250db12d4ac).(ed25519_pub, priv); |
| 60 | |
| 61 | sodium_memzerocxx . . $ sodium_memzero(5500c4293b1bbef0).(priv, sizeof(priv)); |
| 62 | } |