30 #ifndef CRYPTOPP_CPU_H 31 #define CRYPTOPP_CPU_H 36 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 37 # pragma GCC diagnostic push 38 # pragma GCC diagnostic ignored "-Wconversion" 39 # pragma GCC diagnostic ignored "-Wsign-conversion" 43 #if defined(CRYPTOPP_LLVM_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) 45 #define INTEL_PREFIX ".intel_syntax;" 46 #define INTEL_NOPREFIX ".intel_syntax;" 47 #define ATT_PREFIX ".att_syntax;" 48 #define ATT_NOPREFIX ".att_syntax;" 49 #elif defined(__GNUC__) 51 #define INTEL_PREFIX ".intel_syntax prefix;" 52 #define INTEL_NOPREFIX ".intel_syntax noprefix;" 53 #define ATT_PREFIX ".att_syntax prefix;" 54 #define ATT_NOPREFIX ".att_syntax noprefix;" 58 #define INTEL_NOPREFIX 63 #ifdef CRYPTOPP_GENERATE_X64_MASM 65 #define CRYPTOPP_X86_ASM_AVAILABLE 66 #define CRYPTOPP_BOOL_X64 1 67 #define CRYPTOPP_SSE2_ASM_AVAILABLE 1 76 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 || CRYPTOPP_DOXYGEN_PROCESSING 78 #define CRYPTOPP_CPUID_AVAILABLE 1 81 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 83 extern CRYPTOPP_DLL
bool g_x86DetectionDone;
84 extern CRYPTOPP_DLL
bool g_hasSSE2;
85 extern CRYPTOPP_DLL
bool g_hasSSSE3;
86 extern CRYPTOPP_DLL
bool g_hasSSE41;
87 extern CRYPTOPP_DLL
bool g_hasSSE42;
88 extern CRYPTOPP_DLL
bool g_hasAVX;
89 extern CRYPTOPP_DLL
bool g_hasAVX2;
90 extern CRYPTOPP_DLL
bool g_hasAESNI;
91 extern CRYPTOPP_DLL
bool g_hasCLMUL;
92 extern CRYPTOPP_DLL
bool g_hasSHA;
93 extern CRYPTOPP_DLL
bool g_hasADX;
94 extern CRYPTOPP_DLL
bool g_isP4;
95 extern CRYPTOPP_DLL
bool g_hasRDRAND;
96 extern CRYPTOPP_DLL
bool g_hasRDSEED;
97 extern CRYPTOPP_DLL
bool g_hasPadlockRNG;
98 extern CRYPTOPP_DLL
bool g_hasPadlockACE;
99 extern CRYPTOPP_DLL
bool g_hasPadlockACE2;
100 extern CRYPTOPP_DLL
bool g_hasPadlockPHE;
101 extern CRYPTOPP_DLL
bool g_hasPadlockPMM;
102 extern CRYPTOPP_DLL word32 g_cacheLineSize;
104 CRYPTOPP_DLL
void CRYPTOPP_API DetectX86Features();
105 CRYPTOPP_DLL
bool CRYPTOPP_API CpuId(word32 func, word32 subfunc, word32 output[4]);
106 #endif // CRYPTOPP_DOXYGEN_PROCESSING 118 #if CRYPTOPP_BOOL_X64 121 if (!g_x86DetectionDone)
133 if (!g_x86DetectionDone)
144 if (!g_x86DetectionDone)
155 if (!g_x86DetectionDone)
167 if (!g_x86DetectionDone)
179 if (!g_x86DetectionDone)
191 if (!g_x86DetectionDone)
203 if (!g_x86DetectionDone)
215 if (!g_x86DetectionDone)
227 if (!g_x86DetectionDone)
238 if (!g_x86DetectionDone)
249 if (!g_x86DetectionDone)
260 if (!g_x86DetectionDone)
271 if (!g_x86DetectionDone)
273 return g_hasPadlockRNG;
282 if (!g_x86DetectionDone)
284 return g_hasPadlockACE;
293 if (!g_x86DetectionDone)
295 return g_hasPadlockACE2;
304 if (!g_x86DetectionDone)
306 return g_hasPadlockPHE;
315 if (!g_x86DetectionDone)
317 return g_hasPadlockPMM;
330 if (!g_x86DetectionDone)
332 return g_cacheLineSize;
336 #endif // CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 340 #if CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8 || CRYPTOPP_DOXYGEN_PROCESSING 343 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 344 extern bool g_ArmDetectionDone;
345 extern bool g_hasARMv7;
346 extern bool g_hasNEON;
347 extern bool g_hasPMULL;
348 extern bool g_hasCRC32;
349 extern bool g_hasAES;
350 extern bool g_hasSHA1;
351 extern bool g_hasSHA2;
352 extern bool g_hasSHA512;
353 extern bool g_hasSHA3;
354 extern bool g_hasSM3;
355 extern bool g_hasSM4;
356 void CRYPTOPP_API DetectArmFeatures();
357 #endif // CRYPTOPP_DOXYGEN_PROCESSING 370 #if defined(__aarch32__) || defined(__aarch64__) 373 if (!g_ArmDetectionDone)
390 #if defined(__aarch32__) || defined(__aarch64__) 393 if (!g_ArmDetectionDone)
410 #if defined(__aarch32__) || defined(__aarch64__) 411 if (!g_ArmDetectionDone)
431 #if defined(__aarch32__) || defined(__aarch64__) 432 if (!g_ArmDetectionDone)
451 #if defined(__aarch32__) || defined(__aarch64__) 452 if (!g_ArmDetectionDone)
471 #if defined(__aarch32__) || defined(__aarch64__) 472 if (!g_ArmDetectionDone)
491 #if defined(__aarch32__) || defined(__aarch64__) 492 if (!g_ArmDetectionDone)
511 #if defined(__aarch32__) || defined(__aarch64__) 512 if (!g_ArmDetectionDone)
531 #if defined(__aarch32__) || defined(__aarch64__) 532 if (!g_ArmDetectionDone)
551 #if defined(__aarch32__) || defined(__aarch64__) 552 if (!g_ArmDetectionDone)
571 #if defined(__aarch32__) || defined(__aarch64__) 572 if (!g_ArmDetectionDone)
582 #endif // CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8 586 #if CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64 || CRYPTOPP_DOXYGEN_PROCESSING 589 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 590 extern bool g_PowerpcDetectionDone;
591 extern bool g_hasAltivec;
592 extern bool g_hasPower7;
593 extern bool g_hasPower8;
594 extern bool g_hasPower9;
595 extern bool g_hasAES;
596 extern bool g_hasPMULL;
597 extern bool g_hasSHA256;
598 extern bool g_hasSHA512;
599 extern bool g_hasDARN;
600 extern word32 g_cacheLineSize;
601 void CRYPTOPP_API DetectPowerpcFeatures();
602 #endif // CRYPTOPP_DOXYGEN_PROCESSING 616 if (!g_PowerpcDetectionDone)
617 DetectPowerpcFeatures();
629 if (!g_PowerpcDetectionDone)
630 DetectPowerpcFeatures();
642 if (!g_PowerpcDetectionDone)
643 DetectPowerpcFeatures();
655 if (!g_PowerpcDetectionDone)
656 DetectPowerpcFeatures();
669 if (!g_PowerpcDetectionDone)
670 DetectPowerpcFeatures();
683 if (!g_PowerpcDetectionDone)
684 DetectPowerpcFeatures();
697 if (!g_PowerpcDetectionDone)
698 DetectPowerpcFeatures();
711 if (!g_PowerpcDetectionDone)
712 DetectPowerpcFeatures();
724 if (!g_PowerpcDetectionDone)
725 DetectPowerpcFeatures();
728 #if defined(__ibmxl__) && defined(__linux__) 745 if (!g_PowerpcDetectionDone)
746 DetectPowerpcFeatures();
747 return g_cacheLineSize;
752 #endif // CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64 757 #if !(CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) 768 return CRYPTOPP_L1_CACHE_LINE_SIZE;
770 #endif // Non-Intel systems 772 #endif // CRYPTOPP_GENERATE_X64_MASM 776 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 778 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 780 #ifdef CRYPTOPP_GENERATE_X64_MASM 781 #define AS1(x) x*newline* 782 #define AS2(x, y) x, y*newline* 783 #define AS3(x, y, z) x, y, z*newline* 784 #define ASS(x, y, a, b, c, d) x, y, a*64+b*16+c*4+d*newline* 785 #define ASL(x) label##x:*newline* 786 #define ASJ(x, y, z) x label##y*newline* 787 #define ASC(x, y) x label##y*newline* 788 #define AS_HEX(y) 0##y##h 789 #elif defined(_MSC_VER) || defined(__BORLANDC__) 790 #define AS1(x) __asm {x} 791 #define AS2(x, y) __asm {x, y} 792 #define AS3(x, y, z) __asm {x, y, z} 793 #define ASS(x, y, a, b, c, d) __asm {x, y, (a)*64+(b)*16+(c)*4+(d)} 794 #define ASL(x) __asm {label##x:} 795 #define ASJ(x, y, z) __asm {x label##y} 796 #define ASC(x, y) __asm {x label##y} 797 #define CRYPTOPP_NAKED __declspec(naked) 798 #define AS_HEX(y) 0x##y 801 #define GNU_AS1(x) #x ";" NEW_LINE 802 #define GNU_AS2(x, y) #x ", " #y ";" NEW_LINE 803 #define GNU_AS3(x, y, z) #x ", " #y ", " #z ";" NEW_LINE 804 #define GNU_ASL(x) "\n" #x ":" NEW_LINE 806 #if (CRYPTOPP_LLVM_CLANG_VERSION >= 50000) || (CRYPTOPP_APPLE_CLANG_VERSION >= 90000) 807 #define GNU_ASJ(x, y, z) ATT_PREFIX ";" NEW_LINE #x " " #y #z ";" NEW_LINE INTEL_PREFIX ";" NEW_LINE 809 #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE 811 #define AS1(x) GNU_AS1(x) 812 #define AS2(x, y) GNU_AS2(x, y) 813 #define AS3(x, y, z) GNU_AS3(x, y, z) 814 #define ASS(x, y, a, b, c, d) #x ", " #y ", " #a "*64+" #b "*16+" #c "*4+" #d ";" 815 #define ASL(x) GNU_ASL(x) 816 #define ASJ(x, y, z) GNU_ASJ(x, y, z) 817 #define ASC(x, y) #x " " #y ";" 818 #define CRYPTOPP_NAKED 819 #define AS_HEX(y) 0x##y 825 #ifdef CRYPTOPP_GENERATE_X64_MASM 826 #define ASM_MOD(x, y) ((x) MOD (y)) 827 #define XMMWORD_PTR XMMWORD PTR 830 #define ASM_MOD(x, y) ((x)-((x)/(y))*(y)) 835 #if CRYPTOPP_BOOL_X86 843 #define AS_REG_1d ecx 844 #define AS_REG_2d edx 845 #define AS_REG_3d esi 846 #define AS_REG_4d edi 847 #define AS_REG_5d eax 848 #define AS_REG_6d ebx 849 #define AS_REG_7d ebp 851 #define WORD_REG(x) e##x 852 #define WORD_PTR DWORD PTR 853 #define AS_PUSH_IF86(x) AS1(push e##x) 854 #define AS_POP_IF86(x) AS1(pop e##x) 855 #define AS_JCXZ jecxz 856 #elif CRYPTOPP_BOOL_X32 862 #define AS_REG_6 r10d 863 #define AS_REG_7 r11d 864 #define AS_REG_1d ecx 865 #define AS_REG_2d edx 866 #define AS_REG_3d r8d 867 #define AS_REG_4d r9d 868 #define AS_REG_5d eax 869 #define AS_REG_6d r10d 870 #define AS_REG_7d r11d 872 #define WORD_REG(x) e##x 873 #define WORD_PTR DWORD PTR 874 #define AS_PUSH_IF86(x) AS1(push r##x) 875 #define AS_POP_IF86(x) AS1(pop r##x) 876 #define AS_JCXZ jecxz 877 #elif CRYPTOPP_BOOL_X64 878 #ifdef CRYPTOPP_GENERATE_X64_MASM 886 #define AS_REG_1d ecx 887 #define AS_REG_2d edx 888 #define AS_REG_3d r8d 889 #define AS_REG_4d r9d 890 #define AS_REG_5d eax 891 #define AS_REG_6d r10d 892 #define AS_REG_7d r11d 901 #define AS_REG_1d edi 902 #define AS_REG_2d esi 903 #define AS_REG_3d edx 904 #define AS_REG_4d ecx 905 #define AS_REG_5d r8d 906 #define AS_REG_6d r9d 907 #define AS_REG_7d r10d 910 #define WORD_REG(x) r##x 911 #define WORD_PTR QWORD PTR 912 #define AS_PUSH_IF86(x) 913 #define AS_POP_IF86(x) 914 #define AS_JCXZ jrcxz 918 #define AS_XMM_OUTPUT4(labelPrefix, inputPtr, outputPtr, x0, x1, x2, x3, t, p0, p1, p2, p3, increment)\ 919 AS2( test inputPtr, inputPtr)\ 920 ASC( jz, labelPrefix##3)\ 921 AS2( test inputPtr, 15)\ 922 ASC( jnz, labelPrefix##7)\ 923 AS2( pxor xmm##x0, [inputPtr+p0*16])\ 924 AS2( pxor xmm##x1, [inputPtr+p1*16])\ 925 AS2( pxor xmm##x2, [inputPtr+p2*16])\ 926 AS2( pxor xmm##x3, [inputPtr+p3*16])\ 927 AS2( add inputPtr, increment*16)\ 928 ASC( jmp, labelPrefix##3)\ 930 AS2( movdqu xmm##t, [inputPtr+p0*16])\ 931 AS2( pxor xmm##x0, xmm##t)\ 932 AS2( movdqu xmm##t, [inputPtr+p1*16])\ 933 AS2( pxor xmm##x1, xmm##t)\ 934 AS2( movdqu xmm##t, [inputPtr+p2*16])\ 935 AS2( pxor xmm##x2, xmm##t)\ 936 AS2( movdqu xmm##t, [inputPtr+p3*16])\ 937 AS2( pxor xmm##x3, xmm##t)\ 938 AS2( add inputPtr, increment*16)\ 940 AS2( test outputPtr, 15)\ 941 ASC( jnz, labelPrefix##8)\ 942 AS2( movdqa [outputPtr+p0*16], xmm##x0)\ 943 AS2( movdqa [outputPtr+p1*16], xmm##x1)\ 944 AS2( movdqa [outputPtr+p2*16], xmm##x2)\ 945 AS2( movdqa [outputPtr+p3*16], xmm##x3)\ 946 ASC( jmp, labelPrefix##9)\ 948 AS2( movdqu [outputPtr+p0*16], xmm##x0)\ 949 AS2( movdqu [outputPtr+p1*16], xmm##x1)\ 950 AS2( movdqu [outputPtr+p2*16], xmm##x2)\ 951 AS2( movdqu [outputPtr+p3*16], xmm##x3)\ 953 AS2( add outputPtr, increment*16) 955 #endif // CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 957 #endif // Not CRYPTOPP_DOXYGEN_PROCESSING 962 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 963 # pragma GCC diagnostic pop 966 #endif // CRYPTOPP_CPU_H bool HasSHA()
Determines SHA availability.
bool HasDARN()
Determine if a PowerPC processor has DARN available.
bool HasAltivec()
Determine if a PowerPC processor has Altivec available.
bool HasSM4()
Determine if an ARM processor has SM4 available.
bool HasCRC32()
Determine if an ARM processor has CRC32 available.
bool HasSSSE3()
Determines SSSE3 availability.
bool HasADX()
Determines ADX availability.
bool HasPadlockRNG()
Determines Padlock RNG availability.
bool HasAVX2()
Determines AVX2 availability.
bool HasAES()
Determine if an ARM processor has AES available.
bool IsP4()
Determines if the CPU is an Intel P4.
Library configuration file.
int GetCacheLineSize()
Provides the cache line size.
bool HasRDRAND()
Determines RDRAND availability.
bool HasPower7()
Determine if a PowerPC processor has Power7 available.
bool HasSHA256()
Determine if a PowerPC processor has SHA256 available.
bool HasSM3()
Determine if an ARM processor has SM3 available.
bool HasPower8()
Determine if a PowerPC processor has Power8 available.
bool HasRDSEED()
Determines RDSEED availability.
bool HasCLMUL()
Determines Carryless Multiply availability.
bool HasSHA1()
Determine if an ARM processor has SHA1 available.
bool HasSHA512()
Determine if an ARM processor has SHA512 available.
bool HasPadlockACE2()
Determines Padlock ACE2 availability.
bool HasPadlockPHE()
Determines Padlock PHE availability.
bool HasPadlockPMM()
Determines Padlock PMM availability.
bool HasAESNI()
Determines AES-NI availability.
bool HasPower9()
Determine if a PowerPC processor has Power9 available.
bool HasSSE2()
Determines SSE2 availability.
bool HasSHA2()
Determine if an ARM processor has SHA256 available.
bool HasAVX()
Determines AVX availability.
bool HasSSE41()
Determines SSE4.1 availability.
Crypto++ library namespace.
bool HasSHA3()
Determine if an ARM processor has SHA3 available.
bool HasARMv7()
Determine if an ARM processor is ARMv7 or above.
bool HasPadlockACE()
Determines Padlock ACE availability.
bool HasSSE42()
Determines SSE4.2 availability.
bool HasPMULL()
Determine if an ARM processor provides Polynomial Multiplication.
bool HasNEON()
Determine if an ARM processor has Advanced SIMD available.