Subversion Repositories planix.SVN

Rev

Rev 22 | Details | Compare with Previous | 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;
26 7u83 20
	mpnorm(p);
2 - 21
 
22
	// keep icrementing till it looks prime
23
	for(;;){
24
		if(probably_prime(p, accuracy))
25
			break;
26
		mpadd(p, mptwo, p);
27
	}
28
}