updated example with key exchange

This commit is contained in:
Orson Peters 2013-03-24 23:32:21 +01:00
parent d739478ae1
commit 6dcff448da

View File

@ -118,6 +118,7 @@ Example
```c
unsigned char seed[32], public_key[32], private_key[64], signature[64];
unsigned char other_public_key[32], other_private_key[64], shared_secret[32];
const unsigned char message[] = "TEST MESSAGE";
/* create a random seed, and a key pair out of that seed */
@ -137,6 +138,21 @@ if (ed25519_verify(signature, message, strlen(message), public_key)) {
} else {
printf("invalid signature\n");
}
/* create a dummy keypair to use for a key exchange, normally you'd only have
the public key and receive it through some communication channel */
if (ed25519_create_seed(seed)) {
printf("error while generating seed\n");
exit(1);
}
ed25519_create_keypair(other_public_key, other_private_key, seed);
/* do a key exchange with other_public_key */
ed25519_key_exchange(shared_secret, other_public_key, private_key);
/* the magic is that ed25519_key_exchange(shared_secret, public_key, other_private_key); would result in the same shared_secret */
```
License