From 4232cfd40b692da38a3c3098af801d16ebb26852 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 25 Dec 2017 22:27:53 -0500 Subject: [PATCH] Fix failed self test under Clang (GH #533) This may cause GH #300, "Clang 3.9 and missing member definitions for template classes" or GH #294, "Fix clang warnings about undefined variable templates in pkcspad.h" to resurface. Man I hope not... --- Filelist.txt | 1 + cryptlib.cpp | 2 +- emsa2.h | 11 ++--------- pkcspad.cpp | 3 ++- pkcspad.h | 30 ++++-------------------------- pssr.cpp | 4 +++- 6 files changed, 13 insertions(+), 38 deletions(-) diff --git a/Filelist.txt b/Filelist.txt index 329f1104..dca7df64 100644 --- a/Filelist.txt +++ b/Filelist.txt @@ -136,6 +136,7 @@ gost.cpp gost.h gzip.cpp gzip.h +hashfwd.h hex.cpp hex.h hkdf.h diff --git a/cryptlib.cpp b/cryptlib.cpp index ddc829db..fbe5687a 100644 --- a/cryptlib.cpp +++ b/cryptlib.cpp @@ -148,7 +148,7 @@ size_t BlockTransformation::AdvancedProcessBlocks(const byte *inBlocks, const by CRYPTOPP_ASSERT(outBlocks); CRYPTOPP_ASSERT(length); - const ptrdiff_t blockSize = static_cast(BlockSize()); + const size_t blockSize = BlockSize(); ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize; ptrdiff_t xorIncrement = xorBlocks ? blockSize : 0; ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize; diff --git a/emsa2.h b/emsa2.h index e41ee45f..3a9efb07 100644 --- a/emsa2.h +++ b/emsa2.h @@ -8,6 +8,7 @@ #include "cryptlib.h" #include "pubkey.h" +#include "hashfwd.h" #include "misc.h" #ifdef CRYPTOPP_IS_DLL @@ -47,15 +48,7 @@ public: }; // EMSA2HashId can be instantiated with the following classes. -class SHA1; -class SHA224; -class SHA256; -class SHA384; -class SHA512; -class RIPEMD128; -class RIPEMD160; -class Whirlpool; -// end of list +// SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD128, RIPEMD160, Whirlpool #ifdef CRYPTOPP_IS_DLL CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId; diff --git a/pkcspad.cpp b/pkcspad.cpp index d7204c54..6a792d2f 100644 --- a/pkcspad.cpp +++ b/pkcspad.cpp @@ -7,12 +7,13 @@ #include "pkcspad.h" #include "emsa2.h" +#include "hashfwd.h" #include "misc.h" #include "trap.h" NAMESPACE_BEGIN(CryptoPP) -// More in dll.cpp. Typedef/cast change due to Clang, http://github.com/weidai11/cryptopp/issues/300 +// 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 = (unsigned int)sizeof(PKCS_DigestDecoration::decoration); diff --git a/pkcspad.h b/pkcspad.h index e885995d..6425e395 100644 --- a/pkcspad.h +++ b/pkcspad.h @@ -2,13 +2,15 @@ /// \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. +/// \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 #include "cryptlib.h" #include "pubkey.h" +#include "hashfwd.h" #ifdef CRYPTOPP_IS_DLL #include "sha.h" @@ -40,24 +42,7 @@ public: // PKCS_DigestDecoration can be instantiated with the following // classes as specified in PKCS #1 v2.0 and P1363a -class SHA1; -class SHA224; -class SHA256; -class SHA384; -class SHA512; -class Tiger; -class RIPEMD160; - -namespace Weak1 { - class MD2; - class MD5; -} - -// http://github.com/weidai11/cryptopp/issues/517 -class SHA3_256; -class SHA3_384; -class SHA3_512; -// end of list +// SHA1, SHA224, SHA256, SHA384, SHA512, Tiger, RIPEMD160, MD2, MD5 #if defined(CRYPTOPP_IS_DLL) CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; @@ -69,13 +54,6 @@ CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration; -#elif defined(__clang__) -// Provide a default definition to avoid Clang warnings. CRTP will provide a -// real definition later. The single element is due to MSVC compile failures -// after adding the default definition. However, GCC produces multiple -// definitions which result in link failures. I give up... -template -const byte PKCS_DigestDecoration::decoration[1] = {0x00}; #endif /// \class PKCS1v15_SignatureMessageEncodingMethod diff --git a/pssr.cpp b/pssr.cpp index 914b921f..b8863fce 100644 --- a/pssr.cpp +++ b/pssr.cpp @@ -2,13 +2,15 @@ #include "pch.h" #include "pssr.h" +#include "emsa2.h" +#include "ripemd.h" +#include "whrlpool.h" #include "misc.h" #include NAMESPACE_BEGIN(CryptoPP) -// more in dll.cpp template<> const byte EMSA2HashId::id = 0x31; template<> const byte EMSA2HashId::id = 0x32; template<> const byte EMSA2HashId::id = 0x37;