mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
ED25519_NONDETERMINISTIC: derive keys from the seed the same way
as when ED25519_NONDETERMINISTIC is not defined
This commit is contained in:
@@ -15,11 +15,7 @@ crypto_sign_ed25519_seed_keypair(unsigned char *pk, unsigned char *sk,
|
|||||||
{
|
{
|
||||||
ge25519_p3 A;
|
ge25519_p3 A;
|
||||||
|
|
||||||
#ifdef ED25519_NONDETERMINISTIC
|
|
||||||
memmove(sk, seed, 32);
|
|
||||||
#else
|
|
||||||
crypto_hash_sha512(sk, seed, 32);
|
crypto_hash_sha512(sk, seed, 32);
|
||||||
#endif
|
|
||||||
sk[0] &= 248;
|
sk[0] &= 248;
|
||||||
sk[31] &= 127;
|
sk[31] &= 127;
|
||||||
sk[31] |= 64;
|
sk[31] |= 64;
|
||||||
@@ -76,11 +72,7 @@ crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
|
|||||||
{
|
{
|
||||||
unsigned char h[crypto_hash_sha512_BYTES];
|
unsigned char h[crypto_hash_sha512_BYTES];
|
||||||
|
|
||||||
#ifdef ED25519_NONDETERMINISTIC
|
|
||||||
memcpy(h, ed25519_sk, 32);
|
|
||||||
#else
|
|
||||||
crypto_hash_sha512(h, ed25519_sk, 32);
|
crypto_hash_sha512(h, ed25519_sk, 32);
|
||||||
#endif
|
|
||||||
h[0] &= 248;
|
h[0] &= 248;
|
||||||
h[31] &= 127;
|
h[31] &= 127;
|
||||||
h[31] |= 64;
|
h[31] |= 64;
|
||||||
|
|||||||
@@ -18,16 +18,10 @@ main(void)
|
|||||||
unsigned char curve25519_sk[crypto_scalarmult_curve25519_BYTES];
|
unsigned char curve25519_sk[crypto_scalarmult_curve25519_BYTES];
|
||||||
char curve25519_pk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
|
char curve25519_pk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
|
||||||
char curve25519_sk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
|
char curve25519_sk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
|
||||||
unsigned char hseed[crypto_hash_sha512_BYTES];
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
assert(crypto_sign_ed25519_SEEDBYTES <= crypto_hash_sha512_BYTES);
|
assert(crypto_sign_ed25519_SEEDBYTES <= crypto_hash_sha512_BYTES);
|
||||||
#ifdef ED25519_NONDETERMINISTIC
|
crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, keypair_seed);
|
||||||
crypto_hash_sha512(hseed, keypair_seed, crypto_sign_ed25519_SEEDBYTES);
|
|
||||||
#else
|
|
||||||
memcpy(hseed, keypair_seed, crypto_sign_ed25519_SEEDBYTES);
|
|
||||||
#endif
|
|
||||||
crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, hseed);
|
|
||||||
|
|
||||||
if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) != 0) {
|
if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) != 0) {
|
||||||
printf("conversion failed\n");
|
printf("conversion failed\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user