comparison common-algo.c @ 761:ac2158e3e403 ecc

ecc kind of works, needs fixing/testing
author Matt Johnston <matt@ucc.asn.au>
date Sun, 07 Apr 2013 01:36:42 +0800
parents 76fba0856749
children a78a38e402d1
comparison
equal deleted inserted replaced
760:f336d232fc63 761:ac2158e3e403
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE. */ 24 * SOFTWARE. */
25 25
26 #include "includes.h"
26 #include "algo.h" 27 #include "algo.h"
27 #include "dbutil.h" 28 #include "dbutil.h"
28 #include "kex.h" 29 #include "kex.h"
30 #include "ltc_prng.h"
31 #include "ecc.h"
29 32
30 /* This file (algo.c) organises the ciphers which can be used, and is used to 33 /* This file (algo.c) organises the ciphers which can be used, and is used to
31 * decide which ciphers/hashes/compression/signing to use during key exchange*/ 34 * decide which ciphers/hashes/compression/signing to use during key exchange*/
32 35
36 #ifdef DROPBEAR_LTC_PRNG
37 int dropbear_ltc_prng = -1;
38 #endif
39
40
41
33 static int void_cipher(const unsigned char* in, unsigned char* out, 42 static int void_cipher(const unsigned char* in, unsigned char* out,
34 unsigned long len, void *cipher_state) { 43 unsigned long len, void* UNUSED(cipher_state)) {
35 if (in != out) { 44 if (in != out) {
36 memmove(out, in, len); 45 memmove(out, in, len);
37 } 46 }
38 return CRYPT_OK; 47 return CRYPT_OK;
39 } 48 }
40 49
41 static int void_start(int cipher, const unsigned char *IV, 50 static int void_start(int UNUSED(cipher), const unsigned char* UNUSED(IV),
42 const unsigned char *key, 51 const unsigned char* UNUSED(key),
43 int keylen, int num_rounds, void *cipher_state) { 52 int UNUSED(keylen), int UNUSED(num_rounds), void* UNUSED(cipher_state)) {
44 return CRYPT_OK; 53 return CRYPT_OK;
45 } 54 }
46 55
47 /* Mappings for ciphers, parameters are 56 /* Mappings for ciphers, parameters are
48 {&cipher_desc, keysize, blocksize} */ 57 {&cipher_desc, keysize, blocksize} */
214 }; 223 };
215 224
216 static struct dropbear_kex kex_dh_group1 = {dh_p_1, DH_P_1_LEN, NULL, &sha1_desc }; 225 static struct dropbear_kex kex_dh_group1 = {dh_p_1, DH_P_1_LEN, NULL, &sha1_desc };
217 static struct dropbear_kex kex_dh_group14 = {dh_p_14, DH_P_14_LEN, NULL, &sha1_desc }; 226 static struct dropbear_kex kex_dh_group14 = {dh_p_14, DH_P_14_LEN, NULL, &sha1_desc };
218 227
219 #ifdef DROPBEAR_ECC_DH 228 #ifdef DROPBEAR_ECDH
220 #ifdef DROPBEAR_ECC_256 229 #ifdef DROPBEAR_ECC_256
221 static struct dropbear_kex kex_ecdh_secp256r1 = {NULL, 0, &ecc_curve_secp256r1, &sha256_desc }; 230 static struct dropbear_kex kex_ecdh_secp256r1 = {NULL, 0, &ecc_curve_secp256r1, &sha256_desc };
222 #endif 231 #endif
223 #ifdef DROPBEAR_ECC_384 232 #ifdef DROPBEAR_ECC_384
224 static struct dropbear_kex kex_ecdh_secp384r1 = {NULL, 0, &ecc_curve_secp384r1, &sha384_desc }; 233 static struct dropbear_kex kex_ecdh_secp384r1 = {NULL, 0, &ecc_curve_secp384r1, &sha384_desc };
225 #endif 234 #endif
226 #ifdef DROPBEAR_ECC_521 235 #ifdef DROPBEAR_ECC_521
227 static struct dropbear_kex kex_ecdh_secp521r1 = {NULL, 0, &ecc_curve_secp521r1, &sha512_desc }; 236 static struct dropbear_kex kex_ecdh_secp521r1 = {NULL, 0, &ecc_curve_secp521r1, &sha512_desc };
228 #endif 237 #endif
229 #endif // DROPBEAR_ECC_DH 238 #endif // DROPBEAR_ECDH
230 239
231 240
232 algo_type sshkex[] = { 241 algo_type sshkex[] = {
233 #ifdef DROPBEAR_ECC_DH 242 #ifdef DROPBEAR_ECDH
234 #ifdef DROPBEAR_ECC_256 243 #ifdef DROPBEAR_ECC_256
235 {"ecdh-sha2-secp256r1", 0, &kex_ecdh_descp256r1, 1, NULL}, 244 {"ecdh-sha2-secp256r1", 0, &kex_ecdh_secp256r1, 1, NULL},
236 #endif 245 #endif
237 #ifdef DROPBEAR_ECC_384 246 #ifdef DROPBEAR_ECC_384
238 {"ecdh-sha2-secp384r1", 0, &kex_ecdh_descp384r1, 1, NULL}, 247 {"ecdh-sha2-secp384r1", 0, &kex_ecdh_secp384r1, 1, NULL},
239 #endif 248 #endif
240 #ifdef DROPBEAR_ECC_521 249 #ifdef DROPBEAR_ECC_521
241 {"ecdh-sha2-secp521r1", 0, &kex_ecdh_descp521r1, 1, NULL}, 250 {"ecdh-sha2-secp521r1", 0, &kex_ecdh_secp521r1, 1, NULL},
242 #endif 251 #endif
243 #endif 252 #endif
244 {"diffie-hellman-group1-sha1", 0, &kex_dh_group1, 1, NULL}, 253 {"diffie-hellman-group1-sha1", 0, &kex_dh_group1, 1, NULL},
245 {"diffie-hellman-group14-sha1", 0, &kex_dh_group14, 1, NULL}, 254 {"diffie-hellman-group14-sha1", 0, &kex_dh_group14, 1, NULL},
246 {NULL, 0, NULL, 0, NULL} 255 {NULL, 0, NULL, 0, NULL}
295 for (i = 0; reghashes[i] != NULL; i++) { 304 for (i = 0; reghashes[i] != NULL; i++) {
296 if (register_hash(reghashes[i]) == -1) { 305 if (register_hash(reghashes[i]) == -1) {
297 dropbear_exit("Error registering crypto"); 306 dropbear_exit("Error registering crypto");
298 } 307 }
299 } 308 }
309
310 #ifdef DROPBEAR_LTC_PRNG
311 dropbear_ltc_prng = register_prng(&dropbear_prng_desc);
312 if (dropbear_ltc_prng == -1) {
313 dropbear_exit("Error registering crypto");
314 }
315 #endif
316
317 #ifdef DROPBEAR_ECC
318 ltc_mp = ltm_desc;
319 #endif
300 } 320 }
301 321
302 /* algolen specifies the length of algo, algos is our local list to match 322 /* algolen specifies the length of algo, algos is our local list to match
303 * against. 323 * against.
304 * Returns DROPBEAR_SUCCESS if we have a match for algo, DROPBEAR_FAILURE 324 * Returns DROPBEAR_SUCCESS if we have a match for algo, DROPBEAR_FAILURE