diff options
author | weidai <weidai11@users.noreply.github.com> | 2003-03-20 01:24:12 +0000 |
---|---|---|
committer | weidai <weidai11@users.noreply.github.com> | 2003-03-20 01:24:12 +0000 |
commit | 538de80a91da74598ba2449fbbec6de37376a4ce (patch) | |
tree | f85b3bed971083e90e5f3dbb84539ea4ba0359e9 /pkcspad.h | |
parent | 21955e23ec9697d1cd47ff91f91b08af382b8a6d (diff) | |
download | cryptopp-git-538de80a91da74598ba2449fbbec6de37376a4ce.tar.gz |
various changes for 5.1
Diffstat (limited to 'pkcspad.h')
-rw-r--r-- | pkcspad.h | 76 |
1 files changed, 27 insertions, 49 deletions
@@ -6,8 +6,8 @@ NAMESPACE_BEGIN(CryptoPP) -/// <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a> -class PKCS_EncryptionPaddingScheme : public PK_PaddingAlgorithm +//! <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a> +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; }; -/// <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a> -class PKCS_SignaturePaddingScheme : public PK_PaddingAlgorithm +template <class H> 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; }; -/// <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a> -template <class H> -class PKCS_DecoratedHashModule : public HashTransformationWithDefaultTruncation +//! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a> +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 <class H> struct HashIdentifierLookup2 + { + static HashIdentifier Lookup() + { + return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::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 <class H> struct SignaturePaddingAlgorithm {typedef PKCS_SignaturePaddingScheme type;}; - template <class H> struct DecoratedHashingAlgorithm {typedef PKCS_DecoratedHashModule<H> type;}; -}; - -template<> struct CryptoStandardTraits<PKCS1v15> : public PKCS1v15 {}; - -template <class H> 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 <class H> -void PKCS_DecoratedHashModule<H>::Final(byte *digest) -{ - const unsigned int decorationLen = PKCS_DigestDecoration<H>::length; - memcpy(digest, PKCS_DigestDecoration<H>::decoration, decorationLen); - h.Final(digest+decorationLen); -} - -template <class H> -unsigned int PKCS_DecoratedHashModule<H>::DigestSize() const -{ - return h.DigestSize() + PKCS_DigestDecoration<H>::length; // PKCS_DigestDecoration<H>::length; -} - NAMESPACE_END #endif |