blob: 90496fbdf461be3174e90e409fff5cafd938a115 [file] [log] [blame]
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001/* $OpenBSD: kex.h,v 1.14 2001/02/11 12:59:24 markus 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
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000029#include <openssl/evp.h>
30#include "buffer.h"
31
Damien Miller874d77b2000-10-14 16:23:11 +110032#define KEX_DH1 "diffie-hellman-group1-sha1"
33#define KEX_DHGEX "diffie-hellman-group-exchange-sha1"
Damien Miller33b13562000-04-04 14:38:59 +100034
35enum kex_init_proposals {
36 PROPOSAL_KEX_ALGS,
37 PROPOSAL_SERVER_HOST_KEY_ALGS,
38 PROPOSAL_ENC_ALGS_CTOS,
39 PROPOSAL_ENC_ALGS_STOC,
40 PROPOSAL_MAC_ALGS_CTOS,
41 PROPOSAL_MAC_ALGS_STOC,
42 PROPOSAL_COMP_ALGS_CTOS,
43 PROPOSAL_COMP_ALGS_STOC,
44 PROPOSAL_LANG_CTOS,
45 PROPOSAL_LANG_STOC,
46 PROPOSAL_MAX
47};
48
49enum kex_modes {
50 MODE_IN,
51 MODE_OUT,
52 MODE_MAX
53};
54
Damien Miller874d77b2000-10-14 16:23:11 +110055enum kex_exchange {
56 DH_GRP1_SHA1,
57 DH_GEX_SHA1
58};
Kevin Stevesef4eea92001-02-05 12:42:17 +000059
Damien Miller33b13562000-04-04 14:38:59 +100060typedef struct Kex Kex;
61typedef struct Mac Mac;
62typedef struct Comp Comp;
63typedef struct Enc Enc;
64
65struct Enc {
Damien Miller874d77b2000-10-14 16:23:11 +110066 char *name;
67 Cipher *cipher;
Damien Miller33b13562000-04-04 14:38:59 +100068 int enabled;
Ben Lindstrom46c16222000-12-22 01:43:59 +000069 u_char *key;
70 u_char *iv;
Damien Miller33b13562000-04-04 14:38:59 +100071};
72struct Mac {
Damien Miller874d77b2000-10-14 16:23:11 +110073 char *name;
Damien Miller33b13562000-04-04 14:38:59 +100074 int enabled;
Damien Miller874d77b2000-10-14 16:23:11 +110075 EVP_MD *md;
Damien Miller33b13562000-04-04 14:38:59 +100076 int mac_len;
Ben Lindstrom46c16222000-12-22 01:43:59 +000077 u_char *key;
Damien Miller33b13562000-04-04 14:38:59 +100078 int key_len;
Damien Miller33b13562000-04-04 14:38:59 +100079};
80struct Comp {
81 int type;
82 int enabled;
83 char *name;
84};
85struct Kex {
86 Enc enc [MODE_MAX];
87 Mac mac [MODE_MAX];
88 Comp comp[MODE_MAX];
89 int we_need;
90 int server;
91 char *name;
Damien Miller0bc1bd82000-11-13 22:57:25 +110092 int hostkey_type;
Damien Miller874d77b2000-10-14 16:23:11 +110093 int kex_type;
Damien Miller33b13562000-04-04 14:38:59 +100094};
95
96Buffer *kex_init(char *myproposal[PROPOSAL_MAX]);
Damien Millerb1715dc2000-05-30 13:44:51 +100097void
98kex_exchange_kexinit(
99 Buffer *my_kexinit, Buffer *peer_kexint,
100 char *peer_proposal[PROPOSAL_MAX]);
101Kex *
102kex_choose_conf(char *cprop[PROPOSAL_MAX],
103 char *sprop[PROPOSAL_MAX], int server);
Ben Lindstrom46c16222000-12-22 01:43:59 +0000104int kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret);
Damien Millerb1715dc2000-05-30 13:44:51 +1000105void packet_set_kex(Kex *k);
Damien Miller78928792000-04-12 20:17:38 +1000106int dh_pub_is_valid(DH *dh, BIGNUM *dh_pub);
Damien Miller874d77b2000-10-14 16:23:11 +1100107DH *dh_new_group_asc(const char *, const char *);
108DH *dh_new_group(BIGNUM *, BIGNUM *);
Ben Lindstrom46c16222000-12-22 01:43:59 +0000109void dh_gen_key(DH *);
110DH *dh_new_group1(void);
Damien Miller33b13562000-04-04 14:38:59 +1000111
Ben Lindstrom46c16222000-12-22 01:43:59 +0000112u_char *
Damien Miller33b13562000-04-04 14:38:59 +1000113kex_hash(
114 char *client_version_string,
115 char *server_version_string,
116 char *ckexinit, int ckexinitlen,
117 char *skexinit, int skexinitlen,
118 char *serverhostkeyblob, int sbloblen,
119 BIGNUM *client_dh_pub,
120 BIGNUM *server_dh_pub,
121 BIGNUM *shared_secret);
122
Ben Lindstrom46c16222000-12-22 01:43:59 +0000123u_char *
Damien Miller874d77b2000-10-14 16:23:11 +1100124kex_hash_gex(
125 char *client_version_string,
126 char *server_version_string,
127 char *ckexinit, int ckexinitlen,
128 char *skexinit, int skexinitlen,
129 char *serverhostkeyblob, int sbloblen,
130 int minbits, BIGNUM *prime, BIGNUM *gen,
131 BIGNUM *client_dh_pub,
132 BIGNUM *server_dh_pub,
133 BIGNUM *shared_secret);
Damien Miller33b13562000-04-04 14:38:59 +1000134#endif