diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2003-03-20 01:24:12 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2003-03-20 01:24:12 +0000 |
commit | d23a489940499bd6c634a1cb0a9875f094f8a850 (patch) | |
tree | f85b3bed971083e90e5f3dbb84539ea4ba0359e9 /gfpcrypt.h | |
parent | b3517523a738277cfe22428bd757833e69abb66e (diff) | |
download | cryptopp-d23a489940499bd6c634a1cb0a9875f094f8a850.tar.gz |
various changes for 5.1
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@38 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'gfpcrypt.h')
-rw-r--r-- | gfpcrypt.h | 55 |
1 files changed, 39 insertions, 16 deletions
@@ -149,18 +149,13 @@ class DL_Algorithm_GDSA : public DL_ElgamalLikeSignatureAlgorithm<T> public: static const char * StaticAlgorithmName() {return "DSA-1363";} - Integer EncodeDigest(unsigned int modulusBits, const byte *digest, unsigned int digestLen) const - { - return DSA_EncodeDigest(modulusBits, digest, digestLen); - } - - bool Sign(const DL_GroupParameters<T> ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const + void Sign(const DL_GroupParameters<T> ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const { const Integer &q = params.GetSubgroupOrder(); - r = params.ConvertElementToInteger(params.ExponentiateBase(k)) % q; + r %= q; Integer kInv = k.InverseMod(q); s = (kInv * (x*r + e)) % q; - return (!!r && !!s); + assert(!!r && !!s); } bool Verify(const DL_GroupParameters<T> ¶ms, const DL_PublicKey<T> &publicKey, const Integer &e, const Integer &r, const Integer &s) const @@ -189,12 +184,12 @@ public: return NR_EncodeDigest(modulusBits, digest, digestLen); } - bool Sign(const DL_GroupParameters<T> ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const + void Sign(const DL_GroupParameters<T> ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const { const Integer &q = params.GetSubgroupOrder(); - r = (params.ConvertElementToInteger(params.ExponentiateBase(k)) + e) % q; + r = (r + e) % q; s = (k - x*r) % q; - return !!r; + assert(!!r); } bool Verify(const DL_GroupParameters<T> ¶ms, const DL_PublicKey<T> &publicKey, const Integer &e, const Integer &r, const Integer &s) const @@ -345,13 +340,21 @@ public: //! <a href="http://www.weidai.com/scan-mirror/sig.html#DSA-1363">DSA-1363</a> template <class H> -struct GDSA : public DL_SSA<DL_SignatureKeys_GFP, DL_Algorithm_GDSA<Integer>, H> +struct GDSA : public DL_SS< + DL_SignatureKeys_GFP, + DL_Algorithm_GDSA<Integer>, + DL_SignatureMessageEncodingMethod_DSA, + H> { }; //! <a href="http://www.weidai.com/scan-mirror/sig.html#NR">NR</a> template <class H> -struct NR : public DL_SSA<DL_SignatureKeys_GFP, DL_Algorithm_NR<Integer>, H> +struct NR : public DL_SS< + DL_SignatureKeys_GFP, + DL_Algorithm_NR<Integer>, + DL_SignatureMessageEncodingMethod_NR, + H> { }; @@ -376,7 +379,12 @@ struct DL_Keys_DSA }; //! <a href="http://www.weidai.com/scan-mirror/sig.html#DSA">DSA</a> -struct DSA : public DL_SSA<DL_Keys_DSA, DL_Algorithm_GDSA<Integer>, SHA, DSA> +struct DSA : public DL_SS< + DL_Keys_DSA, + DL_Algorithm_GDSA<Integer>, + DL_SignatureMessageEncodingMethod_DSA, + SHA, + DSA> { static std::string StaticAlgorithmName() {return std::string("DSA");} @@ -426,7 +434,14 @@ public: } xorbuf(cipherText, plainText, cipherKey, plainTextLength); - MAC(macKey).CalculateDigest(cipherText + plainTextLength, cipherText, plainTextLength); + MAC mac(macKey); + mac.Update(cipherText, plainTextLength); + if (DHAES_MODE) + { + const byte L[8] = {0,0,0,0,0,0,0,0}; + mac.Update(L, 8); + } + mac.Final(cipherText + plainTextLength); } DecodingResult SymmetricDecrypt(const byte *key, const byte *cipherText, unsigned int cipherTextLength, byte *plainText) const { @@ -443,8 +458,16 @@ public: macKey = key + plainTextLength; } - if (!MAC(macKey).VerifyDigest(cipherText + plainTextLength, cipherText, plainTextLength)) + MAC mac(macKey); + mac.Update(cipherText, plainTextLength); + if (DHAES_MODE) + { + const byte L[8] = {0,0,0,0,0,0,0,0}; + mac.Update(L, 8); + } + if (!mac.Verify(cipherText + plainTextLength)) return DecodingResult(); + xorbuf(plainText, cipherText, cipherKey, plainTextLength); return DecodingResult(plainTextLength); } |