File indexing completed on 2025-01-18 09:55:06
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CRYPTOPP_PKCSPAD_H
0009 #define CRYPTOPP_PKCSPAD_H
0010
0011 #include "cryptlib.h"
0012 #include "pubkey.h"
0013 #include "hashfwd.h"
0014
0015 #ifdef CRYPTOPP_IS_DLL
0016 #include "sha.h"
0017 #endif
0018
0019 NAMESPACE_BEGIN(CryptoPP)
0020
0021
0022
0023 class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod
0024 {
0025 public:
0026 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
0027
0028 size_t MaxUnpaddedLength(size_t paddedLength) const;
0029 void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs ¶meters) const;
0030 DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) const;
0031 };
0032
0033
0034 template <class H> class PKCS_DigestDecoration
0035 {
0036 public:
0037 static const byte decoration[];
0038 static const unsigned int length;
0039 };
0040
0041
0042
0043
0044
0045 #if defined(CRYPTOPP_IS_DLL)
0046 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>;
0047 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>;
0048 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>;
0049 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>;
0050 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>;
0051
0052 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA3_256>;
0053 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA3_384>;
0054 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA3_512>;
0055 #endif
0056
0057
0058
0059 #if defined(__clang__)
0060 template<> const byte PKCS_DigestDecoration<SHA1>::decoration[];
0061 template<> const unsigned int PKCS_DigestDecoration<SHA1>::length;
0062 template<> const byte PKCS_DigestDecoration<SHA224>::decoration[];
0063 template<> const unsigned int PKCS_DigestDecoration<SHA224>::length;
0064 template<> const byte PKCS_DigestDecoration<SHA256>::decoration[];
0065 template<> const unsigned int PKCS_DigestDecoration<SHA256>::length;
0066 template<> const byte PKCS_DigestDecoration<SHA384>::decoration[];
0067 template<> const unsigned int PKCS_DigestDecoration<SHA384>::length;
0068 template<> const byte PKCS_DigestDecoration<SHA512>::decoration[];
0069 template<> const unsigned int PKCS_DigestDecoration<SHA512>::length;
0070
0071
0072 template<> const byte PKCS_DigestDecoration<SHA3_256>::decoration[];
0073 template<> const unsigned int PKCS_DigestDecoration<SHA3_256>::length;
0074 template<> const byte PKCS_DigestDecoration<SHA3_384>::decoration[];
0075 template<> const unsigned int PKCS_DigestDecoration<SHA3_384>::length;
0076 template<> const byte PKCS_DigestDecoration<SHA3_512>::decoration[];
0077 template<> const unsigned int PKCS_DigestDecoration<SHA3_512>::length;
0078
0079 template<> const byte PKCS_DigestDecoration<Weak1::MD2>::decoration[];
0080 template<> const unsigned int PKCS_DigestDecoration<Weak1::MD2>::length;
0081 template<> const byte PKCS_DigestDecoration<Weak1::MD5>::decoration[];
0082 template<> const unsigned int PKCS_DigestDecoration<Weak1::MD5>::length;
0083 #endif
0084
0085
0086
0087 class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod
0088 {
0089 public:
0090 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
0091
0092 size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
0093 {return 8 * (digestSize + hashIdentifierSize + 10);}
0094
0095 void ComputeMessageRepresentative(RandomNumberGenerator &rng,
0096 const byte *recoverableMessage, size_t recoverableMessageLength,
0097 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
0098 byte *representative, size_t representativeBitLength) const;
0099
0100 struct HashIdentifierLookup
0101 {
0102 template <class H> struct HashIdentifierLookup2
0103 {
0104 static HashIdentifier Lookup()
0105 {
0106 return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::length);
0107 }
0108 };
0109 };
0110 };
0111
0112
0113
0114
0115 struct PKCS1v15 : public SignatureStandard, public EncryptionStandard
0116 {
0117 typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod;
0118 typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod;
0119 };
0120
0121 NAMESPACE_END
0122
0123 #endif