1 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 * LibTomMath is library that provides for multiple-precision
4 * integer arithmetic as well as number theoretic functionality.
6 * The library is designed directly after the MPI library by
7 * Michael Fromberger but has been written from scratch with
8 * additional optimizations in place.
10 * The library is free for all purposes without any express
13 * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
17 /* performs one Fermat test.
19 * If "a" were prime then b^a == b (mod a) since the order of
20 * the multiplicative sub-group would be phi(a) = a-1. That means
21 * it would be the same as b^(a mod (a-1)) == b^1 == b (mod a).
23 * Sets result to 1 if the congruence holds, or zero otherwise.
26 mp_prime_fermat (mp_int * a, mp_int * b, int *result)
35 if ((err = mp_init (&t)) != MP_OKAY) {
39 /* compute t = b^a mod a */
40 if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) {
44 /* is it equal to b? */
45 if (mp_cmp (&t, b) == MP_EQ) {