pkcspad.h

00001 #ifndef CRYPTOPP_PKCSPAD_H
00002 #define CRYPTOPP_PKCSPAD_H
00003 
00004 #include "cryptlib.h"
00005 #include "pubkey.h"
00006 
00007 #ifdef CRYPTOPP_IS_DLL
00008 #include "sha.h"
00009 #endif
00010 
00011 NAMESPACE_BEGIN(CryptoPP)
00012 
00013 //! <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a>
00014 class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod
00015 {
00016 public:
00017         static const char * StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
00018 
00019         size_t MaxUnpaddedLength(size_t paddedLength) const;
00020         void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
00021         DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs &parameters) const;
00022 };
00023 
00024 template <class H> class PKCS_DigestDecoration
00025 {
00026 public:
00027         static const byte decoration[];
00028         static const unsigned int length;
00029 };
00030 
00031 // PKCS_DigestDecoration can be instantiated with the following
00032 // classes as specified in PKCS#1 v2.0 and P1363a
00033 class SHA1;
00034 class MD2;
00035 class MD5;
00036 class RIPEMD160;
00037 class Tiger;
00038 class SHA224;
00039 class SHA256;
00040 class SHA384;
00041 class SHA512;
00042 // end of list
00043 
00044 #ifdef CRYPTOPP_IS_DLL
00045 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>;
00046 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>;
00047 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>;
00048 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>;
00049 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>;
00050 #endif
00051 
00052 //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a>
00053 class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod
00054 {
00055 public:
00056         static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
00057 
00058         size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
00059                 {return 8 * (digestSize + hashIdentifierSize + 10);}
00060 
00061         void ComputeMessageRepresentative(RandomNumberGenerator &rng, 
00062                 const byte *recoverableMessage, size_t recoverableMessageLength,
00063                 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
00064                 byte *representative, size_t representativeBitLength) const;
00065 
00066         struct HashIdentifierLookup
00067         {
00068                 template <class H> struct HashIdentifierLookup2
00069                 {
00070                         static HashIdentifier Lookup()
00071                         {
00072                                 return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::length);
00073                         }
00074                 };
00075         };
00076 };
00077 
00078 //! PKCS #1 version 1.5, for use with RSAES and RSASS
00079 /*! Only the following hash functions are supported by this signature standard:
00080         \dontinclude pkcspad.h
00081         \skip can be instantiated
00082         \until end of list
00083 */
00084 struct PKCS1v15 : public SignatureStandard, public EncryptionStandard
00085 {
00086         typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod;
00087         typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod;
00088 };
00089 
00090 NAMESPACE_END
00091 
00092 #endif

Generated on Sat Dec 23 02:07:09 2006 for Crypto++ by  doxygen 1.5.1-p1