Improved AES-NI check on Linux to avoid crashes on CPUs that do

not support it (e.g. Intel Celeron N2930)
This commit is contained in:
Luca Deri
2022-04-29 14:50:21 +02:00
parent 71636dcafd
commit e4318ffc2d
+19 -1
View File
@@ -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
}
/*