RootKdfDefs.lean
Declarations on this page (8)
libsignal's root KDF as a PRF-PRNG
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/.
Models the HKDF-SHA256 step of libsignal v0.105.4 RootKey::create_chain (rust/, info "WhisperRatchet", 64-byte output split into 32-byte root and chain keys) as rootKdf, packages it as the ACD19 PRF-PRNG rootPRNG (a named assumption of the session theorem, DEV-LS30), and defines its single-step PRG/PRF components expandPRG and extractPRF.
@[expose] public sectionopen OracleComp OracleSpec ENNRealnamespace CryptoGamesnamespace Ratchetopen HMAC HKDF CBC MACSchemeabbrev RootKey
256-bit root key as its 32 LE bytes (RootKey., keys.rs:185–188).
abbrev RootKey := BitVec 256def whisperRatchetInfo
HKDF info "WhisperRatchet" (14 ASCII bytes, keys.rs:207).
def whisperRatchetInfo : List (BitVec 8) :=
"WhisperRatchet".toList.map fun c => BitVec.ofNat 8 c.toNatdef rootSalt
HKDF salt Some(&self. (keys.rs:206).
def rootSalt (rk : RootKey) : Salt :=
some ⟨keyToBytes32 rk, rk:RootKey⊢ (keyToBytes32 rk).length = 32 All goals completed! 🐙⟩def rootExpand
HKDF-Expand(prk, "WhisperRatchet", 64) split into (rootKey, chainKey) (keys.rs:205–209).
def rootExpand (F : ShaState → List (BitVec 8) → ShaState) (prk : List (BitVec 8)) :
RootKey × ChainKey :=
let okm := hkdfExpand F prk whisperRatchetInfo 64
(bytesToKey32 (okm.take 32), bytesToKey32 ((okm.drop 32).take 32))def rootKdf
RootKey::create_chain KDF step (keys.rs:204–217): HKDF(salt = rk, ikm, "WhisperRatchet", 64) split into (okm[0..32], okm[32..64]).
def rootKdf (F : ShaState → List (BitVec 8) → ShaState) (rk : RootKey) (ikm : List (BitVec 8)) :
RootKey × ChainKey :=
let okm := hkdf F (rootSalt rk) ikm whisperRatchetInfo 64
(bytesToKey32 (okm.take 32), bytesToKey32 ((okm.drop 32).take 32))def rootPRNG
def expandPRG
rootExpand as a PRG from a uniform 256-bit PRK to RootKey × ChainKey.
def expandPRG (F : ShaState → List (BitVec 8) → ShaState) :
PRGScheme (BitVec 256) (RootKey × ChainKey) :=
⟨fun prk => rootExpand F (keyToBytes32 prk)⟩def extractPRF
HKDF-Extract keyed by the root key in the salt slot as a PRF RootKey → Pt → BitVec 256.
def extractPRF (F : ShaState → List (BitVec 8) → ShaState) {Pt : Type}
(enc : Pt → List (BitVec 8)) : MACScheme RootKey Pt (BitVec 256) :=
⟨fun σ I => bytesToKey32 (hkdfExtract F (rootSalt σ) (enc I))⟩end Ratchetend CryptoGames