Skip to content

Various deprecations #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 18, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.gcno
*.gcov
*.lib
*.tmp
[Dd]ebug/
[Rr]elease/
/MSVC_*
Expand Down
42 changes: 42 additions & 0 deletions bn_deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,48 @@

/* SPDX-License-Identifier: Unlicense */
#include <tommath_private.h>
#ifdef BN_MP_GET_BIT_C
/* 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 */
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 s_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);
}
mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c)
{
return s_mp_jacobi(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 ret = s_mp_rand_source(r, sizeof(mp_digit));
*r &= MP_MASK;
return ret;
}
#endif
#ifdef BN_FAST_MP_INVMOD_C
mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
{
Expand Down
31 changes: 0 additions & 31 deletions bn_mp_get_bit.c

This file was deleted.

5 changes: 2 additions & 3 deletions bn_mp_ilogb.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static mp_digit s_digit_ilogb(mp_digit base, mp_digit n)
mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
{
mp_err err;
int cmp;
mp_ord cmp;
unsigned int high, low, mid;
mp_int bracket_low, bracket_high, bracket_mid, t, bi_base;
mp_digit tmp;
Expand All @@ -90,8 +90,7 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
return MP_VAL;
}
if (base == 2u) {
cmp = mp_count_bits(a) - 1;
mp_set_int(c, (unsigned long)cmp);
mp_set_int(c, (unsigned long)(mp_count_bits(a) - 1));
return err;
}
if (a->used == 1) {
Expand Down
23 changes: 0 additions & 23 deletions bn_mp_jacobi.c

This file was deleted.

2 changes: 1 addition & 1 deletion bn_mp_n_root_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
{
mp_int t1, t2, t3, a_;
int cmp;
mp_ord cmp;
int ilog2;
mp_err res;

Expand Down
8 changes: 2 additions & 6 deletions bn_mp_prime_frobenius_underwood.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
{
mp_int T1z, T2z, Np1z, sz, tz;

int a, ap2, length, i, j, isset;
int a, ap2, length, i, j;
mp_err e;

*result = MP_NO;
Expand Down Expand Up @@ -129,11 +129,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
if ((e = mp_mod(&T1z, N, &sz)) != MP_OKAY) {
goto LBL_FU_ERR;
}
if ((isset = mp_get_bit(&Np1z, i)) == MP_VAL) {
e = MP_VAL;
goto LBL_FU_ERR;
}
if (isset == MP_YES) {
if (s_mp_get_bit(&Np1z, (unsigned int)i) == MP_YES) {
/*
* temp = (a+2) * sz + tz
* tz = 2 * tz - sz
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_prime_is_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
if ((err = mp_is_square(a, &res)) != MP_OKAY) {
return err;
}
if (res != 0) {
if (res != MP_NO) {
return MP_OKAY;
}

Expand Down
7 changes: 1 addition & 6 deletions bn_mp_prime_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/* This is possibly the mother of all prime generation functions, muahahahahaha! */
static 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, private_mp_prime_callback cb, void *dat)
{
unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
int bsize, maskOR_msb_offset;
Expand Down Expand Up @@ -132,11 +132,6 @@ static int s_mp_rand_cb(unsigned char *dst, int len, void *dat)
return len;
}

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);
}

mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
{
return s_mp_prime_random_ex(a, t, size, flags, s_mp_rand_cb, NULL);
Expand Down
8 changes: 2 additions & 6 deletions bn_mp_prime_strong_lucas_selfridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
/* CZ TODO: Some of them need the full 32 bit, hence the (temporary) exclusion of MP_8BIT */
int32_t D, Ds, J, sign, P, Q, r, s, u, Nbits;
mp_err e;
int isset, oddness;
mp_bool oddness;

*result = MP_NO;
/*
Expand Down Expand Up @@ -246,11 +246,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
if ((e = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) {
goto LBL_LS_ERR;
}
if ((isset = mp_get_bit(&Dz, u)) == MP_VAL) {
e = MP_VAL;
goto LBL_LS_ERR;
}
if (isset == MP_YES) {
if (s_mp_get_bit(&Dz, (unsigned int)u) == MP_YES) {
/* Formulas for addition of indices (carried out mod N);
*
* U_(m+n) = (U_m*V_n + U_n*V_m)/2
Expand Down
8 changes: 0 additions & 8 deletions bn_mp_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ void mp_rand_source(mp_err(*source)(void *out, size_t size))
s_mp_rand_source = (source == NULL) ? s_mp_rand_platform : source;
}

/* makes a pseudo-random int of a given size */
mp_err mp_rand_digit(mp_digit *r)
{
mp_err ret = s_mp_rand_source(r, sizeof(mp_digit));
*r &= MP_MASK;
return ret;
}

mp_err mp_rand(mp_int *a, int digits)
{
int i;
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_sqrtmod_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
return MP_OKAY;
}
if (mp_cmp_d(prime, 2uL) == MP_EQ) return MP_VAL; /* prime must be odd */
if ((res = mp_jacobi(n, prime, &legendre)) != MP_OKAY) return res;
if ((res = mp_kronecker(n, prime, &legendre)) != MP_OKAY) return res;
if (legendre == -1) return MP_VAL; /* quadratic non-residue mod prime */

if ((res = mp_init_multi(&t1, &C, &Q, &S, &Z, &M, &T, &R, &two, NULL)) != MP_OKAY) {
Expand Down Expand Up @@ -62,7 +62,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
mp_set_int(&Z, 2uL);
/* Z = 2 */
while (1) {
if ((res = mp_jacobi(&Z, prime, &legendre)) != MP_OKAY) goto cleanup;
if ((res = mp_kronecker(&Z, prime, &legendre)) != MP_OKAY) goto cleanup;
if (legendre == -1) break;
if ((res = mp_add_d(&Z, 1uL, &Z)) != MP_OKAY) goto cleanup;
/* Z = Z + 1 */
Expand Down
21 changes: 21 additions & 0 deletions bn_s_mp_get_bit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "tommath_private.h"
#ifdef BN_S_MP_GET_BIT_C

/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */

/* Get bit at position b and return MP_YES if the bit is 1, MP_NO if it is 0 */
mp_bool s_mp_get_bit(const mp_int *a, unsigned int b)
{
mp_digit bit;
int limb = (int)(b / MP_DIGIT_BIT);

if (limb >= a->used) {
return MP_NO;
}

bit = (mp_digit)1 << (b % MP_DIGIT_BIT);
return ((a->dp[limb] & bit) != 0u) ? MP_YES : MP_NO;
}

#endif
Loading