Mercurial > dropbear
comparison libtomcrypt/src/pk/ecc/ecc_verify_hash.c @ 1710:1ff2a1034c52
Fix whitespace changes vs upstream libtomcrypt
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 10 Jun 2020 23:01:33 +0800 |
parents | 8305ebe45940 |
children |
comparison
equal
deleted
inserted
replaced
1709:04155ce30759 | 1710:1ff2a1034c52 |
---|---|
12 #if defined(LTC_MECC) && defined(LTC_DER) | 12 #if defined(LTC_MECC) && defined(LTC_DER) |
13 | 13 |
14 /** | 14 /** |
15 @file ecc_verify_hash.c | 15 @file ecc_verify_hash.c |
16 ECC Crypto, Tom St Denis | 16 ECC Crypto, Tom St Denis |
17 */ | 17 */ |
18 | 18 |
19 static int _ecc_verify_hash(const unsigned char *sig, unsigned long siglen, | 19 static int _ecc_verify_hash(const unsigned char *sig, unsigned long siglen, |
20 const unsigned char *hash, unsigned long hashlen, | 20 const unsigned char *hash, unsigned long hashlen, |
21 int *stat, ecc_key *key, int sigformat) | 21 int *stat, ecc_key *key, int sigformat) |
22 { | 22 { |
23 ecc_point *mG, *mQ; | 23 ecc_point *mG, *mQ; |
24 void *r, *s, *v, *w, *u1, *u2, *e, *p, *m; | 24 void *r, *s, *v, *w, *u1, *u2, *e, *p, *m; |
25 void *mp; | 25 void *mp; |
64 if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig, i)) != CRYPT_OK) { goto error; } | 64 if ((err = mp_read_unsigned_bin(r, (unsigned char *)sig, i)) != CRYPT_OK) { goto error; } |
65 if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+i, i)) != CRYPT_OK) { goto error; } | 65 if ((err = mp_read_unsigned_bin(s, (unsigned char *)sig+i, i)) != CRYPT_OK) { goto error; } |
66 } | 66 } |
67 else { | 67 else { |
68 /* ASN.1 format */ | 68 /* ASN.1 format */ |
69 if ((err = der_decode_sequence_multi(sig, siglen, | 69 if ((err = der_decode_sequence_multi(sig, siglen, |
70 LTC_ASN1_INTEGER, 1UL, r, | 70 LTC_ASN1_INTEGER, 1UL, r, |
71 LTC_ASN1_INTEGER, 1UL, s, | 71 LTC_ASN1_INTEGER, 1UL, s, |
72 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { goto error; } | 72 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { goto error; } |
73 } | 73 } |
74 | 74 |
75 /* get the order */ | 75 /* get the order */ |
76 if ((err = mp_read_radix(p, (char *)key->dp->order, 16)) != CRYPT_OK) { goto error; } | 76 if ((err = mp_read_radix(p, (char *)key->dp->order, 16)) != CRYPT_OK) { goto error; } |
123 | 123 |
124 /* compute u1*mG + u2*mQ = mG */ | 124 /* compute u1*mG + u2*mQ = mG */ |
125 if (ltc_mp.ecc_mul2add == NULL) { | 125 if (ltc_mp.ecc_mul2add == NULL) { |
126 if ((err = ltc_mp.ecc_ptmul(u1, mG, mG, m, 0)) != CRYPT_OK) { goto error; } | 126 if ((err = ltc_mp.ecc_ptmul(u1, mG, mG, m, 0)) != CRYPT_OK) { goto error; } |
127 if ((err = ltc_mp.ecc_ptmul(u2, mQ, mQ, m, 0)) != CRYPT_OK) { goto error; } | 127 if ((err = ltc_mp.ecc_ptmul(u2, mQ, mQ, m, 0)) != CRYPT_OK) { goto error; } |
128 | 128 |
129 /* find the montgomery mp */ | 129 /* find the montgomery mp */ |
130 if ((err = mp_montgomery_setup(m, &mp)) != CRYPT_OK) { goto error; } | 130 if ((err = mp_montgomery_setup(m, &mp)) != CRYPT_OK) { goto error; } |
131 | 131 |
132 /* add them */ | 132 /* add them */ |
133 if ((err = ltc_mp.ecc_ptadd(mQ, mG, mG, m, mp)) != CRYPT_OK) { goto error; } | 133 if ((err = ltc_mp.ecc_ptadd(mQ, mG, mG, m, mp)) != CRYPT_OK) { goto error; } |
134 | 134 |
135 /* reduce */ | 135 /* reduce */ |
136 if ((err = ltc_mp.ecc_map(mG, m, mp)) != CRYPT_OK) { goto error; } | 136 if ((err = ltc_mp.ecc_map(mG, m, mp)) != CRYPT_OK) { goto error; } |
137 } else { | 137 } else { |
138 /* use Shamir's trick to compute u1*mG + u2*mQ using half of the doubles */ | 138 /* use Shamir's trick to compute u1*mG + u2*mQ using half of the doubles */ |
139 if ((err = ltc_mp.ecc_mul2add(mG, u1, mQ, u2, mG, m)) != CRYPT_OK) { goto error; } | 139 if ((err = ltc_mp.ecc_mul2add(mG, u1, mQ, u2, mG, m)) != CRYPT_OK) { goto error; } |
151 err = CRYPT_OK; | 151 err = CRYPT_OK; |
152 error: | 152 error: |
153 ltc_ecc_del_point(mG); | 153 ltc_ecc_del_point(mG); |
154 ltc_ecc_del_point(mQ); | 154 ltc_ecc_del_point(mQ); |
155 mp_clear_multi(r, s, v, w, u1, u2, p, e, m, NULL); | 155 mp_clear_multi(r, s, v, w, u1, u2, p, e, m, NULL); |
156 if (mp != NULL) { | 156 if (mp != NULL) { |
157 mp_montgomery_free(mp); | 157 mp_montgomery_free(mp); |
158 } | 158 } |
159 return err; | 159 return err; |
160 } | 160 } |
161 | 161 |