1/*	$NetBSD: bn_mp_prime_is_divisible.c,v 1.2 2017/01/28 21:31:47 christos Exp $	*/
2
3#include <tommath.h>
4#ifdef BN_MP_PRIME_IS_DIVISIBLE_C
5/* LibTomMath, multiple-precision integer library -- Tom St Denis
6 *
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
9 *
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
13 *
14 * The library is free for all purposes without any express
15 * guarantee it works.
16 *
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18 */
19
20/* determines if an integers is divisible by one
21 * of the first PRIME_SIZE primes or not
22 *
23 * sets result to 0 if not, 1 if yes
24 */
25int mp_prime_is_divisible (mp_int * a, int *result)
26{
27  int     err, ix;
28  mp_digit res;
29
30  /* default to not */
31  *result = MP_NO;
32
33  for (ix = 0; ix < PRIME_SIZE; ix++) {
34    /* what is a mod LBL_prime_tab[ix] */
35    if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) {
36      return err;
37    }
38
39    /* is the residue zero? */
40    if (res == 0) {
41      *result = MP_YES;
42      return MP_OKAY;
43    }
44  }
45
46  return MP_OKAY;
47}
48#endif
49
50/* Source: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v  */
51/* Revision: 1.4  */
52/* Date: 2006/12/28 01:25:13  */
53