VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/cpu.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto/cpu.h')
-rw-r--r--src/Crypto/cpu.h72
1 files changed, 67 insertions, 5 deletions
diff --git a/src/Crypto/cpu.h b/src/Crypto/cpu.h
index cddec05c..2661bf1c 100644
--- a/src/Crypto/cpu.h
+++ b/src/Crypto/cpu.h
@@ -25,6 +25,25 @@
#define ATT_NOPREFIX
#endif
+#if defined (_MSC_VER) && !defined (TC_WINDOWS_BOOT)
+#if defined(TC_WINDOWS_DRIVER) || defined (_UEFI)
+#if defined(__cplusplus)
+extern "C" {
+#endif
+#if defined(_M_X64) || defined (_M_IX86) || defined (_M_IX86_FP)
+extern unsigned __int64 __rdtsc();
+#endif
+#if defined(__cplusplus)
+}
+#endif
+#else
+#include <intrin.h>
+#if defined(_M_X64) || defined (_M_IX86) || defined (_M_IX86_FP)
+#pragma intrinsic(__rdtsc)
+#endif
+#endif
+#endif
+
#ifdef CRYPTOPP_GENERATE_X64_MASM
#define CRYPTOPP_X86_ASM_AVAILABLE
@@ -89,8 +108,10 @@ extern __m128i _mm_unpacklo_epi64(__m128i _A, __m128i _B);
extern void _mm_store_si128(__m128i *_P, __m128i _B);
extern __m64 _m_pxor(__m64 _MM1, __m64 _MM2);
extern __m128i _mm_set_epi64(__m64 _Q1, __m64 _Q0);
+extern __m128i _mm_set1_epi64(__m64 q);
extern __m128i _mm_setr_epi32(int _I0, int _I1, int _I2, int _I3);
extern __m128i _mm_loadu_si128(__m128i const*_P);
+extern __m128i _mm_set_epi8(char b15, char b14, char b13, char b12, char b11, char b10, char b9, char b8, char b7, char b6, char b5, char b4, char b3, char b2, char b1, char b0);
extern __m128i _mm_set_epi32(int _I3, int _I2, int _I1, int _I0);
extern __m128i _mm_set1_epi32(int _I);
extern void _mm_storeu_si128(__m128i *_P, __m128i _B);
@@ -99,6 +120,7 @@ extern __m128i _mm_slli_epi32(__m128i _A, int _Count);
extern __m128i _mm_srli_epi32(__m128i _A, int _Count);
extern __m128i _mm_add_epi32(__m128i _A, __m128i _B);
extern __m128i _mm_sub_epi32(__m128i _A, __m128i _B);
+extern __m128i _mm_add_epi64 (__m128i a, __m128i b);
extern __m128i _mm_or_si128(__m128i _A, __m128i _B);
extern __m128i _mm_and_si128(__m128i _A, __m128i _B);
extern __m128i _mm_andnot_si128(__m128i _A, __m128i _B);
@@ -109,6 +131,14 @@ extern __m128i _mm_unpackhi_epi32(__m128i _A, __m128i _B);
extern __m128i _mm_unpackhi_epi64(__m128i _A, __m128i _B);
extern __m128i _mm_srli_epi16(__m128i _A, int _Count);
extern __m128i _mm_slli_epi16(__m128i _A, int _Count);
+extern __m128i _mm_shuffle_epi32 (__m128i a, int imm8);
+extern __m128i _mm_set_epi64x (__int64 e1, __int64 e0);
+extern __m128i _mm_set1_epi64x (__int64 a);
+extern __m128i _mm_castps_si128(__m128);
+extern __m128 _mm_castsi128_ps(__m128i);
+extern __m128 _mm_shuffle_ps(__m128 _A, __m128 _B, unsigned int _Imm8);
+extern __m128i _mm_srli_si128(__m128i _A, int _Imm);
+extern __m128i _mm_slli_si128(__m128i _A, int _Imm);
#define _mm_xor_si64 _m_pxor
#define _mm_empty _m_empty
#define _MM_SHUFFLE(fp3,fp2,fp1,fp0) (((fp3) << 6) | ((fp2) << 4) | \
@@ -122,13 +152,13 @@ extern __m128i _mm_slli_epi16(__m128i _A, int _Count);
#endif
#endif
-#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
-#if defined(__SSSE3__) || defined(__INTEL_COMPILER)
+#if CRYPTOPP_BOOL_SSSE3_INTRINSICS_AVAILABLE || defined(__INTEL_COMPILER)
#if defined(TC_WINDOWS_DRIVER) || defined (_UEFI)
#if defined(__cplusplus)
extern "C" {
#endif
extern __m128i _mm_shuffle_epi8 (__m128i a, __m128i b);
+extern __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int n);
#if defined(__cplusplus)
}
#endif
@@ -137,13 +167,14 @@ extern __m128i _mm_shuffle_epi8 (__m128i a, __m128i b);
#endif
#endif
-#if defined(__SSE4_1__) || defined(__INTEL_COMPILER) || defined(_MSC_VER)
+#if CRYPTOPP_BOOL_SSE41_INTRINSICS_AVAILABLE || defined(__INTEL_COMPILER)
#if defined(TC_WINDOWS_DRIVER) || defined (_UEFI)
#if defined(__cplusplus)
extern "C" {
#endif
extern int _mm_extract_epi32(__m128i src, const int ndx);
extern __m128i _mm_insert_epi32(__m128i dst, int s, const int ndx);
+extern __m128i _mm_blend_epi16 (__m128i v1, __m128i v2, const int mask);
#if defined(_M_X64)
extern __m128i _mm_insert_epi64(__m128i dst, __int64 s, const int ndx);
#endif
@@ -175,7 +206,6 @@ extern __m128i _mm_aesdeclast_si128(__m128i v, __m128i rkey);
#include <wmmintrin.h>
#endif
#endif
-#endif
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64
@@ -184,6 +214,9 @@ extern "C" {
#endif
#define CRYPTOPP_CPUID_AVAILABLE
+#if !defined(CRYPTOPP_DISABLE_AESNI) && !defined(WOLFCRYPT_BACKEND)
+#define TC_AES_HW_CPU
+#endif
// these should not be used directly
extern volatile int g_x86DetectionDone;
@@ -199,17 +232,24 @@ extern volatile int g_hasSSSE3;
extern volatile int g_hasAESNI;
extern volatile int g_hasCLMUL;
extern volatile int g_isP4;
+extern volatile int g_hasRDRAND;
+extern volatile int g_hasRDSEED;
extern volatile int g_isIntel;
extern volatile int g_isAMD;
extern volatile uint32 g_cacheLineSize;
void DetectX86Features(); // must be called at the start of the program/driver
-int CpuId(uint32 input, uint32 *output);
+int CpuId(uint32 input, uint32 output[4]);
// disable all CPU extended features (e.g. SSE, AVX, AES) that may have
// been enabled by DetectX86Features.
void DisableCPUExtendedFeatures ();
+#ifdef CRYPTOPP_BOOL_X64
+#define HasSSE2() 1
+#define HasISSE() 1
+#else
#define HasSSE2() g_hasSSE2
#define HasISSE() g_hasISSE
+#endif
#define HasMMX() g_hasMMX
#define HasSSE42() g_hasSSE42
#define HasSSE41() g_hasSSE41
@@ -220,6 +260,8 @@ void DisableCPUExtendedFeatures ();
#define HasAESNI() g_hasAESNI
#define HasCLMUL() g_hasCLMUL
#define IsP4() g_isP4
+#define HasRDRAND() g_hasRDRAND
+#define HasRDSEED() g_hasRDSEED
#define IsCpuIntel() g_isIntel
#define IsCpuAMD() g_isAMD
#define GetCacheLineSize() g_cacheLineSize
@@ -230,8 +272,28 @@ void DisableCPUExtendedFeatures ();
#else
+#define HasSSE2() 0
+#define HasISSE() 0
+
+#define HasMMX() 0
+#define HasSSE42() 0
+#define HasSSE41() 0
+#define HasSAVX() 0
+#define HasSAVX2() 0
+#define HasSBMI2() 0
+#define HasSSSE3() 0
+#define HasAESNI() 0
+#define HasCLMUL() 0
+#define IsP4() 0
+#define HasRDRAND() 0
+#define HasRDSEED() 0
+#define IsCpuIntel() 0
+#define IsCpuAMD() 0
#define GetCacheLineSize() CRYPTOPP_L1_CACHE_LINE_SIZE
+#define DetectX86Features()
+#define DisableCPUExtendedFeatures()
+
#endif
#endif