Forked From : https://github.com/SergeyBel/AES
This fork was optimized and used by my file encryption/decryption program.
This header only library provides AES encryption and decryption algorithms, it has a portable C++ implementation and you can also activate and use the code that utilizes the AES-NI instructions.
Compilation Note: This is a header only library, you only need to include the "Krypt.hpp"
, no need to compile the library first, and there's no need to add/link the .cpp
files of the library to your compilation flag, see the example below.
To get the peak performance of this portable library compile it with the flags -O3 -march=native
If your system supports AES-NI instructions, just add the option -D USE_AESNI -maes
in compilation to boost the performance.
sample program:
compile with [pure c/c++ code] g++ -o sample.exe sample.cpp -O3 -march=native
comple with [AES-NI] g++ -o sample.exe sample.cpp -D USE_AESNI -maes -O3 -march=native
The Krypt
namespace contains the following :
sub-namespace | sub-namespace classes |
---|---|
BlockCipher | AES |
Padding | ZeroNulls , ANSI_X9_23 , ISO_IEC_7816_4 , PKCS_5_7 |
Mode | ECB , CBC , CFB |
Methods of the Classes inside the Mode
namespace
encrypt()
decrypt()
Methods of the Classes inside the BlockCipher
namespace
EncryptBlock()
DecryptBlock()
Methods of the Classes inside the Padding
namespace
AddPadding()
RemovePadding()
The ByteArray
class is used to hold the output of encrypt()/decrypt()
methods of the Mode
classes, and the output of AddPadding()/RemovePadding()
methods of the Padding
classes... ByteArray
methods are listed below :
length
- returns the size of the byte arrayarray
- returns the byte array pointer[Krypt::Bytes* or unsigned char*
]detach()
- returns the byte array pointer[Krypt::Bytes* or unsigned char*
], that pointer is then dettached to the instance of the ByteArrayoperator<<
- an overload for the left-shift operatoroperator>>
- an overload for the right-shift operatoroperator[]
- an overload for the bracket operator, use for indexing the array