Mercurial > dropbear
comparison libtomcrypt/src/pk/ecc/ltc_ecc_projective_dbl_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_dbl_point.c | 18 @file ltc_ecc_projective_dbl_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 Double an ECC point | 25 Double an ECC point |
28 @param P The point to double | 26 @param P The point to double |
29 @param R [out] The destination of the double | 27 @param R [out] The destination of the double |
60 /* Z = 2Z */ | 58 /* Z = 2Z */ |
61 if ((err = mp_add(R->z, R->z, R->z)) != CRYPT_OK) { goto done; } | 59 if ((err = mp_add(R->z, R->z, R->z)) != CRYPT_OK) { goto done; } |
62 if (mp_cmp(R->z, modulus) != LTC_MP_LT) { | 60 if (mp_cmp(R->z, modulus) != LTC_MP_LT) { |
63 if ((err = mp_sub(R->z, modulus, R->z)) != CRYPT_OK) { goto done; } | 61 if ((err = mp_sub(R->z, modulus, R->z)) != CRYPT_OK) { goto done; } |
64 } | 62 } |
65 | 63 |
66 /* T2 = X - T1 */ | 64 /* T2 = X - T1 */ |
67 if ((err = mp_sub(R->x, t1, t2)) != CRYPT_OK) { goto done; } | 65 if ((err = mp_sub(R->x, t1, t2)) != CRYPT_OK) { goto done; } |
68 if (mp_cmp_d(t2, 0) == LTC_MP_LT) { | 66 if (mp_cmp_d(t2, 0) == LTC_MP_LT) { |
69 if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK) { goto done; } | 67 if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK) { goto done; } |
70 } | 68 } |
119 if ((err = mp_sub(R->x, R->y, R->x)) != CRYPT_OK) { goto done; } | 117 if ((err = mp_sub(R->x, R->y, R->x)) != CRYPT_OK) { goto done; } |
120 if (mp_cmp_d(R->x, 0) == LTC_MP_LT) { | 118 if (mp_cmp_d(R->x, 0) == LTC_MP_LT) { |
121 if ((err = mp_add(R->x, modulus, R->x)) != CRYPT_OK) { goto done; } | 119 if ((err = mp_add(R->x, modulus, R->x)) != CRYPT_OK) { goto done; } |
122 } | 120 } |
123 | 121 |
124 /* Y = Y - X */ | 122 /* Y = Y - X */ |
125 if ((err = mp_sub(R->y, R->x, R->y)) != CRYPT_OK) { goto done; } | 123 if ((err = mp_sub(R->y, R->x, R->y)) != CRYPT_OK) { goto done; } |
126 if (mp_cmp_d(R->y, 0) == LTC_MP_LT) { | 124 if (mp_cmp_d(R->y, 0) == LTC_MP_LT) { |
127 if ((err = mp_add(R->y, modulus, R->y)) != CRYPT_OK) { goto done; } | 125 if ((err = mp_add(R->y, modulus, R->y)) != CRYPT_OK) { goto done; } |
128 } | 126 } |
129 /* Y = Y * T1 */ | 127 /* Y = Y * T1 */ |
132 /* Y = Y - T2 */ | 130 /* Y = Y - T2 */ |
133 if ((err = mp_sub(R->y, t2, R->y)) != CRYPT_OK) { goto done; } | 131 if ((err = mp_sub(R->y, t2, R->y)) != CRYPT_OK) { goto done; } |
134 if (mp_cmp_d(R->y, 0) == LTC_MP_LT) { | 132 if (mp_cmp_d(R->y, 0) == LTC_MP_LT) { |
135 if ((err = mp_add(R->y, modulus, R->y)) != CRYPT_OK) { goto done; } | 133 if ((err = mp_add(R->y, modulus, R->y)) != CRYPT_OK) { goto done; } |
136 } | 134 } |
137 | 135 |
138 err = CRYPT_OK; | 136 err = CRYPT_OK; |
139 done: | 137 done: |
140 mp_clear_multi(t1, t2, NULL); | 138 mp_clear_multi(t1, t2, NULL); |
141 return err; | 139 return err; |
142 } | 140 } |
143 #endif | 141 #endif |
144 /* $Source$ */ | 142 /* ref: $Format:%D$ */ |
145 /* $Revision$ */ | 143 /* git commit: $Format:%H$ */ |
146 /* $Date$ */ | 144 /* commit time: $Format:%ai$ */ |
147 | 145 |