This commit is contained in:
Orson Peters 2013-01-22 11:34:38 +01:00
parent f89f5ae94c
commit 2ec6a34a11

View File

@ -22,37 +22,46 @@ There are no defined types for seeds, signing keys, verifying keys or
signatures. Instead simple `unsigned char` buffers are used with the following signatures. Instead simple `unsigned char` buffers are used with the following
sizes: sizes:
unsigned char seed[32] ```c
unsigned char signature[64] unsigned char seed[32];
unsigned char verify_key[32] unsigned char signature[64];
unsigned char signing_key[64] unsigned char verify_key[32];
unsigned char signing_key[64];
```
API API
--- ---
int ed25519_create_seed(unsigned char *seed); ```c
int ed25519_create_seed(unsigned char *seed);
```
Creates a 32 byte random seed in `seed` for key generation. `seed` must be a Creates a 32 byte random seed in `seed` for key generation. `seed` must be a
writable 32 byte buffer. Returns 0 on success, and nonzero on failure. writable 32 byte buffer. Returns 0 on success, and nonzero on failure.
void ed25519_create_keypair(unsigned char *verify_key, unsigned char *sign_key, const unsigned char *seed); ```c
void ed25519_create_keypair(unsigned char *verify_key, unsigned char *sign_key, const unsigned char *seed);
```
Creates a new key pair from the given seed. `verify_key` must be a writable 32 Creates a new key pair from the given seed. `verify_key` must be a writable 32
byte buffer, `sign_key` must be a writable 64 byte buffer and `seed` must be a byte buffer, `sign_key` must be a writable 64 byte buffer and `seed` must be a
32 byte buffer.
void ed25519_sign(unsigned char *signature, 32 byte buffer.
const unsigned char *message, size_t message_len, ```c
const unsigned char *sign_key); void ed25519_sign(unsigned char *signature,
const unsigned char *message, size_t message_len,
const unsigned char *sign_key);
```
Creates a signature of the given message with `sign_key`. `signature` must be Creates a signature of the given message with `sign_key`. `signature` must be
a writable 64 byte buffer. `message` must have at least `message_len` bytes to a writable 64 byte buffer. `message` must have at least `message_len` bytes to
be read. `sign_key` must be a 64 byte signing key generated by be read. `sign_key` must be a 64 byte signing key generated by
`ed25519_create_keypair`. `ed25519_create_keypair`.
int ed25519_verify(const unsigned char *signature, ```c
const unsigned char *message, size_t message_len, int ed25519_verify(const unsigned char *signature,
const unsigned char *verify_key); const unsigned char *message, size_t message_len,
const unsigned char *verify_key);
```
Verifies the signature on the given message using verify_key. `signature` must be Verifies the signature on the given message using verify_key. `signature` must be
a readable 64 byte buffer. `message` must have at least `message_len` bytes to a readable 64 byte buffer. `message` must have at least `message_len` bytes to
@ -61,23 +70,25 @@ be read. `sign_key` must be a 32 byte verifying key generated by
Example Example
------- -------
unsigned char seed[32], sign_key[64], verify_key[32], signature[64]; ```c
const unsigned char message[] = "TEST MESSAGE"; unsigned char seed[32], sign_key[64], verify_key[32], signature[64];
const unsigned char message[] = "TEST MESSAGE";
/* create a random seed, and a keypair out of that seed */ /* create a random seed, and a keypair out of that seed */
if (ed25519_create_seed(seed)) { if (ed25519_create_seed(seed)) {
printf("error while generating seed\n"); printf("error while generating seed\n");
exit(1); exit(1);
} }
ed25519_create_keypair(verify_key, sign_key, seed); ed25519_create_keypair(verify_key, sign_key, seed);
/* create signature on the message with the sign key */ /* create signature on the message with the sign key */
ed25519_sign(signature, message, strlen(message), sign_key); ed25519_sign(signature, message, strlen(message), sign_key);
/* verify the signature */ /* verify the signature */
if (ed25519_verify(signature, message, strlen(message), verify_key)) { if (ed25519_verify(signature, message, strlen(message), verify_key)) {
printf("invalid signature\n"); printf("invalid signature\n");
} else { } else {
printf("valid signature\n"); printf("valid signature\n");
} }
```