Documentation

CslibFrontier.Crypto.Primitives.ByteString

Byte strings #

This module supplies the byte boundary shared by executable cryptographic primitives. A byte is an unsigned integer below 256, and FixedBytes n records a byte-string length in its type. The big-endian bit conversion follows the byte convention used by FIPS 180-4 and FIPS 205; primitives with a different within-byte convention, such as FIPS 202's Keccak, keep that conversion explicit.

Main definitions #

Main results #

@[reducible, inline]

One byte, represented by its unsigned integer value.

@[reducible, inline]

A byte string whose byte length is part of its type.

Turn a list whose length is known exactly into a fixed-length byte string.

The list view of a fixed-length byte string.

@[simp]

The list view has the byte length recorded in the type.

@[simp]

The list view of ofListExact X h is the list X it was built from.

theorem Cslib.Crypto.FixedBytes.exists_toList {n : ℕ} {bytes : List Byte} (h : bytes.length = n) :
∃ (v : FixedBytes n), v.toList = bytes

A byte string of length n is the list view of a fixed-length byte string.

The eight big-endian bits of a byte.

The bits of a byte list in big-endian order within each byte.

@[simp]

A byte list has eight serialized bits per byte.

Equal-length byte strings and their big-endian bit serializations have the same strict lexicographic order.

Read at most eight big-endian bits as one byte. Missing low-order bits are not added; callers that require a full byte should supply an eight-bit chunk.

@[simp]

Serializing one byte to eight big-endian bits and reading it back recovers the byte.

@[simp]
theorem Cslib.Crypto.byteBitsBE_byteOfBitsBE (bits : List Bool) (h : bits.length = 8) :

Reading an eight-bit word as a byte and serializing it recovers the word.

Split a bit list into n consecutive big-endian bytes. An incomplete or absent final chunk is read using byteOfBitsBE; exact-length clients avoid that fallback by construction.

@[simp]

An exact 8 * n-bit word round-trips through its n typed big-endian bytes.

Encode a natural number as exactly n big-endian bytes, retaining its low 8n bits.

Serializing a natural number as n bytes produces its low 8n bits in big-endian order.