A minimal C++ library implementing AES-128 and AES-256 encryption, built strictly to FIPS 197.
This library is a proof of concept, its not intended for production use. While the implementation follows FIPS-197, it hasn't undergone any security audit. For production systems, please use a well-audited library such as OpenSSL or libsodium.
This library does not provide padding. All inputs must be a multiple of 16 bytes. Padding is intentionally left to the caller, this avoids padding oracle vulnerabilities and keeps the API minimal.
My personal take on the AES (Advanced Encryption Standard) algorithm, implemented strictly following FIPS 197. Designed with a focus on simplicity, clean API, no dependencies, single include.
ECB (Electronic Codebook) is the simplest block cipher mode, each 16-byte block is encrypted independently, which makes it fast, but also means identical plaintext blocks produce identical ciphertext blocks. Read about the vulnerability here.
CBC (Cipher Block Chaining) XORs each plaintext block with the previous ciphertext block before encrypting, using an initialization vector (IV) for the first block. This eliminates ECB's identical-block weakness at the cost of sequential (non-parallelizable) encryption, which is slower.
- Visual Studio 2022 (or later with C++17 support)
- Platform Toolset v143 or later
- Clone the repository:
git clone https://github.com/NtProtectVirtualMemory/AES.git- Add the
cryptofolder to your build system or Visual Studio project.
#include "crypto/AES.h"
int main()
{
// Column Major
uint8_t state[16] =
{
0x32, 0x43, 0xf6, 0xa8,
0x88, 0x5a, 0x30, 0x8d,
0x31, 0x31, 0x98, 0xa2,
0xe0, 0x37, 0x07, 0x34
};
uint8_t key[16] =
{
0x2b, 0x7e, 0x15, 0x16,
0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88,
0x09, 0xcf, 0x4f, 0x3c
};
AES::Context ctx{ 0 };
AES::init_context(ctx, key, AES_128);
AES::encrypt_block(state, ctx);
AES::decrypt_block(state, ctx);
}
- If you're fixing a bug or adding a feature, please open an issue first (unless it's a very obvious typo/doc fix)
- Fork the repository and create your branch from
master - Make sure the code follows the current style:
- Use C++20 features when it improves readability/safety
- Use
snake_caseeverywhere - Keep the public API clean & minimal
- Make small, focused pull requests with clear titles & description
This project is licensed under the MIT License - see the LICENSE file for details.