AlphaProof Code: Verifying Signal’s Security at the Machine-Code Level

Paper › LibsignalBinary/Specifications/CryptoGames/AEAD › EtMDefs.leanTier 2 · definitions

EtMDefs.lean🔗

Tier 2 · definitions used by the computational proof and symbolic proof 5 headline theorems depend on it 51 of 341 lines trusted trust banner B3, trusted in part source ↗

Read the definitions shown. Only the declarations that the headline statements use are shown, with the namespace, section, open and variable commands needed to read them. The collapsed runs are theorems, which Lean checks, and definitions that no headline statement uses.

Declarations on this page (8)

Encrypt-then-MAC AEAD from a one-time cipher and a PRF-based MAC

Trusted in part. The theorems of Computational/Theorems/ use only CipherScheme, MACScheme, PRFAdversary, PRFState, prfAdvantage, prfEval, prfGame, prfSpec from this file: read them. Everything else here is checked by Lean. See Computational/docs/TRUSTED_BASE.md.

Defines one-time symmetric ciphers (CipherScheme, indcpaEncrypt, indcpaGame, indcpaAdvantage), deterministic MACs/PRFs (MACScheme), the Encrypt-then-MAC AEADScheme etm, the decryption-query bound MakesAtMostDecQueries, and the concrete reductions redCipher, redMACChall, and redMACForge used by etm_otcca (EtM.lean). Because the OT-CCA and IND-CPA games sample uniform ciphertexts from $ᵗ C, instantiations with AES-256-CBC fix the plaintext length (DEV-AEAD2).

@[expose] public section
open OracleComp OracleSpec ENNReal MeasureTheory
namespace CryptoGames

One-time symmetric cipher (IND-CPA)

structure CipherSchemeL41–48 ↗#

A deterministic one-time symmetric cipher. All randomness (e.g. key and IV in Signal's AES-256-CBC-PKCS#7) comes from the one-time key Key. Decryption returns Option Message to accommodate padding validation.

structure CipherScheme (Key Message Ciphertext : Type) where /-- `Enc(k, m)`: encrypt message `m` under key `k`. -/ enc : Key → Message → Ciphertext /-- `Dec(k, c)`: decrypt ciphertext `c` under key `k`; `none` means rejection (e.g. bad padding). -/ dec : Key → Ciphertext → Option Message
10 declarations not shown (lines 54–122): theorems, which Lean checks, or definitions that no headline statement uses

CryptoGames.CipherScheme.Correct, CryptoGames.CipherScheme.indcpaSpec, CryptoGames.CipherScheme.INDCPAState.queried, CryptoGames.CipherScheme.INDCPAState.b, CryptoGames.CipherScheme.INDCPAState.key, CryptoGames.CipherScheme.INDCPAState, CryptoGames.CipherScheme.INDCPAAdversary, CryptoGames.CipherScheme.encryptQuery, CryptoGames.CipherScheme.indcpaEncrypt, CryptoGames.CipherScheme.branch, CryptoGames.CipherScheme.indcpaGame, CryptoGames.CipherScheme.indcpaAdvantage, CryptoGames.CipherScheme.indcpaAdvantage_eq_boolDist

Deterministic MAC / PRF game

structure MACSchemeL128–132 ↗#

A deterministic MAC / PRF with key space Key, input space Input, and tag space Tag (in Signal: 8-byte truncated HMAC-SHA256).

structure MACScheme (Key Input Tag : Type) where /-- `Tag(k, x)`: compute the authentication tag of `x` under key `k`. -/ tag : Key → Input → Tag
namespace MACScheme
variable {Key Input Tag : Type}

abbrev prfSpecL138–140 ↗#

PRF evaluation oracle Input →ₒ Tag.

abbrev prfSpec (Input Tag : Type) := Input →ₒ Tag

structure PRFStateL142–146 ↗#

PRF game state: key, hidden bit b, and the lazy table of the random function.

structure PRFState (Key Input Tag : Type) where key : Key b : Bool table : List (Input × Tag) := []

abbrev PRFAdversaryL148–150 ↗#

A PRF adversary, with its own coins (unifSpec) and the evaluation oracle Input →ₒ Tag.

abbrev PRFAdversary (Input Tag : Type) := OracleComp (unifSpec + prfSpec Input Tag) Bool
1 declaration not shown (lines 152–154): theorems, which Lean checks, or definitions that no headline statement uses

CryptoGames.MACScheme.evalQuery

variable [DecidableEq Input] [SampleableType Tag]

def prfEvalL158–171 ↗#

PRF evaluation oracle: b = false returns mac.tag key x; b = true returns a lazily sampled random function on Input → Tag.

def prfEval (mac : MACScheme Key Input Tag) : QueryImpl (prfSpec Input Tag) (StateT (PRFState Key Input Tag) ProbComp) := fun x => do let st ← get if st.b then match st.table.lookup x with | some t => return t | none => let t ← liftM ($ᵗ Tag) set { st with table := (x, t) :: st.table } return t else return mac.tag st.key x
1 declaration not shown (lines 173–179): theorems, which Lean checks, or definitions that no headline statement uses

CryptoGames.MACScheme.branch

def prfGameL181–189 ↗#

PRF hidden-bit game.

def prfGame [SampleableType Key] (mac : MACScheme Key Input Tag) (A : PRFAdversary Input Tag) : ProbComp Bool := do let b ← $ᵗ Bool let key ← $ᵗ Key let impl := (QueryImpl.ofLift unifSpec ProbComp).liftTarget (StateT (PRFState Key Input Tag) ProbComp) + prfEval mac let b' ← (simulateQ impl A).run' { key, b } return b == b'

def prfAdvantageL191–194 ↗#

Adv^{prf}_{mac}(A), the bias 2·|Pr[b = b'] − 1/2|.

noncomputable def prfAdvantage [SampleableType Key] (mac : MACScheme Key Input Tag) (A : PRFAdversary Input Tag) : ℝ≥0∞ := 𝒟[mac.prfGame A].boolBias
1 declaration not shown (lines 196–204): theorems, which Lean checks, or definitions that no headline statement uses

CryptoGames.MACScheme.prfAdvantage_eq_boolDist

end MACScheme
10 declarations not shown (lines 216–342): theorems, which Lean checks, or definitions that no headline statement uses

CryptoGames.AEADScheme.etm, CryptoGames.AEADScheme.isDecQuery, CryptoGames.AEADScheme.MakesAtMostDecQueries, CryptoGames.AEADScheme.cipherRedImpl, CryptoGames.AEADScheme.redCipher, CryptoGames.AEADScheme.challRedImpl, CryptoGames.AEADScheme.redMACChall, CryptoGames.AEADScheme.ForgeState.forged, CryptoGames.AEADScheme.ForgeState, CryptoGames.AEADScheme.ForgeState.chal, CryptoGames.AEADScheme.ForgeState.idx, CryptoGames.AEADScheme.forgeRedImpl, CryptoGames.AEADScheme.redMACForge

end CryptoGames