Documentation

Complexity.Crypto.Computational.Encryption.Authenticated

Authenticated Encryption and Adaptive Chosen-Ciphertext Security #

This module formalizes symmetric authenticated encryption (AuthenticatedEncryption) and adaptive chosen-ciphertext security (INDCCA) following Boneh and Shoup, A Graduate Course in Applied Cryptography, Version 0.6, Chapter 5 (Sections 5.3 and 5.10) and Chapter 9 (Sections 9.1 and 9.2.2–9.2.3):

  1. Symmetric ciphers and adaptive CPA security (SymmetricCipher, cpaGame, INDCPA, not_indcpa_of_ciphertext_length_eq) ([BS23], Section 5.3, Attack Game 5.2, Definition 5.2, and Example 5.1, printed pp. 181–182; Exercise 5.10(a), printed p. 211): a uniform symmetric cipher on n-bit messages at security parameter n consists of strict PPT key generation keyGen, strict PPT encryption encrypt, and deterministic polynomial-time decryption decrypt returning Option (List Bool) (encoded via encOption encBits). In cpaGame, an adaptive OracleDistinguisher submits left-or-right pairs (m0, m1) of n-bit messages and receives encrypt n k (if bit then m1 else m0). We also formalize Example 5.1 and Exercise 5.10(a) (not_indcpa_of_ciphertext_length_eq): if every supported ciphertext of an n-bit message has length n, decryption completeness forces encrypt to be a deterministic permutation on n-bit strings, which a 2-query CPA adversary (detCPAAdversary) breaks with advantage 1.
  2. Ciphertext integrity and authenticated encryption (ciGame, CiphertextIntegrity, AuthenticatedEncryption) ([BS23], Section 9.1, Attack Game 9.1 and Definitions 9.1–9.2, printed pp. 358–359): in ciGame, an adaptive CIAdversary queries an encryption oracle on n-bit messages (logging returned ciphertexts in queriedCiphertexts) and wins by outputting a candidate ciphertext ct such that !queriedCiphertexts.contains ct and (decrypt n k ct).isSome. A cipher provides AuthenticatedEncryption when it satisfies both INDCPA and CiphertextIntegrity.
  3. Adaptive chosen-ciphertext security and AE $\Rightarrow$ CCA (ccaGame, INDCCA, ccaToCPAAdversary, ccaToCIAdversary, ccaToCIHiddenBitAdversary, advantage_ccaGame_le, advantage_ccaGame_le_two_mul, AuthenticatedEncryption.indcca) ([BS23], Sections 9.2.2–9.2.3, Attack Game 9.2, Definition 9.5, and Theorem 9.1, printed pp. 362–365): in ccaGame, a two-channel CCAAdversary (Operation = Bool) may interleave left-or-right encryption queries (false, recording challenge ciphertexts) with decryption queries (true, rejecting recorded challenge ciphertexts and returning encOption encBits (decrypt n k ct) on all other ciphertexts). Using the difference lemma (OracleComp.IdenticalUntilBad.advantage_le, [BS23], Theorem 4.7) between ccaGame and ccaRejectGame (where all decryption queries are rejected), we prove that every AuthenticatedEncryption cipher is INDCCA-secure.

The generic Encrypt-then-MAC composition ([BS23], Section 9.4.1, Theorem 9.2, printed pp. 367–368) and its concrete non-vacuous PRF-based cipher instance ([BS23], Section 5.4.1, Example 5.2 and Theorem 5.2, printed pp. 183–187) are planned for PR 3 of #1000.

Specializations and losses relative to Boneh–Shoup Chapter 9 #

Main definitions #

Main results #

References #

@[reducible, inline]

An adaptive ciphertext-integrity adversary receives the unary security parameter and an auxiliary word, queries an encryption oracle on chosen messages, and outputs a candidate ciphertext.

Instances For
    @[reducible, inline]

    An adaptive chosen-ciphertext distinguisher receives the unary security parameter and an auxiliary word, queries a left-or-right encryption oracle (false) and a decryption oracle (true), and outputs a distinguishing bit.

    Instances For

      A uniform symmetric cipher on n-bit messages at security parameter n, with strict probabilistic polynomial-time key generation and encryption, deterministic polynomial-time decryption (returning Option (List Bool)), and perfect decryption completeness on supported keys, n-bit messages, and ciphertexts ([BS23], Sections 5.3 and 9.1).

      Instances For

        E.keyGen composed with a plain polynomial-time parameter selector is uniformly strict PPT.

        E.encrypt composed with plain polynomial-time parameter, key, and message selectors is uniformly strict PPT.

        E.decrypt composed with plain polynomial-time parameter, key, and ciphertext selectors is computable in plain polynomial time.

        Adaptive Chosen-Plaintext Security (cpaGame, INDCPA) #

        Stateful left-or-right CPA encryption oracle ([BS23], Section 5.3, Attack Game 5.2): decode the request into m0 = unframe request.2 and m1 = dropFrame request.2; if both have length n, encrypt if bit then m1 else m0 under k, and otherwise return [].

        Instances For

          The adaptive symmetric IND-CPA experiment ([BS23], Section 5.3, Attack Game 5.2): sample k ← E.keyGen n and run adversary n [] against E.cpaEncryptionOracle n k bit.

          Instances For

            The symmetric CPA experiment is uniformly strict PPT in the unary security parameter.

            The symmetric CPA experiment is uniformly strict PPT, independently of unused auxiliary input.

            Adaptive chosen-plaintext security (INDCPA) for a symmetric cipher ([BS23], Section 5.3, Attack Game 5.2 and Definition 5.2): every uniform strict IsOraclePPT encBool distinguisher has negligible advantage between E.cpaGame adversary false and E.cpaGame adversary true.

            Instances For

              Impossibility of Zero-Expansion CPA Security (Boneh–Shoup Example 5.1 & Exercise 5.10(a)) #

              theorem Cslib.Crypto.SymmetricCipher.encrypt_eq_of_ciphertext_length_eq (E : SymmetricCipher) {n : ℕ} {ke : List Bool} (hke : ke ∈ (E.keyGen n).eval.support) (hctLen : ∀ (msg : List Bool), msg.length = n → ∀ c ∈ (E.encrypt n ke msg).eval.support, c.length = n) {msg : List Bool} (hmsg : msg.length = n) {c₁ c₂ : List Bool} (hc₁ : c₁ ∈ (E.encrypt n ke msg).eval.support) (hc₂ : c₂ ∈ (E.encrypt n ke msg).eval.support) :
              c₁ = c₂

              Zero ciphertext expansion forces deterministic encryption ([BS23], Exercise 5.10(a), printed p. 211): if every supported ciphertext of an n-bit message under a supported key ke at parameter n has length n, then decryption completeness (E.decrypt_encrypt) gives an injection from the 2^n plaintexts BitString n into BitString n by choosing one supported ciphertext per plaintext; by finiteness of BitString n, this map is surjective, forcing all supported ciphertexts of any n-bit plaintext msg under ke to coincide.

              Two-query CPA distinguisher against any deterministic symmetric cipher ([BS23], Example 5.1, printed p. 182): queries (0^n, 1^n) followed by (0^n, 0^n) and outputs true iff the two returned ciphertexts are equal (c₁ == c₂).

              Instances For
                theorem Cslib.Crypto.SymmetricCipher.eval_cpaGame_detCPAAdversary_false (E : SymmetricCipher) (n : ℕ) (hctLen : ∀ ke ∈ (E.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ c ∈ (E.encrypt n ke msg).eval.support, c.length = n) :

                In Experiment false, detCPAAdversary receives two encryptions of 0^n; when all supported ciphertexts of n-bit plaintexts have length n, both encryptions return the same ciphertext and detCPAAdversary outputs true with probability 1.

                theorem Cslib.Crypto.SymmetricCipher.eval_cpaGame_detCPAAdversary_true (E : SymmetricCipher) {n : ℕ} (hn : 1 ≤ n) (hctLen : ∀ ke ∈ (E.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ c ∈ (E.encrypt n ke msg).eval.support, c.length = n) :

                In Experiment true for n ≥ 1, detCPAAdversary receives an encryption of 1^n followed by an encryption of 0^n; by decryption completeness the two ciphertexts are distinct, so detCPAAdversary outputs false with probability 1.

                theorem Cslib.Crypto.SymmetricCipher.advantage_cpaGame_detCPAAdversary (E : SymmetricCipher) {n : ℕ} (hn : 1 ≤ n) (hctLen : ∀ ke ∈ (E.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ c ∈ (E.encrypt n ke msg).eval.support, c.length = n) :

                At every security parameter n ≥ 1 where supported ciphertexts of n-bit plaintexts have length n, detCPAAdversary achieves CPA advantage 1 ([BS23], Example 5.1).

                theorem Cslib.Crypto.SymmetricCipher.not_indcpa_of_ciphertext_length_eq (E : SymmetricCipher) (hctLen : ∀ (n : ℕ), ∀ ke ∈ (E.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ c ∈ (E.encrypt n ke msg).eval.support, c.length = n) :

                No zero-expansion symmetric cipher is CPA-secure ([BS23], Example 5.1 and Exercise 5.10(a), printed pp. 182, 211): if for every security parameter n, every supported key ke, and every n-bit message msg, every supported ciphertext of msg has length n, then E cannot satisfy INDCPA.

                Ciphertext Integrity and Authenticated Encryption (ciGame, CiphertextIntegrity, #

                AuthenticatedEncryption)

                Stateful encryption oracle for the ciphertext-integrity game ([BS23], Section 9.1, Attack Game 9.1): if request.2.length == n, encrypt request.2 under k, prepend the resulting ciphertext to queriedCiphertexts, and return it; otherwise return [] without modifying the ciphertext log.

                Instances For

                  The ciphertext-integrity experiment ([BS23], Section 9.1, Attack Game 9.1): sample k ← E.keyGen n, run adversary n [] with oracle access to E.ciEncryptionOracle n k, and accept when the adversary outputs a candidate ciphertext ct that was never returned by the encryption oracle (!out.2.contains out.1) and decrypts without rejection ((E.decrypt n k out.1).isSome).

                  Instances For

                    The ciphertext-integrity experiment is uniformly strict PPT in the unary security parameter.

                    The ciphertext-integrity experiment is uniformly strict PPT, independently of unused auxiliary input.

                    Ciphertext integrity (CiphertextIntegrity, or CI) for a symmetric cipher ([BS23], Section 9.1, Attack Game 9.1 and Definition 9.1): every uniform strict IsOraclePPT encBits adversary has negligible probability of outputting a fresh valid ciphertext.

                    Instances For

                      Ciphertext integrity gives negligible winning probability in ciGame for every oracle-PPT CI adversary.

                      Establish CiphertextIntegrity by bounding every oracle-PPT CI adversary's winning probability.

                      Authenticated encryption (AuthenticatedEncryption, or AE-security) for a symmetric cipher ([BS23], Section 9.1, Definition 9.2): the cipher satisfies both INDCPA and CiphertextIntegrity.

                      Instances For

                        Adaptive Chosen-Ciphertext Security (ccaGame, ccaRejectGame, INDCCA) #

                        noncomputable def Cslib.Crypto.SymmetricCipher.ccaOracle (E : SymmetricCipher) (n : ℕ) (k : List Bool) (bit : Bool) (request : Bool × List Bool) :

                        Stateful two-channel oracle for the adaptive chosen-ciphertext experiment ([BS23], Section 9.2.2, Attack Game 9.2):

                        • On an encryption query (false, req): decode m0 = unframe req and m1 = dropFrame req; if both have length n, encrypt if bit then m1 else m0 under k, prepend the resulting ciphertext ct to queriedCiphertexts, and return ct; otherwise return [].
                        • On a decryption query (true, ct): if queriedCiphertexts.contains ct is true, return [] (prohibited challenge ciphertext); otherwise return encOption encBits (E.decrypt n k ct).
                        Instances For
                          noncomputable def Cslib.Crypto.SymmetricCipher.ccaGame (E : SymmetricCipher) (adversary : CCAAdversary) (bit : Bool) (n : ℕ) :

                          The adaptive chosen-ciphertext experiment ([BS23], Section 9.2.2, Attack Game 9.2): sample k ← E.keyGen n and run adversary n [] against E.ccaOracle n k bit.

                          Instances For

                            The adaptive CCA experiment is uniformly strict PPT in the unary security parameter.

                            The adaptive CCA experiment is uniformly strict PPT, independently of unused auxiliary input.

                            Adaptive chosen-ciphertext security (INDCCA, or CCA-security) for a symmetric cipher ([BS23], Section 9.2.2, Attack Game 9.2 and Definition 9.5, printed p. 362): every uniform strict IsOraclePPT encBool CCA adversary has negligible advantage between E.ccaGame adversary false and E.ccaGame adversary true.

                            In [BS23], Section 9.2.2, Definition 9.5 defines adaptive multi-query CCA security, whereas one-time CCA security (1CCA) is defined separately in Definition 9.6 (printed p. 363).

                            Instances For

                              Authenticated Encryption Implies Adaptive CCA Security (Boneh–Shoup Theorem 9.1) #

                              Hybrid two-channel oracle for Game 1 in the proof of [BS23], Theorem 9.1 (Section 9.2.3, printed pp. 363–364): encryption queries (false, req) behave identically to ccaOracle, whereas every decryption query (true, _) immediately returns [] (rejection) without invoking decrypt.

                              Instances For
                                noncomputable def Cslib.Crypto.SymmetricCipher.ccaRejectGame (E : SymmetricCipher) (adversary : CCAAdversary) (bit : Bool) (n : ℕ) :

                                The all-reject hybrid CCA experiment (Game 1 in [BS23], Section 9.2.3, Theorem 9.1): sample k ← E.keyGen n and run adversary n [] against E.ccaRejectOracle n k bit.

                                Instances For

                                  Stateful handler for ccaToCPAAdversary ([BS23], Section 9.2.3, Theorem 9.1): reject all decryption queries (true, _) with [], and forward valid left-or-right encryption queries (false, req) to the external CPA encryption oracle (truncating replies to ctBound).

                                  Instances For

                                    Reduction from the all-reject hybrid ccaRejectGame to the adaptive CPA experiment cpaGame ([BS23], Section 9.2.3, adversary $B_{\mathrm{cpa}}$ in Theorem 9.1): run adversary n [] against ccaToCPAHandler n (ctBound n).

                                    Instances For
                                      theorem Cslib.Crypto.SymmetricCipher.eval_cpaGame_ccaToCPAAdversary (E : SymmetricCipher) (ctBound : ℕ → ℕ) (adversary : CCAAdversary) (bit : Bool) (n : ℕ) (hctBound : ∀ k ∈ (E.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ ct ∈ (E.encrypt n k msg).eval.support, ct.length ≤ ctBound n) :
                                      (E.cpaGame (ccaToCPAAdversary ctBound adversary) bit n).eval = (E.ccaRejectGame adversary bit n).eval

                                      When ctBound n bounds all ciphertext lengths produced by E.encrypt n k on n-bit messages, running ccaToCPAAdversary ctBound adversary in cpaGame has the exact same output distribution as ccaRejectGame adversary ([BS23], Section 9.2.3, equation (9.7) in the proof of Theorem 9.1, printed p. 365).

                                      Stateful handler for ccaToCIAtIndexAdversary and ccaToCIAdversary ([BS23], Section 9.2.3, adversary $B_{\mathrm{ci}}$ in Theorem 9.1): maintains (rem, (hasCaptured, capturedCt)) : ℕ × (Bool × List Bool).

                                      • Once hasCaptured = true, all subsequent queries return [] without calling the external CI encryption oracle.
                                      • While hasCaptured = false:
                                        • if rem == 0, a decryption query (true, ct) captures (0, (true, ct)) and an encryption query (false, _) captures (0, (true, [])), both returning [] without calling the external CI oracle;
                                        • if rem != 0, a decryption query (true, _) returns ([], (rem - 1, (false, []))), and an encryption query (false, req) with (unframe req).length == n && (dropFrame req).length == n queries the external CI encryption oracle on if bit then dropFrame req else unframe req (truncating the reply to ctBound) and transitions to (rem - 1, (false, [])).
                                      Instances For
                                        noncomputable def Cslib.Crypto.SymmetricCipher.ccaToCIAtIndexAdversary (ctBound : ℕ → ℕ) (j : ℕ) (bit : Bool) (adversary : CCAAdversary) :

                                        Deterministic-index ciphertext-integrity reduction at query countdown j ([BS23], Section 9.2.3, Theorem 9.1): run adversary n [] against ccaToCIHandler n (ctBound n) bit starting from (j, (false, [])) and output the captured ciphertext candidate out.2.2.2.

                                        Instances For
                                          noncomputable def Cslib.Crypto.SymmetricCipher.ccaToCIAdversary (ctBound Q : ℕ → ℕ) (bit : Bool) (adversary : CCAAdversary) :

                                          Reduction from decryption-oracle forgery in ccaRejectGame to the ciphertext-integrity game ciGame for fixed challenge bit bit ([BS23], Section 9.2.3, adversary $B_{\mathrm{ci}}$ in Theorem 9.1): sample a uniform dyadic query countdown j ← ProbOracleComp.sample (ProbComp.sampleDyadicIndex (Q n)) and run ccaToCIAtIndexAdversary ctBound j bit adversary.

                                          Instances For

                                            Single-adversary ciphertext-integrity reduction that samples a hidden challenge bit uniformly via BitString.sampleList 1 and invokes ccaToCIAdversary ([BS23], Section 9.2.3, proof of Theorem 9.1, printed p. 364).

                                            Instances For

                                              Difference-Lemma Hop and Query-Budget Induction for Theorem 9.1 #

                                              theorem Cslib.Crypto.SymmetricCipher.eval_ciGame_ccaToCIAdversary (E : SymmetricCipher) (ctBound Q : ℕ → ℕ) (bit : Bool) (adversary : CCAAdversary) (n : ℕ) :
                                              (E.ciGame (ccaToCIAdversary ctBound Q bit adversary) n).eval = (Probability.PMF.uniformOfFintype (Fin (Probability.dyadicSize (Q n)))).bind fun (i : Fin (Probability.dyadicSize (Q n))) => (E.ciGame (ccaToCIAtIndexAdversary ctBound (↑i) bit adversary) n).eval

                                              Running ccaToCIAdversary in ciGame averages ccaToCIAtIndexAdversary uniformly over Fin (dyadicSize (Q n)).

                                              theorem Cslib.Crypto.SymmetricCipher.advantage_ccaGame_le (E : SymmetricCipher) (ctBound Q : ℕ → ℕ) (adversary : CCAAdversary) (n : ℕ) (hq : ProbOracleComp.IsQueryBounded (adversary n []) (Q n)) (hctBound : ∀ k ∈ (E.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ ct ∈ (E.encrypt n k msg).eval.support, ct.length ≤ ctBound n) :
                                              ↑(Game.advantage (E.ccaGame adversary false n).eval (E.ccaGame adversary true n).eval) ≤ ↑(Probability.dyadicSize (Q n)) * ↑(Game.succProbability (E.ciGame (ccaToCIAdversary ctBound Q false adversary) n).eval) + ↑(Game.advantage (E.cpaGame (ccaToCPAAdversary ctBound adversary) false n).eval (E.cpaGame (ccaToCPAAdversary ctBound adversary) true n).eval) + ↑(Probability.dyadicSize (Q n)) * ↑(Game.succProbability (E.ciGame (ccaToCIAdversary ctBound Q true adversary) n).eval)

                                              Quantitative AE $\Rightarrow$ CCA bound ([BS23], Section 9.2.3, Theorem 9.1, printed pp. 363–365): for any CCAAdversary making at most Q n total oracle queries at security parameter n, the adaptive CCA distinguishing advantage is bounded by the CPA advantage of ccaToCPAAdversary plus dyadicSize (Q n) times the ciphertext-integrity winning probabilities of ccaToCIAdversary for bit = false and bit = true.

                                              Relative to equation (9.3) in [BS23] (CCAadv[A, E] ≤ CPAadv[Bcpa, E] + 2 Qd · CIadv[Bci, E]), ccaToCIAdversary samples a query index uniformly from {0, ..., dyadicSize (Q n) - 1} over the total query budget Q n ≥ Qe + Qd, giving coefficient dyadicSize (Q n) ≤ 2 * Q n + 2 per bit.

                                              theorem Cslib.Crypto.SymmetricCipher.eval_ciGame_ccaToCIHiddenBitAdversary (E : SymmetricCipher) (ctBound Q : ℕ → ℕ) (adversary : CCAAdversary) (n : ℕ) :
                                              (E.ciGame (ccaToCIHiddenBitAdversary ctBound Q adversary) n).eval = (Probability.PMF.uniformOfFintype Bool).bind fun (bit : Bool) => (E.ciGame (ccaToCIAdversary ctBound Q bit adversary) n).eval

                                              Running ccaToCIHiddenBitAdversary in ciGame averages ccaToCIAdversary uniformly over bit : Bool.

                                              theorem Cslib.Crypto.SymmetricCipher.advantage_ccaGame_le_two_mul (E : SymmetricCipher) (ctBound Q : ℕ → ℕ) (adversary : CCAAdversary) (n : ℕ) (hq : ProbOracleComp.IsQueryBounded (adversary n []) (Q n)) (hctBound : ∀ k ∈ (E.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ ct ∈ (E.encrypt n k msg).eval.support, ct.length ≤ ctBound n) :
                                              ↑(Game.advantage (E.ccaGame adversary false n).eval (E.ccaGame adversary true n).eval) ≤ 2 * ↑(Probability.dyadicSize (Q n)) * ↑(Game.succProbability (E.ciGame (ccaToCIHiddenBitAdversary ctBound Q adversary) n).eval) + ↑(Game.advantage (E.cpaGame (ccaToCPAAdversary ctBound adversary) false n).eval (E.cpaGame (ccaToCPAAdversary ctBound adversary) true n).eval)

                                              Single-adversary quantitative AE $\Rightarrow$ CCA bound ([BS23], Section 9.2.3, Theorem 9.1, equation (9.3) and proof on printed pp. 363–364): using ccaToCIHiddenBitAdversary to sample the hidden challenge bit uniformly yields factor 2 * dyadicSize (Q n) ≤ 4 * Q n + 4 (over the total query budget Q n, vs. 2 * Qd over decryption queries in (9.3)) on the single CI adversary.

                                              Authenticated encryption implies adaptive CCA security ([BS23], Section 9.2.3, Theorem 9.1, printed pp. 363–365): every symmetric cipher satisfying AuthenticatedEncryption (INDCPA ∧ CiphertextIntegrity) also satisfies INDCCA (the multi-query AE ⇒ CCA half of Theorem 9.1; the one-time 1AE ⇒ 1CCA half over Definition 9.6 is omitted).