[cryptography] Intel Security Driver and AVX CPUs (rdrand)

Peter Gutmann pgut001 at cs.auckland.ac.nz
Thu Sep 1 23:57:18 EDT 2011

Jeffrey Walton <noloader at gmail.com> writes:

>Does anyone know if Intel is shipping an updated driver which wraps/includes
>rdrand from AVX?

I posted the following to the list a few months back:

-- Snip --

In case this is useful to anyone, here's the Windows code to use rdrand, to
complement the gcc version for Unix systems.  It'll also be present in the
next release of the cryptlib RNG code, available under a GPL, LGPL, or BSD
license, depending on which you prefer.

#if defined( _MSC_VER )
  #define rdrand_eax    __asm _emit 0x0F __asm _emit 0xC7 __asm _emit 0xF0
#endif /* VC++ */
#if defined __BORLANDC__
  #define rdrand_eax    } __emit__( 0x0F, 0xC7, 0xF0 ); __asm {
#endif /* BC++ */

    unsigned long buffer[ 8 + 8 ];
    int byteCount = 0;

    __asm {
        xor eax, eax        /* Tell VC++ that EAX will be trashed */
        xor ecx, ecx
        jnc trngExit        /* TRNG result bad, exit with byteCount = 0 */
        mov [buffer+ecx], eax
        add ecx, 4
        cmp ecx, 32         /* Fill 32 bytes worth */
        jl trngLoop
        mov [byteCount], ecx
    if( byteCount > 0 )
        /* buffer[ 0 ... byteCount ] contains random bytes */

This has been verified under XP, Vista, and Win7 using the Intel Software
Development Emulator.

-- Snip --

(Oh, the RNG 'next release' means the one that's out now, since this was from 
a few months ago).


More information about the cryptography mailing list