From 6282aab71c9f925b533065e4dbfce632b83ee4ac Mon Sep 17 00:00:00 2001 From: weidai Date: Sat, 19 Jan 2013 02:20:00 +0000 Subject: add SHA-3 update DSA to FIPS 186-3 update version numbers git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@535 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- gfpcrypt.h | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'gfpcrypt.h') diff --git a/gfpcrypt.h b/gfpcrypt.h index 5e9c635..7af993f 100644 --- a/gfpcrypt.h +++ b/gfpcrypt.h @@ -369,51 +369,43 @@ public: /*! parameters: (ModulusSize), or (Modulus, SubgroupOrder, SubgroupGenerator) */ /*! ModulusSize must be between DSA::MIN_PRIME_LENGTH and DSA::MAX_PRIME_LENGTH, and divisible by DSA::PRIME_LENGTH_MULTIPLE */ void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); + + static bool CRYPTOPP_API IsValidPrimeLength(unsigned int pbits) + {return pbits >= MIN_PRIME_LENGTH && pbits <= MAX_PRIME_LENGTH && pbits % PRIME_LENGTH_MULTIPLE == 0;} + + enum {MIN_PRIME_LENGTH = 1024, MAX_PRIME_LENGTH = 3072, PRIME_LENGTH_MULTIPLE = 1024}; }; -struct DSA; +template +class DSA2; //! DSA keys struct DL_Keys_DSA { typedef DL_PublicKey_GFP PublicKey; - typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA> PrivateKey; + typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA2 > PrivateKey; }; -//! DSA -struct CRYPTOPP_DLL DSA : public DL_SS< +//! DSA, as specified in FIPS 186-3 +// class named DSA2 instead of DSA for backwards compatibility (DSA was a non-template class) +template +class DSA2 : public DL_SS< DL_Keys_DSA, DL_Algorithm_GDSA, DL_SignatureMessageEncodingMethod_DSA, - SHA, - DSA> + H, + DSA2 > { - static const char * CRYPTOPP_API StaticAlgorithmName() {return "DSA";} - - //! Generate DSA primes according to NIST standard - /*! Both seedLength and primeLength are in bits, but seedLength should - be a multiple of 8. - If useInputCounterValue == true, the counter parameter is taken as input, otherwise it's used for output - */ - static bool CRYPTOPP_API GeneratePrimes(const byte *seed, unsigned int seedLength, int &counter, - Integer &p, unsigned int primeLength, Integer &q, bool useInputCounterValue = false); - - static bool CRYPTOPP_API IsValidPrimeLength(unsigned int pbits) - {return pbits >= MIN_PRIME_LENGTH && pbits <= MAX_PRIME_LENGTH && pbits % PRIME_LENGTH_MULTIPLE == 0;} - - //! FIPS 186-2 Change Notice 1 changed the minimum modulus length to 1024 - enum { -#if (DSA_1024_BIT_MODULUS_ONLY) - MIN_PRIME_LENGTH = 1024, -#else - MIN_PRIME_LENGTH = 512, -#endif - MAX_PRIME_LENGTH = 1024, PRIME_LENGTH_MULTIPLE = 64}; +public: + static std::string CRYPTOPP_API StaticAlgorithmName() {return "DSA/" + (std::string)H::StaticAlgorithmName();} }; +//! DSA with SHA-1, typedef'd for backwards compatibility +typedef DSA2 DSA; + CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_GFP; CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_GFP; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA>; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA2 >; //! the XOR encryption method, for use with DL-based cryptosystems template -- cgit v1.2.1