From 95575415e5d3451b6de7a260d4093e491797faad Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 17 Dec 2016 16:20:03 +0000 Subject: Define X25519_KEY_LENGTH and use it so we have fewer magic numbers. ok beck@ --- src/lib/libcrypto/curve25519/curve25519.c | 8 +++++--- src/lib/libcrypto/curve25519/curve25519.h | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/curve25519/curve25519.c b/src/lib/libcrypto/curve25519/curve25519.c index f24adc1fbe..994b804af5 100644 --- a/src/lib/libcrypto/curve25519/curve25519.c +++ b/src/lib/libcrypto/curve25519/curve25519.c @@ -4895,7 +4895,8 @@ x25519_public_from_private(uint8_t out_public_value[32], } void -X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]) +X25519_keypair(uint8_t out_public_value[X25519_KEY_LENGTH], + uint8_t out_private_key[X25519_KEY_LENGTH]) { /* All X25519 implementations should decode scalars correctly (see * https://tools.ietf.org/html/rfc7748#section-5). However, if an @@ -4920,8 +4921,9 @@ X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]) } int -X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], - const uint8_t peer_public_value[32]) +X25519(uint8_t out_shared_key[X25519_KEY_LENGTH], + const uint8_t private_key[X25519_KEY_LENGTH], + const uint8_t peer_public_value[X25519_KEY_LENGTH]) { static const uint8_t kZeros[32] = {0}; diff --git a/src/lib/libcrypto/curve25519/curve25519.h b/src/lib/libcrypto/curve25519/curve25519.h index 077bbbf97c..5aaa8c0869 100644 --- a/src/lib/libcrypto/curve25519/curve25519.h +++ b/src/lib/libcrypto/curve25519/curve25519.h @@ -39,11 +39,14 @@ extern "C" { * See http://cr.yp.to/ecdh.html and https://tools.ietf.org/html/rfc7748. */ +#define X25519_KEY_LENGTH 32 + /* * X25519_keypair sets |out_public_value| and |out_private_key| to a freshly * generated, public/private key pair. */ -void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]); +void X25519_keypair(uint8_t out_public_value[X25519_KEY_LENGTH], + uint8_t out_private_key[X25519_KEY_LENGTH]); /* * X25519 writes a shared key to |out_shared_key| that is calculated from the @@ -53,8 +56,9 @@ void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]); * Don't use the shared key directly, rather use a KDF and also include the two * public values as inputs. */ -int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], - const uint8_t peers_public_value[32]); +int X25519(uint8_t out_shared_key[X25519_KEY_LENGTH], + const uint8_t private_key[X25519_KEY_LENGTH], + const uint8_t peers_public_value[X25519_KEY_LENGTH]); #if defined(__cplusplus) } /* extern C */ -- cgit v1.2.3-55-g6feb