diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-01-21 10:20:12 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-01-21 22:07:02 +1100 |
commit | dfd591618cdf2c96727ac0eb65f89cf54af0d97e (patch) | |
tree | 59700563da0dc6f1de649394ffb4c787710eda5a /kex.h | |
parent | b1b2ff4ed559051d1035419f8f236275fa66d5d6 (diff) |
upstream: Add support for a PQC KEX/KEM:
sntrup4591761x25519-sha512@tinyssh.org using the Streamlined NTRU Prime
4591^761 implementation from SUPERCOP coupled with X25519 as a stop-loss. Not
enabled by default.
introduce KEM API; a simplified framework for DH-ish KEX methods.
from markus@ feedback & ok djm@
OpenBSD-Commit-ID: d687f76cffd3561dd73eb302d17a1c3bf321d1a7
Diffstat (limited to 'kex.h')
-rw-r--r-- | kex.h | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: kex.h,v 1.98 2019/01/21 10:07:22 djm Exp $ */ | 1 | /* $OpenBSD: kex.h,v 1.99 2019/01/21 10:20:12 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
@@ -27,6 +27,7 @@ | |||
27 | #define KEX_H | 27 | #define KEX_H |
28 | 28 | ||
29 | #include "mac.h" | 29 | #include "mac.h" |
30 | #include "crypto_api.h" | ||
30 | 31 | ||
31 | #ifdef WITH_LEAKMALLOC | 32 | #ifdef WITH_LEAKMALLOC |
32 | #include "leakmalloc.h" | 33 | #include "leakmalloc.h" |
@@ -62,6 +63,7 @@ | |||
62 | #define KEX_ECDH_SHA2_NISTP521 "ecdh-sha2-nistp521" | 63 | #define KEX_ECDH_SHA2_NISTP521 "ecdh-sha2-nistp521" |
63 | #define KEX_CURVE25519_SHA256 "curve25519-sha256" | 64 | #define KEX_CURVE25519_SHA256 "curve25519-sha256" |
64 | #define KEX_CURVE25519_SHA256_OLD "curve25519-sha256@libssh.org" | 65 | #define KEX_CURVE25519_SHA256_OLD "curve25519-sha256@libssh.org" |
66 | #define KEX_SNTRUP4591761X25519_SHA512 "sntrup4591761x25519-sha512@tinyssh.org" | ||
65 | 67 | ||
66 | #define COMP_NONE 0 | 68 | #define COMP_NONE 0 |
67 | /* pre-auth compression (COMP_ZLIB) is only supported in the client */ | 69 | /* pre-auth compression (COMP_ZLIB) is only supported in the client */ |
@@ -100,6 +102,7 @@ enum kex_exchange { | |||
100 | KEX_DH_GEX_SHA256, | 102 | KEX_DH_GEX_SHA256, |
101 | KEX_ECDH_SHA2, | 103 | KEX_ECDH_SHA2, |
102 | KEX_C25519_SHA256, | 104 | KEX_C25519_SHA256, |
105 | KEX_KEM_SNTRUP4591761X25519_SHA512, | ||
103 | KEX_MAX | 106 | KEX_MAX |
104 | }; | 107 | }; |
105 | 108 | ||
@@ -164,8 +167,10 @@ struct kex { | |||
164 | u_int min, max, nbits; /* GEX */ | 167 | u_int min, max, nbits; /* GEX */ |
165 | EC_KEY *ec_client_key; /* ECDH */ | 168 | EC_KEY *ec_client_key; /* ECDH */ |
166 | const EC_GROUP *ec_group; /* ECDH */ | 169 | const EC_GROUP *ec_group; /* ECDH */ |
167 | u_char c25519_client_key[CURVE25519_SIZE]; /* 25519 */ | 170 | u_char c25519_client_key[CURVE25519_SIZE]; /* 25519 + KEM */ |
168 | u_char c25519_client_pubkey[CURVE25519_SIZE]; /* 25519 */ | 171 | u_char c25519_client_pubkey[CURVE25519_SIZE]; /* 25519 */ |
172 | u_char sntrup4591761_client_key[crypto_kem_sntrup4591761_SECRETKEYBYTES]; /* KEM */ | ||
173 | struct sshbuf *kem_client_pub; /* KEM */ | ||
169 | }; | 174 | }; |
170 | 175 | ||
171 | int kex_names_valid(const char *); | 176 | int kex_names_valid(const char *); |
@@ -203,6 +208,14 @@ int kexecdh_client(struct ssh *); | |||
203 | int kexecdh_server(struct ssh *); | 208 | int kexecdh_server(struct ssh *); |
204 | int kexc25519_client(struct ssh *); | 209 | int kexc25519_client(struct ssh *); |
205 | int kexc25519_server(struct ssh *); | 210 | int kexc25519_server(struct ssh *); |
211 | int kex_kem_client(struct ssh *); | ||
212 | int kex_kem_server(struct ssh *); | ||
213 | |||
214 | int kex_kem_sntrup4591761x25519_keypair(struct kex *); | ||
215 | int kex_kem_sntrup4591761x25519_enc(struct kex *, const u_char *, size_t, | ||
216 | struct sshbuf **, struct sshbuf **); | ||
217 | int kex_kem_sntrup4591761x25519_dec(struct kex *, const u_char *, size_t, | ||
218 | struct sshbuf **); | ||
206 | 219 | ||
207 | int kex_dh_keygen(struct kex *); | 220 | int kex_dh_keygen(struct kex *); |
208 | int kex_dh_compute_key(struct kex *, BIGNUM *, struct sshbuf *); | 221 | int kex_dh_compute_key(struct kex *, BIGNUM *, struct sshbuf *); |
@@ -224,7 +237,7 @@ int kex_ecdh_hash(int, const EC_GROUP *, | |||
224 | 237 | ||
225 | int kex_c25519_hash(int, const struct sshbuf *, const struct sshbuf *, | 238 | int kex_c25519_hash(int, const struct sshbuf *, const struct sshbuf *, |
226 | const u_char *, size_t, const u_char *, size_t, | 239 | const u_char *, size_t, const u_char *, size_t, |
227 | const u_char *, size_t, const u_char *, const u_char *, | 240 | const u_char *, size_t, const u_char *, size_t, const u_char *, size_t, |
228 | const u_char *, size_t, u_char *, size_t *); | 241 | const u_char *, size_t, u_char *, size_t *); |
229 | 242 | ||
230 | void kexc25519_keygen(u_char key[CURVE25519_SIZE], u_char pub[CURVE25519_SIZE]) | 243 | void kexc25519_keygen(u_char key[CURVE25519_SIZE], u_char pub[CURVE25519_SIZE]) |
@@ -234,9 +247,13 @@ int kexc25519_shared_key(const u_char key[CURVE25519_SIZE], | |||
234 | const u_char pub[CURVE25519_SIZE], struct sshbuf *out) | 247 | const u_char pub[CURVE25519_SIZE], struct sshbuf *out) |
235 | __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE))) | 248 | __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE))) |
236 | __attribute__((__bounded__(__minbytes__, 2, CURVE25519_SIZE))); | 249 | __attribute__((__bounded__(__minbytes__, 2, CURVE25519_SIZE))); |
250 | int kexc25519_shared_key_ext(const u_char key[CURVE25519_SIZE], | ||
251 | const u_char pub[CURVE25519_SIZE], struct sshbuf *out, int) | ||
252 | __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE))) | ||
253 | __attribute__((__bounded__(__minbytes__, 2, CURVE25519_SIZE))); | ||
237 | 254 | ||
238 | #if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH) | 255 | #if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH) |
239 | void dump_digest(char *, u_char *, int); | 256 | void dump_digest(const char *, const u_char *, int); |
240 | #endif | 257 | #endif |
241 | 258 | ||
242 | #if !defined(WITH_OPENSSL) || !defined(OPENSSL_HAS_ECC) | 259 | #if !defined(WITH_OPENSSL) || !defined(OPENSSL_HAS_ECC) |