Documentation

CslibFrontier.Crypto.Protocols.PerfectSecrecy.ShannonCiphers

The example Shannon ciphers of Boneh–Shoup §2.1 #

The example ciphers of [BS23], v0.6, §2.1 (printed pp. 6–10) other than the one-time pad, as information-theoretic encryption schemes EncScheme, with the book's verdicts on their perfect security. Each is EncScheme.ofPure (uniformOfFintype K) enc dec h, the book's Shannon cipher with a uniformly random key; its CiphertextIndist is the book's Definition 2.1, and perfectlySecret_iff_ciphertextIndist converts it to the library's PerfectlySecret (the posterior form of [KL20], Definition 2.3). The one-time pad itself (Example 2.1, Theorem 2.2) is otp with otp_perfectlySecret.

The cipher definitions are exposed, as otp is, so that the criteria of CslibFrontier.Crypto.Protocols.PerfectSecrecy.Characterization, which are stated for ofPure, apply to them directly. The variable-length pad's encryption varXor is evaluated through its public equation coe_varXor.

Main definitions #

Main results #

Deviations from [BS23] #

References #

The additive one-time pad #

The additive one-time pad over a finite additive group G: keys, messages and ciphertexts are elements of G, with E(k, m) = m + k, D(k, c) = c - k and a uniformly random key. [BS23], Example 2.4 (p. 7), defines it for G = ZMod n with n positive, which is additiveOTP (ZMod n) under [NeZero n].

Under the additive one-time pad every message has the uniform ciphertext law.

The additive one-time pad is perfectly secure: [BS23], Example 2.7 (p. 10), for every finite additive group rather than only ZMod n. The book's argument is N_c = 1 in Theorem 2.1 (ii); this proof uses that the ciphertext law is uniform.

The additive one-time pad is perfectly secret in the posterior sense of PerfectlySecret.

The variable-length one-time pad #

Encryption and decryption of the variable-length one-time pad (this library's name): a word w of at most L bits, of length ℓ, is XORed with the first ℓ bits of the key k, the book's k[0 .. ℓ - 1] ⊕ w.

The underlying word of varXor: the word XORed with as many leading key bits as it has.

@[simp]

varXor preserves the length of a word.

@[simp]

varXor with a fixed key is an involution: decryption inverts encryption.

The variable-length one-time pad of [BS23], Example 2.2 (p. 6): the key is L uniformly random bits, messages and ciphertexts are words of at most L bits, and a word is encrypted and decrypted by varXor, XOR with as many key bits as it is long. The book's {0,1}^{≤L} is the subtype {w : List Bool // w.length ≤ L}; BitString.shortWords L is the same set as a Finset.

Under the variable-length one-time pad, the ciphertext of m is a uniformly random word of the length of m.

Two messages have the same ciphertext law under the variable-length one-time pad exactly when they have the same length: a precise form of the remark in [BS23], Example 2.5 (p. 9), that the ciphertext leaks the length of the message and nothing else.

Under the variable-length one-time pad a ciphertext whose length differs from the message's has probability 0: the mass Pr[E(k, m₁) = c] = 0 for a 2-bit m₁ and a 1-bit c in [BS23], Example 2.5 (p. 9).

The variable-length one-time pad is perfectly secure only without key bits: it satisfies Definition 2.1 of [BS23] if and only if L = 0. For L ≥ 1 the empty word and a 1-bit word have different ciphertext laws; for L = 0 the empty word is the only message. [BS23], Example 2.5 (p. 9), separates messages of lengths 1 and 2, which needs L ≥ 2.

The variable-length one-time pad is not perfectly secret when 0 < L: [BS23], Example 2.5 (p. 9), for the library's PerfectlySecret, with 0 < L in place of the book's implicit L ≥ 2.

The substitution cipher #

noncomputable def Cslib.Crypto.Protocols.PerfectSecrecy.substitutionCipher (α : Type u) [Fintype α] [DecidableEq α] (L : ℕ) :
EncScheme (Fin L → α) (Equiv.Perm α) (Fin L → α)

The substitution cipher of [BS23], Example 2.3 (p. 7), over a finite alphabet α with decidable equality (the book's Σ): messages and ciphertexts are words Fin L → α of L symbols, the key is a uniformly random permutation of α, encryption applies it to each symbol and decryption applies its inverse.

theorem Cslib.Crypto.Protocols.PerfectSecrecy.substitutionCipher_apply_eq_iff {α : Type u} [Fintype α] [DecidableEq α] {L : ℕ} {m c : Fin L → α} (hc : c ∈ ((substitutionCipher α L).ciphertextDist m).support) (i j : Fin L) :
c i = c j ↔ m i = m j

Under the substitution cipher, every possible ciphertext of m repeats a symbol exactly where m does. This is the observation of [BS23], Example 2.6 (p. 10).

The substitution cipher is not perfectly secure: [BS23], Example 2.6, first paragraph (p. 10), with the book's implicit L ≥ 2 and |Σ| ≥ 2 as hypotheses. As in the book, a message with equal first two symbols and one with different first two symbols have different ciphertext laws.

The substitution cipher is not perfectly secret in the posterior sense of PerfectlySecret, for 2 ≤ L and at least two symbols.