VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Crypto/Sha2Intel.c60
-rw-r--r--src/Crypto/cpu.c57
2 files changed, 61 insertions, 56 deletions
diff --git a/src/Crypto/Sha2Intel.c b/src/Crypto/Sha2Intel.c
index c926f76a..943115bf 100644
--- a/src/Crypto/Sha2Intel.c
+++ b/src/Crypto/Sha2Intel.c
@@ -21,6 +21,66 @@
#if CRYPTOPP_SHANI_AVAILABLE
+#ifndef _MSC_VER
+#include <signal.h>
+#include <setjmp.h>
+
+typedef void (*SigHandler)(int);
+
+static jmp_buf s_jmpNoSHA;
+static void SigIllHandlerSHA(int p)
+{
+ longjmp(s_jmpNoSHA, 1);
+}
+#endif
+
+int TrySHA256()
+{
+ volatile int result = 0;
+#ifdef _MSC_VER
+ __try
+#else
+ SigHandler oldHandler = signal(SIGILL, SigIllHandlerSHA);
+ if (oldHandler == SIG_ERR)
+ return 0;
+ if (setjmp(s_jmpNoSHA))
+ result = 0;
+ else
+#endif
+ {
+ // Known input message block
+ __m128i msg0 = _mm_setr_epi32(0x12345678, 0x9ABCDEF0, 0x87654321, 0x0FEDCBA9);
+ __m128i msg1 = _mm_setr_epi32(0x11111111, 0x22222222, 0x33333333, 0x44444444);
+
+ // SHA256 message schedule update
+ __m128i tmp = _mm_sha256msg1_epu32(msg0, msg1);
+
+ // Verify result - these values were pre-computed for the given input
+#ifdef _MSC_VER
+ if (tmp.m128i_u32[0] == 0xD8131B44 &&
+ tmp.m128i_u32[1] == 0x9DE6E22B &&
+ tmp.m128i_u32[2] == 0xA86D643A &&
+ tmp.m128i_u32[3] == 0x74320FED)
+#else
+ if (((uint32_t*)(&tmp))[0] == 0xD8131B44 &&
+ ((uint32_t*)(&tmp))[1] == 0x9DE6E22B &&
+ ((uint32_t*)(&tmp))[2] == 0xA86D643A &&
+ ((uint32_t*)(&tmp))[3] == 0x74320FED)
+#endif
+ result = 1;
+ }
+#ifdef _MSC_VER
+ __except (EXCEPTION_EXECUTE_HANDLER)
+ {
+ // ignore error if SHA instructions not supported
+ }
+#else
+ signal(SIGILL, oldHandler);
+#endif
+
+ return result;
+}
+
//
void sha256_intel(void *mp, uint_32t state[8], uint_64t num_blks)
{
diff --git a/src/Crypto/cpu.c b/src/Crypto/cpu.c
index c00d8409..30263361 100644
--- a/src/Crypto/cpu.c
+++ b/src/Crypto/cpu.c
@@ -55,16 +55,6 @@ static void SigIllHandlerAESNI(int p)
#endif
-#if !defined (_UEFI) && (defined(__SHA__) || defined(__INTEL_COMPILER) || CRYPTOPP_SHANI_AVAILABLE)
-
-static jmp_buf s_jmpNoSHA;
-static void SigIllHandlerSHA(int p)
-{
- longjmp(s_jmpNoSHA, 1);
-}
-
-#endif
-
#if CRYPTOPP_BOOL_X64 == 0
static jmp_buf s_jmpNoSSE2;
static void SigIllHandlerSSE2(int p)
@@ -322,52 +312,7 @@ static int Detect_MS_HyperV_AES ()
#endif
#if defined(__SHA__) || defined(__INTEL_COMPILER) || CRYPTOPP_SHANI_AVAILABLE
-static int TrySHA256()
-{
- volatile int result = 0;
-#ifdef _MSC_VER
- __try
-#else
- SigHandler oldHandler = signal(SIGILL, SigIllHandlerSHA);
- if (oldHandler == SIG_ERR)
- return 0;
- if (setjmp(s_jmpNoSHA))
- result = 0;
- else
-#endif
- {
- // Known input message block
- __m128i msg0 = _mm_setr_epi32(0x12345678, 0x9ABCDEF0, 0x87654321, 0x0FEDCBA9);
- __m128i msg1 = _mm_setr_epi32(0x11111111, 0x22222222, 0x33333333, 0x44444444);
-
- // SHA256 message schedule update
- __m128i tmp = _mm_sha256msg1_epu32(msg0, msg1);
-
- // Verify result - these values were pre-computed for the given input
-#ifdef _MSC_VER
- if (tmp.m128i_u32[0] == 0xD8131B44 &&
- tmp.m128i_u32[1] == 0x9DE6E22B &&
- tmp.m128i_u32[2] == 0xA86D643A &&
- tmp.m128i_u32[3] == 0x74320FED)
-#else
- if (((uint32_t*)(&tmp))[0] == 0xD8131B44 &&
- ((uint32_t*)(&tmp))[1] == 0x9DE6E22B &&
- ((uint32_t*)(&tmp))[2] == 0xA86D643A &&
- ((uint32_t*)(&tmp))[3] == 0x74320FED)
-#endif
- result = 1;
- }
-#ifdef _MSC_VER
- __except (EXCEPTION_EXECUTE_HANDLER)
- {
- // ignore error if SHA instructions not supported
- }
-#else
- signal(SIGILL, oldHandler);
-#endif
-
- return result;
-}
+extern int TrySHA256();
#endif
static BOOL CheckSHA256Support() {