Algorithm Search⌘K

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 LL bits means that the output multiplies the attacker's success probability by 2L2^L. 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 XX takes values in a finite set X\mathcal X with a prior distribution π\pi. A system is modeled as a channel from X\mathcal X to a finite set Y\mathcal Y of observable outputs, given by a matrix CC with C[x,y]=P(Y=y∣X=x)C[x, y] = P(Y = y \mid X = x); each row sums to 1. A deterministic program y=f(x)y = f(x) has C[x,f(x)]=1C[x, f(x)] = 1 and zeros elsewhere. The joint distribution is p(x,y)=π(x) C[x,y]p(x, y) = \pi(x)\, C[x, y].

Adversary. The attacker knows π\pi and CC, sees one output yy, and makes one guess of the secret. The guess wins when it equals XX exactly. The attacker may choose the guess as any function of yy. Nothing else is observed: timing, repeated runs and other side information are outside the model unless they are part of YY.

Vulnerabilities.

V(π)=max⁡xπ(x),V(π,C)=∑yp(y)max⁡xp(x∣y)=∑ymax⁡xπ(x) C[x,y].V(\pi) = \max_{x} \pi(x), \qquad V(\pi, C) = \sum_{y} p(y) \max_x p(x \mid y) = \sum_{y} \max_{x} \pi(x)\, C[x, y].

The second form of V(π,C)V(\pi, C) follows from Bayes' theorem, p(y) p(x∣y)=π(x) C[x,y]p(y)\,p(x \mid y) = \pi(x)\,C[x, y], and needs no division. V(π)V(\pi) is the probability that the best blind guess is right. V(π,C)V(\pi, C) is the probability that the best guess after seeing yy is right, averaged over yy.

Min-entropy and leakage. The min-entropy of the prior and the conditional min-entropy are

H∞(π)=−log⁡2V(π),H∞(π,C)=−log⁡2V(π,C).H_\infty(\pi) = -\log_2 V(\pi), \qquad H_\infty(\pi, C) = -\log_2 V(\pi, C).

The min-entropy page defines the same quantity; the QIF pages measure it in bits, with log⁡2\log_2. The min-entropy leakage of CC under π\pi is

L(π,C)=H∞(π)−H∞(π,C)=log⁡2V(π,C)V(π).\mathcal L(\pi, C) = H_\infty(\pi) - H_\infty(\pi, C) = \log_2 \frac{V(\pi, C)}{V(\pi)}.

The min-capacity is the worst case over priors, ML(C)=sup⁡πL(π,C)\mathcal{ML}(C) = \sup_\pi \mathcal L(\pi, C). The min-capacity bound proves that ML(C)=log⁡2∑ymax⁡xC[x,y]\mathcal{ML}(C) = \log_2 \sum_y \max_x C[x, y], reached by the uniform prior.

Computation. With ∣X∣=n|\mathcal X| = n secrets and ∣Y∣=k|\mathcal Y| = k outputs, the leakage costs O(nk)O(nk) arithmetic operations:

  1. MIN-ENTROPY-LEAKAGE(π, C)
  2. 1V0 ← max over x of π[x]
  3. 2V1 ← 0
  4. 3for each output y do
  5. 4V1 ← V1 + max over x of π[x] · C[x, y]
  6. 5return 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 V(π,C)V(\pi, C) 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.

  • V(π,C)V(\pi, C) is the success of the best strategy. A strategy is a map ss from outputs to guesses, and it wins with probability ∑yπ(s(y)) C[s(y),y]≤∑ymax⁡xπ(x)C[x,y]\sum_y \pi(s(y))\, C[s(y), y] \le \sum_y \max_x \pi(x) C[x, y], with equality for s(y)=arg⁡max⁡xπ(x)C[x,y]s(y) = \arg\max_x \pi(x) C[x, y].
  • Leakage is never negative. Let x∗x^* maximize π\pi. Then V(π,C)≥∑yπ(x∗) C[x∗,y]=π(x∗)=V(π)V(\pi, C) \ge \sum_y \pi(x^*)\, C[x^*, y] = \pi(x^*) = V(\pi), so L(π,C)≥0\mathcal L(\pi, C) \ge 0.
  • Zero leakage. L(π,C)=0\mathcal L(\pi, C) = 0 if and only if one guess xx maximizes π(x)C[x,y]\pi(x) C[x, y] for every output yy 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 DD is a second channel applied to the output of CC, then ∑zmax⁡x∑yπ(x)C[x,y]D[y,z]≤∑z∑yD[y,z]max⁡xπ(x)C[x,y]=V(π,C)\sum_z \max_x \sum_y \pi(x) C[x, y] D[y, z] \le \sum_z \sum_y D[y, z] \max_x \pi(x) C[x, y] = V(\pi, C), because the rows of DD sum to 1. So L(π,CD)≤L(π,C)\mathcal L(\pi, CD) \le \mathcal L(\pi, C).
  • A security guarantee. V(π,C)=2−H∞(π,C)V(\pi, C) = 2^{-H_\infty(\pi, C)} exactly, so a bound on the leakage is a bound on the attacker's one-try success: V(π,C)≤2L(π,C) V(π)V(\pi, C) \le 2^{\mathcal L(\pi, C)}\, V(\pi). With mm tries the success is at most m V(π,C)m\, V(\pi, C).

Examples and non-examples

Example: the last two bits. Let hh be uniform on {0,…,7}\{0, \ldots, 7\} and let the program output h mod 4h \bmod 4. Then V(π)=1/8V(\pi) = 1/8. Each of the 4 outputs has two secrets of probability 1/81/8, so V(π,C)=4⋅1/8=1/2V(\pi, C) = 4 \cdot 1/8 = 1/2 and L=log⁡24=2\mathcal L = \log_2 4 = 2 bits. The attacker's chance goes from 1/81/8 to 1/21/2.

Example: a password check. Let hh be uniform on 8 values and let the output be whether hh equals a fixed value. The output "yes" has one secret of probability 1/81/8 and the output "no" has seven, so V(π,C)=1/8+1/8=1/4V(\pi, C) = 1/8 + 1/8 = 1/4 and L=1\mathcal L = 1 bit. For a uniform secret on nn values the leakage of one check is always 1 bit, while the attacker's chance grows only from 1/n1/n to 2/n2/n.

Example: a noisy bit. The binary symmetric channel with crossover probability 0.10.1 copies a secret bit and flips it with probability 0.10.1. Under the uniform prior, V(π)=1/2V(\pi) = 1/2 and V(π,C)=0.45+0.45=0.9V(\pi, C) = 0.45 + 0.45 = 0.9, so L=log⁡21.8=0.847997\mathcal L = \log_2 1.8 = 0.847997 bits. This is also its min-capacity. Its Shannon capacity is 1−H(0.1)=0.5310041 - H(0.1) = 0.531004 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 π=(0.9,0.1)\pi = (0.9, 0.1). Then V(π)=0.9V(\pi) = 0.9, and V(π,C)=max⁡(0.81,0.01)+max⁡(0.09,0.09)=0.9V(\pi, C) = \max(0.81, 0.01) + \max(0.09, 0.09) = 0.9, so L=0\mathcal L = 0. The best guess is 0 whatever the output, so the output does not help a one-try attacker. The Shannon mutual information is H(Y)−H(Y∣X)=H(0.82)−H(0.1)=0.211H(Y) - H(Y \mid X) = H(0.82) - H(0.1) = 0.211 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 hh be uniform on {0,…,255}\{0, \ldots, 255\}, an 8-bit secret, and compare two programs, after the examples of Smith (2009):

  • program A outputs hh when hh is a multiple of 8 and outputs 1 otherwise;
  • program B outputs the last three bits of hh.
program outputs Shannon leakage H(Y)H(Y) V(π,C)V(\pi, C) min-entropy leakage
A 33 1.169 bits 33/256 = 0.129 log⁡233=5.044\log_2 33 = 5.044 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.

  • Min-entropy. The same quantity −log⁡2max⁡xπ(x)-\log_2 \max_x \pi(x), used in randomness extraction. Here it measures the uncertainty that matters for one guess.
  • Shannon entropy and conditional entropy. The Shannon leakage is H(X)−H(X∣Y)H(X) - H(X \mid Y), 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. V(π,C)−V(π)V(\pi, C) - V(\pi), 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 (1/5,1/5,3/5)(1/5, 1/5, 3/5), (4/7,3/7,0)(4/7, 3/7, 0) and (0,1/5,4/5)(0, 1/5, 4/5), the uniform prior gives 4/154/15 and the prior (0,1/2,1/2)(0, 1/2, 1/2) gives 2/52/5.
  • g-leakage. Replaces "one exact guess" by a gain function g(w,x)g(w, x); min-entropy leakage is the case of the identity gain.
  • Min-capacity bound. The theorem that gives ML(C)\mathcal{ML}(C) in closed form and, for a deterministic program, log⁡2\log_2 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.

min_entropy_leakage.pyI0RawGitHub
# 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

  1. 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)
  2. 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
  3. 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)
  4. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/7HY8Q8/text.yaml