summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2007-08-13 23:53:09 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2007-08-13 23:53:09 +0000
commitebb56f57edd46175798c2a70b6dd88bd6ce7f877 (patch)
treef096ef9661b273e6059f26284dd133c439a528b4
parent3d0cf61bb4132e0ade13f86a9af16b2702aab524 (diff)
downloadcryptopp-ebb56f57edd46175798c2a70b6dd88bd6ce7f877.tar.gz
fixed Whirlpool crash on Pentium 2 machines
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@385 57ff6487-cd31-0410-9ec3-f628ee90f5f0
-rw-r--r--config.h4
-rwxr-xr-xcpu.cpp15
-rwxr-xr-xcpu.h11
-rw-r--r--validat1.cpp3
-rw-r--r--whrlpool.cpp6
5 files changed, 33 insertions, 6 deletions
diff --git a/config.h b/config.h
index 422cbb5..8baba34 100644
--- a/config.h
+++ b/config.h
@@ -260,7 +260,7 @@ NAMESPACE_END
#define CRYPTOPP_DISABLE_SSE2
#endif
-#if !defined(CRYPTOPP_DISABLE_ASM) && ((defined(CRYPTOPP_MSVC6PP_OR_LATER) && defined(_M_IX86)) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))))
+#if !defined(CRYPTOPP_DISABLE_ASM) && ((defined(_MSC_VER) && defined(_M_IX86)) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))))
#define CRYPTOPP_X86_ASM_AVAILABLE
#if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(CRYPTOPP_MSVC6PP_OR_LATER) || CRYPTOPP_GCC_VERSION >= 30300)
@@ -339,6 +339,8 @@ NAMESPACE_END
#define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
#endif
+#define CRYPTOPP_VERSION 552
+
// ***************** determine availability of OS features ********************
#ifndef NO_OS_DEPENDENCE
diff --git a/cpu.cpp b/cpu.cpp
index 4d8577e..3e46804 100755
--- a/cpu.cpp
+++ b/cpu.cpp
@@ -145,7 +145,7 @@ static bool TrySSE2()
}
bool g_x86DetectionDone = false;
-bool g_hasSSE2 = false, g_hasSSSE3 = false, g_hasMMX = false, g_isP4 = false;
+bool g_hasISSE = false, g_hasSSE2 = false, g_hasSSSE3 = false, g_hasMMX = false, g_isP4 = false;
word32 g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
void DetectX86Features()
@@ -161,6 +161,19 @@ void DetectX86Features()
g_hasSSE2 = TrySSE2();
g_hasSSSE3 = g_hasSSE2 && (cpuid1[2] & (1<<9));
+ if ((cpuid1[3] & (1 << 25)) != 0)
+ g_hasISSE = true;
+ else
+ {
+ word32 cpuid2[4];
+ CpuId(0x080000000, cpuid2);
+ if (cpuid2[0] >= 0x080000001)
+ {
+ CpuId(0x080000001, cpuid2);
+ g_hasISSE = (cpuid2[3] & (1 << 22)) != 0;
+ }
+ }
+
std::swap(cpuid[2], cpuid[3]);
if (memcmp(cpuid+1, "GenuineIntel", 12) == 0)
{
diff --git a/cpu.h b/cpu.h
index 6eae489..bec63fd 100755
--- a/cpu.h
+++ b/cpu.h
@@ -16,6 +16,7 @@ NAMESPACE_BEGIN(CryptoPP)
// these should not be used directly
extern CRYPTOPP_DLL bool g_x86DetectionDone;
extern CRYPTOPP_DLL bool g_hasSSE2;
+extern CRYPTOPP_DLL bool g_hasISSE;
extern CRYPTOPP_DLL bool g_hasMMX;
extern CRYPTOPP_DLL bool g_hasSSSE3;
extern CRYPTOPP_DLL bool g_isP4;
@@ -26,6 +27,7 @@ CRYPTOPP_DLL bool CpuId(word32 input, word32 *output);
#if CRYPTOPP_BOOL_X64
inline bool HasSSE2() {return true;}
+inline bool HasISSE() {return true;}
inline bool HasMMX() {return true;}
#else
@@ -36,6 +38,13 @@ inline bool HasSSE2()
return g_hasSSE2;
}
+inline bool HasISSE()
+{
+ if (!g_x86DetectionDone)
+ DetectX86Features();
+ return g_hasISSE;
+}
+
inline bool HasMMX()
{
if (!g_x86DetectionDone)
@@ -79,9 +88,11 @@ inline bool IsP4() {return false;}
// assume MMX and SSE2 if intrinsics are enabled
#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_X64
inline bool HasSSE2() {return true;}
+inline bool HasISSE() {return true;}
inline bool HasMMX() {return true;}
#else
inline bool HasSSE2() {return false;}
+inline bool HasISSE() {return false;}
inline bool HasMMX() {return false;}
#endif
diff --git a/validat1.cpp b/validat1.cpp
index 616b92c..365fca5 100644
--- a/validat1.cpp
+++ b/validat1.cpp
@@ -229,6 +229,7 @@ bool TestSettings()
cout << endl;
bool hasMMX = HasMMX();
+ bool hasISSE = HasISSE();
bool hasSSE2 = HasSSE2();
bool hasSSSE3 = HasSSSE3();
bool isP4 = IsP4();
@@ -242,7 +243,7 @@ bool TestSettings()
else
cout << "passed: ";
- cout << "hasMMX == " << hasMMX << ", hasSSE2 == " << hasSSE2 << ", hasSSSE3 == " << hasSSSE3 << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize;
+ cout << "hasMMX == " << hasMMX << ", hasISSE == " << hasISSE << ", hasSSE2 == " << hasSSE2 << ", hasSSSE3 == " << hasSSSE3 << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize;
if (!pass)
{
diff --git a/whrlpool.cpp b/whrlpool.cpp
index 20e721e..149be39 100644
--- a/whrlpool.cpp
+++ b/whrlpool.cpp
@@ -1,6 +1,6 @@
// whrlpool.cpp - originally modified by Kevin Springle from
// Paulo Barreto and Vincent Rijmen's public domain code, whirlpool.c.
-// Updated to Whirlpool version 3.0, optimized and MMX version added by Wei Dai
+// Updated to Whirlpool version 3.0, optimized and SSE version added by Wei Dai
// Any modifications are placed in the public domain
// This is the original introductory comment:
@@ -390,8 +390,8 @@ CRYPTOPP_ALIGN_DATA(16) static const word64 Whirlpool_C[4*256+R] CRYPTOPP_SECTIO
// Whirlpool basic transformation. Transforms state based on block.
void Whirlpool::Transform(word64 *digest, const word64 *block)
{
-#if defined(CRYPTOPP_X86_ASM_AVAILABLE)
- if (HasMMX())
+#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE
+ if (HasISSE())
{
// MMX version has the same structure as C version below
#ifdef __GNUC__