summaryrefslogtreecommitdiff
path: root/kex.h
diff options
context:
space:
mode:
Diffstat (limited to 'kex.h')
-rw-r--r--kex.h98
1 files changed, 67 insertions, 31 deletions
diff --git a/kex.h b/kex.h
index 4e5ead839..39f67bbc1 100644
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.h,v 1.91 2018/07/11 18:53:29 markus Exp $ */ 1/* $OpenBSD: kex.h,v 1.107 2019/01/23 00:30:41 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,13 +102,21 @@ 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,
106#ifdef GSSAPI
103 KEX_GSS_GRP1_SHA1, 107 KEX_GSS_GRP1_SHA1,
104 KEX_GSS_GRP14_SHA1, 108 KEX_GSS_GRP14_SHA1,
109 KEX_GSS_GRP14_SHA256,
110 KEX_GSS_GRP16_SHA512,
105 KEX_GSS_GEX_SHA1, 111 KEX_GSS_GEX_SHA1,
112 KEX_GSS_NISTP256_SHA256,
113 KEX_GSS_C25519_SHA256,
114#endif
106 KEX_MAX 115 KEX_MAX
107}; 116};
108 117
109#define KEX_INIT_SENT 0x0001 118#define KEX_INIT_SENT 0x0001
119#define KEX_INITIAL 0x0002
110 120
111struct sshenc { 121struct sshenc {
112 char *name; 122 char *name;
@@ -147,6 +157,8 @@ struct kex {
147 int ext_info_c; 157 int ext_info_c;
148 struct sshbuf *my; 158 struct sshbuf *my;
149 struct sshbuf *peer; 159 struct sshbuf *peer;
160 struct sshbuf *client_version;
161 struct sshbuf *server_version;
150 sig_atomic_t done; 162 sig_atomic_t done;
151 u_int flags; 163 u_int flags;
152 int hash_alg; 164 int hash_alg;
@@ -157,31 +169,36 @@ struct kex {
157 char *gss_host; 169 char *gss_host;
158 char *gss_client; 170 char *gss_client;
159#endif 171#endif
160 char *client_version_string;
161 char *server_version_string;
162 char *failed_choice; 172 char *failed_choice;
163 int (*verify_host_key)(struct sshkey *, struct ssh *); 173 int (*verify_host_key)(struct sshkey *, struct ssh *);
164 struct sshkey *(*load_host_public_key)(int, int, struct ssh *); 174 struct sshkey *(*load_host_public_key)(int, int, struct ssh *);
165 struct sshkey *(*load_host_private_key)(int, int, struct ssh *); 175 struct sshkey *(*load_host_private_key)(int, int, struct ssh *);
166 int (*host_key_index)(struct sshkey *, int, struct ssh *); 176 int (*host_key_index)(struct sshkey *, int, struct ssh *);
167 int (*sign)(struct sshkey *, struct sshkey *, u_char **, size_t *, 177 int (*sign)(struct ssh *, struct sshkey *, struct sshkey *,
168 const u_char *, size_t, const char *, u_int); 178 u_char **, size_t *, const u_char *, size_t, const char *);
169 int (*kex[KEX_MAX])(struct ssh *); 179 int (*kex[KEX_MAX])(struct ssh *);
170 /* kex specific state */ 180 /* kex specific state */
171 DH *dh; /* DH */ 181 DH *dh; /* DH */
172 u_int min, max, nbits; /* GEX */ 182 u_int min, max, nbits; /* GEX */
173 EC_KEY *ec_client_key; /* ECDH */ 183 EC_KEY *ec_client_key; /* ECDH */
174 const EC_GROUP *ec_group; /* ECDH */ 184 const EC_GROUP *ec_group; /* ECDH */
175 u_char c25519_client_key[CURVE25519_SIZE]; /* 25519 */ 185 u_char c25519_client_key[CURVE25519_SIZE]; /* 25519 + KEM */
176 u_char c25519_client_pubkey[CURVE25519_SIZE]; /* 25519 */ 186 u_char c25519_client_pubkey[CURVE25519_SIZE]; /* 25519 */
187 u_char sntrup4591761_client_key[crypto_kem_sntrup4591761_SECRETKEYBYTES]; /* KEM */
188 struct sshbuf *client_pub;
177}; 189};
178 190
179int kex_names_valid(const char *); 191int kex_names_valid(const char *);
180char *kex_alg_list(char); 192char *kex_alg_list(char);
193char *kex_gss_alg_list(char);
181char *kex_names_cat(const char *, const char *); 194char *kex_names_cat(const char *, const char *);
182int kex_assemble_names(char **, const char *, const char *); 195int kex_assemble_names(char **, const char *, const char *);
196int kex_gss_names_valid(const char *);
197
198int kex_exchange_identification(struct ssh *, int, int, const char *);
183 199
184int kex_new(struct ssh *, char *[PROPOSAL_MAX], struct kex **); 200struct kex *kex_new(void);
201int kex_ready(struct ssh *, char *[PROPOSAL_MAX]);
185int kex_setup(struct ssh *, char *[PROPOSAL_MAX]); 202int kex_setup(struct ssh *, char *[PROPOSAL_MAX]);
186void kex_free_newkeys(struct newkeys *); 203void kex_free_newkeys(struct newkeys *);
187void kex_free(struct kex *); 204void kex_free(struct kex *);
@@ -189,48 +206,63 @@ void kex_free(struct kex *);
189int kex_buf2prop(struct sshbuf *, int *, char ***); 206int kex_buf2prop(struct sshbuf *, int *, char ***);
190int kex_prop2buf(struct sshbuf *, char *proposal[PROPOSAL_MAX]); 207int kex_prop2buf(struct sshbuf *, char *proposal[PROPOSAL_MAX]);
191void kex_prop_free(char **); 208void kex_prop_free(char **);
209int kex_load_hostkey(struct ssh *, struct sshkey **, struct sshkey **);
210int kex_verify_host_key(struct ssh *, struct sshkey *);
192 211
193int kex_send_kexinit(struct ssh *); 212int kex_send_kexinit(struct ssh *);
194int kex_input_kexinit(int, u_int32_t, struct ssh *); 213int kex_input_kexinit(int, u_int32_t, struct ssh *);
195int kex_input_ext_info(int, u_int32_t, struct ssh *); 214int kex_input_ext_info(int, u_int32_t, struct ssh *);
196int kex_derive_keys(struct ssh *, u_char *, u_int, const struct sshbuf *); 215int kex_derive_keys(struct ssh *, u_char *, u_int, const struct sshbuf *);
197int kex_derive_keys_bn(struct ssh *, u_char *, u_int, const BIGNUM *);
198int kex_send_newkeys(struct ssh *); 216int kex_send_newkeys(struct ssh *);
199int kex_start_rekex(struct ssh *); 217int kex_start_rekex(struct ssh *);
200 218
201int kexdh_client(struct ssh *);
202int kexdh_server(struct ssh *);
203int kexgex_client(struct ssh *); 219int kexgex_client(struct ssh *);
204int kexgex_server(struct ssh *); 220int kexgex_server(struct ssh *);
205int kexecdh_client(struct ssh *); 221int kex_gen_client(struct ssh *);
206int kexecdh_server(struct ssh *); 222int kex_gen_server(struct ssh *);
207int kexc25519_client(struct ssh *); 223#if defined(GSSAPI) && defined(WITH_OPENSSL)
208int kexc25519_server(struct ssh *); 224int kexgssgex_client(struct ssh *);
209 225int kexgssgex_server(struct ssh *);
210#ifdef GSSAPI
211int kexgss_client(struct ssh *); 226int kexgss_client(struct ssh *);
212int kexgss_server(struct ssh *); 227int kexgss_server(struct ssh *);
213#endif 228#endif
214 229
215int kex_dh_hash(int, const char *, const char *, 230int kex_dh_keypair(struct kex *);
216 const u_char *, size_t, const u_char *, size_t, const u_char *, size_t, 231int kex_dh_enc(struct kex *, const struct sshbuf *, struct sshbuf **,
217 const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *); 232 struct sshbuf **);
233int kex_dh_dec(struct kex *, const struct sshbuf *, struct sshbuf **);
234
235int kex_ecdh_keypair(struct kex *);
236int kex_ecdh_enc(struct kex *, const struct sshbuf *, struct sshbuf **,
237 struct sshbuf **);
238int kex_ecdh_dec(struct kex *, const struct sshbuf *, struct sshbuf **);
218 239
219int kexgex_hash(int, const char *, const char *, 240int kex_c25519_keypair(struct kex *);
220 const u_char *, size_t, const u_char *, size_t, const u_char *, size_t, 241int kex_c25519_enc(struct kex *, const struct sshbuf *, struct sshbuf **,
242 struct sshbuf **);
243int kex_c25519_dec(struct kex *, const struct sshbuf *, struct sshbuf **);
244
245int kex_kem_sntrup4591761x25519_keypair(struct kex *);
246int kex_kem_sntrup4591761x25519_enc(struct kex *, const struct sshbuf *,
247 struct sshbuf **, struct sshbuf **);
248int kex_kem_sntrup4591761x25519_dec(struct kex *, const struct sshbuf *,
249 struct sshbuf **);
250
251int kex_dh_keygen(struct kex *);
252int kex_dh_compute_key(struct kex *, BIGNUM *, struct sshbuf *);
253
254int kexgex_hash(int, const struct sshbuf *, const struct sshbuf *,
255 const struct sshbuf *, const struct sshbuf *, const struct sshbuf *,
221 int, int, int, 256 int, int, int,
222 const BIGNUM *, const BIGNUM *, const BIGNUM *, 257 const BIGNUM *, const BIGNUM *, const BIGNUM *,
223 const BIGNUM *, const BIGNUM *, 258 const BIGNUM *, const u_char *, size_t,
224 u_char *, size_t *); 259 u_char *, size_t *);
225 260
226int kex_ecdh_hash(int, const EC_GROUP *, const char *, const char *, 261int kex_gen_hash(int hash_alg, const struct sshbuf *client_version,
227 const u_char *, size_t, const u_char *, size_t, const u_char *, size_t, 262 const struct sshbuf *server_version, const struct sshbuf *client_kexinit,
228 const EC_POINT *, const EC_POINT *, const BIGNUM *, u_char *, size_t *); 263 const struct sshbuf *server_kexinit, const struct sshbuf *server_host_key_blob,
229 264 const struct sshbuf *client_pub, const struct sshbuf *server_pub,
230int kex_c25519_hash(int, const char *, const char *, 265 const struct sshbuf *shared_secret, u_char *hash, size_t *hashlen);
231 const u_char *, size_t, const u_char *, size_t,
232 const u_char *, size_t, const u_char *, const u_char *,
233 const u_char *, size_t, u_char *, size_t *);
234 266
235void kexc25519_keygen(u_char key[CURVE25519_SIZE], u_char pub[CURVE25519_SIZE]) 267void kexc25519_keygen(u_char key[CURVE25519_SIZE], u_char pub[CURVE25519_SIZE])
236 __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE))) 268 __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE)))
@@ -239,9 +271,13 @@ int kexc25519_shared_key(const u_char key[CURVE25519_SIZE],
239 const u_char pub[CURVE25519_SIZE], struct sshbuf *out) 271 const u_char pub[CURVE25519_SIZE], struct sshbuf *out)
240 __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE))) 272 __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE)))
241 __attribute__((__bounded__(__minbytes__, 2, CURVE25519_SIZE))); 273 __attribute__((__bounded__(__minbytes__, 2, CURVE25519_SIZE)));
274int kexc25519_shared_key_ext(const u_char key[CURVE25519_SIZE],
275 const u_char pub[CURVE25519_SIZE], struct sshbuf *out, int)
276 __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE)))
277 __attribute__((__bounded__(__minbytes__, 2, CURVE25519_SIZE)));
242 278
243#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH) 279#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH)
244void dump_digest(char *, u_char *, int); 280void dump_digest(const char *, const u_char *, int);
245#endif 281#endif
246 282
247#if !defined(WITH_OPENSSL) || !defined(OPENSSL_HAS_ECC) 283#if !defined(WITH_OPENSSL) || !defined(OPENSSL_HAS_ECC)