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<AlgorithmParameters<AlgorithmParameters<NullNameValuePairs, Integer::RandomNumberType>, Integer>, Integer>
00060 CRYPTOPP_API MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength);
00061
00062
00063
00064 inline Integer GCD(const Integer &a, const Integer &b)
00065 {return Integer::Gcd(a,b);}
00066 inline bool RelativelyPrime(const Integer &a, const Integer &b)
00067 {return Integer::Gcd(a,b) == Integer::One();}
00068 inline Integer LCM(const Integer &a, const Integer &b)
00069 {return a/Integer::Gcd(a,b)*b;}
00070 inline Integer EuclideanMultiplicativeInverse(const Integer &a, const Integer &b)
00071 {return a.InverseMod(b);}
00072
00073
00074 CRYPTOPP_DLL Integer CRYPTOPP_API CRT(const Integer &xp, const Integer &p, const Integer &xq, const Integer &q);
00075
00076 CRYPTOPP_DLL Integer CRYPTOPP_API CRT(const Integer &xp, const Integer &p, const Integer &xq, const Integer &q, const Integer &u);
00077
00078
00079
00080 CRYPTOPP_DLL int CRYPTOPP_API Jacobi(const Integer &a, const Integer &b);
00081
00082
00083 CRYPTOPP_DLL Integer CRYPTOPP_API Lucas(const Integer &e, const Integer &p, const Integer &n);
00084
00085 CRYPTOPP_DLL Integer CRYPTOPP_API InverseLucas(const Integer &e, const Integer &m, const Integer &p, const Integer &q);
00086
00087 CRYPTOPP_DLL Integer CRYPTOPP_API InverseLucas(const Integer &e, const Integer &m, const Integer &p, const Integer &q, const Integer &u);
00088
00089 inline Integer ModularExponentiation(const Integer &a, const Integer &e, const Integer &m)
00090 {return a_exp_b_mod_c(a, e, m);}
00091
00092 CRYPTOPP_DLL Integer CRYPTOPP_API ModularSquareRoot(const Integer &a, const Integer &p);
00093
00094
00095 CRYPTOPP_DLL Integer CRYPTOPP_API ModularRoot(const Integer &a, const Integer &e, const Integer &p, const Integer &q);
00096
00097
00098 CRYPTOPP_DLL Integer CRYPTOPP_API ModularRoot(const Integer &a, const Integer &dp, const Integer &dq, const Integer &p, const Integer &q, const Integer &u);
00099
00100
00101
00102 CRYPTOPP_DLL bool CRYPTOPP_API SolveModularQuadraticEquation(Integer &r1, Integer &r2, const Integer &a, const Integer &b, const Integer &c, const Integer &p);
00103
00104
00105 CRYPTOPP_DLL unsigned int CRYPTOPP_API DiscreteLogWorkFactor(unsigned int bitlength);
00106 CRYPTOPP_DLL unsigned int CRYPTOPP_API FactoringWorkFactor(unsigned int bitlength);
00107
00108
00109
00110
00111 class CRYPTOPP_DLL PrimeAndGenerator
00112 {
00113 public:
00114 PrimeAndGenerator() {}
00115
00116
00117
00118 PrimeAndGenerator(signed int delta, RandomNumberGenerator &rng, unsigned int pbits)
00119 {Generate(delta, rng, pbits, pbits-1);}
00120
00121
00122 PrimeAndGenerator(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned qbits)
00123 {Generate(delta, rng, pbits, qbits);}
00124
00125 void Generate(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned qbits);
00126
00127 const Integer& Prime() const {return p;}
00128 const Integer& SubPrime() const {return q;}
00129 const Integer& Generator() const {return g;}
00130
00131 private:
00132 Integer p, q, g;
00133 };
00134
00135 NAMESPACE_END
00136
00137 #endif