From d6b4e54448ea4c6aa729474d7b3ecd0c757fbc68 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 13 Mar 2009 02:55:23 +0000 Subject: [PATCH] fix compile on MSVC 6 --- config.h | 6 ++++++ datatest.cpp | 2 +- secblock.h | 14 +++++++------- sha.cpp | 14 ++++++++++++-- sha.h | 4 ++-- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/config.h b/config.h index 838d5a94..485b8d09 100644 --- a/config.h +++ b/config.h @@ -287,6 +287,12 @@ NAMESPACE_END #define CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 0 #endif +#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) + #define CRYPTOPP_BOOL_ALIGN16_ENABLED 1 +#else + #define CRYPTOPP_BOOL_ALIGN16_ENABLED 0 +#endif + // how to allocate 16-byte aligned memory (for SSE2) #if defined(CRYPTOPP_MSVC6PP_OR_LATER) #define CRYPTOPP_MM_MALLOC_AVAILABLE diff --git a/datatest.cpp b/datatest.cpp index 6f40923a..d23d5d92 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -308,7 +308,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters) if (test == "Encrypt" || test == "EncryptXorDigest" || test == "Resync") { - static std::auto_ptr encryptor, decryptor; + static member_ptr encryptor, decryptor; static std::string lastName; if (name != lastName) diff --git a/secblock.h b/secblock.h index 481533c2..d66470e9 100644 --- a/secblock.h +++ b/secblock.h @@ -98,7 +98,7 @@ public: if (n == 0) return NULL; - if (T_Align16 && n*sizeof(T) >= 16) + if (CRYPTOPP_BOOL_ALIGN16_ENABLED && T_Align16 && n*sizeof(T) >= 16) { byte *p; #ifdef CRYPTOPP_MM_MALLOC_AVAILABLE @@ -132,7 +132,7 @@ public: { memset_z(p, 0, n*sizeof(T)); - if (T_Align16 && n*sizeof(T) >= 16) + if (CRYPTOPP_BOOL_ALIGN16_ENABLED && T_Align16 && n*sizeof(T) >= 16) { #ifdef CRYPTOPP_MM_MALLOC_AVAILABLE _mm_free(p); @@ -262,8 +262,8 @@ private: T* GetAlignedArray() {return m_array;} T m_array[S]; #else - T* GetAlignedArray() {return T_Align16 ? (T*)(((byte *)m_array) + (0-(size_t)m_array)%16) : m_array;} - CRYPTOPP_ALIGN_DATA(8) T m_array[T_Align16 ? S+8/sizeof(T) : S]; + T* GetAlignedArray() {return (CRYPTOPP_BOOL_ALIGN16_ENABLED && T_Align16) ? (T*)(((byte *)m_array) + (0-(size_t)m_array)%16) : m_array;} + CRYPTOPP_ALIGN_DATA(8) T m_array[(CRYPTOPP_BOOL_ALIGN16_ENABLED && T_Align16) ? S+8/sizeof(T) : S]; #endif A m_fallbackAllocator; bool m_allocated; @@ -401,7 +401,7 @@ public: void CleanNew(size_type newSize) { New(newSize); - memset(m_ptr, 0, m_size*sizeof(T)); + memset_z(m_ptr, 0, m_size*sizeof(T)); } //! change size only if newSize > current size. contents are preserved @@ -447,7 +447,7 @@ public: }; typedef SecBlock SecByteBlock; -typedef SecBlock > AlignedSecByteBlock; +typedef SecBlock > AlignedSecByteBlock; typedef SecBlock SecWordBlock; //! a SecBlock with fixed size, allocated statically @@ -458,7 +458,7 @@ public: explicit FixedSizeSecBlock() : SecBlock(S) {} }; -template +template class FixedSizeAlignedSecBlock : public FixedSizeSecBlock, T_Align16> > { }; diff --git a/sha.cpp b/sha.cpp index 945ad390..b125127b 100644 --- a/sha.cpp +++ b/sha.cpp @@ -272,16 +272,19 @@ static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 AS2( mov DATA_END, WORD_REG(di)) AS2( mov K_END, WORD_REG(si)) +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE #if CRYPTOPP_BOOL_X86 AS2( test edi, 1) ASJ( jnz, 2, f) #endif - AS2( movdqa xmm0, XMMWORD_PTR [WORD_REG(cx)+0*16]) AS2( movdqa xmm1, XMMWORD_PTR [WORD_REG(cx)+1*16]) +#endif #if CRYPTOPP_BOOL_X86 +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE ASJ( jmp, 0, f) +#endif ASL(2) // non-SSE2 AS2( mov esi, ecx) AS2( lea edi, A(0)) @@ -291,9 +294,11 @@ static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 ASJ( jmp, 3, f) #endif +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE ASL(0) AS2( movdqa E(0), xmm1) AS2( movdqa A(0), xmm0) +#endif #if CRYPTOPP_BOOL_X86 ASL(3) #endif @@ -352,11 +357,11 @@ static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 AS2( mov AS_REG_7, STATE_SAVE) AS2( mov DATA_SAVE, WORD_REG(dx)) +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE #if CRYPTOPP_BOOL_X86 AS2( test DWORD PTR DATA_END, 1) ASJ( jnz, 4, f) #endif - AS2( movdqa xmm1, XMMWORD_PTR [AS_REG_7+1*16]) AS2( movdqa xmm0, XMMWORD_PTR [AS_REG_7+0*16]) AS2( paddd xmm1, E(0)) @@ -365,10 +370,13 @@ static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 AS2( movdqa [AS_REG_7+0*16], xmm0) AS2( cmp WORD_REG(dx), DATA_END) ASJ( jl, 0, b) +#endif #if CRYPTOPP_BOOL_X86 +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE ASJ( jmp, 5, f) ASL(4) // non-SSE2 +#endif AS2( add [AS_REG_7+0*4], ecx) // A AS2( add [AS_REG_7+4*4], edi) // E AS2( mov eax, B(0)) @@ -386,7 +394,9 @@ static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 AS2( mov ecx, AS_REG_7d) AS2( cmp WORD_REG(dx), DATA_END) ASJ( jl, 2, b) +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE ASL(5) +#endif #endif AS_POP_IF86(sp) diff --git a/sha.h b/sha.h index ff580f6a..679081e8 100644 --- a/sha.h +++ b/sha.h @@ -17,7 +17,7 @@ public: typedef SHA1 SHA; // for backwards compatibility //! implements the SHA-256 standard -class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform +class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform { public: #if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE) @@ -29,7 +29,7 @@ public: }; //! implements the SHA-224 standard -class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform +class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform { public: #if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)