Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:02

0001 // emsa2.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file emsa2.h

0004 /// \brief Classes and functions for various padding schemes used in public key algorithms

0005 
0006 #ifndef CRYPTOPP_EMSA2_H
0007 #define CRYPTOPP_EMSA2_H
0008 
0009 #include "cryptlib.h"
0010 #include "pubkey.h"
0011 #include "hashfwd.h"
0012 #include "misc.h"
0013 
0014 #ifdef CRYPTOPP_IS_DLL
0015 # include "sha.h"
0016 #endif
0017 
0018 NAMESPACE_BEGIN(CryptoPP)
0019 
0020 /// \brief EMSA2 hash identifier

0021 /// \tparam H HashTransformation derived class

0022 /// \since Crypto++ 5.0

0023 template <class H> class EMSA2HashId
0024 {
0025 public:
0026     static const byte id;
0027 };
0028 
0029 /// \brief EMSA2 padding method

0030 /// \tparam BASE Message encoding method

0031 /// \since Crypto++ 5.0

0032 template <class BASE>
0033 class EMSA2HashIdLookup : public BASE
0034 {
0035 public:
0036     struct HashIdentifierLookup
0037     {
0038         template <class H> struct HashIdentifierLookup2
0039         {
0040             static HashIdentifier Lookup()
0041             {
0042                 return HashIdentifier(&EMSA2HashId<H>::id, 1);
0043             }
0044         };
0045     };
0046 };
0047 
0048 // EMSA2HashId can be instantiated with the following classes.

0049 // SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD128, RIPEMD160, Whirlpool

0050 
0051 #ifdef CRYPTOPP_IS_DLL
0052 CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA1>;
0053 CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA224>;
0054 CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA256>;
0055 CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA384>;
0056 CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA512>;
0057 #endif
0058 
0059 // https://github.com/weidai11/cryptopp/issues/300 and

0060 // https://github.com/weidai11/cryptopp/issues/533

0061 #if defined(__clang__)
0062 template<> const byte EMSA2HashId<SHA1>::id;
0063 template<> const byte EMSA2HashId<SHA224>::id;
0064 template<> const byte EMSA2HashId<SHA256>::id;
0065 template<> const byte EMSA2HashId<SHA384>::id;
0066 template<> const byte EMSA2HashId<SHA512>::id;
0067 #endif
0068 
0069 /// \brief EMSA2 padding method

0070 /// \since Crypto++ 5.0

0071 class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod>
0072 {
0073 public:
0074     CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";}
0075 
0076     size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const
0077         {CRYPTOPP_UNUSED(hashIdentifierLength); return 8*digestLength + 31;}
0078 
0079     void ComputeMessageRepresentative(RandomNumberGenerator &rng,
0080         const byte *recoverableMessage, size_t recoverableMessageLength,
0081         HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
0082         byte *representative, size_t representativeBitLength) const;
0083 };
0084 
0085 // EMSA2, for use with RWSS and RSA_ISO

0086 // Only the following hash functions are supported by this signature standard:

0087 //  \dontinclude emsa2.h

0088 //  \skip EMSA2HashId can be instantiated

0089 //  \until end of list

0090 
0091 /// \brief EMSA2/P1363 padding method

0092 /// \details Use with RWSS and RSA_ISO

0093 /// \since Crypto++ 5.0

0094 struct P1363_EMSA2 : public SignatureStandard
0095 {
0096     typedef EMSA2Pad SignatureMessageEncodingMethod;
0097 };
0098 
0099 NAMESPACE_END
0100 
0101 #endif