[FFmpeg-devel] Help: AES GF Multiply
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Mon Jul 30 22:03:27 CEST 2012
On Mon, Jul 30, 2012 at 11:49:51PM +1000, Peter Ross wrote:
> libavutil/aes.c is performing GF multiplication, but its not obvious to
> me how to access this functionality. The math is especially foreign.
Assuming that someone might be interesting, and because I always get
confused myself for a short time, I made a try at explaining it,
maybe it helps someone...
It isn't really that foreign, GF2 really just means/can be thought as polynomial
multiplication with the coefficients being a single bit, and
a special rule, in AES e.g. x^8 + x^4 + x^3 + x^1 + 1 = 0
(that is the 0x11B in line 204 in aes.c).
It only gets really confusing when you store those polynomials
in a normal int and then mix it with some other ints that really
do represent normal numbers...
The
j ^= j + j;
if (j > 255)
j ^= 0x11B;
btw. is the multiplication of the polynomial stored in j by
the polynomial (x + 1) which we have chosen to be basis for
our log/exp functions.
If you take "p" to be the polynomial j represents, then
j ^ (j << 1)
really means
p + p*x = p * (x + 1)
and
j ^ 0x11B;
really is
p + x^8 + x^4 + x^3 + x^1 + 1
More information about the ffmpeg-devel
mailing list