Exemple #1
0
    def keyScheduleRounds(self,
                          inputkey,
                          inputround,
                          desiredround,
                          returnSubkeys=True):
        """Create the 16 subkeys K[1] to K[16] from the given key"""
        if inputround == 0:
            inputkey = bytearray2binarylist(inputkey, 8)
            key = self.__permutate(self.__pc1, inputkey)
        else:
            inputkey = bytearray2binarylist(inputkey, 6)
            key = self.__permutate(self.__pc2_inv, inputkey)
        i = inputround
        L = key[:28]
        R = key[28:]
        while i < desiredround:
            i += 1
            j = 0
            # Perform circular left shifts
            while j < self.__left_rotations[i]:
                L.append(L[0])
                del L[0]

                R.append(R[0])
                del R[0]

                j += 1
        while i > desiredround:
            # Perform circular right shifts
            j = 0
            while j < self.__left_rotations[i]:
                L.insert(0, L[27])
                del L[28]

                R.insert(0, R[27])
                del R[28]

                j += 1
            i -= 1
        if desiredround == 0:
            key = self.__permutate(self.__pc1_inv, L + R)
            return binarylist2bytearray(key, 8) if returnSubkeys else key
        else:
            key = self.__permutate(self.__pc2, L + R)
            return binarylist2bytearray(key, 6) if returnSubkeys else key
Exemple #2
0
    def keyScheduleRounds(self, inputkey, inputround, desiredround, returnSubkeys=True):
        """Create the 16 subkeys K[1] to K[16] from the given key"""
        if inputround == 0:
            inputkey = bytearray2binarylist(inputkey,8)
            key = self.__permutate(self.__pc1, inputkey)
        else:
            inputkey = bytearray2binarylist(inputkey,6)
            key = self.__permutate(self.__pc2_inv, inputkey)
        i = inputround
        L = key[:28]
        R = key[28:]
        while i < desiredround:
            i += 1
            j = 0
            # Perform circular left shifts
            while j < self.__left_rotations[i]:
                L.append(L[0])
                del L[0]

                R.append(R[0])
                del R[0]

                j += 1
        while i > desiredround:
            # Perform circular right shifts
            j = 0
            while j < self.__left_rotations[i]:
                L.insert(0,L[27])
                del L[28]

                R.insert(0,R[27])
                del R[28]

                j += 1
            i -= 1
        if desiredround==0:
            key = self.__permutate(self.__pc1_inv, L + R)
            return binarylist2bytearray(key, 8) if returnSubkeys else key
        else:
            key = self.__permutate(self.__pc2, L + R)
            return binarylist2bytearray(key, 6) if returnSubkeys else key
Exemple #3
0
 def leakage(self, pt, ct, key, bnum):
     return binarylist2bytearray(self.sbox_in_first_fbox(pt, key[bnum], bnum), 6)[0]
Exemple #4
0
 def leakage(self, pt, ct, key, bnum):
     return binarylist2bytearray(self.sbox_in_first_fbox(pt, key[bnum], bnum), 6)[0]