コード例 #1
0
 def cipher(self, pt, key):
     # Note: we assume fixed key here for huge speedup
     # TODO: make this an option
     #if self.ks is None:
     self.ks = [keyScheduleRounds(key, 0, r) for r in range(11)]
 
     ret = {}
     
     Nr = 10
     state = pt
     ret['Plaintext'] = self.flatten(state[:])
     
     ret['Key'] = self.flatten(self.ks[0])
     
     state = [state[i] ^ self.ks[0][i] for i in range(16)]
     ret['Round 0: AddRoundKey Output'] = self.flatten(state[:])
     
     for r in range(1, Nr):
         state = subbytes(state)
         ret['Round ' + str(r) + ': SubBytes Output'] = self.flatten(state[:])
         
         state = shiftrows(state)
         ret['Round ' + str(r) + ': ShiftRows Output'] = self.flatten(state[:])
         
         state = mixcolumns(state)
         ret['Round ' + str(r) + ': MixColumns Output'] = self.flatten(state[:])
     
         ret['Round ' + str(r) + ': RoundKey'] = self.flatten(self.ks[r])
     
         state = [state[i] ^ self.ks[r][i] for i in range(16)]
         ret['Round ' + str(r) + ': AddRoundKey Output'] = self.flatten(state[:])
     
     
     
     state = subbytes(state)
     ret['Round 10: SubBytes Output'] = self.flatten(state[:])
     
     state = shiftrows(state)
     ret['Round 10: ShiftRows Output'] = self.flatten(state[:])
     
     ret['Round 10: RoundKey'] = self.flatten(self.ks[Nr])
     
     state = [state[i] ^ self.ks[Nr][i] for i in range(16)]
     ret['Ciphertext'] = self.flatten(state[:])
     
     return ret
コード例 #2
0
ファイル: Partition.py プロジェクト: ymz000/chipwhisperer
    def getPartitionNum(self, trace, tnum):
        key = trace.getKnownKey(tnum)
        ct = trace.getTextout(tnum)

        #Convert from initial key to final-round key, currently
        #this assumes AES
        if len(key) == 16:
            rounds = 10
        else:
            raise ValueError("Need to implement for selected AES")
        key = keyScheduleRounds(key, 0, rounds)

        guess = [0] * 16
        for i in range(0, 16):
            st10 = ct[AES128_8bit.INVSHIFT[i]]
            st9 = inv_sbox(ct[i] ^ key[i])
            guess[i] = AES128_8bit.getHW(st9 ^ st10)
        return guess
コード例 #3
0
    def getPartitionNum(self, trace, tnum):
        key = trace.getKnownKey(tnum)
        ct = trace.getTextout(tnum)

        #Convert from initial key to final-round key, currently
        #this assumes AES
        if len(key) == 16:
            rounds = 10
        else:
            raise ValueError("Need to implement for selected AES")
        key = keyScheduleRounds(key, 0, rounds)

        guess = [0] * 16
        for i in range(0, 16):
            st10 = ct[AES128_8bit.INVSHIFT[i]]
            st9 = inv_sbox(ct[i] ^ key[i])
            guess[i] = AES128_8bit.getHW(st9 ^ st10)
        return guess
コード例 #4
0
 def cipher(self, input, key):
     Nr = 14
     #if self.ks is None:
     self.ks = [keyScheduleRounds(key, 0, r) for r in range(Nr+1)]
 
     ret = {}
     
     state = input
     ret['Ciphertext (Unflipped)'] = self.flatten(state)
     
     
     ret['Key (bytes 0-15)']  = self.flatten(self.ks[0])
     ret['Key (bytes 16-31)'] = self.flatten(self.ks[1])
     
     state = self.reverse_bits(input)
     ret['Ciphertext (Flipped)'] = self.flatten(state)
     state = [state[i] ^ self.ks[Nr][i] for i in range(16)]
     
     ret['Round 14: ShiftRows Output'] = self.flatten(state[:])
     state = inv_shiftrows(state)
     
     ret['Round 14: SubBytes Output'] = self.flatten(state[:])
     state = inv_subbytes(state)
  
     for r in reversed(range(1, Nr)):
         ret['Round ' + str(r) + ': AddRoundKey Output'] = self.flatten(state[:])
         state = [state[i] ^ self.ks[r][i] for i in range(16)]
         
         ret['Round ' + str(r) + ': MixColumns Output'] = self.flatten(state[:])
         state = inv_mixcolumns(state)
         
         ret['Round ' + str(r) + ': ShiftRows Output'] = self.flatten(state[:])
         state = inv_shiftrows(state)
         
         ret['Round ' + str(r) + ': SubBytes Output'] = self.flatten(state[:])
         state = inv_subbytes(state)
     
     ret['Round 0: AddRoundKey Output'] = self.flatten(state[:])
     state = [state[i] ^ self.ks[0][i] for i in range(16)]
     
     
     ret['Plaintext'] = self.flatten(state[:])
     
     return ret
コード例 #5
0
 def cipher(self, pt, key):
     Nr = 14
     if self.ks is None:
         self.ks = [keyScheduleRounds(key, 0, r) for r in range(Nr+1)]
 
     ret = {}
     
     state = pt
     ret['Plaintext'] = self.flatten(state[:])
     
     ret['Key (bytes 0-15)']  = self.flatten(self.ks[0])
     ret['Key (bytes 16-31)'] = self.flatten(self.ks[1])
     
     state = [state[i] ^ self.ks[0][i] for i in range(16)]
     ret['Round 0: AddRoundKey Output'] = self.flatten(state[:])
     
     for r in range(1, Nr):
         state = subbytes(state)
         ret['Round ' + str(r) + ': SubBytes Output'] = self.flatten(state[:])
         
         state = shiftrows(state)
         ret['Round ' + str(r) + ': ShiftRows Output'] = self.flatten(state[:])
         
         state = mixcolumns(state)
         ret['Round ' + str(r) + ': MixColumns Output'] = self.flatten(state[:])
         
         state = [state[i] ^ self.ks[r][i] for i in range(16)]
         ret['Round ' + str(r) + ': AddRoundKey Output'] = self.flatten(state[:])
     
     
     state = subbytes(state)
     ret['Round 14: SubBytes Output'] = self.flatten(state[:])
     
     state = shiftrows(state)
     ret['Round 14: ShiftRows Output'] = self.flatten(state[:])
     
     state = [state[i] ^ self.ks[Nr][i] for i in range(16)]
     ret['Ciphertext'] = self.flatten(state[:])
     
     return ret
コード例 #6
0
 def processKnownKey(self, inpkey):
     if self.model == self.LEAK_HD_LASTROUND_STATE:
         return keyScheduleRounds(inpkey, 0, 10)
     return inpkey
コード例 #7
0
 def keyScheduleRounds(self, inputkey, inputround, desiredround):
     return keyScheduleRounds(inputkey, inputround, desiredround)
コード例 #8
0
 def keyScheduleRounds(self, inputkey, inputround, desiredround):
     """Helper function: takes AES key from one round to another round-eky """
     return keyScheduleRounds(inputkey, inputround, desiredround)
コード例 #9
0
 def processKnownKey(self, inpkey):
     return keyScheduleRounds(inpkey, 0, 10)
コード例 #10
0
 def processKnownKey(self, inpkey):
     k = keyScheduleRounds(inpkey, 0, 10)
     k = self.shiftrows(k)
     return k
コード例 #11
0
 def keyScheduleRounds(self, inputkey, inputround, desiredround):
     """Helper function: takes AES key from one round to another round-eky """
     return keyScheduleRounds(inputkey, inputround, desiredround)
コード例 #12
0
 def keyScheduleRounds(self, inputkey, inputround, desiredround):
     return keyScheduleRounds(inputkey, inputround, desiredround)
コード例 #13
0
 def processKnownKey(self, inpkey):
     return keyScheduleRounds(inpkey, 0, 10)