1
|
1 /* LibTomMath, multiple-precision integer library -- Tom St Denis |
|
2 * |
|
3 * LibTomMath is a library that provides multiple-precision |
|
4 * integer arithmetic as well as number theoretic functionality. |
|
5 * |
|
6 * The library was designed directly after the MPI library by |
|
7 * Michael Fromberger but has been written from scratch with |
|
8 * additional optimizations in place. |
|
9 * |
|
10 * The library is free for all purposes without any express |
|
11 * guarantee it works. |
|
12 * |
|
13 * Tom St Denis, [email protected], http://math.libtomcrypt.org |
|
14 */ |
|
15 #include <tommath.h> |
|
16 |
|
17 /* determines if an integers is divisible by one |
|
18 * of the first PRIME_SIZE primes or not |
|
19 * |
|
20 * sets result to 0 if not, 1 if yes |
|
21 */ |
|
22 int mp_prime_is_divisible (mp_int * a, int *result) |
|
23 { |
|
24 int err, ix; |
|
25 mp_digit res; |
|
26 |
|
27 /* default to not */ |
|
28 *result = MP_NO; |
|
29 |
|
30 for (ix = 0; ix < PRIME_SIZE; ix++) { |
|
31 /* what is a mod __prime_tab[ix] */ |
|
32 if ((err = mp_mod_d (a, __prime_tab[ix], &res)) != MP_OKAY) { |
|
33 return err; |
|
34 } |
|
35 |
|
36 /* is the residue zero? */ |
|
37 if (res == 0) { |
|
38 *result = MP_YES; |
|
39 return MP_OKAY; |
|
40 } |
|
41 } |
|
42 |
|
43 return MP_OKAY; |
|
44 } |