deprecate PRIME_SIZE in favor of MP_PRIME_SIZE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
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".