blob: 7bd6bc2159bf007e24417e00cef6ed2fede14ae0 [file] [log] [blame]
Damien Miller630d6f42002-01-22 23:17:30 +11001/* $OpenBSD: kex.h,v 1.28 2001/12/28 15:06:00 markus Exp $ */
Ben Lindstrom36579d32001-01-29 07:39:26 +00002
Damien Miller33b13562000-04-04 14:38:59 +10003/*
Ben Lindstrom44697232001-07-04 03:32:30 +00004 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
Damien Miller33b13562000-04-04 14:38:59 +10005 *
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;
Ben Lindstrombe2cc432001-04-04 23:46:07 +000098 Newkeys *newkeys[MODE_MAX];
Ben Lindstrom2d90e002001-04-04 02:00:54 +000099 int we_need;
100 int server;
101 char *name;
102 int hostkey_type;
103 int kex_type;
104 Buffer my;
105 Buffer peer;
Ben Lindstrombe2cc432001-04-04 23:46:07 +0000106 int done;
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000107 int flags;
108 char *client_version_string;
109 char *server_version_string;
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000110 int (*verify_host_key)(Key *);
111 Key *(*load_host_key)(int);
Damien Miller33b13562000-04-04 14:38:59 +1000112};
113
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000114Kex *kex_setup(char *[PROPOSAL_MAX]);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000115void kex_finish(Kex *);
Ben Lindstrom238abf62001-04-04 17:52:53 +0000116
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000117void kex_send_kexinit(Kex *);
Damien Miller630d6f42002-01-22 23:17:30 +1100118void kex_input_kexinit(int, u_int32_t, void *);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000119void kex_derive_keys(Kex *, u_char *, BIGNUM *);
Damien Miller33b13562000-04-04 14:38:59 +1000120
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000121void kexdh(Kex *);
122void kexgex(Kex *);
Damien Miller33b13562000-04-04 14:38:59 +1000123
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000124Newkeys *kex_get_newkeys(int);
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000125
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000126#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH)
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000127void dump_digest(char *, u_char *, int);
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000128#endif
129
Damien Miller33b13562000-04-04 14:38:59 +1000130#endif