Skip to content

Commit 97bc7ca

Browse files
authored
Merge pull request #260 from libtom/deprecations2
Various deprecations
2 parents b96d82d + f55f0a9 commit 97bc7ca

24 files changed

+358
-372
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.gcno
77
*.gcov
88
*.lib
9+
*.tmp
910
[Dd]ebug/
1011
[Rr]elease/
1112
/MSVC_*

bn_deprecated.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,48 @@
66

77
/* SPDX-License-Identifier: Unlicense */
88
#include <tommath_private.h>
9+
#ifdef BN_MP_GET_BIT_C
10+
/* Checks the bit at position b and returns MP_YES
11+
if the bit is 1, MP_NO if it is 0 and MP_VAL
12+
in case of error */
13+
int mp_get_bit(const mp_int *a, int b)
14+
{
15+
if (b < 0) {
16+
return MP_VAL;
17+
}
18+
return s_mp_get_bit(a, (unsigned int)b) == MP_YES ? MP_YES : MP_NO;
19+
}
20+
#endif
21+
#ifdef BN_MP_JACOBI_C
22+
mp_err s_mp_jacobi(const mp_int *a, const mp_int *n, int *c)
23+
{
24+
if (a->sign == MP_NEG) {
25+
return MP_VAL;
26+
}
27+
if (mp_cmp_d(n, 0uL) != MP_GT) {
28+
return MP_VAL;
29+
}
30+
return mp_kronecker(a, n, c);
31+
}
32+
mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c)
33+
{
34+
return s_mp_jacobi(a, n, c);
35+
}
36+
#endif
37+
#ifdef BN_MP_PRIME_RANDOM_EX_C
38+
mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat)
39+
{
40+
return s_mp_prime_random_ex(a, t, size, flags, cb, dat);
41+
}
42+
#endif
43+
#ifdef BN_MP_RAND_DIGIT_C
44+
mp_err mp_rand_digit(mp_digit *r)
45+
{
46+
mp_err ret = s_mp_rand_source(r, sizeof(mp_digit));
47+
*r &= MP_MASK;
48+
return ret;
49+
}
50+
#endif
951
#ifdef BN_FAST_MP_INVMOD_C
1052
mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
1153
{

bn_mp_get_bit.c

Lines changed: 0 additions & 31 deletions
This file was deleted.

bn_mp_ilogb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static mp_digit s_digit_ilogb(mp_digit base, mp_digit n)
7373
mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
7474
{
7575
mp_err err;
76-
int cmp;
76+
mp_ord cmp;
7777
unsigned int high, low, mid;
7878
mp_int bracket_low, bracket_high, bracket_mid, t, bi_base;
7979
mp_digit tmp;
@@ -90,8 +90,7 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
9090
return MP_VAL;
9191
}
9292
if (base == 2u) {
93-
cmp = mp_count_bits(a) - 1;
94-
mp_set_int(c, (unsigned long)cmp);
93+
mp_set_int(c, (unsigned long)(mp_count_bits(a) - 1));
9594
return err;
9695
}
9796
if (a->used == 1) {

bn_mp_jacobi.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

bn_mp_n_root_ex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
1616
{
1717
mp_int t1, t2, t3, a_;
18-
int cmp;
18+
mp_ord cmp;
1919
int ilog2;
2020
mp_err res;
2121

bn_mp_prime_frobenius_underwood.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
2727
{
2828
mp_int T1z, T2z, Np1z, sz, tz;
2929

30-
int a, ap2, length, i, j, isset;
30+
int a, ap2, length, i, j;
3131
mp_err e;
3232

3333
*result = MP_NO;
@@ -129,11 +129,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
129129
if ((e = mp_mod(&T1z, N, &sz)) != MP_OKAY) {
130130
goto LBL_FU_ERR;
131131
}
132-
if ((isset = mp_get_bit(&Np1z, i)) == MP_VAL) {
133-
e = MP_VAL;
134-
goto LBL_FU_ERR;
135-
}
136-
if (isset == MP_YES) {
132+
if (s_mp_get_bit(&Np1z, (unsigned int)i) == MP_YES) {
137133
/*
138134
* temp = (a+2) * sz + tz
139135
* tz = 2 * tz - sz

bn_mp_prime_is_prime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
5151
if ((err = mp_is_square(a, &res)) != MP_OKAY) {
5252
return err;
5353
}
54-
if (res != 0) {
54+
if (res != MP_NO) {
5555
return MP_OKAY;
5656
}
5757

bn_mp_prime_rand.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/* This is possibly the mother of all prime generation functions, muahahahahaha! */
21-
static mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat)
21+
mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat)
2222
{
2323
unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
2424
int bsize, maskOR_msb_offset;
@@ -132,11 +132,6 @@ static int s_mp_rand_cb(unsigned char *dst, int len, void *dat)
132132
return len;
133133
}
134134

135-
mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat)
136-
{
137-
return s_mp_prime_random_ex(a, t, size, flags, cb, dat);
138-
}
139-
140135
mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
141136
{
142137
return s_mp_prime_random_ex(a, t, size, flags, s_mp_rand_cb, NULL);

bn_mp_prime_strong_lucas_selfridge.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
7272
/* CZ TODO: Some of them need the full 32 bit, hence the (temporary) exclusion of MP_8BIT */
7373
int32_t D, Ds, J, sign, P, Q, r, s, u, Nbits;
7474
mp_err e;
75-
int isset, oddness;
75+
mp_bool oddness;
7676

7777
*result = MP_NO;
7878
/*
@@ -246,11 +246,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
246246
if ((e = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) {
247247
goto LBL_LS_ERR;
248248
}
249-
if ((isset = mp_get_bit(&Dz, u)) == MP_VAL) {
250-
e = MP_VAL;
251-
goto LBL_LS_ERR;
252-
}
253-
if (isset == MP_YES) {
249+
if (s_mp_get_bit(&Dz, (unsigned int)u) == MP_YES) {
254250
/* Formulas for addition of indices (carried out mod N);
255251
*
256252
* U_(m+n) = (U_m*V_n + U_n*V_m)/2

0 commit comments

Comments
 (0)