-
Notifications
You must be signed in to change notification settings - Fork 0
/
AES_wrapper.c
58 lines (45 loc) · 860 Bytes
/
AES_wrapper.c
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
56
57
58
#include "AES.h"
#include <time.h>
#include <stdlib.h>
int init_flag = 0;
int pos = BLOCK_SIZE;
void init_AES() {
AES_SetRoundConstant();
AES_SetSbox();
AES_KeyExpansion();
srand((unsigned int)time(0));
}
void* AES(void *v, int size) {
int i;
uint8_t *value;
if (!init_flag) {
init_AES();
init_flag = 1;
}
value = (uint8_t *)v;
for (i = 0; i < size; i++) {
if (pos >= BLOCK_SIZE) {
for (int j; j < BLOCK_SIZE; j++) {
Plain[j] = rand() % 0x100; // 0x00..0xFF
}
AES_Encryption();
pos = 0;
}
value[i] ^= Cipher[pos++];
}
return (void *)value;
}
int main() {
uint8_t value[4] = { 0x12, 0x34, 0x56, 0x78 };
int size = 4;
uint8_t *ret;
int i;
for(int t=0; t<100; t++){
ret = (uint8_t *)AES((void *)value, size);
for (i = 0; i < size; i++) {
printf("%02x ", value[i]);
}
puts("\n");
}
return 0;
}