Mercurial > dropbear
comparison libtommath/bn_mp_invmod.c @ 1692:1051e4eea25a
Update LibTomMath to 1.2.0 (#84)
* update C files
* update other files
* update headers
* update makefiles
* remove mp_set/get_double()
* use ltm 1.2.0 API
* update ltm_desc
* use bundled tommath if system-tommath is too old
* XMALLOC etc. were changed to MP_MALLOC etc.
author | Steffen Jaeckel <s@jaeckel.eu> |
---|---|
date | Tue, 26 May 2020 17:36:47 +0200 |
parents | f52919ffd3b1 |
children |
comparison
equal
deleted
inserted
replaced
1691:2d3745d58843 | 1692:1051e4eea25a |
---|---|
1 #include "tommath_private.h" | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_INVMOD_C | 2 #ifdef BN_MP_INVMOD_C |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis | 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */ |
4 * | 4 /* SPDX-License-Identifier: Unlicense */ |
5 * LibTomMath is a library that provides multiple-precision | |
6 * integer arithmetic as well as number theoretic functionality. | |
7 * | |
8 * The library was designed directly after the MPI library by | |
9 * Michael Fromberger but has been written from scratch with | |
10 * additional optimizations in place. | |
11 * | |
12 * SPDX-License-Identifier: Unlicense | |
13 */ | |
14 | 5 |
15 /* hac 14.61, pp608 */ | 6 /* hac 14.61, pp608 */ |
16 int mp_invmod(const mp_int *a, const mp_int *b, mp_int *c) | 7 mp_err mp_invmod(const mp_int *a, const mp_int *b, mp_int *c) |
17 { | 8 { |
18 /* b cannot be negative and has to be >1 */ | 9 /* b cannot be negative and has to be >1 */ |
19 if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1uL) != MP_GT)) { | 10 if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1uL) != MP_GT)) { |
20 return MP_VAL; | 11 return MP_VAL; |
21 } | 12 } |
22 | 13 |
23 #ifdef BN_FAST_MP_INVMOD_C | |
24 /* if the modulus is odd we can use a faster routine instead */ | 14 /* if the modulus is odd we can use a faster routine instead */ |
25 if ((mp_isodd(b) == MP_YES)) { | 15 if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) { |
26 return fast_mp_invmod(a, b, c); | 16 return s_mp_invmod_fast(a, b, c); |
27 } | 17 } |
28 #endif | |
29 | 18 |
30 #ifdef BN_MP_INVMOD_SLOW_C | 19 return MP_HAS(S_MP_INVMOD_SLOW) |
31 return mp_invmod_slow(a, b, c); | 20 ? s_mp_invmod_slow(a, b, c) |
32 #else | 21 : MP_VAL; |
33 return MP_VAL; | |
34 #endif | |
35 } | 22 } |
36 #endif | 23 #endif |
37 | |
38 /* ref: HEAD -> master, tag: v1.1.0 */ | |
39 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ | |
40 /* commit time: 2019-01-28 20:32:32 +0100 */ |