00001
00002
00003 #ifndef CRYPTOPP_NBTHEORY_H
00004 #define CRYPTOPP_NBTHEORY_H
00005
00006 #include "integer.h"
00007 #include "algparam.h"
00008
00009 NAMESPACE_BEGIN(CryptoPP)
00010
00011
00012 CRYPTOPP_DLL const word16 * CRYPTOPP_API GetPrimeTable(unsigned int &size);
00013
00014
00015
00016
00017 CRYPTOPP_DLL Integer CRYPTOPP_API MaurerProvablePrime(RandomNumberGenerator &rng, unsigned int bits);
00018 CRYPTOPP_DLL Integer CRYPTOPP_API MihailescuProvablePrime(RandomNumberGenerator &rng, unsigned int bits);
00019
00020 CRYPTOPP_DLL bool CRYPTOPP_API IsSmallPrime(const Integer &p);
00021
00022
00023
00024 CRYPTOPP_DLL bool CRYPTOPP_API TrialDivision(const Integer &p, unsigned bound);
00025
00026
00027 CRYPTOPP_DLL bool CRYPTOPP_API SmallDivisorsTest(const Integer &p);
00028
00029
00030 CRYPTOPP_DLL bool CRYPTOPP_API IsFermatProbablePrime(const Integer &n, const Integer &b);
00031 CRYPTOPP_DLL bool CRYPTOPP_API IsLucasProbablePrime(const Integer &n);
00032
00033 CRYPTOPP_DLL bool CRYPTOPP_API IsStrongProbablePrime(const Integer &n, const Integer &b);
00034 CRYPTOPP_DLL bool CRYPTOPP_API IsStrongLucasProbablePrime(const Integer &n);
00035
00036
00037
00038 CRYPTOPP_DLL bool CRYPTOPP_API RabinMillerTest(RandomNumberGenerator &rng, const Integer &w, unsigned int rounds);
00039
00040
00041 CRYPTOPP_DLL bool CRYPTOPP_API IsPrime(const Integer &p);
00042
00043
00044 CRYPTOPP_DLL bool CRYPTOPP_API VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level = 1);
00045
00046 class CRYPTOPP_DLL PrimeSelector
00047 {
00048 public:
00049 const PrimeSelector *GetSelectorPointer() const {return this;}
00050 virtual bool IsAcceptable(const Integer &candidate) const =0;
00051 };
00052
00053
00054
00055 CRYPTOPP_DLL bool CRYPTOPP_API FirstPrime(Integer &p, const Integer &max, const Integer &equiv, const Integer &mod, const PrimeSelector *pSelector);
00056
00057 CRYPTOPP_DLL unsigned int CRYPTOPP_API PrimeSearchInterval(const Integer &max);
00058
00059 CRYPTOPP_DLL AlgorithmParameters CRYPTOPP_API MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength);
00060
00061
00062
00063 inline Integer GCD(const Integer &a, const Integer &b)
00064 {return Integer::Gcd(a,b);}
00065 inline bool RelativelyPrime(const Integer &a, const Integer &b)
00066 {return Integer::Gcd(a,b) == Integer::One();}
00067 inline Integer LCM(const Integer &a, const Integer &b)
00068 {return a/Integer::Gcd(a,b)*b;}
00069 inline Integer EuclideanMultiplicativeInverse(const Integer &a, const Integer &b)
00070 {return a.InverseMod(b);}
00071
00072
00073 CRYPTOPP_DLL Integer CRYPTOPP_API CRT(const Integer &xp, const Integer &p, const Integer &xq, const Integer &q, const Integer &u);
00074
00075
00076
00077 CRYPTOPP_DLL int CRYPTOPP_API Jacobi(const Integer &a, const Integer &b);
00078
00079
00080 CRYPTOPP_DLL Integer CRYPTOPP_API Lucas(const Integer &e, const Integer &p, const Integer &n);
00081
00082 CRYPTOPP_DLL Integer CRYPTOPP_API InverseLucas(const Integer &e, const Integer &m, const Integer &p, const Integer &q, const Integer &u);
00083
00084 inline Integer ModularExponentiation(const Integer &a, const Integer &e, const Integer &m)
00085 {return a_exp_b_mod_c(a, e, m);}
00086
00087 CRYPTOPP_DLL Integer CRYPTOPP_API ModularSquareRoot(const Integer &a, const Integer &p);
00088
00089
00090
00091
00092 CRYPTOPP_DLL Integer CRYPTOPP_API ModularRoot(const Integer &a, const Integer &dp, const Integer &dq, const Integer &p, const Integer &q, const Integer &u);
00093
00094
00095
00096 CRYPTOPP_DLL bool CRYPTOPP_API SolveModularQuadraticEquation(Integer &r1, Integer &r2, const Integer &a, const Integer &b, const Integer &c, const Integer &p);
00097
00098
00099 CRYPTOPP_DLL unsigned int CRYPTOPP_API DiscreteLogWorkFactor(unsigned int bitlength);
00100 CRYPTOPP_DLL unsigned int CRYPTOPP_API FactoringWorkFactor(unsigned int bitlength);
00101
00102
00103
00104
00105 class CRYPTOPP_DLL PrimeAndGenerator
00106 {
00107 public:
00108 PrimeAndGenerator() {}
00109
00110
00111
00112 PrimeAndGenerator(signed int delta, RandomNumberGenerator &rng, unsigned int pbits)
00113 {Generate(delta, rng, pbits, pbits-1);}
00114
00115
00116 PrimeAndGenerator(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned qbits)
00117 {Generate(delta, rng, pbits, qbits);}
00118
00119 void Generate(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned qbits);
00120
00121 const Integer& Prime() const {return p;}
00122 const Integer& SubPrime() const {return q;}
00123 const Integer& Generator() const {return g;}
00124
00125 private:
00126 Integer p, q, g;
00127 };
00128
00129 NAMESPACE_END
00130
00131 #endif