aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2022-10-26 13:51:00 +0200
committerLuca Deri <deri@ntop.org>2022-10-26 13:51:00 +0200
commit55f885f3edac48c335541a3df910434fa719111e (patch)
tree443b39b1f8f17fe13c357a64bb43d5d701e79525
parentde16fd35aa08ab584eaec487c02d31ad7a7a8942 (diff)
Improved AESNI check
-rw-r--r--src/lib/third_party/src/gcrypt/aesni.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/lib/third_party/src/gcrypt/aesni.c b/src/lib/third_party/src/gcrypt/aesni.c
index 5a32ae692..00f64aed0 100644
--- a/src/lib/third_party/src/gcrypt/aesni.c
+++ b/src/lib/third_party/src/gcrypt/aesni.c
@@ -45,6 +45,10 @@
#include <intrin.h>
#endif
+#if defined(linux) || defined(__linux__)
+static u_int8_t cached_has_aesni = 0. has_aesni_checked = 0;
+#endif
+
/*
* AES-NI support detection routine
*/
@@ -59,10 +63,10 @@ int mbedtls_aesni_has_support( unsigned int what )
#if defined(linux) || defined(__linux__)
unsigned int eax, ebx, ecx, edx;
- {
+ if(has_aesni_checked == 0) {
/*
NOTE
-
+
This code is necessary as __get_cpuid() is not reliable
Example with Intel(R) Celeron(R) CPU N2930 (that has NO AES-NI)
the code based on __get_cpuid() reports that AES-NI is present
@@ -73,21 +77,27 @@ int mbedtls_aesni_has_support( unsigned int what )
if(fd != NULL) {
char *line = NULL;
size_t len = 0;
- int found = 0;
+ u_int8_t num_lines = 0;
while(getline(&line, &len, fd) != -1) {
if(strstr(line, "aes")) {
/* printf("FOUND %s", line); */
- found = 1;
+ cached_has_aesni = 1;
break;
}
+
+ if(++num_lines > 99)
+ break; /* We giveup */
}
free(line);
fclose(fd);
+
+ has_aesni_checked = 1;
return(found);
}
- }
+ } else
+ return(cached_has_aesni);
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
{