diff --git a/config.h b/config.h index 291b1488..9d2d38e0 100644 --- a/config.h +++ b/config.h @@ -216,12 +216,6 @@ typedef unsigned int word32; typedef word64 lword; const lword LWORD_MAX = W64LIT(0xffffffffffffffff); -// Clang pretends to be VC++, too. -// See http://github.com/weidai11/cryptopp/issues/147 -#if defined(_MSC_VER) && defined(__clang__) -# error: "Unsupported configuration" -#endif - #ifdef __GNUC__ #define CRYPTOPP_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #endif @@ -335,7 +329,7 @@ NAMESPACE_END #define CRYPTOPP_FASTCALL #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) #define CRYPTOPP_NO_VTABLE __declspec(novtable) #else #define CRYPTOPP_NO_VTABLE diff --git a/filters.cpp b/filters.cpp index 7b0017a6..6568fa17 100644 --- a/filters.cpp +++ b/filters.cpp @@ -745,7 +745,7 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length) if (m_padding == PKCS_PADDING) { byte pad = space[s-1]; - if (pad < 1 || pad > s || std::find_if(space+s-pad, space+s, std::bind2nd(std::not_equal_to(), pad)) != space+s) + if (pad < 1 || pad > s || std::find_if(space+s-pad, space+s, std::bind(std::not_equal_to(), std::placeholders::_1, pad)) != space+s) throw InvalidCiphertext("StreamTransformationFilter: invalid PKCS #7 block padding found"); length = s-pad; } diff --git a/ida.cpp b/ida.cpp index 125ab979..9bc7b3b8 100644 --- a/ida.cpp +++ b/ida.cpp @@ -389,7 +389,7 @@ size_t PaddingRemover::Put2(const byte *begin, size_t length, int messageEnd, bo if (m_possiblePadding) { - size_t len = std::find_if(begin, end, std::bind2nd(std::not_equal_to(), byte(0))) - begin; + size_t len = std::find_if(begin, end, std::bind(std::not_equal_to(), std::placeholders::_1, byte(0))) - begin; m_zeroCount += len; begin += len; if (begin == end) @@ -402,7 +402,7 @@ size_t PaddingRemover::Put2(const byte *begin, size_t length, int messageEnd, bo m_possiblePadding = false; } - const byte *x = std::find_if(RevIt(end), RevIt(begin), std::bind2nd(std::not_equal_to(), byte(0))).base(); + const byte *x = std::find_if(RevIt(end), RevIt(begin), std::bind(std::not_equal_to(), std::placeholders::_1, byte(0))).base(); if (x != begin && *(x-1) == 1) { AttachedTransformation()->Put(begin, x-begin-1); diff --git a/integer.cpp b/integer.cpp index cb38ca29..b7269f20 100644 --- a/integer.cpp +++ b/integer.cpp @@ -238,7 +238,7 @@ static word AtomicInverseModPower2(word A) #define HighWord(a) a##1 #ifdef _MSC_VER #define MultiplyWordsLoHi(p0, p1, a, b) p0 = _umul128(a, b, &p1); - #ifndef __INTEL_COMPILER + #if !defined(__INTEL_COMPILER) && !defined(__clang__) #define Double3Words(c, d) d##1 = __shiftleft128(d##0, d##1, 1); d##0 = __shiftleft128(c, d##0, 1); c *= 2; #endif #elif defined(__DECCXX) diff --git a/oaep.cpp b/oaep.cpp index 08d75a99..0344dffb 100644 --- a/oaep.cpp +++ b/oaep.cpp @@ -82,7 +82,7 @@ DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, size_t oaepBlockLen, byte // DB = pHash' || 00 ... || 01 || M byte *M = std::find(maskedDB+hLen, maskedDB+dbLen, 0x01); invalid = (M == maskedDB+dbLen) || invalid; - invalid = (std::find_if(maskedDB+hLen, M, std::bind2nd(std::not_equal_to(), byte(0))) != M) || invalid; + invalid = (std::find_if(maskedDB+hLen, M, std::bind(std::not_equal_to(), std::placeholders::_1, byte(0))) != M) || invalid; invalid = !pHash->VerifyDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()) || invalid; if (invalid) diff --git a/pssr.cpp b/pssr.cpp index 914b921f..d98d7c3d 100644 --- a/pssr.cpp +++ b/pssr.cpp @@ -125,7 +125,7 @@ DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative( // extract salt and recoverableMessage from DB = 00 ... || 01 || M || salt byte *salt = representative + representativeByteLength - u - digestSize - saltSize; - byte *M = std::find_if(representative, salt-1, std::bind2nd(std::not_equal_to(), byte(0))); + byte *M = std::find_if(representative, salt-1, std::bind(std::not_equal_to(), std::placeholders::_1, byte(0))); recoverableMessageLength = salt-M-1; if (*M == 0x01 && (size_t)(M - representative - (representativeBitLength % 8 != 0)) >= MinPadLen(digestSize) && diff --git a/rdrand.cpp b/rdrand.cpp index b591407d..0b9b5514 100644 --- a/rdrand.cpp +++ b/rdrand.cpp @@ -152,6 +152,14 @@ inline void RDRAND32(void* output) : "=a" (*reinterpret_cast(output)) : : "cc" ); +#elif defined(CRYPTOPP_MSC_VERSION) && defined(CRYPTOPP_LLVM_CLANG_VERSION) + __asm__ __volatile__ + ( + ".byte 0x0f, 0xc7, 0xf0;\n" + ".byte 0x73, 0xfb;\n" + : "=a" (*reinterpret_cast(output)) + : : "cc" + ); #elif defined(ALL_RDRAND_INTRIN_AVAILABLE) while(!_rdrand32_step(reinterpret_cast(output))) {} #else @@ -194,6 +202,14 @@ inline void RDRAND64(void* output) : "=a" (*reinterpret_cast(output)) : : "cc" ); +#elif defined(CRYPTOPP_MSC_VERSION) && defined(CRYPTOPP_LLVM_CLANG_VERSION) + __asm__ __volatile__ + ( + ".byte 0x48, 0x0f, 0xc7, 0xf0;\n" + ".byte 0x73, 0xfa;\n" + : "=a" (*reinterpret_cast(output)) + : : "cc" + ); #elif defined(ALL_RDRAND_INTRIN_AVAILABLE) while(!_rdrand64_step(reinterpret_cast(output))) {} #else @@ -309,6 +325,14 @@ inline void RDSEED32(void* output) : "=a" (*reinterpret_cast(output)) : : "cc" ); +#elif defined(CRYPTOPP_MSC_VERSION) && defined(CRYPTOPP_LLVM_CLANG_VERSION) + __asm__ __volatile__ + ( + ".byte 0x0f, 0xc7, 0xf8;\n" + ".byte 0x73, 0xfb;\n" + : "=a" (*reinterpret_cast(output)) + : : "cc" + ); #elif defined(ALL_RDSEED_INTRIN_AVAILABLE) while(!_rdseed32_step(reinterpret_cast(output))) {} #else @@ -351,6 +375,14 @@ inline void RDSEED64(void* output) : "=a" (*reinterpret_cast(output)) : : "cc" ); +#elif defined(CRYPTOPP_MSC_VERSION) && defined(CRYPTOPP_LLVM_CLANG_VERSION) + __asm__ __volatile__ + ( + ".byte 0x48, 0x0f, 0xc7, 0xf8;\n" + ".byte 0x73, 0xfa;\n" + : "=a" (*reinterpret_cast(output)) + : : "cc" + ); #elif defined(ALL_RDSEED_INTRIN_AVAILABLE) while(!_rdseed64_step(reinterpret_cast(output))) {} #else diff --git a/zdeflate.cpp b/zdeflate.cpp index 24576b9f..31ba9993 100644 --- a/zdeflate.cpp +++ b/zdeflate.cpp @@ -676,11 +676,11 @@ void Deflator::EncodeBlock(bool eof, unsigned int blockType) m_literalCounts[256] = 1; HuffmanEncoder::GenerateCodeLengths(literalCodeLengths, 15, m_literalCounts, 286); m_dynamicLiteralEncoder.Initialize(literalCodeLengths, 286); - unsigned int hlit = (unsigned int)(std::find_if(RevIt(literalCodeLengths.end()), RevIt(literalCodeLengths.begin()+257), std::bind2nd(std::not_equal_to(), 0)).base() - (literalCodeLengths.begin()+257)); + unsigned int hlit = (unsigned int)(std::find_if(RevIt(literalCodeLengths.end()), RevIt(literalCodeLengths.begin()+257), std::bind(std::not_equal_to(), std::placeholders::_1, 0)).base() - (literalCodeLengths.begin()+257)); HuffmanEncoder::GenerateCodeLengths(distanceCodeLengths, 15, m_distanceCounts, 30); m_dynamicDistanceEncoder.Initialize(distanceCodeLengths, 30); - unsigned int hdist = (unsigned int)(std::find_if(RevIt(distanceCodeLengths.end()), RevIt(distanceCodeLengths.begin()+1), std::bind2nd(std::not_equal_to(), 0)).base() - (distanceCodeLengths.begin()+1)); + unsigned int hdist = (unsigned int)(std::find_if(RevIt(distanceCodeLengths.end()), RevIt(distanceCodeLengths.begin()+1), std::bind(std::not_equal_to(), std::placeholders::_1, 0)).base() - (distanceCodeLengths.begin()+1)); SecBlockWithHint combinedLengths(hlit+257+hdist+1); memcpy(combinedLengths, literalCodeLengths, (hlit+257)*sizeof(unsigned int));