bn_mp_dr_is_modulus.c 1.03 KB
Newer Older
1
#include "tommath_private.h"
2 3 4 5 6 7 8 9 10 11
#ifdef BN_MP_DR_IS_MODULUS_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
 *
 * LibTomMath is a library that provides multiple-precision
 * integer arithmetic as well as number theoretic functionality.
 *
 * The library was designed directly after the MPI library by
 * Michael Fromberger but has been written from scratch with
 * additional optimizations in place.
 *
12
 * SPDX-License-Identifier: Unlicense
13 14 15
 */

/* determines if a number is a valid DR modulus */
16
int mp_dr_is_modulus(const mp_int *a)
17 18 19 20 21 22 23 24 25 26 27 28
{
   int ix;

   /* must be at least two digits */
   if (a->used < 2) {
      return 0;
   }

   /* must be of the form b**k - a [a <= b] so all
    * but the first digit must be equal to -1 (mod b).
    */
   for (ix = 1; ix < a->used; ix++) {
29 30 31
      if (a->dp[ix] != MP_MASK) {
         return 0;
      }
32 33 34 35 36 37
   }
   return 1;
}

#endif

38 39 40
/* ref:         HEAD -> release/1.1.0, tag: v1.1.0-rc4 */
/* git commit:  e543ff319ab338f495663b3c55cf4a22da918562 */
/* commit time: 2019-01-22 13:49:36 +0100 */