From b7133e7b3b25ad15810ec90911b0bd01a2ff5ad6 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 26 Dec 2017 00:46:50 -0500 Subject: [PATCH] Fix Clang specialization and definition warnings (GH #300, GH #533) Clang 3.8 and above generates lots of "'PKCS_DigestDecoration::decoration' required here, but no definition is available" warnings --- emsa2.cpp | 9 +++++++++ emsa2.h | 10 ++++++++++ pkcspad.cpp | 6 ------ pkcspad.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/emsa2.cpp b/emsa2.cpp index 1cde59c5..dd5173dd 100644 --- a/emsa2.cpp +++ b/emsa2.cpp @@ -7,6 +7,15 @@ NAMESPACE_BEGIN(CryptoPP) +// Inclusion based on DLL due to Clang, http://github.com/weidai11/cryptopp/issues/300 +#ifndef CRYPTOPP_IS_DLL +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 + void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator& /*rng*/, const byte* recoverableMessage, size_t recoverableMessageLength, HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, diff --git a/emsa2.h b/emsa2.h index 3a9efb07..8dc5da20 100644 --- a/emsa2.h +++ b/emsa2.h @@ -58,6 +58,16 @@ CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; #endif +// https://github.com/weidai11/cryptopp/issues/300 and +// https://github.com/weidai11/cryptopp/issues/533 +#if defined(__clang__) +template<> const byte EMSA2HashId::id; +template<> const byte EMSA2HashId::id; +template<> const byte EMSA2HashId::id; +template<> const byte EMSA2HashId::id; +template<> const byte EMSA2HashId::id; +#endif + /// \class EMSA2Pad /// \brief EMSA2 padding method /// \since Crypto++ 5.0 diff --git a/pkcspad.cpp b/pkcspad.cpp index 6a792d2f..5192c109 100644 --- a/pkcspad.cpp +++ b/pkcspad.cpp @@ -53,12 +53,6 @@ template<> const unsigned int PKCS_DigestDecoration::length = (unsigne template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x51,0x30,0x0d, 0x06,0x09,0x60,0x86, 0x48,0x01,0x65,0x03, 0x04,0x02,0x0a,0x05, 0x00,0x04,0x40}; template<> const unsigned int PKCS_DigestDecoration::length = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte EMSA2HashId< SHA1>::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 6425e395..3bdb18ff 100644 --- a/pkcspad.h +++ b/pkcspad.h @@ -56,6 +56,34 @@ CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; #endif +// https://github.com/weidai11/cryptopp/issues/300 and +// https://github.com/weidai11/cryptopp/issues/533 +#if defined(__clang__) +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; + +// http://github.com/weidai11/cryptopp/issues/517 +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; + +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +template<> const byte PKCS_DigestDecoration::decoration[]; +template<> const unsigned int PKCS_DigestDecoration::length; +#endif + /// \class PKCS1v15_SignatureMessageEncodingMethod /// \brief PKCS #1 v1.5 Signature Encoding Scheme /// \sa EMSA-PKCS1-v1_5