Crypto++
|
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 ¶meters) const; 00021 DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) 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 RIPEMD160; 00035 class Tiger; 00036 class SHA224; 00037 class SHA256; 00038 class SHA384; 00039 class SHA512; 00040 namespace Weak1 { 00041 class MD2; 00042 class MD5; 00043 } 00044 // end of list 00045 00046 #ifdef CRYPTOPP_IS_DLL 00047 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>; 00048 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>; 00049 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>; 00050 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>; 00051 CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>; 00052 #endif 00053 00054 //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a> 00055 class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod 00056 { 00057 public: 00058 static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";} 00059 00060 size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const 00061 {return 8 * (digestSize + hashIdentifierSize + 10);} 00062 00063 void ComputeMessageRepresentative(RandomNumberGenerator &rng, 00064 const byte *recoverableMessage, size_t recoverableMessageLength, 00065 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 00066 byte *representative, size_t representativeBitLength) const; 00067 00068 struct HashIdentifierLookup 00069 { 00070 template <class H> struct HashIdentifierLookup2 00071 { 00072 static HashIdentifier Lookup() 00073 { 00074 return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::length); 00075 } 00076 }; 00077 }; 00078 }; 00079 00080 //! PKCS #1 version 1.5, for use with RSAES and RSASS 00081 /*! Only the following hash functions are supported by this signature standard: 00082 \dontinclude pkcspad.h 00083 \skip can be instantiated 00084 \until end of list 00085 */ 00086 struct PKCS1v15 : public SignatureStandard, public EncryptionStandard 00087 { 00088 typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod; 00089 typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod; 00090 }; 00091 00092 NAMESPACE_END 00093 00094 #endif