bn_mp_dr_is_modulus.c 610 B

123456789101112131415161718192021222324252627
  1. #include "tommath_private.h"
  2. #ifdef BN_MP_DR_IS_MODULUS_C
  3. /* LibTomMath, multiple-precision integer library -- Tom St Denis */
  4. /* SPDX-License-Identifier: Unlicense */
  5. /* determines if a number is a valid DR modulus */
  6. mp_bool mp_dr_is_modulus(const mp_int *a)
  7. {
  8. int ix;
  9. /* must be at least two digits */
  10. if (a->used < 2) {
  11. return MP_NO;
  12. }
  13. /* must be of the form b**k - a [a <= b] so all
  14. * but the first digit must be equal to -1 (mod b).
  15. */
  16. for (ix = 1; ix < a->used; ix++) {
  17. if (a->dp[ix] != MP_MASK) {
  18. return MP_NO;
  19. }
  20. }
  21. return MP_YES;
  22. }
  23. #endif