3

I searching for solution, how to check aes-ni are available on CPU. I need to put this information in my application, so i'm not looking for any CPU-Z, bash commands or something. I know that it is seen as aes flag. I have no idea how to check it in assembly or c. Main application is written in C#, but it doesn't matter.

s3ven
  • 85
  • 2
  • 6
  • Related: http://unix.stackexchange.com/questions/14077/how-to-check-that-aes-ni-is-supported-by-my-cpu . On linux `/proc/cpuinfo` is as available to C as it is to bash, but this requires of course a unix system. – Maarten Bodewes Nov 30 '14 at 01:34

2 Answers2

4

This information is returned by the cpuid instruction. Pass in eax=1 and bit #25 in ecx will show support. See the intel instruction set reference for more details. Sample code:

mov eax, 1
cpuid
test ecx, 1<<25
jz no_aesni

Also, you might just try executing it and catch the exception.

Jester
  • 56,577
  • 4
  • 81
  • 125
2

In visual C++

static bool GetNNICapability()
{
    unsigned int b;

    __asm
    {
        mov     eax, 1
        cpuid
        mov     b, ecx
    }

    return (b & (1 << 25)) != 0;
}
JGU
  • 879
  • 12
  • 14