CreateChainDefs.lean
RootKey::create_chain with the X25519 agreement, over abstract SHA-256 and X25519
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 X25519 key-agreement half of libsignal v0.105.4 RootKey::create_chain (rust/): RFC 7748 scalar clamping (clampScalar), abstract X25519 evaluation (X25519Fn), all-zero shared-secret rejection, and HKDF root derivation via rootKdf.
@[expose] public sectionnamespace CryptoGamesnamespace Ratchetopen HMAC HKDFabbrev X25519Fn
Abstract X25519 function mapping 32 clamped scalar bytes and 32 u-coordinate bytes to 32 u-coordinate bytes (all LE).
abbrev X25519Fn := List.Vector (BitVec 8) 32 → List.Vector (BitVec 8) 32 → List.Vector (BitVec 8) 32def clampScalar
curve25519_dalek::scalar::clamp_integer (v5.0.0): k[0] &= 0xf8; k[31] &= 0x7f; k[31] |= 0x40.
def clampScalar (k : List.Vector (BitVec 8) 32) : List.Vector (BitVec 8) 32 :=
((k.set 0 (k.get 0 &&& 0xf8#8)).set 31 ((k.get 31 &&& 0x7f#8) ||| 0x40#8))def keyToBytesVec32
32 LE bytes of a 256-bit key as a List..
def keyToBytesVec32 (k : BitVec 256) : List.Vector (BitVec 8) 32 :=
⟨keyToBytes32 k, k:BitVec 256⊢ (keyToBytes32 k).length = 32 All goals completed! 🐙⟩def createChain
RootKey::create_chain over abstract SHA-256 F and X25519 X: computes ss = X (clampScalar priv) pub, returning none if ss is all zero and rootKdf F rk ss.
end Ratchetend CryptoGames