Skip to content
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
6 changes: 3 additions & 3 deletions bn_mp_2expt.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ int mp_2expt(mp_int *a, int b)
mp_zero(a);

/* grow a to accomodate the single bit */
if ((res = mp_grow(a, (b / DIGIT_BIT) + 1)) != MP_OKAY) {
if ((res = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
return res;
}

/* set the used count of where the bit will go */
a->used = (b / DIGIT_BIT) + 1;
a->used = (b / MP_DIGIT_BIT) + 1;

/* put the single bit in its place */
a->dp[b / DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % DIGIT_BIT);
a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT);

return MP_OKAY;
}
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_add_d.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
* the carry.
*/
*tmpc = *tmpa++ + b;
mu = *tmpc >> DIGIT_BIT;
mu = *tmpc >> MP_DIGIT_BIT;
*tmpc++ &= MP_MASK;

/* now handle rest of the digits */
for (ix = 1; ix < a->used; ix++) {
*tmpc = *tmpa++ + mu;
mu = *tmpc >> DIGIT_BIT;
mu = *tmpc >> MP_DIGIT_BIT;
*tmpc++ &= MP_MASK;
}
/* set final carry */
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_cnt_lsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int mp_cnt_lsb(const mp_int *a)
/* scan lower digits until non-zero */
for (x = 0; (x < a->used) && (a->dp[x] == 0u); x++) {}
q = a->dp[x];
x *= DIGIT_BIT;
x *= MP_DIGIT_BIT;

/* now scan this digit until a 1 is found */
if ((q & 1u) == 0u) {
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_count_bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int mp_count_bits(const mp_int *a)
}

/* get number of digits and add that */
r = (a->used - 1) * DIGIT_BIT;
r = (a->used - 1) * MP_DIGIT_BIT;

/* take the last digit and count the bits in it */
q = a->dp[a->used - 1];
Expand Down
12 changes: 6 additions & 6 deletions bn_mp_div.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
x.sign = y.sign = MP_ZPOS;

/* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */
norm = mp_count_bits(&y) % DIGIT_BIT;
if (norm < (DIGIT_BIT - 1)) {
norm = (DIGIT_BIT - 1) - norm;
/* normalize both x and y, ensure that y >= b/2, [b == 2**MP_DIGIT_BIT] */
norm = mp_count_bits(&y) % MP_DIGIT_BIT;
if (norm < (MP_DIGIT_BIT - 1)) {
norm = (MP_DIGIT_BIT - 1) - norm;
if ((res = mp_mul_2d(&x, norm, &x)) != MP_OKAY) {
goto LBL_Y;
}
Expand Down Expand Up @@ -178,10 +178,10 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
/* step 3.1 if xi == yt then set q{i-t-1} to b-1,
* otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
if (x.dp[i] == y.dp[t]) {
q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)DIGIT_BIT) - (mp_digit)1;
q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)MP_DIGIT_BIT) - (mp_digit)1;
} else {
mp_word tmp;
tmp = (mp_word)x.dp[i] << (mp_word)DIGIT_BIT;
tmp = (mp_word)x.dp[i] << (mp_word)MP_DIGIT_BIT;
tmp |= (mp_word)x.dp[i - 1];
tmp /= (mp_word)y.dp[t];
if (tmp > (mp_word)MP_MASK) {
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_div_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int mp_div_2(const mp_int *a, mp_int *b)
rr = *tmpa & 1u;

/* shift the current digit, add in carry and store */
*tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
*tmpb-- = (*tmpa-- >> 1) | (r << (MP_DIGIT_BIT - 1));

/* forward carry to next iteration */
r = rr;
Expand Down
10 changes: 5 additions & 5 deletions bn_mp_div_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
}

/* shift by as many digits in the bit count */
if (b >= DIGIT_BIT) {
mp_rshd(c, b / DIGIT_BIT);
if (b >= MP_DIGIT_BIT) {
mp_rshd(c, b / MP_DIGIT_BIT);
}

/* shift any bit count < DIGIT_BIT */
D = (mp_digit)(b % DIGIT_BIT);
/* shift any bit count < MP_DIGIT_BIT */
D = (mp_digit)(b % MP_DIGIT_BIT);
if (D != 0u) {
mp_digit *tmpc, mask, shift;

/* mask */
mask = ((mp_digit)1 << D) - 1uL;

/* shift for lsb */
shift = (mp_digit)DIGIT_BIT - D;
shift = (mp_digit)MP_DIGIT_BIT - D;

/* alias */
tmpc = c->dp + (c->used - 1);
Expand Down
8 changes: 4 additions & 4 deletions bn_mp_div_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
mp_digit b;
int res, ix;

/* b = 2**DIGIT_BIT / 3 */
b = ((mp_word)1 << (mp_word)DIGIT_BIT) / (mp_word)3;
/* b = 2**MP_DIGIT_BIT / 3 */
b = ((mp_word)1 << (mp_word)MP_DIGIT_BIT) / (mp_word)3;

if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
return res;
Expand All @@ -22,11 +22,11 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
q.sign = a->sign;
w = 0;
for (ix = a->used - 1; ix >= 0; ix--) {
w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix];
w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];

if (w >= 3u) {
/* multiply w by [1/3] */
t = (w * (mp_word)b) >> (mp_word)DIGIT_BIT;
t = (w * (mp_word)b) >> (mp_word)MP_DIGIT_BIT;

/* now subtract 3 * [w/3] from w, to get the remainder */
w -= t+t+t;
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_div_d.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static int s_is_power_of_two(mp_digit b, int *p)
return 0;
}

for (x = 0; x < DIGIT_BIT; x++) {
for (x = 0; x < MP_DIGIT_BIT; x++) {
if (b == ((mp_digit)1<<(mp_digit)x)) {
*p = x;
return 1;
Expand Down Expand Up @@ -72,7 +72,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
q.sign = a->sign;
w = 0;
for (ix = a->used - 1; ix >= 0; ix--) {
w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix];
w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];

if (w >= b) {
t = (mp_digit)(w / b);
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_dr_reduce.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k)
for (i = 0; i < m; i++) {
r = ((mp_word)*tmpx2++ * (mp_word)k) + *tmpx1 + mu;
*tmpx1++ = (mp_digit)(r & MP_MASK);
mu = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
mu = (mp_digit)(r >> ((mp_word)MP_DIGIT_BIT));
}

/* set final carry */
Expand Down
6 changes: 3 additions & 3 deletions bn_mp_dr_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
/* determines the setup value */
void mp_dr_setup(const mp_int *a, mp_digit *d)
{
/* the casts are required if DIGIT_BIT is one less than
* the number of bits in a mp_digit [e.g. DIGIT_BIT==31]
/* the casts are required if MP_DIGIT_BIT is one less than
* the number of bits in a mp_digit [e.g. MP_DIGIT_BIT==31]
*/
*d = (mp_digit)(((mp_word)1 << (mp_word)DIGIT_BIT) - (mp_word)a->dp[0]);
*d = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - (mp_word)a->dp[0]);
}

#endif
4 changes: 2 additions & 2 deletions bn_mp_expt_d_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
b >>= 1;
}
} else {
for (x = 0; x < (unsigned)DIGIT_BIT; x++) {
for (x = 0; x < (unsigned)MP_DIGIT_BIT; x++) {
/* square */
if ((res = mp_sqr(c, c)) != MP_OKAY) {
mp_clear(&g);
return res;
}

/* if the bit is set multiply */
if ((b & ((mp_digit)1 << (DIGIT_BIT - 1))) != 0u) {
if ((b & ((mp_digit)1 << (MP_DIGIT_BIT - 1))) != 0u) {
if ((res = mp_mul(c, &g, c)) != MP_OKAY) {
mp_clear(&g);
return res;
Expand Down
4 changes: 2 additions & 2 deletions bn_mp_get_bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ int mp_get_bit(const mp_int *a, int b)
return MP_VAL;
}

limb = b / DIGIT_BIT;
limb = b / MP_DIGIT_BIT;

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

bit = (mp_digit)(1) << (b % DIGIT_BIT);
bit = (mp_digit)(1) << (b % MP_DIGIT_BIT);

isset = a->dp[limb] & bit;
return (isset != 0u) ? MP_YES : MP_NO;
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_get_double.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ double mp_get_double(const mp_int *a)
{
int i;
double d = 0.0, fac = 1.0;
for (i = 0; i < DIGIT_BIT; ++i) {
for (i = 0; i < MP_DIGIT_BIT; ++i) {
fac *= 2.0;
}
for (i = a->used; i --> 0;) {
Expand Down
6 changes: 3 additions & 3 deletions bn_mp_get_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ unsigned long mp_get_long(const mp_int *a)
}

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

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

#if (ULONG_MAX != 0xFFFFFFFFUL) || (DIGIT_BIT < 32)
#if (ULONG_MAX != 0xFFFFFFFFUL) || (MP_DIGIT_BIT < 32)
while (--i >= 0) {
res = (res << DIGIT_BIT) | (unsigned long)a->dp[i];
res = (res << MP_DIGIT_BIT) | (unsigned long)a->dp[i];
}
#endif
return res;
Expand Down
6 changes: 3 additions & 3 deletions bn_mp_get_long_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ unsigned long long mp_get_long_long(const mp_int *a)
}

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

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

#if DIGIT_BIT < 64
#if MP_DIGIT_BIT < 64
while (--i >= 0) {
res = (res << DIGIT_BIT) | (unsigned long long)a->dp[i];
res = (res << MP_DIGIT_BIT) | (unsigned long long)a->dp[i];
}
#endif
return res;
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_is_square.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int mp_is_square(const mp_int *arg, int *ret)
return MP_OKAY;
}

/* First check mod 128 (suppose that DIGIT_BIT is at least 7) */
/* First check mod 128 (suppose that MP_DIGIT_BIT is at least 7) */
if (rem_128[127u & arg->dp[0]] == (char)1) {
return MP_OKAY;
}
Expand Down
8 changes: 4 additions & 4 deletions bn_mp_mod_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int mp_mod_2d(const mp_int *a, int b, mp_int *c)
}

/* if the modulus is larger than the value than return */
if (b >= (a->used * DIGIT_BIT)) {
if (b >= (a->used * MP_DIGIT_BIT)) {
res = mp_copy(a, c);
return res;
}
Expand All @@ -26,12 +26,12 @@ int mp_mod_2d(const mp_int *a, int b, mp_int *c)
}

/* zero digits above the last digit of the modulus */
for (x = (b / DIGIT_BIT) + (((b % DIGIT_BIT) == 0) ? 0 : 1); x < c->used; x++) {
for (x = (b / MP_DIGIT_BIT) + (((b % MP_DIGIT_BIT) == 0) ? 0 : 1); x < c->used; x++) {
c->dp[x] = 0;
}
/* clear the digit that is not completely outside/inside the modulus */
c->dp[b / DIGIT_BIT] &=
((mp_digit)1 << (mp_digit)(b % DIGIT_BIT)) - (mp_digit)1;
c->dp[b / MP_DIGIT_BIT] &=
((mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT)) - (mp_digit)1;
mp_clamp(c);
return MP_OKAY;
}
Expand Down
6 changes: 3 additions & 3 deletions bn_mp_montgomery_calc_normalization.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b)
int x, bits, res;

/* how many bits of last digit does b use */
bits = mp_count_bits(b) % DIGIT_BIT;
bits = mp_count_bits(b) % MP_DIGIT_BIT;

if (b->used > 1) {
if ((res = mp_2expt(a, ((b->used - 1) * DIGIT_BIT) + bits - 1)) != MP_OKAY) {
if ((res = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) {
return res;
}
} else {
Expand All @@ -27,7 +27,7 @@ int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b)


/* now compute C = A * B mod b */
for (x = bits - 1; x < (int)DIGIT_BIT; x++) {
for (x = bits - 1; x < (int)MP_DIGIT_BIT; x++) {
if ((res = mp_mul_2(a, a)) != MP_OKAY) {
return res;
}
Expand Down
6 changes: 3 additions & 3 deletions bn_mp_montgomery_reduce.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
if ((digs < (int)MP_WARRAY) &&
(x->used <= (int)MP_WARRAY) &&
(n->used <
(int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
(int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)MP_DIGIT_BIT))))) {
return s_mp_montgomery_reduce_fast(x, n, rho);
}

Expand Down Expand Up @@ -64,7 +64,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
(mp_word)u + (mp_word)*tmpx;

/* get carry */
u = (mp_digit)(r >> (mp_word)DIGIT_BIT);
u = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);

/* fix digit */
*tmpx++ = (mp_digit)(r & (mp_word)MP_MASK);
Expand All @@ -75,7 +75,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
/* propagate carries upwards as required*/
while (u != 0u) {
*tmpx += u;
u = *tmpx >> DIGIT_BIT;
u = *tmpx >> MP_DIGIT_BIT;
*tmpx++ &= MP_MASK;
}
}
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_montgomery_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int mp_montgomery_setup(const mp_int *n, mp_digit *rho)
#endif

/* rho = -1/m mod b */
*rho = (mp_digit)(((mp_word)1 << (mp_word)DIGIT_BIT) - x) & MP_MASK;
*rho = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - x) & MP_MASK;

return MP_OKAY;
}
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int mp_mul(const mp_int *a, const mp_int *b, mp_int *c)
#ifdef BN_S_MP_MUL_DIGS_FAST_C
if ((digs < (int)MP_WARRAY) &&
(MP_MIN(a->used, b->used) <=
(int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
(int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)MP_DIGIT_BIT))))) {
res = s_mp_mul_digs_fast(a, b, c, digs);
} else
#endif
Expand Down
2 changes: 1 addition & 1 deletion bn_mp_mul_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int mp_mul_2(const mp_int *a, mp_int *b)
/* get what will be the *next* carry bit from the
* MSB of the current digit
*/
rr = *tmpa >> (mp_digit)(DIGIT_BIT - 1);
rr = *tmpa >> (mp_digit)(MP_DIGIT_BIT - 1);

/* now shift up this digit, add in the carry [from the previous] */
*tmpb++ = ((*tmpa++ << 1uL) | r) & MP_MASK;
Expand Down
Loading