comparison libtommath/bn_s_mp_prime_is_divisible.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
children
comparison
equal deleted inserted replaced
1691:2d3745d58843 1692:1051e4eea25a
1 #include "tommath_private.h"
2 #ifdef BN_S_MP_PRIME_IS_DIVISIBLE_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
5
6 /* determines if an integers is divisible by one
7 * of the first PRIME_SIZE primes or not
8 *
9 * sets result to 0 if not, 1 if yes
10 */
11 mp_err s_mp_prime_is_divisible(const mp_int *a, mp_bool *result)
12 {
13 int ix;
14 mp_err err;
15 mp_digit res;
16
17 /* default to not */
18 *result = MP_NO;
19
20 for (ix = 0; ix < PRIVATE_MP_PRIME_TAB_SIZE; ix++) {
21 /* what is a mod LBL_prime_tab[ix] */
22 if ((err = mp_mod_d(a, s_mp_prime_tab[ix], &res)) != MP_OKAY) {
23 return err;
24 }
25
26 /* is the residue zero? */
27 if (res == 0u) {
28 *result = MP_YES;
29 return MP_OKAY;
30 }
31 }
32
33 return MP_OKAY;
34 }
35 #endif