Documentation

QedShareCli.Facts

Facts about the CLI pipeline #

Theorems about the pure CLI layer (QedShareCli.Pipeline), so that the code between the proven core and the terminal is proven too, not only tested.

Characters #

A hex digit is never whitespace.

Hex-encoded bytes contain no whitespace.

n bytes are 2n hex digits.

theorem QedShare.Cli.dropWhile_of_head {α : Type} (p : α → Bool) (l : List α) (h : ∀ (a : α), a ∈ l.head? → p a = false) :

dropWhile keeps a list whose first element fails the test.

theorem QedShare.Cli.trimWs_ofList (l : List Char) (hh : ∀ (c : Char), c ∈ l.head? → c.isWhitespace = false) (hl : ∀ (c : Char), c ∈ l.getLast? → c.isWhitespace = false) :

trimWs keeps text whose first and last characters are not whitespace.

Text with no whitespace at all is kept by trimWs.

theorem QedShare.Cli.dropWhile_nil_or {α : Type} (p : α → Bool) (l : List α) :

Either dropWhile p removes everything and every element passes p, or what is left has an element that fails p.

isBlank says what (trimWs s).isEmpty says.

Hex shares #

A hex share contains no whitespace.

A hex share has at most 61 + 2·(payload bytes) characters (tag, six dashes, set id, k, x, payload, a 16-byte token and the checksum).

Word shares #

Every word of the list has at most 8 letters.

theorem QedShare.Cli.wordOf_lower {n : Nat} (hn : n < 2048) :

Every character of a word is a lowercase letter.

theorem QedShare.Cli.length_wordOf {n : Nat} (hn : n < 2048) :

A word has at most 8 letters.

theorem QedShare.Cli.mem_intercalate {c : Char} {ws : List (List Char)} (h : c ∈ [' '].intercalate ws) :
c = ' ' ∨ ∃ (w : List Char), w ∈ ws ∧ c ∈ w

Words joined by spaces: every character is a space or a character of one of the words.

theorem QedShare.Cli.length_intercalate_le (ws : List (List Char)) (m : Nat) (h : ∀ (w : List Char), w ∈ ws → w.length ≤ m) :
([' '].intercalate ws).length ≤ (m + 1) * ws.length

Words joined by spaces are at most one character longer per word than the words.

theorem QedShare.Cli.head?_intercalate (w : List Char) (ws : List (List Char)) (hw : w ≠ []) :
([' '].intercalate (w :: ws)).head? = w.head?

The first character of words joined by spaces is the first character of the first word.

theorem QedShare.Cli.getLast?_intercalate (ws : List (List Char)) (h : ∀ (w : List Char), w ∈ ws → w ≠ []) (c : Char) :
c ∈ ([' '].intercalate ws).getLast? → ∃ (w : List Char), w ∈ ws ∧ c ∈ w

The last character of words joined by spaces is the last character of the last word.

A word share: the words, as character lists.

A word share has at least one word.

The number of bytes in a word share.

tokenLen is at most 16 bytes.

A word share contains no -, so it is never taken for a hex share.

A word share has at most 8192 characters (the limit decodeShare allows).

The CLI reads back what it writes. A share written as hex or as words by encodeRecord is read by decodeShare (trimming, telling hex from words, length limits, decoding and every check) as exactly the same record. Conditions: the token has the right length for the format, the payload is no longer than a 1 MiB secret's, and, for words, at most 255 bytes.

Reading many shares #

theorem QedShare.Cli.mapM_ok {α β ε : Type} (f : α → Except ε β) (g : α → β) (l : List α) (h : ∀ (a : α), a ∈ l → f a = Except.ok (g a)) :

mapM in Except succeeds with l.map g when f succeeds with g a on every element.

theorem QedShare.Cli.mapM_ok_zip {α β ε : Type} (f : α → Except ε β) (l : List α) (out : List β) (h : List.mapM f l = Except.ok out) :
out.length = l.length ∧ ∀ (p : α × β), p ∈ l.zip out → f p.fst = Except.ok p.snd

If mapM in Except succeeds, the output has the input's length and each output is f of the input at the same position.

theorem QedShare.Cli.recoverSecret_ok {inputs : List (String × String)} {secret : List UInt8} (h : recoverSecret inputs = Except.ok secret) :
∃ (records : List Encoding.ShareRecord), records.length = inputs.length ∧ (∀ (p : (String × String) × Encoding.ShareRecord), p ∈ inputs.zip records → decodeShare p.fst.fst p.fst.snd = Except.ok p.snd) ∧ records ≠ [] ∧ (∀ (r : Encoding.ShareRecord), r ∈ records → r.setId = records.head!.setId ∧ r.k = records.head!.k ∧ r.fmt = records.head!.fmt) ∧ records.head!.k.toNat ≤ records.length ∧ ∃ (tagged : List GF256), Shamir.combine records.head!.k.toNat (List.map (fun (x : Encoding.ShareRecord) => x.share) records) = Except.ok tagged ∧ untagSecret records.head!.fmt records.head!.k.toNat tagged (tokensOf records) = some secret

What it means when combine accepts. If recoverSecret (what qedshare combine runs) returns a secret, then each input string was read as a share record (one per input, in order), the records agree on set id, threshold k and format, there are at least k of them, and the secret is exactly what the core computes: combine on their shares, then the format's check (Token.decode for qs3: the AMD tag and every share's token). So the core theorems about combine and Token.decode, such as combine_detects_forgery_tok, apply to the CLI as it runs.

Splitting #

theorem QedShare.Cli.makeShares_eq {k n : Nat} {secret random sid : List UInt8} {form : ShareForm} {out : List String} (h : makeShares k n secret random sid form = Except.ok out) :
∃ (p : Shamir.Params), p.k = k ∧ p.n = n ∧ secret ≠ [] ∧ secret.length ≤ maxSecretBytes ∧ (form = ShareForm.words → secret.length ≤ maxWordsSecretBytes k) ∧ ∃ (key : GF2_128), ∃ (G : List GF2_128), ∃ (rand : List Poly), G.length = k ∧ Shamir.ValidRand p (Token.encode (List.map GF256.mk secret) G key).length rand ∧ out = List.map (fun (x : GF256) => encodeRecord form { setId := setIdOf sid, k := k.toUInt8, share := Shamir.shareAt (Token.encode (List.map GF256.mk secret) G key) rand x, fmt := Encoding.Fmt.v3, token := ByteCoords.toBytes (Token.tokenAt G x) }) (Shamir.indices n)

What makeShares returns. When it succeeds (in the qs3 format the CLI uses), the parameters are valid, the secret is non-empty and within the limits, and the share strings are the encoded shares at 1 … n of one split of E = Token.encode s G key, each with its token G(x), for a token polynomial G with k coefficients and valid split randomness.