Share text formats qs1, qs2 and qs3 #
qs1-<setid>-<k>-<x>-<payload>-<checksum>
qs2-<setid>-<k>-<x>-<payload>-<checksum>
qs3-<setid>-<k>-<x>-<payload>-<token>-<checksum>
All fields are lowercase hex (README: Share format):
| Field | Bytes | Meaning |
|---|---|---|
qs1/qs2/qs3 | — | Format tag and version |
setid | 4 | Random, the same for every share of one split |
k | 1 | Threshold |
x | 1 | Share index (never 0 for shares made by split) |
payload | any | One byte per byte of secret ‖ tag |
token | 16 (qs3) | The share's token G(x) (Token.lean); not interpolated |
checksum | 4 | CRC-32 of setid ‖ k ‖ x ‖ payload (accidents only); for qs2, of 2 ‖ setid ‖ k ‖ x ‖ payload; for qs3, of 3 ‖ setid ‖ k ‖ x ‖ payload ‖ token |
The versions differ in what protects the secret: qs1 carries a 4-byte CRC-32 of the secret
(Tag.lean), qs2 a 32-byte AMD tag (Amd.lean), and qs3 the AMD tag over the secret and a
token polynomial, plus a token per share (Token.lean), which catches a forged share with exactly
k shares in every case. split writes qs3; combine reads all three.
decode_encode proves that decoding an encoded share gives back exactly the same record.
The share format version: v1 (qs1, CRC-32 secret tag), v2 (qs2, AMD tag) or v3
(qs3, AMD tag and share tokens).
- v1 : Fmt
qs1: the secret tag is CRC-32. - v2 : Fmt
qs2: the secret tag is the AMD tag over GF(2¹²⁸). - v3 : Fmt
qs3: the AMD tag over the secret and the token polynomial, and a token per share.
Instances For
Equations
- QedShare.Encoding.instReprFmt.repr QedShare.Encoding.Fmt.v1 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "QedShare.Encoding.Fmt.v1")).group prec✝
- QedShare.Encoding.instReprFmt.repr QedShare.Encoding.Fmt.v2 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "QedShare.Encoding.Fmt.v2")).group prec✝
- QedShare.Encoding.instReprFmt.repr QedShare.Encoding.Fmt.v3 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "QedShare.Encoding.Fmt.v3")).group prec✝
Instances For
Equations
Equations
Token bytes in a share: 16 for qs3, none before.
Equations
Instances For
A share together with the metadata written next to it.
- setId : UInt32
Random identifier shared by all shares of one split.
- k : UInt8
The threshold of the split.
- share : Shamir.Share
The share itself.
- fmt : Fmt
The format version.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Why a share string could not be decoded.
- badLayout : DecodeError
Not six
--separated fields (seven forqs3). - unknownTag : DecodeError
The first field is not
qs1,qs2orqs3. - badField : DecodeError
A field is not valid hex, or has the wrong length.
- badChecksum : DecodeError
The checksum does not match: the share was mistyped or damaged.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
The format tag: qs1, qs2 or qs3.
Equations
- QedShare.Encoding.tag QedShare.Encoding.Fmt.v1 = ['q', 's', '1']
- QedShare.Encoding.tag QedShare.Encoding.Fmt.v2 = ['q', 's', '2']
- QedShare.Encoding.tag QedShare.Encoding.Fmt.v3 = ['q', 's', '3']
Instances For
Split a character list at every -.
Equations
Instances For
Tail-recursive splitDash for compiled code #
splitDash recurses once per character, which overflows the stack on very long shares. The loop
below is proved equal to it (splitDash_eq_splitDashTR, @[csimp]), so the compiler uses the
loop and the proofs keep using splitDash.
Loop for splitDashTR: acc holds the finished fields, cur the current field reversed.
Equations
Instances For
The loop splitDashAux computes splitDash, after the fields already collected.
The checksum of a record.
Instances For
The token field with its leading - (only in qs3).
Equations
- QedShare.Encoding.tokenField r = match r.fmt with | QedShare.Encoding.Fmt.v3 => '-' :: QedShare.Hex.encode (List.map (fun (x : QedShare.GF256) => x.val) r.token) | x => []
Instances For
Encode a record as characters.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Encode a record as a share string qs1-…, qs2-… or qs3-….
Equations
Instances For
Decode the fields after the tag (tk is the token field, empty before qs3).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decode characters into a record, checking layout, tag, field lengths and checksum.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decode a share string. (The CLI trims surrounding whitespace before calling this.)
Equations
Instances For
Round trip #
Reading back the 4 bytes of a 32-bit word gives the word.
Decoding an encoded share gives back exactly the same record (whose token has the length its
format needs: 16 bytes for qs3, none before).