-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAESCipher.cpp
45 lines (30 loc) · 947 Bytes
/
AESCipher.cpp
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
/*
* File: AESCipher.cpp
* Author: ph4r05
*
* Created on May 16, 2014, 11:42 AM
*/
#include <string.h>
#include "aes.h"
#include "AESCipher.h"
AESCipher::AESCipher() : rounds(-1) {
}
AESCipher::AESCipher(const AESCipher& orig) : rounds(orig.rounds) {
}
AESCipher::~AESCipher() {
}
int AESCipher::evaluate(const unsigned char* input, unsigned char* output) const {
unsigned char inp[AES_BLOCK_SIZE];
unsigned char key[AES_BLOCK_SIZE];
memcpy(inp, input, AES_BLOCK_SIZE);
memcpy(key, input + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
return evaluate(inp, key, output);
}
int AESCipher::evaluate(const unsigned char* input, const unsigned char* key, unsigned char* output) const {
unsigned int key_schedule[60];
// Generate enc key.
KeyExpansion(key,key_schedule, 128);
// Encrypt.
aes_encrypt(input, output, key_schedule, 128, this->rounds);
return 1;
}