AlphaProof Code: Verifying Signal’s Security at the Machine-Code Level

Paper › LibsignalBinary/Specifications/RecordCodecs › Proto.leanTier 2 · definitions

Proto.lean🔗

Tier 2 · definitions used by the symbolic proof 3 headline theorems depend on it 56 of 268 lines trusted trust banner B3, trusted in part source ↗

Read the definitions shown. Only the declarations that the headline statements use are shown, with the namespace, section, open and variable commands needed to read them. The collapsed runs are theorems, which Lean checks, and definitions that no headline statement uses.

Declarations on this page (10)

Protobuf Record Codecs for Identity and Pre-Key Stores

Trusted in part. SignalSession/PqDir.lean (encodeDir) encodes identity and pre-key store files with IdentityKeyPairStructure, SignedPreKeyRecordStructure, and PreKeyRecordStructure (encode) via encodeProto3BytesField, encodeProto3Uint32Field, encodeProto3Fixed64Field, and le64Bytes; the decoders (empty, mergeField, decode, decodeFieldsLoop, skipUnknown, mergeFixed64, le64) and record wrappers (PreKeyRecord, SignedPreKeyRecord, KyberPreKeyRecord, deserialize, serialize) are checked by Lean. See Computational/docs/TRUSTED_BASE.md.

Models prost 0.14.4's proto3 encoders (tag-ordered fields, omitting default 0 / empty values) and decoders (Message::merge from default with last-write-wins field merging and unknown-field skipping up to recursion limit 100) for storage.proto messages.

@[expose] public section
namespace CryptoVerification.RecordCodecs
open CryptoGames.LibsignalSession CryptoVerification.LibsignalProtoCodec
3 declarations not shown (lines 38–64): theorems, which Lean checks, or definitions that no headline statement uses

CryptoVerification.RecordCodecs.decodeFieldsLoop, CryptoVerification.RecordCodecs.skipUnknown, CryptoVerification.RecordCodecs.le64

def le64BytesL66–69 ↗#

BufMut::put_u64_le: the 8 little-endian bytes of v.

def le64Bytes (v : BitVec 64) : List (BitVec 8) := [v.extractLsb' 0 8, v.extractLsb' 8 8, v.extractLsb' 16 8, v.extractLsb' 24 8, v.extractLsb' 32 8, v.extractLsb' 40 8, v.extractLsb' 48 8, v.extractLsb' 56 8]
1 declaration not shown (lines 71–78): theorems, which Lean checks, or definitions that no headline statement uses

CryptoVerification.RecordCodecs.mergeFixed64

proto3 field encoders (omit the default value, D/field/scalar.rs:119–126)

def encodeProto3BytesFieldL82–85 ↗#

A proto3 bytes field: nothing when empty, else bytes::encode(tag, value) (P/encoding.rs:691–695).

def encodeProto3BytesField (tag : ℕ) (v : List (BitVec 8)) : List (BitVec 8) := if v = [] then [] else encodeBytesField tag (some v)

def encodeProto3Uint32FieldL87–89 ↗#

A proto3 uint32 field: nothing when 0, else uint32::encode(tag, value).

def encodeProto3Uint32Field (tag : ℕ) (v : BitVec 32) : List (BitVec 8) := if v = 0 then [] else encodeUint32Field tag (some v)

def encodeProto3Fixed64FieldL91–93 ↗#

A proto3 fixed64 field: nothing when 0, else the key and put_u64_le(value).

def encodeProto3Fixed64Field (tag : ℕ) (v : BitVec 64) : List (BitVec 8) := if v = 0 then [] else encodeKey tag .sixtyFourBit ++ le64Bytes v

PreKeyRecordStructure (storage.proto:76–80)

structure PreKeyRecordStructureL97–106 ↗#

message PreKeyRecordStructure { uint32 id = 1; bytes public_key = 2; bytes private_key = 3; } (prost struct proto::storage::PreKeyRecordStructure).

structure PreKeyRecordStructure where /-- `uint32 id = 1`. -/ id : BitVec 32 /-- `bytes public_key = 2` (libsignal writes `PublicKey::serialize`, 33 bytes). -/ publicKey : List (BitVec 8) /-- `bytes private_key = 3` (libsignal writes `PrivateKey::serialize`, 32 bytes). -/ privateKey : List (BitVec 8) deriving DecidableEq, Repr
namespace PreKeyRecordStructure
3 declarations not shown (lines 110–124): theorems, which Lean checks, or definitions that no headline statement uses

CryptoVerification.RecordCodecs.PreKeyRecordStructure.empty, CryptoVerification.RecordCodecs.PreKeyRecordStructure.mergeField, CryptoVerification.RecordCodecs.PreKeyRecordStructure.decode

def encodeL126–128 ↗#

<PreKeyRecordStructure as Message>::encode_to_vec.

end PreKeyRecordStructure

SignedPreKeyRecordStructure (storage.proto:82–88)

structure SignedPreKeyRecordStructureL134–148 ↗#

message SignedPreKeyRecordStructure { uint32 id = 1; bytes public_key = 2; bytes private_key = 3; bytes signature = 4; fixed64 timestamp = 5; }. Both SignedPreKeyRecord (X25519 keys) and KyberPreKeyRecord (KEM keys) store one.

structure SignedPreKeyRecordStructure where /-- `uint32 id = 1`. -/ id : BitVec 32 /-- `bytes public_key = 2`. -/ publicKey : List (BitVec 8) /-- `bytes private_key = 3`. -/ privateKey : List (BitVec 8) /-- `bytes signature = 4`. -/ signature : List (BitVec 8) /-- `fixed64 timestamp = 5` (milliseconds since the epoch). -/ timestamp : BitVec 64 deriving DecidableEq, Repr
namespace SignedPreKeyRecordStructure
3 declarations not shown (lines 152–168): theorems, which Lean checks, or definitions that no headline statement uses

CryptoVerification.RecordCodecs.SignedPreKeyRecordStructure.empty, CryptoVerification.RecordCodecs.SignedPreKeyRecordStructure.mergeField, CryptoVerification.RecordCodecs.SignedPreKeyRecordStructure.decode

end SignedPreKeyRecordStructure

IdentityKeyPairStructure (storage.proto:90–93)

structure IdentityKeyPairStructureL179–185 ↗#

message IdentityKeyPairStructure { bytes public_key = 1; bytes private_key = 2; }.

structure IdentityKeyPairStructure where /-- `bytes public_key = 1`. -/ publicKey : List (BitVec 8) /-- `bytes private_key = 2`. -/ privateKey : List (BitVec 8) deriving DecidableEq, Repr
namespace IdentityKeyPairStructure
3 declarations not shown (lines 189–202): theorems, which Lean checks, or definitions that no headline statement uses

CryptoVerification.RecordCodecs.IdentityKeyPairStructure.empty, CryptoVerification.RecordCodecs.IdentityKeyPairStructure.mergeField, CryptoVerification.RecordCodecs.IdentityKeyPairStructure.decode

def encodeL204–206 ↗#

<IdentityKeyPairStructure as Message>::encode_to_vec.

end IdentityKeyPairStructure
9 declarations not shown (lines 212–269): theorems, which Lean checks, or definitions that no headline statement uses

CryptoVerification.RecordCodecs.PreKeyRecord.preKey, CryptoVerification.RecordCodecs.PreKeyRecord, CryptoVerification.RecordCodecs.PreKeyRecord.deserialize, CryptoVerification.RecordCodecs.PreKeyRecord.serialize, CryptoVerification.RecordCodecs.SignedPreKeyRecord, CryptoVerification.RecordCodecs.SignedPreKeyRecord.signedPreKey, CryptoVerification.RecordCodecs.SignedPreKeyRecord.deserialize, CryptoVerification.RecordCodecs.SignedPreKeyRecord.serialize, CryptoVerification.RecordCodecs.KyberPreKeyRecord.signedPreKey, CryptoVerification.RecordCodecs.KyberPreKeyRecord, CryptoVerification.RecordCodecs.KyberPreKeyRecord.deserialize, CryptoVerification.RecordCodecs.KyberPreKeyRecord.serialize

end CryptoVerification.RecordCodecs