Crypto++ 7.0 Free C++ class library of cryptographic schemes

emsa2.h
Go to the documentation of this file.
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 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";}
75
76 size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const
77 {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
misc.h
Utility functions for the Crypto++ library.
hashfwd.h
Forward declarations for hash functions used in signature encoding methods.
pubkey.h
This file contains helper classes/functions for implementing public key algorithms.
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
RandomNumberGenerator
Interface for random number generators.
Definition: cryptlib.h:1349
EMSA2Pad
EMSA2 padding method.
Definition: emsa2.h:71
SignatureStandard
Base class for public key signature standard classes.
Definition: pubkey.h:2216
EMSA2HashIdLookup::HashIdentifierLookup::HashIdentifierLookup2
Definition: emsa2.h:38
EMSA2HashId
EMSA2 hash identifier.
Definition: emsa2.h:23
P1363_EMSA2
EMSA2/P1363 padding method.
Definition: emsa2.h:94
EMSA2HashIdLookup::HashIdentifierLookup
Definition: emsa2.h:36
EMSA2HashIdLookup
EMSA2 padding method.
Definition: emsa2.h:33
sha.h
Classes for SHA-1 and SHA-2 family of message digests.
HashTransformation
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1084
CryptoPP
Crypto++ library namespace.