Galois Field Arithmetic

James S. Plank
Here's the resource I use, which is a technical report I wrote in 2013 with Kevin Greenan and Ethan Miller. It is a very thorough paper, with many, many implementations of Galois Field arithmetic:

James S. Plank, Kevin M. Greenan and Ethan L. Miller, "A Complete Treatment of Software Implementations of Finite Field Arithmetic for Erasure Coding Applications," Technical Report UT-CS-13-717 EECS Department, University of Tennessee, October, 2013.


I don't go in detail here -- please use the technical report above. This is simply a listing of the topics that I cover with relevant pictures that I use in class.
  1. Review Reed-Solomon coding, and why you need finite field arithmetic.

    RS.jpg

    Go over why multiplying a region by an number is such an important operation.

  2. Four representations. Give a table of: 0, 1, 2, 5, 7, 10, 11, 13 in GF(2^4). Write it on the board and leave it there.

  3. GF = polynomial addition & multiplication with coefficients in GF(2). Do the following examples:

  4. Irreducible polynomial. Go over what modulo means with polynomials. Example with 10 * 13 (should equal 11).

    IP-Table.jpg

  5. SHIFT for GF 2^8 (pp = 0x1d) -- Carry-free multiplication followed by reduction. Show it incrementally with an example in Shift-Example.odp.

    In case you need it, the program is m8.cpp

    #include <iostream>
    using namespace std;
    
    int main()
    {
      int a, b, p, i;
      string s1, s2;
    
      cin >> s1 >> s2;
    
      if (sscanf(s1.c_str(), "0x%x", &a) == 0) sscanf(s1.c_str(), "%d", &a);
      if (sscanf(s2.c_str(), "0x%x", &b) == 0) sscanf(s2.c_str(), "%d", &b);
    
      p = 0;
      for (i = 0; i < 8; i++) {        // Carry free multiplication
        if (a & (1 << i)) p ^= (b << i);
      }
      for (i = 14; i >= 8; i--) {      // Reduction
        if (p & (1 << i)) p ^= (0x11d << (i-8));
      }
      printf("%d 0x%x\n", p, p);
      return 0;
    }
    

    The picture from the TR (and the odp above) is in: Shift.jpg.

  6. When Intel gives you a Carry-Free Multiplication Instruction:

    Start with multiplying 10000xxx + 1234yyy in decimal. What do you know about the first four digits of the product? Show some ezamples (they will be 1234zzz or 1235zzz).

    Now show how this works in GF(2^64):

    UNIX> sh CFM.sh
    
    I have the whole thing below:

    The irreducible polynomial for GF(2^64) is the following:
    
    100000000000000c5
    
    Now, suppose that I multiply two numbers in GF(2^64) and end up with the following before reduction:
    
    55225eb7fc0f37b1bdea1a6a8d61cdac
    
    If I multiply the first 64 bits (55225eb7fc0f37b1) by the IP, I get: 
    
    10000000000000000 * 55225eb7fc0f37b1 = 55225eb7fc0f37b10000000000000000
                   c5 * 55225eb7fc0f37b1 = 000000000000003ed813d2690865ddb5
    -----------------------------------------------------------------------
    100000000000000c5 * 55225eb7fc0f37b1 = 55225eb7fc0f378fd813d2690865ddb5
                             These bits:   ^^^^^^^^^^^^^ are the same as the product's!
         When we xor this ith the product: 55225eb7fc0f37b1bdea1a6a8d61cdac
    ----------------------------------------------------- ------------------
    We have zero'd 14*4=56 bits!           000000000000003e65f9c80385041019
    
    Therefore, we can do the entire reduction with two CFM's and two XOR's!
    

  7. Tables.

  8. Discrete Logarithms: Logs.jpg

    You should still have your table leftover from the beginning, so use it to create the log table.

    Again, go over 10 * 13 = 11
    Two tables.
    Big zero.

  9. Split table. Go over WRT GF(2^8) -- use m8.cpp to multiply 230 (0xe6) and 178 (0xf8):
    UNIX> echo 0xe6 0xf8 | a.out
    117 0x75
    UNIX> echo 0xe0 0xf8 | a.out
    95 0x5f
    UNIX> echo 0x06 0xf8 | a.out
    42 0x2a
    UNIX> 
    
    Do the bit arithmetic: 0x5f ^ 0x2a = 0x75 = 117.

    Discuss implications on tables -- now you can do GF(2^8) with two 16-element tables.

    Also talk about ramifications with GF(2^32) and (2^64). Show Split.jpg

  10. (SKIP unless you're on your game and have time): Bytwo_p -- go over equation 4, and then how it renders to code with Fig 11. You can do loop unrolling.

  11. (SKIP unless you're on your game and have time): Bytwo_b -- go over equation 6, and how it render to code with figure 12.

  12. (SKIP. It's simply too hard, fascinating as it is): Group

  13. Composite fields -- go through Composite-Field.odp