Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_posix/sys/src/cmd/unix/drawterm/libsec/genprime.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <mp.h>
3
#include <libsec.h>
4
 
5
//  generate a probable prime.  accuracy is the miller-rabin interations
6
void
7
genprime(mpint *p, int n, int accuracy)
8
{
9
	mpdigit x;
10
 
11
	// generate n random bits with high and low bits set
12
	mpbits(p, n);
13
	genrandom((uchar*)p->p, (n+7)/8);
14
	p->top = (n+Dbits-1)/Dbits;
15
	x = 1;
16
	x <<= ((n-1)%Dbits);
17
	p->p[p->top-1] &= (x-1);
18
	p->p[p->top-1] |= x;
19
	p->p[0] |= 1;
20
 
21
	// keep icrementing till it looks prime
22
	for(;;){
23
		if(probably_prime(p, accuracy))
24
			break;
25
		mpadd(p, mptwo, p);
26
	}
27
}