Mercurial > dropbear
annotate common-algo.c @ 502:43bbe17d6ba0
- Add Counter Mode support
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 29 Sep 2008 13:53:31 +0000 |
parents | d58c478bd399 |
children | 0cdbc95bb3d2 |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
2 * Dropbear SSH |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * Copyright (c) 2002,2003 Matt Johnston |
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
5 * Copyright (c) 2004 by Mihnea Stoenescu |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * Permission is hereby granted, free of charge, to any person obtaining a copy |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * of this software and associated documentation files (the "Software"), to deal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * in the Software without restriction, including without limitation the rights |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * copies of the Software, and to permit persons to whom the Software is |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * furnished to do so, subject to the following conditions: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * The above copyright notice and this permission notice shall be included in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * all copies or substantial portions of the Software. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 * SOFTWARE. */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 #include "algo.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "dbutil.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 /* This file (algo.c) organises the ciphers which can be used, and is used to |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 * decide which ciphers/hashes/compression/signing to use during key exchange*/ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 |
502 | 32 static int void_cipher(const unsigned char* in, unsigned char* out, |
33 unsigned long len, void *cipher_state) { | |
34 memcpy(out, in, len); | |
35 return CRYPT_OK; | |
36 } | |
37 | |
38 static int void_start(int cipher, const unsigned char *IV, | |
39 const unsigned char *key, | |
40 int keylen, int num_rounds, void *cipher_state) { | |
41 return CRYPT_OK; | |
42 } | |
43 | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 /* Mappings for ciphers, parameters are |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 {&cipher_desc, keysize, blocksize} */ |
409
0e69e948caba
Add comments about requiring keysize <= 2*SHA1_HASH_SIZE
Matt Johnston <matt@ucc.asn.au>
parents:
255
diff
changeset
|
46 /* NOTE: if keysize > 2*SHA1_HASH_SIZE, code such as hashkeys() |
0e69e948caba
Add comments about requiring keysize <= 2*SHA1_HASH_SIZE
Matt Johnston <matt@ucc.asn.au>
parents:
255
diff
changeset
|
47 needs revisiting */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 |
502 | 49 #ifdef DROPBEAR_AES256 |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
50 static const struct dropbear_cipher dropbear_aes256 = |
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
51 {&aes_desc, 32, 16}; |
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
52 #endif |
502 | 53 #ifdef DROPBEAR_AES128 |
227 | 54 static const struct dropbear_cipher dropbear_aes128 = |
150
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
74
diff
changeset
|
55 {&aes_desc, 16, 16}; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 #endif |
502 | 57 #ifdef DROPBEAR_BLOWFISH |
227 | 58 static const struct dropbear_cipher dropbear_blowfish = |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 {&blowfish_desc, 16, 8}; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 #endif |
502 | 61 #ifdef DROPBEAR_TWOFISH256 |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
62 static const struct dropbear_cipher dropbear_twofish256 = |
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
63 {&twofish_desc, 32, 16}; |
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
64 #endif |
502 | 65 #ifdef DROPBEAR_TWOFISH128 |
227 | 66 static const struct dropbear_cipher dropbear_twofish128 = |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 {&twofish_desc, 16, 16}; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 #endif |
502 | 69 #ifdef DROPBEAR_3DES |
227 | 70 static const struct dropbear_cipher dropbear_3des = |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 {&des3_desc, 24, 8}; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 /* used to indicate no encryption, as defined in rfc2410 */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 const struct dropbear_cipher dropbear_nocipher = |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 {NULL, 16, 8}; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 |
502 | 78 /* A few void* s are required to silence warnings |
79 * about the symmetric_CBC vs symmetric_CTR cipher_state pointer */ | |
80 const struct dropbear_cipher_mode dropbear_mode_cbc = | |
81 {(void*)cbc_start, (void*)cbc_encrypt, (void*)cbc_decrypt}; | |
82 const struct dropbear_cipher_mode dropbear_mode_none = | |
83 {void_start, void_cipher, void_cipher}; | |
84 #ifdef DROPBEAR_ENABLE_CTR_MODE | |
85 /* a wrapper to make ctr_start and cbc_start look the same */ | |
86 static int dropbear_big_endian_ctr_start(int cipher, | |
87 const unsigned char *IV, | |
88 const unsigned char *key, int keylen, | |
89 int num_rounds, symmetric_CTR *ctr) { | |
90 return ctr_start(cipher, IV, key, keylen, num_rounds, CTR_COUNTER_BIG_ENDIAN, ctr); | |
91 } | |
92 const struct dropbear_cipher_mode dropbear_mode_ctr = | |
93 {(void*)dropbear_big_endian_ctr_start, (void*)ctr_encrypt, (void*)ctr_decrypt}; | |
94 #endif | |
95 | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
96 /* Mapping of ssh hashes to libtomcrypt hashes, including keysize etc. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 {&hash_desc, keysize, hashsize} */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 #ifdef DROPBEAR_SHA1_HMAC |
227 | 100 static const struct dropbear_hash dropbear_sha1 = |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 {&sha1_desc, 20, 20}; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 #endif |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
103 #ifdef DROPBEAR_SHA1_96_HMAC |
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
104 static const struct dropbear_hash dropbear_sha1_96 = |
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
105 {&sha1_desc, 20, 12}; |
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
106 #endif |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 #ifdef DROPBEAR_MD5_HMAC |
227 | 108 static const struct dropbear_hash dropbear_md5 = |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 {&md5_desc, 16, 16}; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 const struct dropbear_hash dropbear_nohash = |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 {NULL, 16, 0}; /* used initially */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 |
502 | 116 /* The following map ssh names to internal values. |
117 * The ordering here is important for the client - the first mode | |
118 * that is also supported by the server will get used. */ | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 algo_type sshciphers[] = { |
502 | 121 #ifdef DROPBEAR_ENABLE_CTR_MODE |
122 #ifdef DROPBEAR_AES128 | |
123 {"aes128-ctr", 0, &dropbear_aes128, 1, &dropbear_mode_ctr}, | |
124 #endif | |
125 #ifdef DROPBEAR_3DES | |
126 {"3des-ctr", 0, &dropbear_3des, 1, &dropbear_mode_ctr}, | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 #endif |
502 | 128 #ifdef DROPBEAR_AES256 |
129 {"aes256-ctr", 0, &dropbear_aes256, 1, &dropbear_mode_ctr}, | |
130 #endif | |
131 #ifdef DROPBEAR_TWOFISH256 | |
132 {"twofish256-ctr", 0, &dropbear_twofish256, 1, &dropbear_mode_ctr}, | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
133 #endif |
502 | 134 #ifdef DROPBEAR_TWOFISH128 |
135 {"twofish128-ctr", 0, &dropbear_twofish128, 1, &dropbear_mode_ctr}, | |
136 #endif | |
137 #ifdef DROPBEAR_BLOWFISH | |
138 {"blowfish-ctr", 0, &dropbear_blowfish, 1, &dropbear_mode_ctr}, | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
139 #endif |
502 | 140 #endif /* DROPBEAR_ENABLE_CTR_MODE */ |
141 | |
142 /* CBC modes are always enabled */ | |
143 #ifdef DROPBEAR_AES128 | |
144 {"aes128-cbc", 0, &dropbear_aes128, 1, &dropbear_mode_cbc}, | |
145 #endif | |
146 #ifdef DROPBEAR_3DES | |
147 {"3des-cbc", 0, &dropbear_3des, 1, &dropbear_mode_cbc}, | |
148 #endif | |
149 #ifdef DROPBEAR_AES256 | |
150 {"aes256-cbc", 0, &dropbear_aes256, 1, &dropbear_mode_cbc}, | |
235
c3dbd3e1a8ce
Change the preferred algorithm order
Matt Johnston <matt@ucc.asn.au>
parents:
234
diff
changeset
|
151 #endif |
502 | 152 #ifdef DROPBEAR_TWOFISH256 |
153 {"twofish256-cbc", 0, &dropbear_twofish256, 1, &dropbear_mode_cbc}, | |
154 {"twofish-cbc", 0, &dropbear_twofish256, 1, &dropbear_mode_cbc}, | |
235
c3dbd3e1a8ce
Change the preferred algorithm order
Matt Johnston <matt@ucc.asn.au>
parents:
234
diff
changeset
|
155 #endif |
502 | 156 #ifdef DROPBEAR_TWOFISH128 |
157 {"twofish128-cbc", 0, &dropbear_twofish128, 1, &dropbear_mode_cbc}, | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 #endif |
502 | 159 #ifdef DROPBEAR_BLOWFISH |
160 {"blowfish-cbc", 0, &dropbear_blowfish, 1, &dropbear_mode_cbc}, | |
161 #endif | |
162 {NULL, 0, NULL, 0, NULL} | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 }; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 algo_type sshhashes[] = { |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
166 #ifdef DROPBEAR_SHA1_96_HMAC |
502 | 167 {"hmac-sha1-96", 0, &dropbear_sha1_96, 1, NULL}, |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
168 #endif |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 #ifdef DROPBEAR_SHA1_HMAC |
502 | 170 {"hmac-sha1", 0, &dropbear_sha1, 1, NULL}, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
172 #ifdef DROPBEAR_MD5_HMAC |
502 | 173 {"hmac-md5", 0, &dropbear_md5, 1, NULL}, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
174 #endif |
502 | 175 {NULL, 0, NULL, 0, NULL} |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
176 }; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
177 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
178 algo_type sshcompress[] = { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
179 #ifndef DISABLE_ZLIB |
502 | 180 {"zlib", DROPBEAR_COMP_ZLIB, NULL, 1, NULL}, |
181 {"[email protected]", DROPBEAR_COMP_ZLIB_DELAY, NULL, 1, NULL}, | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 #endif |
502 | 183 {"none", DROPBEAR_COMP_NONE, NULL, 1, NULL}, |
184 {NULL, 0, NULL, 0, NULL} | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
185 }; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
186 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
187 algo_type sshhostkey[] = { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
188 #ifdef DROPBEAR_RSA |
502 | 189 {"ssh-rsa", DROPBEAR_SIGNKEY_RSA, NULL, 1, NULL}, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
190 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
191 #ifdef DROPBEAR_DSS |
502 | 192 {"ssh-dss", DROPBEAR_SIGNKEY_DSS, NULL, 1, NULL}, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
193 #endif |
502 | 194 {NULL, 0, NULL, 0, NULL} |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
195 }; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
196 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
197 algo_type sshkex[] = { |
502 | 198 {"diffie-hellman-group1-sha1", DROPBEAR_KEX_DH_GROUP1, NULL, 1, NULL}, |
199 {NULL, 0, NULL, 0, NULL} | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
200 }; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
201 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
202 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
203 /* Register the compiled in ciphers. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
204 * This should be run before using any of the ciphers/hashes */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
205 void crypto_init() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
206 |
194
e972be139cb5
Switching to libtomcrypt 1.02
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
207 const struct ltc_cipher_descriptor *regciphers[] = { |
502 | 208 #ifdef DROPBEAR_AES |
150
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
74
diff
changeset
|
209 &aes_desc, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 #endif |
502 | 211 #ifdef DROPBEAR_BLOWFISH |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 &blowfish_desc, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
213 #endif |
502 | 214 #ifdef DROPBEAR_TWOFISH |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
215 &twofish_desc, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
216 #endif |
502 | 217 #ifdef DROPBEAR_3DES |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
218 &des3_desc, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
219 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
220 NULL |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
221 }; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 |
194
e972be139cb5
Switching to libtomcrypt 1.02
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
223 const struct ltc_hash_descriptor *reghashes[] = { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
224 /* we need sha1 for hostkey stuff regardless */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 &sha1_desc, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 #ifdef DROPBEAR_MD5_HMAC |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 &md5_desc, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
229 NULL |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
230 }; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
232 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 for (i = 0; regciphers[i] != NULL; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 if (register_cipher(regciphers[i]) == -1) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
235 dropbear_exit("error registering crypto"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
236 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
237 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
239 for (i = 0; reghashes[i] != NULL; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
240 if (register_hash(reghashes[i]) == -1) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
241 dropbear_exit("error registering crypto"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
242 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
244 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
245 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
246 /* algolen specifies the length of algo, algos is our local list to match |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
247 * against. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
248 * Returns DROPBEAR_SUCCESS if we have a match for algo, DROPBEAR_FAILURE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
249 * otherwise */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
250 int have_algo(char* algo, size_t algolen, algo_type algos[]) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
251 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
252 int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
253 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 for (i = 0; algos[i].name != NULL; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
255 if (strlen(algos[i].name) == algolen |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
256 && (strncmp(algos[i].name, algo, algolen) == 0)) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
257 return DROPBEAR_SUCCESS; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
258 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
259 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
261 return DROPBEAR_FAILURE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
262 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
263 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
264 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
265 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
266 /* Output a comma separated list of algorithms to a buffer */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
267 void buf_put_algolist(buffer * buf, algo_type localalgos[]) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
268 |
238
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
269 unsigned int i, len; |
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
270 unsigned int donefirst = 0; |
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
271 buffer *algolist = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
272 |
502 | 273 algolist = buf_new(160); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
274 for (i = 0; localalgos[i].name != NULL; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
275 if (localalgos[i].usable) { |
238
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
276 if (donefirst) |
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
277 buf_putbyte(algolist, ','); |
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
278 donefirst = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
279 len = strlen(localalgos[i].name); |
238
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
280 buf_putbytes(algolist, localalgos[i].name, len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
281 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
282 } |
238
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
283 buf_putstring(buf, algolist->data, algolist->len); |
e923801a7678
use a buffer rather than raw char array for creating
Matt Johnston <matt@ucc.asn.au>
parents:
237
diff
changeset
|
284 buf_free(algolist); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
285 } |