blob: 52d442e9a7d19b39068f7cc534f714e01f215dca [file] [log] [blame]
Damien Miller8e7fb332003-02-24 12:03:03 +11001/* $OpenBSD: kex.h,v 1.33 2003/02/16 17:09:57 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 {
Damien Miller8e7fb332003-02-24 12:03:03 +110058 KEX_DH_GRP1_SHA1,
59 KEX_DH_GEX_SHA1,
60 KEX_MAX
Damien Miller874d77b2000-10-14 16:23:11 +110061};
Kevin Stevesef4eea92001-02-05 12:42:17 +000062
Ben Lindstrom2d90e002001-04-04 02:00:54 +000063#define KEX_INIT_SENT 0x0001
64
Damien Miller33b13562000-04-04 14:38:59 +100065typedef struct Kex Kex;
66typedef struct Mac Mac;
67typedef struct Comp Comp;
68typedef struct Enc Enc;
Ben Lindstrom2d90e002001-04-04 02:00:54 +000069typedef struct Newkeys Newkeys;
Damien Miller33b13562000-04-04 14:38:59 +100070
71struct Enc {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000072 char *name;
73 Cipher *cipher;
74 int enabled;
Damien Miller963f6b22002-02-19 15:21:23 +110075 u_int key_len;
76 u_int block_size;
Ben Lindstrom46c16222000-12-22 01:43:59 +000077 u_char *key;
78 u_char *iv;
Damien Miller33b13562000-04-04 14:38:59 +100079};
80struct Mac {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000081 char *name;
82 int enabled;
Ben Lindstrom6a246412002-06-06 19:48:16 +000083 const EVP_MD *md;
Ben Lindstrom2d90e002001-04-04 02:00:54 +000084 int mac_len;
Ben Lindstrom46c16222000-12-22 01:43:59 +000085 u_char *key;
Ben Lindstrom2d90e002001-04-04 02:00:54 +000086 int key_len;
Damien Miller33b13562000-04-04 14:38:59 +100087};
88struct Comp {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000089 int type;
90 int enabled;
91 char *name;
Damien Miller33b13562000-04-04 14:38:59 +100092};
Ben Lindstrom2d90e002001-04-04 02:00:54 +000093struct Newkeys {
94 Enc enc;
95 Mac mac;
96 Comp comp;
97};
Damien Miller33b13562000-04-04 14:38:59 +100098struct Kex {
Ben Lindstrom2d90e002001-04-04 02:00:54 +000099 u_char *session_id;
Damien Millera10f5612002-09-12 09:49:15 +1000100 u_int session_id_len;
Ben Lindstrombe2cc432001-04-04 23:46:07 +0000101 Newkeys *newkeys[MODE_MAX];
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000102 int we_need;
103 int server;
104 char *name;
105 int hostkey_type;
106 int kex_type;
107 Buffer my;
108 Buffer peer;
Ben Lindstrombe2cc432001-04-04 23:46:07 +0000109 int done;
Ben Lindstrom2d90e002001-04-04 02:00:54 +0000110 int flags;
111 char *client_version_string;
112 char *server_version_string;
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000113 int (*verify_host_key)(Key *);
114 Key *(*load_host_key)(int);
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000115 int (*host_key_index)(Key *);
Damien Miller8e7fb332003-02-24 12:03:03 +1100116 void (*kex[KEX_MAX])(Kex *);
Damien Miller33b13562000-04-04 14:38:59 +1000117};
118
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000119Kex *kex_setup(char *[PROPOSAL_MAX]);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000120void kex_finish(Kex *);
Ben Lindstrom238abf62001-04-04 17:52:53 +0000121
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000122void kex_send_kexinit(Kex *);
Damien Miller630d6f42002-01-22 23:17:30 +1100123void kex_input_kexinit(int, u_int32_t, void *);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000124void kex_derive_keys(Kex *, u_char *, BIGNUM *);
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
Damien Miller8e7fb332003-02-24 12:03:03 +1100128void kexdh_client(Kex *);
129void kexdh_server(Kex *);
130void kexgex_client(Kex *);
131void kexgex_server(Kex *);
132
133u_char *
134kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
135 BIGNUM *, BIGNUM *, BIGNUM *);
136u_char *
137kexgex_hash(char *, char *, char *, int, char *, int, u_char *, int,
138 int, int, int, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *);
139
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000140#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH)
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000141void dump_digest(char *, u_char *, int);
Ben Lindstrom20d7c7b2001-04-04 01:56:17 +0000142#endif
143
Damien Miller33b13562000-04-04 14:38:59 +1000144#endif