-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
78 lines (56 loc) · 1.68 KB
/
test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <openssl/rand.h>
#include "./pcbc.hpp"
void test(size_t test_payload_size)
{
byte key[BLOCK_SIZE];
RAND_bytes(key, BLOCK_SIZE);
byte iv[BLOCK_SIZE];
RAND_bytes(iv, BLOCK_SIZE);
byte *test_payload = new byte[test_payload_size];
RAND_bytes(test_payload, test_payload_size);
byte *encrypted;
size_t encrypted_size;
encrypt_aes256_pcbc(test_payload, test_payload_size, key, iv, encrypted, encrypted_size);
// printf("[%ld] Encrypted: %ld -> %ld\n", test_payload_size, test_payload_size, encrypted_size);
byte *decrypted;
size_t decrypted_size;
decrypt_aes256_pcbc(encrypted, encrypted_size, key, iv, decrypted, decrypted_size);
// printf("[%ld] Decrypted: %ld -> %ld\n", test_payload_size, encrypted_size, decrypted_size);
if (test_payload_size != decrypted_size)
{
printf("! Different sizes !\n");
abort();
}
for (size_t i = 0; i < test_payload_size; i += 1)
{
if (test_payload[i] != decrypted[i])
{
printf("! Different bytes [%ld] !\n", i);
abort();
}
}
printf("[%3ld] Pass! (%3ld -> %3ld -> %3ld)\n", test_payload_size, test_payload_size, encrypted_size, decrypted_size);
delete[] test_payload;
}
int main()
{
// test(1);
// test(BLOCK_SIZE - 1);
// test(BLOCK_SIZE);
// test(BLOCK_SIZE + 1);
// test(BLOCK_SIZE * 5);
// test(BLOCK_SIZE * 5 + 2);
// printf("--- Random tests ---\n");
// for (size_t r = 0; r < 50; r += 1)
// {
// byte rs;
// RAND_bytes(&rs, 1);
// test(rs);
// }
///////
for (size_t s = 0; s < 256; s += 1)
{
test(s);
}
return 0;
}