Skip to content

Commit

Permalink
Avoid magic values. External interface doesn't use it. But the compil…
Browse files Browse the repository at this point in the history
…er will verify lengths agree
  • Loading branch information
torben-hansen committed Oct 28, 2023
1 parent 61d96e4 commit 31868cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions crypto/curve25519/curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,14 @@ static void x25519_s2n_bignum_public_from_private(

// Stub function until ED25519 lands in s2n-bignum
static void ed25519_public_key_from_hashed_seed_s2n_bignum(
uint8_t out_public_key[32], uint8_t az[SHA512_DIGEST_LENGTH]) {
uint8_t out_public_key[ED25519_PUBLIC_KEY_LEN],
uint8_t az[SHA512_DIGEST_LENGTH]) {
abort();
}

void ED25519_keypair_from_seed(uint8_t out_public_key[ED25519_PUBLIC_KEY_LEN],
uint8_t out_private_key[64], const uint8_t seed[ED25519_SEED_LEN]) {
uint8_t out_private_key[ED25519_PRIVATE_KEY_LEN],
const uint8_t seed[ED25519_SEED_LEN]) {

// Step: rfc8032 5.1.5.1
// Compute SHA512(seed).
Expand All @@ -268,13 +270,14 @@ void ED25519_keypair_from_seed(uint8_t out_public_key[ED25519_PUBLIC_KEY_LEN],

// Encoded public key is a suffix in the private key. Avoids having to
// generate the public key from the private key when signing.
OPENSSL_STATIC_ASSERT(64 == (ED25519_SEED_LEN + ED25519_PUBLIC_KEY_LEN), ed25519_parameter_length_mismatch)
OPENSSL_STATIC_ASSERT(ED25519_PRIVATE_KEY_LEN == (ED25519_SEED_LEN + ED25519_PUBLIC_KEY_LEN), ed25519_parameter_length_mismatch)
OPENSSL_memcpy(out_private_key, seed, ED25519_SEED_LEN);
OPENSSL_memcpy(out_private_key + ED25519_SEED_LEN, out_public_key,
ED25519_PUBLIC_KEY_LEN);
}

void ED25519_keypair(uint8_t out_public_key[32], uint8_t out_private_key[64]) {
void ED25519_keypair(uint8_t out_public_key[ED25519_PUBLIC_KEY_LEN],
uint8_t out_private_key[ED25519_PRIVATE_KEY_LEN]) {

// Ed25519 key generation: rfc8032 5.1.5
// Private key is 32 octets of random data.
Expand Down
5 changes: 3 additions & 2 deletions crypto/curve25519/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ void x25519_scalar_mult_generic_nohw(uint8_t out[32],
const uint8_t point[32]);
void x25519_public_from_private_nohw(uint8_t out_public_value[32],
const uint8_t private_key[32]);
void ed25519_public_key_from_hashed_seed_nohw(uint8_t out_public_key[32],
uint8_t az[SHA512_DIGEST_LENGTH]);
void ed25519_public_key_from_hashed_seed_nohw(
uint8_t out_public_key[ED25519_PUBLIC_KEY_LEN],
uint8_t az[SHA512_DIGEST_LENGTH]);

// Port to internal linkage in curve25519_nohw.c when adding implementation
// from s2n-bignum ed25519
Expand Down

0 comments on commit 31868cd

Please sign in to comment.