Files Classes Functions Hierarchy
#include <primegen.h>
Public Member Functions | |
| largePrimeGenerator () | |
| Constructor generates a small prime table. | |
| ~largePrimeGenerator () | |
| void | findprime_sequentially (ZZ &n, uintc nbits) const |
| void | findprime_randomly (ZZ &n, uintc nbits) const |
| Keep looking for primes randomly till one found. | |
| bool const | isprime (ZZ const &n) const |
| Statistical prime test. | |
| void | ensurenbits (ZZ &n, uintc nbits) const |
| n is >= 2^nbits. | |
The library could do many of these functions but these functions are so easily to implement that another library could be easily used instead, so the library calls are isolated.
ie ZZ could be templated, random bit generation implemented and prime testing implemented then the only dependency is ZZ.
Definition at line 21 of file primegen.h.
| largePrimeGenerator::largePrimeGenerator | ( | ) |
Constructor generates a small prime table.
Definition at line 64 of file primegen.cpp.
00065 : v(0), vmax(1000) 00066 { 00067 PrimeSeq s; 00068 00069 v = new long int [vmax]; 00070 00071 for (uint i=0; i<vmax; ++i) 00072 v[i] = s.next(); 00073 }
| largePrimeGenerator::~largePrimeGenerator | ( | ) |
| void largePrimeGenerator::ensurenbits | ( | ZZ & | n, | |
| uintc | nbits | |||
| ) | const |
n is >= 2^nbits.
Definition at line 7 of file primegen.cpp.
00008 { 00009 ZZ n2; 00010 ZZ x; 00011 conv(x,"2"); 00012 power(n2,x,nbits); 00013 if (n<n2) 00014 n += n2; 00015 00016 if ((n%2)==0) 00017 ++n; 00018 }
| void largePrimeGenerator::findprime_randomly | ( | ZZ & | n, | |
| uintc | nbits | |||
| ) | const |
Keep looking for primes randomly till one found.
Definition at line 21 of file primegen.cpp.
Referenced by rsaGenKey::rsaGenKey(), and rsatest::test02().
00025 { 00026 for ( ; ; ) 00027 { 00028 RandomBits(n,nbits); 00029 ensurenbits(n,nbits); 00030 if (isprime(n)) 00031 return; 00032 } 00033 }
| void largePrimeGenerator::findprime_sequentially | ( | ZZ & | n, | |
| uintc | nbits | |||
| ) | const |
Definition at line 37 of file primegen.cpp.
Referenced by rsatest::test02().
00041 { 00042 RandomBits(n,nbits); 00043 ensurenbits(n,nbits); 00044 00045 for ( ; ; ) 00046 { 00047 if (isprime(n)) 00048 return; 00049 00050 n += 2; 00051 } 00052 }
| bool const largePrimeGenerator::isprime | ( | ZZ const & | n | ) | const |
Statistical prime test.
Do not use with small primes.
Definition at line 54 of file primegen.cpp.
00055 { 00056 for (uint i=0; i<vmax; ++i) 00057 if ((n%v[i])==0) 00058 return false; 00059 00060 return ProbPrime(n,15); 00061 }
1.5.8