forked from wolfSSL/wolfssl
fix ecc sign/hash truncation with odd bit sizes when hash length is longer than key size
This commit is contained in:
@@ -328,8 +328,7 @@ bn_reverse (unsigned char *s, int len)
|
||||
remainder in d) */
|
||||
int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
|
||||
{
|
||||
mp_digit D, r, rr;
|
||||
int x, res;
|
||||
int D, res;
|
||||
mp_int t;
|
||||
|
||||
|
||||
@@ -366,33 +365,9 @@ int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
|
||||
}
|
||||
|
||||
/* shift any bit count < DIGIT_BIT */
|
||||
D = (mp_digit) (b % DIGIT_BIT);
|
||||
D = (b % DIGIT_BIT);
|
||||
if (D != 0) {
|
||||
register mp_digit *tmpc, mask, shift;
|
||||
|
||||
/* mask */
|
||||
mask = (((mp_digit)1) << D) - 1;
|
||||
|
||||
/* shift for lsb */
|
||||
shift = DIGIT_BIT - D;
|
||||
|
||||
/* alias */
|
||||
tmpc = c->dp + (c->used - 1);
|
||||
|
||||
/* carry */
|
||||
r = 0;
|
||||
for (x = c->used - 1; x >= 0; x--) {
|
||||
/* get the lower bits of this word in a temp */
|
||||
rr = *tmpc & mask;
|
||||
|
||||
/* shift the current word and mix in the carry bits from the previous
|
||||
word */
|
||||
*tmpc = (*tmpc >> D) | (r << shift);
|
||||
--tmpc;
|
||||
|
||||
/* set the carry to the carry bits of the current word found above */
|
||||
r = rr;
|
||||
}
|
||||
mp_rshb(c, D);
|
||||
}
|
||||
mp_clamp (c);
|
||||
if (d != NULL) {
|
||||
@@ -457,6 +432,38 @@ mp_exch (mp_int * a, mp_int * b)
|
||||
}
|
||||
|
||||
|
||||
/* shift right a certain number of bits */
|
||||
void mp_rshb (mp_int *c, int x)
|
||||
{
|
||||
register mp_digit *tmpc, mask, shift;
|
||||
mp_digit r, rr;
|
||||
mp_digit D = x;
|
||||
|
||||
/* mask */
|
||||
mask = (((mp_digit)1) << D) - 1;
|
||||
|
||||
/* shift for lsb */
|
||||
shift = DIGIT_BIT - D;
|
||||
|
||||
/* alias */
|
||||
tmpc = c->dp + (c->used - 1);
|
||||
|
||||
/* carry */
|
||||
r = 0;
|
||||
for (x = c->used - 1; x >= 0; x--) {
|
||||
/* get the lower bits of this word in a temp */
|
||||
rr = *tmpc & mask;
|
||||
|
||||
/* shift the current word and mix in the carry bits from previous word */
|
||||
*tmpc = (*tmpc >> D) | (r << shift);
|
||||
--tmpc;
|
||||
|
||||
/* set the carry to the carry bits of the current word found above */
|
||||
r = rr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* shift right a certain amount of digits */
|
||||
void mp_rshd (mp_int * a, int b)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user