crypto23 is a modern C++23, header-only implementation of Rijndael (including AES variants).
- Provides a templated
crypto23::rijndael<BlockMode, KeyMode>implementation. - Includes convenient aliases for AES block mode:
crypto23::aes_128crypto23::aes_192crypto23::aes_256
- Supports compile-time and runtime encryption/decryption APIs.
- Works on contiguous byte-like buffers (
std::array,std::vector,std::string,std::span, etc.).
- C++23 compiler
- CMake 3.31+
add_subdirectory(path/to/crypto23)
target_link_libraries(your_target PRIVATE crypto23::crypto23)After installing crypto23, use:
find_package(crypto23 CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE crypto23::crypto23)#include <array>
#include <cstddef>
#include <crypto23/rijndael.h>
#include <string>
int main() {
constexpr auto key = std::array{
std::byte{0x2b}, std::byte{0x7e}, std::byte{0x15}, std::byte{0x16},
std::byte{0x28}, std::byte{0xae}, std::byte{0xd2}, std::byte{0xa6},
std::byte{0xab}, std::byte{0xf7}, std::byte{0x15}, std::byte{0x88},
std::byte{0x09}, std::byte{0xcf}, std::byte{0x4f}, std::byte{0x3c}
};
// Runtime API
std::string message = "Hello, World!";
auto encrypted = crypto23::aes_128::encrypt(message, key);
auto decrypted = crypto23::aes_128::decrypt(encrypted, key);
// Compile-time friendly API for string literals
constexpr auto encrypted_literal = crypto23::aes_128::encrypt_string("Hello, World!", key);
auto decrypted_literal = crypto23::aes_128::decrypt_string(encrypted_literal, key);
return (decrypted_literal == "Hello, World!" && decrypted.size() == message.size()) ? 0 : 1;
}encrypt_string/decrypt_string: string-literal focused helpers.encrypt_buffer/decrypt_buffer: fixed-size buffer helpers.encrypt/decrypt: generic contiguous range helpers.
All helpers apply padding so plaintext size does not need to be block-aligned.
- The current API encrypts blocks independently (ECB-style behavior).
- For production-sensitive data, prefer a mode with IV/nonce and authentication (for example, GCM or CTR + MAC) at a higher layer.
- Always use unpredictable keys and keep them out of source control.
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build
ctest --test-dir build --output-on-failureContributions, bug reports, and feature requests are welcome. Open an issue or submit a pull request.
- Fork it
- Create your feature branch:
git checkout -b feature/my-new-feature - Commit your changes:
git commit -am "Add some feature" - Push to the branch:
git push origin feature/my-new-feature - Submit a pull request
This project is licensed under the MIT License.