Improved AESNI check
This commit is contained in:
+14
-4
@@ -45,6 +45,10 @@
|
|||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(linux) || defined(__linux__)
|
||||||
|
static u_int8_t cached_has_aesni = 0. has_aesni_checked = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AES-NI support detection routine
|
* AES-NI support detection routine
|
||||||
*/
|
*/
|
||||||
@@ -59,7 +63,7 @@ int mbedtls_aesni_has_support( unsigned int what )
|
|||||||
#if defined(linux) || defined(__linux__)
|
#if defined(linux) || defined(__linux__)
|
||||||
unsigned int eax, ebx, ecx, edx;
|
unsigned int eax, ebx, ecx, edx;
|
||||||
|
|
||||||
{
|
if(has_aesni_checked == 0) {
|
||||||
/*
|
/*
|
||||||
NOTE
|
NOTE
|
||||||
|
|
||||||
@@ -73,21 +77,27 @@ int mbedtls_aesni_has_support( unsigned int what )
|
|||||||
if(fd != NULL) {
|
if(fd != NULL) {
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
int found = 0;
|
u_int8_t num_lines = 0;
|
||||||
|
|
||||||
while(getline(&line, &len, fd) != -1) {
|
while(getline(&line, &len, fd) != -1) {
|
||||||
if(strstr(line, "aes")) {
|
if(strstr(line, "aes")) {
|
||||||
/* printf("FOUND %s", line); */
|
/* printf("FOUND %s", line); */
|
||||||
found = 1;
|
cached_has_aesni = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(++num_lines > 99)
|
||||||
|
break; /* We giveup */
|
||||||
}
|
}
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
|
||||||
|
has_aesni_checked = 1;
|
||||||
return(found);
|
return(found);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
return(cached_has_aesni);
|
||||||
|
|
||||||
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
|
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user