Skip to content
Closed
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
57 changes: 57 additions & 0 deletions bn_deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,61 @@ mp_err mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
return mp_signed_rsh(a, b, c);
}
#endif
#ifdef BN_MP_INIT_SET_INT_C
mp_err mp_init_set_int(mp_int *a, unsigned long b)
{
return mp_init_u32(a, (uint32_t)b);
}
#endif
#ifdef BN_MP_INIT_SET_C
mp_err mp_init_set(mp_int *a, mp_digit b)
{
return mp_init_u64(a, b & MP_MASK);
}
#endif
#ifdef BN_MP_SET_C
void mp_set(mp_int *a, mp_digit b)
{
mp_set_u64(a, b & MP_MASK);
}
#endif
#ifdef BN_MP_SET_INT_C
mp_err mp_set_int(mp_int *a, unsigned long b)
{
mp_set_u32(a, (uint32_t)b);
return MP_OKAY;
}
#endif
#ifdef BN_MP_SET_LONG_C
mp_err mp_set_long(mp_int *a, unsigned long b)
{
mp_set_u64(a, b);
return MP_OKAY;
}
#endif
#ifdef BN_MP_SET_LONG_LONG_C
mp_err mp_set_long_long(mp_int *a, unsigned long long b)
{
mp_set_u64(a, b);
return MP_OKAY;
}
#endif
#ifdef BN_MP_GET_INT_C
unsigned long mp_get_int(const mp_int *a)
{
return mp_get_u32(a);
}
#endif
#ifdef BN_MP_GET_LONG_C
unsigned long mp_get_long(const mp_int *a)
{
return sizeof(long) > sizeof(int32_t) ? (unsigned long)mp_get_mag64(a) : (unsigned long)mp_get_mag32(a);
}
#endif
#ifdef BN_MP_GET_LONG_LONG_C
unsigned long long mp_get_long_long(const mp_int *a)
{
return (unsigned long long)mp_get_mag64(a);
}
#endif
#endif
2 changes: 1 addition & 1 deletion bn_mp_decr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mp_err mp_decr(mp_int *a)
{
if (MP_IS_ZERO(a)) {
mp_set(a,1uL);
mp_set_u(a, 1u);
a->sign = MP_NEG;
return MP_OKAY;
} else if (a->sign == MP_NEG) {
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_expt_d_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
}

/* set initial result */
mp_set(c, 1uL);
mp_set_u(c, 1u);

if (fast != 0) {
while (b > 0u) {
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_exteuclid.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ mp_err mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp
}

/* initialize, (u1,u2,u3) = (1,0,a) */
mp_set(&u1, 1uL);
mp_set_u(&u1, 1u);
if ((err = mp_copy(a, &u3)) != MP_OKAY) {
goto LBL_ERR;
}

/* initialize, (v1,v2,v3) = (0,1,b) */
mp_set(&v2, 1uL);
mp_set_u(&v2, 1u);
if ((err = mp_copy(b, &v3)) != MP_OKAY) {
goto LBL_ERR;
}
Expand Down
12 changes: 0 additions & 12 deletions bn_mp_get_int.c

This file was deleted.

29 changes: 0 additions & 29 deletions bn_mp_get_long.c

This file was deleted.

29 changes: 0 additions & 29 deletions bn_mp_get_long_long.c

This file was deleted.

20 changes: 9 additions & 11 deletions bn_mp_ilogb.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
mp_ord cmp;
unsigned int high, low, mid;
mp_int bracket_low, bracket_high, bracket_mid, t, bi_base;
mp_digit tmp;

err = MP_OKAY;
if (a->sign == MP_NEG) {
Expand All @@ -90,12 +89,11 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
return MP_VAL;
}
if (base == 2u) {
mp_set_int(c, (unsigned long)(mp_count_bits(a) - 1));
mp_set_i(c, mp_count_bits(a) - 1);
return err;
}
if (a->used == 1) {
tmp = s_digit_ilogb(base, a->dp[0]);
mp_set(c, tmp);
mp_set_u64(c, s_digit_ilogb(base, a->dp[0]));
return err;
}

Expand All @@ -106,7 +104,7 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
return err;
}
if (cmp == MP_EQ) {
mp_set(c, (mp_digit)1uL);
mp_set_u(c, 1u);
return err;
}

Expand All @@ -117,10 +115,10 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
}

low = 0u;
mp_set(&bracket_low, 1uL);
mp_set_u(&bracket_low, 1u);
high = 1u;

mp_set(&bracket_high, base);
mp_set_u64(&bracket_high, base);

/*
A kind of Giant-step/baby-step algorithm.
Expand All @@ -138,7 +136,7 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
goto LBL_ERR;
}
}
mp_set(&bi_base, base);
mp_set_u64(&bi_base, base);

while ((high - low) > 1u) {
mid = (high + low) >> 1;
Expand All @@ -163,15 +161,15 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
mp_exch(&bracket_mid, &bracket_low);
}
if (cmp == MP_EQ) {
mp_set_int(c, (unsigned long)mid);
mp_set_u64(c, mid);
goto LBL_END;
}
}

if (mp_cmp(&bracket_high, a) == MP_EQ) {
mp_set_int(c, (unsigned long)high);
mp_set_u64(c, high);
} else {
mp_set_int(c, (unsigned long)low);
mp_set_u64(c, low);
}

LBL_END:
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_incr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mp_err mp_incr(mp_int *a)
{
if (MP_IS_ZERO(a)) {
mp_set(a,1uL);
mp_set_u(a,1uL);
return MP_OKAY;
} else if (a->sign == MP_NEG) {
mp_err err;
Expand Down
16 changes: 0 additions & 16 deletions bn_mp_init_set.c

This file was deleted.

15 changes: 0 additions & 15 deletions bn_mp_init_set_int.c

This file was deleted.

4 changes: 2 additions & 2 deletions bn_mp_is_square.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ mp_err mp_is_square(const mp_int *arg, mp_bool *ret)
}


if ((err = mp_init_set_int(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
if ((err = mp_init_u(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
return err;
}
if ((err = mp_mod(arg, &t, &t)) != MP_OKAY) {
goto LBL_ERR;
}
r = mp_get_int(&t);
r = mp_get_u(&t);
/* Check for other prime modules, note it's not an ERROR but we must
* free "t" so the easiest way is to goto LBL_ERR. We know that err
* is already equal to MP_OKAY from the mp_mod call
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_montgomery_calc_normalization.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mp_err mp_montgomery_calc_normalization(mp_int *a, const mp_int *b)
return err;
}
} else {
mp_set(a, 1uL);
mp_set_u(a, 1uL);
bits = 1;
}

Expand Down
6 changes: 3 additions & 3 deletions bn_mp_n_root_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
*/
if (sizeof(mp_digit) >= sizeof(int)) {
if (b > (mp_digit)(INT_MAX/2)) {
mp_set(c, 1uL);
mp_set_u(c, 1u);
c->sign = a->sign;
err = MP_OKAY;
goto LBL_ERR;
Expand All @@ -58,14 +58,14 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
#endif
/* "b" is smaller than INT_MAX, we can cast safely */
if (ilog2 < (int)b) {
mp_set(c, 1uL);
mp_set_u(c, 1u);
c->sign = a->sign;
err = MP_OKAY;
goto LBL_ERR;
}
ilog2 = ilog2 / ((int)b);
if (ilog2 == 0) {
mp_set(c, 1uL);
mp_set_u(c, 1u);
c->sign = a->sign;
err = MP_OKAY;
goto LBL_ERR;
Expand Down
10 changes: 5 additions & 5 deletions bn_mp_prime_frobenius_underwood.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
continue;
}
/* (32764^2 - 4) < 2^31, no bigint for >MP_8BIT needed) */
mp_set_long(&T1z, (unsigned long)a);
mp_set_u(&T1z, (uint32_t)a);

if ((err = mp_sqr(&T1z, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
Expand Down Expand Up @@ -72,7 +72,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
goto LBL_FU_ERR;
}
/* Composite if N and (a+4)*(2*a+5) are not coprime */
mp_set_long(&T1z, (unsigned long)((a+4)*((2*a)+5)));
mp_set_u(&T1z, (uint32_t)((a+4)*((2*a)+5)));

if ((err = mp_gcd(N, &T1z, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
Expand All @@ -87,8 +87,8 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
goto LBL_FU_ERR;
}

mp_set(&sz, 1uL);
mp_set(&tz, 2uL);
mp_set_u(&sz, 1uL);
mp_set_u(&tz, 2uL);
length = mp_count_bits(&Np1z);

for (i = length - 2; i >= 0; i--) {
Expand Down Expand Up @@ -157,7 +157,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
}
}

mp_set_long(&T1z, (unsigned long)((2 * a) + 5));
mp_set_u(&T1z, (uint32_t)((2 * a) + 5));
if ((err = mp_mod(&T1z, N, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR;
}
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_prime_is_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
/*
Run the Miller-Rabin test with base 2 for the BPSW test.
*/
if ((err = mp_init_set(&b, 2uL)) != MP_OKAY) {
if ((err = mp_init_u(&b, 2uL)) != MP_OKAY) {
return err;
}

Expand Down Expand Up @@ -211,7 +211,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
}
/* we did bases 2 and 3 already, skip them */
for (ix = 2; ix < p_max; ix++) {
mp_set(&b, ltm_prime_tab[ix]);
mp_set_u(&b, (uint32_t)ltm_prime_tab[ix]);
if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
goto LBL_B;
}
Expand Down
Loading