SlideShare a Scribd company logo
1 of 25
Download to read offline
The entropic principle
/dev/u?random and NetBSD
Taylor ‘Riastradh’ Campbell
campbell@mumble.net
riastradh@NetBSD.org
EuroBSDcon 2014
Sofia, Bulgaria
September 28, 2014
Use /dev/urandom.
What is /dev/u?random?
/dev/random and /dev/urandom are device files on all
modern Unix systems.
Can’t predict what you will read from them.
(Writes influence future reads.)
Reading from /dev/random sometimes blocks.
Much cargo-cult voodoo surrounds /dev/u?random.
Unpredictability matters
There are bad guys on the internet.
They want to eavesdrop on our conversations.
They want to intercept our conversations.
We need crypto to defend against this, and crypto needs
unpredictable secrets.
Unpredictability matters
What happens if you use crypto with predictable secrets?
Smart cards generated keys for Taiwan’s national identity
database with broken RNGs leading to repeated and
factorable keys: http://smartfacts.cr.yp.to/
Sony used ECDSA with a broken RNG to sign Playstation
firmware updates, revealing the signing key.
Millions of embedded devices on the internet have private
RSA keys with factors in common generated from the same
RNG states: https://factorable.net/ (Mining Your P’s
and Q’s).
The NSA chose to backdoor the US’s pseudorandom number
generation standard, NIST SP800-90A, with Dual EC DRBG.
Security modelling
APPLICATION: Generate bits with uniform distribution for
user programs.
THREAT MODEL(S):
Attacker may read other bits from /dev/u?random.
Attacker may influence /dev/u?random.
Attacker may compromise the kernel and get the internal state
of /dev/u?random.
SECURITY PROPERTY: Attacker must not predict any
outputs not witnessed!
(Can’t attain the security property against attacker who
compromises the kernel, but some people worry about theoretically
approximating it for some reason.)
Formalizing unpredictability
Random variable X: observable physical system which can
take on possible values x0, x1, . . . , xn−1.
Probability that we observe X to have value x: Pr[X = x].
Observation of X may not be predictable, but how do we
formalize measuring how unpredictable?
Formalizing unpredictability: Shannon entropy
Popular approach to measure unpredictability of X is Shannon
entropy, in units of bits:
H[X] = −
i
Pr[X = xi ] log2 Pr[X = xi ],
giving average bits of information per bit of observation of X.
If X is drawn from {00, 01, 10, 11}, and
Pr[X = 00] = Pr[X = 11] = 1/2,
Pr[X = 01] = Pr[X = 10] = 0,
then H[X] = 1, so since an observation of X has two bits, X
has half a bit of information per bit of observation.
Guessing this is only as hard as guessing what a single coin
flip was, not two coin flips in a row.
Formalizing unpredictability: not Shannon entropy
Shannon entropy is no good for crypto: if there are 2255 + 1
possibilities for X, and
Pr[X = x] =
1/2, if x = ‘hunter2’;
1/2256 otherwise,
(1)
then H[X] ≈ 128, but I don’t have to try 2127 possibilities
before I can probably guess your password — I have a pretty
good guess what it is!
Formalizing unpredictability: min-entropy
Crypto instead uses min-entropy:
H∞[X] = − max
i
log2 Pr[X = xi ]. (2)
Min-entropy estimates the difficulty of the best strategy at
guessing X.
If X is drawn uniformly from k-bit strings, then H∞[X] = k,
which is as good as you can get!
Standard crypto practice is to use uniform distributions with
k = 128 or k = 256 for key material.
/dev/u?random as random variable
Kernel’s job is to make the random variable of reading k bits
from /dev/u?random have k bits of entropy.
How does it choose the bits?
Computer programs (single-threaded) are supposed to be
deterministic!
Entropy sources
Computers make nondeterministic observations: clock skew,
network packets, keyboard input, disk seek times.
% gpg --gen-key
...
Please bang on the keyboard like a monkey
to ensure there’s enough entropy!
These entropy sources are random variables with highly
nonuniform distribution.
Attacker may influence them: send regular network packets,
bang on the keyboard like a robot, &c.
Entropy pooling and distribution
Kernel combines entropy sources with crypto magic called
entropy extractors.
Kernel uses output as seed for deterministic pseudorandom
number generator when you read from /dev/u?random.
What if there’s not much entropy?
Your system autogenerated sshd keys from /dev/u?random
before you’ve had a chance to bang on the keyboard like a
monkey!
Keys are predictable! Bad guys can guess them and log in!
Even Debian is laughing at you! How do we prevent this?
What if there’s not much entropy?
Na¨ıve answer: wait until system is unpredictable enough.
/dev/random traditionally estimates how much entropy the
system has observed, and blocks until it reaches a threshold.
Use it as an ‘unpredictability barrier’: read once from
/dev/random and once it unblocks, use /dev/urandom to
generate keys.
/dev/urandom never blocks: whatever has been fed into the
entropy pool, the kernel uses it to seed a pseudorandom
number generator and generate output.
What if there’s not much entropy?
Problem: Can’t say whether a state is unpredictable. Can only say
whether a process is unpredictable.
(Obligatory Dilbert reference.)
Estimating this is a hard problem! No good solution. Typical
approaches are ad hoc.
Running out of entropy?
/dev/random also traditionally blocks sometimes long after
boot.
Original theory was if you read too much from it you run out
of entropy, so you’d better wait for more.
But entropy is not a scarce resource like oil.
Entropy is a property of a physical process.
So why block after boot?
Topping off the entropy tank
/dev/random blocking after boot is still useful!
If you use it as an unpredictability barrier, you keep your
blocking code paths exercised.
If you use it to generate keys always, you will notice when your
application blocks — instead of being told two years from now
that it doesn’t work on an embedded system you never even
heard of because it doesn’t have enough entropy at boot!
But most applications just need /dev/urandom.
What if there is no entropy?
What if there are no entropy sources?
No disk, no mouse, no keyboard, no monkey.
Kernel is totally deterministic: can’t be unpredictable.
Can’t usefully serve /dev/u?random.
Example: embedded appliances (Mining P’s & Q’s).
Solution: save entropy from the factory installer onto small
(32-byte) nonvolatile storage on install and shutdown, restore
on boot.
This system engineering avoids need for /dev/random as
unpredictability barrier.
Exotic threat models
Attacker can influence network packet timings? (Easy.)
Attacker can influence keytrokes and timings?
Attacker can compromise your CPU? (Paranoid view of Intel
rdrand!)
Good entropy extractors thwart manipulation of one entropy source
or another.
Hardware random number generators
PCI devices: HIFN 7751, Broadcom BCM58xx.
SoC on-board devices: Broadcom BCM2385 (Raspberry Pi).
CPU instructions: Intel rdrand, VIA PadLock.
Hardware random number generators
. . . The coin in your trouser pocket:
% echo hhhtttthhththttthhht... >> /dev/random
NetBSD
Current code written mainly by Thor Lancelot Simon and me.
/dev/u?random uses per-open or per-CPU pseudorandom
number generator state, so it scales.
Kernel uses slow NIST CTR DRBG with AES-128 for key
material and /dev/u?random: attacker must never predict
unseen outputs.
Kernel uses fast ChaCha8 without backtracking resistance for
non-key material, e.g. NFS transaction ids: attacker must not
predict new outputs ahead of time, but may predict old ones.
Userland arc4random(3) API soon to be reimplemented with
per-thread state and ChaCha8 instead of global RC4.
(Let me know if you’ve heard of arc4random(3) being used
for key material! I wouldn’t recommend it!)
Questions?
(Use /dev/urandom!)
Appendix: Entropy game!
http://www.loper-os.org/bad-at-entropy/manmach.html
My password manager:
{ tr -cd ’[:graph:]’ < /dev/urandom | head -c 20; } | 
scrypt enc /dev/stdin password.scrypt

More Related Content

Similar to The entropic principle: /dev/u?random and NetBSD by Taylor R Campbell

A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKINGA BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
Silvio Cesare
 
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Simplilearn
 
Security & ethical hacking
Security & ethical hackingSecurity & ethical hacking
Security & ethical hacking
Amanpreet Singh
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
Logicaltrust pl
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
Yury Chemerkin
 
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
RootedCON
 

Similar to The entropic principle: /dev/u?random and NetBSD by Taylor R Campbell (20)

Defeating the entropy downgrade attack
Defeating the entropy downgrade attackDefeating the entropy downgrade attack
Defeating the entropy downgrade attack
 
CNIT 141: 2. Randomness
CNIT 141: 2. RandomnessCNIT 141: 2. Randomness
CNIT 141: 2. Randomness
 
Random
RandomRandom
Random
 
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKINGA BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
 
Breaking paravirtualized devices
Breaking paravirtualized devicesBreaking paravirtualized devices
Breaking paravirtualized devices
 
PUF_lecture1.pdf
PUF_lecture1.pdfPUF_lecture1.pdf
PUF_lecture1.pdf
 
Hacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortHacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades short
 
Deep Networks with Neuromorphic VLSI devices
Deep Networks with Neuromorphic VLSI devicesDeep Networks with Neuromorphic VLSI devices
Deep Networks with Neuromorphic VLSI devices
 
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
 
Если нашлась одна ошибка — есть и другие. Один способ выявить «наследуемые» у...
Если нашлась одна ошибка — есть и другие. Один способ выявить «наследуемые» у...Если нашлась одна ошибка — есть и другие. Один способ выявить «наследуемые» у...
Если нашлась одна ошибка — есть и другие. Один способ выявить «наследуемые» у...
 
Secure coding for developers
Secure coding for developersSecure coding for developers
Secure coding for developers
 
Killer Bugs From Outer Space
Killer Bugs From Outer SpaceKiller Bugs From Outer Space
Killer Bugs From Outer Space
 
Security & ethical hacking
Security & ethical hackingSecurity & ethical hacking
Security & ethical hacking
 
Much ado about randomness. What is really a random number?
Much ado about randomness. What is really a random number?Much ado about randomness. What is really a random number?
Much ado about randomness. What is really a random number?
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
 
Neural Networks in the Wild: Handwriting Recognition
Neural Networks in the Wild: Handwriting RecognitionNeural Networks in the Wild: Handwriting Recognition
Neural Networks in the Wild: Handwriting Recognition
 
[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis
 
Ransomware for fun and non-profit
Ransomware for fun and non-profitRansomware for fun and non-profit
Ransomware for fun and non-profit
 
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
 

More from eurobsdcon

OpenStack and OpenContrail for FreeBSD platform by Michał Dubiel
OpenStack and OpenContrail for FreeBSD platform by Michał DubielOpenStack and OpenContrail for FreeBSD platform by Michał Dubiel
OpenStack and OpenContrail for FreeBSD platform by Michał Dubiel
eurobsdcon
 
Porting NetBSD to the LatticeMico32 open source CPU by Yann Sionneau
Porting NetBSD to the LatticeMico32 open source CPU by Yann SionneauPorting NetBSD to the LatticeMico32 open source CPU by Yann Sionneau
Porting NetBSD to the LatticeMico32 open source CPU by Yann Sionneau
eurobsdcon
 
Bugs Ex Ante by Kristaps Dzonsons
Bugs Ex Ante by Kristaps DzonsonsBugs Ex Ante by Kristaps Dzonsons
Bugs Ex Ante by Kristaps Dzonsons
eurobsdcon
 

More from eurobsdcon (20)

EuroBSDCon 2014 Program Front
EuroBSDCon 2014 Program FrontEuroBSDCon 2014 Program Front
EuroBSDCon 2014 Program Front
 
EuroBSDCon 2014 tutorials program Thursday & Friday
EuroBSDCon 2014 tutorials program Thursday & FridayEuroBSDCon 2014 tutorials program Thursday & Friday
EuroBSDCon 2014 tutorials program Thursday & Friday
 
EuroBSDCon 2014 Sofia Welcome
EuroBSDCon 2014 Sofia WelcomeEuroBSDCon 2014 Sofia Welcome
EuroBSDCon 2014 Sofia Welcome
 
EuroBSDCon 2014 Sofia Closing talk
EuroBSDCon 2014 Sofia Closing talkEuroBSDCon 2014 Sofia Closing talk
EuroBSDCon 2014 Sofia Closing talk
 
Submitting documents anonymously by Atanas Chobanov
Submitting documents anonymously by Atanas ChobanovSubmitting documents anonymously by Atanas Chobanov
Submitting documents anonymously by Atanas Chobanov
 
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois TigeotPorting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
 
University of Oslo's TSD service - storing sensitive & restricted data by D...
  University of Oslo's TSD service - storing sensitive & restricted data by D...  University of Oslo's TSD service - storing sensitive & restricted data by D...
University of Oslo's TSD service - storing sensitive & restricted data by D...
 
secure lazy binding, and the 64bit time_t development process by Philip Guenther
secure lazy binding, and the 64bit time_t development process by Philip Guenthersecure lazy binding, and the 64bit time_t development process by Philip Guenther
secure lazy binding, and the 64bit time_t development process by Philip Guenther
 
The LLDB Debugger in FreeBSD by Ed Maste
The LLDB Debugger in FreeBSD by Ed MasteThe LLDB Debugger in FreeBSD by Ed Maste
The LLDB Debugger in FreeBSD by Ed Maste
 
Porting Valgrind to NetBSD and OpenBSD by Masao Uebayashi
Porting Valgrind to NetBSD and OpenBSD by Masao UebayashiPorting Valgrind to NetBSD and OpenBSD by Masao Uebayashi
Porting Valgrind to NetBSD and OpenBSD by Masao Uebayashi
 
Multiplatform JIT Code Generator for NetBSD by Alexander Nasonov
Multiplatform JIT Code Generator for NetBSD by Alexander NasonovMultiplatform JIT Code Generator for NetBSD by Alexander Nasonov
Multiplatform JIT Code Generator for NetBSD by Alexander Nasonov
 
OpenStack and OpenContrail for FreeBSD platform by Michał Dubiel
OpenStack and OpenContrail for FreeBSD platform by Michał DubielOpenStack and OpenContrail for FreeBSD platform by Michał Dubiel
OpenStack and OpenContrail for FreeBSD platform by Michał Dubiel
 
Porting NetBSD to the LatticeMico32 open source CPU by Yann Sionneau
Porting NetBSD to the LatticeMico32 open source CPU by Yann SionneauPorting NetBSD to the LatticeMico32 open source CPU by Yann Sionneau
Porting NetBSD to the LatticeMico32 open source CPU by Yann Sionneau
 
Smartcom's control plane software, a customized version of FreeBSD by Boris A...
Smartcom's control plane software, a customized version of FreeBSD by Boris A...Smartcom's control plane software, a customized version of FreeBSD by Boris A...
Smartcom's control plane software, a customized version of FreeBSD by Boris A...
 
Bugs Ex Ante by Kristaps Dzonsons
Bugs Ex Ante by Kristaps DzonsonsBugs Ex Ante by Kristaps Dzonsons
Bugs Ex Ante by Kristaps Dzonsons
 
Cross Building the FreeBSD ports tree by Baptiste Daroussin
Cross Building the FreeBSD ports tree by Baptiste DaroussinCross Building the FreeBSD ports tree by Baptiste Daroussin
Cross Building the FreeBSD ports tree by Baptiste Daroussin
 
Building packages through emulation by Sean Bruno
Building packages through emulation by Sean BrunoBuilding packages through emulation by Sean Bruno
Building packages through emulation by Sean Bruno
 
Making OpenBSD Useful on the Octeon Network Gear by Paul Irofti
Making OpenBSD Useful on the Octeon Network Gear by Paul IroftiMaking OpenBSD Useful on the Octeon Network Gear by Paul Irofti
Making OpenBSD Useful on the Octeon Network Gear by Paul Irofti
 
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. TanenbaumA Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
 
Using routing domains / routing tables in a production network by Peter Hessler
Using routing domains / routing tables in a production network by Peter HesslerUsing routing domains / routing tables in a production network by Peter Hessler
Using routing domains / routing tables in a production network by Peter Hessler
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

The entropic principle: /dev/u?random and NetBSD by Taylor R Campbell

  • 1. The entropic principle /dev/u?random and NetBSD Taylor ‘Riastradh’ Campbell campbell@mumble.net riastradh@NetBSD.org EuroBSDcon 2014 Sofia, Bulgaria September 28, 2014
  • 3. What is /dev/u?random? /dev/random and /dev/urandom are device files on all modern Unix systems. Can’t predict what you will read from them. (Writes influence future reads.) Reading from /dev/random sometimes blocks. Much cargo-cult voodoo surrounds /dev/u?random.
  • 4. Unpredictability matters There are bad guys on the internet. They want to eavesdrop on our conversations. They want to intercept our conversations. We need crypto to defend against this, and crypto needs unpredictable secrets.
  • 5. Unpredictability matters What happens if you use crypto with predictable secrets? Smart cards generated keys for Taiwan’s national identity database with broken RNGs leading to repeated and factorable keys: http://smartfacts.cr.yp.to/ Sony used ECDSA with a broken RNG to sign Playstation firmware updates, revealing the signing key. Millions of embedded devices on the internet have private RSA keys with factors in common generated from the same RNG states: https://factorable.net/ (Mining Your P’s and Q’s). The NSA chose to backdoor the US’s pseudorandom number generation standard, NIST SP800-90A, with Dual EC DRBG.
  • 6. Security modelling APPLICATION: Generate bits with uniform distribution for user programs. THREAT MODEL(S): Attacker may read other bits from /dev/u?random. Attacker may influence /dev/u?random. Attacker may compromise the kernel and get the internal state of /dev/u?random. SECURITY PROPERTY: Attacker must not predict any outputs not witnessed! (Can’t attain the security property against attacker who compromises the kernel, but some people worry about theoretically approximating it for some reason.)
  • 7. Formalizing unpredictability Random variable X: observable physical system which can take on possible values x0, x1, . . . , xn−1. Probability that we observe X to have value x: Pr[X = x]. Observation of X may not be predictable, but how do we formalize measuring how unpredictable?
  • 8. Formalizing unpredictability: Shannon entropy Popular approach to measure unpredictability of X is Shannon entropy, in units of bits: H[X] = − i Pr[X = xi ] log2 Pr[X = xi ], giving average bits of information per bit of observation of X. If X is drawn from {00, 01, 10, 11}, and Pr[X = 00] = Pr[X = 11] = 1/2, Pr[X = 01] = Pr[X = 10] = 0, then H[X] = 1, so since an observation of X has two bits, X has half a bit of information per bit of observation. Guessing this is only as hard as guessing what a single coin flip was, not two coin flips in a row.
  • 9. Formalizing unpredictability: not Shannon entropy Shannon entropy is no good for crypto: if there are 2255 + 1 possibilities for X, and Pr[X = x] = 1/2, if x = ‘hunter2’; 1/2256 otherwise, (1) then H[X] ≈ 128, but I don’t have to try 2127 possibilities before I can probably guess your password — I have a pretty good guess what it is!
  • 10. Formalizing unpredictability: min-entropy Crypto instead uses min-entropy: H∞[X] = − max i log2 Pr[X = xi ]. (2) Min-entropy estimates the difficulty of the best strategy at guessing X. If X is drawn uniformly from k-bit strings, then H∞[X] = k, which is as good as you can get! Standard crypto practice is to use uniform distributions with k = 128 or k = 256 for key material.
  • 11. /dev/u?random as random variable Kernel’s job is to make the random variable of reading k bits from /dev/u?random have k bits of entropy. How does it choose the bits? Computer programs (single-threaded) are supposed to be deterministic!
  • 12. Entropy sources Computers make nondeterministic observations: clock skew, network packets, keyboard input, disk seek times. % gpg --gen-key ... Please bang on the keyboard like a monkey to ensure there’s enough entropy! These entropy sources are random variables with highly nonuniform distribution. Attacker may influence them: send regular network packets, bang on the keyboard like a robot, &c.
  • 13. Entropy pooling and distribution Kernel combines entropy sources with crypto magic called entropy extractors. Kernel uses output as seed for deterministic pseudorandom number generator when you read from /dev/u?random.
  • 14. What if there’s not much entropy? Your system autogenerated sshd keys from /dev/u?random before you’ve had a chance to bang on the keyboard like a monkey! Keys are predictable! Bad guys can guess them and log in! Even Debian is laughing at you! How do we prevent this?
  • 15. What if there’s not much entropy? Na¨ıve answer: wait until system is unpredictable enough. /dev/random traditionally estimates how much entropy the system has observed, and blocks until it reaches a threshold. Use it as an ‘unpredictability barrier’: read once from /dev/random and once it unblocks, use /dev/urandom to generate keys. /dev/urandom never blocks: whatever has been fed into the entropy pool, the kernel uses it to seed a pseudorandom number generator and generate output.
  • 16. What if there’s not much entropy? Problem: Can’t say whether a state is unpredictable. Can only say whether a process is unpredictable. (Obligatory Dilbert reference.) Estimating this is a hard problem! No good solution. Typical approaches are ad hoc.
  • 17. Running out of entropy? /dev/random also traditionally blocks sometimes long after boot. Original theory was if you read too much from it you run out of entropy, so you’d better wait for more. But entropy is not a scarce resource like oil. Entropy is a property of a physical process. So why block after boot?
  • 18. Topping off the entropy tank /dev/random blocking after boot is still useful! If you use it as an unpredictability barrier, you keep your blocking code paths exercised. If you use it to generate keys always, you will notice when your application blocks — instead of being told two years from now that it doesn’t work on an embedded system you never even heard of because it doesn’t have enough entropy at boot! But most applications just need /dev/urandom.
  • 19. What if there is no entropy? What if there are no entropy sources? No disk, no mouse, no keyboard, no monkey. Kernel is totally deterministic: can’t be unpredictable. Can’t usefully serve /dev/u?random. Example: embedded appliances (Mining P’s & Q’s). Solution: save entropy from the factory installer onto small (32-byte) nonvolatile storage on install and shutdown, restore on boot. This system engineering avoids need for /dev/random as unpredictability barrier.
  • 20. Exotic threat models Attacker can influence network packet timings? (Easy.) Attacker can influence keytrokes and timings? Attacker can compromise your CPU? (Paranoid view of Intel rdrand!) Good entropy extractors thwart manipulation of one entropy source or another.
  • 21. Hardware random number generators PCI devices: HIFN 7751, Broadcom BCM58xx. SoC on-board devices: Broadcom BCM2385 (Raspberry Pi). CPU instructions: Intel rdrand, VIA PadLock.
  • 22. Hardware random number generators . . . The coin in your trouser pocket: % echo hhhtttthhththttthhht... >> /dev/random
  • 23. NetBSD Current code written mainly by Thor Lancelot Simon and me. /dev/u?random uses per-open or per-CPU pseudorandom number generator state, so it scales. Kernel uses slow NIST CTR DRBG with AES-128 for key material and /dev/u?random: attacker must never predict unseen outputs. Kernel uses fast ChaCha8 without backtracking resistance for non-key material, e.g. NFS transaction ids: attacker must not predict new outputs ahead of time, but may predict old ones. Userland arc4random(3) API soon to be reimplemented with per-thread state and ChaCha8 instead of global RC4. (Let me know if you’ve heard of arc4random(3) being used for key material! I wouldn’t recommend it!)
  • 25. Appendix: Entropy game! http://www.loper-os.org/bad-at-entropy/manmach.html My password manager: { tr -cd ’[:graph:]’ < /dev/urandom | head -c 20; } | scrypt enc /dev/stdin password.scrypt