1#ifndef CRYPTOPP_EMSA2_H
2#define CRYPTOPP_EMSA2_H
3
4/** \file
5	This file contains various padding schemes for public key algorithms.
6*/
7
8#include "cryptlib.h"
9#include "pubkey.h"
10
11#ifdef CRYPTOPP_IS_DLL
12#include "sha.h"
13#endif
14
15NAMESPACE_BEGIN(CryptoPP)
16
17template <class H> class EMSA2HashId
18{
19public:
20	static const byte id;
21};
22
23template <class BASE>
24class EMSA2HashIdLookup : public BASE
25{
26public:
27	struct HashIdentifierLookup
28	{
29		template <class H> struct HashIdentifierLookup2
30		{
31			static HashIdentifier Lookup()
32			{
33				return HashIdentifier(&EMSA2HashId<H>::id, 1);
34			}
35		};
36	};
37};
38
39// EMSA2HashId can be instantiated with the following classes.
40class SHA1;
41class RIPEMD160;
42class RIPEMD128;
43class SHA256;
44class SHA384;
45class SHA512;
46class Whirlpool;
47class SHA224;
48// end of list
49
50#ifdef CRYPTOPP_IS_DLL
51CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA1>;
52CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA224>;
53CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA256>;
54CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA384>;
55CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA512>;
56#endif
57
58//! _
59class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod>
60{
61public:
62	static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";}
63
64	size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const
65		{return 8*digestLength + 31;}
66
67	void ComputeMessageRepresentative(RandomNumberGenerator &rng,
68		const byte *recoverableMessage, size_t recoverableMessageLength,
69		HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
70		byte *representative, size_t representativeBitLength) const;
71};
72
73//! EMSA2, for use with RWSS and RSA_ISO
74/*! Only the following hash functions are supported by this signature standard:
75	\dontinclude emsa2.h
76	\skip EMSA2HashId can be instantiated
77	\until end of list
78*/
79struct P1363_EMSA2 : public SignatureStandard
80{
81	typedef EMSA2Pad SignatureMessageEncodingMethod;
82};
83
84NAMESPACE_END
85
86#endif
87