RDRAND explained

RDRAND (for "read random") is an instruction for returning random numbers from an Intel on-chip hardware random number generator which has been seeded by an on-chip entropy source.[1] It is also known as Intel Secure Key Technology,[2] codenamed Bull Mountain.[3] Intel introduced the feature around 2012, and AMD added support for the instruction in June 2015. (RDRAND is available in Ivy Bridge processors and is part of the Intel 64 and IA-32 instruction set architectures.) [4]

The random number generator is compliant with security and cryptographic standards such as NIST SP 800-90A,[5] FIPS 140-2, and ANSI X9.82. Intel also requested Cryptography Research Inc. to review the random number generator in 2012, which resulted in the paper Analysis of Intel's Ivy Bridge Digital Random Number Generator.[6]

RDSEED is similar to RDRAND and provides lower-level access to the entropy-generating hardware. The RDSEED generator and processor instruction rdseed are available with Intel Broadwell CPUs[7] and AMD Zen CPUs.[8]

Overview

The [[CPUID]] instruction can be used on both AMD and Intel CPUs to check whether the RDRAND instruction is supported. If it is, bit 30 of the ECX register is set after calling CPUID standard function 01H.[9] AMD processors are checked for the feature using the same test.[10] RDSEED availability can be checked on Intel CPUs in a similar manner. If RDSEED is supported, the bit 18 of the EBX register is set after calling CPUID standard function 07H.[11]

The opcode for RDRAND is 0x0F 0xC7, followed by a ModRM byte that specifies the destination register and optionally combined with a REX prefix in 64-bit mode.[12]

Intel Secure Key is Intel's name for both the RDRAND instruction and the underlying random number generator (RNG) hardware implementation, which was codenamed "Bull Mountain" during development. Intel calls their RNG a "digital random number generator" or DRNG. The generator takes pairs of 256-bit raw entropy samples generated by the hardware entropy source and applies them to an Advanced Encryption Standard (AES) (in CBC-MAC mode) conditioner which reduces them to a single 256-bit conditioned entropy sample. A deterministic random-bit generator called CTR DRBG defined in NIST SP 800-90A is seeded by the output from the conditioner, providing cryptographically secure random numbers to applications requesting them via the RDRAND instruction.[13] The hardware will issue a maximum of 511 128-bit samples before changing the seed value. Using the RDSEED operation provides access to the conditioned 256-bit samples from the AES-CBC-MAC.

The RDSEED instruction was added to Intel Secure Key for seeding another pseudorandom number generator,[14] available in Broadwell CPUs. The entropy source for the RDSEED instruction runs asynchronously on a self-timed circuit and uses thermal noise within the silicon to output a random stream of bits at the rate of 3 GHz,[15] slower than the effective 6.4 Gbit/s obtainable from RDRAND (both rates are shared between all cores and threads).[16] The RDSEED instruction is intended for seeding a software PRNG of arbitrary width, whereas the RDRAND is intended for applications that merely require high-quality random numbers. If cryptographic security is not required, a software PRNG such as Xorshift is usually faster.[17]

Performance

On an Intel Core i7-7700K, 4500 MHz (45 × 100 MHz) processor (Kaby Lake-S microarchitecture), a single RDRAND or RDSEED instruction takes 110 ns, or 463 clock cycles, regardless of the operand size (16/32/64 bits). This number of clock cycles applies to all processors with Skylake or Kaby Lake microarchitecture. On the Silvermont microarchitecture processors, each of the instructions take around 1472 clock cycles, regardless of the operand size; and on Ivy Bridge processors RDRAND takes up to 117 clock cycles.[18]

On an AMD Ryzen CPU, each of the instructions takes around 1200 clock cycles for 16-bit or 32-bit operand, and around 2500 clock cycles for a 64-bit operand.

An astrophysical Monte Carlo simulator examined the time to generate 107 64-bit random numbers using RDRAND on a quad-core Intel i7-3740 QM processor. They found that a C implementation of RDRAND ran about 2× slower than the default random number generator in C, and about 20× slower than the Mersenne Twister. Although a Python module of RDRAND has been constructed, it was found to be 20× slower than the default random number generator in Python,[19] although a performance comparison between a PRNG and CSPRNG cannot be made.

A microcode update released by Intel in June 2020, designed to mitigate the CrossTalk vulnerability (see the security issues section below), negatively impacts the performance of RDRAND and RDSEED due to additional security controls. On processors with the mitigations applied, each affected instruction incurs additional latency and simultaneous execution of RDRAND or RDSEED across cores is effectively serialised. Intel introduced a mechanism to relax these security checks, thus reducing the performance impact in most scenarios, but Intel processors do not apply this security relaxation by default.

Compilers

Visual C++ 2015 provides intrinsic wrapper support for the RDRAND and RDSEED functions.[20] GCC 4.6+ and Clang 3.2+ provide intrinsic functions for RDRAND when -mrdrnd is specified in the flags,[21] also setting __RDRND__ to allow conditional compilation. Newer versions additionally provide immintrin.h to wrap these built-ins into functions compatible with version 12.1+ of Intel's C Compiler. These functions write random data to the location pointed to by their parameter, and return 1 on success.[22]

Applications

It is an option to generate cryptographically secure random numbers using RDRAND and RDSEED in OpenSSL, to help secure communications.

Scientific application of RDRAND in a Monte Carlo simulator was evaluated, focusing on performance and reproducibility, compared to other random number generators. It led to the conclusion that using RDRAND as opposed to Mersenne Twister doesn't provide different results, but worse performance and reproducibility.[23] [19]

Reception

In September 2013, in response to a New York Times article revealing the NSA's effort to weaken encryption,[24] Theodore Ts'o publicly posted concerning the use of RDRAND for [[/dev/random]] in the Linux kernel:[25]

Linus Torvalds dismissed concerns about the use of RDRAND in the Linux kernel and pointed out that it is not used as the only source of entropy for /dev/random, but rather used to improve the entropy by combining the values received from RDRAND with other sources of randomness.[26] However, Taylor Hornby of Defuse Security demonstrated that the Linux random number generator could become insecure if a backdoor is introduced into the RDRAND instruction that specifically targets the code using it. Hornby's proof-of-concept implementation works on an unmodified Linux kernel prior to version 3.13.[27] [28] [29] The issue was mitigated in the Linux kernel in 2013.[30]

Developers changed the FreeBSD kernel away from using RDRAND and VIA PadLock directly with the comment "For FreeBSD 10, we are going to backtrack and remove RDRAND and Padlock backends and feed them into Yarrow instead of delivering their output directly to /dev/random. It will still be possible to access hardware random number generators, that is, RDRAND, Padlock etc., directly by inline assembly or by using OpenSSL from userland, if required, but we cannot trust them any more."[31] [32] FreeBSD /dev/random uses Fortuna and RDRAND started from FreeBSD 11.[33]

Security issues

On 9 June 2020, researchers from Vrije Universiteit Amsterdam published a side-channel attack named CrossTalk (CVE-2020-0543) that affected RDRAND on a number of Intel processors.[34] They discovered that outputs from the hardware digital random number generator (DRNG) were stored in a staging buffer that was shared across all cores. The vulnerability allowed malicious code running on an affected processor to read RDRAND and RDSEED instruction results from a victim application running on another core of that same processor, including applications running inside Intel SGX enclaves. The researchers developed a proof-of-concept exploit[35] which extracted a complete ECDSA key from an SGX enclave running on a separate CPU core after only one signature operation.[34] The vulnerability affects scenarios where untrusted code runs alongside trusted code on the same processor, such as in a shared hosting environment.

Intel refers to the CrossTalk vulnerability as Special Register Buffer Data Sampling (SRBDS). In response to the research, Intel released microcode updates to mitigate the issue. The updated microcode ensures that off-core accesses are delayed until sensitive operations specifically the RDRAND, RDSEED, and EGETKEY instructions are completed and the staging buffer has been overwritten.[36] The SRBDS attack also affects other instructions, such as those that read MSRs, but Intel did not apply additional security protections to them due to performance concerns and the reduced need for confidentiality of those instructions' results. A wide range of Intel processors released between 2012 and 2019 were affected, including desktop, mobile, and server processors.[37] The mitigations themselves resulted in negative performance impacts when using the affected instructions, particularly when executed in parallel by multi-threaded applications, due to increased latency introduced by the security checks and the effective serialisation of affected instructions across cores. Intel introduced an opt-out option, configurable via the IA32_MCU_OPT_CTRL MSR on each logical processor, which improves performance by disabling the additional security checks for instructions executing outside of an SGX enclave.

See also

External links

Notes and References

  1. Web site: Intel Digital Random Number Generator (DRNG): Software Implementation Guide, Revision 1.1 . . 2012-08-07 . 2012-11-25.
  2. Web site: What is Intel® Secure Key Technology?. 2020-09-23. Intel. en.
  3. Web site: Find out about Intel's new RDRAND Instruction. . Hofemeier . Gael . 2011-06-22 . Intel Developer Zone Blogs . 30 December 2013 .
  4. Web site: AMD64 Architecture Programmer's Manual Volume 3: General-Purpose and System Instructions . June 2015 . AMD Developer Guides, Manuals & ISA Documents . 16 October 2015.
  5. Barker . Elaine . Kelsey . John . Recommendation for Random Number Generation Using Deterministic Random Bit Generators . . January 2012 . 10.6028/NIST.SP.800-90A . September 16, 2013.
  6. Web site: Analysis of Intel's Ivy Bridge Digital Random Number Generator . Hamburg . Mike . Kocher . Paul . Marson . Mark . 2012-03-12 . Cryptography Research, Inc. . 2015-08-21 . dead . https://web.archive.org/web/20141230024150/http://www.cryptography.com/public/pdf/Intel_TRNG_Report_20120312.pdf . 2014-12-30.
  7. Web site: Introduction to Intel AES-NI and Intel SecureKey Instructions . Hofemeier . Gael . 2012-07-26 . Intel Developer Zone . Intel . 2015-10-24.
  8. Web site: AMD Starts Linux Enablement On Next-Gen "Zen" Architecture - Phoronix. www.phoronix.com. 2015-10-25.
  9. Web site: Volume 1, Section 7.3.17, 'Random Number Generator Instruction' . Intel® 64 and IA-32 Architectures Software Developer’s Manual Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B and 3C . Intel Corporation . 24 June 2013 . 177 . June 2013 . All Intel processors that support the RDRAND instruction indicate the availability of the RDRAND instruction via reporting CPUID.01H:ECX.RDRAND[bit 30] = 1.
  10. Web site: AMD64 Architecture Programmer's Manual Volume 3: General-Purpose and System Instructions . AMD . 15 October 2015 . 278 . June 2015 . Support for the RDRAND instruction is optional. On processors that support the instruction, CPUID Fn0000_0001_ECX[RDRAND] = 1.
  11. Web site: Volume 1, Section 7.3.17, 'Random Number Generator Instruction' . Intel® 64 and IA-32 Architectures Software Developer’s Manual Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B and 3C . Intel Corporation . 25 October 2015 . 177 . June 2013 . All Intel processors that support the RDSEED instruction indicate the availability of the RDSEED instruction via reporting CPUID.(EAX=07H, ECX=0H):EBX.RDSEED[bit 18] = 1.
  12. Web site: Intel® Digital Random Number Generator (DRNG) Software Implementation Guide . Software.intel.com . 2014-01-30.
  13. Greg . Taylor . George . Cox . Behind Intel's New Random-Number Generator . https://web.archive.org/web/20110906190416/http://spectrum.ieee.org/computing/hardware/behind-intels-new-randomnumber-generator/0 . dead . September 6, 2011 . . September 2011.
  14. Web site: The Difference Between RDRAND and RDSEED . software.intel.com . Intel Corporation . 1 January 2014 . John Mechalas . November 2012.
  15. Web site: Mechalas . John . Intel Digital Random Number Generator (DRNG) Software Implementation Guide, Section 3.2.1 Entropy Source (ES) . Intel Software . Intel . 18 February 2015.
  16. https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide says 800 megabytes, which is 6.4 gigabits per second.
  17. The simplest 64-bit implementation of Xorshift has 3 XORs and 3 shifts; if these are executed in a tight loop on 4 cores at 2 GHz, the throughput is 80 Gb/s. In practice it will be less due to load/store overheads etc, but is still likely to exceed the 6.4 Gb/s of RDRAND. On the other hand, the quality of RDRAND's numbers should be higher than that of a software PRNG like Xorshift.
  18. http://www.agner.org/optimize/instruction_tables.pdf
  19. Route . Matthew . Radio-flaring Ultracool Dwarf Population Synthesis . The Astrophysical Journal . August 10, 2017 . 845 . 1 . 66 . 10.3847/1538-4357/aa7ede . 1707.02212. 2017ApJ...845...66R . 118895524 . free .
  20. Web site: x86 intrinsics list. 2020-05-07 . 2020-02-28. docs.microsoft.com.
  21. Web site: X86 Built-in Functions - Using the GNU Compiler Collection (GCC).
  22. Web site: Intel® C++ Compiler 19.1 Developer Guide and Reference . 2019-12-23.
  23. Intel Secure Key-Powered Radio-flaring Ultracool Dwarf Population Synthesis . American Astronomical Society Meeting #234, id. 207.01. Bulletin of the American Astronomical Society, Vol. 51, No. 4. 2019AAS...23420701R. Route. Matthew. American Astronomical Society Meeting Abstracts #234. 2019. 234.
  24. News: Perlroth. Nicole. Larson. Jeff. Shane. Scott. September 5, 2013. N.S.A. Able to Foil Basic Safeguards of Privacy on Web. The New York Times. November 15, 2017.
  25. Web site: I am so glad I resisted pressure from Intel engineers to let /dev/random rely... . September 6, 2013 . Ts'o . Theodore . https://web.archive.org/web/20180611180213/https://plus.google.com/117091380454742934025/posts/SDcoemc9V3J . 2018-06-11.
  26. Web site: Torvalds shoots down call to yank 'backdoored' Intel RDRAND in Linux crypto . 10 September 2013 . 12 March 2014 . Gavin Clarke . theregister.co.uk.
  27. Web site: RDRAND backdoor proof of concept is working! Stock kernel (3.8.13), only the RDRAND instruction is modified. . 6 December 2013 . 9 April 2015 . Taylor Hornby.
  28. DefuseSec . 377609001258598400 . 10 September 2013 . Taylor Hornby . I wrote a short dialogue explaining why Linux's use of RDRAND is problematic. http://pastebin.com/A07q3nL3 /cc @kaepora @voodooKobra . 11 January 2016.
  29. Web site: Randomness generation . 16 May 2014 . 9 April 2015 . Daniel J. Bernstein . Tanja Lange . Tanja Lange.
  30. Web site: random: mix in architectural randomness earlier in extract_buf . Ts'o . Theodore . 2013-10-10 . GitHub . en . 30 July 2021.
  31. News: FreeBSD abandoning hardware randomness . Richard Chirgwin . 2013-12-09 . The Register.
  32. Web site: FreeBSD Quarterly Status Report . Freebsd.org . 2014-01-30.
  33. Web site: random(4) . 2020-09-25 . www.freebsd.org.
  34. Web site: Ragab . Hany . Milburn . Alyssa . Razavi . Kaveh . Bos . Herbert . Giuffrida . Cristiano . CrossTalk: Speculative Data Leaks Across Cores Are Real . Systems and Network Security Group, Vrije Universiteit Amsterdam (VUSec) . 26 December 2020.
  35. Web site: VUSec RIDL cpuid_leak PoC, modified to leak rdrand output . GitHub . 26 December 2020.
  36. Web site: Special Register Buffer Data Sampling . Intel . 26 December 2020.
  37. Web site: Processors Affected: Special Register Buffer Data Sampling . Intel Developer Zone . 26 December 2020.