source: git/src-cryptopp/pkcspad.h

Last change on this file was e230cb0, checked in by David Stainton <dstainton415@…>, at 2016-10-12T13:27:29Z

Add cryptopp from tag CRYPTOPP_5_6_5

  • Property mode set to 100644
File size: 3.5 KB
Line 
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
17NAMESPACE_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>
22class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod
23{
24public:
25        CRYPTOPP_CONSTEXPR static 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
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
43class SHA1;
44class SHA224;
45class SHA256;
46class SHA384;
47class SHA512;
48class Tiger;
49class RIPEMD160;
50namespace Weak1 {
51class MD2;
52class MD5;
53}
54// end of list
55
56#ifdef CRYPTOPP_IS_DLL
57CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>;
58CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>;
59CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>;
60CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>;
61CRYPTOPP_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>
67class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod
68{
69public:
70        CRYPTOPP_CONSTEXPR static 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
80        struct HashIdentifierLookup
81        {
82                template <class H> struct HashIdentifierLookup2
83                {
84                        static HashIdentifier Lookup()
85                        {
86                                return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::length);
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*/
98struct PKCS1v15 : public SignatureStandard, public EncryptionStandard
99{
100        typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod;
101        typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod;
102};
103
104NAMESPACE_END
105
106#endif
Note: See TracBrowser for help on using the repository browser.