<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.newae.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gdeon</id>
		<title>ChipWhisperer Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.newae.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gdeon"/>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/Special:Contributions/Gdeon"/>
		<updated>2026-04-24T13:22:58Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=3714</id>
		<title>Tutorial A5 Breaking AES-256 Bootloader</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=3714"/>
				<updated>2018-08-04T04:21:26Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: Update code for new SAD API&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Warningbox|This tutorial has been updated for ChipWhisperer 4.0.0 release. If you are using 3.x.x see the &amp;quot;V3&amp;quot; link in the sidebar.}}&lt;br /&gt;
&lt;br /&gt;
{{Infobox tutorial&lt;br /&gt;
|name                   = A5: Breaking AES-256 Bootloader&lt;br /&gt;
|image                  = &lt;br /&gt;
|caption                = &lt;br /&gt;
|software versions      =&lt;br /&gt;
|capture hardware       = CW-Lite, CW-Lite 2-Part, CW-Pro&lt;br /&gt;
|Target Device          = &lt;br /&gt;
|Target Architecture    = XMEGA&lt;br /&gt;
|Hardware Crypto        = No&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This tutorial will take you through a complete attack on an encrypted bootloader using AES-256. This demonstrates how to using side-channel power analysis on practical systems, along with discussing how to perform analysis with custom scripts.&lt;br /&gt;
&lt;br /&gt;
Whilst the tutorial assumes you will be performing the entire capture of traces along with the attack, it is possible to download the traces if you don't have the hardware, in which case skip section [[#Setting up the Hardware]] and [[#Capturing the Traces]].&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
In the world of microcontrollers, a bootloader is a special piece of firmware that is made to let the user upload new programs into memory. This is especially useful for devices with complex code that may need to be patched or otherwise updated in the future - a bootloader makes it possible for the user to upload a patched version of the firmware onto the micro. The bootloader receives information from a communication line (a USB port, serial port, ethernet port, WiFi connection, etc...) and stores this data into program memory. Once the full firmware has been received, the micro can happily run its updated code.&lt;br /&gt;
&lt;br /&gt;
There is one big security issue to worry about with bootloaders. A company may want to stop their customers from writing their own firmware and uploading it onto the micro. For example, this might be for protection reasons - hackers might be able to access parts of the device that weren't meant to be accessed. One way of stopping this is to add encryption. The company can add their own secret signature to the firmware code and encrypt it with a secret key. Then, the bootloader can decrypt the incoming firmware and confirm that the incoming firmware is correctly signed. Users will not know the secret key or the signature tied to the firmware, so they won't be able to &amp;quot;fake&amp;quot; their own.&lt;br /&gt;
&lt;br /&gt;
This tutorial will work with a simple AES-256 bootloader. The victim will receive data through a serial connection, decrypt the command, and confirm that the included signature is correct. Then, it will only save the code into memory if the signature check succeeded. To make this system more robust against attacks, the bootloader will use cipher-block chaining (CBC mode). Our goal is to find the secret key and the CBC initialization vector so that we could successfully fake our own firmware.&lt;br /&gt;
&lt;br /&gt;
=== Bootloader Communications Protocol ===&lt;br /&gt;
The bootloader's communications protocol operates over a serial port at 38400 baud rate. The bootloader is always waiting for new data to be sent in this example; in real life one would typically force the bootloader to enter through a command sequence.&lt;br /&gt;
&lt;br /&gt;
Commands sent to the bootloader look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       |&amp;lt;-------- Encrypted block (16 bytes) ----------&amp;gt;|&lt;br /&gt;
       |                                                |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
| 0x00 |    Signature (4 Bytes)    |  Data (12 Bytes)   |   CRC-16    |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This frame has four parts:&lt;br /&gt;
* &amp;lt;code&amp;gt;0x00&amp;lt;/code&amp;gt;: 1 byte of fixed header&lt;br /&gt;
* Signature: A secret 4 byte constant. The bootloader will confirm that this signature is correct after decrypting the frame.&lt;br /&gt;
* Data: 12 bytes of the incoming firmware. This system forces us to send the code 12 bytes at a time; more complete bootloaders may allow longer variable-length frames.&lt;br /&gt;
* CRC-16: A 16-bit checksum using the CRC-CCITT polynomial (0x1021). The LSB of the CRC is sent first, followed by the MSB. The bootloader will reply over the serial port, describing whether or not this CRC check was valid.&lt;br /&gt;
As described in the diagram, the 16 byte block is not sent as plaintext. Instead, it is encrypted using AES-256 in CBC mode. This encryption method will be described in the next section.&lt;br /&gt;
&lt;br /&gt;
The bootloader responds to each command with a single byte indicating if the CRC-16 was OK or not:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            +------+&lt;br /&gt;
CRC-OK:     | 0xA1 |&lt;br /&gt;
            +------+&lt;br /&gt;
&lt;br /&gt;
            +------+&lt;br /&gt;
CRC Failed: | 0xA4 |&lt;br /&gt;
            +------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, after replying to the command, the bootloader veries that the signature is correct. If it matches the expected manufacturer's signature, the 12 bytes of data will be written to flash memory. Otherwise, the data is discarded.&lt;br /&gt;
&lt;br /&gt;
=== Details of AES-256 CBC ===&lt;br /&gt;
&lt;br /&gt;
The system uses the AES algorithm in Cipher Block Chaining (CBC) mode. In general one avoids using encryption 'as-is' (i.e. Electronic Code Book), since it means any piece of plaintext always maps to the same piece of ciphertext. Cipher Block Chaining ensures that if you encrypted the same thing a bunch of times it would always encrypt to a new piece of ciphertext.&lt;br /&gt;
&lt;br /&gt;
You can see another reference on the design of the encryption side; we'll be only talking about the decryption side here. In this case AES-256 CBC mode is used as follows, where the details of the AES-256 Decryption block will be discussed in detail later:&lt;br /&gt;
&lt;br /&gt;
[[File:aes256_cbc.png|image]]&lt;br /&gt;
&lt;br /&gt;
This diagram shows that the output of the decryption is no longer used directly as the plaintext. Instead, the output is XORed with a 16 byte mask, which is usually taken from the previous ciphertext. Also, the first decryption block has no previous ciphertext to use, so a secret initialization vector (IV) is used instead. If we are going to decrypt the entire ciphertext (including block 0) or correctly generate our own ciphertext, we'll need to find this IV along with the AES key.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Attacking AES-256 ===&lt;br /&gt;
The system in this tutorial uses AES-256 encryption, which has a 256 bit (32 byte) key - twice as large as the 16 byte key we've attacked in previous tutorials. This means that our regular AES-128 CPA attacks won't quite work. However, extending these attacks to AES-256 is fairly straightforward: the theory is explained in detail in [[Extending AES-128 Attacks to AES-256]]. &lt;br /&gt;
&lt;br /&gt;
As the theory page explains, our AES-256 attack will have 4 steps:&lt;br /&gt;
# Perform a standard attack (as in AES-128 decryption) to determine the first 16 bytes of the key, corresponding to the 14th round encryption key.&lt;br /&gt;
# Using the known 14th round key, calculate the hypothetical outputs of each S-Box from the 13th round using the ciphertext processed by the 14th round, and determine the 16 bytes of the 13th round key manipulated by inverse MixColumns.&lt;br /&gt;
# Perform the MixColumns and ShiftRows operation on the hypothetical key determined above, recovering the 13th round key.&lt;br /&gt;
# Using the AES-256 key schedule, reverse the 13th and 14th round keys to determine the original AES-256 encryption key.&lt;br /&gt;
&lt;br /&gt;
== Setting up the Hardware ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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)''.&lt;br /&gt;
&lt;br /&gt;
=== Building/Programming the Bootloader ===&lt;br /&gt;
&lt;br /&gt;
{{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!}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The firmware that implements the bootloader is available inside the ChipWhisperer folder at &amp;lt;code&amp;gt;chipwhisperer\hardware\victims\firmware\bootloader-aes256&amp;lt;/code&amp;gt;. If you've uploaded the firmware for any of the other tutorials, the process is identical:&lt;br /&gt;
&lt;br /&gt;
# Open a command prompt/terminal window and navigate to this folder. Enter the command &amp;lt;code&amp;gt;make PLATFORM=X&amp;lt;/code&amp;gt;, where X is the name of your target. For instance, use &amp;lt;code&amp;gt;PLATFORM=CW303&amp;lt;/code&amp;gt; on the ChipWhisperer Lite. Ensure that the program is successfully compiled. The output should end with a line like&lt;br /&gt;
#: &amp;lt;pre&amp;gt;Built for platform CW-Lite XMEGA&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open the ChipWhisperer Capture software and connect to your hardware. Open the programmer window (''Tools &amp;gt; CW-Lite XMEGA Programmer''), find the &amp;lt;code&amp;gt;.hex&amp;lt;/code&amp;gt; file that you just made, and ''Erase/Program/Verify FLASH''.&lt;br /&gt;
&lt;br /&gt;
The firmware is now loaded onto your hardware, and you can continue onto the capture process.&lt;br /&gt;
&lt;br /&gt;
== Capturing the Traces ==&lt;br /&gt;
Once the hardware is ready, we can capture some traces for our attack using the ChipWhisperer Capture software. If you somehow got to the 5th ''Advanced Tutorial'' without getting this software ready, you can follow the helpful guide at [[Installing ChipWhisperer]].&lt;br /&gt;
&lt;br /&gt;
The first thing we need to do is add a new target to the ChipWhisperer system. (None of the existing ones know about the bootloader's data format, nor do they recognize the CRC responses that are sent back to us.) The code for this target is included in [[#Appendix A: Target Code]]. Copy/paste this into a Python file (call it whatever you want) and save it in a place where ChipWhisperer will look for it. There are two folders that you can use:&lt;br /&gt;
* Your computer should have a folder called &amp;lt;code&amp;gt;chipwhisperer_projects&amp;lt;/code&amp;gt; - if you don't know where this is, the ''File &amp;gt; Preferences'' window will tell you. The system looks in the folder &amp;lt;code&amp;gt;chipwhisperer_projects\chipwhisperer\capture\targets&amp;lt;/code&amp;gt; for new targets, so you can save your file here.&lt;br /&gt;
* Alternatively, all of the normal targets are stored in &amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\targets&amp;lt;/code&amp;gt;, so you can also save the file here. Note that this may not be possible if you don't have access to these folders (ex: your account doesn't have admin access).&lt;br /&gt;
&lt;br /&gt;
Next is the capture script. In some of the previous tutorials, we entered all of the capture settings by hand. Since we are civilized humans armed with technology, we can use a script to do all of this setup for us. A pre-written Python script is provided at [[#Appendix B: Capture Script]]. Take a look at this code and notice what it does:&lt;br /&gt;
* it fills in the scope, target, and trace format that we'll use;&lt;br /&gt;
* it connects to the hardware; and&lt;br /&gt;
* it loads all of the hardware parameters for us. Nice!&lt;br /&gt;
Copy this script into a &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file somewhere convenient. Then, perform the following steps to finish the capture:&lt;br /&gt;
# Run the capture script, which will open a ChipWhisperer Capture window with everything connected for us.&lt;br /&gt;
# Open the terminal (''Tools &amp;gt; Terminal'') and connect to the board. While the terminal is open, press the ''Capture 1'' button. A single byte of data should appear in the terminal. This byte will either be &amp;lt;code&amp;gt;a1&amp;lt;/code&amp;gt; (CRC failed) or &amp;lt;code&amp;gt;a4&amp;lt;/code&amp;gt; (CRC OK). If you see any other responses, something is wrong. &lt;br /&gt;
#: [[File:Tutorial-A5-Capture.PNG|image]]&lt;br /&gt;
# Once you're happy with this, open the General Settings tab and set the Number of Traces. You should need around 100 traces to break AES.&lt;br /&gt;
# Press the ''Capture Many'' button to record the 100 traces. You'll see the new traces plotted on-screen.&lt;br /&gt;
# Once the program is finished capturing the traces, save the project. Put it somewhere memorable and give it a nice name.&lt;br /&gt;
&lt;br /&gt;
== Finding the Encryption Key ==&lt;br /&gt;
Now that we have our traces, we can go ahead and perform the attack. As described in the background theory, we'll have to do two attacks - one to get the 14th round key, and another (using the first result) to get the 13th round key. Then, we'll do some post-processing to finally get the 256 bit encryption key.&lt;br /&gt;
&lt;br /&gt;
=== 14th Round Key ===&lt;br /&gt;
We can attack the 14th round key with a standard, no-frills CPA attack:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer program and load the &amp;lt;code&amp;gt;.cwp&amp;lt;/code&amp;gt; file with the 13th and 14th round traces. This can be either the &amp;lt;code&amp;gt;aes256_round1413_key0_100.cwp&amp;lt;/code&amp;gt; file downloaded or the capture you performed.&lt;br /&gt;
# View and manipulate the trace data with the following steps:&lt;br /&gt;
## Switch to the ''Trace Output Plot'' tab&lt;br /&gt;
## Switch to the ''Results'' parameter setting tab&lt;br /&gt;
## Choose the traces to be plotted and press the ''Redraw'' button to draw them&lt;br /&gt;
## Right-click on the waveform to change options, or left-click and drag to zoom&lt;br /&gt;
## Use the toolbar to quickly reset the zoom back to original&lt;br /&gt;
##: [[File:Tutorial-A5-Plot-Traces.PNG|image]]&lt;br /&gt;
##: Notice that the traces are synchronized for the first 7000 samples, but become unsynchronized later. This fact will be important later in the tutorial.&lt;br /&gt;
# Set up the attack in the ''Attack'' script:&lt;br /&gt;
## Make a copy of the ''attack_cpa.py'' script, call it something new (such as ''attack_aesdec14.py'')&lt;br /&gt;
## Adjust the model from ''SBox_output'' to ''InvSBox_output''. This is done by finding the following line in the script:&lt;br /&gt;
##: &amp;lt;pre&amp;gt;from chipwhisperer.analyzer.attacks.models.AES128_8bit import AES128_8bit, SBox_output&amp;lt;/pre&amp;gt;&lt;br /&gt;
##: and change that line to:&lt;br /&gt;
##: &amp;lt;pre&amp;gt;from chipwhisperer.analyzer.attacks.models.AES128_8bit import AES128_8bit, InvSBox_output&amp;lt;/pre&amp;gt;&lt;br /&gt;
## and then also change this further down where we set the leakage model:&lt;br /&gt;
##: &amp;lt;pre&amp;gt;leak_model = AES128_8bit(InvSBox_output)&amp;lt;/pre&amp;gt;&lt;br /&gt;
## 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:&lt;br /&gt;
##: &amp;lt;pre&amp;gt;attack.setPointRange((2900, 4200))&amp;lt;/pre&amp;gt;&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Finally, run the attack by switching to the ''Results Table'' tab and then hitting the ''Run'' button while your script is selected.&lt;br /&gt;
#: [[File:A5_run_script_round14.png|400px]]&lt;br /&gt;
There are a few ways to check the results of the attack. First, the results table will show the best guesses for each subkey. With the highlight override enabled, the red bytes should be the best guesses for every single subkey:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Right-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
However, the correct key will still rise to the top even if the wrong bytes are highlighted. The coloring and correlation coefficients in the results table should still make it clear that the top guess is the best one:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Wrong-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
{{warningbox|The default capture stores the WRONG knownkey, so you will have highlighted bytes that are not the correct key. We are looking instead for a large delta between the best-guess and all other guesses. For example for Byte 0 we have the most likely as 0.8141, and 2nd best guess as 0.3551. If our best guess was 0.8141 and 2nd best guess was 0.7981 this would indicate we likely haven't broken the key.}}&lt;br /&gt;
&lt;br /&gt;
Finally, the ''Output vs Point Plot'' shows the correlation against all of the sample points. The spikes on this plot show exactly where the attack was successful (ie: where the sensitive data was leaked):&lt;br /&gt;
&lt;br /&gt;
[[File:Aes14round points.png|image]]&lt;br /&gt;
&lt;br /&gt;
In any case, we've determined that the correct 14th round key is &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
''NOTE: if you're stuck, a full listing of the attack script is given in [[#Appendix C: AES-256 14th Round Key Script]].''&lt;br /&gt;
&lt;br /&gt;
=== 13th Round Key ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer software again and reopen the project file (if closed).&lt;br /&gt;
# 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.)&lt;br /&gt;
#: [[File:syncproblems.png|image]]&lt;br /&gt;
# Resynchronize the traces, see the separate 'Preprocessing' tutorial (NB: only in slides right now!)&lt;br /&gt;
&lt;br /&gt;
{{warningbox|Make sure you get a nice aligned last section of the traces, as in the below figure. You may need to adjust the &amp;quot;input window&amp;quot; or &amp;quot;reference points&amp;quot; slightly. If you do not see the nice alignment the remaining attack will fail!&lt;br /&gt;
&lt;br /&gt;
[[File:A5_pp_resync_end.png|400px]]}}&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper&lt;br /&gt;
&lt;br /&gt;
class AES256_Round13_Model(AESLeakageHelper):&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        #You must but YOUR recovered 14th round key here - this example may not be accurate!&lt;br /&gt;
        calc_round_key = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [calc_round_key[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can look back at the C code of the AES-256 decryption to see how this is implementing the decryption code. Note that because of the Inverse MixColumns operation, we need the entire input ciphertext -- otherwise, we would only need to operate on one byte of the ciphertext.&lt;br /&gt;
&lt;br /&gt;
The last step is to perform the attack using this model:&lt;br /&gt;
# Add the above function to your custom script file.&lt;br /&gt;
# Change the &amp;lt;code&amp;gt;setAnalysisAlgorithm&amp;lt;/code&amp;gt; in the script to use your custom functions by making the following call:&lt;br /&gt;
#:&amp;lt;pre&amp;gt;leak_model = AES128_8bit(AES256_Round13_Model)&amp;lt;/pre&amp;gt;&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;setPointRange()&amp;lt;/code&amp;gt; function call to&lt;br /&gt;
#:&amp;lt;pre&amp;gt;self.attack.setPointRange((8000,10990))&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Start the attack! Wait for the attack to complete, and you will determine the 13th round key:&lt;br /&gt;
#: [[File:Tutorial-A5-Results-Round-13.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Note you can check [[#Appendix C AES-256 13th Round Key Script]] for the complete contents of the attack script.&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;code&amp;gt;C6 BD 4E 50 AB CA 75 77 79 87 96 CA 1C 7F C5 82&amp;lt;/code&amp;gt;, if you recovered a different key replace the &amp;lt;code&amp;gt;knownkey&amp;lt;/code&amp;gt; value with yours):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from chipwhisperer.analyzer.attacks.models.aes.funcs import shiftrows,mixcolumns&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; knownkey = [0xC6, 0xBD, 0x4E, 0x50, 0xAB, 0xCA, 0x75, 0x77, 0x79, 0x87, 0x96, 0xCA, 0x1C, 0x7F, 0xC5, 0x82]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = shiftrows(knownkey)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = mixcolumns(key)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print &amp;amp;quot; &amp;amp;quot;.join([&amp;amp;quot;%02x&amp;amp;quot; % i for i in key])&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our hard work has rewarded us with the 13th round key, which is &amp;lt;code&amp;gt;c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Recovering the Encryption Key ===&lt;br /&gt;
Finally, we have enough information to recover the initial encryption key. In AES-256, the initial key is used in the key expansion routine to generate 15 round keys, and we know the key for round 13 and 14. All we need to do now is reverse the key scheduling algorithm to calculate the ''0/1 Round Key'' from the ''13/14 Round Key''. &lt;br /&gt;
&lt;br /&gt;
In the ChipWhisperer Analyzer software, a key schedule calculator is provided in ''Tools &amp;gt; AES Key Schedule'':&lt;br /&gt;
&lt;br /&gt;
[[File:keyschedule_tool.png|image]]&lt;br /&gt;
&lt;br /&gt;
Open this tool and paste the 13/14 round keys, which are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63 ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tell the tool that this key is the 13/14 round key; it will automatically display the entire key schedule and the initial encryption key. You should find the initial encryption key is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
94 28 5d 4d 6d cf ec 08 d8 ac dd f6 be 25 a4 99 c4 d9 d0 1e c3 40 7e d7 d5 28 d4 09 e9 f0 88 a1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Peek into &amp;lt;code&amp;gt;supersecret.h&amp;lt;/code&amp;gt;, confirm that this is the right key, and celebrate!&lt;br /&gt;
&lt;br /&gt;
== Next Steps ==&lt;br /&gt;
If you want to go further with this tutorial, [[Tutorial A5-Bonus Breaking AES-256 Bootloader]] continues working with the same firmware to find the remaining secrets in the bootloader (the IV and the signature).&lt;br /&gt;
&lt;br /&gt;
== Appendix A: Target Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import time&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.capture.targets.SimpleSerial import SimpleSerial&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.capture.targets._base import TargetTemplate&lt;br /&gt;
from chipwhisperer.common.utils import pluginmanager&lt;br /&gt;
from chipwhisperer.capture.targets.simpleserial_readers.cwlite import SimpleSerial_ChipWhispererLite&lt;br /&gt;
from chipwhisperer.common.utils.parameter import setupSetParam&lt;br /&gt;
&lt;br /&gt;
# Class Crc&lt;br /&gt;
#############################################################&lt;br /&gt;
# These CRC routines are copy-pasted from pycrc, which are:&lt;br /&gt;
# Copyright (c) 2006-2013 Thomas Pircher &amp;lt;tehpeh@gmx.net&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
class Crc(object):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    A base class for CRC routines.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, width, poly):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;The Crc constructor.&lt;br /&gt;
&lt;br /&gt;
        The parameters are as follows:&lt;br /&gt;
            width&lt;br /&gt;
            poly&lt;br /&gt;
            reflect_in&lt;br /&gt;
            xor_in&lt;br /&gt;
            reflect_out&lt;br /&gt;
            xor_out&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.Width = width&lt;br /&gt;
        self.Poly = poly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.MSB_Mask = 0x1 &amp;lt;&amp;lt; (self.Width - 1)&lt;br /&gt;
        self.Mask = ((self.MSB_Mask - 1) &amp;lt;&amp;lt; 1) | 1&lt;br /&gt;
&lt;br /&gt;
        self.XorIn = 0x0000&lt;br /&gt;
        self.XorOut = 0x0000&lt;br /&gt;
&lt;br /&gt;
        self.DirectInit = self.XorIn&lt;br /&gt;
        self.NonDirectInit = self.__get_nondirect_init(self.XorIn)&lt;br /&gt;
        if self.Width &amp;lt; 8:&lt;br /&gt;
            self.CrcShift = 8 - self.Width&lt;br /&gt;
        else:&lt;br /&gt;
            self.CrcShift = 0&lt;br /&gt;
&lt;br /&gt;
    def __get_nondirect_init(self, init):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return the non-direct init if the direct algorithm has been selected.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        crc = init&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            bit = crc &amp;amp; 0x01&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc ^= self.Poly&lt;br /&gt;
            crc &amp;gt;&amp;gt;= 1&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc |= self.MSB_Mask&lt;br /&gt;
        return crc &amp;amp; self.Mask&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def bit_by_bit(self, in_data):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Classic simple and slow CRC implementation.  This function iterates bit&lt;br /&gt;
        by bit over the augmented input message and returns the calculated CRC&lt;br /&gt;
        value at the end.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # If the input data is a string, convert to bytes.&lt;br /&gt;
        if isinstance(in_data, str):&lt;br /&gt;
            in_data = [ord(c) for c in in_data]&lt;br /&gt;
&lt;br /&gt;
        register = self.NonDirectInit&lt;br /&gt;
        for octet in in_data:&lt;br /&gt;
            for i in range(8):&lt;br /&gt;
                topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
                register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask) | ((octet &amp;gt;&amp;gt; (7 - i)) &amp;amp; 0x01)&lt;br /&gt;
                if topbit:&lt;br /&gt;
                    register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
            register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask)&lt;br /&gt;
            if topbit:&lt;br /&gt;
                register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        return register ^ self.XorOut&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
class BootloaderTarget(TargetTemplate):&lt;br /&gt;
    _name = 'AES Bootloader'&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        TargetTemplate.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        ser_cons = pluginmanager.getPluginsInDictFromPackage(&amp;quot;chipwhisperer.capture.targets.simpleserial_readers&amp;quot;, True, False)&lt;br /&gt;
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]&lt;br /&gt;
&lt;br /&gt;
        self.keylength = 16&lt;br /&gt;
        self.input = &amp;quot;&amp;quot;&lt;br /&gt;
        self.crc = Crc(width=16, poly=0x1021)&lt;br /&gt;
        self.setConnection(self.ser)&lt;br /&gt;
&lt;br /&gt;
    def setKeyLen(self, klen):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Set key length in BITS &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.keylength = klen / 8        &lt;br /&gt;
 &lt;br /&gt;
    def keyLen(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Return key length in BYTES &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return self.keylength&lt;br /&gt;
&lt;br /&gt;
    def getConnection(self):&lt;br /&gt;
        return self.ser&lt;br /&gt;
&lt;br /&gt;
    def setConnection(self, con):&lt;br /&gt;
        self.ser = con&lt;br /&gt;
        self.params.append(self.ser.getParams())&lt;br /&gt;
        self.ser.connectStatus.connect(self.connectStatus.emit)&lt;br /&gt;
        self.ser.selectionChanged()&lt;br /&gt;
&lt;br /&gt;
    def con(self, scope=None):&lt;br /&gt;
        if not scope or not hasattr(scope, &amp;quot;qtadc&amp;quot;): Warning(&lt;br /&gt;
            &amp;quot;You need a scope with OpenADC connected to use this Target&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        self.ser.con(scope)&lt;br /&gt;
        # 'x' flushes everything &amp;amp; sets system back to idle&lt;br /&gt;
        self.ser.write(&amp;quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;quot;)&lt;br /&gt;
        self.ser.flush()&lt;br /&gt;
        self.connectStatus.setValue(True)&lt;br /&gt;
&lt;br /&gt;
    def close(self):&lt;br /&gt;
        if self.ser != None:&lt;br /&gt;
            self.ser.close()&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def init(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def setModeEncrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def setModeDecrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def convertVarToString(self, var):&lt;br /&gt;
        if isinstance(var, str):&lt;br /&gt;
            return var&lt;br /&gt;
&lt;br /&gt;
        sep = &amp;quot;&amp;quot;&lt;br /&gt;
        s = sep.join([&amp;quot;%c&amp;quot; % b for b in var])&lt;br /&gt;
        return s&lt;br /&gt;
&lt;br /&gt;
    def loadEncryptionKey(self, key):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def loadInput(self, inputtext):&lt;br /&gt;
        self.input = inputtext&lt;br /&gt;
&lt;br /&gt;
    def readOutput(self):&lt;br /&gt;
        # No actual output&lt;br /&gt;
        return [0] * 16&lt;br /&gt;
&lt;br /&gt;
    def isDone(self):&lt;br /&gt;
        return True&lt;br /&gt;
&lt;br /&gt;
    def checkEncryptionKey(self, kin):&lt;br /&gt;
        return kin&lt;br /&gt;
&lt;br /&gt;
    def go(self):&lt;br /&gt;
        # Starting byte is 0x00&lt;br /&gt;
        message = [0x00]&lt;br /&gt;
&lt;br /&gt;
        # Append 16 bytes of data&lt;br /&gt;
        message.extend(self.input)&lt;br /&gt;
&lt;br /&gt;
        # Append 2 bytes of CRC for input only (not including 0x00)&lt;br /&gt;
        crcdata = self.crc.bit_by_bit(self.input)&lt;br /&gt;
&lt;br /&gt;
        message.append(crcdata &amp;gt;&amp;gt; 8)&lt;br /&gt;
        message.append(crcdata &amp;amp; 0xff)&lt;br /&gt;
&lt;br /&gt;
        # Write message&lt;br /&gt;
        message = self.convertVarToString(message)&lt;br /&gt;
        for i in range(0, 5):&lt;br /&gt;
            self.ser.flush()&lt;br /&gt;
            self.ser.write(message)&lt;br /&gt;
            time.sleep(0.1)&lt;br /&gt;
            data = self.ser.read(1)&lt;br /&gt;
&lt;br /&gt;
            if len(data) &amp;gt; 0:&lt;br /&gt;
                resp = ord(data[0])&lt;br /&gt;
&lt;br /&gt;
                if resp == 0xA4:&lt;br /&gt;
                    # Encryption run OK&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
                if resp != 0xA1:&lt;br /&gt;
                    raise IOError(&amp;quot;Bad Response %x&amp;quot; % resp)&lt;br /&gt;
&lt;br /&gt;
        if len(data) &amp;gt; 0:&lt;br /&gt;
            if resp != 0xA4:&lt;br /&gt;
                raise IOError(&amp;quot;Failed to communicate, last response: %x&amp;quot; % resp)&lt;br /&gt;
        else:&lt;br /&gt;
            raise IOError(&amp;quot;Failed to communicate, no response&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Appendix B: Capture Script ==&lt;br /&gt;
&lt;br /&gt;
Note you need to manually CONNECT to the CW-Lite &amp;amp; AES Bootloader target before running this. To do this:&lt;br /&gt;
&lt;br /&gt;
# Set the 'Scope Module' as 'ChipWhisperer/OpenADC'&lt;br /&gt;
# Set the 'Target Module' as 'AES Bootloader' (you need to have that target on your system)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;Setup script for CWLite/1200 with XMEGA (CW303/CW308-XMEGA/CWLite target)&lt;br /&gt;
specifically for Tutorial A5: the AES-256 bootloader attack&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    scope = self.scope&lt;br /&gt;
except NameError:&lt;br /&gt;
    pass&lt;br /&gt;
    &lt;br /&gt;
scope.gain.gain = 45&lt;br /&gt;
scope.adc.samples = 11000&lt;br /&gt;
scope.adc.offset = 0&lt;br /&gt;
scope.adc.basic_mode = &amp;quot;rising_edge&amp;quot;&lt;br /&gt;
scope.clock.clkgen_freq = 7370000&lt;br /&gt;
scope.clock.adc_src = &amp;quot;clkgen_x4&amp;quot;&lt;br /&gt;
scope.trigger.triggers = &amp;quot;tio4&amp;quot;&lt;br /&gt;
scope.io.tio1 = &amp;quot;serial_rx&amp;quot;&lt;br /&gt;
scope.io.tio2 = &amp;quot;serial_tx&amp;quot;&lt;br /&gt;
scope.io.hs2 = &amp;quot;clkgen&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Appendix C: AES-256 14th Round Key Script ==&lt;br /&gt;
Full attack script, copy/paste into a file then run from within ChipWhisperer-Analyzer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
import chipwhisperer as cw&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AES128_8bit, InvSBox_output&lt;br /&gt;
&lt;br /&gt;
#self.project = cw.openProject(&amp;quot;2017-mar23-xmega-aes.cwp&amp;quot;)&lt;br /&gt;
traces = self.project.traceManager()&lt;br /&gt;
&lt;br /&gt;
attack = CPA()&lt;br /&gt;
leak_model = AES128_8bit(InvSBox_output)&lt;br /&gt;
attack.setAnalysisAlgorithm(CPAProgressive, leak_model)&lt;br /&gt;
attack.setTraceSource(traces)&lt;br /&gt;
attack.setTraceStart(0)&lt;br /&gt;
attack.setTracesPerAttack(-1)&lt;br /&gt;
attack.setIterations(1)&lt;br /&gt;
attack.setReportingInterval(10)&lt;br /&gt;
attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
attack.setPointRange((2900, 3400))&lt;br /&gt;
&lt;br /&gt;
self.results_table.setAnalysisSource(attack)&lt;br /&gt;
self.correlation_plot.setAnalysisSource(attack)&lt;br /&gt;
self.output_plot.setAnalysisSource(attack)&lt;br /&gt;
self.pge_plot.setAnalysisSource(attack)&lt;br /&gt;
attack.processTraces()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Appendix D: AES-256 13th Round Key Script ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
import chipwhisperer as cw&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AES128_8bit, AESLeakageHelper&lt;br /&gt;
from chipwhisperer.analyzer.preprocessing.resync_sad import ResyncSAD&lt;br /&gt;
&lt;br /&gt;
class AES256_Round13_Model(AESLeakageHelper):&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        #You must but YOUR recovered 14th round key here - this example may not be accurate!&lt;br /&gt;
        calc_round_key = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [calc_round_key[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&lt;br /&gt;
traces = self.project.traceManager()&lt;br /&gt;
&lt;br /&gt;
resync_traces = ResyncSAD(traces)&lt;br /&gt;
resync_traces.enabled = True&lt;br /&gt;
resync_traces.ref_trace = 0&lt;br /&gt;
resync_traces.target_window = (9100, 9300)&lt;br /&gt;
resync_traces.max_shift = 200&lt;br /&gt;
&lt;br /&gt;
attack = CPA()&lt;br /&gt;
leak_model = AES128_8bit(AES256_Round13_Model)&lt;br /&gt;
attack.setAnalysisAlgorithm(CPAProgressive, leak_model)&lt;br /&gt;
attack.setTraceSource(resync_traces)&lt;br /&gt;
attack.setTraceStart(0)&lt;br /&gt;
attack.setTracesPerAttack(-1)&lt;br /&gt;
attack.setIterations(1)&lt;br /&gt;
attack.setReportingInterval(10)&lt;br /&gt;
attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
attack.setPointRange((0, -1))&lt;br /&gt;
&lt;br /&gt;
self.results_table.setAnalysisSource(attack)&lt;br /&gt;
self.correlation_plot.setAnalysisSource(attack)&lt;br /&gt;
self.output_plot.setAnalysisSource(attack)&lt;br /&gt;
self.pge_plot.setAnalysisSource(attack)&lt;br /&gt;
attack.processTraces()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_B1-2_Controlling_ChipWhisperer_using_Python&amp;diff=2805</id>
		<title>Tutorial B1-2 Controlling ChipWhisperer using Python</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_B1-2_Controlling_ChipWhisperer_using_Python&amp;diff=2805"/>
				<updated>2017-08-18T19:48:53Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: Created page with &amp;quot;This tutorial is an introduction to the ChipWhisperer's Python API. While it is possible to use all of the ChipWhisperer devices' features without writing any code, controllin...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial is an introduction to the ChipWhisperer's Python API. While it is possible to use all of the ChipWhisperer devices' features without writing any code, controlling them with Python makes them much more powerful, allowing capture settings to be prepared and power traces to be recorded automatically. &lt;br /&gt;
&lt;br /&gt;
{{TOC|limit=3}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; The ChipWhisperer package &amp;lt;/h1&amp;gt;&lt;br /&gt;
The ChipWhisperer Python package contains the high-level API used to control and communicate with ChipWhisperer devices. This package can be imported in any Python interpreter as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import chipwhisperer as cw&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ChipWhisperer is a relatively large package that contains many features ranging from low-level control of USB devices to a PyQt GUI program, and it's possible to access all of these components through the package. However, for most users, only a small subset of the package is important. For these tutorials, there are five main concepts to understand:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; A &amp;lt;b&amp;gt;scope&amp;lt;/b&amp;gt; object represents a connection to a ChipWhisperer device, such as a CW-Lite or CW1200. Scopes have a large number of settings related to clock frequencies, ADC levels, trigger logic, IO lines, and glitch output - the same parameters that are accessed under the &amp;quot;Scope Settings&amp;quot; tab. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; A &amp;lt;b&amp;gt;target&amp;lt;/b&amp;gt; object represents a connection to a target (or &amp;lt;i&amp;gt;victim&amp;lt;/i&amp;gt;) board. The target classes describe how the ChipWhisperer program can communicate with a target board to cause encryptions, password checks, or other operations of interest. As with the scope, the &amp;quot;Target Settings&amp;quot; tab contains the same settings as a target object. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; A &amp;lt;b&amp;gt;project&amp;lt;/b&amp;gt; object is in charge of saving recorded power traces along with some auxiliary data. There are multiple project classes that save data in different formats - for example, it's possible to save power traces to make them compatible with DPAContest v3. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; An &amp;lt;b&amp;gt;aux_list&amp;lt;/b&amp;gt; object keeps track of some extra functions that can be run during a capture. For example, one aux function could reset the target board immediately before capturing a power trace to show a power trace of the device's boot process. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; A &amp;lt;b&amp;gt;ktp&amp;lt;/b&amp;gt; (short for &amp;lt;i&amp;gt;key-text pattern&amp;lt;/i&amp;gt;) controls what data is sent to the target during a capture. For example, the basic KTP object can be configured to send many encryption inputs with a fixed key for side-channel analysis. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Outside of these objects, the main function for capturing power traces is &amp;lt;code&amp;gt;captureN()&amp;lt;/code&amp;gt;. Generally, this function requires a scope, target, project, aux_list, and ktp, along with the number of traces to be captured. However, some of these parameters can be left out. For example, the call&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
captureN(scope, target, None, aux_list, ktp, 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will capture a single power trace without saving the data to a project. This is similar to the Capture 1 button in the GUI, which is helpful for testing the ChipWhisperer's settings.&lt;br /&gt;
&lt;br /&gt;
To find more details about any of these objects, try running &amp;lt;code&amp;gt;help(cw)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;help(x)&amp;lt;/code&amp;gt; on a scope/target/etc object. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; The Python Console&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Interpreter &amp;lt;/h2&amp;gt;&lt;br /&gt;
The ChipWhisperer Capture program includes a Python interpreter to give users an interface to the program. This is a full-featured Python console: any installed packages can be imported and used as if Python was run from the command line. &lt;br /&gt;
&lt;br /&gt;
This console also has a few special objects that provide access to the objects from the GUI. In this console, &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; is a special object that refers to the CWCapture GUI. This object contains a scope, target, project, aux_list, and ktp, and changes to these objects are linked to the settings shown in the sidebar. For example, with a connected CW-Lite, the line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
self.scope.clock.clkgen_freq = 7370000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
is equivalent to changing the CLKGEN frequency in the Scope Settings tab. By working with these special objects, it's possible to recreate the entire scope setup process in Python, removing all the hard work of preparing these settings by hand.&lt;br /&gt;
&lt;br /&gt;
{{Warningbox|Caution: The built-in Python console runs in the program's main thread to give it access to the program's scope, target, and other objects. Unfortunately, this means that it's very possible to lock up CWCapture with the console. We've taken a few precautions to avoid lockups: Ctrl-C can stop a running script, and the GUI regains control for a moment every time the interpreter prints to the output field. However, code like &amp;lt;code&amp;gt;while True: pass&amp;lt;/code&amp;gt; will certainly stop CWCapture in its tracks. Be careful! }}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Script Browser &amp;lt;/h2&amp;gt;&lt;br /&gt;
Alongside the Python console, ChipWhisperer Capture has a file browser and a text preview window. These widgets are used to run pre-written scripts in the console. The file browser has three tabs:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The &amp;lt;b&amp;gt;ChipWhisperer&amp;lt;/b&amp;gt; tab has its root in the &amp;lt;code&amp;gt;chipwhisperer/software/chipwhisperer&amp;lt;/code&amp;gt; directory. This tab is provided for convenience - it saves the trouble of digging through folders to find the ChipWhisperer folder to run a script. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The &amp;lt;b&amp;gt;Hard Drive&amp;lt;/b&amp;gt; tab has its root at the root of the computer's file system. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The &amp;lt;b&amp;gt;Recent&amp;lt;/b&amp;gt; tab shows the 10 most recently run scripts. It also allows useful scripts to be pinned to the top of the list or removed using the right-click menu. To save space, the full paths aren't shown in this tab - to see it, hold your mouse over a file and the tooltip will show the entire path. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
To get you started, the ChipWhisperer repository contains a number of scripts in the &amp;lt;code&amp;gt;capture/scripts&amp;lt;/code&amp;gt; folder. These pre-written Python files perform a number of tasks ranging from connecting to a ChipWhisperer to setting up auxiliary modules. Of course, you're encouraged to copy and edit these scripts however you like for your own projects.&lt;br /&gt;
&lt;br /&gt;
On the side, the preview window shows the selected script. To run it, double-click a script in the browser or press the Run button: the Python console will show the line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
execfile(&amp;quot;path/to/script.py&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
which runs the file as if its contents were pasted into the input. The preview window is read-only, but the Edit button opens the selected file in an external editor. By default, the system's regular Python file editor is used, but you can select any executable as the editor under &amp;lt;i&amp;gt;File &amp;gt; Preferences&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Warningbox|Caution: The script preview doesn't automatically update when a file is modified. Don't worry - if you press Run, the most recent copy of the file will be executed! This is just a cosmetic issue. }}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Repeating Tutorial B1 &amp;lt;/h1&amp;gt;&lt;br /&gt;
Let's re-run the Tutorial B1 setup. Run the following two scripts:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt;capture/scripts/connect_cwlite_simpleserial.py&amp;lt;/code&amp;gt;: Connect to a ChipWhisperer-Lite/Pro and a SimpleSerial target &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt;capture/scripts/setup_cwlite_xmega_spa&amp;lt;/code&amp;gt;: Configure the ChipWhisperer's ADC/clock/IO settings for SPA (&amp;lt;i&amp;gt;simple power analysis&amp;lt;/i&amp;gt;) on the XMEGA target board &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
That's it! If all went well, you can capture power traces as if you worked through the previous tutorial. These scripts will come in handy for the rest of the tutorials.&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2786</id>
		<title>Tutorial A5 Breaking AES-256 Bootloader</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2786"/>
				<updated>2017-07-23T16:24:38Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* 13th Round Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial will take you through a complete attack on an encrypted bootloader using AES-256. This demonstrates how to using side-channel power analysis on practical systems, along with discussing how to perform analysis with custom scripts.&lt;br /&gt;
&lt;br /&gt;
Whilst the tutorial assumes you will be performing the entire capture of traces along with the attack, it is possible to download the traces if you don't have the hardware, in which case skip section [[#Setting up the Hardware]] and [[#Capturing the Traces]].&lt;br /&gt;
&lt;br /&gt;
= Background =&lt;br /&gt;
In the world of microcontrollers, a bootloader is a special piece of firmware that is made to let the user upload new programs into memory. This is especially useful for devices with complex code that may need to be patched or otherwise updated in the future - a bootloader makes it possible for the user to upload a patched version of the firmware onto the micro. The bootloader receives information from a communication line (a USB port, serial port, ethernet port, WiFi connection, etc...) and stores this data into program memory. Once the full firmware has been received, the micro can happily run its updated code.&lt;br /&gt;
&lt;br /&gt;
There is one big security issue to worry about with bootloaders. A company may want to stop their customers from writing their own firmware and uploading it onto the micro. For example, this might be for protection reasons - hackers might be able to access parts of the device that weren't meant to be accessed. One way of stopping this is to add encryption. The company can add their own secret signature to the firmware code and encrypt it with a secret key. Then, the bootloader can decrypt the incoming firmware and confirm that the incoming firmware is correctly signed. Users will not know the secret key or the signature tied to the firmware, so they won't be able to &amp;quot;fake&amp;quot; their own.&lt;br /&gt;
&lt;br /&gt;
This tutorial will work with a simple AES-256 bootloader. The victim will receive data through a serial connection, decrypt the command, and confirm that the included signature is correct. Then, it will only save the code into memory if the signature check succeeded. To make this system more robust against attacks, the bootloader will use cipher-block chaining (CBC mode). Our goal is to find the secret key and the CBC initialization vector so that we could successfully fake our own firmware.&lt;br /&gt;
&lt;br /&gt;
== Bootloader Communications Protocol ==&lt;br /&gt;
The bootloader's communications protocol operates over a serial port at 38400 baud rate. The bootloader is always waiting for new data to be sent in this example; in real life one would typically force the bootloader to enter through a command sequence.&lt;br /&gt;
&lt;br /&gt;
Commands sent to the bootloader look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       |&amp;lt;-------- Encrypted block (16 bytes) ----------&amp;gt;|&lt;br /&gt;
       |                                                |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
| 0x00 |    Signature (4 Bytes)    |  Data (12 Bytes)   |   CRC-16    |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This frame has four parts:&lt;br /&gt;
* &amp;lt;code&amp;gt;0x00&amp;lt;/code&amp;gt;: 1 byte of fixed header&lt;br /&gt;
* Signature: A secret 4 byte constant. The bootloader will confirm that this signature is correct after decrypting the frame.&lt;br /&gt;
* Data: 12 bytes of the incoming firmware. This system forces us to send the code 12 bytes at a time; more complete bootloaders may allow longer variable-length frames.&lt;br /&gt;
* CRC-16: A 16-bit checksum using the CRC-CCITT polynomial (0x1021). The LSB of the CRC is sent first, followed by the MSB. The bootloader will reply over the serial port, describing whether or not this CRC check was valid.&lt;br /&gt;
As described in the diagram, the 16 byte block is not sent as plaintext. Instead, it is encrypted using AES-256 in CBC mode. This encryption method will be described in the next section.&lt;br /&gt;
&lt;br /&gt;
The bootloader responds to each command with a single byte indicating if the CRC-16 was OK or not:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            +------+&lt;br /&gt;
CRC-OK:     | 0xA1 |&lt;br /&gt;
            +------+&lt;br /&gt;
&lt;br /&gt;
            +------+&lt;br /&gt;
CRC Failed: | 0xA4 |&lt;br /&gt;
            +------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, after replying to the command, the bootloader veries that the signature is correct. If it matches the expected manufacturer's signature, the 12 bytes of data will be written to flash memory. Otherwise, the data is discarded.&lt;br /&gt;
&lt;br /&gt;
== Details of AES-256 CBC ==&lt;br /&gt;
&lt;br /&gt;
The system uses the AES algorithm in Cipher Block Chaining (CBC) mode. In general one avoids using encryption 'as-is' (i.e. Electronic Code Book), since it means any piece of plaintext always maps to the same piece of ciphertext. Cipher Block Chaining ensures that if you encrypted the same thing a bunch of times it would always encrypt to a new piece of ciphertext.&lt;br /&gt;
&lt;br /&gt;
You can see another reference on the design of the encryption side; we'll be only talking about the decryption side here. In this case AES-256 CBC mode is used as follows, where the details of the AES-256 Decryption block will be discussed in detail later:&lt;br /&gt;
&lt;br /&gt;
[[File:aes256_cbc.png|image]]&lt;br /&gt;
&lt;br /&gt;
This diagram shows that the output of the decryption is no longer used directly as the plaintext. Instead, the output is XORed with a 16 byte mask, which is usually taken from the previous ciphertext. Also, the first decryption block has no previous ciphertext to use, so a secret initialization vector (IV) is used instead. If we are going to decrypt the entire ciphertext (including block 0) or correctly generate our own ciphertext, we'll need to find this IV along with the AES key.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Attacking AES-256 ==&lt;br /&gt;
The system in this tutorial uses AES-256 encryption, which has a 256 bit (32 byte) key - twice as large as the 16 byte key we've attacked in previous tutorials. This means that our regular AES-128 CPA attacks won't quite work. However, extending these attacks to AES-256 is fairly straightforward: the theory is explained in detail in [[Extending AES-128 Attacks to AES-256]]. &lt;br /&gt;
&lt;br /&gt;
As the theory page explains, our AES-256 attack will have 4 steps:&lt;br /&gt;
# Perform a standard attack (as in AES-128 decryption) to determine the first 16 bytes of the key, corresponding to the 14th round encryption key.&lt;br /&gt;
# Using the known 14th round key, calculate the hypothetical outputs of each S-Box from the 13th round using the ciphertext processed by the 14th round, and determine the 16 bytes of the 13th round key manipulated by inverse MixColumns.&lt;br /&gt;
# Perform the MixColumns and ShiftRows operation on the hypothetical key determined above, recovering the 13th round key.&lt;br /&gt;
# Using the AES-256 key schedule, reverse the 13th and 14th round keys to determine the original AES-256 encryption key.&lt;br /&gt;
&lt;br /&gt;
= Setting up the Hardware =&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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)''.&lt;br /&gt;
&lt;br /&gt;
== Building/Programming the Bootloader ==&lt;br /&gt;
The firmware that implements the bootloader is available inside the ChipWhisperer folder at &amp;lt;code&amp;gt;chipwhisperer\hardware\victims\firmware\bootloader-aes256&amp;lt;/code&amp;gt;. If you've uploaded the firmware for any of the other tutorials, the process is identical:&lt;br /&gt;
&lt;br /&gt;
# Open a command prompt/terminal window and navigate to this folder. Enter the command &amp;lt;code&amp;gt;make PLATFORM=X&amp;lt;/code&amp;gt;, where X is the name of your target. For instance, use &amp;lt;code&amp;gt;PLATFORM=CW303&amp;lt;/code&amp;gt; on the ChipWhisperer Lite. Ensure that the program is successfully compiled. The output should end with a line like&lt;br /&gt;
#: &amp;lt;pre&amp;gt;Built for platform CW-Lite XMEGA&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open the ChipWhisperer Capture software and connect to your hardware. Open the programmer window (''Tools &amp;gt; CW-Lite XMEGA Programmer''), find the &amp;lt;code&amp;gt;.hex&amp;lt;/code&amp;gt; file that you just made, and ''Erase/Program/Verify FLASH''.&lt;br /&gt;
&lt;br /&gt;
The firmware is now loaded onto your hardware, and you can continue onto the capture process.&lt;br /&gt;
&lt;br /&gt;
= Capturing the Traces =&lt;br /&gt;
Once the hardware is ready, we can capture some traces for our attack using the ChipWhisperer Capture software. If you somehow got to the 5th ''Advanced Tutorial'' without getting this software ready, you can follow the helpful guide at [[Installing ChipWhisperer]].&lt;br /&gt;
&lt;br /&gt;
The first thing we need to do is add a new target to the ChipWhisperer system. (None of the existing ones know about the bootloader's data format, nor do they recognize the CRC responses that are sent back to us.) The code for this target is included in [[#Appendix A: Target Code]]. Copy/paste this into a Python file (call it whatever you want) and save it in a place where ChipWhisperer will look for it. There are two folders that you can use:&lt;br /&gt;
* Your computer should have a folder called &amp;lt;code&amp;gt;chipwhisperer_projects&amp;lt;/code&amp;gt; - if you don't know where this is, the ''File &amp;gt; Preferences'' window will tell you. The system looks in the folder &amp;lt;code&amp;gt;chipwhisperer_projects\chipwhisperer\capture\targets&amp;lt;/code&amp;gt; for new targets, so you can save your file here.&lt;br /&gt;
* Alternatively, all of the normal targets are stored in &amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\targets&amp;lt;/code&amp;gt;, so you can also save the file here. Note that this may not be possible if you don't have access to these folders (ex: your account doesn't have admin access).&lt;br /&gt;
&lt;br /&gt;
Next is the capture script. In some of the previous tutorials, we entered all of the capture settings by hand. Since we are civilized humans armed with technology, we can use a script to do all of this setup for us. A pre-written Python script is provided at [[#Appendix B: Capture Script]]. Take a look at this code and notice what it does:&lt;br /&gt;
* it fills in the scope, target, and trace format that we'll use;&lt;br /&gt;
* it connects to the hardware; and&lt;br /&gt;
* it loads all of the hardware parameters for us. Nice!&lt;br /&gt;
Copy this script into a &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file somewhere convenient. Then, perform the following steps to finish the capture:&lt;br /&gt;
# Run the capture script, which will open a ChipWhisperer Capture window with everything connected for us.&lt;br /&gt;
# Open the terminal (''Tools &amp;gt; Terminal'') and connect to the board. While the terminal is open, press the ''Capture 1'' button. A single byte of data should appear in the terminal. This byte will either be &amp;lt;code&amp;gt;a1&amp;lt;/code&amp;gt; (CRC failed) or &amp;lt;code&amp;gt;a4&amp;lt;/code&amp;gt; (CRC OK). If you see any other responses, something is wrong. &lt;br /&gt;
#: [[File:Tutorial-A5-Capture.PNG|image]]&lt;br /&gt;
# Once you're happy with this, open the General Settings tab and set the Number of Traces. You should need around 100 traces to break AES.&lt;br /&gt;
# Press the ''Capture Many'' button to record the 100 traces. You'll see the new traces plotted on-screen.&lt;br /&gt;
# Once the program is finished capturing the traces, save the project. Put it somewhere memorable and give it a nice name.&lt;br /&gt;
&lt;br /&gt;
= Finding the Encryption Key =&lt;br /&gt;
Now that we have our traces, we can go ahead and perform the attack. As described in the background theory, we'll have to do two attacks - one to get the 14th round key, and another (using the first result) to get the 13th round key. Then, we'll do some post-processing to finally get the 256 bit encryption key.&lt;br /&gt;
&lt;br /&gt;
== 14th Round Key ==&lt;br /&gt;
We can attack the 14th round key with a standard, no-frills CPA attack:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer program and load the &amp;lt;code&amp;gt;.cwp&amp;lt;/code&amp;gt; file with the 13th and 14th round traces. This can be either the &amp;lt;code&amp;gt;aes256_round1413_key0_100.cwp&amp;lt;/code&amp;gt; file downloaded or the capture you performed.&lt;br /&gt;
# View and manipulate the trace data with the following steps:&lt;br /&gt;
## Switch to the ''Trace Output Plot'' tab&lt;br /&gt;
## Switch to the ''Results'' parameter setting tab&lt;br /&gt;
## Choose the traces to be plotted and press the ''Redraw'' button to draw them&lt;br /&gt;
## Right-click on the waveform to change options, or left-click and drag to zoom&lt;br /&gt;
## Use the toolbar to quickly reset the zoom back to original&lt;br /&gt;
##: [[File:Tutorial-A5-Plot-Traces.PNG|image]]&lt;br /&gt;
##: Notice that the traces are synchronized for the first 7000 samples, but become unsynchronized later. This fact will be important later in the tutorial.&lt;br /&gt;
# Set up the attack in the ''Attack'' settings tab:&lt;br /&gt;
## Leave the Crypto Algorithm set to AES-128. (Remember that we're applying the AES-128 attack to half of the AES-256 key!)&lt;br /&gt;
## Change the Leakage Model to ''HW: AES Inv SBox Output, First Round (Dec)''. &lt;br /&gt;
## 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!&lt;br /&gt;
##: [[File:Tutorial-A5-Hardware-Model.PNG|image]]&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Finally, run the attack by switching to the ''Results Table'' tab and then hitting the ''Attack'' button.&lt;br /&gt;
&lt;br /&gt;
There are a few ways to check the results of the attack. First, the results table will show the best guesses for each subkey. With the highlight override enabled, the red bytes should be the best guesses for every single subkey:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Right-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
However, the correct key will still rise to the top even if the wrong bytes are highlighted. The coloring and correlation coefficients in the results table should still make it clear that the top guess is the best one:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Wrong-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
{{warningbox|The default capture stores the WRONG knownkey, so you will have highlighted bytes that are not the correct key. We are looking instead for a large delta between the best-guess and all other guesses. For example for Byte 0 we have the most likely as 0.8141, and 2nd best guess as 0.3551. If our best guess was 0.8141 and 2nd best guess was 0.7981 this would indicate we likely haven't broken the key.}}&lt;br /&gt;
&lt;br /&gt;
Finally, the ''Output vs Point Plot'' shows the correlation against all of the sample points. The spikes on this plot show exactly where the attack was successful (ie: where the sensitive data was leaked):&lt;br /&gt;
&lt;br /&gt;
[[File:Aes14round points.png|image]]&lt;br /&gt;
&lt;br /&gt;
In any case, we've determined that the correct 14th round key is &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
''NOTE: if you're stuck, a full listing of the attack script is given in [[#Appendix C: AES-256 14th Round Key Script]].''&lt;br /&gt;
&lt;br /&gt;
== 13th Round Key ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The ChipWhisperer Analyzer software uses the settings in the GUI to automatically adjust an attack script. Every time you change a setting in the GUI, the autogenerated script is overwritten. Fpr example, the point range is mapped directly to an API call:&lt;br /&gt;
&lt;br /&gt;
[[File:autoscript1.png|image]]&lt;br /&gt;
&lt;br /&gt;
If we modified this script directly, it would be very easy for us to accidentally overwrite our custom script from the GUI. Instead, we'll use the autogenerated code to set up a base script, then add in our own attack model. To set up the base script, the procedure is as follows:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer software again and reopen the project file.&lt;br /&gt;
# 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.)&lt;br /&gt;
#: [[File:syncproblems.png|image]]&lt;br /&gt;
# Resynchronize the traces:&lt;br /&gt;
## In the ''Attack Script Generator'' tab, enable the ''Resync: Sum of Difference'' preprocessing:&lt;br /&gt;
##: [[File:resyncsad.png|image]]&lt;br /&gt;
## Enable the module and configure the input points. To start, set the reference points to (9063, 9177) and the input window to (9010, 9080), but don't be afraid to change these ranges:&lt;br /&gt;
##: [[File:resyncsad2.png|image]]&lt;br /&gt;
## Redraw the traces and confirm we now have synchronization on the second half:&lt;br /&gt;
##: [[File:resyncsad3.png|image]]&lt;br /&gt;
&lt;br /&gt;
{{warningbox|Make sure you get a nice aligned last section of the traces, as in the above figure. You may need to adjust the &amp;quot;input window&amp;quot; or &amp;quot;reference points&amp;quot; slightly. If you do not see the nice alignment the remaining attack will fail!}}&lt;br /&gt;
&lt;br /&gt;
Now, we are ready to make a copy of this script:&lt;br /&gt;
# Click on the auto-generated script&lt;br /&gt;
# Hit ''Copy'' and save the file somewhere&lt;br /&gt;
# Double-click on the description of the new file and give it a better name. &lt;br /&gt;
# Finally, hit ''Set Active'' after clicking on your new file. The result should look like this:&lt;br /&gt;
#: [[File:aes256_customscript.png|image]]&lt;br /&gt;
You can now edit the custom script file using the built-in editor OR with an external editor. In this example, the file would be &amp;lt;code&amp;gt;C:\Users\Colin\AppData\Local\Temp\testaes256.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = &amp;lt;PUT YOUR 14TH ROUND KEY YOU RECOVERED HERE&amp;gt;&lt;br /&gt;
        #For example: knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can look back at the C code of the AES-256 decryption to see how this is implementing the decryption code. Note that because of the Inverse MixColumns operation, we need the entire input ciphertext -- otherwise, we would only need to operate on one byte of the ciphertext.&lt;br /&gt;
&lt;br /&gt;
The last step is to perform the attack using this model:&lt;br /&gt;
# Add the above function to your custom script file.&lt;br /&gt;
# Change the &amp;lt;code&amp;gt;setAnalysisAlgorithm&amp;lt;/code&amp;gt; in the script to use your custom functions by making the following call:&lt;br /&gt;
#:&amp;lt;pre&amp;gt;leakage_object = AES128_8bit(AES256_Model)&amp;lt;/pre&amp;gt;&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;setPointRange()&amp;lt;/code&amp;gt; function call to&lt;br /&gt;
#:&amp;lt;pre&amp;gt;self.attack.setPointRange((8000,10990))&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Start the attack! Wait for the attack to complete, and you will determine the 13th round key:&lt;br /&gt;
#: [[File:Tutorial-A5-Results-Round-13.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Note you can check [[#Appendix C AES-256 13th Round Key Script]] for the complete contents of the attack script.&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;code&amp;gt;C6 BD 4E 50 AB CA 75 77 79 87 96 CA 1C 7F C5 82&amp;lt;/code&amp;gt;, if you recovered a different key replace the &amp;lt;code&amp;gt;knownkey&amp;lt;/code&amp;gt; value with yours):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from chipwhisperer.analyzer.attacks.models.aes.funcs import shiftrows,mixcolumns&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; knownkey = [0xC6, 0xBD, 0x4E, 0x50, 0xAB, 0xCA, 0x75, 0x77, 0x79, 0x87, 0x96, 0xCA, 0x1C, 0x7F, 0xC5, 0x82]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = shiftrows(knownkey)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = mixcolumns(key)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print &amp;amp;quot; &amp;amp;quot;.join([&amp;amp;quot;%02x&amp;amp;quot; % i for i in key])&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our hard work has rewarded us with the 13th round key, which is &amp;lt;code&amp;gt;c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Recovering the Encryption Key ==&lt;br /&gt;
Finally, we have enough information to recover the initial encryption key. In AES-256, the initial key is used in the key expansion routine to generate 15 round keys, and we know the key for round 13 and 14. All we need to do now is reverse the key scheduling algorithm to calculate the ''0/1 Round Key'' from the ''13/14 Round Key''. &lt;br /&gt;
&lt;br /&gt;
In the ChipWhisperer Analyzer software, a key schedule calculator is provided in ''Tools &amp;gt; AES Key Schedule'':&lt;br /&gt;
&lt;br /&gt;
[[File:keyschedule_tool.png|image]]&lt;br /&gt;
&lt;br /&gt;
Open this tool and paste the 13/14 round keys, which are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63 ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tell the tool that this key is the 13/14 round key; it will automatically display the entire key schedule and the initial encryption key. You should find the initial encryption key is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
94 28 5d 4d 6d cf ec 08 d8 ac dd f6 be 25 a4 99 c4 d9 d0 1e c3 40 7e d7 d5 28 d4 09 e9 f0 88 a1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Peek into &amp;lt;code&amp;gt;supersecret.h&amp;lt;/code&amp;gt;, confirm that this is the right key, and celebrate!&lt;br /&gt;
&lt;br /&gt;
= Next Steps =&lt;br /&gt;
If you want to go further with this tutorial, [[Tutorial A5-Bonus Breaking AES-256 Bootloader]] continues working with the same firmware to find the remaining secrets in the bootloader (the IV and the signature).&lt;br /&gt;
&lt;br /&gt;
= Appendix A: Target Code =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import time&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.capture.targets.SimpleSerial import SimpleSerial&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.capture.targets._base import TargetTemplate&lt;br /&gt;
from chipwhisperer.common.utils import pluginmanager&lt;br /&gt;
from chipwhisperer.capture.targets.simpleserial_readers.cwlite import SimpleSerial_ChipWhispererLite&lt;br /&gt;
from chipwhisperer.common.utils.parameter import setupSetParam&lt;br /&gt;
&lt;br /&gt;
# Class Crc&lt;br /&gt;
#############################################################&lt;br /&gt;
# These CRC routines are copy-pasted from pycrc, which are:&lt;br /&gt;
# Copyright (c) 2006-2013 Thomas Pircher &amp;lt;tehpeh@gmx.net&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
class Crc(object):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    A base class for CRC routines.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, width, poly):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;The Crc constructor.&lt;br /&gt;
&lt;br /&gt;
        The parameters are as follows:&lt;br /&gt;
            width&lt;br /&gt;
            poly&lt;br /&gt;
            reflect_in&lt;br /&gt;
            xor_in&lt;br /&gt;
            reflect_out&lt;br /&gt;
            xor_out&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.Width = width&lt;br /&gt;
        self.Poly = poly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.MSB_Mask = 0x1 &amp;lt;&amp;lt; (self.Width - 1)&lt;br /&gt;
        self.Mask = ((self.MSB_Mask - 1) &amp;lt;&amp;lt; 1) | 1&lt;br /&gt;
&lt;br /&gt;
        self.XorIn = 0x0000&lt;br /&gt;
        self.XorOut = 0x0000&lt;br /&gt;
&lt;br /&gt;
        self.DirectInit = self.XorIn&lt;br /&gt;
        self.NonDirectInit = self.__get_nondirect_init(self.XorIn)&lt;br /&gt;
        if self.Width &amp;lt; 8:&lt;br /&gt;
            self.CrcShift = 8 - self.Width&lt;br /&gt;
        else:&lt;br /&gt;
            self.CrcShift = 0&lt;br /&gt;
&lt;br /&gt;
    def __get_nondirect_init(self, init):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return the non-direct init if the direct algorithm has been selected.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        crc = init&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            bit = crc &amp;amp; 0x01&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc ^= self.Poly&lt;br /&gt;
            crc &amp;gt;&amp;gt;= 1&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc |= self.MSB_Mask&lt;br /&gt;
        return crc &amp;amp; self.Mask&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def bit_by_bit(self, in_data):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Classic simple and slow CRC implementation.  This function iterates bit&lt;br /&gt;
        by bit over the augmented input message and returns the calculated CRC&lt;br /&gt;
        value at the end.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # If the input data is a string, convert to bytes.&lt;br /&gt;
        if isinstance(in_data, str):&lt;br /&gt;
            in_data = [ord(c) for c in in_data]&lt;br /&gt;
&lt;br /&gt;
        register = self.NonDirectInit&lt;br /&gt;
        for octet in in_data:&lt;br /&gt;
            for i in range(8):&lt;br /&gt;
                topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
                register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask) | ((octet &amp;gt;&amp;gt; (7 - i)) &amp;amp; 0x01)&lt;br /&gt;
                if topbit:&lt;br /&gt;
                    register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
            register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask)&lt;br /&gt;
            if topbit:&lt;br /&gt;
                register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        return register ^ self.XorOut&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
class BootloaderTarget(TargetTemplate):&lt;br /&gt;
    _name = 'AES Bootloader'&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        TargetTemplate.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        ser_cons = pluginmanager.getPluginsInDictFromPackage(&amp;quot;chipwhisperer.capture.targets.simpleserial_readers&amp;quot;, True, False)&lt;br /&gt;
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]&lt;br /&gt;
&lt;br /&gt;
        self.keylength = 16&lt;br /&gt;
        self.input = &amp;quot;&amp;quot;&lt;br /&gt;
        self.crc = Crc(width=16, poly=0x1021)&lt;br /&gt;
        self.setConnection(self.ser)&lt;br /&gt;
&lt;br /&gt;
    def setKeyLen(self, klen):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Set key length in BITS &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.keylength = klen / 8        &lt;br /&gt;
 &lt;br /&gt;
    def keyLen(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Return key length in BYTES &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return self.keylength&lt;br /&gt;
&lt;br /&gt;
    def getConnection(self):&lt;br /&gt;
        return self.ser&lt;br /&gt;
&lt;br /&gt;
    def setConnection(self, con):&lt;br /&gt;
        self.ser = con&lt;br /&gt;
        self.params.append(self.ser.getParams())&lt;br /&gt;
        self.ser.connectStatus.connect(self.connectStatus.emit)&lt;br /&gt;
        self.ser.selectionChanged()&lt;br /&gt;
&lt;br /&gt;
    def con(self, scope=None):&lt;br /&gt;
        if not scope or not hasattr(scope, &amp;quot;qtadc&amp;quot;): Warning(&lt;br /&gt;
            &amp;quot;You need a scope with OpenADC connected to use this Target&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        self.ser.con(scope)&lt;br /&gt;
        # 'x' flushes everything &amp;amp; sets system back to idle&lt;br /&gt;
        self.ser.write(&amp;quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;quot;)&lt;br /&gt;
        self.ser.flush()&lt;br /&gt;
        self.connectStatus.setValue(True)&lt;br /&gt;
&lt;br /&gt;
    def close(self):&lt;br /&gt;
        if self.ser != None:&lt;br /&gt;
            self.ser.close()&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def init(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def setModeEncrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def setModeDecrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def convertVarToString(self, var):&lt;br /&gt;
        if isinstance(var, str):&lt;br /&gt;
            return var&lt;br /&gt;
&lt;br /&gt;
        sep = &amp;quot;&amp;quot;&lt;br /&gt;
        s = sep.join([&amp;quot;%c&amp;quot; % b for b in var])&lt;br /&gt;
        return s&lt;br /&gt;
&lt;br /&gt;
    def loadEncryptionKey(self, key):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def loadInput(self, inputtext):&lt;br /&gt;
        self.input = inputtext&lt;br /&gt;
&lt;br /&gt;
    def readOutput(self):&lt;br /&gt;
        # No actual output&lt;br /&gt;
        return [0] * 16&lt;br /&gt;
&lt;br /&gt;
    def isDone(self):&lt;br /&gt;
        return True&lt;br /&gt;
&lt;br /&gt;
    def checkEncryptionKey(self, kin):&lt;br /&gt;
        return kin&lt;br /&gt;
&lt;br /&gt;
    def go(self):&lt;br /&gt;
        # Starting byte is 0x00&lt;br /&gt;
        message = [0x00]&lt;br /&gt;
&lt;br /&gt;
        # Append 16 bytes of data&lt;br /&gt;
        message.extend(self.input)&lt;br /&gt;
&lt;br /&gt;
        # Append 2 bytes of CRC for input only (not including 0x00)&lt;br /&gt;
        crcdata = self.crc.bit_by_bit(self.input)&lt;br /&gt;
&lt;br /&gt;
        message.append(crcdata &amp;gt;&amp;gt; 8)&lt;br /&gt;
        message.append(crcdata &amp;amp; 0xff)&lt;br /&gt;
&lt;br /&gt;
        # Write message&lt;br /&gt;
        message = self.convertVarToString(message)&lt;br /&gt;
        for i in range(0, 5):&lt;br /&gt;
            self.ser.flush()&lt;br /&gt;
            self.ser.write(message)&lt;br /&gt;
            time.sleep(0.1)&lt;br /&gt;
            data = self.ser.read(1)&lt;br /&gt;
&lt;br /&gt;
            if len(data) &amp;gt; 0:&lt;br /&gt;
                resp = ord(data[0])&lt;br /&gt;
&lt;br /&gt;
                if resp == 0xA4:&lt;br /&gt;
                    # Encryption run OK&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
                if resp != 0xA1:&lt;br /&gt;
                    raise IOError(&amp;quot;Bad Response %x&amp;quot; % resp)&lt;br /&gt;
&lt;br /&gt;
        if len(data) &amp;gt; 0:&lt;br /&gt;
            if resp != 0xA4:&lt;br /&gt;
                raise IOError(&amp;quot;Failed to communicate, last response: %x&amp;quot; % resp)&lt;br /&gt;
        else:&lt;br /&gt;
            raise IOError(&amp;quot;Failed to communicate, no response&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix B: Capture Script =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
&lt;br /&gt;
# Check for PySide&lt;br /&gt;
try:&lt;br /&gt;
    from PySide.QtCore import *&lt;br /&gt;
    from PySide.QtGui import *&lt;br /&gt;
except ImportError:&lt;br /&gt;
    print &amp;quot;ERROR: PySide is required for this program&amp;quot;&lt;br /&gt;
    sys.exit()&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        super(UserScript, self).__init__(api)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        #User commands here&lt;br /&gt;
        print &amp;quot;***** Starting User Script *****&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
        # Set up board and target&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Scope Module', 'ChipWhisperer/OpenADC'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Trace Format', 'ChipWhisperer/Native'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Target Module', 'AES Bootloader'])&lt;br /&gt;
        self.api.connect()&lt;br /&gt;
&lt;br /&gt;
        # Fill in our other settings&lt;br /&gt;
        lstexample = [['CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
                      ['CW Extra Settings', 'Clock Source', 'Target IO-IN'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO2', 'Serial TXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO1', 'Serial RXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target HS IO-Out', 'CLKGEN'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Source', 'CLKGEN x4 via DCM'],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Total Samples', 11000],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Offset', 0],&lt;br /&gt;
                      ['OpenADC', 'Gain Setting', 'Setting', 45],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Mode', 'rising edge'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Multiply', 2],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Divide', 26],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
                      ]&lt;br /&gt;
&lt;br /&gt;
        # NOTE: For IV: offset = 70000&lt;br /&gt;
        #Download all hardware setup parameters&lt;br /&gt;
        for cmd in lstexample:&lt;br /&gt;
            self.api.setParameter(cmd)&lt;br /&gt;
&lt;br /&gt;
        # Try a couple of captures&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;***** Ending User Script *****&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    # Run the program&lt;br /&gt;
    app = cwc.makeApplication()&lt;br /&gt;
    Parameter.usePyQtGraph = True &lt;br /&gt;
    api = CWCoreAPI()             &lt;br /&gt;
    gui = cwc.CWCaptureGUI(api)                &lt;br /&gt;
    gui.show()                                 &lt;br /&gt;
    &lt;br /&gt;
    # Run our program and let the GUI take over&lt;br /&gt;
    api.runScriptClass(UserScript)             &lt;br /&gt;
    sys.exit(app.exec_())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix C: AES-256 14th Round Key Script =&lt;br /&gt;
Full attack script, copy/paste into a file then add as active attack script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 14th Round Key Attack&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        self.traces = self.api.project().traceManager()&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(CPAProgressive,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit.LEAK_HW_INVSBOXOUT_FIRSTROUND)&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(200)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    app = cwa.makeApplication()     # Comment if you don't need the GUI&lt;br /&gt;
    Parameter.usePyQtGraph = True   # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()               # Instantiate the API&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)    # Comment if you don't need the GUI&lt;br /&gt;
    gui.show()                      # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)  # Run UserScript through the API&lt;br /&gt;
    app.exec_()                     # Comment if you don't need the GUI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix D: AES-256 13th Round Key Script =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 13th Round Key Script&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    _name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    _description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        ppMod0 = preprocessing.resync_sad.ResyncSAD(self.api.project().traceManager())&lt;br /&gt;
        ppMod0.setEnabled(True)&lt;br /&gt;
        ppMod0.setReference(rtraceno=0, refpoints=(9100,9300), inputwindow=(8900,9500))&lt;br /&gt;
        ppMod0.init()&lt;br /&gt;
        self.traces = ppMod0&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setProject(self.api.project())&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        leakage_object = AES128_8bit(AES256_Model)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(chipwhisperer.analyzer.attacks.cpa_algorithms.progressive.CPAProgressive,leakage_object)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(150)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    Parameter.usePyQtGraph = True            # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()                        # Instantiate the API&lt;br /&gt;
    app = cwa.makeApplication(&amp;quot;Analyzer&amp;quot;)    # Comment if you don't need the GUI&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)             # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)           # Run UserScript through the API&lt;br /&gt;
    app.exec_()                              # Comment if you don't need the GUI&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2785</id>
		<title>Tutorial A5 Breaking AES-256 Bootloader</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2785"/>
				<updated>2017-07-23T16:20:03Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial will take you through a complete attack on an encrypted bootloader using AES-256. This demonstrates how to using side-channel power analysis on practical systems, along with discussing how to perform analysis with custom scripts.&lt;br /&gt;
&lt;br /&gt;
Whilst the tutorial assumes you will be performing the entire capture of traces along with the attack, it is possible to download the traces if you don't have the hardware, in which case skip section [[#Setting up the Hardware]] and [[#Capturing the Traces]].&lt;br /&gt;
&lt;br /&gt;
= Background =&lt;br /&gt;
In the world of microcontrollers, a bootloader is a special piece of firmware that is made to let the user upload new programs into memory. This is especially useful for devices with complex code that may need to be patched or otherwise updated in the future - a bootloader makes it possible for the user to upload a patched version of the firmware onto the micro. The bootloader receives information from a communication line (a USB port, serial port, ethernet port, WiFi connection, etc...) and stores this data into program memory. Once the full firmware has been received, the micro can happily run its updated code.&lt;br /&gt;
&lt;br /&gt;
There is one big security issue to worry about with bootloaders. A company may want to stop their customers from writing their own firmware and uploading it onto the micro. For example, this might be for protection reasons - hackers might be able to access parts of the device that weren't meant to be accessed. One way of stopping this is to add encryption. The company can add their own secret signature to the firmware code and encrypt it with a secret key. Then, the bootloader can decrypt the incoming firmware and confirm that the incoming firmware is correctly signed. Users will not know the secret key or the signature tied to the firmware, so they won't be able to &amp;quot;fake&amp;quot; their own.&lt;br /&gt;
&lt;br /&gt;
This tutorial will work with a simple AES-256 bootloader. The victim will receive data through a serial connection, decrypt the command, and confirm that the included signature is correct. Then, it will only save the code into memory if the signature check succeeded. To make this system more robust against attacks, the bootloader will use cipher-block chaining (CBC mode). Our goal is to find the secret key and the CBC initialization vector so that we could successfully fake our own firmware.&lt;br /&gt;
&lt;br /&gt;
== Bootloader Communications Protocol ==&lt;br /&gt;
The bootloader's communications protocol operates over a serial port at 38400 baud rate. The bootloader is always waiting for new data to be sent in this example; in real life one would typically force the bootloader to enter through a command sequence.&lt;br /&gt;
&lt;br /&gt;
Commands sent to the bootloader look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       |&amp;lt;-------- Encrypted block (16 bytes) ----------&amp;gt;|&lt;br /&gt;
       |                                                |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
| 0x00 |    Signature (4 Bytes)    |  Data (12 Bytes)   |   CRC-16    |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This frame has four parts:&lt;br /&gt;
* &amp;lt;code&amp;gt;0x00&amp;lt;/code&amp;gt;: 1 byte of fixed header&lt;br /&gt;
* Signature: A secret 4 byte constant. The bootloader will confirm that this signature is correct after decrypting the frame.&lt;br /&gt;
* Data: 12 bytes of the incoming firmware. This system forces us to send the code 12 bytes at a time; more complete bootloaders may allow longer variable-length frames.&lt;br /&gt;
* CRC-16: A 16-bit checksum using the CRC-CCITT polynomial (0x1021). The LSB of the CRC is sent first, followed by the MSB. The bootloader will reply over the serial port, describing whether or not this CRC check was valid.&lt;br /&gt;
As described in the diagram, the 16 byte block is not sent as plaintext. Instead, it is encrypted using AES-256 in CBC mode. This encryption method will be described in the next section.&lt;br /&gt;
&lt;br /&gt;
The bootloader responds to each command with a single byte indicating if the CRC-16 was OK or not:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            +------+&lt;br /&gt;
CRC-OK:     | 0xA1 |&lt;br /&gt;
            +------+&lt;br /&gt;
&lt;br /&gt;
            +------+&lt;br /&gt;
CRC Failed: | 0xA4 |&lt;br /&gt;
            +------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, after replying to the command, the bootloader veries that the signature is correct. If it matches the expected manufacturer's signature, the 12 bytes of data will be written to flash memory. Otherwise, the data is discarded.&lt;br /&gt;
&lt;br /&gt;
== Details of AES-256 CBC ==&lt;br /&gt;
&lt;br /&gt;
The system uses the AES algorithm in Cipher Block Chaining (CBC) mode. In general one avoids using encryption 'as-is' (i.e. Electronic Code Book), since it means any piece of plaintext always maps to the same piece of ciphertext. Cipher Block Chaining ensures that if you encrypted the same thing a bunch of times it would always encrypt to a new piece of ciphertext.&lt;br /&gt;
&lt;br /&gt;
You can see another reference on the design of the encryption side; we'll be only talking about the decryption side here. In this case AES-256 CBC mode is used as follows, where the details of the AES-256 Decryption block will be discussed in detail later:&lt;br /&gt;
&lt;br /&gt;
[[File:aes256_cbc.png|image]]&lt;br /&gt;
&lt;br /&gt;
This diagram shows that the output of the decryption is no longer used directly as the plaintext. Instead, the output is XORed with a 16 byte mask, which is usually taken from the previous ciphertext. Also, the first decryption block has no previous ciphertext to use, so a secret initialization vector (IV) is used instead. If we are going to decrypt the entire ciphertext (including block 0) or correctly generate our own ciphertext, we'll need to find this IV along with the AES key.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Attacking AES-256 ==&lt;br /&gt;
The system in this tutorial uses AES-256 encryption, which has a 256 bit (32 byte) key - twice as large as the 16 byte key we've attacked in previous tutorials. This means that our regular AES-128 CPA attacks won't quite work. However, extending these attacks to AES-256 is fairly straightforward: the theory is explained in detail in [[Extending AES-128 Attacks to AES-256]]. &lt;br /&gt;
&lt;br /&gt;
As the theory page explains, our AES-256 attack will have 4 steps:&lt;br /&gt;
# Perform a standard attack (as in AES-128 decryption) to determine the first 16 bytes of the key, corresponding to the 14th round encryption key.&lt;br /&gt;
# Using the known 14th round key, calculate the hypothetical outputs of each S-Box from the 13th round using the ciphertext processed by the 14th round, and determine the 16 bytes of the 13th round key manipulated by inverse MixColumns.&lt;br /&gt;
# Perform the MixColumns and ShiftRows operation on the hypothetical key determined above, recovering the 13th round key.&lt;br /&gt;
# Using the AES-256 key schedule, reverse the 13th and 14th round keys to determine the original AES-256 encryption key.&lt;br /&gt;
&lt;br /&gt;
= Setting up the Hardware =&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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)''.&lt;br /&gt;
&lt;br /&gt;
== Building/Programming the Bootloader ==&lt;br /&gt;
The firmware that implements the bootloader is available inside the ChipWhisperer folder at &amp;lt;code&amp;gt;chipwhisperer\hardware\victims\firmware\bootloader-aes256&amp;lt;/code&amp;gt;. If you've uploaded the firmware for any of the other tutorials, the process is identical:&lt;br /&gt;
&lt;br /&gt;
# Open a command prompt/terminal window and navigate to this folder. Enter the command &amp;lt;code&amp;gt;make PLATFORM=X&amp;lt;/code&amp;gt;, where X is the name of your target. For instance, use &amp;lt;code&amp;gt;PLATFORM=CW303&amp;lt;/code&amp;gt; on the ChipWhisperer Lite. Ensure that the program is successfully compiled. The output should end with a line like&lt;br /&gt;
#: &amp;lt;pre&amp;gt;Built for platform CW-Lite XMEGA&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open the ChipWhisperer Capture software and connect to your hardware. Open the programmer window (''Tools &amp;gt; CW-Lite XMEGA Programmer''), find the &amp;lt;code&amp;gt;.hex&amp;lt;/code&amp;gt; file that you just made, and ''Erase/Program/Verify FLASH''.&lt;br /&gt;
&lt;br /&gt;
The firmware is now loaded onto your hardware, and you can continue onto the capture process.&lt;br /&gt;
&lt;br /&gt;
= Capturing the Traces =&lt;br /&gt;
Once the hardware is ready, we can capture some traces for our attack using the ChipWhisperer Capture software. If you somehow got to the 5th ''Advanced Tutorial'' without getting this software ready, you can follow the helpful guide at [[Installing ChipWhisperer]].&lt;br /&gt;
&lt;br /&gt;
The first thing we need to do is add a new target to the ChipWhisperer system. (None of the existing ones know about the bootloader's data format, nor do they recognize the CRC responses that are sent back to us.) The code for this target is included in [[#Appendix A: Target Code]]. Copy/paste this into a Python file (call it whatever you want) and save it in a place where ChipWhisperer will look for it. There are two folders that you can use:&lt;br /&gt;
* Your computer should have a folder called &amp;lt;code&amp;gt;chipwhisperer_projects&amp;lt;/code&amp;gt; - if you don't know where this is, the ''File &amp;gt; Preferences'' window will tell you. The system looks in the folder &amp;lt;code&amp;gt;chipwhisperer_projects\chipwhisperer\capture\targets&amp;lt;/code&amp;gt; for new targets, so you can save your file here.&lt;br /&gt;
* Alternatively, all of the normal targets are stored in &amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\targets&amp;lt;/code&amp;gt;, so you can also save the file here. Note that this may not be possible if you don't have access to these folders (ex: your account doesn't have admin access).&lt;br /&gt;
&lt;br /&gt;
Next is the capture script. In some of the previous tutorials, we entered all of the capture settings by hand. Since we are civilized humans armed with technology, we can use a script to do all of this setup for us. A pre-written Python script is provided at [[#Appendix B: Capture Script]]. Take a look at this code and notice what it does:&lt;br /&gt;
* it fills in the scope, target, and trace format that we'll use;&lt;br /&gt;
* it connects to the hardware; and&lt;br /&gt;
* it loads all of the hardware parameters for us. Nice!&lt;br /&gt;
Copy this script into a &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file somewhere convenient. Then, perform the following steps to finish the capture:&lt;br /&gt;
# Run the capture script, which will open a ChipWhisperer Capture window with everything connected for us.&lt;br /&gt;
# Open the terminal (''Tools &amp;gt; Terminal'') and connect to the board. While the terminal is open, press the ''Capture 1'' button. A single byte of data should appear in the terminal. This byte will either be &amp;lt;code&amp;gt;a1&amp;lt;/code&amp;gt; (CRC failed) or &amp;lt;code&amp;gt;a4&amp;lt;/code&amp;gt; (CRC OK). If you see any other responses, something is wrong. &lt;br /&gt;
#: [[File:Tutorial-A5-Capture.PNG|image]]&lt;br /&gt;
# Once you're happy with this, open the General Settings tab and set the Number of Traces. You should need around 100 traces to break AES.&lt;br /&gt;
# Press the ''Capture Many'' button to record the 100 traces. You'll see the new traces plotted on-screen.&lt;br /&gt;
# Once the program is finished capturing the traces, save the project. Put it somewhere memorable and give it a nice name.&lt;br /&gt;
&lt;br /&gt;
= Finding the Encryption Key =&lt;br /&gt;
Now that we have our traces, we can go ahead and perform the attack. As described in the background theory, we'll have to do two attacks - one to get the 14th round key, and another (using the first result) to get the 13th round key. Then, we'll do some post-processing to finally get the 256 bit encryption key.&lt;br /&gt;
&lt;br /&gt;
== 14th Round Key ==&lt;br /&gt;
We can attack the 14th round key with a standard, no-frills CPA attack:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer program and load the &amp;lt;code&amp;gt;.cwp&amp;lt;/code&amp;gt; file with the 13th and 14th round traces. This can be either the &amp;lt;code&amp;gt;aes256_round1413_key0_100.cwp&amp;lt;/code&amp;gt; file downloaded or the capture you performed.&lt;br /&gt;
# View and manipulate the trace data with the following steps:&lt;br /&gt;
## Switch to the ''Trace Output Plot'' tab&lt;br /&gt;
## Switch to the ''Results'' parameter setting tab&lt;br /&gt;
## Choose the traces to be plotted and press the ''Redraw'' button to draw them&lt;br /&gt;
## Right-click on the waveform to change options, or left-click and drag to zoom&lt;br /&gt;
## Use the toolbar to quickly reset the zoom back to original&lt;br /&gt;
##: [[File:Tutorial-A5-Plot-Traces.PNG|image]]&lt;br /&gt;
##: Notice that the traces are synchronized for the first 7000 samples, but become unsynchronized later. This fact will be important later in the tutorial.&lt;br /&gt;
# Set up the attack in the ''Attack'' settings tab:&lt;br /&gt;
## Leave the Crypto Algorithm set to AES-128. (Remember that we're applying the AES-128 attack to half of the AES-256 key!)&lt;br /&gt;
## Change the Leakage Model to ''HW: AES Inv SBox Output, First Round (Dec)''. &lt;br /&gt;
## 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!&lt;br /&gt;
##: [[File:Tutorial-A5-Hardware-Model.PNG|image]]&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Finally, run the attack by switching to the ''Results Table'' tab and then hitting the ''Attack'' button.&lt;br /&gt;
&lt;br /&gt;
There are a few ways to check the results of the attack. First, the results table will show the best guesses for each subkey. With the highlight override enabled, the red bytes should be the best guesses for every single subkey:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Right-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
However, the correct key will still rise to the top even if the wrong bytes are highlighted. The coloring and correlation coefficients in the results table should still make it clear that the top guess is the best one:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Wrong-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
{{warningbox|The default capture stores the WRONG knownkey, so you will have highlighted bytes that are not the correct key. We are looking instead for a large delta between the best-guess and all other guesses. For example for Byte 0 we have the most likely as 0.8141, and 2nd best guess as 0.3551. If our best guess was 0.8141 and 2nd best guess was 0.7981 this would indicate we likely haven't broken the key.}}&lt;br /&gt;
&lt;br /&gt;
Finally, the ''Output vs Point Plot'' shows the correlation against all of the sample points. The spikes on this plot show exactly where the attack was successful (ie: where the sensitive data was leaked):&lt;br /&gt;
&lt;br /&gt;
[[File:Aes14round points.png|image]]&lt;br /&gt;
&lt;br /&gt;
In any case, we've determined that the correct 14th round key is &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
''NOTE: if you're stuck, a full listing of the attack script is given in [[#Appendix C: AES-256 14th Round Key Script]].''&lt;br /&gt;
&lt;br /&gt;
== 13th Round Key ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The ChipWhisperer Analyzer software uses the settings in the GUI to automatically adjust an attack script. Every time you change a setting in the GUI, the autogenerated script is overwritten. Fpr example, the point range is mapped directly to an API call:&lt;br /&gt;
&lt;br /&gt;
[[File:autoscript1.png|image]]&lt;br /&gt;
&lt;br /&gt;
If we modified this script directly, it would be very easy for us to accidentally overwrite our custom script from the GUI. Instead, we'll use the autogenerated code to set up a base script, then add in our own attack model. To set up the base script, the procedure is as follows:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer software again and reopen the project file.&lt;br /&gt;
# 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.)&lt;br /&gt;
#: [[File:syncproblems.png|image]]&lt;br /&gt;
# Resynchronize the traces:&lt;br /&gt;
## In the ''Attack Script Generator'' tab, enable the ''Resync: Sum of Difference'' preprocessing:&lt;br /&gt;
##: [[File:resyncsad.png|image]]&lt;br /&gt;
## Enable the module and configure the input points. To start, set the reference points to (9063, 9177) and the input window to (9010, 9080), but don't be afraid to change these ranges:&lt;br /&gt;
##: [[File:resyncsad2.png|image]]&lt;br /&gt;
##: You may have to adjust the reference points &amp;amp; input window ranges - the objective is to get a nice aligned trace on the second part.&lt;br /&gt;
## Redraw the traces and confirm we now have synchronization on the second half:&lt;br /&gt;
##: [[File:resyncsad3.png|image]]&lt;br /&gt;
&lt;br /&gt;
Now, we are ready to make a copy of this script:&lt;br /&gt;
# Click on the auto-generated script&lt;br /&gt;
# Hit ''Copy'' and save the file somewhere&lt;br /&gt;
# Double-click on the description of the new file and give it a better name. &lt;br /&gt;
# Finally, hit ''Set Active'' after clicking on your new file. The result should look like this:&lt;br /&gt;
#: [[File:aes256_customscript.png|image]]&lt;br /&gt;
You can now edit the custom script file using the built-in editor OR with an external editor. In this example, the file would be &amp;lt;code&amp;gt;C:\Users\Colin\AppData\Local\Temp\testaes256.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = &amp;lt;PUT YOUR 14TH ROUND KEY YOU RECOVERED HERE&amp;gt;&lt;br /&gt;
        #For example: knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can look back at the C code of the AES-256 decryption to see how this is implementing the decryption code. Note that because of the Inverse MixColumns operation, we need the entire input ciphertext -- otherwise, we would only need to operate on one byte of the ciphertext.&lt;br /&gt;
&lt;br /&gt;
The last step is to perform the attack using this model:&lt;br /&gt;
# Add the above function to your custom script file.&lt;br /&gt;
# Change the &amp;lt;code&amp;gt;setAnalysisAlgorithm&amp;lt;/code&amp;gt; in the script to use your custom functions by making the following call:&lt;br /&gt;
#:&amp;lt;pre&amp;gt;leakage_object = AES128_8bit(AES256_Model)&amp;lt;/pre&amp;gt;&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;setPointRange()&amp;lt;/code&amp;gt; function call to&lt;br /&gt;
#:&amp;lt;pre&amp;gt;self.attack.setPointRange((8000,10990))&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Start the attack! Wait for the attack to complete, and you will determine the 13th round key:&lt;br /&gt;
#: [[File:Tutorial-A5-Results-Round-13.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Note you can check [[#Appendix C AES-256 13th Round Key Script]] for the complete contents of the attack script.&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;code&amp;gt;C6 BD 4E 50 AB CA 75 77 79 87 96 CA 1C 7F C5 82&amp;lt;/code&amp;gt;, if you recovered a different key replace the &amp;lt;code&amp;gt;knownkey&amp;lt;/code&amp;gt; value with yours):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from chipwhisperer.analyzer.attacks.models.aes.funcs import shiftrows,mixcolumns&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; knownkey = [0xC6, 0xBD, 0x4E, 0x50, 0xAB, 0xCA, 0x75, 0x77, 0x79, 0x87, 0x96, 0xCA, 0x1C, 0x7F, 0xC5, 0x82]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = shiftrows(knownkey)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = mixcolumns(key)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print &amp;amp;quot; &amp;amp;quot;.join([&amp;amp;quot;%02x&amp;amp;quot; % i for i in key])&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our hard work has rewarded us with the 13th round key, which is &amp;lt;code&amp;gt;c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Recovering the Encryption Key ==&lt;br /&gt;
Finally, we have enough information to recover the initial encryption key. In AES-256, the initial key is used in the key expansion routine to generate 15 round keys, and we know the key for round 13 and 14. All we need to do now is reverse the key scheduling algorithm to calculate the ''0/1 Round Key'' from the ''13/14 Round Key''. &lt;br /&gt;
&lt;br /&gt;
In the ChipWhisperer Analyzer software, a key schedule calculator is provided in ''Tools &amp;gt; AES Key Schedule'':&lt;br /&gt;
&lt;br /&gt;
[[File:keyschedule_tool.png|image]]&lt;br /&gt;
&lt;br /&gt;
Open this tool and paste the 13/14 round keys, which are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63 ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tell the tool that this key is the 13/14 round key; it will automatically display the entire key schedule and the initial encryption key. You should find the initial encryption key is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
94 28 5d 4d 6d cf ec 08 d8 ac dd f6 be 25 a4 99 c4 d9 d0 1e c3 40 7e d7 d5 28 d4 09 e9 f0 88 a1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Peek into &amp;lt;code&amp;gt;supersecret.h&amp;lt;/code&amp;gt;, confirm that this is the right key, and celebrate!&lt;br /&gt;
&lt;br /&gt;
= Next Steps =&lt;br /&gt;
If you want to go further with this tutorial, [[Tutorial A5-Bonus Breaking AES-256 Bootloader]] continues working with the same firmware to find the remaining secrets in the bootloader (the IV and the signature).&lt;br /&gt;
&lt;br /&gt;
= Appendix A: Target Code =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import time&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.capture.targets.SimpleSerial import SimpleSerial&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.capture.targets._base import TargetTemplate&lt;br /&gt;
from chipwhisperer.common.utils import pluginmanager&lt;br /&gt;
from chipwhisperer.capture.targets.simpleserial_readers.cwlite import SimpleSerial_ChipWhispererLite&lt;br /&gt;
from chipwhisperer.common.utils.parameter import setupSetParam&lt;br /&gt;
&lt;br /&gt;
# Class Crc&lt;br /&gt;
#############################################################&lt;br /&gt;
# These CRC routines are copy-pasted from pycrc, which are:&lt;br /&gt;
# Copyright (c) 2006-2013 Thomas Pircher &amp;lt;tehpeh@gmx.net&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
class Crc(object):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    A base class for CRC routines.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, width, poly):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;The Crc constructor.&lt;br /&gt;
&lt;br /&gt;
        The parameters are as follows:&lt;br /&gt;
            width&lt;br /&gt;
            poly&lt;br /&gt;
            reflect_in&lt;br /&gt;
            xor_in&lt;br /&gt;
            reflect_out&lt;br /&gt;
            xor_out&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.Width = width&lt;br /&gt;
        self.Poly = poly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.MSB_Mask = 0x1 &amp;lt;&amp;lt; (self.Width - 1)&lt;br /&gt;
        self.Mask = ((self.MSB_Mask - 1) &amp;lt;&amp;lt; 1) | 1&lt;br /&gt;
&lt;br /&gt;
        self.XorIn = 0x0000&lt;br /&gt;
        self.XorOut = 0x0000&lt;br /&gt;
&lt;br /&gt;
        self.DirectInit = self.XorIn&lt;br /&gt;
        self.NonDirectInit = self.__get_nondirect_init(self.XorIn)&lt;br /&gt;
        if self.Width &amp;lt; 8:&lt;br /&gt;
            self.CrcShift = 8 - self.Width&lt;br /&gt;
        else:&lt;br /&gt;
            self.CrcShift = 0&lt;br /&gt;
&lt;br /&gt;
    def __get_nondirect_init(self, init):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return the non-direct init if the direct algorithm has been selected.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        crc = init&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            bit = crc &amp;amp; 0x01&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc ^= self.Poly&lt;br /&gt;
            crc &amp;gt;&amp;gt;= 1&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc |= self.MSB_Mask&lt;br /&gt;
        return crc &amp;amp; self.Mask&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def bit_by_bit(self, in_data):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Classic simple and slow CRC implementation.  This function iterates bit&lt;br /&gt;
        by bit over the augmented input message and returns the calculated CRC&lt;br /&gt;
        value at the end.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # If the input data is a string, convert to bytes.&lt;br /&gt;
        if isinstance(in_data, str):&lt;br /&gt;
            in_data = [ord(c) for c in in_data]&lt;br /&gt;
&lt;br /&gt;
        register = self.NonDirectInit&lt;br /&gt;
        for octet in in_data:&lt;br /&gt;
            for i in range(8):&lt;br /&gt;
                topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
                register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask) | ((octet &amp;gt;&amp;gt; (7 - i)) &amp;amp; 0x01)&lt;br /&gt;
                if topbit:&lt;br /&gt;
                    register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
            register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask)&lt;br /&gt;
            if topbit:&lt;br /&gt;
                register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        return register ^ self.XorOut&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
class BootloaderTarget(TargetTemplate):&lt;br /&gt;
    _name = 'AES Bootloader'&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        TargetTemplate.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        ser_cons = pluginmanager.getPluginsInDictFromPackage(&amp;quot;chipwhisperer.capture.targets.simpleserial_readers&amp;quot;, True, False)&lt;br /&gt;
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]&lt;br /&gt;
&lt;br /&gt;
        self.keylength = 16&lt;br /&gt;
        self.input = &amp;quot;&amp;quot;&lt;br /&gt;
        self.crc = Crc(width=16, poly=0x1021)&lt;br /&gt;
        self.setConnection(self.ser)&lt;br /&gt;
&lt;br /&gt;
    def setKeyLen(self, klen):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Set key length in BITS &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.keylength = klen / 8        &lt;br /&gt;
 &lt;br /&gt;
    def keyLen(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Return key length in BYTES &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return self.keylength&lt;br /&gt;
&lt;br /&gt;
    def getConnection(self):&lt;br /&gt;
        return self.ser&lt;br /&gt;
&lt;br /&gt;
    def setConnection(self, con):&lt;br /&gt;
        self.ser = con&lt;br /&gt;
        self.params.append(self.ser.getParams())&lt;br /&gt;
        self.ser.connectStatus.connect(self.connectStatus.emit)&lt;br /&gt;
        self.ser.selectionChanged()&lt;br /&gt;
&lt;br /&gt;
    def con(self, scope=None):&lt;br /&gt;
        if not scope or not hasattr(scope, &amp;quot;qtadc&amp;quot;): Warning(&lt;br /&gt;
            &amp;quot;You need a scope with OpenADC connected to use this Target&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        self.ser.con(scope)&lt;br /&gt;
        # 'x' flushes everything &amp;amp; sets system back to idle&lt;br /&gt;
        self.ser.write(&amp;quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;quot;)&lt;br /&gt;
        self.ser.flush()&lt;br /&gt;
        self.connectStatus.setValue(True)&lt;br /&gt;
&lt;br /&gt;
    def close(self):&lt;br /&gt;
        if self.ser != None:&lt;br /&gt;
            self.ser.close()&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def init(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def setModeEncrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def setModeDecrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def convertVarToString(self, var):&lt;br /&gt;
        if isinstance(var, str):&lt;br /&gt;
            return var&lt;br /&gt;
&lt;br /&gt;
        sep = &amp;quot;&amp;quot;&lt;br /&gt;
        s = sep.join([&amp;quot;%c&amp;quot; % b for b in var])&lt;br /&gt;
        return s&lt;br /&gt;
&lt;br /&gt;
    def loadEncryptionKey(self, key):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def loadInput(self, inputtext):&lt;br /&gt;
        self.input = inputtext&lt;br /&gt;
&lt;br /&gt;
    def readOutput(self):&lt;br /&gt;
        # No actual output&lt;br /&gt;
        return [0] * 16&lt;br /&gt;
&lt;br /&gt;
    def isDone(self):&lt;br /&gt;
        return True&lt;br /&gt;
&lt;br /&gt;
    def checkEncryptionKey(self, kin):&lt;br /&gt;
        return kin&lt;br /&gt;
&lt;br /&gt;
    def go(self):&lt;br /&gt;
        # Starting byte is 0x00&lt;br /&gt;
        message = [0x00]&lt;br /&gt;
&lt;br /&gt;
        # Append 16 bytes of data&lt;br /&gt;
        message.extend(self.input)&lt;br /&gt;
&lt;br /&gt;
        # Append 2 bytes of CRC for input only (not including 0x00)&lt;br /&gt;
        crcdata = self.crc.bit_by_bit(self.input)&lt;br /&gt;
&lt;br /&gt;
        message.append(crcdata &amp;gt;&amp;gt; 8)&lt;br /&gt;
        message.append(crcdata &amp;amp; 0xff)&lt;br /&gt;
&lt;br /&gt;
        # Write message&lt;br /&gt;
        message = self.convertVarToString(message)&lt;br /&gt;
        for i in range(0, 5):&lt;br /&gt;
            self.ser.flush()&lt;br /&gt;
            self.ser.write(message)&lt;br /&gt;
            time.sleep(0.1)&lt;br /&gt;
            data = self.ser.read(1)&lt;br /&gt;
&lt;br /&gt;
            if len(data) &amp;gt; 0:&lt;br /&gt;
                resp = ord(data[0])&lt;br /&gt;
&lt;br /&gt;
                if resp == 0xA4:&lt;br /&gt;
                    # Encryption run OK&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
                if resp != 0xA1:&lt;br /&gt;
                    raise IOError(&amp;quot;Bad Response %x&amp;quot; % resp)&lt;br /&gt;
&lt;br /&gt;
        if len(data) &amp;gt; 0:&lt;br /&gt;
            if resp != 0xA4:&lt;br /&gt;
                raise IOError(&amp;quot;Failed to communicate, last response: %x&amp;quot; % resp)&lt;br /&gt;
        else:&lt;br /&gt;
            raise IOError(&amp;quot;Failed to communicate, no response&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix B: Capture Script =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
&lt;br /&gt;
# Check for PySide&lt;br /&gt;
try:&lt;br /&gt;
    from PySide.QtCore import *&lt;br /&gt;
    from PySide.QtGui import *&lt;br /&gt;
except ImportError:&lt;br /&gt;
    print &amp;quot;ERROR: PySide is required for this program&amp;quot;&lt;br /&gt;
    sys.exit()&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        super(UserScript, self).__init__(api)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        #User commands here&lt;br /&gt;
        print &amp;quot;***** Starting User Script *****&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
        # Set up board and target&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Scope Module', 'ChipWhisperer/OpenADC'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Trace Format', 'ChipWhisperer/Native'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Target Module', 'AES Bootloader'])&lt;br /&gt;
        self.api.connect()&lt;br /&gt;
&lt;br /&gt;
        # Fill in our other settings&lt;br /&gt;
        lstexample = [['CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
                      ['CW Extra Settings', 'Clock Source', 'Target IO-IN'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO2', 'Serial TXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO1', 'Serial RXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target HS IO-Out', 'CLKGEN'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Source', 'CLKGEN x4 via DCM'],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Total Samples', 11000],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Offset', 0],&lt;br /&gt;
                      ['OpenADC', 'Gain Setting', 'Setting', 45],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Mode', 'rising edge'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Multiply', 2],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Divide', 26],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
                      ]&lt;br /&gt;
&lt;br /&gt;
        # NOTE: For IV: offset = 70000&lt;br /&gt;
        #Download all hardware setup parameters&lt;br /&gt;
        for cmd in lstexample:&lt;br /&gt;
            self.api.setParameter(cmd)&lt;br /&gt;
&lt;br /&gt;
        # Try a couple of captures&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;***** Ending User Script *****&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    # Run the program&lt;br /&gt;
    app = cwc.makeApplication()&lt;br /&gt;
    Parameter.usePyQtGraph = True &lt;br /&gt;
    api = CWCoreAPI()             &lt;br /&gt;
    gui = cwc.CWCaptureGUI(api)                &lt;br /&gt;
    gui.show()                                 &lt;br /&gt;
    &lt;br /&gt;
    # Run our program and let the GUI take over&lt;br /&gt;
    api.runScriptClass(UserScript)             &lt;br /&gt;
    sys.exit(app.exec_())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix C: AES-256 14th Round Key Script =&lt;br /&gt;
Full attack script, copy/paste into a file then add as active attack script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 14th Round Key Attack&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        self.traces = self.api.project().traceManager()&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(CPAProgressive,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit.LEAK_HW_INVSBOXOUT_FIRSTROUND)&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(200)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    app = cwa.makeApplication()     # Comment if you don't need the GUI&lt;br /&gt;
    Parameter.usePyQtGraph = True   # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()               # Instantiate the API&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)    # Comment if you don't need the GUI&lt;br /&gt;
    gui.show()                      # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)  # Run UserScript through the API&lt;br /&gt;
    app.exec_()                     # Comment if you don't need the GUI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix D: AES-256 13th Round Key Script =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 13th Round Key Script&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    _name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    _description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        ppMod0 = preprocessing.resync_sad.ResyncSAD(self.api.project().traceManager())&lt;br /&gt;
        ppMod0.setEnabled(True)&lt;br /&gt;
        ppMod0.setReference(rtraceno=0, refpoints=(9100,9300), inputwindow=(8900,9500))&lt;br /&gt;
        ppMod0.init()&lt;br /&gt;
        self.traces = ppMod0&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setProject(self.api.project())&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        leakage_object = AES128_8bit(AES256_Model)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(chipwhisperer.analyzer.attacks.cpa_algorithms.progressive.CPAProgressive,leakage_object)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(150)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    Parameter.usePyQtGraph = True            # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()                        # Instantiate the API&lt;br /&gt;
    app = cwa.makeApplication(&amp;quot;Analyzer&amp;quot;)    # Comment if you don't need the GUI&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)             # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)           # Run UserScript through the API&lt;br /&gt;
    app.exec_()                              # Comment if you don't need the GUI&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2784</id>
		<title>Tutorial A5 Breaking AES-256 Bootloader</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2784"/>
				<updated>2017-07-23T16:18:24Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial will take you through a complete attack on an encrypted bootloader using AES-256. This demonstrates how to using side-channel power analysis on practical systems, along with discussing how to perform analysis with custom scripts.&lt;br /&gt;
&lt;br /&gt;
Whilst the tutorial assumes you will be performing the entire capture of traces along with the attack, it is possible to download the traces if you don't have the hardware, in which case skip section [[#Setting up the Hardware]] and [[#Capturing the Traces]].&lt;br /&gt;
&lt;br /&gt;
= Background =&lt;br /&gt;
In the world of microcontrollers, a bootloader is a special piece of firmware that is made to let the user upload new programs into memory. This is especially useful for devices with complex code that may need to be patched or otherwise updated in the future - a bootloader makes it possible for the user to upload a patched version of the firmware onto the micro. The bootloader receives information from a communication line (a USB port, serial port, ethernet port, WiFi connection, etc...) and stores this data into program memory. Once the full firmware has been received, the micro can happily run its updated code.&lt;br /&gt;
&lt;br /&gt;
There is one big security issue to worry about with bootloaders. A company may want to stop their customers from writing their own firmware and uploading it onto the micro. For example, this might be for protection reasons - hackers might be able to access parts of the device that weren't meant to be accessed. One way of stopping this is to add encryption. The company can add their own secret signature to the firmware code and encrypt it with a secret key. Then, the bootloader can decrypt the incoming firmware and confirm that the incoming firmware is correctly signed. Users will not know the secret key or the signature tied to the firmware, so they won't be able to &amp;quot;fake&amp;quot; their own.&lt;br /&gt;
&lt;br /&gt;
This tutorial will work with a simple AES-256 bootloader. The victim will receive data through a serial connection, decrypt the command, and confirm that the included signature is correct. Then, it will only save the code into memory if the signature check succeeded. To make this system more robust against attacks, the bootloader will use cipher-block chaining (CBC mode). Our goal is to find the secret key and the CBC initialization vector so that we could successfully fake our own firmware.&lt;br /&gt;
&lt;br /&gt;
== Bootloader Communications Protocol ==&lt;br /&gt;
The bootloader's communications protocol operates over a serial port at 38400 baud rate. The bootloader is always waiting for new data to be sent in this example; in real life one would typically force the bootloader to enter through a command sequence.&lt;br /&gt;
&lt;br /&gt;
Commands sent to the bootloader look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       |&amp;lt;-------- Encrypted block (16 bytes) ----------&amp;gt;|&lt;br /&gt;
       |                                                |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
| 0x00 |    Signature (4 Bytes)    |  Data (12 Bytes)   |   CRC-16    |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This frame has four parts:&lt;br /&gt;
* &amp;lt;code&amp;gt;0x00&amp;lt;/code&amp;gt;: 1 byte of fixed header&lt;br /&gt;
* Signature: A secret 4 byte constant. The bootloader will confirm that this signature is correct after decrypting the frame.&lt;br /&gt;
* Data: 12 bytes of the incoming firmware. This system forces us to send the code 12 bytes at a time; more complete bootloaders may allow longer variable-length frames.&lt;br /&gt;
* CRC-16: A 16-bit checksum using the CRC-CCITT polynomial (0x1021). The LSB of the CRC is sent first, followed by the MSB. The bootloader will reply over the serial port, describing whether or not this CRC check was valid.&lt;br /&gt;
As described in the diagram, the 16 byte block is not sent as plaintext. Instead, it is encrypted using AES-256 in CBC mode. This encryption method will be described in the next section.&lt;br /&gt;
&lt;br /&gt;
The bootloader responds to each command with a single byte indicating if the CRC-16 was OK or not:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            +------+&lt;br /&gt;
CRC-OK:     | 0xA1 |&lt;br /&gt;
            +------+&lt;br /&gt;
&lt;br /&gt;
            +------+&lt;br /&gt;
CRC Failed: | 0xA4 |&lt;br /&gt;
            +------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, after replying to the command, the bootloader veries that the signature is correct. If it matches the expected manufacturer's signature, the 12 bytes of data will be written to flash memory. Otherwise, the data is discarded.&lt;br /&gt;
&lt;br /&gt;
== Details of AES-256 CBC ==&lt;br /&gt;
&lt;br /&gt;
The system uses the AES algorithm in Cipher Block Chaining (CBC) mode. In general one avoids using encryption 'as-is' (i.e. Electronic Code Book), since it means any piece of plaintext always maps to the same piece of ciphertext. Cipher Block Chaining ensures that if you encrypted the same thing a bunch of times it would always encrypt to a new piece of ciphertext.&lt;br /&gt;
&lt;br /&gt;
You can see another reference on the design of the encryption side; we'll be only talking about the decryption side here. In this case AES-256 CBC mode is used as follows, where the details of the AES-256 Decryption block will be discussed in detail later:&lt;br /&gt;
&lt;br /&gt;
[[File:aes256_cbc.png|image]]&lt;br /&gt;
&lt;br /&gt;
This diagram shows that the output of the decryption is no longer used directly as the plaintext. Instead, the output is XORed with a 16 byte mask, which is usually taken from the previous ciphertext. Also, the first decryption block has no previous ciphertext to use, so a secret initialization vector (IV) is used instead. If we are going to decrypt the entire ciphertext (including block 0) or correctly generate our own ciphertext, we'll need to find this IV along with the AES key.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Attacking AES-256 ==&lt;br /&gt;
The system in this tutorial uses AES-256 encryption, which has a 256 bit (32 byte) key - twice as large as the 16 byte key we've attacked in previous tutorials. This means that our regular AES-128 CPA attacks won't quite work. However, extending these attacks to AES-256 is fairly straightforward: the theory is explained in detail in [[Extending AES-128 Attacks to AES-256]]. &lt;br /&gt;
&lt;br /&gt;
As the theory page explains, our AES-256 attack will have 4 steps:&lt;br /&gt;
# Perform a standard attack (as in AES-128 decryption) to determine the first 16 bytes of the key, corresponding to the 14th round encryption key.&lt;br /&gt;
# Using the known 14th round key, calculate the hypothetical outputs of each S-Box from the 13th round using the ciphertext processed by the 14th round, and determine the 16 bytes of the 13th round key manipulated by inverse MixColumns.&lt;br /&gt;
# Perform the MixColumns and ShiftRows operation on the hypothetical key determined above, recovering the 13th round key.&lt;br /&gt;
# Using the AES-256 key schedule, reverse the 13th and 14th round keys to determine the original AES-256 encryption key.&lt;br /&gt;
&lt;br /&gt;
= Setting up the Hardware =&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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)''.&lt;br /&gt;
&lt;br /&gt;
== Building/Programming the Bootloader ==&lt;br /&gt;
The firmware that implements the bootloader is available inside the ChipWhisperer folder at &amp;lt;code&amp;gt;chipwhisperer\hardware\victims\firmware\bootloader-aes256&amp;lt;/code&amp;gt;. If you've uploaded the firmware for any of the other tutorials, the process is identical:&lt;br /&gt;
&lt;br /&gt;
# Open a command prompt/terminal window and navigate to this folder. Enter the command &amp;lt;code&amp;gt;make PLATFORM=X&amp;lt;/code&amp;gt;, where X is the name of your target. For instance, use &amp;lt;code&amp;gt;PLATFORM=CW303&amp;lt;/code&amp;gt; on the ChipWhisperer Lite. Ensure that the program is successfully compiled. The output should end with a line like&lt;br /&gt;
#: &amp;lt;pre&amp;gt;Built for platform CW-Lite XMEGA&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open the ChipWhisperer Capture software and connect to your hardware. Open the programmer window (''Tools &amp;gt; CW-Lite XMEGA Programmer''), find the &amp;lt;code&amp;gt;.hex&amp;lt;/code&amp;gt; file that you just made, and ''Erase/Program/Verify FLASH''.&lt;br /&gt;
&lt;br /&gt;
The firmware is now loaded onto your hardware, and you can continue onto the capture process.&lt;br /&gt;
&lt;br /&gt;
= Capturing the Traces =&lt;br /&gt;
Once the hardware is ready, we can capture some traces for our attack using the ChipWhisperer Capture software. If you somehow got to the 5th ''Advanced Tutorial'' without getting this software ready, you can follow the helpful guide at [[Installing ChipWhisperer]].&lt;br /&gt;
&lt;br /&gt;
The first thing we need to do is add a new target to the ChipWhisperer system. (None of the existing ones know about the bootloader's data format, nor do they recognize the CRC responses that are sent back to us.) The code for this target is included in [[#Appendix A: Target Code]]. Copy/paste this into a Python file (call it whatever you want) and save it in a place where ChipWhisperer will look for it. There are two folders that you can use:&lt;br /&gt;
* Your computer should have a folder called &amp;lt;code&amp;gt;chipwhisperer_projects&amp;lt;/code&amp;gt; - if you don't know where this is, the ''File &amp;gt; Preferences'' window will tell you. The system looks in the folder &amp;lt;code&amp;gt;chipwhisperer_projects\chipwhisperer\capture\targets&amp;lt;/code&amp;gt; for new targets, so you can save your file here.&lt;br /&gt;
* Alternatively, all of the normal targets are stored in &amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\targets&amp;lt;/code&amp;gt;, so you can also save the file here. Note that this may not be possible if you don't have access to these folders (ex: your account doesn't have admin access).&lt;br /&gt;
&lt;br /&gt;
Next is the capture script. In some of the previous tutorials, we entered all of the capture settings by hand. Since we are civilized humans armed with technology, we can use a script to do all of this setup for us. A pre-written Python script is provided at [[#Appendix B: Capture Script]]. Take a look at this code and notice what it does:&lt;br /&gt;
* it fills in the scope, target, and trace format that we'll use;&lt;br /&gt;
* it connects to the hardware; and&lt;br /&gt;
* it loads all of the hardware parameters for us. Nice!&lt;br /&gt;
Copy this script into a &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file somewhere convenient. Then, perform the following steps to finish the capture:&lt;br /&gt;
# Run the capture script, which will open a ChipWhisperer Capture window with everything connected for us.&lt;br /&gt;
# Open the terminal (''Tools &amp;gt; Terminal'') and connect to the board. While the terminal is open, press the ''Capture 1'' button. A single byte of data should appear in the terminal. This byte will either be &amp;lt;code&amp;gt;a1&amp;lt;/code&amp;gt; (CRC failed) or &amp;lt;code&amp;gt;a4&amp;lt;/code&amp;gt; (CRC OK). If you see any other responses, something is wrong. &lt;br /&gt;
#: [[File:Tutorial-A5-Capture.PNG|image]]&lt;br /&gt;
# Once you're happy with this, open the General Settings tab and set the Number of Traces. You should need around 100 traces to break AES.&lt;br /&gt;
# Press the ''Capture Many'' button to record the 100 traces. You'll see the new traces plotted on-screen.&lt;br /&gt;
# Once the program is finished capturing the traces, save the project. Put it somewhere memorable and give it a nice name.&lt;br /&gt;
&lt;br /&gt;
= Finding the Encryption Key =&lt;br /&gt;
Now that we have our traces, we can go ahead and perform the attack. As described in the background theory, we'll have to do two attacks - one to get the 14th round key, and another (using the first result) to get the 13th round key. Then, we'll do some post-processing to finally get the 256 bit encryption key.&lt;br /&gt;
&lt;br /&gt;
== 14th Round Key ==&lt;br /&gt;
We can attack the 14th round key with a standard, no-frills CPA attack:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer program and load the &amp;lt;code&amp;gt;.cwp&amp;lt;/code&amp;gt; file with the 13th and 14th round traces. This can be either the &amp;lt;code&amp;gt;aes256_round1413_key0_100.cwp&amp;lt;/code&amp;gt; file downloaded or the capture you performed.&lt;br /&gt;
# View and manipulate the trace data with the following steps:&lt;br /&gt;
## Switch to the ''Trace Output Plot'' tab&lt;br /&gt;
## Switch to the ''Results'' parameter setting tab&lt;br /&gt;
## Choose the traces to be plotted and press the ''Redraw'' button to draw them&lt;br /&gt;
## Right-click on the waveform to change options, or left-click and drag to zoom&lt;br /&gt;
## Use the toolbar to quickly reset the zoom back to original&lt;br /&gt;
##: [[File:Tutorial-A5-Plot-Traces.PNG|image]]&lt;br /&gt;
##: Notice that the traces are synchronized for the first 7000 samples, but become unsynchronized later. This fact will be important later in the tutorial.&lt;br /&gt;
# Set up the attack in the ''Attack'' settings tab:&lt;br /&gt;
## Leave the Crypto Algorithm set to AES-128. (Remember that we're applying the AES-128 attack to half of the AES-256 key!)&lt;br /&gt;
## Change the Leakage Model to ''HW: AES Inv SBox Output, First Round (Dec)''. &lt;br /&gt;
## 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!&lt;br /&gt;
##: [[File:Tutorial-A5-Hardware-Model.PNG|image]]&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Finally, run the attack by switching to the ''Results Table'' tab and then hitting the ''Attack'' button.&lt;br /&gt;
&lt;br /&gt;
There are a few ways to check the results of the attack. First, the results table will show the best guesses for each subkey. With the highlight override enabled, the red bytes should be the best guesses for every single subkey:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Right-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
However, the correct key will still rise to the top even if the wrong bytes are highlighted. The coloring and correlation coefficients in the results table should still make it clear that the top guess is the best one:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Wrong-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
{{warningbox|The default capture stores the WRONG knownkey, so you will have highlighted bytes that are not the correct key. We are looking instead for a large delta between the best-guess and all other guesses. For example for Byte 0 we have the most likely as 0.8141, and 2nd best guess as 0.3551. If our best guess was 0.8141 and 2nd best guess was 0.7981 this would indicate we likely haven't broken the key.}}&lt;br /&gt;
&lt;br /&gt;
Finally, the ''Output vs Point Plot'' shows the correlation against all of the sample points. The spikes on this plot show exactly where the attack was successful (ie: where the sensitive data was leaked):&lt;br /&gt;
&lt;br /&gt;
[[File:Aes14round points.png|image]]&lt;br /&gt;
&lt;br /&gt;
In any case, we've determined that the correct 14th round key is &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
''NOTE: if you're stuck, a full listing of the attack script is given in [[#Appendix C: AES-256 14th Round Key Script]].''&lt;br /&gt;
&lt;br /&gt;
== 13th Round Key ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The ChipWhisperer Analyzer software uses the settings in the GUI to automatically adjust an attack script. Every time you change a setting in the GUI, the autogenerated script is overwritten. Fpr example, the point range is mapped directly to an API call:&lt;br /&gt;
&lt;br /&gt;
[[File:autoscript1.png|image]]&lt;br /&gt;
&lt;br /&gt;
If we modified this script directly, it would be very easy for us to accidentally overwrite our custom script from the GUI. Instead, we'll use the autogenerated code to set up a base script, then add in our own attack model. To set up the base script, the procedure is as follows:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer software again and reopen the project file.&lt;br /&gt;
# 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.)&lt;br /&gt;
#: [[File:syncproblems.png|image]]&lt;br /&gt;
# Resynchronize the traces:&lt;br /&gt;
## In the ''Attack Script Generator'' tab, enable the ''Resync: Sum of Difference'' preprocessing:&lt;br /&gt;
##: [[File:resyncsad.png|image]]&lt;br /&gt;
## Enable the module and configure the input points. To start, set the reference points to (9063, 9177) and the input window to (9010, 9080), but don't be afraid to change these ranges:&lt;br /&gt;
##: [[File:resyncsad2.png|image]]&lt;br /&gt;
##: {{warningbox| You may have to adjust the reference points &amp;amp; input window ranges - the objective is to get a nice aligned trace on the second part.}}&lt;br /&gt;
## Redraw the traces and confirm we now have synchronization on the second half:&lt;br /&gt;
##: [[File:resyncsad3.png|image]]&lt;br /&gt;
&lt;br /&gt;
Now, we are ready to make a copy of this script:&lt;br /&gt;
# Click on the auto-generated script&lt;br /&gt;
# Hit ''Copy'' and save the file somewhere&lt;br /&gt;
# Double-click on the description of the new file and give it a better name. &lt;br /&gt;
# Finally, hit ''Set Active'' after clicking on your new file. The result should look like this:&lt;br /&gt;
#: [[File:aes256_customscript.png|image]]&lt;br /&gt;
You can now edit the custom script file using the built-in editor OR with an external editor. In this example, the file would be &amp;lt;code&amp;gt;C:\Users\Colin\AppData\Local\Temp\testaes256.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = &amp;lt;PUT YOUR 14TH ROUND KEY YOU RECOVERED HERE&amp;gt;&lt;br /&gt;
        #For example: knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can look back at the C code of the AES-256 decryption to see how this is implementing the decryption code. Note that because of the Inverse MixColumns operation, we need the entire input ciphertext -- otherwise, we would only need to operate on one byte of the ciphertext.&lt;br /&gt;
&lt;br /&gt;
The last step is to perform the attack using this model:&lt;br /&gt;
# Add the above function to your custom script file.&lt;br /&gt;
# Change the &amp;lt;code&amp;gt;setAnalysisAlgorithm&amp;lt;/code&amp;gt; in the script to use your custom functions by making the following call:&lt;br /&gt;
#:&amp;lt;pre&amp;gt;leakage_object = AES128_8bit(AES256_Model)&amp;lt;/pre&amp;gt;&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;setPointRange()&amp;lt;/code&amp;gt; function call to&lt;br /&gt;
#:&amp;lt;pre&amp;gt;self.attack.setPointRange((8000,10990))&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Start the attack! Wait for the attack to complete, and you will determine the 13th round key:&lt;br /&gt;
#: [[File:Tutorial-A5-Results-Round-13.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Note you can check [[#Appendix C AES-256 13th Round Key Script]] for the complete contents of the attack script.&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;code&amp;gt;C6 BD 4E 50 AB CA 75 77 79 87 96 CA 1C 7F C5 82&amp;lt;/code&amp;gt;, if you recovered a different key replace the &amp;lt;code&amp;gt;knownkey&amp;lt;/code&amp;gt; value with yours):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from chipwhisperer.analyzer.attacks.models.aes.funcs import shiftrows,mixcolumns&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; knownkey = [0xC6, 0xBD, 0x4E, 0x50, 0xAB, 0xCA, 0x75, 0x77, 0x79, 0x87, 0x96, 0xCA, 0x1C, 0x7F, 0xC5, 0x82]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = shiftrows(knownkey)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = mixcolumns(key)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print &amp;amp;quot; &amp;amp;quot;.join([&amp;amp;quot;%02x&amp;amp;quot; % i for i in key])&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our hard work has rewarded us with the 13th round key, which is &amp;lt;code&amp;gt;c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Recovering the Encryption Key ==&lt;br /&gt;
Finally, we have enough information to recover the initial encryption key. In AES-256, the initial key is used in the key expansion routine to generate 15 round keys, and we know the key for round 13 and 14. All we need to do now is reverse the key scheduling algorithm to calculate the ''0/1 Round Key'' from the ''13/14 Round Key''. &lt;br /&gt;
&lt;br /&gt;
In the ChipWhisperer Analyzer software, a key schedule calculator is provided in ''Tools &amp;gt; AES Key Schedule'':&lt;br /&gt;
&lt;br /&gt;
[[File:keyschedule_tool.png|image]]&lt;br /&gt;
&lt;br /&gt;
Open this tool and paste the 13/14 round keys, which are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63 ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tell the tool that this key is the 13/14 round key; it will automatically display the entire key schedule and the initial encryption key. You should find the initial encryption key is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
94 28 5d 4d 6d cf ec 08 d8 ac dd f6 be 25 a4 99 c4 d9 d0 1e c3 40 7e d7 d5 28 d4 09 e9 f0 88 a1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Peek into &amp;lt;code&amp;gt;supersecret.h&amp;lt;/code&amp;gt;, confirm that this is the right key, and celebrate!&lt;br /&gt;
&lt;br /&gt;
= Next Steps =&lt;br /&gt;
If you want to go further with this tutorial, [[Tutorial A5-Bonus Breaking AES-256 Bootloader]] continues working with the same firmware to find the remaining secrets in the bootloader (the IV and the signature).&lt;br /&gt;
&lt;br /&gt;
= Appendix A: Target Code =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import time&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.capture.targets.SimpleSerial import SimpleSerial&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.capture.targets._base import TargetTemplate&lt;br /&gt;
from chipwhisperer.common.utils import pluginmanager&lt;br /&gt;
from chipwhisperer.capture.targets.simpleserial_readers.cwlite import SimpleSerial_ChipWhispererLite&lt;br /&gt;
from chipwhisperer.common.utils.parameter import setupSetParam&lt;br /&gt;
&lt;br /&gt;
# Class Crc&lt;br /&gt;
#############################################################&lt;br /&gt;
# These CRC routines are copy-pasted from pycrc, which are:&lt;br /&gt;
# Copyright (c) 2006-2013 Thomas Pircher &amp;lt;tehpeh@gmx.net&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
class Crc(object):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    A base class for CRC routines.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, width, poly):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;The Crc constructor.&lt;br /&gt;
&lt;br /&gt;
        The parameters are as follows:&lt;br /&gt;
            width&lt;br /&gt;
            poly&lt;br /&gt;
            reflect_in&lt;br /&gt;
            xor_in&lt;br /&gt;
            reflect_out&lt;br /&gt;
            xor_out&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.Width = width&lt;br /&gt;
        self.Poly = poly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.MSB_Mask = 0x1 &amp;lt;&amp;lt; (self.Width - 1)&lt;br /&gt;
        self.Mask = ((self.MSB_Mask - 1) &amp;lt;&amp;lt; 1) | 1&lt;br /&gt;
&lt;br /&gt;
        self.XorIn = 0x0000&lt;br /&gt;
        self.XorOut = 0x0000&lt;br /&gt;
&lt;br /&gt;
        self.DirectInit = self.XorIn&lt;br /&gt;
        self.NonDirectInit = self.__get_nondirect_init(self.XorIn)&lt;br /&gt;
        if self.Width &amp;lt; 8:&lt;br /&gt;
            self.CrcShift = 8 - self.Width&lt;br /&gt;
        else:&lt;br /&gt;
            self.CrcShift = 0&lt;br /&gt;
&lt;br /&gt;
    def __get_nondirect_init(self, init):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return the non-direct init if the direct algorithm has been selected.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        crc = init&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            bit = crc &amp;amp; 0x01&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc ^= self.Poly&lt;br /&gt;
            crc &amp;gt;&amp;gt;= 1&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc |= self.MSB_Mask&lt;br /&gt;
        return crc &amp;amp; self.Mask&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def bit_by_bit(self, in_data):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Classic simple and slow CRC implementation.  This function iterates bit&lt;br /&gt;
        by bit over the augmented input message and returns the calculated CRC&lt;br /&gt;
        value at the end.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # If the input data is a string, convert to bytes.&lt;br /&gt;
        if isinstance(in_data, str):&lt;br /&gt;
            in_data = [ord(c) for c in in_data]&lt;br /&gt;
&lt;br /&gt;
        register = self.NonDirectInit&lt;br /&gt;
        for octet in in_data:&lt;br /&gt;
            for i in range(8):&lt;br /&gt;
                topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
                register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask) | ((octet &amp;gt;&amp;gt; (7 - i)) &amp;amp; 0x01)&lt;br /&gt;
                if topbit:&lt;br /&gt;
                    register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
            register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask)&lt;br /&gt;
            if topbit:&lt;br /&gt;
                register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        return register ^ self.XorOut&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
class BootloaderTarget(TargetTemplate):&lt;br /&gt;
    _name = 'AES Bootloader'&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        TargetTemplate.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        ser_cons = pluginmanager.getPluginsInDictFromPackage(&amp;quot;chipwhisperer.capture.targets.simpleserial_readers&amp;quot;, True, False)&lt;br /&gt;
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]&lt;br /&gt;
&lt;br /&gt;
        self.keylength = 16&lt;br /&gt;
        self.input = &amp;quot;&amp;quot;&lt;br /&gt;
        self.crc = Crc(width=16, poly=0x1021)&lt;br /&gt;
        self.setConnection(self.ser)&lt;br /&gt;
&lt;br /&gt;
    def setKeyLen(self, klen):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Set key length in BITS &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.keylength = klen / 8        &lt;br /&gt;
 &lt;br /&gt;
    def keyLen(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Return key length in BYTES &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return self.keylength&lt;br /&gt;
&lt;br /&gt;
    def getConnection(self):&lt;br /&gt;
        return self.ser&lt;br /&gt;
&lt;br /&gt;
    def setConnection(self, con):&lt;br /&gt;
        self.ser = con&lt;br /&gt;
        self.params.append(self.ser.getParams())&lt;br /&gt;
        self.ser.connectStatus.connect(self.connectStatus.emit)&lt;br /&gt;
        self.ser.selectionChanged()&lt;br /&gt;
&lt;br /&gt;
    def con(self, scope=None):&lt;br /&gt;
        if not scope or not hasattr(scope, &amp;quot;qtadc&amp;quot;): Warning(&lt;br /&gt;
            &amp;quot;You need a scope with OpenADC connected to use this Target&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        self.ser.con(scope)&lt;br /&gt;
        # 'x' flushes everything &amp;amp; sets system back to idle&lt;br /&gt;
        self.ser.write(&amp;quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;quot;)&lt;br /&gt;
        self.ser.flush()&lt;br /&gt;
        self.connectStatus.setValue(True)&lt;br /&gt;
&lt;br /&gt;
    def close(self):&lt;br /&gt;
        if self.ser != None:&lt;br /&gt;
            self.ser.close()&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def init(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def setModeEncrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def setModeDecrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def convertVarToString(self, var):&lt;br /&gt;
        if isinstance(var, str):&lt;br /&gt;
            return var&lt;br /&gt;
&lt;br /&gt;
        sep = &amp;quot;&amp;quot;&lt;br /&gt;
        s = sep.join([&amp;quot;%c&amp;quot; % b for b in var])&lt;br /&gt;
        return s&lt;br /&gt;
&lt;br /&gt;
    def loadEncryptionKey(self, key):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def loadInput(self, inputtext):&lt;br /&gt;
        self.input = inputtext&lt;br /&gt;
&lt;br /&gt;
    def readOutput(self):&lt;br /&gt;
        # No actual output&lt;br /&gt;
        return [0] * 16&lt;br /&gt;
&lt;br /&gt;
    def isDone(self):&lt;br /&gt;
        return True&lt;br /&gt;
&lt;br /&gt;
    def checkEncryptionKey(self, kin):&lt;br /&gt;
        return kin&lt;br /&gt;
&lt;br /&gt;
    def go(self):&lt;br /&gt;
        # Starting byte is 0x00&lt;br /&gt;
        message = [0x00]&lt;br /&gt;
&lt;br /&gt;
        # Append 16 bytes of data&lt;br /&gt;
        message.extend(self.input)&lt;br /&gt;
&lt;br /&gt;
        # Append 2 bytes of CRC for input only (not including 0x00)&lt;br /&gt;
        crcdata = self.crc.bit_by_bit(self.input)&lt;br /&gt;
&lt;br /&gt;
        message.append(crcdata &amp;gt;&amp;gt; 8)&lt;br /&gt;
        message.append(crcdata &amp;amp; 0xff)&lt;br /&gt;
&lt;br /&gt;
        # Write message&lt;br /&gt;
        message = self.convertVarToString(message)&lt;br /&gt;
        for i in range(0, 5):&lt;br /&gt;
            self.ser.flush()&lt;br /&gt;
            self.ser.write(message)&lt;br /&gt;
            time.sleep(0.1)&lt;br /&gt;
            data = self.ser.read(1)&lt;br /&gt;
&lt;br /&gt;
            if len(data) &amp;gt; 0:&lt;br /&gt;
                resp = ord(data[0])&lt;br /&gt;
&lt;br /&gt;
                if resp == 0xA4:&lt;br /&gt;
                    # Encryption run OK&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
                if resp != 0xA1:&lt;br /&gt;
                    raise IOError(&amp;quot;Bad Response %x&amp;quot; % resp)&lt;br /&gt;
&lt;br /&gt;
        if len(data) &amp;gt; 0:&lt;br /&gt;
            if resp != 0xA4:&lt;br /&gt;
                raise IOError(&amp;quot;Failed to communicate, last response: %x&amp;quot; % resp)&lt;br /&gt;
        else:&lt;br /&gt;
            raise IOError(&amp;quot;Failed to communicate, no response&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix B: Capture Script =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
&lt;br /&gt;
# Check for PySide&lt;br /&gt;
try:&lt;br /&gt;
    from PySide.QtCore import *&lt;br /&gt;
    from PySide.QtGui import *&lt;br /&gt;
except ImportError:&lt;br /&gt;
    print &amp;quot;ERROR: PySide is required for this program&amp;quot;&lt;br /&gt;
    sys.exit()&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        super(UserScript, self).__init__(api)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        #User commands here&lt;br /&gt;
        print &amp;quot;***** Starting User Script *****&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
        # Set up board and target&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Scope Module', 'ChipWhisperer/OpenADC'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Trace Format', 'ChipWhisperer/Native'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Target Module', 'AES Bootloader'])&lt;br /&gt;
        self.api.connect()&lt;br /&gt;
&lt;br /&gt;
        # Fill in our other settings&lt;br /&gt;
        lstexample = [['CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
                      ['CW Extra Settings', 'Clock Source', 'Target IO-IN'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO2', 'Serial TXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO1', 'Serial RXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target HS IO-Out', 'CLKGEN'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Source', 'CLKGEN x4 via DCM'],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Total Samples', 11000],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Offset', 0],&lt;br /&gt;
                      ['OpenADC', 'Gain Setting', 'Setting', 45],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Mode', 'rising edge'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Multiply', 2],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Divide', 26],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
                      ]&lt;br /&gt;
&lt;br /&gt;
        # NOTE: For IV: offset = 70000&lt;br /&gt;
        #Download all hardware setup parameters&lt;br /&gt;
        for cmd in lstexample:&lt;br /&gt;
            self.api.setParameter(cmd)&lt;br /&gt;
&lt;br /&gt;
        # Try a couple of captures&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;***** Ending User Script *****&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    # Run the program&lt;br /&gt;
    app = cwc.makeApplication()&lt;br /&gt;
    Parameter.usePyQtGraph = True &lt;br /&gt;
    api = CWCoreAPI()             &lt;br /&gt;
    gui = cwc.CWCaptureGUI(api)                &lt;br /&gt;
    gui.show()                                 &lt;br /&gt;
    &lt;br /&gt;
    # Run our program and let the GUI take over&lt;br /&gt;
    api.runScriptClass(UserScript)             &lt;br /&gt;
    sys.exit(app.exec_())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix C: AES-256 14th Round Key Script =&lt;br /&gt;
Full attack script, copy/paste into a file then add as active attack script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 14th Round Key Attack&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        self.traces = self.api.project().traceManager()&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(CPAProgressive,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit.LEAK_HW_INVSBOXOUT_FIRSTROUND)&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(200)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    app = cwa.makeApplication()     # Comment if you don't need the GUI&lt;br /&gt;
    Parameter.usePyQtGraph = True   # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()               # Instantiate the API&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)    # Comment if you don't need the GUI&lt;br /&gt;
    gui.show()                      # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)  # Run UserScript through the API&lt;br /&gt;
    app.exec_()                     # Comment if you don't need the GUI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix D: AES-256 13th Round Key Script =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 13th Round Key Script&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    _name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    _description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        ppMod0 = preprocessing.resync_sad.ResyncSAD(self.api.project().traceManager())&lt;br /&gt;
        ppMod0.setEnabled(True)&lt;br /&gt;
        ppMod0.setReference(rtraceno=0, refpoints=(9100,9300), inputwindow=(8900,9500))&lt;br /&gt;
        ppMod0.init()&lt;br /&gt;
        self.traces = ppMod0&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setProject(self.api.project())&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        leakage_object = AES128_8bit(AES256_Model)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(chipwhisperer.analyzer.attacks.cpa_algorithms.progressive.CPAProgressive,leakage_object)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(150)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    Parameter.usePyQtGraph = True            # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()                        # Instantiate the API&lt;br /&gt;
    app = cwa.makeApplication(&amp;quot;Analyzer&amp;quot;)    # Comment if you don't need the GUI&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)             # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)           # Run UserScript through the API&lt;br /&gt;
    app.exec_()                              # Comment if you don't need the GUI&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2783</id>
		<title>Tutorial A5 Breaking AES-256 Bootloader</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2783"/>
				<updated>2017-07-23T16:13:34Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial will take you through a complete attack on an encrypted bootloader using AES-256. This demonstrates how to using side-channel power analysis on practical systems, along with discussing how to perform analysis with custom scripts.&lt;br /&gt;
&lt;br /&gt;
Whilst the tutorial assumes you will be performing the entire capture of traces along with the attack, it is possible to download the traces if you don't have the hardware, in which case skip section [[#Setting up the Hardware]] and [[#Capturing the Traces]].&lt;br /&gt;
&lt;br /&gt;
= Background =&lt;br /&gt;
In the world of microcontrollers, a bootloader is a special piece of firmware that is made to let the user upload new programs into memory. This is especially useful for devices with complex code that may need to be patched or otherwise updated in the future - a bootloader makes it possible for the user to upload a patched version of the firmware onto the micro. The bootloader receives information from a communication line (a USB port, serial port, ethernet port, WiFi connection, etc...) and stores this data into program memory. Once the full firmware has been received, the micro can happily run its updated code.&lt;br /&gt;
&lt;br /&gt;
There is one big security issue to worry about with bootloaders. A company may want to stop their customers from writing their own firmware and uploading it onto the micro. For example, this might be for protection reasons - hackers might be able to access parts of the device that weren't meant to be accessed. One way of stopping this is to add encryption. The company can add their own secret signature to the firmware code and encrypt it with a secret key. Then, the bootloader can decrypt the incoming firmware and confirm that the incoming firmware is correctly signed. Users will not know the secret key or the signature tied to the firmware, so they won't be able to &amp;quot;fake&amp;quot; their own.&lt;br /&gt;
&lt;br /&gt;
This tutorial will work with a simple AES-256 bootloader. The victim will receive data through a serial connection, decrypt the command, and confirm that the included signature is correct. Then, it will only save the code into memory if the signature check succeeded. To make this system more robust against attacks, the bootloader will use cipher-block chaining (CBC mode). Our goal is to find the secret key and the CBC initialization vector so that we could successfully fake our own firmware.&lt;br /&gt;
&lt;br /&gt;
== Bootloader Communications Protocol ==&lt;br /&gt;
The bootloader's communications protocol operates over a serial port at 38400 baud rate. The bootloader is always waiting for new data to be sent in this example; in real life one would typically force the bootloader to enter through a command sequence.&lt;br /&gt;
&lt;br /&gt;
Commands sent to the bootloader look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       |&amp;lt;-------- Encrypted block (16 bytes) ----------&amp;gt;|&lt;br /&gt;
       |                                                |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
| 0x00 |    Signature (4 Bytes)    |  Data (12 Bytes)   |   CRC-16    |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This frame has four parts:&lt;br /&gt;
* &amp;lt;code&amp;gt;0x00&amp;lt;/code&amp;gt;: 1 byte of fixed header&lt;br /&gt;
* Signature: A secret 4 byte constant. The bootloader will confirm that this signature is correct after decrypting the frame.&lt;br /&gt;
* Data: 12 bytes of the incoming firmware. This system forces us to send the code 12 bytes at a time; more complete bootloaders may allow longer variable-length frames.&lt;br /&gt;
* CRC-16: A 16-bit checksum using the CRC-CCITT polynomial (0x1021). The LSB of the CRC is sent first, followed by the MSB. The bootloader will reply over the serial port, describing whether or not this CRC check was valid.&lt;br /&gt;
As described in the diagram, the 16 byte block is not sent as plaintext. Instead, it is encrypted using AES-256 in CBC mode. This encryption method will be described in the next section.&lt;br /&gt;
&lt;br /&gt;
The bootloader responds to each command with a single byte indicating if the CRC-16 was OK or not:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            +------+&lt;br /&gt;
CRC-OK:     | 0xA1 |&lt;br /&gt;
            +------+&lt;br /&gt;
&lt;br /&gt;
            +------+&lt;br /&gt;
CRC Failed: | 0xA4 |&lt;br /&gt;
            +------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, after replying to the command, the bootloader veries that the signature is correct. If it matches the expected manufacturer's signature, the 12 bytes of data will be written to flash memory. Otherwise, the data is discarded.&lt;br /&gt;
&lt;br /&gt;
== Details of AES-256 CBC ==&lt;br /&gt;
&lt;br /&gt;
The system uses the AES algorithm in Cipher Block Chaining (CBC) mode. In general one avoids using encryption 'as-is' (i.e. Electronic Code Book), since it means any piece of plaintext always maps to the same piece of ciphertext. Cipher Block Chaining ensures that if you encrypted the same thing a bunch of times it would always encrypt to a new piece of ciphertext.&lt;br /&gt;
&lt;br /&gt;
You can see another reference on the design of the encryption side; we'll be only talking about the decryption side here. In this case AES-256 CBC mode is used as follows, where the details of the AES-256 Decryption block will be discussed in detail later:&lt;br /&gt;
&lt;br /&gt;
[[File:aes256_cbc.png|image]]&lt;br /&gt;
&lt;br /&gt;
This diagram shows that the output of the decryption is no longer used directly as the plaintext. Instead, the output is XORed with a 16 byte mask, which is usually taken from the previous ciphertext. Also, the first decryption block has no previous ciphertext to use, so a secret initialization vector (IV) is used instead. If we are going to decrypt the entire ciphertext (including block 0) or correctly generate our own ciphertext, we'll need to find this IV along with the AES key.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Attacking AES-256 ==&lt;br /&gt;
The system in this tutorial uses AES-256 encryption, which has a 256 bit (32 byte) key - twice as large as the 16 byte key we've attacked in previous tutorials. This means that our regular AES-128 CPA attacks won't quite work. However, extending these attacks to AES-256 is fairly straightforward: the theory is explained in detail in [[Extending AES-128 Attacks to AES-256]]. &lt;br /&gt;
&lt;br /&gt;
As the theory page explains, our AES-256 attack will have 4 steps:&lt;br /&gt;
# Perform a standard attack (as in AES-128 decryption) to determine the first 16 bytes of the key, corresponding to the 14th round encryption key.&lt;br /&gt;
# Using the known 14th round key, calculate the hypothetical outputs of each S-Box from the 13th round using the ciphertext processed by the 14th round, and determine the 16 bytes of the 13th round key manipulated by inverse MixColumns.&lt;br /&gt;
# Perform the MixColumns and ShiftRows operation on the hypothetical key determined above, recovering the 13th round key.&lt;br /&gt;
# Using the AES-256 key schedule, reverse the 13th and 14th round keys to determine the original AES-256 encryption key.&lt;br /&gt;
&lt;br /&gt;
= Setting up the Hardware =&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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)''.&lt;br /&gt;
&lt;br /&gt;
== Building/Programming the Bootloader ==&lt;br /&gt;
The firmware that implements the bootloader is available inside the ChipWhisperer folder at &amp;lt;code&amp;gt;chipwhisperer\hardware\victims\firmware\bootloader-aes256&amp;lt;/code&amp;gt;. If you've uploaded the firmware for any of the other tutorials, the process is identical:&lt;br /&gt;
&lt;br /&gt;
# Open a command prompt/terminal window and navigate to this folder. Enter the command &amp;lt;code&amp;gt;make PLATFORM=X&amp;lt;/code&amp;gt;, where X is the name of your target. For instance, use &amp;lt;code&amp;gt;PLATFORM=CW303&amp;lt;/code&amp;gt; on the ChipWhisperer Lite. Ensure that the program is successfully compiled. The output should end with a line like&lt;br /&gt;
#: &amp;lt;pre&amp;gt;Built for platform CW-Lite XMEGA&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open the ChipWhisperer Capture software and connect to your hardware. Open the programmer window (''Tools &amp;gt; CW-Lite XMEGA Programmer''), find the &amp;lt;code&amp;gt;.hex&amp;lt;/code&amp;gt; file that you just made, and ''Erase/Program/Verify FLASH''.&lt;br /&gt;
&lt;br /&gt;
The firmware is now loaded onto your hardware, and you can continue onto the capture process.&lt;br /&gt;
&lt;br /&gt;
= Capturing the Traces =&lt;br /&gt;
Once the hardware is ready, we can capture some traces for our attack using the ChipWhisperer Capture software. If you somehow got to the 5th ''Advanced Tutorial'' without getting this software ready, you can follow the helpful guide at [[Installing ChipWhisperer]].&lt;br /&gt;
&lt;br /&gt;
The first thing we need to do is add a new target to the ChipWhisperer system. (None of the existing ones know about the bootloader's data format, nor do they recognize the CRC responses that are sent back to us.) The code for this target is included in [[#Appendix A: Target Code]]. Copy/paste this into a Python file (call it whatever you want) and save it in a place where ChipWhisperer will look for it. There are two folders that you can use:&lt;br /&gt;
* Your computer should have a folder called &amp;lt;code&amp;gt;chipwhisperer_projects&amp;lt;/code&amp;gt; - if you don't know where this is, the ''File &amp;gt; Preferences'' window will tell you. The system looks in the folder &amp;lt;code&amp;gt;chipwhisperer_projects\chipwhisperer\capture\targets&amp;lt;/code&amp;gt; for new targets, so you can save your file here.&lt;br /&gt;
* Alternatively, all of the normal targets are stored in &amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\targets&amp;lt;/code&amp;gt;, so you can also save the file here. Note that this may not be possible if you don't have access to these folders (ex: your account doesn't have admin access).&lt;br /&gt;
&lt;br /&gt;
Next is the capture script. In some of the previous tutorials, we entered all of the capture settings by hand. Since we are civilized humans armed with technology, we can use a script to do all of this setup for us. A pre-written Python script is provided at [[#Appendix B: Capture Script]]. Take a look at this code and notice what it does:&lt;br /&gt;
* it fills in the scope, target, and trace format that we'll use;&lt;br /&gt;
* it connects to the hardware; and&lt;br /&gt;
* it loads all of the hardware parameters for us. Nice!&lt;br /&gt;
Copy this script into a &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file somewhere convenient. Then, perform the following steps to finish the capture:&lt;br /&gt;
# Run the capture script, which will open a ChipWhisperer Capture window with everything connected for us.&lt;br /&gt;
# Open the terminal (''Tools &amp;gt; Terminal'') and connect to the board. While the terminal is open, press the ''Capture 1'' button. A single byte of data should appear in the terminal. This byte will either be &amp;lt;code&amp;gt;a1&amp;lt;/code&amp;gt; (CRC failed) or &amp;lt;code&amp;gt;a4&amp;lt;/code&amp;gt; (CRC OK). If you see any other responses, something is wrong. &lt;br /&gt;
#: [[File:Tutorial-A5-Capture.PNG|image]]&lt;br /&gt;
# Once you're happy with this, open the General Settings tab and set the Number of Traces. You should need around 100 traces to break AES.&lt;br /&gt;
# Press the ''Capture Many'' button to record the 100 traces. You'll see the new traces plotted on-screen.&lt;br /&gt;
# Once the program is finished capturing the traces, save the project. Put it somewhere memorable and give it a nice name.&lt;br /&gt;
&lt;br /&gt;
= Finding the Encryption Key =&lt;br /&gt;
Now that we have our traces, we can go ahead and perform the attack. As described in the background theory, we'll have to do two attacks - one to get the 14th round key, and another (using the first result) to get the 13th round key. Then, we'll do some post-processing to finally get the 256 bit encryption key.&lt;br /&gt;
&lt;br /&gt;
== 14th Round Key ==&lt;br /&gt;
We can attack the 14th round key with a standard, no-frills CPA attack:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer program and load the &amp;lt;code&amp;gt;.cwp&amp;lt;/code&amp;gt; file with the 13th and 14th round traces. This can be either the &amp;lt;code&amp;gt;aes256_round1413_key0_100.cwp&amp;lt;/code&amp;gt; file downloaded or the capture you performed.&lt;br /&gt;
# View and manipulate the trace data with the following steps:&lt;br /&gt;
## Switch to the ''Trace Output Plot'' tab&lt;br /&gt;
## Switch to the ''Results'' parameter setting tab&lt;br /&gt;
## Choose the traces to be plotted and press the ''Redraw'' button to draw them&lt;br /&gt;
## Right-click on the waveform to change options, or left-click and drag to zoom&lt;br /&gt;
## Use the toolbar to quickly reset the zoom back to original&lt;br /&gt;
##: [[File:Tutorial-A5-Plot-Traces.PNG|image]]&lt;br /&gt;
##: Notice that the traces are synchronized for the first 7000 samples, but become unsynchronized later. This fact will be important later in the tutorial.&lt;br /&gt;
# Set up the attack in the ''Attack'' settings tab:&lt;br /&gt;
## Leave the Crypto Algorithm set to AES-128. (Remember that we're applying the AES-128 attack to half of the AES-256 key!)&lt;br /&gt;
## Change the Leakage Model to ''HW: AES Inv SBox Output, First Round (Dec)''. &lt;br /&gt;
## 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!&lt;br /&gt;
##: [[File:Tutorial-A5-Hardware-Model.PNG|image]]&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Finally, run the attack by switching to the ''Results Table'' tab and then hitting the ''Attack'' button.&lt;br /&gt;
&lt;br /&gt;
There are a few ways to check the results of the attack. First, the results table will show the best guesses for each subkey. With the highlight override enabled, the red bytes should be the best guesses for every single subkey:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Right-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
However, the correct key will still rise to the top even if the wrong bytes are highlighted. The coloring and correlation coefficients in the results table should still make it clear that the top guess is the best one:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Wrong-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Finally, the ''Output vs Point Plot'' shows the correlation against all of the sample points. The spikes on this plot show exactly where the attack was successful (ie: where the sensitive data was leaked):&lt;br /&gt;
&lt;br /&gt;
[[File:Aes14round points.png|image]]&lt;br /&gt;
&lt;br /&gt;
In any case, we've determined that the correct 14th round key is &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
''NOTE: if you're stuck, a full listing of the attack script is given in [[#Appendix C: AES-256 14th Round Key Script]].''&lt;br /&gt;
&lt;br /&gt;
== 13th Round Key ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The ChipWhisperer Analyzer software uses the settings in the GUI to automatically adjust an attack script. Every time you change a setting in the GUI, the autogenerated script is overwritten. Fpr example, the point range is mapped directly to an API call:&lt;br /&gt;
&lt;br /&gt;
[[File:autoscript1.png|image]]&lt;br /&gt;
&lt;br /&gt;
If we modified this script directly, it would be very easy for us to accidentally overwrite our custom script from the GUI. Instead, we'll use the autogenerated code to set up a base script, then add in our own attack model. To set up the base script, the procedure is as follows:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer software again and reopen the project file.&lt;br /&gt;
# 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.)&lt;br /&gt;
#: [[File:syncproblems.png|image]]&lt;br /&gt;
# Resynchronize the traces:&lt;br /&gt;
## In the ''Attack Script Generator'' tab, enable the ''Resync: Sum of Difference'' preprocessing:&lt;br /&gt;
##: [[File:resyncsad.png|image]]&lt;br /&gt;
## Enable the module and configure the input points. To start, set the reference points to (9063, 9177) and the input window to (9010, 9080), but don't be afraid to change these ranges:&lt;br /&gt;
##: [[File:resyncsad2.png|image]]&lt;br /&gt;
## Redraw the traces and confirm we now have synchronization on the second half:&lt;br /&gt;
##: [[File:resyncsad3.png|image]]&lt;br /&gt;
&lt;br /&gt;
Now, we are ready to make a copy of this script:&lt;br /&gt;
# Click on the auto-generated script&lt;br /&gt;
# Hit ''Copy'' and save the file somewhere&lt;br /&gt;
# Double-click on the description of the new file and give it a better name. &lt;br /&gt;
# Finally, hit ''Set Active'' after clicking on your new file. The result should look like this:&lt;br /&gt;
#: [[File:aes256_customscript.png|image]]&lt;br /&gt;
You can now edit the custom script file using the built-in editor OR with an external editor. In this example, the file would be &amp;lt;code&amp;gt;C:\Users\Colin\AppData\Local\Temp\testaes256.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = &amp;lt;PUT YOUR 14TH ROUND KEY YOU RECOVERED HERE&amp;gt;&lt;br /&gt;
        #For example: knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can look back at the C code of the AES-256 decryption to see how this is implementing the decryption code. Note that because of the Inverse MixColumns operation, we need the entire input ciphertext -- otherwise, we would only need to operate on one byte of the ciphertext.&lt;br /&gt;
&lt;br /&gt;
The last step is to perform the attack using this model:&lt;br /&gt;
# Add the above function to your custom script file.&lt;br /&gt;
# Change the &amp;lt;code&amp;gt;setAnalysisAlgorithm&amp;lt;/code&amp;gt; in the script to use your custom functions by making the following call:&lt;br /&gt;
#:&amp;lt;pre&amp;gt;leakage_object = AES128_8bit(AES256_Model)&amp;lt;/pre&amp;gt;&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;setPointRange()&amp;lt;/code&amp;gt; function call to&lt;br /&gt;
#:&amp;lt;pre&amp;gt;self.attack.setPointRange((8000,10990))&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Start the attack! Wait for the attack to complete, and you will determine the 13th round key:&lt;br /&gt;
#: [[File:Tutorial-A5-Results-Round-13.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Note you can check [[#Appendix C AES-256 13th Round Key Script]] for the complete contents of the attack script.&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;code&amp;gt;C6 BD 4E 50 AB CA 75 77 79 87 96 CA 1C 7F C5 82&amp;lt;/code&amp;gt;, if you recovered a different key replace the &amp;lt;code&amp;gt;knownkey&amp;lt;/code&amp;gt; value with yours):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from chipwhisperer.analyzer.attacks.models.aes.funcs import shiftrows,mixcolumns&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; knownkey = [0xC6, 0xBD, 0x4E, 0x50, 0xAB, 0xCA, 0x75, 0x77, 0x79, 0x87, 0x96, 0xCA, 0x1C, 0x7F, 0xC5, 0x82]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = shiftrows(knownkey)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = mixcolumns(key)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print &amp;amp;quot; &amp;amp;quot;.join([&amp;amp;quot;%02x&amp;amp;quot; % i for i in key])&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our hard work has rewarded us with the 13th round key, which is &amp;lt;code&amp;gt;c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Recovering the Encryption Key ==&lt;br /&gt;
Finally, we have enough information to recover the initial encryption key. In AES-256, the initial key is used in the key expansion routine to generate 15 round keys, and we know the key for round 13 and 14. All we need to do now is reverse the key scheduling algorithm to calculate the ''0/1 Round Key'' from the ''13/14 Round Key''. &lt;br /&gt;
&lt;br /&gt;
In the ChipWhisperer Analyzer software, a key schedule calculator is provided in ''Tools &amp;gt; AES Key Schedule'':&lt;br /&gt;
&lt;br /&gt;
[[File:keyschedule_tool.png|image]]&lt;br /&gt;
&lt;br /&gt;
Open this tool and paste the 13/14 round keys, which are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63 ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tell the tool that this key is the 13/14 round key; it will automatically display the entire key schedule and the initial encryption key. You should find the initial encryption key is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
94 28 5d 4d 6d cf ec 08 d8 ac dd f6 be 25 a4 99 c4 d9 d0 1e c3 40 7e d7 d5 28 d4 09 e9 f0 88 a1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Peek into &amp;lt;code&amp;gt;supersecret.h&amp;lt;/code&amp;gt;, confirm that this is the right key, and celebrate!&lt;br /&gt;
&lt;br /&gt;
= Next Steps =&lt;br /&gt;
If you want to go further with this tutorial, [[Tutorial A5-Bonus Breaking AES-256 Bootloader]] continues working with the same firmware to find the remaining secrets in the bootloader (the IV and the signature).&lt;br /&gt;
&lt;br /&gt;
= Appendix A: Target Code =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import time&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.capture.targets.SimpleSerial import SimpleSerial&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.capture.targets._base import TargetTemplate&lt;br /&gt;
from chipwhisperer.common.utils import pluginmanager&lt;br /&gt;
from chipwhisperer.capture.targets.simpleserial_readers.cwlite import SimpleSerial_ChipWhispererLite&lt;br /&gt;
from chipwhisperer.common.utils.parameter import setupSetParam&lt;br /&gt;
&lt;br /&gt;
# Class Crc&lt;br /&gt;
#############################################################&lt;br /&gt;
# These CRC routines are copy-pasted from pycrc, which are:&lt;br /&gt;
# Copyright (c) 2006-2013 Thomas Pircher &amp;lt;tehpeh@gmx.net&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
class Crc(object):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    A base class for CRC routines.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, width, poly):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;The Crc constructor.&lt;br /&gt;
&lt;br /&gt;
        The parameters are as follows:&lt;br /&gt;
            width&lt;br /&gt;
            poly&lt;br /&gt;
            reflect_in&lt;br /&gt;
            xor_in&lt;br /&gt;
            reflect_out&lt;br /&gt;
            xor_out&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.Width = width&lt;br /&gt;
        self.Poly = poly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.MSB_Mask = 0x1 &amp;lt;&amp;lt; (self.Width - 1)&lt;br /&gt;
        self.Mask = ((self.MSB_Mask - 1) &amp;lt;&amp;lt; 1) | 1&lt;br /&gt;
&lt;br /&gt;
        self.XorIn = 0x0000&lt;br /&gt;
        self.XorOut = 0x0000&lt;br /&gt;
&lt;br /&gt;
        self.DirectInit = self.XorIn&lt;br /&gt;
        self.NonDirectInit = self.__get_nondirect_init(self.XorIn)&lt;br /&gt;
        if self.Width &amp;lt; 8:&lt;br /&gt;
            self.CrcShift = 8 - self.Width&lt;br /&gt;
        else:&lt;br /&gt;
            self.CrcShift = 0&lt;br /&gt;
&lt;br /&gt;
    def __get_nondirect_init(self, init):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return the non-direct init if the direct algorithm has been selected.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        crc = init&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            bit = crc &amp;amp; 0x01&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc ^= self.Poly&lt;br /&gt;
            crc &amp;gt;&amp;gt;= 1&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc |= self.MSB_Mask&lt;br /&gt;
        return crc &amp;amp; self.Mask&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def bit_by_bit(self, in_data):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Classic simple and slow CRC implementation.  This function iterates bit&lt;br /&gt;
        by bit over the augmented input message and returns the calculated CRC&lt;br /&gt;
        value at the end.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # If the input data is a string, convert to bytes.&lt;br /&gt;
        if isinstance(in_data, str):&lt;br /&gt;
            in_data = [ord(c) for c in in_data]&lt;br /&gt;
&lt;br /&gt;
        register = self.NonDirectInit&lt;br /&gt;
        for octet in in_data:&lt;br /&gt;
            for i in range(8):&lt;br /&gt;
                topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
                register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask) | ((octet &amp;gt;&amp;gt; (7 - i)) &amp;amp; 0x01)&lt;br /&gt;
                if topbit:&lt;br /&gt;
                    register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
            register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask)&lt;br /&gt;
            if topbit:&lt;br /&gt;
                register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        return register ^ self.XorOut&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
class BootloaderTarget(TargetTemplate):&lt;br /&gt;
    _name = 'AES Bootloader'&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        TargetTemplate.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        ser_cons = pluginmanager.getPluginsInDictFromPackage(&amp;quot;chipwhisperer.capture.targets.simpleserial_readers&amp;quot;, True, False)&lt;br /&gt;
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]&lt;br /&gt;
&lt;br /&gt;
        self.keylength = 16&lt;br /&gt;
        self.input = &amp;quot;&amp;quot;&lt;br /&gt;
        self.crc = Crc(width=16, poly=0x1021)&lt;br /&gt;
        self.setConnection(self.ser)&lt;br /&gt;
&lt;br /&gt;
    def setKeyLen(self, klen):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Set key length in BITS &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.keylength = klen / 8        &lt;br /&gt;
 &lt;br /&gt;
    def keyLen(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Return key length in BYTES &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return self.keylength&lt;br /&gt;
&lt;br /&gt;
    def getConnection(self):&lt;br /&gt;
        return self.ser&lt;br /&gt;
&lt;br /&gt;
    def setConnection(self, con):&lt;br /&gt;
        self.ser = con&lt;br /&gt;
        self.params.append(self.ser.getParams())&lt;br /&gt;
        self.ser.connectStatus.connect(self.connectStatus.emit)&lt;br /&gt;
        self.ser.selectionChanged()&lt;br /&gt;
&lt;br /&gt;
    def con(self, scope=None):&lt;br /&gt;
        if not scope or not hasattr(scope, &amp;quot;qtadc&amp;quot;): Warning(&lt;br /&gt;
            &amp;quot;You need a scope with OpenADC connected to use this Target&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        self.ser.con(scope)&lt;br /&gt;
        # 'x' flushes everything &amp;amp; sets system back to idle&lt;br /&gt;
        self.ser.write(&amp;quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;quot;)&lt;br /&gt;
        self.ser.flush()&lt;br /&gt;
        self.connectStatus.setValue(True)&lt;br /&gt;
&lt;br /&gt;
    def close(self):&lt;br /&gt;
        if self.ser != None:&lt;br /&gt;
            self.ser.close()&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def init(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def setModeEncrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def setModeDecrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def convertVarToString(self, var):&lt;br /&gt;
        if isinstance(var, str):&lt;br /&gt;
            return var&lt;br /&gt;
&lt;br /&gt;
        sep = &amp;quot;&amp;quot;&lt;br /&gt;
        s = sep.join([&amp;quot;%c&amp;quot; % b for b in var])&lt;br /&gt;
        return s&lt;br /&gt;
&lt;br /&gt;
    def loadEncryptionKey(self, key):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def loadInput(self, inputtext):&lt;br /&gt;
        self.input = inputtext&lt;br /&gt;
&lt;br /&gt;
    def readOutput(self):&lt;br /&gt;
        # No actual output&lt;br /&gt;
        return [0] * 16&lt;br /&gt;
&lt;br /&gt;
    def isDone(self):&lt;br /&gt;
        return True&lt;br /&gt;
&lt;br /&gt;
    def checkEncryptionKey(self, kin):&lt;br /&gt;
        return kin&lt;br /&gt;
&lt;br /&gt;
    def go(self):&lt;br /&gt;
        # Starting byte is 0x00&lt;br /&gt;
        message = [0x00]&lt;br /&gt;
&lt;br /&gt;
        # Append 16 bytes of data&lt;br /&gt;
        message.extend(self.input)&lt;br /&gt;
&lt;br /&gt;
        # Append 2 bytes of CRC for input only (not including 0x00)&lt;br /&gt;
        crcdata = self.crc.bit_by_bit(self.input)&lt;br /&gt;
&lt;br /&gt;
        message.append(crcdata &amp;gt;&amp;gt; 8)&lt;br /&gt;
        message.append(crcdata &amp;amp; 0xff)&lt;br /&gt;
&lt;br /&gt;
        # Write message&lt;br /&gt;
        message = self.convertVarToString(message)&lt;br /&gt;
        for i in range(0, 5):&lt;br /&gt;
            self.ser.flush()&lt;br /&gt;
            self.ser.write(message)&lt;br /&gt;
            time.sleep(0.1)&lt;br /&gt;
            data = self.ser.read(1)&lt;br /&gt;
&lt;br /&gt;
            if len(data) &amp;gt; 0:&lt;br /&gt;
                resp = ord(data[0])&lt;br /&gt;
&lt;br /&gt;
                if resp == 0xA4:&lt;br /&gt;
                    # Encryption run OK&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
                if resp != 0xA1:&lt;br /&gt;
                    raise IOError(&amp;quot;Bad Response %x&amp;quot; % resp)&lt;br /&gt;
&lt;br /&gt;
        if len(data) &amp;gt; 0:&lt;br /&gt;
            if resp != 0xA4:&lt;br /&gt;
                raise IOError(&amp;quot;Failed to communicate, last response: %x&amp;quot; % resp)&lt;br /&gt;
        else:&lt;br /&gt;
            raise IOError(&amp;quot;Failed to communicate, no response&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix B: Capture Script =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
&lt;br /&gt;
# Check for PySide&lt;br /&gt;
try:&lt;br /&gt;
    from PySide.QtCore import *&lt;br /&gt;
    from PySide.QtGui import *&lt;br /&gt;
except ImportError:&lt;br /&gt;
    print &amp;quot;ERROR: PySide is required for this program&amp;quot;&lt;br /&gt;
    sys.exit()&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        super(UserScript, self).__init__(api)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        #User commands here&lt;br /&gt;
        print &amp;quot;***** Starting User Script *****&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
        # Set up board and target&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Scope Module', 'ChipWhisperer/OpenADC'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Trace Format', 'ChipWhisperer/Native'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Target Module', 'AES Bootloader'])&lt;br /&gt;
        self.api.connect()&lt;br /&gt;
&lt;br /&gt;
        # Fill in our other settings&lt;br /&gt;
        lstexample = [['CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
                      ['CW Extra Settings', 'Clock Source', 'Target IO-IN'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO2', 'Serial TXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO1', 'Serial RXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target HS IO-Out', 'CLKGEN'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Source', 'CLKGEN x4 via DCM'],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Total Samples', 11000],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Offset', 0],&lt;br /&gt;
                      ['OpenADC', 'Gain Setting', 'Setting', 45],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Mode', 'rising edge'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Multiply', 2],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Divide', 26],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
                      ]&lt;br /&gt;
&lt;br /&gt;
        # NOTE: For IV: offset = 70000&lt;br /&gt;
        #Download all hardware setup parameters&lt;br /&gt;
        for cmd in lstexample:&lt;br /&gt;
            self.api.setParameter(cmd)&lt;br /&gt;
&lt;br /&gt;
        # Try a couple of captures&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;***** Ending User Script *****&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    # Run the program&lt;br /&gt;
    app = cwc.makeApplication()&lt;br /&gt;
    Parameter.usePyQtGraph = True &lt;br /&gt;
    api = CWCoreAPI()             &lt;br /&gt;
    gui = cwc.CWCaptureGUI(api)                &lt;br /&gt;
    gui.show()                                 &lt;br /&gt;
    &lt;br /&gt;
    # Run our program and let the GUI take over&lt;br /&gt;
    api.runScriptClass(UserScript)             &lt;br /&gt;
    sys.exit(app.exec_())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix C: AES-256 14th Round Key Script =&lt;br /&gt;
Full attack script, copy/paste into a file then add as active attack script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 14th Round Key Attack&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        self.traces = self.api.project().traceManager()&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(CPAProgressive,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit.LEAK_HW_INVSBOXOUT_FIRSTROUND)&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(200)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    app = cwa.makeApplication()     # Comment if you don't need the GUI&lt;br /&gt;
    Parameter.usePyQtGraph = True   # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()               # Instantiate the API&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)    # Comment if you don't need the GUI&lt;br /&gt;
    gui.show()                      # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)  # Run UserScript through the API&lt;br /&gt;
    app.exec_()                     # Comment if you don't need the GUI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix D: AES-256 13th Round Key Script =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 13th Round Key Script&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    _name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    _description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        ppMod0 = preprocessing.resync_sad.ResyncSAD(self.api.project().traceManager())&lt;br /&gt;
        ppMod0.setEnabled(True)&lt;br /&gt;
        ppMod0.setReference(rtraceno=0, refpoints=(9100,9300), inputwindow=(8900,9500))&lt;br /&gt;
        ppMod0.init()&lt;br /&gt;
        self.traces = ppMod0&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setProject(self.api.project())&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        leakage_object = AES128_8bit(AES256_Model)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(chipwhisperer.analyzer.attacks.cpa_algorithms.progressive.CPAProgressive,leakage_object)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(150)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    Parameter.usePyQtGraph = True            # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()                        # Instantiate the API&lt;br /&gt;
    app = cwa.makeApplication(&amp;quot;Analyzer&amp;quot;)    # Comment if you don't need the GUI&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)             # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)           # Run UserScript through the API&lt;br /&gt;
    app.exec_()                              # Comment if you don't need the GUI&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2782</id>
		<title>Tutorial A5 Breaking AES-256 Bootloader</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_A5_Breaking_AES-256_Bootloader&amp;diff=2782"/>
				<updated>2017-07-23T00:07:53Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* 14th Round Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial will take you through a complete attack on an encrypted bootloader using AES-256. This demonstrates how to using side-channel power analysis on practical systems, along with discussing how to perform analysis with custom scripts.&lt;br /&gt;
&lt;br /&gt;
Whilst the tutorial assumes you will be performing the entire capture of traces along with the attack, it is possible to download the traces if you don't have the hardware, in which case skip section [[#Setting up the Hardware]] and [[#Capturing the Traces]].&lt;br /&gt;
&lt;br /&gt;
= Background =&lt;br /&gt;
In the world of microcontrollers, a bootloader is a special piece of firmware that is made to let the user upload new programs into memory. This is especially useful for devices with complex code that may need to be patched or otherwise updated in the future - a bootloader makes it possible for the user to upload a patched version of the firmware onto the micro. The bootloader receives information from a communication line (a USB port, serial port, ethernet port, WiFi connection, etc...) and stores this data into program memory. Once the full firmware has been received, the micro can happily run its updated code.&lt;br /&gt;
&lt;br /&gt;
There is one big security issue to worry about with bootloaders. A company may want to stop their customers from writing their own firmware and uploading it onto the micro. For example, this might be for protection reasons - hackers might be able to access parts of the device that weren't meant to be accessed. One way of stopping this is to add encryption. The company can add their own secret signature to the firmware code and encrypt it with a secret key. Then, the bootloader can decrypt the incoming firmware and confirm that the incoming firmware is correctly signed. Users will not know the secret key or the signature tied to the firmware, so they won't be able to &amp;quot;fake&amp;quot; their own.&lt;br /&gt;
&lt;br /&gt;
This tutorial will work with a simple AES-256 bootloader. The victim will receive data through a serial connection, decrypt the command, and confirm that the included signature is correct. Then, it will only save the code into memory if the signature check succeeded. To make this system more robust against attacks, the bootloader will use cipher-block chaining (CBC mode). Our goal is to find the secret key and the CBC initialization vector so that we could successfully fake our own firmware.&lt;br /&gt;
&lt;br /&gt;
== Bootloader Communications Protocol ==&lt;br /&gt;
The bootloader's communications protocol operates over a serial port at 38400 baud rate. The bootloader is always waiting for new data to be sent in this example; in real life one would typically force the bootloader to enter through a command sequence.&lt;br /&gt;
&lt;br /&gt;
Commands sent to the bootloader look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       |&amp;lt;-------- Encrypted block (16 bytes) ----------&amp;gt;|&lt;br /&gt;
       |                                                |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
| 0x00 |    Signature (4 Bytes)    |  Data (12 Bytes)   |   CRC-16    |&lt;br /&gt;
+------+------+------+------+------+------+ .... +------+------+------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This frame has four parts:&lt;br /&gt;
* &amp;lt;code&amp;gt;0x00&amp;lt;/code&amp;gt;: 1 byte of fixed header&lt;br /&gt;
* Signature: A secret 4 byte constant. The bootloader will confirm that this signature is correct after decrypting the frame.&lt;br /&gt;
* Data: 12 bytes of the incoming firmware. This system forces us to send the code 12 bytes at a time; more complete bootloaders may allow longer variable-length frames.&lt;br /&gt;
* CRC-16: A 16-bit checksum using the CRC-CCITT polynomial (0x1021). The LSB of the CRC is sent first, followed by the MSB. The bootloader will reply over the serial port, describing whether or not this CRC check was valid.&lt;br /&gt;
As described in the diagram, the 16 byte block is not sent as plaintext. Instead, it is encrypted using AES-256 in CBC mode. This encryption method will be described in the next section.&lt;br /&gt;
&lt;br /&gt;
The bootloader responds to each command with a single byte indicating if the CRC-16 was OK or not:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            +------+&lt;br /&gt;
CRC-OK:     | 0xA1 |&lt;br /&gt;
            +------+&lt;br /&gt;
&lt;br /&gt;
            +------+&lt;br /&gt;
CRC Failed: | 0xA4 |&lt;br /&gt;
            +------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, after replying to the command, the bootloader veries that the signature is correct. If it matches the expected manufacturer's signature, the 12 bytes of data will be written to flash memory. Otherwise, the data is discarded.&lt;br /&gt;
&lt;br /&gt;
== Details of AES-256 CBC ==&lt;br /&gt;
&lt;br /&gt;
The system uses the AES algorithm in Cipher Block Chaining (CBC) mode. In general one avoids using encryption 'as-is' (i.e. Electronic Code Book), since it means any piece of plaintext always maps to the same piece of ciphertext. Cipher Block Chaining ensures that if you encrypted the same thing a bunch of times it would always encrypt to a new piece of ciphertext.&lt;br /&gt;
&lt;br /&gt;
You can see another reference on the design of the encryption side; we'll be only talking about the decryption side here. In this case AES-256 CBC mode is used as follows, where the details of the AES-256 Decryption block will be discussed in detail later:&lt;br /&gt;
&lt;br /&gt;
[[File:aes256_cbc.png|image]]&lt;br /&gt;
&lt;br /&gt;
This diagram shows that the output of the decryption is no longer used directly as the plaintext. Instead, the output is XORed with a 16 byte mask, which is usually taken from the previous ciphertext. Also, the first decryption block has no previous ciphertext to use, so a secret initialization vector (IV) is used instead. If we are going to decrypt the entire ciphertext (including block 0) or correctly generate our own ciphertext, we'll need to find this IV along with the AES key.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Attacking AES-256 ==&lt;br /&gt;
The system in this tutorial uses AES-256 encryption, which has a 256 bit (32 byte) key - twice as large as the 16 byte key we've attacked in previous tutorials. This means that our regular AES-128 CPA attacks won't quite work. However, extending these attacks to AES-256 is fairly straightforward: the theory is explained in detail in [[Extending AES-128 Attacks to AES-256]]. &lt;br /&gt;
&lt;br /&gt;
As the theory page explains, our AES-256 attack will have 4 steps:&lt;br /&gt;
# Perform a standard attack (as in AES-128 decryption) to determine the first 16 bytes of the key, corresponding to the 14th round encryption key.&lt;br /&gt;
# Using the known 14th round key, calculate the hypothetical outputs of each S-Box from the 13th round using the ciphertext processed by the 14th round, and determine the 16 bytes of the 13th round key manipulated by inverse MixColumns.&lt;br /&gt;
# Perform the MixColumns and ShiftRows operation on the hypothetical key determined above, recovering the 13th round key.&lt;br /&gt;
# Using the AES-256 key schedule, reverse the 13th and 14th round keys to determine the original AES-256 encryption key.&lt;br /&gt;
&lt;br /&gt;
= Setting up the Hardware =&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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)''.&lt;br /&gt;
&lt;br /&gt;
== Building/Programming the Bootloader ==&lt;br /&gt;
The firmware that implements the bootloader is available inside the ChipWhisperer folder at &amp;lt;code&amp;gt;chipwhisperer\hardware\victims\firmware\bootloader-aes256&amp;lt;/code&amp;gt;. If you've uploaded the firmware for any of the other tutorials, the process is identical:&lt;br /&gt;
&lt;br /&gt;
# Open a command prompt/terminal window and navigate to this folder. Enter the command &amp;lt;code&amp;gt;make PLATFORM=X&amp;lt;/code&amp;gt;, where X is the name of your target. For instance, use &amp;lt;code&amp;gt;PLATFORM=CW303&amp;lt;/code&amp;gt; on the ChipWhisperer Lite. Ensure that the program is successfully compiled. The output should end with a line like&lt;br /&gt;
#: &amp;lt;pre&amp;gt;Built for platform CW-Lite XMEGA&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Open the ChipWhisperer Capture software and connect to your hardware. Open the programmer window (''Tools &amp;gt; CW-Lite XMEGA Programmer''), find the &amp;lt;code&amp;gt;.hex&amp;lt;/code&amp;gt; file that you just made, and ''Erase/Program/Verify FLASH''.&lt;br /&gt;
&lt;br /&gt;
The firmware is now loaded onto your hardware, and you can continue onto the capture process.&lt;br /&gt;
&lt;br /&gt;
= Capturing the Traces =&lt;br /&gt;
Once the hardware is ready, we can capture some traces for our attack using the ChipWhisperer Capture software. If you somehow got to the 5th ''Advanced Tutorial'' without getting this software ready, you can follow the helpful guide at [[Installing ChipWhisperer]].&lt;br /&gt;
&lt;br /&gt;
The first thing we need to do is add a new target to the ChipWhisperer system. (None of the existing ones know about the bootloader's data format, nor do they recognize the CRC responses that are sent back to us.) The code for this target is included in [[#Appendix A: Target Code]]. Copy/paste this into a Python file (call it whatever you want) and save it in a place where ChipWhisperer will look for it. There are two folders that you can use:&lt;br /&gt;
* Your computer should have a folder called &amp;lt;code&amp;gt;chipwhisperer_projects&amp;lt;/code&amp;gt; - if you don't know where this is, the ''File &amp;gt; Preferences'' window will tell you. The system looks in the folder &amp;lt;code&amp;gt;chipwhisperer_projects\chipwhisperer\capture\targets&amp;lt;/code&amp;gt; for new targets, so you can save your file here.&lt;br /&gt;
* Alternatively, all of the normal targets are stored in &amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\targets&amp;lt;/code&amp;gt;, so you can also save the file here. Note that this may not be possible if you don't have access to these folders (ex: your account doesn't have admin access).&lt;br /&gt;
&lt;br /&gt;
Next is the capture script. In some of the previous tutorials, we entered all of the capture settings by hand. Since we are civilized humans armed with technology, we can use a script to do all of this setup for us. A pre-written Python script is provided at [[#Appendix B: Capture Script]]. Take a look at this code and notice what it does:&lt;br /&gt;
* it fills in the scope, target, and trace format that we'll use;&lt;br /&gt;
* it connects to the hardware; and&lt;br /&gt;
* it loads all of the hardware parameters for us. Nice!&lt;br /&gt;
Copy this script into a &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file somewhere convenient. Then, perform the following steps to finish the capture:&lt;br /&gt;
# Run the capture script, which will open a ChipWhisperer Capture window with everything connected for us.&lt;br /&gt;
# Open the terminal (''Tools &amp;gt; Terminal'') and connect to the board. While the terminal is open, press the ''Capture 1'' button. A single byte of data should appear in the terminal. This byte will either be &amp;lt;code&amp;gt;a1&amp;lt;/code&amp;gt; (CRC failed) or &amp;lt;code&amp;gt;a4&amp;lt;/code&amp;gt; (CRC OK). If you see any other responses, something is wrong. &lt;br /&gt;
#: [[File:Tutorial-A5-Capture.PNG|image]]&lt;br /&gt;
# Once you're happy with this, open the General Settings tab and set the Number of Traces. You should need around 100 traces to break AES.&lt;br /&gt;
# Press the ''Capture Many'' button to record the 100 traces. You'll see the new traces plotted on-screen.&lt;br /&gt;
# Once the program is finished capturing the traces, save the project. Put it somewhere memorable and give it a nice name.&lt;br /&gt;
&lt;br /&gt;
= Finding the Encryption Key =&lt;br /&gt;
Now that we have our traces, we can go ahead and perform the attack. As described in the background theory, we'll have to do two attacks - one to get the 14th round key, and another (using the first result) to get the 13th round key. Then, we'll do some post-processing to finally get the 256 bit encryption key.&lt;br /&gt;
&lt;br /&gt;
== 14th Round Key ==&lt;br /&gt;
We can attack the 14th round key with a standard, no-frills CPA attack:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer program and load the &amp;lt;code&amp;gt;.cwp&amp;lt;/code&amp;gt; file with the 13th and 14th round traces. This can be either the &amp;lt;code&amp;gt;aes256_round1413_key0_100.cwp&amp;lt;/code&amp;gt; file downloaded or the capture you performed.&lt;br /&gt;
# View and manipulate the trace data with the following steps:&lt;br /&gt;
## Switch to the ''Trace Output Plot'' tab&lt;br /&gt;
## Switch to the ''Results'' parameter setting tab&lt;br /&gt;
## Choose the traces to be plotted and press the ''Redraw'' button to draw them&lt;br /&gt;
## Right-click on the waveform to change options, or left-click and drag to zoom&lt;br /&gt;
## Use the toolbar to quickly reset the zoom back to original&lt;br /&gt;
##: [[File:Tutorial-A5-Plot-Traces.PNG|image]]&lt;br /&gt;
##: Notice that the traces are synchronized for the first 7000 samples, but become unsynchronized later. This fact will be important later in the tutorial.&lt;br /&gt;
# Set up the attack in the ''Attack'' settings tab:&lt;br /&gt;
## Leave the Crypto Algorithm set to AES-128. (Remember that we're applying the AES-128 attack to half of the AES-256 key!)&lt;br /&gt;
## Change the Leakage Model to ''HW: AES Inv SBox Output, First Round (Dec)''. &lt;br /&gt;
## 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!&lt;br /&gt;
##: [[File:Tutorial-A5-Hardware-Model.PNG|image]]&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Finally, run the attack by switching to the ''Results Table'' tab and then hitting the ''Attack'' button.&lt;br /&gt;
&lt;br /&gt;
There are a few ways to check the results of the attack. First, the results table will show the best guesses for each subkey. With the highlight override enabled, the red bytes should be the best guesses for every single subkey:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Right-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
However, the correct key will still rise to the top even if the wrong bytes are highlighted. The coloring and correlation coefficients in the results table should still make it clear that the top guess is the best one:&lt;br /&gt;
&lt;br /&gt;
[[File:Tutorial-A5-Results-Wrong-Key.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Finally, the ''Output vs Point Plot'' shows the correlation against all of the sample points. The spikes on this plot show exactly where the attack was successful (ie: where the sensitive data was leaked):&lt;br /&gt;
&lt;br /&gt;
[[File:Aes14round points.png|image]]&lt;br /&gt;
&lt;br /&gt;
In any case, we've determined that the correct 14th round key is &amp;lt;code&amp;gt;ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
''NOTE: if you're stuck, a full listing of the attack script is given in [[#Appendix C: AES-256 14th Round Key Script]].''&lt;br /&gt;
&lt;br /&gt;
== 13th Round Key ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The ChipWhisperer Analyzer software uses the settings in the GUI to automatically adjust an attack script. Every time you change a setting in the GUI, the autogenerated script is overwritten. Fpr example, the point range is mapped directly to an API call:&lt;br /&gt;
&lt;br /&gt;
[[File:autoscript1.png|image]]&lt;br /&gt;
&lt;br /&gt;
If we modified this script directly, it would be very easy for us to accidentally overwrite our custom script from the GUI. Instead, we'll use the autogenerated code to set up a base script, then add in our own attack model. To set up the base script, the procedure is as follows:&lt;br /&gt;
&lt;br /&gt;
# Open the ChipWhisperer Analyzer software again and reopen the project file.&lt;br /&gt;
# 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.)&lt;br /&gt;
#: [[File:syncproblems.png|image]]&lt;br /&gt;
# Resynchronize the traces:&lt;br /&gt;
## In the ''Attack Script Generator'' tab, enable the ''Resync: Sum of Difference'' preprocessing:&lt;br /&gt;
##: [[File:resyncsad.png|image]]&lt;br /&gt;
## Enable the module and configure the input points. To start, set the reference points to (9063, 9177) and the input window to (9010, 9080), but don't be afraid to change these ranges:&lt;br /&gt;
##: [[File:resyncsad2.png|image]]&lt;br /&gt;
## Redraw the traces and confirm we now have synchronization on the second half:&lt;br /&gt;
##: [[File:resyncsad3.png|image]]&lt;br /&gt;
&lt;br /&gt;
Now, we are ready to make a copy of this script:&lt;br /&gt;
# Click on the auto-generated script&lt;br /&gt;
# Hit ''Copy'' and save the file somewhere&lt;br /&gt;
# Double-click on the description of the new file and give it a better name. &lt;br /&gt;
# Finally, hit ''Set Active'' after clicking on your new file. The result should look like this:&lt;br /&gt;
#: [[File:aes256_customscript.png|image]]&lt;br /&gt;
You can now edit the custom script file using the built-in editor OR with an external editor. In this example, the file would be &amp;lt;code&amp;gt;C:\Users\Colin\AppData\Local\Temp\testaes256.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can look back at the C code of the AES-256 decryption to see how this is implementing the decryption code. Note that because of the Inverse MixColumns operation, we need the entire input ciphertext -- otherwise, we would only need to operate on one byte of the ciphertext.&lt;br /&gt;
&lt;br /&gt;
The last step is to perform the attack using this model:&lt;br /&gt;
# Add the above function to your custom script file.&lt;br /&gt;
# Change the &amp;lt;code&amp;gt;setAnalysisAlgorithm&amp;lt;/code&amp;gt; in the script to use your custom functions by making the following call:&lt;br /&gt;
#:&amp;lt;pre&amp;gt;leakage_object = AES128_8bit(AES256_Model)&amp;lt;/pre&amp;gt;&lt;br /&gt;
# 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 &amp;lt;code&amp;gt;setPointRange()&amp;lt;/code&amp;gt; function call to&lt;br /&gt;
#:&amp;lt;pre&amp;gt;self.attack.setPointRange((8000,10990))&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Start the attack! Wait for the attack to complete, and you will determine the 13th round key:&lt;br /&gt;
#: [[File:Tutorial-A5-Results-Round-13.PNG|image]]&lt;br /&gt;
&lt;br /&gt;
Note you can check [[#Appendix C AES-256 13th Round Key Script]] for the complete contents of the attack script.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from chipwhisperer.analyzer.attacks.models.aes.funcs import shiftrows,mixcolumns&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; knownkey = [0xC6, 0xBD, 0x4E, 0x50, 0xAB, 0xCA, 0x75, 0x77, 0x79, 0x87, 0x96, 0xCA, 0x1C, 0x7F, 0xC5, 0x82]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = shiftrows(knownkey)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; key = mixcolumns(key)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print &amp;amp;quot; &amp;amp;quot;.join([&amp;amp;quot;%02x&amp;amp;quot; % i for i in key])&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our hard work has rewarded us with the 13th round key, which is &amp;lt;code&amp;gt;c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Recovering the Encryption Key ==&lt;br /&gt;
Finally, we have enough information to recover the initial encryption key. In AES-256, the initial key is used in the key expansion routine to generate 15 round keys, and we know the key for round 13 and 14. All we need to do now is reverse the key scheduling algorithm to calculate the ''0/1 Round Key'' from the ''13/14 Round Key''. &lt;br /&gt;
&lt;br /&gt;
In the ChipWhisperer Analyzer software, a key schedule calculator is provided in ''Tools &amp;gt; AES Key Schedule'':&lt;br /&gt;
&lt;br /&gt;
[[File:keyschedule_tool.png|image]]&lt;br /&gt;
&lt;br /&gt;
Open this tool and paste the 13/14 round keys, which are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c6 6a a6 12 4a ba 4d 04 4a 22 03 54 5b 28 0e 63 ea 79 79 20 c8 71 44 7d 46 62 5f 51 85 c1 3b cb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tell the tool that this key is the 13/14 round key; it will automatically display the entire key schedule and the initial encryption key. You should find the initial encryption key is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
94 28 5d 4d 6d cf ec 08 d8 ac dd f6 be 25 a4 99 c4 d9 d0 1e c3 40 7e d7 d5 28 d4 09 e9 f0 88 a1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Peek into &amp;lt;code&amp;gt;supersecret.h&amp;lt;/code&amp;gt;, confirm that this is the right key, and celebrate!&lt;br /&gt;
&lt;br /&gt;
= Next Steps =&lt;br /&gt;
If you want to go further with this tutorial, [[Tutorial A5-Bonus Breaking AES-256 Bootloader]] continues working with the same firmware to find the remaining secrets in the bootloader (the IV and the signature).&lt;br /&gt;
&lt;br /&gt;
= Appendix A: Target Code =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import time&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.capture.targets.SimpleSerial import SimpleSerial&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.capture.targets._base import TargetTemplate&lt;br /&gt;
from chipwhisperer.common.utils import pluginmanager&lt;br /&gt;
from chipwhisperer.capture.targets.simpleserial_readers.cwlite import SimpleSerial_ChipWhispererLite&lt;br /&gt;
from chipwhisperer.common.utils.parameter import setupSetParam&lt;br /&gt;
&lt;br /&gt;
# Class Crc&lt;br /&gt;
#############################################################&lt;br /&gt;
# These CRC routines are copy-pasted from pycrc, which are:&lt;br /&gt;
# Copyright (c) 2006-2013 Thomas Pircher &amp;lt;tehpeh@gmx.net&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
class Crc(object):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    A base class for CRC routines.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, width, poly):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;The Crc constructor.&lt;br /&gt;
&lt;br /&gt;
        The parameters are as follows:&lt;br /&gt;
            width&lt;br /&gt;
            poly&lt;br /&gt;
            reflect_in&lt;br /&gt;
            xor_in&lt;br /&gt;
            reflect_out&lt;br /&gt;
            xor_out&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.Width = width&lt;br /&gt;
        self.Poly = poly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.MSB_Mask = 0x1 &amp;lt;&amp;lt; (self.Width - 1)&lt;br /&gt;
        self.Mask = ((self.MSB_Mask - 1) &amp;lt;&amp;lt; 1) | 1&lt;br /&gt;
&lt;br /&gt;
        self.XorIn = 0x0000&lt;br /&gt;
        self.XorOut = 0x0000&lt;br /&gt;
&lt;br /&gt;
        self.DirectInit = self.XorIn&lt;br /&gt;
        self.NonDirectInit = self.__get_nondirect_init(self.XorIn)&lt;br /&gt;
        if self.Width &amp;lt; 8:&lt;br /&gt;
            self.CrcShift = 8 - self.Width&lt;br /&gt;
        else:&lt;br /&gt;
            self.CrcShift = 0&lt;br /&gt;
&lt;br /&gt;
    def __get_nondirect_init(self, init):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return the non-direct init if the direct algorithm has been selected.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        crc = init&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            bit = crc &amp;amp; 0x01&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc ^= self.Poly&lt;br /&gt;
            crc &amp;gt;&amp;gt;= 1&lt;br /&gt;
            if bit:&lt;br /&gt;
                crc |= self.MSB_Mask&lt;br /&gt;
        return crc &amp;amp; self.Mask&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def bit_by_bit(self, in_data):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Classic simple and slow CRC implementation.  This function iterates bit&lt;br /&gt;
        by bit over the augmented input message and returns the calculated CRC&lt;br /&gt;
        value at the end.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # If the input data is a string, convert to bytes.&lt;br /&gt;
        if isinstance(in_data, str):&lt;br /&gt;
            in_data = [ord(c) for c in in_data]&lt;br /&gt;
&lt;br /&gt;
        register = self.NonDirectInit&lt;br /&gt;
        for octet in in_data:&lt;br /&gt;
            for i in range(8):&lt;br /&gt;
                topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
                register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask) | ((octet &amp;gt;&amp;gt; (7 - i)) &amp;amp; 0x01)&lt;br /&gt;
                if topbit:&lt;br /&gt;
                    register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        for i in range(self.Width):&lt;br /&gt;
            topbit = register &amp;amp; self.MSB_Mask&lt;br /&gt;
            register = ((register &amp;lt;&amp;lt; 1) &amp;amp; self.Mask)&lt;br /&gt;
            if topbit:&lt;br /&gt;
                register ^= self.Poly&lt;br /&gt;
&lt;br /&gt;
        return register ^ self.XorOut&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
class BootloaderTarget(TargetTemplate):&lt;br /&gt;
    _name = 'AES Bootloader'&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        TargetTemplate.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        ser_cons = pluginmanager.getPluginsInDictFromPackage(&amp;quot;chipwhisperer.capture.targets.simpleserial_readers&amp;quot;, True, False)&lt;br /&gt;
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]&lt;br /&gt;
&lt;br /&gt;
        self.keylength = 16&lt;br /&gt;
        self.input = &amp;quot;&amp;quot;&lt;br /&gt;
        self.crc = Crc(width=16, poly=0x1021)&lt;br /&gt;
        self.setConnection(self.ser)&lt;br /&gt;
&lt;br /&gt;
    def setKeyLen(self, klen):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Set key length in BITS &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        self.keylength = klen / 8        &lt;br /&gt;
 &lt;br /&gt;
    def keyLen(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot; Return key length in BYTES &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return self.keylength&lt;br /&gt;
&lt;br /&gt;
    def getConnection(self):&lt;br /&gt;
        return self.ser&lt;br /&gt;
&lt;br /&gt;
    def setConnection(self, con):&lt;br /&gt;
        self.ser = con&lt;br /&gt;
        self.params.append(self.ser.getParams())&lt;br /&gt;
        self.ser.connectStatus.connect(self.connectStatus.emit)&lt;br /&gt;
        self.ser.selectionChanged()&lt;br /&gt;
&lt;br /&gt;
    def con(self, scope=None):&lt;br /&gt;
        if not scope or not hasattr(scope, &amp;quot;qtadc&amp;quot;): Warning(&lt;br /&gt;
            &amp;quot;You need a scope with OpenADC connected to use this Target&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        self.ser.con(scope)&lt;br /&gt;
        # 'x' flushes everything &amp;amp; sets system back to idle&lt;br /&gt;
        self.ser.write(&amp;quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;quot;)&lt;br /&gt;
        self.ser.flush()&lt;br /&gt;
        self.connectStatus.setValue(True)&lt;br /&gt;
&lt;br /&gt;
    def close(self):&lt;br /&gt;
        if self.ser != None:&lt;br /&gt;
            self.ser.close()&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def init(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def setModeEncrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def setModeDecrypt(self):&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    def convertVarToString(self, var):&lt;br /&gt;
        if isinstance(var, str):&lt;br /&gt;
            return var&lt;br /&gt;
&lt;br /&gt;
        sep = &amp;quot;&amp;quot;&lt;br /&gt;
        s = sep.join([&amp;quot;%c&amp;quot; % b for b in var])&lt;br /&gt;
        return s&lt;br /&gt;
&lt;br /&gt;
    def loadEncryptionKey(self, key):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def loadInput(self, inputtext):&lt;br /&gt;
        self.input = inputtext&lt;br /&gt;
&lt;br /&gt;
    def readOutput(self):&lt;br /&gt;
        # No actual output&lt;br /&gt;
        return [0] * 16&lt;br /&gt;
&lt;br /&gt;
    def isDone(self):&lt;br /&gt;
        return True&lt;br /&gt;
&lt;br /&gt;
    def checkEncryptionKey(self, kin):&lt;br /&gt;
        return kin&lt;br /&gt;
&lt;br /&gt;
    def go(self):&lt;br /&gt;
        # Starting byte is 0x00&lt;br /&gt;
        message = [0x00]&lt;br /&gt;
&lt;br /&gt;
        # Append 16 bytes of data&lt;br /&gt;
        message.extend(self.input)&lt;br /&gt;
&lt;br /&gt;
        # Append 2 bytes of CRC for input only (not including 0x00)&lt;br /&gt;
        crcdata = self.crc.bit_by_bit(self.input)&lt;br /&gt;
&lt;br /&gt;
        message.append(crcdata &amp;gt;&amp;gt; 8)&lt;br /&gt;
        message.append(crcdata &amp;amp; 0xff)&lt;br /&gt;
&lt;br /&gt;
        # Write message&lt;br /&gt;
        message = self.convertVarToString(message)&lt;br /&gt;
        for i in range(0, 5):&lt;br /&gt;
            self.ser.flush()&lt;br /&gt;
            self.ser.write(message)&lt;br /&gt;
            time.sleep(0.1)&lt;br /&gt;
            data = self.ser.read(1)&lt;br /&gt;
&lt;br /&gt;
            if len(data) &amp;gt; 0:&lt;br /&gt;
                resp = ord(data[0])&lt;br /&gt;
&lt;br /&gt;
                if resp == 0xA4:&lt;br /&gt;
                    # Encryption run OK&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
                if resp != 0xA1:&lt;br /&gt;
                    raise IOError(&amp;quot;Bad Response %x&amp;quot; % resp)&lt;br /&gt;
&lt;br /&gt;
        if len(data) &amp;gt; 0:&lt;br /&gt;
            if resp != 0xA4:&lt;br /&gt;
                raise IOError(&amp;quot;Failed to communicate, last response: %x&amp;quot; % resp)&lt;br /&gt;
        else:&lt;br /&gt;
            raise IOError(&amp;quot;Failed to communicate, no response&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix B: Capture Script =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# Copyright (c) 2013-2016, NewAE Technology Inc&lt;br /&gt;
# All rights reserved.&lt;br /&gt;
#&lt;br /&gt;
# Authors: Colin O'Flynn, Greg d'Eon&lt;br /&gt;
#&lt;br /&gt;
# Find this and more at newae.com - this file is part of the chipwhisperer&lt;br /&gt;
# project, http://www.assembla.com/spaces/chipwhisperer&lt;br /&gt;
#&lt;br /&gt;
#    This file is part of chipwhisperer.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is free software: you can redistribute it and/or modify&lt;br /&gt;
#    it under the terms of the GNU General Public License as published by&lt;br /&gt;
#    the Free Software Foundation, either version 3 of the License, or&lt;br /&gt;
#    (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#    chipwhisperer is distributed in the hope that it will be useful,&lt;br /&gt;
#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#    GNU Lesser General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#    You should have received a copy of the GNU General Public License&lt;br /&gt;
#    along with chipwhisperer.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
#=================================================&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import chipwhisperer.capture.ui.CWCaptureGUI as cwc&lt;br /&gt;
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
&lt;br /&gt;
# Check for PySide&lt;br /&gt;
try:&lt;br /&gt;
    from PySide.QtCore import *&lt;br /&gt;
    from PySide.QtGui import *&lt;br /&gt;
except ImportError:&lt;br /&gt;
    print &amp;quot;ERROR: PySide is required for this program&amp;quot;&lt;br /&gt;
    sys.exit()&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        super(UserScript, self).__init__(api)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        #User commands here&lt;br /&gt;
        print &amp;quot;***** Starting User Script *****&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
        # Set up board and target&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Scope Module', 'ChipWhisperer/OpenADC'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Trace Format', 'ChipWhisperer/Native'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Target Module', 'AES Bootloader'])&lt;br /&gt;
        self.api.connect()&lt;br /&gt;
&lt;br /&gt;
        # Fill in our other settings&lt;br /&gt;
        lstexample = [['CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
                      ['CW Extra Settings', 'Clock Source', 'Target IO-IN'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO2', 'Serial TXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO1', 'Serial RXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target HS IO-Out', 'CLKGEN'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Source', 'CLKGEN x4 via DCM'],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Total Samples', 11000],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Offset', 0],&lt;br /&gt;
                      ['OpenADC', 'Gain Setting', 'Setting', 45],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Mode', 'rising edge'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Multiply', 2],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Divide', 26],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
                      ]&lt;br /&gt;
&lt;br /&gt;
        # NOTE: For IV: offset = 70000&lt;br /&gt;
        #Download all hardware setup parameters&lt;br /&gt;
        for cmd in lstexample:&lt;br /&gt;
            self.api.setParameter(cmd)&lt;br /&gt;
&lt;br /&gt;
        # Try a couple of captures&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;***** Ending User Script *****&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    # Run the program&lt;br /&gt;
    app = cwc.makeApplication()&lt;br /&gt;
    Parameter.usePyQtGraph = True &lt;br /&gt;
    api = CWCoreAPI()             &lt;br /&gt;
    gui = cwc.CWCaptureGUI(api)                &lt;br /&gt;
    gui.show()                                 &lt;br /&gt;
    &lt;br /&gt;
    # Run our program and let the GUI take over&lt;br /&gt;
    api.runScriptClass(UserScript)             &lt;br /&gt;
    sys.exit(app.exec_())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix C: AES-256 14th Round Key Script =&lt;br /&gt;
Full attack script, copy/paste into a file then add as active attack script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 14th Round Key Attack&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        self.traces = self.api.project().traceManager()&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(CPAProgressive,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit,chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit.LEAK_HW_INVSBOXOUT_FIRSTROUND)&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(200)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    app = cwa.makeApplication()     # Comment if you don't need the GUI&lt;br /&gt;
    Parameter.usePyQtGraph = True   # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()               # Instantiate the API&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)    # Comment if you don't need the GUI&lt;br /&gt;
    gui.show()                      # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)  # Run UserScript through the API&lt;br /&gt;
    app.exec_()                     # Comment if you don't need the GUI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Appendix D: AES-256 13th Round Key Script =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# AES-256 13th Round Key Script&lt;br /&gt;
from chipwhisperer.common.scripts.base import UserScriptBase&lt;br /&gt;
# Imports from Preprocessing&lt;br /&gt;
import chipwhisperer.analyzer.preprocessing as preprocessing&lt;br /&gt;
# Imports from Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa import CPA&lt;br /&gt;
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive&lt;br /&gt;
import chipwhisperer.analyzer.attacks.models.AES128_8bit&lt;br /&gt;
# Imports from utilList&lt;br /&gt;
&lt;br /&gt;
# Imports for AES256 Attack&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.base import ModelsBase&lt;br /&gt;
from chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit&lt;br /&gt;
&lt;br /&gt;
class AES256_Model(AESLeakageHelper):&lt;br /&gt;
    name = 'Our model'&lt;br /&gt;
    def leakage(self, pt, ct, guess, bnum):&lt;br /&gt;
        knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]&lt;br /&gt;
        xored = [knownkey[i] ^ pt[i] for i in range(0, 16)]&lt;br /&gt;
        block = xored&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        block = self.inv_subbytes(block)&lt;br /&gt;
        block = self.inv_mixcolumns(block)&lt;br /&gt;
        block = self.inv_shiftrows(block)&lt;br /&gt;
        result = block&lt;br /&gt;
        return self.inv_sbox((result[bnum] ^ guess[bnum]))&lt;br /&gt;
&lt;br /&gt;
class UserScript(UserScriptBase):&lt;br /&gt;
    _name = &amp;quot;Auto-generated&amp;quot;&lt;br /&gt;
    _description = &amp;quot;Auto-generated Attack Script&amp;quot;&lt;br /&gt;
    def __init__(self, api):&lt;br /&gt;
        UserScriptBase.__init__(self, api)&lt;br /&gt;
        self.initProject()&lt;br /&gt;
        self.initPreprocessing()&lt;br /&gt;
        self.initAnalysis()&lt;br /&gt;
        self.initReporting()&lt;br /&gt;
&lt;br /&gt;
    def initProject(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def initPreprocessing(self):&lt;br /&gt;
        ppMod0 = preprocessing.resync_sad.ResyncSAD(self.api.project().traceManager())&lt;br /&gt;
        ppMod0.setEnabled(True)&lt;br /&gt;
        ppMod0.setReference(rtraceno=0, refpoints=(9100,9300), inputwindow=(8900,9500))&lt;br /&gt;
        ppMod0.init()&lt;br /&gt;
        self.traces = ppMod0&lt;br /&gt;
&lt;br /&gt;
    def initAnalysis(self):&lt;br /&gt;
        self.attack = CPA()&lt;br /&gt;
        self.attack.setProject(self.api.project())&lt;br /&gt;
        self.attack.setTraceSource(self.traces, blockSignal=True)&lt;br /&gt;
        leakage_object = AES128_8bit(AES256_Model)&lt;br /&gt;
        self.attack.setAnalysisAlgorithm(chipwhisperer.analyzer.attacks.cpa_algorithms.progressive.CPAProgressive,leakage_object)&lt;br /&gt;
        self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])&lt;br /&gt;
        self.attack.setTraceStart(0)&lt;br /&gt;
        self.attack.setTracesPerAttack(150)&lt;br /&gt;
        self.attack.setIterations(1)&lt;br /&gt;
        self.attack.setReportingInterval(10)&lt;br /&gt;
        self.attack.setPointRange((0,10991))&lt;br /&gt;
&lt;br /&gt;
    def initReporting(self):&lt;br /&gt;
        # Configures the attack observers (usually a set of GUI widgets)&lt;br /&gt;
        self.api.getResults(&amp;quot;Attack Settings&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Correlation vs Traces in Attack&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Output vs Point Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;PGE vs Trace Plot&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Results Table&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Save to Files&amp;quot;).setAnalysisSource(self.attack)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Output Plot&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
        self.api.getResults(&amp;quot;Trace Recorder&amp;quot;).setTraceSource(self.traces)&lt;br /&gt;
&lt;br /&gt;
    def run(self):&lt;br /&gt;
        self.attack.processTraces()&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa&lt;br /&gt;
    from chipwhisperer.common.utils.parameter import Parameter&lt;br /&gt;
    Parameter.usePyQtGraph = True            # Comment if you don't need the GUI&lt;br /&gt;
    api = CWCoreAPI()                        # Instantiate the API&lt;br /&gt;
    app = cwa.makeApplication(&amp;quot;Analyzer&amp;quot;)    # Comment if you don't need the GUI&lt;br /&gt;
    gui = cwa.CWAnalyzerGUI(api)             # Comment if you don't need the GUI&lt;br /&gt;
    api.runScriptClass(UserScript)           # Run UserScript through the API&lt;br /&gt;
    app.exec_()                              # Comment if you don't need the GUI&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_A8_32bit_AES&amp;diff=2770</id>
		<title>Tutorial A8 32bit AES</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_A8_32bit_AES&amp;diff=2770"/>
				<updated>2017-07-18T14:22:38Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Most of our previous tutorials were running on 8-bit modes of operation. We can target typical implementation on ARM devices which actually looks a little different.&lt;br /&gt;
&lt;br /&gt;
This tutorial is ONLY possible if you have an ARM target. For example the UFO Board with the STM32F3 target (or similar).&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
A 32-bit machine can operate on 32-bit words, so it seems wasteful to use the same 8-bit operations. Indeed we can speed up the AES operation considerably by generating several tables (called T-Tables), as was described in the book [http://www.springer.com/gp/book/9783540425809 The Design of Rijndael] which was published by the authors of AES.&lt;br /&gt;
&lt;br /&gt;
In order to take advantage of our 32 bit machine, we can examine a typical round of AES. With the exception of the final round, each round looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{a} = \text{Round Input}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{b} = \text{SubBytes}(\mathbf{a})&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{c} = \text{ShiftRows}(\mathbf{b})&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{d} = \text{MixColumns}(\mathbf{c})&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{a'} = \text{AddRoundKey}(d) = \text{Round Output}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We'll leave AddRoundKey the way it is. The other operations are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
b_{i,j} = \text{sbox}[a_{i,j}]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
c_{0,j}	\\&lt;br /&gt;
c_{1,j}	\\&lt;br /&gt;
c_{2,j}	\\&lt;br /&gt;
c_{3,j}	&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
=&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
b_{0, j+0} \\&lt;br /&gt;
b_{1, j+1} \\&lt;br /&gt;
b_{2, j+2} \\&lt;br /&gt;
b_{3, j+3}&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
d_{0,j}	\\&lt;br /&gt;
d_{1,j}	\\&lt;br /&gt;
d_{2,j}	\\&lt;br /&gt;
d_{3,j}	&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
=&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
02 &amp;amp; 03 &amp;amp; 01 &amp;amp; 01 \\&lt;br /&gt;
01 &amp;amp; 02 &amp;amp; 03 &amp;amp; 01 \\&lt;br /&gt;
01 &amp;amp; 01 &amp;amp; 02 &amp;amp; 03 \\&lt;br /&gt;
03 &amp;amp; 01 &amp;amp; 01 &amp;amp; 02&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\times&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
c_{0,j}	\\&lt;br /&gt;
c_{1,j}	\\&lt;br /&gt;
c_{2,j}	\\&lt;br /&gt;
c_{3,j}	&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the ShiftRows operation &amp;lt;math&amp;gt;b_{i, j+c}&amp;lt;/math&amp;gt; is a cyclic shift and the matrix multiplcation in MixColumns denotes the xtime operation in GF(&amp;lt;math&amp;gt;2^8&amp;lt;/math&amp;gt;). &lt;br /&gt;
&lt;br /&gt;
It's possible to combine all three of these operations into a single line. We can write 4 bytes of &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; as the linear combination of four different 4 byte vectors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
d_{0,j}	\\&lt;br /&gt;
d_{1,j}	\\&lt;br /&gt;
d_{2,j}	\\&lt;br /&gt;
d_{3,j}	&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
=&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
02 \\&lt;br /&gt;
01 \\&lt;br /&gt;
01 \\&lt;br /&gt;
03&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\text{sbox}[a_{0,j+0}]\ &lt;br /&gt;
&lt;br /&gt;
\oplus&lt;br /&gt;
&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
03 \\&lt;br /&gt;
02 \\&lt;br /&gt;
01 \\&lt;br /&gt;
01&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\text{sbox}[a_{1,j+1}]\ &lt;br /&gt;
&lt;br /&gt;
\oplus&lt;br /&gt;
&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
01 \\&lt;br /&gt;
03 \\&lt;br /&gt;
02 \\&lt;br /&gt;
01&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\text{sbox}[a_{2,j+2}]\ &lt;br /&gt;
&lt;br /&gt;
\oplus&lt;br /&gt;
&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
01 \\&lt;br /&gt;
01 \\&lt;br /&gt;
03 \\&lt;br /&gt;
02&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\text{sbox}[a_{3,j+3}]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, for each of these four components, we can tabulate the outputs for every possible 8-bit input:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
T_0[a] = &lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
02 \times \text{sbox}[a] \\&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
03 \times \text{sbox}[a] \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
T_1[a] = &lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
03 \times \text{sbox}[a] \\&lt;br /&gt;
02 \times \text{sbox}[a] \\&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
T_2[a] = &lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
03 \times \text{sbox}[a] \\&lt;br /&gt;
02 \times \text{sbox}[a] \\&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
T_3[a] = &lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
01 \times \text{sbox}[a] \\&lt;br /&gt;
03 \times \text{sbox}[a] \\&lt;br /&gt;
02 \times \text{sbox}[a] \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These tables have 2^8 different 32-bit entries, so together the tables take up 4 kB. Finally, we can quickly compute one round of AES by calculating&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
d_{0,j}	\\&lt;br /&gt;
d_{1,j}	\\&lt;br /&gt;
d_{2,j}	\\&lt;br /&gt;
d_{3,j}	&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
=&lt;br /&gt;
T_0[a_0,j+0] \oplus&lt;br /&gt;
T_1[a_1,j+1] \oplus&lt;br /&gt;
T_2[a_2,j+2] \oplus&lt;br /&gt;
T_3[a_3,j+3]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All together, with AddRoundKey at the end, a single round now takes 16 table lookups and 16 32-bit XOR operations. This arrangement is much more efficient than the traditional 8-bit implementation. There are a few more tradeoffs that can be made: for instance, the tables only differ by 8-bit shifts, so it's also possible to store only 1 kB of lookup tables at the expense of a few rotate operations.&lt;br /&gt;
&lt;br /&gt;
Note that T-tables don't have a big effect on AES from a side-channel analysis perspective. The SubBytes output is still buried in the T-tables and the other operations are linear, so it's still possible to attack 32-bit AES using the same 8-bit attack methods.&lt;br /&gt;
&lt;br /&gt;
== Building Firmware ==&lt;br /&gt;
&lt;br /&gt;
You will have to build with the &amp;lt;code&amp;gt;PLATFORM&amp;lt;/code&amp;gt; set to one of the ARM targets (such as &amp;lt;code&amp;gt;CW308_STM32F0&amp;lt;/code&amp;gt; for the STM32F0 victim, or &amp;lt;code&amp;gt;CW308_STM32F3&amp;lt;/code&amp;gt; for the STM32F3 victim). If you haven't setup the ARM build environment see the page [[CW308T-STM32F#Example_Projects]]. Assuming your build environment is OK, you can build it as follows:&lt;br /&gt;
&lt;br /&gt;
   cd chipwhisperer\hardware\victims\firmware\simpleserial-aes&lt;br /&gt;
   make PLATFORM=CW308_STM32F3 CRYPTO_TARGET=MBEDTLS&lt;br /&gt;
&lt;br /&gt;
If this works you should get something like the following:&lt;br /&gt;
&lt;br /&gt;
   Creating Symbol Table: simpleserial-aes-CW308_STM32F3.sym&lt;br /&gt;
   arm-none-eabi-nm -n simpleserial-aes-CW308_STM32F3.elf &amp;gt; simpleserial-aes-CW308_&lt;br /&gt;
   STM32F3.sym&lt;br /&gt;
   Size after:&lt;br /&gt;
      text    data     bss     dec     hex filename&lt;br /&gt;
      8440    1076   10320   19836    4d7c simpleserial-aes-CW308_STM32F3.elf&lt;br /&gt;
      +--------------------------------------------------------&lt;br /&gt;
      + Built for platform CW308T: STM32F3 Target&lt;br /&gt;
      +--------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
== Hardware Setup ==&lt;br /&gt;
&lt;br /&gt;
# Using a UFO board, connect your desired STM32Fx target:&lt;br /&gt;
#: [[File:A8_hwsetup.jpg|600px]]&lt;br /&gt;
# Before finishing the hardware setup, you should connect to the target device. To do this you can use one of the standard setup scripts. This will provide a clock &amp;amp; setup TX/RX lines as expected for the STM32F, which is required for the programmer to work.&lt;br /&gt;
#: &lt;br /&gt;
&lt;br /&gt;
=== Programming STM32F Device ===&lt;br /&gt;
&lt;br /&gt;
{{:CW308T-STM32F/ChipWhisperer_Bootloader}}&lt;br /&gt;
&lt;br /&gt;
== Capturing Traces ==&lt;br /&gt;
&lt;br /&gt;
The capture process is similar to previous setups. After running the setup script, adjust the following settings:&lt;br /&gt;
&lt;br /&gt;
# Set the offset to by 0 samples:&lt;br /&gt;
#: [[File:A8_offset.png|400px]]&lt;br /&gt;
# Adjust the gain upward to get a good signal - note it will look VERY different from previous encryption examples:&lt;br /&gt;
#: [[File:A8_traceexample.png|400px]]&lt;br /&gt;
#Capture a larger (~500) number of traces.&lt;br /&gt;
&lt;br /&gt;
== Running Attack ==&lt;br /&gt;
&lt;br /&gt;
The attach is ran in the same manner as previous AES attacks, we use the same leakage assumptions as we don't actually care about the T-Table implementation. The resulting output vs. point location will look a little &amp;quot;messier&amp;quot;, as shown here:&lt;br /&gt;
&lt;br /&gt;
[[File:A8_outputvspoint.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:09_Cw1173_connectrun.png&amp;diff=2742</id>
		<title>File:09 Cw1173 connectrun.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:09_Cw1173_connectrun.png&amp;diff=2742"/>
				<updated>2017-07-17T13:04:29Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: Gdeon uploaded a new version of File:09 Cw1173 connectrun.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Tutorial_B3-1_Timing_Analysis_with_Power_for_Password_Bypass&amp;diff=2741</id>
		<title>Tutorial B3-1 Timing Analysis with Power for Password Bypass</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Tutorial_B3-1_Timing_Analysis_with_Power_for_Password_Bypass&amp;diff=2741"/>
				<updated>2017-07-17T12:53:15Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Recording Power Traces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial will introduce you to breaking devices by determining when a device is performing certain operations. It will use a simple password check, and demonstrate how to perform a basic power analysis.&lt;br /&gt;
&lt;br /&gt;
In addition this example shows you how to drive the ChipWhisperer software with a script, rather than using the GUI. This will be required when attacking new devices which you have not yet added to the core ChipWhisperer software.&lt;br /&gt;
&lt;br /&gt;
Note this is not a prerequisite to the tutorial on breaking AES. You can skip this tutorial if you wish to go ahead with the AES tutorial.&lt;br /&gt;
&lt;br /&gt;
You can also view a 53-min [https://www.youtube.com/watch?v=h4eAU6vEONs&amp;amp;hd=1 Video Version on YouTube]:&lt;br /&gt;
&lt;br /&gt;
= Prerequisites =&lt;br /&gt;
&lt;br /&gt;
You should have already completed [[Tutorial B2 Viewing Instruction Power Differences]] to gain a better understanding of the ChipWhisperer interface.&lt;br /&gt;
&lt;br /&gt;
= Building the Target Firmware =&lt;br /&gt;
&lt;br /&gt;
The target firmware is located in the directory &amp;lt;code&amp;gt;chipwhisperer\hardware\victims\firmware\basic-passwdcheck&amp;lt;/code&amp;gt;. Build the firmware using &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;, once again being careful to ensure you are using the correct &amp;lt;code&amp;gt;PLATFORM=&amp;lt;/code&amp;gt; command. You should end up with something like this being printed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Creating Symbol Table: basic-passwdcheck.sym&lt;br /&gt;
avr-nm -n basic-passwdcheck.elf &amp;amp;gt; basic-passwdcheck.sym&lt;br /&gt;
&lt;br /&gt;
Size after:&lt;br /&gt;
AVR Memory Usage&lt;br /&gt;
----------------&lt;br /&gt;
Device: atxmega128d3&lt;br /&gt;
&lt;br /&gt;
Program:    5400 bytes (3.9% Full)&lt;br /&gt;
(.text + .data + .bootloader)&lt;br /&gt;
&lt;br /&gt;
Data:        524 bytes (6.4% Full)&lt;br /&gt;
(.data + .bss + .noinit)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Built for platform CW-Lite XMEGA&lt;br /&gt;
&lt;br /&gt;
-------- end --------&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Manual Communications with the Target =&lt;br /&gt;
&lt;br /&gt;
At this point, you should be able to configure the target as in the previous tutorials. Rather than tediously going through the setup process again, we'll simply use one of the scripts built into the ChipWhisperer-Capture software. This will demonstrate how we can use a script as a starting point to simplify our setup.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Connect your target hardware (ChipWhisperer-Lite/Pro or ChipWhisperer-Capture Rev 2 with target board).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open the ChipWhisperer-Capture software.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;From the ''Example Scripts'', select one which most closely matches your hardware. For example here I'm using a ChipWhisperer-Lite with the XMEGA target, so will select that script. Note I'm ''NOT'' attacking AES, so will need to make some adjustments later.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The system should connect to your hardware. Remember you have not yet reprogrammed the target so won't be communicating with the target program.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using the programming tool (such as XMEGA programming dialog), program the file &amp;lt;code&amp;gt;basic-passwdcheck.hex&amp;lt;/code&amp;gt; into the target device. This file is located where you ran &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; previously.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Select ''Tools --&amp;amp;gt; Open Terminal'', and press ''Connect''. You should see a window such as this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:Termconn.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;At this point we need to reset the target device. The easiest way to do this is use the programmer interface, and press the ''Check Signature'' or ''Read Signature'' button. This will reset the target device as part of the signature read operation. You should see some messages come across the terminal emulator window:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:Checksig_print.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;Note a few warnings about the terminal emulator:&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The on-board buffer is fairly small, and can be easily overflowed. You may notice a few longer lines become trunicated if printing is too fast!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You can uncheck the &amp;amp;quot;Show non-ASCII as hex&amp;amp;quot; to avoid having the &amp;lt;code&amp;gt;0a&amp;lt;/code&amp;gt; printed in red. The &amp;lt;code&amp;gt;0a&amp;lt;/code&amp;gt; is the hex character for a newline. Many protocols use non-ASCII characters, so to help with debugging it is left enabled by default.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/dd&amp;gt;&amp;lt;/dl&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;We've now got some super-secure system! Let's begin with some exploratory tests - in this case I happened to know the correct password is &amp;lt;code&amp;gt;h0px3&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;'''tip'''&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;In real systems, you may often know ''one'' of the passwords, which is sufficient to investigate the password checking routines as we will do. You also normally have an ability to reset passwords to default. While the reset procedure would erase any data you care about, the attacker will be able to use this 'sacrificial' device to learn about possible vulnerabilites. So the assumption that we have access to the password is really just saying we have access to ''a'' password, and will use that knowledge to break the system in general.&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Using the terminal emulator, write the correct password in, and press &amp;lt;code&amp;gt;&amp;amp;lt;enter&amp;amp;gt;&amp;lt;/code&amp;gt;. You should be greeted by a welcome message, and if using the CW-Lite XMEGA target the green LED will illuminate:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Passok.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The system enters an infinite loop for any password entry. Thus you must reset the system, use the ''Programmer Window'' to again perform a ''Check Signature'' or ''Read Signature'' operation.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Enter an incorrect password - notice a different message is printed, and if using the CW-Lite XMEGA target the red LED will come on.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Recording Power Traces =&lt;br /&gt;
Now that we can communicate with our super-secure system, our next goal is to get a power trace while the target is running. To do this, we'll get the power measurements to trigger after we send our password to the target. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;We'll make some changes to the trigger setup of the ChipWhisperer. In particular, ensure you set the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Offset = 0&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Timeout set to 5 seconds or greater (to give yourself time when manually testing)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Timeout_offset.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Change to the ''Target Settings'' tab, and delete the ''Command'' strings. Those strings are used in the AES attack to send a specific command to the target device, for now we will be manually sending data:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:Text_targetsettings.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Still in the ''Target Settings'' tab, under ''Protocol Version'', change ''Version'' from ''Auto'' to ''1.0''&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Perform the following actions:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;ol style=&amp;quot;list-style-type: lower-roman;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reset the target device (e.g. by performing the signature check).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Enter the password &amp;lt;code&amp;gt;h0px3&amp;lt;/code&amp;gt; in the terminal window, but ''do not'' yet hit enter.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Press the ''Capture 1'' button, and immediately switch to the terminal emulator window and press &amp;lt;code&amp;gt;&amp;amp;lt;enter&amp;amp;gt;&amp;lt;/code&amp;gt; to send the password.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;You must send the password before the timeout occurs -- you can increase the length of the timeout if needed to give yourself more time! If this works you should see the power consumption displayed in the GUI:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:Trace_manual_pass.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Rather than using the manual terminal, let's now use the GUI to automatically send a password try. Switching back to the ''Target Settings'' tab, write &amp;lt;code&amp;gt;h0px3\n&amp;lt;/code&amp;gt; into the ''Go Command'' option:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:Gocorrect.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ''Go Command'' is sent right after the scope is armed. In this example it means we can capture the power consumption during the password entry phase.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Now perform the following actions:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;ol style=&amp;quot;list-style-type: lower-roman;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reset the target device (e.g. by performing the signature check).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Press the ''Capture 1'' button.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Hopefully this resulted in the same waveform as before! Note the device takes around 1 second to 'boot', so if you are too lightning fast after resetting the device it won't actually be ready to accept the password. You can keep the terminal emulator window open to view the output data.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Play around with the password entered on the ''Go Command'' - try all of the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;h0px3\n&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;h0px4\n&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;h0paa\n&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;haaaa\n&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;a\n&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;You should notice a distinct change in the password depending how many characters were correct. For example the following shows the difference between passwords of &amp;lt;code&amp;gt;h0px4&amp;lt;/code&amp;gt; (which has 4 correct characters) and &amp;lt;code&amp;gt;h0paa&amp;lt;/code&amp;gt; (which has 3 correct characters):&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:3vs4.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Automatic Resets =&lt;br /&gt;
The last step before scripting an entire attack is to figure out how to automatically reset the target device before (or after) each capture. There are two ways to do this, and the following steps take you through two examples of how to accomplish this goal.&lt;br /&gt;
&lt;br /&gt;
== Reset via Spare IO Lines ==&lt;br /&gt;
&lt;br /&gt;
TODO - see reset via programming interface for now&lt;br /&gt;
&lt;br /&gt;
== Reset via Auxiliary Module ==&lt;br /&gt;
&lt;br /&gt;
Auxiliary modules are small pieces of code that can perform some extra functions during the capture process. The functions inside these Python modules are run before a capture, before the power measurement is armed, before the measurement is triggered, after a single trace is completed, and after an entire capture is finished. We will use an existing auxiliary module to reset the target chip before arming the measurement so that we don't have to manually reset the device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; We're going to use the ''Reset AVR/XMEGA via CW-Lite'' auxiliary module. Let's get an idea of how this module works: &lt;br /&gt;
* Navigate to the auxiliary modules folder (&amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\auxiliary\&amp;lt;/code&amp;gt;) and open &amp;lt;code&amp;gt;ResetCW1183Read.py&amp;lt;/code&amp;gt; in your choice of text editor.&lt;br /&gt;
* Find the function definition for &amp;lt;code&amp;gt;resetDevice()&amp;lt;/code&amp;gt;. It contains a line that looks like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CWCoreAPI.getInstance().getScope().scopetype.cwliteXMEGA.readSignature()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Look for the lines where this function gets called. You'll find that the function &amp;lt;code&amp;gt;traceArm()&amp;lt;/code&amp;gt; uses it like:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resettiming = self.findParam('resettiming').value()&lt;br /&gt;
if resettiming == 'Pre-Arm':&lt;br /&gt;
    self.resetDevice()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Effectively, this code will read the target's signature before we arm the power measurement. This means that the target will automatically be reset before capturing a power trace.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Go back to the ChipWhisperer Capture software. In the ''Generic Settings'' tab, switch the Auxiliary Module to ''Reset AVR/XMEGA via CW-Lite''.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now, in the ''Aux Settings'' tab, we can configure our automatic reset. Make sure the settings are:&lt;br /&gt;
* Pre-arm delay: roughly 1200 ms&lt;br /&gt;
* Post-arm delay: the default (0 ms) is fine&lt;br /&gt;
* Reset timing: Pre-arm (reset the device before we arm the scope)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Press ''Capture 1''. The target will automatically reset, with the Safe-o-matic 3000 boot sequence appearing in the console. Then, 1 second later, the program will send the password to the target and record a power trace.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, confirm that you can try different passwords (in ''Target Settings'') and see how the power trace changes when your password has 0, 1, 2... correct characters.&lt;br /&gt;
&lt;br /&gt;
= Performing the Timing Attack =&lt;br /&gt;
So far, we've set up our ChipWhisperer to automatically reset the target, send it a password attempt of our choice, and record a power trace while the target processes the password. Now, we'll write a Python script to automatically try different passwords and use these power traces to discover the password stored on the target.&lt;br /&gt;
&lt;br /&gt;
== Scripting the Setup ==&lt;br /&gt;
Our first step will be to write a script that automatically sets up the ChipWhisperer Capture software with all of the settings we've tested above. We'll do this by modifying an existing script with our own settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make a copy of an existing ChipWhisperer script. The example scripts are located at &amp;lt;code&amp;gt;chipwhisperer\software\chipwhisperer\capture\scripts&amp;lt;/code&amp;gt;; for example, the default one for the XMEGA device is called &amp;lt;code&amp;gt;cwlite-simpleserialxmega.py&amp;lt;/code&amp;gt;. Make a copy of this script and put it somewhere memorable.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Rename the script something else - for example, &amp;lt;code&amp;gt;cwlite-passwordcrack.py&amp;lt;/code&amp;gt; - and open it for editing. You'll notice that a large chunk of the code is used to set the parameters:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#Example of using a list to set parameters. Slightly easier to copy/paste in this format&lt;br /&gt;
lstexample = [['CW Extra', 'CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
              ['CW Extra', 'CW Extra Settings', 'Target IOn Pins', 'Target IO1', 'Serial RXD'],&lt;br /&gt;
              ['CW Extra', 'CW Extra Settings', 'Target IOn Pins', 'Target IO2', 'Serial TXD'],&lt;br /&gt;
              ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Desired Frequency', 7370000.0],&lt;br /&gt;
              ['CW Extra', 'CW Extra Settings', 'Target HS IO-Out', 'CLKGEN'],&lt;br /&gt;
              ['OpenADC', 'Clock Setup', 'ADC Clock', 'Source', 'CLKGEN x4 via DCM'],&lt;br /&gt;
              ['OpenADC', 'Trigger Setup', 'Total Samples', 3000],&lt;br /&gt;
              ['OpenADC', 'Trigger Setup', 'Offset', 1500],&lt;br /&gt;
              ['OpenADC', 'Gain Setting', 'Setting', 45],&lt;br /&gt;
              ['OpenADC', 'Trigger Setup', 'Mode', 'rising edge'],&lt;br /&gt;
              #Final step: make DCMs relock in case they are lost&lt;br /&gt;
              ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
              ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Those parameters come from the ''Scripting Parameters'' tab. Switch over to it and notice this tab logs all of the parameter changes, showing you how to change the parameters through the API:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:Scriptcommands.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Note that commands run via the script are also printed, so you can see where the values being set are coming from too. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;At this point, close the ''ChipWhisperer-Capture'' window so we can confirm the script still works. Run the new script (which doesn't have any changes yet) from the command line. You may have to open a console with Python in the path:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;ol style=&amp;quot;list-style-type: lower-roman;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If you installed WinPython, run the ''WinPython Console'' from your WinPython installation directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If using the VMWare image of a Linux machine, this should just be a regular console&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Run the script with &amp;lt;code&amp;gt;python cwlite-passwordcrack.py&amp;lt;/code&amp;gt;. If the script errors out, it might be that the location of the FPGA bitstream is stored in relative terms. To fix this perform the following:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;ol style=&amp;quot;list-style-type: lower-roman;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open ChipWhisperer-Capture regularly.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the ChipWhisperer script that you used previously.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select ''Tools--&amp;amp;gt;Config CW Firmware''&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &amp;amp;quot;FPGA .zip (Release)&amp;amp;quot;, hit the &amp;amp;quot;Find&amp;amp;quot; button. Point the system to the file &amp;lt;code&amp;gt;chipwhisperer/hardware/capture/chipwhisperer-lite/cwlite_firmware.zip&amp;lt;/code&amp;gt; on your filesystem. Note by default there is a relative path.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol start=&amp;quot;4&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once again on the ''Target Settings'' tab, delete the various commands. Make a note of the resulting ''Script Commands'' which you will need to enter to achieve this same goal. Close ChipWhisperer-Capture.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Continue editing your script. First, find the line setting the Trigger Offset:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;['OpenADC', 'Trigger Setup', 'Offset', 1500],&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And set this to 0, which we were using previously:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;['OpenADC', 'Trigger Setup', 'Offset', 0],&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Next, append the required commands to clear the simpleserial commands and to enable the automatic resets:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#Example of using a list to set parameters. Slightly easier to copy/paste in this format&lt;br /&gt;
lstexample = [['CW Extra', 'CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
              ...BUNCH MORE COMMANDS HERE HAVE BEEN REMOVED...&lt;br /&gt;
              #Final step: make DCMs relock in case they are lost&lt;br /&gt;
              ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
&lt;br /&gt;
              #Append your commands here&lt;br /&gt;
              ['Simple Serial', 'Load Key Command', u''],&lt;br /&gt;
              ['Simple Serial', 'Go Command', u''],&lt;br /&gt;
              ['Simple Serial', 'Output Format', u''],   &lt;br /&gt;
&lt;br /&gt;
              ['Generic Settings', 'Auxiliary Module', 'Reset AVR/XMEGA via CW-Lite'],&lt;br /&gt;
              ['Aux Settings', 'Reset AVR/XMEGA via CW-Lite', 'Delay (Post-Arm)', 1200],                   &lt;br /&gt;
              ]&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Finally, we will set the password. You can enter the password in the Capture ''Target Settings'' tab, and see the following sort of call would set the appropriate password:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;self.api.setParameter(['Simple Serial', 'Go Command', u'h0px3\\n'])&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Note the newline is actually escaped, to set the text equivalent of what will be printed. This will result in an actual newline going out across the serial port. Set that command at some point in your script.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Close any open ChipWhisperer-Capture windows, and run the script as before. You should connect to the target, and be able to press ''Capture 1'' and see the correct waveform.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Running a Single Capture ==&lt;br /&gt;
With our settings prepared, the next step is to use our script to record and analyze a power trace. We need to be able to get the trace data into our Python script so we can analyze it for the timing attack.&lt;br /&gt;
&lt;br /&gt;
The API allows us to ''press the Capture 1'' button and ''view the power trace'' without using the GUI. There are two relevant commands here:&lt;br /&gt;
* &amp;lt;code&amp;gt; self.api.capture1()&amp;lt;/code&amp;gt; acts as if we've just pressed the ''Capture 1'' button;&lt;br /&gt;
* &amp;lt;code&amp;gt; self.api.getScope().channels[0].getTrace()&amp;lt;/code&amp;gt; returns a list of datapoints that were recorded in the previous capture.&lt;br /&gt;
We want to test these two commands. After the setup portion of your script, add some code similar to the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
self.api.capture1()&lt;br /&gt;
data = self.api.getScope().channels[0].getTrace()&lt;br /&gt;
print data&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run your script. The ChipWhisperer should automatically capture one trace and print out the several thousand datapoints. This is all we need to continue.&lt;br /&gt;
&lt;br /&gt;
== Attacking a Single Letter ==&lt;br /&gt;
Now that we can record one power trace, we can start the timing attack. Our goal here is to automatically find the first letter of the Super Secret (tm) password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Look at this example of the power traces when 0 and 1 bytes are correct. We can see a clear point that appears to shift forward in time:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;[[File:Passwordcrackerpts.png|image]]&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When we guess the first byte incorrectly, there is a distinct power spike at sample number 153. However, when we guess correctly, the target spends more time processing the password, and this spike moves 72 samples forward. This means that we can check if our first byte is correct by checking this data point: if we're right, it will have an amplitude greater than -0.2. Note the specific point will change for different hardware, and may also change if you use different versions of avr-gcc to compile the target code. The example code here was compiled with WinAVR 20100110, which has avr-gcc 4.3.3. If you view the video version of this tutorial the point numbers are different for example, so be sure to check what they are for your specific system.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Add a loop to your script that does the following:&lt;br /&gt;
* Sets the ''Go Command'' to the next character we want to try&lt;br /&gt;
* Captures a power trace&lt;br /&gt;
* Checks if sample 153 is above -0.2 (fill in the appropriate numbers here)&lt;br /&gt;
* Repeats for all characters we want to try&lt;br /&gt;
An example of this loop is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
trylist = 'abcdefghijklmnopqrstuvwxyz0123456789'&lt;br /&gt;
&lt;br /&gt;
for c in trylist:&lt;br /&gt;
    # Test this password and record a power trace&lt;br /&gt;
    self.api.setParameter(['Simple Serial', 'Go Command', c + '\n'])&lt;br /&gt;
    self.api.capture1()&lt;br /&gt;
    &lt;br /&gt;
    # Get the data and check data[153]&lt;br /&gt;
    data = self.api.getScope().channels[0].getTrace()&lt;br /&gt;
    if data[153] &amp;gt; -0.2:&lt;br /&gt;
        print &amp;quot;Success: &amp;quot; + c          &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This script will eventually stop, but you can use Ctrl+C on the command line to kill it. Make sure your script prints &amp;quot;Success: h&amp;quot;!&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Attacking the Full Password ==&lt;br /&gt;
The last step is to attack the entire password, one letter at a time. The procedure to do this is:&lt;br /&gt;
* Start with a blank password string&lt;br /&gt;
* Loop through all of the characters we want to try:&lt;br /&gt;
** Add the next character to the end of the password&lt;br /&gt;
** Test this new candidate password using code similar to the above&lt;br /&gt;
** If the new password is correct up to character (1, 2, ..., 5), add it to the end of the password&lt;br /&gt;
* Repeat until we've cracked all 5 characters.&lt;br /&gt;
&lt;br /&gt;
Note that the point of interest is no longer at sample 153. We noticed earlier that this key point moves 72 samples forward for every correct character, so we'll have to check location &amp;lt;code&amp;gt;153&amp;lt;/code&amp;gt; for character 0, &amp;lt;code&amp;gt;153 + 72&amp;lt;/code&amp;gt; for character 1, and &amp;lt;code&amp;gt;153 + i*72&amp;lt;/code&amp;gt; for character &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An example of this loop is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
password = ''&lt;br /&gt;
trylist = 'abcdefghijklmnopqrstuvwxyz0123456789'&lt;br /&gt;
  &lt;br /&gt;
for i in range(5):&lt;br /&gt;
    for c in trylist:&lt;br /&gt;
        # Get a power trace using our next attempt&lt;br /&gt;
        nextPass = password + '{}'.format(c)&lt;br /&gt;
        self.api.setParameter(['Simple Serial', 'Go Command', '{}\n'.format(nextPass)])&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
        &lt;br /&gt;
        # Grab the trace&lt;br /&gt;
        nextTrace = self.api.getScope().channels[0].getTrace()&lt;br /&gt;
        &lt;br /&gt;
        # Check location 153, 225, etc. If it's too low, we've failed&lt;br /&gt;
        if nextTrace[153 + 72*i] &amp;lt; -0.2:&lt;br /&gt;
            continue&lt;br /&gt;
            &lt;br /&gt;
        # If we got here, we've found the right letter&lt;br /&gt;
        password += c&lt;br /&gt;
        print '{} characters: {}'.format(i+1, password)&lt;br /&gt;
        break&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After some time, this prints &amp;lt;code&amp;gt;5 characters: h0px3&amp;lt;/code&amp;gt; -- it automatically finds the correct password.&lt;br /&gt;
&lt;br /&gt;
That's it! You should have successfully cracked a password using the timing attack. Some notes on this method:&lt;br /&gt;
&lt;br /&gt;
* The target device has a finite start-up time, which slows down the attack. If you wish, remove some of the printf()'s from the target code, recompile and reprogram, and see how quickly you can do this attack.&lt;br /&gt;
* The current script doesn't look for the &amp;amp;quot;WELCOME&amp;amp;quot; message when the password is OK. That is an extension that allows it to crack any size password.&lt;br /&gt;
* If there was a lock-out on a wrong password, the system would ignore it, as it resets the target after every attempt.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
This tutorial has demonstrated the use of the power side-channel for performing timing attacks. A target with a simple password-based security system is broken. In addition you have learned about the scripting support in the ChipWhisperer-Capture software.&lt;br /&gt;
&lt;br /&gt;
= Appendix: Completed Timing Attack Script =&lt;br /&gt;
The &amp;lt;code&amp;gt;run()&amp;lt;/code&amp;gt; function at the end of the tutorial might look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def run(self):&lt;br /&gt;
        # This is the function that gets called when our script starts&lt;br /&gt;
        &lt;br /&gt;
        # First: set up the basics and connect to the CW-Lite&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Scope Module', 'ChipWhisperer/OpenADC'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Target Module', 'Simple Serial'])&lt;br /&gt;
        self.api.setParameter(['Generic Settings', 'Trace Format', 'ChipWhisperer/Native'])&lt;br /&gt;
        self.api.setParameter(['Simple Serial', 'Connection', 'ChipWhisperer-Lite'])&lt;br /&gt;
        self.api.setParameter(['ChipWhisperer/OpenADC', 'Connection', 'ChipWhisperer-Lite'])&lt;br /&gt;
        self.api.connect()&lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        # Next: set up everything we need to connect to the target&lt;br /&gt;
        # Put all of our commands in a list and execute them at the end&lt;br /&gt;
        lstexample = [&lt;br /&gt;
                      # Gain&lt;br /&gt;
                      ['OpenADC', 'Gain Setting', 'Setting', 45],&lt;br /&gt;
                      # Trigger&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Mode', 'rising edge'],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Offset', 0],&lt;br /&gt;
                      ['OpenADC', 'Trigger Setup', 'Total Samples', 2000],&lt;br /&gt;
                      # Clock&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'CLKGEN Settings', 'Desired Frequency', 7370000.0],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Source', 'CLKGEN x4 via DCM'],&lt;br /&gt;
                      ['OpenADC', 'Clock Setup', 'ADC Clock', 'Reset ADC DCM', None],&lt;br /&gt;
                      # Pins&lt;br /&gt;
                      ['CW Extra Settings', 'Trigger Pins', 'Target IO4 (Trigger Line)', True],&lt;br /&gt;
                      ['CW Extra Settings', 'Target HS IO-Out', 'CLKGEN'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO1', 'Serial RXD'],&lt;br /&gt;
                      ['CW Extra Settings', 'Target IOn Pins', 'Target IO2', 'Serial TXD'],&lt;br /&gt;
                      # Automatic commands&lt;br /&gt;
                      ['Simple Serial', 'Load Key Command', ''],&lt;br /&gt;
                      ['Simple Serial', 'Go Command', 'h0px3\n'],&lt;br /&gt;
                      ['Simple Serial', 'Output Format', ''],&lt;br /&gt;
                      # Auto-reset&lt;br /&gt;
                      ['Generic Settings', 'Auxiliary Module', 'Reset AVR/XMEGA via CW-Lite'],&lt;br /&gt;
                      ['Aux Settings', 'Reset AVR/XMEGA via CW-Lite', 'Delay (Post-Arm)', 1200],&lt;br /&gt;
                      ]&lt;br /&gt;
        &lt;br /&gt;
        #Download all hardware setup parameters&lt;br /&gt;
        for cmd in lstexample: &lt;br /&gt;
            self.api.setParameter(cmd)&lt;br /&gt;
                       &lt;br /&gt;
        # Get one capture for fun&lt;br /&gt;
        self.api.capture1()&lt;br /&gt;
        data = self.api.getScope().channels[0].getTrace()&lt;br /&gt;
        print data&lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        # Crack the first letter&lt;br /&gt;
        password = ''&lt;br /&gt;
        trylist = 'abcdefghijklmnopqrstuvwxyz0123456789'&lt;br /&gt;
          &lt;br /&gt;
        for i in range(5):&lt;br /&gt;
            for c in trylist:&lt;br /&gt;
                # Get a power trace using our next attempt&lt;br /&gt;
                nextPass = password + '{}'.format(c)&lt;br /&gt;
                self.api.setParameter(['Simple Serial', 'Go Command', '{}\n'.format(nextPass)])&lt;br /&gt;
                self.api.capture1()&lt;br /&gt;
                &lt;br /&gt;
                # Grab the trace&lt;br /&gt;
                nextTrace = self.api.getScope().channels[0].getTrace()&lt;br /&gt;
                &lt;br /&gt;
                # Check location 153, 225, etc. If it's too low, we've failed&lt;br /&gt;
                if nextTrace[153 + 72*i] &amp;lt; -0.2:&lt;br /&gt;
                    continue&lt;br /&gt;
                    &lt;br /&gt;
                # If we got here, we've found the right letter&lt;br /&gt;
                password += c&lt;br /&gt;
                print '{} characters: {}'.format(i+1, password)&lt;br /&gt;
                break&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Installing_ChipWhisperer_from_Git&amp;diff=2663</id>
		<title>Installing ChipWhisperer/Installing ChipWhisperer from Git</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Installing_ChipWhisperer_from_Git&amp;diff=2663"/>
				<updated>2017-07-10T17:33:10Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: Use git submodule commands instead of manually cloning&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you want the cutting-edge version of ChipWhisperer, you can clone the repository. If you have Git already set up, this is easy to do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git@github.com:newaetech/chipwhisperer.git&lt;br /&gt;
cd chipwhisperer/software&lt;br /&gt;
python setup.py develop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may also want the OpenADC software, which is necessary to build new firmware for the ChipWhisperer FPGA. This is unnecessary for most users. If you need it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ..&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
cd openadc/controlsw/python&lt;br /&gt;
python setup.py develop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer&amp;diff=2575</id>
		<title>Installing ChipWhisperer</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer&amp;diff=2575"/>
				<updated>2017-05-19T17:30:21Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;span class=&amp;quot;expandall&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This page describes how to install the ChipWhisperer software. &lt;br /&gt;
&lt;br /&gt;
There are four ways to set up ChipWhisperer:&lt;br /&gt;
* '''VMWare Virtual Machine:''' Get a pre-prepared virtual machine image with all of the required tools already installed. ''Recommended for beginners.''&lt;br /&gt;
* '''ChipWhisperer Releases:''' Get a zip file with the latest stable ChipWhisperer code and run it on your own environment. &lt;br /&gt;
* '''PyPi Package:''' &amp;lt;code&amp;gt;pip install chipwhisperer&amp;lt;/code&amp;gt;. Only includes the software - doesn't come with the hardware source files.&lt;br /&gt;
* '''Git Repository:''' Get the latest, bleeding-edge features and bugs. Recommended if you're an experienced developer and you want to contribute to ChipWhisperer.&lt;br /&gt;
&lt;br /&gt;
{{TOC|limit=3}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro = = Using VMWare Virtual Machine =&lt;br /&gt;
|content= Installing ChipWhisperer/Using VMWare Virtual Machine}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro= = Required Tools - Windows =&lt;br /&gt;
|content= Installing ChipWhisperer/Required Tools - Windows}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro= = Required Tools - Linux =&lt;br /&gt;
|content= Installing ChipWhisperer/Required Tools - Linux}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro= = Required Tools - Mac OS X =&lt;br /&gt;
|content= Installing ChipWhisperer/Required Tools - Mac OS X}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro= = Installing ChipWhisperer from Releases =&lt;br /&gt;
|content= Installing ChipWhisperer/Installing ChipWhisperer from Releases}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro= = Installing ChipWhisperer from PyPi =&lt;br /&gt;
|content= Installing ChipWhisperer/Installing ChipWhisperer from PyPi}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro= = Installing ChipWhisperer from Git =&lt;br /&gt;
|content= Installing ChipWhisperer/Installing ChipWhisperer from Git}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleSection&lt;br /&gt;
|intro= = Quick Tests =&lt;br /&gt;
|content= Installing ChipWhisperer/Quick Tests}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Introduction]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2574</id>
		<title>Installing ChipWhisperer/Required Tools - Windows</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2574"/>
				<updated>2017-05-19T17:29:34Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h2&amp;gt; Python &amp;lt;/h2&amp;gt;&lt;br /&gt;
For any of the other installation methods, you'll need to have Python 2 installed on your computer. If you already a recent version of Python installed (2.7.x), you can skip this step. Note that Python 3.x will not work with this codebase. There's also a bit of setup that's needed to get other tools and prepare other drivers.&lt;br /&gt;
&lt;br /&gt;
The recommend method of installing Python is to use a distribution called [http://winpython.github.io/ WinPython]. This setup avoids installing Python globally, and includes most of the software you will need. In addition it makes it possible to install 32-bit and 64-bit Python on the same system with minimal problems. This can be very useful as the 64-bit version is handy for doing analysis on large data sets.&lt;br /&gt;
&lt;br /&gt;
To install WinPython 2.7.x, Download a release in the 2.7.x branch from the [http://winpython.github.io/ WinPython] site. It's recommended to use the 32-bit version, but you can also use the 64-bit version. Also, note that the recent releases (like WinPython-32bit-2.7.13.0Zero) don't come with any pre-installed packages. We recommend [https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/ WinPython 2.7.10.3].&lt;br /&gt;
&lt;br /&gt;
Note that certain drivers (such as the SmartCard driver) ''do not'' work on the 64-bit version. Choose a reasonable location to install this to - note the default is simply in the download directory. Instead it's recommended to find a directory such as &amp;lt;code&amp;gt;c:\WinPython32bit-2.7.10.3&amp;lt;/code&amp;gt;, or into your local directory such as &amp;lt;code&amp;gt;c:\Users\yourname\WinPython-32bit-2.7.10.3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Go to your installation directory for WinPython, and run the shortcut called '''WinPython Command Prompt.exe'''. This will give you a command prompt which is setup to run Python along with associated scripts.&lt;br /&gt;
&lt;br /&gt;
''Optional'': You can add the python.exe you just installed to your PATH. To do so navigate to your installation folder, and run the '''WinPython Control Panel.exe''' program. Then select ''Advanced -&amp;gt; Register distribution...''. If you do not do this, you will have to run all commands in this document via the '''WinPython Command Prompt.exe'''. If you plan on running both 32-bit and 64-bit Python, you should not register them. Instead explicitly call the correct Python by always running the '''WinPython Command Prompt.exe''', and then calling specific programs (such as CW Capture or Analyzer) from that command prompt.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Python Packages &amp;lt;/h2&amp;gt;&lt;br /&gt;
There are a number of packages that the ChipWhisperer project uses. You'll need to install these so that the software can run. Note that the PyPi install process should automatically install these, so you shouldn't need to manually install everything there.&lt;br /&gt;
&lt;br /&gt;
Run the following commands to get the needed packages:&lt;br /&gt;
* '''PyQTGraph:''' &amp;lt;code&amp;gt;pip install pyqtgraph&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ConfigObj:''' &amp;lt;code&amp;gt;pip install configobj&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might also need some extra packages. Generally you can avoid them unless you have specific need of the features they enable:&lt;br /&gt;
&lt;br /&gt;
'''PyUSB:''' if you're planning to use the ChipWhisperer Capture Rev2 hardware, this is necessary. You can install this using pip:&lt;br /&gt;
* &amp;lt;code&amp;gt;pip install pyusb&amp;lt;/code&amp;gt;&lt;br /&gt;
* If that fails, try specifying the latest version, like: &amp;lt;code&amp;gt;pip install pyusb==1.0.0b1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''FTD2XX:''' [https://github.com/snmishra/ftd2xx ftd2xx] is required for SASEBO-W, SAKURA-G, and SASEBO-GII Support. To install this package, [https://github.com/snmishra/ftd2xx/archive/master.zip download a copy of the ftd2xx repository] and unzip it somewhere. Then run the following where you unzipped it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python setup.py install&amp;lt;/pre&amp;gt;&lt;br /&gt;
This package will also require you to install the [http://www.ftdichip.com/Drivers/D2XX.htm FTDI D2XX Drivers]. In the preceeding link simply find the correct driver for your OS Version and install that.&lt;br /&gt;
&lt;br /&gt;
'''MYSQL:''' If you want to use the MySQL trace format (not used by default), you'll need to install [https://pypi.python.org/pypi/umysql umysql]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pip install umysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''PYSCARD:''' If planning on using a PS/SC smartcard reader (i.e. standard USB-connected reader), you will need to install [https://sourceforge.net/projects/pyscard/files/pyscard/ pyscard].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Installing Hardware Drivers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Details of driver installation are on specific pages for supported hardware (such as cwcapturerev2 and naecw1173_cwlite). Drivers are available from [http://chipwhisperer.com ChipWhisperer] release section.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Getting AVR Compiler Toolchain &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following section is not required for your first attack - you can jump right to the tutorial if you wish. However you'll ultimately wish to modify the code of the device under test, and these instructions tell you how. You should first follow the tutorial to confirm your system is working before modifying the code however!&lt;br /&gt;
&lt;br /&gt;
To build the code, you'll need to install avr-gcc on Windows (if using the Virtual Machine, the following is ''not required'', as the VM comes setup with the AVR compiler already). On Windows, you could choose to install:&lt;br /&gt;
&lt;br /&gt;
* Atmel AVR-GCC standalone - see [http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx Atmel avr-gcc standalone] (registration required)&lt;br /&gt;
* WinAVR. Last release - 2010, see [https://sourceforge.net/projects/winavr/files/latest/download?source=typ_redirect WinAVR Page] (no registration required)&lt;br /&gt;
&lt;br /&gt;
To test the code build, follow these steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to the directory with the avr-serial example, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd c:\chipwhisperer\hardware\victims\firmware\simpleserial-aes&lt;br /&gt;
make&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If this is successful, you'll see an output like the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Avr-build-ok.png|image]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If instead you get an error something like &amp;lt;code&amp;gt;make: *** No rule to make target `simpleserial.elf', needed by `elf'.  Stop.&amp;lt;/code&amp;gt;, this means a required file was missing.&amp;lt;/p&amp;gt;&lt;br /&gt;
Programming the target AVR is accomplished in one of two methods depending on your hardware. The ChipWhisperer Capture Rev 2 uses the external &amp;quot;AVR Studio&amp;quot; program, whereas the CW1173 and CW1200 use a programmer menu from the ChipWhisperer-Capture software. &lt;br /&gt;
&lt;br /&gt;
For details about programming the targets, see [[Tutorial B1 Building a SimpleSerial Project]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; WinAVR Path Settings &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, WinAVR is added to your system path. This means you can run avr-gcc, make and other programs from your normal Windows command line. You may not want this on certain systems where you already have similar tools installed. In which case either uncheck the Add WinAVR to Path option, or edit your system path to remove the WinAVR directories.&lt;br /&gt;
&lt;br /&gt;
If you do not add it to the system path, you’ll need a method of readding the WinAVR directories when you want to use WinAVR. To do so create a file called winavr.bat in C:\WinAVR-20100110 with the following contents:&lt;br /&gt;
&lt;br /&gt;
 set PATH=%PATH%;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin&lt;br /&gt;
 cmd&lt;br /&gt;
&lt;br /&gt;
Now when you want to run WinAVR (e.g. to continue the examples here), you can simply double-click on the winavr.bat file. This will configure the path for just that terminal, rather than every terminal you open.&lt;br /&gt;
&lt;br /&gt;
Note if using WinAVR on Windows 8.1, you must replace the dll msys-1.0.dll with an updated version. See [http://www.avrfreaks.net/forum/windows-81-compilation-error Windows 8.1 Fix] for a link to this DLL replacement.&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Dynamic_Time_Warp&amp;diff=2543</id>
		<title>Dynamic Time Warp</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Dynamic_Time_Warp&amp;diff=2543"/>
				<updated>2017-05-16T20:46:17Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dynamic Time Warp gives the ability to automatically resyncronize traces. This uses the Dynamic Time Warp (DTW), which was suggested in the paper [https://www.riscure.com/benzine/documents/elastic_ctrsa_final.pdf Elastic Alignment]. The result is something like the following, showing traces going from unaligned to aligned, where sections of &amp;quot;dead space&amp;quot; are detected:&lt;br /&gt;
&lt;br /&gt;
[[File:alignfull.gif]]&lt;br /&gt;
&lt;br /&gt;
The DTW algorithm has one parameter that can be adjusted. The ''radius'' describes how wide the search should be: with a larger radius, the DTW process will allow larger gaps in the synchronized traces. The maximum allowed gap does not increase one-to-one with the radius, but in general a larger radius will produce a better match with a slightly longer processing time.&lt;br /&gt;
&lt;br /&gt;
== Important Notes ==&lt;br /&gt;
&lt;br /&gt;
Every time the redraw happens, the entire realignment is run. To avoid this you should set the [[Trace Cache]] module as a preprocessing module immediately after the &amp;quot;Dynamic Time Warp&amp;quot;. Be sure to enable that module first on the ''Preprocessing Module'' tab. The results should be the DTW is only run when needed, and not EVERY time you redraw traces.&lt;br /&gt;
&lt;br /&gt;
[[File:dtwcache.png|400px]]&lt;br /&gt;
&lt;br /&gt;
You can specify further modules after the trace cache, for example a digital filter. If you adjust the settings of the digital filter (or any other module after the cache), traces will be read from the cache instead of the DTW process rerunning. If you adjust settings of a module infront of the cache (such as a digital filter before the DTW process) the cache is invalidated and the DTW process runs again.&lt;br /&gt;
&lt;br /&gt;
== Known Issues ==&lt;br /&gt;
&lt;br /&gt;
* Current progress bar is nonsensical, and only present to give you some idea of processing status.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: Preprocessing Module]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2521</id>
		<title>Installing ChipWhisperer/Required Tools - Windows</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2521"/>
				<updated>2017-05-16T19:47:43Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Python ==&lt;br /&gt;
For any of the other installation methods, you'll need to have Python 2 installed on your computer. If you already a recent version of Python installed (2.7.x), you can skip this step. Note that Python 3.x will not work with this codebase. There's also a bit of setup that's needed to get other tools and prepare other drivers.&lt;br /&gt;
&lt;br /&gt;
The recommend method of installing Python is to use a distribution called [http://winpython.github.io/ WinPython]. This setup avoids installing Python globally, and includes most of the software you will need. In addition it makes it possible to install 32-bit and 64-bit Python on the same system with minimal problems. This can be very useful as the 64-bit version is handy for doing analysis on large data sets.&lt;br /&gt;
&lt;br /&gt;
To install WinPython 2.7.x, Download a release in the 2.7.x branch from the [http://winpython.github.io/ WinPython] site. It's recommended to use the 32-bit version, but you can also use the 64-bit version. Also, note that the recent releases (like WinPython-32bit-2.7.13.0Zero) don't come with any pre-installed packages. We recommend [https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/ WinPython 2.7.10.3].&lt;br /&gt;
&lt;br /&gt;
Note that certain drivers (such as the SmartCard driver) ''do not'' work on the 64-bit version. Choose a reasonable location to install this to - note the default is simply in the download directory. Instead it's recommended to find a directory such as &amp;lt;code&amp;gt;c:\WinPython32bit-2.7.10.3&amp;lt;/code&amp;gt;, or into your local directory such as &amp;lt;code&amp;gt;c:\Users\yourname\WinPython-32bit-2.7.10.3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Go to your installation directory for WinPython, and run the shortcut called '''WinPython Command Prompt.exe'''. This will give you a command prompt which is setup to run Python along with associated scripts.&lt;br /&gt;
&lt;br /&gt;
''Optional'': You can add the python.exe you just installed to your PATH. To do so navigate to your installation folder, and run the '''WinPython Control Panel.exe''' program. Then select ''Advanced -&amp;gt; Register distribution...''. If you do not do this, you will have to run all commands in this document via the '''WinPython Command Prompt.exe'''. If you plan on running both 32-bit and 64-bit Python, you should not register them. Instead explicitly call the correct Python by always running the '''WinPython Command Prompt.exe''', and then calling specific programs (such as CW Capture or Analyzer) from that command prompt.&lt;br /&gt;
&lt;br /&gt;
== Python Packages ==&lt;br /&gt;
There are a number of packages that the ChipWhisperer project uses. You'll need to install these so that the software can run. Note that the PyPi install process should automatically install these, so you shouldn't need to manually install everything there.&lt;br /&gt;
&lt;br /&gt;
Run the following commands to get the needed packages:&lt;br /&gt;
* '''PyQTGraph:''' &amp;lt;code&amp;gt;pip install pyqtgraph&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ConfigObj:''' &amp;lt;code&amp;gt;pip install configobj&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might also need some extra packages. Generally you can avoid them unless you have specific need of the features they enable:&lt;br /&gt;
&lt;br /&gt;
'''PyUSB:''' if you're planning to use the ChipWhisperer Capture Rev2 hardware, this is necessary. You can install this using pip:&lt;br /&gt;
* &amp;lt;code&amp;gt;pip install pyusb&amp;lt;/code&amp;gt;&lt;br /&gt;
* If that fails, try specifying the latest version, like: &amp;lt;code&amp;gt;pip install pyusb==1.0.0b1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''FTD2XX:''' [https://github.com/snmishra/ftd2xx ftd2xx] is required for SASEBO-W, SAKURA-G, and SASEBO-GII Support. To install this package, [https://github.com/snmishra/ftd2xx/archive/master.zip download a copy of the ftd2xx repository] and unzip it somewhere. Then run the following where you unzipped it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python setup.py install&amp;lt;/pre&amp;gt;&lt;br /&gt;
This package will also require you to install the [http://www.ftdichip.com/Drivers/D2XX.htm FTDI D2XX Drivers]. In the preceeding link simply find the correct driver for your OS Version and install that.&lt;br /&gt;
&lt;br /&gt;
'''MYSQL:''' If you want to use the MySQL trace format (not used by default), you'll need to install [https://pypi.python.org/pypi/umysql umysql]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pip install umysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''PYSCARD:''' If planning on using a PS/SC smartcard reader (i.e. standard USB-connected reader), you will need to install [https://sourceforge.net/projects/pyscard/files/pyscard/ pyscard].&lt;br /&gt;
&lt;br /&gt;
== Installing Hardware Drivers ==&lt;br /&gt;
&lt;br /&gt;
Details of driver installation are on specific pages for supported hardware (such as hwcapturerev2 and naecw1173_cwlite). Drivers are available from [http://chipwhisperer.com ChipWhisperer] release section.&lt;br /&gt;
&lt;br /&gt;
== Getting AVR Compiler Toolchain ==&lt;br /&gt;
&lt;br /&gt;
The following section is not required for your first attack - you can jump right to the tutorial if you wish. However you'll ultimately wish to modify the code of the device under test, and these instructions tell you how. You should first follow the tutorial to confirm your system is working before modifying the code however!&lt;br /&gt;
&lt;br /&gt;
To build the code, you'll need to install avr-gcc on Windows (if using the Virtual Machine, the following is ''not required'', as the VM comes setup with the AVR compiler already). On Windows, you could choose to install:&lt;br /&gt;
&lt;br /&gt;
* Atmel AVR-GCC standalone - see [http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx Atmel avr-gcc standalone] (registration required)&lt;br /&gt;
* WinAVR. Last release - 2010, see [https://sourceforge.net/projects/winavr/files/latest/download?source=typ_redirect WinAVR Page] (no registration required)&lt;br /&gt;
&lt;br /&gt;
To test the code build, follow these steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to the directory with the avr-serial example, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd c:\chipwhisperer\hardware\victims\firmware\simpleserial-aes&lt;br /&gt;
make&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If this is successful, you'll see an output like the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Avr-build-ok.png|image]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If instead you get an error something like &amp;lt;code&amp;gt;make: *** No rule to make target `simpleserial.elf', needed by `elf'.  Stop.&amp;lt;/code&amp;gt;, this means a required file was missing.&amp;lt;/p&amp;gt;&lt;br /&gt;
Programming the target AVR is accomplished in one of two methods depending on your hardware. The ChipWhisperer Capture Rev 2 uses the external &amp;quot;AVR Studio&amp;quot; program, whereas the CW1173 and CW1200 use a programmer menu from the ChipWhisperer-Capture software. &lt;br /&gt;
&lt;br /&gt;
For details about programming the targets, see [[Tutorial B1 Building a SimpleSerial Project]].&lt;br /&gt;
&lt;br /&gt;
=== WinAVR Path Settings ===&lt;br /&gt;
&lt;br /&gt;
By default, WinAVR is added to your system path. This means you can run avr-gcc, make and other programs from your normal Windows command line. You may not want this on certain systems where you already have similar tools installed. In which case either uncheck the Add WinAVR to Path option, or edit your system path to remove the WinAVR directories.&lt;br /&gt;
&lt;br /&gt;
If you do not add it to the system path, you’ll need a method of readding the WinAVR directories when you want to use WinAVR. To do so create a file called winavr.bat in C:\WinAVR-20100110 with the following contents:&lt;br /&gt;
&lt;br /&gt;
 set PATH=%PATH%;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin&lt;br /&gt;
 cmd&lt;br /&gt;
&lt;br /&gt;
Now when you want to run WinAVR (e.g. to continue the examples here), you can simply double-click on the winavr.bat file. This will configure the path for just that terminal, rather than every terminal you open.&lt;br /&gt;
&lt;br /&gt;
Note if using WinAVR on Windows 8.1, you must replace the dll msys-1.0.dll with an updated version. See [http://www.avrfreaks.net/forum/windows-81-compilation-error Windows 8.1 Fix] for a link to this DLL replacement.&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2520</id>
		<title>Installing ChipWhisperer/Required Tools - Windows</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2520"/>
				<updated>2017-05-16T19:46:37Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Python ==&lt;br /&gt;
For any of the other installation methods, you'll need to have Python 2 installed on your computer. If you already a recent version of Python installed (2.7.x), you can skip this step. Note that Python 3.x will not work with this codebase. There's also a bit of setup that's needed to get other tools and prepare other drivers.&lt;br /&gt;
&lt;br /&gt;
The recommend method of installing Python is to use a distribution called [http://winpython.github.io/ WinPython]. This setup avoids installing Python globally, and includes most of the software you will need. In addition it makes it possible to install 32-bit and 64-bit Python on the same system with minimal problems. This can be very useful as the 64-bit version is handy for doing analysis on large data sets.&lt;br /&gt;
&lt;br /&gt;
To install WinPython 2.7.x, Download a release in the 2.7.x branch from the [http://winpython.github.io/ WinPython] site. It's recommended to use the 32-bit version, but you can also use the 64-bit version. Also, note that the recent releases (like WinPython-32bit-2.7.13.0Zero) don't come with any pre-installed packages. We recommend [https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/ WinPython 2.7.10.3].&lt;br /&gt;
&lt;br /&gt;
Note that certain drivers (such as the SmartCard driver) ''do not'' work on the 64-bit version. Choose a reasonable location to install this to - note the default is simply in the download directory. Instead it's recommended to find a directory such as &amp;lt;code&amp;gt;c:\WinPython32bit-2.7.10.3&amp;lt;/code&amp;gt;, or into your local directory such as &amp;lt;code&amp;gt;c:\Users\yourname\WinPython-32bit-2.7.10.3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Go to your installation directory for WinPython, and run the shortcut called '''WinPython Command Prompt.exe'''. This will give you a command prompt which is setup to run Python along with associated scripts.&lt;br /&gt;
&lt;br /&gt;
''Optional'': You can add the python.exe you just installed to your PATH. To do so navigate to your installation folder, and run the '''WinPython Control Panel.exe''' program. Then select ''Advanced -&amp;gt; Register distribution...''. If you do not do this, you will have to run all commands in this document via the '''WinPython Command Prompt.exe'''. If you plan on running both 32-bit and 64-bit Python, you should not register them. Instead explicitly call the correct Python by always running the '''WinPython Command Prompt.exe''', and then calling specific programs (such as CW Capture or Analyzer) from that command prompt.&lt;br /&gt;
&lt;br /&gt;
== Python Packages ==&lt;br /&gt;
There are a number of packages that the ChipWhisperer project uses. You'll need to install these so that the software can run. Note that the PyPi install process should automatically install these, so you shouldn't need to manually install everything there.&lt;br /&gt;
&lt;br /&gt;
Run the following commands to get the needed packages:&lt;br /&gt;
* '''PyQTGraph:''' &amp;lt;code&amp;gt;pip install pyqtgraph&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ConfigObj:''' &amp;lt;code&amp;gt;pip install configobj&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might also need some extra packages. Generally you can avoid them unless you have specific need of the features they enable:&lt;br /&gt;
&lt;br /&gt;
'''PyUSB:''' if you're planning to use the ChipWhisperer Capture Rev2 hardware, this is necessary. You can install this using pip:&lt;br /&gt;
* &amp;lt;code&amp;gt;pip install pyusb&amp;lt;/code&amp;gt;&lt;br /&gt;
* If that fails, try specifying the latest version, like: &amp;lt;code&amp;gt;pip install pyusb==1.0.0b1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''FTD2XX:''' [https://github.com/snmishra/ftd2xx ftd2xx] is required for SASEBO-W, SAKURA-G, and SASEBO-GII Support. To install this package, [https://github.com/snmishra/ftd2xx/archive/master.zip download a copy of the ftd2xx repository] and unzip it somewhere. Then run the following where you unzipped it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python setup.py install&amp;lt;/pre&amp;gt;&lt;br /&gt;
This package will also require you to install the [http://www.ftdichip.com/Drivers/D2XX.htm FTDI D2XX Drivers]. In the preceeding link simply find the correct driver for your OS Version and install that.&lt;br /&gt;
&lt;br /&gt;
'''MYSQL:''' If you want to use the MySQL trace format (not used by default), you'll need to install [https://pypi.python.org/pypi/umysql umysql]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pip install umysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''PYSCARD:''' If planning on using a PS/SC smartcard reader (i.e. standard USB-connected reader), you will need to install [https://sourceforge.net/projects/pyscard/files/pyscard/ pyscard].&lt;br /&gt;
&lt;br /&gt;
== Installing Hardware Drivers ==&lt;br /&gt;
&lt;br /&gt;
Details of driver installation are on specific pages for supported hardware (such as hwcapturerev2 and naecw1173_cwlite). Drivers are available from [http://chipwhisperer.com ChipWhisperer] release section.&lt;br /&gt;
&lt;br /&gt;
== Getting AVR Compiler Toolchain ==&lt;br /&gt;
&lt;br /&gt;
The following section is not required for your first attack - you can jump right to the tutorial if you wish. However you'll ultimately wish to modify the code of the device under test, and these instructions tell you how. You should first follow the tutorial to confirm your system is working before modifying the code however!&lt;br /&gt;
&lt;br /&gt;
To build the code, you'll need to install avr-gcc on Windows (if using the Virtual Machine, the following is ''not required'', as the VM comes setup with the AVR compiler already). On Windows, you could choose to install:&lt;br /&gt;
&lt;br /&gt;
* Atmel AVR-GCC standalone - see [http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx Atmel avr-gcc standalone] (registration required)&lt;br /&gt;
* WinAVR. Last release - 2010, see [https://sourceforge.net/projects/winavr/files/latest/download?source=typ_redirect WinAVR Page] (no registration required)&lt;br /&gt;
&lt;br /&gt;
To test the code build, follow these steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to the directory with the avr-serial example, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd c:\chipwhisperer\hardware\victims\firmware\simpleserial-aes&lt;br /&gt;
make&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If this is successful, you'll see an output like the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Avr-build-ok.png|image]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If instead you get an error something like &amp;lt;code&amp;gt;make: *** No rule to make target `simpleserial.elf', needed by `elf'.  Stop.&amp;lt;/code&amp;gt;, this means a required file was missing.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
Programming the target AVR is accomplished in one of two methods depending on your hardware. The ChipWhisperer Capture Rev 2 uses the external &amp;quot;AVR Studio&amp;quot; program, whereas the CW1173 and CW1200 use a programmer menu from the ChipWhisperer-Capture software. &lt;br /&gt;
&lt;br /&gt;
For details about programming the targets, see [[Tutorial B1 Building a SimpleSerial Project]].&lt;br /&gt;
&lt;br /&gt;
=== WinAVR Path Settings ===&lt;br /&gt;
&lt;br /&gt;
By default, WinAVR is added to your system path. This means you can run avr-gcc, make and other programs from your normal Windows command line. You may not want this on certain systems where you already have similar tools installed. In which case either uncheck the Add WinAVR to Path option, or edit your system path to remove the WinAVR directories.&lt;br /&gt;
&lt;br /&gt;
If you do not add it to the system path, you’ll need a method of readding the WinAVR directories when you want to use WinAVR. To do so create a file called winavr.bat in C:\WinAVR-20100110 with the following contents:&lt;br /&gt;
&lt;br /&gt;
 set PATH=%PATH%;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin&lt;br /&gt;
 cmd&lt;br /&gt;
&lt;br /&gt;
Now when you want to run WinAVR (e.g. to continue the examples here), you can simply double-click on the winavr.bat file. This will configure the path for just that terminal, rather than every terminal you open.&lt;br /&gt;
&lt;br /&gt;
Note if using WinAVR on Windows 8.1, you must replace the dll msys-1.0.dll with an updated version. See [http://www.avrfreaks.net/forum/windows-81-compilation-error Windows 8.1 Fix] for a link to this DLL replacement.&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2503</id>
		<title>Installing ChipWhisperer/Required Tools - Windows</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2503"/>
				<updated>2017-05-16T18:08:07Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Python ==&lt;br /&gt;
For any of the other installation methods, you'll need to have Python 2 installed on your computer. If you already a recent version of Python installed (2.7.x), you can skip this step. Note that Python 3.x will not work with this codebase. There's also a bit of setup that's needed to get other tools and prepare other drivers.&lt;br /&gt;
&lt;br /&gt;
The recommend method of installing Python is to use a distribution called [http://winpython.github.io/ WinPython]. This setup avoids installing Python globally, and includes most of the software you will need. In addition it makes it possible to install 32-bit and 64-bit Python on the same system with minimal problems. This can be very useful as the 64-bit version is handy for doing analysis on large data sets.&lt;br /&gt;
&lt;br /&gt;
To install WinPython 2.7.x, Download a release in the 2.7.x branch from the [http://winpython.github.io/ WinPython] site. It's recommended to use the 32-bit version, but you can also use the 64-bit version. Also, note that the recent releases (like WinPython-32bit-2.7.13.0Zero) don't come with any pre-installed packages. We recommend [https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/ WinPython 2.7.10.3].&lt;br /&gt;
&lt;br /&gt;
Note that certain drivers (such as the SmartCard driver) ''do not'' work on the 64-bit version. Choose a reasonable location to install this to - note the default is simply in the download directory. Instead it's recommended to find a directory such as &amp;lt;code&amp;gt;c:\WinPython32bit-2.7.10.3&amp;lt;/code&amp;gt;, or into your local directory such as &amp;lt;code&amp;gt;c:\Users\yourname\WinPython-32bit-2.7.10.3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Go to your installation directory for WinPython, and run the shortcut called '''WinPython Command Prompt.exe'''. This will give you a command prompt which is setup to run Python along with associated scripts.&lt;br /&gt;
&lt;br /&gt;
''Optional'': You can add the python.exe you just installed to your PATH. To do so navigate to your installation folder, and run the '''WinPython Control Panel.exe''' program. Then select ''Advanced -&amp;gt; Register distribution...''. If you do not do this, you will have to run all commands in this document via the '''WinPython Command Prompt.exe'''. If you plan on running both 32-bit and 64-bit Python, you should not register them. Instead explicitly call the correct Python by always running the '''WinPython Command Prompt.exe''', and then calling specific programs (such as CW Capture or Analyzer) from that command prompt.&lt;br /&gt;
&lt;br /&gt;
== Python Packages ==&lt;br /&gt;
There are a number of packages that the ChipWhisperer project uses. You'll need to install these so that the software can run. Note that the PyPi install process should automatically install these, so you shouldn't need to manually install everything there.&lt;br /&gt;
&lt;br /&gt;
Run the following commands to get the needed packages:&lt;br /&gt;
* '''PyQTGraph:''' &amp;lt;code&amp;gt;pip install pyqtgraph&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ConfigObj:''' &amp;lt;code&amp;gt;pip install configobj&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might also need some extra packages. Generally you can avoid them unless you have specific need of the features they enable:&lt;br /&gt;
&lt;br /&gt;
'''PyUSB:''' if you're planning to use the ChipWhisperer Capture Rev2 hardware, this is necessary. You can install this using pip:&lt;br /&gt;
* &amp;lt;code&amp;gt;pip install pyusb&amp;lt;/code&amp;gt;&lt;br /&gt;
* If that fails, try specifying the latest version, like: &amp;lt;code&amp;gt;pip install pyusb==1.0.0b1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''FTD2XX:''' [https://github.com/snmishra/ftd2xx ftd2xx] is required for SASEBO-W, SAKURA-G, and SASEBO-GII Support. To install this package, [https://github.com/snmishra/ftd2xx/archive/master.zip download a copy of the ftd2xx repository] and unzip it somewhere. Then run the following where you unzipped it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python setup.py install&amp;lt;/pre&amp;gt;&lt;br /&gt;
This package will also require you to install the [http://www.ftdichip.com/Drivers/D2XX.htm FTDI D2XX Drivers]. In the preceeding link simply find the correct driver for your OS Version and install that.&lt;br /&gt;
&lt;br /&gt;
'''MYSQL:''' If you want to use the MySQL trace format (not used by default), you'll need to install [https://pypi.python.org/pypi/umysql umysql]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pip install umysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''PYSCARD:''' If planning on using a PS/SC smartcard reader (i.e. standard USB-connected reader), you will need to install [https://sourceforge.net/projects/pyscard/files/pyscard/ pyscard].&lt;br /&gt;
&lt;br /&gt;
== Installing Hardware Drivers ==&lt;br /&gt;
&lt;br /&gt;
Details of driver installation are on specific pages for supported hardware (such as hwcapturerev2 and naecw1173_cwlite). Drivers are available from [http://chipwhisperer.com ChipWhisperer] release section.&lt;br /&gt;
&lt;br /&gt;
== Getting AVR Compiler Toolchain ==&lt;br /&gt;
&lt;br /&gt;
The following section is not required for your first attack - you can jump right to the tutorial if you wish. However you'll ultimately wish to modify the code of the device under test, and these instructions tell you how. You should first follow the tutorial to confirm your system is working before modifying the code however!&lt;br /&gt;
&lt;br /&gt;
To build the code, you'll need to install avr-gcc on Windows (if using the Virtual Machine, the following is ''not required'', as the VM comes setup with the AVR compiler already). On Windows, you could choose to install:&lt;br /&gt;
&lt;br /&gt;
* Atmel AVR-GCC standalone - see [http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx Atmel avr-gcc standalone] (registration required)&lt;br /&gt;
* WinAVR. Last release - 2010, see [https://sourceforge.net/projects/winavr/files/latest/download?source=typ_redirect WinAVR Page] (no registration required)&lt;br /&gt;
&lt;br /&gt;
To test the code build, follow these steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to the directory with the avr-serial example, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd c:\chipwhisperer\hardware\victims\firmware\simpleserial-aes&lt;br /&gt;
make&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If this is successful, you'll see an output like the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Avr-build-ok.png|image]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If instead you get an error something like &amp;lt;code&amp;gt;make: *** No rule to make target `simpleserial.elf', needed by `elf'.  Stop.&amp;lt;/code&amp;gt;, this means a required file was missing.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Programming the target AVR is accomplished in one of two methods depending on your hardware. The ChipWhisperer Capture Rev 2 uses the external &amp;quot;AVR Studio&amp;quot; program, whereas the CW1173 and CW1200 use a programmer menu from the ChipWhisperer-Capture software. &lt;br /&gt;
&lt;br /&gt;
For details about programming the targets, see [[Tutorial B1 Building a SimpleSerial Project]].&lt;br /&gt;
&lt;br /&gt;
=== WinAVR Path Settings ===&lt;br /&gt;
&lt;br /&gt;
By default, WinAVR is added to your system path. This means you can run avr-gcc, make and other programs from your normal Windows command line. You may not want this on certain systems where you already have similar tools installed. In which case either uncheck the Add WinAVR to Path option, or edit your system path to remove the WinAVR directories.&lt;br /&gt;
&lt;br /&gt;
If you do not add it to the system path, you’ll need a method of readding the WinAVR directories when you want to use WinAVR. To do so create a file called winavr.bat in C:\WinAVR-20100110 with the following contents:&lt;br /&gt;
&lt;br /&gt;
 set PATH=%PATH%;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin&lt;br /&gt;
 cmd&lt;br /&gt;
&lt;br /&gt;
Now when you want to run WinAVR (e.g. to continue the examples here), you can simply double-click on the winavr.bat file. This will configure the path for just that terminal, rather than every terminal you open.&lt;br /&gt;
&lt;br /&gt;
Note if using WinAVR on Windows 8.1, you must replace the dll msys-1.0.dll with an updated version. See [http://www.avrfreaks.net/forum/windows-81-compilation-error Windows 8.1 Fix] for a link to this DLL replacement.&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2501</id>
		<title>Installing ChipWhisperer/Required Tools - Windows</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2501"/>
				<updated>2017-05-16T18:02:23Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Test&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
For any of the other installation methods, you'll need to have Python 2 installed on your computer. If you already a recent version of Python installed (2.7.x), you can skip this step. Note that Python 3.x will not work with this codebase. There's also a bit of setup that's needed to get other tools and prepare other drivers.&lt;br /&gt;
&lt;br /&gt;
The recommend method of installing Python is to use a distribution called [http://winpython.github.io/ WinPython]. This setup avoids installing Python globally, and includes most of the software you will need. In addition it makes it possible to install 32-bit and 64-bit Python on the same system with minimal problems. This can be very useful as the 64-bit version is handy for doing analysis on large data sets.&lt;br /&gt;
&lt;br /&gt;
To install WinPython 2.7.x, Download a release in the 2.7.x branch from the [http://winpython.github.io/ WinPython] site. It's recommended to use the 32-bit version, but you can also use the 64-bit version. Also, note that the recent releases (like WinPython-32bit-2.7.13.0Zero) don't come with any pre-installed packages. We recommend [https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/ WinPython 2.7.10.3].&lt;br /&gt;
&lt;br /&gt;
Note that certain drivers (such as the SmartCard driver) ''do not'' work on the 64-bit version. Choose a reasonable location to install this to - note the default is simply in the download directory. Instead it's recommended to find a directory such as &amp;lt;code&amp;gt;c:\WinPython32bit-2.7.10.3&amp;lt;/code&amp;gt;, or into your local directory such as &amp;lt;code&amp;gt;c:\Users\yourname\WinPython-32bit-2.7.10.3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Go to your installation directory for WinPython, and run the shortcut called '''WinPython Command Prompt.exe'''. This will give you a command prompt which is setup to run Python along with associated scripts.&lt;br /&gt;
&lt;br /&gt;
''Optional'': You can add the python.exe you just installed to your PATH. To do so navigate to your installation folder, and run the '''WinPython Control Panel.exe''' program. Then select ''Advanced -&amp;gt; Register distribution...''. If you do not do this, you will have to run all commands in this document via the '''WinPython Command Prompt.exe'''. If you plan on running both 32-bit and 64-bit Python, you should not register them. Instead explicitly call the correct Python by always running the '''WinPython Command Prompt.exe''', and then calling specific programs (such as CW Capture or Analyzer) from that command prompt.&lt;br /&gt;
&lt;br /&gt;
== Python Packages ==&lt;br /&gt;
There are a number of packages that the ChipWhisperer project uses. You'll need to install these so that the software can run. Note that the PyPi install process should automatically install these, so you shouldn't need to manually install everything there.&lt;br /&gt;
&lt;br /&gt;
Run the following commands to get the needed packages:&lt;br /&gt;
* '''PyQTGraph:''' &amp;lt;code&amp;gt;pip install pyqtgraph&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ConfigObj:''' &amp;lt;code&amp;gt;pip install configobj&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might also need some extra packages. Generally you can avoid them unless you have specific need of the features they enable:&lt;br /&gt;
&lt;br /&gt;
'''PyUSB:''' if you're planning to use the ChipWhisperer Capture Rev2 hardware, this is necessary. You can install this using pip:&lt;br /&gt;
* &amp;lt;code&amp;gt;pip install pyusb&amp;lt;/code&amp;gt;&lt;br /&gt;
* If that fails, try specifying the latest version, like: &amp;lt;code&amp;gt;pip install pyusb==1.0.0b1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''FTD2XX:''' [https://github.com/snmishra/ftd2xx ftd2xx] is required for SASEBO-W, SAKURA-G, and SASEBO-GII Support. To install this package, [https://github.com/snmishra/ftd2xx/archive/master.zip download a copy of the ftd2xx repository] and unzip it somewhere. Then run the following where you unzipped it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python setup.py install&amp;lt;/pre&amp;gt;&lt;br /&gt;
This package will also require you to install the [http://www.ftdichip.com/Drivers/D2XX.htm FTDI D2XX Drivers]. In the preceeding link simply find the correct driver for your OS Version and install that.&lt;br /&gt;
&lt;br /&gt;
'''MYSQL:''' If you want to use the MySQL trace format (not used by default), you'll need to install [https://pypi.python.org/pypi/umysql umysql]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pip install umysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''PYSCARD:''' If planning on using a PS/SC smartcard reader (i.e. standard USB-connected reader), you will need to install [https://sourceforge.net/projects/pyscard/files/pyscard/ pyscard].&lt;br /&gt;
&lt;br /&gt;
== Installing Hardware Drivers ==&lt;br /&gt;
&lt;br /&gt;
Details of driver installation are on specific pages for supported hardware (such as hwcapturerev2 and naecw1173_cwlite). Drivers are available from [http://chipwhisperer.com ChipWhisperer] release section.&lt;br /&gt;
&lt;br /&gt;
== Getting AVR Compiler Toolchain ==&lt;br /&gt;
&lt;br /&gt;
The following section is not required for your first attack - you can jump right to the tutorial if you wish. However you'll ultimately wish to modify the code of the device under test, and these instructions tell you how. You should first follow the tutorial to confirm your system is working before modifying the code however!&lt;br /&gt;
&lt;br /&gt;
To build the code, you'll need to install avr-gcc on Windows (if using the Virtual Machine, the following is ''not required'', as the VM comes setup with the AVR compiler already). On Windows, you could choose to install:&lt;br /&gt;
&lt;br /&gt;
* Atmel AVR-GCC standalone - see [http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx Atmel avr-gcc standalone] (registration required)&lt;br /&gt;
* WinAVR. Last release - 2010, see [https://sourceforge.net/projects/winavr/files/latest/download?source=typ_redirect WinAVR Page] (no registration required)&lt;br /&gt;
&lt;br /&gt;
To test the code build, follow these steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to the directory with the avr-serial example, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd c:\chipwhisperer\hardware\victims\firmware\simpleserial-aes&lt;br /&gt;
make&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If this is successful, you'll see an output like the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Avr-build-ok.png|image]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If instead you get an error something like &amp;lt;code&amp;gt;make: *** No rule to make target `simpleserial.elf', needed by `elf'.  Stop.&amp;lt;/code&amp;gt;, this means a required file was missing.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Programming the target AVR is accomplished in one of two methods depending on your hardware. The ChipWhisperer Capture Rev 2 uses the external &amp;quot;AVR Studio&amp;quot; program, whereas the CW1173 and CW1200 use a programmer menu from the ChipWhisperer-Capture software. &lt;br /&gt;
&lt;br /&gt;
For details about programming the targets, see [[Tutorial B1 Building a SimpleSerial Project]].&lt;br /&gt;
&lt;br /&gt;
=== WinAVR Path Settings ===&lt;br /&gt;
&lt;br /&gt;
By default, WinAVR is added to your system path. This means you can run avr-gcc, make and other programs from your normal Windows command line. You may not want this on certain systems where you already have similar tools installed. In which case either uncheck the Add WinAVR to Path option, or edit your system path to remove the WinAVR directories.&lt;br /&gt;
&lt;br /&gt;
If you do not add it to the system path, you’ll need a method of readding the WinAVR directories when you want to use WinAVR. To do so create a file called winavr.bat in C:\WinAVR-20100110 with the following contents:&lt;br /&gt;
&lt;br /&gt;
 set PATH=%PATH%;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin&lt;br /&gt;
 cmd&lt;br /&gt;
&lt;br /&gt;
Now when you want to run WinAVR (e.g. to continue the examples here), you can simply double-click on the winavr.bat file. This will configure the path for just that terminal, rather than every terminal you open.&lt;br /&gt;
&lt;br /&gt;
Note if using WinAVR on Windows 8.1, you must replace the dll msys-1.0.dll with an updated version. See [http://www.avrfreaks.net/forum/windows-81-compilation-error Windows 8.1 Fix] for a link to this DLL replacement.&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2500</id>
		<title>Installing ChipWhisperer/Required Tools - Windows</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Installing_ChipWhisperer/Required_Tools_-_Windows&amp;diff=2500"/>
				<updated>2017-05-16T18:01:59Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Python ===&lt;br /&gt;
For any of the other installation methods, you'll need to have Python 2 installed on your computer. If you already a recent version of Python installed (2.7.x), you can skip this step. Note that Python 3.x will not work with this codebase. There's also a bit of setup that's needed to get other tools and prepare other drivers.&lt;br /&gt;
&lt;br /&gt;
The recommend method of installing Python is to use a distribution called [http://winpython.github.io/ WinPython]. This setup avoids installing Python globally, and includes most of the software you will need. In addition it makes it possible to install 32-bit and 64-bit Python on the same system with minimal problems. This can be very useful as the 64-bit version is handy for doing analysis on large data sets.&lt;br /&gt;
&lt;br /&gt;
To install WinPython 2.7.x, Download a release in the 2.7.x branch from the [http://winpython.github.io/ WinPython] site. It's recommended to use the 32-bit version, but you can also use the 64-bit version. Also, note that the recent releases (like WinPython-32bit-2.7.13.0Zero) don't come with any pre-installed packages. We recommend [https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/ WinPython 2.7.10.3].&lt;br /&gt;
&lt;br /&gt;
Note that certain drivers (such as the SmartCard driver) ''do not'' work on the 64-bit version. Choose a reasonable location to install this to - note the default is simply in the download directory. Instead it's recommended to find a directory such as &amp;lt;code&amp;gt;c:\WinPython32bit-2.7.10.3&amp;lt;/code&amp;gt;, or into your local directory such as &amp;lt;code&amp;gt;c:\Users\yourname\WinPython-32bit-2.7.10.3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Go to your installation directory for WinPython, and run the shortcut called '''WinPython Command Prompt.exe'''. This will give you a command prompt which is setup to run Python along with associated scripts.&lt;br /&gt;
&lt;br /&gt;
''Optional'': You can add the python.exe you just installed to your PATH. To do so navigate to your installation folder, and run the '''WinPython Control Panel.exe''' program. Then select ''Advanced -&amp;gt; Register distribution...''. If you do not do this, you will have to run all commands in this document via the '''WinPython Command Prompt.exe'''. If you plan on running both 32-bit and 64-bit Python, you should not register them. Instead explicitly call the correct Python by always running the '''WinPython Command Prompt.exe''', and then calling specific programs (such as CW Capture or Analyzer) from that command prompt.&lt;br /&gt;
&lt;br /&gt;
== Python Packages ==&lt;br /&gt;
There are a number of packages that the ChipWhisperer project uses. You'll need to install these so that the software can run. Note that the PyPi install process should automatically install these, so you shouldn't need to manually install everything there.&lt;br /&gt;
&lt;br /&gt;
Run the following commands to get the needed packages:&lt;br /&gt;
* '''PyQTGraph:''' &amp;lt;code&amp;gt;pip install pyqtgraph&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ConfigObj:''' &amp;lt;code&amp;gt;pip install configobj&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might also need some extra packages. Generally you can avoid them unless you have specific need of the features they enable:&lt;br /&gt;
&lt;br /&gt;
'''PyUSB:''' if you're planning to use the ChipWhisperer Capture Rev2 hardware, this is necessary. You can install this using pip:&lt;br /&gt;
* &amp;lt;code&amp;gt;pip install pyusb&amp;lt;/code&amp;gt;&lt;br /&gt;
* If that fails, try specifying the latest version, like: &amp;lt;code&amp;gt;pip install pyusb==1.0.0b1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''FTD2XX:''' [https://github.com/snmishra/ftd2xx ftd2xx] is required for SASEBO-W, SAKURA-G, and SASEBO-GII Support. To install this package, [https://github.com/snmishra/ftd2xx/archive/master.zip download a copy of the ftd2xx repository] and unzip it somewhere. Then run the following where you unzipped it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python setup.py install&amp;lt;/pre&amp;gt;&lt;br /&gt;
This package will also require you to install the [http://www.ftdichip.com/Drivers/D2XX.htm FTDI D2XX Drivers]. In the preceeding link simply find the correct driver for your OS Version and install that.&lt;br /&gt;
&lt;br /&gt;
'''MYSQL:''' If you want to use the MySQL trace format (not used by default), you'll need to install [https://pypi.python.org/pypi/umysql umysql]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pip install umysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''PYSCARD:''' If planning on using a PS/SC smartcard reader (i.e. standard USB-connected reader), you will need to install [https://sourceforge.net/projects/pyscard/files/pyscard/ pyscard].&lt;br /&gt;
&lt;br /&gt;
== Installing Hardware Drivers ==&lt;br /&gt;
&lt;br /&gt;
Details of driver installation are on specific pages for supported hardware (such as hwcapturerev2 and naecw1173_cwlite). Drivers are available from [http://chipwhisperer.com ChipWhisperer] release section.&lt;br /&gt;
&lt;br /&gt;
== Getting AVR Compiler Toolchain ==&lt;br /&gt;
&lt;br /&gt;
The following section is not required for your first attack - you can jump right to the tutorial if you wish. However you'll ultimately wish to modify the code of the device under test, and these instructions tell you how. You should first follow the tutorial to confirm your system is working before modifying the code however!&lt;br /&gt;
&lt;br /&gt;
To build the code, you'll need to install avr-gcc on Windows (if using the Virtual Machine, the following is ''not required'', as the VM comes setup with the AVR compiler already). On Windows, you could choose to install:&lt;br /&gt;
&lt;br /&gt;
* Atmel AVR-GCC standalone - see [http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx Atmel avr-gcc standalone] (registration required)&lt;br /&gt;
* WinAVR. Last release - 2010, see [https://sourceforge.net/projects/winavr/files/latest/download?source=typ_redirect WinAVR Page] (no registration required)&lt;br /&gt;
&lt;br /&gt;
To test the code build, follow these steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to the directory with the avr-serial example, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd c:\chipwhisperer\hardware\victims\firmware\simpleserial-aes&lt;br /&gt;
make&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If this is successful, you'll see an output like the following:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;[[File:Avr-build-ok.png|image]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If instead you get an error something like &amp;lt;code&amp;gt;make: *** No rule to make target `simpleserial.elf', needed by `elf'.  Stop.&amp;lt;/code&amp;gt;, this means a required file was missing.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Programming the target AVR is accomplished in one of two methods depending on your hardware. The ChipWhisperer Capture Rev 2 uses the external &amp;quot;AVR Studio&amp;quot; program, whereas the CW1173 and CW1200 use a programmer menu from the ChipWhisperer-Capture software. &lt;br /&gt;
&lt;br /&gt;
For details about programming the targets, see [[Tutorial B1 Building a SimpleSerial Project]].&lt;br /&gt;
&lt;br /&gt;
=== WinAVR Path Settings ===&lt;br /&gt;
&lt;br /&gt;
By default, WinAVR is added to your system path. This means you can run avr-gcc, make and other programs from your normal Windows command line. You may not want this on certain systems where you already have similar tools installed. In which case either uncheck the Add WinAVR to Path option, or edit your system path to remove the WinAVR directories.&lt;br /&gt;
&lt;br /&gt;
If you do not add it to the system path, you’ll need a method of readding the WinAVR directories when you want to use WinAVR. To do so create a file called winavr.bat in C:\WinAVR-20100110 with the following contents:&lt;br /&gt;
&lt;br /&gt;
 set PATH=%PATH%;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin&lt;br /&gt;
 cmd&lt;br /&gt;
&lt;br /&gt;
Now when you want to run WinAVR (e.g. to continue the examples here), you can simply double-click on the winavr.bat file. This will configure the path for just that terminal, rather than every terminal you open.&lt;br /&gt;
&lt;br /&gt;
Note if using WinAVR on Windows 8.1, you must replace the dll msys-1.0.dll with an updated version. See [http://www.avrfreaks.net/forum/windows-81-compilation-error Windows 8.1 Fix] for a link to this DLL replacement.&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2499</id>
		<title>Template:CollapsibleSection</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2499"/>
				<updated>2017-05-16T18:00:01Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: Undo revision 2498 by Gdeon (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;collapse-pre-one{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;desktoponly mw-collapsible {{{uncollapsed|mw-collapsed}}}&amp;quot; style=&amp;quot;line-height:inherit;margin-left:{{{indentation|-5}}}px&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible-toggle toccolours&amp;quot; style=&amp;quot;float: none;border:none;background-color:transparent;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;mw-collapsible-toggle-row&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-header&amp;quot; style=&amp;quot;padding:0;&amp;quot;&amp;gt;&lt;br /&gt;
{{{intro|}}}&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-indicator&amp;quot; style=&amp;quot;width:30px;&amp;quot;&amp;gt;[[File:right-black-arrow.png|20px|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:{{{content|}}}}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mobileonly&amp;quot;&amp;gt;&lt;br /&gt;
{{{intro|}}} {{:{{{content|}}}}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2498</id>
		<title>Template:CollapsibleSection</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2498"/>
				<updated>2017-05-16T17:52:13Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: Undo revision 2484 by Dsevastian (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;collapse-pre-one{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;line-height:inherit;margin-left:{{{indentation|-5}}}px&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible-toggle toccolours&amp;quot; style=&amp;quot;float: none;border:none;background-color:transparent;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;mw-collapsible-toggle-row&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-header&amp;quot; style=&amp;quot;padding:0;&amp;quot;&amp;gt;&lt;br /&gt;
{{{intro|}}}&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-indicator&amp;quot; style=&amp;quot;width:30px;&amp;quot;&amp;gt;[[File:right-black-arrow.png|150px|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:{{{content|}}}}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2468</id>
		<title>Template:CollapsibleSection</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2468"/>
				<updated>2017-05-15T18:17:41Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;collapse-pre-one{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;line-height:inherit;margin-left:{{{indentation|-5}}}px&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible-toggle toccolours&amp;quot; style=&amp;quot;float: none;border:none;background-color:transparent;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;mw-collapsible-toggle-row&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-header&amp;quot; style=&amp;quot;padding:0;&amp;quot;&amp;gt;&lt;br /&gt;
{{{intro|}}}&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-indicator&amp;quot; style=&amp;quot;width:30px;&amp;quot;&amp;gt;[[File:right-black-arrow.png|150px|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:{{{content|}}}}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2467</id>
		<title>Template:CollapsibleSection</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2467"/>
				<updated>2017-05-15T18:16:57Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;collapse-pre-one{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;line-height:inherit;margin-left:{{{indentation|0}}}px&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible-toggle toccolours&amp;quot; style=&amp;quot;float: none;border:none;background-color:transparent;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;mw-collapsible-toggle-row&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-header&amp;quot; style=&amp;quot;padding:0;&amp;quot;&amp;gt;&lt;br /&gt;
{{{intro|}}}&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-indicator&amp;quot; style=&amp;quot;width:30px;&amp;quot;&amp;gt;[[File:right-black-arrow.png|150px|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:{{{content|}}}}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2466</id>
		<title>Template:CollapsibleSection</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Template:CollapsibleSection&amp;diff=2466"/>
				<updated>2017-05-15T18:15:45Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;collapse-pre-one{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;line-height:inherit;margin-left:{{{indentation|2}}}px&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;{{{content|collapsible-id-default}}}&amp;quot; class=&amp;quot;mw-collapsible-toggle toccolours&amp;quot; style=&amp;quot;float: none;border:none;background-color:transparent;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;mw-collapsible-toggle-row&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-header&amp;quot; style=&amp;quot;padding:0;&amp;quot;&amp;gt;&lt;br /&gt;
{{{intro|}}}&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div class=&amp;quot;mw-collapsible-toggle-indicator&amp;quot; style=&amp;quot;width:30px;&amp;quot;&amp;gt;[[File:right-black-arrow.png|150px|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:{{{content|}}}}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Main_Page&amp;diff=2448</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Main_Page&amp;diff=2448"/>
				<updated>2017-05-09T15:24:24Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Recent/Upcoming Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;strong&amp;gt; ChipWhisperer® by NewAE Technology Inc. &amp;lt;/strong&amp;gt;&lt;br /&gt;
&amp;lt;!-- You MUST resave this page for categorytree to update for now --&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;categorytree mode=all depth=4 hideroot='on' style=&amp;quot;float:right; clear:right; margin-left:1ex; border:1px solid gray; padding:0.7ex; background-color:white;&amp;quot;&amp;gt;TocRoot&amp;lt;/categorytree&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Welcome to ChipWhisperer - the complete open-source toolchain for side-channel power analysis and glitching attacks. This is the main landing page for ChipWhisperer. ChipWhisperer has been presented at conferences such as DEFCON and Blackhat, had a [https://www.kickstarter.com/projects/coflynn/chipwhisperer-lite-a-new-era-of-hardware-security successful Kickstarter (that delivered ahead of schedule)], and placed 2nd place in the first annual Hackaday Prize. ChipWhisperer has been used in a number of academic articles, and is featured in the Car Hacking Handbook. Portions of the design have even been used by [http://permalink.lanl.gov/object/tr?what=info:lanl-repo/lareport/LA-UR-15-26344 Los Alamos Labs for an electron accelerator]. You can see a full list of references on the [[Press]] page.&lt;br /&gt;
&lt;br /&gt;
ChipWhisperer is maintained by [https://www.newae.com NewAE Technology Inc.], which sells a combination of open-source hardware, supporting tools, training, and consulting services. ChipWhisperer is trademark of NewAE Technology Inc., registered in the US and Europe. This means only NewAE can sell official products under the ChipWhisperer name, and was done to ensure products meet [[Quality Control Guidelines]], as these fairly complex products require good testing to ensure you don't have a frustrating experience.&lt;br /&gt;
&lt;br /&gt;
Beyond supporting just the ChipWhisperer project, this wiki is now growing towards the objective of offering a complete reference on embedded security.&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
Where to begin? If you're new to this area, see the [[Getting Started]] page, which details how you can get involved in side-channel power analysis. From there you can see the hardware documentation (linked below), or take one of the [http://newae.com/training/ Training Courses].&lt;br /&gt;
&lt;br /&gt;
If you're stuck, you can also get help on the [https://www.newae.com/forum Discussion Forum].&lt;br /&gt;
&lt;br /&gt;
= Hardware Documentation =&lt;br /&gt;
&lt;br /&gt;
{{Template:Hardware}}&lt;br /&gt;
&lt;br /&gt;
= Software Documentation =&lt;br /&gt;
&lt;br /&gt;
ChipWhisperer is an open-source project. All of the source code is available from the [https://github.com/newaetech/chipwhisperer Git Repository]. For more information about the software releases, see [https://github.com/newaetech/chipwhisperer/releases Releases] or the installation instructions at [[Installing ChipWhisperer]].&lt;br /&gt;
&lt;br /&gt;
The following pages document some of the many features of the ChipWhisperer Capture and Analyzer software, along with some other ChipWhisperer interfaces:&lt;br /&gt;
&lt;br /&gt;
* [[Installing ChipWhisperer]]&lt;br /&gt;
* [[Common Tool Information]]&lt;br /&gt;
** [[Making Scripts]]&lt;br /&gt;
** [[Adding Modules/Parameters]]&lt;br /&gt;
* [[CW-Capture Tool]]&lt;br /&gt;
** [[Glitch Explorer]]&lt;br /&gt;
** [[Serial Terminal]]&lt;br /&gt;
* [[CW-Analyzer Tool]]&lt;br /&gt;
* [[File Formats]]&lt;br /&gt;
* [[MATLAB Control of CW-Lite]]&lt;br /&gt;
&lt;br /&gt;
The remaining documentation is intended for developers:&lt;br /&gt;
&lt;br /&gt;
* [[Error Messages / Common Problems]]&lt;br /&gt;
* [[FPGA Details]]&lt;br /&gt;
* [[CW Release Steps]]&lt;br /&gt;
&lt;br /&gt;
= Sample Projects and Tutorials =&lt;br /&gt;
&lt;br /&gt;
== ChipWhisperer Tutorials ==&lt;br /&gt;
&lt;br /&gt;
The following tutorials use the ChipWhisperer software and/or hardware. They are designed to take you through a complete attack. You may also want to check the page on [[Embedded Attacks]] for more snippets of simple attacks and other things you should verify when making a secure system.&lt;br /&gt;
&lt;br /&gt;
Not all tutorials are possible with all hardware. See the various tutorial pages for details.&lt;br /&gt;
&lt;br /&gt;
{{Template:Tutorials}}&lt;br /&gt;
&lt;br /&gt;
== Example Attacks / Other ==&lt;br /&gt;
&lt;br /&gt;
While ChipWhisperer started as a side-channel power analysis platform, it has grown to be useful in other attack types. This section is designed to show you a wide variety of attacks on embedded systems, to give you an idea of what is required for building secure embedded systems. These are held on the page [[Embedded Attacks]].&lt;br /&gt;
&lt;br /&gt;
In 2016, ChipWhisperer was used as part of the CHES2016 CTF challenge. See details of the event on the [[CHES2016 CTF]] page.&lt;br /&gt;
&lt;br /&gt;
= Recent/Upcoming Events =&lt;br /&gt;
&lt;br /&gt;
Upcoming events with NewAE:&lt;br /&gt;
* Blackhat USA 2017 ([https://www.blackhat.com/us-17/training/advanced-hardware-hacking-hands-on-power-analysis-and-glitching-with-the-chipwhisperer.html Hands-on Power Analysis &amp;amp; Glitching with the ChipWhisperer])&lt;br /&gt;
&lt;br /&gt;
These are some past events that were attended by someone from NewAE:&lt;br /&gt;
* COSADE 2017: Gold sponsor&lt;br /&gt;
* Blackhat USA 2016: Training based on ChipWhisperer, 2x talks by Colin, Arsenal&lt;br /&gt;
* CHES 2016: Sponsor with exhibit booth&lt;br /&gt;
* Blackhat USA 2014: Training class&lt;br /&gt;
* RECON 2014: [http://recon.cx/2014/video/recon2014-24-colin-o-flynn-Power-Analysis-and-Clock-Glitching-with-the-Open-Source-ChipWhisperer-Platform.mp4 Video] and [https://www.assembla.com/spaces/chipwhisperer/documents/cnp7Ss_8Sr471aacwqjQXA/download/cnp7Ss_8Sr471aacwqjQXA Slides]&lt;br /&gt;
* [http://solidcon.com/solid2014 O'Reilly Solid 2014]: [http://solidcon.com/solid2014/public/schedule/detail/33655 Demo]&lt;br /&gt;
* [http://cosade.org/ COSADE] 2014: [http://eprint.iacr.org/2014/204.pdf Paper]&lt;br /&gt;
* CHES 2013: [http://www.newae.com/files/CHES2013_Tutorial.pptx Slides] and [http://www.youtube.com/watch?v=UzDx5yx3Qc4&amp;amp;hd=1 Video]&lt;br /&gt;
* Blackhat USA 2013 &lt;br /&gt;
* iSEC Open Security Forum (April 2013)  &lt;br /&gt;
* Design West 2013&lt;br /&gt;
* Blackhat EU 2013&lt;br /&gt;
* AtlSecCon 2013&lt;br /&gt;
* Blackhat Abu Dhabi 2012&lt;br /&gt;
&lt;br /&gt;
= Extra Notes =&lt;br /&gt;
&lt;br /&gt;
See the page [[Thanks]] for a note about the people who made this project possible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ChipWhisperer is a Trademark of NewAE Technology Inc., registered in the U.S and Europe. Used with Permission.&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2439</id>
		<title>CW308T-STM32F</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2439"/>
				<updated>2017-04-26T17:17:21Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Building and Debugging via ST's System Workbench */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox cw308target&lt;br /&gt;
|name                   = CW308T-STM32F&lt;br /&gt;
|image                  = cw308_stm32f.jpg&lt;br /&gt;
|caption                = &lt;br /&gt;
|Target Device          = ST STM32F&lt;br /&gt;
|Target Architecture    = Cortex M0,M3,M4&lt;br /&gt;
|Hardware Crypto        = Possible&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
|Design Files           = [https://github.com/newaetech/chipwhisperer/tree/master/hardware/victims/cw308_ufo_target/stm32f GITHub Link]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.newae.com/CW308T-STM32F OSH Park PCBs]&lt;br /&gt;
&lt;br /&gt;
|Supported Applications = [[SimpleSerial | Simple Serial Enc/Auth]]&lt;br /&gt;
|Programmer             = ST-LINK/V2&lt;br /&gt;
|Status                 = Released&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Supported Devices ==&lt;br /&gt;
&lt;br /&gt;
The STM32F board supports several STM32F devices in the TQFP-64 package. Various solder jumpers need to bet set to either the &amp;quot;A&amp;quot; or &amp;quot;B&amp;quot; position to select appropriate VCC supply for the different series. The following table summarizes examples of suitable devices:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!STM32F Series&lt;br /&gt;
!Package&lt;br /&gt;
!Device&lt;br /&gt;
!Hardware AES&lt;br /&gt;
!Tested&lt;br /&gt;
!Jumper&lt;br /&gt;
|-&lt;br /&gt;
|F0&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F071RBT6&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F1&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F100RBT6B&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F2&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F215RET6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F3&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F303R8T6&lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F415RGT6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F405RGT6&lt;br /&gt;
|No&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== VCC-Int Supply ===&lt;br /&gt;
Several devices (F2, F4) have internal core voltage regulators. By default the CW308 board attempts to provide power for these pins, but the voltage may not be high enough to cause the internal regulator to disable itself. In this case you can use the VADJ regulator to ensure the internal regulator is disabled. See [[Targets with Internal Regulators]] for details.&lt;br /&gt;
&lt;br /&gt;
=== Pin-outs across TQFP Devices ===&lt;br /&gt;
&lt;br /&gt;
The following shows differences in pinouts between three groups of devices. The left-most is the STM32F051RB, which uses the same 3.3V VCORE as the STM32F1/F3. It has fewer VCC pins, so the I/O occupying that are VCC/GND pins on the STM32F1 (such as PF6/PF7) are tied to GND/VCC. The right-most part is the pinout of the STM32F2/F4. It has an internal regulator, where the VCAP pins are the output of this regulator (and input to the internal core logic).&lt;br /&gt;
&lt;br /&gt;
[[File:power_diffstm32.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Note for the devices with a 3.3V VCORE, you should not mount decoupling capacitors C5/C6/C7/C8. You will still get some leakage with those capacitors mounted, but a stronger signal is present without them.&lt;br /&gt;
&lt;br /&gt;
== Hardware AES ==&lt;br /&gt;
&lt;br /&gt;
The STM32F21x, and STM32F41x/43x have hardware crypto modules (AES, DES, TDES) along with hardware hash (SHA1, MD5).&lt;br /&gt;
&lt;br /&gt;
== Programming Connection ==&lt;br /&gt;
&lt;br /&gt;
The 20-pin JTAG port (J6 on CW308 Board) can be used with the [https://www.digikey.com/product-detail/en/stmicroelectronics/ST-LINK-V2/497-10484-ND/2214535 ST-LINK/V2] which is a low-cost JTAG programmer. &lt;br /&gt;
&lt;br /&gt;
It is also possible to use other JTAG programmers such as OpenOCD. The following command worked with an Olimex OpenOCD programmer and their [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/ OpenOCD for Windows] software:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openocd &lt;br /&gt;
  -f path/to/board/files/cw308.cfg &lt;br /&gt;
  -c init &lt;br /&gt;
  -c targets &lt;br /&gt;
  -c &amp;quot;halt&amp;quot; &lt;br /&gt;
  -c &amp;quot;flash write_image erase path/to/firmware.hex&amp;quot;       &lt;br /&gt;
  -c &amp;quot;verify_image path/to/firmware.hex&amp;quot;        &lt;br /&gt;
  -c &amp;quot;reset run&amp;quot; &lt;br /&gt;
  -c shutdown&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the contents of &amp;lt;code&amp;gt;cw308.cfg&amp;lt;/code&amp;gt; are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source [find interface/olimex-arm-usb-ocd-h.cfg]&lt;br /&gt;
source [find target/stm32f4x.cfg]&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example Projects ==&lt;br /&gt;
&lt;br /&gt;
SimpleSerial builds for each of the STM32Fx Devices. Each device is a separate HAL. These HAL modules have been copied from ST's HAL (not the CUBE) and greatly reduced in size by deleting unused files (such as headers for unused devices), and combining several C-source files into a single low-level C-file.&lt;br /&gt;
&lt;br /&gt;
=== Building ST Example on Command Line ===&lt;br /&gt;
The regular firmware build process works with the STM32 devices. For example, to build `simpleserial-aes`, navigate to the folder `chipwhisperer\hardware\victims\firmware\simpleserial-aes` and run the following command on the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
make PLATFORM=CW308_STM32F0 CRYPTO_TARGET=TINYAES128C&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, this command will finish by printing the output file size and the platform:&lt;br /&gt;
[[File:Stm32-make.png]]&lt;br /&gt;
&lt;br /&gt;
=== Running ST Example with ST-Link ===&lt;br /&gt;
Once you've built a binary to load onto the target, you're ready to program it. Plug your programmer into the 20 pin JTAG connector (J6 on the UFO board):&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-jtag.jpg|600px]]&lt;br /&gt;
&lt;br /&gt;
Then, the details of this step will depend on your programmer. If you're using an ST-Link programmer, open the ST-Link utility and connect to the device:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-connect.png]]&lt;br /&gt;
&lt;br /&gt;
Load your `.hex` file and program the device with the Program and Verify button:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-program.png]]&lt;br /&gt;
&lt;br /&gt;
After this, you're ready to go - you can use the ChipWhisperer terminal to talk to your target. You might need to reset the target before you do anything else.&lt;br /&gt;
&lt;br /&gt;
=== Building and Debugging via ST's System Workbench ===&lt;br /&gt;
It's also possible to work on the example projects using [http://www.st.com/en/development-tools/sw4stm32.html ST's System Workbench IDE]. This IDE also supports debugging, which is helpful for working out all the kinks in your firmware.&lt;br /&gt;
&lt;br /&gt;
To build the ChipWhisperer examples in System Workbench:&lt;br /&gt;
&lt;br /&gt;
1. Create a ''Makefile Project with Existing Code'' and enter the firmware's location in Existing Code Location:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-st-1.png]]&lt;br /&gt;
&lt;br /&gt;
2. Link the external files into the project. To do this, under ''File &amp;gt; Import'', select ''File System''. In the `chipwhisperer\hardware\victims\firmware` directory, select all of the relevant files and folders (Makefile in base folder, Makefile in HAL folder, STM32Fx HAL folder). Ensure that make links to these files (instead of directly importing them):&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-st-2.png]]&lt;br /&gt;
&lt;br /&gt;
3. Set up the build command. In ''File &amp;gt; Properties'', go to ''C/C++ Build'' and deselect 'Use default build command'. Enter the command you would normally enter on the command line:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-st-3.png]]&lt;br /&gt;
&lt;br /&gt;
4. Build the project and confirm that the build works from the output in the IDE console.&lt;br /&gt;
&lt;br /&gt;
Then, if you want to set up debugging:&lt;br /&gt;
&lt;br /&gt;
1. Find ST's list of debugging targets (check around `C:\STMicro\Ac6\SystemWorkbench\plugins\fr.ac6.mcu.debug_1.12.1.201703061527\resources\openocd\scripts\board`). Make a config file for your target. This file's contents should be something like (adjust for your board):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This is an CW308T_STM32F0 board with a single STM32F071R8Tx chip.&lt;br /&gt;
# Generated by System Workbench for STM32&lt;br /&gt;
&lt;br /&gt;
source [find ../interface/stlink-v2-1.cfg]&lt;br /&gt;
&lt;br /&gt;
set WORKAREASIZE 0x2000&lt;br /&gt;
transport select &amp;quot;hla_swd&amp;quot;&lt;br /&gt;
&lt;br /&gt;
set CHIPNAME STM32F071R8Tx&lt;br /&gt;
&lt;br /&gt;
source [find ../target/stm32f0x_stlink.cfg]&lt;br /&gt;
&lt;br /&gt;
# use hardware reset, connect under reset&lt;br /&gt;
reset_config srst_only srst_nogate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. In ''Run &amp;gt; Debug Configurations'', make a new ''Ac6 STM32 Debugging'' configuration. Under the 'Debugger' tab, select ''Use local script'' and select your custom script:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-st-4.png]]&lt;br /&gt;
&lt;br /&gt;
3. Enter debugging mode. &lt;br /&gt;
&lt;br /&gt;
'''Caveat''': the I/O register map in the debugger appears to use the last known device (ie: if you debugged an STM32F4 project before your Makefile project, it sticks with F4's registers). Check that the registers' addresses are correct before you trust them!&lt;br /&gt;
&lt;br /&gt;
== Schematic ==&lt;br /&gt;
[[File:CW308T_STM32F_02.png|1100px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: CW308 Targets]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-st-4.png&amp;diff=2438</id>
		<title>File:Stm32-st-4.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-st-4.png&amp;diff=2438"/>
				<updated>2017-04-26T17:17:07Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-st-3.png&amp;diff=2437</id>
		<title>File:Stm32-st-3.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-st-3.png&amp;diff=2437"/>
				<updated>2017-04-26T17:16:54Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-st-2.png&amp;diff=2436</id>
		<title>File:Stm32-st-2.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-st-2.png&amp;diff=2436"/>
				<updated>2017-04-26T17:16:43Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-st-1.png&amp;diff=2435</id>
		<title>File:Stm32-st-1.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-st-1.png&amp;diff=2435"/>
				<updated>2017-04-26T17:15:59Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2434</id>
		<title>CW308T-STM32F</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2434"/>
				<updated>2017-04-25T16:31:39Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Building and Debugging via ST's System Workbench */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox cw308target&lt;br /&gt;
|name                   = CW308T-STM32F&lt;br /&gt;
|image                  = cw308_stm32f.jpg&lt;br /&gt;
|caption                = &lt;br /&gt;
|Target Device          = ST STM32F&lt;br /&gt;
|Target Architecture    = Cortex M0,M3,M4&lt;br /&gt;
|Hardware Crypto        = Possible&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
|Design Files           = [https://github.com/newaetech/chipwhisperer/tree/master/hardware/victims/cw308_ufo_target/stm32f GITHub Link]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.newae.com/CW308T-STM32F OSH Park PCBs]&lt;br /&gt;
&lt;br /&gt;
|Supported Applications = [[SimpleSerial | Simple Serial Enc/Auth]]&lt;br /&gt;
|Programmer             = ST-LINK/V2&lt;br /&gt;
|Status                 = Released&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Supported Devices ==&lt;br /&gt;
&lt;br /&gt;
The STM32F board supports several STM32F devices in the TQFP-64 package. Various solder jumpers need to bet set to either the &amp;quot;A&amp;quot; or &amp;quot;B&amp;quot; position to select appropriate VCC supply for the different series. The following table summarizes examples of suitable devices:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!STM32F Series&lt;br /&gt;
!Package&lt;br /&gt;
!Device&lt;br /&gt;
!Hardware AES&lt;br /&gt;
!Tested&lt;br /&gt;
!Jumper&lt;br /&gt;
|-&lt;br /&gt;
|F0&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F071RBT6&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F1&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F100RBT6B&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F2&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F215RET6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F3&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F303R8T6&lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F415RGT6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F405RGT6&lt;br /&gt;
|No&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== VCC-Int Supply ===&lt;br /&gt;
Several devices (F2, F4) have internal core voltage regulators. By default the CW308 board attempts to provide power for these pins, but the voltage may not be high enough to cause the internal regulator to disable itself. In this case you can use the VADJ regulator to ensure the internal regulator is disabled. See [[Targets with Internal Regulators]] for details.&lt;br /&gt;
&lt;br /&gt;
=== Pin-outs across TQFP Devices ===&lt;br /&gt;
&lt;br /&gt;
The following shows differences in pinouts between three groups of devices. The left-most is the STM32F051RB, which uses the same 3.3V VCORE as the STM32F1/F3. It has fewer VCC pins, so the I/O occupying that are VCC/GND pins on the STM32F1 (such as PF6/PF7) are tied to GND/VCC. The right-most part is the pinout of the STM32F2/F4. It has an internal regulator, where the VCAP pins are the output of this regulator (and input to the internal core logic).&lt;br /&gt;
&lt;br /&gt;
[[File:power_diffstm32.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Note for the devices with a 3.3V VCORE, you should not mount decoupling capacitors C5/C6/C7/C8. You will still get some leakage with those capacitors mounted, but a stronger signal is present without them.&lt;br /&gt;
&lt;br /&gt;
== Hardware AES ==&lt;br /&gt;
&lt;br /&gt;
The STM32F21x, and STM32F41x/43x have hardware crypto modules (AES, DES, TDES) along with hardware hash (SHA1, MD5).&lt;br /&gt;
&lt;br /&gt;
== Programming Connection ==&lt;br /&gt;
&lt;br /&gt;
The 20-pin JTAG port (J6 on CW308 Board) can be used with the [https://www.digikey.com/product-detail/en/stmicroelectronics/ST-LINK-V2/497-10484-ND/2214535 ST-LINK/V2] which is a low-cost JTAG programmer. &lt;br /&gt;
&lt;br /&gt;
It is also possible to use other JTAG programmers such as OpenOCD. The following command worked with an Olimex OpenOCD programmer and their [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/ OpenOCD for Windows] software:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openocd &lt;br /&gt;
  -f path/to/board/files/cw308.cfg &lt;br /&gt;
  -c init &lt;br /&gt;
  -c targets &lt;br /&gt;
  -c &amp;quot;halt&amp;quot; &lt;br /&gt;
  -c &amp;quot;flash write_image erase path/to/firmware.hex&amp;quot;       &lt;br /&gt;
  -c &amp;quot;verify_image path/to/firmware.hex&amp;quot;        &lt;br /&gt;
  -c &amp;quot;reset run&amp;quot; &lt;br /&gt;
  -c shutdown&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the contents of &amp;lt;code&amp;gt;cw308.cfg&amp;lt;/code&amp;gt; are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source [find interface/olimex-arm-usb-ocd-h.cfg]&lt;br /&gt;
source [find target/stm32f4x.cfg]&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example Projects ==&lt;br /&gt;
&lt;br /&gt;
SimpleSerial builds for each of the STM32Fx Devices. Each device is a separate HAL. These HAL modules have been copied from ST's HAL (not the CUBE) and greatly reduced in size by deleting unused files (such as headers for unused devices), and combining several C-source files into a single low-level C-file.&lt;br /&gt;
&lt;br /&gt;
=== Building ST Example on Command Line ===&lt;br /&gt;
The regular firmware build process works with the STM32 devices. For example, to build `simpleserial-aes`, navigate to the folder `chipwhisperer\hardware\victims\firmware\simpleserial-aes` and run the following command on the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
make PLATFORM=CW308_STM32F0 CRYPTO_TARGET=TINYAES128C&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, this command will finish by printing the output file size and the platform:&lt;br /&gt;
[[File:Stm32-make.png]]&lt;br /&gt;
&lt;br /&gt;
=== Running ST Example with ST-Link ===&lt;br /&gt;
Once you've built a binary to load onto the target, you're ready to program it. Plug your programmer into the 20 pin JTAG connector (J6 on the UFO board):&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-jtag.jpg|600px]]&lt;br /&gt;
&lt;br /&gt;
Then, the details of this step will depend on your programmer. If you're using an ST-Link programmer, open the ST-Link utility and connect to the device:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-connect.png]]&lt;br /&gt;
&lt;br /&gt;
Load your `.hex` file and program the device with the Program and Verify button:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-program.png]]&lt;br /&gt;
&lt;br /&gt;
After this, you're ready to go - you can use the ChipWhisperer terminal to talk to your target. You might need to reset the target before you do anything else.&lt;br /&gt;
&lt;br /&gt;
=== Building and Debugging via ST's System Workbench ===&lt;br /&gt;
It's also possible to work on the example projects using [http://www.st.com/en/development-tools/sw4stm32.html ST's System Workbench IDE]. This IDE also supports debugging, which is helpful for working out all the kinks in your firmware.&lt;br /&gt;
&lt;br /&gt;
(TODO: details)&lt;br /&gt;
&lt;br /&gt;
== Schematic ==&lt;br /&gt;
[[File:CW308T_STM32F_02.png|1100px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: CW308 Targets]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2433</id>
		<title>CW308T-STM32F</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2433"/>
				<updated>2017-04-25T16:28:38Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Running ST Example with ST-Link */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox cw308target&lt;br /&gt;
|name                   = CW308T-STM32F&lt;br /&gt;
|image                  = cw308_stm32f.jpg&lt;br /&gt;
|caption                = &lt;br /&gt;
|Target Device          = ST STM32F&lt;br /&gt;
|Target Architecture    = Cortex M0,M3,M4&lt;br /&gt;
|Hardware Crypto        = Possible&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
|Design Files           = [https://github.com/newaetech/chipwhisperer/tree/master/hardware/victims/cw308_ufo_target/stm32f GITHub Link]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.newae.com/CW308T-STM32F OSH Park PCBs]&lt;br /&gt;
&lt;br /&gt;
|Supported Applications = [[SimpleSerial | Simple Serial Enc/Auth]]&lt;br /&gt;
|Programmer             = ST-LINK/V2&lt;br /&gt;
|Status                 = Released&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Supported Devices ==&lt;br /&gt;
&lt;br /&gt;
The STM32F board supports several STM32F devices in the TQFP-64 package. Various solder jumpers need to bet set to either the &amp;quot;A&amp;quot; or &amp;quot;B&amp;quot; position to select appropriate VCC supply for the different series. The following table summarizes examples of suitable devices:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!STM32F Series&lt;br /&gt;
!Package&lt;br /&gt;
!Device&lt;br /&gt;
!Hardware AES&lt;br /&gt;
!Tested&lt;br /&gt;
!Jumper&lt;br /&gt;
|-&lt;br /&gt;
|F0&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F071RBT6&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F1&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F100RBT6B&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F2&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F215RET6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F3&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F303R8T6&lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F415RGT6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F405RGT6&lt;br /&gt;
|No&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== VCC-Int Supply ===&lt;br /&gt;
Several devices (F2, F4) have internal core voltage regulators. By default the CW308 board attempts to provide power for these pins, but the voltage may not be high enough to cause the internal regulator to disable itself. In this case you can use the VADJ regulator to ensure the internal regulator is disabled. See [[Targets with Internal Regulators]] for details.&lt;br /&gt;
&lt;br /&gt;
=== Pin-outs across TQFP Devices ===&lt;br /&gt;
&lt;br /&gt;
The following shows differences in pinouts between three groups of devices. The left-most is the STM32F051RB, which uses the same 3.3V VCORE as the STM32F1/F3. It has fewer VCC pins, so the I/O occupying that are VCC/GND pins on the STM32F1 (such as PF6/PF7) are tied to GND/VCC. The right-most part is the pinout of the STM32F2/F4. It has an internal regulator, where the VCAP pins are the output of this regulator (and input to the internal core logic).&lt;br /&gt;
&lt;br /&gt;
[[File:power_diffstm32.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Note for the devices with a 3.3V VCORE, you should not mount decoupling capacitors C5/C6/C7/C8. You will still get some leakage with those capacitors mounted, but a stronger signal is present without them.&lt;br /&gt;
&lt;br /&gt;
== Hardware AES ==&lt;br /&gt;
&lt;br /&gt;
The STM32F21x, and STM32F41x/43x have hardware crypto modules (AES, DES, TDES) along with hardware hash (SHA1, MD5).&lt;br /&gt;
&lt;br /&gt;
== Programming Connection ==&lt;br /&gt;
&lt;br /&gt;
The 20-pin JTAG port (J6 on CW308 Board) can be used with the [https://www.digikey.com/product-detail/en/stmicroelectronics/ST-LINK-V2/497-10484-ND/2214535 ST-LINK/V2] which is a low-cost JTAG programmer. &lt;br /&gt;
&lt;br /&gt;
It is also possible to use other JTAG programmers such as OpenOCD. The following command worked with an Olimex OpenOCD programmer and their [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/ OpenOCD for Windows] software:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openocd &lt;br /&gt;
  -f path/to/board/files/cw308.cfg &lt;br /&gt;
  -c init &lt;br /&gt;
  -c targets &lt;br /&gt;
  -c &amp;quot;halt&amp;quot; &lt;br /&gt;
  -c &amp;quot;flash write_image erase path/to/firmware.hex&amp;quot;       &lt;br /&gt;
  -c &amp;quot;verify_image path/to/firmware.hex&amp;quot;        &lt;br /&gt;
  -c &amp;quot;reset run&amp;quot; &lt;br /&gt;
  -c shutdown&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the contents of &amp;lt;code&amp;gt;cw308.cfg&amp;lt;/code&amp;gt; are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source [find interface/olimex-arm-usb-ocd-h.cfg]&lt;br /&gt;
source [find target/stm32f4x.cfg]&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example Projects ==&lt;br /&gt;
&lt;br /&gt;
SimpleSerial builds for each of the STM32Fx Devices. Each device is a separate HAL. These HAL modules have been copied from ST's HAL (not the CUBE) and greatly reduced in size by deleting unused files (such as headers for unused devices), and combining several C-source files into a single low-level C-file.&lt;br /&gt;
&lt;br /&gt;
=== Building ST Example on Command Line ===&lt;br /&gt;
The regular firmware build process works with the STM32 devices. For example, to build `simpleserial-aes`, navigate to the folder `chipwhisperer\hardware\victims\firmware\simpleserial-aes` and run the following command on the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
make PLATFORM=CW308_STM32F0 CRYPTO_TARGET=TINYAES128C&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, this command will finish by printing the output file size and the platform:&lt;br /&gt;
[[File:Stm32-make.png]]&lt;br /&gt;
&lt;br /&gt;
=== Running ST Example with ST-Link ===&lt;br /&gt;
Once you've built a binary to load onto the target, you're ready to program it. Plug your programmer into the 20 pin JTAG connector (J6 on the UFO board):&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-jtag.jpg|600px]]&lt;br /&gt;
&lt;br /&gt;
Then, the details of this step will depend on your programmer. If you're using an ST-Link programmer, open the ST-Link utility and connect to the device:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-connect.png]]&lt;br /&gt;
&lt;br /&gt;
Load your `.hex` file and program the device with the Program and Verify button:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-program.png]]&lt;br /&gt;
&lt;br /&gt;
After this, you're ready to go - you can use the ChipWhisperer terminal to talk to your target. You might need to reset the target before you do anything else.&lt;br /&gt;
&lt;br /&gt;
=== Building and Debugging via ST's System Workbench ===&lt;br /&gt;
&lt;br /&gt;
== Schematic ==&lt;br /&gt;
[[File:CW308T_STM32F_02.png|1100px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: CW308 Targets]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2432</id>
		<title>CW308T-STM32F</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2432"/>
				<updated>2017-04-25T16:27:57Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Running ST Example with ST-Link */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox cw308target&lt;br /&gt;
|name                   = CW308T-STM32F&lt;br /&gt;
|image                  = cw308_stm32f.jpg&lt;br /&gt;
|caption                = &lt;br /&gt;
|Target Device          = ST STM32F&lt;br /&gt;
|Target Architecture    = Cortex M0,M3,M4&lt;br /&gt;
|Hardware Crypto        = Possible&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
|Design Files           = [https://github.com/newaetech/chipwhisperer/tree/master/hardware/victims/cw308_ufo_target/stm32f GITHub Link]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.newae.com/CW308T-STM32F OSH Park PCBs]&lt;br /&gt;
&lt;br /&gt;
|Supported Applications = [[SimpleSerial | Simple Serial Enc/Auth]]&lt;br /&gt;
|Programmer             = ST-LINK/V2&lt;br /&gt;
|Status                 = Released&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Supported Devices ==&lt;br /&gt;
&lt;br /&gt;
The STM32F board supports several STM32F devices in the TQFP-64 package. Various solder jumpers need to bet set to either the &amp;quot;A&amp;quot; or &amp;quot;B&amp;quot; position to select appropriate VCC supply for the different series. The following table summarizes examples of suitable devices:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!STM32F Series&lt;br /&gt;
!Package&lt;br /&gt;
!Device&lt;br /&gt;
!Hardware AES&lt;br /&gt;
!Tested&lt;br /&gt;
!Jumper&lt;br /&gt;
|-&lt;br /&gt;
|F0&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F071RBT6&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F1&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F100RBT6B&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F2&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F215RET6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F3&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F303R8T6&lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F415RGT6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F405RGT6&lt;br /&gt;
|No&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== VCC-Int Supply ===&lt;br /&gt;
Several devices (F2, F4) have internal core voltage regulators. By default the CW308 board attempts to provide power for these pins, but the voltage may not be high enough to cause the internal regulator to disable itself. In this case you can use the VADJ regulator to ensure the internal regulator is disabled. See [[Targets with Internal Regulators]] for details.&lt;br /&gt;
&lt;br /&gt;
=== Pin-outs across TQFP Devices ===&lt;br /&gt;
&lt;br /&gt;
The following shows differences in pinouts between three groups of devices. The left-most is the STM32F051RB, which uses the same 3.3V VCORE as the STM32F1/F3. It has fewer VCC pins, so the I/O occupying that are VCC/GND pins on the STM32F1 (such as PF6/PF7) are tied to GND/VCC. The right-most part is the pinout of the STM32F2/F4. It has an internal regulator, where the VCAP pins are the output of this regulator (and input to the internal core logic).&lt;br /&gt;
&lt;br /&gt;
[[File:power_diffstm32.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Note for the devices with a 3.3V VCORE, you should not mount decoupling capacitors C5/C6/C7/C8. You will still get some leakage with those capacitors mounted, but a stronger signal is present without them.&lt;br /&gt;
&lt;br /&gt;
== Hardware AES ==&lt;br /&gt;
&lt;br /&gt;
The STM32F21x, and STM32F41x/43x have hardware crypto modules (AES, DES, TDES) along with hardware hash (SHA1, MD5).&lt;br /&gt;
&lt;br /&gt;
== Programming Connection ==&lt;br /&gt;
&lt;br /&gt;
The 20-pin JTAG port (J6 on CW308 Board) can be used with the [https://www.digikey.com/product-detail/en/stmicroelectronics/ST-LINK-V2/497-10484-ND/2214535 ST-LINK/V2] which is a low-cost JTAG programmer. &lt;br /&gt;
&lt;br /&gt;
It is also possible to use other JTAG programmers such as OpenOCD. The following command worked with an Olimex OpenOCD programmer and their [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/ OpenOCD for Windows] software:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openocd &lt;br /&gt;
  -f path/to/board/files/cw308.cfg &lt;br /&gt;
  -c init &lt;br /&gt;
  -c targets &lt;br /&gt;
  -c &amp;quot;halt&amp;quot; &lt;br /&gt;
  -c &amp;quot;flash write_image erase path/to/firmware.hex&amp;quot;       &lt;br /&gt;
  -c &amp;quot;verify_image path/to/firmware.hex&amp;quot;        &lt;br /&gt;
  -c &amp;quot;reset run&amp;quot; &lt;br /&gt;
  -c shutdown&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the contents of &amp;lt;code&amp;gt;cw308.cfg&amp;lt;/code&amp;gt; are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source [find interface/olimex-arm-usb-ocd-h.cfg]&lt;br /&gt;
source [find target/stm32f4x.cfg]&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example Projects ==&lt;br /&gt;
&lt;br /&gt;
SimpleSerial builds for each of the STM32Fx Devices. Each device is a separate HAL. These HAL modules have been copied from ST's HAL (not the CUBE) and greatly reduced in size by deleting unused files (such as headers for unused devices), and combining several C-source files into a single low-level C-file.&lt;br /&gt;
&lt;br /&gt;
=== Building ST Example on Command Line ===&lt;br /&gt;
The regular firmware build process works with the STM32 devices. For example, to build `simpleserial-aes`, navigate to the folder `chipwhisperer\hardware\victims\firmware\simpleserial-aes` and run the following command on the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
make PLATFORM=CW308_STM32F0 CRYPTO_TARGET=TINYAES128C&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, this command will finish by printing the output file size and the platform:&lt;br /&gt;
[[File:Stm32-make.png]]&lt;br /&gt;
&lt;br /&gt;
=== Running ST Example with ST-Link ===&lt;br /&gt;
Once you've built a binary to load onto the target, you're ready to program it. Plug your programmer into the 20 pin JTAG connector (J6 on the UFO board):&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-jtag.jpg]]&lt;br /&gt;
&lt;br /&gt;
Then, the details of this step will depend on your programmer. If you're using an ST-Link programmer, open the ST-Link utility and connect to the device:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-connect.png]]&lt;br /&gt;
&lt;br /&gt;
Load your `.hex` file and program the device with the Program and Verify button:&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32-program.png]]&lt;br /&gt;
&lt;br /&gt;
After this, you're ready to go - you can use the ChipWhisperer terminal to talk to your target. You might need to reset the target before you do anything else.&lt;br /&gt;
&lt;br /&gt;
=== Building and Debugging via ST's System Workbench ===&lt;br /&gt;
&lt;br /&gt;
== Schematic ==&lt;br /&gt;
[[File:CW308T_STM32F_02.png|1100px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: CW308 Targets]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-jtag.jpg&amp;diff=2431</id>
		<title>File:Stm32-jtag.jpg</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-jtag.jpg&amp;diff=2431"/>
				<updated>2017-04-25T16:27:29Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2430</id>
		<title>CW308T-STM32F</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2430"/>
				<updated>2017-04-25T16:25:26Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Example Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox cw308target&lt;br /&gt;
|name                   = CW308T-STM32F&lt;br /&gt;
|image                  = cw308_stm32f.jpg&lt;br /&gt;
|caption                = &lt;br /&gt;
|Target Device          = ST STM32F&lt;br /&gt;
|Target Architecture    = Cortex M0,M3,M4&lt;br /&gt;
|Hardware Crypto        = Possible&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
|Design Files           = [https://github.com/newaetech/chipwhisperer/tree/master/hardware/victims/cw308_ufo_target/stm32f GITHub Link]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.newae.com/CW308T-STM32F OSH Park PCBs]&lt;br /&gt;
&lt;br /&gt;
|Supported Applications = [[SimpleSerial | Simple Serial Enc/Auth]]&lt;br /&gt;
|Programmer             = ST-LINK/V2&lt;br /&gt;
|Status                 = Released&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Supported Devices ==&lt;br /&gt;
&lt;br /&gt;
The STM32F board supports several STM32F devices in the TQFP-64 package. Various solder jumpers need to bet set to either the &amp;quot;A&amp;quot; or &amp;quot;B&amp;quot; position to select appropriate VCC supply for the different series. The following table summarizes examples of suitable devices:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!STM32F Series&lt;br /&gt;
!Package&lt;br /&gt;
!Device&lt;br /&gt;
!Hardware AES&lt;br /&gt;
!Tested&lt;br /&gt;
!Jumper&lt;br /&gt;
|-&lt;br /&gt;
|F0&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F071RBT6&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F1&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F100RBT6B&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F2&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F215RET6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F3&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F303R8T6&lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F415RGT6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F405RGT6&lt;br /&gt;
|No&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== VCC-Int Supply ===&lt;br /&gt;
Several devices (F2, F4) have internal core voltage regulators. By default the CW308 board attempts to provide power for these pins, but the voltage may not be high enough to cause the internal regulator to disable itself. In this case you can use the VADJ regulator to ensure the internal regulator is disabled. See [[Targets with Internal Regulators]] for details.&lt;br /&gt;
&lt;br /&gt;
=== Pin-outs across TQFP Devices ===&lt;br /&gt;
&lt;br /&gt;
The following shows differences in pinouts between three groups of devices. The left-most is the STM32F051RB, which uses the same 3.3V VCORE as the STM32F1/F3. It has fewer VCC pins, so the I/O occupying that are VCC/GND pins on the STM32F1 (such as PF6/PF7) are tied to GND/VCC. The right-most part is the pinout of the STM32F2/F4. It has an internal regulator, where the VCAP pins are the output of this regulator (and input to the internal core logic).&lt;br /&gt;
&lt;br /&gt;
[[File:power_diffstm32.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Note for the devices with a 3.3V VCORE, you should not mount decoupling capacitors C5/C6/C7/C8. You will still get some leakage with those capacitors mounted, but a stronger signal is present without them.&lt;br /&gt;
&lt;br /&gt;
== Hardware AES ==&lt;br /&gt;
&lt;br /&gt;
The STM32F21x, and STM32F41x/43x have hardware crypto modules (AES, DES, TDES) along with hardware hash (SHA1, MD5).&lt;br /&gt;
&lt;br /&gt;
== Programming Connection ==&lt;br /&gt;
&lt;br /&gt;
The 20-pin JTAG port (J6 on CW308 Board) can be used with the [https://www.digikey.com/product-detail/en/stmicroelectronics/ST-LINK-V2/497-10484-ND/2214535 ST-LINK/V2] which is a low-cost JTAG programmer. &lt;br /&gt;
&lt;br /&gt;
It is also possible to use other JTAG programmers such as OpenOCD. The following command worked with an Olimex OpenOCD programmer and their [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/ OpenOCD for Windows] software:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openocd &lt;br /&gt;
  -f path/to/board/files/cw308.cfg &lt;br /&gt;
  -c init &lt;br /&gt;
  -c targets &lt;br /&gt;
  -c &amp;quot;halt&amp;quot; &lt;br /&gt;
  -c &amp;quot;flash write_image erase path/to/firmware.hex&amp;quot;       &lt;br /&gt;
  -c &amp;quot;verify_image path/to/firmware.hex&amp;quot;        &lt;br /&gt;
  -c &amp;quot;reset run&amp;quot; &lt;br /&gt;
  -c shutdown&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the contents of &amp;lt;code&amp;gt;cw308.cfg&amp;lt;/code&amp;gt; are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source [find interface/olimex-arm-usb-ocd-h.cfg]&lt;br /&gt;
source [find target/stm32f4x.cfg]&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example Projects ==&lt;br /&gt;
&lt;br /&gt;
SimpleSerial builds for each of the STM32Fx Devices. Each device is a separate HAL. These HAL modules have been copied from ST's HAL (not the CUBE) and greatly reduced in size by deleting unused files (such as headers for unused devices), and combining several C-source files into a single low-level C-file.&lt;br /&gt;
&lt;br /&gt;
=== Building ST Example on Command Line ===&lt;br /&gt;
The regular firmware build process works with the STM32 devices. For example, to build `simpleserial-aes`, navigate to the folder `chipwhisperer\hardware\victims\firmware\simpleserial-aes` and run the following command on the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
make PLATFORM=CW308_STM32F0 CRYPTO_TARGET=TINYAES128C&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, this command will finish by printing the output file size and the platform:&lt;br /&gt;
[[File:Stm32-make.png]]&lt;br /&gt;
&lt;br /&gt;
=== Running ST Example with ST-Link ===&lt;br /&gt;
Once you've built a binary to load onto the target, you're ready to program it. Plug your programmer into the 20 pin JTAG connector (J6 on the UFO board):&lt;br /&gt;
[[File:]]&lt;br /&gt;
&lt;br /&gt;
Then, the details of this step will depend on your programmer. If you're using an ST-Link programmer, open the ST-Link utility and connect to the device:&lt;br /&gt;
[[File:Stm32-connect.png]]&lt;br /&gt;
&lt;br /&gt;
Load your `.hex` file and program the device with the Program and Verify button:&lt;br /&gt;
[[File:Stm32-program.png]]&lt;br /&gt;
&lt;br /&gt;
After this, you're ready to go - you can use the ChipWhisperer terminal to talk to your target. You might need to reset the target before you do anything else.&lt;br /&gt;
&lt;br /&gt;
=== Building and Debugging via ST's System Workbench ===&lt;br /&gt;
&lt;br /&gt;
== Schematic ==&lt;br /&gt;
[[File:CW308T_STM32F_02.png|1100px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: CW308 Targets]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-program.png&amp;diff=2428</id>
		<title>File:Stm32-program.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-program.png&amp;diff=2428"/>
				<updated>2017-04-25T16:23:38Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-connect.png&amp;diff=2427</id>
		<title>File:Stm32-connect.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-connect.png&amp;diff=2427"/>
				<updated>2017-04-25T16:21:42Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2423</id>
		<title>CW308T-STM32F</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2423"/>
				<updated>2017-04-25T15:14:46Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Example Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox cw308target&lt;br /&gt;
|name                   = CW308T-STM32F&lt;br /&gt;
|image                  = cw308_stm32f.jpg&lt;br /&gt;
|caption                = &lt;br /&gt;
|Target Device          = ST STM32F&lt;br /&gt;
|Target Architecture    = Cortex M0,M3,M4&lt;br /&gt;
|Hardware Crypto        = Possible&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
|Design Files           = [https://github.com/newaetech/chipwhisperer/tree/master/hardware/victims/cw308_ufo_target/stm32f GITHub Link]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.newae.com/CW308T-STM32F OSH Park PCBs]&lt;br /&gt;
&lt;br /&gt;
|Supported Applications = [[SimpleSerial | Simple Serial Enc/Auth]]&lt;br /&gt;
|Programmer             = ST-LINK/V2&lt;br /&gt;
|Status                 = Released&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Supported Devices ==&lt;br /&gt;
&lt;br /&gt;
The STM32F board supports several STM32F devices in the TQFP-64 package. Various solder jumpers need to bet set to either the &amp;quot;A&amp;quot; or &amp;quot;B&amp;quot; position to select appropriate VCC supply for the different series. The following table summarizes examples of suitable devices:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!STM32F Series&lt;br /&gt;
!Package&lt;br /&gt;
!Device&lt;br /&gt;
!Hardware AES&lt;br /&gt;
!Tested&lt;br /&gt;
!Jumper&lt;br /&gt;
|-&lt;br /&gt;
|F0&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F071RBT6&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F1&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F100RBT6B&lt;br /&gt;
|No&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F2&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F215RET6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F3&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F303R8T6&lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F415RGT6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F405RGT6&lt;br /&gt;
|No&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== VCC-Int Supply ===&lt;br /&gt;
Several devices (F2, F4) have internal core voltage regulators. By default the CW308 board attempts to provide power for these pins, but the voltage may not be high enough to cause the internal regulator to disable itself. In this case you can use the VADJ regulator to ensure the internal regulator is disabled. See [[Targets with Internal Regulators]] for details.&lt;br /&gt;
&lt;br /&gt;
=== Pin-outs across TQFP Devices ===&lt;br /&gt;
&lt;br /&gt;
The following shows differences in pinouts between three groups of devices. The left-most is the STM32F051RB, which uses the same 3.3V VCORE as the STM32F1/F3. It has fewer VCC pins, so the I/O occupying that are VCC/GND pins on the STM32F1 (such as PF6/PF7) are tied to GND/VCC. The right-most part is the pinout of the STM32F2/F4. It has an internal regulator, where the VCAP pins are the output of this regulator (and input to the internal core logic).&lt;br /&gt;
&lt;br /&gt;
[[File:power_diffstm32.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Note for the devices with a 3.3V VCORE, you should not mount decoupling capacitors C5/C6/C7/C8. You will still get some leakage with those capacitors mounted, but a stronger signal is present without them.&lt;br /&gt;
&lt;br /&gt;
== Hardware AES ==&lt;br /&gt;
&lt;br /&gt;
The STM32F21x, and STM32F41x/43x have hardware crypto modules (AES, DES, TDES) along with hardware hash (SHA1, MD5).&lt;br /&gt;
&lt;br /&gt;
== Programming Connection ==&lt;br /&gt;
&lt;br /&gt;
The 20-pin JTAG port (J6 on CW308 Board) can be used with the [https://www.digikey.com/product-detail/en/stmicroelectronics/ST-LINK-V2/497-10484-ND/2214535 ST-LINK/V2] which is a low-cost JTAG programmer. &lt;br /&gt;
&lt;br /&gt;
It is also possible to use other JTAG programmers such as OpenOCD. The following command worked with an Olimex OpenOCD programmer and their [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/ OpenOCD for Windows] software:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openocd &lt;br /&gt;
  -f path/to/board/files/cw308.cfg &lt;br /&gt;
  -c init &lt;br /&gt;
  -c targets &lt;br /&gt;
  -c &amp;quot;halt&amp;quot; &lt;br /&gt;
  -c &amp;quot;flash write_image erase path/to/firmware.hex&amp;quot;       &lt;br /&gt;
  -c &amp;quot;verify_image path/to/firmware.hex&amp;quot;        &lt;br /&gt;
  -c &amp;quot;reset run&amp;quot; &lt;br /&gt;
  -c shutdown&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the contents of &amp;lt;code&amp;gt;cw308.cfg&amp;lt;/code&amp;gt; are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source [find interface/olimex-arm-usb-ocd-h.cfg]&lt;br /&gt;
source [find target/stm32f4x.cfg]&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example Projects ==&lt;br /&gt;
&lt;br /&gt;
SimpleSerial builds for each of the STM32Fx Devices. Each device is a separate HAL. These HAL modules have been copied from ST's HAL (not the CUBE) and greatly reduced in size by deleting unused files (such as headers for unused devices), and combining several C-source files into a single low-level C-file.&lt;br /&gt;
&lt;br /&gt;
=== Building ST Example on Command Line ===&lt;br /&gt;
The regular firmware build process works with the STM32 devices. For example, to build `simpleserial-aes`, navigate to the folder `chipwhisperer\hardware\victims\firmware\simpleserial-aes` and run the following command on the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
make PLATFORM=CW308_STM32F0 CRYPTO_TARGET=TINYAES128C&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, this command will finish by printing the output file size and the platform:&lt;br /&gt;
[[File:Stm32-make.png]]&lt;br /&gt;
&lt;br /&gt;
=== Building ST Example via GUI ===&lt;br /&gt;
&lt;br /&gt;
=== Running ST Example ===&lt;br /&gt;
&lt;br /&gt;
== Schematic ==&lt;br /&gt;
[[File:CW308T_STM32F_02.png|1100px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: CW308 Targets]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=File:Stm32-make.png&amp;diff=2422</id>
		<title>File:Stm32-make.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=File:Stm32-make.png&amp;diff=2422"/>
				<updated>2017-04-25T15:13:42Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2421</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2421"/>
				<updated>2017-04-25T14:54:03Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h00\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|Set encryption key; possibly trigger key scheduling&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m00\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v\n&lt;br /&gt;
|Check protocol version (no reply on v1.0; ACK on v1.1)&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|x\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z00\n&lt;br /&gt;
|ACK - Command processing done (with optional status code)&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to 2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to 2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2414</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2414"/>
				<updated>2017-04-21T15:04:17Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Authentication Application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h00\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|Set encryption key; possibly trigger key scheduling&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m00\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v01\n&lt;br /&gt;
|Select protocol version (00 = original, 01 = 1.1)&lt;br /&gt;
|In&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|xxxxx\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z00\n&lt;br /&gt;
|ACK - Command processing done (with optional status code)&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to 2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to 2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2411</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2411"/>
				<updated>2017-04-20T15:27:53Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Encryption Application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h00\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|Set encryption key; possibly trigger key scheduling&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m00\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v01\n&lt;br /&gt;
|Select protocol version (00 = original, 01 = 1.1)&lt;br /&gt;
|In&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|xxxxx\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z00\n&lt;br /&gt;
|ACK - Command processing done (with optional status code)&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to 2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2410</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2410"/>
				<updated>2017-04-20T14:47:59Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h00\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|Set encryption key; possibly trigger key scheduling&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m00\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v01\n&lt;br /&gt;
|Select protocol version (00 = original, 01 = 1.1)&lt;br /&gt;
|In&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|xxxxx\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z00\n&lt;br /&gt;
|ACK - Command processing done (with optional status code)&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2409</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2409"/>
				<updated>2017-04-20T14:47:10Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h00\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m00\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v01\n&lt;br /&gt;
|Select protocol version (00 = original, 01 = 1.1)&lt;br /&gt;
|In&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|xxxxx\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z00\n&lt;br /&gt;
|ACK - Command processing done (with optional status code)&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2408</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2408"/>
				<updated>2017-04-20T14:43:53Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h00\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m00\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v01\n&lt;br /&gt;
|Select protocol version (00 = original, 01 = 1.1)&lt;br /&gt;
|In&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|xxxxx\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z\n&lt;br /&gt;
|ACK - Command processing done&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2407</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2407"/>
				<updated>2017-04-20T14:39:00Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h0\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m0\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v01\n&lt;br /&gt;
|Select protocol version (00 = original, 01 = 1.1)&lt;br /&gt;
|In&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|xxxxx\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z\n&lt;br /&gt;
|ACK - Command processing done&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW508_SMA_Analog_Filters&amp;diff=2406</id>
		<title>CW508 SMA Analog Filters</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW508_SMA_Analog_Filters&amp;diff=2406"/>
				<updated>2017-04-20T14:11:39Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The CW508 Analog Filters provide an easily method of filtering out noise at both low and high frequency. These two filters serve different purposes:&lt;br /&gt;
* The high pass filter helps filter out low frequency noise. A common cause of this is switch-mode power supplies, which typically operate at 50 - 500 kHz. &lt;br /&gt;
* The low pass filter helps remove short spikes from the traces. For example, if other peripherals are running on the target, a LPF might help remove their effects from the traces. This is especially helpful for fast hardware crypto with the slow, synchronous captures on the ChipWhisperer. It can be difficult to fix the traces afterwards with a digital filter, so it is much more helpful to use a hardware filter instead.&lt;br /&gt;
&lt;br /&gt;
These filters can simply be screwed onto the front of the ChipWhisperer capture device:&lt;br /&gt;
&lt;br /&gt;
[[File:cw508_cwpro.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
== HPF 500 KHz Response ==&lt;br /&gt;
&lt;br /&gt;
[[File:500khzhpf_50khz_5mhz.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[File:500khzhpf_50khz_100mhz.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== LPF 20 MHz Response ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:20mhzlpf_100khz_100mhz.png|800px]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2399</id>
		<title>SimpleSerial</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=SimpleSerial&amp;diff=2399"/>
				<updated>2017-04-18T18:17:22Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SimpleSerial is the name given to the default communication protocol used by NewAE Technology Inc.'s demos.&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Command&lt;br /&gt;
!Example&lt;br /&gt;
!Description&lt;br /&gt;
!In/Out&lt;br /&gt;
!ENC&lt;br /&gt;
!AUTH&lt;br /&gt;
|-&lt;br /&gt;
|h&lt;br /&gt;
|h0\n&lt;br /&gt;
|Select stack / hardware to use (if supported).&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|k&lt;br /&gt;
|k2b7e151628aed2a6abf7158809cf4f3c\n&lt;br /&gt;
|&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|m&lt;br /&gt;
|m0\n&lt;br /&gt;
|Select cipher mode (if supported)&lt;br /&gt;
|In&lt;br /&gt;
|M&lt;br /&gt;
|M&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|p126110475e17505a6966be70c89a829c\n&lt;br /&gt;
|Send input plain-text, cause encryption&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|r&lt;br /&gt;
|r10000000000000000000000000000000\n&lt;br /&gt;
|Result of function - if encryption is encrypted result, if auth is '0..0' or '100..0'.&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|t&lt;br /&gt;
|t640a4a78332a8dee2bce15132ec44027\n&lt;br /&gt;
|Authentication challenge (i.e., expected AES result if using AES as auth-method)&lt;br /&gt;
|In&lt;br /&gt;
|N&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|v&lt;br /&gt;
|v\n&lt;br /&gt;
|Select protocol version (0 = original, 1 = 1.1)&lt;br /&gt;
|In&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|x&lt;br /&gt;
|xxxxx\n&lt;br /&gt;
|Clears Buffers (resets to 'IDLE' state), does not clear any variables.&lt;br /&gt;
|In&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|z&lt;br /&gt;
|z\n&lt;br /&gt;
|ACK - Command processing done&lt;br /&gt;
|Out&lt;br /&gt;
|Y&lt;br /&gt;
|Y&lt;br /&gt;
|}&lt;br /&gt;
Y = YES, Command support for application.&lt;br /&gt;
&lt;br /&gt;
N = NO, Command not supported for application.&lt;br /&gt;
&lt;br /&gt;
M = MAYBE, Command may be supported depending on build target.&lt;br /&gt;
&lt;br /&gt;
== Encryption Application ==&lt;br /&gt;
The encryption application provides a simple method to encrypt a plaintext into a ciphertext. This application was the original &amp;quot;simple serial&amp;quot;. The following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# The ciphertext is returned with the 'r' command.&lt;br /&gt;
&lt;br /&gt;
== Authentication Application ==&lt;br /&gt;
The authentication application does not expose the result of the encryption. Instead, the result is used only in authentication mode, where the following operations are performed:&lt;br /&gt;
# Load encryption key with 'k' command (for example, k2b7e151628aed2a6abf7158809cf4f3c\n sets key to k2b7e151628aed2a6abf7158809cf4f3c).&lt;br /&gt;
# Set the authentication challenge with 't' command.&lt;br /&gt;
# Set input text to encryption module with 'p' command. Device encrypts input text, and toggles the I/O trigger line during the encryption operation.&lt;br /&gt;
# Device compares the resulting ciphertext with the challenge set with 't'.&lt;br /&gt;
# If challenge and ciphertext match (auth OK), device responds with 'r1000000000000000\n'. If do not match, device response with 'r0000000000000000\n'.&lt;br /&gt;
The authentication application is the '''default shipped with ALL programmed modules'''.&lt;br /&gt;
&lt;br /&gt;
[[Category: Victim Firmware]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2378</id>
		<title>CW308T-STM32F</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=CW308T-STM32F&amp;diff=2378"/>
				<updated>2017-04-10T19:53:02Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: /* Programming Connection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox cw308target&lt;br /&gt;
|name                   = CW308T-STM32F&lt;br /&gt;
|image                  = &lt;br /&gt;
|caption                = &lt;br /&gt;
|Target Device          = ST STM32F&lt;br /&gt;
|Target Architecture    = Cortex M0,M3,M4&lt;br /&gt;
|Hardware Crypto        = Possible&lt;br /&gt;
|Purchase Hardware      = &lt;br /&gt;
|Design Files           = [https://github.com/newaetech/chipwhisperer/tree/master/hardware/victims/cw308_ufo_target/stm32f GITHub Link]&lt;br /&gt;
&lt;br /&gt;
|Supported Applications = [[SimpleSerial | Simple Serial Enc/Auth]]&lt;br /&gt;
|Programmer             = ST-LINK/V2&lt;br /&gt;
|Status                 = Released&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Supported Devices ==&lt;br /&gt;
&lt;br /&gt;
The STM32F board supports several STM32F devices in the TQFP-64 package. Various solder jumpers need to bet set to either the &amp;quot;A&amp;quot; or &amp;quot;B&amp;quot; position to select appropriate VCC supply for the different series. The following table summarizes examples of suitable devices:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!STM32F Series&lt;br /&gt;
!Package&lt;br /&gt;
!Device&lt;br /&gt;
!Hardware AES&lt;br /&gt;
!Tested&lt;br /&gt;
!Jumper&lt;br /&gt;
|-&lt;br /&gt;
|F0&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F1&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F2&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|F3&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|F4&lt;br /&gt;
|TQFP-64&lt;br /&gt;
|STM32F415RGT6&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== VCC-Int Supply ===&lt;br /&gt;
Several devices (F2, F4) have internal core voltage regulators. By default the CW308 board attempts to provide power for these pins, but the voltage may not be high enough to cause the internal regulator to disable itself. In this case you can use the VADJ regulator to ensure the internal regulator is disabled. See [[Targets with Internal Regulators]] for details.&lt;br /&gt;
&lt;br /&gt;
== Hardware AES ==&lt;br /&gt;
&lt;br /&gt;
The STM32F21x, and STM32F41x/43x have hardware crypto modules (AES, DES, TDES) along with hardware hash (SHA1, MD5).&lt;br /&gt;
&lt;br /&gt;
== Programming Connection ==&lt;br /&gt;
&lt;br /&gt;
The 20-pin JTAG port (J6 on CW308 Board) can be used with the [https://www.digikey.com/product-detail/en/stmicroelectronics/ST-LINK-V2/497-10484-ND/2214535 ST-LINK/V2] which is a low-cost JTAG programmer. &lt;br /&gt;
&lt;br /&gt;
It is also possible to use other JTAG programmers such as OpenOCD. The following command worked with an Olimex OpenOCD programmer and their [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/ OpenOCD for Windows] software:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openocd &lt;br /&gt;
  -f path/to/board/files/cw308.cfg &lt;br /&gt;
  -c init &lt;br /&gt;
  -c targets &lt;br /&gt;
  -c &amp;quot;halt&amp;quot; &lt;br /&gt;
  -c &amp;quot;flash write_image erase path/to/firmware.hex&amp;quot;       &lt;br /&gt;
  -c &amp;quot;verify_image path/to/firmware.hex&amp;quot;        &lt;br /&gt;
  -c &amp;quot;reset run&amp;quot; &lt;br /&gt;
  -c shutdown&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the contents of &amp;lt;code&amp;gt;cw308.cfg&amp;lt;/code&amp;gt; are&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source [find interface/olimex-arm-usb-ocd-h.cfg]&lt;br /&gt;
source [find target/stm32f4x.cfg]&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Schematic ==&lt;br /&gt;
[[File:CW308T_STM32F_02.png|1100px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: CW308 Targets]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	<entry>
		<id>http://wiki.newae.com/index.php?title=Downsampling&amp;diff=2354</id>
		<title>Downsampling</title>
		<link rel="alternate" type="text/html" href="http://wiki.newae.com/index.php?title=Downsampling&amp;diff=2354"/>
				<updated>2017-04-07T16:36:45Z</updated>
		
		<summary type="html">&lt;p&gt;Gdeon: Created page with &amp;quot;The ChipWhisperer's downsampling factor allows the ADC to discard a number of samples. For example, with a downsampling factor of 4, only every 4th sample is kept - the other...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The ChipWhisperer's downsampling factor allows the ADC to discard a number of samples. For example, with a downsampling factor of 4, only every 4th sample is kept - the other 3 are thrown out before the trace is sent back to the computer. This feature has several uses:&lt;br /&gt;
* On the ChipWhisperer Lite, space is very limited - the maximum sample count of 24400 can make it difficult to find interesting features in traces or capture longer operations like ECC. Using downsampling can make it easier to find interesting features in these traces.&lt;br /&gt;
* On the ChipWhisperer Pro, the sampling rate in streaming mode is limited by the USB connection's data rate: the maximum sampling rate is approximately 10 MS/s. Using downsampling can make it easier to fit under this limit. &lt;br /&gt;
For all of these use cases, make sure you're already running the ADC clock slowly if possible. Don't use a 4x faster ADC just to throw out 3/4 of the samples!&lt;br /&gt;
&lt;br /&gt;
Caution: be careful using the ChipWhisperer Pro's SAD trigger! The discarded ADC samples are still used as input for the SAD trigger module. If your reference trace was captured using downsampling, then the ChipWhisperer will never find this downsampled pattern in the raw samples.&lt;br /&gt;
&lt;br /&gt;
[[Category:Tips]]&lt;/div&gt;</summary>
		<author><name>Gdeon</name></author>	</entry>

	</feed>