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:
+19
-1
@@ -40,15 +40,32 @@
|
|||||||
*/
|
*/
|
||||||
int mbedtls_aesni_has_support( unsigned int what )
|
int mbedtls_aesni_has_support( unsigned int what )
|
||||||
{
|
{
|
||||||
|
#if !(defined(linux) || defined(__linux__))
|
||||||
static int done = 0;
|
static int done = 0;
|
||||||
static unsigned int c = 0;
|
static unsigned int c = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__has_feature)
|
#if defined(__has_feature)
|
||||||
# if __has_feature(memory_sanitizer)
|
# if __has_feature(memory_sanitizer)
|
||||||
return 0;
|
return 0;
|
||||||
# endif
|
# endif
|
||||||
#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 )
|
if( ! done )
|
||||||
{
|
{
|
||||||
asm( "movl $1, %%eax \n\t"
|
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 );
|
return( ( (volatile unsigned int)c & what ) != 0 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user