aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2022-04-29 14:50:21 +0200
committerLuca Deri <deri@ntop.org>2022-04-29 14:50:21 +0200
commite4318ffc2d3b9b7f481bf1fd9aac713218e65bd9 (patch)
tree09a51e38e006a84acb6325f87e9a58a46f92977d
parent71636dcafdfc8b78d31ae9a74c74e2fe725671df (diff)
Improved AES-NI check on Linux to avoid crashes on CPUs that do
not support it (e.g. Intel Celeron N2930)
-rw-r--r--src/lib/third_party/src/gcrypt/aesni.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/lib/third_party/src/gcrypt/aesni.c b/src/lib/third_party/src/gcrypt/aesni.c
index 76edeea4e..b61c39a63 100644
--- a/src/lib/third_party/src/gcrypt/aesni.c
+++ b/src/lib/third_party/src/gcrypt/aesni.c
@@ -40,15 +40,32 @@
*/
int mbedtls_aesni_has_support( unsigned int what )
{
+#if !(defined(linux) || defined(__linux__))
static int done = 0;
static unsigned int c = 0;
-
+#endif
+
#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
return 0;
# endif
#endif
+#if defined(linux) || defined(__linux__)
+ FILE *p;
+ int ch;
+
+ p = popen("sort -u /proc/crypto | grep aesni_intel | wc -l","r");
+ if(p == NULL)
+ return(0);
+
+ ch=fgetc(p);
+ pclose(p);
+
+ /* printf("*** %d / %c\n", ch, ch); */
+
+ return(ch == '1' ? 1 : 0);
+#else
if( ! done )
{
asm( "movl $1, %%eax \n\t"
@@ -60,6 +77,7 @@ int mbedtls_aesni_has_support( unsigned int what )
}
return( ( (volatile unsigned int)c & what ) != 0 );
+#endif
}
/*