Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions bn_deprecated.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "tommath_private.h"
#ifdef BN_DEPRECATED_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
/* LibTomMath, multiple-precision integer library -- Tom St Denis */

/* SPDX-License-Identifier: Unlicense */
#include <tommath_private.h>
#ifdef BN_FAST_MP_INVMOD_C
int 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
int 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
int 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
int 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
int 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
int 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
int 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
int 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
int 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
int mp_karatsuba_sqr(const mp_int *a, mp_int *b)
{
return s_mp_karatsuba_sqr(a, b);
}
#endif
#ifdef BN_MP_TOOM_MUL_C
int 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
int mp_toom_sqr(const mp_int *a, mp_int *b)
{
return s_mp_toom_sqr(a, b);
}
#endif
#ifdef BN_REVERSE_C
void bn_reverse(unsigned char *s, int len)
{
s_mp_reverse(s, len);
}
#endif
#endif
2 changes: 1 addition & 1 deletion bn_mp_clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void mp_clear(mp_int *a)
}

/* free ram */
XFREE(a->dp, sizeof(mp_digit) * (size_t)a->alloc);
MP_FREE(a->dp, sizeof(mp_digit) * (size_t)a->alloc);

/* reset members to make debugging easier */
a->dp = NULL;
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_cnt_lsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int mp_cnt_lsb(const mp_int *a)
mp_digit q, qq;

/* easy out */
if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion bn_mp_count_bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int mp_count_bits(const mp_int *a)
mp_digit q;

/* shortcut */
if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions bn_mp_decr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int mp_decr(mp_int *a)
{
int e = MP_OKAY;
if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
mp_set(a,1uL);
a->sign = MP_NEG;
return MP_OKAY;
Expand All @@ -17,7 +17,7 @@ int mp_decr(mp_int *a)
return e;
}
/* There is no -0 in LTM */
if (!IS_ZERO(a)) {
if (!MP_IS_ZERO(a)) {
a->sign = MP_NEG;
}
return MP_OKAY;
Expand Down
8 changes: 4 additions & 4 deletions bn_mp_div.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
int res, n, n2;

/* is divisor zero ? */
if (IS_ZERO(b)) {
if (MP_IS_ZERO(b)) {
return MP_VAL;
}

Expand Down Expand Up @@ -62,11 +62,11 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
n2 = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
if (c != NULL) {
mp_exch(c, &q);
c->sign = IS_ZERO(c) ? MP_ZPOS : n2;
c->sign = MP_IS_ZERO(c) ? MP_ZPOS : n2;
}
if (d != NULL) {
mp_exch(d, &ta);
d->sign = IS_ZERO(d) ? MP_ZPOS : n;
d->sign = MP_IS_ZERO(d) ? MP_ZPOS : n;
}
LBL_ERR:
mp_clear_multi(&ta, &tb, &tq, &q, NULL);
Expand Down Expand Up @@ -94,7 +94,7 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
int res, n, t, i, norm, neg;

/* is divisor zero ? */
if (IS_ZERO(b)) {
if (MP_IS_ZERO(b)) {
return MP_VAL;
}

Expand Down
2 changes: 1 addition & 1 deletion bn_mp_div_d.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
}

/* quick outs */
if ((b == 1u) || IS_ZERO(a)) {
if ((b == 1u) || MP_IS_ZERO(a)) {
if (d != NULL) {
*d = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions bn_mp_exptmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
#endif

/* if the modulus is odd or dr != 0 use the montgomery method */
#ifdef BN_MP_EXPTMOD_FAST_C
if (IS_ODD(P) || (dr != 0)) {
return mp_exptmod_fast(G, X, P, Y, dr);
#ifdef BN_S_MP_EXPTMOD_FAST_C
if (MP_IS_ODD(P) || (dr != 0)) {
return s_mp_exptmod_fast(G, X, P, Y, dr);
} else {
#endif
#ifdef BN_S_MP_EXPTMOD_C
Expand All @@ -87,7 +87,7 @@ int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
/* no exptmod for evens */
return MP_VAL;
#endif
#ifdef BN_MP_EXPTMOD_FAST_C
#ifdef BN_S_MP_EXPTMOD_FAST_C
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_exteuclid.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_in
}

/* loop while v3 != 0 */
while (!IS_ZERO(&v3)) {
while (!MP_IS_ZERO(&v3)) {
/* q = u3/v3 */
if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) {
goto LBL_ERR;
Expand Down
8 changes: 4 additions & 4 deletions bn_mp_fwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream)
return err;
}

buf = (char *) XMALLOC((size_t)len);
buf = (char *) MP_MALLOC((size_t)len);
if (buf == NULL) {
return MP_MEM;
}

if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
XFREE(buf, len);
MP_FREE(buf, len);
return err;
}

for (x = 0; x < len; x++) {
if (fputc((int)buf[x], stream) == EOF) {
XFREE(buf, len);
MP_FREE(buf, len);
return MP_VAL;
}
}

XFREE(buf, len);
MP_FREE(buf, len);
return MP_OKAY;
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions bn_mp_gcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
int k, u_lsb, v_lsb, res;

/* either zero than gcd is the largest */
if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
return mp_abs(b, c);
}
if (IS_ZERO(b)) {
if (MP_IS_ZERO(b)) {
return mp_abs(a, c);
}

Expand All @@ -32,7 +32,7 @@ int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
/* B1. Find the common power of two for u and v */
u_lsb = mp_cnt_lsb(&u);
v_lsb = mp_cnt_lsb(&v);
k = MIN(u_lsb, v_lsb);
k = MP_MIN(u_lsb, v_lsb);

if (k > 0) {
/* divide the power of two out */
Expand All @@ -58,7 +58,7 @@ int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
}
}

while (!IS_ZERO(&v)) {
while (!MP_IS_ZERO(&v)) {
/* make sure v is the largest */
if (mp_cmp_mag(&u, &v) == MP_GT) {
/* swap u and v to make sure v is >= u */
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_get_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ unsigned long mp_get_long(const mp_int *a)
int i;
unsigned long res;

if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
return 0;
}

/* get number of digits of the lsb we have to read */
i = MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;

/* get most significant digit of result */
res = (unsigned long)a->dp[i];
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_get_long_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ unsigned long long mp_get_long_long(const mp_int *a)
int i;
unsigned long long res;

if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
return 0;
}

/* get number of digits of the lsb we have to read */
i = MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;

/* get most significant digit of result */
res = (unsigned long long)a->dp[i];
Expand Down
6 changes: 3 additions & 3 deletions bn_mp_grow.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ int mp_grow(mp_int *a, int size)
* in case the operation failed we don't want
* to overwrite the dp member of a.
*/
tmp = (mp_digit *) XREALLOC(a->dp,
(size_t)a->alloc * sizeof(mp_digit),
(size_t)size * sizeof(mp_digit));
tmp = (mp_digit *) MP_REALLOC(a->dp,
(size_t)a->alloc * sizeof(mp_digit),
(size_t)size * sizeof(mp_digit));
if (tmp == NULL) {
/* reallocation failed but "a" is still valid [can be freed] */
return MP_MEM;
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_ilogb.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int mp_ilogb(mp_int *a, mp_digit base, mp_int *c)
if (a->sign == MP_NEG) {
return MP_VAL;
}
if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
return MP_VAL;
}

Expand Down
4 changes: 2 additions & 2 deletions bn_mp_incr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int mp_incr(mp_int *a)
{
int e = MP_OKAY;
if (IS_ZERO(a)) {
if (MP_IS_ZERO(a)) {
mp_set(a,1uL);
return MP_OKAY;
} else if (a->sign == MP_NEG) {
Expand All @@ -16,7 +16,7 @@ int mp_incr(mp_int *a)
return e;
}
/* There is no -0 in LTM */
if (!IS_ZERO(a)) {
if (!MP_IS_ZERO(a)) {
a->sign = MP_NEG;
}
return MP_OKAY;
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int mp_init(mp_int *a)
{
/* allocate memory required and clear it */
a->dp = (mp_digit *) XCALLOC((size_t)MP_PREC, sizeof(mp_digit));
a->dp = (mp_digit *) MP_CALLOC((size_t)MP_PREC, sizeof(mp_digit));
if (a->dp == NULL) {
return MP_MEM;
}
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_init_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int mp_init_size(mp_int *a, int size)
size += (MP_PREC * 2) - (size % MP_PREC);

/* alloc mem */
a->dp = (mp_digit *) XCALLOC((size_t)size, sizeof(mp_digit));
a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit));
if (a->dp == NULL) {
return MP_MEM;
}
Expand Down
10 changes: 5 additions & 5 deletions bn_mp_invmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ int mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
return MP_VAL;
}

#ifdef BN_FAST_MP_INVMOD_C
#ifdef BN_S_MP_INVMOD_FAST_C
/* if the modulus is odd we can use a faster routine instead */
if (IS_ODD(b)) {
return fast_mp_invmod(a, b, c);
if (MP_IS_ODD(b)) {
return s_mp_invmod_fast(a, b, c);
}
#endif

#ifdef BN_MP_INVMOD_SLOW_C
return mp_invmod_slow(a, b, c);
#ifdef BN_S_MP_INVMOD_SLOW_C
return s_mp_invmod_slow(a, b, c);
#else
return MP_VAL;
#endif
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_is_square.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int mp_is_square(const mp_int *arg, int *ret)
return MP_VAL;
}

if (IS_ZERO(arg)) {
if (MP_IS_ZERO(arg)) {
return MP_OKAY;
}

Expand Down
2 changes: 1 addition & 1 deletion bn_mp_iseven.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

int mp_iseven(const mp_int *a)
{
return IS_EVEN(a) ? MP_YES : MP_NO;
return MP_IS_EVEN(a) ? MP_YES : MP_NO;
}
#endif
2 changes: 1 addition & 1 deletion bn_mp_isodd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

int mp_isodd(const mp_int *a)
{
return IS_ODD(a) ? MP_YES : MP_NO;
return MP_IS_ODD(a) ? MP_YES : MP_NO;
}
#endif
Loading