Cuberite
A lightweight, fast and extensible game server for Minecraft
AesCfb128Decryptor.cpp
Go to the documentation of this file.
1 
2 // AesCfb128Decryptor.cpp
3 
4 // Implements the cAesCfb128Decryptor class decrypting data using AES CFB-128
5 
6 #include "Globals.h"
7 #include "AesCfb128Decryptor.h"
8 
9 
10 
11 
12 
14  m_IsValid(false)
15 {
16  mbedtls_aes_init(&m_Aes);
17 }
18 
19 
20 
21 
22 
24 {
25  // Clear the leftover in-memory data, so that they can't be accessed by a backdoor
26  mbedtls_aes_free(&m_Aes);
27 }
28 
29 
30 
31 
32 
33 void cAesCfb128Decryptor::Init(const Byte a_Key[16], const Byte a_IV[16])
34 {
35  ASSERT(!IsValid()); // Cannot Init twice
36 
37  memcpy(m_IV, a_IV, 16);
38  mbedtls_aes_setkey_enc(&m_Aes, a_Key, 128);
39  m_IsValid = true;
40 }
41 
42 
43 
44 
45 
46 void cAesCfb128Decryptor::ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length)
47 {
48  ASSERT(IsValid()); // Must Init() first
49  mbedtls_aes_crypt_cfb8(&m_Aes, MBEDTLS_AES_DECRYPT, a_Length, m_IV, a_EncryptedIn, a_DecryptedOut);
50 }
51 
52 
53 
54 
55 
void Init(const Byte a_Key[16], const Byte a_IV[16])
Initializes the decryptor with the specified Key / IV.
Byte m_IV[16]
The InitialVector, used by the CFB mode decryption.
bool m_IsValid
Indicates whether the object has been initialized with the Key / IV.
#define ASSERT(x)
Definition: Globals.h:335
mbedtls_aes_context m_Aes
void ProcessData(Byte *a_DecryptedOut, const Byte *a_EncryptedIn, size_t a_Length)
Decrypts a_Length bytes of the encrypted data; produces a_Length output bytes.
unsigned char Byte
Definition: Globals.h:117
bool IsValid(void) const
Returns true if the object has been initialized with the Key / IV.