ATmega644 Smart-Card
aes.h
1 
11 #ifndef AES_H
12 #define AES_H
13 
14 #include <string.h>
15 
16 #include "defs.h"
17 #include "lut.h"
18 #include "aesMath.h"
19 
20 // Logger
21 #ifdef DEBUG
22 #include "logger.h"
23 #endif
24 
25 // Masking
26 #ifdef MASKING
27 #include "masking.h"
28 #endif
29 
30 // Hiding
31 #if defined(SHUFFLING) || defined(DUMMY_OPS)
32 #include "hiding.h"
33 #endif
34 
45 class AES
46 {
47 public:
52  AES(const aes_key_t masterKey);
53 
59  void decrypt(uint8_t *cipher);
60 
61 private:
62  // *******************************************************************************
63  // Private Attributes ************************************************************
64  // *******************************************************************************
65  sub_keys_t mSubkeys = {};
66  static uint8_t mRCs[ROUNDS];
67 
68  // Logger
69  #ifdef DEBUG
71  #endif
72 
73  // Masking
74  #ifdef MASKING
76  sub_keys_t mOriginalSubKeys;
77  #endif
78 
79  // Hiding
80  #if defined(SHUFFLING) || defined(DUMMY_OPS)
82  #endif
83 
84  #ifdef SHUFFLING
85  uint8_t mShuffledSBoxIndices[STATE_BYTES] = {};
86  #endif
87 
88  // ******************************************************************************
89  // Private Methods **************************************************************
90  // ******************************************************************************
91  // Key Schedule *****************************************************************
103  void createKeySchedule(const aes_key_t masterKey, sub_keys_t subKeys) const;
104 
105  // Key Addition Layer ***********************************************************
113  void addRoundKey(const aes_key_t roundKey, state_t state);
114 
115  // Diffusion Layer **************************************************************
122  void invMixCols(state_t state);
123 
130  void invShiftRows(state_t state);
131 
132  // Byte Substitution layer ******************************************************
139  void invByteSub(state_t state);
140 };
141 
142 #endif // AES_H
AES::mShuffledSBoxIndices
uint8_t mShuffledSBoxIndices[STATE_BYTES]
Array of indices of the S-Box, if shuffling is enabled.
Definition: aes.h:85
AES::mRCs
static uint8_t mRCs[ROUNDS]
Array of round coefficients that are used in the key schedule.
Definition: aes.h:66
AES
Class providing functionality for 128-bit AES decryption.
Definition: aes.h:45
AES::mHiding
Hiding mHiding
Hiding object.
Definition: aes.h:81
AES::mLog
Logger mLog
Logger.
Definition: aes.h:70
AES::invMixCols
void invMixCols(state_t state)
Inverse MixColumn sublayer.
Hiding
Class that implements 2 hiding techniques: dummy-ops & shuffling.
Definition: hiding.h:31
AES::decrypt
void decrypt(uint8_t *cipher)
Decrypt a cipher using the 128-bit AES algorithm.
AES::AES
AES(const aes_key_t masterKey)
Construct a new AES object.
Masking
Masking class that provides functionality for masking and unmasking AES-decryption.
Definition: masking.h:36
AES::invShiftRows
void invShiftRows(state_t state)
Inverse ShiftRows sublayer.
AES::mOriginalSubKeys
sub_keys_t mOriginalSubKeys
Array that contains all original subkeys, if masking is enabled.
Definition: aes.h:76
AES::addRoundKey
void addRoundKey(const aes_key_t roundKey, state_t state)
Add the key for the current round to state.
AES::mSubkeys
sub_keys_t mSubkeys
Array that contains all subkeys.
Definition: aes.h:65
Logger
Logger class that outputs logs over USART.
Definition: logger.h:26
AES::createKeySchedule
void createKeySchedule(const aes_key_t masterKey, sub_keys_t subKeys) const
Create the AES key-schedule & store all subkeys in mSubkeys.
AES::mMasking
Masking mMasking
Masking object.
Definition: aes.h:75
AES::invByteSub
void invByteSub(state_t state)
Inverse Byte Substituion layer.