|capture hardware = CW-Lite, CW-Lite 2-Part, CW-Pro
|Target Device =
|Target Architecture = XMEGA
|Hardware Crypto = No
|Purchase Hardware =
# Using the AES-256 key schedule, reverse the 13th and 14th round keys to determine the original AES-256 encryption key.
Setting up the Hardware == This tutorial uses the [[CW1173 ChipWhisperer-Lite]] hardware. This hardware does not require any special setup - it should be ready to go out-of-the-box.
Note that you '''don't need hardware''' to complete the tutorial. Instead, you can download [https://www.assembla.com/spaces/chipwhisperer/wiki/Example_Captures example traces from the ChipWhisperer Site]. Just look for the traces titled ''AVR: AES256 Bootloader (ChipWhisperer Tutorial #A5)''.
Building/Programming the Bootloader ===
Warningbox| Are you following this tutorial at a training event? If so ONLY use the provided hex-file with secret key already embedded, do not rebuild the firmware!}}
The firmware that implements the bootloader is available inside the ChipWhisperer folder at <code>chipwhisperer\hardware\victims\firmware\bootloader-aes256</code>. If you've uploaded the firmware for any of the other tutorials, the process is identical:
# Open a command prompt/terminal window and navigate to this folder. Enter the command <code>make PLATFORM= X</code>, where X is the name of your target. For instance, use <code>PLATFORM= CW303</code> on the ChipWhisperer Lite. Ensure that the program is successfully compiled. The output should end with a line like #: <pre>Built for platform CW-Lite XMEGA</pre> # Open the ChipWhisperer Capture software and connect to your hardware. Open the programmer window ( ''Tools > CW-Lite XMEGA Programmer'') , find the <code>.hex</code> file that you just made, and ''Erase/Program/Verify FLASH''.
The firmware is now loaded onto your hardware, and you can continue onto the capture process.
== Capturing the Traces ==
## Use the toolbar to quickly reset the zoom back to original
##: Notice that the traces are synchronized for the first 7000 samples, but become unsynchronized later. This fact will be important later in the tutorial.
# Set up the attack in the ''Attack'' script:
## Make a copy of the ''attack_cpa.py'' script, call it something new (such as ''attack_aesdec14.py'')
## and then also change this further down where we set the leakage model:
##: <pre>leak_model = AES128_8bit(InvSBox_output)</pre>
## If you're finding the attack very slow, narrow down the attack a bit. Normally, this requires a bit of investigation to determine which ranges of the trace are important. Here, you can use the range from 2900
for 4200. The default settings will also work fine ! To do this adjust the following line to look as follows:
##: <pre>attack.setPointRange((2900, 4200))</pre>
# Note that we do ''not'' know the secret encryption key, so we cannot highlight the correct key automatically. If you want to fix this, the ''Results'' settings tab has a Highlighted Key setting. Change this to Override mode and enter the key <code>ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb</code>.
Unfortunately, we cannot use the GUI to attack the 13th round key. The system has no built-in model for round 13 of the AES-256 algorithm. Instead, we can write our own script and insert a custom model into the system. See [[#Appendix D: AES-256 13th Round Key Script]] for complete script used here.
# Open the ChipWhisperer Analyzer software again and reopen the project file (if closed).
# Recall from the 14th round attack that the trace data becomes unsynchronized around sample 7000. This is due to a non-constant AES implementation: the code does not always take the same amount of time to run for every input. (It's actually possible to do a timing attack on this AES implementation! We'll stick with our CPA attack for now.)
The next step is to program our own leakage model. The following Python code models the Hamming weight model of the 13th round S-box:
# Imports for AES256 Attack
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper
#:<pre>leak_model = AES128_8bit(AES256_Round13_Model)</pre>
# As we did in the 14th round attack, reducing the point range can speed up the attack. For example, to use a smaller range of points, try changing the <code>setPointRange()</code> function call to
# Start the attack! Wait for the attack to complete, and you will determine the 13th round key:
Finally, we need to convert this hypothetical key into the actual value of the 13th round key. We can do this by passing the key through ShiftRows and MixColumns to remove the effect of these two functions. This is easy to do in the Python console (assuming we had the recovered key <code>C6 BD 4E 50 AB CA 75 77 79 87 96 CA 1C 7F C5 82</code>, if you recovered a different key replace the <code>knownkey</code> value with yours):
>>> from chipwhisperer.analyzer.attacks.models.aes.funcs import shiftrows,mixcolumns
>>> knownkey = [0xC6, 0xBD, 0x4E, 0x50, 0xAB, 0xCA, 0x75, 0x77, 0x79, 0x87, 0x96, 0xCA, 0x1C, 0x7F, 0xC5, 0x82]
== Appendix A: Target Code ==
# -*- coding: utf-8 -*-
# Set the 'Target Module' as 'AES Bootloader' (you need to have that target on your system)
"""Setup script for CWLite/1200 with XMEGA (CW303/CW308-XMEGA/CWLite target)
specifically for Tutorial A5: the AES-256 bootloader attack
attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])