1#ifndef CRYPTOPP_PKCSPAD_H
2#define CRYPTOPP_PKCSPAD_H
3
4#include "cryptlib.h"
5#include "pubkey.h"
6
7#ifdef CRYPTOPP_IS_DLL
8#include "sha.h"
9#endif
10
11NAMESPACE_BEGIN(CryptoPP)
12
13//! <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a>
14class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod
15{
16public:
17	static const char * StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
18
19	size_t MaxUnpaddedLength(size_t paddedLength) const;
20	void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
21	DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs &parameters) const;
22};
23
24template <class H> class PKCS_DigestDecoration
25{
26public:
27	static const byte decoration[];
28	static const unsigned int length;
29};
30
31// PKCS_DigestDecoration can be instantiated with the following
32// classes as specified in PKCS#1 v2.0 and P1363a
33class SHA1;
34class RIPEMD160;
35class Tiger;
36class SHA224;
37class SHA256;
38class SHA384;
39class SHA512;
40namespace Weak1 {
41class MD2;
42class MD5;
43}
44// end of list
45
46#ifdef CRYPTOPP_IS_DLL
47CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>;
48CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>;
49CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>;
50CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>;
51CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>;
52#endif
53
54//! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a>
55class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod
56{
57public:
58	static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
59
60	size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
61		{return 8 * (digestSize + hashIdentifierSize + 10);}
62
63	void ComputeMessageRepresentative(RandomNumberGenerator &rng,
64		const byte *recoverableMessage, size_t recoverableMessageLength,
65		HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
66		byte *representative, size_t representativeBitLength) const;
67
68	struct HashIdentifierLookup
69	{
70		template <class H> struct HashIdentifierLookup2
71		{
72			static HashIdentifier Lookup()
73			{
74				return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::length);
75			}
76		};
77	};
78};
79
80//! PKCS #1 version 1.5, for use with RSAES and RSASS
81/*! Only the following hash functions are supported by this signature standard:
82	\dontinclude pkcspad.h
83	\skip can be instantiated
84	\until end of list
85*/
86struct PKCS1v15 : public SignatureStandard, public EncryptionStandard
87{
88	typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod;
89	typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod;
90};
91
92NAMESPACE_END
93
94#endif
95