diff --git a/bn_deprecated.c b/bn_deprecated.c
index 90a40640c..763def895 100644
--- a/bn_deprecated.c
+++ b/bn_deprecated.c
@@ -146,4 +146,61 @@ mp_err mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
return mp_signed_rsh(a, b, c);
}
#endif
+#ifdef BN_MP_INIT_SET_INT_C
+mp_err mp_init_set_int(mp_int *a, unsigned long b)
+{
+ return mp_init_u32(a, (uint32_t)b);
+}
+#endif
+#ifdef BN_MP_INIT_SET_C
+mp_err mp_init_set(mp_int *a, mp_digit b)
+{
+ return mp_init_u64(a, b & MP_MASK);
+}
+#endif
+#ifdef BN_MP_SET_C
+void mp_set(mp_int *a, mp_digit b)
+{
+ mp_set_u64(a, b & MP_MASK);
+}
+#endif
+#ifdef BN_MP_SET_INT_C
+mp_err mp_set_int(mp_int *a, unsigned long b)
+{
+ mp_set_u32(a, (uint32_t)b);
+ return MP_OKAY;
+}
+#endif
+#ifdef BN_MP_SET_LONG_C
+mp_err mp_set_long(mp_int *a, unsigned long b)
+{
+ mp_set_u64(a, b);
+ return MP_OKAY;
+}
+#endif
+#ifdef BN_MP_SET_LONG_LONG_C
+mp_err mp_set_long_long(mp_int *a, unsigned long long b)
+{
+ mp_set_u64(a, b);
+ return MP_OKAY;
+}
+#endif
+#ifdef BN_MP_GET_INT_C
+unsigned long mp_get_int(const mp_int *a)
+{
+ return mp_get_u32(a);
+}
+#endif
+#ifdef BN_MP_GET_LONG_C
+unsigned long mp_get_long(const mp_int *a)
+{
+ return sizeof(long) > sizeof(int32_t) ? (unsigned long)mp_get_mag64(a) : (unsigned long)mp_get_mag32(a);
+}
+#endif
+#ifdef BN_MP_GET_LONG_LONG_C
+unsigned long long mp_get_long_long(const mp_int *a)
+{
+ return (unsigned long long)mp_get_mag64(a);
+}
+#endif
#endif
diff --git a/bn_mp_decr.c b/bn_mp_decr.c
index c6a1572c6..da6e9f496 100644
--- a/bn_mp_decr.c
+++ b/bn_mp_decr.c
@@ -7,7 +7,7 @@
mp_err mp_decr(mp_int *a)
{
if (MP_IS_ZERO(a)) {
- mp_set(a,1uL);
+ mp_set_u(a, 1u);
a->sign = MP_NEG;
return MP_OKAY;
} else if (a->sign == MP_NEG) {
diff --git a/bn_mp_expt_d_ex.c b/bn_mp_expt_d_ex.c
index fdabf8479..0d0f6af19 100644
--- a/bn_mp_expt_d_ex.c
+++ b/bn_mp_expt_d_ex.c
@@ -16,7 +16,7 @@ mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
}
/* set initial result */
- mp_set(c, 1uL);
+ mp_set_u(c, 1u);
if (fast != 0) {
while (b > 0u) {
diff --git a/bn_mp_exteuclid.c b/bn_mp_exteuclid.c
index 3af7467ce..a0d3c828a 100644
--- a/bn_mp_exteuclid.c
+++ b/bn_mp_exteuclid.c
@@ -16,13 +16,13 @@ mp_err mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp
}
/* initialize, (u1,u2,u3) = (1,0,a) */
- mp_set(&u1, 1uL);
+ mp_set_u(&u1, 1u);
if ((err = mp_copy(a, &u3)) != MP_OKAY) {
goto LBL_ERR;
}
/* initialize, (v1,v2,v3) = (0,1,b) */
- mp_set(&v2, 1uL);
+ mp_set_u(&v2, 1u);
if ((err = mp_copy(b, &v3)) != MP_OKAY) {
goto LBL_ERR;
}
diff --git a/bn_mp_get_int.c b/bn_mp_get_int.c
deleted file mode 100644
index e3571e1f5..000000000
--- a/bn_mp_get_int.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_GET_INT_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-/* get the lower 32-bits of an mp_int */
-unsigned long mp_get_int(const mp_int *a)
-{
- /* force result to 32-bits always so it is consistent on non 32-bit platforms */
- return mp_get_long(a) & 0xFFFFFFFFuL;
-}
-#endif
diff --git a/bn_mp_get_long.c b/bn_mp_get_long.c
deleted file mode 100644
index a800efb3d..000000000
--- a/bn_mp_get_long.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_GET_LONG_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-/* get the lower unsigned long of an mp_int, platform dependent */
-unsigned long mp_get_long(const mp_int *a)
-{
- int i;
- unsigned long res;
-
- if (MP_IS_ZERO(a)) {
- return 0;
- }
-
- /* get number of digits of the lsb we have to read */
- i = MP_MIN(a->used, (((int)MP_SIZEOF_BITS(unsigned long) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
-
- /* get most significant digit of result */
- res = (unsigned long)a->dp[i];
-
-#if (ULONG_MAX != 0xFFFFFFFFuL) || (MP_DIGIT_BIT < 32)
- while (--i >= 0) {
- res = (res << MP_DIGIT_BIT) | (unsigned long)a->dp[i];
- }
-#endif
- return res;
-}
-#endif
diff --git a/bn_mp_get_long_long.c b/bn_mp_get_long_long.c
deleted file mode 100644
index 91dde4c3e..000000000
--- a/bn_mp_get_long_long.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_GET_LONG_LONG_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-/* get the lower unsigned long long of an mp_int, platform dependent */
-unsigned long long mp_get_long_long(const mp_int *a)
-{
- int i;
- unsigned long long res;
-
- if (MP_IS_ZERO(a)) {
- return 0;
- }
-
- /* get number of digits of the lsb we have to read */
- i = MP_MIN(a->used, (((int)MP_SIZEOF_BITS(unsigned long long) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
-
- /* get most significant digit of result */
- res = (unsigned long long)a->dp[i];
-
-#if MP_DIGIT_BIT < 64
- while (--i >= 0) {
- res = (res << MP_DIGIT_BIT) | (unsigned long long)a->dp[i];
- }
-#endif
- return res;
-}
-#endif
diff --git a/bn_mp_ilogb.c b/bn_mp_ilogb.c
index efcd5f940..dd5e3d0c1 100644
--- a/bn_mp_ilogb.c
+++ b/bn_mp_ilogb.c
@@ -76,7 +76,6 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
mp_ord cmp;
unsigned int high, low, mid;
mp_int bracket_low, bracket_high, bracket_mid, t, bi_base;
- mp_digit tmp;
err = MP_OKAY;
if (a->sign == MP_NEG) {
@@ -90,12 +89,11 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
return MP_VAL;
}
if (base == 2u) {
- mp_set_int(c, (unsigned long)(mp_count_bits(a) - 1));
+ mp_set_i(c, mp_count_bits(a) - 1);
return err;
}
if (a->used == 1) {
- tmp = s_digit_ilogb(base, a->dp[0]);
- mp_set(c, tmp);
+ mp_set_u64(c, s_digit_ilogb(base, a->dp[0]));
return err;
}
@@ -106,7 +104,7 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
return err;
}
if (cmp == MP_EQ) {
- mp_set(c, (mp_digit)1uL);
+ mp_set_u(c, 1u);
return err;
}
@@ -117,10 +115,10 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
}
low = 0u;
- mp_set(&bracket_low, 1uL);
+ mp_set_u(&bracket_low, 1u);
high = 1u;
- mp_set(&bracket_high, base);
+ mp_set_u64(&bracket_high, base);
/*
A kind of Giant-step/baby-step algorithm.
@@ -138,7 +136,7 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
goto LBL_ERR;
}
}
- mp_set(&bi_base, base);
+ mp_set_u64(&bi_base, base);
while ((high - low) > 1u) {
mid = (high + low) >> 1;
@@ -163,15 +161,15 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
mp_exch(&bracket_mid, &bracket_low);
}
if (cmp == MP_EQ) {
- mp_set_int(c, (unsigned long)mid);
+ mp_set_u64(c, mid);
goto LBL_END;
}
}
if (mp_cmp(&bracket_high, a) == MP_EQ) {
- mp_set_int(c, (unsigned long)high);
+ mp_set_u64(c, high);
} else {
- mp_set_int(c, (unsigned long)low);
+ mp_set_u64(c, low);
}
LBL_END:
diff --git a/bn_mp_incr.c b/bn_mp_incr.c
index 5d0039e0a..41ad22014 100644
--- a/bn_mp_incr.c
+++ b/bn_mp_incr.c
@@ -7,7 +7,7 @@
mp_err mp_incr(mp_int *a)
{
if (MP_IS_ZERO(a)) {
- mp_set(a,1uL);
+ mp_set_u(a,1uL);
return MP_OKAY;
} else if (a->sign == MP_NEG) {
mp_err err;
diff --git a/bn_mp_init_set.c b/bn_mp_init_set.c
deleted file mode 100644
index 5068f2bf6..000000000
--- a/bn_mp_init_set.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_INIT_SET_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-/* initialize and set a digit */
-mp_err mp_init_set(mp_int *a, mp_digit b)
-{
- mp_err err;
- if ((err = mp_init(a)) != MP_OKAY) {
- return err;
- }
- mp_set(a, b);
- return err;
-}
-#endif
diff --git a/bn_mp_init_set_int.c b/bn_mp_init_set_int.c
deleted file mode 100644
index fbb2b6bc3..000000000
--- a/bn_mp_init_set_int.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_INIT_SET_INT_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-/* initialize and set a digit */
-mp_err mp_init_set_int(mp_int *a, unsigned long b)
-{
- mp_err err;
- if ((err = mp_init(a)) != MP_OKAY) {
- return err;
- }
- return mp_set_int(a, b);
-}
-#endif
diff --git a/bn_mp_is_square.c b/bn_mp_is_square.c
index 491b576f2..3fac8e3f2 100644
--- a/bn_mp_is_square.c
+++ b/bn_mp_is_square.c
@@ -58,13 +58,13 @@ mp_err mp_is_square(const mp_int *arg, mp_bool *ret)
}
- if ((err = mp_init_set_int(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
+ if ((err = mp_init_u(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
return err;
}
if ((err = mp_mod(arg, &t, &t)) != MP_OKAY) {
goto LBL_ERR;
}
- r = mp_get_int(&t);
+ r = mp_get_u(&t);
/* Check for other prime modules, note it's not an ERROR but we must
* free "t" so the easiest way is to goto LBL_ERR. We know that err
* is already equal to MP_OKAY from the mp_mod call
diff --git a/bn_mp_montgomery_calc_normalization.c b/bn_mp_montgomery_calc_normalization.c
index 837978925..3983b9461 100644
--- a/bn_mp_montgomery_calc_normalization.c
+++ b/bn_mp_montgomery_calc_normalization.c
@@ -22,7 +22,7 @@ mp_err mp_montgomery_calc_normalization(mp_int *a, const mp_int *b)
return err;
}
} else {
- mp_set(a, 1uL);
+ mp_set_u(a, 1uL);
bits = 1;
}
diff --git a/bn_mp_n_root_ex.c b/bn_mp_n_root_ex.c
index a6ddfdb9b..a535b6895 100644
--- a/bn_mp_n_root_ex.c
+++ b/bn_mp_n_root_ex.c
@@ -49,7 +49,7 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
*/
if (sizeof(mp_digit) >= sizeof(int)) {
if (b > (mp_digit)(INT_MAX/2)) {
- mp_set(c, 1uL);
+ mp_set_u(c, 1u);
c->sign = a->sign;
err = MP_OKAY;
goto LBL_ERR;
@@ -58,14 +58,14 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
#endif
/* "b" is smaller than INT_MAX, we can cast safely */
if (ilog2 < (int)b) {
- mp_set(c, 1uL);
+ mp_set_u(c, 1u);
c->sign = a->sign;
err = MP_OKAY;
goto LBL_ERR;
}
ilog2 = ilog2 / ((int)b);
if (ilog2 == 0) {
- mp_set(c, 1uL);
+ mp_set_u(c, 1u);
c->sign = a->sign;
err = MP_OKAY;
goto LBL_ERR;
diff --git a/bn_mp_prime_frobenius_underwood.c b/bn_mp_prime_frobenius_underwood.c
index c01e28003..7c3281ece 100644
--- a/bn_mp_prime_frobenius_underwood.c
+++ b/bn_mp_prime_frobenius_underwood.c
@@ -43,7 +43,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
continue;
}
/* (32764^2 - 4) < 2^31, no bigint for >MP_8BIT needed) */
- mp_set_long(&T1z, (unsigned long)a);
+ mp_set_u(&T1z, (uint32_t)a);
if ((err = mp_sqr(&T1z, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
@@ -72,7 +72,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
goto LBL_FU_ERR;
}
/* Composite if N and (a+4)*(2*a+5) are not coprime */
- mp_set_long(&T1z, (unsigned long)((a+4)*((2*a)+5)));
+ mp_set_u(&T1z, (uint32_t)((a+4)*((2*a)+5)));
if ((err = mp_gcd(N, &T1z, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
@@ -87,8 +87,8 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
goto LBL_FU_ERR;
}
- mp_set(&sz, 1uL);
- mp_set(&tz, 2uL);
+ mp_set_u(&sz, 1uL);
+ mp_set_u(&tz, 2uL);
length = mp_count_bits(&Np1z);
for (i = length - 2; i >= 0; i--) {
@@ -157,7 +157,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
}
}
- mp_set_long(&T1z, (unsigned long)((2 * a) + 5));
+ mp_set_u(&T1z, (uint32_t)((2 * a) + 5));
if ((err = mp_mod(&T1z, N, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
}
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index 6f91e1826..596833d35 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -77,7 +77,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
/*
Run the Miller-Rabin test with base 2 for the BPSW test.
*/
- if ((err = mp_init_set(&b, 2uL)) != MP_OKAY) {
+ if ((err = mp_init_u(&b, 2uL)) != MP_OKAY) {
return err;
}
@@ -211,7 +211,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
}
/* we did bases 2 and 3 already, skip them */
for (ix = 2; ix < p_max; ix++) {
- mp_set(&b, ltm_prime_tab[ix]);
+ mp_set_u(&b, (uint32_t)ltm_prime_tab[ix]);
if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
goto LBL_B;
}
diff --git a/bn_mp_prime_next_prime.c b/bn_mp_prime_next_prime.c
index f5ce9eb9c..ced6a4b96 100644
--- a/bn_mp_prime_next_prime.c
+++ b/bn_mp_prime_next_prime.c
@@ -35,20 +35,20 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style)
/* scan upwards for a prime congruent to 3 mod 4 */
for (y = x + 1; y < MP_PRIME_SIZE; y++) {
if ((ltm_prime_tab[y] & 3u) == 3u) {
- mp_set(a, ltm_prime_tab[y]);
+ mp_set_u(a, (uint32_t)ltm_prime_tab[y]);
return MP_OKAY;
}
}
}
} else {
- mp_set(a, ltm_prime_tab[x + 1]);
+ mp_set_u(a, (uint32_t)ltm_prime_tab[x + 1]);
return MP_OKAY;
}
}
}
/* at this point a maybe 1 */
if (mp_cmp_d(a, 1uL) == MP_EQ) {
- mp_set(a, 2uL);
+ mp_set_u(a, 2u);
return MP_OKAY;
}
/* fall through to the sieve */
diff --git a/bn_mp_prime_strong_lucas_selfridge.c b/bn_mp_prime_strong_lucas_selfridge.c
index 5f288c86a..a62d7c539 100644
--- a/bn_mp_prime_strong_lucas_selfridge.c
+++ b/bn_mp_prime_strong_lucas_selfridge.c
@@ -19,32 +19,21 @@
* multiply bigint a with int d and put the result in c
* Like mp_mul_d() but with a signed long as the small input
*/
-static mp_err s_mp_mul_si(const mp_int *a, long d, mp_int *c)
+static mp_err s_mp_mul_si(const mp_int *a, int32_t d, mp_int *c)
{
mp_int t;
mp_err err;
- int neg = 0;
if ((err = mp_init(&t)) != MP_OKAY) {
return err;
}
- if (d < 0) {
- neg = 1;
- d = -d;
- }
/*
* mp_digit might be smaller than a long, which excludes
* the use of mp_mul_d() here.
*/
- mp_set_long(&t, (unsigned long) d);
- if ((err = mp_mul(a, &t, c)) != MP_OKAY) {
- goto LBL_MPMULSI_ERR;
- }
- if (neg == 1) {
- c->sign = (a->sign == MP_NEG) ? MP_ZPOS: MP_NEG;
- }
-LBL_MPMULSI_ERR:
+ mp_set_i(&t, d);
+ err = mp_mul(a, &t, c);
mp_clear(&t);
return err;
}
@@ -94,7 +83,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
for (;;) {
Ds = sign * D;
sign = -sign;
- mp_set_long(&Dz, (unsigned long)D);
+ mp_set_u(&Dz, (uint32_t)D);
if ((err = mp_gcd(a, &Dz, &gcd)) != MP_OKAY) {
goto LBL_LS_ERR;
}
@@ -183,30 +172,30 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
combined with the previous totals for U and V, using the
composition formulas for addition of indices. */
- mp_set(&Uz, 1uL); /* U=U_1 */
- mp_set(&Vz, (mp_digit)P); /* V=V_1 */
- mp_set(&U2mz, 1uL); /* U_1 */
- mp_set(&V2mz, (mp_digit)P); /* V_1 */
+ mp_set_u(&Uz, 1u); /* U=U_1 */
+ mp_set_u(&Vz, (uint32_t)P); /* V=V_1 */
+ mp_set_u(&U2mz, 1u); /* U_1 */
+ mp_set_u(&V2mz, (uint32_t)P); /* V_1 */
if (Q < 0) {
Q = -Q;
- mp_set_long(&Qmz, (unsigned long)Q);
+ mp_set_u(&Qmz, (uint32_t)Q);
if ((err = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) {
goto LBL_LS_ERR;
}
/* Initializes calculation of Q^d */
- mp_set_long(&Qkdz, (unsigned long)Q);
+ mp_set_u(&Qkdz, (uint32_t)Q);
Qmz.sign = MP_NEG;
Q2mz.sign = MP_NEG;
Qkdz.sign = MP_NEG;
Q = -Q;
} else {
- mp_set_long(&Qmz, (unsigned long)Q);
+ mp_set_u(&Qmz, (uint32_t)Q);
if ((err = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) {
goto LBL_LS_ERR;
}
/* Initializes calculation of Q^d */
- mp_set_long(&Qkdz, (unsigned long)Q);
+ mp_set_u(&Qkdz, (uint32_t)Q);
}
Nbits = mp_count_bits(&Dz);
@@ -266,7 +255,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
if ((err = mp_mul(&U2mz, &Uz, &T4z)) != MP_OKAY) {
goto LBL_LS_ERR;
}
- if ((err = s_mp_mul_si(&T4z, (long)Ds, &T4z)) != MP_OKAY) {
+ if ((err = s_mp_mul_si(&T4z, Ds, &T4z)) != MP_OKAY) {
goto LBL_LS_ERR;
}
if ((err = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) {
diff --git a/bn_mp_reduce.c b/bn_mp_reduce.c
index d5d3fb102..c54f623db 100644
--- a/bn_mp_reduce.c
+++ b/bn_mp_reduce.c
@@ -63,7 +63,7 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
/* If x < 0, add b**(k+1) to it */
if (mp_cmp_d(x, 0uL) == MP_LT) {
- mp_set(&q, 1uL);
+ mp_set_u(&q, 1uL);
if ((err = mp_lshd(&q, um + 1)) != MP_OKAY)
goto CLEANUP;
if ((err = mp_add(x, &q, x)) != MP_OKAY)
diff --git a/bn_mp_set.c b/bn_mp_set.c
index a41b71134..e48b789c2 100644
--- a/bn_mp_set.c
+++ b/bn_mp_set.c
@@ -1,13 +1,127 @@
#include "tommath_private.h"
-#ifdef BN_MP_SET_C
+
+/* Fancy macro to set an MPI from another type.
+ * There are several things assumed:
+ * x is the counter
+ * a is the pointer to the MPI
+ * b is the original value that should be set in the MPI.
+ */
+#define MP_SET_UNSIGNED(w) \
+ void mp_set_u##w(mp_int * a, uint##w##_t b) \
+ { \
+ int i = 0; \
+ while (b != 0u) { \
+ a->dp[i++] = ((mp_digit)b & MP_MASK); \
+ if (w <= MP_DIGIT_BIT) { break; } \
+ b >>= ((w <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
+ } \
+ a->used = i; \
+ a->sign = MP_ZPOS; \
+ MP_ZERO_DIGITS(a->dp, a->alloc - a->used); \
+ }
+#define MP_SET_SIGNED(w) \
+ void mp_set_i##w(mp_int * a, int##w##_t b) \
+ { \
+ mp_set_##uname(a, b < 0 ? -(uint##w##_t)b : (uint##w##_t)b); \
+ if (b < 0) { a->sign = MP_NEG; } \
+ }
+#define MP_INIT_INT(name, type) \
+ mp_err mp_init_##name(mp_int * a, type b) \
+ { \
+ mp_err err; \
+ if ((err = mp_init(a)) != MP_OKAY) { \
+ return err; \
+ } \
+ mp_set_##name(a, b); \
+ return MP_OKAY; \
+ }
+#define MP_GET_MAG(w) \
+ uint##w##_t mp_get_mag##w(const mp_int* a) \
+ { \
+ unsigned i = MP_MIN((unsigned)a->used, (unsigned)((w + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)); \
+ uint##w##_t res = 0; \
+ while (i --> 0) { \
+ res <<= ((w <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
+ res |= (uint##w##_t)a->dp[i]; \
+ if (w <= MP_DIGIT_BIT) { break; } \
+ } \
+ return res; \
+ }
+#define MP_GET_SIGNED(w) \
+ int##w##_t mp_get_i##w(const mp_int* a) \
+ { \
+ uint64_t res = mp_get_mag##w(a); \
+ return a->sign == MP_NEG ? (int##w##_t)-res : (int##w##_t)res; \
+ }
+
+#ifdef BN_MP_SET_U32_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_SET_UNSIGNED(32)
+#endif
+
+#ifdef BN_MP_SET_U64_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
+MP_SET_UNSIGNED(64)
+#endif
+
+#ifdef BN_MP_SET_I32_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_SET_SIGNED(32)
+#endif
+
+#ifdef BN_MP_SET_I64_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_SET_SIGNED(64)
+#endif
+
+#ifdef BN_MP_GET_I32_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_GET_SIGNED(32)
+#endif
+
+#ifdef BN_MP_GET_I64_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_GET_SIGNED(64)
+#endif
-/* set to a digit */
-void mp_set(mp_int *a, mp_digit b)
-{
- mp_zero(a);
- a->dp[0] = b & MP_MASK;
- a->used = (a->dp[0] != 0u) ? 1 : 0;
-}
+#ifdef BN_MP_GET_MAG32_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_GET_MAG(32)
+#endif
+
+#ifdef BN_MP_GET_MAG64_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_GET_MAG(64)
+#endif
+
+#ifdef BN_MP_INIT_U32_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_INIT_INT(u32, uint32_t)
+#endif
+
+#ifdef BN_MP_INIT_U64_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_INIT_INT(u64, uint64_t)
+#endif
+
+#ifdef BN_MP_INIT_I32_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_INIT_INT(i32, int32_t)
+#endif
+
+#ifdef BN_MP_INIT_I64_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+MP_INIT_INT(i64, int64_t)
#endif
diff --git a/bn_mp_set_double.c b/bn_mp_set_double.c
index 9e00362ba..a42fc70d9 100644
--- a/bn_mp_set_double.c
+++ b/bn_mp_set_double.c
@@ -23,7 +23,7 @@ mp_err mp_set_double(mp_int *a, double b)
}
exp -= 1023 + 52;
- mp_set_long_long(a, frac);
+ mp_set_u64(a, frac);
err = (exp < 0) ? mp_div_2d(a, -exp, a, NULL) : mp_mul_2d(a, exp, a);
if (err != MP_OKAY) {
diff --git a/bn_mp_set_int.c b/bn_mp_set_int.c
deleted file mode 100644
index f0c7434d6..000000000
--- a/bn_mp_set_int.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_SET_INT_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-/* set a 32-bit const */
-mp_err mp_set_int(mp_int *a, unsigned long b)
-{
- return mp_set_long(a, b & 0xFFFFFFFFuL);
-}
-#endif
diff --git a/bn_mp_set_long.c b/bn_mp_set_long.c
deleted file mode 100644
index e5d45d84b..000000000
--- a/bn_mp_set_long.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_SET_LONG_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-MP_SET_XLONG(mp_set_long, unsigned long)
-#endif
diff --git a/bn_mp_set_long_long.c b/bn_mp_set_long_long.c
deleted file mode 100644
index 6beecd8ea..000000000
--- a/bn_mp_set_long_long.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_SET_LONG_LONG_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-/* set a platform dependent unsigned long long int */
-MP_SET_XLONG(mp_set_long_long, unsigned long long)
-#endif
diff --git a/bn_mp_sqrtmod_prime.c b/bn_mp_sqrtmod_prime.c
index 26770ae00..6d42b9802 100644
--- a/bn_mp_sqrtmod_prime.c
+++ b/bn_mp_sqrtmod_prime.c
@@ -59,7 +59,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
}
/* find a Z such that the Legendre symbol (Z|prime) == -1 */
- mp_set_int(&Z, 2uL);
+ mp_set_u(&Z, 2uL);
/* Z = 2 */
while (1) {
if ((err = mp_kronecker(&Z, prime, &legendre)) != MP_OKAY) goto cleanup;
@@ -79,7 +79,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
/* T = n ^ Q mod prime */
if ((err = mp_copy(&S, &M)) != MP_OKAY) goto cleanup;
/* M = S */
- mp_set_int(&two, 2uL);
+ mp_set_u(&two, 2uL);
while (1) {
if ((err = mp_copy(&T, &t1)) != MP_OKAY) goto cleanup;
@@ -106,7 +106,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
/* R = (R * t1) mod prime */
if ((err = mp_mulmod(&T, &C, prime, &T)) != MP_OKAY) goto cleanup;
/* T = (T * C) mod prime */
- mp_set(&M, i);
+ mp_set_u(&M, (uint32_t)i);
/* M = i */
}
diff --git a/bn_s_mp_exptmod.c b/bn_s_mp_exptmod.c
index b1cc0e948..890946814 100644
--- a/bn_s_mp_exptmod.c
+++ b/bn_s_mp_exptmod.c
@@ -123,7 +123,7 @@ mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y
if ((err = mp_init(&res)) != MP_OKAY) {
goto LBL_MU;
}
- mp_set(&res, 1uL);
+ mp_set_u(&res, 1uL);
/* set initial mode and bit cnt */
mode = 0;
diff --git a/bn_s_mp_exptmod_fast.c b/bn_s_mp_exptmod_fast.c
index 6b4483c09..875c97355 100644
--- a/bn_s_mp_exptmod_fast.c
+++ b/bn_s_mp_exptmod_fast.c
@@ -149,7 +149,7 @@ mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_i
goto LBL_RES;
#endif
} else {
- mp_set(&res, 1uL);
+ mp_set_u(&res, 1uL);
if ((err = mp_mod(G, P, &M[1])) != MP_OKAY) {
goto LBL_RES;
}
diff --git a/bn_s_mp_invmod_fast.c b/bn_s_mp_invmod_fast.c
index be7813c96..e32ace517 100644
--- a/bn_s_mp_invmod_fast.c
+++ b/bn_s_mp_invmod_fast.c
@@ -48,7 +48,7 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
if ((err = mp_copy(&y, &v)) != MP_OKAY) {
goto LBL_ERR;
}
- mp_set(&D, 1uL);
+ mp_set_u(&D, 1uL);
top:
/* 4. while u is even do */
diff --git a/bn_s_mp_invmod_slow.c b/bn_s_mp_invmod_slow.c
index faf62213c..45474bc85 100644
--- a/bn_s_mp_invmod_slow.c
+++ b/bn_s_mp_invmod_slow.c
@@ -41,8 +41,8 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
if ((err = mp_copy(&y, &v)) != MP_OKAY) {
goto LBL_ERR;
}
- mp_set(&A, 1uL);
- mp_set(&D, 1uL);
+ mp_set_u(&A, 1uL);
+ mp_set_u(&D, 1uL);
top:
/* 4. while u is even do */
diff --git a/libtommath_VS2008.vcproj b/libtommath_VS2008.vcproj
index 84e0b16e9..7ffc66b19 100644
--- a/libtommath_VS2008.vcproj
+++ b/libtommath_VS2008.vcproj
@@ -464,18 +464,6 @@
RelativePath="bn_mp_get_double.c"
>
-
-
-
-
-
-
@@ -504,14 +492,6 @@
RelativePath="bn_mp_init_multi.c"
>
-
-
-
-
@@ -708,18 +688,6 @@
RelativePath="bn_mp_set_double.c"
>
-
-
-
-
-
-
diff --git a/makefile b/makefile
index 6dbe1ab1b..1fe56d275 100644
--- a/makefile
+++ b/makefile
@@ -31,9 +31,8 @@ bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cm
bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \
bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \
bn_mp_error_to_string.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \
-bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_int.o \
-bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_ilogb.o bn_mp_import.o bn_mp_incr.o bn_mp_init.o \
-bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o \
+bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_grow.o bn_mp_ilogb.o \
+bn_mp_import.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_size.o \
bn_mp_invmod.o bn_mp_is_square.o bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_lshd.o \
bn_mp_mod.o bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \
bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o \
@@ -44,16 +43,15 @@ bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp
bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce.o \
bn_mp_reduce_2k.o bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o \
bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o \
-bn_mp_set_double.o bn_mp_set_int.o bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o \
-bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o \
-bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \
-bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_toradix.o bn_mp_toradix_n.o \
-bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_s_mp_add.o bn_s_mp_balance_mul.o \
-bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o bn_s_mp_invmod_slow.o \
-bn_s_mp_karatsuba_mul.o bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o bn_s_mp_mul_digs.o \
-bn_s_mp_mul_digs_fast.o bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o bn_s_mp_rand_jenkins.o \
-bn_s_mp_rand_platform.o bn_s_mp_reverse.o bn_s_mp_sqr.o bn_s_mp_sqr_fast.o bn_s_mp_sub.o \
-bn_s_mp_toom_mul.o bn_s_mp_toom_sqr.o
+bn_mp_set_double.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o \
+bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o \
+bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_toradix.o \
+bn_mp_toradix_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_s_mp_add.o \
+bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o \
+bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o \
+bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o \
+bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o bn_s_mp_sqr.o bn_s_mp_sqr_fast.o \
+bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_sqr.o
#END_INS
diff --git a/makefile.mingw b/makefile.mingw
index 2ed79b3f1..25e8c2f5e 100644
--- a/makefile.mingw
+++ b/makefile.mingw
@@ -34,9 +34,8 @@ bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cm
bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \
bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \
bn_mp_error_to_string.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \
-bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_int.o \
-bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_ilogb.o bn_mp_import.o bn_mp_incr.o bn_mp_init.o \
-bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o \
+bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_grow.o bn_mp_ilogb.o \
+bn_mp_import.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_size.o \
bn_mp_invmod.o bn_mp_is_square.o bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_lshd.o \
bn_mp_mod.o bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \
bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o \
@@ -47,6 +46,15 @@ bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp
bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce.o \
bn_mp_reduce_2k.o bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o \
bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o \
+bn_mp_set_double.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o \
+bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o \
+bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_toradix.o \
+bn_mp_toradix_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_s_mp_add.o \
+bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o \
+bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o \
+bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o \
+bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o bn_s_mp_sqr.o bn_s_mp_sqr_fast.o \
+bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_sqr.o
bn_mp_set_double.o bn_mp_set_int.o bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o \
bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o \
bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \
diff --git a/makefile.msvc b/makefile.msvc
index e957530c6..afc41dd0e 100644
--- a/makefile.msvc
+++ b/makefile.msvc
@@ -26,9 +26,8 @@ bn_mp_and.obj bn_mp_clamp.obj bn_mp_clear.obj bn_mp_clear_multi.obj bn_mp_cmp.ob
bn_mp_cnt_lsb.obj bn_mp_complement.obj bn_mp_copy.obj bn_mp_count_bits.obj bn_mp_decr.obj bn_mp_div.obj bn_mp_div_2.obj \
bn_mp_div_2d.obj bn_mp_div_3.obj bn_mp_div_d.obj bn_mp_dr_is_modulus.obj bn_mp_dr_reduce.obj bn_mp_dr_setup.obj \
bn_mp_error_to_string.obj bn_mp_exch.obj bn_mp_export.obj bn_mp_expt_d.obj bn_mp_expt_d_ex.obj bn_mp_exptmod.obj \
-bn_mp_exteuclid.obj bn_mp_fread.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_double.obj bn_mp_get_int.obj \
-bn_mp_get_long.obj bn_mp_get_long_long.obj bn_mp_grow.obj bn_mp_ilogb.obj bn_mp_import.obj bn_mp_incr.obj bn_mp_init.obj \
-bn_mp_init_copy.obj bn_mp_init_multi.obj bn_mp_init_set.obj bn_mp_init_set_int.obj bn_mp_init_size.obj \
+bn_mp_exteuclid.obj bn_mp_fread.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_double.obj bn_mp_grow.obj bn_mp_ilogb.obj \
+bn_mp_import.obj bn_mp_incr.obj bn_mp_init.obj bn_mp_init_copy.obj bn_mp_init_multi.obj bn_mp_init_size.obj \
bn_mp_invmod.obj bn_mp_is_square.obj bn_mp_iseven.obj bn_mp_isodd.obj bn_mp_kronecker.obj bn_mp_lcm.obj bn_mp_lshd.obj \
bn_mp_mod.obj bn_mp_mod_2d.obj bn_mp_mod_d.obj bn_mp_montgomery_calc_normalization.obj bn_mp_montgomery_reduce.obj \
bn_mp_montgomery_setup.obj bn_mp_mul.obj bn_mp_mul_2.obj bn_mp_mul_2d.obj bn_mp_mul_d.obj bn_mp_mulmod.obj \
@@ -39,6 +38,15 @@ bn_mp_prime_rand.obj bn_mp_prime_strong_lucas_selfridge.obj bn_mp_radix_size.obj
bn_mp_rand.obj bn_mp_read_radix.obj bn_mp_read_signed_bin.obj bn_mp_read_unsigned_bin.obj bn_mp_reduce.obj \
bn_mp_reduce_2k.obj bn_mp_reduce_2k_l.obj bn_mp_reduce_2k_setup.obj bn_mp_reduce_2k_setup_l.obj \
bn_mp_reduce_is_2k.obj bn_mp_reduce_is_2k_l.obj bn_mp_reduce_setup.obj bn_mp_rshd.obj bn_mp_set.obj \
+bn_mp_set_double.obj bn_mp_shrink.obj bn_mp_signed_bin_size.obj bn_mp_signed_rsh.obj bn_mp_sqr.obj bn_mp_sqrmod.obj \
+bn_mp_sqrt.obj bn_mp_sqrtmod_prime.obj bn_mp_sub.obj bn_mp_sub_d.obj bn_mp_submod.obj bn_mp_to_signed_bin.obj \
+bn_mp_to_signed_bin_n.obj bn_mp_to_unsigned_bin.obj bn_mp_to_unsigned_bin_n.obj bn_mp_toradix.obj \
+bn_mp_toradix_n.obj bn_mp_unsigned_bin_size.obj bn_mp_xor.obj bn_mp_zero.obj bn_prime_tab.obj bn_s_mp_add.obj \
+bn_s_mp_balance_mul.obj bn_s_mp_exptmod.obj bn_s_mp_exptmod_fast.obj bn_s_mp_get_bit.obj bn_s_mp_invmod_fast.obj \
+bn_s_mp_invmod_slow.obj bn_s_mp_karatsuba_mul.obj bn_s_mp_karatsuba_sqr.obj bn_s_mp_montgomery_reduce_fast.obj \
+bn_s_mp_mul_digs.obj bn_s_mp_mul_digs_fast.obj bn_s_mp_mul_high_digs.obj bn_s_mp_mul_high_digs_fast.obj \
+bn_s_mp_rand_jenkins.obj bn_s_mp_rand_platform.obj bn_s_mp_reverse.obj bn_s_mp_sqr.obj bn_s_mp_sqr_fast.obj \
+bn_s_mp_sub.obj bn_s_mp_toom_mul.obj bn_s_mp_toom_sqr.obj
bn_mp_set_double.obj bn_mp_set_int.obj bn_mp_set_long.obj bn_mp_set_long_long.obj bn_mp_shrink.obj \
bn_mp_signed_bin_size.obj bn_mp_signed_rsh.obj bn_mp_sqr.obj bn_mp_sqrmod.obj bn_mp_sqrt.obj bn_mp_sqrtmod_prime.obj \
bn_mp_sub.obj bn_mp_sub_d.obj bn_mp_submod.obj bn_mp_to_signed_bin.obj bn_mp_to_signed_bin_n.obj \
diff --git a/makefile.shared b/makefile.shared
index 371291b78..a0e9213dc 100644
--- a/makefile.shared
+++ b/makefile.shared
@@ -28,9 +28,8 @@ bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cm
bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \
bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \
bn_mp_error_to_string.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \
-bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_int.o \
-bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_ilogb.o bn_mp_import.o bn_mp_incr.o bn_mp_init.o \
-bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o \
+bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_grow.o bn_mp_ilogb.o \
+bn_mp_import.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_size.o \
bn_mp_invmod.o bn_mp_is_square.o bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_lshd.o \
bn_mp_mod.o bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \
bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o \
@@ -41,6 +40,15 @@ bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp
bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce.o \
bn_mp_reduce_2k.o bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o \
bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o \
+bn_mp_set_double.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o \
+bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o \
+bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_toradix.o \
+bn_mp_toradix_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_s_mp_add.o \
+bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o \
+bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o \
+bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o \
+bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o bn_s_mp_sqr.o bn_s_mp_sqr_fast.o \
+bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_sqr.o
bn_mp_set_double.o bn_mp_set_int.o bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o \
bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o \
bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \
@@ -102,7 +110,3 @@ tune: $(LIBNAME)
$(LTLINK) $(LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
cd etc/; /bin/sh tune_it.sh; cd ..
$(MAKE) -f makefile.shared
-
-
-
-
diff --git a/makefile.unix b/makefile.unix
index 2831040dd..03e302686 100644
--- a/makefile.unix
+++ b/makefile.unix
@@ -35,9 +35,8 @@ bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cm
bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \
bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \
bn_mp_error_to_string.o bn_mp_exch.o bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o \
-bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_int.o \
-bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_ilogb.o bn_mp_import.o bn_mp_incr.o bn_mp_init.o \
-bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_set_int.o bn_mp_init_size.o \
+bn_mp_exteuclid.o bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_grow.o bn_mp_ilogb.o \
+bn_mp_import.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_size.o \
bn_mp_invmod.o bn_mp_is_square.o bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_lshd.o \
bn_mp_mod.o bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \
bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o \
@@ -48,6 +47,15 @@ bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp
bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce.o \
bn_mp_reduce_2k.o bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o \
bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o \
+bn_mp_set_double.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o \
+bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o \
+bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_toradix.o \
+bn_mp_toradix_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_prime_tab.o bn_s_mp_add.o \
+bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o \
+bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o \
+bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o \
+bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o bn_s_mp_sqr.o bn_s_mp_sqr_fast.o \
+bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_sqr.o
bn_mp_set_double.o bn_mp_set_int.o bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o \
bn_mp_signed_bin_size.o bn_mp_signed_rsh.o bn_mp_sqr.o bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o \
bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \
@@ -102,4 +110,3 @@ install: $(LIBMAIN_S)
@cp $(LIBMAIN_S) $(DESTDIR)$(LIBPATH)/
@cp $(HEADERS_PUB) $(DESTDIR)$(INCPATH)/
@sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtommath.pc.in > $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
-
diff --git a/tommath.h b/tommath.h
index 2349306d6..b287dda62 100644
--- a/tommath.h
+++ b/tommath.h
@@ -270,38 +270,64 @@ mp_bool mp_isodd(const mp_int *a) MP_WUR;
/* set to zero */
void mp_zero(mp_int *a);
-/* set to a digit */
-void mp_set(mp_int *a, mp_digit b);
-
-/* set a double */
-mp_err mp_set_double(mp_int *a, double b) MP_WUR;
-
-/* set a 32-bit const */
-/* TODO void - never fails */ mp_err mp_set_int(mp_int *a, unsigned long b);
-
-/* set a platform dependent unsigned long value */
-/* TODO void - never fails */ mp_err mp_set_long(mp_int *a, unsigned long b);
-
-/* set a platform dependent unsigned long long value */
-/* TODO void - never fails */ mp_err mp_set_long_long(mp_int *a, unsigned long long b);
-
-/* get a double */
+/* get and set doubles */
double mp_get_double(const mp_int *a) MP_WUR;
+mp_err mp_set_double(mp_int *a, double b) MP_WUR;
-/* get a 32-bit value */
-unsigned long mp_get_int(const mp_int *a) MP_WUR;
-
-/* get a platform dependent unsigned long value */
-unsigned long mp_get_long(const mp_int *a) MP_WUR;
-
-/* get a platform dependent unsigned long long value */
-unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
-
-/* initialize and set a digit */
-mp_err mp_init_set(mp_int *a, mp_digit b) MP_WUR;
-
-/* initialize and set 32-bit value */
-mp_err mp_init_set_int(mp_int *a, unsigned long b) MP_WUR;
+/* get integer, set integer and init with integer (int32_t) */
+int32_t mp_get_i32(const mp_int *a) MP_WUR;
+void mp_set_i32(mp_int *a, int32_t b);
+mp_err mp_init_i32(mp_int *a, int32_t b) MP_WUR;
+
+/* get integer, set integer and init with integer (int64_t) */
+int64_t mp_get_i64(const mp_int *a) MP_WUR;
+void mp_set_i64(mp_int *a, int64_t b);
+mp_err mp_init_i64(mp_int *a, int64_t b) MP_WUR;
+
+/* get integer, set integer and init with integer, behaves like two complement for negative numbers (uint32_t) */
+#define mp_get_u32(a) ((uint32_t)mp_get_i32(a))
+void mp_set_u32(mp_int *a, uint32_t b);
+mp_err mp_init_u32(mp_int *a, uint32_t b) MP_WUR;
+
+/* get integer, set integer and init with integer, behaves like two complement for negative numbers (uint64_t) */
+#define mp_get_u64(a) ((uint64_t)mp_get_i64(a))
+void mp_set_u64(mp_int *a, uint64_t b);
+mp_err mp_init_u64(mp_int *a, uint64_t b) MP_WUR;
+
+/* get magnitude */
+uint32_t mp_get_mag32(const mp_int *a) MP_WUR;
+uint64_t mp_get_mag64(const mp_int *a) MP_WUR;
+
+/* get integer, set integer and init with integer (int) */
+#define mp_get_i(a) ((int)mp_get_i32(a))
+#define mp_set_i(a, b) mp_set_i32((a), (b))
+#define mp_init_i(a, b) mp_init_set_i32((a), (b))
+
+/* get integer, set integer (unsigned int) */
+#define mp_get_u(a) ((unsigned)mp_get_u32(a))
+#define mp_set_u(a, b) mp_set_u32((a), (b))
+#define mp_init_u(a, b) mp_init_u32((a), (b))
+
+/* get integer, set integer (long) */
+#define mp_get_l(a) (sizeof (long) == sizeof (int64_t) ? (long)mp_get_i64(a) : (long)mp_get_i32(a))
+#define mp_set_l(a, b) (sizeof (long) == sizeof (int64_t) ? mp_set_i64((a), (b)) : mp_set_i32((a), (int32_t)(b)))
+#define mp_init_l(a, b) (sizeof (long) == sizeof (int64_t) ? mp_init_i64((a), (b)) : mp_init_i32((a), (int32_t)(b)))
+
+/* get integer, set integer (unsigned long) */
+#define mp_get_ul(a) (sizeof (long) == sizeof (int64_t) ? (unsigned long)mp_get_u64(a) : (unsigned long)mp_get_u32(a))
+#define mp_set_ul(a, b) (sizeof (long) == sizeof (int64_t) ? mp_set_u64((a), (b)) : mp_set_u32((a), (uint32_t)(b)))
+#define mp_init_ul(a, b) (sizeof (long) == sizeof (int64_t) ? mp_init_u64((a), (b)) : mp_init_u32((a), (uint32_t)(b)))
+
+/* get integer, set integer and init with integer (deprecated) */
+MP_DEPRECATED(mp_get_u32) unsigned long mp_get_int(const mp_int *a) MP_WUR;
+MP_DEPRECATED(mp_get_u32) unsigned long mp_get_long(const mp_int *a) MP_WUR;
+MP_DEPRECATED(mp_get_u64) unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
+MP_DEPRECATED(mp_set_u64) void mp_set(mp_int *a, mp_digit b);
+MP_DEPRECATED(mp_set_u32) mp_err mp_set_int(mp_int *a, unsigned long b);
+MP_DEPRECATED(mp_set_u32) mp_err mp_set_long(mp_int *a, unsigned long b);
+MP_DEPRECATED(mp_set_u64) mp_err mp_set_long_long(mp_int *a, unsigned long long b);
+MP_DEPRECATED(mp_init_i64) mp_err mp_init_set(mp_int *a, mp_digit b) MP_WUR;
+MP_DEPRECATED(mp_init_i64) mp_err mp_init_set_int(mp_int *a, unsigned long b) MP_WUR;
/* copy, b = a */
mp_err mp_copy(const mp_int *a, mp_int *b) MP_WUR;
diff --git a/tommath_class.h b/tommath_class.h
index b7e59b255..b3de955cc 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -48,9 +48,6 @@
# define BN_MP_FWRITE_C
# define BN_MP_GCD_C
# define BN_MP_GET_DOUBLE_C
-# define BN_MP_GET_INT_C
-# define BN_MP_GET_LONG_C
-# define BN_MP_GET_LONG_LONG_C
# define BN_MP_GROW_C
# define BN_MP_ILOGB_C
# define BN_MP_IMPORT_C
@@ -58,8 +55,6 @@
# define BN_MP_INIT_C
# define BN_MP_INIT_COPY_C
# define BN_MP_INIT_MULTI_C
-# define BN_MP_INIT_SET_C
-# define BN_MP_INIT_SET_INT_C
# define BN_MP_INIT_SIZE_C
# define BN_MP_INVMOD_C
# define BN_MP_IS_SQUARE_C
@@ -109,9 +104,6 @@
# define BN_MP_RSHD_C
# define BN_MP_SET_C
# define BN_MP_SET_DOUBLE_C
-# define BN_MP_SET_INT_C
-# define BN_MP_SET_LONG_C
-# define BN_MP_SET_LONG_LONG_C
# define BN_MP_SHRINK_C
# define BN_MP_SIGNED_BIN_SIZE_C
# define BN_MP_SIGNED_RSH_C
@@ -202,6 +194,22 @@
# define BN_MP_XOR_C
# define BN_MP_TC_DIV_2D_C
# define BN_MP_SIGNED_RSH_C
+# define BN_MP_INIT_SET_INT_C
+# define BN_MP_INIT_U32_C
+# define BN_MP_INIT_SET_C
+# define BN_MP_INIT_U64_C
+# define BN_MP_SET_C
+# define BN_MP_SET_U64_C
+# define BN_MP_SET_INT_C
+# define BN_MP_SET_U32_C
+# define BN_MP_SET_LONG_C
+# define BN_MP_SET_LONG_LONG_C
+# define BN_MP_GET_INT_C
+# define BN_MP_GET_U32_C
+# define BN_MP_GET_LONG_C
+# define BN_MP_GET_MAG64_C
+# define BN_MP_GET_MAG32_C
+# define BN_MP_GET_LONG_LONG_C
#endif
#if defined(BN_MP_2EXPT_C)
@@ -273,7 +281,7 @@
#endif
#if defined(BN_MP_DECR_C)
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_INCR_C
# define BN_MP_ZERO_C
# define BN_MP_SUB_D_C
@@ -366,7 +374,7 @@
#if defined(BN_MP_EXPT_D_EX_C)
# define BN_MP_INIT_COPY_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_MUL_C
# define BN_MP_CLEAR_C
# define BN_MP_SQR_C
@@ -387,7 +395,7 @@
#if defined(BN_MP_EXTEUCLID_C)
# define BN_MP_INIT_MULTI_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_COPY_C
# define BN_MP_DIV_C
# define BN_MP_MUL_C
@@ -424,25 +432,16 @@
#if defined(BN_MP_GET_DOUBLE_C)
#endif
-#if defined(BN_MP_GET_INT_C)
-# define BN_MP_GET_LONG_C
-#endif
-
-#if defined(BN_MP_GET_LONG_C)
-#endif
-
-#if defined(BN_MP_GET_LONG_LONG_C)
-#endif
-
#if defined(BN_MP_GROW_C)
#endif
#if defined(BN_MP_ILOGB_C)
-# define BN_MP_SET_INT_C
+# define BN_MP_SET_I_C
# define BN_MP_COUNT_BITS_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U64_C
# define BN_MP_CMP_D_C
# define BN_MP_ZERO_C
+# define BN_MP_SET_U_C
# define BN_MP_INIT_MULTI_C
# define BN_MP_CMP_C
# define BN_MP_COPY_C
@@ -460,7 +459,7 @@
#endif
#if defined(BN_MP_INCR_C)
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_DECR_C
# define BN_MP_ADD_D_C
#endif
@@ -479,16 +478,6 @@
# define BN_MP_CLEAR_C
#endif
-#if defined(BN_MP_INIT_SET_C)
-# define BN_MP_INIT_C
-# define BN_MP_SET_C
-#endif
-
-#if defined(BN_MP_INIT_SET_INT_C)
-# define BN_MP_INIT_C
-# define BN_MP_SET_INT_C
-#endif
-
#if defined(BN_MP_INIT_SIZE_C)
#endif
@@ -500,9 +489,9 @@
#if defined(BN_MP_IS_SQUARE_C)
# define BN_MP_MOD_D_C
-# define BN_MP_INIT_SET_INT_C
+# define BN_MP_INIT_U_C
# define BN_MP_MOD_C
-# define BN_MP_GET_INT_C
+# define BN_MP_GET_U_C
# define BN_MP_SQRT_C
# define BN_MP_SQR_C
# define BN_MP_CMP_MAG_C
@@ -559,7 +548,7 @@
#if defined(BN_MP_MONTGOMERY_CALC_NORMALIZATION_C)
# define BN_MP_COUNT_BITS_C
# define BN_MP_2EXPT_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_MUL_2_C
# define BN_MP_CMP_MAG_C
# define BN_S_MP_SUB_C
@@ -615,7 +604,7 @@
#if defined(BN_MP_N_ROOT_EX_C)
# define BN_MP_INIT_MULTI_C
# define BN_MP_COUNT_BITS_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_2EXPT_C
# define BN_MP_COPY_C
# define BN_MP_EXPT_D_EX_C
@@ -649,13 +638,12 @@
#if defined(BN_MP_PRIME_FROBENIUS_UNDERWOOD_C)
# define BN_MP_INIT_MULTI_C
-# define BN_MP_SET_LONG_C
+# define BN_MP_SET_U_C
# define BN_MP_SQR_C
# define BN_MP_SUB_D_C
# define BN_MP_KRONECKER_C
# define BN_MP_GCD_C
# define BN_MP_ADD_D_C
-# define BN_MP_SET_C
# define BN_MP_COUNT_BITS_C
# define BN_MP_MUL_2_C
# define BN_MP_MUL_D_C
@@ -677,13 +665,13 @@
# define BN_MP_IS_SQUARE_C
# define BN_MP_CMP_D_C
# define BN_MP_PRIME_IS_DIVISIBLE_C
-# define BN_MP_INIT_SET_C
+# define BN_MP_INIT_U_C
# define BN_MP_PRIME_MILLER_RABIN_C
# define BN_MP_PRIME_FROBENIUS_UNDERWOOD_C
# define BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C
# define BN_MP_READ_RADIX_C
# define BN_MP_CMP_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_COUNT_BITS_C
# define BN_MP_RAND_C
# define BN_MP_DIV_2D_C
@@ -704,7 +692,7 @@
#if defined(BN_MP_PRIME_NEXT_PRIME_C)
# define BN_MP_CMP_D_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_SUB_D_C
# define BN_MP_MOD_D_C
# define BN_MP_INIT_C
@@ -731,10 +719,11 @@
#if defined(BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C)
# define BN_S_MP_MUL_SI_C
# define BN_MP_INIT_C
-# define BN_MP_SET_LONG_C
+# define BN_MP_SET_I_C
# define BN_MP_MUL_C
# define BN_MP_CLEAR_C
# define BN_MP_INIT_MULTI_C
+# define BN_MP_SET_U_C
# define BN_MP_GCD_C
# define BN_MP_CMP_D_C
# define BN_MP_CMP_C
@@ -742,7 +731,6 @@
# define BN_MP_ADD_D_C
# define BN_MP_CNT_LSB_C
# define BN_MP_DIV_2D_C
-# define BN_MP_SET_C
# define BN_MP_MUL_2_C
# define BN_MP_COUNT_BITS_C
# define BN_MP_MOD_C
@@ -799,7 +787,7 @@
# define BN_S_MP_MUL_DIGS_C
# define BN_MP_SUB_C
# define BN_MP_CMP_D_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_LSHD_C
# define BN_MP_ADD_C
# define BN_MP_CMP_C
@@ -862,25 +850,15 @@
#endif
#if defined(BN_MP_SET_C)
-# define BN_MP_ZERO_C
+# define BN_MP_INIT_C
#endif
#if defined(BN_MP_SET_DOUBLE_C)
-# define BN_MP_SET_LONG_LONG_C
+# define BN_MP_SET_U64_C
# define BN_MP_DIV_2D_C
# define BN_MP_MUL_2D_C
#endif
-#if defined(BN_MP_SET_INT_C)
-# define BN_MP_SET_LONG_C
-#endif
-
-#if defined(BN_MP_SET_LONG_C)
-#endif
-
-#if defined(BN_MP_SET_LONG_LONG_C)
-#endif
-
#if defined(BN_MP_SHRINK_C)
#endif
@@ -931,10 +909,10 @@
# define BN_MP_EXPTMOD_C
# define BN_MP_COPY_C
# define BN_MP_SUB_D_C
-# define BN_MP_SET_INT_C
+# define BN_MP_SET_U_C
# define BN_MP_SQRMOD_C
# define BN_MP_MULMOD_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U64_C
# define BN_MP_CLEAR_MULTI_C
#endif
@@ -1033,7 +1011,7 @@
# define BN_MP_COPY_C
# define BN_MP_SQR_C
# define BN_MP_MUL_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_EXCH_C
#endif
@@ -1046,7 +1024,7 @@
# define BN_MP_REDUCE_2K_SETUP_C
# define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
# define BN_MP_MULMOD_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_MOD_C
# define BN_MP_COPY_C
# define BN_MP_SQR_C
@@ -1061,7 +1039,7 @@
# define BN_MP_INIT_MULTI_C
# define BN_MP_COPY_C
# define BN_MP_MOD_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_DIV_2_C
# define BN_MP_SUB_C
# define BN_MP_CMP_C
@@ -1076,7 +1054,7 @@
# define BN_MP_INIT_MULTI_C
# define BN_MP_MOD_C
# define BN_MP_COPY_C
-# define BN_MP_SET_C
+# define BN_MP_SET_U_C
# define BN_MP_DIV_2_C
# define BN_MP_ADD_C
# define BN_MP_SUB_C
diff --git a/tommath_private.h b/tommath_private.h
index 260062f05..937811cf8 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -198,26 +198,6 @@ extern MP_PRIVATE const char *const mp_s_rmap;
extern MP_PRIVATE const uint8_t mp_s_rmap_reverse[];
extern MP_PRIVATE const size_t mp_s_rmap_reverse_sz;
-/* Fancy macro to set an MPI from another type.
- * There are several things assumed:
- * x is the counter
- * a is the pointer to the MPI
- * b is the original value that should be set in the MPI.
- */
-#define MP_SET_XLONG(func_name, type) \
-mp_err func_name (mp_int * a, type b) \
-{ \
- int x = 0; \
- mp_zero(a); \
- while (b != 0u) { \
- a->dp[x++] = ((mp_digit)b & MP_MASK); \
- if (MP_SIZEOF_BITS(b) <= MP_DIGIT_BIT) { break; } \
- b >>= ((MP_SIZEOF_BITS(b) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
- } \
- a->used = x; \
- return MP_OKAY; \
-}
-
/* deprecated functions */
MP_DEPRECATED(s_mp_invmod_fast) mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c);
MP_DEPRECATED(s_mp_montgomery_reduce_fast) mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n,