libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_sign / ed25519 / ref10 / keypair.c
blobd1969254523100de5bebdcac7cd452974c7e5584
1 #include "api.h"
2 #include "randombytes.h"
3 #include "crypto_hash_sha512.h"
4 #include "ge.h"
6 int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk,
7 const unsigned char *seed)
9 ge_p3 A;
10 int i;
12 crypto_hash_sha512(sk,seed,32);
13 sk[0] &= 248;
14 sk[31] &= 63;
15 sk[31] |= 64;
17 ge_scalarmult_base(&A,sk);
18 ge_p3_tobytes(pk,&A);
20 for (i = 0;i < 32;++i) sk[i] = seed[i];
21 for (i = 0;i < 32;++i) sk[32 + i] = pk[i];
22 return 0;
25 int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
27 unsigned char seed[32];
29 randombytes(seed,32);
30 return crypto_sign_seed_keypair(pk,sk,seed);