Skip to content

Commit a752242

Browse files
authored
Merge pull request #172 from minad/rename-internals
Rename internals
2 parents a105bc9 + 8bf2eaa commit a752242

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+5976
-4883
lines changed

bn_deprecated.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include "tommath_private.h"
2+
#ifdef BN_DEPRECATED_C
3+
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4+
/* SPDX-License-Identifier: Unlicense */
5+
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
6+
7+
/* SPDX-License-Identifier: Unlicense */
8+
#include <tommath_private.h>
9+
#ifdef BN_FAST_MP_INVMOD_C
10+
int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
11+
{
12+
return s_mp_invmod_fast(a, b, c);
13+
}
14+
#endif
15+
#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
16+
int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
17+
{
18+
return s_mp_montgomery_reduce_fast(x, n, rho);
19+
}
20+
#endif
21+
#ifdef BN_FAST_S_MP_MUL_DIGS_C
22+
int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
23+
{
24+
return s_mp_mul_digs_fast(a, b, c, digs);
25+
}
26+
#endif
27+
#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
28+
int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
29+
{
30+
return s_mp_mul_high_digs_fast(a, b, c, digs);
31+
}
32+
#endif
33+
#ifdef BN_FAST_S_MP_SQR_C
34+
int fast_s_mp_sqr(const mp_int *a, mp_int *b)
35+
{
36+
return s_mp_sqr_fast(a, b);
37+
}
38+
#endif
39+
#ifdef BN_MP_BALANCE_MUL_C
40+
int mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c)
41+
{
42+
return s_mp_balance_mul(a, b, c);
43+
}
44+
#endif
45+
#ifdef BN_MP_EXPTMOD_FAST_C
46+
int mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
47+
{
48+
return s_mp_exptmod_fast(G, X, P, Y, redmode);
49+
}
50+
#endif
51+
#ifdef BN_MP_INVMOD_SLOW_C
52+
int mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
53+
{
54+
return s_mp_invmod_slow(a, b, c);
55+
}
56+
#endif
57+
#ifdef BN_MP_KARATSUBA_MUL_C
58+
int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
59+
{
60+
return s_mp_karatsuba_mul(a, b, c);
61+
}
62+
#endif
63+
#ifdef BN_MP_KARATSUBA_SQR_C
64+
int mp_karatsuba_sqr(const mp_int *a, mp_int *b)
65+
{
66+
return s_mp_karatsuba_sqr(a, b);
67+
}
68+
#endif
69+
#ifdef BN_MP_TOOM_MUL_C
70+
int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
71+
{
72+
return s_mp_toom_mul(a, b, c);
73+
}
74+
#endif
75+
#ifdef BN_MP_TOOM_SQR_C
76+
int mp_toom_sqr(const mp_int *a, mp_int *b)
77+
{
78+
return s_mp_toom_sqr(a, b);
79+
}
80+
#endif
81+
#ifdef BN_REVERSE_C
82+
void bn_reverse(unsigned char *s, int len)
83+
{
84+
s_mp_reverse(s, len);
85+
}
86+
#endif
87+
#endif

bn_mp_clear.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void mp_clear(mp_int *a)
1616
}
1717

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

2121
/* reset members to make debugging easier */
2222
a->dp = NULL;

bn_mp_cnt_lsb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int mp_cnt_lsb(const mp_int *a)
1414
mp_digit q, qq;
1515

1616
/* easy out */
17-
if (IS_ZERO(a)) {
17+
if (MP_IS_ZERO(a)) {
1818
return 0;
1919
}
2020

bn_mp_count_bits.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int mp_count_bits(const mp_int *a)
1010
mp_digit q;
1111

1212
/* shortcut */
13-
if (IS_ZERO(a)) {
13+
if (MP_IS_ZERO(a)) {
1414
return 0;
1515
}
1616

bn_mp_decr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
int mp_decr(mp_int *a)
88
{
99
int e = MP_OKAY;
10-
if (IS_ZERO(a)) {
10+
if (MP_IS_ZERO(a)) {
1111
mp_set(a,1uL);
1212
a->sign = MP_NEG;
1313
return MP_OKAY;
@@ -17,7 +17,7 @@ int mp_decr(mp_int *a)
1717
return e;
1818
}
1919
/* There is no -0 in LTM */
20-
if (!IS_ZERO(a)) {
20+
if (!MP_IS_ZERO(a)) {
2121
a->sign = MP_NEG;
2222
}
2323
return MP_OKAY;

bn_mp_div.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
1212
int res, n, n2;
1313

1414
/* is divisor zero ? */
15-
if (IS_ZERO(b)) {
15+
if (MP_IS_ZERO(b)) {
1616
return MP_VAL;
1717
}
1818

@@ -62,11 +62,11 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
6262
n2 = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
6363
if (c != NULL) {
6464
mp_exch(c, &q);
65-
c->sign = IS_ZERO(c) ? MP_ZPOS : n2;
65+
c->sign = MP_IS_ZERO(c) ? MP_ZPOS : n2;
6666
}
6767
if (d != NULL) {
6868
mp_exch(d, &ta);
69-
d->sign = IS_ZERO(d) ? MP_ZPOS : n;
69+
d->sign = MP_IS_ZERO(d) ? MP_ZPOS : n;
7070
}
7171
LBL_ERR:
7272
mp_clear_multi(&ta, &tb, &tq, &q, NULL);
@@ -94,7 +94,7 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
9494
int res, n, t, i, norm, neg;
9595

9696
/* is divisor zero ? */
97-
if (IS_ZERO(b)) {
97+
if (MP_IS_ZERO(b)) {
9898
return MP_VAL;
9999
}
100100

bn_mp_div_d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
3535
}
3636

3737
/* quick outs */
38-
if ((b == 1u) || IS_ZERO(a)) {
38+
if ((b == 1u) || MP_IS_ZERO(a)) {
3939
if (d != NULL) {
4040
*d = 0;
4141
}

bn_mp_exptmod.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
7575
#endif
7676

7777
/* if the modulus is odd or dr != 0 use the montgomery method */
78-
#ifdef BN_MP_EXPTMOD_FAST_C
79-
if (IS_ODD(P) || (dr != 0)) {
80-
return mp_exptmod_fast(G, X, P, Y, dr);
78+
#ifdef BN_S_MP_EXPTMOD_FAST_C
79+
if (MP_IS_ODD(P) || (dr != 0)) {
80+
return s_mp_exptmod_fast(G, X, P, Y, dr);
8181
} else {
8282
#endif
8383
#ifdef BN_S_MP_EXPTMOD_C
@@ -87,7 +87,7 @@ int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
8787
/* no exptmod for evens */
8888
return MP_VAL;
8989
#endif
90-
#ifdef BN_MP_EXPTMOD_FAST_C
90+
#ifdef BN_S_MP_EXPTMOD_FAST_C
9191
}
9292
#endif
9393
}

bn_mp_exteuclid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_in
2828
}
2929

3030
/* loop while v3 != 0 */
31-
while (!IS_ZERO(&v3)) {
31+
while (!MP_IS_ZERO(&v3)) {
3232
/* q = u3/v3 */
3333
if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) {
3434
goto LBL_ERR;

bn_mp_fwrite.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream)
1313
return err;
1414
}
1515

16-
buf = (char *) XMALLOC((size_t)len);
16+
buf = (char *) MP_MALLOC((size_t)len);
1717
if (buf == NULL) {
1818
return MP_MEM;
1919
}
2020

2121
if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
22-
XFREE(buf, len);
22+
MP_FREE(buf, len);
2323
return err;
2424
}
2525

2626
for (x = 0; x < len; x++) {
2727
if (fputc((int)buf[x], stream) == EOF) {
28-
XFREE(buf, len);
28+
MP_FREE(buf, len);
2929
return MP_VAL;
3030
}
3131
}
3232

33-
XFREE(buf, len);
33+
MP_FREE(buf, len);
3434
return MP_OKAY;
3535
}
3636
#endif

bn_mp_gcd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
1010
int k, u_lsb, v_lsb, res;
1111

1212
/* either zero than gcd is the largest */
13-
if (IS_ZERO(a)) {
13+
if (MP_IS_ZERO(a)) {
1414
return mp_abs(b, c);
1515
}
16-
if (IS_ZERO(b)) {
16+
if (MP_IS_ZERO(b)) {
1717
return mp_abs(a, c);
1818
}
1919

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

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

61-
while (!IS_ZERO(&v)) {
61+
while (!MP_IS_ZERO(&v)) {
6262
/* make sure v is the largest */
6363
if (mp_cmp_mag(&u, &v) == MP_GT) {
6464
/* swap u and v to make sure v is >= u */

bn_mp_get_long.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ unsigned long mp_get_long(const mp_int *a)
99
int i;
1010
unsigned long res;
1111

12-
if (IS_ZERO(a)) {
12+
if (MP_IS_ZERO(a)) {
1313
return 0;
1414
}
1515

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

1919
/* get most significant digit of result */
2020
res = (unsigned long)a->dp[i];

bn_mp_get_long_long.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ unsigned long long mp_get_long_long(const mp_int *a)
99
int i;
1010
unsigned long long res;
1111

12-
if (IS_ZERO(a)) {
12+
if (MP_IS_ZERO(a)) {
1313
return 0;
1414
}
1515

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

1919
/* get most significant digit of result */
2020
res = (unsigned long long)a->dp[i];

bn_mp_grow.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ int mp_grow(mp_int *a, int size)
2020
* in case the operation failed we don't want
2121
* to overwrite the dp member of a.
2222
*/
23-
tmp = (mp_digit *) XREALLOC(a->dp,
24-
(size_t)a->alloc * sizeof(mp_digit),
25-
(size_t)size * sizeof(mp_digit));
23+
tmp = (mp_digit *) MP_REALLOC(a->dp,
24+
(size_t)a->alloc * sizeof(mp_digit),
25+
(size_t)size * sizeof(mp_digit));
2626
if (tmp == NULL) {
2727
/* reallocation failed but "a" is still valid [can be freed] */
2828
return MP_MEM;

bn_mp_ilogb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int mp_ilogb(mp_int *a, mp_digit base, mp_int *c)
8181
if (a->sign == MP_NEG) {
8282
return MP_VAL;
8383
}
84-
if (IS_ZERO(a)) {
84+
if (MP_IS_ZERO(a)) {
8585
return MP_VAL;
8686
}
8787

bn_mp_incr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
int mp_incr(mp_int *a)
88
{
99
int e = MP_OKAY;
10-
if (IS_ZERO(a)) {
10+
if (MP_IS_ZERO(a)) {
1111
mp_set(a,1uL);
1212
return MP_OKAY;
1313
} else if (a->sign == MP_NEG) {
@@ -16,7 +16,7 @@ int mp_incr(mp_int *a)
1616
return e;
1717
}
1818
/* There is no -0 in LTM */
19-
if (!IS_ZERO(a)) {
19+
if (!MP_IS_ZERO(a)) {
2020
a->sign = MP_NEG;
2121
}
2222
return MP_OKAY;

bn_mp_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
int mp_init(mp_int *a)
88
{
99
/* allocate memory required and clear it */
10-
a->dp = (mp_digit *) XCALLOC((size_t)MP_PREC, sizeof(mp_digit));
10+
a->dp = (mp_digit *) MP_CALLOC((size_t)MP_PREC, sizeof(mp_digit));
1111
if (a->dp == NULL) {
1212
return MP_MEM;
1313
}

bn_mp_init_size.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int mp_init_size(mp_int *a, int size)
1010
size += (MP_PREC * 2) - (size % MP_PREC);
1111

1212
/* alloc mem */
13-
a->dp = (mp_digit *) XCALLOC((size_t)size, sizeof(mp_digit));
13+
a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit));
1414
if (a->dp == NULL) {
1515
return MP_MEM;
1616
}

bn_mp_invmod.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ int mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
1111
return MP_VAL;
1212
}
1313

14-
#ifdef BN_FAST_MP_INVMOD_C
14+
#ifdef BN_S_MP_INVMOD_FAST_C
1515
/* if the modulus is odd we can use a faster routine instead */
16-
if (IS_ODD(b)) {
17-
return fast_mp_invmod(a, b, c);
16+
if (MP_IS_ODD(b)) {
17+
return s_mp_invmod_fast(a, b, c);
1818
}
1919
#endif
2020

21-
#ifdef BN_MP_INVMOD_SLOW_C
22-
return mp_invmod_slow(a, b, c);
21+
#ifdef BN_S_MP_INVMOD_SLOW_C
22+
return s_mp_invmod_slow(a, b, c);
2323
#else
2424
return MP_VAL;
2525
#endif

bn_mp_is_square.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int mp_is_square(const mp_int *arg, int *ret)
4040
return MP_VAL;
4141
}
4242

43-
if (IS_ZERO(arg)) {
43+
if (MP_IS_ZERO(arg)) {
4444
return MP_OKAY;
4545
}
4646

bn_mp_iseven.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
int mp_iseven(const mp_int *a)
77
{
8-
return IS_EVEN(a) ? MP_YES : MP_NO;
8+
return MP_IS_EVEN(a) ? MP_YES : MP_NO;
99
}
1010
#endif

bn_mp_isodd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
int mp_isodd(const mp_int *a)
77
{
8-
return IS_ODD(a) ? MP_YES : MP_NO;
8+
return MP_IS_ODD(a) ? MP_YES : MP_NO;
99
}
1010
#endif

0 commit comments

Comments
 (0)