eric6/Utilities/crypto/py3AES.py

changeset 8235
78e6d29eb773
parent 8220
006ee31b4835
equal deleted inserted replaced
8234:fcb6b4b96274 8235:78e6d29eb773
310 @param state state to be worked on (bytearray) 310 @param state state to be worked on (bytearray)
311 @param isInv flag indicating an inverse operation (boolean) 311 @param isInv flag indicating an inverse operation (boolean)
312 @return modified state (bytearray) 312 @return modified state (bytearray)
313 """ 313 """
314 state = state[:] 314 state = state[:]
315 if isInv: 315 getter = self.__getSBoxInvert if isInv else self.__getSBoxValue
316 getter = self.__getSBoxInvert
317 else:
318 getter = self.__getSBoxValue
319 for i in range(16): 316 for i in range(16):
320 state[i] = getter(state[i]) 317 state[i] = getter(state[i])
321 return state 318 return state
322 319
323 def __shiftRows(self, state, isInv): 320 def __shiftRows(self, state, isInv):
387 @param column column to be worked on (bytearray) 384 @param column column to be worked on (bytearray)
388 @param isInv flag indicating an inverse operation (boolean) 385 @param isInv flag indicating an inverse operation (boolean)
389 @return modified column (bytearray) 386 @return modified column (bytearray)
390 """ 387 """
391 column = column[:] 388 column = column[:]
392 if isInv: 389 mult = [14, 9, 13, 11] if isInv else [2, 1, 1, 3]
393 mult = [14, 9, 13, 11]
394 else:
395 mult = [2, 1, 1, 3]
396 cpy = column[:] 390 cpy = column[:]
397 g = self.__galois_multiplication 391 g = self.__galois_multiplication
398 392
399 column[0] = ( 393 column[0] = (
400 g(cpy[0], mult[0]) ^ g(cpy[3], mult[1]) ^ 394 g(cpy[0], mult[0]) ^ g(cpy[3], mult[1]) ^
632 @param mode mode of operation (0, 1, 2) 626 @param mode mode of operation (0, 1, 2)
633 @return extracted bytes (bytearray) 627 @return extracted bytes (bytearray)
634 """ 628 """
635 if end - start > 16: 629 if end - start > 16:
636 end = start + 16 630 end = start + 16
637 if mode == self.ModeOfOperation["CBC"]: 631 ar = (bytearray(16) if mode == self.ModeOfOperation["CBC"]
638 ar = bytearray(16) 632 else bytearray())
639 else:
640 ar = bytearray()
641 633
642 i = start 634 i = start
643 j = 0 635 j = 0
644 while len(ar) < end - start: 636 while len(ar) < end - start:
645 ar.append(0) 637 ar.append(0)

eric ide

mercurial