Documentation

QedShareCli.Pipeline

Pure CLI pipeline #

The glue between bytes and share strings, with no IO, so the whole CLI flow can be tested deterministically. QedShareCli.Main only reads input, fetches OS randomness, and writes output.

Error messages never contain secret bytes or share payloads.

The largest secret the CLI accepts: 1 MiB. Shamir sharing is meant for keys and passwords; to protect a large file, encrypt it and split the key. (The core works on lists, so much larger inputs would use a lot of memory.)

Equations
Instances For

    Bytes the payload adds to the secret, for threshold k: 4 for qs1 (CRC-32), 32 for qs2 (AMD key and tag), 32 + 16k for qs3 (also the k coefficients of the token polynomial).

    Equations
    Instances For

      Longest share string recoverSecret accepts: the encoding of a share of a maxSecretBytes secret (qs3 with k = 255: 6 dashes, set id, k, x, token, checksum, and the payload, all hex).

      Equations
      Instances For

        The largest secret a word share can hold: its payload must fit the one-byte length field, so 223 − 16k bytes for qs3 (0 for k ≥ 14), 223 for qs2 and 251 for qs1 (README: Share format).

        Equations
        Instances For

          Longest text accepted as a word share. The longest real one (255-byte payload) has ⌈8·267/11⌉ = 195 words of at most 8 letters; this leaves plenty of room for extra whitespace.

          Equations
          Instances For

            Number of random bytes makeShares needs: k − 1 coefficients per payload byte, plus the 16-byte AMD key (qs2, qs3) and the 16k bytes of the token polynomial (qs3).

            Equations
            Instances For

              The bytes to split for the format, the token polynomial (qs3; empty before), and the random bytes left for the coefficients. The AMD key is the first 16 random bytes; for qs3 the next 16k are the token polynomial.

              Equations
              Instances For

                Check and remove the secret tag (and, for qs3, the tokens of the shares used): some secret, or none if a check fails.

                Equations
                Instances For

                  The (index, token) pairs of some records.

                  Equations
                  Instances For

                    Cut bytes into len coefficient lists of k − 1 field elements each (chunk b is bytes[b·(k−1) … (b+1)·(k−1))). Slicing an Array keeps this linear in the secret length.

                    Equations
                    Instances For

                      Read 4 bytes as a big-endian UInt32 (or 0 if there are fewer than 4).

                      Equations
                      Instances For
                        def QedShare.Cli.makeShares (k n : Nat) (secret random setIdBytes : List UInt8) (form : ShareForm := ShareForm.hex) (fmt : Encoding.Fmt := Encoding.Fmt.v3) :

                        Split secret into share strings with threshold k and n shares, using random (at least randomBytesNeeded k secret.length bytes) and setIdBytes (4 bytes). The CLI always writes qs3; fmt := .v1/.v2 exist only so the tests can make old-format shares.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Why a set of share strings could not be turned back into the secret.

                          Equations
                          Instances For

                            Why a word share could not be read. Positions are shown counting from 1.

                            Equations
                            Instances For

                              true for the hex form: a single run of text containing - (qs3-…, qs2-…, qs1-…). Anything else is read as words.

                              Equations
                              Instances For

                                Read one share, hex or words (label names the file or line in errors).

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  Describe a combine error.

                                  Equations
                                  Instances For

                                    Above this much work (shares² × payload bytes), oddOneOut is skipped: it runs combine once per share, and is only a hint.

                                    Equations
                                    Instances For

                                      After combine found that the shares do not all fit together: if leaving out exactly one share makes the rest fit (and pass the secret tag), return that share's label.

                                      Only tried with k + 2 or more shares, so the rest still has k + 1 shares to check against. If exactly one share is bad, this always finds it (oddOneOut_names_bad, in proofs/): without it, the k + 1 or more genuine shares fit (combine_split); without any other share, the bad one is still among k or more genuine ones and is caught (combine_detects_forgery). With several bad shares it may find none, or (if the cheaters work together and few genuine shares are given) point at the wrong one, so it is reported as a hint, never as proof.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Rebuild the secret from labelled share strings (label names the file or line in errors).

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          Rewrite each share in the given form. Every share is fully checked (checksums included) on the way; nothing is combined, so no secret is ever rebuilt.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            Checking and describing shares #

                                            A byte count in words: 1 byte, 5 bytes.

                                            Equations
                                            Instances For
                                              def QedShare.Cli.verifyMessage (count secretLen : Nat) (weak : Bool) :

                                              What verify prints for count shares that rebuild a secret of secretLen bytes: only those two numbers, never the secret. weak adds the note for old qs1 shares given without an extra share.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For
                                                def QedShare.Cli.verifyReport (inputs : List (String × String)) (secretLen : Nat) :

                                                What verify prints for shares that rebuild a secret of secretLen bytes.

                                                Equations
                                                Instances For

                                                  Check that the shares rebuild a secret, exactly as recoverSecret does, and say so without returning the secret: the message only has the number of shares and the secret's length.

                                                  Equations
                                                  Instances For

                                                    The name of a share format: qs1, qs2 or qs3.

                                                    Equations
                                                    Instances For

                                                      A set id as 8 hex digits, as in the hex form of a share.

                                                      Equations
                                                      Instances For

                                                        What info reads from one share: everything except the payload bytes, of which only the number is kept. All of it is written in the clear in the share, so none of it is secret.

                                                        • The share format.

                                                        • k : UInt8

                                                          The threshold of the split.

                                                        • x : GF256

                                                          The share index.

                                                        • setId : UInt32

                                                          The set id.

                                                        • len : Nat

                                                          The number of payload bytes.

                                                        Instances For

                                                          What info reads from a share record.

                                                          Equations
                                                          Instances For

                                                            What one share says about itself.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              The lines of info for shares already read (label, whether in the hex form, and what was read or the error): one line per share, then whether there are enough of them. The Bool is false if a share could not be read.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For

                                                                Describe each share (info), then say whether there are enough of them. Unlike combine, this keeps going past a share that cannot be read; the Bool is false if there was one. Nothing is combined, so no secret is rebuilt, and whether the shares fit together is not checked (verifyShares does that).

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For

                                                                  From input text to share strings #

                                                                  true if the text is empty or only whitespace: what (trimWs s).isEmpty says, without building the trimmed text (isBlank_eq).

                                                                  Equations
                                                                  Instances For

                                                                    Position of the first byte from i on that is not whitespace (at most n steps).

                                                                    Equations
                                                                    Instances For

                                                                      Position after the last byte before j that is not whitespace (at most n steps).

                                                                      Equations
                                                                      Instances For

                                                                        Loop for lineRanges: start is where the current line begins, i the byte looked at.

                                                                        Equations
                                                                        Instances For

                                                                          The lines of the bytes from start on, as byte ranges (from, to) without the line feeds. (A line feed is a single byte in UTF-8, and no byte of a longer character equals it.)

                                                                          Equations
                                                                          Instances For

                                                                            The size of a UTF-8 byte order mark at the start of the bytes: 3, or 0 if there is none.

                                                                            Equations
                                                                            Instances For

                                                                              Bytes a to b as text. (Empty if they are not UTF-8, which does not happen for a line or the whole of a text.)

                                                                              Equations
                                                                              Instances For

                                                                                The non-blank lines of a text (given as its UTF-8 bytes): line number (counting from 1) and byte range. The lines are not copied out of the text: a share can be megabytes long, and a file can hold many.

                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For

                                                                                  The shares on stdin (given as UTF-8 bytes): one per non-blank line, labelled by line number, as byte ranges (sliceText gives the share).

                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For

                                                                                    The shares on stdin: one per non-blank line, labelled by line number.

                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For
                                                                                      def QedShare.Cli.fileShareRanges (isHex : Nat → Nat → Bool) (isShare : String → Nat → Nat → Bool) (name : String) (bs : ByteArray) :

                                                                                      The shares in the file name with contents bs (UTF-8 bytes), as byte ranges (sliceText gives the share).

                                                                                      A file usually holds one share, and a word share may be wrapped over several lines, so the whole file is one share when it has a single non-blank line or reads as one share. A file may also hold several shares, one per line (what split prints): that is how it is read when every line looks like a hex share, or when the file as a whole is not a share but at least one of its lines is. Then each share is labelled with its line number.

                                                                                      isHex a b says whether bytes a to b look like a hex share: looksHex on the trimmed text (fileShares), or the executable's looksHexFast, which is the same (looksHexFast_eq). isShare label a b says whether they read as a share: decodeShare succeeds on them (fileShares), or the executable's reader does, which is the same (decodeBytes_eq).

                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For

                                                                                        The shares in the file name with contents text (see fileShareRanges).

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For