Definitionadvanced
Min-entropy leakage
Also called vulnerability-based leakage.
The leakage of a channel as the log of the ratio of an attacker's chance to guess the secret in one try after and before seeing the output.
Min-entropy leakage measures how much a channel helps an attacker who wants to guess a secret in one try. It compares the attacker's best chance of a correct guess before seeing the output, the prior vulnerability, with the best chance after seeing it, the posterior vulnerability, and reports the base-2 log of the ratio. A leakage of bits means that the output multiplies the attacker's success probability by . Geoffrey Smith proposed it in 2009 because the Shannon measures of quantitative information flow can rate a program as safe when it lets the attacker guess the secret often.
Definition
Secret, prior and channel. The secret takes values in a finite set with a prior distribution . A system is modeled as a channel from to a finite set of observable outputs, given by a matrix with ; each row sums to 1. A deterministic program has and zeros elsewhere. The joint distribution is .
Adversary. The attacker knows and , sees one output , and makes one guess of the secret. The guess wins when it equals exactly. The attacker may choose the guess as any function of . Nothing else is observed: timing, repeated runs and other side information are outside the model unless they are part of .
Vulnerabilities.
The second form of follows from Bayes' theorem, , and needs no division. is the probability that the best blind guess is right. is the probability that the best guess after seeing is right, averaged over .
Min-entropy and leakage. The min-entropy of the prior and the conditional min-entropy are
The min-entropy page defines the same quantity; the QIF pages measure it in bits, with . The min-entropy leakage of under is
The min-capacity is the worst case over priors, . The min-capacity bound proves that , reached by the uniform prior.
Computation. With secrets and outputs, the leakage costs arithmetic operations:
MIN-ENTROPY-LEAKAGE(π, C)- 1
V0 ← max over x of π[x] - 2
V1 ← 0 - 3
for each output y do - 4
V1 ← V1 + max over x of π[x] · C[x, y] - 5
return log2(V1 / V0)
The Python implementation does all of this with fractions.Fraction and takes the logarithm only at the end. Its tests check every example on this page, compare with an enumeration of all guessing strategies on 600 random channels, and compare the min-capacity formula with a search over all priors on a grid of step 1/12.
Basic facts. Each is a theorem with a short proof.
- is the success of the best strategy. A strategy is a map from outputs to guesses, and it wins with probability , with equality for .
- Leakage is never negative. Let maximize . Then , so .
- Zero leakage. if and only if one guess maximizes for every output at once, by the equality case of the previous line. So zero leakage does not mean that the output is independent of the secret; see the skewed channel below.
- Post-processing cannot increase it. If is a second channel applied to the output of , then , because the rows of sum to 1. So .
- A security guarantee. exactly, so a bound on the leakage is a bound on the attacker's one-try success: . With tries the success is at most .
Examples and non-examples
Example: the last two bits. Let be uniform on and let the program output . Then . Each of the 4 outputs has two secrets of probability , so and bits. The attacker's chance goes from to .
Example: a password check. Let be uniform on 8 values and let the output be whether equals a fixed value. The output "yes" has one secret of probability and the output "no" has seven, so and bit. For a uniform secret on values the leakage of one check is always 1 bit, while the attacker's chance grows only from to .
Example: a noisy bit. The binary symmetric channel with crossover probability copies a secret bit and flips it with probability . Under the uniform prior, and , so bits. This is also its min-capacity. Its Shannon capacity is bits, which is smaller; the min-capacity bound page proves that the min-capacity is never below the Shannon capacity.
Non-example: zero leakage with a dependent output. Use the same channel with the prior . Then , and , so . The best guess is 0 whatever the output, so the output does not help a one-try attacker. The Shannon mutual information is bits, so the output does carry information in the Shannon sense. Zero min-entropy leakage is not noninterference: noninterference asks that the output distribution be the same for every secret, which fails here.
Non-example: Shannon leakage as a proxy. Let be uniform on , an 8-bit secret, and compare two programs, after the examples of Smith (2009):
- program A outputs when is a multiple of 8 and outputs 1 otherwise;
- program B outputs the last three bits of .
| program | outputs | Shannon leakage | min-entropy leakage | |
|---|---|---|---|---|
| A | 33 | 1.169 bits | 33/256 = 0.129 | bits |
| B | 8 | 3 bits | 8/256 = 0.031 | 3 bits |
For a deterministic program the Shannon leakage is the entropy of the output. By that measure A leaks less than B. But A reveals the whole secret one time in eight, and its attacker guesses right with probability 0.129, four times the 0.031 of B. Min-entropy leakage ranks them the right way for a one-try attacker. The numbers were computed exactly with the implementation of this page.
Non-example: a different attacker. If the attacker has three tries, or wins by guessing a value close to the secret, min-entropy leakage is the wrong measure. g-leakage handles those attackers with a gain function.
Related definitions
- Min-entropy. The same quantity , used in randomness extraction. Here it measures the uncertainty that matters for one guess.
- Shannon entropy and conditional entropy. The Shannon leakage is , the mutual information. It measures the expected number of bits needed to describe the secret, not the chance of guessing it. For a deterministic program under a uniform prior, the two agree exactly when all outputs are equally likely, which is the case for program B in the table and not for program A.
- Additive leakage. , studied by Braun, Chatzikokolakis and Palamidessi (2009) next to the multiplicative form above. It is not maximized by the uniform prior in general: for the channel with rows , and , the uniform prior gives and the prior gives .
- g-leakage. Replaces "one exact guess" by a gain function ; min-entropy leakage is the case of the identity gain.
- Min-capacity bound. The theorem that gives in closed form and, for a deterministic program, of the number of distinct outputs.
- Channel capacity. The Shannon analogue: the maximum mutual information over priors.
- Covert channel. Min-capacity per use is one way to state the bandwidth of a covert channel against a one-try receiver.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/min-entropy-leakage/. The authors are listed in prov/7HY8Q8.jsonl.
import math
from collections.abc import Callable, Hashable, Sequence
from fractions import Fraction
Prior = Sequence[Fraction]
Channel = Sequence[Sequence[Fraction]]
def prior_vulnerability(pi: Prior) -> Fraction:
"""V(pi) = max_x pi[x], the chance to guess the secret in one try. Cost: O(|X|)."""
return max(pi)
def posterior_vulnerability(pi: Prior, c: Channel) -> Fraction:
"""V(pi, C) = sum_y max_x pi[x] C[x][y]. Precondition: each row of C sums to 1. Cost: O(|X| |Y|)."""
total = Fraction(0)
for y in range(len(c[0])):
total += max(pi[x] * c[x][y] for x in range(len(pi)))
return total
def leakage_ratio(pi: Prior, c: Channel) -> Fraction:
"""V(pi, C) / V(pi), exact. The leakage in bits is its base-2 logarithm."""
return posterior_vulnerability(pi, c) / prior_vulnerability(pi)
def min_entropy_leakage(pi: Prior, c: Channel) -> float:
"""Min-entropy leakage L(pi, C) = log2(V(pi, C) / V(pi)) in bits.
pi is a probability distribution on the secrets 0..|X|-1 and c[x][y] is
P(Y = y | X = x). Precondition: pi sums to 1 and each row of c sums to 1.
Cost: O(|X| |Y|) exact arithmetic operations.
"""
v0 = max(pi) # @line L1
v1 = Fraction(0) # @line L2
for y in range(len(c[0])): # @line L3
v1 += max(pi[x] * c[x][y] for x in range(len(pi))) # @line L4
return math.log2(v1 / v0) # @line L5
def min_capacity(c: Channel) -> float:
"""ML(C) = log2 sum_y max_x C[x][y], the largest min-entropy leakage over all priors."""
return math.log2(sum(max(row[y] for row in c) for y in range(len(c[0]))))
def deterministic_channel(f: Callable[[int], Hashable], n: int) -> tuple[list[list[Fraction]], list[Hashable]]:
"""The channel matrix of a program y = f(x) on the secrets 0..n-1, and its outputs in order of first use."""
outputs: list[Hashable] = []
for x in range(n):
if f(x) not in outputs:
outputs.append(f(x))
c = [[Fraction(1) if f(x) == y else Fraction(0) for y in outputs] for x in range(n)]
return c, outputs
test_min_entropy_leakage.py 139 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/min-entropy-leakage/. The authors are listed in prov/7HY8Q8.jsonl.
import itertools
import math
import random
from fractions import Fraction as F
from min_entropy_leakage import (
deterministic_channel,
leakage_ratio,
min_capacity,
min_entropy_leakage,
posterior_vulnerability,
prior_vulnerability,
)
def uniform(n):
return [F(1, n)] * n
def best_strategy(pi, c):
"""Oracle: try every map from outputs to guesses and keep the best success chance."""
nx, ny = len(pi), len(c[0])
best = F(0)
for guess in itertools.product(range(nx), repeat=ny):
win = sum(pi[guess[y]] * c[guess[y]][y] for y in range(ny))
best = max(best, win)
return best
def random_channel(rng, nx, ny):
c = []
for _ in range(nx):
w = [rng.randint(0, 4) for _ in range(ny)]
if sum(w) == 0:
w[rng.randrange(ny)] = 1
s = sum(w)
c.append([F(v, s) for v in w])
return c
def random_prior(rng, nx):
w = [rng.randint(1, 6) for _ in range(nx)]
return [F(v, sum(w)) for v in w]
def grid_priors(nx, d):
for parts in itertools.product(range(d + 1), repeat=nx - 1):
if sum(parts) <= d:
yield [F(p, d) for p in parts] + [F(d - sum(parts), d)]
def test_mod_four() -> None:
c, outs = deterministic_channel(lambda h: h % 4, 8)
pi = uniform(8)
assert outs == [0, 1, 2, 3]
assert prior_vulnerability(pi) == F(1, 8)
assert posterior_vulnerability(pi, c) == F(1, 2)
assert leakage_ratio(pi, c) == 4
assert min_entropy_leakage(pi, c) == 2.0
def test_binary_symmetric_channel() -> None:
c = [[F(9, 10), F(1, 10)], [F(1, 10), F(9, 10)]]
assert leakage_ratio(uniform(2), c) == F(9, 5)
assert abs(min_entropy_leakage(uniform(2), c) - 0.847997) < 1e-6
assert abs(min_capacity(c) - 0.847997) < 1e-6
# A skewed prior: the best guess is 0 before and after, so nothing leaks.
skew = [F(9, 10), F(1, 10)]
assert posterior_vulnerability(skew, c) == F(9, 10)
assert min_entropy_leakage(skew, c) == 0.0
def test_password_checker() -> None:
c, _ = deterministic_channel(lambda h: h == 5, 8)
assert posterior_vulnerability(uniform(8), c) == F(1, 4)
assert min_entropy_leakage(uniform(8), c) == 1.0
def test_shannon_contrast() -> None:
a, outs_a = deterministic_channel(lambda h: h if h % 8 == 0 else 1, 256)
b, outs_b = deterministic_channel(lambda h: h & 7, 256)
pi = uniform(256)
assert len(outs_a) == 33 and len(outs_b) == 8
assert posterior_vulnerability(pi, a) == F(33, 256)
assert posterior_vulnerability(pi, b) == F(1, 32)
assert abs(min_entropy_leakage(pi, a) - math.log2(33)) < 1e-12
assert min_entropy_leakage(pi, b) == 3.0
def test_edges() -> None:
# One secret: nothing to learn.
assert min_entropy_leakage([F(1)], [[F(1, 2), F(1, 2)]]) == 0.0
# A constant program and the identity program.
pi = [F(1, 2), F(1, 4), F(1, 4)]
const, _ = deterministic_channel(lambda h: 0, 3)
ident, _ = deterministic_channel(lambda h: h, 3)
assert min_entropy_leakage(pi, const) == 0.0
assert posterior_vulnerability(pi, ident) == 1
assert min_entropy_leakage(pi, ident) == 1.0
# A point prior: the attacker already knows the secret.
assert min_entropy_leakage([F(0), F(1), F(0)], ident) == 0.0
def test_against_strategy_enumeration() -> None:
rng = random.Random(2009)
for _ in range(600):
nx, ny = rng.randint(1, 3), rng.randint(1, 3)
c = random_channel(rng, nx, ny)
pi = random_prior(rng, nx)
v1 = posterior_vulnerability(pi, c)
assert v1 == best_strategy(pi, c)
assert v1 >= prior_vulnerability(pi)
assert min_entropy_leakage(pi, c) >= 0.0
assert min_entropy_leakage(pi, c) <= min_capacity(c) + 1e-12
def test_capacity_against_prior_grid() -> None:
rng = random.Random(42)
for _ in range(120):
nx, ny = rng.randint(2, 3), rng.randint(1, 3)
c = random_channel(rng, nx, ny)
cap = sum(max(row[y] for row in c) for y in range(ny))
best = max(leakage_ratio(p, c) for p in grid_priors(nx, 12))
# The grid contains the uniform prior, which attains the capacity.
assert best == cap
assert leakage_ratio(uniform(nx), c) == cap
def test_deterministic_capacity_counts_outputs() -> None:
rng = random.Random(5)
for _ in range(200):
n = rng.randint(1, 8)
table = [rng.randrange(4) for _ in range(n)]
c, outs = deterministic_channel(lambda h: table[h], n)
assert abs(min_capacity(c) - math.log2(len(outs))) < 1e-12
assert abs(min_entropy_leakage(uniform(n), c) - math.log2(len(outs))) < 1e-12
References
- Geoffrey Smith, On the foundations of quantitative information flow, Proceedings of FoSSaCS 2009, LNCS 5504, pp. 288 to 302; Section 4 (the examples where Shannon entropy misjudges the one-guess threat) and Section 5 (Definitions 1 to 4 of vulnerability, min-entropy, conditional vulnerability and conditional min-entropy, and Theorem 1)
- Christelle Braun, Konstantinos Chatzikokolakis and Catuscia Palamidessi, Quantitative notions of leakage for one-try attacks, Proceedings of MFPS 2009, Electronic Notes in Theoretical Computer Science 249, pp. 75 to 91, multiplicative and additive leakage for one-try attacks and the min-capacity
- Mario S. Alvim, Konstantinos Chatzikokolakis, Catuscia Palamidessi and Geoffrey Smith, Measuring information leakage using generalized gain functions, Proceedings of CSF 2012, pp. 265 to 279, Section 2 (min-entropy leakage and min-capacity as the starting point of g-leakage)
- Mario S. Alvim, Konstantinos Chatzikokolakis, Annabelle McIver, Carroll Morgan, Catuscia Palamidessi and Geoffrey Smith, The Science of Quantitative Information Flow, Springer, 2020, Chapter 2 (Bayes vulnerability of a prior), Chapter 4 (channels), Chapter 5 (posterior vulnerability and leakage) and Chapter 7 (capacity)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 7HY8Q8 Edit this page History Report an error Markdown