Documentation

QedShare.Field.Mul

Multiplication in GF(2⁸) #

Two versions:

mul_eq_mulSpec proves the two agree on all 65 536 input pairs.

Textbook specification #

Multiply a byte by x (i.e. by 0x02) modulo 0x11B, the textbook way (FIPS 197 §4.2.1): shift left, and if a bit fell off the top, XOR in 0x1B. Branches on its input.

Equations
Instances For

    bitSet b i is true when bit i of b is 1.

    Equations
    Instances For

      Textbook GF(2⁸) multiplication of bytes: a · b = Σ_{i : bit i of b is 1} a · xⁱ. aᵢ below is a · xⁱ. Branches on b; specification only.

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

        Textbook GF(2⁸) multiplication (specification only, not constant-time).

        Equations
        Instances For

          Constant-time implementation #

          @[inline]

          mask b is 0xFF if the lowest bit of b is 1 and 0x00 otherwise, without branching (0 - 1 = 0xFF in 8-bit arithmetic).

          Equations
          Instances For
            @[inline]

            Constant-time multiply by x modulo 0x11B: like xtimeSpec, but the conditional XOR of 0x1B is done with a mask built from the top bit.

            Equations
            Instances For

              Constant-time GF(2⁸) multiplication of bytes: the same sum as mulSpecByte, with every if bit then aᵢ else 0 replaced by aᵢ &&& mask (b >>> i). No branches, no tables.

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

                GF(2⁸) multiplication, constant-time. This is the * used everywhere at runtime.

                Equations
                Instances For
                  @[instance_reducible]
                  Equations
                  @[simp]
                  theorem QedShare.GF256.val_mul (a b : GF256) :
                  (a * b).val = mulByte a.val b.val

                  The byte of a product is the constant-time byte multiply mulByte.

                  The constant-time byte multiply equals the textbook byte multiply, for every input.

                  theorem QedShare.GF256.mul_eq_mulSpec (a b : GF256) :
                  a * b = a.mulSpec b

                  The constant-time multiply equals the textbook multiply, for every input.