comparison libtommath/bn_mp_invmod.c @ 1733:d529a52b2f7c coverity coverity

merge coverity from main
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 Jun 2020 21:07:34 +0800
parents 1051e4eea25a
children
comparison
equal deleted inserted replaced
1643:b59623a64678 1733:d529a52b2f7c
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 * The library is free for all purposes without any express
13 * guarantee it works.
14 *
15 * Tom St Denis, [email protected], http://libtom.org
16 */
17 5
18 /* hac 14.61, pp608 */ 6 /* hac 14.61, pp608 */
19 int mp_invmod (mp_int * a, mp_int * b, mp_int * c) 7 mp_err mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
20 { 8 {
21 /* b cannot be negative */ 9 /* b cannot be negative and has to be >1 */
22 if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) { 10 if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1uL) != MP_GT)) {
23 return MP_VAL; 11 return MP_VAL;
24 } 12 }
25 13
26 #ifdef BN_FAST_MP_INVMOD_C 14 /* if the modulus is odd we can use a faster routine instead */
27 /* if the modulus is odd we can use a faster routine instead */ 15 if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) {
28 if ((mp_isodd(b) == MP_YES) && (mp_cmp_d(b, 1) != MP_EQ)) { 16 return s_mp_invmod_fast(a, b, c);
29 return fast_mp_invmod (a, b, c); 17 }
30 }
31 #endif
32 18
33 #ifdef BN_MP_INVMOD_SLOW_C 19 return MP_HAS(S_MP_INVMOD_SLOW)
34 return mp_invmod_slow(a, b, c); 20 ? s_mp_invmod_slow(a, b, c)
35 #else 21 : MP_VAL;
36 return MP_VAL;
37 #endif
38 } 22 }
39 #endif 23 #endif
40
41 /* ref: $Format:%D$ */
42 /* git commit: $Format:%H$ */
43 /* commit time: $Format:%ai$ */