Line | Count | Source (jump to first uncovered line) |
1 | | // emsa2.h - originally 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 "hashfwd.h" |
12 | | #include "misc.h" |
13 | | |
14 | | #ifdef CRYPTOPP_IS_DLL |
15 | | # include "sha.h" |
16 | | #endif |
17 | | |
18 | | NAMESPACE_BEGIN(CryptoPP) |
19 | | |
20 | | /// \brief EMSA2 hash identifier |
21 | | /// \tparam H HashTransformation derived class |
22 | | /// \since Crypto++ 5.0 |
23 | | template <class H> class EMSA2HashId |
24 | | { |
25 | | public: |
26 | | static const byte id; |
27 | | }; |
28 | | |
29 | | /// \brief EMSA2 padding method |
30 | | /// \tparam BASE Message encoding method |
31 | | /// \since Crypto++ 5.0 |
32 | | template <class BASE> |
33 | | class EMSA2HashIdLookup : public BASE |
34 | | { |
35 | | public: |
36 | | struct HashIdentifierLookup |
37 | | { |
38 | | template <class H> struct HashIdentifierLookup2 |
39 | | { |
40 | | static HashIdentifier Lookup() |
41 | | { |
42 | | return HashIdentifier(&EMSA2HashId<H>::id, 1); |
43 | | } |
44 | | }; |
45 | | }; |
46 | | }; |
47 | | |
48 | | // EMSA2HashId can be instantiated with the following classes. |
49 | | // SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD128, RIPEMD160, Whirlpool |
50 | | |
51 | | #ifdef CRYPTOPP_IS_DLL |
52 | | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA1>; |
53 | | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA224>; |
54 | | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA256>; |
55 | | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA384>; |
56 | | CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA512>; |
57 | | #endif |
58 | | |
59 | | // https://github.com/weidai11/cryptopp/issues/300 and |
60 | | // https://github.com/weidai11/cryptopp/issues/533 |
61 | | #if defined(__clang__) |
62 | | template<> const byte EMSA2HashId<SHA1>::id; |
63 | | template<> const byte EMSA2HashId<SHA224>::id; |
64 | | template<> const byte EMSA2HashId<SHA256>::id; |
65 | | template<> const byte EMSA2HashId<SHA384>::id; |
66 | | template<> const byte EMSA2HashId<SHA512>::id; |
67 | | #endif |
68 | | |
69 | | /// \brief EMSA2 padding method |
70 | | /// \since Crypto++ 5.0 |
71 | | class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod> |
72 | | { |
73 | | public: |
74 | 0 | CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";} |
75 | | |
76 | | size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const |
77 | 0 | {CRYPTOPP_UNUSED(hashIdentifierLength); return 8*digestLength + 31;} |
78 | | |
79 | | void ComputeMessageRepresentative(RandomNumberGenerator &rng, |
80 | | const byte *recoverableMessage, size_t recoverableMessageLength, |
81 | | HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, |
82 | | byte *representative, size_t representativeBitLength) const; |
83 | | }; |
84 | | |
85 | | // EMSA2, for use with RWSS and RSA_ISO |
86 | | // Only the following hash functions are supported by this signature standard: |
87 | | // \dontinclude emsa2.h |
88 | | // \skip EMSA2HashId can be instantiated |
89 | | // \until end of list |
90 | | |
91 | | /// \brief EMSA2/P1363 padding method |
92 | | /// \details Use with RWSS and RSA_ISO |
93 | | /// \since Crypto++ 5.0 |
94 | | struct P1363_EMSA2 : public SignatureStandard |
95 | | { |
96 | | typedef EMSA2Pad SignatureMessageEncodingMethod; |
97 | | }; |
98 | | |
99 | | NAMESPACE_END |
100 | | |
101 | | #endif |