Commit 290c28c10e986e28794d501f03dd908bca8c7f5d

Daniel Mendler 2019-05-07T09:49:26

deprecate PRIME_SIZE in favor of MP_PRIME_SIZE

diff --git a/bn_mp_prime_is_divisible.c b/bn_mp_prime_is_divisible.c
index cc073be..2697cc7 100644
--- a/bn_mp_prime_is_divisible.c
+++ b/bn_mp_prime_is_divisible.c
@@ -4,7 +4,7 @@
 /* SPDX-License-Identifier: Unlicense */
 
 /* determines if an integers is divisible by one
- * of the first PRIME_SIZE primes or not
+ * of the first MP_PRIME_SIZE primes or not
  *
  * sets result to 0 if not, 1 if yes
  */
@@ -16,7 +16,7 @@ int mp_prime_is_divisible(const mp_int *a, int *result)
    /* default to not */
    *result = MP_NO;
 
-   for (ix = 0; ix < PRIME_SIZE; ix++) {
+   for (ix = 0; ix < MP_PRIME_SIZE; ix++) {
       /* what is a mod LBL_prime_tab[ix] */
       if ((err = mp_mod_d(a, ltm_prime_tab[ix], &res)) != MP_OKAY) {
          return err;
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index b6f5927..3a371e2 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -24,7 +24,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
    *result = MP_NO;
 
    /* valid value of t? */
-   if (t > PRIME_SIZE) {
+   if (t > MP_PRIME_SIZE) {
       return MP_VAL;
    }
 
@@ -54,7 +54,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
    }
 
    /* is the input equal to one of the primes in the table? */
-   for (ix = 0; ix < PRIME_SIZE; ix++) {
+   for (ix = 0; ix < MP_PRIME_SIZE; ix++) {
       if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) {
          *result = MP_YES;
          return MP_OKAY;
@@ -62,7 +62,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
    }
 #ifdef MP_8BIT
    /* The search in the loop above was exhaustive in this case */
-   if ((a->used == 1) && (PRIME_SIZE >= 31)) {
+   if ((a->used == 1) && (MP_PRIME_SIZE >= 31)) {
       return MP_OKAY;
    }
 #endif
@@ -208,7 +208,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
          p_max = t;
       }
 
-      if (p_max > PRIME_SIZE) {
+      if (p_max > MP_PRIME_SIZE) {
          err = MP_VAL;
          goto LBL_B;
       }
diff --git a/bn_mp_prime_next_prime.c b/bn_mp_prime_next_prime.c
index 7d306fb..2e27eed 100644
--- a/bn_mp_prime_next_prime.c
+++ b/bn_mp_prime_next_prime.c
@@ -11,16 +11,16 @@
 int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
 {
    int      err, res = MP_NO, x, y;
-   mp_digit res_tab[PRIME_SIZE], step, kstep;
+   mp_digit res_tab[MP_PRIME_SIZE], step, kstep;
    mp_int   b;
 
    /* force positive */
    a->sign = MP_ZPOS;
 
    /* simple algo if a is less than the largest prime in the table */
-   if (mp_cmp_d(a, ltm_prime_tab[PRIME_SIZE-1]) == MP_LT) {
+   if (mp_cmp_d(a, ltm_prime_tab[MP_PRIME_SIZE-1]) == MP_LT) {
       /* find which prime it is bigger than */
-      for (x = PRIME_SIZE - 2; x >= 0; x--) {
+      for (x = MP_PRIME_SIZE - 2; x >= 0; x--) {
          if (mp_cmp_d(a, ltm_prime_tab[x]) != MP_LT) {
             if (bbs_style == 1) {
                /* ok we found a prime smaller or
@@ -31,7 +31,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
                 */
                if ((ltm_prime_tab[x + 1] & 3u) != 3u) {
                   /* scan upwards for a prime congruent to 3 mod 4 */
-                  for (y = x + 1; y < PRIME_SIZE; y++) {
+                  for (y = x + 1; y < MP_PRIME_SIZE; y++) {
                      if ((ltm_prime_tab[y] & 3u) == 3u) {
                         mp_set(a, ltm_prime_tab[y]);
                         return MP_OKAY;
@@ -78,7 +78,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
    }
 
    /* generate the restable */
-   for (x = 1; x < PRIME_SIZE; x++) {
+   for (x = 1; x < MP_PRIME_SIZE; x++) {
       if ((err = mp_mod_d(a, ltm_prime_tab[x], res_tab + x)) != MP_OKAY) {
          return err;
       }
@@ -100,7 +100,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
          step += kstep;
 
          /* compute the new residue without using division */
-         for (x = 1; x < PRIME_SIZE; x++) {
+         for (x = 1; x < MP_PRIME_SIZE; x++) {
             /* add the step to each residue */
             res_tab[x] += kstep;
 
diff --git a/tommath.h b/tommath.h
index 66bc269..901eb91 100644
--- a/tommath.h
+++ b/tommath.h
@@ -512,15 +512,16 @@ int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y);
 
 /* number of primes */
 #ifdef MP_8BIT
-#  define PRIME_SIZE 31
+#  define MP_PRIME_SIZE 31
 #else
-#  define PRIME_SIZE 256
+#  define MP_PRIME_SIZE 256
 #endif
+#define PRIME_SIZE (MP_DEPRECATED_PRAGMA("PRIME_SIZE has been deprecated, use MP_PRIME_SIZE") MP_PRIME_SIZE)
 
-/* table of first PRIME_SIZE primes */
-extern const mp_digit ltm_prime_tab[PRIME_SIZE];
+/* table of first MP_PRIME_SIZE primes */
+extern const mp_digit ltm_prime_tab[MP_PRIME_SIZE];
 
-/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
+/* result=1 if a is divisible by one of the first MP_PRIME_SIZE primes */
 int mp_prime_is_divisible(const mp_int *a, int *result);
 
 /* performs one Fermat test of "a" using base "b".