-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_AES.cpp
More file actions
50 lines (36 loc) · 1.51 KB
/
C_AES.cpp
File metadata and controls
50 lines (36 loc) · 1.51 KB
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
//////////////////////////////////////////////////////////////////////////////////
// [ AES_Class_Source ]
//////////////////////////////////////////////////////////////////////////////////
#include "C_AES.hpp"
//////////////////////////////////////////////////////////////////////////////////
// [_Encrypt]
//////////////////////////////////////////////////////////////////////////////////
int C_AES::encrypt(char* pInput, unsigned long cInput, C_Array* pAOutput){
if(!pInput || !cInput || !pAOutput) return(C_AES_ERROR);
unsigned long cRest = cInput % 16;
unsigned long cRounds = cInput / 16;
unsigned long cData = cInput;
if(cRest){
cRounds++;
cData += (16 - cRest);
}
pAOutput->_Destroy();
pAOutput->_Create(1, cData);
char* pBuffer = pAOutput->_Get_pBuffer();
C_Rijndael.Encrypt(pInput, pBuffer, cData, 1);
return(C_AES_READY);
}
//////////////////////////////////////////////////////////////////////////////////
// [_Decrypt]
//////////////////////////////////////////////////////////////////////////////////
int C_AES::decrypt(char* pInput, unsigned long cInput, C_Array* pAOutput){
if(!pInput || !cInput || !pAOutput) return(C_AES_ERROR);
DWORD cRest = cInput % 16;
DWORD cRounds = cInput / 16;
if(cRest) return(C_AES_ERROR);
pAOutput->_Destroy();
pAOutput->_Create(cRounds, 16);
char* pBuffer = pAOutput->_Get_pBuffer();
C_Rijndael.Decrypt(pInput, pBuffer, cInput, 1);
return(C_AES_READY);
}