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 #
additiveOTP: the additive one-time pad over a finite additive groupG(Example 2.4).variableLengthOTP: the variable-length one-time pad withLkey bits (Example 2.2), built fromvarXor, whichcoe_varXorevaluates.substitutionCipher: the substitution cipher on words ofLsymbols of a finite alphabetαwith decidable equality (Example 2.3).
Main results #
additiveOTP_ciphertextIndist,additiveOTP_perfectlySecret: Example 2.7, the additive one-time pad is perfectly secure, for every finite additive group.variableLengthOTP_ciphertextIndist_iff: the variable-length one-time pad is perfectly secure if and only ifL = 0;not_perfectlySecret_variableLengthOTPis Example 2.5 for0 < L.variableLengthOTP_ciphertextDist_map_val,variableLengthOTP_ciphertextDist_eq_iff: the ciphertext is a uniform word of the message's length, so two messages have the same ciphertext law exactly when they have the same length. This is a precise form of Example 2.5's remark that the ciphertext leaks the length of the message and, informally, nothing else.substitutionCipher_apply_eq_iff,not_ciphertextIndist_substitutionCipher,not_perfectlySecret_substitutionCipher: Example 2.6, first paragraph. A ciphertext repeats a symbol exactly where its message does, so for2 ≤ Land at least two symbols the substitution cipher is not perfectly secure.
Deviations from [BS23] #
- The additive one-time pad is defined over any finite additive group, commutative or not. The
book's cipher is the case
G = ZMod nwithnpositive, which isadditiveOTP (ZMod n)under[NeZero n]. The book proves Example 2.7 byN_c = 1in Theorem 2.1 (ii), the key being-m + c; here the ciphertext law is shown uniform instead, and the test file checks the book's route throughciphertextIndist_ofPure_uniformOfFintype_of_existsUnique. - The book's
{0,1}^{≤L}is the subtype{w : List Bool // w.length ≤ L};BitString.shortWords Lis the same set as aFinset. The key{0,1}^LisBitString L, and its truncationk[0 .. ℓ - 1]is(List.ofFn k).take ℓ. - Example 2.5 says that the variable-length one-time pad is not perfectly secure, using messages of
lengths 1 and 2, so it assumes
L ≥ 2implicitly.variableLengthOTP_ciphertextIndist_iffis exact: lengths 0 and 1 already separate forL ≥ 1, and forL = 0there is one message and the cipher is perfectly secure. Of the book's two masses, the0isvariableLengthOTP_ciphertextDist_apply_of_length_ne, and the test file checks the1/2of a 1-bit ciphertext under a 1-bit message for everyL ≥ 1. The mass(2 ^ ℓ)⁻¹of a word of any lengthℓ, which the book does not state, needs an exact-mass lemma forBitString.uniformListthat the library does not have, and is not stated here. - Example 2.6 leaves
L ≥ 2and|Σ| ≥ 2implicit; here they are the hypotheses2 ≤ LandNontrivial α. Neither can be dropped: the test file checks that the cipher is perfectly secure on words of one symbol ofBool, and on words overUnit, where there is only one message. The book makes no positive claim for these cases, and none is stated here in general. The second paragraph of Example 2.6 is an informal discussion with no statement and is not formalized.
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 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.
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 #
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.
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.