Documentation

CslibFrontier.Crypto.Primitives.Hash.ExtendableOutput

Extendable-output functions on raw bit strings #

A request specifies an input and a byte count. Every request at the same input reads a prefix of one stream, even if the counts or the roles of the callers differ.

A bit-input XOF with output lengths in bytes.

Byte input uses the FIPS 202 least-significant-bit-first convention.

A call to an extendable-output stream specifies the raw input and requested byte count.

  • input : List Bool

    Complete input bits, including any message, seed or counter framing.

  • count : ℕ

    Number of bytes requested from the beginning of this stream.

@[reducible, inline]

Adaptive requests to a single prefix-consistent XOF on raw bit strings.

Read every request consistently from one XOF.

Read an XOF with the first bytes of this stream replaced. Requests shorter than the replacement are truncations. Longer requests continue with the original tail.

Overwriting each selected input's prefix gives a single prefix-consistent XOF on raw inputs. Every role reading the same input sees the same bytes, including when their counts differ.

Replacing a stream prefix by its actual first bytes preserves every read.

def Cslib.Crypto.ExtendableOutput.fill (H : ExtendableOutput) {rows : Finset (List Bool)} {width : ℕ} (seen : List Bool → ℕ) (tape : ↥rows → FixedBytes width) :

Fill a finite window of each selected raw row, starting after its previously read prefix. All earlier bytes, other rows and bytes past the window come from the original XOF.

theorem Cslib.Crypto.ExtendableOutput.read_fill_of_notMem (H : ExtendableOutput) {rows : Finset (List Bool)} {width : ℕ} (seen : List Bool → ℕ) (tape : ↥rows → FixedBytes width) {x : List Bool} (hx : x ∉ rows) (n : ℕ) :
(H.fill seen tape).read x n = H.read x n

An input outside the completed rows keeps its entire XOF output.

theorem Cslib.Crypto.ExtendableOutput.read_fill_window (H : ExtendableOutput) {rows : Finset (List Bool)} {width : ℕ} (seen : List Bool → ℕ) (tape : ↥rows → FixedBytes width) (x : ↥rows) {n : ℕ} (hn : n ≤ seen ↑x + width) :
(H.fill seen tape).read (↑x) n = List.take n (H.read (↑x) (seen ↑x) ++ List.ofFn (tape x))

Within the filled window a raw read consists of its old prefix followed by fresh bytes.

theorem Cslib.Crypto.ExtendableOutput.read_fill_of_le (H : ExtendableOutput) {rows : Finset (List Bool)} {width : ℕ} (seen : List Bool → ℕ) (tape : ↥rows → FixedBytes width) {x : List Bool} {n : ℕ} (hn : n ≤ seen x) :
(H.fill seen tape).read x n = H.read x n

All previously read prefixes, including repeated reads at different lengths, survive.

The byte at a fixed offset of a raw XOF input stream.

theorem Cslib.Crypto.ExtendableOutput.getElem_read (H : ExtendableOutput) (x : List Bool) {i n : ℕ} (hi : i < n) :
(H.read x n)[i] = H.byteAt x i

All reads long enough to contain an offset agree on its byte.

theorem Cslib.Crypto.ExtendableOutput.byteAt_withPrefixes (H : ExtendableOutput) (f : List Bool → Option (List Byte)) (x : List Bool) (i : ℕ) :
(H.withPrefixes f).byteAt x i = ((f x).bind fun (row : List Byte) => row[i]?).getD (H.byteAt x i)

A prefix update affects exactly the byte offsets present in the replacement row.

theorem Cslib.Crypto.ExtendableOutput.read_eq_of_byteAt_eq {H G : ExtendableOutput} {x : List Bool} {n : ℕ} (same : ∀ i < n, H.byteAt x i = G.byteAt x i) :
H.read x n = G.read x n

The first n bytes at one input determine its n-byte read.

theorem Cslib.Crypto.ExtendableOutput.ext_byteAt {H G : ExtendableOutput} (same : ∀ (x : List Bool) (i : ℕ), H.byteAt x i = G.byteAt x i) :
H = G

Two XOFs agree on all finite reads if their individual bytes agree.