Documentation

QedShare.Field.GF256

The field GF(2⁸): elements and addition #

An element of GF(2⁸) is a byte, read as a polynomial of degree < 8 over GF(2): bit i is the coefficient of xⁱ. Addition (and subtraction) is XOR.

GF256 is a structure wrapping UInt8, not an abbrev. That way + and * on GF256 can only ever mean field operations, never byte arithmetic mod 256. Lean represents a one-field structure as the bare field at runtime, so this costs nothing.

structure QedShare.GF256 :

An element of GF(2⁸) with the AES reduction polynomial x⁸ + x⁴ + x³ + x + 1 (0x11B).

  • val : UInt8

    The underlying byte. Bit i is the coefficient of xⁱ.

Instances For
    def QedShare.instDecidableEqGF256.decEq (x✝ x✝¹ : GF256) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      theorem QedShare.GF256.ext {a b : GF256} (h : a.val = b.val) :
      a = b

      Two field elements are equal when their bytes are equal.

      theorem QedShare.GF256.ext_iff {a b : GF256} :
      a = b ↔ a.val = b.val

      The additive identity, the zero polynomial.

      Equations
      Instances For

        The multiplicative identity, the constant polynomial 1.

        Equations
        Instances For

          Field addition: coefficient-wise addition mod 2, i.e. XOR of the bytes.

          Equations
          Instances For
            @[instance_reducible]
            Equations
            @[instance_reducible]
            Equations
            @[instance_reducible]

            Subtraction equals addition in characteristic 2.

            Equations
            @[instance_reducible]

            Negation is the identity in characteristic 2.

            Equations
            @[simp]

            The byte of 0 is 0.

            @[simp]

            The byte of 1 is 1.

            @[simp]
            theorem QedShare.GF256.val_add (a b : GF256) :
            (a + b).val = a.val ^^^ b.val

            Addition is XOR of the bytes.

            @[simp]
            theorem QedShare.GF256.val_sub (a b : GF256) :
            (a - b).val = a.val ^^^ b.val

            Subtraction is also XOR of the bytes.

            @[simp]
            theorem QedShare.GF256.neg_eq (a : GF256) :
            -a = a

            Every element is its own negative (characteristic 2).

            theorem QedShare.GF256.sub_eq_add (a b : GF256) :
            a - b = a + b

            Subtraction is addition.

            theorem QedShare.GF256.add_comm (a b : GF256) :
            a + b = b + a

            Addition is commutative.

            theorem QedShare.GF256.add_assoc (a b c : GF256) :
            a + b + c = a + (b + c)

            Addition is associative.

            theorem QedShare.GF256.add_zero (a : GF256) :
            a + 0 = a

            Zero is a right identity for addition.

            theorem QedShare.GF256.zero_add (a : GF256) :
            0 + a = a

            Zero is a left identity for addition.

            theorem QedShare.GF256.add_self (a : GF256) :
            a + a = 0

            Every element is its own additive inverse: a + a = 0.