annotate ecdsa.c @ 766:d1575fdc29a6 ecc

start on ecdsa keys
author Matt Johnston <matt@ucc.asn.au>
date Tue, 09 Apr 2013 00:36:04 +0800
parents
children e465ed10c51d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
766
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include "includes.h"
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #include "dbutil.h"
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 #include "crypto_desc.h"
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 #ifdef DROPBEAR_ECDSA
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 ecc_key *gen_ecdsa_priv_key(unsigned int bit_size) {
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 const ltc_ecc_set_type *dp = NULL; // curve domain parameters
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 // TODO: use raw bytes for the dp rather than the hex strings in libtomcrypt's ecc.c
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 switch (bit_size) {
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 #ifdef DROPBEAR_ECC_256
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 case 256:
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 dp = &ltc_ecc_sets[0];
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 break;
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 #endif
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 #ifdef DROPBEAR_ECC_384
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 case 384:
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 dp = &ltc_ecc_sets[0];
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 break;
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 #endif
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 #ifdef DROPBEAR_ECC_521
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 case 521:
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 dp = &ltc_ecc_sets[0];
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 break;
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #endif
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 }
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 if (!dp) {
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 dropbear_exit("Key size %d isn't valid. Try "
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #ifdef DROPBEAR_ECC_256
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 "256 "
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 #endif
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 #ifdef DROPBEAR_ECC_384
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 "384 "
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 #endif
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 #ifdef DROPBEAR_ECC_521
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 "521 "
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 #endif
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 , bit_size);
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 }
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 ecc_key *new_key = m_malloc(sizeof(*new_key));
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 if (ecc_make_key_ex(NULL, dropbear_ltc_prng, new_key, dp) != CRYPT_OK) {
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 dropbear_exit("ECC error");
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 }
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 return new_key;
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 }
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 int buf_get_ecdsa_pub_key(buffer* buf, ecc_key *key) {
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 }
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 #endif // DROPBEAR_ECDSA