2017-09-19 08:34:08 +00:00
|
|
|
|
2014-04-29 15:37:15 +00:00
|
|
|
// AesCfb128Encryptor.cpp
|
|
|
|
|
|
|
|
// Implements the cAesCfb128Encryptor class encrypting data using AES CFB-128
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "AesCfb128Encryptor.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-30 14:00:06 +00:00
|
|
|
cAesCfb128Encryptor::cAesCfb128Encryptor(void):
|
2014-04-29 15:37:15 +00:00
|
|
|
m_IsValid(false)
|
|
|
|
{
|
2017-08-30 14:00:06 +00:00
|
|
|
mbedtls_aes_init(&m_Aes);
|
2014-04-29 15:37:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cAesCfb128Encryptor::~cAesCfb128Encryptor()
|
|
|
|
{
|
|
|
|
// Clear the leftover in-memory data, so that they can't be accessed by a backdoor
|
2017-08-30 14:00:06 +00:00
|
|
|
mbedtls_aes_free(&m_Aes);
|
2014-04-29 15:37:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cAesCfb128Encryptor::Init(const Byte a_Key[16], const Byte a_IV[16])
|
|
|
|
{
|
|
|
|
ASSERT(!IsValid()); // Cannot Init twice
|
2016-02-05 21:45:45 +00:00
|
|
|
|
2014-04-29 15:37:15 +00:00
|
|
|
memcpy(m_IV, a_IV, 16);
|
2017-08-30 14:00:06 +00:00
|
|
|
mbedtls_aes_setkey_enc(&m_Aes, a_Key, 128);
|
2014-04-29 15:37:15 +00:00
|
|
|
m_IsValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-11 16:39:43 +00:00
|
|
|
void cAesCfb128Encryptor::ProcessData(std::byte * const a_EncryptedOut, const std::byte * const a_PlainIn, size_t a_Length)
|
2014-04-29 15:37:15 +00:00
|
|
|
{
|
|
|
|
ASSERT(IsValid()); // Must Init() first
|
2021-01-11 16:39:43 +00:00
|
|
|
mbedtls_aes_crypt_cfb8(&m_Aes, MBEDTLS_AES_ENCRYPT, a_Length, m_IV, reinterpret_cast<const unsigned char *>(a_PlainIn), reinterpret_cast<unsigned char *>(a_EncryptedOut));
|
2014-04-29 15:37:15 +00:00
|
|
|
}
|