Mercurial > dropbear
comparison libtomcrypt/src/pk/ecc/ltc_ecc_projective_add_point.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 | 9 |
12 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b | 10 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b |
13 * | 11 * |
14 * All curves taken from NIST recommendation paper of July 1999 | 12 * All curves taken from NIST recommendation paper of July 1999 |
17 #include "tomcrypt.h" | 15 #include "tomcrypt.h" |
18 | 16 |
19 /** | 17 /** |
20 @file ltc_ecc_projective_add_point.c | 18 @file ltc_ecc_projective_add_point.c |
21 ECC Crypto, Tom St Denis | 19 ECC Crypto, Tom St Denis |
22 */ | 20 */ |
23 | 21 |
24 #if defined(LTC_MECC) && (!defined(LTC_MECC_ACCEL) || defined(LTM_LTC_DESC)) | 22 #if defined(LTC_MECC) && (!defined(LTC_MECC_ACCEL) || defined(LTM_DESC)) |
25 | 23 |
26 /** | 24 /** |
27 Add two ECC points | 25 Add two ECC points |
28 @param P The point to add | 26 @param P The point to add |
29 @param Q The point to add | 27 @param Q The point to add |
44 LTC_ARGCHK(mp != NULL); | 42 LTC_ARGCHK(mp != NULL); |
45 | 43 |
46 if ((err = mp_init_multi(&t1, &t2, &x, &y, &z, NULL)) != CRYPT_OK) { | 44 if ((err = mp_init_multi(&t1, &t2, &x, &y, &z, NULL)) != CRYPT_OK) { |
47 return err; | 45 return err; |
48 } | 46 } |
49 | 47 |
50 /* should we dbl instead? */ | 48 /* should we dbl instead? */ |
51 if ((err = mp_sub(modulus, Q->y, t1)) != CRYPT_OK) { goto done; } | 49 if ((err = mp_sub(modulus, Q->y, t1)) != CRYPT_OK) { goto done; } |
52 | 50 |
53 if ( (mp_cmp(P->x, Q->x) == LTC_MP_EQ) && | 51 if ( (mp_cmp(P->x, Q->x) == LTC_MP_EQ) && |
54 (Q->z != NULL && mp_cmp(P->z, Q->z) == LTC_MP_EQ) && | 52 (Q->z != NULL && mp_cmp(P->z, Q->z) == LTC_MP_EQ) && |
55 (mp_cmp(P->y, Q->y) == LTC_MP_EQ || mp_cmp(P->y, t1) == LTC_MP_EQ)) { | 53 (mp_cmp(P->y, Q->y) == LTC_MP_EQ || mp_cmp(P->y, t1) == LTC_MP_EQ)) { |
56 mp_clear_multi(t1, t2, x, y, z, NULL); | 54 mp_clear_multi(t1, t2, x, y, z, NULL); |
57 return ltc_ecc_projective_dbl_point(P, R, modulus, mp); | 55 return ltc_ecc_projective_dbl_point(P, R, modulus, mp); |
58 } | 56 } |
142 if ((err = mp_mul(t2, x, t2)) != CRYPT_OK) { goto done; } | 140 if ((err = mp_mul(t2, x, t2)) != CRYPT_OK) { goto done; } |
143 if ((err = mp_montgomery_reduce(t2, modulus, mp)) != CRYPT_OK) { goto done; } | 141 if ((err = mp_montgomery_reduce(t2, modulus, mp)) != CRYPT_OK) { goto done; } |
144 /* T1 = T1 * X */ | 142 /* T1 = T1 * X */ |
145 if ((err = mp_mul(t1, x, t1)) != CRYPT_OK) { goto done; } | 143 if ((err = mp_mul(t1, x, t1)) != CRYPT_OK) { goto done; } |
146 if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK) { goto done; } | 144 if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK) { goto done; } |
147 | 145 |
148 /* X = Y*Y */ | 146 /* X = Y*Y */ |
149 if ((err = mp_sqr(y, x)) != CRYPT_OK) { goto done; } | 147 if ((err = mp_sqr(y, x)) != CRYPT_OK) { goto done; } |
150 if ((err = mp_montgomery_reduce(x, modulus, mp)) != CRYPT_OK) { goto done; } | 148 if ((err = mp_montgomery_reduce(x, modulus, mp)) != CRYPT_OK) { goto done; } |
151 /* X = X - T2 */ | 149 /* X = X - T2 */ |
152 if ((err = mp_sub(x, t2, x)) != CRYPT_OK) { goto done; } | 150 if ((err = mp_sub(x, t2, x)) != CRYPT_OK) { goto done; } |
156 | 154 |
157 /* T2 = T2 - X */ | 155 /* T2 = T2 - X */ |
158 if ((err = mp_sub(t2, x, t2)) != CRYPT_OK) { goto done; } | 156 if ((err = mp_sub(t2, x, t2)) != CRYPT_OK) { goto done; } |
159 if (mp_cmp_d(t2, 0) == LTC_MP_LT) { | 157 if (mp_cmp_d(t2, 0) == LTC_MP_LT) { |
160 if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK) { goto done; } | 158 if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK) { goto done; } |
161 } | 159 } |
162 /* T2 = T2 - X */ | 160 /* T2 = T2 - X */ |
163 if ((err = mp_sub(t2, x, t2)) != CRYPT_OK) { goto done; } | 161 if ((err = mp_sub(t2, x, t2)) != CRYPT_OK) { goto done; } |
164 if (mp_cmp_d(t2, 0) == LTC_MP_LT) { | 162 if (mp_cmp_d(t2, 0) == LTC_MP_LT) { |
165 if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK) { goto done; } | 163 if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK) { goto done; } |
166 } | 164 } |
188 return err; | 186 return err; |
189 } | 187 } |
190 | 188 |
191 #endif | 189 #endif |
192 | 190 |
193 /* $Source$ */ | 191 /* ref: $Format:%D$ */ |
194 /* $Revision$ */ | 192 /* git commit: $Format:%H$ */ |
195 /* $Date$ */ | 193 /* commit time: $Format:%ai$ */ |
196 | 194 |