EMZETT.
Login

Entropy in cryptography

In short: Entropy measures how unpredictable a value is. Secure keys need entropy, that is real randomness that an attacker cannot guess.

In more detail: It is measured in bits: a value with n bits of entropy can be guessed only with about 2ⁿ attempts. A “128-bit key” from a predictable random generator really has far less.

In Depth

  • Sources: Timing of key presses and mouse movements, disk and network events, hardware noise, CPU instructions such as RDRAND.
  • Operating system: The kernel collects entropy in a pool and delivers secure random numbers from it via /dev/urandom and getrandom(). Modern Linux kernels can do so shortly after boot.
  • Problem cases: Virtual machines and small devices right after boot have little entropy. Cloned VM images yield identical random numbers.
  • Passwords: A password of 4 random words from 7776 (Diceware) has about 51 bits, an invented pattern far fewer.
  • Rule of thumb: For keys use only the platform’s cryptographically secure functions (secrets, crypto.getRandomValues), never rand() or Math.random().

See also: random numbers: pseudo-random and true random