Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Okay, some stuff to remember here:
- ; The irreducible polynomial for polynomial multiplication is x^8+x^4+x^3+x+1 or 1101 1000 1000 0000 ({b1}{10})
- ; invertible 4term poly:
- ; Fwd: 20 10 10 30
- ; Bwd: E0 90 d0 b0
- ;
- ; RotWord Poly:
- ; 00 00 00 10
- SET PC, AES_Test_MixColumns
- :AES_rcon_lookup
- DAT 0xD8, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08, 0xB1, 0x63, 0xC6, 0x8D ; We can save space by not including the whole 256-byte Rcon lookup table (and I don't want to reverse 256 bytes manually)
- ; *******************************************************************************************************************************************
- ; FlipByte - Flip a byte
- ; Flips the byte AT Y's least/most significant nibbles. f.e. 0xDE ---> 0xED.
- ; For some reason flipping the multiplication tables breaks things, so we're going to flip the bytes BEFORE and AFTER doing the multiplications
- :FlipByte
- SET PUSH, A
- SET PUSH, B
- SET A, [Y]
- SET B, [Y]
- AND A, 0x000F
- AND B, 0x00F0
- SHR B, 4
- SHL A, 4
- SET [Y], A
- BOR [Y], B
- SET B, POP
- SET A, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_xtime - The xtime() function
- ; Multiplies a polynomial in X by x (note the caps).
- :AES_xtime
- SET PUSH, A
- SHR X, 1
- SET A, X
- AND A, 0x0001
- IFE A, 1
- XOR X, 0xB1
- SET A, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; Rijndael_Multiply - Multiplication in GF(256)
- ; Multiplies the number in register A by the the number in register B in GF(256).
- ; The result is returned in C.
- :Rijndael_Multiply
- SET PUSH, I
- SET PUSH, J
- SET PUSH, X
- SET PUSH, Y
- SET PUSH, A
- SET PUSH, B
- SET J, 0
- SET Y, 0
- :Rijndael_Multiply_loop
- IFE A, 0
- SET PC, Rijndael_Multiply_loop_end
- IFE B, 0
- SET PC, Rijndael_Multiply_loop_end
- IFE A, 0
- SET PC, Rijndael_Multiply_loop_end
- IFG Y, 7
- SET PC, Rijndael_Multiply_loop_end
- SET I, B
- AND I, 0x1
- IFG I, 0 ; If the leftmost bit if B is set...
- XOR J, A ; ...add A to the product.
- SHL B, 1 ; Discard x^0
- SET X, A
- JSR AES_xtime ; perform xtimes() on A (whoops I called it xtime on accident, my bad)
- SET A, X
- ADD Y, 1
- SET PC, Rijndael_Multiply_loop
- :Rijndael_Multiply_loop_end
- SET C, J
- SET B, POP
- SET A, POP
- SET Y, POP
- SET X, POP
- SET J, POP
- SET I, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; Rijndael_Multiply_4term - Multiply four-term polynomials in GF(256)
- ; Multiply the four-term polynomial at X by the four-term polynomial at Y, storing the result at Z.
- :Rijndael_Multiply_4term
- ; Array Offset to MemOffset:
- ; 0 - +3
- ; 1 - +2
- ; 2 - +1
- ; 3 - +0
- SET PUSH, X
- SET PUSH, Y
- SET PUSH, Z
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, I
- SET PUSH, J
- ; d0
- SET A, [X+3]
- SET B, [Y+3]
- JSR Rijndael_Multiply
- SET [Z+3], C
- SET A, [X]
- SET B, [Y+2]
- JSR Rijndael_Multiply
- XOR [Z+3], C
- SET A, [X+1]
- SET B, [Y+1]
- JSR Rijndael_Multiply
- XOR [Z+3], C
- SET A, [X+2]
- SET B, [Y]
- JSR Rijndael_Multiply
- XOR [Z+3], C
- ; d1
- SET A, [X+2]
- SET B, [Y+3]
- JSR Rijndael_Multiply
- SET [Z+2], C
- SET A, [X+3]
- SET B, [Y+2]
- JSR Rijndael_Multiply
- XOR [Z+2], C
- SET A, [X]
- SET B, [Y+1]
- JSR Rijndael_Multiply
- XOR [Z+2], C
- SET A, [X+1]
- SET B, [Y]
- JSR Rijndael_Multiply
- XOR [Z+2], C
- ; d2
- SET A, [X+1]
- SET B, [Y+3]
- JSR Rijndael_Multiply
- SET [Z+1], C
- SET A, [X+2]
- SET B, [Y+2]
- JSR Rijndael_Multiply
- XOR [Z+1], C
- SET A, [X+3]
- SET B, [Y+1]
- JSR Rijndael_Multiply
- XOR [Z+1], C
- SET A, [X]
- SET B, [Y]
- JSR Rijndael_Multiply
- XOR [Z+1], C
- ; d3
- SET A, [X]
- SET B, [Y+3]
- JSR Rijndael_Multiply
- SET [Z], C
- SET A, [X+1]
- SET B, [Y+2]
- JSR Rijndael_Multiply
- XOR [Z], C
- SET A, [X+2]
- SET B, [Y+1]
- JSR Rijndael_Multiply
- XOR [Z], C
- SET A, [X+3]
- SET B, [Y]
- JSR Rijndael_Multiply
- XOR [Z], C
- SET J, POP
- SET I, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET Z, POP
- SET Y, POP
- SET X, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; Rijndael_Add_4term - Add four-term polynomials in GF(256)
- ; Add the four-term polynomial at X to the four-term polynomial at Y, storing the result at Z.
- :Rijndael_Add_4term
- SET [Z], [X]
- XOR [Z], [Y]
- SET [Z+1], [X+1]
- XOR [Z+1], [Y+1]
- SET [Z+2], [X+2]
- XOR [Z+2], [Y+2]
- SET [Z+3], [X+3]
- XOR [Z+3], [Y+3]
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_Sbox_lookup - S-box Lookup
- ; Transforms the number at X according to Rijndael's S-box.
- :AES_Sbox_lookup
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET A, [X]
- SET B, [X]
- AND A, 0x00F0 ; less significant
- AND B, 0x000F ; most signficant
- SHR A, 4
- SET C, B
- MUL C, 16
- ADD C, A
- ADD C, AES_sbox_table
- SET [X], [C]
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_Inv_Sbox_lookup - Inverse S-box Lookup
- ; Transforms the number at X according to Rijndael's Inverted S-box.
- :AES_Inv_Sbox_lookup
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET A, [X]
- SET B, [X]
- AND A, 0x00F0 ; less significant
- AND B, 0x000F ; most signficant
- SHR A, 4
- SET C, B
- MUL C, 16
- ADD C, A
- ADD C, AES_inv_sbox_table
- SET [X], [C]
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_ShiftRow - Shift a single row
- ; Shifts the row X in the state pointed to by Z by Y. Can be signed.
- :AES_ShiftRow
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, I
- SET PUSH, J
- SET J, X
- MUL J, 4
- ADD J, Z
- IFU Y, 0
- SET PC, AES_ShiftRow_Negative
- MOD Y, 4
- :AES_ShiftRow_positive_loop
- IFE Y, 0
- SET PC, AES_ShiftRow_End
- JSR AES_ShiftRow_doShift
- SUB Y, 1
- SET PC, AES_ShiftRow_positive_loop
- :AES_ShiftRow_Negative
- MDI Y, -4
- :AES_ShiftRow_negative_loop
- IFE Y, 0
- SET PC, AES_ShiftRow_End
- JSR AES_ShiftRow_doShift
- ADD Y, 1
- SET PC, AES_ShiftRow_negative_loop
- :AES_ShiftRow_doShift
- SET A, [J] ; e3
- SET B, [J+1] ; e2
- SET C, [J+2] ; e1
- SET I, [J+3] ; e0
- SET [J+3], A
- SET [J], B
- SET [J+1], C
- SET [J+2], I
- SET PC, POP
- :AES_ShiftRow_End
- SET J, POP
- SET I, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_ShiftRows - Rijndael's ShiftRows() step
- ; Shifts the rows pointed to by Z.
- :AES_ShiftRows
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, X
- ; r1:
- ; c0: [Z+11]
- ; c1: [Z+10]
- ; c2: [Z+9]
- ; c3: [Z+8]
- SET A, [Z+11]
- SET B, [Z+10]
- SET C, [Z+9]
- SET X, [Z+8]
- SET [Z+10], A
- SET [Z+9], B
- SET [Z+8], C
- SET [Z+11], X
- ; r2:
- ; c0: [Z+7]
- ; c1: [Z+6]
- ; c2: [Z+5]
- ; c3: [Z+4]
- SET A, [Z+7]
- SET B, [Z+6]
- SET C, [Z+5]
- SET X, [Z+4]
- SET [Z+5], A ; c0 goes to c2
- SET [Z+4], B ; c1 goes to c3
- SET [Z+7], C ; c2 goes to c0
- SET [Z+6], X ; c3 goes to c1
- ; r3:
- ; c0: [Z+3]
- ; c1: [Z+2]
- ; c2: [Z+1]
- ; c3: [Z]
- SET A, [Z+3]
- SET B, [Z+2]
- SET C, [Z+1]
- SET X, [Z]
- SET [Z], A
- SET [Z+3], B
- SET [Z+2], C
- SET [Z+1], X
- SET X, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_InvShiftRows - Rijndael's Inverted ShiftRows() step
- ; Shifts the rows pointed to by Z.
- :AES_InvShiftRows
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, X
- ; r1:
- ; c0: [Z+11]
- ; c1: [Z+10]
- ; c2: [Z+9]
- ; c3: [Z+8]
- SET A, [Z+11]
- SET B, [Z+10]
- SET C, [Z+9]
- SET X, [Z+8]
- SET [Z+8], A
- SET [Z+11], B
- SET [Z+10], C
- SET [Z+9], X
- ; r1:
- ; c0: [Z+7]
- ; c1: [Z+6]
- ; c2: [Z+5]
- ; c3: [Z+4]
- SET A, [Z+7]
- SET B, [Z+6]
- SET C, [Z+5]
- SET X, [Z+4]
- SET [Z+5], A
- SET [Z+4], B
- SET [Z+7], C
- SET [Z+6], X
- ; r1:
- ; c0: [Z+3]
- ; c1: [Z+2]
- ; c2: [Z+1]
- ; c3: [Z]
- SET A, [Z+3]
- SET B, [Z+2]
- SET C, [Z+1]
- SET X, [Z]
- SET [Z], A
- SET [Z+3], B
- SET [Z+2], C
- SET [Z+1], X
- SET X, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; **************************************************************************************************************************
- ; AES_MixColumn - Perform the MixColumns step on one column
- ; Perform the MixColumns step on column X of state Z.
- :AES_MixColumn
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, Y
- SET PUSH, I
- SET PUSH, J
- SET Y, Z
- ADD Y, X
- ; R0: [Y]
- ; R1: [Y+4]
- ; R2: [Y+8]
- ; R3: [Y+12]
- ADD Y, 12
- JSR FlipByte ; little -> big
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SET A, [Y+12]
- SET B, [Y+8]
- SET C, [Y+4]
- SET J, [Y]
- SET [Y+12], [A+Rijndael_multiply_table_2]
- XOR [Y+12], [B+Rijndael_multiply_table_3]
- XOR [Y+12], C
- XOR [Y+12], J
- SET [Y+8], A
- XOR [Y+8], [B+Rijndael_multiply_table_2]
- XOR [Y+8], [C+Rijndael_multiply_table_3]
- XOR [Y+8], J
- SET [Y+4], A
- XOR [Y+4], B
- XOR [Y+4], [C+Rijndael_multiply_table_2]
- XOR [Y+4], [J+Rijndael_multiply_table_3]
- SET [Y], [A+Rijndael_multiply_table_3]
- XOR [Y], B
- XOR [Y], C
- XOR [Y], [J+Rijndael_multiply_table_2]
- ADD Y, 12
- JSR FlipByte ; big -> little
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SET J, POP
- SET I, POP
- SET Y, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; **************************************************************************************************************************
- ; AES_InvMixColumn - Perform the InvMixColumns step on one column
- ; Perform the InvMixColumns step on column X of state Z.
- :AES_InvMixColumn
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, Y
- SET PUSH, I
- SET PUSH, J
- SET Y, Z
- ADD Y, X
- ; R0: [Y]
- ; R1: [Y+4]
- ; R2: [Y+8]
- ; R3: [Y+12]
- ADD Y, 12
- JSR FlipByte ; little -> big
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SET A, [Y+12]
- SET B, [Y+8]
- SET C, [Y+4]
- SET J, [Y]
- SET [Y+12], [A+Rijndael_multiply_table_14]
- XOR [Y+12], [B+Rijndael_multiply_table_11]
- XOR [Y+12], [C+Rijndael_multiply_table_13]
- XOR [Y+12], [J+Rijndael_multiply_table_9]
- SET [Y+8], [A+Rijndael_multiply_table_9]
- XOR [Y+8], [B+Rijndael_multiply_table_14]
- XOR [Y+8], [C+Rijndael_multiply_table_11]
- XOR [Y+8], [J+Rijndael_multiply_table_13]
- SET [Y+4], [A+Rijndael_multiply_table_13]
- XOR [Y+4], [B+Rijndael_multiply_table_9]
- XOR [Y+4], [C+Rijndael_multiply_table_14]
- XOR [Y+4], [J+Rijndael_multiply_table_11]
- SET [Y], [A+Rijndael_multiply_table_11]
- XOR [Y], [B+Rijndael_multiply_table_13]
- XOR [Y], [C+Rijndael_multiply_table_9]
- XOR [Y], [J+Rijndael_multiply_table_14]
- ADD Y, 12
- JSR FlipByte ; big -> little
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SUB Y, 4
- JSR FlipByte
- SET J, POP
- SET I, POP
- SET Y, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; **************************************************************************************************************************
- ; AES_MixColumns - Perform the MixColumns Step
- ; Mixes the columns of state Z.
- :AES_MixColumns
- SET PUSH, X
- SET X, 0
- JSR AES_MixColumn
- SET X, 1
- JSR AES_MixColumn
- SET X, 2
- JSR AES_MixColumn
- SET X, 3
- JSR AES_MixColumn
- SET X, POP
- SET PC, POP
- ; **************************************************************************************************************************
- ; AES_InvMixColumns - Perform the Inverted MixColumns Step
- ; Mixes the columns of state Z.
- :AES_InvMixColumns
- SET PUSH, X
- SET X, 0
- JSR AES_InvMixColumn
- SET X, 1
- JSR AES_InvMixColumn
- SET X, 2
- JSR AES_InvMixColumn
- SET X, 3
- JSR AES_InvMixColumn
- SET X, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_AddRoundKey - Rijndael's AddRoundKey() step
- ; Adds the key for round X from the keys stored at Y to the state at Z.
- :AES_AddRoundKey
- SET PUSH, I
- SET PUSH, J
- SET I, X
- MUL I, 4
- SET J, Y
- SUB J, I
- XOR [Z+15], [J+15]
- XOR [Z+14], [J+14]
- XOR [Z+13], [J+13]
- XOR [Z+12], [J+12]
- XOR [Z+11], [J+11]
- XOR [Z+10], [J+10]
- XOR [Z+9], [J+9]
- XOR [Z+8], [J+8]
- XOR [Z+7], [J+7]
- XOR [Z+6], [J+6]
- XOR [Z+5], [J+5]
- XOR [Z+4], [J+4]
- XOR [Z+3], [J+3]
- XOR [Z+2], [J+2]
- XOR [Z+1], [J+1]
- XOR [Z], [J]
- SET J, POP
- SET I, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_ExpandKey - AES Key Expansion
- ; Expands a key at X into 176 bytes, storing the round keys at Y.
- :AES_ExpandKey
- SET PUSH, Y
- SET PUSH, I
- SET PUSH, J
- SET I, 1
- ADD Y, 160 ; We start at 175 and work down...
- SET I, 160
- SET [Y], [X]
- SET [Y+1], [X+1]
- SET [Y+2], [X+2]
- SET [Y+3], [X+3]
- SET [Y+4], [X+4]
- SET [Y+5], [X+5]
- SET [Y+6], [X+6]
- SET [Y+7], [X+7]
- SET [Y+8], [X+8]
- SET [Y+9], [X+9]
- SET [Y+10], [X+10]
- SET [Y+11], [X+11]
- SET [Y+12], [X+12]
- SET [Y+13], [X+13]
- SET [Y+14], [X+14]
- SET [Y+15], [X+15]
- :AES_ExpandKey_loop
- IFE I, 0
- SET PC, AES_ExpandKey_loop_end
- ; Inital 4:
- JSR AES_ExpandKey_Perform_Assign
- JSR AES_ExpandKey_Core
- ADD X, 1
- JSR AES_ExpandKey_Perform_XOR
- SUB Y, 1 ; Make sure we don't overwrite the leading end of the last 4 bytes
- ; Next 12:
- JSR AES_ExpandKey_Perform_Assign
- JSR AES_ExpandKey_Perform_XOR
- SUB Y, 1
- JSR AES_ExpandKey_Perform_Assign
- JSR AES_ExpandKey_Perform_XOR
- SUB Y, 1
- JSR AES_ExpandKey_Perform_Assign
- JSR AES_ExpandKey_Perform_XOR
- SUB Y, 1
- SET PC, AES_ExpandKey_loop
- :AES_ExpandKey_loop_end
- SET J, POP
- SET I, POP
- SET Y, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_ExpandKey_Perform_XOR - Perform the XOR Step
- ; XOR's the current 4 bytes with the 4 bytes 16 bytes before.
- :AES_ExpandKey_Perform_XOR
- XOR [Y+3], [Y+19]
- XOR [Y+2], [Y+18]
- XOR [Y+1], [Y+17]
- XOR [Y], [Y+16]
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_ExpandKey_Perform_Assign - Perform the Assignment Step
- ; Assigns the last 4 bytes to the current four bytes.
- :AES_ExpandKey_Perform_Assign
- SET [Y], [Y+3] ; Y+3
- SUB Y, 1
- SET [Y], [Y+3] ; Y+2
- SUB Y, 1
- SET [Y], [Y+3] ; Y+1
- SUB Y, 1
- SET [Y], [Y+3] ; Y
- SUB I, 4
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES_ExpandKey_Core - AES Key Schedule Core
- ; Performs the Key Schedule Core on the 32-bit word at Y, with the rcon iteration number in X.
- :AES_ExpandKey_Core
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, I
- SET A, [Y+3]
- SET B, [Y+2]
- SET C, [Y+1]
- SET I, [Y]
- ; 3 2 1 0
- ; 2 1 0 3
- SET [Y+3], B
- SET [Y+2], C
- SET [Y+1], I
- SET [Y], A
- JSR AES_Sbox_lookup
- ADD Y, 1
- JSR AES_Sbox_lookup
- ADD Y, 1
- JSR AES_Sbox_lookup
- ADD Y, 1
- JSR AES_Sbox_lookup
- SUB Y, 3
- XOR [Y+3], [X+AES_rcon_lookup]
- SET I, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
- ; *******************************************************************************************************************************************
- ; AES Test Suite:
- ; AES_Test_MixColumns: Runs MixColumns on the input vector 0x54, 0x35, 0x31, 0xBD. This should return 0xCB, 0x1A, 0xD4, 0xE8.
- ; AES_Test_KeyExpand: Tests the key expander on the input vector 0xC3, 0xF4, 0xFC, 0x90, 0x88, 0x51, 0x7F, 0xBA, 0x6A, 0x2D, 0xEA, 0x82, 0x61, 0x51, 0xE7, 0xB2.
- :AES_Test_MixColumns
- SET Y, AES_Test_MixColumns_TestVector
- JSR AES_MixColumns_Linear
- SET PC, AES_Test_Halt
- DAT 0xC0DE ; Look for these when looking at the memory; These tell you where the values start/end. (f.e 0xC0DE 0x0005 0x0005 0x0562 0xFACE 0xC0DE. The 0x0005 - 0xFACE is the data, the 0xC0DE's tell you when the data starts/stops)
- :AES_Test_MixColumns_TestVector
- DAT 0x54, 0x35, 0x31, 0xBD, 0xC0DE
- :AES_Test_KeyExpand
- SET Y, AES_Test_KeyExpand_Keys
- SET X, AES_Test_KeyExpand_TestKey
- JSR AES_ExpandKey
- SET PC, AES_Test_Halt
- :AES_Test_KeyExpand_TestKey
- DAT 0xC3, 0xF4, 0xFC, 0x90, 0x88, 0x51, 0x7F, 0xBA, 0x6A, 0x2D, 0xEA, 0x82, 0x61, 0x51, 0xE7, 0xB2, 0xC0DE
- :AES_Test_KeyExpand_Keys
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; 176 words
- DAT 0xC0DE
- :AES_Test_Halt
- DAT 0 ; Force emulators to halt
- ; *******************************************************************************************************************************************
- ; AES_MixColumns_Linear - Linear Version of Rijndael's MixColumns() step (for testing)
- ; Mixes the 4 bytes starting at Y.
- :AES_MixColumns_Linear
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET PUSH, Y
- SET PUSH, I
- SET PUSH, J
- ; e0: [Y+3] / A
- ; e1: [Y+2] / B
- ; e2: [Y+1] / C
- ; e3: [Y] / J
- ADD Y, 3
- JSR FlipByte ; little - > big
- SUB Y, 1
- JSR FlipByte
- SUB Y, 1
- JSR FlipByte
- SUB Y, 1
- JSR FlipByte
- SET A, [Y+3]
- SET B, [Y+2]
- SET C, [Y+1]
- SET J, [Y]
- SET [Y+3], [A+Rijndael_multiply_table_2]
- XOR [Y+3], [B+Rijndael_multiply_table_3]
- XOR [Y+3], C
- XOR [Y+3], J
- SET [Y+2], A
- XOR [Y+2], [B+Rijndael_multiply_table_2]
- XOR [Y+2], [C+Rijndael_multiply_table_3]
- XOR [Y+2], J
- SET [Y+1], A
- XOR [Y+1], B
- XOR [Y+1], [C+Rijndael_multiply_table_2]
- XOR [Y+1], [J+Rijndael_multiply_table_3]
- SET [Y], [A+Rijndael_multiply_table_3]
- XOR [Y], B
- XOR [Y], C
- XOR [Y], [J+Rijndael_multiply_table_2]
- ADD Y, 3
- JSR FlipByte ; big - > little
- SUB Y, 1
- JSR FlipByte
- SUB Y, 1
- JSR FlipByte
- SUB Y, 1
- JSR FlipByte
- SET J, POP
- SET I, POP
- SET Y, POP
- SET C, POP
- SET B, POP
- SET A, POP
- SET PC, POP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement