|
| 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. |
0 commit comments