X25519.h (1033B)
1 /* 2 * X25519 - Elliptic Curve Diffie-Hellman using Curve25519 3 * RFC 7748 4 * 5 * Fast, secure key exchange 6 * Public key: 32 bytes 7 * Secret key: 32 bytes 8 * Shared secret: 32 bytes 9 */ 10 11 #ifndef X25519_H 12 #define X25519_H 13 14 #include <stdint.h> 15 #include <stddef.h> 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #define X25519_KEY_SIZE 32 22 23 /** 24 * Generate X25519 public key from secret key 25 * 26 * @param public_key Output: 32-byte public key 27 * @param secret_key Input: 32-byte secret key 28 */ 29 void x25519_public_key(uint8_t public_key[32], const uint8_t secret_key[32]); 30 31 /** 32 * Compute X25519 shared secret 33 * 34 * @param shared_secret Output: 32-byte shared secret 35 * @param my_secret_key My 32-byte secret key 36 * @param their_public_key Their 32-byte public key 37 * @return 0 on success, -1 if public key is invalid 38 */ 39 int x25519_shared_secret(uint8_t shared_secret[32], 40 const uint8_t my_secret_key[32], 41 const uint8_t their_public_key[32]); 42 43 #ifdef __cplusplus 44 } 45 #endif 46 47 #endif /* X25519_H */