Merge pull request #378 from libtom/remove-deprecated
Remove deprecated functions
This commit is contained in:
commit
b07141387a
321
bn_deprecated.c
321
bn_deprecated.c
@ -1,321 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_DEPRECATED_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#ifdef BN_MP_GET_BIT_C
|
||||
int mp_get_bit(const mp_int *a, int b)
|
||||
{
|
||||
if (b < 0) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return (s_mp_get_bit(a, (unsigned int)b) == MP_YES) ? MP_YES : MP_NO;
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_JACOBI_C
|
||||
mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c)
|
||||
{
|
||||
if (a->sign == MP_NEG) {
|
||||
return MP_VAL;
|
||||
}
|
||||
if (mp_cmp_d(n, 0uL) != MP_GT) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_kronecker(a, n, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_PRIME_RANDOM_EX_C
|
||||
mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat)
|
||||
{
|
||||
return s_mp_prime_random_ex(a, t, size, flags, cb, dat);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_RAND_DIGIT_C
|
||||
mp_err mp_rand_digit(mp_digit *r)
|
||||
{
|
||||
mp_err err = s_mp_rand_source(r, sizeof(mp_digit));
|
||||
*r &= MP_MASK;
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_MP_INVMOD_C
|
||||
mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_invmod_fast(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
|
||||
mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
|
||||
{
|
||||
return s_mp_montgomery_reduce_fast(x, n, rho);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_S_MP_MUL_DIGS_C
|
||||
mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
{
|
||||
return s_mp_mul_digs_fast(a, b, c, digs);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
{
|
||||
return s_mp_mul_high_digs_fast(a, b, c, digs);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_S_MP_SQR_C
|
||||
mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b)
|
||||
{
|
||||
return s_mp_sqr_fast(a, b);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_BALANCE_MUL_C
|
||||
mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_balance_mul(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPTMOD_FAST_C
|
||||
mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
|
||||
{
|
||||
return s_mp_exptmod_fast(G, X, P, Y, redmode);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_INVMOD_SLOW_C
|
||||
mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_invmod_slow(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_KARATSUBA_MUL_C
|
||||
mp_err mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_karatsuba_mul(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_KARATSUBA_SQR_C
|
||||
mp_err mp_karatsuba_sqr(const mp_int *a, mp_int *b)
|
||||
{
|
||||
return s_mp_karatsuba_sqr(a, b);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TOOM_MUL_C
|
||||
mp_err mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_toom_mul(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TOOM_SQR_C
|
||||
mp_err mp_toom_sqr(const mp_int *a, mp_int *b)
|
||||
{
|
||||
return s_mp_toom_sqr(a, b);
|
||||
}
|
||||
#endif
|
||||
#ifdef S_MP_REVERSE_C
|
||||
void bn_reverse(unsigned char *s, int len)
|
||||
{
|
||||
if (len > 0) {
|
||||
s_mp_reverse(s, (size_t)len);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_AND_C
|
||||
mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return mp_and(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_OR_C
|
||||
mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return mp_or(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_XOR_C
|
||||
mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return mp_xor(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_DIV_2D_C
|
||||
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 (unsigned long)mp_get_mag_u32(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_GET_LONG_C
|
||||
unsigned long mp_get_long(const mp_int *a)
|
||||
{
|
||||
return (unsigned long)mp_get_mag_ul(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_GET_LONG_LONG_C
|
||||
unsigned long long mp_get_long_long(const mp_int *a)
|
||||
{
|
||||
return mp_get_mag_ull(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_PRIME_IS_DIVISIBLE_C
|
||||
mp_err mp_prime_is_divisible(const mp_int *a, mp_bool *result)
|
||||
{
|
||||
return s_mp_prime_is_divisible(a, result);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPT_D_EX_C
|
||||
mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
{
|
||||
(void)fast;
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_expt_u32(a, (uint32_t)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPT_D_C
|
||||
mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
{
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_expt_u32(a, (uint32_t)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_N_ROOT_EX_C
|
||||
mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
{
|
||||
(void)fast;
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_root_u32(a, (uint32_t)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_N_ROOT_C
|
||||
mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c)
|
||||
{
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_root_u32(a, (uint32_t)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
int mp_unsigned_bin_size(const mp_int *a)
|
||||
{
|
||||
return (int)mp_ubin_size(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_READ_UNSIGNED_BIN_C
|
||||
mp_err mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c)
|
||||
{
|
||||
return mp_from_ubin(a, b, (size_t) c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_UNSIGNED_BIN_C
|
||||
mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
|
||||
{
|
||||
return mp_to_ubin(a, b, SIZE_MAX, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_UNSIGNED_BIN_N_C
|
||||
mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen)
|
||||
{
|
||||
size_t n = mp_ubin_size(a);
|
||||
if (*outlen < (unsigned long)n) {
|
||||
return MP_VAL;
|
||||
}
|
||||
*outlen = (unsigned long)n;
|
||||
return mp_to_ubin(a, b, n, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_SIGNED_BIN_SIZE_C
|
||||
int mp_signed_bin_size(const mp_int *a)
|
||||
{
|
||||
return (int)mp_sbin_size(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_READ_SIGNED_BIN_C
|
||||
mp_err mp_read_signed_bin(mp_int *a, const unsigned char *b, int c)
|
||||
{
|
||||
return mp_from_sbin(a, b, (size_t) c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_SIGNED_BIN_C
|
||||
mp_err mp_to_signed_bin(const mp_int *a, unsigned char *b)
|
||||
{
|
||||
return mp_to_sbin(a, b, SIZE_MAX, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_SIGNED_BIN_N_C
|
||||
mp_err mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen)
|
||||
{
|
||||
size_t n = mp_sbin_size(a);
|
||||
if (*outlen < (unsigned long)n) {
|
||||
return MP_VAL;
|
||||
}
|
||||
*outlen = (unsigned long)n;
|
||||
return mp_to_sbin(a, b, n, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TORADIX_N_C
|
||||
mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
|
||||
{
|
||||
if (maxlen < 0) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_to_radix(a, str, (size_t)maxlen, NULL, radix);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TORADIX_C
|
||||
mp_err mp_toradix(const mp_int *a, char *str, int radix)
|
||||
{
|
||||
return mp_to_radix(a, str, SIZE_MAX, NULL, radix);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_IMPORT_C
|
||||
mp_err mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails,
|
||||
const void *op)
|
||||
{
|
||||
return mp_unpack(rop, count, order, size, endian, nails, op);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPORT_C
|
||||
mp_err mp_export(void *rop, size_t *countp, int order, size_t size,
|
||||
int endian, size_t nails, const mp_int *op)
|
||||
{
|
||||
return mp_pack(rop, SIZE_MAX, countp, order, size, endian, nails, op);
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -30,11 +30,11 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream)
|
||||
do {
|
||||
int y;
|
||||
unsigned pos = (unsigned)(ch - (int)'(');
|
||||
if (mp_s_rmap_reverse_sz < pos) {
|
||||
if (MP_RMAP_REVERSE_SIZE < pos) {
|
||||
break;
|
||||
}
|
||||
|
||||
y = (int)mp_s_rmap_reverse[pos];
|
||||
y = (int)s_mp_rmap_reverse[pos];
|
||||
|
||||
if ((y == 0xff) || (y >= radix)) {
|
||||
break;
|
||||
|
@ -51,7 +51,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
|
||||
}
|
||||
|
||||
/* is the input equal to one of the primes in the table? */
|
||||
for (ix = 0; ix < PRIVATE_MP_PRIME_TAB_SIZE; ix++) {
|
||||
for (ix = 0; ix < MP_PRIME_TAB_SIZE; ix++) {
|
||||
if (mp_cmp_d(a, s_mp_prime_tab[ix]) == MP_EQ) {
|
||||
*result = MP_YES;
|
||||
return MP_OKAY;
|
||||
@ -59,7 +59,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
|
||||
}
|
||||
#ifdef MP_8BIT
|
||||
/* The search in the loop above was exhaustive in this case */
|
||||
if ((a->used == 1) && (PRIVATE_MP_PRIME_TAB_SIZE >= 31)) {
|
||||
if ((a->used == 1) && (MP_PRIME_TAB_SIZE >= 31)) {
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -13,16 +13,16 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style)
|
||||
int x, y, cmp;
|
||||
mp_err err;
|
||||
mp_bool res = MP_NO;
|
||||
mp_digit res_tab[PRIVATE_MP_PRIME_TAB_SIZE], step, kstep;
|
||||
mp_digit res_tab[MP_PRIME_TAB_SIZE], step, kstep;
|
||||
mp_int b;
|
||||
|
||||
/* force positive */
|
||||
a->sign = MP_ZPOS;
|
||||
|
||||
/* simple algo if a is less than the largest prime in the table */
|
||||
if (mp_cmp_d(a, s_mp_prime_tab[PRIVATE_MP_PRIME_TAB_SIZE-1]) == MP_LT) {
|
||||
if (mp_cmp_d(a, s_mp_prime_tab[MP_PRIME_TAB_SIZE-1]) == MP_LT) {
|
||||
/* find which prime it is bigger than "a" */
|
||||
for (x = 0; x < PRIVATE_MP_PRIME_TAB_SIZE; x++) {
|
||||
for (x = 0; x < MP_PRIME_TAB_SIZE; x++) {
|
||||
cmp = mp_cmp_d(a, s_mp_prime_tab[x]);
|
||||
if (cmp == MP_EQ) {
|
||||
continue;
|
||||
@ -66,7 +66,7 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style)
|
||||
}
|
||||
|
||||
/* generate the restable */
|
||||
for (x = 1; x < PRIVATE_MP_PRIME_TAB_SIZE; x++) {
|
||||
for (x = 1; x < MP_PRIME_TAB_SIZE; x++) {
|
||||
if ((err = mp_mod_d(a, s_mp_prime_tab[x], res_tab + x)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
@ -88,7 +88,7 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style)
|
||||
step += kstep;
|
||||
|
||||
/* compute the new residue without using division */
|
||||
for (x = 1; x < PRIVATE_MP_PRIME_TAB_SIZE; x++) {
|
||||
for (x = 1; x < MP_PRIME_TAB_SIZE; x++) {
|
||||
/* add the step to each residue */
|
||||
res_tab[x] += kstep;
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/* This is possibly the mother of all prime generation functions, muahahahahaha! */
|
||||
mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat)
|
||||
mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, mp_prime_callback cb, void *dat)
|
||||
{
|
||||
unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
|
||||
int bsize, maskOR_msb_offset;
|
||||
|
@ -4,8 +4,8 @@
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* chars used in radix conversions */
|
||||
const char *const mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
|
||||
const uint8_t mp_s_rmap_reverse[] = {
|
||||
const char s_mp_rmap[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
|
||||
const uint8_t s_mp_rmap_reverse[] = {
|
||||
0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, /* ()*+,-./ */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */
|
||||
0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 89:;<=>? */
|
||||
@ -18,5 +18,5 @@ const uint8_t mp_s_rmap_reverse[] = {
|
||||
0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, /* pqrstuvw */
|
||||
0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, /* xyz{|}~. */
|
||||
};
|
||||
const size_t mp_s_rmap_reverse_sz = sizeof(mp_s_rmap_reverse);
|
||||
MP_STATIC_ASSERT(correct_rmap_reverse_size, sizeof(s_mp_rmap_reverse) == MP_RMAP_REVERSE_SIZE)
|
||||
#endif
|
||||
|
@ -43,10 +43,10 @@ mp_err mp_read_radix(mp_int *a, const char *str, int radix)
|
||||
*/
|
||||
ch = (radix <= 36) ? (char)MP_TOUPPER((int)*str) : *str;
|
||||
pos = (unsigned)(ch - '(');
|
||||
if (mp_s_rmap_reverse_sz < pos) {
|
||||
if (MP_RMAP_REVERSE_SIZE < pos) {
|
||||
break;
|
||||
}
|
||||
y = (int)mp_s_rmap_reverse[pos];
|
||||
y = (int)s_mp_rmap_reverse[pos];
|
||||
|
||||
/* if the char was found in the map
|
||||
* and is less than the given radix add it
|
||||
|
@ -60,7 +60,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
|
||||
if ((err = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
*str++ = mp_s_rmap[d];
|
||||
*str++ = s_mp_rmap[d];
|
||||
++digs;
|
||||
}
|
||||
/* reverse the digits of the string. In this case _s points
|
||||
|
@ -3,7 +3,7 @@
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
const mp_digit ltm_prime_tab[] = {
|
||||
const mp_digit s_mp_prime_tab[] = {
|
||||
0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
|
||||
0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
|
||||
0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
|
||||
@ -44,18 +44,4 @@ const mp_digit ltm_prime_tab[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
const mp_digit *s_mp_prime_tab = ltm_prime_tab;
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(_MSC_VER) && _MSC_VER >= 1500
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4996)
|
||||
const mp_digit *s_mp_prime_tab = ltm_prime_tab;
|
||||
#pragma warning(pop)
|
||||
#else
|
||||
const mp_digit *s_mp_prime_tab = ltm_prime_tab;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@ mp_err s_mp_prime_is_divisible(const mp_int *a, mp_bool *result)
|
||||
/* default to not */
|
||||
*result = MP_NO;
|
||||
|
||||
for (ix = 0; ix < PRIVATE_MP_PRIME_TAB_SIZE; ix++) {
|
||||
for (ix = 0; ix < MP_PRIME_TAB_SIZE; ix++) {
|
||||
/* what is a mod LBL_prime_tab[ix] */
|
||||
if ((err = mp_mod_d(a, s_mp_prime_tab[ix], &res)) != MP_OKAY) {
|
||||
return err;
|
||||
|
15
demo/test.c
15
demo/test.c
@ -1283,21 +1283,6 @@ static int test_mp_read_radix(void)
|
||||
if ((err = mp_to_radix(&a, buf, SIZE_MAX, &written, 10)) != MP_OKAY) goto LTM_ERR;
|
||||
printf(" '0' a == %s, length = %zu\n", buf, written);
|
||||
|
||||
|
||||
|
||||
/* Although deprecated it needs to function as long as it isn't dropped */
|
||||
/*
|
||||
printf("Testing deprecated mp_toradix_n\n");
|
||||
if( (err = mp_read_radix(&a, "-123456", 10) ) != MP_OKAY) goto LTM_ERR;
|
||||
if( (err = mp_toradix_n(&a, buf, 10, 3) ) != MP_OKAY) goto LTM_ERR;
|
||||
printf("a == %s\n", buf);
|
||||
if( (err = mp_toradix_n(&a, buf, 10, 4) ) != MP_OKAY) goto LTM_ERR;
|
||||
printf("a == %s\n", buf);
|
||||
if( (err = mp_toradix_n(&a, buf, 10, 30) ) != MP_OKAY) goto LTM_ERR;
|
||||
printf("a == %s\n", buf);
|
||||
*/
|
||||
|
||||
|
||||
while (0) {
|
||||
char *s = fgets(buf, sizeof(buf), stdin);
|
||||
if (s != buf) break;
|
||||
|
16
doc/bn.tex
16
doc/bn.tex
@ -2089,19 +2089,17 @@ The variable $flags$ specifies one of several options available
|
||||
The function mp\_prime\_rand() is suitable for generating primes which must be secret (as in the case of RSA) since there
|
||||
is no skew on the least significant bits.
|
||||
|
||||
\textit{Note:} This function replaces the deprecated mp\_prime\_random and mp\_prime\_random\_ex functions.
|
||||
|
||||
\begin{figure}[h]
|
||||
\begin{center}
|
||||
\begin{small}
|
||||
\begin{tabular}{|r|l|}
|
||||
\hline \textbf{Flag} & \textbf{Meaning} \\
|
||||
\hline LTM\_PRIME\_BBS & Make the prime congruent to $3$ modulo $4$ \\
|
||||
\hline LTM\_PRIME\_SAFE & Make a prime $p$ such that $(p - 1)/2$ is also prime. \\
|
||||
& This option implies LTM\_PRIME\_BBS as well. \\
|
||||
\hline LTM\_PRIME\_2MSB\_OFF & Makes sure that the bit adjacent to the most significant bit \\
|
||||
\hline MP\_PRIME\_BBS & Make the prime congruent to $3$ modulo $4$ \\
|
||||
\hline MP\_PRIME\_SAFE & Make a prime $p$ such that $(p - 1)/2$ is also prime. \\
|
||||
& This option implies MP\_PRIME\_BBS as well. \\
|
||||
\hline MP\_PRIME\_2MSB\_OFF & Makes sure that the bit adjacent to the most significant bit \\
|
||||
& Is forced to zero. \\
|
||||
\hline LTM\_PRIME\_2MSB\_ON & Makes sure that the bit adjacent to the most significant bit \\
|
||||
\hline MP\_PRIME\_2MSB\_ON & Makes sure that the bit adjacent to the most significant bit \\
|
||||
& Is forced to one. \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
@ -2154,7 +2152,7 @@ int mp_radix_size (mp_int * a, int radix, int *size)
|
||||
This stores in ``size'' the number of characters (including space for the NUL terminator) required. Upon error this
|
||||
function returns an error code and ``size'' will be zero.
|
||||
|
||||
If \texttt{LTM\_NO\_FILE} is not defined a function to write to a file is also available.
|
||||
If \texttt{MP\_NO\_FILE} is not defined a function to write to a file is also available.
|
||||
\index{mp\_fwrite}
|
||||
\begin{alltt}
|
||||
int mp_fwrite(const mp_int *a, int radix, FILE *stream);
|
||||
@ -2170,7 +2168,7 @@ This will read the base-``radix'' NUL terminated string from ``str'' into $a$.
|
||||
character it does not recognize (which happens to include th NUL char... imagine that...). A single leading $-$ sign
|
||||
can be used to denote a negative number.
|
||||
|
||||
If \texttt{LTM\_NO\_FILE} is not defined a function to read from a file is also available.
|
||||
If \texttt{MP\_NO\_FILE} is not defined a function to read from a file is also available.
|
||||
\index{mp\_fread}
|
||||
\begin{alltt}
|
||||
int mp_fread(mp_int *a, int radix, FILE *stream);
|
||||
|
14
helper.pl
14
helper.pl
@ -358,15 +358,9 @@ EOS
|
||||
my %depmap;
|
||||
foreach my $filename (glob 'bn*.c') {
|
||||
my $content;
|
||||
if ($filename =~ "bn_deprecated.c") {
|
||||
open(my $src, '<', $filename) or die "Can't open source file!\n";
|
||||
read $src, $content, -s $src;
|
||||
close $src;
|
||||
} else {
|
||||
my $cc = $ENV{'CC'} || 'gcc';
|
||||
$content = `$cc -E -x c -DLTM_ALL $filename`;
|
||||
$content =~ s/^# 1 "$filename".*?^# 2 "$filename"//ms;
|
||||
}
|
||||
my $cc = $ENV{'CC'} || 'gcc';
|
||||
$content = `$cc -E -x c -DLTM_ALL $filename`;
|
||||
$content =~ s/^# 1 "$filename".*?^# 2 "$filename"//ms;
|
||||
|
||||
# convert filename to upper case so we can use it as a define
|
||||
$filename =~ tr/[a-z]/[A-Z]/;
|
||||
@ -434,8 +428,6 @@ sub generate_def {
|
||||
@files = map { my $x = $_; $x =~ s/^bn_|\.c$//g; $x; } @files;
|
||||
@files = grep(!/mp_radix_smap/, @files);
|
||||
|
||||
push(@files, qw(mp_set_int mp_set_long mp_set_long_long mp_get_int mp_get_long mp_get_long_long mp_init_set_int));
|
||||
|
||||
my $files = join("\n ", sort(grep(/^mp_/, @files)));
|
||||
write_file "tommath.def", "; libtommath
|
||||
;
|
||||
|
@ -316,10 +316,6 @@
|
||||
RelativePath="bn_cutoffs.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="bn_deprecated.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="bn_mp_2expt.c"
|
||||
>
|
||||
|
11
makefile
11
makefile
@ -26,10 +26,10 @@ 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 \
|
||||
OBJECTS=bn_cutoffs.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_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \
|
||||
bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \
|
||||
bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \
|
||||
@ -95,9 +95,6 @@ uninstall:
|
||||
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
|
||||
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
||||
|
||||
test_standalone: test
|
||||
@echo "test_standalone is deprecated, please use make-target 'test'"
|
||||
|
||||
DEMOS=test mtest_opponent
|
||||
|
||||
define DEMO_template
|
||||
|
@ -29,10 +29,10 @@ 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 \
|
||||
OBJECTS=bn_cutoffs.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_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \
|
||||
bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \
|
||||
bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \
|
||||
@ -86,9 +86,6 @@ test.exe: demo/shared.o demo/test.o $(LIBMAIN_S)
|
||||
$(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@
|
||||
@echo NOTICE: start the tests by launching test.exe
|
||||
|
||||
test_standalone: test.exe
|
||||
@echo test_standalone is deprecated, please use make-target 'test.exe'
|
||||
|
||||
all: $(LIBMAIN_S) test.exe
|
||||
|
||||
tune: $(LIBNAME_S)
|
||||
|
@ -21,10 +21,10 @@ 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 \
|
||||
OBJECTS=bn_cutoffs.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_expt_u32.obj bn_mp_exptmod.obj bn_mp_exteuclid.obj bn_mp_fread.obj \
|
||||
bn_mp_from_sbin.obj bn_mp_from_ubin.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_double.obj bn_mp_get_i32.obj \
|
||||
bn_mp_get_i64.obj bn_mp_get_l.obj bn_mp_get_ll.obj bn_mp_get_mag_u32.obj bn_mp_get_mag_u64.obj bn_mp_get_mag_ul.obj \
|
||||
@ -72,9 +72,6 @@ test.exe: $(LIBMAIN_S) demo/shared.obj demo/test.obj
|
||||
cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/shared.c demo/test.c /Fe$@
|
||||
@echo NOTICE: start the tests by launching test.exe
|
||||
|
||||
test_standalone: test.exe
|
||||
@echo test_standalone is deprecated, please use make-target 'test.exe'
|
||||
|
||||
all: $(LIBMAIN_S) test.exe
|
||||
|
||||
tune: $(LIBMAIN_S)
|
||||
|
@ -23,10 +23,10 @@ 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 \
|
||||
OBJECTS=bn_cutoffs.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_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \
|
||||
bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \
|
||||
bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \
|
||||
@ -79,9 +79,6 @@ uninstall:
|
||||
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
||||
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
|
||||
|
||||
test_standalone: test
|
||||
@echo "test_standalone is deprecated, please use make-target 'test'"
|
||||
|
||||
test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o
|
||||
$(LTLINK) $(LTM_LDFLAGS) demo/$@.o $^ -o $@
|
||||
|
||||
|
@ -30,10 +30,10 @@ 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 \
|
||||
OBJECTS=bn_cutoffs.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_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \
|
||||
bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \
|
||||
bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \
|
||||
@ -84,9 +84,6 @@ test: demo/shared.o demo/test.o $(LIBMAIN_S)
|
||||
$(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@
|
||||
@echo "NOTICE: start the tests by: ./test"
|
||||
|
||||
test_standalone: test
|
||||
@echo "test_standalone is deprecated, please use make-target 'test'"
|
||||
|
||||
all: $(LIBMAIN_S) test
|
||||
|
||||
tune: $(LIBMAIN_S)
|
||||
|
@ -44,11 +44,8 @@ EXPORTS
|
||||
mp_get_double
|
||||
mp_get_i32
|
||||
mp_get_i64
|
||||
mp_get_int
|
||||
mp_get_l
|
||||
mp_get_ll
|
||||
mp_get_long
|
||||
mp_get_long_long
|
||||
mp_get_mag_u32
|
||||
mp_get_mag_u64
|
||||
mp_get_mag_ul
|
||||
@ -63,7 +60,6 @@ EXPORTS
|
||||
mp_init_ll
|
||||
mp_init_multi
|
||||
mp_init_set
|
||||
mp_init_set_int
|
||||
mp_init_size
|
||||
mp_init_u32
|
||||
mp_init_u64
|
||||
@ -118,11 +114,8 @@ EXPORTS
|
||||
mp_set_double
|
||||
mp_set_i32
|
||||
mp_set_i64
|
||||
mp_set_int
|
||||
mp_set_l
|
||||
mp_set_ll
|
||||
mp_set_long
|
||||
mp_set_long_long
|
||||
mp_set_u32
|
||||
mp_set_u64
|
||||
mp_set_ul
|
||||
|
140
tommath.h
140
tommath.h
@ -6,12 +6,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef LTM_NO_FILE
|
||||
# warning LTM_NO_FILE has been deprecated, use MP_NO_FILE.
|
||||
# define MP_NO_FILE
|
||||
#endif
|
||||
|
||||
#ifndef MP_NO_FILE
|
||||
# include <stdio.h>
|
||||
@ -98,11 +92,6 @@ typedef uint64_t private_mp_word;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* mp_word is a private type */
|
||||
#define mp_word MP_DEPRECATED_PRAGMA("mp_word has been made private") private_mp_word
|
||||
|
||||
#define MP_SIZEOF_MP_DIGIT (MP_DEPRECATED_PRAGMA("MP_SIZEOF_MP_DIGIT has been deprecated, use sizeof (mp_digit)") sizeof (mp_digit))
|
||||
|
||||
#define MP_MASK ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
|
||||
#define MP_DIGIT_MAX MP_MASK
|
||||
|
||||
@ -111,10 +100,6 @@ typedef uint64_t private_mp_word;
|
||||
#define MP_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
|
||||
#define MP_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
|
||||
|
||||
#define LTM_PRIME_BBS (MP_DEPRECATED_PRAGMA("LTM_PRIME_BBS has been deprecated, use MP_PRIME_BBS") MP_PRIME_BBS)
|
||||
#define LTM_PRIME_SAFE (MP_DEPRECATED_PRAGMA("LTM_PRIME_SAFE has been deprecated, use MP_PRIME_SAFE") MP_PRIME_SAFE)
|
||||
#define LTM_PRIME_2MSB_ON (MP_DEPRECATED_PRAGMA("LTM_PRIME_2MSB_ON has been deprecated, use MP_PRIME_2MSB_ON") MP_PRIME_2MSB_ON)
|
||||
|
||||
typedef enum {
|
||||
MP_ZPOS = 0, /* positive */
|
||||
MP_NEG = 1 /* negative */
|
||||
@ -164,22 +149,6 @@ TOOM_SQR_CUTOFF;
|
||||
/* define this to use lower memory usage routines (exptmods mostly) */
|
||||
/* #define MP_LOW_MEM */
|
||||
|
||||
/* default precision */
|
||||
#ifndef MP_PREC
|
||||
# ifndef MP_LOW_MEM
|
||||
# define PRIVATE_MP_PREC 32 /* default digits of precision */
|
||||
# elif defined(MP_8BIT)
|
||||
# define PRIVATE_MP_PREC 16 /* default digits of precision */
|
||||
# else
|
||||
# define PRIVATE_MP_PREC 8 /* default digits of precision */
|
||||
# endif
|
||||
# define MP_PREC (MP_DEPRECATED_PRAGMA("MP_PREC is an internal macro") PRIVATE_MP_PREC)
|
||||
#endif
|
||||
|
||||
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
|
||||
#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
|
||||
#define MP_WARRAY (MP_DEPRECATED_PRAGMA("MP_WARRAY is an internal macro") PRIVATE_MP_WARRAY)
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define MP_NULL_TERMINATED __attribute__((sentinel))
|
||||
#else
|
||||
@ -221,11 +190,6 @@ TOOM_SQR_CUTOFF;
|
||||
# define MP_DEPRECATED_PRAGMA(s)
|
||||
#endif
|
||||
|
||||
#define DIGIT_BIT (MP_DEPRECATED_PRAGMA("DIGIT_BIT macro is deprecated, MP_DIGIT_BIT instead") MP_DIGIT_BIT)
|
||||
#define USED(m) (MP_DEPRECATED_PRAGMA("USED macro is deprecated, use z->used instead") (m)->used)
|
||||
#define DIGIT(m, k) (MP_DEPRECATED_PRAGMA("DIGIT macro is deprecated, use z->dp instead") (m)->dp[(k)])
|
||||
#define SIGN(m) (MP_DEPRECATED_PRAGMA("SIGN macro is deprecated, use z->sign instead") (m)->sign)
|
||||
|
||||
/* the infamous mp_int structure */
|
||||
typedef struct {
|
||||
int used, alloc;
|
||||
@ -233,10 +197,6 @@ typedef struct {
|
||||
mp_digit *dp;
|
||||
} mp_int;
|
||||
|
||||
/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
|
||||
typedef int private_mp_prime_callback(unsigned char *dst, int len, void *dat);
|
||||
typedef private_mp_prime_callback MP_DEPRECATED(mp_rand_source) ltm_prime_callback;
|
||||
|
||||
/* error code to char* string */
|
||||
const char *mp_error_to_string(mp_err code) MP_WUR;
|
||||
|
||||
@ -328,15 +288,6 @@ mp_err mp_init_ull(mp_int *a, unsigned long long b) MP_WUR;
|
||||
void mp_set(mp_int *a, mp_digit b);
|
||||
mp_err mp_init_set(mp_int *a, mp_digit b) MP_WUR;
|
||||
|
||||
/* get integer, set integer and init with integer (deprecated) */
|
||||
MP_DEPRECATED(mp_get_mag_u32/mp_get_u32) unsigned long mp_get_int(const mp_int *a) MP_WUR;
|
||||
MP_DEPRECATED(mp_get_mag_ul/mp_get_ul) unsigned long mp_get_long(const mp_int *a) MP_WUR;
|
||||
MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
|
||||
MP_DEPRECATED(mp_set_ul) 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_ull) mp_err mp_set_long_long(mp_int *a, unsigned long long b);
|
||||
MP_DEPRECATED(mp_init_ul) 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;
|
||||
|
||||
@ -346,16 +297,6 @@ mp_err mp_init_copy(mp_int *a, const mp_int *b) MP_WUR;
|
||||
/* trim unused digits */
|
||||
void mp_clamp(mp_int *a);
|
||||
|
||||
|
||||
/* export binary data */
|
||||
MP_DEPRECATED(mp_pack) mp_err mp_export(void *rop, size_t *countp, int order, size_t size,
|
||||
int endian, size_t nails, const mp_int *op) MP_WUR;
|
||||
|
||||
/* import binary data */
|
||||
MP_DEPRECATED(mp_unpack) mp_err mp_import(mp_int *rop, size_t count, int order,
|
||||
size_t size, int endian, size_t nails,
|
||||
const void *op) MP_WUR;
|
||||
|
||||
/* unpack binary data */
|
||||
mp_err mp_unpack(mp_int *rop, size_t count, mp_order order, size_t size, mp_endian endian,
|
||||
size_t nails, const void *op) MP_WUR;
|
||||
@ -401,46 +342,24 @@ int mp_cnt_lsb(const mp_int *a) MP_WUR;
|
||||
|
||||
/* makes a pseudo-random mp_int of a given size */
|
||||
mp_err mp_rand(mp_int *a, int digits) MP_WUR;
|
||||
/* makes a pseudo-random small int of a given size */
|
||||
MP_DEPRECATED(mp_rand) mp_err mp_rand_digit(mp_digit *r) MP_WUR;
|
||||
/* use custom random data source instead of source provided the platform */
|
||||
void mp_rand_source(mp_err(*source)(void *out, size_t size));
|
||||
|
||||
#ifdef MP_PRNG_ENABLE_LTM_RNG
|
||||
# warning MP_PRNG_ENABLE_LTM_RNG has been deprecated, use mp_rand_source instead.
|
||||
/* A last resort to provide random data on systems without any of the other
|
||||
* implemented ways to gather entropy.
|
||||
* It is compatible with `rng_get_bytes()` from libtomcrypt so you could
|
||||
* provide that one and then set `ltm_rng = rng_get_bytes;` */
|
||||
extern unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
|
||||
extern void (*ltm_rng_callback)(void);
|
||||
#endif
|
||||
|
||||
/* ---> binary operations <--- */
|
||||
|
||||
/* Checks the bit at position b and returns MP_YES
|
||||
* if the bit is 1, MP_NO if it is 0 and MP_VAL
|
||||
* in case of error
|
||||
*/
|
||||
MP_DEPRECATED(s_mp_get_bit) int mp_get_bit(const mp_int *a, int b) MP_WUR;
|
||||
|
||||
/* c = a XOR b (two complement) */
|
||||
MP_DEPRECATED(mp_xor) mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
|
||||
mp_err mp_xor(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
|
||||
|
||||
/* c = a OR b (two complement) */
|
||||
MP_DEPRECATED(mp_or) mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
|
||||
mp_err mp_or(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
|
||||
|
||||
/* c = a AND b (two complement) */
|
||||
MP_DEPRECATED(mp_and) mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
|
||||
mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
|
||||
|
||||
/* b = ~a (bitwise not, two complement) */
|
||||
mp_err mp_complement(const mp_int *a, mp_int *b) MP_WUR;
|
||||
|
||||
/* right shift with sign extension */
|
||||
MP_DEPRECATED(mp_signed_rsh) mp_err mp_tc_div_2d(const mp_int *a, int b, mp_int *c) MP_WUR;
|
||||
mp_err mp_signed_rsh(const mp_int *a, int b, mp_int *c) MP_WUR;
|
||||
|
||||
/* ---> Basic arithmetic <--- */
|
||||
@ -532,8 +451,6 @@ mp_err mp_lcm(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
|
||||
* returns error if a < 0 and b is even
|
||||
*/
|
||||
mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
|
||||
MP_DEPRECATED(mp_root_u32) mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c) MP_WUR;
|
||||
MP_DEPRECATED(mp_root_u32) mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR;
|
||||
|
||||
/* special sqrt algo */
|
||||
mp_err mp_sqrt(const mp_int *arg, mp_int *ret) MP_WUR;
|
||||
@ -544,9 +461,6 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret) MP_WU
|
||||
/* is number a square? */
|
||||
mp_err mp_is_square(const mp_int *arg, mp_bool *ret) MP_WUR;
|
||||
|
||||
/* computes the jacobi c = (a | n) (or Legendre if b is prime) */
|
||||
MP_DEPRECATED(mp_kronecker) mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c) MP_WUR;
|
||||
|
||||
/* computes the Kronecker symbol c = (a | p) (like jacobi() but with {a,p} in Z */
|
||||
mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) MP_WUR;
|
||||
|
||||
@ -603,20 +517,6 @@ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
|
||||
|
||||
/* ---> Primes <--- */
|
||||
|
||||
/* number of primes */
|
||||
#ifdef MP_8BIT
|
||||
# define PRIVATE_MP_PRIME_TAB_SIZE 31
|
||||
#else
|
||||
# define PRIVATE_MP_PRIME_TAB_SIZE 256
|
||||
#endif
|
||||
#define PRIME_SIZE (MP_DEPRECATED_PRAGMA("PRIME_SIZE has been made internal") PRIVATE_MP_PRIME_TAB_SIZE)
|
||||
|
||||
/* table of first PRIME_SIZE primes */
|
||||
MP_DEPRECATED(internal) extern const mp_digit ltm_prime_tab[PRIVATE_MP_PRIME_TAB_SIZE];
|
||||
|
||||
/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
|
||||
MP_DEPRECATED(mp_prime_is_prime) mp_err mp_prime_is_divisible(const mp_int *a, mp_bool *result) MP_WUR;
|
||||
|
||||
/* performs one Fermat test of "a" using base "b".
|
||||
* Sets result to 0 if composite or 1 if probable prime
|
||||
*/
|
||||
@ -665,17 +565,6 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result) MP_WUR;
|
||||
*/
|
||||
mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) MP_WUR;
|
||||
|
||||
/* makes a truly random prime of a given size (bytes),
|
||||
* call with bbs = 1 if you want it to be congruent to 3 mod 4
|
||||
*
|
||||
* You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
|
||||
* have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
|
||||
* so it can be NULL
|
||||
*
|
||||
* The prime generated will be larger than 2^(8*size).
|
||||
*/
|
||||
#define mp_prime_random(a, t, size, bbs, cb, dat) (MP_DEPRECATED_PRAGMA("mp_prime_random has been deprecated, use mp_prime_rand instead") mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?MP_PRIME_BBS:0, cb, dat))
|
||||
|
||||
/* makes a truly random prime of a given size (bits),
|
||||
*
|
||||
* Flags are as follows:
|
||||
@ -689,8 +578,6 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) MP_WUR;
|
||||
* so it can be NULL
|
||||
*
|
||||
*/
|
||||
MP_DEPRECATED(mp_prime_rand) mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags,
|
||||
private_mp_prime_callback cb, void *dat) MP_WUR;
|
||||
mp_err mp_prime_rand(mp_int *a, int t, int size, int flags) MP_WUR;
|
||||
|
||||
/* Integer logarithm to integer base */
|
||||
@ -698,23 +585,10 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c) MP_WUR;
|
||||
|
||||
/* c = a**b */
|
||||
mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
|
||||
MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c) MP_WUR;
|
||||
MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR;
|
||||
|
||||
/* ---> radix conversion <--- */
|
||||
int mp_count_bits(const mp_int *a) MP_WUR;
|
||||
|
||||
|
||||
MP_DEPRECATED(mp_ubin_size) int mp_unsigned_bin_size(const mp_int *a) MP_WUR;
|
||||
MP_DEPRECATED(mp_from_ubin) mp_err mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c) MP_WUR;
|
||||
MP_DEPRECATED(mp_to_ubin) mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b) MP_WUR;
|
||||
MP_DEPRECATED(mp_to_ubin) mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) MP_WUR;
|
||||
|
||||
MP_DEPRECATED(mp_sbin_size) int mp_signed_bin_size(const mp_int *a) MP_WUR;
|
||||
MP_DEPRECATED(mp_from_sbin) mp_err mp_read_signed_bin(mp_int *a, const unsigned char *b, int c) MP_WUR;
|
||||
MP_DEPRECATED(mp_to_sbin) mp_err mp_to_signed_bin(const mp_int *a, unsigned char *b) MP_WUR;
|
||||
MP_DEPRECATED(mp_to_sbin) mp_err mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) MP_WUR;
|
||||
|
||||
size_t mp_ubin_size(const mp_int *a) MP_WUR;
|
||||
mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR;
|
||||
mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR;
|
||||
@ -724,8 +598,6 @@ mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR;
|
||||
mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR;
|
||||
|
||||
mp_err mp_read_radix(mp_int *a, const char *str, int radix) MP_WUR;
|
||||
MP_DEPRECATED(mp_to_radix) mp_err mp_toradix(const mp_int *a, char *str, int radix) MP_WUR;
|
||||
MP_DEPRECATED(mp_to_radix) mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) MP_WUR;
|
||||
mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, int radix) MP_WUR;
|
||||
mp_err mp_radix_size(const mp_int *a, int radix, int *size) MP_WUR;
|
||||
|
||||
@ -734,18 +606,6 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream) MP_WUR;
|
||||
mp_err mp_fwrite(const mp_int *a, int radix, FILE *stream) MP_WUR;
|
||||
#endif
|
||||
|
||||
#define mp_read_raw(mp, str, len) (MP_DEPRECATED_PRAGMA("replaced by mp_read_signed_bin") mp_read_signed_bin((mp), (str), (len)))
|
||||
#define mp_raw_size(mp) (MP_DEPRECATED_PRAGMA("replaced by mp_signed_bin_size") mp_signed_bin_size(mp))
|
||||
#define mp_toraw(mp, str) (MP_DEPRECATED_PRAGMA("replaced by mp_to_signed_bin") mp_to_signed_bin((mp), (str)))
|
||||
#define mp_read_mag(mp, str, len) (MP_DEPRECATED_PRAGMA("replaced by mp_read_unsigned_bin") mp_read_unsigned_bin((mp), (str), (len))
|
||||
#define mp_mag_size(mp) (MP_DEPRECATED_PRAGMA("replaced by mp_unsigned_bin_size") mp_unsigned_bin_size(mp))
|
||||
#define mp_tomag(mp, str) (MP_DEPRECATED_PRAGMA("replaced by mp_to_unsigned_bin") mp_to_unsigned_bin((mp), (str)))
|
||||
|
||||
#define mp_tobinary(M, S) (MP_DEPRECATED_PRAGMA("replaced by mp_to_binary") mp_toradix((M), (S), 2))
|
||||
#define mp_tooctal(M, S) (MP_DEPRECATED_PRAGMA("replaced by mp_to_octal") mp_toradix((M), (S), 8))
|
||||
#define mp_todecimal(M, S) (MP_DEPRECATED_PRAGMA("replaced by mp_to_decimal") mp_toradix((M), (S), 10))
|
||||
#define mp_tohex(M, S) (MP_DEPRECATED_PRAGMA("replaced by mp_to_hex") mp_toradix((M), (S), 16))
|
||||
|
||||
#define mp_to_binary(M, S, N) mp_to_radix((M), (S), (N), NULL, 2)
|
||||
#define mp_to_octal(M, S, N) mp_to_radix((M), (S), (N), NULL, 8)
|
||||
#define mp_to_decimal(M, S, N) mp_to_radix((M), (S), (N), NULL, 10)
|
||||
|
@ -12,7 +12,6 @@
|
||||
#define LTM1
|
||||
#if defined(LTM_ALL)
|
||||
# define BN_CUTOFFS_C
|
||||
# define BN_DEPRECATED_C
|
||||
# define BN_MP_2EXPT_C
|
||||
# define BN_MP_ABS_C
|
||||
# define BN_MP_ADD_C
|
||||
@ -173,93 +172,6 @@
|
||||
#if defined(BN_CUTOFFS_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_DEPRECATED_C)
|
||||
# define BN_FAST_MP_INVMOD_C
|
||||
# define BN_FAST_MP_MONTGOMERY_REDUCE_C
|
||||
# define BN_FAST_S_MP_MUL_DIGS_C
|
||||
# define BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
# define BN_FAST_S_MP_SQR_C
|
||||
# define BN_MP_AND_C
|
||||
# define BN_MP_BALANCE_MUL_C
|
||||
# define BN_MP_CMP_D_C
|
||||
# define BN_MP_EXPORT_C
|
||||
# define BN_MP_EXPTMOD_FAST_C
|
||||
# define BN_MP_EXPT_D_C
|
||||
# define BN_MP_EXPT_D_EX_C
|
||||
# define BN_MP_EXPT_U32_C
|
||||
# define BN_MP_FROM_SBIN_C
|
||||
# define BN_MP_FROM_UBIN_C
|
||||
# define BN_MP_GET_BIT_C
|
||||
# define BN_MP_GET_INT_C
|
||||
# define BN_MP_GET_LONG_C
|
||||
# define BN_MP_GET_LONG_LONG_C
|
||||
# define BN_MP_GET_MAG_U32_C
|
||||
# define BN_MP_GET_MAG_ULL_C
|
||||
# define BN_MP_GET_MAG_UL_C
|
||||
# define BN_MP_IMPORT_C
|
||||
# define BN_MP_INIT_SET_INT_C
|
||||
# define BN_MP_INIT_U32_C
|
||||
# define BN_MP_INVMOD_SLOW_C
|
||||
# define BN_MP_JACOBI_C
|
||||
# define BN_MP_KARATSUBA_MUL_C
|
||||
# define BN_MP_KARATSUBA_SQR_C
|
||||
# define BN_MP_KRONECKER_C
|
||||
# define BN_MP_N_ROOT_C
|
||||
# define BN_MP_N_ROOT_EX_C
|
||||
# define BN_MP_OR_C
|
||||
# define BN_MP_PACK_C
|
||||
# define BN_MP_PRIME_IS_DIVISIBLE_C
|
||||
# define BN_MP_PRIME_RANDOM_EX_C
|
||||
# define BN_MP_RAND_DIGIT_C
|
||||
# define BN_MP_READ_SIGNED_BIN_C
|
||||
# define BN_MP_READ_UNSIGNED_BIN_C
|
||||
# define BN_MP_ROOT_U32_C
|
||||
# define BN_MP_SBIN_SIZE_C
|
||||
# define BN_MP_SET_INT_C
|
||||
# define BN_MP_SET_LONG_C
|
||||
# define BN_MP_SET_LONG_LONG_C
|
||||
# define BN_MP_SET_U32_C
|
||||
# define BN_MP_SET_U64_C
|
||||
# define BN_MP_SIGNED_BIN_SIZE_C
|
||||
# define BN_MP_SIGNED_RSH_C
|
||||
# define BN_MP_TC_AND_C
|
||||
# define BN_MP_TC_DIV_2D_C
|
||||
# define BN_MP_TC_OR_C
|
||||
# define BN_MP_TC_XOR_C
|
||||
# define BN_MP_TOOM_MUL_C
|
||||
# define BN_MP_TOOM_SQR_C
|
||||
# define BN_MP_TORADIX_C
|
||||
# define BN_MP_TORADIX_N_C
|
||||
# define BN_MP_TO_RADIX_C
|
||||
# define BN_MP_TO_SBIN_C
|
||||
# define BN_MP_TO_SIGNED_BIN_C
|
||||
# define BN_MP_TO_SIGNED_BIN_N_C
|
||||
# define BN_MP_TO_UBIN_C
|
||||
# define BN_MP_TO_UNSIGNED_BIN_C
|
||||
# define BN_MP_TO_UNSIGNED_BIN_N_C
|
||||
# define BN_MP_UBIN_SIZE_C
|
||||
# define BN_MP_UNPACK_C
|
||||
# define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
# define BN_MP_XOR_C
|
||||
# define BN_S_MP_BALANCE_MUL_C
|
||||
# define BN_S_MP_EXPTMOD_FAST_C
|
||||
# define BN_S_MP_GET_BIT_C
|
||||
# define BN_S_MP_INVMOD_FAST_C
|
||||
# define BN_S_MP_INVMOD_SLOW_C
|
||||
# define BN_S_MP_KARATSUBA_MUL_C
|
||||
# define BN_S_MP_KARATSUBA_SQR_C
|
||||
# define BN_S_MP_MONTGOMERY_REDUCE_FAST_C
|
||||
# define BN_S_MP_MUL_DIGS_FAST_C
|
||||
# define BN_S_MP_MUL_HIGH_DIGS_FAST_C
|
||||
# define BN_S_MP_PRIME_IS_DIVISIBLE_C
|
||||
# define BN_S_MP_PRIME_RANDOM_EX_C
|
||||
# define BN_S_MP_RAND_SOURCE_C
|
||||
# define BN_S_MP_REVERSE_C
|
||||
# define BN_S_MP_SQR_FAST_C
|
||||
# define BN_S_MP_TOOM_MUL_C
|
||||
# define BN_S_MP_TOOM_SQR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_2EXPT_C)
|
||||
# define BN_MP_GROW_C
|
||||
# define BN_MP_ZERO_C
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "tommath.h"
|
||||
#include "tommath_class.h"
|
||||
#include <limits.h>
|
||||
|
||||
/*
|
||||
* Private symbols
|
||||
@ -146,7 +147,6 @@ extern void MP_FREE(void *mem, size_t size);
|
||||
#define MP_HAS(x) (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
|
||||
|
||||
/* TODO: Remove private_mp_word as soon as deprecated mp_word is removed from tommath. */
|
||||
#undef mp_word
|
||||
typedef private_mp_word mp_word;
|
||||
|
||||
#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
@ -163,14 +163,18 @@ typedef private_mp_word mp_word;
|
||||
#define MP_SIZEOF_BITS(type) ((size_t)CHAR_BIT * sizeof(type))
|
||||
#define MP_MAXFAST (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
|
||||
|
||||
/* TODO: Remove PRIVATE_MP_WARRAY as soon as deprecated MP_WARRAY is removed from tommath.h */
|
||||
#undef MP_WARRAY
|
||||
#define MP_WARRAY PRIVATE_MP_WARRAY
|
||||
#define MP_WARRAY (1 << ((MP_SIZEOF_BITS(mp_word) - (2 * MP_DIGIT_BIT)) + 1))
|
||||
|
||||
/* TODO: Remove PRIVATE_MP_PREC as soon as deprecated MP_PREC is removed from tommath.h */
|
||||
#ifdef PRIVATE_MP_PREC
|
||||
# undef MP_PREC
|
||||
# define MP_PREC PRIVATE_MP_PREC
|
||||
|
||||
/* default precision */
|
||||
#ifndef MP_PREC
|
||||
# ifndef MP_LOW_MEM
|
||||
# define MP_PREC 32 /* default digits of precision */
|
||||
# elif defined(MP_8BIT)
|
||||
# define MP_PREC 16 /* default digits of precision */
|
||||
# else
|
||||
# define MP_PREC 8 /* default digits of precision */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Minimum number of available digits in mp_int, MP_PREC >= MP_MIN_PREC */
|
||||
@ -202,7 +206,8 @@ MP_PRIVATE mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_dig
|
||||
MP_PRIVATE mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
|
||||
MP_PRIVATE mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
|
||||
MP_PRIVATE mp_err s_mp_rand_platform(void *p, size_t n) MP_WUR;
|
||||
MP_PRIVATE mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat);
|
||||
typedef int mp_prime_callback(unsigned char *dst, int len, void *dat);
|
||||
MP_PRIVATE mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, mp_prime_callback cb, void *dat);
|
||||
MP_PRIVATE void s_mp_reverse(unsigned char *s, size_t len);
|
||||
MP_PRIVATE mp_err s_mp_prime_is_divisible(const mp_int *a, mp_bool *result);
|
||||
|
||||
@ -210,31 +215,17 @@ MP_PRIVATE mp_err s_mp_prime_is_divisible(const mp_int *a, mp_bool *result);
|
||||
MP_PRIVATE mp_err s_mp_rand_jenkins(void *p, size_t n) MP_WUR;
|
||||
MP_PRIVATE void s_mp_rand_jenkins_init(uint64_t seed);
|
||||
|
||||
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;
|
||||
extern MP_PRIVATE const mp_digit *s_mp_prime_tab;
|
||||
#define MP_RMAP_REVERSE_SIZE 88
|
||||
extern MP_PRIVATE const char s_mp_rmap[];
|
||||
extern MP_PRIVATE const uint8_t s_mp_rmap_reverse[];
|
||||
extern MP_PRIVATE const mp_digit s_mp_prime_tab[];
|
||||
|
||||
/* 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,
|
||||
mp_digit rho);
|
||||
MP_DEPRECATED(s_mp_mul_digs_fast) mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c,
|
||||
int digs);
|
||||
MP_DEPRECATED(s_mp_mul_high_digs_fast) mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b,
|
||||
mp_int *c,
|
||||
int digs);
|
||||
MP_DEPRECATED(s_mp_sqr_fast) mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b);
|
||||
MP_DEPRECATED(s_mp_balance_mul) mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c);
|
||||
MP_DEPRECATED(s_mp_exptmod_fast) mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P,
|
||||
mp_int *Y,
|
||||
int redmode);
|
||||
MP_DEPRECATED(s_mp_invmod_slow) mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c);
|
||||
MP_DEPRECATED(s_mp_karatsuba_mul) mp_err mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c);
|
||||
MP_DEPRECATED(s_mp_karatsuba_sqr) mp_err mp_karatsuba_sqr(const mp_int *a, mp_int *b);
|
||||
MP_DEPRECATED(s_mp_toom_mul) mp_err mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c);
|
||||
MP_DEPRECATED(s_mp_toom_sqr) mp_err mp_toom_sqr(const mp_int *a, mp_int *b);
|
||||
MP_DEPRECATED(s_mp_reverse) void bn_reverse(unsigned char *s, int len);
|
||||
/* number of primes */
|
||||
#ifdef MP_8BIT
|
||||
# define MP_PRIME_TAB_SIZE 31
|
||||
#else
|
||||
# define MP_PRIME_TAB_SIZE 256
|
||||
#endif
|
||||
|
||||
#define MP_GET_ENDIANNESS(x) \
|
||||
do{\
|
||||
|
Loading…
Reference in New Issue
Block a user