Discussions of performing power analysis, techniques, implementations, etc. Does not need to use ChipWhisperer.
#1489 by coflynn
Mon Aug 07, 2017 11:48 am
For anyone playing with RHME3, I thought I'd post some file conversion hints.

The default .mat file don't load in scipy.io it seems, so the example conversion utilities on the wiki are no good. A quick-n-dirty method of fixing this is to:

  1. Split the .mat file (it's text, open it in a text editor) into two text-files. The first contains the list of data (AFTER the header of '300 32') which can be loaded by numpy. The second file contains the other block of data which is in a slightly different format.
  2. Run the below script. It will create a directory 'rhme3'.
  3. Open ChipWhisperer analyzer, open the "Trace Manager", and then hit "Add Trace" (the + button). Point it at the generated .cfg file.

Code: Select allimport numpy as np
import ctypes
import os
from chipwhisperer.common.traces.TraceContainerNative import TraceContainerNative

ntraces = 300

inout = np.loadtxt('inout.txt')
traces = np.loadtxt('traces.txt')
inout = np.reshape(inout, (32, ntraces))
inout = inout.T

inp = np.uint8(inout[:, 0:16])
out = np.uint8(inout[:, 16:32])

#If you'd like to plot a trace to see it
from matplotlib.pylab import *
#plot(traces[0,:], 'r')
#plot(traces[1,:], 'b')
#show()

#Save as ChipWhisperer project
tc = TraceContainerNative()
for i in range(0, ntraces):
    tc.addWave(traces[i])
    tc.addTextin(inp[i])
    tc.addTextout(out[i])

    #Temp - add fake key info. Required on Linux possibly, will be fixed to avoid this. Be sure to turn
    #highlight key off to avoid being confused.
    tc.addKey([0]*16)

os.mkdir('rhme3')
tc.saveAllTraces('rhme3')
tc.config.setConfigFilename(r'rhme3\rhme.cfg')
tc.config.saveTrace()


EDIT: There is a short hack needed for now - open the .cfg file generated, and change the line:
Code: Select allprefix = None

to:
Code: Select allprefix =
.
The first line worked OK on Windows, but the Linux version failed. The real fix is a code patch but that work-around is good for now (or you can set a prefix as well solves the problem).
#1490 by coflynn
Mon Aug 07, 2017 12:20 pm
To actually recover the key, one may need to use features like SAD alignment, as you may notice the traces are slightly out of alignment if you plot several of them (i.e., 0-20).
#1498 by abhi
Sun Aug 13, 2017 11:09 am
Hi Colin,

I'm using the latest chipwisperer analyser from github develop branch (tried the pip one too).
It is working really good until I turn on SAD resync.
When I start the attack, getting the following error after a few seconds

Code: Select allCould not execute method run in script class UserScript: 'IndexError: too many indices for array:too many indices for array'


line number 56 [inside function oneSubkey] variable traces_all expected to be a multidimensional array [it is, if you disable SAD] but which is coming as a single dimensional array.

When I do print traces_all.shape in the the code, it is printing (10,) with SAD enabled, (10, 6095) with SAD disabled

In chipwhisperer/analyzer/attacks/cpa_algorithms/progressive.py
Code: Select all   
def oneSubkey(self, bnum, pointRange, traces_all, numtraces, plaintexts, ciphertexts, knownkeys, progressBar, state, pbcnt):
        diffs = [0] * self.model.getPermPerSubkey()
        self.totalTraces += numtraces

        if pointRange == None:
            traces = traces_all
            # padbefore = 0
            # padafter = 0
        else:
            try:
                print traces_all.shape
            except:
                pass
            traces = traces_all[:, pointRange[0] : pointRange[1]] # Exception here


Is that a bug, or am I missing something?

Thanks
#1506 by coflynn
Mon Aug 14, 2017 2:14 pm
Hello,

This sounds like it might be an invalid input range? Can you post your capture script (or just the proprocessing setup part).

When it fails to find matches it may do funky things.

Do the traces look OK without the preprocessing enabled?

-Colin
#1537 by ExMachina
Wed Aug 23, 2017 8:57 am
I found that scipy can read older version of the mat format so was able to do the following in octave.

load "traces.mat"
save -6 newtraces.mat

newtraces are now scipy compatible.
#1546 by icot
Sun Aug 27, 2017 10:49 am
Hello,

You get that error if you try to run the attack with the default SAD parameters (everything set to 0?). Once you vary the reference points and the window in the preprocessing setup it works ( although some combinations of values may still result in that error).

abhi wrote:Hi Colin,

I'm using the latest chipwisperer analyser from github develop branch (tried the pip one too).
It is working really good until I turn on SAD resync.
When I start the attack, getting the following error after a few seconds

Code: Select allCould not execute method run in script class UserScript: 'IndexError: too many indices for array:too many indices for array'


line number 56 [inside function oneSubkey] variable traces_all expected to be a multidimensional array [it is, if you disable SAD] but which is coming as a single dimensional array.

When I do print traces_all.shape in the the code, it is printing (10,) with SAD enabled, (10, 6095) with SAD disabled

In chipwhisperer/analyzer/attacks/cpa_algorithms/progressive.py
Code: Select all   
def oneSubkey(self, bnum, pointRange, traces_all, numtraces, plaintexts, ciphertexts, knownkeys, progressBar, state, pbcnt):
        diffs = [0] * self.model.getPermPerSubkey()
        self.totalTraces += numtraces

        if pointRange == None:
            traces = traces_all
            # padbefore = 0
            # padafter = 0
        else:
            try:
                print traces_all.shape
            except:
                pass
            traces = traces_all[:, pointRange[0] : pointRange[1]] # Exception here


Is that a bug, or am I missing something?

Thanks

Who is online

Users browsing this forum: No registered users and 2 guests