Download the static binary libraries, source code, and documentation:
This software is distributed under the Intel Sample Source Code license.
This is the DRNG Library, a project designed to bring the rdrand and rdseed instructions to customers who would traditionally not have access to them.
The "rdrand" and "rdseed" instructions are available at all privilege levels to any programmer, but tool chain support on some platforms is limited. One goal of this project is to provide access to these instructions via pre-compiled, static libraries. A second level goal is to provide a consistent, small, and very easy-to-use API to access the "rdrand" and "rdseed" instruction for various sizes of random data.
The source code and build system are provided for the entire library allowing the user to make any needed changes, or build dynamic versions, for incorporation into their own code.
For ease of use, this library is distributed with static libraries for Microsoft* Windows* and Microsoft* Visual Studio*, Linux Ubuntu* 14.10, and OS X* Yosemite*. The library can also be built from source, and requires the Visual Studio with the Intel® C++ Compiler or Visual Studio 2013 on Windows, or GNU* gcc* on Linux and OS X*. See the Building section for more details.
Once the static library is compiled, it is simply a matter of linking in the library with your code and including the header in the header search path to use the library. Linking the static library is beyond the scope of this documentation, but for demonstration, a simple Microsoft* Visual Studio* project is included, named test, as well as a simple project with Makefile for Linux or OS X. Source for the test is in main.c, and the test project on Linux can uses the top-level Makefile. The rdrand.sln solution includes the test project.
Rdrand is only supported on 3rd generation Intel(r) Core processors and beyond, and Rdseed is only supported on 5th generation Intel(r) Core processors and Core M processors and beyond. It makes sense to determine whether or not these instructions are supported by the CPU and this is done by examining the appropriate feature bits after calling cpuid. To ease use the library automatically handles this, and stores the results internally and transparently to the end user of the library. This result is stored in global data, and is thread-safe, given that if one thread of execution supports rdrand, they all will. Users may find it more practical, however, to call the RdRand_isSupported() and RdSeed_isSupported() functions when managing multiple potential code paths in an application.
The API was designed to be as simple and easy-to-use as possible, and consists of these functions:
int rdrand_16(uint16_t* x, int retry); int rdrand_32(uint32_t* x, int retry); int rdrand_64(uint64_t* x, int retry); int rdseed_16(uint16_t* x, int retry_count); int rdseed_32(uint32_t* x, int retry_count); int rdseed_64(uint64_t* x, int retry_count); int rdrand_get_n_64(unsigned int n, uint64_t* x); int rdrand_get_n_32(unsigned int n, uint32_t* x); int rdseed_get_n_64(unsigned int n, uint64_t* x, unsigned int skip, int max_retries); int rdseed_get_n_32(unsigned int n, uint32_t* x, unsigned int skip, int max_retries); int rdrand_get_bytes(unsigned int n, unsigned char *buffer); int rdseed_get_bytes(unsigned int n, unsigned char *buffer, unsigned into skip, int max_retries);
Each function calls rdrand or rdseed internally for a specific data-size of random data to return to the caller.
The return of these functions states the hardware was not ready (if non-retry specified), success, or that the host hardware doesn't support the desired instruction at all.
More detailed information about the library and its usage can be found in the companion article, Intel® Digital Random Number Generator (DRNG) Library Implementation and Uses.
Building the Rdrand Library is supported under Microsoft* Visual Studio 2013*, Linux* and OS X*. Use of the Intel® C++ Compiler is optional unless you are using a version of Visual Studio earlier than 2013 on Microsoft Windows*.
To build the library, open the rdrand Microsoft Visual Studio solution (rdrand.sln), and build the project as normal from the build menu. Included are two projects, rdrand the actual library and test, the demonstration program.
On Linux and OS X the build is wrapped with GNU* autoconf*. To build:
$ ./configure $ make
The DRNG Library is simple and as of this release is functionally complete. There are no known issues.
© 2015 Intel Corporation. All rights reserved.
Product and Performance Information
Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.