comparison libtommath/bn_mp_prime_is_divisible.c @ 1655:f52919ffd3b1

update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79) * make key-generation compliant to FIPS 186.4 * fix includes in tommath_class.h * update fuzzcorpus instead of error-out * fixup fuzzing make-targets * update Makefile.in * apply necessary patches to ltm sources * clean-up not required ltm files * update to vanilla ltm 1.1.0 this already only contains the required files * remove set/get double
author Steffen Jaeckel <s_jaeckel@gmx.de>
date Mon, 16 Sep 2019 15:50:38 +0200
parents 8bba51a55704
children
comparison
equal deleted inserted replaced
1654:cc0fc5131c5c 1655:f52919ffd3b1
1 #include <tommath_private.h> 1 #include "tommath_private.h"
2 #ifdef BN_MP_PRIME_IS_DIVISIBLE_C 2 #ifdef BN_MP_PRIME_IS_DIVISIBLE_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 * 4 *
5 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
7 * 7 *
8 * The library was designed directly after the MPI library by 8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with 9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * SPDX-License-Identifier: Unlicense
13 * guarantee it works.
14 *
15 * Tom St Denis, [email protected], http://libtom.org
16 */ 13 */
17 14
18 /* determines if an integers is divisible by one 15 /* determines if an integers is divisible by one
19 * of the first PRIME_SIZE primes or not 16 * of the first PRIME_SIZE primes or not
20 * 17 *
21 * sets result to 0 if not, 1 if yes 18 * sets result to 0 if not, 1 if yes
22 */ 19 */
23 int mp_prime_is_divisible (mp_int * a, int *result) 20 int mp_prime_is_divisible(const mp_int *a, int *result)
24 { 21 {
25 int err, ix; 22 int err, ix;
26 mp_digit res; 23 mp_digit res;
27 24
28 /* default to not */ 25 /* default to not */
29 *result = MP_NO; 26 *result = MP_NO;
30 27
31 for (ix = 0; ix < PRIME_SIZE; ix++) { 28 for (ix = 0; ix < PRIME_SIZE; ix++) {
32 /* what is a mod LBL_prime_tab[ix] */ 29 /* what is a mod LBL_prime_tab[ix] */
33 if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) { 30 if ((err = mp_mod_d(a, ltm_prime_tab[ix], &res)) != MP_OKAY) {
34 return err; 31 return err;
35 } 32 }
36 33
37 /* is the residue zero? */ 34 /* is the residue zero? */
38 if (res == 0) { 35 if (res == 0u) {
39 *result = MP_YES; 36 *result = MP_YES;
40 return MP_OKAY; 37 return MP_OKAY;
41 } 38 }
42 } 39 }
43 40
44 return MP_OKAY; 41 return MP_OKAY;
45 } 42 }
46 #endif 43 #endif
47 44
48 /* ref: $Format:%D$ */ 45 /* ref: HEAD -> master, tag: v1.1.0 */
49 /* git commit: $Format:%H$ */ 46 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
50 /* commit time: $Format:%ai$ */ 47 /* commit time: 2019-01-28 20:32:32 +0100 */