-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
61 lines (55 loc) · 1.62 KB
/
main.c
File metadata and controls
61 lines (55 loc) · 1.62 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
51
52
53
54
55
56
57
58
59
60
61
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "./lib/AES.h"
/**
* @union A union that allow us to deal with our parameters as groups of
* bytes as well as words. To be used in a future update.
*/
union {
uint32_t word[4];
uint8_t byte[16];
} byteWordUnion;
/**
* @brief A function that parses command line argument strings for
* hexadecimal numbers. To be updated when AES-196 and AES-256 algorithms are implemented.
* As for now, and since only AES-128 is impleemented, output is truncated at 16 bytes.
* @param argv The argv array of arguments.
* @param argIndex The index of the argument to be parsed.
* @return A pointer to the parsed argument.
*/
uint8_t *commandLineParser (char **argv, int argIndex)
{
uint8_t *buffer;
buffer = (uint8_t*) calloc (16, sizeof (uint8_t));
for (int i = 0; i < 16; i++) {
char *temp;
temp = (uint8_t *) calloc (3, sizeof (char));
strncpy (temp, argv[argIndex] + 2 * i, 2 * sizeof (char));
*(buffer + i) = (uint8_t)strtol (temp, NULL, 16);
free (temp);
}
return buffer;
}
int main (int argc, char **argv)
{
uint8_t *buffer;
uint8_t *cipherKey;
if (argc < 3) {
printf("Usage: %s plaintext key\nBoth plaintext and key should be in hexadecimal format without prefixed 0x.\nBeware!\
Since only AES-128 is implemented for now, the plaintext and key would be truncated at 16 bytes.",argv[0]);
exit (1);
} else {
buffer = commandLineParser (argv, 1);
cipherKey = commandLineParser (argv, 2);
}
AES128 (buffer, cipherKey);
for (int i = 0; i < 16; i++) {
printf ("%.2x", buffer[i]);
}
puts("");
free(buffer);
free(cipherKey);
return 0;
}