Documentation

CslibFrontier.Crypto.Primitives.BlockCipher.ECB

Electronic codebook (ECB) mode #

The ℓ-wise ECB cipher derived from a block cipher E encrypts a sequence of at most ℓ data blocks block by block, E′(k, m) = (E(k, m[0]), …, E(k, m[v-1])) ([BS23], §4.1.4, pp. 102–106). This file gives the concrete single-cipher analysis underlying Section 4.1.4; the asymptotic statements for a uniform block cipher are in CslibFrontier.Crypto.Computational.Encryption.ECB.

Main definitions #

Main results #

The statements are for a fixed block cipher (the concrete attack and equation (4.3)); the asymptotic statements (BlockCipher.PRP.ecb_demOneTimeKeyINDCPAOn, BlockCipher.PRP.ecb_demOneTimeKeyINDCPAOn_one, and BlockCipher.not_demOneTimeKeyINDCPAOn_ecbEncrypt) are proved in CslibFrontier.Crypto.Computational.Encryption.ECB. The block-cipher advantage is PRP.advantage (Attack Game 4.1), against a uniform key and a uniform permutation.

References #

def Cslib.Crypto.Cipher.ecb {Key D : Type} (E : Key → Equiv.Perm D) :
Cipher Key (List D) (List D)

The ECB cipher of a block cipher E ([BS23], §4.1.4, p. 102): encrypt and decrypt every block separately under the same key. The book's ℓ-wise cipher is defined on X^{≤ℓ}; here encryption is defined on lists of any length, and the bound ℓ enters through the admissible challenge pairs (ECB.admissible).

theorem Cslib.Crypto.Cipher.ecb_correct {Key D : Type} (E : Key → Equiv.Perm D) :

ECB decrypts every encryption.

def Cslib.Crypto.ECB.admissible {D : Type} (ℓ : ℕ) (m₀ m₁ : List D) :

The challenge pairs of Attack Game 2.1 for ECB on X^{≤ℓ}: two messages of the same length, at most ℓ.

def Cslib.Crypto.ECB.distinctAdmissible {D : Type} [DecidableEq D] (ℓ : ℕ) (m₀ m₁ : List D) :

The challenge pairs of Attack Game 2.1 for the message space X_*^{≤ℓ} of Theorem 4.1: two messages of the same length, at most ℓ, each consisting of distinct blocks.

The two-block attack #

The two-block attack on ECB ([BS23], §4.1.4, pp. 103–104): submit m₀ = (x, x) and m₁ = (x, y) and output true exactly when the two ciphertext blocks are equal.

theorem Cslib.Crypto.ECB.advantage_twoBlockAdversary {Key D : Type} [DecidableEq D] (E : Key → Equiv.Perm D) (sampleKey : ProbComp Key) {ℓ : ℕ} (hℓ : 2 ≤ ℓ) {x y : D} (hxy : x ≠ y) :

The typed two-block attack has advantage 1 against the ECB cipher of every fixed block cipher and key law, for 2 ≤ ℓ and distinct blocks: the attack of [BS23] §4.1.4 (pp. 103–104) for one fixed cipher; the asymptotic statement is BlockCipher.not_demOneTimeKeyINDCPAOn_ecbEncrypt in CslibFrontier.Crypto.Computational.Encryption.ECB.

Theorem 4.1 #

noncomputable def Cslib.Crypto.ECB.reduction {D : Type} [DecidableEq D] (ℓ : ℕ) {σ : Type} (A : TwoStage Unit (MessagePair (List D)) (List D) Bool σ) :
ProbOracleComp (fun (x : D) => D) Bool

The block-cipher adversary of the proof of Theorem 4.1 ([BS23], p. 106). It draws the hidden bit b, runs A's first stage, and on an admissible pair answers the challenge by querying its oracle on the blocks of m_b; it outputs whether A's guess equals b. On an inadmissible pair it outputs whether false equals b, as the challenger of Attack Game 2.1 returns false there.

ECB.reduction ℓ A makes at most ℓ queries, one per block of the challenge message.

Theorem 4.1, equation (4.3) ([BS23], pp. 104–105): for the ECB cipher of a block cipher E over finite types, with challenge pairs restricted to sequences of at most ℓ distinct blocks, every one-time adversary A has semantic-security advantage exactly twice the block-cipher advantage of ECB.reduction ℓ A, which makes at most ℓ queries (ECB.isQueryBounded_reduction). Keys are uniform. This is the concrete identity for a fixed block cipher; the asymptotic statement is BlockCipher.PRP.ecb_demOneTimeKeyINDCPAOn in CslibFrontier.Crypto.Computational.Encryption.ECB.