Documentation

CslibFrontier.Crypto.Computational.Encryption.EncryptThenMAC

Encrypt-then-MAC Authenticated Encryption and PRF-Based Instantiation #

This module formalizes the generic Encrypt-then-MAC composition (encryptThenMAC) and its security reductions (Boneh and Shoup, A Graduate Course in Applied Cryptography, Version 0.6, Section 9.4.1 and Theorem 9.2, printed pp. 367–368), together with a concrete randomized PRF-based symmetric cipher (prfCipher, [BS23], Section 5.4.1, Example 5.2 and Theorem 5.2, printed pp. 183–189) that witnesses joint non-vacuity of all hypotheses:

  1. Generic Encrypt-then-MAC composition (encryptThenMAC, etmToMACForger, etmToOneTimeMACForger, etmToCPAAdversary, etmToOneTimeCPAAdversary, isQueryBounded_etmToMACForger, isQueryBounded_etmToCPAAdversary, succProbability_ciGame_encryptThenMAC_eq, succProbability_ciOneTimeGame_encryptThenMAC_eq, advantage_cpaGame_encryptThenMAC_eq, advantage_cpaOneTimeGame_encryptThenMAC_eq, ciphertextIntegrity_encryptThenMAC, oneTimeCiphertextIntegrity_encryptThenMAC, indcpa_encryptThenMAC, oneTimeINDCPA_encryptThenMAC, authenticatedEncryption_encryptThenMAC, oneTimeAuthenticatedEncryption_encryptThenMAC, indcca_encryptThenMAC, oneTimeINDCCA_encryptThenMAC) ([BS23], Section 9.4.1, Theorem 9.2, printed pp. 367–368): given a symmetric cipher E : SymmetricCipher whose ciphertexts on n-bit plaintexts under supported keys at security parameter n have length M.msgLen n, and a message authentication code M : MACScheme authenticating M.msgLen n-bit messages:
  2. Concrete non-vacuous PRF-based symmetric cipher and end-to-end Encrypt-then-MAC instance (prfCipher, cpaToPrfDistinguisher, advantage_cpaGame_prfCipher_le, PseudorandomFunction.indcpa_prfCipher, prfEncryptThenMAC, PseudorandomFunction.authenticatedEncryption_prfEncryptThenMAC, PseudorandomFunction.indcca_prfEncryptThenMAC) ([BS23], Section 5.4.1, Example 5.2 and Theorem 5.2, printed pp. 183–189): for any PseudorandomFunction family, prfCipher encrypts an n-bit message msg under an n-bit key k by sampling a random nonce r ← BitString.sampleList n and outputting the 2 * n-bit ciphertext r ++ List.zipWith xor (family k r) msg. Using StateLens.probIdenticalUntilBad_latch between the lazy random-function game (Boneh–Shoup Game 2, "faithful gnome") and the fresh one-time-pad game (Boneh–Shoup Game 3, "forgetful gnome") together with StateLens.toOuterMeasure_latch_le, we prove the quantitative CPA bound of Theorem 5.2 and derive PseudorandomFunction.indcpa_prfCipher. Combining prfCipher with (prfMAC family hprf.polyTime).reindex (fun n => 2 * n) _ produces prfEncryptThenMAC, which satisfies AuthenticatedEncryption and INDCCA assuming only PseudorandomFunction family.

Specializations and omissions relative to Boneh–Shoup Section 9.4.1 and Section 5.4.1 #

Main definitions #

Main results #

References #

Generic Encrypt-then-MAC Construction and Security (Boneh–Shoup Section 9.4.1) #

noncomputable def Cslib.Crypto.encryptThenMAC (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) :

Encrypt-then-MAC symmetric cipher ([BS23], Section 9.4.1, printed p. 367): given a symmetric cipher E : SymmetricCipher whose ciphertexts on n-bit messages under supported keys at security parameter n have length M.msgLen n, and a message authentication code M : MACScheme on M.msgLen n-bit messages:

  • keyGen n samples independent keys ke ← E.keyGen n and km ← M.keyGen n and returns encPair encBits encBits (ke, km).
  • encrypt n k msg encrypts c ← E.encrypt n (unframe k) msg, computes a tag tag ← M.sign (dropFrame k) c, and returns encPair encBits encBits (c, tag).
  • decrypt n k ct checks canonical pair framing encPair encBits encBits (unframe ct, dropFrame ct) == ct, checks (unframe ct).length == M.msgLen n, and verifies M.verify (dropFrame k) (unframe ct) (dropFrame ct); if all three hold, it returns E.decrypt n (unframe k) (unframe ct), and otherwise none.
  • The ciphertext space ctSpace n is the canonically framed pairs (c, tag) with c an M.msgLen n-bit word of E.ctSpace n and tag any word: the source's C × T, where MACScheme declares no tag space.

Canonical pair framing encPair encBits encBits (c, tag) establishes a bijection between valid encoded ciphertexts ct and pairs (c, tag) with c.length = M.msgLen n, so ciphertext freshness in ciGame coincides with pair freshness in M.sufCmaGame.

Ciphertext-Integrity to SUF-CMA Reduction for Theorem 9.2 #

Open stateful handler that simulates the ciEncryptionOracle of encryptThenMAC E M inside M.sufCmaGame ([BS23], Section 9.4.1, Theorem 9.2, Part 1): on an n-bit message query request.2, it encrypts c ← E.encrypt n ke request.2, queries the external MAC signing oracle on ((), c) (truncating the returned tag to tagBound bits), and returns encPair encBits encBits (c, tag).

noncomputable def Cslib.Crypto.etmToMACForger (E : SymmetricCipher) (M : MACScheme) (tagBound : ℕ → ℕ) (adversary : CIAdversary) :

Ciphertext-integrity to SUF-CMA reduction etmToMACForger ([BS23], Section 9.4.1, Theorem 9.2, Part 1, printed pp. 367–368): samples ke ← E.keyGen n, runs adversary n [] against etmToMACHandler E n (tagBound n) ke, and when the candidate ciphertext out.1 has canonical pair framing and E.decrypt n ke (unframe out.1) succeeds, outputs the candidate forgery pair (unframe out.1, dropFrame out.1); otherwise outputs a dummy pair of first-component length ≠ M.msgLen n that is rejected by M.sufCmaGame.

theorem Cslib.Crypto.eval_sufCmaGame_etmToMACForger (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (tagBound : ℕ → ℕ) (adversary : CIAdversary) (n : ℕ) (htagBound : ∀ km ∈ (M.keyGen n).eval.support, ∀ (c : List Bool), c.length = M.msgLen n → ∀ tag ∈ (M.sign km c).eval.support, tag.length ≤ tagBound n) :
(M.sufCmaGame (etmToMACForger E M tagBound adversary) n).eval = ((encryptThenMAC E M hctLen).ciGame adversary n).eval

Running etmToMACForger E M tagBound adversary in M.sufCmaGame produces the exact same winning distribution as running adversary in (encryptThenMAC E M hctLen).ciGame whenever tagBound n bounds all MAC tag lengths on M.msgLen n-bit ciphertexts under supported keys at security parameter n.

theorem Cslib.Crypto.succProbability_ciGame_encryptThenMAC_eq (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (tagBound : ℕ → ℕ) (adversary : CIAdversary) (n : ℕ) (htagBound : ∀ km ∈ (M.keyGen n).eval.support, ∀ (c : List Bool), c.length = M.msgLen n → ∀ tag ∈ (M.sign km c).eval.support, tag.length ≤ tagBound n) :
Game.succProbability ((encryptThenMAC E M hctLen).ciGame adversary n).eval = Game.succProbability (M.sufCmaGame (etmToMACForger E M tagBound adversary) n).eval

Quantitative Ciphertext-Integrity to SUF-CMA equality ([BS23], Section 9.4.1, Theorem 9.2, Part 1, printed pp. 367–368): when tagBound n bounds all MAC tag lengths on M.msgLen n-bit ciphertexts under supported keys at security parameter n, the ciphertext-integrity winning probability of adversary against encryptThenMAC E M hctLen equals the SUF-CMA winning probability of etmToMACForger E M tagBound adversary against M (CIadv[Aci, EEtM] = MACadv[Bmac, I]).

theorem Cslib.Crypto.isQueryBounded_etmToMACForger (E : SymmetricCipher) (M : MACScheme) (tagBound : ℕ → ℕ) (adversary : CIAdversary) (n : ℕ) (aux : List Bool) {Q : ℕ} (hq : ProbOracleComp.IsQueryBounded (adversary n []) Q) :
ProbOracleComp.IsQueryBounded (etmToMACForger E M tagBound adversary n aux) Q

Query-count preservation for etmToMACForger ([BS23], Section 9.4.1, Theorem 9.2, Part 1, printed p. 367): if adversary n [] makes at most Q encryption queries, then etmToMACForger E M tagBound adversary n aux makes at most Q signing queries.

Open stateful handler that simulates the oneTimeCIEncryptionOracle of encryptThenMAC E M inside M.sufOneTimeGame ([BS23], Section 9.4.1, Theorem 9.2): maintains a boolean flag alreadyQueried (initially false). On the first valid n-bit message query request.2, it encrypts c ← E.encrypt n ke request.2, queries the external one-time MAC signing oracle on ((), c) (truncating the returned tag to tagBound bits), sets alreadyQueried := true, and returns encPair encBits encBits (c, tag). All subsequent or malformed queries return [] without invoking the signing oracle.

noncomputable def Cslib.Crypto.etmToOneTimeMACForger (E : SymmetricCipher) (M : MACScheme) (tagBound : ℕ → ℕ) (adversary : CIAdversary) :

One-time ciphertext-integrity to OneTimeSUFCMA reduction etmToOneTimeMACForger ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): samples ke ← E.keyGen n, runs adversary n [] against etmToOneTimeMACHandler E n (tagBound n) ke starting from false, and extracts the candidate forgery pair (unframe out.1, dropFrame out.1) when out.1 has canonical pair framing and E.decrypt n ke (unframe out.1) succeeds.

theorem Cslib.Crypto.isQueryBounded_etmToOneTimeMACForger (E : SymmetricCipher) (M : MACScheme) (tagBound : ℕ → ℕ) (adversary : CIAdversary) (n : ℕ) (aux : List Bool) {Q : ℕ} (hq : ProbOracleComp.IsQueryBounded (adversary n []) Q) :
ProbOracleComp.IsQueryBounded (etmToOneTimeMACForger E M tagBound adversary n aux) Q

Query-count preservation for etmToOneTimeMACForger ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): if adversary n [] makes at most Q encryption queries, then etmToOneTimeMACForger E M tagBound adversary n aux makes at most Q signing queries.

theorem Cslib.Crypto.eval_sufOneTimeGame_etmToOneTimeMACForger (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (tagBound : ℕ → ℕ) (adversary : CIAdversary) (n : ℕ) (htagBound : ∀ km ∈ (M.keyGen n).eval.support, ∀ (c : List Bool), c.length = M.msgLen n → ∀ tag ∈ (M.sign km c).eval.support, tag.length ≤ tagBound n) :
(M.sufOneTimeGame (etmToOneTimeMACForger E M tagBound adversary) n).eval = ((encryptThenMAC E M hctLen).ciOneTimeGame adversary n).eval

Running etmToOneTimeMACForger E M tagBound adversary in M.sufOneTimeGame produces the exact same winning distribution as running adversary in (encryptThenMAC E M hctLen).ciOneTimeGame whenever tagBound n bounds all MAC tag lengths on M.msgLen n-bit ciphertexts under supported keys at security parameter n.

theorem Cslib.Crypto.succProbability_ciOneTimeGame_encryptThenMAC_eq (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (tagBound : ℕ → ℕ) (adversary : CIAdversary) (n : ℕ) (htagBound : ∀ km ∈ (M.keyGen n).eval.support, ∀ (c : List Bool), c.length = M.msgLen n → ∀ tag ∈ (M.sign km c).eval.support, tag.length ≤ tagBound n) :

Quantitative one-time Ciphertext-Integrity to OneTimeSUFCMA equality ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): when tagBound n bounds all MAC tag lengths on M.msgLen n-bit ciphertexts under supported keys at security parameter n, the one-time ciphertext-integrity winning probability of adversary against encryptThenMAC E M hctLen equals the sufOneTimeGame winning probability of etmToOneTimeMACForger E M tagBound adversary against M.

IND-CPA Reduction for Theorem 9.2 #

Open stateful handler that simulates the CPA oracle of encryptThenMAC E M inside E.cpaGame ([BS23], Section 9.4.1, Theorem 9.2, Part 2): on a valid pair of n-bit messages request.2, it forwards request to the external CPA encryption oracle of E (truncating the returned ciphertext c to M.msgLen n bits), computes tag ← M.sign km c, and returns encPair encBits encBits (c, tag).

IND-CPA reduction etmToCPAAdversary for encryptThenMAC E M ([BS23], Section 9.4.1, Theorem 9.2, Part 2, printed pp. 367–368): samples a secret MAC key km ← M.keyGen n privately and runs adversary n [] against etmToCPAHandler M n km.

theorem Cslib.Crypto.eval_cpaGame_etmToCPAAdversary (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (adversary : OracleDistinguisher) (bit : Bool) (n : ℕ) :
(E.cpaGame (etmToCPAAdversary M adversary) bit n).eval = ((encryptThenMAC E M hctLen).cpaGame adversary bit n).eval

Running etmToCPAAdversary M adversary in E.cpaGame at challenge bit bit produces the exact same output distribution as running adversary in (encryptThenMAC E M hctLen).cpaGame at challenge bit bit.

theorem Cslib.Crypto.advantage_cpaGame_encryptThenMAC_eq (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (adversary : OracleDistinguisher) (n : ℕ) :
Game.advantage ((encryptThenMAC E M hctLen).cpaGame adversary false n).eval ((encryptThenMAC E M hctLen).cpaGame adversary true n).eval = Game.advantage (E.cpaGame (etmToCPAAdversary M adversary) false n).eval (E.cpaGame (etmToCPAAdversary M adversary) true n).eval

Quantitative IND-CPA equality for Encrypt-then-MAC ([BS23], Section 9.4.1, Theorem 9.2, Part 2, printed pp. 367–368): the CPA distinguishing advantage of adversary against encryptThenMAC E M hctLen equals the CPA distinguishing advantage of etmToCPAAdversary M adversary against E (CPAadv[Acpa, EEtM] = CPAadv[Bcpa, E]).

Query-count preservation for etmToCPAAdversary ([BS23], Section 9.4.1, Theorem 9.2, Part 2, printed p. 368): if adversary n [] makes at most Q encryption queries, then etmToCPAAdversary M adversary n aux makes at most Q encryption queries.

Open stateful handler that simulates the oneTimeCPAEncryptionOracle of encryptThenMAC E M inside E.cpaOneTimeGame ([BS23], Section 9.4.1, Theorem 9.2): maintains a boolean flag alreadyQueried (initially false). On the first valid pair of n-bit messages request.2, it forwards request to the external one-time CPA encryption oracle of E (truncating the returned ciphertext c to M.msgLen n bits), computes tag ← M.sign km c, sets alreadyQueried := true, and returns encPair encBits encBits (c, tag). All subsequent or malformed queries return [] without querying the external oracle.

One-time IND-CPA reduction etmToOneTimeCPAAdversary for encryptThenMAC E M ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): samples a secret MAC key km ← M.keyGen n privately and runs adversary n [] against etmToOneTimeCPAHandler M n km starting from false.

Query-count preservation for etmToOneTimeCPAAdversary ([BS23], Section 9.4.1, Theorem 9.2, printed p. 368): if adversary n [] makes at most Q encryption queries, then etmToOneTimeCPAAdversary M adversary n aux makes at most Q encryption queries.

theorem Cslib.Crypto.eval_cpaOneTimeGame_etmToOneTimeCPAAdversary (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (adversary : OracleDistinguisher) (bit : Bool) (n : ℕ) :
(E.cpaOneTimeGame (etmToOneTimeCPAAdversary M adversary) bit n).eval = ((encryptThenMAC E M hctLen).cpaOneTimeGame adversary bit n).eval

Running etmToOneTimeCPAAdversary M adversary in E.cpaOneTimeGame at challenge bit bit produces the exact same output distribution as running adversary in (encryptThenMAC E M hctLen).cpaOneTimeGame at challenge bit bit.

Quantitative one-time IND-CPA equality for Encrypt-then-MAC ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): the one-time CPA distinguishing advantage of adversary against encryptThenMAC E M hctLen equals the one-time CPA distinguishing advantage of etmToOneTimeCPAAdversary M adversary against E.

Asymptotic Security of Encrypt-then-MAC (Boneh–Shoup Theorem 9.2) #

SUF-CMA security implies Ciphertext Integrity for Encrypt-then-MAC ([BS23], Section 9.4.1, Theorem 9.2, Part 1, printed pp. 367–368): if M is strongly unforgeable (M.SUFCMA), then encryptThenMAC E M hctLen satisfies CiphertextIntegrity.

theorem Cslib.Crypto.indcpa_encryptThenMAC (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (hcpa : E.INDCPA) :
(encryptThenMAC E M hctLen).INDCPA

IND-CPA security transfers to Encrypt-then-MAC ([BS23], Section 9.4.1, Theorem 9.2, Part 2, printed pp. 367–368): if E satisfies INDCPA, then encryptThenMAC E M hctLen also satisfies INDCPA.

Encrypt-then-MAC Authenticated Encryption Theorem ([BS23], Section 9.4.1, Theorem 9.2, printed pp. 367–368): if E is INDCPA-secure and M is SUFCMA-secure, then encryptThenMAC E M hctLen is an AuthenticatedEncryption cipher (INDCPA ∧ CiphertextIntegrity).

theorem Cslib.Crypto.indcca_encryptThenMAC (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (hcpa : E.INDCPA) (hmac : M.SUFCMA) :
(encryptThenMAC E M hctLen).INDCCA

Corollary of authenticatedEncryption_encryptThenMAC ([BS23], Theorem 9.2) and SymmetricCipher.AuthenticatedEncryption.indcca (Theorem 9.1), not a separate cited result: if E is INDCPA-secure and M is SUFCMA-secure, then encryptThenMAC E M hctLen is INDCCA-secure.

theorem Cslib.Crypto.authenticatedEncryption_encryptThenMAC_prfMAC (E : SymmetricCipher) {family : List Bool → List Bool → List Bool} (hprf : PseudorandomFunction family) {ctLen : ℕ → ℕ} (hctPoly : Turing.MultiTapeTM.ComputableInPolyTime ctLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (hctMono : StrictMono ctLen) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (ctLen n)) (hcpa : E.INDCPA) :
(encryptThenMAC E ((prfMAC family ⋯).reindex ctLen hctPoly) hctLen).AuthenticatedEncryption

Encrypt-then-MAC with a reindexed PRF-based MAC is Authenticated Encryption ([BS23], combining Theorem 6.2 and Theorem 9.2): if E is INDCPA-secure with ciphertext-length schedule ctLen (strictly monotone and computable in plain polynomial time) and family is a uniform PseudorandomFunction, then encryptThenMAC E ((prfMAC family hprf.polyTime).reindex ctLen hctPoly) hctLen satisfies AuthenticatedEncryption.

theorem Cslib.Crypto.indcca_encryptThenMAC_prfMAC (E : SymmetricCipher) {family : List Bool → List Bool → List Bool} (hprf : PseudorandomFunction family) {ctLen : ℕ → ℕ} (hctPoly : Turing.MultiTapeTM.ComputableInPolyTime ctLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (hctMono : StrictMono ctLen) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (ctLen n)) (hcpa : E.INDCPA) :
(encryptThenMAC E ((prfMAC family ⋯).reindex ctLen hctPoly) hctLen).INDCCA

Encrypt-then-MAC with a reindexed PRF-based MAC is IND-CCA secure ([BS23], combining Theorem 6.2, Theorem 9.2, and Theorem 9.1): if E is INDCPA-secure with ciphertext-length schedule ctLen (strictly monotone and computable in plain polynomial time) and family is a uniform PseudorandomFunction, then encryptThenMAC E ((prfMAC family hprf.polyTime).reindex ctLen hctPoly) hctLen satisfies INDCCA.

OneTimeSUFCMA security implies OneTimeCiphertextIntegrity for Encrypt-then-MAC ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): if M is one-time strongly unforgeable (M.OneTimeSUFCMA), then encryptThenMAC E M hctLen satisfies OneTimeCiphertextIntegrity.

One-time OneTimeINDCPA security transfers to Encrypt-then-MAC ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): if E satisfies OneTimeINDCPA, then encryptThenMAC E M hctLen also satisfies OneTimeINDCPA.

One-time Encrypt-then-MAC Authenticated Encryption Theorem ([BS23], Section 9.4.1, Theorem 9.2, printed p. 367): "Also, $\mathcal{E}_{\mathrm{EtM}}$ is 1AE-secure assuming $\mathcal{E}$ is semantically secure and $\mathcal{I}$ is a one-time secure MAC system." If E satisfies OneTimeINDCPA and M satisfies OneTimeSUFCMA, then encryptThenMAC E M hctLen satisfies OneTimeAuthenticatedEncryption.

theorem Cslib.Crypto.oneTimeINDCCA_encryptThenMAC (E : SymmetricCipher) (M : MACScheme) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (M.msgLen n)) (hcpa : E.OneTimeINDCPA) (hmac : M.OneTimeSUFCMA) :

Corollary of oneTimeAuthenticatedEncryption_encryptThenMAC (the 1AE half of [BS23], Theorem 9.2) and SymmetricCipher.OneTimeAuthenticatedEncryption.oneTimeINDCCA (the 1AE ⇒ 1CCA half of Theorem 9.1), not a separate cited result: if E satisfies OneTimeINDCPA and M satisfies OneTimeSUFCMA, then encryptThenMAC E M hctLen satisfies OneTimeINDCCA.

One-time Encrypt-then-MAC with a reindexed PRF-based MAC is One-Time Authenticated Encryption: if E satisfies OneTimeINDCPA with ciphertext-length schedule ctLen (strictly monotone and computable in plain polynomial time) and family is a uniform PseudorandomFunction, then encryptThenMAC E ((prfMAC family hprf.polyTime).reindex ctLen hctPoly) hctLen satisfies OneTimeAuthenticatedEncryption.

theorem Cslib.Crypto.oneTimeINDCCA_encryptThenMAC_prfMAC (E : SymmetricCipher) {family : List Bool → List Bool → List Bool} (hprf : PseudorandomFunction family) {ctLen : ℕ → ℕ} (hctPoly : Turing.MultiTapeTM.ComputableInPolyTime ctLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (hctMono : StrictMono ctLen) (hctLen : ∀ (n : ℕ), E.CiphertextLength n (ctLen n)) (hcpa : E.OneTimeINDCPA) :
(encryptThenMAC E ((prfMAC family ⋯).reindex ctLen hctPoly) hctLen).OneTimeINDCCA

One-time Encrypt-then-MAC with a reindexed PRF-based MAC is One-Time IND-CCA secure: if E satisfies OneTimeINDCPA with ciphertext-length schedule ctLen (strictly monotone and computable in plain polynomial time) and family is a uniform PseudorandomFunction, then encryptThenMAC E ((prfMAC family hprf.polyTime).reindex ctLen hctPoly) hctLen satisfies OneTimeINDCCA.

Concrete Non-Vacuous PRF-Based Cipher (Boneh–Shoup Example 5.2 & Theorem 5.2) #

noncomputable def Cslib.Crypto.prfCipher (family : List Bool → List Bool → List Bool) (hpoly : Turing.MultiTapeTM.ComputableInPolyTime (fun (pair : List Bool × List Bool) => family pair.1 pair.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) :

Randomized PRF-based symmetric cipher ([BS23], Section 5.4.1, Example 5.2 and Theorem 5.2, printed pp. 183–189): given a keyed function family family : List Bool → List Bool → List Bool computable in plain polynomial time that maps n-bit keys and n-bit inputs to n-bit outputs:

  • keyGen n samples a uniform n-bit key k ← BitString.sampleList n.
  • encrypt n k msg samples a uniform n-bit nonce r ← BitString.sampleList n and outputs the 2 * n-bit ciphertext r ++ List.zipWith xor (family k r) msg.
  • decrypt n k ct checks ct.length == 2 * n; if so, splits r := ct.take n and c := ct.drop n and outputs some (List.zipWith xor (family k r) c), and otherwise outputs none.
  • The ciphertext space ctSpace n is the 2 * n-bit words, the source's X × C with X = C = {0,1}^n.
theorem Cslib.Crypto.prfCipher_ciphertext_length (family : List Bool → List Bool → List Bool) (hpoly : Turing.MultiTapeTM.ComputableInPolyTime (fun (pair : List Bool × List Bool) => family pair.1 pair.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) (n : ℕ) :
(prfCipher family hpoly hlen).CiphertextLength n (2 * n)

Every supported ciphertext of prfCipher family hpoly hlen on an n-bit plaintext under a supported key at security parameter n has length 2 * n.

CPA-to-PRF Reduction and Game Hops for Theorem 5.2 #

Open stateful handler that simulates the CPA oracle of prfCipher inside the PRF distinguishing experiment ([BS23], Section 5.4.1, Theorem 5.2, Figure 5.1, printed pp. 185–186): on a pair of n-bit messages (m0, m1), it samples a random nonce r ← BitString.sampleList n, queries the external PRF/random-function oracle at ((), r) (truncating the returned pad to n bits), and returns r ++ List.zipWith xor pad msg where msg := if bit then m1 else m0.

CPA-to-PRF reduction cpaToPrfDistinguisher ([BS23], Section 5.4.1, Theorem 5.2, Figure 5.1, printed pp. 185–186): runs adversary n [] against cpaToPrfHandler n bit.

theorem Cslib.Crypto.eval_prfRealGame_cpaToPrfDistinguisher (family : List Bool → List Bool → List Bool) (hpoly : Turing.MultiTapeTM.ComputableInPolyTime (fun (pair : List Bool × List Bool) => family pair.1 pair.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) (adversary : OracleDistinguisher) (bit : Bool) (n : ℕ) :
(prfRealGame id family (cpaToPrfDistinguisher adversary bit) n).eval = ((prfCipher family hpoly hlen).cpaGame adversary bit n).eval

Running cpaToPrfDistinguisher adversary bit in prfRealGame id family produces the exact same output distribution as running adversary in (prfCipher family hpoly hlen).cpaGame at challenge bit bit ([BS23], Section 5.4.1, Theorem 5.2, Game 0, printed pp. 184–185).

theorem Cslib.Crypto.advantage_cpaGame_prfCipher_le (family : List Bool → List Bool → List Bool) (hpoly : Turing.MultiTapeTM.ComputableInPolyTime (fun (pair : List Bool × List Bool) => family pair.1 pair.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) (adversary : OracleDistinguisher) (n Q : ℕ) (hq : ProbOracleComp.IsQueryBounded (adversary n []) Q) :
↑(Game.advantage ((prfCipher family hpoly hlen).cpaGame adversary false n).eval ((prfCipher family hpoly hlen).cpaGame adversary true n).eval) ≤ ↑(Game.advantage (prfRealGame id family (cpaToPrfDistinguisher adversary false) n).eval (prfIdealGame id id (cpaToPrfDistinguisher adversary false) n).eval) + ↑(Game.advantage (prfRealGame id family (cpaToPrfDistinguisher adversary true) n).eval (prfIdealGame id id (cpaToPrfDistinguisher adversary true) n).eval) + 2 * ↑Q ^ 2 / 2 ^ n

Quantitative IND-CPA security bound for prfCipher ([BS23], Section 5.4.1, Theorem 5.2, equation (5.5), printed pp. 184–189): for any OracleDistinguisher making at most Q encryption queries at security parameter n, the CPA distinguishing advantage against prfCipher is bounded by the sum of the PRF distinguishing advantages of cpaToPrfDistinguisher adversary false and cpaToPrfDistinguisher adversary true plus 2 * Q^2 / 2^n (where 2 * Q^2 / 2^n is a factor-2 loosening of the source's Q^2 / N = Q^2 / 2^n collision term from equation (5.11) on printed p. 187, arising from the Q * Q / 2^n union bound per challenge bit from ProbOracleComp.toOuterMeasure_bad_le).

Any secure PseudorandomFunction yields an INDCPA-secure symmetric cipher prfCipher ([BS23], Section 5.4.1, Example 5.2 and Theorem 5.2, printed pp. 183–189).

End-to-End Non-Vacuous PRF Encrypt-then-MAC Instance #

noncomputable def Cslib.Crypto.prfEncryptThenMAC (family : List Bool → List Bool → List Bool) (hpoly : Turing.MultiTapeTM.ComputableInPolyTime (fun (pair : List Bool × List Bool) => family pair.1 pair.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) :

Concrete PRF-based Encrypt-then-MAC cipher combining prfCipher (2 * n-bit ciphertexts on n-bit plaintexts) with (prfMAC family hpoly).reindex (fun n => 2 * n) ((by polytime)) (authenticating 2 * n-bit ciphertexts at security parameter n).

End-to-end non-vacuity of authenticatedEncryption_encryptThenMAC: for any secure PseudorandomFunction family, prfEncryptThenMAC satisfies AuthenticatedEncryption, with all hypotheses (hctLen, INDCPA, and SUFCMA) discharged simultaneously from hprf.

End-to-end non-vacuity of indcca_encryptThenMAC and AuthenticatedEncryption.indcca: for any secure PseudorandomFunction family, prfEncryptThenMAC satisfies adaptive chosen-ciphertext security (INDCCA), with all hypotheses discharged simultaneously from hprf.