Ed25519.h (1581B)
1 /* 2 * Ed25519 - EdDSA signature scheme using Curve25519 3 * RFC 8032 4 * 5 * Fast, secure digital signatures 6 * Public key: 32 bytes 7 * Secret key: 32 bytes (seed) + 32 bytes (public key) = 64 bytes 8 * Signature: 64 bytes 9 */ 10 11 #ifndef ED25519_H 12 #define ED25519_H 13 14 #include <stdint.h> 15 #include <stddef.h> 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #define ED25519_PUBLIC_KEY_SIZE 32 22 #define ED25519_SECRET_KEY_SIZE 64 23 #define ED25519_SEED_SIZE 32 24 #define ED25519_SIGNATURE_SIZE 64 25 26 /** 27 * Generate Ed25519 keypair from random seed 28 * 29 * @param public_key Output: 32-byte public key 30 * @param secret_key Output: 64-byte secret key (seed + public) 31 */ 32 void ed25519_create_keypair(uint8_t public_key[32], uint8_t secret_key[64], 33 const uint8_t seed[32]); 34 35 /** 36 * Sign message with Ed25519 37 * 38 * @param signature Output: 64-byte signature 39 * @param message Message to sign 40 * @param message_len Message length 41 * @param secret_key 64-byte secret key 42 */ 43 void ed25519_sign(uint8_t signature[64], 44 const uint8_t *message, size_t message_len, 45 const uint8_t secret_key[64]); 46 47 /** 48 * Verify Ed25519 signature 49 * 50 * @param signature 64-byte signature to verify 51 * @param message Message that was signed 52 * @param message_len Message length 53 * @param public_key 32-byte public key 54 * @return 0 if valid, -1 if invalid 55 */ 56 int ed25519_verify(const uint8_t signature[64], 57 const uint8_t *message, size_t message_len, 58 const uint8_t public_key[32]); 59 60 #ifdef __cplusplus 61 } 62 #endif 63 64 #endif /* ED25519_H */