Auth.lean
Declarations on this page (21)
- abbrev Mac
- abbrev hmacU32UnwrapPanic
- inductive AuthError
-
def AuthError.
toError - structure Authenticator
- abbrev macSize
- def updateLabel
- def ctLabel
- def hdrLabel
- def update
- def new
- def macCtUnchecked
- def macCt
- def verifyCt
- def verifyCtError
- def macHdrUnchecked
- def macHdr
- def verifyHdr
- def verifyHdrError
- def intoPb
- def fromPb
SPQR V1: Authenticator (spqr/, src/)
Trusted in part. The theorems of Computational/ use every definition in this file except compare_prefix, Authenticator., Authenticator. and the test vectors in Tests, which are checked by Lean (see Computational/).
Models SPQR's epoch authenticator (Mac, AuthError, Authenticator with macSize, new, update, intoPb, fromPb), panic-explicit HMAC-SHA256 tag computation and constant-time verification (macCt, verifyCt, verifyCtError, macHdr, verifyHdr, verifyHdrError, hmacU32UnwrapPanic), and unchecked helpers (macCtUnchecked, macHdrUnchecked, verifyCt_eq_ok_prefix, verifyHdr_eq_ok_prefix).
@[expose] public sectionnamespace CryptoVerification.LibsignalSpqrV1open CryptoGames.HMAC4 declarations not shown (lines 39–61): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification.
Types and constants (spqr/)
abbrev Mac
abbrev Mac := Bytesabbrev hmacU32UnwrapPanic
Panic site in libcrux-hmac 0.0.8 (src/): u32 length unwrap when key. or data..
inductive AuthError
spqr::authenticator::Error (src/).
inductive AuthError where
| invalidCtMac
| invalidHdrMac
| authenticatorRootKeyPresent
| authenticatorRootKeyMissing
| authenticatorMacKeyPresent
| authenticatorMacKeyMissing
deriving DecidableEq, Repr, Inhabited
def AuthError.
def AuthError.toError : AuthError → Error := fun _ => .macVerifyFailedstructure Authenticator
spqr::authenticator::Authenticator (src/).
namespace Authenticatorabbrev macSize
abbrev macSize : ℕ := 32def updateLabel
def updateLabel : Bytes :=
"Signal_PQCKA_V1_MLKEM768:Authenticator Update".toList.map fun c => BitVec.ofNat 8 c.toNatdef ctLabel
def ctLabel : Bytes :=
"Signal_PQCKA_V1_MLKEM768:ciphertext".toList.map fun c => BitVec.ofNat 8 c.toNatdef hdrLabel
def hdrLabel : Bytes :=
"Signal_PQCKA_V1_MLKEM768:ekheader".toList.map fun c => BitVec.ofNat 8 c.toNatdef update
Authenticator::update (src/): derives (rootKey, macKey) via 64-byte HKDF-SHA256 from rootKey ++ k and updateLabel ++ ep.
def update (F : ShaState → List (BitVec 8) → ShaState)
(self : Authenticator) (ep : Epoch) (k : Bytes) : Authenticator :=
let ikm := self.rootKey ++ k
let info := updateLabel ++ toBEBytes 8 ep
let kdfOut := hkdfToVecUnchecked F (List.replicate 32 0) ikm info 64
{ rootKey := kdfOut.take 32
macKey := kdfOut.drop 32 }def new
Authenticator::new (src/).
def new (F : ShaState → List (BitVec 8) → ShaState) (rootKey : Bytes) (ep : Epoch) : Authenticator :=
let result : Authenticator := { rootKey := List.replicate 32 0, macKey := List.replicate 32 0 }
result.update F ep rootKeydef macCtUnchecked
1 declaration not shown (lines 124–128): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification.
def macCt
Authenticator::mac_ct (src/): HMAC-SHA256 tag over ctLabel ++ ep.hmacU32UnwrapPanic if key or input length reaches 2^32.
def macCt (F : ShaState → List (BitVec 8) → ShaState)
(self : Authenticator) (ep : Epoch) (ct : Bytes) : Except SpqrPanic Mac :=
let ctMacData := ctLabel ++ toBEBytes 8 ep ++ ct
if self.macKey.length < 2 ^ 32 ∧ ctMacData.length < 2 ^ 32 then
.ok (self.macCtUnchecked F ep ct)
else
.error hmacU32UnwrapPanic2 declarations not shown (lines 141–153): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification., CryptoVerification.
def verifyCt
Authenticator::verify_ct (src/): checks expectedMac against macCt F ep ct via Core. (which compares 0..expectedMac. and panics if expectedMac.).
def verifyCt (F : ShaState → List (BitVec 8) → ShaState)
(self : Authenticator) (ep : Epoch) (ct expectedMac : Bytes) :
Except SpqrPanic (Except AuthError Unit) := do
let mac ← self.macCt F ep ct
let c ← compare expectedMac mac
return if c != 0#8 then .error .invalidCtMac else .ok ()def verifyCtError
def verifyCtError (F : ShaState → List (BitVec 8) → ShaState)
(self : Authenticator) (ep : Epoch) (ct expectedMac : Bytes) :
Except SpqrPanic (Except Error Unit) :=
(self.verifyCt F ep ct expectedMac).map (Except.mapError AuthError.toError)1 declaration not shown (lines 170–179): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification.
def macHdrUnchecked
1 declaration not shown (lines 186–190): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification.
def macHdr
Authenticator::mac_hdr (src/): HMAC-SHA256 tag over hdrLabel ++ ep.hmacU32UnwrapPanic if key or input length reaches 2^32.
def macHdr (F : ShaState → List (BitVec 8) → ShaState)
(self : Authenticator) (ep : Epoch) (hdr : Bytes) : Except SpqrPanic Mac :=
let ctMacData := hdrLabel ++ toBEBytes 8 ep ++ hdr
if self.macKey.length < 2 ^ 32 ∧ ctMacData.length < 2 ^ 32 then
.ok (self.macHdrUnchecked F ep hdr)
else
.error hmacU32UnwrapPanic2 declarations not shown (lines 203–215): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification., CryptoVerification.
def verifyHdr
Authenticator::verify_hdr (src/): checks expectedMac against macHdr F ep hdr via Core. (panicking if expectedMac.).
def verifyHdr (F : ShaState → List (BitVec 8) → ShaState)
(self : Authenticator) (ep : Epoch) (hdr expectedMac : Bytes) :
Except SpqrPanic (Except AuthError Unit) := do
let mac ← self.macHdr F ep hdr
let c ← compare expectedMac mac
return if c != 0#8 then .error .invalidHdrMac else .ok ()def verifyHdrError
def verifyHdrError (F : ShaState → List (BitVec 8) → ShaState)
(self : Authenticator) (ep : Epoch) (hdr expectedMac : Bytes) :
Except SpqrPanic (Except Error Unit) :=
(self.verifyHdr F ep hdr expectedMac).map (Except.mapError AuthError.toError)1 declaration not shown (lines 231–240): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification.
def intoPb
def intoPb (self : Authenticator) : ProtoAuthenticator :=
{ rootKey := self.rootKey, macKey := self.macKey }def fromPb
def fromPb (pb : ProtoAuthenticator) : Authenticator :=
{ rootKey := pb.rootKey, macKey := pb.macKey }2 declarations not shown (lines 248–252): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification., CryptoVerification.
end Authenticator11 declarations not shown (lines 262–349): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification., CryptoVerification.
end CryptoVerification.LibsignalSpqrV1