Skip to content

๐Ÿ”‘ Implementation of Advanced Encryption Standart.

License

Notifications You must be signed in to change notification settings

red-sayed/AES_Implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”‘ AES_Implementation

plot

WARNING:

This repository was the first version of AES, for a newer one check RedLibrary.

What is it?

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.

Where to use?

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.

What does AES consist of?

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

How to use it?

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.

Want to build your own standard?

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'.

Screenshots? Here they are:

Here's an example of encryption in CBC128 mode:

plot

And the following one is the decryption of previous message:

plot

All material in this repository is in the public domain.