From e5888a1ffdae813d7575f5fb02275c6bb07e5199 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Wed, 30 Mar 2011 15:46:40 +0300 Subject: Import sources from 2011-03-30 iso image --- sys/src/cmd/unix/drawterm/libsec/genprime.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 sys/src/cmd/unix/drawterm/libsec/genprime.c (limited to 'sys/src/cmd/unix/drawterm/libsec/genprime.c') diff --git a/sys/src/cmd/unix/drawterm/libsec/genprime.c b/sys/src/cmd/unix/drawterm/libsec/genprime.c new file mode 100755 index 000000000..c0e16d92b --- /dev/null +++ b/sys/src/cmd/unix/drawterm/libsec/genprime.c @@ -0,0 +1,27 @@ +#include "os.h" +#include +#include + +// generate a probable prime. accuracy is the miller-rabin interations +void +genprime(mpint *p, int n, int accuracy) +{ + mpdigit x; + + // generate n random bits with high and low bits set + mpbits(p, n); + genrandom((uchar*)p->p, (n+7)/8); + p->top = (n+Dbits-1)/Dbits; + x = 1; + x <<= ((n-1)%Dbits); + p->p[p->top-1] &= (x-1); + p->p[p->top-1] |= x; + p->p[0] |= 1; + + // keep icrementing till it looks prime + for(;;){ + if(probably_prime(p, accuracy)) + break; + mpadd(p, mptwo, p); + } +} -- cgit v1.2.3