예제 #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
    def leakage(self, pt, ct, key, bnum):
        state = [pt[i] ^ key[i] for i in range(0, 16)]
        state = self.subbytes(state)
        state1 = state[:]
        state = self.shiftrows(state)
        state = self.mixcolumns(state)

        key2 = self.keyScheduleRounds(key, 0, 1)
        state = [state[i] ^ key2[i] for i in range(0, 16)]
        state = subbytes(state)
        return state[bnum] ^ state1[bnum]
예제 #3
0
    def leakage(self, pt, ct, key, bnum):
        state = [pt[i] ^ key[i] for i in range(0, 16)]
        state = self.subbytes(state)
        state1 = state[:]
        state = self.shiftrows(state)
        state = self.mixcolumns(state)

        key2 = self.keyScheduleRounds(key, 0, 1)
        state = [state[i] ^ key2[i] for i in range(0, 16)]
        state = subbytes(state)
        return state[bnum] ^ state1[bnum]
예제 #4
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
예제 #5
0
 def subbytes(self, state):
     """Helper function: performs AES sbox on all bytes of state"""
     return subbytes(state)
예제 #6
0
 def subbytes(self, state):
     """Helper function: performs AES sbox on all bytes of state"""
     return subbytes(state)