Mercurial > dropbear
comparison libtomcrypt/src/pk/ecc/ltc_ecc_map.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_map.c | 18 @file ltc_ecc_map.c |
21 ECC Crypto, Tom St Denis | 19 ECC Crypto, Tom St Denis |
22 */ | 20 */ |
23 | 21 |
24 #ifdef LTC_MECC | 22 #ifdef LTC_MECC |
25 | 23 |
26 /** | 24 /** |
27 Map a projective jacbobian point back to affine space | 25 Map a projective jacbobian point back to affine space |
38 LTC_ARGCHK(P != NULL); | 36 LTC_ARGCHK(P != NULL); |
39 LTC_ARGCHK(modulus != NULL); | 37 LTC_ARGCHK(modulus != NULL); |
40 LTC_ARGCHK(mp != NULL); | 38 LTC_ARGCHK(mp != NULL); |
41 | 39 |
42 if ((err = mp_init_multi(&t1, &t2, NULL)) != CRYPT_OK) { | 40 if ((err = mp_init_multi(&t1, &t2, NULL)) != CRYPT_OK) { |
43 return CRYPT_MEM; | 41 return err; |
44 } | 42 } |
45 | 43 |
46 /* first map z back to normal */ | 44 /* first map z back to normal */ |
47 if ((err = mp_montgomery_reduce(P->z, modulus, mp)) != CRYPT_OK) { goto done; } | 45 if ((err = mp_montgomery_reduce(P->z, modulus, mp)) != CRYPT_OK) { goto done; } |
48 | 46 |
49 /* get 1/z */ | 47 /* get 1/z */ |
50 if ((err = mp_invmod(P->z, modulus, t1)) != CRYPT_OK) { goto done; } | 48 if ((err = mp_invmod(P->z, modulus, t1)) != CRYPT_OK) { goto done; } |
51 | 49 |
52 /* get 1/z^2 and 1/z^3 */ | 50 /* get 1/z^2 and 1/z^3 */ |
53 if ((err = mp_sqr(t1, t2)) != CRYPT_OK) { goto done; } | 51 if ((err = mp_sqr(t1, t2)) != CRYPT_OK) { goto done; } |
54 if ((err = mp_mod(t2, modulus, t2)) != CRYPT_OK) { goto done; } | 52 if ((err = mp_mod(t2, modulus, t2)) != CRYPT_OK) { goto done; } |
55 if ((err = mp_mul(t1, t2, t1)) != CRYPT_OK) { goto done; } | 53 if ((err = mp_mul(t1, t2, t1)) != CRYPT_OK) { goto done; } |
56 if ((err = mp_mod(t1, modulus, t1)) != CRYPT_OK) { goto done; } | 54 if ((err = mp_mod(t1, modulus, t1)) != CRYPT_OK) { goto done; } |
68 return err; | 66 return err; |
69 } | 67 } |
70 | 68 |
71 #endif | 69 #endif |
72 | 70 |
73 /* $Source$ */ | 71 /* ref: $Format:%D$ */ |
74 /* $Revision$ */ | 72 /* git commit: $Format:%H$ */ |
75 /* $Date$ */ | 73 /* commit time: $Format:%ai$ */ |
76 | 74 |