aboutsummaryrefslogtreecommitdiff
path: root/primes.cpp
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-06 20:20:49 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-06 20:20:49 +0200
commit053d2e76ad5848c8d95d7d56bfe7f8a6a324c229 (patch)
tree0c7c16fc80d00d42913fc24d06f82794c8a6b944 /primes.cpp
parent98c5cb7a99222b3dc2d78468bd953a4a4a4142d7 (diff)
RNG
Diffstat (limited to 'primes.cpp')
-rw-r--r--primes.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/primes.cpp b/primes.cpp
index 934d886..ddb559c 100644
--- a/primes.cpp
+++ b/primes.cpp
@@ -31,7 +31,7 @@ void fillsmallprimes(){
//cerr<<endl;
}
-pair<Bigint,Bigint> genprimepair(int nbits){
+pair<Bigint,Bigint> genprimepair(Rng &rng,int nbits){
// for x = nbits/2:
// (2^x)^2 = 2^(2x)
// (2^x + 2^(x-2))^2 = 2^(2x) + 2^(2x-1) + 2^(2x-4)
@@ -41,11 +41,11 @@ pair<Bigint,Bigint> genprimepair(int nbits){
int x1=nbits/2-2,x2=(nbits+1)/2+2;
assert(x1+x2==nbits);
return make_pair(
- randprime(Bigint::one<<x1,(Bigint::one<<x1)+(Bigint::one<<(x1-2))),
- randprime(Bigint::one<<x2,(Bigint::one<<x2)+(Bigint::one<<(x2-2))));
+ randprime(rng,Bigint::one<<x1,(Bigint::one<<x1)+(Bigint::one<<(x1-2))),
+ randprime(rng,Bigint::one<<x2,(Bigint::one<<x2)+(Bigint::one<<(x2-2))));
}
-Bigint randprime(const Bigint &biglow,const Bigint &bighigh){
+Bigint randprime(Rng &rng,const Bigint &biglow,const Bigint &bighigh){
//https://en.wikipedia.org/wiki/Generating_primes#Large_primes
if(!smallprimes_inited)fillsmallprimes();
@@ -58,7 +58,7 @@ Bigint randprime(const Bigint &biglow,const Bigint &bighigh){
high=bighigh;
// cerr<<"low=biglow="<<low<<" high=bighigh="<<high<<endl;
} else {
- high=low=cryptrandom_big(diff-maxrangesize);
+ high=low=bigrandom(rng,diff-maxrangesize);
high+=maxrangesize;
// cerr<<"low="<<low<<" high="<<high<<endl;
}
@@ -102,7 +102,7 @@ Bigint randprime(const Bigint &biglow,const Bigint &bighigh){
// cerr<<endl;
while(maybeprimes.size()){
- int idx=arc4random_uniform(maybeprimes.size());
+ int idx=rng.get_uniform(maybeprimes.size());
int i=maybeprimes[idx];
Bigint bi(low+2*i);
if(bailliePSW(bi))return bi;