Documentation

CslibFrontier.Crypto.Computational.Encryption.Basic

Chosen-message security for public-key encryption #

The adversary receives the public key, chooses two messages of type Msg and saves a finite state, then receives an encryption of the selected message. Both stages are single uniform strict PPT algorithms. Their clocks charge the unary security parameter and the complete encoded input, including the saved state. The adversary may retain the public key in that state.

This is the single-challenge public-key experiment of Boneh and Shoup, Section 11.2, Attack Game 11.1, p. 436. That game requires the two challenge messages to have the same length. Here admissibility is a Boolean predicate valid : ℕ → List Bool → Msg → Msg → Bool on the security parameter, the public key and the challenge pair: gameOn valid outputs false in both experiments when the pair is invalid, so an invalid pair contributes no advantage. The unrestricted experiment game and notion INDCPAOf are the always-true case. Single-bit messages (Adversary, INDCPA) are unrestricted, and bit-word messages (WordAdversary, WordINDCPA) use the equal-length predicate fun _ _ m₀ m₁ => m₀.length == m₁.length. For public-key encryption, further encryptions can be computed from the public key. The separate multi-challenge equivalence of their Theorem 11.1 is not formalized here. Encryption correctness and efficiency of the honest algorithms remain separate properties.

Main definitions #

Main results #

References #

A chosen-message adversary over message space Msg. The saved word contains all data retained between stages.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.encChoiceOut {Msg : Type} (encMsg : Msg ↪ List Bool) :
(Msg × Msg) × List Bool ↪ List Bool

Message-selection output ((m₀, m₁), state): the two challenge messages, each encoded by encMsg, then the saved state word. The message pair is framed, and m₀ is framed again inside it.

@[reducible, inline]

Guessing-stage input (1ⁿ, state, ct): the security parameter n in unary, then the state saved by message selection and the challenge ciphertext, both as bit words. The parameter and the state are framed. The layout is that of the keyed-algorithm input Cslib.Crypto.encKeyedInput encBits; the name records the role.

@[reducible, inline]

Input (1ⁿ, pk, (m₀, m₁)) of a challenge-pair admissibility predicate valid: the security parameter n in unary, the public key as a bit word, and the two challenge messages, each encoded by encMsg. The parameter, the public key and m₀ are framed.

structure Cslib.Crypto.Encryption.AdversaryOf.IsPPT {Msg : Type} (encMsg : Msg ↪ List Bool) (adversary : AdversaryOf Msg) :

One finite-machine certificate for each whole stage over message encoding encMsg, including the full saved-state cost. There is no parameter-dependent advice or separate algorithm for each security parameter.

@[reducible, inline]

A chosen-message adversary for single-bit messages (Bool).

@[reducible, inline]

Phase 1 choice ((msg₀, msg₁), state) returned by an AdversaryOf Msg.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.ChoiceOut.msgs {Msg : Type} (c : ChoiceOut Msg) :
Msg × Msg

Challenge message pair (msg₀, msg₁) of a Phase 1 ChoiceOut.

@[reducible, inline]

First challenge message msg₀ of a Phase 1 ChoiceOut.

@[reducible, inline]

Second challenge message msg₁ of a Phase 1 ChoiceOut.

@[reducible, inline]

Saved adversary state of a Phase 1 ChoiceOut.

@[simp]
theorem Cslib.Crypto.Encryption.ChoiceOut.msg₀_mk {Msg : Type} (msgs : Msg × Msg) (st : List Bool) :
msg₀ (msgs, st) = msgs.1
@[simp]
theorem Cslib.Crypto.Encryption.ChoiceOut.msg₁_mk {Msg : Type} (msgs : Msg × Msg) (st : List Bool) :
msg₁ (msgs, st) = msgs.2
@[simp]
theorem Cslib.Crypto.Encryption.ChoiceOut.state_mk {Msg : Type} (msgs : Msg × Msg) (st : List Bool) :
state (msgs, st) = st
@[reducible, inline]

Native uniform strict PPT admissibility for a bit chosen-message adversary.

@[reducible, inline]

A chosen-message adversary for bit-word messages (List Bool).

@[reducible, inline]

Native uniform strict PPT admissibility for a bit-word chosen-message adversary.

def Cslib.Crypto.Encryption.gameOn {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :

The single-challenge chosen-message experiment with challenge-pair admissibility predicate valid ([BS23], Section 11.2, Attack Game 11.1, p. 436). Sample the key pair and pass the public key to adversary.choose. If valid n pk m₀ m₁ holds for the chosen pair, encrypt the selected message with the honest algorithm and return the adversary's guess; otherwise return false, in both experiments. The secret key is never passed to the adversary.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.game {Msg : Type} (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :

The unrestricted chosen-message experiment: gameOn with every challenge pair admissible.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.Encryption.advantage (experiment : Bool → ℕ → ProbComp Bool) (n : ℕ) :

The distinguishing advantage of a two-sided experiment experiment bit n at parameter n: the advantage between its runs with bit = false and bit = true. The adversary is already part of experiment, as in gameOn valid keyGen encrypt adversary; INDCPAOn asks that this advantage be negligible for every admissible adversary.

def Cslib.Crypto.Encryption.INDCPAOn {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encMsg : Msg ↪ List Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) :

Single-challenge IND-CPA for encryption over message encoding encMsg with challenge-pair admissibility predicate valid, against every uniform strict PPT adversary. The negligible bound may depend on the adversary, which is fixed before the parameter. This is semantic security, [BS23], Attack Game 11.1 and Definition 11.2 (pp. 436–437), with the source's rule that the two messages have the same length replaced by valid: a pair that valid rejects makes both experiments output false. With the equal-length rule it is the source's notion (WordINDCPA). Efficiency and correctness of keyGen and encrypt, which the source's scheme has, are separate properties.

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

Single-challenge IND-CPA with every challenge pair admissible: [BS23], Attack Game 11.1 and Definition 11.2 (pp. 436–437), with 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, as for Bool. At List Bool it is strictly stronger, so it is not the source's notion there; WordINDCPA is.

@[reducible, inline]
abbrev Cslib.Crypto.Encryption.INDCPA (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Bool → ProbComp (List Bool)) :

Single-challenge IND-CPA for bit encryption against every uniform strict PPT adversary: semantic security, [BS23], Attack Game 11.1 and Definition 11.2 (pp. 436–437), for the message space of single bits.

@[reducible, inline]

Single-challenge IND-CPA for bit-word encryption under Attack Game 11.1's equal-length rule ([BS23], Section 11.2, p. 436): challenge pairs with m₀.length ≠ m₁.length are inadmissible.

theorem Cslib.Crypto.Encryption.eval_gameOn {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(gameOn valid keyGen encrypt adversary bit n).eval = do let pk ← PMF.map Prod.fst (keyGen n).eval let choice ← (adversary.choose n pk).eval if valid n pk (ChoiceOut.msg₀ choice) (ChoiceOut.msg₁ choice) = true then do let ciphertext ← (encrypt n pk (if bit = true then ChoiceOut.msg₁ choice else ChoiceOut.msg₀ choice)).eval (adversary.guess n (ChoiceOut.state choice) ciphertext).eval else pure false

Only the public-key marginal of key generation is observed by gameOn.

theorem Cslib.Crypto.Encryption.eval_game {Msg : Type} (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(game keyGen encrypt adversary bit n).eval = do let pk ← PMF.map Prod.fst (keyGen n).eval let choice ← (adversary.choose n pk).eval let ciphertext ← (encrypt n pk (if bit = true then ChoiceOut.msg₁ choice else ChoiceOut.msg₀ choice)).eval (adversary.guess n (ChoiceOut.state choice) ciphertext).eval

Only the public-key marginal of key generation is observed by the unrestricted experiment.

theorem Cslib.Crypto.Encryption.INDCPAOn.congr {Msg : Type} {valid : ℕ → List Bool → Msg → Msg → Bool} {encMsg : Msg ↪ List Bool} {keyGen keyGen' : ℕ → ProbComp (List Bool × List Bool)} {encrypt encrypt' : ℕ → List Bool → Msg → ProbComp (List Bool)} (h : INDCPAOn valid encMsg keyGen encrypt) (hkeyGen : ∀ (n : ℕ), PMF.map Prod.fst (keyGen n).eval = PMF.map Prod.fst (keyGen' n).eval) (hencrypt : ∀ (n : ℕ) (pk : List Bool) (msg : Msg), (encrypt n pk msg).eval = (encrypt' n pk msg).eval) :
INDCPAOn valid encMsg keyGen' encrypt'

Equal public-key marginals and equal encryption laws preserve INDCPAOn.

theorem Cslib.Crypto.Encryption.INDCPAOf.congr {Msg : Type} {encMsg : Msg ↪ List Bool} {keyGen keyGen' : ℕ → ProbComp (List Bool × List Bool)} {encrypt encrypt' : ℕ → List Bool → Msg → ProbComp (List Bool)} (h : INDCPAOf encMsg keyGen encrypt) (hkeyGen : ∀ (n : ℕ), PMF.map Prod.fst (keyGen n).eval = PMF.map Prod.fst (keyGen' n).eval) (hencrypt : ∀ (n : ℕ) (pk : List Bool) (msg : Msg), (encrypt n pk msg).eval = (encrypt' n pk msg).eval) :
INDCPAOf encMsg keyGen' encrypt'

Equal public-key marginals and equal encryption laws preserve security.

theorem Cslib.Crypto.Encryption.INDCPA.congr {keyGen keyGen' : ℕ → ProbComp (List Bool × List Bool)} {encrypt encrypt' : ℕ → List Bool → Bool → ProbComp (List Bool)} (h : INDCPA keyGen encrypt) (hkeyGen : ∀ (n : ℕ), PMF.map Prod.fst (keyGen n).eval = PMF.map Prod.fst (keyGen' n).eval) (hencrypt : ∀ (n : ℕ) (pk : List Bool) (bit : Bool), (encrypt n pk bit).eval = (encrypt' n pk bit).eval) :
INDCPA keyGen' encrypt'

Equal public-key marginals and equal bit-encryption laws preserve security.

Playing a restricted game inside the unrestricted one #

def Cslib.Crypto.Encryption.AdversaryOf.restrict {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (adversary : AdversaryOf Msg) :

The adversary that plays gameOn valid inside the unrestricted game. Its choose runs adversary.choose n pk and puts the bit valid n pk m₀ m₁ in front of the saved state; its guess returns false when that bit is false and otherwise runs adversary.guess on the rest of the state. The challenge pair itself is passed on unchanged.

theorem Cslib.Crypto.Encryption.eval_game_restrict {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
(game keyGen encrypt (AdversaryOf.restrict valid adversary) bit n).eval = (gameOn valid keyGen encrypt adversary bit n).eval

Running the unrestricted game on adversary.restrict valid has the same output distribution as running gameOn valid on adversary.

Word-level algorithms as a typed scheme #

The two-stage adversary that adversary plays at parameter n: message selection returns the chosen pair as a MessagePair, and the saved state word is the two-stage state.

A uniform strict PPT word-level adversary is a uniform strict PPT two-stage family over the same encodings of the public key, challenge pair, ciphertext and state.

theorem Cslib.Crypto.Encryption.gameOn_eq_cpaExperiment {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (decrypt : List Bool → List Bool → Option Msg) (adversary : AdversaryOf Msg) (bit : Bool) (n : ℕ) :
gameOn valid keyGen encrypt adversary bit n = { keyGen := keyGen n, encrypt := encrypt n, decrypt := decrypt }.cpaExperiment (valid n) (adversary.toTwoStage n) bit

At each parameter n, the word-level experiment gameOn is the chosen-plaintext experiment of the scheme with key generation keyGen n and encryption encrypt n, played by adversary.toTwoStage n. The experiment never decrypts, so decrypt is arbitrary.

theorem Cslib.Crypto.Encryption.advantage_gameOn_eq_cpaExperiment {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (decrypt : List Bool → List Bool → Option Msg) (adversary : AdversaryOf Msg) (n : ℕ) :
advantage (gameOn valid keyGen encrypt adversary) n = ({ keyGen := keyGen n, encrypt := encrypt n, decrypt := decrypt }.cpaExperiment (valid n) (adversary.toTwoStage n) false).advantage ({ keyGen := keyGen n, encrypt := encrypt n, decrypt := decrypt }.cpaExperiment (valid n) (adversary.toTwoStage n) true)

The word-level advantage of gameOn at parameter n is the advantage between the two sides of the typed chosen-plaintext experiment, so a bound on one fixed scheme transfers to INDCPAOn.