Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def expandRoundKeys(key):
- """
- https://en.m.wikipedia.org/wiki/AES_key_schedule?fbclid=IwAR2MKdPC8cO1BeqKlkaheZYKKlUf_QgO7-t1SDPD5etsE8_RvhrLnQnWYAA
- """
- genRoundConsts()
- key_size = len(key)
- # print('key_size', key_size)
- num_keys = util.getNumOfRounds() + 1 # this is R
- # Initialize round keys with the original key
- round_keys = [key[i:i + 4] for i in range(0, key_size, 4)]
- """
- N as the length of the key in 32-bit words:
- 4 words for AES-128, 6 words for AES-192,
- and 8 words for AES-256
- R as the number of rounds:
- 10 rounds for AES-128, 12 rounds for AES-192,
- 14 rounds for AES-256
- """
- # print('round const hex', aes_extension.roundConstsHex)
- N = key_size // 4
- for i in range(N, 4 * num_keys):
- # i >= N
- prevWord = round_keys[i - 1].copy()
- if i % N == 0:
- prevWord = rot_word(prevWord)
- prevWord = sub_word(prevWord)
- prevWord[0] ^= roundConstsHex[i // N]
- elif i >= N and N > 6 and i % N == 4: # todo check
- prevWord = sub_word(prevWord) # SubWord(W[i-1])
- # common for all cases
- # todo
- prevWord = [round_keys[i - N][j] ^ prevWord[j] for j in range(4)]
- round_keys.append(prevWord)
- # print('round keys', round_keys)
- allRoundKeys = []
- for i in range(0, len(round_keys), 4): # range(start, stop, step) 4 words per round
- currRoundKey = []
- for j in range(4):
- currRoundKey.append(round_keys[i + j])
- allRoundKeys.append(np.transpose(currRoundKey))
- flattened_list = [element for sublist in allRoundKeys for element in sublist]
- # print(flattened_list[2])
- global expandedRoundKeys
- expandedRoundKeys = flattened_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement