diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-12-01 11:13:52 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-12-01 11:13:52 +0100 |
commit | ffdfc17ceede743b6fa32a6d1659f62f0d0d8650 (patch) | |
tree | dfb1588b402bdc87a03b64b66d404b06cf05d0a6 /sys/src/libmp | |
parent | fbd825890e8376b80a480ef294496d628fb75d3c (diff) |
libmp: with mpmod() m = 2^a - c ensure that digits(c) < digits(m)
Diffstat (limited to 'sys/src/libmp')
-rw-r--r-- | sys/src/libmp/port/mpmod.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sys/src/libmp/port/mpmod.c b/sys/src/libmp/port/mpmod.c index c053f5b7f..b5dddf105 100644 --- a/sys/src/libmp/port/mpmod.c +++ b/sys/src/libmp/port/mpmod.c @@ -13,7 +13,7 @@ mpmod(mpint *x, mpint *n, mpint *r) sign = x->sign; assert(n->flags & MPnorm); - if(n->top < 2 || n->top > nelem(q) || (x->top-n->top) > nelem(q)) + if(n->top <= 2 || n->top > nelem(q) || (x->top-n->top) > nelem(q)) goto hard; /* @@ -42,11 +42,15 @@ mpmod(mpint *x, mpint *n, mpint *r) c = mpnew(0); p = mpnew(0); } - mpassign(n, p); - - mpleft(n, s, m); + mpleft(p, s, m); mpleft(mpone, k*Dbits, c); mpsub(c, m, c); + if(c->top >= k){ + mpassign(mpzero, p); + busy = 0; + goto hard; + } + mpassign(n, p); } mpleft(x, s, r); |