Mercurial > dropbear
comparison libtommath/bn_mp_dr_is_modulus.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_DR_IS_MODULUS_C | 2 #ifdef BN_MP_DR_IS_MODULUS_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 /* determines if a number is a valid DR modulus */ | 6 /* determines if a number is a valid DR modulus */ |
19 int mp_dr_is_modulus(mp_int *a) | 7 mp_bool mp_dr_is_modulus(const mp_int *a) |
20 { | 8 { |
21 int ix; | 9 int ix; |
22 | 10 |
23 /* must be at least two digits */ | 11 /* must be at least two digits */ |
24 if (a->used < 2) { | 12 if (a->used < 2) { |
25 return 0; | 13 return MP_NO; |
26 } | 14 } |
27 | 15 |
28 /* must be of the form b**k - a [a <= b] so all | 16 /* must be of the form b**k - a [a <= b] so all |
29 * but the first digit must be equal to -1 (mod b). | 17 * but the first digit must be equal to -1 (mod b). |
30 */ | 18 */ |
31 for (ix = 1; ix < a->used; ix++) { | 19 for (ix = 1; ix < a->used; ix++) { |
32 if (a->dp[ix] != MP_MASK) { | 20 if (a->dp[ix] != MP_MASK) { |
33 return 0; | 21 return MP_NO; |
34 } | 22 } |
35 } | 23 } |
36 return 1; | 24 return MP_YES; |
37 } | 25 } |
38 | 26 |
39 #endif | 27 #endif |
40 | |
41 /* ref: $Format:%D$ */ | |
42 /* git commit: $Format:%H$ */ | |
43 /* commit time: $Format:%ai$ */ |