Documentation

QedShare.Encoding.Amd

AMD tag over GF(2¹²⁸) (share format qs2) #

Before splitting, the secret s (L bytes) is extended to

E = s ‖ x ‖ t        (L + 32 bytes)

E is split byte by byte like any secret. After combining, decode recomputes the tag and refuses if it does not match. This is an algebraic manipulation detection (AMD) code (Cramer, Dodis, Fehr, Padró, Wichs, EUROCRYPT 2008). Whatever shares are combined, the rebuilt bytes are a·E + β (each byte times the same a, plus an offset), where a has one term per honest share and (a, β) does not depend on x. The proof in proofs/ shows that, for a ≠ 0, such a change passes the check for at most D + 2 of the 2¹²⁸ keys x, unless it changes nothing. D is odd and gcd(D + 1, 255) = 1; the second condition handles a ≠ 1. a ≠ 0 holds when only one given share is honest, and a = 1 when the forgers know or use at most k − 1 indices. Forgers with k − 1 shares and two honest shares present can make a = 0, which no tag can catch (README: Forged shares).

The secret length L is not stored: it is the payload length minus 32.

The exponent D #

Offsets tried by chooseD: D is the first of s, s + 2, …, s + 8 that works, where s is the smallest odd number ≥ d.

Equations
Instances For

    D works when gcd(D + 1, 255) = 1.

    Equations
    Instances For

      The smallest odd D ≥ d with gcd(D + 1, 255) = 1.

      Equations
      Instances For

        Among any 5 consecutive even numbers, one is coprime to 255 (checked on all residues).

        theorem QedShare.Amd.chooseD_spec (d : Nat) :
        chooseD d % 2 = 1 ∧ (chooseD d + 1).gcd 255 = 1 ∧ d ≤ chooseD d ∧ chooseD d ≤ d + 9

        chooseD d is odd, satisfies gcd(D + 1, 255) = 1, and lies between d and d + 9.

        Blocks and the tag #

        The secret as 16-byte blocks, the last one padded with zeros.

        Equations
        Instances For
          @[irreducible]

          Loop for blocksTR: acc holds the blocks so far.

          Equations
          Instances For

            blocks in linear time (blocks itself drops 16·i bytes for every block i).

            Equations
            Instances For

              A non-empty list: its first block, then the blocks of the rest.

              The loop computes blocks, after the blocks already collected.

              @[csimp]

              The compiler uses the linear loop in place of blocks.

              x^n * acc, with a loop (no deep recursion for large n).

              Equations
              Instances For

                b₁·x + b₂·x² + ⋯ + b_d·x^d by Horner's rule (a loop over the reversed blocks).

                Equations
                Instances For

                  The tag t = x^(D+2) + Σᵢ sᵢ·xⁱ with D = chooseD d, d the number of blocks.

                  Equations
                  Instances For

                    Encode and decode #

                    E = s ‖ x ‖ t: the bytes that get split. x is the random key.

                    Equations
                    Instances For

                      Recompute and check the tag: some s if E = s ‖ x ‖ t with the right t, none otherwise (also when E is shorter than 32 bytes). The comparison is constant-time (sameBytes).

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

                        E is 32 bytes longer than the secret.

                        Round trip: decoding a correctly encoded secret gives back the secret.