AES-DH Implementation
Loading...
Searching...
No Matches
aes::state_array Class Reference

The state array is a 4x4 byte matrix to which AES operations are performed; also called a block. More...

#include <aes.h>

Public Member Functions

 state_array (const std::string &in, size_t &x)
 Initialize a state_array from a string.
 
 state_array (const std::string &in)
 
 state_array (const state_array &arr)
 
auto & get ()
 
const auto & get () const
 
void xor_arr (const state_array &arr)
 
void shift_r (const size_t &bits)
 
std::string unravel () const
 Unravel the state_array back into a string.
 
void AddRoundKey (const uint64_t &round, const std::vector< uint32_t > &keys)
 Add the round key.
 
void SubBytes ()
 A invertible, non-linear transformation of the state.
 
void InvSubBytes ()
 : Invert the SubBytes step of AES.
 
void ShiftRows ()
 Cyclically shift the bytes in each row.
 
void InvShiftRows ()
 Invert the cyclical shift in ShiftRows()
 
void MixColumns ()
 Transform each column by a single, fixed matrix.
 
void InvMixColumns ()
 Inverts the column transformation.
 

Detailed Description

The state array is a 4x4 byte matrix to which AES operations are performed; also called a block.

For every 16 bytes of input, the state_array organizes these bytes column first, Such that state_array[0] = [0,1,2,3], state_array[1] = [4,5,6,7]

Remarks
See Figure 1 of the Reference.

Constructor & Destructor Documentation

◆ state_array()

aes::state_array::state_array ( const std::string & in,
size_t & x )
inline

Initialize a state_array from a string.

Parameters
inThe input string.
xA mutable index of the string, so that multiple arrays can be initialized from the state class.

Member Function Documentation

◆ AddRoundKey()

void aes::state_array::AddRoundKey ( const uint64_t & round,
const std::vector< uint32_t > & keys )
inline

Add the round key.

Parameters
roundThe current round.
keysThe vector of keys.
Remarks
Each round has 4 keys, one for each column.

◆ InvMixColumns()

void aes::state_array::InvMixColumns ( )
inline

Inverts the column transformation.

Remarks
See 5.3.3 of the Reference.

◆ InvShiftRows()

void aes::state_array::InvShiftRows ( )
inline

Invert the cyclical shift in ShiftRows()

Remarks
This step in AES transposes values in (r,c) to (r, c-r % 4)
See 5.3.1 of the Reference.
InvShiftRows is pretty much identical to ShiftRows(), and the inversion is simply changing c+r to c-r.

◆ InvSubBytes()

void aes::state_array::InvSubBytes ( )
inline

: Invert the SubBytes step of AES.

Remarks
As a testament to the ubiquity and performance of using a lookup table over manual calculation: The Reference does not provide formulas for this stage, and I couldn't find any implementation that doesn't just use InvSBox.

◆ MixColumns()

void aes::state_array::MixColumns ( )
inline

Transform each column by a single, fixed matrix.

Remarks
See 5.1.3 of the Reference.
Each byte in the column are combined, which provides diffusion.

◆ ShiftRows()

void aes::state_array::ShiftRows ( )
inline

Cyclically shift the bytes in each row.

Remarks
This step in AES transposes values in (r,c) to (r, c+r % 4)
See 5.1.2 of the Reference.
This step acts as the transposition stage, and is important to avoid columns being encrypted independently; if this stage was absent, AES would effectively be four separate ciphers acting on each row independently.

◆ SubBytes()

void aes::state_array::SubBytes ( )
inline

A invertible, non-linear transformation of the state.

Remarks
This function takes the multiplicative inverse of each byte in the state (Or 0 if byte is 0), and then performs an affine transformation against a constant value 99.
This function is entirely deterministic, and as such we could (and should) use a lookup table to determine values. Table 4 of the Reference provides said table, which we can use for O(1) efficiency. To better understand the process, here we manually calculate each byte, at the expense of speed.
This step of AES provides non-linearity, and ensures that The resultant byte is not the same as the input.

◆ unravel()

std::string aes::state_array::unravel ( ) const
inline

Unravel the state_array back into a string.

Returns
The string.

The documentation for this class was generated from the following file: