342 """ |
342 """ |
343 state = state[:] |
343 state = state[:] |
344 for i in range(nbr): |
344 for i in range(nbr): |
345 if isInv: |
345 if isInv: |
346 state[statePointer:statePointer + 4] = \ |
346 state[statePointer:statePointer + 4] = \ |
347 state[statePointer + 3:statePointer + 4] + \ |
347 state[statePointer + 3:statePointer + 4] + \ |
348 state[statePointer:statePointer + 3] |
348 state[statePointer:statePointer + 3] |
349 else: |
349 else: |
350 state[statePointer:statePointer + 4] = \ |
350 state[statePointer:statePointer + 4] = \ |
351 state[statePointer + 1:statePointer + 4] + \ |
351 state[statePointer + 1:statePointer + 4] + \ |
352 state[statePointer:statePointer + 1] |
352 state[statePointer:statePointer + 1] |
353 return state |
353 return state |
354 |
354 |
355 def __mixColumns(self, state, isInv): |
355 def __mixColumns(self, state, isInv): |
356 """ |
356 """ |
357 Private method to perform a galois multiplication of the 4x4 matrix. |
357 Private method to perform a galois multiplication of the 4x4 matrix. |
389 mult = [2, 1, 1, 3] |
389 mult = [2, 1, 1, 3] |
390 cpy = column[:] |
390 cpy = column[:] |
391 g = self.__galois_multiplication |
391 g = self.__galois_multiplication |
392 |
392 |
393 column[0] = g(cpy[0], mult[0]) ^ g(cpy[3], mult[1]) ^ \ |
393 column[0] = g(cpy[0], mult[0]) ^ g(cpy[3], mult[1]) ^ \ |
394 g(cpy[2], mult[2]) ^ g(cpy[1], mult[3]) |
394 g(cpy[2], mult[2]) ^ g(cpy[1], mult[3]) |
395 column[1] = g(cpy[1], mult[0]) ^ g(cpy[0], mult[1]) ^ \ |
395 column[1] = g(cpy[1], mult[0]) ^ g(cpy[0], mult[1]) ^ \ |
396 g(cpy[3], mult[2]) ^ g(cpy[2], mult[3]) |
396 g(cpy[3], mult[2]) ^ g(cpy[2], mult[3]) |
397 column[2] = g(cpy[2], mult[0]) ^ g(cpy[1], mult[1]) ^ \ |
397 column[2] = g(cpy[2], mult[0]) ^ g(cpy[1], mult[1]) ^ \ |
398 g(cpy[0], mult[2]) ^ g(cpy[3], mult[3]) |
398 g(cpy[0], mult[2]) ^ g(cpy[3], mult[3]) |
399 column[3] = g(cpy[3], mult[0]) ^ g(cpy[2], mult[1]) ^ \ |
399 column[3] = g(cpy[3], mult[0]) ^ g(cpy[2], mult[1]) ^ \ |
400 g(cpy[1], mult[2]) ^ g(cpy[0], mult[3]) |
400 g(cpy[1], mult[2]) ^ g(cpy[0], mult[3]) |
401 return column |
401 return column |
402 |
402 |
403 def __aes_round(self, state, roundKey): |
403 def __aes_round(self, state, roundKey): |
404 """ |
404 """ |
405 Private method to apply the 4 operations of the forward round in |
405 Private method to apply the 4 operations of the forward round in |