Added support for getrandom()/getentropy(), and a fix for the RDRAND bug on AMD CPU...
[BearSSL] / src / symcipher / aes_x86ni.c
index dcc3952..d5408f1 100644 (file)
@@ -22,6 +22,7 @@
  * SOFTWARE.
  */
 
+#define BR_ENABLE_INTRINSICS   1
 #include "inner.h"
 
 /*
 
 #if BR_AES_X86NI
 
-#if BR_AES_X86NI_GCC
-#include <wmmintrin.h>
-#include <cpuid.h>
-#endif
-
-#if BR_AES_X86NI_MSC
-#include <intrin.h>
-#endif
-
 /* see inner.h */
 int
 br_aes_x86ni_supported(void)
@@ -49,28 +41,11 @@ br_aes_x86ni_supported(void)
         *   19   SSE4.1 (used for _mm_insert_epi32(), for AES-CTR)
         *   25   AES-NI
         */
-#define MASK   0x02080000
-
-#if BR_AES_X86NI_GCC
-       unsigned eax, ebx, ecx, edx;
-
-       if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
-               return (ecx & MASK) == MASK;
-       } else {
-               return 0;
-       }
-#elif BR_AES_X86NI_MSC
-       int info[4];
-
-       __cpuid(info, 1);
-       return ((uint32_t)info[2] & MASK) == MASK;
-#else
-       return 0;
-#endif
-
-#undef MASK
+       return br_cpuid(0, 0, 0x02080000, 0);
 }
 
+BR_TARGETS_X86_UP
+
 BR_TARGET("sse2,aes")
 static inline __m128i
 expand_step128(__m128i k, __m128i k2)
@@ -260,4 +235,6 @@ br_aes_x86ni_keysched_dec(unsigned char *skni, const void *key, size_t len)
        return num_rounds;
 }
 
+BR_TARGETS_X86_DOWN
+
 #endif