Skip to content

Commit dd83686

Browse files
committed
howto and minor fixes
1 parent b64b310 commit dd83686

9 files changed

+146
-10
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# configuration for git-lfs
22
traces/*.trs filter=lfs diff=lfs merge=lfs -text
33
traces/*.npz filter=lfs diff=lfs merge=lfs -text
4+
howto/*.png filter=lfs diff=lfs merge=lfs -text

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22

33
This toolbox was started in 2014 to experiment with efficient differential power analysis (DPA) techniques from the paper "Behind the Scene of Side Channel Attacks" by Victor Lomné, Emmanuel Prouff, and Thomas Roche (https://eprint.iacr.org/2013/794).
44

5-
The toolox can do:
6-
* non-profiled linear-regression analysis (LRA)
5+
The toolbox was designed with the following in mind:
6+
* state-of-the-art DPA techniques
7+
* performance
8+
* visualization of metrics for security evaluations purpose (and not just attack)
9+
* simplicity and flexibility through use of a scientific computing suitable language
10+
11+
In terms of these points, Pysca (still) outperforms some commercial tooling. Pysca is nowadays mostly superseded by https://github.com/Riscure/Jlsca.
12+
13+
Pysca implements:
14+
* non-profiled linear-regression analysis (LRA) with configurable basis functions
715
* classical correlation power analysis (CPA)
8-
* speed-up of the above by conditional averaging
9-
* AES (S-box out) and DES (round in XOR round out, round out, S-box out)
16+
* significant speed-up of the above by conditional averaging
17+
* targets: AES (S-box out) and DES (round in XOR round out, round out, S-box out)
1018
* visualization of results
1119

12-
It works on traces converted from trs format into numpy npz. The conversion script is included. The trs reader was originally implemented by Erik van den Brink.
13-
14-
Pysca runs under python 2.7, numpy 1.12.1, matplotlib 2.0.2. See project wiki for usage examples. The example traces are included in the repo using git-lfs.
20+
Pysca works on traces stored in npz (numpy zipped) format. Example tracesets are included in the repo using git-lfs. The conversion script from Riscure Inspector trs format is included. The trs reader was originally implemented by Erik van den Brink.
1521

16-
Pysca is mostly superseded by https://github.com/Riscure/Jlsca.
22+
Pysca requires python 2.7 with packages numpy, matplotlib, and optionally jupyter. See [HOWTO](howto/HOWTO.md) for usage basics.
1723

18-
Author: Ilya Kizhvatov
24+
Under the hood, the most interesting technical tricks in pysca are perhaps:
25+
* fast computation of correlation (see https://github.com/ikizhvatov/efficient-columnwise-correlation for a dedicated study)
26+
* conditional averaging implementation for DES (because of all the bit permuations, it requires splitting the leakage function into two stages)
1927

28+
Author: Ilya Kizhvatov<br>
2029
Version: 1.0, 2017-05-14

attackaessbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
### 0. Configurable parameters
2727

2828
## Traceset, number of traces, and S-box to attack
29-
tracesetFilename = "traces/swaes_atmega_powertraces.npz"
29+
tracesetFilename = "traces/swaes_atmega_power.npz"
3030
sampleRange = (800, 1500) # range of samples to attack, in the format (low, high)
3131
N = 100 # number of traces to attack (less or equal to the amount of traces in the file)
3232
offset = 0 # trace number to start from

howto/HOWTO.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Pysca toolbox HOWTO
2+
3+
This is a walkthrough showing how to put pysca in action with the provided example tracesets. It does not go deep under the hood; if you like that, the best way is to dive into the code starting from the scripts used here.
4+
5+
## Environment setup
6+
7+
Pysca needs python 2.7 with numpy and matplotlib, and jupyter if you like to work with notebook format in a browser. Here is how to create a minimal environment for pysca with Anaconda python distribution in Linux and activate it:
8+
9+
elbrus:pysca ilya$ conda create --name py27min python=2.7 numpy matplotlib jupyter
10+
[... all the conda printouts will be here ..]
11+
elbrus:pysca ilya$ source activate py27min
12+
(py27min) elbrus:pysca ilya$
13+
14+
Note that Anaconda provides numpy built against Intel MKL (Math Kernel Library), which is essential for performance. If you use other python dstribution, ensure that you use numpy-MKL.
15+
16+
## Traceset conversion
17+
18+
Convert an example set of power traces obtained from a software AES running on an ATmega microcontroller.
19+
20+
(py27min) elbrus:pysca ilya$ python trs2npz.py traces\swaes_atmega_power
21+
Number of traces: 2000
22+
Samples per trace: 2800
23+
Samples datatype: int8
24+
Data bytes: 16
25+
Trace block size:
26+
Header size:
27+
Preallocating arrays
28+
Populating arrays
29+
Saving file
30+
Done
31+
32+
## CPA and LRA attacks on SW AES
33+
34+
For this example we will use the commad line script. Execute the script that performs the attacks, recovering a single key byte.
35+
36+
(py27min) elbrus:pysca ilya$ attackaessbox.py
37+
---
38+
Attack parameters
39+
Intermediate function : sBoxOut
40+
CPA leakage function : leakageModelHW
41+
LRA basis functions : basisModelSingleBits
42+
Encryption : True
43+
S-box number : 2
44+
Known key : 0x2b7e151628aed2a6abf7158809cf4f3c
45+
Known roundkey : 0x2b7e151628aed2a6abf7158809cf4f3c
46+
---
47+
Loading traces/swaes_atmega_power.npz
48+
Number of traces loaded : 100
49+
Trace length : 700
50+
Loading time : 0.03 s
51+
---
52+
Attack
53+
ConditionalAverager: initialized for 256 values and trace length 700
54+
---
55+
Results after 20 traces
56+
CPA
57+
Winning candidate: 0xd3, peak magnitude 0.827157
58+
Correct candidate: 0x15, peak magnitude 0.748879, rank 22
59+
LRA
60+
Winning candidate: 0x7d, peak magnitude 0.951581
61+
Correct candidate: 0x15, peak magnitude 0.884216, rank 50
62+
---
63+
[...]
64+
Results after 100 traces
65+
CPA
66+
Winning candidate: 0x15, peak magnitude 0.481228
67+
Correct candidate: 0x15, peak magnitude 0.481228, rank 1
68+
LRA
69+
Winning candidate: 0x15, peak magnitude 0.512743
70+
Correct candidate: 0x15, peak magnitude 0.512743, rank 1
71+
---
72+
Cumulative timing
73+
24.56 s
74+
---
75+
Plotting...
76+
77+
Observe the result visualization. The plots show results of CPA (correlation traces) and LRA (R2 traces and matrix of basis fucntion coefficients characterising the leakage function) for the maximum amonut of traces, and evolution of the correct key candidate rank with the increasing amount of traces.
78+
79+
<img src="howto-script-aes-result.png" width="640">
80+
81+
The parameters of the attack can be adjusted in the configuration section of the script.
82+
83+
## CPA and LRA attack on HW DES
84+
85+
For this example, we will use another (convenient) way to work: a Jupyter noteboook in a browser. Launch the notebook server:
86+
87+
(py27min) elbrus:pysca ilya$ jupyter notebook
88+
[I 13:15:38.823 NotebookApp] Serving notebooks from local directory: /Users/ilya/pysca
89+
[I 13:15:38.823 NotebookApp] 0 active kernels
90+
[I 13:15:38.824 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=a75f5aa53be646d4a96bedc760728c9baea3a3a72b9111be
91+
[I 13:15:38.824 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
92+
93+
You will see the browser poping up with the directory contents, with two .ipynb notebooks.
94+
95+
<img src="howto-notebooks.png" width="640">
96+
97+
Open the notebook with the attack on DES round XOR.
98+
99+
<img src="howto-notebook-des.png" width="640">
100+
101+
The code in the notebook is arranged in cells. Here is the cell with attack settings:
102+
103+
<img src="howto-notebook-des-settings.png" width="640">
104+
105+
The example traceset comes in npz format. Execute cells one-by-one and get an attack result plot in-line.
106+
107+
<img src="howto-notebook-des-result.png" width="640">
108+
109+
This is the instantaneous attack result. To see the evolution, you can proceed with the following cells.
110+
111+
This is it so far for the basics.

howto/howto-notebook-des-result.png

Lines changed: 3 additions & 0 deletions
Loading

howto/howto-notebook-des-settings.png

Lines changed: 3 additions & 0 deletions
Loading

howto/howto-notebook-des.png

Lines changed: 3 additions & 0 deletions
Loading

howto/howto-notebooks.png

Lines changed: 3 additions & 0 deletions
Loading

howto/howto-script-aes-result.png

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)