blob: d8f37c1a67d68b8a1e079230a7e8dab4e298b9d9 [file] [log] [blame]
Kevin Steves2b725a02001-02-05 18:16:28 +00001/* $OpenBSD: kex.h,v 1.13 2001/02/04 15:32:24 stevesk Exp $ */
Ben Lindstrom36579d32001-01-29 07:39:26 +00002
Damien Miller33b13562000-04-04 14:38:59 +10003/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
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.
Damien Miller33b13562000-04-04 14:38:59 +100014 *
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
Damien Miller874d77b2000-10-14 16:23:11 +110029#define KEX_DH1 "diffie-hellman-group1-sha1"
30#define KEX_DHGEX "diffie-hellman-group-exchange-sha1"
31#define KEX_DSS "ssh-dss"
Damien Miller33b13562000-04-04 14:38:59 +100032
33enum kex_init_proposals {
34 PROPOSAL_KEX_ALGS,
35 PROPOSAL_SERVER_HOST_KEY_ALGS,
36 PROPOSAL_ENC_ALGS_CTOS,
37 PROPOSAL_ENC_ALGS_STOC,
38 PROPOSAL_MAC_ALGS_CTOS,
39 PROPOSAL_MAC_ALGS_STOC,
40 PROPOSAL_COMP_ALGS_CTOS,
41 PROPOSAL_COMP_ALGS_STOC,
42 PROPOSAL_LANG_CTOS,
43 PROPOSAL_LANG_STOC,
44 PROPOSAL_MAX
45};
46
47enum kex_modes {
48 MODE_IN,
49 MODE_OUT,
50 MODE_MAX
51};
52
Damien Miller874d77b2000-10-14 16:23:11 +110053enum kex_exchange {
54 DH_GRP1_SHA1,
55 DH_GEX_SHA1
56};
Kevin Stevesef4eea92001-02-05 12:42:17 +000057
Damien Miller33b13562000-04-04 14:38:59 +100058typedef struct Kex Kex;
59typedef struct Mac Mac;
60typedef struct Comp Comp;
61typedef struct Enc Enc;
62
63struct Enc {
Damien Miller874d77b2000-10-14 16:23:11 +110064 char *name;
65 Cipher *cipher;
Damien Miller33b13562000-04-04 14:38:59 +100066 int enabled;
Ben Lindstrom46c16222000-12-22 01:43:59 +000067 u_char *key;
68 u_char *iv;
Damien Miller33b13562000-04-04 14:38:59 +100069};
70struct Mac {
Damien Miller874d77b2000-10-14 16:23:11 +110071 char *name;
Damien Miller33b13562000-04-04 14:38:59 +100072 int enabled;
Damien Miller874d77b2000-10-14 16:23:11 +110073 EVP_MD *md;
Damien Miller33b13562000-04-04 14:38:59 +100074 int mac_len;
Ben Lindstrom46c16222000-12-22 01:43:59 +000075 u_char *key;
Damien Miller33b13562000-04-04 14:38:59 +100076 int key_len;
Damien Miller33b13562000-04-04 14:38:59 +100077};
78struct Comp {
79 int type;
80 int enabled;
81 char *name;
82};
83struct Kex {
84 Enc enc [MODE_MAX];
85 Mac mac [MODE_MAX];
86 Comp comp[MODE_MAX];
87 int we_need;
88 int server;
89 char *name;
Damien Miller0bc1bd82000-11-13 22:57:25 +110090 int hostkey_type;
Damien Miller874d77b2000-10-14 16:23:11 +110091 int kex_type;
Damien Miller33b13562000-04-04 14:38:59 +100092};
93
94Buffer *kex_init(char *myproposal[PROPOSAL_MAX]);
Damien Millerb1715dc2000-05-30 13:44:51 +100095void
96kex_exchange_kexinit(
97 Buffer *my_kexinit, Buffer *peer_kexint,
98 char *peer_proposal[PROPOSAL_MAX]);
99Kex *
100kex_choose_conf(char *cprop[PROPOSAL_MAX],
101 char *sprop[PROPOSAL_MAX], int server);
Ben Lindstrom46c16222000-12-22 01:43:59 +0000102int kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret);
Damien Millerb1715dc2000-05-30 13:44:51 +1000103void packet_set_kex(Kex *k);
Damien Miller78928792000-04-12 20:17:38 +1000104int dh_pub_is_valid(DH *dh, BIGNUM *dh_pub);
Damien Miller874d77b2000-10-14 16:23:11 +1100105DH *dh_new_group_asc(const char *, const char *);
106DH *dh_new_group(BIGNUM *, BIGNUM *);
Ben Lindstrom46c16222000-12-22 01:43:59 +0000107void dh_gen_key(DH *);
108DH *dh_new_group1(void);
Damien Miller33b13562000-04-04 14:38:59 +1000109
Ben Lindstrom46c16222000-12-22 01:43:59 +0000110u_char *
Damien Miller33b13562000-04-04 14:38:59 +1000111kex_hash(
112 char *client_version_string,
113 char *server_version_string,
114 char *ckexinit, int ckexinitlen,
115 char *skexinit, int skexinitlen,
116 char *serverhostkeyblob, int sbloblen,
117 BIGNUM *client_dh_pub,
118 BIGNUM *server_dh_pub,
119 BIGNUM *shared_secret);
120
Ben Lindstrom46c16222000-12-22 01:43:59 +0000121u_char *
Damien Miller874d77b2000-10-14 16:23:11 +1100122kex_hash_gex(
123 char *client_version_string,
124 char *server_version_string,
125 char *ckexinit, int ckexinitlen,
126 char *skexinit, int skexinitlen,
127 char *serverhostkeyblob, int sbloblen,
128 int minbits, BIGNUM *prime, BIGNUM *gen,
129 BIGNUM *client_dh_pub,
130 BIGNUM *server_dh_pub,
131 BIGNUM *shared_secret);
Damien Miller33b13562000-04-04 14:38:59 +1000132#endif