Defs.lean
Declarations on this page (22)
- structure CKAScheme
- abbrev spec
- abbrev AdversaryComp
- abbrev Adversary
- notation "Comp"
- structure GameState
- def canSend
- def canReceive
- def allowCorr
- def finished
- def afterSend
- def afterReceive
- notation "GameM"
- def sendImpl
- def sendWithAdversaryCoinsImpl
- def challImpl
- def receiveImpl
- def corrImpl
- def oracleImpl
- def initState
- def game
- def advantage
Continuous key agreement (CKA): syntax and security game
Trusted: definitions used by the statement. The theorems of Computational/ use every definition in this file: read them. The theorems here are checked by Lean. See Computational/.
Defines continuous key agreement (CKAScheme) and its synchronous ping-pong real-or-random security game (CKA., CKA.), following ACD19 §4.1.1, Defs. 12–13 and Fig. 3. Odd epochs have A send and B receive; even epochs swap roles. A passive adversary may supply sender coins (sendWithAdversaryCoinsImpl) or corrupt states (corrImpl) outside the healing window around challenge epoch t* (allowCorr for max(t_A, t_B) ≤ t* − 2, or finished once t_P ≥ t* + Δ). Related CKA deviations appear in CKA/ (DEV-CKA9), Computational/ (DEV-CKA8), and CKA/ (DEV-CKA10, DEV-CKA17).
@[expose] public sectionopen OracleComp OracleSpec ENNRealnamespace CryptoGamesstructure CKAScheme
ACD19 Def. 12: a continuous-key-agreement (CKA) scheme with initialization keys Key, states State, sender coins Coins, messages Msg, and output keys CKey.
structure CKAScheme (Key State Coins Msg CKey : Type) where
/-- `CKA-Init-A`: `A`'s initial state `γ_A` from shared key `k`. -/
initA : Key → State
/-- `CKA-Init-B`: `B`'s initial state `γ_B` from shared key `k`. -/
initB : Key → State
/-- `CKA-S(γ; r)`: send with coins `r`, returning `(γ', T, I)`.
**DEV-CKA1 (formalization): explicit sender coins.** ACD19 Fig. 3 writes `CKA-S(γ; r)` for a
randomized algorithm. Here `send` is a deterministic function of the state and explicit coins
`r : Coins`. The game samples `r` uniformly for `send-P` and `chall-P`, and takes it from the
adversary for `send-P'`. Effect: none. -/
send : State → Coins → State × Msg × CKey
/-- `CKA-R(γ, T)`: receive `T`, returning `(γ', I)`. -/
receive : State → Msg → State × CKeynamespace CKAabbrev spec
ACD19 Fig. 3 oracle interface (none = refused).
abbrev AdversaryComp
Computations with own coins plus the Fig. 3 CKA oracles.
abbrev AdversaryComp (State Coins Msg CKey : Type) :=
OracleComp (unifSpec + spec State Coins Msg CKey)abbrev Adversary
A CKA adversary outputting a hidden-bit guess.
abbrev Adversary (State Coins Msg CKey : Type) := AdversaryComp State Coins Msg CKey Boolvariable {Key State Coins Msg CKey : Type}notation "Comp"
local notation "Comp" => AdversaryComp State Coins Msg CKeystructure GameState
ACD19 Fig. 3 game state.
structure GameState (State Msg : Type) where
/-- Party CKA states `(γ_A, γ_B)`.
**DEV-CKA6 (formalization): one state type.** ACD19 Fig. 3 names the states `γ_A` and `γ_B`
without fixing their types. Here both parties' states have the same type `State`. Effect: none
(a scheme with two state types uses their sum). -/
st : Party → State
/-- Epoch counters `(t_A, t_B)`. -/
epoch : Party → ℕ := fun _ => 0
/-- Hidden bit (`true` = random challenge key). -/
b : Bool
/-- Latest message `T_t` in transit to the receiving party. -/
lastMsg : Option Msg := nonenamespace GameStatevariable (s : GameState State Msg)def canSend
Ping-pong send condition: both parties are at the same epoch and P sends in the next epoch.
DEV-CKA2 (formalization): req and ping-pong order. ACD19 states the ping-pong order in prose (§4.1.1) and aborts on a failing req. Here a call out of order, or with a failing req, returns none and leaves the state unchanged; the epoch counter grows only on success. Effect: none.
def canReceive
Ping-pong receive condition: P. is one epoch ahead of P.
def allowCorr
allow-corr :⇔ max(t_A, t_B) ≤ t* − 2.
def finished
finished_P :⇔ t_P ≥ t* + Δ.
def afterSend
Update s after P sends T and transitions to state γ.
def afterReceive
Update s after P receives and transitions to state γ.
end GameStatesection Oraclesvariable (cka : CKAScheme Key State Coins Msg CKey) (Δ tStar : ℕ)
[SampleableType Coins] [SampleableType CKey]notation "GameM"
local notation "GameM" => StateT (GameState State Msg) ProbCompdef sendImpl
ACD19 Fig. 3 send-P: outside epoch t*, run CKA-S with fresh coins and return (T, I).
DEV-CKA3 (formalization): no plain send in the challenge epoch. ACD19 Fig. 3 lets the adversary call send-P instead of chall-P in epoch t* (it then gets no challenge). Here send-P is refused in epoch t*, so that the DDH reduction can embed its challenge there. Effect: w.l.o.g., proved: CKA. (Computational/) shows that every adversary of the paper's game has the same advantage as a converted adversary here.
def sendWithAdversaryCoinsImpl
ACD19 Fig. 3 send-P'(r): run CKA-S with adversarial coins r while t_P + 1 ≤ t* − 2.
def challImpl
ACD19 Fig. 3 chall-P: in epoch t*, run CKA-S with fresh coins and return (T, I) if b = false or (T, I') for uniform I' if b = true.
def challImpl : QueryImpl (Party →ₒ Option (Msg × CKey)) GameM := fun P => do
let s ← get
if !(s.canSend P) || s.epoch P + 1 != tStar then return none
let r ← ($ᵗ Coins : ProbComp Coins)
let out := cka.send (s.st P) r
set (s.afterSend P out.1 out.2.1)
if s.b then
let I' ← ($ᵗ CKey : ProbComp CKey)
return some (out.2.1, I')
else
return some out.2def receiveImpl
ACD19 Fig. 3 receive-P: run CKA-R on lastMsg without revealing the derived key.
DEV-CKA4 (formalization): receive-P outputs nothing, and the game does not end. As in ACD19 Fig. 3, the receiver's key is not given to the adversary. ACD19 §4.1.1 ends the game once both states are revealed after the challenge phase ("not made explicit"); here it continues, which cannot help the adversary. Effect: none.
def receiveImpl : QueryImpl (Party →ₒ Option Unit) GameM := fun P => do
let s ← get
if !(s.canReceive P) then return none
match s.lastMsg with
| none => return none
| some T =>
set (s.afterReceive P (cka.receive (s.st P) T).1)
return some ()def corrImpl
ACD19 Fig. 3 corr-P: reveal γ_P if allowCorr or finished holds.
def oracleImpl
Combined Fig. 3 oracle implementation.
def oracleImpl : QueryImpl (spec State Coins Msg CKey) GameM :=
sendImpl cka tStar + sendWithAdversaryCoinsImpl cka tStar + challImpl cka tStar + receiveImpl cka
+ (corrImpl Δ tStar : QueryImpl _ GameM)end Oraclessection Gamevariable (cka : CKAScheme Key State Coins Msg CKey) (Δ tStar : ℕ)
[SampleableType Key] [SampleableType Coins] [SampleableType CKey]def initState
Initial state after Fig. 3 init for key k and hidden bit b.
def game
ACD19 Fig. 3 hidden-bit game for challenge epoch t* and healing parameter Δ.
DEV-CKA5 (formalization): t* and b. ACD19 Fig. 3 starts with init(t*). Here t* is a parameter of the game, and security quantifies over all t*. The hidden bit b = true means random (Fig. 3's b = 1). Effect: none.
def game (A : Adversary State Coins Msg CKey) : ProbComp Bool := do
let b ← $ᵗ Bool
let k ← $ᵗ Key
let impl := (QueryImpl.ofLift unifSpec ProbComp).liftTarget
(StateT (GameState State Msg) ProbComp) + oracleImpl cka Δ tStar
let b' ← (simulateQ impl A).run' (initState cka k b)
return b == b'def advantage
Adv^{CKA}_{ror,Δ}(A) (ACD19 Def. 13): the bias 2·|Pr[b = b'] − 1/.
DEV-CKA7 (formalization): advantage as a bias. ACD19 §2.1 prints the advantage as 2·P[A wins] − 1/, a typo. Lean uses the intended bias 2·|Pr[b = b'] − 1/, VCVio's boolBias. Effect: none.
end Gameend CKAend CryptoGames