diff options
author | Luca Deri <deri@ntop.org> | 2022-08-29 17:42:28 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2022-08-29 17:42:28 +0200 |
commit | ef99eb674e86eeb9b5ae3e6edb8cac88f654c19c (patch) | |
tree | f49f6235a70ef332499cd999155ce982f8607087 | |
parent | a329730d24bc99a77a8e49334ac146fdaf50fb65 (diff) |
Improved AES-NI presence check on Linux
-rw-r--r-- | src/lib/third_party/src/gcrypt/aesni.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/third_party/src/gcrypt/aesni.c b/src/lib/third_party/src/gcrypt/aesni.c index db5c92eb6..8cdba5802 100644 --- a/src/lib/third_party/src/gcrypt/aesni.c +++ b/src/lib/third_party/src/gcrypt/aesni.c @@ -59,6 +59,35 @@ int mbedtls_aesni_has_support( unsigned int what ) #if defined(linux) || defined(__linux__) unsigned int eax, ebx, ecx, edx; + if(what == MBEDTLS_AESNI_AES) { + /* + 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 + and thus nDPI crashes on such platform. + */ + FILE *fd = fopen("/proc/cpuinfo", "r"); + + if(fd != NULL) { + char *line = NULL; + size_t len = 0; + int found = 0; + + while(getline(&line, &len, fd) != -1) { + if(strstr(line, "aes")) { + /* printf("FOUND %s", line); */ + found = 1; + break; + } + } + + fclose(fd); + return(found); + } + } + if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0) { return 0; |