Software Library for AES-128 Encryption and Decryption [APPLICATION NOTE]
Atmel-42508A-AT10764-Software-Library-for-AES-128-Encryption-and-Decryption_ApplicationNote_08/2015
Table of Contents
Introduction ............................................................................................................. 1
Features ................................................................................................................... 1
1 Glossary ........................................................................................................... 4
2 Hardware and Software Setup ........................................................................ 4
3 AES Algorithm .................................................................................................. 5
3.1 AES Encryption ....................................................................................................................... 5
3.1.1 AddRoundKey Transformation .................................................................................... 6
3.1.2 SubBytes Transformation............................................................................................ 7
3.1.3 ShiftRows Transformation ........................................................................................... 8
3.1.4 MixColumns Transformation ....................................................................................... 8
3.1.5 C Implementation ........................................................................................................ 8
3.2 Key Expansion ........................................................................................................................ 9
3.2.1 C implementation ........................................................................................................ 9
3.3 AES Decryption ....................................................................................................................... 9
3.3.1 Inverse of AddRoundKey .......................................................................................... 10
3.3.2 Inverse SubBytes Transformation ............................................................................. 10
3.3.3 Inverse ShiftRows Transformation ............................................................................ 11
3.3.4 Inverse MixColumns Transformation ........................................................................ 11
3.3.5 C Implementation ...................................................................................................... 12
4 Block Cipher Modes of Operation ................................................................. 12
4.1 Electronic Codebook Mode ................................................................................................... 12
4.1.2 C Implementation of ECB mode ................................................................................ 13
4.2 The Cipher Block Chaining Mode (CBC) ............................................................................... 13
4.2.1 CBC Encryption ........................................................................................................ 13
4.2.2 CBC Decryption ........................................................................................................ 14
4.2.3 C Implementation of CBC mode ............................................................................... 14
4.3 Cipher Feedback mode ......................................................................................................... 15
4.3.1 CFB Encryption ......................................................................................................... 15
4.3.2 CFB Decryption ......................................................................................................... 16
4.3.3 C Implementation ...................................................................................................... 16
4.4 Output Feedback mode ......................................................................................................... 19
4.4.1 OFB Encryption ......................................................................................................... 19
4.4.2 OFB Decryption ........................................................................................................ 19
4.4.3 C Implementation ...................................................................................................... 20
4.5 The Counter Mode (CTR) ...................................................................................................... 21
4.5.1 CTR Encryption ......................................................................................................... 21
4.5.2 CTR Decryption ........................................................................................................ 22
4.5.3 Generation of counter blocks .................................................................................... 22
4.5.4 C Implementation of CTR mode ................................................................................ 22
5 AES -128 Example Implementation ............................................................... 25
6 Execution of Example in Atmel Studio ......................................................... 26
7 References ..................................................................................................... 28
7.1 FIPS – 197 Advanced Encryption Standard (AES) ............................................................... 28
7.2 FIPS SP 800-38A Recommendation for Block Cipher Modes of Operation .......................... 28