~ubuntu-branches/debian/squeeze/pycryptopp/squeeze

« back to all changes in this revision

Viewing changes to cryptopp/pkcspad.h

  • Committer: Bazaar Package Importer
  • Author(s): Zooko O'Whielacronx
  • Date: 2009-06-22 22:20:50 UTC
  • Revision ID: james.westby@ubuntu.com-20090622222050-hbqmn50dt2kvoz5o
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef CRYPTOPP_PKCSPAD_H
 
2
#define CRYPTOPP_PKCSPAD_H
 
3
 
 
4
#include "cryptlib.h"
 
5
#include "pubkey.h"
 
6
 
 
7
#ifdef CRYPTOPP_IS_DLL
 
8
#include "sha.h"
 
9
#endif
 
10
 
 
11
NAMESPACE_BEGIN(CryptoPP)
 
12
 
 
13
//! <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a>
 
14
class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod
 
15
{
 
16
public:
 
17
        static const char * StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
 
18
 
 
19
        size_t MaxUnpaddedLength(size_t paddedLength) const;
 
20
        void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
 
21
        DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs &parameters) const;
 
22
};
 
23
 
 
24
template <class H> class PKCS_DigestDecoration
 
25
{
 
26
public:
 
27
        static const byte decoration[];
 
28
        static const unsigned int length;
 
29
};
 
30
 
 
31
// PKCS_DigestDecoration can be instantiated with the following
 
32
// classes as specified in PKCS#1 v2.0 and P1363a
 
33
class SHA1;
 
34
class RIPEMD160;
 
35
class Tiger;
 
36
class SHA224;
 
37
class SHA256;
 
38
class SHA384;
 
39
class SHA512;
 
40
namespace Weak1 {
 
41
class MD2;
 
42
class MD5;
 
43
}
 
44
// end of list
 
45
 
 
46
#ifdef CRYPTOPP_IS_DLL
 
47
CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>;
 
48
CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>;
 
49
CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>;
 
50
CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>;
 
51
CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>;
 
52
#endif
 
53
 
 
54
//! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a>
 
55
class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod
 
56
{
 
57
public:
 
58
        static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
 
59
 
 
60
        size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
 
61
                {return 8 * (digestSize + hashIdentifierSize + 10);}
 
62
 
 
63
        void ComputeMessageRepresentative(RandomNumberGenerator &rng, 
 
64
                const byte *recoverableMessage, size_t recoverableMessageLength,
 
65
                HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
 
66
                byte *representative, size_t representativeBitLength) const;
 
67
 
 
68
        struct HashIdentifierLookup
 
69
        {
 
70
                template <class H> struct HashIdentifierLookup2
 
71
                {
 
72
                        static HashIdentifier Lookup()
 
73
                        {
 
74
                                return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::length);
 
75
                        }
 
76
                };
 
77
        };
 
78
};
 
79
 
 
80
//! PKCS #1 version 1.5, for use with RSAES and RSASS
 
81
/*! Only the following hash functions are supported by this signature standard:
 
82
        \dontinclude pkcspad.h
 
83
        \skip can be instantiated
 
84
        \until end of list
 
85
*/
 
86
struct PKCS1v15 : public SignatureStandard, public EncryptionStandard
 
87
{
 
88
        typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod;
 
89
        typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod;
 
90
};
 
91
 
 
92
NAMESPACE_END
 
93
 
 
94
#endif