liveBook · Manning

Entropy

As explained in Hacking Cryptography

Entropy is a measure of uncertainty in a probability distribution, calculated as the negative sum of each outcome probability multiplied by its logarithmic probability.

Entropy measures how unpredictable a probability distribution is. For outcomes with probabilities p₁ through pₙ, compute it as the negative sum of each probability multiplied by its base-2 logarithm. The result is measured in bits: higher entropy means less ability to predict the next outcome. section 2.1.2

Equation 2.2
\[\begin{aligned} H(X) &= -\sum_{x \in X} p_x \log_2 p_x \notag\\ &= - p_{1} \times \log_2 (p_{1}) - p_{2} \times \log_2 (p_{2}) - ... p_{n} \times \log_2 (p_{n}) \label{equation:entropy-binary-log} \end{aligned}\]

Use the binary-log formula to total the uncertainty contributed by every possible outcome in a distribution. section 2.1.2

Biased coin toss

A fair coin has 1 bit of entropy because heads and tails are equally likely. Ten successive fair tosses have 10 bits. Bias reduces entropy: probabilities of 0.75 and 0.25 produce about 0.81 bits, while a coin that always lands tails has 0 bits. Entropy therefore measures uncertainty, not merely the number of named outcomes. section 2.1.2 section 2.1.2

When assessing randomness for cryptography, treat entropy as an engineering requirement:

  • Prefer a uniform output distribution, which maximizes an RNG’s entropy. section 2.3
  • Model both the entropy rate and generation rate of a physical source; the model assesses quality without predicting its actual output bits. section 2.2.1
  • Continuously health-test raw physical output and stop generation if the tests fail. section 2.2.1 section 10.2
  • Condition biased raw bits with a randomness extractor, then use the resulting quality entropy to seed and periodically reseed a CSPRNG. section 10.2

Poor entropy can defeat an otherwise sound cryptographic design. Encryption relies on randomness to produce different ciphertexts for the same plaintext, and password storage uses random salts. In ECDSA, guessing only a few bytes of the signing nonce can break security; selecting a weak randomness source nullifies the guarantees expected from the main algorithm. section 10.2

How Hacking Cryptography covers it

How deep it goes
Defines binary-log entropy, calculates biased-coin values, and applies entropy to TRNG health testing and CSPRNG seeding.
Examples
Uses fair and biased coin tosses, including 0.75/0.25 probabilities yielding about 0.81 bits.
What it assumes
Introduces probabilities and base-2 logarithms while explaining that outcome probabilities sum to one.
What you can do after
Evaluate/understand how probability bias lowers unpredictability and why cryptographic systems require monitored quality entropy.
How it connects
Connects entropy to random number generators, TRNGs, CSPRNGs, randomness extractors, ECDSA, and cryptographic nonces.

Also explained in

Compare how 13 books explain entropy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hacking Cryptography. The section links point to the parts of the book it draws on.