Core.lean
Declarations on this page (13)
SPQR V1: shared core types (src/) and constant-time helpers (src/)
Trusted in part. The theorems of Computational/ use every definition in this file except Direction. and Direction., which are checked by Lean (see Computational/).
Shared SPQR V1 types (Epoch, Secret, EpochSecret, Direction with switch and toI32, Error with isStateDecode, SpqrPanic) and constant-time comparison helpers (inz, isNonZero, compare) from spqr (src/, src/).
@[expose] public sectionnamespace CryptoVerification.LibsignalSpqrV1
Core types from src/ and src/
structure EpochSecret
pub struct EpochSecret (src/).
inductive Direction
pub enum Direction (src/, src/).
inductive Direction where
| a2b
| b2a
deriving DecidableEq, Repr, Inhabitednamespace Direction2 declarations not shown (lines 52–54): theorems, which Lean checks, or definitions that no headline statement uses
CryptoVerification., CryptoVerification.
def toI32
def fromI32?
Direction::try_from(v: i32) (src/).
end Directioninductive Error
pub enum Error (src/).
inductive Error where
| stateDecode
| notImplemented
| msgDecode
| macVerifyFailed
| epochOutOfRange (epoch : Epoch)
| encodingDecoding
| serialization
| versionMismatch
| minimumVersion
| keyJump (ctr atIdx : BitVec 32)
| keyTrimmed (atIdx : BitVec 32)
| keyAlreadyRequested (atIdx : BitVec 32)
| erroneousDataReceived
| sendKeyEpochDecreased (sendEpoch epoch : Epoch)
| invalidParams (msg : String)
| chainNotAvailable
deriving DecidableEq, Repr, Inhabitednamespace Errordef isStateDecode
def isStateDecode : Error → Bool
| .stateDecode => true
| _ => falseend ErrorPanics
inductive SpqrPanic
Shared Rust panic sites (compareBounds at src/, or site for cited panics).
inductive SpqrPanic where
/-- `src/util.rs:29`: `rhs[i]` out of bounds in `compare` when `rhs.len() < lhs.len()`. -/
| compareBounds
| site (loc : String)
deriving DecidableEq, Repr, Inhabited
src/
def inz
spqr::util::inz(value: u8) -> u8 (src/).
def inz (value : BitVec 8) : BitVec 8 :=
let v16 : BitVec 16 := value.zeroExtend 16
let result : BitVec 16 := ((v16 ||| ((~~~v16) + 1#16)) >>> 8) &&& 1#16
result.truncate 8def isNonZero
def isNonZero (value : BitVec 8) : BitVec 8 :=
inz valuedef compare
spqr::util::compare(lhs: &[u8], rhs: &[u8]) -> u8 (src/): returns 0 iff lhs equals the first lhs. bytes of rhs, or panics with compareBounds when lhs..
def compare (lhs rhs : Bytes) : Except SpqrPanic (BitVec 8) :=
if lhs.length ≤ rhs.length then
.ok (isNonZero ((lhs.zip rhs).foldl (fun r (a, b) => r ||| (a ^^^ b)) 0#8))
else .error .compareBoundsend CryptoVerification.LibsignalSpqrV1