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 #
Cslib.Crypto.Byte: one unsigned byte.Cslib.Crypto.FixedBytes: a byte string whose length is part of its type.Cslib.Crypto.FixedBytes.ofListExact: turn a list with a proved length into typed bytes.Cslib.Crypto.bytesToBitsBE: big-endian serialization of a list of bytes.Cslib.Crypto.bitsToFixedBytesBE: split a bit list into typed big-endian bytes.
Main results #
Cslib.Crypto.length_bytesToBitsBE: byte serialization has eight bits per byte.Cslib.Crypto.byteOfBitsBE_byteBitsBE,Cslib.Crypto.byteBitsBE_byteOfBitsBE: converting one byte to bits and back is exact in either direction.Cslib.Crypto.bytesToBitsBE_bitsToFixedBytesBE: an exact-length bit string round-trips through typed bytes.Cslib.Crypto.bytesToBitsBE_natToFixedBytesBE: natural-number serialization retains exactly its low8nbits.Cslib.Crypto.bytesToBitsBE_lt_iff_lt: equal-length byte strings and their big-endian bit serializations have the same lexicographic order.
One byte, represented by its unsigned integer value.
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.
The list view has the byte length recorded in the type.
The list view of ofListExact X h is the list X it was built from.
A byte list has eight serialized bits per byte.
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.
Serializing one byte to eight big-endian bits and reading it back recovers the byte.
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.
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.