Skip to content

Commit ce591b5

Browse files
authored
Merge pull request #572 from libtom/deprecate-apis
Deprecate APIs
2 parents 97e5003 + a469dd0 commit ce591b5

31 files changed

+573
-550
lines changed

bn_deprecated.c

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c)
7474
return s_mp_balance_mul(a, b, c);
7575
}
7676
#endif
77+
#ifdef BN_MP_DIV_3_C
78+
mp_err mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
79+
{
80+
return s_mp_div_3(a, c, d);
81+
}
82+
#endif
7783
#ifdef BN_MP_EXPTMOD_FAST_C
7884
mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
7985
{
@@ -184,51 +190,97 @@ unsigned long mp_get_long(const mp_int *a)
184190
#ifdef BN_MP_GET_LONG_LONG_C
185191
unsigned long long mp_get_long_long(const mp_int *a)
186192
{
187-
return mp_get_mag_ull(a);
193+
return (unsigned long long)mp_get_mag_u64(a);
188194
}
189195
#endif
196+
#ifdef BN_MP_GET_LL_C
197+
MP_GET_SIGNED(mp_get_ll, mp_get_mag_u64, long long, uint64_t)
198+
#endif
199+
#ifdef BN_MP_GET_MAG_ULL_C
200+
MP_GET_MAG(mp_get_mag_ull, unsigned long long)
201+
#endif
202+
#ifdef BN_MP_INIT_LL_C
203+
MP_INIT_INT(mp_init_ll, mp_set_i64, long long)
204+
#endif
205+
#ifdef BN_MP_SET_LL_C
206+
MP_SET_SIGNED(mp_set_ll, mp_set_i64, long long, unsigned long long)
207+
#endif
208+
#ifdef BN_MP_INIT_ULL_C
209+
MP_INIT_INT(mp_init_ull, mp_set_u64, unsigned long long)
210+
#endif
211+
#ifdef BN_MP_SET_ULL_C
212+
MP_SET_UNSIGNED(mp_set_ull, unsigned long long)
213+
#endif
190214
#ifdef BN_MP_PRIME_IS_DIVISIBLE_C
191215
mp_err mp_prime_is_divisible(const mp_int *a, mp_bool *result)
192216
{
193217
return s_mp_prime_is_divisible(a, result);
194218
}
195219
#endif
220+
#ifdef BN_MP_LOG_U32_C
221+
mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
222+
{
223+
mp_err e;
224+
int c_;
225+
if (base > MP_MIN(MP_DIGIT_MAX, INT_MAX)) {
226+
return MP_VAL;
227+
}
228+
e = mp_log_n(a, (int)base, &c_);
229+
*c = c_;
230+
return e;
231+
}
232+
#endif
196233
#ifdef BN_MP_EXPT_D_EX_C
197234
mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
198235
{
199236
(void)fast;
200-
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
237+
if (b > MP_MIN(MP_DIGIT_MAX, INT_MAX)) {
201238
return MP_VAL;
202239
}
203-
return mp_expt_u32(a, (uint32_t)b, c);
240+
return mp_expt_n(a, (int)b, c);
204241
}
205242
#endif
206243
#ifdef BN_MP_EXPT_D_C
207244
mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c)
208245
{
209-
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
246+
if (b > MP_MIN(MP_DIGIT_MAX, INT_MAX)) {
210247
return MP_VAL;
211248
}
212-
return mp_expt_u32(a, (uint32_t)b, c);
249+
return mp_expt_n(a, (int)b, c);
250+
}
251+
#endif
252+
#ifdef BN_MP_EXPT_U32_C
253+
mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c)
254+
{
255+
if (b > MP_MIN(MP_DIGIT_MAX, INT_MAX)) {
256+
return MP_VAL;
257+
}
258+
return mp_expt_n(a, (int)b, c);
213259
}
214260
#endif
215261
#ifdef BN_MP_N_ROOT_EX_C
216262
mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
217263
{
218264
(void)fast;
219-
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
265+
if (b > MP_MIN(MP_DIGIT_MAX, INT_MAX)) {
220266
return MP_VAL;
221267
}
222-
return mp_root_u32(a, (uint32_t)b, c);
268+
return mp_root_n(a, (int)b, c);
223269
}
224270
#endif
225271
#ifdef BN_MP_N_ROOT_C
226272
mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c)
227273
{
228-
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
274+
if (b > MP_MIN(MP_DIGIT_MAX, INT_MAX)) {
229275
return MP_VAL;
230276
}
231-
return mp_root_u32(a, (uint32_t)b, c);
277+
return mp_root_n(a, (int)b, c);
278+
}
279+
#endif
280+
#ifdef BN_MP_ROOT_U32_C
281+
mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
282+
{
283+
return mp_root_n(a, (int)b, c);
232284
}
233285
#endif
234286
#ifdef BN_MP_UNSIGNED_BIN_SIZE_C

bn_mp_div_d.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
4444
}
4545

4646
/* three? */
47-
if (MP_HAS(MP_DIV_3) && (b == 3u)) {
48-
return mp_div_3(a, c, d);
47+
if (MP_HAS(S_MP_DIV_3) && (b == 3u)) {
48+
return s_mp_div_3(a, c, d);
4949
}
5050

5151
/* no easy answer [c'est la vie]. Just division */

bn_mp_expt_u32.c renamed to bn_mp_expt_n.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "tommath_private.h"
2-
#ifdef BN_MP_EXPT_U32_C
2+
#ifdef BN_MP_EXPT_N_C
33
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* calculate c = a**b using a square-multiply algorithm */
7-
mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c)
7+
mp_err mp_expt_n(const mp_int *a, int b, mp_int *c)
88
{
99
mp_err err;
10-
1110
mp_int g;
1211

1312
if ((err = mp_init_copy(&g, a)) != MP_OKAY) {
@@ -17,16 +16,16 @@ mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c)
1716
/* set initial result */
1817
mp_set(c, 1uL);
1918

20-
while (b > 0u) {
19+
while (b > 0) {
2120
/* if the bit is set multiply */
22-
if ((b & 1u) != 0u) {
21+
if ((b & 1) != 0) {
2322
if ((err = mp_mul(c, &g, c)) != MP_OKAY) {
2423
goto LBL_ERR;
2524
}
2625
}
2726

2827
/* square */
29-
if (b > 1u) {
28+
if (b > 1) {
3029
if ((err = mp_sqr(&g, &g)) != MP_OKAY) {
3130
goto LBL_ERR;
3231
}
@@ -36,8 +35,6 @@ mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c)
3635
b >>= 1;
3736
}
3837

39-
err = MP_OKAY;
40-
4138
LBL_ERR:
4239
mp_clear(&g);
4340
return err;

bn_mp_get_ll.c

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

bn_mp_get_mag_ull.c

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

bn_mp_init_ll.c

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

bn_mp_init_ull.c

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

bn_mp_log_n.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "tommath_private.h"
2+
#ifdef BN_MP_LOG_N_C
3+
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4+
/* SPDX-License-Identifier: Unlicense */
5+
6+
mp_err mp_log_n(const mp_int *a, int base, int *c)
7+
{
8+
if (mp_isneg(a) || mp_iszero(a) || (base < 2) || (unsigned)base > (unsigned)MP_DIGIT_MAX) {
9+
return MP_VAL;
10+
}
11+
12+
if (MP_HAS(S_MP_LOG_2EXPT) && MP_IS_2EXPT((mp_digit)base)) {
13+
*c = s_mp_log_2expt(a, (mp_digit)base);
14+
return MP_OKAY;
15+
}
16+
17+
if (MP_HAS(S_MP_LOG_D) && (a->used == 1)) {
18+
*c = s_mp_log_d((mp_digit)base, a->dp[0]);
19+
return MP_OKAY;
20+
}
21+
22+
if (MP_HAS(S_MP_LOG)) {
23+
return s_mp_log(a, (mp_digit)base, c);
24+
}
25+
26+
return MP_VAL;
27+
}
28+
29+
#endif

0 commit comments

Comments
 (0)