assert failed: m->flags & MPnorm since 283cc2200e34

Tue, 1 Dec 2015 03:26:12 EST
mischief@[REDACTED]

in 283cc2200e34, a new assert for MPnorm was introduced into mpexp() in libmp. however, it seems sometimes rsagen makes a number without this flag set. i only reproduced this on 386. here’s a simple case to reproduce.

include <u.h>

include <libc.h>

include <mp.h>

include <libsec.h>

void main(int argc, char *argv[]) {

RSApriv *p;

ARGBEGIN{
}ARGEND

for(;;){
    p = rsagen(2048, 65537, 0);
    assert(p);
    rsaprivfree(p);
}

}

term% ./mpexp-283cc2200e34 assert failed: m->flags & MPnorm mpexp-283cc2200e34 142: suicide: sys: trap: page fault pc=0x00001591 term% acid 142 /proc/142/text:386 plan 9 executable /sys/lib/acid/port /sys/lib/acid/386 acid: lstk() abort()+0x0 /sys/src/libc/9sys/abort.c:6 assert(s=0x1cb04)+0x3a /sys/src/libc/port/assert.c:12 mpexp(m=0x1eda8,e=0x1eda8,res=0x212a8,b=0x211e8)+0x31b /sys/src/libmp/port/mpexp.c:26

t=0xb7bb1b14
tofree=0x626d
i=0x212a8
d=0x211e8
bit=0x626d
j=0xd9ae

probably_prime(n=0x1eda8,nrep=0x12)+0xc1 /sys/src/libsec/port/probably_prime.c:39

x=0x211e8
y=0x212a8
nbits=0x670d
nm1=0x11
k=0xfffffff9
q=0xda27
rep=0x1e078
r=0x4f69a694
j=0x21
isprime=0x11

genprime(p=0x1eda8,n=0x401,accuracy=0x0)+0x9d /sys/src/libsec/port/genprime.c:23 rsagen(nlen=0x800,elen=0x10001,rounds=0x0)+0xd4 /sys/src/libsec/port/rsagen.c:21

p=0x1ece8
q=0x1eda8
n=0x1ee68
e=0x1efa8
d=0x20fe8
phi=0x210a8
t1=0x7b54
t2=0xdb84
c2=0x2a080
kq=0x214c0
kp=0x29fc8
rsa=0x1ccc4

main(argv=0x3fffffa8,argc=0x0)+0x53 /usr/mischief/src/regress/mpexp-283cc2200e34.c:15

_argc=0x0
_args=0x0
p=0x2a088

_main+0x31 /sys/src/libc/386/main9.s:16 acid:


Tue, 1 Dec 2015 14:29:10 EST
sl@[REDACTED]

Date: Tue, Dec 01, 2015 at 3:42 AM Subject: Fwd: [9front-commits] cinap_lenrek at hg/plan9front: libsec: fix genprime() to produce… To: <
9front-commits@[REDACTED]
[9front-commits@[REDACTED]] > details: http://code.9front.org/hg/plan9front/rev/3b8120c2afba changeset: 4997:3b8120c2afba user:
cinap_lenrek@[REDACTED] date: Tue Dec 01 09:40:24 2015 +0100 description: libsec: fix genprime() to produce normalized result

this fixed bug “assert_failed_m-flags__mpnorm_since_283cc2200e34”.