comparison ecdsa.c @ 1295:750ec4ec4cbe

Convert #ifdef to #if, other build changes
author Matt Johnston <matt@ucc.asn.au>
date Wed, 04 May 2016 15:33:40 +0200
parents 2bb4c662d1c2
children 06d52bcb8094
comparison
equal deleted inserted replaced
1294:56aba7dedbea 1295:750ec4ec4cbe
4 #include "crypto_desc.h" 4 #include "crypto_desc.h"
5 #include "ecc.h" 5 #include "ecc.h"
6 #include "ecdsa.h" 6 #include "ecdsa.h"
7 #include "signkey.h" 7 #include "signkey.h"
8 8
9 #ifdef DROPBEAR_ECDSA 9 #if DROPBEAR_ECDSA
10 10
11 int signkey_is_ecdsa(enum signkey_type type) 11 int signkey_is_ecdsa(enum signkey_type type)
12 { 12 {
13 return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256 13 return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
14 || type == DROPBEAR_SIGNKEY_ECDSA_NISTP384 14 || type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
15 || type == DROPBEAR_SIGNKEY_ECDSA_NISTP521; 15 || type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
16 } 16 }
17 17
18 enum signkey_type ecdsa_signkey_type(ecc_key * key) { 18 enum signkey_type ecdsa_signkey_type(ecc_key * key) {
19 #ifdef DROPBEAR_ECC_256 19 #if DROPBEAR_ECC_256
20 if (key->dp == ecc_curve_nistp256.dp) { 20 if (key->dp == ecc_curve_nistp256.dp) {
21 return DROPBEAR_SIGNKEY_ECDSA_NISTP256; 21 return DROPBEAR_SIGNKEY_ECDSA_NISTP256;
22 } 22 }
23 #endif 23 #endif
24 #ifdef DROPBEAR_ECC_384 24 #if DROPBEAR_ECC_384
25 if (key->dp == ecc_curve_nistp384.dp) { 25 if (key->dp == ecc_curve_nistp384.dp) {
26 return DROPBEAR_SIGNKEY_ECDSA_NISTP384; 26 return DROPBEAR_SIGNKEY_ECDSA_NISTP384;
27 } 27 }
28 #endif 28 #endif
29 #ifdef DROPBEAR_ECC_521 29 #if DROPBEAR_ECC_521
30 if (key->dp == ecc_curve_nistp521.dp) { 30 if (key->dp == ecc_curve_nistp521.dp) {
31 return DROPBEAR_SIGNKEY_ECDSA_NISTP521; 31 return DROPBEAR_SIGNKEY_ECDSA_NISTP521;
32 } 32 }
33 #endif 33 #endif
34 return DROPBEAR_SIGNKEY_NONE; 34 return DROPBEAR_SIGNKEY_NONE;
36 36
37 ecc_key *gen_ecdsa_priv_key(unsigned int bit_size) { 37 ecc_key *gen_ecdsa_priv_key(unsigned int bit_size) {
38 const ltc_ecc_set_type *dp = NULL; /* curve domain parameters */ 38 const ltc_ecc_set_type *dp = NULL; /* curve domain parameters */
39 ecc_key *new_key = NULL; 39 ecc_key *new_key = NULL;
40 switch (bit_size) { 40 switch (bit_size) {
41 #ifdef DROPBEAR_ECC_256 41 #if DROPBEAR_ECC_256
42 case 256: 42 case 256:
43 dp = ecc_curve_nistp256.dp; 43 dp = ecc_curve_nistp256.dp;
44 break; 44 break;
45 #endif 45 #endif
46 #ifdef DROPBEAR_ECC_384 46 #if DROPBEAR_ECC_384
47 case 384: 47 case 384:
48 dp = ecc_curve_nistp384.dp; 48 dp = ecc_curve_nistp384.dp;
49 break; 49 break;
50 #endif 50 #endif
51 #ifdef DROPBEAR_ECC_521 51 #if DROPBEAR_ECC_521
52 case 521: 52 case 521:
53 dp = ecc_curve_nistp521.dp; 53 dp = ecc_curve_nistp521.dp;
54 break; 54 break;
55 #endif 55 #endif
56 } 56 }
57 if (!dp) { 57 if (!dp) {
58 dropbear_exit("Key size %d isn't valid. Try " 58 dropbear_exit("Key size %d isn't valid. Try "
59 #ifdef DROPBEAR_ECC_256 59 #if DROPBEAR_ECC_256
60 "256 " 60 "256 "
61 #endif 61 #endif
62 #ifdef DROPBEAR_ECC_384 62 #if DROPBEAR_ECC_384
63 "384 " 63 "384 "
64 #endif 64 #endif
65 #ifdef DROPBEAR_ECC_521 65 #if DROPBEAR_ECC_521
66 "521 " 66 "521 "
67 #endif 67 #endif
68 , bit_size); 68 , bit_size);
69 } 69 }
70 70