Documentation

CslibFrontier.Crypto.Computational.Encryption.Deterministic

Deterministic public-key encryption is not semantically secure #

In a public-key encryption scheme, the adversary receives the public key and can encrypt any message itself. If encryption is deterministic, the adversary of Boneh and Shoup, Section 11.3.1, pp. 438–439 submits two distinct challenge messages (m₀, m₁), receives the challenge ciphertext c, computes c₀ ← E(pk, m₀) under the public key it saved, and outputs false (0) when c = c₀ and true (1) otherwise. In experiment false it outputs false with probability 1; in experiment true it outputs true with probability 1, so its semantic-security advantage is 1.

This module formalizes that adversary and its analysis at both layers of the public-key encryption API:

The hypotheses relate to [BS23], Section 11.3.1, as follows. CslibFrontierTests.Crypto.DeterministicPKE has checked instances showing that correctness, admissibility, m₀ ≠ m₁ and determinism are each needed.

Main definitions #

Main results #

References #

Typed layer #

def Cslib.Crypto.PKE.detAdversary {PK SK M C : Type} [BEq C] (E : PKE PK SK M C) (m₀ m₁ : M) :

The adversary of [BS23], Section 11.3.1 (p. 438), against a fixed scheme E: challenge with (m₀, m₁), save the public key pk, re-encrypt m₀ under pk, and output false (0) when the challenge equals that ciphertext and true (1) otherwise.

theorem Cslib.Crypto.PKE.eval_cpaExperiment_detAdversary_false {PK SK M C : Type} [BEq C] [LawfulBEq C] (E : PKE PK SK M C) (valid : PK → M → M → Bool) {m₀ m₁ : M} (hdet : ∀ keys ∈ E.keyGen.eval.support, ∃ (c : C), (E.encrypt keys.1 m₀).eval = PMF.pure c) :

In experiment false, if E.encrypt keys.1 m₀ is deterministic (a point mass) on every supported key pair keys, then E.detAdversary m₀ m₁ outputs false with probability 1 ([BS23], Section 11.3.1, p. 438).

theorem Cslib.Crypto.PKE.eval_cpaExperiment_detAdversary_true {PK SK M C : Type} [BEq C] [LawfulBEq C] (E : PKE PK SK M C) (valid : PK → M → M → Bool) {m₀ m₁ : M} (hvalid : ∀ keys ∈ E.keyGen.eval.support, valid keys.1 m₀ m₁ = true) (hne : ∀ keys ∈ E.keyGen.eval.support, ∀ c₁ ∈ (E.encrypt keys.1 m₁).eval.support, c₁ ∉ (E.encrypt keys.1 m₀).eval.support) :

In experiment true, if (m₀, m₁) is admissible and no ciphertext in the support of E.encrypt keys.1 m₁ belongs to the support of E.encrypt keys.1 m₀ on any supported key pair keys, then E.detAdversary m₀ m₁ outputs true with probability 1 ([BS23], Section 11.3.1, p. 438).

theorem Cslib.Crypto.PKE.advantage_cpaExperiment_detAdversary {PK SK M C : Type} [BEq C] [LawfulBEq C] (E : PKE PK SK M C) (valid : PK → M → M → Bool) {m₀ m₁ : M} (hvalid : ∀ keys ∈ E.keyGen.eval.support, valid keys.1 m₀ m₁ = true) (hdet : ∀ keys ∈ E.keyGen.eval.support, ∃ (c : C), (E.encrypt keys.1 m₀).eval = PMF.pure c) (hne : ∀ keys ∈ E.keyGen.eval.support, ∀ c₁ ∈ (E.encrypt keys.1 m₁).eval.support, c₁ ∉ (E.encrypt keys.1 m₀).eval.support) :
(E.cpaExperiment valid (E.detAdversary m₀ m₁) false).advantage (E.cpaExperiment valid (E.detAdversary m₀ m₁) true) = 1

Under the hypotheses of eval_cpaExperiment_detAdversary_false and eval_cpaExperiment_detAdversary_true, E.detAdversary m₀ m₁ achieves chosen-plaintext advantage 1 ([BS23], Section 11.3.1, pp. 438–439).

theorem Cslib.Crypto.PKE.Correct.notMem_support_encrypt {PK SK M C : Type} {E : PKE PK SK M C} (hE : E.Correct) {m₀ m₁ : M} (hm : m₀ ≠ m₁) {keys : PK × SK} (hkeys : keys ∈ E.keyGen.eval.support) {c : C} (hc : c ∈ (E.encrypt keys.1 m₁).eval.support) :
c ∉ (E.encrypt keys.1 m₀).eval.support

A correct scheme never encrypts two distinct messages to the same ciphertext under any supported key pair.

Word level #

def Cslib.Crypto.Encryption.detAdversary {Msg : Type} (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (m₀ m₁ : ℕ → Msg) :

The word-level adversary of [BS23], Section 11.3.1 (p. 438): at security parameter n, challenge with (m₀ n, m₁ n), save the public key pk as the state word, re-encrypt m₀ n under pk, and output c != c₀.

theorem Cslib.Crypto.Encryption.isPPT_detAdversary {Msg : Type} {encMsg : Msg ↪ List Bool} {encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)} {m₀ m₁ : ℕ → Msg} (hencrypt : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, pk, msg) => encrypt n pk msg) (hm₀ : Turing.MultiTapeTM.ComputableInPolyTime m₀ Turing.MultiTapeTM.encUnary encMsg) (hm₁ : Turing.MultiTapeTM.ComputableInPolyTime m₁ Turing.MultiTapeTM.encUnary encMsg) :
AdversaryOf.IsPPT encMsg (detAdversary encrypt m₀ m₁)

detAdversary encrypt m₀ m₁ is uniform strict PPT whenever encrypt is PPT on encKeyedInput encMsg and m₀, m₁ are computable in polynomial time from the unary security parameter.

theorem Cslib.Crypto.Encryption.advantage_gameOn_detAdversary {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (keyGen : ℕ → ProbComp (List Bool × List Bool)) (encrypt : ℕ → List Bool → Msg → ProbComp (List Bool)) (m₀ m₁ : ℕ → Msg) (n : ℕ) (hvalid : ∀ keys ∈ (keyGen n).eval.support, valid n keys.1 (m₀ n) (m₁ n) = true) (hdet : ∀ keys ∈ (keyGen n).eval.support, ∃ (c : List Bool), (encrypt n keys.1 (m₀ n)).eval = PMF.pure c) (hne : ∀ keys ∈ (keyGen n).eval.support, ∀ c₁ ∈ (encrypt n keys.1 (m₁ n)).eval.support, c₁ ∉ (encrypt n keys.1 (m₀ n)).eval.support) :
advantage (gameOn valid keyGen encrypt (detAdversary encrypt m₀ m₁)) n = 1

At security parameter n, detAdversary encrypt m₀ m₁ achieves gameOn advantage 1 when (m₀ n, m₁ n) is admissible, encryption of m₀ n is deterministic, and the ciphertext supports of m₀ n and m₁ n are disjoint under every supported key pair ([BS23], Section 11.3.1, pp. 438–439).

theorem Cslib.Crypto.Encryption.not_indcpaOn_of_deterministic {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)} (decrypt : ℕ → List Bool → List Bool → Option Msg) {m₀ m₁ : ℕ → Msg} (n₀ : ℕ) (hencrypt : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, pk, msg) => encrypt n pk msg) (hm₀ : Turing.MultiTapeTM.ComputableInPolyTime m₀ Turing.MultiTapeTM.encUnary encMsg) (hm₁ : Turing.MultiTapeTM.ComputableInPolyTime m₁ Turing.MultiTapeTM.encUnary encMsg) (hcorrect : ∀ (n : ℕ), n₀ ≤ n → { keyGen := keyGen n, encrypt := encrypt n, decrypt := decrypt n }.Correct) (hm : ∀ (n : ℕ), n₀ ≤ n → m₀ n ≠ m₁ n) (hvalid : ∀ (n : ℕ), n₀ ≤ n → ∀ keys ∈ (keyGen n).eval.support, valid n keys.1 (m₀ n) (m₁ n) = true) (hdet : ∀ (n : ℕ), n₀ ≤ n → ∀ keys ∈ (keyGen n).eval.support, ∃ (c : List Bool), (encrypt n keys.1 (m₀ n)).eval = PMF.pure c) :
¬INDCPAOn valid encMsg keyGen encrypt

A deterministic public-key encryption scheme is not semantically secure ([BS23], Section 11.3.1, pp. 438–439): if encrypt is PPT, m₀ and m₁ are computable in polynomial time, and from some parameter n₀ onward the scheme is correct, m₀ n ≠ m₁ n, the pair (m₀ n, m₁ n) is admissible under every supported public key, and encrypt n pk (m₀ n) is deterministic under every supported public key, then the scheme fails INDCPAOn valid encMsg.