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

The namespace containing AES encryption/decryption functions. More...

Namespaces

namespace  gcm
 Functions related to AES-GCM.
 
namespace  gf
 Helper utilities for working within a Galois Field 2**8.
 
namespace  key
 Manage the key.
 

Classes

class  state
 An arbitrary collection of state arrays. More...
 
class  state_array
 The state array is a 4x4 byte matrix to which AES operations are performed; also called a block. More...
 

Functions

std::string Cipher (const std::string &in, const std::array< uint64_t, 4 > &k, const uint64_t &Nr)
 Encrypt a message with AES.
 
std::string InvCipher (const std::string &in, const std::array< uint64_t, 4 > &k, const uint64_t &Nr)
 Decrypt a message with AES.
 
std::string Ctr (const std::string &in, const std::array< uint64_t, 4 > &k, const uint64_t Nr, uint64_t nonce)
 An implementation of AES in CTR mode.
 

Detailed Description

The namespace containing AES encryption/decryption functions.

Remarks
This code has been created with reference to: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf Herein referred to as "The Reference"
Another wonderful source is available here: https://cs.ru.nl/~joan/papers/JDA_VRI_Rijndael_2002.pdf Which we will refer to as the "2002 Paper"
AES is block cipher which takes a message of arbitrary size, alongside a key, and returns a ciphertext that can be safely shared across an untrusted network. AES breaks down a message into a set of 16 byte blocks, and extends the key into a Key Schedule. It then repeatedly applies four operations to each block: SubBytes, ShiftRows, MixColumns, and AddRoundKey. The amount of repetitions (Or rounds) depends on the size of the key, with 10 rounds for a 128 bit key, 12 for 192, and 14 for 256. The Key Schedule creates a unique key for each column of the block, for each round Of the algorithm. Operations are typically performed in the Finite Field GF(256), Which is a field of 256 elements. The reason for this is performance.
This implemention supports three modes of AES: ECB, CTR, and GCM. ECB takes a message, and directly feeds it through AES to receive a ciphertext. CTR uses a nonce value and runs this through AES to generate a block–or pad–that is then XOR'd against The message in a similar fashion to the One-Time Pad. With an incrementing nonce, each Pad will be unique, eliminating a key issue of ECB. Finally, GCM is essentially a version of CTR that incorporates a MAC algorithm to provide integrity.

Function Documentation

◆ Cipher()

std::string aes::Cipher ( const std::string & in,
const std::array< uint64_t, 4 > & k,
const uint64_t & Nr )

Encrypt a message with AES.

Parameters
inThe input string.
kThe key
NrThe number of rounds we should run (Determine how much of the key is used).
Remarks
This function is intentionally a verbatim translation of the pseudo-code outlined in Algorithm 1 of the Reference.
Warning
This function, on its own is no different from ECB!

◆ Ctr()

std::string aes::Ctr ( const std::string & in,
const std::array< uint64_t, 4 > & k,
const uint64_t Nr,
uint64_t nonce )

An implementation of AES in CTR mode.

Parameters
inThe input string.
kThe key.
NrThe number of rounds to perform.
nonceThe nonce value to use.
Remarks
CTR mode generates a OTP that is then XOR'ed to the message. Therefore, Encryption/Decryption Uses the same function.

◆ InvCipher()

std::string aes::InvCipher ( const std::string & in,
const std::array< uint64_t, 4 > & k,
const uint64_t & Nr )

Decrypt a message with AES.

Parameters
inThe input string.
kThe key
NrThe number of rounds to run.
Remarks
This function is intentionally a verbatim translation of the pseudo-code outlined in Algorithm 3 of the Reference.
Warning
This function, on its own is no different from ECB!