Inverses in the Field GF(2^8)

来源:互联网 发布:中国银联财务待遇 知乎 编辑:程序博客网 时间:2024/05/16 12:13

Subject: Multiplicative Inverse in GF(2^8)

I have a 4x4 matrix of bytes:

    [B0  B4  B8  B12]

    [B1  B5  B9  B13]

    [B2  B6  B10 B14]

    [B3  B7  B11 B15]

I need to get the multiplicative inverse ofthis matrix in GF(2^8). Is this the same as obtaining the inverse of a4x4 matrix?It is just the same, as long as you do allyour arithmetic in GF(2^8).Your first job is to figure out the map thatcarries bytes into field elements, and vice versa. Map the byte matrixinto a field element matrix, do the inversion, then map the resultback into bytes.

I would like to obtain the multiplicativeinverse of each individual byte in GF(2^8). How do I do this?The field GF(2^8) is usually defined in thefollowing way. Find a polynomial f(x) of degree 8 which isirreducible over GF(2). There are 30 of these to choose from. Then thepolynomials of degree less than 8 over GF(2) form a set of size 2^8."Addition" is the usual addition ofpolynomials (reducing coefficients modulo 2), and "multiplication" isthe usual multiplication of polynomials (reducing coefficients modulo 2),followed by a reduction modulo f(x) (and further coefficientreduction modulo 2) until the result has degree less than 8. Using theseoperations, this set forms a field isomorphic to GF(2^8).

For example, suppose the polynomial were f(x) = x^8 + x^6 + x^5 + x + 1

which is irreducible over GF(2). Then to addx^7 + x^3 + x + 1 and x^4 + 1, 

you would get x^7 + x^4 + x^3 + x +2, and reducing the coefficients modulo 2, you get x^7 + x^4 + x^3+ x, which is the sum.

To multiply these same polynomials, you get:

       x^11 + 2*x^7 + x^5 + x^4 + x^3 + x + 1

-> x^11 + x^5 + x^4 + x^3 + x + 1

 -> x^7 + x^2 + x

which is the product.Now suppose one of the entries in your matrixis the byte 11001001. You have to figure out whether this means  x^7 + x^6 + x^3 + 1(so the bits from left to right are thecoefficients of the powers of x in decreasing order) or x^7 + x^4 + x + 1Then you have todetermine what polynomial f(x) is being used to do the arithmetic. Onceyou know these data, you canconstruct the multiplicative inverses youseek in the following way.First figure out what polynomial a(x) thebyte you want to invert is equivalent to.Given a polynomial a(x) whose inverse youseek, perform the Extended Euclidean Algorithm on a(x) and f(x). If a(x)is not zero, you will obtain polynomials r(x) and s(x) such that

 r(x)*a(x) + s(x)*f(x) = 1 Then reduce this equation modulo f(x): r(x)*a(x) = 1 (mod f(x)) a(x) will be the multiplicative inverse of r(x). 

Example: Inverse of x^4 + 1. 

    x^8 + x^6 + x^5 + x + 1 = (x^4+x^2+x+1)*(x^4+1) + (x^2)

    x^4 + 1 = (x^2)*(x^2) + 1 and, working backwards,

  1= 1*(x^4+1) + (x^2)*(x^2)

      = 1*(x^4+1) + (x^2)*([x^4+x^2+x+1]*[x^4+1]+[x^8+x^6+x^5+x+1])

      = (x^6+x^4+x^3+x^2+1)*(x^4+1) + (x^2)*(x^8+x^6+x^5+x+1)

so, reducing modulo f(x), 

1= (x^6+x^4+x^3+x^2+1)*(x^4+1) (mod f(x))

Thus the multiplicative inverse sought is x^6+ x^4 + x^3 + x^2 + 1. You can remove the need to work backwards bykeeping track of some auxiliary quantities as you perform theEuclidean Algorithm.

    Remainder        Quotient     Auxiliary

    x^8+x^6+x^5+x+1               0

    x^4+1                         1

    x^2              x^4+x^2+x+1  x^4+x^2+x+1

    1                x^2          x^6+x^4+x^3+x^2+1

The Auxiliary column always starts with 0 and1. The Remainder column always starts with f(x) and a(x). To fill inany subsequent row, divide the remainders in the previous tworows, and put the quotient in the Quotient column and the remainder inthe Remainder column. Then multiply the quotient times the Auxiliarynumber in the previous row and add the Auxiliary number in the rowbefore that, putting the result in the Auxiliary column. When theremainder is reduced to 1, the content of the Auxiliary column in thatrow is the inverse of a(x). This is a version of the ExtendedEuclidean Algorithm which you can use to advantage here.  Of course, once you have the inverse, youhave to convert that polynomial back to a byte.

 

	
				
		
原创粉丝点击