Mercurial > dropbear
comparison common-algo.c @ 297:79bf1023cf11 agent-client
propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712)
to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 21 Mar 2006 16:20:59 +0000 |
parents | 89ace56293f6 |
children | 64abb124763d 0e69e948caba |
comparison
equal
deleted
inserted
replaced
225:ca7e76d981d9 | 297:79bf1023cf11 |
---|---|
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 /* Mappings for ciphers, parameters are | 32 /* Mappings for ciphers, parameters are |
33 {&cipher_desc, keysize, blocksize} */ | 33 {&cipher_desc, keysize, blocksize} */ |
34 | 34 |
35 #ifdef DROPBEAR_AES256_CBC | |
36 static const struct dropbear_cipher dropbear_aes256 = | |
37 {&aes_desc, 32, 16}; | |
38 #endif | |
35 #ifdef DROPBEAR_AES128_CBC | 39 #ifdef DROPBEAR_AES128_CBC |
36 const struct dropbear_cipher dropbear_aes128 = | 40 static const struct dropbear_cipher dropbear_aes128 = |
37 {&aes_desc, 16, 16}; | 41 {&aes_desc, 16, 16}; |
38 #endif | 42 #endif |
39 #ifdef DROPBEAR_BLOWFISH_CBC | 43 #ifdef DROPBEAR_BLOWFISH_CBC |
40 const struct dropbear_cipher dropbear_blowfish = | 44 static const struct dropbear_cipher dropbear_blowfish = |
41 {&blowfish_desc, 16, 8}; | 45 {&blowfish_desc, 16, 8}; |
42 #endif | 46 #endif |
47 #ifdef DROPBEAR_TWOFISH256_CBC | |
48 static const struct dropbear_cipher dropbear_twofish256 = | |
49 {&twofish_desc, 32, 16}; | |
50 #endif | |
43 #ifdef DROPBEAR_TWOFISH128_CBC | 51 #ifdef DROPBEAR_TWOFISH128_CBC |
44 const struct dropbear_cipher dropbear_twofish128 = | 52 static const struct dropbear_cipher dropbear_twofish128 = |
45 {&twofish_desc, 16, 16}; | 53 {&twofish_desc, 16, 16}; |
46 #endif | 54 #endif |
47 #ifdef DROPBEAR_3DES_CBC | 55 #ifdef DROPBEAR_3DES_CBC |
48 const struct dropbear_cipher dropbear_3des = | 56 static const struct dropbear_cipher dropbear_3des = |
49 {&des3_desc, 24, 8}; | 57 {&des3_desc, 24, 8}; |
50 #endif | 58 #endif |
51 | 59 |
52 /* used to indicate no encryption, as defined in rfc2410 */ | 60 /* used to indicate no encryption, as defined in rfc2410 */ |
53 const struct dropbear_cipher dropbear_nocipher = | 61 const struct dropbear_cipher dropbear_nocipher = |
55 | 63 |
56 /* Mapping of ssh hashes to libtomcrypt hashes, including keysize etc. | 64 /* Mapping of ssh hashes to libtomcrypt hashes, including keysize etc. |
57 {&hash_desc, keysize, hashsize} */ | 65 {&hash_desc, keysize, hashsize} */ |
58 | 66 |
59 #ifdef DROPBEAR_SHA1_HMAC | 67 #ifdef DROPBEAR_SHA1_HMAC |
60 const struct dropbear_hash dropbear_sha1 = | 68 static const struct dropbear_hash dropbear_sha1 = |
61 {&sha1_desc, 20, 20}; | 69 {&sha1_desc, 20, 20}; |
62 #endif | 70 #endif |
71 #ifdef DROPBEAR_SHA1_96_HMAC | |
72 static const struct dropbear_hash dropbear_sha1_96 = | |
73 {&sha1_desc, 20, 12}; | |
74 #endif | |
63 #ifdef DROPBEAR_MD5_HMAC | 75 #ifdef DROPBEAR_MD5_HMAC |
64 const struct dropbear_hash dropbear_md5 = | 76 static const struct dropbear_hash dropbear_md5 = |
65 {&md5_desc, 16, 16}; | 77 {&md5_desc, 16, 16}; |
66 #endif | 78 #endif |
67 | 79 |
68 const struct dropbear_hash dropbear_nohash = | 80 const struct dropbear_hash dropbear_nohash = |
69 {NULL, 16, 0}; /* used initially */ | 81 {NULL, 16, 0}; /* used initially */ |
73 | 85 |
74 algo_type sshciphers[] = { | 86 algo_type sshciphers[] = { |
75 #ifdef DROPBEAR_AES128_CBC | 87 #ifdef DROPBEAR_AES128_CBC |
76 {"aes128-cbc", 0, (void*)&dropbear_aes128, 1}, | 88 {"aes128-cbc", 0, (void*)&dropbear_aes128, 1}, |
77 #endif | 89 #endif |
90 #ifdef DROPBEAR_3DES_CBC | |
91 {"3des-cbc", 0, (void*)&dropbear_3des, 1}, | |
92 #endif | |
93 #ifdef DROPBEAR_AES256_CBC | |
94 {"aes256-cbc", 0, (void*)&dropbear_aes256, 1}, | |
95 #endif | |
96 #ifdef DROPBEAR_TWOFISH256_CBC | |
97 {"twofish256-cbc", 0, (void*)&dropbear_twofish256, 1}, | |
98 {"twofish-cbc", 0, (void*)&dropbear_twofish256, 1}, | |
99 #endif | |
100 #ifdef DROPBEAR_TWOFISH128_CBC | |
101 {"twofish128-cbc", 0, (void*)&dropbear_twofish128, 1}, | |
102 #endif | |
78 #ifdef DROPBEAR_BLOWFISH_CBC | 103 #ifdef DROPBEAR_BLOWFISH_CBC |
79 {"blowfish-cbc", 0, (void*)&dropbear_blowfish, 1}, | 104 {"blowfish-cbc", 0, (void*)&dropbear_blowfish, 1}, |
80 #endif | 105 #endif |
81 #ifdef DROPBEAR_TWOFISH128_CBC | |
82 {"twofish-cbc", 0, (void*)&dropbear_twofish128, 1}, | |
83 #endif | |
84 #ifdef DROPBEAR_3DES_CBC | |
85 {"3des-cbc", 0, (void*)&dropbear_3des, 1}, | |
86 #endif | |
87 {NULL, 0, NULL, 0} | 106 {NULL, 0, NULL, 0} |
88 }; | 107 }; |
89 | 108 |
90 algo_type sshhashes[] = { | 109 algo_type sshhashes[] = { |
110 #ifdef DROPBEAR_SHA1_96_HMAC | |
111 {"hmac-sha1-96", 0, (void*)&dropbear_sha1_96, 1}, | |
112 #endif | |
91 #ifdef DROPBEAR_SHA1_HMAC | 113 #ifdef DROPBEAR_SHA1_HMAC |
92 {"hmac-sha1", 0, (void*)&dropbear_sha1, 1}, | 114 {"hmac-sha1", 0, (void*)&dropbear_sha1, 1}, |
93 #endif | 115 #endif |
94 #ifdef DROPBEAR_MD5_HMAC | 116 #ifdef DROPBEAR_MD5_HMAC |
95 {"hmac-md5", 0, (void*)&dropbear_md5, 1}, | 117 {"hmac-md5", 0, (void*)&dropbear_md5, 1}, |
96 #endif | 118 #endif |
97 {NULL, 0, NULL, 0} | 119 {NULL, 0, NULL, 0} |
98 }; | 120 }; |
99 | 121 |
100 algo_type sshcompress[] = { | 122 algo_type sshcompress[] = { |
101 {"none", DROPBEAR_COMP_NONE, NULL, 1}, | |
102 #ifndef DISABLE_ZLIB | 123 #ifndef DISABLE_ZLIB |
103 {"zlib", DROPBEAR_COMP_ZLIB, NULL, 1}, | 124 {"zlib", DROPBEAR_COMP_ZLIB, NULL, 1}, |
104 #endif | 125 #endif |
126 {"none", DROPBEAR_COMP_NONE, NULL, 1}, | |
105 {NULL, 0, NULL, 0} | 127 {NULL, 0, NULL, 0} |
106 }; | 128 }; |
107 | 129 |
108 algo_type sshhostkey[] = { | 130 algo_type sshhostkey[] = { |
109 #ifdef DROPBEAR_RSA | 131 #ifdef DROPBEAR_RSA |
124 /* Register the compiled in ciphers. | 146 /* Register the compiled in ciphers. |
125 * This should be run before using any of the ciphers/hashes */ | 147 * This should be run before using any of the ciphers/hashes */ |
126 void crypto_init() { | 148 void crypto_init() { |
127 | 149 |
128 const struct ltc_cipher_descriptor *regciphers[] = { | 150 const struct ltc_cipher_descriptor *regciphers[] = { |
129 #ifdef DROPBEAR_AES128_CBC | 151 #ifdef DROPBEAR_AES_CBC |
130 &aes_desc, | 152 &aes_desc, |
131 #endif | 153 #endif |
132 #ifdef DROPBEAR_BLOWFISH_CBC | 154 #ifdef DROPBEAR_BLOWFISH_CBC |
133 &blowfish_desc, | 155 &blowfish_desc, |
134 #endif | 156 #endif |
135 #ifdef DROPBEAR_TWOFISH128_CBC | 157 #ifdef DROPBEAR_TWOFISH_CBC |
136 &twofish_desc, | 158 &twofish_desc, |
137 #endif | 159 #endif |
138 #ifdef DROPBEAR_3DES_CBC | 160 #ifdef DROPBEAR_3DES_CBC |
139 &des3_desc, | 161 &des3_desc, |
140 #endif | 162 #endif |
185 | 207 |
186 | 208 |
187 /* Output a comma separated list of algorithms to a buffer */ | 209 /* Output a comma separated list of algorithms to a buffer */ |
188 void buf_put_algolist(buffer * buf, algo_type localalgos[]) { | 210 void buf_put_algolist(buffer * buf, algo_type localalgos[]) { |
189 | 211 |
190 unsigned int pos = 0, i, len; | 212 unsigned int i, len; |
191 char str[50]; /* enough for local algo storage */ | 213 unsigned int donefirst = 0; |
192 | 214 buffer *algolist = NULL; |
215 | |
216 algolist = buf_new(100); | |
193 for (i = 0; localalgos[i].name != NULL; i++) { | 217 for (i = 0; localalgos[i].name != NULL; i++) { |
194 if (localalgos[i].usable) { | 218 if (localalgos[i].usable) { |
195 /* Avoid generating a trailing comma */ | 219 if (donefirst) |
196 if (pos) | 220 buf_putbyte(algolist, ','); |
197 str[pos++] = ','; | 221 donefirst = 1; |
198 len = strlen(localalgos[i].name); | 222 len = strlen(localalgos[i].name); |
199 memcpy(&str[pos], localalgos[i].name, len); | 223 buf_putbytes(algolist, localalgos[i].name, len); |
200 pos += len; | 224 } |
201 } | 225 } |
202 } | 226 buf_putstring(buf, algolist->data, algolist->len); |
203 str[pos]=0; | 227 buf_free(algolist); |
204 /* Debug this */ | |
205 TRACE(("buf_put_algolist: %s", str)) | |
206 buf_putstring(buf, str, pos); | |
207 } | 228 } |