blob: 83f54fd968a1f650eab0d1eb77da535d2431fb9b [file] [log] [blame]
Ben Lindstrom2d90e002001-04-04 02:00:54 +00001/* $OpenBSD: kex.h,v 1.19 2001/04/03 23:32:12 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"
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +000031#include "cipher.h"
32#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000033
Damien Miller874d77b2000-10-14 16:23:11 +110034#define KEX_DH1 "diffie-hellman-group1-sha1"
35#define KEX_DHGEX "diffie-hellman-group-exchange-sha1"
Damien Miller33b13562000-04-04 14:38:59 +100036
37enum kex_init_proposals {
38 PROPOSAL_KEX_ALGS,
39 PROPOSAL_SERVER_HOST_KEY_ALGS,
40 PROPOSAL_ENC_ALGS_CTOS,
41 PROPOSAL_ENC_ALGS_STOC,
42 PROPOSAL_MAC_ALGS_CTOS,
43 PROPOSAL_MAC_ALGS_STOC,
44 PROPOSAL_COMP_ALGS_CTOS,
45 PROPOSAL_COMP_ALGS_STOC,
46 PROPOSAL_LANG_CTOS,
47 PROPOSAL_LANG_STOC,
48 PROPOSAL_MAX
49};
50
51enum kex_modes {
52 MODE_IN,
53 MODE_OUT,
54 MODE_MAX
55};
56
Damien Miller874d77b2000-10-14 16:23:11 +110057enum kex_exchange {
58 DH_GRP1_SHA1,
59 DH_GEX_SHA1
60};
Kevin Stevesef4eea92001-02-05 12:42:17 +000061
Ben Lindstrom2d90e002001-04-04 02:00:54 +000062#define KEX_INIT_SENT 0x0001
63
Damien Miller33b13562000-04-04 14:38:59 +100064typedef struct Kex Kex;
65typedef struct Mac Mac;
66typedef struct Comp Comp;
67typedef struct Enc Enc;
Ben Lindstrom2d90e002001-04-04 02:00:54 +000068typedef struct Newkeys Newkeys;
Damien Miller33b13562000-04-04 14:38:59 +100069
70struct Enc {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000071 char *name;
72 Cipher *cipher;
73 int enabled;
Ben Lindstrom46c16222000-12-22 01:43:59 +000074 u_char *key;
75 u_char *iv;
Damien Miller33b13562000-04-04 14:38:59 +100076};
77struct Mac {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000078 char *name;
79 int enabled;
80 EVP_MD *md;
81 int mac_len;
Ben Lindstrom46c16222000-12-22 01:43:59 +000082 u_char *key;
Ben Lindstrom2d90e002001-04-04 02:00:54 +000083 int key_len;
Damien Miller33b13562000-04-04 14:38:59 +100084};
85struct Comp {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000086 int type;
87 int enabled;
88 char *name;
Damien Miller33b13562000-04-04 14:38:59 +100089};
Ben Lindstrom2d90e002001-04-04 02:00:54 +000090struct Newkeys {
91 Enc enc;
92 Mac mac;
93 Comp comp;
94};
Damien Miller33b13562000-04-04 14:38:59 +100095struct Kex {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000096 u_char *session_id;
97 int session_id_len;
98 Newkeys *keys[MODE_MAX];
99 int we_need;
100 int server;
101 char *name;
102 int hostkey_type;
103 int kex_type;
104 Buffer my;
105 Buffer peer;
106 int newkeys;
107 int flags;
108 char *client_version_string;
109 char *server_version_string;
110 int (*check_host_key)(Key *hostkey);
111 Key *(*load_host_key)(int type);
Damien Miller33b13562000-04-04 14:38:59 +1000112};
113
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000114Kex *kex_start(char *proposal[PROPOSAL_MAX]);
115void kex_send_newkeys(void);
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000116void kex_send_kexinit(Kex *kex);
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000117void kex_protocol_error(int type, int plen, void *ctxt);
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000118void kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret);
Damien Miller33b13562000-04-04 14:38:59 +1000119
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000120void kexdh(Kex *);
121void kexgex(Kex *);
Damien Miller33b13562000-04-04 14:38:59 +1000122
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000123Newkeys *kex_get_newkeys(int mode);
124
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000125#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH)
126void dump_digest(char *msg, u_char *digest, int len);
127#endif
128
Damien Miller33b13562000-04-04 14:38:59 +1000129#endif