Kdf.lean
SPQR V1: HKDF-SHA256 key derivation (spqr/)
Trusted in part. The theorems of Computational/ use the HKDF functions of this file (hkdfToVec, hkdfToSlice, hkdfToVecUnchecked, hkdfToSliceUnchecked, hkdfExtractBytes, hkdfMaxOkmLen, kdfInvalidLengthPanic, with bridges hkdfToSlice_of_le and hkdfToVec_of_le); the test helpers in Tests are checked by Lean (see Computational/).
Panic-explicit model of spqr/ over an abstract SHA-256 compression function F, returning Except SpqrPanic Bytes with .error kdfInvalidLengthPanic when okmLen > 255 * 32.
@[expose] public sectionnamespace CryptoVerification.LibsignalSpqrV1open CryptoGames.HMAC CryptoGames.HKDFabbrev hkdfMaxOkmLen
Maximum HKDF-SHA256 output length in bytes (255 * 32 = 8160, RFC 5869 §2.3).
abbrev hkdfMaxOkmLen : ℕ := 255 * 32abbrev kdfInvalidLengthPanic
Panic site of spqr::kdf::hkdf_to_slice (src/) when okm_len > 255 * 32.
def hkdfExtractBytes
HKDF-Extract (HMAC-SHA256(salt, ikm), src/).
1 declaration not shown (lines 45–49): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification.
def hkdfToSliceUnchecked
def hkdfToSliceUnchecked (F : ShaState → List (BitVec 8) → ShaState)
(salt ikm info : Bytes) (okmLen : ℕ) : Bytes :=
hkdfExpand F (hkdfExtractBytes F salt ikm) info okmLendef hkdfToSlice
spqr::kdf::hkdf_to_slice (src/), panicking with kdfInvalidLengthPanic when okmLen > hkdfMaxOkmLen.
def hkdfToSlice (F : ShaState → List (BitVec 8) → ShaState)
(salt ikm info : Bytes) (okmLen : ℕ) : Except SpqrPanic Bytes :=
if okmLen ≤ hkdfMaxOkmLen then
.ok (hkdfToSliceUnchecked F salt ikm info okmLen)
else
.error kdfInvalidLengthPanicdef hkdfToVecUnchecked
def hkdfToVecUnchecked (F : ShaState → List (BitVec 8) → ShaState)
(salt ikm info : Bytes) (okmLen : ℕ) : Bytes :=
hkdfToSliceUnchecked F salt ikm info okmLendef hkdfToVec
spqr::kdf::hkdf_to_vec (src/).
16 declarations not shown (lines 73–172): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification.
end CryptoVerification.LibsignalSpqrV1