Documentation

CslibFrontier.Crypto.Computational.Encryption.Hybrid

KEM–DEM hybrid public-key encryption #

A Key Encapsulation Mechanism (KEM) samples a public/secret key pair (pk, sk) ← keyGen n and encapsulates a symmetric key (k, ctKem) ← encaps n pk ([BS23], Exercise 11.9). Its chosen-plaintext security KEMINDCPA asks that replacing the encapsulated key k with an independent uniform keyLen n-bit key is computationally indistinguishable to every uniform strict PPT distinguisher receiving (pk, (k, ctKem)). This is the KEM security of [CS03], Section 7.1.2, restricted to adversaries that make no decryption queries. It is stronger than the semantic security of Exercise 11.9, whose challenger does not give the distinguisher pk.

A Data Encapsulation Mechanism (DEM) over message space Msg encrypts a single challenge message under a fresh uniform keyLen n-bit key ([BS23], Section 2.2, Attack Game 2.1, p. 16, and Definition 2.2). As for public-key encryption (Encryption.gameOn), demKeyGameOn takes a challenge-pair admissibility predicate valid, and an inadmissible pair makes it output false in both experiments. demKeyGame and DEMOneTimeKeyINDCPAOf are the always-true case. The normalized interfaces demGameOn, demGame, and DEMOneTimeINDCPAOf specialize to keyLen n = n; DEMOneTimeINDCPA specializes further to single-bit messages, and DEMOneTimeWordINDCPA imposes Attack Game 2.1's equal-length rule on bit words.

Combining encaps with encryptSym produces the hybrid public-key encryption scheme hybridEncrypt encaps encryptSym (hybridDecrypt ctSpace decaps decryptSym, Exercise 11.9(a)). If the KEM satisfies KEMINDCPA and the DEM is one-time IND-CPA secure, then hybridEncrypt encaps encryptSym is IND-CPA secure: KEMINDCPA.hybrid_indcpa for unrestricted challenge pairs, and KEMINDCPA.hybrid_indcpaOn under an admissibility predicate that ignores the public key, such as the equal-length rule. This is a corrected form of Exercise 11.9(b), not the printed exercise: under the exercise's KEM notion, whose challenger does not give the distinguisher pk, part (b) is false (KEMINDCPA gives a counterexample). We formalize both the single hidden-bit KEM distinguisher bound of the corrected form (advantage_hybridGame_le_two_mul) and its two-distinguisher triangle-inequality variant (advantage_hybridGame_le), together with non-vacuous single-bit and n-bit word one-time pad DEM instantiations (otpEncrypt, otpDecrypt, demOneTimeINDCPA_otpEncrypt, KEMINDCPA.hybrid_otpEncrypt_indcpa, otpWordEncrypt, otpWordDecrypt, demOneTimeINDCPA_otpWordEncrypt, demOneTimeWordINDCPA_otpWordEncrypt, KEMINDCPA.hybrid_otpWordEncrypt_indcpa).

Relative to Boneh and Shoup, Exercise 11.9, this development has the following representation conventions:

Main definitions #

Main results #

References #

Key Encapsulation Mechanisms #

The shared real KEM experiment: generate keys and encapsulate, then run the challenger continuation with (sk, pk, key, ciphertext). The secret key is internal challenger data, not an adversary input. CPA and CCA experiments specialize the same sampling computation.

noncomputable def Cslib.Crypto.Encryption.kemIdealGameWith (keyLen : ℕ → ℕ) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (next : ℕ → List Bool → List Bool → List Bool → List Bool → ProbComp Bool) (n : ℕ) :

The shared ideal KEM experiment replaces only the key shown to the continuation with an independent uniform keyLen n-bit word. Key generation, encapsulation, and their order are those of kemRealGameWith; the secret key and ciphertext remain unchanged.

@[reducible, inline]

The encoding of a KEM distinguisher's input (pk, (k, ctKem)): the public key, the challenge key and the encapsulation, as nested framed pairs.

def Cslib.Crypto.Encryption.kemRealGame (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (distinguisher : Distinguisher) (n : ℕ) :

The real experiment of KEMINDCPA, the KEM game of [CS03] §7.1.2 without decryption queries (Exercise 11.9's Experiment 0 of [BS23] with pk also given): sample (pk, sk) ← keyGen n and (k, ctKem) ← encaps n pk, and pass the encoded triple (pk, (k, ctKem)) to distinguisher n.

noncomputable def Cslib.Crypto.Encryption.kemIdealGame (keyLen : ℕ → ℕ) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (distinguisher : Distinguisher) (n : ℕ) :

The ideal experiment of KEMINDCPA, the KEM game of [CS03] §7.1.2 without decryption queries (Exercise 11.9's Experiment 1 of [BS23] with pk also given): sample (pk, sk) ← keyGen n, (k, ctKem) ← encaps n pk, and an independent uniform keyLen n-bit key kIdeal ← BitString.sampleList (keyLen n), and pass (pk, (kIdeal, ctKem)) to distinguisher n.

The real KEM IND-CPA experiment is uniform strict PPT when key generation, encapsulation, and the distinguisher have native certificates.

The ideal KEM IND-CPA experiment is uniform strict PPT when key generation, encapsulation, and the distinguisher have native certificates and keyLen is computable in polynomial time in unary.

def Cslib.Crypto.Encryption.KEMINDCPA (keyLen : ℕ → ℕ) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) :

IND-CPA security for a Key Encapsulation Mechanism with the public key given to the distinguisher: every uniform strict PPT distinguisher has negligible advantage between kemRealGame and kemIdealGame keyLen, which pass it (pk, (k, ctKem)). This is the security notion of [CS03], Section 7.1.2 (pp. 38–39 of the authors' revised manuscript of August 14, 2003), restricted to adversaries that make no decryption queries: the adversary receives the public key (Stage 1) and the pair of a key and its encapsulation (Stage 3), the key being the encapsulated one or uniform on keyLen n-bit words. The advantage is the two-experiment form AdvCCA', twice the source's AdvCCA. Security does not bundle correctness (soundness, Section 7.1.1) or efficient honest algorithms.

[BS23], Exercise 11.9 (§11.8, p. 460), defines a weaker notion: its challenger sends only (k_b, c_kem), without pk. That notion does not suffice for the exercise's part (b). If key generation outputs a uniform pk with sk = pk and encapsulation returns (pk, []), both printed experiments show a uniform key and an empty encapsulation, so the KEM is secure there. Yet its hybrid with the one-time pad encrypts m as pk ⊕ m, which anyone holding pk decrypts. KEMINDCPA excludes this KEM. It holds for the hashed ElGamal KEM under DDH and a secure KDF (DDH.kemINDCPA_hashedElGamalEncapsProb) and for the encrypted-key KEM of a WordINDCPA scheme (WordINDCPA.kemINDCPA_encryptKeyEncaps).

One-Time Symmetric Encryption (DEM) #

noncomputable def Cslib.Crypto.Encryption.demKeyGameOn {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :

The one-time symmetric chosen-plaintext experiment over message space Msg with challenge-pair admissibility predicate valid and key-length function keyLen : ℕ → ℕ ([BS23], Section 2.2, Attack Game 2.1, p. 16): sample a uniform keyLen n-bit key k ← BitString.sampleList (keyLen n) and invoke adversary.choose n []; the adversary receives the empty public key [], and valid is evaluated at it. If the chosen pair is valid, encrypt the selected message under encryptSym n k and pass the saved state and challenge ciphertext to adversary.guess n; otherwise return false, in both experiments.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.Encryption.demKeyGame {Msg : Type} (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :

The unrestricted one-time symmetric experiment at key-length function keyLen: demKeyGameOn with every challenge pair admissible.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.Encryption.demGameOn {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :

The normalized (n-bit key) one-time symmetric chosen-plaintext experiment over message space Msg with challenge-pair admissibility predicate valid ([BS23], Section 2.2, Attack Game 2.1, p. 16): demKeyGameOn specialized to keyLen n = n.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.Encryption.demGame {Msg : Type} (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :

The unrestricted n-bit key one-time symmetric experiment: demGameOn with every challenge pair admissible.

theorem Cslib.Crypto.Encryption.demKeyGameOn_id {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
demKeyGameOn valid (fun (m : ℕ) => m) encryptSym adversary bit n = demGameOn valid encryptSym adversary bit n

At the normalized key length keyLen n = n, demKeyGameOn is definitionally demGameOn.

theorem Cslib.Crypto.Encryption.demKeyGameOn_eq_demGameOn_of_eq {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) {n : ℕ} (h : keyLen n = n) :
demKeyGameOn valid keyLen encryptSym adversary bit n = demGameOn valid encryptSym adversary bit n

Whenever keyLen n = n, demKeyGameOn at security parameter n coincides with demGameOn.

theorem Cslib.Crypto.Encryption.eval_demKeyGame_restrict {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(demKeyGame keyLen encryptSym (AdversaryOf.restrict valid adversary) bit n).eval = (demKeyGameOn valid keyLen encryptSym adversary bit n).eval

Running the unrestricted demKeyGame on adversary.restrict valid has the same output distribution as running demKeyGameOn valid on adversary.

theorem Cslib.Crypto.Encryption.eval_demGame_restrict {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(demGame encryptSym (AdversaryOf.restrict valid adversary) bit n).eval = (demGameOn valid encryptSym adversary bit n).eval

Running the unrestricted demGame on adversary.restrict valid has the same output distribution as running demGameOn valid on adversary.

theorem Cslib.Crypto.Encryption.isPPTOn_demKeyGameOn {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {keyLen : ℕ → ℕ} (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool × Msg × Msg) => valid p.1 p.2.1 p.2.2.1 p.2.2.2) (encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) (hkeyLen : Turing.MultiTapeTM.ComputableInPolyTime keyLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hencrypt : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (p : ℕ × List Bool × Msg) => encryptSym p.1 p.2.1 p.2.2) {adversary : AdversaryOf Msg} (hadversary : AdversaryOf.IsPPT encMsg adversary) {α : Type} {input : α ↪ List Bool} {n : α → ℕ} {bit : α → Bool} (hn : Turing.MultiTapeTM.ComputableInPolyTime n input Turing.MultiTapeTM.encUnary) (hbit : Turing.MultiTapeTM.ComputableInPolyTime bit input Turing.MultiTapeTM.encBool) :
Probability.IsPPTOn input Turing.MultiTapeTM.encBool fun (a : α) => demKeyGameOn valid keyLen encryptSym adversary (bit a) (n a)

The one-time symmetric experiment demKeyGameOn valid keyLen has a strict polynomial clock when valid and keyLen are computable in polynomial time and symmetric encryption and both adversary stages have native certificates.

theorem Cslib.Crypto.Encryption.isPPTOn_demKeyGame {Msg : Type} {encMsg : Msg ↪ List Bool} {keyLen : ℕ → ℕ} (hkeyLen : Turing.MultiTapeTM.ComputableInPolyTime keyLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hencrypt : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (p : ℕ × List Bool × Msg) => encryptSym p.1 p.2.1 p.2.2) {adversary : AdversaryOf Msg} (hadversary : AdversaryOf.IsPPT encMsg adversary) {α : Type} {input : α ↪ List Bool} {n : α → ℕ} {bit : α → Bool} (hn : Turing.MultiTapeTM.ComputableInPolyTime n input Turing.MultiTapeTM.encUnary) (hbit : Turing.MultiTapeTM.ComputableInPolyTime bit input Turing.MultiTapeTM.encBool) :
Probability.IsPPTOn input Turing.MultiTapeTM.encBool fun (a : α) => demKeyGame keyLen encryptSym adversary (bit a) (n a)

The unrestricted one-time symmetric experiment demKeyGame keyLen has a strict polynomial clock when keyLen is computable in polynomial time and symmetric encryption and both adversary stages have native certificates.

theorem Cslib.Crypto.Encryption.isPPTOn_demGameOn {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × Msg × Msg) => match x with | (n, pk, m₀, m₁) => valid n pk m₀ m₁) (encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hencrypt : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, msg) => encryptSym n k msg) {adversary : AdversaryOf Msg} (hadversary : AdversaryOf.IsPPT encMsg adversary) {α : Type} {input : α ↪ List Bool} {n : α → ℕ} {bit : α → Bool} (hn : Turing.MultiTapeTM.ComputableInPolyTime n input Turing.MultiTapeTM.encUnary) (hbit : Turing.MultiTapeTM.ComputableInPolyTime bit input Turing.MultiTapeTM.encBool) :
Probability.IsPPTOn input Turing.MultiTapeTM.encBool fun (a : α) => demGameOn valid encryptSym adversary (bit a) (n a)

The normalized (n-bit key) one-time symmetric experiment demGameOn valid has a strict polynomial clock when valid is computable in polynomial time and symmetric encryption and both adversary stages have native certificates.

theorem Cslib.Crypto.Encryption.isPPTOn_demGame {Msg : Type} {encMsg : Msg ↪ List Bool} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hencrypt : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, msg) => encryptSym n k msg) {adversary : AdversaryOf Msg} (hadversary : AdversaryOf.IsPPT encMsg adversary) {α : Type} {input : α ↪ List Bool} {n : α → ℕ} {bit : α → Bool} (hn : Turing.MultiTapeTM.ComputableInPolyTime n input Turing.MultiTapeTM.encUnary) (hbit : Turing.MultiTapeTM.ComputableInPolyTime bit input Turing.MultiTapeTM.encBool) :
Probability.IsPPTOn input Turing.MultiTapeTM.encBool fun (a : α) => demGame encryptSym adversary (bit a) (n a)

The unrestricted n-bit key one-time symmetric experiment has a strict polynomial clock when symmetric encryption and both adversary stages have native certificates.

def Cslib.Crypto.Encryption.DEMOneTimeKeyINDCPAOn {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encMsg : Msg ↪ List Bool) (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) :

One-time symmetric IND-CPA / semantic security over message encoding encMsg with challenge-pair admissibility predicate valid and key-length function keyLen : ℕ → ℕ ([BS23], Section 2.2, Attack Game 2.1, p. 16, and Definition 2.2): every uniform strict PPT Encryption.AdversaryOf Msg has negligible distinguishing advantage between demKeyGameOn valid keyLen encryptSym adversary false and demKeyGameOn valid keyLen encryptSym adversary true.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.DEMOneTimeKeyINDCPAOf {Msg : Type} (encMsg : Msg ↪ List Bool) (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) :

One-time symmetric IND-CPA at key-length function keyLen with every challenge pair admissible: semantic security, [BS23], Attack Game 2.1 and Definition 2.2 (p. 16), with a uniform keyLen n-bit key and every pair of messages admitted as a challenge in place of the source's rule that the two messages have the same length. The notion is generic in the message type Msg. It is exactly the source's notion when all messages of Msg have one length. At List Bool it is strictly stronger, so it is not the source's notion there; DEMOneTimeKeyWordINDCPA is.

theorem Cslib.Crypto.Encryption.DEMOneTimeKeyINDCPAOf.demOneTimeKeyINDCPAOn {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {keyLen : ℕ → ℕ} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (h : DEMOneTimeKeyINDCPAOf encMsg keyLen encryptSym) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool × Msg × Msg) => valid p.1 p.2.1 p.2.2.1 p.2.2.2) (encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) :
DEMOneTimeKeyINDCPAOn valid encMsg keyLen encryptSym

Unrestricted one-time symmetric IND-CPA at key length keyLen implies one-time symmetric IND-CPA under every polynomial-time admissibility predicate.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.DEMOneTimeKeyINDCPA (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → Bool → ProbComp (List Bool)) :

One-time symmetric IND-CPA / semantic security for single-bit encryption at key length keyLen.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.DEMOneTimeKeyWordINDCPA (keyLen : ℕ → ℕ) (encryptSym : ℕ → List Bool → List Bool → ProbComp (List Bool)) :

One-time symmetric IND-CPA / semantic security for bit-word encryption at key length keyLen under Attack Game 2.1's equal-length rule ([BS23], Section 2.2, p. 16).

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.DEMOneTimeINDCPAOn {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encMsg : Msg ↪ List Bool) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) :

Normalized (n-bit key) one-time symmetric IND-CPA / semantic security over message encoding encMsg with challenge-pair admissibility predicate valid ([BS23], Section 2.2, Attack Game 2.1, p. 16, and Definition 2.2): DEMOneTimeKeyINDCPAOn specialized to keyLen n = n.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.DEMOneTimeINDCPAOf {Msg : Type} (encMsg : Msg ↪ List Bool) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) :

Normalized (n-bit key) one-time symmetric IND-CPA with every challenge pair admissible: semantic security, [BS23], Attack Game 2.1 and Definition 2.2 (p. 16), with a uniform n-bit key and every pair of messages admitted as a challenge in place of the source's rule that the two messages have the same length. The notion is generic in the message type Msg. It is exactly the source's notion when all messages of Msg have one length. At List Bool it is strictly stronger, so it is not the source's notion there; DEMOneTimeWordINDCPA is.

theorem Cslib.Crypto.Encryption.DEMOneTimeINDCPAOf.demOneTimeINDCPAOn {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (h : DEMOneTimeINDCPAOf encMsg encryptSym) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × Msg × Msg) => match x with | (n, pk, m₀, m₁) => valid n pk m₀ m₁) (encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) :
DEMOneTimeINDCPAOn valid encMsg encryptSym

Unrestricted n-bit key one-time symmetric IND-CPA implies one-time symmetric IND-CPA under every polynomial-time admissibility predicate.

@[reducible, inline]

Normalized (n-bit key) one-time symmetric IND-CPA / semantic security for single-bit encryption.

@[reducible, inline]

Normalized (n-bit key) one-time symmetric IND-CPA / semantic security for bit-word encryption under Attack Game 2.1's equal-length rule ([BS23], Section 2.2, p. 16): challenge pairs with m₀.length ≠ m₁.length are inadmissible.

theorem Cslib.Crypto.Encryption.demOneTimeKeyINDCPAOn_id {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encMsg : Msg ↪ List Bool) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) :
DEMOneTimeKeyINDCPAOn valid encMsg (fun (n : ℕ) => n) encryptSym ↔ DEMOneTimeINDCPAOn valid encMsg encryptSym

At the normalized key length keyLen n = n, DEMOneTimeKeyINDCPAOn is definitionally DEMOneTimeINDCPAOn.

theorem Cslib.Crypto.Encryption.DEMOneTimeINDCPAOn.demOneTimeKeyINDCPAOn {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {keyLen : ℕ → ℕ} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (h : DEMOneTimeINDCPAOn valid encMsg encryptSym) (hkeyLen : ∀ (n : ℕ), keyLen n = n) :
DEMOneTimeKeyINDCPAOn valid encMsg keyLen encryptSym

Whenever keyLen n = n for all n, DEMOneTimeINDCPAOn implies DEMOneTimeKeyINDCPAOn.

Hybrid Encryption Construction and Correctness #

def Cslib.Crypto.Encryption.hybridEncrypt {Msg : Type} (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (n : ℕ) (pk : List Bool) (msg : Msg) :

KEM–DEM hybrid encryption ([BS23], Exercise 11.9): encapsulate a symmetric key (k, ctKem) ← encaps n pk, encrypt the plaintext message under k via ctDem ← encryptSym n k msg, and encode (ctKem, ctDem) using encPair encBits encBits.

def Cslib.Crypto.Encryption.hybridDecrypt {Msg : Type} (ctSpace : ℕ → List Bool → Bool) (decaps : ℕ → List Bool → List Bool → Option (List Bool)) (decryptSym : ℕ → List Bool → List Bool → Option Msg) (n : ℕ) (sk ct : List Bool) :
Option Msg

Deterministic KEM–DEM hybrid decryption ([BS23], Exercises 11.9 and 12.5). Reject noncanonical ciphertext-pair encodings and KEM components outside ctSpace, decapsulate the KEM component, and decrypt the DEM component. Either component may reject with none; accepted empty keys/messages are preserved.

theorem Cslib.Crypto.Encryption.isPPTOn_hybridEncrypt {Msg : Type} {encMsg : Msg ↪ List Bool} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hencaps : Probability.IsPPTOn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) fun (p : ℕ × List Bool) => encaps p.1 p.2) (hencryptSym : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, msg) => encryptSym n k msg) :
Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, pk, msg) => hybridEncrypt encaps encryptSym n pk msg

Hybrid encryption is uniform strict PPT when encapsulation and symmetric encryption are.

theorem Cslib.Crypto.Encryption.computableInPolyTime_hybridDecrypt {Msg : Type} {encMsg : Msg ↪ List Bool} {ctSpace : ℕ → List Bool → Bool} {decaps : ℕ → List Bool → List Bool → Option (List Bool)} {decryptSym : ℕ → List Bool → List Bool → Option Msg} (hctSpace : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool) => match x with | (n, ctKem) => ctSpace n ctKem) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBool) (hdecaps : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × List Bool) => match x with | (n, sk, ctKem) => decaps n sk ctKem) (encKeyedInput Turing.MultiTapeTM.encBits) (Turing.MultiTapeTM.encOption Turing.MultiTapeTM.encBits)) (hdecryptSym : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × List Bool) => match x with | (n, k, ctDem) => decryptSym n k ctDem) (encKeyedInput Turing.MultiTapeTM.encBits) (Turing.MultiTapeTM.encOption encMsg)) :

Hybrid decryption is computable in polynomial time when the KEM ciphertext-space test, decapsulation, and symmetric decryption are computable in polynomial time.

Malformed ciphertext-pair encodings are rejected before either component is used.

theorem Cslib.Crypto.Encryption.hybridDecrypt_of_ctSpace_eq_false {Msg : Type} (ctSpace : ℕ → List Bool → Bool) (decaps : ℕ → List Bool → List Bool → Option (List Bool)) (decryptSym : ℕ → List Bool → List Bool → Option Msg) (n : ℕ) (sk ct : List Bool) (hct : ctSpace n (Turing.MultiTapeTM.unframe ct) = false) :
hybridDecrypt ctSpace decaps decryptSym n sk ct = none

Ciphertexts whose KEM projection lies outside ctSpace are rejected without decapsulating.

theorem Cslib.Crypto.Encryption.hybridDecrypt_encPair {Msg : Type} (ctSpace : ℕ → List Bool → Bool) (decaps : ℕ → List Bool → List Bool → Option (List Bool)) (decryptSym : ℕ → List Bool → List Bool → Option Msg) (n : ℕ) (sk ctKem ctDem : List Bool) :
hybridDecrypt ctSpace decaps decryptSym n sk ((Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) (ctKem, ctDem)) = if ctSpace n ctKem = true then do let k ← decaps n sk ctKem decryptSym n k ctDem else none

Decryption of a canonical pair checks KEM ciphertext-space membership, decapsulates its KEM component, and propagates any rejection before invoking symmetric decryption on the DEM component.

theorem Cslib.Crypto.Encryption.hybridDecrypt_hybridEncrypt {Msg : Type} {ctSpace : ℕ → List Bool → Bool} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} {decaps : ℕ → List Bool → List Bool → Option (List Bool)} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} {decryptSym : ℕ → List Bool → List Bool → Option Msg} {n : ℕ} {pk sk ct : List Bool} {msg : Msg} (hctSpace : ∀ (k ctKem : List Bool), (k, ctKem) ∈ (encaps n pk).eval.support → ctSpace n ctKem = true) (hkem : ∀ (k ctKem : List Bool), (k, ctKem) ∈ (encaps n pk).eval.support → decaps n sk ctKem = some k) (hdem : ∀ (k ctDem : List Bool), (∃ (ctKem : List Bool), (k, ctKem) ∈ (encaps n pk).eval.support) → ctDem ∈ (encryptSym n k msg).eval.support → decryptSym n k ctDem = some msg) (hct : ct ∈ (hybridEncrypt encaps encryptSym n pk msg).eval.support) :
hybridDecrypt ctSpace decaps decryptSym n sk ct = some msg

Hybrid decryption correctness: supported encapsulations lie in ctSpace and decapsulate to some k, and supported symmetric ciphertexts decrypt to some msg. Then every supported hybrid ciphertext decrypts to some msg, including the empty-key and empty-message cases.

Reductions and Asymptotic Security for the Corrected Exercise 11.9(b) #

def Cslib.Crypto.Encryption.hybridToKEMDistinguisher {Msg : Type} (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) :

Direct per-bit KEM distinguisher $D_{\mathrm{kem}, b}$ constructed from an Encryption.AdversaryOf Msg and DEM encryption encryptSym (for the two-distinguisher variant of the corrected [BS23], Exercise 11.9(b)): given an encoded KEM challenge (pk, (k, ctKem)), run adversary.choose n pk, encrypt the bit-selected message under k, and run adversary.guess on (ctKem, ctDem).

noncomputable def Cslib.Crypto.Encryption.hybridToKEMHiddenBitDistinguisher {Msg : Type} (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) :

Single hidden-bit KEM distinguisher $\mathcal{B}_{\mathrm{kem}}$ for the corrected [BS23], Exercise 11.9(b): given an encoded KEM challenge (pk, (k, ctKem)), run adversary.choose n pk, sample a fair challenge bit bit ← ProbComp.uniform Bool, encrypt the selected message under k, run adversary.guess, and return guess ^^ bit.

def Cslib.Crypto.Encryption.hybridToDEMAdversary {Msg : Type} (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (adversary : AdversaryOf Msg) :

Two-stage DEM adversary $\mathcal{B}_{\mathrm{s}}$ constructed from keyGen, encaps, and a hybrid Encryption.AdversaryOf Msg for the corrected [BS23], Exercise 11.9(b): stage 1 samples (pk, sk) ← keyGen n and (k, ctKem) ← encaps n pk, runs adversary.choose n pk, and saves encPair encBits encBits (ctKem, choice.2); stage 2 combines ctKem with the DEM challenge ciphertext ctDem and runs adversary.guess.

theorem Cslib.Crypto.Encryption.isPPT_hybridToKEMDistinguisher {Msg : Type} {encMsg : Msg ↪ List Bool} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} {adversary : AdversaryOf Msg} (hencryptSym : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, msg) => encryptSym n k msg) (hadversary : AdversaryOf.IsPPT encMsg adversary) (bit : Bool) :

hybridToKEMDistinguisher is uniform strict PPT whenever symmetric encryption and the hybrid adversary are.

theorem Cslib.Crypto.Encryption.isPPT_hybridToKEMHiddenBitDistinguisher {Msg : Type} {encMsg : Msg ↪ List Bool} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} {adversary : AdversaryOf Msg} (hencryptSym : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, msg) => encryptSym n k msg) (hadversary : AdversaryOf.IsPPT encMsg adversary) :

hybridToKEMHiddenBitDistinguisher is uniform strict PPT whenever symmetric encryption and the hybrid adversary are.

hybridToDEMAdversary is an admissible uniform strict PPT Encryption.AdversaryOf Msg whenever key generation, encapsulation, and the hybrid adversary are.

The word-level hybrid as an instance of the typed hybrid #

At each parameter n, the word-level algorithms form a typed KEM (wordKEM) and cipher (wordCipher). hybridEncrypt frames the pair of ciphertexts of their hybrid KEM.hybrid, and a word-level adversary plays the typed experiment of the hybrid through AdversaryOf.toHybridTwoStage, which frames the pair before guessing. The word-level games of the Exercise 11.9(b) reductions are then the typed experiments of KEM.hybridDistinguisher, KEM.hybridHiddenBitDistinguisher and KEM.hybridCipherAdversary, so the bounds below are instances of KEM.advantage_hybrid_le and KEM.advantage_hybrid_le_two_mul.

def Cslib.Crypto.Encryption.wordKEM (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (decaps : ℕ → List Bool → List Bool → Option (List Bool)) (n : ℕ) :

The word-level KEM at parameter n as a typed KEM; encapsulation returns the ciphertext before the key, as in KEM.

def Cslib.Crypto.Encryption.wordCipher {Msg : Type} (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (decryptSym : ℕ → List Bool → List Bool → Option Msg) (n : ℕ) :

The word-level symmetric encryption at parameter n as a typed cipher.

The two-stage adversary that adversary plays against the typed hybrid at parameter n: the two-stage form adversary.toTwoStage n, guessing on the framed pair of ciphertexts, as hybridEncrypt frames it.

theorem Cslib.Crypto.Encryption.eval_game_hybridEncrypt {Msg : Type} {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (decaps : ℕ → List Bool → List Bool → Option (List Bool)) (decryptSym : ℕ → List Bool → List Bool → Option Msg) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(game keyGen (hybridEncrypt encaps encryptSym) adversary bit n).eval = ProbComp.eval (((wordKEM keyGen encaps decaps n).hybrid (wordCipher encryptSym decryptSym n)).cpaExperiment (fun (x : List Bool) (x_1 x_2 : Msg) => true) (adversary.toHybridTwoStage n) bit)

At each parameter, the word-level hybrid experiment is the chosen-plaintext experiment of the typed hybrid of wordKEM and wordCipher, played by adversary.toHybridTwoStage n.

theorem Cslib.Crypto.Encryption.eval_kemRealGame_eq_cpaExperiment {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} (decaps : ℕ → List Bool → List Bool → Option (List Bool)) (sampleKey : ProbComp (List Bool)) {distinguisher : Distinguisher} {D : KEM.Challenge (List Bool) (List Bool) (List Bool) → ProbComp Bool} {n : ℕ} (hD : ∀ (pk ct key : List Bool), (distinguisher n (encKEMChallenge (pk, key, ct))).eval = (D { pk := pk, ct := ct, key := key }).eval) :
(kemRealGame keyGen encaps distinguisher n).eval = ProbComp.eval ((wordKEM keyGen encaps decaps n).cpaExperiment sampleKey D false)

The real KEM experiment of a word-level distinguisher is the typed KEM experiment with the encapsulated key, for any typed distinguisher with the same output distribution on the framed challenge (pk, (key, ct)).

theorem Cslib.Crypto.Encryption.eval_kemIdealGame_eq_cpaExperiment {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} (keyLen : ℕ → ℕ) (decaps : ℕ → List Bool → List Bool → Option (List Bool)) {distinguisher : Distinguisher} {D : KEM.Challenge (List Bool) (List Bool) (List Bool) → ProbComp Bool} {n : ℕ} (hD : ∀ (pk ct key : List Bool), (distinguisher n (encKEMChallenge (pk, key, ct))).eval = (D { pk := pk, ct := ct, key := key }).eval) :
(kemIdealGame keyLen keyGen encaps distinguisher n).eval = ProbComp.eval ((wordKEM keyGen encaps decaps n).cpaExperiment (BitString.sampleList (keyLen n)) D true)

The ideal KEM experiment of a word-level distinguisher is the typed KEM experiment with a uniform keyLen n-bit key, for any typed distinguisher with the same output distribution on the framed challenge (pk, (key, ct)).

theorem Cslib.Crypto.Encryption.eval_hybridToKEMDistinguisher_encKEMChallenge {Msg : Type} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (decryptSym : ℕ → List Bool → List Bool → Option Msg) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) (pk ct key : List Bool) :
(hybridToKEMDistinguisher encryptSym adversary bit n (encKEMChallenge (pk, key, ct))).eval = (KEM.hybridDistinguisher (wordCipher encryptSym decryptSym n) (fun (x x_1 : Msg) => true) (adversary.toHybridTwoStage n) bit { pk := pk, ct := ct, key := key }).eval

On a framed challenge, hybridToKEMDistinguisher is the typed distinguisher KEM.hybridDistinguisher of wordCipher and adversary.toHybridTwoStage n.

theorem Cslib.Crypto.Encryption.eval_hybridToKEMHiddenBitDistinguisher_encKEMChallenge {Msg : Type} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (decryptSym : ℕ → List Bool → List Bool → Option Msg) (adversary : AdversaryOf Msg) (n : ℕ) (pk ct key : List Bool) :
(hybridToKEMHiddenBitDistinguisher encryptSym adversary n (encKEMChallenge (pk, key, ct))).eval = (KEM.hybridHiddenBitDistinguisher (wordCipher encryptSym decryptSym n) (fun (x x_1 : Msg) => true) (adversary.toHybridTwoStage n) { pk := pk, ct := ct, key := key }).eval

On a framed challenge, hybridToKEMHiddenBitDistinguisher has the output distribution of the typed distinguisher KEM.hybridHiddenBitDistinguisher of wordCipher and adversary.toHybridTwoStage n.

theorem Cslib.Crypto.Encryption.eval_demKeyGame_eq_oneTimeExperiment {Msg : Type} {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (keyLen : ℕ → ℕ) (decaps : ℕ → List Bool → List Bool → Option (List Bool)) (decryptSym : ℕ → List Bool → List Bool → Option Msg) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(demKeyGame keyLen encryptSym (hybridToDEMAdversary keyGen encaps adversary) bit n).eval = ProbComp.eval ((wordCipher encryptSym decryptSym n).oneTimeExperiment (BitString.sampleList (keyLen n)) (fun (x x_1 : Msg) => true) ((wordKEM keyGen encaps decaps n).hybridCipherAdversary (adversary.toHybridTwoStage n)) bit)

The one-time experiment of hybridToDEMAdversary is the typed one-time experiment of the cipher adversary KEM.hybridCipherAdversary of wordKEM and adversary.toHybridTwoStage n.

theorem Cslib.Crypto.Encryption.advantage_hybridGame_le {Msg : Type} (keyLen : ℕ → ℕ) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (n : ℕ) :
Game.advantage (game keyGen (hybridEncrypt encaps encryptSym) adversary false n).eval (game keyGen (hybridEncrypt encaps encryptSym) adversary true n).eval ≤ Game.advantage (kemRealGame keyGen encaps (hybridToKEMDistinguisher encryptSym adversary false) n).eval (kemIdealGame keyLen keyGen encaps (hybridToKEMDistinguisher encryptSym adversary false) n).eval + Game.advantage (kemRealGame keyGen encaps (hybridToKEMDistinguisher encryptSym adversary true) n).eval (kemIdealGame keyLen keyGen encaps (hybridToKEMDistinguisher encryptSym adversary true) n).eval + Game.advantage (demKeyGame keyLen encryptSym (hybridToDEMAdversary keyGen encaps adversary) false n).eval (demKeyGame keyLen encryptSym (hybridToDEMAdversary keyGen encaps adversary) true n).eval

Quantitative KEM–DEM reduction via two per-bit KEM distinguishers, the concrete bound for the corrected form of [BS23], Exercise 11.9(b) (§11.8, pp. 460–461), in a two-distinguisher variant: the hybrid IND-CPA advantage is bounded by the sum of the KEM advantages of hybridToKEMDistinguisher encryptSym adversary false and hybridToKEMDistinguisher encryptSym adversary true, plus the DEM advantage of hybridToDEMAdversary keyGen encaps adversary. The KEM advantages are those of kemRealGame and kemIdealGame, which give the distinguisher pk; the exercise's printed KEM game does not, and under it part (b) is false (see KEMINDCPA). This is KEM.advantage_hybrid_le for wordKEM and wordCipher at parameter n.

theorem Cslib.Crypto.Encryption.advantage_hybridGame_le_two_mul {Msg : Type} (keyLen : ℕ → ℕ) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (n : ℕ) :
Game.advantage (game keyGen (hybridEncrypt encaps encryptSym) adversary false n).eval (game keyGen (hybridEncrypt encaps encryptSym) adversary true n).eval ≤ 2 * Game.advantage (kemRealGame keyGen encaps (hybridToKEMHiddenBitDistinguisher encryptSym adversary) n).eval (kemIdealGame keyLen keyGen encaps (hybridToKEMHiddenBitDistinguisher encryptSym adversary) n).eval + Game.advantage (demKeyGame keyLen encryptSym (hybridToDEMAdversary keyGen encaps adversary) false n).eval (demKeyGame keyLen encryptSym (hybridToDEMAdversary keyGen encaps adversary) true n).eval

Quantitative KEM–DEM reduction via a single hidden-bit KEM distinguisher, the concrete bound for the corrected form of [BS23], Exercise 11.9(b) (§11.8, pp. 460–461): the hybrid IND-CPA advantage is at most twice the KEM advantage of hybridToKEMHiddenBitDistinguisher encryptSym adversary, plus the DEM advantage of hybridToDEMAdversary keyGen encaps adversary, the exercise's SSadv[A, E] ≤ 2 · SSadv[B_kem, E_kem] + SSadv[B_s, E_s]. The KEM advantage is that of kemRealGame and kemIdealGame, which give the distinguisher pk; the exercise's printed KEM game does not, and under it part (b) is false (see KEMINDCPA). This is KEM.advantage_hybrid_le_two_mul for wordKEM and wordCipher at parameter n.

theorem Cslib.Crypto.Encryption.KEMINDCPA.hybrid_indcpa {keyLen : ℕ → ℕ} {Msg : Type} {encMsg : Msg ↪ List Bool} {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hkem : KEMINDCPA keyLen keyGen encaps) (hdem : DEMOneTimeKeyINDCPAOf encMsg keyLen encryptSym) (hkeyGen : Probability.IsPPTOn Turing.MultiTapeTM.encUnary (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) keyGen) (hencaps : Probability.IsPPTOn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) fun (p : ℕ × List Bool) => encaps p.1 p.2) (hencryptSym : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, msg) => encryptSym n k msg) :
INDCPAOf encMsg keyGen (hybridEncrypt encaps encryptSym)

IND-CPA security of KEM–DEM hybrid encryption from KEMINDCPA, a corrected form of [BS23], Exercise 11.9(b) (§11.8, pp. 460–461): if (keyGen, encaps) satisfies KEMINDCPA and encryptSym is a one-time IND-CPA secure DEM over encMsg at the same keyLen (with uniform strict PPT honest algorithms), then hybridEncrypt encaps encryptSym is IND-CPA secure over encMsg, with every challenge pair admissible.

The exercise's KEM game does not give the distinguisher pk, and under that premise the printed statement is false; the docstring of KEMINDCPA gives the counterexample. KEMINDCPA gives the distinguisher pk: it is the KEM security of [CS03], Section 7.1.2, without decryption queries, a stronger assumption than the printed one, and the one the statement needs.

theorem Cslib.Crypto.Encryption.eval_demKeyGame_hybridToDEMAdversary_restrict {Msg : Type} (keyLen : ℕ → ℕ) (valid : ℕ → List Bool → Msg → Msg → Bool) (hpk : ∀ (n : ℕ) (pk : List Bool) (m₀ m₁ : Msg), valid n pk m₀ m₁ = valid n [] m₀ m₁) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)) (encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(demKeyGame keyLen encryptSym (hybridToDEMAdversary keyGen encaps (AdversaryOf.restrict valid adversary)) bit n).eval = (demKeyGameOn valid keyLen encryptSym (hybridToDEMAdversary keyGen encaps (AdversaryOf.restrict valid adversary)) bit n).eval

When valid ignores the public key, running the unrestricted demKeyGame keyLen on the DEM adversary built from adversary.restrict valid has the same output distribution as running demKeyGameOn valid keyLen on it: an invalid pair already makes the restricted adversary's guess false.

theorem Cslib.Crypto.Encryption.KEMINDCPA.hybrid_indcpaOn {keyLen : ℕ → ℕ} {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encaps : ℕ → List Bool → ProbComp (List Bool × List Bool)} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hkem : KEMINDCPA keyLen keyGen encaps) (hdem : DEMOneTimeKeyINDCPAOn valid encMsg keyLen encryptSym) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × Msg × Msg) => match x with | (n, pk, m₀, m₁) => valid n pk m₀ m₁) (encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) (hpk : ∀ (n : ℕ) (pk : List Bool) (m₀ m₁ : Msg), valid n pk m₀ m₁ = valid n [] m₀ m₁) (hkeyGen : Probability.IsPPTOn Turing.MultiTapeTM.encUnary (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) keyGen) (hencaps : Probability.IsPPTOn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) fun (p : ℕ × List Bool) => encaps p.1 p.2) (hencryptSym : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, msg) => encryptSym n k msg) :
INDCPAOn valid encMsg keyGen (hybridEncrypt encaps encryptSym)

IND-CPA security of KEM–DEM hybrid encryption under an admissibility predicate, from KEMINDCPA, a corrected form of [BS23], Exercise 11.9(b) (§11.8, pp. 460–461): for a polynomial-time predicate valid that ignores the public key, such as the equal-length rule, if (keyGen, encaps) satisfies KEMINDCPA and encryptSym satisfies DEMOneTimeKeyINDCPAOn valid encMsg keyLen, then hybridEncrypt encaps encryptSym satisfies INDCPAOn valid encMsg.

The exercise's KEM game does not give the distinguisher pk, and under that premise the printed statement is false; the docstring of KEMINDCPA gives the counterexample. KEMINDCPA gives the distinguisher pk: it is the KEM security of [CS03], Section 7.1.2, without decryption queries, a stronger assumption than the printed one, and the one the statement needs.

Non-vacuous One-Time Pad DEMs #

One-time pad single-bit symmetric encryption: XOR the first key bit k.headD false with the plaintext bit bit.

One-time pad single-bit symmetric decryption: XOR the first key bit k.headD false with the first ciphertext bit ct.headD false.

One-time pad decryption inverts one-time pad encryption on every supported ciphertext.

One-time pad encryption is uniform strict PPT.

For 1 ≤ n, a uniform n-bit key masks the challenge bit perfectly in demGame otpEncrypt, so the false and true experiment distributions are identical.

For 1 ≤ n, every adversary has exact advantage 0 in demGame otpEncrypt.

The one-time pad is unconditionally one-time IND-CPA secure (DEMOneTimeINDCPA otpEncrypt).

One-time pad keyLen n-bit word symmetric encryption: XOR the keyLen n-bit key k with the plaintext word m at width keyLen n using BitString.listXor (keyLen n) [k, m].

One-time pad keyLen n-bit word symmetric decryption: XOR the keyLen n-bit key k with the ciphertext word ct at width keyLen n using BitString.listXor (keyLen n) [k, ct].

theorem Cslib.Crypto.Encryption.otpKeyWordDecrypt_otpKeyWordEncrypt (keyLen : ℕ → ℕ) (n : ℕ) (k : List Bool) {m : List Bool} (hm : m.length = keyLen n) :
otpKeyWordDecrypt keyLen n k (BitString.listXor (keyLen n) [k, m]) = m

One-time pad word decryption at key length keyLen inverts encryption on every keyLen n-bit plaintext word m.

theorem Cslib.Crypto.Encryption.eval_demKeyGame_otpKeyWordEncrypt_false_eq_true (keyLen : ℕ → ℕ) (n : ℕ) (adversary : WordAdversary) :
(demKeyGame keyLen (otpKeyWordEncrypt keyLen) adversary false n).eval = (demKeyGame keyLen (otpKeyWordEncrypt keyLen) adversary true n).eval

A uniform keyLen n-bit key masks any challenge word perfectly in demKeyGame keyLen (otpKeyWordEncrypt keyLen), so the false and true experiment distributions are identical for every keyLen and n.

theorem Cslib.Crypto.Encryption.advantage_demKeyGame_otpKeyWordEncrypt_eq_zero (keyLen : ℕ → ℕ) (n : ℕ) (adversary : WordAdversary) :
Game.advantage (demKeyGame keyLen (otpKeyWordEncrypt keyLen) adversary false n).eval (demKeyGame keyLen (otpKeyWordEncrypt keyLen) adversary true n).eval = 0

Every word adversary has exact advantage 0 in demKeyGame keyLen (otpKeyWordEncrypt keyLen).

The keyLen n-bit word one-time pad is unconditionally one-time IND-CPA secure (DEMOneTimeKeyINDCPAOf encBits keyLen (otpKeyWordEncrypt keyLen)).

The keyLen n-bit word one-time pad satisfies equal-length word DEM security (DEMOneTimeKeyWordINDCPA keyLen (otpKeyWordEncrypt keyLen)).

@[reducible, inline]

One-time pad n-bit word symmetric encryption: otpKeyWordEncrypt specialized to keyLen n = n.

@[reducible, inline]

One-time pad n-bit word symmetric decryption: otpKeyWordDecrypt specialized to keyLen n = n.

One-time pad word decryption inverts one-time pad word encryption on every n-bit plaintext word m.

A uniform n-bit key masks any challenge word perfectly in demGame otpWordEncrypt, so the false and true experiment distributions are identical for every n.

Combining any KEM that satisfies KEMINDCPA with the n-bit word one-time pad DEM yields a public-key word-encryption scheme satisfying WordINDCPA, through the equal-length instance of KEMINDCPA.hybrid_indcpaOn.