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