AES-DH Implementation
Loading...
Searching...
No Matches
aes::key Namespace Reference

Manage the key. More...

Functions

uint32_t RotWord (const uint32_t &word)
 Rotate a word by one byte left.
 
uint32_t SubWord (const uint32_t &word)
 Substitue the bytes in a key-schedule word.
 
std::vector< uint32_t > Expansion (const std::array< uint64_t, 4 > &key, const uint64_t &Nk)
 Expand a set of keys.
 

Variables

uint32_t Rcon [10]
 The round constants.
 

Detailed Description

Manage the key.

Function Documentation

◆ Expansion()

std::vector< uint32_t > aes::key::Expansion ( const std::array< uint64_t, 4 > & key,
const uint64_t & Nk )

Expand a set of keys.

Parameters
keyThe shared key array.
NkThe size of the key in words.
Returns
A vector of the keys to use.
Remarks
This function is a verbatim translation of Algorithm 2 of the Reference.
key is always exchanged as 4 64bit numbers, or 256 bits total. Nk simply determines where the cutoff is made, thus removing the last 64 bits for AES-192, or the last 128 for AES-128.
When implementing this algorithm, there are two real options: Either do it like the Reference, where we treat the key schedule as a collection of words Or treat it like a collection of individual bytes. The former will be faster, but will also require bitwise operation to index positions in each word. The latter, on the other hand Makes more sense when working on a per key level, but can be confusing when looking at the whole schedule. We followed the Reference.
In essence this function takes a "small" key, and expands it to be large enough for all of AES' rounds, such that it looks random. See Section 5.8 of the 2002 Paper for more details.
For a more visual explanation, see Figure 6, 7, and 8 of the Reference.

◆ RotWord()

uint32_t aes::key::RotWord ( const uint32_t & word)

Rotate a word by one byte left.

Parameters
wordThe word.
Returns
The rotated word.
Remarks
See Figure 5.10 of the Reference

◆ SubWord()

uint32_t aes::key::SubWord ( const uint32_t & word)

Substitue the bytes in a key-schedule word.

Parameters
wordThe word
Returns
The modified word.
Remarks
This uses the exact same algorithm as SubBytes, and as with that step, the Reference just uses a lookup table rather than manually computig it.
See Figure 5.11 of the Reference.

Variable Documentation

◆ Rcon

uint32_t aes::key::Rcon[10]
Initial value:
= {
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
0x20000000, 0x40000000, 0x80000000, 0x1b000000, 0x36000000
}

The round constants.

Remarks
This is copied from Table 5 of the Reference.
The Reference likes to split up words into the individual bytes, but we just treat the whole word as one number.
These values can be computed via r(i)= x(i−4)/4 mod(x8+x4+x3+x+1)
Why do we use these round constants? It eliminates symmetries. See: The 2002 Paper for more details.