rdrand
Read Random Number
Retrieves a hardware-generated random number.
Details
Retrieves a cryptographically secure random number from the CPU's hardware random number generator and stores it in the destination register. The CF flag is set to 1 if a random number was successfully generated within the timeout period, or cleared to 0 if the generator failed to produce a value. No other flags are affected. This instruction is available only on processors with the RDRAND extension and cannot be used in real mode.
Pseudocode Operation
temp ← hardware_RNG();
if (RNG_success) {
dest ← temp;
CF ← 1;
} else {
CF ← 0;
}
Example
Encoding
Operands
-
dest
32-bit general-purpose register (e.g. EAX)
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| NFx 0F C7 /6 | RDRAND | M | V/V | Read a 16-bit random number and store in the destination RDRAND r16 register. | |
| NFx 0F C7 /6 | RDRAND | M | V/V | Read a 32-bit random number and store in the destination RDRAND r32 register. | |
| NFx REX.W + 0F C7 /6 | RDRAND | M | V/I | Read a 64-bit random number and store in the destination RDRAND r64 register. |
Description
Operation
IF HW_RND_GEN.ready = 1 THEN CASE of operand size is 64: DEST[63:0] := HW_RND_GEN.data; operand size is 32: DEST[31:0] := HW_RND_GEN.data; operand size is 16: DEST[15:0] := HW_RND_GEN.data; ESAC CF := 1; ELSE CASE of operand size is 64: DEST[63:0] := 0; operand size is 32: DEST[31:0] := 0; operand size is 16: DEST[15:0] := 0; ESAC CF := 0; FI OF, SF, ZF, AF, PF := 0;
Intel C/C++ Compiler Intrinsic Equivalent
RDRAND int _rdrand16_step( unsigned short * ); RDRAND int _rdrand32_step( unsigned int * ); RDRAND int _rdrand64_step( unsigned __int64 *);
Flags Affected
The CF flag is set according to the result (see the “Operation” section above). The OF, SF, ZF, AF, and PF flags are set to 0. RDRAND—Read Random Number Vol. 2B 4-554