Crypto++ 8.7
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
18NAMESPACE_BEGIN(CryptoPP)
19
20/// \brief EMSA2 hash identifier
21/// \tparam H HashTransformation derived class
22/// \since Crypto++ 5.0
23template <class H> class EMSA2HashId
24{
25public:
26 static const byte id;
27};
28
29/// \brief EMSA2 padding method
30/// \tparam BASE Message encoding method
31/// \since Crypto++ 5.0
32template <class BASE>
33class EMSA2HashIdLookup : public BASE
34{
35public:
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
57#endif
58
59// https://github.com/weidai11/cryptopp/issues/300 and
60// https://github.com/weidai11/cryptopp/issues/533
61#if defined(__clang__)
62template<> const byte EMSA2HashId<SHA1>::id;
63template<> const byte EMSA2HashId<SHA224>::id;
64template<> const byte EMSA2HashId<SHA256>::id;
65template<> const byte EMSA2HashId<SHA384>::id;
66template<> const byte EMSA2HashId<SHA512>::id;
67#endif
68
69/// \brief EMSA2 padding method
70/// \since Crypto++ 5.0
71class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod>
72{
73public:
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
95{
97};
98
99NAMESPACE_END
100
101#endif
EMSA2 hash identifier.
Definition: emsa2.h:24
EMSA2 padding method.
Definition: emsa2.h:34
EMSA2 padding method.
Definition: emsa2.h:72
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1113
Interface for random number generators.
Definition: cryptlib.h:1435
#define CRYPTOPP_API
Win32 calling convention.
Definition: config_dll.h:119
#define CRYPTOPP_DLL_TEMPLATE_CLASS
Instantiate templates in a dynamic library.
Definition: config_dll.h:72
Abstract base classes that provide a uniform interface to this library.
Forward declarations for hash functions used in signature encoding methods.
Utility functions for the Crypto++ library.
Crypto++ library namespace.
This file contains helper classes/functions for implementing public key algorithms.
Classes for SHA-1 and SHA-2 family of message digests.
EMSA2/P1363 padding method.
Definition: emsa2.h:95
Base class for public key signature standard classes.
Definition: pubkey.h:2279