From d23a489940499bd6c634a1cb0a9875f094f8a850 Mon Sep 17 00:00:00 2001 From: weidai Date: Thu, 20 Mar 2003 01:24:12 +0000 Subject: various changes for 5.1 git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@38 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- pkcspad.h | 76 +++++++++++++++++++++++---------------------------------------- 1 file changed, 27 insertions(+), 49 deletions(-) (limited to 'pkcspad.h') diff --git a/pkcspad.h b/pkcspad.h index 347bd95..2e14a5e 100644 --- a/pkcspad.h +++ b/pkcspad.h @@ -6,8 +6,8 @@ NAMESPACE_BEGIN(CryptoPP) -/// EME-PKCS1-v1_5 -class PKCS_EncryptionPaddingScheme : public PK_PaddingAlgorithm +//! EME-PKCS1-v1_5 +class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod { public: static const char * StaticAlgorithmName() {return "EME-PKCS1-v1_5";} @@ -17,50 +17,41 @@ public: DecodingResult Unpad(const byte *padded, unsigned int paddedLength, byte *raw) const; }; -/// EMSA-PKCS1-v1_5 -class PKCS_SignaturePaddingScheme : public PK_PaddingAlgorithm +template struct PKCS_DigestDecoration { -public: - static const char * StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";} - - unsigned int MaxUnpaddedLength(unsigned int paddedLength) const; - void Pad(RandomNumberGenerator &rng, const byte *raw, unsigned int inputLength, byte *padded, unsigned int paddedLength) const; - DecodingResult Unpad(const byte *padded, unsigned int paddedLength, byte *raw) const; + static const byte decoration[]; + static const unsigned int length; }; -/// EMSA-PKCS1-v1_5 -template -class PKCS_DecoratedHashModule : public HashTransformationWithDefaultTruncation +//! EMSA-PKCS1-v1_5 +class PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod { public: - static std::string StaticAlgorithmName() {return std::string("EMSA-PKCS1-v1_5(") + H::StaticAlgorithmName() + ")";} - - void Update(const byte *input, unsigned int length) - {h.Update(input, length);} - unsigned int DigestSize() const; - void Final(byte *digest); - void Restart() {h.Restart();} + static const char * StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";} -private: - H h; + void ComputeMessageRepresentative(RandomNumberGenerator &rng, + const byte *recoverableMessage, unsigned int recoverableMessageLength, + HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, + byte *representative, unsigned int representativeBitLength) const; + + struct HashIdentifierLookup + { + template struct HashIdentifierLookup2 + { + static HashIdentifier Lookup() + { + return HashIdentifier(PKCS_DigestDecoration::decoration, PKCS_DigestDecoration::length); + } + }; + }; }; -//! PKCS #1 version 1.5, for use with RSAES and RSASSA +//! PKCS #1 version 1.5, for use with RSAES and RSASS /*! The following hash functions are supported for signature: SHA, MD2, MD5, RIPEMD160, SHA256, SHA384, SHA512. */ struct PKCS1v15 : public SignatureStandard, public EncryptionStandard { - typedef PKCS_EncryptionPaddingScheme EncryptionPaddingAlgorithm; - - template struct SignaturePaddingAlgorithm {typedef PKCS_SignaturePaddingScheme type;}; - template struct DecoratedHashingAlgorithm {typedef PKCS_DecoratedHashModule type;}; -}; - -template<> struct CryptoStandardTraits : public PKCS1v15 {}; - -template struct PKCS_DigestDecoration -{ - static const byte decoration[]; - static const unsigned int length; + typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod; + typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod; }; // PKCS_DecoratedHashModule can be instantiated with the following @@ -69,24 +60,11 @@ class SHA; class MD2; class MD5; class RIPEMD160; +class Tiger; class SHA256; class SHA384; class SHA512; -template -void PKCS_DecoratedHashModule::Final(byte *digest) -{ - const unsigned int decorationLen = PKCS_DigestDecoration::length; - memcpy(digest, PKCS_DigestDecoration::decoration, decorationLen); - h.Final(digest+decorationLen); -} - -template -unsigned int PKCS_DecoratedHashModule::DigestSize() const -{ - return h.DigestSize() + PKCS_DigestDecoration::length; // PKCS_DigestDecoration::length; -} - NAMESPACE_END #endif -- cgit v1.2.1