← Back to archive
Data Forecasting

Obtaining True Random Numbers with Intel CPUs

随机数

Intel built into its third-generation Ivy Bridge Core processors a feature that obtains hardware true random numbers using resistor thermal noise. The principle of the code here is to read a 16-bit random number directly into the rax register via assembly instruction. In 2013, Kyle Condon of the UK launched a petition on Change.org asking maintainer Linus Torvalds to remove RdRand from /dev/random in order to improve kernel security. Because RdRand is an instruction used to generate random numbers, included in the Intel 64 and IA-32 instruction set architectures, and the cryptographic standard it relies on—NIST SP800-90 set by the NSA—is suspected of containing a backdoor. Linus Torvalds responded to the petition swiftly, blasting the petitioners and calling them far too ignorant. Because in Linux systems the random number generator at /dev/random applies further randomization on top of RdRand's random numbers, which not only avoids the possibility of a backdoor but also improves the quality of the generated random numbers.

 

int rdrand16_step(uint16_t *rand)
{
	unsigned char ok;

	/* rdrand dx */
	__asm
	{
		volatile(".byte 0x0f,0xc7,0xf0; setc %1"
		: "=a" (*rand), "=qm" (ok)
			:
			: "dx"
			);
	}

	return ok;
}

 

There are also ready-made JAVA libraries online: https://github.com/cambecc/drnglib

 

Written by Master Sanfu on June 2, 2016. Please credit the source if you share.

Translation Notice: This English version was translated with AI assistance. Specialized, historical, religious, or culturally sensitive terms may contain nuances, inaccuracies, or debatable wording. In case of ambiguity or discrepancy, the original Chinese text shall prevail.