Information-theoretic privacy: consolidated formalization · Chapter 21 of 22

Appendix A. Executable finite verification

The following Python program uses only the standard library. Copy its code block into a .py file and run it with Python 3. It checks the binary example over all sixteen candidate nonces, all credentials, and all masks; the keypad example over all twelve rotations, all key-map pairs, and all masks; the fixed-dictionary difference sets; the four-position separation schedule; and the repeated-position counterexample.

These are finite arithmetic checks. The general privacy and extraction statements are justified by their proofs above. The burn trace is an abstract single-event model; storage concurrency and rollback require implementation evidence.

from collections import Counter
from fractions import Fraction
from itertools import permutations, product
import json


def add(raw, mask, modulus):
    return tuple((a + b) % modulus for a, b in zip(raw, mask))


def subtract(out, mask, modulus):
    return tuple((a - b) % modulus for a, b in zip(out, mask))


def binary_cells(nonce, symbol):
    return tuple(((symbol + nonce + offset) % 4) // 2
                 for offset in (0, 3))


binary_runs = 0
for nonce in range(16):
    signatures = [binary_cells(nonce, s) for s in range(4)]
    assert len(set(signatures)) == 4
    for phi in permutations(range(2)):
        inverse = {v: i for i, v in enumerate(phi)}
        for secret in range(4):
            raw = phi + tuple(phi[c] for c in signatures[secret])
            outputs = set()
            for mask in product(range(2), repeat=4):
                out = add(raw, mask, 2)
                outputs.add(out)
                decoded = subtract(out, mask, 2)
                assert decoded[:2] == phi
                recovered = tuple(inverse[v] for v in decoded[2:])
                assert signatures.index(recovered) == secret
                binary_runs += 1
            assert len(outputs) == 16

assert add((1, 0, 0, 1), (1, 1, 0, 1), 2) == (0, 1, 0, 0)
offset_law = Counter((n % 4, (n + 3) % 4) for n in range(16))
assert len(offset_law) == 4 and set(offset_law.values()) == {4}

keys = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#')
pairs = tuple((a, b) for a in range(4) for b in range(4) if a != b)
masks4 = tuple(product(range(4), repeat=5))
keypad_runs = 0
difference_checks = 0
for nonce in range(12):
    signatures = [pairs[(i + nonce) % 12] for i in range(12)]
    lookup = {s: i for i, s in enumerate(signatures)}
    assert len(lookup) == 12
    for coordinate in range(2):
        assert Counter(s[coordinate] for s in signatures) == Counter({i: 3 for i in range(4)})
    for phi in permutations(range(4)):
        for domain in (range(12), [i for i, key in enumerate(keys) if key.isdigit()]):
            raw_domain = [tuple(phi[c] for c in signatures[i]) for i in domain]
            differences = {subtract(a, b, 4) for a in raw_domain for b in raw_domain}
            assert len(differences) == 16
            difference_checks += 1
        for secret in range(12):
            raw = phi[:3] + tuple(phi[c] for c in signatures[secret])
            outputs = set()
            for mask in masks4:
                out = add(raw, mask, 4)
                outputs.add(out)
                decoded = subtract(out, mask, 4)
                known = decoded[:3]
                remaining = set(range(4)) - set(known)
                assert len(set(known)) == 3 and len(remaining) == 1
                recovered_phi = known + (remaining.pop(),)
                assert recovered_phi == phi
                recovered_cells = tuple(recovered_phi.index(v) for v in decoded[3:])
                assert lookup[recovered_cells] == secret
                keypad_runs += 1
            assert len(outputs) == 1024

assert add((2, 0, 3, 3, 2), (1, 2, 0, 1, 3), 4) == (3, 2, 3, 0, 1)

# Exact Bayes calculation: equal likelihoods preserve a nonuniform prior.
prior = {'7': Fraction(2, 5)}
prior.update({k: Fraction(3, 55) for k in keys if k != '7'})
likelihood = Fraction(1, 1024)
evidence = sum(prior[k] * likelihood for k in keys)
posterior = {k: prior[k] * likelihood / evidence for k in keys}
assert posterior == prior

# Three independent rotations, one fixed uniformly sampled secret.
guess_successes = 0
for secret in range(4):
    for offsets in product(range(4), repeat=3):
        guess_successes += all(((secret + o) % 4) // 2 == o // 2 for o in offsets)
guess_probability = Fraction(guess_successes, 4 * 4**3)
assert guess_probability == Fraction(5, 16)

# The one-ring full-offset schedule separates every tested slot pair.
full_offset_profiles = 0
for cells in range(2, 7):
    for width in range(1, 6):
        size = cells * width
        signatures = {tuple(((s + o) % size) // width for o in range(size))
                      for s in range(size)}
        assert len(signatures) == size
        full_offset_profiles += 1

# Abstract worked burn trace: the second submission cannot claim the event.
state = 'unallocated'
grants = 0
trace = []
for action in ('reserve', 'issue', 'submit_valid', 'submit_valid'):
    if state == 'unallocated' and action == 'reserve':
        state = 'reserved'
    elif state == 'reserved' and action == 'issue':
        state = 'issued'
    elif state == 'issued' and action == 'submit_valid':
        state = 'burned'
        grants += 1
    trace.append(state)
assert trace == ['reserved', 'issued', 'burned', 'burned'] and grants == 1

print(json.dumps({
    'binary_complete_executions': binary_runs,
    'keypad_complete_executions': keypad_runs,
    'signature_difference_checks': difference_checks,
    'full_offset_ring_profiles': full_offset_profiles,
    'binary_transcript': [0, 1, 0, 0],
    'keypad_transcript': [3, 2, 3, 0, 1],
    'nonuniform_prior_and_posterior_for_key_7': str(posterior['7']),
    'repeated_position_guessing_probability': str(guess_probability),
    'binary_candidate_nonce_entropy_bits': 4,
    'binary_projection_entropy_bits': 2,
    'binary_mask_entropy_bits': 4,
    'burn_trace_acceptances': grants,
    'status': 'all assertions passed'
}, indent=2))

The execution results for this edition are:

{
  "binary_complete_executions": 2048,
  "keypad_complete_executions": 3538944,
  "signature_difference_checks": 576,
  "full_offset_ring_profiles": 25,
  "binary_transcript": [
    0,
    1,
    0,
    0
  ],
  "keypad_transcript": [
    3,
    2,
    3,
    0,
    1
  ],
  "nonuniform_prior_and_posterior_for_key_7": "2/5",
  "repeated_position_guessing_probability": "5/16",
  "binary_candidate_nonce_entropy_bits": 4,
  "binary_projection_entropy_bits": 2,
  "binary_mask_entropy_bits": 4,
  "burn_trace_acceptances": 1,
  "status": "all assertions passed"
}