ANSSI-FR / ASCAD

Side Channels Analysis and Deep Learning
Other
179 stars 60 forks source link

About

ASCAD (ANSSI SCA Database) is a set of databases that aims at providing a benchmarking reference for the SCA community: the purpose is to have something similar to the MNIST database that the Machine Learning community has been using for quite a while now to evaluate classification algorithms performance.

This repository provides scripts and Deep Learning models that demonstrate the efficiency of Deep Learning for SCA.

Several databases are available, depending on the underlying implementation and architecture. More information is available in the corresponding folders:

Copyright and license

Copyright (C) 2021, ANSSI and CEA

The databases, the Deep Learning models and the companion python scripts of this repository are placed under the BSD licence. Please check the LICENSE file for more information.

Getting the ASCAD databases and the trained models

Quick start guide

The scripts and the data are split in two places mainly because git is not suited for large files.

In order to get everything up and running, here are the steps to follow (we provide the steps using a Unix shell syntax, but you can adapt this and use your favorite shell of course):

  1. Clone the current repository to get the scripts:
git clone https://github.com/ANSSI-FR/ASCAD.git
  1. Click on the link corresponding to the chosen campaign and follow the instructions to download and unpack the database.
Implementation Campaign Type Link
ATMEGA boolean masked AES fixed key Power (Icc) link
ATMEGA boolean masked AES variable key Power (Icc) link
STM32 affine masked AES variable key Power (Icc) link
  1. Install the last version of Tensorflow 2 for your platform. Some versions of Tensorflow require a specific version of CUDA, up-to-date and detailed information on the installation can be found here: https://www.tensorflow.org/install. You will also need Keras as the Tensorflow front end API companion.

  2. Now you should be able to use the provided python scripts. If you have the pip Python package manager installed, getting the scripts dependencies is as simple as:

    pip install numpy h5py matplotlib tqdm

    Our scripts now rely on Tensorflow 2, therefore we only support Python 3. If you want to continue to use Python 2, please refer to a previous version of the repository, for example checkouting commit 30f65bb. However you will not be able to run the scripts on our recent databases (STM32_AES_v2 and later).

ASCAD companion scripts

Required Python packages

In order to use ASCAD companion scripts, here is the list of dependencies that need to be installed in your python setup:

Note that these libraries are generally packaged in most of Linux distributions, and/or are available through the pip Python package manager. The case of the tensorflow library is a bit special since depending on the target platform, CPU or GPU acceleration may be configured and used or not. For ASCAD scripts, we strongly suggest (specifically for the profiling/training phase) to use a GPU backed configuration. Configuring tensorflow and GPU acceleration won't be detailed here: please refer to this and this resources for more details on the topic (you will also certainly need to handle Nvidia CUDA drivers and libraries for you platform).

Finally, please note that the scripts only work with Python 3 since we rely on tensorflow 2.

We propose hereafter a high-level description of the proposed scripts. The default parameters of these scripts vary with the downloaded campaign, and are provided as a file in the corresponding folders:

Implementation Campaign Platform Link
ATMEGA boolean masked AES fixed key Linux link
ATMEGA boolean masked AES variable key Linux link
STM32 affine masked AES variable key Linux link

Every script can be launched using the corresponding parameter file:

$ python ASCAD_generate.py path_to_parameters_file
$ python ASCAD_train_models.py path_to_parameters_file
$ python ASCAD_test_models.py path_to_parameters_file

It is easy to run these scripts on custom parameters, either by modifying the default values within the script, or by creating a new parameter file.

ASCAD generation

The ASCAD_generate.py script is used to generate ASCAD databases from any of the available raw traces database.

This script takes as an argument the name of a file containing a python dict with the following keys:

The labelize and multilabelize functions are also of interest in the script: tuning it enables to generate databases that focus on other leaking spots of the masked AES (say byte 5 of the first round, byte 10 of the second round, and so on ...).

By tuning all these parameters, one is able to generate multiple ASCAD databases specialized in various values of interest, with customized desynchronization as well as customized profiling and attacking traces.

Testing the trained models

The trained models can be tested using the ASCAD_test_models.py script.

The script computes the ranking of the real key byte among the 256 possible candidate bytes depending on the number of attack traces the trained model takes as input for prediction: this is a classical classification algorithm efficiency check in SCA (see the article "Study of Deep Learning Techniques for Side-Channel Analysis and Introduction to ASCAD Database" for a more formal definition of the keys ranking). The evolution of the rank with respect to the number of traces is plotted using matplotlib.

This script takes as an argument the name of a file containing a python dict with the following keys:

Training the models

We provide the ASCAD_train_models.py script in order to train the models. This script takes as an argument the name of a file containing a python dict with the following keys: