DPA contests home

Tools

Tools

Attack wrapper for Unix (Linux / Mac OS X / BSD...) and Windows

Introduction

The attack wrapper is a tool used to run and evaluate an attack. It is designed to be run on any Unix-like operating system such as Linux, Mac OS X, etc., and Windows. With this tool, you can develop your attack using almost any programming language (C, C++, Python, Perl...), or using Matlab.

Some other tools are included with the wrapper:

Download

The current version of the wrapper is 2.2.0 (released on July 10, 2015). It can be downloaded:

To use the wrapper, you will also have to download some traces and the corresponding index file.

Requirements

In order to be able to install and use the tools, you need:

Installation on Unix

To install the tools, open a terminal, go to the directory where you have downloaded the wrapper and type the following commands:

$ tar xzf attack_wrapper-2.2.0.tar.gz
$ cd attack_wrapper-2.2.0
$ ./configure
$ make

If everything went fine, three executable files (attack_wrapper, compute_results and traces2text) are available in the directory src. You can leave them and execute them from there or you can install them to a standard location on your system (you may need superuser privileges to perform this operation) by using the command make install.

Installation on Windows

To install the tools, you just have to unzip the archive where you want. The archive contains three pre-compiled binaries: attack_wrapper.exe, compute_results.exe and traces2text.exe.

Attack templates

Templates for developing attacks are available, for the different editions of the contest and for different languages (C, C#, Matlab...), inside the directory examples.

Use

The attack wrapper is a command line tool (even in Windows). To list all the available parameters, type (on Unix):

$ attack_wrapper --help

and on Windows:

$ attack_wrapper.exe --help

The following parameters are mandatory:

The following parameters are optional:

Some options are specific to some editions of the contest:

Examples of use:

$ attack_wrapper -i 20000 -k 0 -o results_k0 -d DPA_contest2_public_base_diff_vcc_a128_2009_12_23 -x DPA_contest2_public_base_index_file -e v2 ./attack_program
$ attack_wrapper -d DPA_contestv4_rsm -x dpav4_rsm_index -e v4_RSM fifo

Once you have one or several results files, you can give them to the tool compute_results (provided with the attack wrapper) that computes the different evaluation metrics. The results are written to several files. (replace compute_results by compute_results.exe on Windows)

$ compute_results results_k0 results_k1

Communication protocol with the attack

The wrapper and the attack exchange data using the following protocol.

If the wrapper uses the fork mode (the default mode on Unix), the wrapper launches by itself the attack and redirects the attack's standard input (stdin or file descriptor 0) and standard output (stdout or file descriptor 1) to communicate. So, from the point of view of the attack, a read from its standard input retrieves information from the wrapper and a write to its standard output sends information to the wrapper.

If the wrapper uses the FIFO mode (if launches with -f or --fifo, or on Windows), the wrapper creates two special files (two fifos or pipes) to communicate with the attack. The attack must be launched manually and must open these two files (on Unix: xxx_from_wrapper in read-only mode and xxx_to_wrapper in write-only mode; on Windows: \\.\pipe\xxx_from_wrapper in read-only mode and \\.\pipe\xxx_to_wrapper in write-only mode). Next, to read data from the wrapper, the attack just have to read from the file xxx_from_wrapper (or \\.\pipe\xxx_from_wrapper on Windows) and to send data to the wrapper, the attack just have to write to the file xxx_to_wrapper (or \\.\pipe\xxx_to_wrapper on Windows). xxx is replace with the last argument on the command line of the wrapper.

For all data transfer, when the data to transfer is larger than a byte (8 bits), the endianness of the transfer is little-endian (i.e. the Least Significant Byte is transferred first).

When the attack starts, the wrapper first send 4 bytes (exact C type: uint32_t, i.e. unsigned integer) representing the number of traces that the wrapper will send to the attack during this execution. If the wrapper is launched with the option --compatibility_v2, the wrapper on sends 2 bytes instead of 4 (to keep the compatibility with the previous version of the protocol).

Next, when the attack is ready, it send the 3 following bytes to the wrapper: 0x0A 0x2E 0x0A.

Next, the wrapper sends a trace to the attack and the attack sends a result to the wrapper. This phase is repeated as many times as there are traces.

The exact representation of the traces and of the results depends on the edition of the contest (the wrapper is able to manage the different editions and implementations of the contest).

Edition Trace structure Results structure
v2
  • 16 unsigned bytes representing the plaintext
  • 16 unsigned bytes representing the ciphertext
  • 2 * 3,253 signed byte representing the 3,253 samples of the trace, each sample is represented by two bytes (int16_t)
  • 1 unsigned byte representing the subkey targeted by the attack (0 represents the subkey used during the first round of the AES, see the FAQ for more details)
  • 256 unsigned bytes representing the 256 possible values for the first byte of the targeted subkey ranked from the most probable to the least probable
  • 256 unsigned bytes representing the 256 possible values for the second byte of the targeted subkey ranked from the most probable to the least probable
  • ...
  • 256 unsigned bytes representing the 256 possible values for the 16th byte of the targeted subkey ranked from the most probable to the least probable
v4 RSM
  • 16 unsigned bytes representing the plaintext
  • 16 unsigned bytes representing the ciphertext
  • 1 unsigned byte representing the offset (always 0 unless the wrapper is launched with the option --provide_offset_v4_rsm)
  • 435,002 signed byte representing the 435,002 samples of the trace
  • 1 unsigned byte representing the subkey targeted by the attack (0 represents the subkey used during the first round of the AES, see the FAQ for more details)
  • 256 unsigned bytes representing the 256 possible values for the first byte of the targeted subkey ranked from the most probable to the least probable
  • 256 unsigned bytes representing the 256 possible values for the second byte of the targeted subkey ranked from the most probable to the least probable
  • ...
  • 256 unsigned bytes representing the 256 possible values for the 16th byte of the targeted subkey ranked from the most probable to the least probable
v4 2
  • 16 unsigned bytes representing the plaintext
  • 16 unsigned bytes representing the ciphertext
  • 16 unsigned bytes representing the Shuffle0 permutation (always 0...0 unless the wrapper is launched with the option --provide_offsets_v4_2)
  • 16 unsigned bytes representing the Shuffle10 permutation (always 0...0 unless the wrapper is launched with the option --provide_offsets_v4_2)
  • 16 unsigned bytes representing the offsets (always 0...0 unless the wrapper is launched with the option --provide_offsets_v4_2)
  • 1,704,402 32-bit floats representing the 1,704,402 samples of the trace (1,704,402 signed bytes if the option --no_float_format is provided)
  • 1 unsigned byte representing the subkey targeted by the attack (0 represents the subkey used during the first round of the AES, see the FAQ for more details)
  • 256 unsigned bytes representing the 256 possible values for the first byte of the targeted subkey ranked from the most probable to the least probable
  • 256 unsigned bytes representing the 256 possible values for the second byte of the targeted subkey ranked from the most probable to the least probable
  • ...
  • 256 unsigned bytes representing the 256 possible values for the 16th byte of the targeted subkey ranked from the most probable to the least probable