This repository was the first version of AES, for a newer one check RedLibrary.
This is a small and portable C++17 implementation of the Advanced Encryption Standartd(AES). At this repository you also can find 'Aes-crypt' terminal application which helps you to encrypt/decrypt strings. It is a part of RedLibrary.
AES can be used everywhere you need. It's got strong encryption level and has pretty good perfomance. But if you're looking for algorithm for specific task, I have an option with excess level of encryption, here it is: RES.
AES includes 2 encryption modes: ECB and CBC with 3 key length cases for each of them:
-
ECB
- AesECB 128 bits key
- AesECB 192 bits key
- AesECB 256 bits key
-
CBC
- AesCBC 128 bits key
- AesCBC 192 bits key
- AesCBC 256 bits key
There are 7 header files(6 with algorithms and 1 with shared definitions) and 6 source files(for each of algorithm).
// AesECB128.h
std::string * EncryptAesECB128(const std::string& in, const std::string_view key);
std::string * DecryptAesECB128(const std::string& in, const std::string_view key);
// AesECB192.h
std::string * EncryptAesECB192(const std::string& in, const std::string_view key);
std::string * DecryptAesECB192(const std::string& in, const std::string_view key);
// AesECB256.h
std::string * EncryptAesECB256(const std::string& in, const std::string_view key);
std::string * DecryptAesECB256(const std::string& in, const std::string_view key);
// AesCBC128.h
std::string * EncryptAesCBC128(const std::string& in, const std::string_view key, const std::string_view iv);
std::string * DecryptAesCBC128(const std::string& in, const std::string_view key, const std::string_view iv);
// AesCBC192.h
std::string * EncryptAesCBC192(const std::string& in, const std::string_view key, const std::string_view iv);
std::string * DecryptAesCBC192(const std::string& in, const std::string_view key, const std::string_view iv);
// AesCBC256.h
std::string * EncryptAesCBC256(const std::string& in, const std::string_view key, const std::string_view iv);
std::string * DecryptAesCBC256(const std::string& in, const std::string_view key, const std::string_view iv);
Tech notes:
- Padding is provided only for "in" params. "Iv" should equals 16 bytes. Key length(in bytes) is calculated using the formula:
KEY_LENGTH / 8
. - ECB mode is considered unsafe for most uses and is not implemented in streaming mode. See wikipedia's article on ECB for more details.
- This library is designed for small code size and simplicity, intended for cases where small binary size, low memory footprint and portability is more important than high performance.
Notes:
- If you want to route result of encryption to
std::cout
, you should convert string to hexadecimal system, in other way you will get bad output! - Convertion functions are included in each of examples.
- There is no built-in error checking or protection from out-of-bounds memory access errors as a result of malicious input.
If you're interested in building your standard on the base of this one, you can find everything you need to know in 'YOUR_STANDARD_GUIDE.txt'.
Here's an example of encryption in CBC128 mode:
And the following one is the decryption of previous message:
All material in this repository is in the public domain.