Documentation

Complexity.Crypto.Computational.MAC

Uniform message authentication codes and PRF-based MACs #

A uniform symmetric message authentication code (MACScheme) consists of a strict probabilistic polynomial-time key generator keyGen, a strict probabilistic polynomial-time tag generator sign, and a deterministic polynomial-time tag verifier verify that accepts every tag produced by sign on an n-bit message under a secret key sampled at security parameter n. Unlike digital signatures (SignatureScheme), verification uses the same secret key as tag generation, and the adversary receives no public key.

We formalize both strong (fresh-pair) existential unforgeability under adaptive chosen-message attack (sufCmaGame, SUFCMA) as in Boneh and Shoup, Attack Game 6.1 / Definition 6.2, and ordinary fresh-message existential unforgeability under adaptive chosen-message attack (eufCmaGame, EUFCMA) and under one-time adaptive chosen-message attack (eufOneTimeGame, OneTimeEUFCMA) against uniform strict oracle-PPT forgers (IsOraclePPT). Both adaptive games share the pair-logging execution core signingPairOracle: sufCmaGame records returned (msg, tag) pairs and accepts any valid n-bit forgery pair (msg, tag) that was never returned (!queriedPairs.contains (msg, tag)), even on a previously queried message, whereas eufCmaGame rejects any candidate forgery whose message was previously queried (!queried.contains msg). We prove the quantitative bound $$\Pr[\text{EUF-CMA}] \le \Pr[\text{SUF-CMA}]$$ (succProbability_eufCmaGame_le_sufCmaGame) and the security implication SUFCMA → EUFCMA (SUFCMA.eufCma). For randomized MACScheme.sign algorithms the two notions differ; for MACs with a unique valid tag per (sk, msg) (eval_sufCmaGame_eq_eufCmaGame_of_unique_tag, sufCma_iff_eufCma_of_unique_tag), including prfMAC, fresh-message and fresh-pair unforgeability coincide.

We then prove that any uniform PseudorandomFunction yields a SUFCMA- and EUFCMA-secure deterministic MAC (prfMAC, PseudorandomFunction.sufCma_prfMAC, PseudorandomFunction.eufCma_prfMAC), with the quantitative security reduction of Boneh and Shoup, Section 6.3, Theorem 6.2: $$\Pr[\text{Forge}] \le \mathrm{Adv}_{\mathrm{PRF}}(B(\mathcal{A}), n) + 2^{-n}.$$

Main definitions #

Main results #

References #

A uniform symmetric message authentication code (MAC) on n-bit messages at security parameter n, with strict polynomial-time key generation and tag generation, deterministic polynomial-time verification, and perfect completeness on supported keys, n-bit messages, and tags Boneh and Shoup, Definition 6.1.

Instances For

    Full adaptive chosen-message security (EUFCMA) #

    Stateful MAC tagging oracle that tags the requested message under sk and prepends the message to the list of queried messages.

    Instances For
      noncomputable def Cslib.Crypto.MACScheme.eufCmaGame (M : MACScheme) (adversary : Forger) (n : ℕ) :

      The fresh-message MAC EUF-CMA experiment: sample sk ← M.keyGen n, run the adaptive forger on (n, []) with oracle access to M.signingOracle sk, and accept when the forger outputs a valid (msg, tag) pair on an n-bit message msg that was never queried to the tagging oracle.

      Unlike Boneh and Shoup, Attack Game 6.1 / Definition 6.2, which logs (msg, tag) pairs and rejects only previously returned pairs, this experiment logs queried messages and rejects any previously queried message (!out.2.contains out.1.1). The two notions differ for randomized sign algorithms, and coincide for deterministic canonical MACs such as prfMAC.

      Instances For

        Run the complete MAC EUF-CMA experiment on its unary security parameter for any oracle-PPT forger.

        The MAC EUF-CMA experiment is uniformly strict PPT, independently of unused auxiliary input.

        Fresh-message existential unforgeability under adaptive chosen-message attack (EUFCMA) for a symmetric MAC against uniform strict oracle-PPT adversaries.

        Note that eufCmaGame enforces fresh-message unforgeability (msg ∉ queried), whereas Boneh and Shoup, Attack Game 6.1 / Definition 6.2 defines the stronger fresh-pair variant ((msg, tag) ∉ queriedPairs) for general (possibly randomized) signing algorithms.

        Instances For

          Full EUF-CMA security gives negligible forgery probability for every oracle-PPT forger.

          Establish EUF-CMA security by bounding every oracle-PPT forger's success probability.

          One-time adaptive chosen-message security (OneTimeEUFCMA) #

          One-time MAC oracle that answers at most the first tagging query using M.sign sk and returns the empty word without tagging on any subsequent query.

          Instances For
            noncomputable def Cslib.Crypto.MACScheme.eufOneTimeGame (M : MACScheme) (adversary : Forger) (n : ℕ) :

            The one-time MAC EUF-CMA experiment: sample sk ← M.keyGen n, run the adaptive forger on (n, []) with oracle access to M.oneTimeSigningOracle sk, and accept when the forger outputs a valid tag on an n-bit message distinct from the queried message (if any).

            Instances For

              Run the complete one-time MAC EUF-CMA experiment on its unary security parameter for any oracle-PPT forger.

              The one-time MAC EUF-CMA experiment is uniformly strict PPT, independently of unused auxiliary input.

              Existential unforgeability under one-time adaptive chosen-message attack for a symmetric MAC.

              Instances For

                One-time EUF-CMA security gives negligible forgery probability for every oracle-PPT forger.

                Establish one-time EUF-CMA security by bounding every oracle-PPT forger's success probability.

                Full EUF-CMA security implies one-time EUF-CMA security for any MACScheme.

                Strong adaptive chosen-message security (SUFCMA, Boneh–Shoup Attack Game 6.1) #

                Stateful MAC tagging oracle that tags the requested message under sk and prepends the returned (msg, tag) pair to the transcript of queried message/tag pairs (Boneh and Shoup, Attack Game 6.1).

                Instances For
                  noncomputable def Cslib.Crypto.MACScheme.sufCmaGame (M : MACScheme) (adversary : Forger) (n : ℕ) :

                  The strong (fresh-pair) MAC SUF-CMA experiment (Boneh and Shoup, Attack Game 6.1 / Definition 6.2): sample sk ← M.keyGen n, run the adaptive forger on (n, []) with oracle access to M.signingPairOracle sk, and accept when the forger outputs a valid (msg, tag) pair on an n-bit message msg such that (msg, tag) was never returned by the tagging oracle (!out.2.contains out.1).

                  Instances For

                    Run the complete MAC SUF-CMA experiment on its unary security parameter for any oracle-PPT forger.

                    The MAC SUF-CMA experiment is uniformly strict PPT, independently of unused auxiliary input.

                    Strong (fresh-pair) existential unforgeability under adaptive chosen-message attack (SUFCMA) for a symmetric MAC against uniform strict oracle-PPT adversaries (Boneh and Shoup, Attack Game 6.1 / Definition 6.2).

                    Instances For

                      Strong unforgeability gives negligible SUF-CMA forgery probability for every oracle-PPT forger.

                      Establish SUF-CMA security by bounding every oracle-PPT forger's success probability.

                      Running an adaptive program against signingOracle produces the exact same distribution as running it against signingPairOracle and projecting the pair transcript to its queried messages.

                      theorem Cslib.Crypto.MACScheme.eval_eufCmaGame_eq_signingPairOracle (M : MACScheme) (adversary : Forger) (n : ℕ) :
                      (M.eufCmaGame adversary n).eval = (do let sk ← M.keyGen n let out ← (OracleComp.interpret (ProbOracleComp.handler (fun (k : ℕ) => StateT.lift (ProbComp.unifFin k)) (M.signingPairOracle sk)) (adversary n [])).run [] pure (out.1.1.length == n && !(List.map Prod.fst out.2).contains out.1.1 && M.verify sk out.1.1 out.1.2)).eval

                      eufCmaGame evaluates the same pair-logging execution signingPairOracle as sufCmaGame, checking message freshness !(out.2.map Prod.fst).contains out.1.1 on the projected message log.

                      Quantitative EUF-CMA vs. SUF-CMA bound: for every MACScheme, adaptive forger, and security parameter n, the fresh-message EUF-CMA forgery probability is at most the strong fresh-pair SUF-CMA forgery probability.

                      Strong unforgeability (SUFCMA) implies ordinary fresh-message unforgeability (EUFCMA) for every MACScheme.

                      Strong unforgeability (SUFCMA) implies one-time unforgeability (OneTimeEUFCMA) for every MACScheme.

                      theorem Cslib.Crypto.MACScheme.eval_sufCmaGame_eq_eufCmaGame_of_unique_tag (M : MACScheme) (huniq : ∀ (n : ℕ), ∀ sk ∈ (M.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ (tag tag' : List Bool), M.verify sk msg tag = true → tag' ∈ (M.sign sk msg).eval.support → tag' = tag) (adversary : Forger) (n : ℕ) :
                      (M.sufCmaGame adversary n).eval = (M.eufCmaGame adversary n).eval

                      For any MACScheme whose valid tags on n-bit messages under supported secret keys agree with every tag in the support of M.sign, the sufCmaGame and eufCmaGame distributions are identical.

                      theorem Cslib.Crypto.MACScheme.succProbability_sufCmaGame_eq_eufCmaGame_of_unique_tag (M : MACScheme) (huniq : ∀ (n : ℕ), ∀ sk ∈ (M.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ (tag tag' : List Bool), M.verify sk msg tag = true → tag' ∈ (M.sign sk msg).eval.support → tag' = tag) (adversary : Forger) (n : ℕ) :

                      For a MACScheme with unique valid tags per (sk, msg), the SUF-CMA and EUF-CMA forgery probabilities are equal for every forger and security parameter n.

                      theorem Cslib.Crypto.MACScheme.sufCma_iff_eufCma_of_unique_tag (M : MACScheme) (huniq : ∀ (n : ℕ), ∀ sk ∈ (M.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = n → ∀ (tag tag' : List Bool), M.verify sk msg tag = true → tag' ∈ (M.sign sk msg).eval.support → tag' = tag) :

                      For a MACScheme with unique valid tags per (sk, msg), strong unforgeability (SUFCMA) is equivalent to ordinary fresh-message unforgeability (EUFCMA).

                      Canonical PRF-based MAC (prfMAC, Boneh–Shoup Section 6.3 & Theorem 6.2) #

                      Canonical deterministic MAC constructed from a keyed function family family (Boneh and Shoup, Section 6.3):

                      • keyGen n samples a uniform n-bit key via BitString.sampleList n.
                      • sign sk msg returns prfOracle family sk.length sk msg (which evaluates family sk msg on sk.length-bit messages and rejects malformed queries with []).
                      • verify sk msg tag checks msg.length == sk.length and family sk msg == tag.
                      Instances For

                        Open stateful handler that forwards each MAC signing request to the external PRF/random-function oracle (truncating the reply to n bits) and records the queried message in the query log.

                        Instances For

                          Oracle reduction turning an adaptive MAC forger adversary into an OracleDistinguisher for the PRF security game Boneh and Shoup, Section 6.3, Theorem 6.2:

                          1. Run adversary n [], answering each tagging query via macLogHandler n and logging all queried messages.
                          2. When adversary outputs ((msg, tag), queried), if msg.length == n and !queried.contains msg, query the external oracle once on msg (reading at most n bits) and check whether the reply equals tag; otherwise return false.
                          Instances For
                            theorem Cslib.Crypto.eval_prfRealGame_macToPrfDistinguisher {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 : Forger) (n : ℕ) :
                            (prfRealGame family (macToPrfDistinguisher adversary) n).eval = ((prfMAC family hpoly).eufCmaGame adversary n).eval

                            Running macToPrfDistinguisher adversary in prfRealGame family produces the exact same Boolean distribution as the EUF-CMA experiment for prfMAC family.

                            In the ideal random-function game, macToPrfDistinguisher adversary succeeds with probability at most 1 / 2 ^ n: any unqueried n-bit forgery message misses the lazy random-oracle cache and draws a fresh uniform n-bit tag, matching the forger's candidate tag with probability at most 1 / 2 ^ n.

                            theorem Cslib.Crypto.eval_sufCmaGame_prfMAC {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) (adversary : Forger) (n : ℕ) :
                            ((prfMAC family hpoly).sufCmaGame adversary n).eval = ((prfMAC family hpoly).eufCmaGame adversary n).eval

                            Because prfMAC is deterministic with a unique valid tag per (sk, msg), its strong fresh-pair sufCmaGame distribution is identical to its fresh-message eufCmaGame distribution.

                            For prfMAC, strong unforgeability (SUFCMA) and fresh-message unforgeability (EUFCMA) coincide.

                            theorem Cslib.Crypto.eval_prfRealGame_macToPrfDistinguisher_eq_sufCmaGame {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 : Forger) (n : ℕ) :
                            (prfRealGame family (macToPrfDistinguisher adversary) n).eval = ((prfMAC family hpoly).sufCmaGame adversary n).eval

                            Running macToPrfDistinguisher adversary in prfRealGame family produces the exact same Boolean distribution as the strong SUF-CMA experiment for prfMAC family.

                            theorem Cslib.Crypto.succProbability_eufCmaGame_prfMAC_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 : Forger) (n : ℕ) :

                            Quantitative PRF-to-MAC forgery bound Boneh and Shoup, Theorem 6.2: for every adaptive MAC forger adversary and every security parameter n, the EUF-CMA forgery probability against prfMAC family is at most the PRF distinguishing advantage of macToPrfDistinguisher adversary plus 1 / 2 ^ n.

                            theorem Cslib.Crypto.succProbability_sufCmaGame_prfMAC_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 : Forger) (n : ℕ) :

                            Quantitative PRF-to-SUF-CMA forgery bound Boneh and Shoup, Theorem 6.2: for every adaptive MAC forger adversary and every security parameter n, the strong SUF-CMA forgery probability against prfMAC family is at most the PRF distinguishing advantage of macToPrfDistinguisher adversary plus 1 / 2 ^ n.

                            PRF-to-MAC security theorem Boneh and Shoup, Theorem 6.2: every uniform PseudorandomFunction yields an EUFCMA-secure MACScheme.

                            PRF-to-SUF-CMA security theorem Boneh and Shoup, Theorem 6.2: every uniform PseudorandomFunction yields a strongly unforgeable (SUFCMA) MACScheme.

                            Every uniform PseudorandomFunction also yields a OneTimeEUFCMA-secure MACScheme.