summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2016-12-17 16:20:03 +0000
committerjsing <>2016-12-17 16:20:03 +0000
commit95575415e5d3451b6de7a260d4093e491797faad (patch)
tree78d02484222416141f064d4da7a44d5a2b927f14 /src/lib
parentf974ae969e821bbb92a8714ed0e77cf33487a2a8 (diff)
downloadopenbsd-95575415e5d3451b6de7a260d4093e491797faad.tar.gz
openbsd-95575415e5d3451b6de7a260d4093e491797faad.tar.bz2
openbsd-95575415e5d3451b6de7a260d4093e491797faad.zip
Define X25519_KEY_LENGTH and use it so we have fewer magic numbers.
ok beck@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/curve25519/curve25519.c8
-rw-r--r--src/lib/libcrypto/curve25519/curve25519.h10
2 files changed, 12 insertions, 6 deletions
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],
4895} 4895}
4896 4896
4897void 4897void
4898X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]) 4898X25519_keypair(uint8_t out_public_value[X25519_KEY_LENGTH],
4899 uint8_t out_private_key[X25519_KEY_LENGTH])
4899{ 4900{
4900 /* All X25519 implementations should decode scalars correctly (see 4901 /* All X25519 implementations should decode scalars correctly (see
4901 * https://tools.ietf.org/html/rfc7748#section-5). However, if an 4902 * 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])
4920} 4921}
4921 4922
4922int 4923int
4923X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], 4924X25519(uint8_t out_shared_key[X25519_KEY_LENGTH],
4924 const uint8_t peer_public_value[32]) 4925 const uint8_t private_key[X25519_KEY_LENGTH],
4926 const uint8_t peer_public_value[X25519_KEY_LENGTH])
4925{ 4927{
4926 static const uint8_t kZeros[32] = {0}; 4928 static const uint8_t kZeros[32] = {0};
4927 4929
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" {
39 * See http://cr.yp.to/ecdh.html and https://tools.ietf.org/html/rfc7748. 39 * See http://cr.yp.to/ecdh.html and https://tools.ietf.org/html/rfc7748.
40 */ 40 */
41 41
42#define X25519_KEY_LENGTH 32
43
42/* 44/*
43 * X25519_keypair sets |out_public_value| and |out_private_key| to a freshly 45 * X25519_keypair sets |out_public_value| and |out_private_key| to a freshly
44 * generated, public/private key pair. 46 * generated, public/private key pair.
45 */ 47 */
46void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]); 48void X25519_keypair(uint8_t out_public_value[X25519_KEY_LENGTH],
49 uint8_t out_private_key[X25519_KEY_LENGTH]);
47 50
48/* 51/*
49 * X25519 writes a shared key to |out_shared_key| that is calculated from the 52 * 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]);
53 * Don't use the shared key directly, rather use a KDF and also include the two 56 * Don't use the shared key directly, rather use a KDF and also include the two
54 * public values as inputs. 57 * public values as inputs.
55 */ 58 */
56int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], 59int X25519(uint8_t out_shared_key[X25519_KEY_LENGTH],
57 const uint8_t peers_public_value[32]); 60 const uint8_t private_key[X25519_KEY_LENGTH],
61 const uint8_t peers_public_value[X25519_KEY_LENGTH]);
58 62
59#if defined(__cplusplus) 63#if defined(__cplusplus)
60} /* extern C */ 64} /* extern C */