blob: 755bf332aa40b52ddd26abc31a82e626a4a63a58 [file] [log] [blame]
Damien Miller963f6b22002-02-19 15:21:23 +11001/* $OpenBSD: kex.h,v 1.29 2002/02/14 23:41:01 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;
Damien Miller963f6b22002-02-19 15:21:23 +110074 u_int key_len;
75 u_int block_size;
Ben Lindstrom46c16222000-12-22 01:43:59 +000076 u_char *key;
77 u_char *iv;
Damien Miller33b13562000-04-04 14:38:59 +100078};
79struct Mac {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000080 char *name;
81 int enabled;
82 EVP_MD *md;
83 int mac_len;
Ben Lindstrom46c16222000-12-22 01:43:59 +000084 u_char *key;
Ben Lindstrom2d90e002001-04-04 02:00:54 +000085 int key_len;
Damien Miller33b13562000-04-04 14:38:59 +100086};
87struct Comp {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000088 int type;
89 int enabled;
90 char *name;
Damien Miller33b13562000-04-04 14:38:59 +100091};
Ben Lindstrom2d90e002001-04-04 02:00:54 +000092struct Newkeys {
93 Enc enc;
94 Mac mac;
95 Comp comp;
96};
Damien Miller33b13562000-04-04 14:38:59 +100097struct Kex {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000098 u_char *session_id;
99 int session_id_len;
Ben Lindstrombe2cc432001-04-04 23:46:07 +0000100 Newkeys *newkeys[MODE_MAX];
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000101 int we_need;
102 int server;
103 char *name;
104 int hostkey_type;
105 int kex_type;
106 Buffer my;
107 Buffer peer;
Ben Lindstrombe2cc432001-04-04 23:46:07 +0000108 int done;
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000109 int flags;
110 char *client_version_string;
111 char *server_version_string;
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000112 int (*verify_host_key)(Key *);
113 Key *(*load_host_key)(int);
Damien Miller33b13562000-04-04 14:38:59 +1000114};
115
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000116Kex *kex_setup(char *[PROPOSAL_MAX]);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000117void kex_finish(Kex *);
Ben Lindstrom238abf62001-04-04 17:52:53 +0000118
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000119void kex_send_kexinit(Kex *);
Damien Miller630d6f42002-01-22 23:17:30 +1100120void kex_input_kexinit(int, u_int32_t, void *);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000121void kex_derive_keys(Kex *, u_char *, BIGNUM *);
Damien Miller33b13562000-04-04 14:38:59 +1000122
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000123void kexdh(Kex *);
124void kexgex(Kex *);
Damien Miller33b13562000-04-04 14:38:59 +1000125
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000126Newkeys *kex_get_newkeys(int);
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000127
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000128#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH)
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000129void dump_digest(char *, u_char *, int);
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000130#endif
131
Damien Miller33b13562000-04-04 14:38:59 +1000132#endif