Skip to content

NtProtectVirtualMemory/AES

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AES

A minimal C++ library implementing AES-128 and AES-256 encryption, built strictly to FIPS 197.

Disclaimer

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.

Overview

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.

Features

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.

EBC Encryption

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.

CBC Encryption

Getting Started

Prerequisites

  • Visual Studio 2022 (or later with C++17 support)
  • Platform Toolset v143 or later

Building

  1. Clone the repository:
git clone https://github.com/NtProtectVirtualMemory/AES.git
  1. Add the crypto folder to your build system or Visual Studio project.

Basic Usage

#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);

}

How to contribute

  1. If you're fixing a bug or adding a feature, please open an issue first (unless it's a very obvious typo/doc fix)
  2. Fork the repository and create your branch from master
  3. Make sure the code follows the current style:
    • Use C++20 features when it improves readability/safety
    • Use snake_case everywhere
    • Keep the public API clean & minimal
  4. Make small, focused pull requests with clear titles & description

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A minimal C++ library for AES encryption and decryption with respect to the official AES standard "FIPS 197"

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages