summaryrefslogtreecommitdiffstats
path: root/src/mbedTLS++/AesCfb128Encryptor.cpp
blob: 11582fc191cb4e0ac3a7b777074d1bd377d5fe54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

// AesCfb128Encryptor.cpp

// Implements the cAesCfb128Encryptor class encrypting data using AES CFB-128

#include "Globals.h"
#include "AesCfb128Encryptor.h"





cAesCfb128Encryptor::cAesCfb128Encryptor(void):
	m_IsValid(false)
{
	mbedtls_aes_init(&m_Aes);
}





cAesCfb128Encryptor::~cAesCfb128Encryptor()
{
	// Clear the leftover in-memory data, so that they can't be accessed by a backdoor
	mbedtls_aes_free(&m_Aes);
}





void cAesCfb128Encryptor::Init(const Byte a_Key[16], const Byte a_IV[16])
{
	ASSERT(!IsValid());  // Cannot Init twice

	memcpy(m_IV, a_IV, 16);
	mbedtls_aes_setkey_enc(&m_Aes, a_Key, 128);
	m_IsValid = true;
}





void cAesCfb128Encryptor::ProcessData(Byte * a_EncryptedOut, const Byte * a_PlainIn, size_t a_Length)
{
	ASSERT(IsValid());  // Must Init() first
	mbedtls_aes_crypt_cfb8(&m_Aes, MBEDTLS_AES_ENCRYPT, a_Length, m_IV, a_PlainIn, a_EncryptedOut);
}