How to use the chipwhisperer.common.utils.util.camel_case_deprecated function in chipwhisperer

To help you get started, we’ve selected a few chipwhisperer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github newaetech / chipwhisperer / software / chipwhisperer / common / api / TraceManager.py View on Github external
"""Save the trace segments information to a project file."""
        config[self.name].clear()
        for indx, t in enumerate(self.traceSegments):
            starttime = datetime.now()
            prefix = starttime.strftime('%Y.%m.%d-%H.%M.%S') + "_"
            t.config.setConfigFilename(os.path.splitext(configfilename)[0] + "_data" + "/traces/config_" + prefix + ".cfg")
            t.config.setAttr("prefix", prefix)
            t.config.setAttr("date", starttime.strftime('%Y-%m-%d %H:%M:%S'))
            config[self.name]['tracefile%d' % indx] = os.path.normpath(os.path.relpath(t.config.configFilename(), os.path.split(configfilename)[0]))
            config[self.name]['enabled%d' % indx] = str(t.enabled)

            t.saveAllTraces(os.path.dirname(t.config.configFilename()), prefix)
        self.dirty.setValue(False)
        self.saved = True

    saveProject = util.camel_case_deprecated(save_project)

    def loadProject(self, configfilename):
        """Load the trace segments information from a project file."""
        config = configparser.RawConfigParser()
        config.read(configfilename)
        alltraces = config.items(self.name)
        self.newProject()

        fdir = os.path.split(configfilename)[0] + "/"

        for t in alltraces:
            if t[0].startswith("tracefile"):
                fname = fdir + t[1]
                fname = os.path.normpath(fname.replace("\\", "/"))
                # print "Opening %s"%fname
                ti = TraceContainerNative()
github newaetech / chipwhisperer / software / chipwhisperer / common / api / TraceManager.py View on Github external
sr = int(float(t.config.attr("scopeSampleRate")))
                if self._sampleRate != sr and sr != 0:
                    if self._sampleRate == 0:
                        self._sampleRate = sr
                    else:
                        logging.warning("Selected trace segments have different sample rates: %d!=%d" % (self._sampleRate, sr))
            else:
                t.mappedRange = None
        self._numTraces = startTrace

    def num_points(self):
        """Return the number of points in traces of the selected segments."""
        return self._numPoints

    numPoints = util.camel_case_deprecated(num_points)

    def num_traces(self):
        """Return the number of traces in the current list of enabled segments."""
        return self._numTraces

    numTraces = util.camel_case_deprecated(num_traces)

    def appendSegment(self, ti, enabled=True):
        """Append a new segment to the list of trace segments."""
        ti.enabled = enabled
        ti._isloaded = True
        self.traceSegments.append(ti)
        self._setModified()

    def _setModified(self):
        """Notify passive and active observers to be updated."""
github newaetech / chipwhisperer / software / chipwhisperer / analyzer / attacks / _base.py View on Github external
if rng[1] < 0:
            ts = self.getTraceSource()
            if ts is None:
                raise ValueError("traceSource not yet set in attack - set TraceSource first to use automatic setPointRange")
            rng = (rng[0], ts.num_points())
        self._pointRange = rng

    setPointRange = camel_case_deprecated(set_point_range)
    def known_key(self):
        """Get the known key via attack"""
        key = self.process_known_key(self.getTraceSource().get_known_key(self.get_trace_start()))
        if key is None:
            key = [None] * len(self.get_statistics().diffs)
        return key

    knownKey = camel_case_deprecated(known_key)
    def set_target_subkeys(self, blist):
        self._targetSubkeys = blist

    setTargetSubkeys = camel_case_deprecated(set_target_subkeys)
    def get_target_subkeys(self):
        return self._targetSubkeys

    getTargetSubkeys = camel_case_deprecated(get_target_subkeys)

    def __del__(self):
        if __debug__: logging.debug('Deleted: ' + str(self))

    def getAbsoluteMode(self):
        return self.useAbs

    def refreshByteList(self, _=None):
github newaetech / chipwhisperer / software / chipwhisperer / analyzer / attacks / _stats.py View on Github external
self.maxes_list = [list() for i in range(0, self.numSubkeys)]

        #TODO: Ensure this gets called by attack algorithms when rerunning

    def simple_PGE(self, bnum):
        if self.maxValid[bnum] == False:
            #TODO: should sort
            return 1
        return self.pge[bnum]

    simplePGE = camel_case_deprecated(simple_PGE)

    def set_known_key(self, knownkey):
        self.knownkey = knownkey

    setKnownkey = camel_case_deprecated(set_known_key)

    def update_subkey(self, bnum, data, copy=True, forceUpdate=False, tnum=None):
        if (id(data) != id(self.diffs[bnum])) or forceUpdate:
            self.maxValid[bnum] = False

            if data is not None and copy:
                self.diffs[bnum] = data[:]
                self.diffs_tnum[bnum] = tnum
            else:
                self.diffs[bnum] = data
                self.diffs_tnum[bnum] = tnum

    updateSubkey = camel_case_deprecated(update_subkey)
    def find_maximums(self, bytelist=None, useAbsolute=True, useSingle=False):
        if bytelist is None:
            bytelist = list(range(0, self.numSubkeys))
github newaetech / chipwhisperer / software / chipwhisperer / capture / scopes / OpenADC.py View on Github external
"""
        if not self.adc.stream_mode:
            return self.qtadc.capture(self.adc.offset)
        else:
            return self.qtadc.capture(None)
        return ret

    def get_last_trace(self):
        """Return the last trace captured with this scope.

        Returns:
           Numpy array of the last capture trace.
        """
        return self.qtadc.datapoints

    getLastTrace = util.camel_case_deprecated(get_last_trace)

    def _dict_repr(self):
        dict = OrderedDict()
        dict['gain']    = self.gain._dict_repr()
        dict['adc']     = self.adc._dict_repr()
        dict['clock']   = self.clock._dict_repr()
        dict['trigger'] = self.trigger._dict_repr()
        dict['io']      = self.io._dict_repr()
        dict['glitch']  = self.glitch._dict_repr()
        if self._getCWType() == "cw1200":
            dict['SAD'] = self.SAD._dict_repr()
            dict['decode_IO'] = self.decode_IO._dict_repr()

        return dict

    def __repr__(self):
github newaetech / chipwhisperer / software / chipwhisperer / common / api / TraceManager.py View on Github external
return {'cfgdata':cfg, 'filedata':filedata}

    def get_trace(self, n):
        """Return the trace with index n in the list of enabled segments"""
        t = self.get_segment(n)
        return t.getTrace(n - t.mappedRange[0])

    getTrace = util.camel_case_deprecated(get_trace)

    def get_textin(self, n):
        """Return the input text of trace with index n in the list of enabled segments"""
        t = self.get_segment(n)
        return t.getTextin(n - t.mappedRange[0])

    getTextin = util.camel_case_deprecated(get_textin)

    def get_textout(self, n):
        """Return the output text of trace with index n in the list of enabled segments"""
        t = self.get_segment(n)
        return t.getTextout(n - t.mappedRange[0])

    getTextout = util.camel_case_deprecated(get_textout)

    def get_known_key(self, n):
        """Return the known encryption key."""
        try:
            t = self.get_segment(n)
            return t.getKnownKey(n - t.mappedRange[0])
        except ValueError:
            return []
github newaetech / chipwhisperer / software / chipwhisperer / __init__.py View on Github external
filename (str): Path to project file.

    Returns:
       A chipwhisperer project object.

    Raises:
       OSError: filename does not exist.
    """
    filename = project.ensure_cwp_extension(filename)

    proj = project.Project()
    proj.load(filename)
    return proj


openProject = camel_case_deprecated(open_project)


def create_project(filename, overwrite=False):
    """Create a new project with the path .

    If  is False, raise an OSError if this path already exists.

    Args:
       filename (str): File path to create project file at. Must end with .cwp
       overwrite (bool, optional): Whether or not to overwrite an existing
           project with . Raises an OSError if path already exists
           and this is false. Defaults to false.

    Returns:
       A chipwhisperer project object.
github newaetech / chipwhisperer / software / chipwhisperer / common / api / TraceManager.py View on Github external
"""Return data about a segment"""
        t = self.get_segment(n)
        cfg = t.getAuxDataConfig(auxDic)
        if cfg is not None:
            filedata = t.loadAuxData(cfg["filename"])
        else:
            filedata = None

        return {'cfgdata':cfg, 'filedata':filedata}

    def get_trace(self, n):
        """Return the trace with index n in the list of enabled segments"""
        t = self.get_segment(n)
        return t.getTrace(n - t.mappedRange[0])

    getTrace = util.camel_case_deprecated(get_trace)

    def get_textin(self, n):
        """Return the input text of trace with index n in the list of enabled segments"""
        t = self.get_segment(n)
        return t.getTextin(n - t.mappedRange[0])

    getTextin = util.camel_case_deprecated(get_textin)

    def get_textout(self, n):
        """Return the output text of trace with index n in the list of enabled segments"""
        t = self.get_segment(n)
        return t.getTextout(n - t.mappedRange[0])

    getTextout = util.camel_case_deprecated(get_textout)

    def get_known_key(self, n):
github newaetech / chipwhisperer / software / chipwhisperer / analyzer / attacks / models / AES128_8bit.py View on Github external
return self.HW[intermediate_value]

    def key_schedule_rounds(self, inputkey, inputround, desiredround):
        """Changes the round of inputkey from inputround to desiredround

        Args:
            inputkey (list): key that you want to change the round of
            inputround (int): Round that inputkey is currently in
            desiredround (int): Round that you want inputkey to be in

        Returns:
            desired key (list)
        """
        return key_schedule_rounds(inputkey, inputround, desiredround)

    keyScheduleRounds = camel_case_deprecated(key_schedule_rounds)
github newaetech / chipwhisperer / software / chipwhisperer / analyzer / preprocessing / _base.py View on Github external
    @enabled.setter
    def enabled(self, en):
        if not isinstance(en, bool):
            raise TypeError("Expected bool; got %s" % type(en), en)
        self._setEnabled(en)

    def get_trace(self, n):
        """Get trace number n"""
        if self.enabled:
            trace = self._traceSource.getTrace(n)
            # Do your preprocessing here
            return trace
        else:
            return self._traceSource.getTrace(n)

    getTrace = camel_case_deprecated(get_trace)
    def get_textin(self, n):
        """Get text-in number n"""
        return self._traceSource.getTextin(n)

    getTextin = camel_case_deprecated(get_textin)

    def get_textout(self, n):
        """Get text-out number n"""
        return self._traceSource.getTextout(n)

    getTextout = camel_case_deprecated(get_textout)

    def get_known_key(self, n=None):
        """Get known-key number n"""
        return self._traceSource.getKnownKey(n)