aes added

This commit is contained in:
orignal 2014-05-06 12:22:22 -04:00
parent 44bba19283
commit d8d8c752b1
3 changed files with 86 additions and 1 deletions

55
aes.h Normal file
View file

@ -0,0 +1,55 @@
#ifndef AES_H__
#define AES_H__
#include <inttypes.h>
#include <cryptopp/modes.h>
#include <cryptopp/aes.h>
namespace i2p
{
namespace crypto
{
union ChipherBlock
{
uint8_t buf[16];
uint64_t ll[2];
};
class CBCEncryption
{
public:
CBCEncryption () { memset (m_LastBlock.buf, 0, 16); };
void SetKey (uint8_t * key) { m_ECBEncryption.SetKey (key, 32); }; // 32 bytes
void SetIV (uint8_t * iv) { memcpy (m_LastBlock.buf, iv, 16); }; // 16 bytes
void Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out);
private:
ChipherBlock m_LastBlock;
CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption m_ECBEncryption;
};
class CBCDecryption
{
public:
CBCDecryption () { memset (m_IV.buf, 0, 16); };
void SetKey (uint8_t * key) { m_ECBDecryption.SetKey (key, 32); }; // 32 bytes
void SetIV (uint8_t * iv) { memcpy (m_IV.buf, iv, 16); }; // 16 bytes
void Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out);
private:
ChipherBlock m_IV;
CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption m_ECBDecryption;
};
}
}
#endif