libmp: timingsafe sign flip for small power-of-two negative divisor for mpdiv()
This commit is contained in:
parent
b65f409d54
commit
bdc87e17bd
|
@ -24,12 +24,11 @@ mpdiv(mpint *dividend, mpint *divisor, mpint *quotient, mpint *remainder)
|
|||
if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){
|
||||
vlong r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1);
|
||||
if(quotient != nil){
|
||||
sign = divisor->sign;
|
||||
for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++)
|
||||
;
|
||||
mpright(dividend, s, quotient);
|
||||
if(sign < 0 && quotient->top != 0)
|
||||
quotient->sign ^= -2;
|
||||
if(divisor->sign < 0)
|
||||
quotient->sign ^= (-mpmagcmp(quotient, mpzero) >> 31) << 1;
|
||||
}
|
||||
if(remainder != nil){
|
||||
remainder->flags |= dividend->flags & MPtimesafe;
|
||||
|
|
Loading…
Reference in a new issue