def inTextChanged(self, data=None):

        data = self.indata.text()

        try:
            newdata = hexstr2list(data)

            if len(newdata) != 16 and len(newdata) != 32:
                err = "ERR: Len=%d: %s" % (len(newdata), newdata)
                self.outkey.setText(err)
                self.keysched.setText(err)
            else:
                if len(newdata) == 16:
                    self.setKeyLength(128)
                elif len(newdata) == 32:
                    self.setKeyLength(256)

                #Read settings
                delim = self.outmode.itemData(self.outmode.currentIndex())
                desired = 0
                inpround = self.inprnd.itemData(self.inprnd.currentIndex())

                key = newdata

                # Get initial key
                result = keyScheduleRounds(key, inpround, desired)
                if len(key) == 32:
                    result.extend(keyScheduleRounds(key, inpround,
                                                    desired + 1))

                rstr = ["%02x" % t for t in result]
                rstr = (delim[1] + delim[0]).join(rstr)
                rstr = delim[0] + rstr

                self.outkey.setText(rstr)

                # Get entire key schedule
                if len(key) == 16:
                    rnds = 10
                elif len(key) == 32:
                    rnds = 14

                totalrndstr = ""
                for r in range(0, rnds + 1):
                    result = keyScheduleRounds(key, inpround, r)
                    rstr = ["%02x" % t for t in result]
                    rstr = (delim[1] + delim[0]).join(rstr)
                    rstr = delim[0] + rstr
                    totalrndstr += rstr + "\n"

                self.keysched.setText(totalrndstr)

        except ValueError:
            self.outkey.setText("ERR in HEX: %s" % data)
    def inTextChanged(self, data=None):

        data = self.indata.text()

        try:
            newdata = hexstr2list(data)

            if len(newdata) != 16 and len(newdata) != 32:
                err = "ERR: Len=%d: %s" % (len(newdata), newdata)
                self.outkey.setText(err)
                self.keysched.setText(err)
            else:
                if len(newdata) == 16:
                    self.setKeyLength(128)
                elif len(newdata) == 32:
                    self.setKeyLength(256)

                #Read settings
                delim = self.outmode.itemData(self.outmode.currentIndex())
                desired = 0
                inpround = self.inprnd.itemData(self.inprnd.currentIndex())

                key = newdata

                # Get initial key
                result = keyScheduleRounds(key, inpround, desired)
                if len(key) == 32:
                    result.extend(keyScheduleRounds(key, inpround, desired + 1))

                rstr = ["%02x" % t for t in result]
                rstr = (delim[1] + delim[0]).join(rstr)
                rstr = delim[0] + rstr

                self.outkey.setText(rstr)

                # Get entire key schedule
                if len(key) == 16:
                    rnds = 10
                elif len(key) == 32:
                    rnds = 14

                totalrndstr = ""
                for r in range(0, rnds+1):
                    result = keyScheduleRounds(key, inpround, r)
                    rstr = ["%02x" % t for t in result]
                    rstr = (delim[1] + delim[0]).join(rstr)
                    rstr = delim[0] + rstr
                    totalrndstr += rstr + "\n"

                self.keysched.setText(totalrndstr)

        except ValueError:
            self.outkey.setText("ERR in HEX: %s" % data)
Example #3
0
    def processKnownKey(self, inpkey):
        if inpkey is None:
            return None

        if self.keyround() == -1:
            # return models_AES_RoundKeys.AES_RoundKeys().getFinalKey(inpkey)
            if len(inpkey) == 16:
                rnds = 10
            elif len(inpkey) == 32:
                rnds = 14
            else:
                raise ValueError('unsupported key length: %d' % len(inpkey))
            return keyScheduleRounds(inpkey, 0, rnds)
        else:
            return inpkey
Example #4
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[INVSHIFT[i]]
            st9 = inv_sbox(ct[i] ^ key[i])
            guess[i] = getHW(st9 ^ st10)
        return guess
Example #5
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[INVSHIFT[i]]
            st9 = inv_sbox(ct[i] ^ key[i])
            guess[i] = getHW(st9 ^ st10)
        return guess
def processKnownKey(setting, inpkey):

    if setting == LEAK_HD_LASTROUND_STATE:
        return keyScheduleRounds(inpkey, 0, 10)

    return inpkey
Example #7
0
def processKnownKey(setting, inpkey):

    if setting == LEAK_HD_LASTROUND_STATE:
        return keyScheduleRounds(inpkey, 0, 10)

    return inpkey