Utilities/crypto/py3AES.py

changeset 3039
8dd0165d805d
parent 3034
7ce719013078
child 3060
5883ce99ee12
child 3160
209a07d7e401
equal deleted inserted replaced
3038:7fe9a53280bd 3039:8dd0165d805d
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

eric ide

mercurial