ATmega644 Smart-Card
|
This repository contains an 128-bit AES decryption algorithm, that runs on a Smart-Card with an AVR ATmega644 microcontroller on it. The code was implemented in the scope of a "Smart-Card Laboratory" at the Technical University of Munich, with the purpose to decrypt chunks of a video stream while communicating with a Smart-Card reader or Terminal. The communication between the Smart-Card an the Terminal occurs over the Smart-Card's ISO7816 I/O contact and follows the T=0 protocol specified in ISO7816. This markdown page provides some information on build configurations & gives an overview of the code.
The code for the clone consists of these main classes:
Communication
class manages the T=0 protocol to communicate with the Terminal.AES
class contains all the functionality required for the 128-bit AES decryption running on the processor.AESMath
class contains some math helper functions for the decryption.Hiding
class implements countermeasures Shuffling & Dummy-Ops.Masking
class implements the Masking countermeasure.RNG
class implements a small, lightweight Random-Number-Generator.Logger
class can be used to log message to a serial console over USART & USB. Note that this functionality is only available in debug mode.avrdude
(e.g. on Debian: sudo apt-get install avrdude
)The repository is built using CMake. To build the default .hex
file that can be flashed on the ATmega644 using an AVR programmer, do the following:
$ mkdir build/
$ cd build/
$ cmake ..
$ make
$ make flash
There are a couple of CMake options that can be turned on/off. To see a complete list of them, run: $ cmake -L ..
from you build folder.
The Smart-Card used in this laboratory came with an USART to USB converter chip. This makes it possible to log messages to a serial console on a PC over the ATmega644's USART peripheral. If you are compiling this code for your own Smart-Card, you might run into issues with USART. To enable logging of debug messages, the project can be compiled in debug mode. Note that this greatly increases the executable size & that some UART message might interfere with the Terminal communication. If these message are unwanted, the project can also be compiled in release mode.
$ cmake -DDebug=ON ..
to build the project in debug mode.$ cmake -DDebug=OFF ..
to build the project in release mode.OFF
.The AES implementation contains a number of DPA countermeasures, including Masking, Shuffling the S-Box access & inserting Dummy NOPs. You can enable/disable these countermeasures with CMake flags:
$ cmake -DMasking=ON ..
to enable masking.$ cmake -DMasking=OFF ..
to disable masking.OFF
.$ cmake -DShuffling=ON
to enable Shuffling.$ cmake -DShuffling=OFF
to disable Shuffling.OFF
.$ cmake -DDummyOps=ON
to enable Dummy-Ops.$ cmake -DDummyOps=OFF
to disable Dummy-Ops.OFF
.The Doxygen custom CSS template used in this project can be found here.