2017-09-19 04:34:08 -04:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
// AesCfb128Decryptor.cpp
|
|
|
|
|
|
|
|
// Implements the cAesCfb128Decryptor class decrypting data using AES CFB-128
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "AesCfb128Decryptor.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-30 10:00:06 -04:00
|
|
|
cAesCfb128Decryptor::cAesCfb128Decryptor(void):
|
2014-04-29 11:37:15 -04:00
|
|
|
m_IsValid(false)
|
|
|
|
{
|
2017-08-30 10:00:06 -04:00
|
|
|
mbedtls_aes_init(&m_Aes);
|
2014-04-29 11:37:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cAesCfb128Decryptor::~cAesCfb128Decryptor()
|
|
|
|
{
|
|
|
|
// Clear the leftover in-memory data, so that they can't be accessed by a backdoor
|
2017-08-30 10:00:06 -04:00
|
|
|
mbedtls_aes_free(&m_Aes);
|
2014-04-29 11:37:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cAesCfb128Decryptor::Init(const Byte a_Key[16], const Byte a_IV[16])
|
|
|
|
{
|
|
|
|
ASSERT(!IsValid()); // Cannot Init twice
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
memcpy(m_IV, a_IV, 16);
|
2017-08-30 10:00:06 -04:00
|
|
|
mbedtls_aes_setkey_enc(&m_Aes, a_Key, 128);
|
2014-04-29 11:37:15 -04:00
|
|
|
m_IsValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cAesCfb128Decryptor::ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length)
|
|
|
|
{
|
|
|
|
ASSERT(IsValid()); // Must Init() first
|
2017-08-30 10:00:06 -04:00
|
|
|
mbedtls_aes_crypt_cfb8(&m_Aes, MBEDTLS_AES_DECRYPT, a_Length, m_IV, a_EncryptedIn, a_DecryptedOut);
|
2014-04-29 11:37:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|