This repository was archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaes_ecb.c
More file actions
47 lines (39 loc) · 1.2 KB
/
aes_ecb.c
File metadata and controls
47 lines (39 loc) · 1.2 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
//
// Created by Ghost on 2018/11/13.
//
#include "aes_ecb.h"
void arg_process(int argc, char *argv[], crypto_data *info) {
info->mode = ENCRYPT;
info->file_path = NULL;
if (argc < 2 || argc > 4) {
printf(USAGE);
exit(0);
} else if (argc == 2) {
printf(USAGE);
if (!strcmp("-h", argv[1])) { exit(0); }
else { exit(1); }
} else if (argc == 3) {
info->key_path = argv[1];
info->file_path = argv[2];
} else {
if (!strcmp("-d", argv[3])) { info->mode = DECRYPT; }
else if (!strcmp("-e", argv[3])) { info->mode = ENCRYPT; }
else {
printf("Invalid argument\n%s", USAGE);
exit(1);
}
info->key_path = argv[1];
info->file_path = argv[2];
}
}
void encrypt(const unsigned char *__data,
const unsigned char *__key, int __mode, unsigned char *__result) {
AES_KEY key;
if (__mode == DECRYPT) {
AES_set_decrypt_key(__key, KEY_SIZE * 8, &key);
} else {
AES_set_encrypt_key(__key, KEY_SIZE * 8, &key);
}
int mode = __mode == DECRYPT ? AES_DECRYPT : AES_ENCRYPT;
AES_ecb_encrypt(__data, __result, &key, mode);
}