-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaes_128_ecb_test.c
45 lines (36 loc) · 1.2 KB
/
aes_128_ecb_test.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
#include <stdio.h>
#include <stdlib.h>
#include "cryptopals.h"
int main(int argc, char **argv)
{
int ret;
if (argc != 2) {
fprintf(stderr, "Usage: %s size\nEncrypt and then decrypt a string of 'A's of the specified size\n", argv[0]);
return 1;
}
size_t len = atol(argv[1]);
byte_array key = cstring_to_bytes("YELLOW SUBMARINE");
byte_array plaintext = alloc_byte_array(len);
set_all_bytes(plaintext, 'A');
printf("input length = %li\ninput = ", len);
print_byte_array_ascii(plaintext);
init_openssl();
printf("\nEncrypting...\n");
byte_array cipher = encrypt_aes_128_ecb(plaintext, key);
printf("cipher length = %li\ncipher = ", cipher.len);
print_byte_array(cipher);
printf("\nDecrypting...\n");
byte_array plain2 = decrypt_aes_128_ecb(cipher, key);
printf("output length = %li\noutput = ", plain2.len);
print_byte_array_ascii(plain2);
if (byte_arrays_equal(plaintext, plain2)) {
printf("Plaintexts match! :-)\n");
ret = 0;
} else {
printf("Plaintexts differ! :-(\n");
ret = 1;
}
cleanup_openssl();
free_byte_arrays(key, plaintext, cipher, plain2, NO_BA);
return ret;
}