Annotation of src/usr.bin/ssh/kex.h, Revision 1.51
1.51 ! djm 1: /* $OpenBSD: kex.h,v 1.50 2010/08/31 11:54:45 djm Exp $ */
1.12 niklas 2:
1.1 markus 3: /*
1.24 markus 4: * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
1.1 markus 5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26: #ifndef KEX_H
27: #define KEX_H
28:
1.14 markus 29: #include <openssl/evp.h>
1.45 djm 30: #include <openssl/hmac.h>
1.50 djm 31: #include <openssl/ec.h>
1.47 andreas 32:
33: #define KEX_COOKIE_LEN 16
1.14 markus 34:
1.38 djm 35: #define KEX_DH1 "diffie-hellman-group1-sha1"
36: #define KEX_DH14 "diffie-hellman-group14-sha1"
37: #define KEX_DHGEX_SHA1 "diffie-hellman-group-exchange-sha1"
1.39 djm 38: #define KEX_DHGEX_SHA256 "diffie-hellman-group-exchange-sha256"
1.48 andreas 39: #define KEX_RESUME "resume@appgate.com"
1.50 djm 40: /* The following represents the family of ECDH methods */
1.51 ! djm 41: #define KEX_ECDH_SHA2_STEM "ecdh-sha2-"
1.37 markus 42:
43: #define COMP_NONE 0
44: #define COMP_ZLIB 1
45: #define COMP_DELAYED 2
1.1 markus 46:
47: enum kex_init_proposals {
48: PROPOSAL_KEX_ALGS,
49: PROPOSAL_SERVER_HOST_KEY_ALGS,
50: PROPOSAL_ENC_ALGS_CTOS,
51: PROPOSAL_ENC_ALGS_STOC,
52: PROPOSAL_MAC_ALGS_CTOS,
53: PROPOSAL_MAC_ALGS_STOC,
54: PROPOSAL_COMP_ALGS_CTOS,
55: PROPOSAL_COMP_ALGS_STOC,
56: PROPOSAL_LANG_CTOS,
57: PROPOSAL_LANG_STOC,
58: PROPOSAL_MAX
59: };
60:
61: enum kex_modes {
62: MODE_IN,
63: MODE_OUT,
64: MODE_MAX
65: };
66:
1.5 provos 67: enum kex_exchange {
1.33 markus 68: KEX_DH_GRP1_SHA1,
1.35 djm 69: KEX_DH_GRP14_SHA1,
1.33 markus 70: KEX_DH_GEX_SHA1,
1.39 djm 71: KEX_DH_GEX_SHA256,
1.50 djm 72: KEX_ECDH_SHA2,
1.33 markus 73: KEX_MAX
1.5 provos 74: };
1.13 stevesk 75:
1.19 markus 76: #define KEX_INIT_SENT 0x0001
77:
1.1 markus 78: typedef struct Kex Kex;
79: typedef struct Mac Mac;
80: typedef struct Comp Comp;
81: typedef struct Enc Enc;
1.19 markus 82: typedef struct Newkeys Newkeys;
1.1 markus 83:
84: struct Enc {
1.19 markus 85: char *name;
86: Cipher *cipher;
87: int enabled;
1.29 markus 88: u_int key_len;
89: u_int block_size;
1.10 markus 90: u_char *key;
91: u_char *iv;
1.1 markus 92: };
93: struct Mac {
1.19 markus 94: char *name;
95: int enabled;
1.36 djm 96: u_int mac_len;
1.10 markus 97: u_char *key;
1.36 djm 98: u_int key_len;
1.46 pvalchev 99: int type;
100: const EVP_MD *evp_md;
101: HMAC_CTX evp_ctx;
102: struct umac_ctx *umac_ctx;
1.1 markus 103: };
104: struct Comp {
1.19 markus 105: int type;
106: int enabled;
107: char *name;
108: };
109: struct Newkeys {
110: Enc enc;
111: Mac mac;
112: Comp comp;
1.1 markus 113: };
114: struct Kex {
1.19 markus 115: u_char *session_id;
1.32 markus 116: u_int session_id_len;
1.22 markus 117: Newkeys *newkeys[MODE_MAX];
1.36 djm 118: u_int we_need;
1.19 markus 119: int server;
120: char *name;
121: int hostkey_type;
122: int kex_type;
1.48 andreas 123: int roaming;
1.19 markus 124: Buffer my;
125: Buffer peer;
1.42 djm 126: sig_atomic_t done;
1.19 markus 127: int flags;
1.38 djm 128: const EVP_MD *evp_md;
1.19 markus 129: char *client_version_string;
130: char *server_version_string;
1.25 itojun 131: int (*verify_host_key)(Key *);
1.49 djm 132: Key *(*load_host_public_key)(int);
133: Key *(*load_host_private_key)(int);
1.30 provos 134: int (*host_key_index)(Key *);
1.33 markus 135: void (*kex[KEX_MAX])(Kex *);
1.1 markus 136: };
137:
1.25 itojun 138: Kex *kex_setup(char *[PROPOSAL_MAX]);
1.26 markus 139: void kex_finish(Kex *);
1.20 markus 140:
1.26 markus 141: void kex_send_kexinit(Kex *);
1.28 markus 142: void kex_input_kexinit(int, u_int32_t, void *);
1.38 djm 143: void kex_derive_keys(Kex *, u_char *, u_int, BIGNUM *);
1.18 markus 144:
1.33 markus 145: Newkeys *kex_get_newkeys(int);
1.19 markus 146:
1.33 markus 147: void kexdh_client(Kex *);
148: void kexdh_server(Kex *);
149: void kexgex_client(Kex *);
150: void kexgex_server(Kex *);
1.50 djm 151: void kexecdh_client(Kex *);
152: void kexecdh_server(Kex *);
1.33 markus 153:
1.38 djm 154: void
1.33 markus 155: kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
1.38 djm 156: BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *);
157: void
158: kexgex_hash(const EVP_MD *, char *, char *, char *, int, char *,
1.40 deraadt 159: int, u_char *, int, int, int, int, BIGNUM *, BIGNUM *, BIGNUM *,
1.38 djm 160: BIGNUM *, BIGNUM *, u_char **, u_int *);
1.50 djm 161: void
162: kex_ecdh_hash(const EVP_MD *, const EC_GROUP *, char *, char *, char *, int,
163: char *, int, u_char *, int, const EC_POINT *, const EC_POINT *,
164: const BIGNUM *, u_char **, u_int *);
165:
166: int kex_ecdh_name_to_nid(const char *);
1.51 ! djm 167: const EVP_MD *kex_ecdh_name_to_evpmd(const char *);
1.34 markus 168:
169: void
170: derive_ssh1_session_id(BIGNUM *, BIGNUM *, u_int8_t[8], u_int8_t[16]);
1.18 markus 171:
1.50 djm 172: #if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH)
1.25 itojun 173: void dump_digest(char *, u_char *, int);
1.18 markus 174: #endif
1.1 markus 175:
176: #endif