{VERSION 5 0 "IBM INTEL NT" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "" 0 1 0 0 0 0 2 0 0 0 0 0 0 0 0 0 }{PSTYLE "Normal " -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 2" -1 4 1 {CSTYLE "" -1 -1 "Times" 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 2 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 3" -1 5 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 1 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Outpu t" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 11 12 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Author" -1 19 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 17 "AES Key Expansion" }} {PARA 19 "" 0 "" {TEXT -1 36 "\251Mike May, S.J., 2002, maymk@slu.edu " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 158 "A second block of material in understanding the AES algorithm is the routine for expansion of a 128 bit key into a collec tion of 44 round keys of 8 bits each." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 138 "The procedure for expanding a key requires the use of th e S-Box used for AES. If that is already loaded the first section can be skipped." }}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 16 "S-Box definition " }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "The S-Box as a lookup table" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6420 "SBoxTable :=table([\"010 00010\" = \"00101100\", \"10101000\" = \"11000010\", \"10110110\" = \" 01001110\", \"00011010\" = \"10100010\", \"00111000\" = \"00000111\", \+ \"11011000\" = \"01100001\", \"00000101\" = \"01101011\", \"00101111\" = \"00010101\", \"00110101\" = \"10010110\", \"00111111\" = \"0111010 1\", \"10000010\" = \"00010011\", \"00000110\" = \"01101111\", \"00100 011\" = \"00100110\", \"10010010\" = \"01001111\", \"11000000\" = \"10 111010\", \"11010000\" = \"01110000\", \"10111010\" = \"11110100\", \" 10010111\" = \"10001000\", \"10101011\" = \"01100010\", \"11100110\" = \"10001110\", \"11101100\" = \"11001110\", \"00011101\" = \"10100100 \", \"00000000\" = \"01100011\", \"10100010\" = \"00111010\", \"110000 01\" = \"01111000\", \"00011001\" = \"11010100\", \"01101110\" = \"100 11111\", \"11101011\" = \"11101001\", \"11101111\" = \"11011111\", \"0 0100111\" = \"11001100\", \"11110100\" = \"10111111\", \"00000001\" = \+ \"01111100\", \"00011011\" = \"10101111\", \"01110111\" = \"11110101\" , \"11010101\" = \"00000011\", \"00010111\" = \"11110000\", \"00111100 \" = \"11101011\", \"10111011\" = \"11101010\", \"01000000\" = \"00001 001\", \"11111011\" = \"00001111\", \"01111001\" = \"10110110\", \"101 10000\" = \"11100111\", \"10100100\" = \"01001001\", \"11000010\" = \" 00100101\", \"11110111\" = \"01101000\", \"00110100\" = \"00011000\", \+ \"01011100\" = \"01001010\", \"00001101\" = \"11010111\", \"00111110\" = \"10110010\", \"01010010\" = \"00000000\", \"01001111\" = \"1000010 0\", \"11000101\" = \"10100110\", \"11110110\" = \"01000010\", \"01110 110\" = \"00111000\", \"00100010\" = \"10010011\", \"00101011\" = \"11 110001\", \"11001000\" = \"11101000\", \"01010110\" = \"10110001\", \" 10101111\" = \"01111001\", \"11011010\" = \"01010111\", \"11111010\" = \"00101101\", \"00101110\" = \"00110001\", \"11011001\" = \"00110101 \", \"11100000\" = \"11100001\", \"01101111\" = \"10101000\", \"111001 00\" = \"01101001\", \"01000101\" = \"01101110\", \"00001000\" = \"001 10000\", \"00000010\" = \"01110111\", \"00011000\" = \"10101101\", \"0 0010100\" = \"11111010\", \"01000001\" = \"10000011\", \"10101110\" = \+ \"11100100\", \"10100110\" = \"00100100\", \"01110000\" = \"01010001\" , \"01010100\" = \"00100000\", \"11100001\" = \"11111000\", \"10111000 \" = \"01101100\", \"00100110\" = \"11110111\", \"10110011\" = \"01101 101\", \"11000100\" = \"00011100\", \"11100111\" = \"10010100\", \"111 01010\" = \"10000111\", \"00001100\" = \"11111110\", \"00110110\" = \" 00000101\", \"01010000\" = \"01010011\", \"11101000\" = \"10011011\", \+ \"10001110\" = \"00011001\", \"11001001\" = \"11011101\", \"11001011\" = \"00011111\", \"10111100\" = \"01100101\", \"00100100\" = \"0011011 0\", \"01011110\" = \"01011000\", \"01001000\" = \"01010010\", \"10000 011\" = \"11101100\", \"11100101\" = \"11011001\", \"11011101\" = \"11 000001\", \"00010000\" = \"11001010\", \"01001101\" = \"11100011\", \" 01111010\" = \"11011010\", \"11010100\" = \"01001000\", \"00101100\" = \"01110001\", \"01011011\" = \"00111001\", \"01011101\" = \"01001100 \", \"10011100\" = \"11011110\", \"01001110\" = \"00101111\", \"110011 10\" = \"10001011\", \"00011111\" = \"11000000\", \"00101010\" = \"111 00101\", \"11110000\" = \"10001100\", \"00110111\" = \"10011010\", \"1 1101101\" = \"01010101\", \"11100011\" = \"00010001\", \"10011011\" = \+ \"00010100\", \"01010001\" = \"11010001\", \"10100101\" = \"00000110\" , \"01011111\" = \"11001111\", \"01100001\" = \"11101111\", \"10001010 \" = \"01111110\", \"00101001\" = \"10100101\", \"00110000\" = \"00000 100\", \"01100111\" = \"10000101\", \"10101100\" = \"10010001\", \"110 10010\" = \"10110101\", \"00100000\" = \"10110111\", \"10000101\" = \" 10010111\", \"01101001\" = \"11111001\", \"00000100\" = \"11110010\", \+ \"10110100\" = \"10001101\", \"01100010\" = \"10101010\", \"01101010\" = \"00000010\", \"01000111\" = \"10100000\", \"00111001\" = \"0001001 0\", \"11010001\" = \"00111110\", \"10010011\" = \"11011100\", \"10011 101\" = \"01011110\", \"01110101\" = \"10011101\", \"11001111\" = \"10 001010\", \"00001011\" = \"00101011\", \"01111111\" = \"11010010\", \" 11010011\" = \"01100110\", \"00011100\" = \"10011100\", \"11111110\" = \"10111011\", \"00011110\" = \"01110010\", \"10000001\" = \"00001100 \", \"10001011\" = \"00111101\", \"00010110\" = \"01000111\", \"100101 00\" = \"00100010\", \"10110101\" = \"11010101\", \"01110011\" = \"100 01111\", \"11011111\" = \"10011110\", \"11111001\" = \"10011001\", \"1 0101010\" = \"10101100\", \"10111101\" = \"01111010\", \"11000111\" = \+ \"11000110\", \"11110010\" = \"10001001\", \"01101000\" = \"01000101\" , \"10010000\" = \"01100000\", \"00110001\" = \"11000111\", \"01011000 \" = \"01101010\", \"10000000\" = \"11001101\", \"10000100\" = \"01011 111\", \"10001111\" = \"01110011\", \"10110111\" = \"10101001\", \"100 11000\" = \"01000110\", \"01111101\" = \"11111111\", \"10000111\" = \" 00010111\", \"11110101\" = \"11100110\", \"11000110\" = \"10110100\", \+ \"10110010\" = \"00110111\", \"01101011\" = \"01111111\", \"01111100\" = \"00010000\", \"10110001\" = \"11001000\", \"00111011\" = \"1110001 0\", \"01000100\" = \"00011011\", \"11111111\" = \"00010110\", \"01100 110\" = \"00110011\", \"01111110\" = \"11110011\", \"10100001\" = \"00 110010\", \"00101101\" = \"11011000\", \"01011010\" = \"10111110\", \" 00111101\" = \"00100111\", \"10101101\" = \"10010101\", \"10000110\" = \"01000100\", \"00010010\" = \"11001001\", \"11110001\" = \"10100001 \", \"01101101\" = \"00111100\", \"10011010\" = \"10111000\", \"010001 10\" = \"01011010\", \"01001001\" = \"00111011\", \"10100000\" = \"111 00000\", \"11101110\" = \"00101000\", \"11111101\" = \"01010100\", \"0 0001111\" = \"01110110\", \"00111010\" = \"10000000\", \"11100010\" = \+ \"10011000\", \"01110001\" = \"10100011\", \"11111000\" = \"01000001\" , \"11000011\" = \"00101110\", \"00010101\" = \"01011001\", \"01010011 \" = \"11101101\", \"01110010\" = \"01000000\", \"10111110\" = \"10101 110\", \"00001110\" = \"10101011\", \"00010001\" = \"10000010\", \"100 01100\" = \"01100100\", \"01001010\" = \"11010110\", \"10101001\" = \" 11010011\", \"11001100\" = \"01001011\", \"10001101\" = \"01011101\", \+ \"11001010\" = \"01110100\", \"10001001\" = \"10100111\", \"10010001\" = \"10000001\", \"11011011\" = \"10111001\", \"00010011\" = \"0111110 1\", \"00100101\" = \"00111111\", \"01100000\" = \"11010000\", \"01001 100\" = \"00101001\", \"10011111\" = \"11011011\", \"11101001\" = \"00 011110\", \"00001001\" = \"00000001\", \"00000111\" = \"11000101\", \" 01011001\" = \"11001011\", \"01111011\" = \"00100001\", \"10001000\" = \"11000100\", \"10111111\" = \"00001000\", \"00101000\" = \"00110100 \", \"10100111\" = \"01011100\", \"10111001\" = \"01010110\", \"000000 11\" = \"01111011\", \"00110010\" = \"00100011\", \"01001011\" = \"101 10011\", \"11110011\" = \"00001101\", \"01010111\" = \"01011011\", \"1 1011100\" = \"10000110\", \"10010101\" = \"00101010\", \"10010110\" = \+ \"10010000\", \"01100011\" = \"11111011\", \"01100101\" = \"01001101\" , \"11010111\" = \"00001110\", \"01110100\" = \"10010010\", \"11001101 \" = \"10111101\", \"01010101\" = \"11111100\", \"01101100\" = \"01010 000\", \"10100011\" = \"00001010\", \"11111100\" = \"10110000\", \"100 11110\" = \"00001011\", \"11011110\" = \"00011101\", \"01111000\" = \" 10111100\", \"10011001\" = \"11101110\", \"01000011\" = \"00011010\", \+ \"11010110\" = \"11110110\", \"00001010\" = \"01100111\", \"00110011\" = \"11000011\", \"01100100\" = \"01000011\", \"00100001\" = \"1111110 1\"]):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 35 "The inverse S-Box as a \+ lookup table" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6425 "InvSBoxTa ble := table([\"00000010\" = \"01101010\", \"01101001\" = \"11100100 \", \"01100000\" = \"10010000\", \"00001111\" = \"11111011\", \"000101 00\" = \"10011011\", \"00100000\" = \"01010100\", \"11101100\" = \"100 00011\", \"10111110\" = \"01011010\", \"01101100\" = \"10111000\", \"1 0001000\" = \"10010111\", \"01011110\" = \"10011101\", \"00100100\" = \+ \"10100110\", \"11111000\" = \"11100001\", \"00111110\" = \"11010001\" , \"11011010\" = \"01111010\", \"11110000\" = \"00010111\", \"10111000 \" = \"10011010\", \"00101001\" = \"01001100\", \"11100101\" = \"00101 010\", \"00000111\" = \"00111000\", \"10110101\" = \"11010010\", \"001 11001\" = \"01011011\", \"11100000\" = \"10100000\", \"11110001\" = \" 00101011\", \"01110011\" = \"10001111\", \"00100111\" = \"00111101\", \+ \"00101000\" = \"11101110\", \"11110110\" = \"11010110\", \"01010011\" = \"01010000\", \"00001011\" = \"10011110\", \"11001001\" = \"0001001 0\", \"00001000\" = \"10111111\", \"00000100\" = \"00110000\", \"00101 010\" = \"10010101\", \"10010000\" = \"10010110\", \"10101100\" = \"10 101010\", \"01100110\" = \"11010011\", \"10111111\" = \"11110100\", \" 01000011\" = \"01100100\", \"00001101\" = \"11110011\", \"10000001\" = \"10010001\", \"01001001\" = \"10100100\", \"01001110\" = \"10110110 \", \"00110000\" = \"00001000\", \"10100101\" = \"00101001\", \"100010 10\" = \"11001111\", \"11110101\" = \"01110111\", \"00000110\" = \"101 00101\", \"10111010\" = \"11000000\", \"10110010\" = \"00111110\", \"1 1110111\" = \"00100110\", \"00111111\" = \"00100101\", \"00000000\" = \+ \"01010010\", \"11001110\" = \"11101100\", \"10101111\" = \"00011011\" , \"00110011\" = \"01100110\", \"01111011\" = \"00000011\", \"10000010 \" = \"00010001\", \"11101010\" = \"10111011\", \"10110001\" = \"01010 110\", \"11000101\" = \"00000111\", \"10000011\" = \"01000001\", \"111 10011\" = \"01111110\", \"10111011\" = \"11111110\", \"01101101\" = \" 10110011\", \"10001111\" = \"01110011\", \"01101010\" = \"01011000\", \+ \"00100010\" = \"10010100\", \"01000101\" = \"01101000\", \"00000001\" = \"00001001\", \"00010010\" = \"00111001\", \"01010000\" = \"0110110 0\", \"10011101\" = \"01110101\", \"10101011\" = \"00001110\", \"10000 110\" = \"11011100\", \"00001110\" = \"11010111\", \"11011000\" = \"00 101101\", \"01011111\" = \"10000100\", \"10001011\" = \"11001110\", \" 01100101\" = \"10111100\", \"10111101\" = \"11001101\", \"10010011\" = \"00100010\", \"10000100\" = \"01001111\", \"11101111\" = \"01100001 \", \"11001000\" = \"10110001\", \"11110100\" = \"10111010\", \"001011 10\" = \"11000011\", \"10010010\" = \"01110100\", \"00110010\" = \"101 00001\", \"10011100\" = \"00011100\", \"00100011\" = \"00110010\", \"0 0101011\" = \"00001011\", \"01010100\" = \"11111101\", \"11011001\" = \+ \"11100101\", \"10101001\" = \"10110111\", \"01110101\" = \"00111111\" , \"11011100\" = \"10010011\", \"10011011\" = \"11101000\", \"01010101 \" = \"11101101\", \"11000110\" = \"11000111\", \"01100010\" = \"10101 011\", \"10101101\" = \"00011000\", \"11100100\" = \"10101110\", \"010 00111\" = \"00010110\", \"00010101\" = \"00101111\", \"11010110\" = \" 01001010\", \"10011110\" = \"11011111\", \"01001010\" = \"01011100\", \+ \"10100110\" = \"11000101\", \"01111000\" = \"11000001\", \"01111101\" = \"00010011\", \"00010111\" = \"10000111\", \"10000101\" = \"0110011 1\", \"00100110\" = \"00100011\", \"01111100\" = \"00000001\", \"11011 111\" = \"11101111\", \"00011111\" = \"11001011\", \"11001011\" = \"01 011001\", \"01001100\" = \"01011101\", \"01110010\" = \"00011110\", \" 01101011\" = \"00000101\", \"01000010\" = \"11110110\", \"10011010\" = \"00110111\", \"11111110\" = \"00001100\", \"00011010\" = \"01000011 \", \"10110110\" = \"01111001\", \"10100001\" = \"11110001\", \"111000 11\" = \"01001101\", \"01100011\" = \"00000000\", \"11001100\" = \"001 00111\", \"11010000\" = \"01100000\", \"01110110\" = \"00001111\", \"0 0111010\" = \"10100010\", \"10100111\" = \"10001001\", \"01001111\" = \+ \"10010010\", \"11000001\" = \"11011101\", \"11110010\" = \"00000100\" , \"10100010\" = \"00011010\", \"01011000\" = \"01011110\", \"10110100 \" = \"11000110\", \"01100001\" = \"11011000\", \"01010111\" = \"11011 010\", \"11101001\" = \"11101011\", \"00011000\" = \"00110100\", \"010 11010\" = \"01000110\", \"11101000\" = \"11001000\", \"10101010\" = \" 01100010\", \"00110100\" = \"00101000\", \"00010000\" = \"01111100\", \+ \"01111110\" = \"10001010\", \"00100101\" = \"11000010\", \"11111011\" = \"01100011\", \"11100001\" = \"11100000\", \"01101000\" = \"1111011 1\", \"11111010\" = \"00010100\", \"10010001\" = \"10101100\", \"11000 100\" = \"10001000\", \"10001101\" = \"10110100\", \"00011001\" = \"10 001110\", \"01011100\" = \"10100111\", \"01010010\" = \"01001000\", \" 10011000\" = \"11100010\", \"10100000\" = \"01000111\", \"01000000\" = \"01110010\", \"00111011\" = \"01001001\", \"10001001\" = \"11110010 \", \"01111010\" = \"10111101\", \"01101111\" = \"00000110\", \"111110 01\" = \"01101001\", \"00101111\" = \"01001110\", \"11101110\" = \"100 11001\", \"11010101\" = \"10110101\", \"11001010\" = \"00010000\", \"1 0100011\" = \"01110001\", \"10101110\" = \"10111110\", \"01001011\" = \+ \"11001100\", \"00011011\" = \"01000100\", \"11101011\" = \"00111100\" , \"10000111\" = \"11101010\", \"11000011\" = \"00110011\", \"00101100 \" = \"01000010\", \"10010111\" = \"10000101\", \"01010110\" = \"10111 001\", \"01110001\" = \"00101100\", \"11011110\" = \"10011100\", \"000 00011\" = \"11010101\", \"10110000\" = \"11111100\", \"01110100\" = \" 11001010\", \"11011011\" = \"10011111\", \"11000000\" = \"00011111\", \+ \"10010110\" = \"00110101\", \"00001100\" = \"10000001\", \"00010011\" = \"10000010\", \"01011101\" = \"10001101\", \"10001100\" = \"1111000 0\", \"00110101\" = \"11011001\", \"00111000\" = \"01110110\", \"01000 100\" = \"10000110\", \"10010100\" = \"11100111\", \"11010111\" = \"00 001101\", \"10110111\" = \"00100000\", \"00111100\" = \"01101101\", \" 01000001\" = \"11111000\", \"11111101\" = \"00100001\", \"00011101\" = \"11011110\", \"10101000\" = \"01101111\", \"01011001\" = \"00010101 \", \"01111001\" = \"10101111\", \"11111111\" = \"01111101\", \"101100 11\" = \"01001011\", \"01110000\" = \"11010000\", \"10111001\" = \"110 11011\", \"00110001\" = \"00101110\", \"01010001\" = \"01110000\", \"0 0011100\" = \"11000100\", \"11000010\" = \"10101000\", \"11010100\" = \+ \"00011001\", \"00010001\" = \"11100011\", \"01110111\" = \"00000010\" , \"11101101\" = \"01010011\", \"11001101\" = \"10000000\", \"01100100 \" = \"10001100\", \"11000111\" = \"00110001\", \"00010110\" = \"11111 111\", \"10000000\" = \"00111010\", \"11100110\" = \"11110101\", \"100 11001\" = \"11111001\", \"00001001\" = \"01000000\", \"01000110\" = \" 10011000\", \"11010001\" = \"01010001\", \"10011111\" = \"01101110\", \+ \"00101101\" = \"11111010\", \"00001010\" = \"10100011\", \"11111100\" = \"01010101\", \"10111100\" = \"01111000\", \"00100001\" = \"0111101 1\", \"10100100\" = \"00011101\", \"11100010\" = \"00111011\", \"11011 101\" = \"11001001\", \"00110110\" = \"00100100\", \"00111101\" = \"10 001011\", \"11001111\" = \"01011111\", \"10001110\" = \"11100110\", \" 11010011\" = \"10101001\", \"11100111\" = \"10110000\", \"00000101\" = \"00110110\", \"11010010\" = \"01111111\", \"00011110\" = \"11101001 \", \"01100111\" = \"00001010\", \"10010101\" = \"10101101\", \"010011 01\" = \"01100101\", \"01111111\" = \"01101011\", \"00110111\" = \"101 10010\", \"01001000\" = \"11010100\", \"01101110\" = \"01000101\", \"0 1011011\" = \"01010111\"]):" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 19 " Preparing some keys" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 251 "To look at key expansion, it is most convenient to think of an AES key as a list of 16 strings, each of which is an 8 bit byte. We produce two keys f or test purposes. The first one starts with a nice hex string. The s econd one is randomly generated" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 265 "testKeyHex := \"0123456789ABCDEF0123456789ABCDEF\";\ntestKeyL ist := [seq(substring(testKeyHex,i*2-1..i*2),i=1..16)];\nhexTo8Bits := hexPair -> substring(convert(convert(\n convert(hexPair,decimal,he x)+256,binary),string),2..9):\ntestKey := map(hexTo8Bits,testKeyList); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%+testKeyHexGQA0123456789ABCDEF01 23456789ABCDEF6\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%,testKeyListG72 Q#016\"Q#23F'Q#45F'Q#67F'Q#89F'Q#ABF'Q#CDF'Q#EFF'F&F(F)F*F+F,F-F." }} {PARA 12 "" 1 "" {XPPMATH 20 "6#>%(testKeyG72Q)000000016\"Q)00100011F' Q)01000101F'Q)01100111F'Q)10001001F'Q)10101011F'Q)11001101F'Q)11101111 F'F&F(F)F*F+F,F-F." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 175 "intT oBits := intValue -> \n substring(convert(convert(intValue+256,binary ), string), 2..9):\nrandKeyInt := [seq(rand(0..255)(),i=1..16)];\nrand Key := map(intToBits, randKeyInt);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# >%+randKeyIntG72\"#*)\"$]\"\"#L\"$.#\"\"!\"$Q\"\"\"&\"#S\"#(*F(\"#:\"$ (=\"$`\"\"#[\"$a\"\"$l\"" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%(randKey G72Q)010110016\"Q)10010110F'Q)00100001F'Q)11001011F'Q)00000000F'Q)1000 1010F'Q)00000101F'Q)00101000F'Q)01100001F'F)Q)00001111F'Q)10111011F'Q) 10011001F'Q)00110000F'Q)10011010F'Q)10100101F'" }}}}{SECT 0 {PARA 4 " " 0 "" {TEXT -1 26 "Step by step key expansion" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 221 "In each round of the key expansion we need the byte r epresentation of (alpha)^(i-1) in the finite field GF(258) with the sp ecified generating polynomial. This is added in as a fudge factor eac h round of the expanded key." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 354 "genPoly := alpha^8 + alpha^4 + alpha^3 + alpha + 1:\nroundFudge := int -> Rem(alpha^(int-1),genPoly,alpha) mod 2:\npolyToInt := poly \+ -> subs(alpha=2, poly):\nintToBits := intValue -> \n substring(conv ert(convert(intValue+256, binary), string), 2..9):\npolyToBits := poly -> intToBits(polyToInt( poly)):\nroundFudgeWord := int -> polyToBits( roundFudge(int)):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 163 "For the ver sion of AES we are using there are 10 rounds. (The number of rounds d epends on both the size used for the key and the size used for the mes sage block.)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 70 "for i from \+ 1 to 10 do\nprint(i,roundFudge(i),roundFudgeWord(i)) end do;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"\"\"F#Q)000000016\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"\"#%&alphaGQ)000000106\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"\"$*$)%&alphaG\"\"#\"\"\"Q)000001006\"" }}{PARA 11 " " 1 "" {XPPMATH 20 "6%\"\"%*$)%&alphaG\"\"$\"\"\"Q)000010006\"" }} {PARA 11 "" 1 "" {XPPMATH 20 "6%\"\"&*$)%&alphaG\"\"%\"\"\"Q)000100006 \"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"\"'*$)%&alphaG\"\"&\"\"\"Q)001 000006\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"\"(*$)%&alphaG\"\"'\"\" \"Q)010000006\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"\")*$)%&alphaG\" \"(\"\"\"Q)100000006\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"\"*,**$)%& alphaG\"\"%\"\"\"F)*$)F'\"\"$F)F)F'F)F)F)Q)000110116\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%\"#5,**$)%&alphaG\"\"&\"\"\"F)*$)F'\"\"%F)F)*$)F' \"\"#F)F)F'F)Q)001101106\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 69 "We \+ also need to be able to XOR 8 bit string representations of bytes." }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 269 "XOR := (a,b) -> if (a=b) t hen \"0\" else \"1\" fi:\nxorNbits := proc(a,b,N) \n local aString, b String:\n aString := convert(a,string):\n bString := convert(b,strin g): \n cat(seq(XOR(substring(aString,i), substring(bString,i)),i=1..N )):\nend:\nxor8 := (a,b) -> xorNbits(a,b,8):" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 207 "We are ready to start making the round keys. Since we have 10 rounds we need 11 keys with a key being 16 bytes. We arrange the expanded key as a 4 by 44 matrix with the original key in the fir st 4 columns." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 138 "keyExpand ed := matrix(4,44):\nfor j from 1 to 4 do\n for i from 1 to 4 do\n \+ keyExpanded[i,j] := testKey[(j-1)*4+i];\n end do;\nend do;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 440 "Now we recursively define the rou nd keys. The ith round defines columns 4*i+1 through 4*i+4. Each col umn is defined by a process that looks at the previous column and the \+ one 4 columns back. Three of the four columns in a round are created \+ by simply XORing the two columns that it depends on. The first column in a round twists one of the columns first, does an S-Box lookup, and adds in a fudge factor based on the number of the round." }}{PARA 0 " " 0 "" {TEXT -1 167 "[Recall that the book's description of AES number s the columns from 0 and we are numbering them from 1. We want the sp ecial rule used for the first column in a round." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 661 "for i from 1 to 10 do\n fudgeWord := round FudgeWord(i);\n keyExpanded[1,4*i+1] := \n xor8(keyExpanded[1,4 *i-3],SBoxTable[keyExpanded[2,4*i]]);\n keyExpanded[2,4*i+1] := \n \+ xor8(keyExpanded[2,4*i-3],SBoxTable[keyExpanded[3,4*i]]);\n key Expanded[3,4*i+1] := \n xor8(keyExpanded[3,4*i-3],SBoxTable[keyE xpanded[4,4*i]]);\n keyExpanded[4,4*i+1] := \n xor8(keyExpande d[4,4*i-3],SBoxTable[keyExpanded[1,4*i]]);\n keyExpanded[1,4*i+1] := xor8(keyExpanded[1,4*i+1],fudgeWord);\n for j from 2 to 4 do\n \+ for k from 1 to 4 do\n keyExpanded[k,4*i+j] :=xor8(keyExpande d[k,4*i+j-4],keyExpanded[k,4*i+j-1]):\n end do:\n end do:\nend \+ do:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 67 "We can convert the expande d key to integer values for easy viewing." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 89 "bitToInt := bitWord -> convert(parse(bitWord),decim al,binary):\nmap(bitToInt,keyExpanded);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#-%'matrixG6#7&7N\"\"\"\"$P\"F(F)\"#)*\"$N#\"$M#\"#**\"#E\"$T#\"# F\"$?\"\"#@\"$G#\"$b#\"$N\"\"#c\"$?#\"#N\"$k\"\"#x\"$X\"\"$y\"\"#A\"$& >\"##)\"$C#\"$Y#\"$p\"\"$^#F0\"$P#\"$A\"\"$H\"\"$a\"\"$>\"\"#()\"$9#\" #w\"#f\"$O\"\"#%*\"#=\"#T7NF8\"$r\"F8FR\"$e\"\"#`F=\"$*=\"\"!FTF8FS\"# u\"$F\"\"##*\"$%>\"#$*\"#M\"$E\"\"$)=FN\"$C\"\"\"#\"$!>\"#&)FP\"#V\"$ \\\"\"$*>\"$Q#\"$(>\"#!)\"#&*\"$x\"\"$;\"\"#O\"#5\"$(=\"$2#F+\"#LFGF\\ oF[o7N\"#p\"$0#F\\pF]pFGFIFO\"$B#\"$)>F;\"$J\"FY\"$,#\"#))\"$>#F5\"$4# F)F?\"$8#\"$W\"\"#D\"#vFS\"$%=\"$h\"F,Feo\"$@#Fin\"$]\"\"$E#\"$H#\"$` \"\"#:FD\"$7\"\"$L#\"$I#\"#6F^p\"#a\"$3#Fcp7N\"$.\"\"$R#FhqFiq\"$#>\"# Z\"#s\"$n\"FL\"#?FYFCF5\"$Z\"Fio\"#_Ffp\"\"$\"$/#\"$[#\"$<#\"$=#F=F`oF S\"#oF?FhnF7\"$_\"\"$-#\"$=\"F)\"# " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 26 "Code for one line commands" }}{EXCHG {PARA 0 " " 0 "" {TEXT -1 188 "We would like to condense the discussion above fo r easier use. The first block of code below has all the preparatory c ode. The second block then does key expansion in a single procedure. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 1059 "genPoly := alpha^8 + \+ alpha^4 + alpha^3 + alpha + 1:\nroundFudge := int -> Rem(alpha^(int-1) ,genPoly,alpha) mod 2:\npolyToInt := poly -> subs(alpha=2, poly):\nint ToBits := intValue -> \n substring(convert(convert(intValue+256, bi nary), string), 2..9):\npolyToBits := poly -> intToBits(polyToInt( pol y)):\nroundFudgeWord := int -> polyToBits(roundFudge(int)):\nXOR := (a ,b) -> if (a=b) then \"0\" else \"1\" fi:\nxorNbits := proc(a,b,N) \n \+ local aString, bString:\n aString := convert(a,string):\n bString : = convert(b,string): \n cat(seq(XOR(substring(aString,i), substring(b String,i)),i=1..N)):\nend:\nxor8 := (a,b) -> xorNbits(a,b,8):\nbitToIn t := bitWord -> convert(parse(bitWord),decimal,binary):\nintToBits := \+ intValue -> \n substring(convert(convert(intValue+256,binary), strin g), 2..9):\nrandKeyGenerator := () -> map(intToBits, \n [seq(rand(0. .255)(),i=1..16)]):\nhexTo8Bits := hexPair -> substring(convert(conver t(\n convert(hexPair,decimal,hex)+256,binary),string),2..9):\nhex32 ToKey:= hexWord ->map(hexTo8Bits,\n [seq(substring(hexWord,2*i-1..2 *i),i=1..16)]):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 977 "keyExpa nder := proc(keyList)\n local keyExpanded, i, j, k, fudgeWord:\n k eyExpanded := matrix(4,44):\n for j from 1 to 4 do\n for i from 1 to 4 do\n keyExpanded[i,j] := keyList[(j-1)*4+i];\n en d do:\n end do:\n for i from 1 to 10 do\n fudgeWord := roundF udgeWord(i);\n keyExpanded[1,4*i+1] := \n xor8(keyExpande d[1,4*i-3],SBoxTable[keyExpanded[2,4*i]]);\n keyExpanded[2,4*i+1] := \n xor8(keyExpanded[2,4*i-3],SBoxTable[keyExpanded[3,4*i] ]);\n keyExpanded[3,4*i+1] := \n xor8(keyExpanded[3,4*i- 3],SBoxTable[keyExpanded[4,4*i]]);\n keyExpanded[4,4*i+1] := \n \+ xor8(keyExpanded[4,4*i-3],SBoxTable[keyExpanded[1,4*i]]);\n \+ keyExpanded[1,4*i+1] := xor8(keyExpanded[1,4*i+1],fudgeWord);\n \+ for j from 2 to 4 do\n for k from 1 to 4 do\n key Expanded[k,4*i+j] \n :=xor8(keyExpanded[k,4*i+j-4],keyEx panded[k,4*i+j-1]):\n end do:\n end do:\n end do:\n k eyExpanded;\nend:" }}}{SECT 0 {PARA 5 "" 0 "" {TEXT -1 0 "" }{TEXT 256 8 "Examples" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "key1 := ( keyExpander(testKey)):\nkey2 := (keyExpander(randKey)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "map(bitToInt,key1);\nmap(bitToInt,k ey2);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#-%'matrixG6#7&7N\"\"\"\"$P\"F (F)\"#)*\"$N#\"$M#\"#**\"#E\"$T#\"#F\"$?\"\"#@\"$G#\"$b#\"$N\"\"#c\"$? #\"#N\"$k\"\"#x\"$X\"\"$y\"\"#A\"$&>\"##)\"$C#\"$Y#\"$p\"\"$^#F0\"$P# \"$A\"\"$H\"\"$a\"\"$>\"\"#()\"$9#\"#w\"#f\"$O\"\"#%*\"#=\"#T7NF8\"$r \"F8FR\"$e\"\"#`F=\"$*=\"\"!FTF8FS\"#u\"$F\"\"##*\"$%>\"#$*\"#M\"$E\" \"$)=FN\"$C\"\"\"#\"$!>\"#&)FP\"#V\"$\\\"\"$*>\"$Q#\"$(>\"#!)\"#&*\"$x \"\"$;\"\"#O\"#5\"$(=\"$2#F+\"#LFGF\\oF[o7N\"#p\"$0#F\\pF]pFGFIFO\"$B# \"$)>F;\"$J\"FY\"$,#\"#))\"$>#F5\"$4#F)F?\"$8#\"$W\"\"#D\"#vFS\"$%=\"$ h\"F,Feo\"$@#Fin\"$]\"\"$E#\"$H#\"$`\"\"#:FD\"$7\"\"$L#\"$I#\"#6F^p\"# a\"$3#Fcp7N\"$.\"\"$R#FhqFiq\"$#>\"#Z\"#s\"$n\"FL\"#?FYFCF5\"$Z\"Fio\" #_Ffp\"\"$\"$/#\"$[#\"$<#\"$=#F=F`oFS\"#oF?FhnF7\"$_\"\"$-#\"$=\"F)\"# \"$*=\"#5\"#g\" $C\"\"$$>\"$.#\"$Z#\"$6\"\"$u\"\"$,\"\"$Y\"\"$c\"\"#]\"#()F;\"$)=\"$U \"\"$<#\"#G\"$:\"\"$`#\"#O\"#c7N\"$]\"\"$Q\"\"#L\"#[\"#YF.\"$L\"\"$\"= \"$N\"\"#N\"$m\"\"#>\"#JF>\"$a\"\"$P\"\"$%=\"$K\"\"#I\"$^\"\"$W#\"$7\" \"$5\"\"$\\#F9\"$*>\"$p\"\"#!)\"$x\"\"$=\"\"$B#\"$V\"FC\"#D\"$)>\"#t\" $b#\"$I#\"#K\"$0\"F8\"$e\"\"$!>F07NFU\"\"&\"#:Fin\"#R\"#M\"#XF9\"#!*F8 \"#&)\"$E#\"#q\"#i\"$2\"FjnF6\"$\">\"$7#F7\"##)\"$P#\"#d\"$+\"\"#@\"$[ #F@\"$l\"F)FfqFcqFGFA\"#^F=FS\"#pFgoF?F1\"$i\"F`q\"$o\"\"#m7NFA\"#S\"$ (=FgqF4\"#8\"$#=Fgn\"$3\"F*F0\"$'>\"#nFgp\"$X#\"#\\\"#z\"$4\"\"$_\"Fdo \"#uFfpF_q\"#A\"$h\"\"$M\"Fcq\"#Z\"$,#FgrFgoF(F]sF_sF_qF^pF_p\"$L#\"#' )\"$w\"FJFjp\"\"$\"$z\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 77 " key3a := randKeyGenerator();\nkey3 := keyExpander(key3a):\nmap(bitToI nt,key3);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&key3aG72Q)101111006\"Q )11000101F'Q)11101011F'Q)10010101F'Q)11100110F'Q)01111110F'Q)11001010F 'Q)10101101F'Q)11111101F'Q)11010101F'Q)00101110F'Q)00000110F'Q)0110000 1F'Q)11110110F'Q)00110111F'Q)11101001F'" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#-%'matrixG6#7&7N\"$)=\"$I#\"$`#\"#(*\"$b#\"#D\"$G#\"$L\"\"$Q\"\" $Z\"\"$>\"\"$U#\"##*\"$2#\"$%=\"#uF,\"#[\"$O\"\"$%>\"$<#\"$L#F+\"$j\" \"$<\"\"$c\"F*\"#%*\"$A\"F)\"#F\"#p\"#v\"$t\"\"$#=\"$V#F;\"$;\"F:\"#\\ \"#l\"#`\"$Z#\"$)>7N\"$(>\"$E\"\"$8#\"$Y#\"#&*\"#L\"$W#\"\"#\"$o\"\"$P \"\"$D\"\"$F\"F/\"#7\"$8\"\"#9\"#()\"#\"*\"#U\"#O\"$l\"\"$a#\"$7#\"$S# \"#sFF\"#)*\"$Y\"\"#;\"$m\"\"$'>\"#')FM\"#'*\"$k\"F3F9\"$K#\"#w\"$!>\" $b\"\"$:\"\"#j\"$H\"7N\"$N#\"$-#\"#Y\"#b\"$X#F^p\"#<\"#QF3\"$0#\"$?#\" $]#\"$[\"\"#*)F/FZ\"$n\"F]o\"$B\"\"\"%\"$5#\"#WFhn\"#$)\"$=\"\"#!*\"#8 F@\"#nF-\"#?F7\"$T#Fio\"$_#FF\"#K\"$+#\"#_\"$I\"\"$M#\"#M\"#AF[q7N\"$ \\\"FE\"\"'F " 0 "" {MPLTEXT 1 0 123 "hexKey := \"0123456789ABCDEFFEDCBA9876543210\":\nkey 4a := hex32ToKey(hexKey);\nkey4 := keyExpander(key4a):\nmap(bitToInt, key4);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&key4aG72Q)000000016\"Q)00 100011F'Q)01000101F'Q)01100111F'Q)10001001F'Q)10101011F'Q)11001101F'Q) 11101111F'Q)11111110F'Q)11011100F'Q)10111010F'Q)10011000F'Q)01110110F' Q)01010100F'Q)00110010F'Q)00010000F'" }}{PARA 12 "" 1 "" {XPPMATH 20 " 6#-%'matrixG6#7&7N\"\"\"\"$P\"\"$a#\"$=\"\"#K\"$p\"\"#()\"#L\"\"%\"$t \"\"$]#\"$>#\"#h\"$W\"\"$1\"\"$x\"\"$K#\"$?\"\"#=\"$j\"\"$7#\"$s\"\"$! >\"#H\"##)F*\"#k\"#$*\"#7\"$U#\"$y\"\"$R#\"$@#\"#Z\"$d\"\"$9\"\"$,#\"$ I#\"$B\"\"\"*\"$(>\"#N\"#))\"#\")7NFP\"$r\"\"$?#\"#%)\"\"!FT\"$>\"FP\" $;\"\"$B#\"$o\"\"$R\"\"#`\"$M#\"#mFKFPFKFfnFinFOFC\"$N\"FO\"$n\"FT\"#W \"$L#\"#I\"$\"=\"$`\"\"$7\"F[oF:Ffn\"$^#\"$#>\"$5#\"#*)\"$i\"\"#&*\"$T \"F " 0 "" {MPLTEXT 1 0 0 " " }}}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 16 "Expanded Example" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 89 "It may be useful to have an expand ed example done. Thus we include the following values." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2597 "testKeyList := [\"01\",\"23\",\"4 5\",\"67\",\"89\",\"AB\",\"CD\",\"EF\",\n \"01\",\"23\",\"4 5\",\"67\",\"89\",\"AB\",\"CD\",\"EF\"]:\ntestKey := [\"00000001\", \" 00100011\", \"01000101\", \"01100111\", \n \"10001001\", \" 10101011\", \"11001101\", \"11101111\", \n \"00000001\", \" 00100011\", \"01000101\", \"01100111\", \n \"10001001\", \" 10101011\", \"11001101\", \"11101111\"]:\nkey1 := matrix([[\"00000001 \", \"10001001\", \"00000001\", \"10001001\",\n \"01100010\", \"1110 1011\", \"11101010\", \"01100011\", \"00011010\",\n \"11110001\", \" 00011011\", \"01111000\", \"00010101\", \"11100100\",\n \"11111111\" , \"10000111\", \"00111000\", \"11011100\", \"00100011\",\n \"101001 00\", \"01001101\", \"10010001\", \"10110010\", \"00010110\",\n \"11 000011\", \"01010010\", \"11100000\", \"11110110\", \"10101001\",\n \+ \"11111011\", \"00011011\", \"11101101\", \"01111010\", \"10000001\", \n \"10011010\", \"01110111\", \"01010111\", \"11010110\", \"0100110 0\",\n \"00111011\", \"10001000\", \"01011110\", \"00010010\", \"001 01001\"],\n [\"00100011\", \"10101011\", \"00100011\", \"10101011\", \"10011110\",\n \"00110101\", \"00010110\", \"10111101\", \"0000000 0\", \"00110101\",\n \"00100011\", \"10011110\", \"01001010\", \"011 11111\", \"01011100\",\n \"11000010\", \"01011101\", \"00100010\", \+ \"01111110\", \"10111100\",\n \"01011110\", \"01111100\", \"00000010 \", \"10111110\", \"01010101\",\n \"00101001\", \"00101011\", \"1001 0101\", \"11000111\", \"11101110\",\n \"11000101\", \"01010000\", \" 01011111\", \"10110001\", \"01110100\",\n \"00100100\", \"00001010\" , \"10111011\", \"11001111\", \"11101011\",\n \"00100001\", \"100110 10\", \"01010101\", \"10111110\"],\n [\"01000101\", \"11001101\", \" 01000101\", \"11001101\", \"10011010\",\n \"01010111\", \"00010010\" , \"11011111\", \"11000110\", \"10010001\",\n \"10000011\", \"010111 00\", \"11001001\", \"01011000\", \"11011011\",\n \"10000111\", \"11 010001\", \"10001001\", \"01010010\", \"11010101\",\n \"10010000\", \+ \"00011001\", \"01001011\", \"10011110\", \"10111000\",\n \"10100001 \", \"11101010\", \"01110100\", \"11011101\", \"01111100\",\n \"1001 0110\", \"11100010\", \"11100101\", \"10011001\", \"00001111\",\n \" 11101101\", \"01110000\", \"11101001\", \"11100110\", \"00001011\",\n \+ \"11011111\", \"00110110\", \"11010000\", \"11011011\"],\n [\"0110 0111\", \"11101111\", \"01100111\", \"11101111\", \"11000000\",\n \" 00101111\", \"01001000\", \"10100111\", \"00111011\", \"00010100\",\n \+ \"01011100\", \"11111011\", \"10000111\", \"10010011\", \"11001111\" ,\n \"00110100\", \"10010000\", \"00000011\", \"11001100\", \"111110 00\",\n \"11011001\", \"11011010\", \"00010110\", \"11101110\", \"10 011110\",\n \"01000100\", \"01010010\", \"10111100\", \"11011100\", \+ \"10011000\",\n \"11001010\", \"01110110\", \"10001001\", \"00010001 \", \"11011011\",\n \"10101101\", \"01111100\", \"01101101\", \"1011 0110\", \"00011011\",\n \"10011110\", \"11110011\", \"01000101\", \" 01011110\"]]):" }}}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {MARK "0 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }