summaryrefslogtreecommitdiff
path: root/sha.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2016-12-01 23:35:13 -0500
committerJeffrey Walton <noloader@gmail.com>2016-12-01 23:35:13 -0500
commitc8b910aff5dbce3536a0535818bfa242432514e3 (patch)
tree558f3cf6fdc08a1d5bf42007b60265e61c3d1021 /sha.cpp
parent406bec8fc7b8825f974a36ddea91e16b00d66f62 (diff)
downloadcryptopp-git-c8b910aff5dbce3536a0535818bfa242432514e3.tar.gz
Backed-off automatically setting CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE due to bad interaction with '-march=x86-64'. Disgorge SSE2 implementation from CXX implementation
Diffstat (limited to 'sha.cpp')
-rw-r--r--sha.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/sha.cpp b/sha.cpp
index 1b75194a..c8a770ac 100644
--- a/sha.cpp
+++ b/sha.cpp
@@ -750,12 +750,11 @@ size_t SHA224::HashMultipleBlocks(const word32 *input, size_t length)
#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3))
#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10))
-// Smaller but slower
#if defined(__OPTIMIZE_SIZE__)
+// Smaller but slower
void SHA256_CXX_Transform(word32 *state, const word32 *data)
{
- word32 T[20];
- word32 W[32];
+ word32 W[32], T[20];
unsigned int i = 0, j = 0;
word32 *t = T+8;
@@ -824,15 +823,10 @@ void SHA256_CXX_Transform(word32 *state, const word32 *data)
state[7] += t[7];
}
#else
+// Bigger but faster
void SHA256_CXX_Transform(word32 *state, const word32 *data)
{
- word32 W[16];
-#if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
- // this byte reverse is a waste of time, but this function is only called by MDC
- ByteReverse(W, data, SHA256::BLOCKSIZE);
- X86_SHA256_HashBlocks(state, W, SHA256::BLOCKSIZE - !HasSSE2());
-#else
- word32 T[8];
+ word32 W[16], T[8];
/* Copy context->state[] to working vars */
memcpy(T, state, sizeof(T));
/* 64 operations, partially loop unrolled */
@@ -852,9 +846,8 @@ void SHA256_CXX_Transform(word32 *state, const word32 *data)
state[5] += f(0);
state[6] += g(0);
state[7] += h(0);
-#endif
}
-#endif
+#endif // __OPTIMIZE_SIZE__
#undef S0
#undef S1
@@ -862,16 +855,28 @@ void SHA256_CXX_Transform(word32 *state, const word32 *data)
#undef s1
#undef R
+#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE
+static void SHA256_SSE2_Transform(word32 *state, const word32 *data)
+{
+ // this byte reverse is a waste of time, but this function is only called by MDC
+ word32 W[16];
+ ByteReverse(W, data, SHA256::BLOCKSIZE);
+ X86_SHA256_HashBlocks(state, W, SHA256::BLOCKSIZE - !HasSSE2());
+}
+#endif // CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE
+
#if CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE
static void SHA256_SSE_SHA_Transform(word32 *state, const word32 *data)
{
return SHA256_SSE_SHA_HashBlocks(state, data, SHA256::BLOCKSIZE);
}
+#endif // CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE
///////////////////////////////////
// start of Walton/Gulley's code //
///////////////////////////////////
+#if CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE
// Based on http://software.intel.com/en-us/articles/intel-sha-extensions and code by Sean Gulley.
static void SHA256_SSE_SHA_HashBlocks(word32 *state, const word32 *data, size_t length)
{
@@ -1081,6 +1086,11 @@ pfnSHATransform InitializeSHA256Transform()
return &SHA256_SSE_SHA_Transform;
else
#endif
+#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE
+ if (HasSSE2())
+ return &SHA256_SSE2_Transform;
+ else
+#endif
return &SHA256_CXX_Transform;
}