ENTROPY(7)
π« ENTROPY(7) π«
okay so this is the entropy(7) page from the Miscellaneous Information Manual, and honestly bestie, it's lowkey one of the most important pages you'll ever read, because it's all about random unpredictable secrets needed for security and that's the whole vibe of modern crypto. π
β¨ NAME β¨
entropy β random unpredictable secrets needed for security π¦
πΈ DESCRIPTION πΈ
So like. Computers need random unpredictable secrets for the security of software such as web browsers and ssh(1). That's just the tea. β
But here's the thing β computers are designed to behave in highly predictable ways, which is iconic for reproducibility and absolutely terrible for secrecy. So they rely on observations of random physical phenomena around them, called entropy sources, to derive unpredictable secrets for cryptography. It's giving "chaos is the blueprint" honestly. πͺοΈ
Some computers have reliable entropy sources β like hardware random number generators based on thermal noise in silicon circuits, which is so main character β but others may require operator intervention for security. Yeah. You. You're the operator. π«΅
π Threats π
- Web browsers and programs such as
ssh(1)rely on unpredictable secrets in cryptography to prevent eavesdropping and detect tampering of sessions over the network. No eavesdroppers allowed, periodt. π ββοΈ ssh-keygen(1)relies on unpredictable secrets to create keys that allow you to log in but keep out malicious adversaries; if an adversary could guess the key then they could impersonate you. And likeβ¦ not the impersonation arc we're going for. π- NetBSD relies on unpredictable secrets to make sure that private user data stored on nonvolatile media when memory is scarce (
swapctl(8), using'vm.swap_encrypt=1'; seesysctl(7)) cannot be recovered by forensic tools after shutdown. So your swap doesn't snitch on you after you dip. π
π§ Entropy in NetBSD π§
NetBSD gathers samples from various kinds of entropy sources, including:
- hardware random number generators
- network traffic timing
- user input (keystrokes, mouse movements, etc.)
- disk I/O latency
- environment sensors (
envsys(4))
The samples are mixed together with cryptography to yield unpredictable secrets through /dev/urandom (see rnd(4)) and related interfaces used by programs like ssh(1), Firefox, and so on. Bestie they're all sipping from the same unpredictable straw and that's the point. π₯€
NetBSD also stores a random seed at /var/db/entropy-file to carry unpredictable secrets over from one boot to the next β as long as the medium remains secret and can be updated on boot. The seed is maintained automatically by /etc/rc.d/random_seed (see rc.conf(5)). It's literally the "remember me" checkbox but for entropy. β¨
π₯ Ensuring enough entropy π₯
Entropy is measured in bits, and only 256 bits of entropy are needed for security, thanks to modern cryptography. That's it. That's the number. 256. Slay. π
To detect potentially insecure systems, NetBSD takes measures to alert the operator if there isn't definitely enough for security:
- NetBSD issues warnings on the console if there's not enough entropy when programs need it; see
rnd(4). It's giving concerned friend energy. π«Ά - The
motd(5)has a warning if there was not enough entropy when network daemons such assshd(8)first generated keys. The message of the day is officially the message of concern. - The daily security report includes an alert if there's still not enough entropy; see
security.conf(5). Daily drama report, honestly.
Since it is hard to know how unpredictable most physical systems are, only devices specifically designed to be hardware random number generators, or a seed file stored on disk, count toward these alerts. Like, only the certified-unpredictable girlies count. No posers. π«
At boot, NetBSD will wait, when 'entropy=wait' is set in rc.conf(5), or fail to single-user mode, when 'entropy=check' is set, if there is not enough entropy from any sources β including devices not designed to be unpredictable, such as the CPU cycle counter sampled by a periodic timer β provided the samples pass a simple filter called the 'entropy estimator', like other operating systems. So yeah, even the sketchy sources get a vibe check from the estimator. π΅οΈββοΈ
Sources known to be predictable, which could give a false sense of security, can be disabled from unblocking boot by setting rndctl_flags in rc.conf(5). Translation: if a source is a known liar, you can literally tell it to stop holding up the line at boot. π
Many new computers have hardware random number generators, such as RDRAND/RDSEED in Intel/AMD CPUs, or ARMv8.5-RNDRRS; virtio(4)-based virtualization platforms such as QEMU can expose entropy from the host with viornd(4); bootloader firmware such as UEFI may also expose an underlying platform's random number generator. New hardware is eating in the entropy department, no cap. π₯
However, many older computers have no reliable entropy sources. Some have the hardware, but have it off by default, such as a disabled tpm(4). Tragic. They have the gift and refuse to use it. π
On computers with no built-in reliable entropy source, you may wish to transfer a seed from another computer with rndctl(8), or manually enter samples into /dev/urandom β see below. Yes we're going there. π
π Adding entropy π
You can manually save and load seeds with the rndctl(8) tool. For example, you might use
rndctl -S seed
to save a seed from one machine, transfer it β over a medium where you are confident there are no eavesdroppers β to another machine, and load it with
rndctl -L seed
on the target machine; then run
/etc/rc.d/random_seed stop
on the target machine to ensure that the entropy will be saved for next boot, even if the system later crashes or otherwise shuts down uncleanly. rndctl -S records the number of bits of entropy in the seed so that rndctl -L can count it. It's literally a little care package of chaos. π
Bestie β that transfer medium part is not a joke. You want no eavesdroppers. Treat that seed like your most private group chat. π
Users can write data to /dev/urandom to be mixed together with all other samples. For example, no matter what entropy sources are built into a computer, you can ensure it has enough entropy (as long as there are no surveillance cameras watching you) by flipping a coin 256 times and running:
echo thttthhhhttththtttht... > /dev/urandom
Then run
/etc/rc.d/random_seed stop
to ensure that the effort will be saved for next boot. Yes, that's genuine physical-coin-flipping sweat equity going straight into the kernel. Iconic behavior, honestly. πͺ
Inputs from the superuser (uid 0) to /dev/urandom count toward the system's entropy estimate, at the maximum rate of one bit of entropy per bit of data; inputs from unprivileged users will affect subsequent outputs but will be counted as having zero entropy. So likeβ¦ root gets credit, everyone else gets vibes only. π
After adding entropy, make sure to regenerate any long-term keys that might be predictable because they were previously generated with too little entropy. For example, if 'sshd=YES' is enabled in /etc/rc.conf, then NetBSD will automatically generate ssh host keys on boot; if they were generated with too little entropy, then you may wish to delete them and create new ones before allowing anyone to log in via ssh(1). Old weak keys are not the moment. Delete and re-do. ποΈβ¨
π DIAGNOSTICS π
NetBSD may print the following warnings to the console:
WARNING: system needs entropy for security; see entropy(7)
Some process tried to draw use entropy from NetBSD, e.g. to generate a key for cryptography, before enough inputs from reliable entropy sources have been obtained. The entropy may be low enough that an adversary could guess keys by brute force. That is so not the vibe β brute-forceable keys are the enemy of the people. π
This message is rate-limited, so if you have added entropy and want to verify that the problem is resolved, you should consult the kern.entropy.needed sysctl(7) variable to confirm it is zero, rather than just look for the absence of this message; see rnd(4) for details. Do not β I repeat, do not β just assume silence means fixed. Check the actual number. Periodt. π
π SEE ALSO π
getrandom(2), arc4random(3), rnd(4), rc.conf(5), rc(8), rndctl(8)
And now the reading list, because the references are honestly a whole curriculum:
- Nadia Heninger, Zakir Durumeric, Eric Wustrow, and J. Alex Halderman, "Mining Your Ps and Qs: Detection of Widespread Weak Keys in Network Devices", Proceedings of the 21st USENIX Security Symposium, USENIX, https://www.usenix.org/conference/usenixsecurity12/technical-sessions/presentation/heninger https://factorable.net/, 205-220, August 2012.
opensslβ predictable random number generator, Debian Security Advisory, https://www.debian.org/security/2008/dsa-1571.html, 2008-05-13, DSA-1571-1.- Features/VirtIORNG, QEMU Wiki, https://wiki.qemu.org/Features/VirtIORNG, 2016-10-17.
πΈ and that's the page, bestie πΈ β this one comes to you from the Debian crew, dated June 30, 2023, and it lives in section ENTROPY(7). Go forth and be unpredictable, fr fr. ππ¦
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2021 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms