As of August 2020 the site you are on ( is deprecated, and content is now at

Profiling Attacks with Neural Networks

From ChipWhisperer Wiki
Revision as of 11:05, 1 June 2016 by Gdeon (Talk | contribs) (Made page)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Template Attacks allow cryptography implementations to be attacked with very few assumptions about the code that is being run. These attacks use (hundreds of) thousands of traces to build some kind of statistical model, which describes how much power a device uses at various points in time. Then, to complete the attack, real power traces are compared to this model, allowing an attacker to find the secret key from a small number of traces. For a walkthrough of how to perform a template attack, check out Tutorial B8 Profiling Attacks (Manual Template Attack).

A multivariate probability distribution is not the only way of modelling a device's power distribution. One idea is to train a neural network (or a multilayer perceptron) to label traces. This is a classic example of a supervised learning problem:

  • We have a large amount of training inputs (traces) with known target outputs (the key values, or the Hamming weights coming out of the AES sbox, or...). These make up the training dataset, which we can use to train the neural network. Since we know the desired outputs, this learning process is supervised.
  • After the network is trained, we have a small number of traces which are not labeled - we don't know the key values that they are associated with. We can use the neural network to classify these inputs, which will give us our known key values or Hamming weights to complete the attack.

Some very recent research has investigated how machine learning techniques can be used to assist in these side-channel attacks. For example, Lerman, Bontempi, and Markowitch presented "Side channel attack: an approach based on machine learning" at COSADE 2011, where they discussed the several machine learning techniques and their applicability to template attacks. 3 years later, Martinsek and Malina published "Comparison of Profiling Power Analysis Attacks Using Templates and Multi-Layer Perceptron Network" in Mathematical Methods in Science and Engineering 2014, comparing the performance of a standard template attack to this new neural network method. They concluded that the machine learning methods could not outperform the existing template attacks, but the success rates were fairly close.

To test how easily these neural networks could classify input traces, a short experiment was run. 2000 traces (from Tutorial B8 Profiling Attacks (Manual Template Attack)) were used to train a feedforward neural network (from here). After 20 minutes of training, the network was still showing large errors - it did not have any ability to classify traces. The experiment was stopped here - template attacks could produce better results in a small fraction of the time.

Python script used for experiment:

# Train a neural network to classify traces with their sbox hamming weight

import numpy as np
import matplotlib.pyplot as plt
from net import Net

# Useful utilities
hw = [bin(x).count("1") for x in range(256)]

# Build profile
# 1: Load data
tempTraces = np.load(r'rand_key_data\traces\2016.05.24-12.53.15_traces.npy')
tempPText  = np.load(r'rand_key_data\traces\2016.05.24-12.53.15_textin.npy')
tempKey    = np.load(r'rand_key_data\traces\2016.05.24-12.53.15_keylist.npy')

numTraces = len(tempTraces)
traceLength = len(tempTraces[0])

# 1.5: split up traces into training and validation
numTraining = int(numTraces * 0.50)
numValidation = numTraces - numTraining

# 2: Calculate Hamming weight of sbox outputs
tempSbox = [sbox[tempPText[i][0] ^ tempKey[i][0]] for i in range(len(tempPText))] 
tempHW   = [hw[s] for s in tempSbox]
# 3: Build training dataset
output = np.zeros([len(tempTraces), 9]) # One-hot signals
for i in range(numTraces):
    output[i, tempHW[i]] = 1
# 4: Try to make classifier
inputRange = [-1, 1]
POIs = [1397, 1345, 1364, 1353, 2113]

net = Net([inputRange]*len(POIs), 20, 9)
net.train_many(tempTraces[0:numTraining, POIs], output[0:numTraining], 0.01, 2000, 0.001*numTraining, True)

# 5: Test it
for i in range(numTraining, numTraining+300):
    print net.sim(tempTraces[i, POIs])
    print output[i]