comparison common-algo.c @ 511:582cb38e4eb5 insecure-nocrypto

propagate from branch 'au.asn.ucc.matt.dropbear' (head cdcc3c729e29544e8b98a408e2dc60e4483dfd2a) to branch 'au.asn.ucc.matt.dropbear.insecure-nocrypto' (head 0ca38a1cf349f7426ac9de34ebe4c3e3735effab)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 06 Nov 2008 13:16:55 +0000
parents 64abb124763d 0cdbc95bb3d2
children 0129fd8ccc71
comparison
equal deleted inserted replaced
361:461c4b1fb35f 511:582cb38e4eb5
27 #include "dbutil.h" 27 #include "dbutil.h"
28 28
29 /* This file (algo.c) organises the ciphers which can be used, and is used to 29 /* This file (algo.c) organises the ciphers which can be used, and is used to
30 * decide which ciphers/hashes/compression/signing to use during key exchange*/ 30 * decide which ciphers/hashes/compression/signing to use during key exchange*/
31 31
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
32 /* Mappings for ciphers, parameters are 44 /* Mappings for ciphers, parameters are
33 {&cipher_desc, keysize, blocksize} */ 45 {&cipher_desc, keysize, blocksize} */
34 46 /* NOTE: if keysize > 2*SHA1_HASH_SIZE, code such as hashkeys()
35 #ifdef DROPBEAR_AES256_CBC 47 needs revisiting */
48
49 #ifdef DROPBEAR_AES256
36 static const struct dropbear_cipher dropbear_aes256 = 50 static const struct dropbear_cipher dropbear_aes256 =
37 {&aes_desc, 32, 16}; 51 {&aes_desc, 32, 16};
38 #endif 52 #endif
39 #ifdef DROPBEAR_AES128_CBC 53 #ifdef DROPBEAR_AES128
40 static const struct dropbear_cipher dropbear_aes128 = 54 static const struct dropbear_cipher dropbear_aes128 =
41 {&aes_desc, 16, 16}; 55 {&aes_desc, 16, 16};
42 #endif 56 #endif
43 #ifdef DROPBEAR_BLOWFISH_CBC 57 #ifdef DROPBEAR_BLOWFISH
44 static const struct dropbear_cipher dropbear_blowfish = 58 static const struct dropbear_cipher dropbear_blowfish =
45 {&blowfish_desc, 16, 8}; 59 {&blowfish_desc, 16, 8};
46 #endif 60 #endif
47 #ifdef DROPBEAR_TWOFISH256_CBC 61 #ifdef DROPBEAR_TWOFISH256
48 static const struct dropbear_cipher dropbear_twofish256 = 62 static const struct dropbear_cipher dropbear_twofish256 =
49 {&twofish_desc, 32, 16}; 63 {&twofish_desc, 32, 16};
50 #endif 64 #endif
51 #ifdef DROPBEAR_TWOFISH128_CBC 65 #ifdef DROPBEAR_TWOFISH128
52 static const struct dropbear_cipher dropbear_twofish128 = 66 static const struct dropbear_cipher dropbear_twofish128 =
53 {&twofish_desc, 16, 16}; 67 {&twofish_desc, 16, 16};
54 #endif 68 #endif
55 #ifdef DROPBEAR_3DES_CBC 69 #ifdef DROPBEAR_3DES
56 static const struct dropbear_cipher dropbear_3des = 70 static const struct dropbear_cipher dropbear_3des =
57 {&des3_desc, 24, 8}; 71 {&des3_desc, 24, 8};
58 #endif 72 #endif
59 73
60 /* used to indicate no encryption, as defined in rfc2410 */ 74 /* used to indicate no encryption, as defined in rfc2410 */
61 const struct dropbear_cipher dropbear_nocipher = 75 const struct dropbear_cipher dropbear_nocipher =
62 {NULL, 16, 8}; 76 {NULL, 16, 8};
63 77
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
64 /* Mapping of ssh hashes to libtomcrypt hashes, including keysize etc. 96 /* Mapping of ssh hashes to libtomcrypt hashes, including keysize etc.
65 {&hash_desc, keysize, hashsize} */ 97 {&hash_desc, keysize, hashsize} */
66 98
67 #ifdef DROPBEAR_SHA1_HMAC 99 #ifdef DROPBEAR_SHA1_HMAC
68 static const struct dropbear_hash dropbear_sha1 = 100 static const struct dropbear_hash dropbear_sha1 =
79 111
80 const struct dropbear_hash dropbear_nohash = 112 const struct dropbear_hash dropbear_nohash =
81 {NULL, 16, 0}; /* used initially */ 113 {NULL, 16, 0}; /* used initially */
82 114
83 115
84 /* The following map ssh names to internal values */ 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. */
85 119
86 algo_type sshciphers[] = { 120 algo_type sshciphers[] = {
87 #ifdef DROPBEAR_AES128_CBC 121 #ifdef DROPBEAR_ENABLE_CTR_MODE
88 {"aes128-cbc", 0, (void*)&dropbear_aes128, 1}, 122 #ifdef DROPBEAR_AES128
89 #endif 123 {"aes128-ctr", 0, &dropbear_aes128, 1, &dropbear_mode_ctr},
90 #ifdef DROPBEAR_3DES_CBC 124 #endif
91 {"3des-cbc", 0, (void*)&dropbear_3des, 1}, 125 #ifdef DROPBEAR_3DES
92 #endif 126 {"3des-ctr", 0, &dropbear_3des, 1, &dropbear_mode_ctr},
93 #ifdef DROPBEAR_AES256_CBC 127 #endif
94 {"aes256-cbc", 0, (void*)&dropbear_aes256, 1}, 128 #ifdef DROPBEAR_AES256
95 #endif 129 {"aes256-ctr", 0, &dropbear_aes256, 1, &dropbear_mode_ctr},
96 #ifdef DROPBEAR_TWOFISH256_CBC 130 #endif
97 {"twofish256-cbc", 0, (void*)&dropbear_twofish256, 1}, 131 #endif /* DROPBEAR_ENABLE_CTR_MODE */
98 {"twofish-cbc", 0, (void*)&dropbear_twofish256, 1}, 132
99 #endif 133 /* CBC modes are always enabled */
100 #ifdef DROPBEAR_TWOFISH128_CBC 134 #ifdef DROPBEAR_AES128
101 {"twofish128-cbc", 0, (void*)&dropbear_twofish128, 1}, 135 {"aes128-cbc", 0, &dropbear_aes128, 1, &dropbear_mode_cbc},
102 #endif 136 #endif
103 #ifdef DROPBEAR_BLOWFISH_CBC 137 #ifdef DROPBEAR_3DES
104 {"blowfish-cbc", 0, (void*)&dropbear_blowfish, 1}, 138 {"3des-cbc", 0, &dropbear_3des, 1, &dropbear_mode_cbc},
139 #endif
140 #ifdef DROPBEAR_AES256
141 {"aes256-cbc", 0, &dropbear_aes256, 1, &dropbear_mode_cbc},
142 #endif
143 #ifdef DROPBEAR_TWOFISH256
144 {"twofish256-cbc", 0, &dropbear_twofish256, 1, &dropbear_mode_cbc},
145 {"twofish-cbc", 0, &dropbear_twofish256, 1, &dropbear_mode_cbc},
146 #endif
147 #ifdef DROPBEAR_TWOFISH128
148 {"twofish128-cbc", 0, &dropbear_twofish128, 1, &dropbear_mode_cbc},
149 #endif
150 #ifdef DROPBEAR_BLOWFISH
151 {"blowfish-cbc", 0, &dropbear_blowfish, 1, &dropbear_mode_cbc},
105 #endif 152 #endif
106 #ifdef DROPBEAR_NONE_CIPHER 153 #ifdef DROPBEAR_NONE_CIPHER
107 {"none", 0, (void*)&dropbear_nocipher, 1}, 154 {"none", 0, (void*)&dropbear_nocipher, 1},
108 #endif 155 #endif
109 {NULL, 0, NULL, 0} 156 {NULL, 0, NULL, 0}
110 }; 157 };
111 158
112 algo_type sshhashes[] = { 159 algo_type sshhashes[] = {
113 #ifdef DROPBEAR_SHA1_96_HMAC 160 #ifdef DROPBEAR_SHA1_96_HMAC
114 {"hmac-sha1-96", 0, (void*)&dropbear_sha1_96, 1}, 161 {"hmac-sha1-96", 0, &dropbear_sha1_96, 1, NULL},
115 #endif 162 #endif
116 #ifdef DROPBEAR_SHA1_HMAC 163 #ifdef DROPBEAR_SHA1_HMAC
117 {"hmac-sha1", 0, (void*)&dropbear_sha1, 1}, 164 {"hmac-sha1", 0, &dropbear_sha1, 1, NULL},
118 #endif 165 #endif
119 #ifdef DROPBEAR_MD5_HMAC 166 #ifdef DROPBEAR_MD5_HMAC
120 {"hmac-md5", 0, (void*)&dropbear_md5, 1}, 167 {"hmac-md5", 0, (void*)&dropbear_md5, 1},
121 #endif 168 #endif
122 #ifdef DROPBEAR_NONE_INTEGRITY 169 #ifdef DROPBEAR_NONE_INTEGRITY
125 {NULL, 0, NULL, 0} 172 {NULL, 0, NULL, 0}
126 }; 173 };
127 174
128 algo_type sshcompress[] = { 175 algo_type sshcompress[] = {
129 #ifndef DISABLE_ZLIB 176 #ifndef DISABLE_ZLIB
130 {"zlib", DROPBEAR_COMP_ZLIB, NULL, 1}, 177 {"zlib", DROPBEAR_COMP_ZLIB, NULL, 1, NULL},
131 #endif 178 {"[email protected]", DROPBEAR_COMP_ZLIB_DELAY, NULL, 1, NULL},
132 {"none", DROPBEAR_COMP_NONE, NULL, 1}, 179 #endif
133 {NULL, 0, NULL, 0} 180 {"none", DROPBEAR_COMP_NONE, NULL, 1, NULL},
181 {NULL, 0, NULL, 0, NULL}
134 }; 182 };
135 183
136 algo_type sshhostkey[] = { 184 algo_type sshhostkey[] = {
137 #ifdef DROPBEAR_RSA 185 #ifdef DROPBEAR_RSA
138 {"ssh-rsa", DROPBEAR_SIGNKEY_RSA, NULL, 1}, 186 {"ssh-rsa", DROPBEAR_SIGNKEY_RSA, NULL, 1, NULL},
139 #endif 187 #endif
140 #ifdef DROPBEAR_DSS 188 #ifdef DROPBEAR_DSS
141 {"ssh-dss", DROPBEAR_SIGNKEY_DSS, NULL, 1}, 189 {"ssh-dss", DROPBEAR_SIGNKEY_DSS, NULL, 1, NULL},
142 #endif 190 #endif
143 {NULL, 0, NULL, 0} 191 {NULL, 0, NULL, 0, NULL}
144 }; 192 };
145 193
146 algo_type sshkex[] = { 194 algo_type sshkex[] = {
147 {"diffie-hellman-group1-sha1", DROPBEAR_KEX_DH_GROUP1, NULL, 1}, 195 {"diffie-hellman-group1-sha1", DROPBEAR_KEX_DH_GROUP1, NULL, 1, NULL},
148 {NULL, 0, NULL, 0} 196 {NULL, 0, NULL, 0, NULL}
149 }; 197 };
150 198
151 199
152 /* Register the compiled in ciphers. 200 /* Register the compiled in ciphers.
153 * This should be run before using any of the ciphers/hashes */ 201 * This should be run before using any of the ciphers/hashes */
154 void crypto_init() { 202 void crypto_init() {
155 203
156 const struct ltc_cipher_descriptor *regciphers[] = { 204 const struct ltc_cipher_descriptor *regciphers[] = {
157 #ifdef DROPBEAR_AES_CBC 205 #ifdef DROPBEAR_AES
158 &aes_desc, 206 &aes_desc,
159 #endif 207 #endif
160 #ifdef DROPBEAR_BLOWFISH_CBC 208 #ifdef DROPBEAR_BLOWFISH
161 &blowfish_desc, 209 &blowfish_desc,
162 #endif 210 #endif
163 #ifdef DROPBEAR_TWOFISH_CBC 211 #ifdef DROPBEAR_TWOFISH
164 &twofish_desc, 212 &twofish_desc,
165 #endif 213 #endif
166 #ifdef DROPBEAR_3DES_CBC 214 #ifdef DROPBEAR_3DES
167 &des3_desc, 215 &des3_desc,
168 #endif 216 #endif
169 NULL 217 NULL
170 }; 218 };
171 219
217 265
218 unsigned int i, len; 266 unsigned int i, len;
219 unsigned int donefirst = 0; 267 unsigned int donefirst = 0;
220 buffer *algolist = NULL; 268 buffer *algolist = NULL;
221 269
222 algolist = buf_new(100); 270 algolist = buf_new(160);
223 for (i = 0; localalgos[i].name != NULL; i++) { 271 for (i = 0; localalgos[i].name != NULL; i++) {
224 if (localalgos[i].usable) { 272 if (localalgos[i].usable) {
225 if (donefirst) 273 if (donefirst)
226 buf_putbyte(algolist, ','); 274 buf_putbyte(algolist, ',');
227 donefirst = 1; 275 donefirst = 1;