Damien Miller | 9709f90 | 2001-03-30 10:50:10 +1000 | [diff] [blame] | 1 | /* $OpenBSD: kex.h,v 1.17 2001/03/29 21:17:40 markus Exp $ */ |
Ben Lindstrom | 36579d3 | 2001-01-29 07:39:26 +0000 | [diff] [blame] | 2 | |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 3 | /* |
| 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 Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 14 | * |
| 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 Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 29 | #include <openssl/evp.h> |
| 30 | #include "buffer.h" |
| 31 | |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 32 | #define KEX_DH1 "diffie-hellman-group1-sha1" |
| 33 | #define KEX_DHGEX "diffie-hellman-group-exchange-sha1" |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 34 | |
| 35 | enum 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 | |
| 49 | enum kex_modes { |
| 50 | MODE_IN, |
| 51 | MODE_OUT, |
| 52 | MODE_MAX |
| 53 | }; |
| 54 | |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 55 | enum kex_exchange { |
| 56 | DH_GRP1_SHA1, |
| 57 | DH_GEX_SHA1 |
| 58 | }; |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 59 | |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 60 | typedef struct Kex Kex; |
| 61 | typedef struct Mac Mac; |
| 62 | typedef struct Comp Comp; |
| 63 | typedef struct Enc Enc; |
| 64 | |
| 65 | struct Enc { |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 66 | char *name; |
| 67 | Cipher *cipher; |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 68 | int enabled; |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 69 | u_char *key; |
| 70 | u_char *iv; |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 71 | }; |
| 72 | struct Mac { |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 73 | char *name; |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 74 | int enabled; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 75 | EVP_MD *md; |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 76 | int mac_len; |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 77 | u_char *key; |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 78 | int key_len; |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 79 | }; |
| 80 | struct Comp { |
| 81 | int type; |
| 82 | int enabled; |
| 83 | char *name; |
| 84 | }; |
| 85 | struct 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 Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 92 | int hostkey_type; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 93 | int kex_type; |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | Buffer *kex_init(char *myproposal[PROPOSAL_MAX]); |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 97 | void |
| 98 | kex_exchange_kexinit( |
| 99 | Buffer *my_kexinit, Buffer *peer_kexint, |
| 100 | char *peer_proposal[PROPOSAL_MAX]); |
| 101 | Kex * |
| 102 | kex_choose_conf(char *cprop[PROPOSAL_MAX], |
| 103 | char *sprop[PROPOSAL_MAX], int server); |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 104 | int kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret); |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 105 | void packet_set_kex(Kex *k); |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 106 | |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 107 | u_char * |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 108 | kex_hash( |
| 109 | char *client_version_string, |
| 110 | char *server_version_string, |
| 111 | char *ckexinit, int ckexinitlen, |
| 112 | char *skexinit, int skexinitlen, |
| 113 | char *serverhostkeyblob, int sbloblen, |
| 114 | BIGNUM *client_dh_pub, |
| 115 | BIGNUM *server_dh_pub, |
| 116 | BIGNUM *shared_secret); |
| 117 | |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 118 | u_char * |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 119 | kex_hash_gex( |
| 120 | char *client_version_string, |
| 121 | char *server_version_string, |
| 122 | char *ckexinit, int ckexinitlen, |
| 123 | char *skexinit, int skexinitlen, |
| 124 | char *serverhostkeyblob, int sbloblen, |
Damien Miller | 2557bfc | 2001-03-30 10:47:14 +1000 | [diff] [blame] | 125 | int min, int wantbits, int max, |
| 126 | BIGNUM *prime, BIGNUM *gen, |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 127 | BIGNUM *client_dh_pub, |
| 128 | BIGNUM *server_dh_pub, |
| 129 | BIGNUM *shared_secret); |
Damien Miller | 33b1356 | 2000-04-04 14:38:59 +1000 | [diff] [blame] | 130 | #endif |