Documentation

CslibFrontier.Crypto.Computational.Encryption.PublicKeyCPA

Chosen-plaintext attacks on public-key encryption #

In the eavesdropping experiment Cslib.Crypto.Encryption.gameOn the adversary already holds the public key, so it can encrypt any message itself. Katz and Lindell conclude that, for public-key encryption, indistinguishability against eavesdroppers implies security against chosen-plaintext attacks ([KL20], Section 12.2.1, Proposition 12.3, p. 406). This module states the chosen-plaintext experiment with an explicit encryption oracle and proves that implication.

The chosen-plaintext experiment is the public-key form of [KL20], Definition 3.21: both stages of the adversary may query an encryption oracle that encrypts any message under the public key with fresh coins. For one fixed scheme E : PKE PK SK M C, E.cpaOracleExperiment is stated with typed keys, messages and ciphertexts against a PKE.CPAOracleAdversary, whose stages are oracle programs over the typed encryption oracle E.encrypt pk. The adversary that answers its own queries, A.toTwoStage E, plays the eavesdropping experiment E.cpaExperiment with exactly the same law (PKE.cpaOracleExperiment_eq_cpaExperiment), which is Proposition 12.3 at one scheme.

Asymptotic security quantifies over uniform strict oracle PPT adversaries, which are word-level oracle programs: both stages of a Cslib.Crypto.Encryption.WordCPAAdversary query the oracle with bit words. The challenge stage and the admissibility predicate valid are those of gameOn. At each parameter, cpaOracleGameOn is the typed experiment of the scheme with the same algorithms, played by adversary.toCPAOracleAdversary n (cpaOracleGameOn_eq_cpaOracleExperiment).

Main definitions #

Main results #

The multiple-encryption form with a left-or-right oracle ([KL20], Section 12.2.2, Theorem 12.6, p. 408) is not formalized here.

References #

A chosen-plaintext adversary against a public-key scheme with public keys PK, messages M and ciphertexts C. Both stages are oracle programs that may ask the encryption oracle for an encryption of any message m : M; σ is the state saved between the stages.

  • choose : PK → ProbOracleComp (fun (x : M) => C) (MessagePair M × σ)

    Receive the public key, query the oracle, and choose two challenge messages and a state.

  • guess : σ → C → ProbOracleComp (fun (x : M) => C) Bool

    Receive the saved state and the challenge ciphertext, query the oracle, and return a guess.

def Cslib.Crypto.PKE.cpaOracleExperiment {PK SK M C σ : Type} (E : PKE PK SK M C) (valid : PK → M → M → Bool) (A : CPAOracleAdversary PK M C σ) (b : Bool) :

The chosen-plaintext experiment of the scheme E with challenge-pair admissibility predicate valid (the public-key form of [KL20], Definition 3.21). Draw a key pair; run message selection against the encryption oracle E.encrypt pk; if valid pk m₀ m₁ holds, encrypt the message selected by b and run the guessing stage against the same oracle, and otherwise return false.

def Cslib.Crypto.PKE.CPAOracleAdversary.toTwoStage {PK SK M C σ : Type} (E : PKE PK SK M C) (A : CPAOracleAdversary PK M C σ) :
TwoStage PK (MessagePair M) C Bool (PK × σ)

The eavesdropper that runs A and answers its oracle queries by encrypting under the public key, which it saves next to A's state.

theorem Cslib.Crypto.PKE.cpaOracleExperiment_eq_cpaExperiment {PK SK M C σ : Type} (E : PKE PK SK M C) (valid : PK → M → M → Bool) (A : CPAOracleAdversary PK M C σ) (b : Bool) :

Against a public-key scheme, the encryption oracle gives the adversary nothing that the public key does not: the eavesdropping experiment of A.toTwoStage E is the chosen-plaintext experiment of A ([KL20], Proposition 12.3, for one fixed scheme).

The encryption oracle under public key pk at parameter n: answer each query word request.2 with a fresh encryption of it. The oracle keeps no state.

noncomputable def Cslib.Crypto.Encryption.runWithEncryption {α : Type} (encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)) (n : ℕ) (pk : List Bool) (program : Probability.WordOracleComp Unit α) :

Run an oracle program against encryptionOracle encrypt n pk, with private coins sampled uniformly, and return its result.

A chosen-plaintext adversary on bit words. Both stages may query the encryption oracle.

Uniform strict oracle PPT admissibility of both stages of a WordCPAAdversary.

noncomputable def Cslib.Crypto.Encryption.cpaOracleGameOn (valid : ℕ → List Bool → List Bool → List Bool → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)) (adversary : WordCPAAdversary) (bit : Bool) (n : ℕ) :

The chosen-plaintext experiment with challenge-pair admissibility predicate valid, the public-key form of [KL20], Definition 3.21. Sample the key pair; run message selection against the encryption oracle; if valid n pk m₀ m₁ holds, encrypt the selected message and run the guessing stage against the oracle, and otherwise return false in both experiments.

def Cslib.Crypto.Encryption.WordINDCPAOracleOn (valid : ℕ → List Bool → List Bool → List Bool → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)) :

Security against chosen-plaintext attacks with admissibility predicate valid, against every uniform strict oracle PPT adversary.

@[reducible, inline]

Security against chosen-plaintext attacks under the equal-length rule of [KL20], Definition 3.21.

The typed adversary that adversary plays at parameter n: each word query (_, m) becomes the typed query m, message selection returns the chosen pair as a MessagePair, and the saved state word is the typed state.

theorem Cslib.Crypto.Encryption.runWithEncryption_eq_run {α : Type} (encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)) (n : ℕ) (pk : List Bool) (program : Probability.WordOracleComp Unit α) :
runWithEncryption encrypt n pk program = (ProbOracleComp.simulate (fun (request : Unit × List Bool) => ProbOracleComp.query request.2) program).run (encrypt n pk)

Running a word oracle program against encryptionOracle encrypt n pk runs its typed form against the typed oracle encrypt n pk.

theorem Cslib.Crypto.Encryption.cpaOracleGameOn_eq_cpaOracleExperiment (valid : ℕ → List Bool → List Bool → List Bool → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)) (decrypt : List Bool → List Bool → Option (List Bool)) (adversary : WordCPAAdversary) (bit : Bool) (n : ℕ) :
cpaOracleGameOn valid keyGen encrypt adversary bit n = { keyGen := keyGen n, encrypt := encrypt n, decrypt := decrypt }.cpaOracleExperiment (valid n) (adversary.toCPAOracleAdversary n) bit

The chosen-plaintext experiment at parameter n is the typed experiment of the scheme with key generation keyGen n and encryption encrypt n, played by adversary.toCPAOracleAdversary n. The experiment never decrypts, so decrypt is arbitrary.

The eavesdropper that runs a chosen-plaintext adversary and answers its oracle queries by encrypting under the public key. Message selection saves the public key in front of the adversary's state; guessing reads it back.

@[reducible, inline]

Encryption-algorithm input (1ⁿ, pk, msg): the security parameter n in unary, then the public key and the plaintext, both as bit words.

theorem Cslib.Crypto.Encryption.isPPTOn_runWithEncryption {Caller α β : Type} {input : Caller ↪ List Bool} {source : α ↪ List Bool} {output : β ↪ List Bool} {encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)} {param : Caller → ℕ} {pk : Caller → List Bool} {prepare : Caller → α} {program : α → Probability.WordOracleComp Unit β} (hencrypt : Probability.IsPPTOn encEncryptInput Turing.MultiTapeTM.encBits fun (p : ℕ × List Bool × List Bool) => encrypt p.1 p.2.1 p.2.2) (hparam : Turing.MultiTapeTM.ComputableInPolyTime param input Turing.MultiTapeTM.encUnary) (hpk : Turing.MultiTapeTM.ComputableInPolyTime pk input Turing.MultiTapeTM.encBits) (hprepare : Turing.MultiTapeTM.ComputableInPolyTime prepare input source) (hprogram : Probability.IsOraclePPTOn source output program) :
Probability.IsPPTOn input output fun (a : Caller) => runWithEncryption encrypt (param a) (pk a) (program (prepare a))

Running an oracle PPT program against the encryption oracle is PPT, when the parameter, the public key and the program input are computed in polynomial time from the caller's input.

theorem Cslib.Crypto.Encryption.WordCPAAdversary.isPPT_toAdversary {encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)} {adversary : WordCPAAdversary} (hencrypt : Probability.IsPPTOn encEncryptInput Turing.MultiTapeTM.encBits fun (p : ℕ × List Bool × List Bool) => encrypt p.1 p.2.1 p.2.2) (hadversary : adversary.IsPPT) :
(toAdversary encrypt adversary).IsPPT

The eavesdropper adversary.toAdversary encrypt is uniform strict PPT, including its saved public key, when the adversary and the honest encryption algorithm are.

theorem Cslib.Crypto.Encryption.WordCPAAdversary.eval_gameOn_toAdversary (valid : ℕ → List Bool → List Bool → List Bool → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)) (adversary : WordCPAAdversary) (bit : Bool) (n : ℕ) :
(gameOn valid keyGen encrypt (toAdversary encrypt adversary) bit n).eval = (cpaOracleGameOn valid keyGen encrypt adversary bit n).eval

The eavesdropping experiment of adversary.toAdversary encrypt is the chosen-plaintext experiment of adversary.

theorem Cslib.Crypto.Encryption.INDCPAOn.wordINDCPAOracleOn {valid : ℕ → List Bool → List Bool → List Bool → Bool} {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)} (hencrypt : Probability.IsPPTOn encEncryptInput Turing.MultiTapeTM.encBits fun (p : ℕ × List Bool × List Bool) => encrypt p.1 p.2.1 p.2.2) (hsecure : INDCPAOn valid Turing.MultiTapeTM.encBits keyGen encrypt) :
WordINDCPAOracleOn valid keyGen encrypt

Indistinguishability against eavesdroppers implies security against chosen-plaintext attacks, for any admissibility predicate ([KL20], Proposition 12.3).

theorem Cslib.Crypto.Encryption.WordINDCPA.wordINDCPAOracle {keyGen : ℕ → ProbComp (List Bool × List Bool)} {encrypt : ℕ → List Bool → List Bool → ProbComp (List Bool)} (hencrypt : Probability.IsPPTOn encEncryptInput Turing.MultiTapeTM.encBits fun (p : ℕ × List Bool × List Bool) => encrypt p.1 p.2.1 p.2.2) (hsecure : WordINDCPA keyGen encrypt) :
WordINDCPAOracle keyGen encrypt

Indistinguishability against eavesdroppers implies security against chosen-plaintext attacks, under the equal-length rule ([KL20], Proposition 12.3).