Merge pull request #285 from libtom/set-int3

introduce mp_set_sint and mp_set_uint functions with precise types
This commit is contained in:
Steffen Jaeckel 2019-05-24 11:23:24 +02:00 committed by GitHub
commit 20ae9fbafd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 603 additions and 466 deletions

4
.gitignore vendored
View File

@ -53,6 +53,10 @@ UpgradeLog*.htm
*.vspx
*.sap
# Linux perf profiler
perf.data
perf.data.old
# ignore mpi.c generated by make
mpi.c

103
bn_conversion.c Normal file
View File

@ -0,0 +1,103 @@
#include "tommath_private.h"
#ifdef BN_CONVERSION_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#define MP_SET_UNSIGNED(name, w) \
void name(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->used, a->alloc - a->used); \
}
#define MP_SET_SIGNED(name, uname, w) \
void name(mp_int * a, int##w##_t b) \
{ \
uname(a, b < 0 ? -(uint##w##_t)b : (uint##w##_t)b); \
if (b < 0) { a->sign = MP_NEG; } \
}
#define MP_INIT_INT(name , set, type) \
mp_err name(mp_int * a, type b) \
{ \
mp_err err; \
if ((err = mp_init(a)) != MP_OKAY) { \
return err; \
} \
set(a, b); \
return MP_OKAY; \
}
#define MP_GET_MAG(name, w) \
uint##w##_t name(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(name, mag, w) \
int##w##_t name(const mp_int* a) \
{ \
uint64_t res = mag(a); \
return a->sign == MP_NEG ? (int##w##_t)-res : (int##w##_t)res; \
}
#ifdef BN_MP_SET_U32_C
MP_SET_UNSIGNED(mp_set_u32, 32)
#endif
#ifdef BN_MP_SET_U64_C
MP_SET_UNSIGNED(mp_set_u64, 64)
#endif
#ifdef BN_MP_SET_I32_C
MP_SET_SIGNED(mp_set_i32, mp_set_u32, 32)
#endif
#ifdef BN_MP_SET_I64_C
MP_SET_SIGNED(mp_set_i64, mp_set_u64, 64)
#endif
#if defined(BN_MP_GET_I32_C) || defined(BN_MP_GET_U32_C)
MP_GET_SIGNED(mp_get_i32, mp_get_mag32, 32)
#endif
#if defined(BN_MP_GET_I64_C) || defined(BN_MP_GET_U64_C)
MP_GET_SIGNED(mp_get_i64, mp_get_mag64, 64)
#endif
#ifdef BN_MP_GET_MAG32_C
MP_GET_MAG(mp_get_mag32, 32)
#endif
#ifdef BN_MP_GET_MAG64_C
MP_GET_MAG(mp_get_mag64, 64)
#endif
#ifdef BN_MP_INIT_U32_C
MP_INIT_INT(mp_init_u32, mp_set_u32, uint32_t)
#endif
#ifdef BN_MP_INIT_I32_C
MP_INIT_INT(mp_init_i32, mp_set_i32, int32_t)
#endif
#ifdef BN_MP_INIT_U64_C
MP_INIT_INT(mp_init_u64, mp_set_u64, uint64_t)
#endif
#ifdef BN_MP_INIT_I64_C
MP_INIT_INT(mp_init_i64, mp_set_i64, int64_t)
#endif
#endif

View File

@ -146,4 +146,49 @@ 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_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_mag32(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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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_u32(c, (uint32_t)(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(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(c, 1u);
return err;
}
@ -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_u32(c, mid);
goto LBL_END;
}
}
if (mp_cmp(&bracket_high, a) == MP_EQ) {
mp_set_int(c, (unsigned long)high);
mp_set_u32(c, high);
} else {
mp_set_int(c, (unsigned long)low);
mp_set_u32(c, low);
}
LBL_END:

View File

@ -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

View File

@ -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_u32(&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_u32(&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

View File

@ -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_u32(&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_u32(&T1z, (uint32_t)((a+4)*((2*a)+5)));
if ((err = mp_gcd(N, &T1z, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
@ -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_u32(&T1z, (uint32_t)((2 * a) + 5));
if ((err = mp_mod(&T1z, N, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
}

View File

@ -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_i32(&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_u32(&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(&Uz, 1u); /* U=U_1 */
mp_set(&Vz, (mp_digit)P); /* V=V_1 */
mp_set(&U2mz, 1uL); /* U_1 */
mp_set(&U2mz, 1u); /* U_1 */
mp_set(&V2mz, (mp_digit)P); /* V_1 */
if (Q < 0) {
Q = -Q;
mp_set_long(&Qmz, (unsigned long)Q);
mp_set_u32(&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_u32(&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_u32(&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_u32(&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) {

View File

@ -6,8 +6,9 @@
/* set to a digit */
void mp_set(mp_int *a, mp_digit b)
{
mp_zero(a);
a->dp[0] = b & MP_MASK;
a->sign = MP_ZPOS;
a->used = (a->dp[0] != 0u) ? 1 : 0;
MP_ZERO_DIGITS(a->dp + a->used, a->alloc - a->used);
}
#endif

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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_u32(&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_u32(&two, 2uL);
while (1) {
if ((err = mp_copy(&T, &t1)) != MP_OKAY) goto cleanup;

View File

@ -20,11 +20,41 @@ static int rand_int(void)
return x;
}
static int32_t rand_int32(void)
{
int32_t x;
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
fprintf(stderr, "s_mp_rand_source failed\n");
exit(EXIT_FAILURE);
}
return x;
}
static int64_t rand_int64(void)
{
int64_t x;
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
fprintf(stderr, "s_mp_rand_source failed\n");
exit(EXIT_FAILURE);
}
return x;
}
static unsigned long ulabs(long x)
{
return x > 0 ? (unsigned long)x : -(unsigned long)x;
}
static uint32_t uabs32(int32_t x)
{
return x > 0 ? (uint32_t)x : -(uint32_t)x;
}
static uint64_t uabs64(int64_t x)
{
return x > 0 ? (uint64_t)x : -(uint64_t)x;
}
static int test_trivial_stuff(void)
{
mp_int a, b, c, d;
@ -35,7 +65,7 @@ static int test_trivial_stuff(void)
(void)mp_error_to_string(e);
/* a: 0->5 */
mp_set_int(&a, 5uL);
mp_set(&a, 5u);
/* a: 5-> b: -5 */
mp_neg(&a, &b);
if (mp_cmp(&a, &b) != MP_GT) {
@ -59,33 +89,39 @@ static int test_trivial_stuff(void)
if (mp_isneg(&b) != MP_YES) {
goto LBL_ERR;
}
if (mp_get_int(&b) != 4) {
if (mp_get_i32(&b) != -4) {
goto LBL_ERR;
}
if (mp_get_u32(&b) != (uint32_t)-4) {
goto LBL_ERR;
}
if (mp_get_mag32(&b) != 4) {
goto LBL_ERR;
}
/* a: -5-> b: 1 */
mp_add_d(&a, 6uL, &b);
if (mp_get_int(&b) != 1) {
if (mp_get_u32(&b) != 1) {
goto LBL_ERR;
}
/* a: -5-> a: 1 */
mp_add_d(&a, 6uL, &a);
if (mp_get_int(&a) != 1) {
if (mp_get_u32(&a) != 1) {
goto LBL_ERR;
}
mp_zero(&a);
/* a: 0-> a: 6 */
mp_add_d(&a, 6uL, &a);
if (mp_get_int(&a) != 6) {
if (mp_get_u32(&a) != 6) {
goto LBL_ERR;
}
mp_set_int(&a, 42uL);
mp_set_int(&b, 1uL);
mp_set(&a, 42u);
mp_set(&b, 1u);
mp_neg(&b, &b);
mp_set_int(&c, 1uL);
mp_set(&c, 1u);
mp_exptmod(&a, &b, &c, &d);
mp_set_int(&c, 7uL);
mp_set(&c, 7u);
mp_exptmod(&a, &b, &c, &d);
if (mp_iseven(&a) == mp_isodd(&a)) {
@ -99,6 +135,92 @@ LBL_ERR:
return EXIT_FAILURE;
}
static int check_get_set_i32(mp_int *a, int32_t b)
{
mp_set_i32(a, b);
if (mp_get_i32(a) != b) return EXIT_FAILURE;
if (mp_get_u32(a) != (uint32_t)b) return EXIT_FAILURE;
if (mp_get_mag32(a) != uabs32(b)) return EXIT_FAILURE;
mp_set_u32(a, (uint32_t)b);
if (mp_get_u32(a) != (uint32_t)b) return EXIT_FAILURE;
if (mp_get_i32(a) != (int32_t)(uint32_t)b) return EXIT_FAILURE;
return EXIT_SUCCESS;
}
static int test_mp_get_set_i32(void)
{
int i;
mp_int a;
if (mp_init(&a) != MP_OKAY) {
return EXIT_FAILURE;
}
check_get_set_i32(&a, 0);
check_get_set_i32(&a, -1);
check_get_set_i32(&a, 1);
check_get_set_i32(&a, INT32_MIN);
check_get_set_i32(&a, INT32_MAX);
for (i = 0; i < 1000; ++i) {
int32_t b = rand_int32();
if (check_get_set_i32(&a, b) != EXIT_SUCCESS) {
goto LBL_ERR;
}
}
mp_clear(&a);
return EXIT_SUCCESS;
LBL_ERR:
mp_clear(&a);
return EXIT_FAILURE;
}
static int check_get_set_i64(mp_int *a, int64_t b)
{
mp_set_i64(a, b);
if (mp_get_i64(a) != b) return EXIT_FAILURE;
if (mp_get_u64(a) != (uint64_t)b) return EXIT_FAILURE;
if (mp_get_mag64(a) != uabs64(b)) return EXIT_FAILURE;
mp_set_u64(a, (uint64_t)b);
if (mp_get_u64(a) != (uint64_t)b) return EXIT_FAILURE;
if (mp_get_i64(a) != (int64_t)(uint64_t)b) return EXIT_FAILURE;
return EXIT_SUCCESS;
}
static int test_mp_get_set_i64(void)
{
int i;
mp_int a;
if (mp_init(&a) != MP_OKAY) {
return EXIT_FAILURE;
}
check_get_set_i64(&a, 0);
check_get_set_i64(&a, -1);
check_get_set_i64(&a, 1);
check_get_set_i64(&a, INT64_MIN);
check_get_set_i64(&a, INT64_MAX);
for (i = 0; i < 1000; ++i) {
int64_t b = rand_int64();
if (check_get_set_i64(&a, b) != EXIT_SUCCESS) {
goto LBL_ERR;
}
}
mp_clear(&a);
return EXIT_SUCCESS;
LBL_ERR:
mp_clear(&a);
return EXIT_FAILURE;
}
static int test_mp_fread_fwrite(void)
{
mp_int a, b;
@ -108,7 +230,7 @@ static int test_mp_fread_fwrite(void)
return EXIT_FAILURE;
}
mp_set_int(&a, 123456uL);
mp_set_ul(&a, 123456uL);
tmp = tmpfile();
if ((e = mp_fwrite(&a, 64, tmp)) != MP_OKAY) {
goto LBL_ERR;
@ -117,7 +239,7 @@ static int test_mp_fread_fwrite(void)
if ((e = mp_fread(&b, 64, tmp)) != MP_OKAY) {
goto LBL_ERR;
}
if (mp_get_int(&b) != 123456uL) {
if (mp_get_u32(&b) != 123456uL) {
goto LBL_ERR;
}
fclose(tmp);
@ -191,8 +313,8 @@ static int test_s_mp_jacobi(void)
return EXIT_FAILURE;
}
mp_set_int(&a, 0uL);
mp_set_int(&b, 1uL);
mp_set_ul(&a, 0uL);
mp_set_ul(&b, 1uL);
if ((err = s_mp_jacobi(&a, &b, &i)) != MP_OKAY) {
printf("Failed executing s_mp_jacobi(0 | 1) %s.\n", mp_error_to_string(err));
goto LBL_ERR;
@ -202,10 +324,10 @@ static int test_s_mp_jacobi(void)
goto LBL_ERR;
}
for (cnt = 0; cnt < (int)(sizeof(jacobi)/sizeof(jacobi[0])); ++cnt) {
mp_set_int(&b, jacobi[cnt].n);
mp_set_ul(&b, jacobi[cnt].n);
/* only test positive values of a */
for (n = -5; n <= 10; ++n) {
mp_set_int(&a, (unsigned int)abs(n));
mp_set_ul(&a, (unsigned int)abs(n));
should = MP_OKAY;
if (n < 0) {
mp_neg(&a, &a);
@ -269,8 +391,8 @@ static int test_mp_kronecker(void)
return EXIT_FAILURE;
}
mp_set_int(&a, 0uL);
mp_set_int(&b, 1uL);
mp_set_ul(&a, 0uL);
mp_set_ul(&b, 1uL);
if ((err = mp_kronecker(&a, &b, &i)) != MP_OKAY) {
printf("Failed executing mp_kronecker(0 | 1) %s.\n", mp_error_to_string(err));
goto LBL_ERR;
@ -282,18 +404,18 @@ static int test_mp_kronecker(void)
for (cnt = 0; cnt < (int)(sizeof(kronecker)/sizeof(kronecker[0])); ++cnt) {
k = kronecker[cnt].n;
if (k < 0) {
mp_set_int(&a, (unsigned long)(-k));
mp_set_ul(&a, (unsigned long)(-k));
mp_neg(&a, &a);
} else {
mp_set_int(&a, (unsigned long) k);
mp_set_ul(&a, (unsigned long) k);
}
/* only test positive values of a */
for (m = -10; m <= 10; m++) {
if (m < 0) {
mp_set_int(&b,(unsigned long)(-m));
mp_set_ul(&b,(unsigned long)(-m));
mp_neg(&b, &b);
} else {
mp_set_int(&b, (unsigned long) m);
mp_set_ul(&b, (unsigned long) m);
}
if ((err = mp_kronecker(&a, &b, &i)) != MP_OKAY) {
printf("Failed executing mp_kronecker(%ld | %ld) %s.\n", kronecker[cnt].n, m, mp_error_to_string(err));
@ -324,13 +446,13 @@ static int test_mp_complement(void)
for (i = 0; i < 1000; ++i) {
long l = rand_long();
mp_set_long(&a, ulabs(l));
mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
mp_complement(&a, &b);
l = ~l;
mp_set_long(&c, ulabs(l));
mp_set_ul(&c, ulabs(l));
if (l < 0)
mp_neg(&c, &c);
@ -361,13 +483,13 @@ static int test_mp_signed_rsh(void)
int em;
l = rand_long();
mp_set_long(&a, ulabs(l));
mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = abs(rand_int()) % 32;
mp_set_long(&d, ulabs(l >> em));
mp_set_ul(&d, ulabs(l >> em));
if ((l >> em) < 0)
mp_neg(&d, &d);
@ -399,16 +521,16 @@ static int test_mp_xor(void)
long l, em;
l = rand_long();
mp_set_int(&a, ulabs(l));
mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = rand_long();
mp_set_int(&b, ulabs(em));
mp_set_ul(&b, ulabs(em));
if (em < 0)
mp_neg(&b, &b);
mp_set_int(&d, ulabs(l ^ em));
mp_set_ul(&d, ulabs(l ^ em));
if ((l ^ em) < 0)
mp_neg(&d, &d);
@ -440,16 +562,16 @@ static int test_mp_or(void)
long l, em;
l = rand_long();
mp_set_long(&a, ulabs(l));
mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = rand_long();
mp_set_long(&b, ulabs(em));
mp_set_ul(&b, ulabs(em));
if (em < 0)
mp_neg(&b, &b);
mp_set_long(&d, ulabs(l | em));
mp_set_ul(&d, ulabs(l | em));
if ((l | em) < 0)
mp_neg(&d, &d);
@ -480,16 +602,16 @@ static int test_mp_and(void)
long l, em;
l = rand_long();
mp_set_long(&a, ulabs(l));
mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = rand_long();
mp_set_long(&b, ulabs(em));
mp_set_ul(&b, ulabs(em));
if (em < 0)
mp_neg(&b, &b);
mp_set_long(&d, ulabs(l & em));
mp_set_ul(&d, ulabs(l & em));
if ((l & em) < 0)
mp_neg(&d, &d);
@ -610,7 +732,7 @@ LBL_ERR:
}
static int test_mp_get_int(void)
static int test_mp_get_u32(void)
{
unsigned long t;
int i;
@ -622,20 +744,20 @@ static int test_mp_get_int(void)
for (i = 0; i < 1000; ++i) {
t = (unsigned long)rand_long() & 0xFFFFFFFFuL;
mp_set_int(&a, t);
if (t != mp_get_int(&a)) {
printf("\nmp_get_int() bad result!");
mp_set_ul(&a, t);
if (t != mp_get_u32(&a)) {
printf("\nmp_get_u32() bad result!");
goto LBL_ERR;
}
}
mp_set_int(&a, 0uL);
if (mp_get_int(&a) != 0) {
printf("\nmp_get_int() bad result!");
mp_set_ul(&a, 0uL);
if (mp_get_u32(&a) != 0) {
printf("\nmp_get_u32() bad result!");
goto LBL_ERR;
}
mp_set_int(&a, 0xFFFFFFFFuL);
if (mp_get_int(&a) != 0xFFFFFFFFuL) {
printf("\nmp_get_int() bad result!");
mp_set_ul(&a, 0xFFFFFFFFuL);
if (mp_get_u32(&a) != 0xFFFFFFFFuL) {
printf("\nmp_get_u32() bad result!");
goto LBL_ERR;
}
@ -646,7 +768,7 @@ LBL_ERR:
return EXIT_FAILURE;
}
static int test_mp_get_long(void)
static int test_mp_get_ul(void)
{
unsigned long s, t;
int i;
@ -662,10 +784,10 @@ static int test_mp_get_long(void)
t = ~0UL;
printf(" t = 0x%lx i = %d\r", t, i);
do {
mp_set_long(&a, t);
s = mp_get_long(&a);
mp_set_ul(&a, t);
s = mp_get_ul(&a);
if (s != t) {
printf("\nmp_get_long() bad result! 0x%lx != 0x%lx", s, t);
printf("\nmp_get_ul() bad result! 0x%lx != 0x%lx", s, t);
goto LBL_ERR;
}
t <<= 1;
@ -679,7 +801,7 @@ LBL_ERR:
return EXIT_FAILURE;
}
static int test_mp_get_long_long(void)
static int test_mp_get_u64(void)
{
unsigned long long q, r;
int i;
@ -695,10 +817,10 @@ static int test_mp_get_long_long(void)
r = ~0ULL;
printf(" r = 0x%llx i = %d\r", r, i);
do {
mp_set_long_long(&a, r);
q = mp_get_long_long(&a);
mp_set_u64(&a, r);
q = mp_get_u64(&a);
if (q != r) {
printf("\nmp_get_long_long() bad result! 0x%llx != 0x%llx", q, r);
printf("\nmp_get_u64() bad result! 0x%llx != 0x%llx", q, r);
goto LBL_ERR;
}
r <<= 1;
@ -821,8 +943,8 @@ static int test_mp_sqrtmod_prime(void)
/* r^2 = n (mod p) */
for (i = 0; i < (int)(sizeof(sqrtmod_prime)/sizeof(sqrtmod_prime[0])); ++i) {
mp_set_int(&a, sqrtmod_prime[i].p);
mp_set_int(&b, sqrtmod_prime[i].n);
mp_set_ul(&a, sqrtmod_prime[i].p);
mp_set_ul(&b, sqrtmod_prime[i].n);
if (mp_sqrtmod_prime(&b, &a, &c) != MP_OKAY) {
printf("Failed executing %d. mp_sqrtmod_prime\n", (i+1));
goto LBL_ERR;
@ -2021,6 +2143,8 @@ int unit_tests(int argc, char **argv)
} test[] = {
#define T(n) { #n, test_##n }
T(trivial_stuff),
T(mp_get_set_i32),
T(mp_get_set_i64),
T(mp_and),
T(mp_cnt_lsb),
T(mp_complement),
@ -2028,9 +2152,9 @@ int unit_tests(int argc, char **argv)
T(mp_div_3),
T(mp_dr_reduce),
T(mp_fread_fwrite),
T(mp_get_int),
T(mp_get_long),
T(mp_get_long_long),
T(mp_get_u32),
T(mp_get_u64),
T(mp_get_ul),
T(mp_ilogb),
T(mp_incr),
T(mp_invmod),

3
dep.pl
View File

@ -96,7 +96,7 @@ EOS
# scan for mp_* and make classes
foreach my $line (split /\n/, $content) {
while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*(?=\()/g) {
while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*(?=\()|(?<=\()mp\_[a-z_0-9]*(?=,)/g) {
my $a = $&;
next if $a eq "mp_err";
$a =~ tr/[a-z]/[A-Z]/;
@ -167,4 +167,3 @@ sub draw_func
$list = $temp;
return;
}

View File

@ -820,28 +820,33 @@ int main(void)
\}
\end{alltt} \end{small}
\subsection{Long Constants}
\subsection{Int32 and Int64 Constants}
To set a constant that is the size of an ISO C ``unsigned long'' and larger than a single digit the following function
can be used.
These functions can be used to set a constant with 32 or 64 bits.
\index{mp\_set\_int}
\begin{alltt}
int mp_set_int (mp_int * a, unsigned long b);
void mp_set_i32 (mp_int * a, int32_t b);
void mp_set_u32 (mp_int * a, uint32_t b);
void mp_set_i64 (mp_int * a, int64_t b);
void mp_set_u64 (mp_int * a, uint64_t b);
\end{alltt}
This will assign the value of the 32-bit variable $b$ to the mp\_int $a$. Unlike mp\_set() this function will always
accept a 32-bit input regardless of the size of a single digit. However, since the value may span several digits
this function can fail if it runs out of heap memory.
To get the ``unsigned long'' copy of an mp\_int the following function can be used.
These functions assign the sign and value of the input \texttt{b} to \texttt{mp_int a}.
The value can be obtained again by calling the following functions.
\index{mp\_get\_int}
\begin{alltt}
unsigned long mp_get_int (mp_int * a);
int32_t mp_get_i32 (mp_int * a);
uint32_t mp_get_u32 (mp_int * a);
uint32_t mp_get_mag32 (mp_int * a);
int64_t mp_get_i64 (mp_int * a);
uint64_t mp_get_u64 (mp_int * a);
uint64_t mp_get_mag64 (mp_int * a);
\end{alltt}
This will return the 32 least significant bits of the mp\_int $a$.
These functions return the 32 or 64 least significant bits of $a$ respectively. The unsigned functions
return negative values in a twos complement representation. The absolute value or magnitude can be obtained using the mp\_get\_mag functions.
\begin{small} \begin{alltt}
int main(void)
@ -856,9 +861,9 @@ int main(void)
\}
/* set the number to 654321 (note this is bigger than 127) */
mp_set_int(&number, 654321);
mp_set_u32(&number, 654321);
printf("number == \%lu", mp_get_int(&number));
printf("number == \%lu", mp_get_i32(&number));
/* we're done with it. */
mp_clear(&number);
@ -875,46 +880,31 @@ number == 654321
\subsection{Long Constants - platform dependant}
\index{mp\_set\_long}
\index{mp\_set\_ulong}
\begin{alltt}
int mp_set_long (mp_int * a, unsigned long b);
void mp_set_l (mp_int * a, long b);
void mp_set_ul (mp_int * a, unsigned long b);
\end{alltt}
This will assign the value of the platform-dependent sized variable $b$ to the mp\_int $a$.
To get the ``unsigned long'' copy of an mp\_int the following function can be used.
To retrieve the value, the following functions can be used.
\index{mp\_get\_long}
\index{mp\_get\_ulong}
\begin{alltt}
unsigned long mp_get_long (mp_int * a);
long mp_get_l (mp_int * a);
unsigned long mp_get_ul (mp_int * a);
\end{alltt}
This will return the least significant bits of the mp\_int $a$ that fit into an ``unsigned long''.
\subsection{Long Long Constants}
\index{mp\_set\_long\_long}
\begin{alltt}
int mp_set_long_long (mp_int * a, unsigned long long b);
\end{alltt}
This will assign the value of the 64-bit variable $b$ to the mp\_int $a$.
To get the ``unsigned long long'' copy of an mp\_int the following function can be used.
\index{mp\_get\_long\_long}
\begin{alltt}
unsigned long long mp_get_long_long (mp_int * a);
\end{alltt}
This will return the 64 least significant bits of the mp\_int $a$.
This will return the least significant bits of the mp\_int $a$ that fit into a ``long''.
\subsection{Initialize and Setting Constants}
To both initialize and set small constants the following two functions are available.
\index{mp\_init\_set} \index{mp\_init\_set\_int}
\begin{alltt}
int mp_init_set (mp_int * a, mp_digit b);
int mp_init_set_int (mp_int * a, unsigned long b);
int mp_init_i32 (mp_int * a, int32_t b);
int mp_init_u32 (mp_int * a, uint32_t b);
\end{alltt}
Both functions work like the previous counterparts except they first mp\_init $a$ before setting the values.
@ -933,7 +923,7 @@ int main(void)
\}
/* initialize and set a long */
if ((result = mp_init_set_int(&number2, 1023)) != MP_OKAY) \{
if ((result = mp_init_set_uint(&number2, 1023)) != MP_OKAY) \{
printf("Error setting number2: \%s",
mp_error_to_string(result));
return EXIT_FAILURE;
@ -941,7 +931,7 @@ int main(void)
/* display */
printf("Number1, Number2 == \%lu, \%lu",
mp_get_int(&number1), mp_get_int(&number2));
mp_get_i32(&number1), mp_get_i32(&number2));
/* clear */
mp_clear_multi(&number1, &number2, NULL);
@ -1375,8 +1365,8 @@ int main(void)
\}
/* set the terms */
mp_set_int(&number, 257);
mp_set_int(&number2, 1023);
mp_set_i32(&number, 257);
mp_set_i32(&number2, 1023);
/* multiply them */
if ((result = mp_mul(&number1, &number2,
@ -1387,7 +1377,7 @@ int main(void)
\}
/* display */
printf("number1 * number2 == \%lu", mp_get_int(&number1));
printf("number1 * number2 == \%lu", mp_get_i32(&number1));
/* free terms and return */
mp_clear_multi(&number1, &number2, NULL);

View File

@ -312,6 +312,10 @@
<References>
</References>
<Files>
<File
RelativePath="bn_conversion.c"
>
</File>
<File
RelativePath="bn_cutoffs.c"
>
@ -464,18 +468,6 @@
RelativePath="bn_mp_get_double.c"
>
</File>
<File
RelativePath="bn_mp_get_int.c"
>
</File>
<File
RelativePath="bn_mp_get_long.c"
>
</File>
<File
RelativePath="bn_mp_get_long_long.c"
>
</File>
<File
RelativePath="bn_mp_grow.c"
>
@ -508,10 +500,6 @@
RelativePath="bn_mp_init_set.c"
>
</File>
<File
RelativePath="bn_mp_init_set_int.c"
>
</File>
<File
RelativePath="bn_mp_init_size.c"
>
@ -708,18 +696,6 @@
RelativePath="bn_mp_set_double.c"
>
</File>
<File
RelativePath="bn_mp_set_int.c"
>
</File>
<File
RelativePath="bn_mp_set_long.c"
>
</File>
<File
RelativePath="bn_mp_set_long_long.c"
>
</File>
<File
RelativePath="bn_mp_shrink.c"
>

View File

@ -26,34 +26,32 @@ endif
LCOV_ARGS=--directory .
#START_INS
OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \
bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \
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_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 \
bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o bn_mp_or.o bn_mp_prime_fermat.o \
bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o \
bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o bn_mp_prime_rabin_miller_trials.o \
bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp_radix_smap.o \
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
OBJECTS=bn_conversion.o bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \
bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \
bn_mp_cmp_mag.o 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_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_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 bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o \
bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o \
bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \
bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \
bn_mp_radix_size.o bn_mp_radix_smap.o 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
#END_INS

View File

@ -29,24 +29,32 @@ LIBMAIN_I =libtommath.dll.a
LIBMAIN_D =libtommath.dll
#List of objects to compile (all goes to libtommath.a)
OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \
bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \
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_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 \
bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o bn_mp_or.o bn_mp_prime_fermat.o \
bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o \
bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o bn_mp_prime_rabin_miller_trials.o \
bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp_radix_smap.o \
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 \
OBJECTS=bn_conversion.o bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \
bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \
bn_mp_cmp_mag.o 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_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_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 bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o \
bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o \
bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \
bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \
bn_mp_radix_size.o bn_mp_radix_smap.o 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 \

View File

@ -21,24 +21,32 @@ LTM_LDFLAGS = advapi32.lib
LIBMAIN_S =tommath.lib
#List of objects to compile (all goes to tommath.lib)
OBJECTS=bn_cutoffs.obj bn_deprecated.obj bn_mp_2expt.obj bn_mp_abs.obj bn_mp_add.obj bn_mp_add_d.obj bn_mp_addmod.obj \
bn_mp_and.obj bn_mp_clamp.obj bn_mp_clear.obj bn_mp_clear_multi.obj bn_mp_cmp.obj bn_mp_cmp_d.obj bn_mp_cmp_mag.obj \
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_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 \
bn_mp_n_root.obj bn_mp_n_root_ex.obj bn_mp_neg.obj bn_mp_or.obj bn_mp_prime_fermat.obj \
bn_mp_prime_frobenius_underwood.obj bn_mp_prime_is_divisible.obj bn_mp_prime_is_prime.obj \
bn_mp_prime_miller_rabin.obj bn_mp_prime_next_prime.obj bn_mp_prime_rabin_miller_trials.obj \
bn_mp_prime_rand.obj bn_mp_prime_strong_lucas_selfridge.obj bn_mp_radix_size.obj bn_mp_radix_smap.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 \
OBJECTS=bn_conversion.obj bn_cutoffs.obj bn_deprecated.obj bn_mp_2expt.obj bn_mp_abs.obj bn_mp_add.obj bn_mp_add_d.obj \
bn_mp_addmod.obj bn_mp_and.obj bn_mp_clamp.obj bn_mp_clear.obj bn_mp_clear_multi.obj bn_mp_cmp.obj bn_mp_cmp_d.obj \
bn_mp_cmp_mag.obj 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_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_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 bn_mp_n_root.obj bn_mp_n_root_ex.obj bn_mp_neg.obj \
bn_mp_or.obj bn_mp_prime_fermat.obj bn_mp_prime_frobenius_underwood.obj bn_mp_prime_is_divisible.obj \
bn_mp_prime_is_prime.obj bn_mp_prime_miller_rabin.obj bn_mp_prime_next_prime.obj \
bn_mp_prime_rabin_miller_trials.obj bn_mp_prime_rand.obj bn_mp_prime_strong_lucas_selfridge.obj \
bn_mp_radix_size.obj bn_mp_radix_smap.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 \

View File

@ -23,24 +23,32 @@ LTLINK = $(LIBTOOL) --mode=link --tag=CC $(CC)
LCOV_ARGS=--directory .libs --directory .
#START_INS
OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \
bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \
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_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 \
bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o bn_mp_or.o bn_mp_prime_fermat.o \
bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o \
bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o bn_mp_prime_rabin_miller_trials.o \
bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp_radix_smap.o \
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 \
OBJECTS=bn_conversion.o bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \
bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \
bn_mp_cmp_mag.o 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_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_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 bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o \
bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o \
bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \
bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \
bn_mp_radix_size.o bn_mp_radix_smap.o 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

View File

@ -30,24 +30,32 @@ LTM_LDFLAGS = $(LDFLAGS)
#Library to be created (this makefile builds only static library)
LIBMAIN_S = libtommath.a
OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \
bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \
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_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 \
bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o bn_mp_or.o bn_mp_prime_fermat.o \
bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o bn_mp_prime_is_prime.o \
bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o bn_mp_prime_rabin_miller_trials.o \
bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o bn_mp_radix_size.o bn_mp_radix_smap.o \
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 \
OBJECTS=bn_conversion.o bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \
bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \
bn_mp_cmp_mag.o 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_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_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 bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_neg.o \
bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o bn_mp_prime_is_divisible.o \
bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \
bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \
bn_mp_radix_size.o bn_mp_radix_smap.o 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

View File

@ -270,38 +270,55 @@ 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 */
/* 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;
/* set a 32-bit const */
/* TODO void - never fails */ mp_err mp_set_int(mp_int *a, unsigned long b);
/* 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;
/* set a platform dependent unsigned long value */
/* TODO void - never fails */ mp_err mp_set_long(mp_int *a, unsigned long b);
/* 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;
/* 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 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 a double */
double mp_get_double(const mp_int *a) 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 a 32-bit value */
unsigned long mp_get_int(const mp_int *a) 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 a platform dependent unsigned long value */
unsigned long mp_get_long(const mp_int *a) MP_WUR;
/* get integer, set integer (long) */
#define mp_get_l(a) (sizeof (long) == 8 ? (long)mp_get_i64(a) : (long)mp_get_i32(a))
#define mp_set_l(a, b) (sizeof (long) == 8 ? mp_set_i64((a), (b)) : mp_set_i32((a), (int32_t)(b)))
/* get a platform dependent unsigned long long value */
unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
/* get integer, set integer (unsigned long) */
#define mp_get_ul(a) (sizeof (long) == 8 ? (unsigned long)mp_get_u64(a) : (unsigned long)mp_get_u32(a))
#define mp_set_ul(a, b) (sizeof (long) == 8 ? mp_set_u64((a), (b)) : mp_set_u32((a), (uint32_t)(b)))
#define mp_get_magl(a) (sizeof (long) == 8 ? (unsigned long)mp_get_mag64(a) : (unsigned long)mp_get_mag32(a))
/* initialize and set a digit */
/* set to single unsigned digit, up to MP_DIGIT_MAX */
void mp_set(mp_int *a, mp_digit b);
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 (deprecated) */
MP_DEPRECATED(mp_get_mag32/mp_get_u32) unsigned long mp_get_int(const mp_int *a) MP_WUR;
MP_DEPRECATED(mp_get_magl/mp_get_ul) unsigned long mp_get_long(const mp_int *a) MP_WUR;
MP_DEPRECATED(mp_get_mag64/mp_get_u64) unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
MP_DEPRECATED(mp_set_u32) mp_err mp_set_int(mp_int *a, unsigned long b);
MP_DEPRECATED(mp_set_ul) 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_u32) 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;

View File

@ -10,6 +10,7 @@
#endif
#define LTM1
#if defined(LTM_ALL)
# define BN_CONVERSION_C
# define BN_CUTOFFS_C
# define BN_DEPRECATED_C
# define BN_MP_2EXPT_C
@ -48,9 +49,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
@ -59,7 +57,6 @@
# 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 +106,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
@ -155,6 +149,22 @@
# define BN_S_MP_TOOM_MUL_C
# define BN_S_MP_TOOM_SQR_C
#endif
#if defined(BN_CONVERSION_C)
# define BN_MP_INIT_C
# define BN_MP_SET_U32_C
# define BN_MP_SET_U64_C
# define BN_MP_SET_I32_C
# define BN_MP_SET_I64_C
# define BN_MP_GET_I32_C
# define BN_MP_GET_I64_C
# define BN_MP_GET_MAG32_C
# define BN_MP_GET_MAG64_C
# define BN_MP_INIT_U32_C
# define BN_MP_INIT_I32_C
# define BN_MP_INIT_U64_C
# define BN_MP_INIT_I64_C
#endif
#if defined(BN_CUTOFFS_C)
#endif
@ -202,6 +212,18 @@
# 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_SET_INT_C
# define BN_MP_SET_U32_C
# define BN_MP_SET_LONG_C
# define BN_MP_SET_U64_C
# define BN_MP_SET_LONG_LONG_C
# define BN_MP_GET_INT_C
# define BN_MP_GET_MAG32_C
# define BN_MP_GET_LONG_C
# define BN_MP_GET_MAG64_C
# define BN_MP_GET_LONG_LONG_C
#endif
#if defined(BN_MP_2EXPT_C)
@ -423,21 +445,11 @@
#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_U32_C
# define BN_MP_COUNT_BITS_C
# define BN_MP_SET_C
# define BN_MP_CMP_D_C
@ -483,11 +495,6 @@
# 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
@ -499,9 +506,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_U32_C
# define BN_MP_MOD_C
# define BN_MP_GET_INT_C
# define BN_MP_GET_U32_C
# define BN_MP_SQRT_C
# define BN_MP_SQR_C
# define BN_MP_CMP_MAG_C
@ -648,7 +655,7 @@
#if defined(BN_MP_PRIME_FROBENIUS_UNDERWOOD_C)
# define BN_MP_INIT_MULTI_C
# define BN_MP_SET_LONG_C
# define BN_MP_SET_U32_C
# define BN_MP_SQR_C
# define BN_MP_SUB_D_C
# define BN_MP_KRONECKER_C
@ -730,10 +737,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_I32_C
# define BN_MP_MUL_C
# define BN_MP_CLEAR_C
# define BN_MP_INIT_MULTI_C
# define BN_MP_SET_U32_C
# define BN_MP_GCD_C
# define BN_MP_CMP_D_C
# define BN_MP_CMP_C
@ -861,25 +869,14 @@
#endif
#if defined(BN_MP_SET_C)
# define BN_MP_ZERO_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
@ -930,7 +927,7 @@
# 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_U32_C
# define BN_MP_SQRMOD_C
# define BN_MP_MULMOD_C
# define BN_MP_SET_C

View File

@ -203,26 +203,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,