ecc_dp_fill_from_sets fix
Karel Miko
6 years ago
11 | 11 | |
12 | 12 | #ifdef LTC_MECC |
13 | 13 | |
14 | static int hexstrcmp(const char *hexa, const char *hexb) | |
15 | { | |
16 | #define MY_TOLOWER(a) ((((a)>='A')&&((a)<='Z')) ? ((a)|0x60) : (a)) | |
17 | /* ignore leading zeroes */ | |
18 | while(*hexa == '0') hexa++; | |
19 | while(*hexb == '0') hexb++; | |
20 | /* compare: case insensitive, hexadecimal chars only */ | |
21 | while (*hexa && *hexb) { | |
22 | if ( (*hexa < '0' || *hexa > '9') && | |
23 | (*hexa < 'a' || *hexa > 'f') && | |
24 | (*hexa < 'A' || *hexa > 'F') ) return 1; | |
25 | if ( (*hexb < '0' || *hexb > '9') && | |
26 | (*hexb < 'a' || *hexb > 'f') && | |
27 | (*hexb < 'A' || *hexb > 'F') ) return 1; | |
28 | if (MY_TOLOWER(*hexa) != MY_TOLOWER(*hexb)) return 1; | |
29 | hexa++; | |
30 | hexb++; | |
31 | } | |
32 | if (*hexa == '\0' && *hexb == '\0') return 0; /* success - match */ | |
33 | return 1; | |
34 | } | |
35 | ||
14 | 36 | /* search known curve by curve parameters and fill in missing parameters into dp |
15 | 37 | * we assume every parameter has the same case (usually uppercase) and no leading zeros |
16 | 38 | */ |
24 | 46 | if (!dp->prime || !dp->A || !dp->B || !dp->order || !dp->Gx || !dp->Gy || dp->cofactor == 0) return CRYPT_INVALID_ARG; |
25 | 47 | |
26 | 48 | for (x = 0; ltc_ecc_sets[x].size != 0; x++) { |
27 | if (XSTRCMP(ltc_ecc_sets[x].prime, dp->prime) == 0 && | |
28 | XSTRCMP(ltc_ecc_sets[x].A, dp->A) == 0 && | |
29 | XSTRCMP(ltc_ecc_sets[x].B, dp->B) == 0 && | |
30 | XSTRCMP(ltc_ecc_sets[x].order, dp->order) == 0 && | |
31 | XSTRCMP(ltc_ecc_sets[x].Gx, dp->Gx) == 0 && | |
32 | XSTRCMP(ltc_ecc_sets[x].Gy, dp->Gy) == 0 && | |
49 | if (hexstrcmp(ltc_ecc_sets[x].prime, dp->prime) == 0 && | |
50 | hexstrcmp(ltc_ecc_sets[x].A, dp->A) == 0 && | |
51 | hexstrcmp(ltc_ecc_sets[x].B, dp->B) == 0 && | |
52 | hexstrcmp(ltc_ecc_sets[x].order, dp->order) == 0 && | |
53 | hexstrcmp(ltc_ecc_sets[x].Gx, dp->Gx) == 0 && | |
54 | hexstrcmp(ltc_ecc_sets[x].Gy, dp->Gy) == 0 && | |
33 | 55 | ltc_ecc_sets[x].cofactor == dp->cofactor) { |
34 | 56 | |
35 | 57 | params = ltc_ecc_sets[x]; |