Пример #1
0
    def init(self, maxtraces):
        """Initialize key text pattern for a specific number of traces.

        Args:
            maxtraces (int): Number of traces to initialize for.

        Raises:
            ValueError: Invalid key length
        """
        length = self.keyLen()
        if length <= 32:
            self._key = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01 34 56 78 9a bc de f0 12"
            )[:length]
        else:
            raise ValueError("Invalid key length: %d bytes" % length)

        self._textin1 = util.hexStrToByteArray(
            "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")

        if length == 16:
            self._interleavedPlaintext = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90")
        elif length == 24:
            self._interleavedPlaintext = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 88")
        elif length == 32:
            self._interleavedPlaintext = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 95")
        else:
            raise ValueError("Invalid key length: %d bytes" % length)

        self.num_group1 = int(maxtraces / 2)
        self.num_group2 = int(maxtraces - self.num_group1)
Пример #2
0
 def __init__(self, target=None):
     AcqKeyTextPattern_Base.__init__(self)
     self.initmask = 'FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
     self.initkey = '2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C'
     self._key = util.hexStrToByteArray(self.initkey)
     self._mask = util.hexStrToByteArray(self.initmask)
     self.setTarget(target)
Пример #3
0
    def __init__(self, target=None):
        AcqKeyTextPattern_Base.__init__(self)
        self.initmask = 'FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
        self.initkey = '2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C'
        self._key = util.hexStrToByteArray(self.initkey)
        self._mask = util.hexStrToByteArray(self.initmask)

        self.getParams().addChildren([
            {
                'name': 'Fixed Encryption Key',
                'key': 'initkey',
                'type': 'str',
                'get': self.getInitialKey,
                'set': self.setInitialKey,
                'visible': True
            },
            {
                'name': 'Plaintext Mask',
                'key': 'initmask',
                'type': 'str',
                'get': self.getInitialMask,
                'set': self.setInitialMask,
                'visible': True
            },
        ])
        self.setTarget(target)
Пример #4
0
    def initPair(self, maxtraces):
        length = self.keyLen()
        if length <= 32:
            self._key = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01 34 56 78 9a bc de f0 12"
            )[:length]
        else:
            raise ValueError("Invalid key length: %d bytes" % length)
        self.findParam("key").setValue(" ".join(
            ["%02X" % b for b in self._key]),
                                       init=True)

        self._textin1 = util.hexStrToByteArray(
            "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")

        if length == 16:
            self._interleavedPlaintext = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90")
        elif length == 24:
            self._interleavedPlaintext = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 88")
        elif length == 32:
            self._interleavedPlaintext = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 95")
        else:
            raise ValueError("Invalid key length: %d bytes" % length)
        self.findParam("text").setValue(" ".join(
            ["%02X" % b for b in self._interleavedPlaintext]),
                                        init=True)

        self.num_group1 = int(maxtraces / 2)
        self.num_group2 = int(maxtraces - self.num_group1)
Пример #5
0
 def __init__(self):
     AcqKeyTextPattern_Base.__init__(self)
     self._fixedKey = True
     self._fixedPlain = False
     self.inittext = '00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F'
     self.initkey = '2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C'
     self._key = util.hexStrToByteArray(self.initkey)
     self._textin = util.hexStrToByteArray(self.inittext)
     self.types = {'Random': False, 'Fixed': True}
        def trace_callback(self, textin, textout, trace, key):
            interleavedPlaintext128 = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90")
            interleavedPlaintext192 = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 88")
            interleavedPlaintext256 = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 95")

            if (textin == interleavedPlaintext128).all() or \
                    (textin == interleavedPlaintext192).all() or \
                    (textin == interleavedPlaintext256).all():
                raise StopIteration()

            return (textin, textout, trace, key)
Пример #7
0
    def __init__(self, target=None):
        AcqKeyTextPattern_Base.__init__(self)
        self._fixedKey = True
        self._fixedPlain = False
        self.inittext = "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"
        self.initkey = "2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C"
        self._key = util.hexStrToByteArray(self.initkey)
        self._textin = util.hexStrToByteArray(self.inittext)
        self.types = {"Random": False, "Fixed": True}

        self.getParams().addChildren(
            [
                {
                    "name": "Key",
                    "type": "list",
                    "values": self.types,
                    "get": self.getKeyType,
                    "set": self.setKeyType,
                    "action": lambda p: self.findParam("initkey").show(p.getValue()),
                    "linked": ["initkey"],
                },
                # {'name':'Size', 'type':'int'},
                {
                    "name": "Fixed Encryption Key",
                    "key": "initkey",
                    "type": "str",
                    "get": self.getInitialKey,
                    "set": self.setInitialKey,
                    "visible": self.getKeyType(),
                },
                {
                    "name": "Plaintext",
                    "type": "list",
                    "values": self.types,
                    "get": self.getPlainType,
                    "set": self.setPlainType,
                    "action": lambda p: self.findParam("inittext").show(p.getValue()),
                    "linked": ["inittext"],
                },
                {
                    "name": "Fixed Plaintext",
                    "key": "inittext",
                    "type": "str",
                    "get": self.getInitialText,
                    "set": self.setInitialText,
                    "visible": self.getPlainType(),
                },
            ]
        )
        self.setTarget(target)
Пример #8
0
    def __init__(self, target=None):
        AcqKeyTextPattern_Base.__init__(self)
        self._fixedKey = True
        self._fixedPlain = False
        self.inittext = '00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F'
        self.initkey = '2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C'
        self._key = util.hexStrToByteArray(self.initkey)
        self._textin = util.hexStrToByteArray(self.inittext)
        self.types = {'Random': False, 'Fixed': True}

        self.getParams().addChildren([
            {
                'name': 'Key',
                'type': 'list',
                'values': self.types,
                'get': self.getKeyType,
                'set': self.setKeyType,
                'action':
                lambda p: self.findParam("initkey").show(p.getValue()),
                'linked': ['initkey']
            },
            # {'name':'Size', 'type':'int'},
            {
                'name': 'Fixed Encryption Key',
                'key': 'initkey',
                'type': 'str',
                'get': self.getInitialKey,
                'set': self.setInitialKey,
                'visible': self.getKeyType()
            },
            {
                'name': 'Plaintext',
                'type': 'list',
                'values': self.types,
                'get': self.getPlainType,
                'set': self.setPlainType,
                'action':
                lambda p: self.findParam("inittext").show(p.getValue()),
                'linked': ['inittext']
            },
            {
                'name': 'Fixed Plaintext',
                'key': 'inittext',
                'type': 'str',
                'get': self.getInitialText,
                'set': self.setInitialText,
                'visible': self.getPlainType()
            },
        ])
        self.setTarget(target)
Пример #9
0
    def getPartitionNum(self, trace, tnum):
        """Checks if plaintext is the fixed TVLA plaintext for this key length or a random value.

        Returns [1] if fixed and [0] if random.
        """
        klen = len(trace.getKnownKey(tnum))

        pt = trace.getTextin(tnum)
        if klen == 16 and (pt == util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90")).all():
            return [1]
        elif klen == 24 and (pt == util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 88")).all():
            return [1]
        elif klen == 32 and (pt == util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 95")).all():
            return [1]
        return [0]
Пример #10
0
    def __init__(self, key_len=16):
        self._key_len = key_len
        self._I_0_fixed = bytearray([0xAA] * 16)
        self._I_0_rand = bytearray([0xCC] * 16)
        self._K_0 = util.hexStrToByteArray(
            "53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53")
        rounds = 10
        if key_len == 16:
            self._K_fixed = util.hexStrToByteArray(
                "81 1E 37 31 B0 12 0A 78 42 78 1E 22 B2 5C DD F9")
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd e0 f0")
        elif key_len == 24:
            rounds = 12
            self._K_fixed = util.hexStrToByteArray(
                "81 1E 37 31 B0 12 0A 78 42 78 1E 22 B2 5C DD F9 94 F4 D9 2C D2 FA E6 45"
            )
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd ef 02 34 56 78 9a bc de 0f 01"
            )
        elif key_len == 32:
            rounds = 14
            self._K_fixed = util.hexStrToByteArray(
                "81 1E 37 31 B0 12 0A 78 42 78 1E 22 B2 5C DD F9 94 F4 D9 2C D2 FA E6 45 37 B9 40 EA 5E 1A F1 12"
            )
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd ef 02 34 56 78 9a bc de f0 13 45 67 89 ab cd e0 f0 12"
            )
        else:
            raise ValueError(
                "Invalid key length {}, must be 16, 24, or 32".format(key_len))

        self._K_gen_exp = _expand_aes_key(self._K_gen)
        self._cipher = AESCipher(self._K_gen_exp)
Пример #11
0
    def __init__(self, target=None):
        AcqKeyTextPattern_Base.__init__(self)
        self._fixedKey = True
        self._fixedPlain = False
        self.inittext = '00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F'
        self.initkey = '2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C'
        self._key = util.hexStrToByteArray(self.initkey)
        self._textin = util.hexStrToByteArray(self.inittext)
        self.types = {'Random': False, 'Fixed': True}

        self.getParams().addChildren([
            {'name':'Key', 'type':'list', 'values':self.types , 'get':self.getKeyType, 'set':self.setKeyType, 'action':lambda p:self.findParam("initkey").show(p.getValue()), 'linked':['initkey']},
            # {'name':'Size', 'type':'int'},
            {'name':'Fixed Encryption Key', 'key':'initkey', 'type':'str', 'get':self.getInitialKey, 'set':self.setInitialKey, 'visible':self.getKeyType()},
            {'name':'Plaintext', 'type':'list', 'values':self.types , 'get':self.getPlainType, 'set':self.setPlainType, 'action':lambda p:self.findParam("inittext").show(p.getValue()), 'linked':['inittext']},
            {'name':'Fixed Plaintext', 'key':'inittext', 'type':'str', 'get':self.getInitialText, 'set':self.setInitialText, 'visible':self.getPlainType()},
        ])
        self.setTarget(target)
Пример #12
0
    def __init__(self):
        TargetTemplate.__init__(self)

        self.ser = SimpleSerial_ChipWhispererLite()

        self.keylength = 16
        self.textlength = 16
        self.outputlength = 16
        self.input = ""
        self.key = ""
        self._protver = 'auto'
        self._read_timeout = 500
        self.masklength = 18
        self._fixedMask = True
        self.initmask = '1F 70 D6 3C 23 EB 1A B8 6A D5 E2 0D 5F D9 58 A3 CA 9D'
        self._mask = util.hexStrToByteArray(self.initmask)
        self.protformat = 'hex'
        self.last_key = bytearray(16)

        # Preset lists are in the form
        # {'Dropdown Name':['Init Command', 'Load Key Command', 'Load Input Command', 'Go Command', 'Output Format']}
        # If a command is None, it's left unchanged and the text field is editable;
        # Otherwise, it's loaded with the value and set to readonly
        self.presets = {
            'Custom': [None, None, None, None, None],
            'SimpleSerial Encryption':
            ['', 'k$KEY$\\n', '', 'p$TEXT$\\n', 'r$RESPONSE$\\n'],
            'SimpleSerial Authentication': [
                '', 'k$KEY$\\n', 't$EXPECTED$\\n', 'p$TEXT$\\n',
                'r$RESPONSE$\\n'
            ],
            'Glitching': [None, None, None, None, '$GLITCH$\\n'],
        }
        self._preset = 'Custom'

        self._linkedmaskgroup = (('maskgroup', 'cmdmask'),
                                 ('maskgroup', 'initmask'), ('maskgroup',
                                                             'masktype'),
                                 ('maskgroup', 'masklen'), ('maskgroup',
                                                            'newmask'))

        self._proto_ver = "auto"
        self._proto_timeoutms = 20
        self._init_cmd = ''
        self._key_cmd = 'k$KEY$\n'
        self._input_cmd = ''
        self._go_cmd = 'p$TEXT$\n'
        self._output_cmd = 'r$RESPONSE$\n'

        self._mask_enabled = False
        self._mask_cmd = 'm$MASK$\n'

        self.outstanding_ack = False

        self.setConnection(self.ser)
        self.disable_newattr()
Пример #13
0
 def setInitialMask(self, initialMask, binaryMask=False):
     if initialMask:
         if binaryMask:
             maskStr = ''
             for s in initialMask:
                 maskStr += '%02x' % s
             self._mask = bytearray(initialMask)
         else:
             maskStr = initialMask
             self._mask = util.hexStrToByteArray(initialMask)
         self.initmask = maskStr
Пример #14
0
    def initPair(self):
        length = self.keyLen()
        if length <= 32:
            self._key = util.hexStrToByteArray("01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01 34 56 78 9a bc de f0 12")[:length]
        else:
            raise ValueError("Invalid key length: %d bytes" % length)
        self.findParam("key").setValue(" ".join(["%02X"%b for b in self._key]), init=True)

        self._textin1 = util.hexStrToByteArray("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")

        if length == 16:
            self._interleavedPlaintext = util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90")
        elif length == 24:
            self._interleavedPlaintext = util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 88")
        elif length == 32:
            self._interleavedPlaintext = util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 95")
        else:
            raise ValueError("Invalid key length: %d bytes" % length)
        self.findParam("text").setValue(" ".join(["%02X" % b for b in self._interleavedPlaintext]), init=True)

        self.group1 = True
Пример #15
0
    def setInitialKey(self, initialKey, binaryKey=False):
        if initialKey:
            if binaryKey:
                keyStr = ""
                for s in initialKey:
                    keyStr += "%02x " % s
                self._key = bytearray(initialKey)
            else:
                keyStr = initialKey
                self._key = util.hexStrToByteArray(initialKey)

            self.initkey = keyStr
Пример #16
0
    def setInitialText(self, initialText, binaryText=False):
        if initialText:
            if binaryText:
                textStr = ''
                for s in initialText:
                    textStr += '%02x ' % s
                self._textin = bytearray(initialText)
            else:
                textStr = initialText
                self._textin = util.hexStrToByteArray(initialText)

            self.inittext = textStr
Пример #17
0
    def setInitialKey(self, initialKey, binaryKey=False):
        if initialKey:
            if binaryKey:
                keyStr = ''
                for s in initialKey:
                    keyStr += '%02x ' % s
                self._key = bytearray(initialKey)
            else:
                keyStr = initialKey
                self._key = util.hexStrToByteArray(initialKey)

            self.initkey = keyStr
Пример #18
0
    def setInitialText(self, initialText, binaryText=False):
        if initialText:
            if binaryText:
                textStr = ""
                for s in initialText:
                    textStr += "%02x " % s
                self._textin = bytearray(initialText)
            else:
                textStr = initialText
                self._textin = util.hexStrToByteArray(initialText)

            self.inittext = textStr
Пример #19
0
 def get_reg(self, reg):
     """Reads a Cortex debug register
     Args:
         reg (string): Register to read. See self.regs for available registers.
     """
     if reg in self.regs:
         data = self.regs[reg] + '00000000'
         self._ss.simpleserial_write('g', util.hexStrToByteArray(data))
         time.sleep(0.1)
         return self._ss.read().split('\n')[0][1:]
     else:
         logging.error('Register %s does not exist.', reg)
Пример #20
0
 def set_reg(self, reg, data, printresult=False):
     """Set a Cortex debug register
     Args:
         reg (string): Register to write. See self.regs for available registers.
         data (string): 8-character hex string, value to write to COMP0 (e.g. '1000F004')
     """
     if reg in self.regs:
         data = self.regs[reg] + data
         self._ss.simpleserial_write('s', util.hexStrToByteArray(data))
         time.sleep(0.1)
         if printresult:
             print(self._ss.read().split('\n')[0])
     else:
         logging.error('Register %s does not exist.', reg)
Пример #21
0
    def __init__(self, key_len=16):
        self._key_len = key_len
        self._I_0 = bytearray([0x00] * 16)
        self.rounds = 10
        if key_len == 16:
            self._I_fixed = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90")
            self._K_dev = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0")
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd e0 f0")
        elif key_len == 24:
            self.rounds = 12
            self._I_fixed = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 88")
            self._K_dev = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01"
            )
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd ef 02 34 56 78 9a bc de 0f 01"
            )
        elif key_len == 32:
            self.rounds = 14
            self._I_fixed = util.hexStrToByteArray(
                "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 95")
            self._K_dev = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01 34 56 78 9a bc de f0 12"
            )
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd ef 02 34 56 78 9a bc de f0 13 45 67 89 ab cd e0 f0 12"
            )
        else:
            raise ValueError(
                "Invalid key length {}, must be 16, 24, or 32".format(key_len))

        self._K_gen_exp = _expand_aes_key(self._K_gen)
        self._K_dev_exp = _expand_aes_key(self._K_dev)
        self._cipher = AESCipher(self._K_gen_exp)
        self._dev_cipher = AESCipher(self._K_dev_exp)
Пример #22
0
    def __init__(self, key_len=16, round=None):
        self._key_len = key_len
        self._I_0 = bytearray([0x00] * 16)
        rounds = 10
        random.seed()
        self._round = round
        self._I_semi_fixed = util.hexStrToByteArray(
            "8B 8A 49 0B DF 7C 00 BD D7 E6 06 6C 61 00 24 12")
        if key_len == 16:
            if not round:
                self._round = 5
            self._K_dev = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0")
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd e0 f0")
        elif key_len == 24:
            rounds = 12
            if not round:
                self._round = 6
            self._K_dev = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01"
            )
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd ef 02 34 56 78 9a bc de 0f 01"
            )
        elif key_len == 32:
            if not round:
                self._round = 7
            rounds = 14
            self._K_dev = util.hexStrToByteArray(
                "01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01 34 56 78 9a bc de f0 12"
            )
            self._K_gen = util.hexStrToByteArray(
                "12 34 56 78 9a bc de f1 23 45 67 89 ab cd ef 02 34 56 78 9a bc de f0 13 45 67 89 ab cd e0 f0 12"
            )
        else:
            raise ValueError(
                "Invalid key length {}, must be 16, 24, or 32".format(key_len))

        self._K_dev_exp = _expand_aes_key(self._K_dev)
        self._K_gen_exp = _expand_aes_key(self._K_gen)

        self._dev_cipher = AESCipher(self._K_dev_exp)
        self._cipher = AESCipher(self._K_gen_exp)
        self._state_start = np.uint32(
            int.from_bytes(self._I_semi_fixed[:4], "big"))
Пример #23
0
    def initPair(self):
        if self.keyLen() == 16:
            self._key = util.hexStrToByteArray("01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0")
        elif self.keyLen() == 24:
            self._key = util.hexStrToByteArray("01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01")
        elif self.keyLen() == 32:
            self._key = util.hexStrToByteArray("01 23 45 67 89 ab cd ef 12 34 56 78 9a bc de f0 23 45 67 89 ab cd ef 01 34 56 78 9a bc de f0 12")
        else:
            raise ValueError("Invalid key length: %d bytes" % self.keyLen())

        self._textin1 = util.hexStrToByteArray("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")

        if self.keyLen() == 16:
            self._textin2 = util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90")
        elif self.keyLen() == 24:
            self._textin2 = util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 88")
        elif self.keyLen() == 32:
            self._textin2 = util.hexStrToByteArray("da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 95")
        else:
            raise ValueError("Invalid key length: %d bytes" % self.keyLen())

        self.group1 = True
Пример #24
0
    def __init__(self):
        TargetTemplate.__init__(self)

        ser_cons = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.targets.simpleserial_readers", True, False)
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]

        self.keylength = 16
        self.textlength = 16
        self.outputlength = 16
        self.input = ""
        self.key = ""
        self._protver = 'auto'
        self._read_timeout = 500
        self.maskEnabled = False
        self.masklength = 18
        self._fixedMask = True
        self.initmask = '1F 70 D6 3C 23 EB 1A B8 6A D5 E2 0D 5F D9 58 A3 CA 9D'
        self._mask = util.hexStrToByteArray(self.initmask)
        self.protformat = 'hex'

        # Preset lists are in the form
        # {'Dropdown Name':['Init Command', 'Load Key Command', 'Load Input Command', 'Go Command', 'Output Format']}
        # If a command is None, it's left unchanged and the text field is editable;
        # Otherwise, it's loaded with the value and set to readonly
        self.presets = {
            'Custom': [None, None, None, None, None],
            'SimpleSerial Encryption':
            ['', 'k$KEY$\\n', '', 'p$TEXT$\\n', 'r$RESPONSE$\\n'],
            'SimpleSerial Authentication': [
                '', 'k$KEY$\\n', 't$EXPECTED$\\n', 'p$TEXT$\\n',
                'r$RESPONSE$\\n'
            ],
            'Glitching': [None, None, None, None, '$GLITCH$\\n'],
        }
        self._preset = 'Custom'

        self._linkedmaskgroup = (('maskgroup', 'cmdmask'),
                                 ('maskgroup', 'initmask'), ('maskgroup',
                                                             'masktype'),
                                 ('maskgroup', 'masklen'), ('maskgroup',
                                                            'newmask'))
        self.params.addChildren([
            {
                'name': 'Connection',
                'type': 'list',
                'key': 'con',
                'values': ser_cons,
                'get': self.getConnection,
                'set': self.setConnection
            },
            {
                'name': 'Key Length (Bytes)',
                'type': 'list',
                'values': [8, 16, 32],
                'get': self.keyLen,
                'set': self.setKeyLen
            },
            {
                'name': 'Input Length (Bytes)',
                'type': 'list',
                'values': [1, 2, 4, 8, 16, 32],
                'default': 16,
                'get': self.textLen,
                'set': self.setTextLen
            },
            {
                'name': 'Output Length (Bytes)',
                'type': 'list',
                'values': [8, 16, 32],
                'default': 16,
                'get': self.outputLen,
                'set': self.setOutputLen
            },
            # {'name':'Plaintext Command', 'key':'ptcmd', 'type':'list', 'values':['p', 'h'], 'value':'p'},
            {
                'name':
                'Protocol Version',
                'key':
                'proto',
                'type':
                'group',
                'expanded':
                True,
                'children': [
                    {
                        'name': 'Version',
                        'key': 'ver',
                        'type': 'list',
                        'values': ['1.0', '1.1', 'auto'],
                        'value': 'auto'
                    },
                    {
                        'name': 'Timeout (ms)',
                        'key': 'timeout',
                        'type': 'int',
                        'value': 20,
                        'range': (0, 500),
                        'step': 1
                    },
                ]
            },
            {
                'name': 'Read timeout (ms)',
                'key': 'timeout',
                'type': 'int',
                'get': self.readTimeout,
                'set': self.setReadTimeout,
                'range': (0, 5000),
                'step': 1
            },
            {
                'name': 'Preset Mode',
                'key': 'preset',
                'type': 'list',
                'values': self.presets,
                'get': self.getPreset,
                'set': self.setPreset
            },
            {
                'name': 'Init Command',
                'key': 'cmdinit',
                'type': 'str',
                'value': ''
            },
            {
                'name': 'Load Key Command',
                'key': 'cmdkey',
                'type': 'str',
                'value': 'k$KEY$\\n'
            },
            {
                'name': 'Load Input Command',
                'key': 'cmdinput',
                'type': 'str',
                'value': ''
            },
            {
                'name': 'Go Command',
                'key': 'cmdgo',
                'type': 'str',
                'value': 'p$TEXT$\\n'
            },
            {
                'name': 'Output Format',
                'key': 'cmdout',
                'type': 'str',
                'value': 'r$RESPONSE$\\n'
            },
            {
                'name':
                'Mask',
                'key':
                'maskgroup',
                'type':
                'group',
                'expanded':
                True,
                'children': [
                    {
                        'name': 'Mask Supported',
                        'key': 'maskenabled',
                        'type': 'bool',
                        'get': self.getMaskEnabled,
                        'set': self.setMaskEnabled,
                        'linked': self._linkedmaskgroup,
                        'action': self.changeMaskEnabled
                    },
                    {
                        'name': 'Mask Length (Bytes)',
                        'key': 'masklen',
                        'type': 'list',
                        'values': [18],
                        'default': 18,
                        'get': self.maskLen,
                        'set': self.setMaskLen,
                        'visible': self.getMaskEnabled()
                    },
                    {
                        'name': 'Load Mask Command',
                        'key': 'cmdmask',
                        'type': 'str',
                        'value': 'm$MASK$\\n',
                        'visible': self.getMaskEnabled()
                    },
                    {
                        'name': 'Mask Type',
                        'key': 'masktype',
                        'type': 'list',
                        'values': {
                            'Random': False,
                            'Fixed': True
                        },
                        'get': self.getMaskType,
                        'set': self.setMaskType,
                        'visible': self.getMaskEnabled(),
                        'action': self.changeMaskType
                    },
                    {
                        'name': 'Fixed Mask',
                        'key': 'initmask',
                        'type': 'str',
                        'get': self.getInitialMask,
                        'set': self.setInitialMask,
                        'visible': self.getMaskEnabled()
                        and self.getMaskType()
                    },
                    {
                        'name': 'New Random Mask',
                        'key': 'newmask',
                        'type': 'action',
                        'action': self.newRandMask,
                        'visible': self.getMaskEnabled()
                        and self.getMaskType()
                    },
                ]
            },
            {
                'name':
                'Protocol format',
                'type':
                'list',
                'values': ['bin', 'hex'],
                'get':
                self.protFormat,
                'set':
                self.setProtFormat,
                'help':
                "Assume the protocol to be in the given format. The original SimpleSerial module assumed that the keys where to be sent in hex format but in some situations it is needed to conver the contents to a binary string representation"
            }
            #{'name':'Data Format', 'key':'datafmt', 'type':'list', 'values':{'DEADBEEF':'',
            #                                                                 'DE AD BE EF':' ',
            #                                                                 'DE:AD:BE:EF':':',
            #                                                                 'DE-AD-BE-EF':'-'}, 'value':''},
        ])

        self.outstanding_ack = False

        self.setConnection(self.ser, blockSignal=True)
        self.disable_newattr()