ATmega644 Smart-Card
Loading...
Searching...
No Matches
masking.h
1
11#ifndef MASK_H
12#define MASK_H
13
14#include "defs.h"
15#include "lut.h"
16#include "aesMath.h"
17#include "rng.h"
18
19// Logger
20#ifdef DEBUG
21#include "logger.h"
22#endif
23
37{
38public:
42 Masking() = default;
43
53 void init();
54
63 void maskSubKeys(const sub_keys_t subKeys, sub_keys_t maskedSubKeys) const;
64
72 void invMaskState(state_t state) const;
73
81 void invReMaskState(state_t state) const;
82
90 void invUnMaskState(state_t state) const;
91
97 uint8_t getInvMaskedSBoxValue(const uint8_t index) const { return mInvMaskedSBox[index]; }
98
99private:
100 // ******************************************************************************
101 // Private Structures ***********************************************************
102 // ******************************************************************************
107 struct mask_t
108 {
109 uint8_t input;
110 uint8_t output;
111 };
112
113 // ******************************************************************************
114 // Private Attributes ***********************************************************
115 // ******************************************************************************
116 uint8_t mInvMaskedSBox[SBOX_BYTES];
117
125
133
135 #ifdef DEBUG
137 #endif
138 // ******************************************************************************
139 // Private Methods **************************************************************
140 // ******************************************************************************
149 void initInvMaskedSBox(uint8_t maskedSBox[], const mask_t &subByteMask) const;
150
156 void initMixColInputMask(mask_t mixColMasks[]) const;
157};
158
159#endif // MASK_H
Logger class that outputs logs over USART.
Definition logger.h:27
Masking class that provides functionality for masking and unmasking AES-decryption.
Definition masking.h:37
void initInvMaskedSBox(uint8_t maskedSBox[], const mask_t &subByteMask) const
Compute the (inverse) masked S-Box.
mask_t mSubByteMask
SubByte input & output mask.
Definition masking.h:124
void maskSubKeys(const sub_keys_t subKeys, sub_keys_t maskedSubKeys) const
Mask the subKeys & store the masked keys in maskedSubKeys.
void initMixColInputMask(mask_t mixColMasks[]) const
Compute masks m_i, i=1..4, by performing a MixCol operation on masks m_i'.
void invReMaskState(state_t state) const
(Inverse) re-mask the state after every MixCol step.
RNG mRNG
Random-Number-Generator.
Definition masking.h:134
uint8_t getInvMaskedSBoxValue(const uint8_t index) const
Get a value of the (inverse) masked S-Box at a specific index.
Definition masking.h:97
mask_t mMixColMasks[4]
4 MixCol input & output masks.
Definition masking.h:132
void invUnMaskState(state_t state) const
(Inverse) un-mask the state after the last AddRoundKey step.
uint8_t mInvMaskedSBox[SBOX_BYTES]
Inverse S-Box with masked values.
Definition masking.h:116
void init()
Initialize the masks & the masked inverse S-Box.
Masking()=default
Construct a new Masking object.
Logger mLog
Logger.
Definition masking.h:136
void invMaskState(state_t state) const
(Inverse) mask the state before the first AddRoundKey step.
Class that provides a random number generator. The RNG can be seeded by reading noise from an unused ...
Definition rng.h:27
Structure for masks. Masks always come in pairs, with an input & output mask.
Definition masking.h:108
uint8_t input
Input mask.
Definition masking.h:109
uint8_t output
Output mask.
Definition masking.h:110