diff --git a/dll.cpp b/dll.cpp index c6733afc..bb44ea78 100644 --- a/dll.cpp +++ b/dll.cpp @@ -23,6 +23,8 @@ NAMESPACE_BEGIN(CryptoPP) +// Guarding based on DLL due to Clang, http://github.com/weidai11/cryptopp/issues/300 +#if defined(CRYPTOPP_IS_DLL) template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14}; template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); @@ -44,6 +46,8 @@ template<> const byte EMSA2HashId::id = 0x34; template<> const byte EMSA2HashId::id = 0x36; template<> const byte EMSA2HashId::id = 0x35; +#endif // CRYPTOPP_IS_DLL + NAMESPACE_END #endif diff --git a/emsa2.h b/emsa2.h index d4189206..c7bf22e4 100644 --- a/emsa2.h +++ b/emsa2.h @@ -11,7 +11,7 @@ #include "misc.h" #ifdef CRYPTOPP_IS_DLL -#include "sha.h" +# include "sha.h" #endif NAMESPACE_BEGIN(CryptoPP) @@ -40,13 +40,13 @@ public: // EMSA2HashId can be instantiated with the following classes. class SHA1; -class RIPEMD160; -class RIPEMD128; +class SHA224; class SHA256; class SHA384; class SHA512; +class RIPEMD128; +class RIPEMD160; class Whirlpool; -class SHA224; // end of list #ifdef CRYPTOPP_IS_DLL diff --git a/pkcspad.cpp b/pkcspad.cpp index 7716256f..a45751ff 100644 --- a/pkcspad.cpp +++ b/pkcspad.cpp @@ -6,23 +6,48 @@ #define CRYPTOPP_PKCSPAD_CPP #include "pkcspad.h" +#include "emsa2.h" #include "misc.h" #include "trap.h" NAMESPACE_BEGIN(CryptoPP) -// more in dll.cpp +// More in dll.cpp. Typedef/cast change due to Clang, http://github.com/weidai11/cryptopp/issues/300 template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x02,0x05,0x00,0x04,0x10}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x04,0x10}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x24,0x03,0x02,0x01,0x05,0x00,0x04,0x14}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x29,0x30,0x0D,0x06,0x09,0x2B,0x06,0x01,0x04,0x01,0xDA,0x47,0x0C,0x02,0x05,0x00,0x04,0x18}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); + +// Inclusion based on DLL due to Clang, http://github.com/weidai11/cryptopp/issues/300 +#ifndef CRYPTOPP_IS_DLL +template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14}; +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); + +template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x2d,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04,0x05,0x00,0x04,0x1c}; +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); + +template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20}; +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); + +template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x41,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30}; +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); + +template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x51,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40}; +template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); + +template<> const byte EMSA2HashId::id = 0x33; +template<> const byte EMSA2HashId::id = 0x38; +template<> const byte EMSA2HashId::id = 0x34; +template<> const byte EMSA2HashId::id = 0x36; +template<> const byte EMSA2HashId::id = 0x35; +#endif size_t PKCS_EncryptionPaddingScheme::MaxUnpaddedLength(size_t paddedLength) const { diff --git a/pkcspad.h b/pkcspad.h index a400e988..a31548da 100644 --- a/pkcspad.h +++ b/pkcspad.h @@ -1,7 +1,8 @@ // pkcspad.h - written and placed in the public domain by Wei Dai -//! \headerfile pkcspad.h +//! \file pkcspad.h //! \brief Classes for PKCS padding schemes +//! \details PKCS#1 v1.5, v2.0 and P1363a allow MD2, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, Tiger and RipeMd-160 to be instantiated. #ifndef CRYPTOPP_PKCSPAD_H #define CRYPTOPP_PKCSPAD_H @@ -15,7 +16,9 @@ NAMESPACE_BEGIN(CryptoPP) -//! EME-PKCS1-v1_5 +//! \class PKCS_EncryptionPaddingScheme +//! \brief PKCS#1 v1.5 Encryption Padding Scheme +//! \sa EME-PKCS1-v1_5 class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod { public: @@ -26,6 +29,8 @@ public: DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs ¶meters) const; }; +//! \class PKCS_DigestDecoration +//! \brief PKCS#1 decoration data structure template class PKCS_DigestDecoration { public: @@ -36,12 +41,12 @@ public: // PKCS_DigestDecoration can be instantiated with the following // classes as specified in PKCS#1 v2.0 and P1363a class SHA1; -class RIPEMD160; -class Tiger; class SHA224; class SHA256; class SHA384; class SHA512; +class Tiger; +class RIPEMD160; namespace Weak1 { class MD2; class MD5; @@ -56,7 +61,9 @@ CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; #endif -//! EMSA-PKCS1-v1_5 +//! \class PKCS1v15_SignatureMessageEncodingMethod +//! \brief PKCS#1 v1.5 Signature Encoding Scheme +//! \sa EMSA-PKCS1-v1_5 class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod { public: @@ -76,7 +83,7 @@ public: { static HashIdentifier Lookup() { - return HashIdentifier(PKCS_DigestDecoration::decoration, (size_t)PKCS_DigestDecoration::length); + return HashIdentifier(PKCS_DigestDecoration::decoration, PKCS_DigestDecoration::length); } }; }; diff --git a/pubkey.h b/pubkey.h index a2032612..9a89d388 100644 --- a/pubkey.h +++ b/pubkey.h @@ -327,7 +327,8 @@ public: // ******************************************************** -typedef std::pair HashIdentifier; +// Typedef change due to Clang, http://github.com/weidai11/cryptopp/issues/300 +typedef std::pair HashIdentifier; //! \class PK_SignatureMessageEncodingMethod //! \brief Interface for message encoding method for public key signature schemes.