summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-08-28 16:33:52 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-08-28 16:33:52 +0200
commitbdc87e17bd2522552f3c97c741bda0ae29df3528 (patch)
tree5b421cb285a5151d34ec43f825d4f627b9352185 /sys
parentb65f409d542e63302a68325f292a364a0b3bae2e (diff)
libmp: timingsafe sign flip for small power-of-two negative divisor for mpdiv()
Diffstat (limited to 'sys')
-rw-r--r--sys/src/libmp/port/mpdiv.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/sys/src/libmp/port/mpdiv.c b/sys/src/libmp/port/mpdiv.c
index 8ee1d2ae5..2c2ce73eb 100644
--- a/sys/src/libmp/port/mpdiv.c
+++ b/sys/src/libmp/port/mpdiv.c
@@ -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;