Crypto++  5.6.5
Free C++ class library of cryptographic schemes
pkcspad.h
Go to the documentation of this file.
1 // pkcspad.h - 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, SHA512, Tiger and RipeMd-160 to be instantiated.
6 
7 #ifndef CRYPTOPP_PKCSPAD_H
8 #define CRYPTOPP_PKCSPAD_H
9 
10 #include "cryptlib.h"
11 #include "pubkey.h"
12 
13 #ifdef CRYPTOPP_IS_DLL
14 #include "sha.h"
15 #endif
16 
17 NAMESPACE_BEGIN(CryptoPP)
18 
19 //! \class PKCS_EncryptionPaddingScheme
20 //! \brief PKCS#1 v1.5 Encryption Padding Scheme
21 //! \sa <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a>
23 {
24 public:
25  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
26 
27  size_t MaxUnpaddedLength(size_t paddedLength) const;
28  void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
29  DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs &parameters) const;
30 };
31 
32 //! \class PKCS_DigestDecoration
33 //! \brief PKCS#1 decoration data structure
34 template <class H> class PKCS_DigestDecoration
35 {
36 public:
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 class SHA1;
44 class SHA224;
45 class SHA256;
46 class SHA384;
47 class SHA512;
48 class Tiger;
49 class RIPEMD160;
50 namespace Weak1 {
51 class MD2;
52 class MD5;
53 }
54 // end of list
55 
56 #ifdef CRYPTOPP_IS_DLL
57 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>;
58 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>;
59 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>;
60 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>;
61 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>;
62 #endif
63 
64 //! \class PKCS1v15_SignatureMessageEncodingMethod
65 //! \brief PKCS#1 v1.5 Signature Encoding Scheme
66 //! \sa <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a>
68 {
69 public:
70  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
71 
72  size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
73  {return 8 * (digestSize + hashIdentifierSize + 10);}
74 
75  void ComputeMessageRepresentative(RandomNumberGenerator &rng,
76  const byte *recoverableMessage, size_t recoverableMessageLength,
77  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
78  byte *representative, size_t representativeBitLength) const;
79 
81  {
82  template <class H> struct HashIdentifierLookup2
83  {
84  static HashIdentifier Lookup()
85  {
87  }
88  };
89  };
90 };
91 
92 //! PKCS #1 version 1.5, for use with RSAES and RSASS
93 /*! Only the following hash functions are supported by this signature standard:
94  \dontinclude pkcspad.h
95  \skip can be instantiated
96  \until end of list
97 */
99 {
102 };
103 
104 NAMESPACE_END
105 
106 #endif
SHA-384 message digest.
Definition: sha.h:81
SHA-256 message digest.
Definition: sha.h:39
This file contains helper classes/functions for implementing public key algorithms.
Tiger
Definition: tiger.h:16
Abstract base classes that provide a uniform interface to this library.
RIPEMD-160 message digest.
Definition: ripemd.h:17
Message encoding method for public key encryption.
Definition: pubkey.h:214
Interface for random number generators.
Definition: cryptlib.h:1188
Base class for public key signature standard classes.
Definition: pubkey.h:2036
PKCS#1 v1.5 Encryption Padding Scheme.
Definition: pkcspad.h:22
Returns a decoding results.
Definition: cryptlib.h:238
Interface for message encoding method for public key signature schemes.
Definition: pubkey.h:398
SHA-512 message digest.
Definition: sha.h:69
PKCS #1 version 1.5, for use with RSAES and RSASS.
Definition: pkcspad.h:98
Base class for public key encryption standard classes.
Definition: pubkey.h:2031
SHA-1 message digest.
Definition: sha.h:25
PKCS#1 v1.5 Signature Encoding Scheme.
Definition: pkcspad.h:67
Classes for SHA-1 and SHA-2 family of message digests.
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:930
PKCS#1 decoration data structure.
Definition: pkcspad.h:34
Crypto++ library namespace.
SHA-224 message digest.
Definition: sha.h:54
Interface for retrieving values given their names.
Definition: cryptlib.h:279