Crypto++ 8.7
Free C++ class library of cryptographic schemes
pkcspad.h
Go to the documentation of this file.
1// pkcspad.h - originally written and placed in the public domain by Wei Dai
2
3/// \file pkcspad.h
4/// \brief Classes for PKCS padding schemes
5/// \details PKCS #1 v1.5, v2.0 and P1363a allow MD2, MD5, SHA1, SHA224, SHA256, SHA384,
6/// SHA512, Tiger and RipeMd-160 to be instantiated.
7
8#ifndef CRYPTOPP_PKCSPAD_H
9#define CRYPTOPP_PKCSPAD_H
10
11#include "cryptlib.h"
12#include "pubkey.h"
13#include "hashfwd.h"
14
15#ifdef CRYPTOPP_IS_DLL
16#include "sha.h"
17#endif
18
19NAMESPACE_BEGIN(CryptoPP)
20
21/// \brief PKCS #1 v1.5 Encryption Padding Scheme
22/// \sa <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a>
24{
25public:
26 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
27
28 size_t MaxUnpaddedLength(size_t paddedLength) const;
29 void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
30 DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs &parameters) const;
31};
32
33/// \brief PKCS #1 decoration data structure
34template <class H> class PKCS_DigestDecoration
35{
36public:
37 static const byte decoration[];
38 static const unsigned int length;
39};
40
41// PKCS_DigestDecoration can be instantiated with the following
42// classes as specified in PKCS #1 v2.0 and P1363a
43// SHA1, SHA224, SHA256, SHA384, SHA512, Tiger, RIPEMD160, MD2, MD5
44
45#if defined(CRYPTOPP_IS_DLL)
51// http://github.com/weidai11/cryptopp/issues/517
55#endif
56
57// https://github.com/weidai11/cryptopp/issues/300 and
58// https://github.com/weidai11/cryptopp/issues/533
59#if defined(__clang__)
60template<> const byte PKCS_DigestDecoration<SHA1>::decoration[];
61template<> const unsigned int PKCS_DigestDecoration<SHA1>::length;
62template<> const byte PKCS_DigestDecoration<SHA224>::decoration[];
63template<> const unsigned int PKCS_DigestDecoration<SHA224>::length;
64template<> const byte PKCS_DigestDecoration<SHA256>::decoration[];
65template<> const unsigned int PKCS_DigestDecoration<SHA256>::length;
66template<> const byte PKCS_DigestDecoration<SHA384>::decoration[];
67template<> const unsigned int PKCS_DigestDecoration<SHA384>::length;
68template<> const byte PKCS_DigestDecoration<SHA512>::decoration[];
69template<> const unsigned int PKCS_DigestDecoration<SHA512>::length;
70
71// http://github.com/weidai11/cryptopp/issues/517
73template<> const unsigned int PKCS_DigestDecoration<SHA3_256>::length;
75template<> const unsigned int PKCS_DigestDecoration<SHA3_384>::length;
77template<> const unsigned int PKCS_DigestDecoration<SHA3_512>::length;
78
80template<> const unsigned int PKCS_DigestDecoration<Weak1::MD2>::length;
82template<> const unsigned int PKCS_DigestDecoration<Weak1::MD5>::length;
83#endif
84
85/// \brief PKCS #1 v1.5 Signature Encoding Scheme
86/// \sa <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a>
88{
89public:
90 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
91
92 size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
93 {return 8 * (digestSize + hashIdentifierSize + 10);}
94
95 void ComputeMessageRepresentative(RandomNumberGenerator &rng,
96 const byte *recoverableMessage, size_t recoverableMessageLength,
97 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
98 byte *representative, size_t representativeBitLength) const;
99
101 {
102 template <class H> struct HashIdentifierLookup2
103 {
104 static HashIdentifier Lookup()
105 {
107 }
108 };
109 };
110};
111
112/// \brief PKCS #1 version 1.5, for use with RSAES and RSASS
113/// \dontinclude pkcspad.h
114
116{
119};
120
121NAMESPACE_END
122
123#endif
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1113
Interface for retrieving values given their names.
Definition: cryptlib.h:322
Interface for message encoding method for public key signature schemes.
Definition: pubkey.h:392
Message encoding method for public key encryption.
Definition: pubkey.h:209
PKCS #1 v1.5 Signature Encoding Scheme.
Definition: pkcspad.h:88
PKCS #1 decoration data structure.
Definition: pkcspad.h:35
PKCS #1 v1.5 Encryption Padding Scheme.
Definition: pkcspad.h:24
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.
Crypto++ library namespace.
const char * Pad()
bool
Definition: argnames.h:72
This file contains helper classes/functions for implementing public key algorithms.
Classes for SHA-1 and SHA-2 family of message digests.
Returns a decoding results.
Definition: cryptlib.h:278
Base class for public key encryption standard classes.
Definition: pubkey.h:2274
PKCS #1 version 1.5, for use with RSAES and RSASS .
Definition: pkcspad.h:116
Base class for public key signature standard classes.
Definition: pubkey.h:2279