man(7)

πŸ“¦ version 2.1.6, in epel 10, epel 9, fedora 43, fedora 44

πŸ‘‘ rdrand-gen β€” man(7)

okay bestie, so this is the man(7) page for rdrand-gen, and it's giving "I asked my CPU for random numbers and it actually delivered." Intel's hardware RNG, straight off the silicon. Let's get into it πŸ’–


✨ NAME ✨

rdrand-gen β€” generate randomness by using RdRand on Intel's CPUs. no cap, that's literally the whole job 🎲


🌸 SYNOPSIS 🌸

rdrand-gen [--amount NUM] [--method NAME] [--output FILE]
[--threads NUM] [--aes-ctr [--aes-keys FILE]] [--verbose] [--version]
[--help]

πŸ¦‹ DESCRIPTION πŸ¦‹

RdRand is an instruction that hands you random numbers from an Intel on-chip hardware random number generator. It's available on Ivy Bridge and later processors, so if your CPU is ancient, sorry bestie, no dice.

The way it works is cascade construction β€” a HW RNG running at 3Gbps combined with a CSPRNG, with every single component sealed up on the CPU itself. The entropy source is a metastable circuit whose behavior is unpredictable and based on thermal noise 🌑️✨. That entropy gets fed into a 3:1 compression ratio entropy extractor (aka a whitener) based on AES-CBC-MAC. Online statistical tests run right at this stage, and only the high quality random data makes it through as the seed for a cryptographically secure SP800-90 AES-CTR DRBG compliant PRNG. This generator produces a maximum of 512 128-bit AES blocks before it gets reseeded. According to the documentation, 512 blocks is the upper limit for a reseed β€” but in practice it reseeds much more frequently. lowkey overachiever behavior.

ngl, even though the statistical tests didn't reveal any flaws in RdRand's output, its internal operation cannot be verified β€” and there's a possibility for a backdoor to be built into it. 🚨 Not saying it's there. Just saying nobody can check. iykyk.

So rdrand-gen is a simple application for generating randomness on Intel's CPUs (Ivy Bridge and newer) using the HW RNG on the CPU. It can generate using three methods:

  • Default, get_bytes β€” the fastest one. On a laptop with a Core i7, about 200 MiB/s in one thread. It simply pulls randomness out of the HW RNG. ⚑
  • reseed_delay and reseed_skip β€” the two slow but more secure methods. Both of these enforce a full regeneration of the CPU's pool before each single value that gets pushed out. πŸ’…

Here's the tea on those two:

  • reseed_delay puts in small delays of 20 microseconds β€” long enough to let the HW reseed RdRand's internal generator with new thermal-noise-based entropy, so two consequent values returned by reseed_delay are guaranteed to be produced with a different seed. 🧚
  • reseed_skip takes one of 1025 64bit values (that's the size of the inner pool) and throws away the rest, which forces the HW to reseed. πŸ—‘οΈ

The performance of these reseeding methods is about 1/1000 of the default one. And it differs on every machine β€” on one machine reseed_skip is faster than reseed_delay, while on another one it can be the other way around. vibe check your own hardware, fr fr.

If aes-ctr is set, then the output of the RdRand instruction is encrypted with AES-CTR from OpenSSL. It can either use a random key, or you can hand it a set of keys and nonces to use via the aes-keys parameter. If AES isn't enabled by that first flag, the keys are ignored. πŸš«πŸ”‘

πŸ” the key file syntax, bestie πŸ”

On each line is a hexadecimal string containing a key and a nonce. There can be 128 lines at max. The length of a single key is twice that of the nonce, so if K stands for a key character and N for a nonce, a single line in the key file will look like the following:

KKKKNN

24 bytes (48 characters) for a key and a nonce represents a 128bit key. This is also the only currently supported length of the key. πŸ‘€ See Examples for a simple way of generating the key file.


πŸ’… OPTIONS πŸ’…

  • --help, -h β€” print this help. 🫢
  • --amount, -n NUM β€” generate the given amount of bytes. Suffixes: K, M, G, T. Without the option, or when it's 0, generate an unlimited amount. ♾️
  • --method, -m NAME β€” use method NAME (default is get_bytes, the others are reseed_skip and reseed_delay).
  • --output, -o FILE β€” save the generated data to the file. πŸ’Ύ
  • --threads, -t NUM β€” run the generator in NUM threads (default 2).
  • --aes-ctr, -a β€” encrypt the output with AES-CTR. πŸ”’
  • --aes-keys, -k FILE β€” use the given key file for the AES encryption instead of a random one. Works only when -a is set.
  • --verbose, -v β€” be verbose (it will print on stderr).
  • --version, -V β€” print version.
heads up: the AES keys in the file for the -k argument have to be 24 bytes long in hexadecimal form.

🌈 EXAMPLES 🌈

Write 10.5MB of random data to the file /tmp/random πŸ“

rdrand-gen -n 10.5M -o /tmp/random

Generate 20 random passwords of length 20 built from all letters and digits. Use the secure get_uint64_array_reseed_skip method.

(rdrand-gen -n2k -m reseed_skip | tr -cd '[:alnum:]' | fold -w 20 &&
echo ) | head -20

Create a GPG encrypted keyfile for aespipe.

Encrypt:

tar -cvf - files... | bzip2 | aespipe -w 10 -K keyfile.gpg >archive.aes

Decrypt:

aespipe -d -K keyfile.gpg < /tmp/archive.aes | bzip2 -d -q | tar -tvf -
rdrand-gen -n3705 -m reseed_skip | uuencode -m - | head -n 66 | tail -n
65 | \
gpg --symmetric -a > keyfile.gpg

Test the randomness of the generated data with the dieharder test suite πŸ”₯

rdrand-gen | dieharder -g 200 -a

Test the randomness of the generated data with PractRand

rdrand-gen | practrand-RNG_test stdin8 -tlmax 4G

Measure the speed of generation.

rdrand-gen | pv > /dev/null

Create a key file for AES encryption

head -n 3100 /dev/random | xxd -p -c 24 | head -n 129 | tail -n 128 >
keys.txt

Create the keys and pass them to rdrand-gen without saving the keys on disk (iconic, honestly πŸ‘‘)

rdrand-gen -a -k <(head -n 3100 /dev/random | \
xxd -p -c 24 | head -n 129 | tail -n 128)

⭐ SEE ALSO ⭐

librdrand(3) librdrand-aes(3)


πŸ’€ BUGS πŸ’€

No known bugs. (not me being shocked β€” we love a clean record 😭✨)


πŸŽ€ AUTHOR πŸŽ€

Jan Tulak (jan@tulak.me) and Jiri Hladky (hladky.jiri@gmail.com) β€” absolute legends for building this 🫢


okay that's the whole page, and yes we ate πŸ’– this is version 1.2, dated 24 April 2014, and it's the rdrand-gen man page. go forth and generate, bestie πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from