Skip to content

Releases: ifknot/aes

Beta AES-CPP17

09 Jun 13:42
Compare
Choose a tag to compare
Beta AES-CPP17 Pre-release
Pre-release

AES C++17 - Header only, iterator driven, in-place block cipher software.

Fast, small, and portable implementation of the AES ECB, CBC, & CTR encryption algorithms, PKCS5 padding and hardware nonce generation - written in C++17. (Trying in particular to use C++11/14/17 idioms)

The default key-size of 256 bit is fixed beacuse, as off this release, the 128 bit and 192 bit switching is broken

Usage:

Given a 256 bit key and any container that provides a non-const forward iterator then for inplace encryption:

//request an AES (default) counter (CTR) block_cipher from the compile time factory
using cipher_t = crypto::block_cipher<crypto::CTR>;

// generate a cryptographically secure (CPU permitting) nonce of 12 bytes length to seed the counter
crypto::nonce<> n;
auto nonce_block = n();

// put the nonce (64 bit) + counter (64 bit) at the front - because the block cipher expects it this way
plain.insert(test.begin(), nonce.begin(), nonce.end());

// AES CTR block cipher
cipher_t aes(key);

//encrypt a section of the container as defined by the passed iterators
aes.encrypt(test.begin() + 16, test.end());

//decrypt a section of the container as defined by the passed iterators
aes.decrypt(test.begin() + 16, test.end()); // yes it just calls encrypt but it maintains the API