-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.cxx
More file actions
195 lines (107 loc) · 2.87 KB
/
example.cxx
File metadata and controls
195 lines (107 loc) · 2.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "accelmem.hxx"
#include <iostream>
#include <string>
#include <chrono>
#include <random>
std::mt19937_64 rng(static_cast<std::uint64_t>(std::time(nullptr)));
std::uint8_t block1[(UINT16_MAX + 1) * 250];
std::uint8_t block2[(UINT16_MAX + 1) * 250];
std::int32_t main() noexcept {
std::uint64_t data_r = NULL;
std::size_t iter = 0;
do {
data_r = rng();
*reinterpret_cast<std::uint64_t*>(&block1[iter]) = data_r;
iter += sizeof(std::uint64_t);
} while (iter < sizeof(block1));
// memcpy Example
accelmem::a_memcpy(
block2,
block1,
sizeof(block1)
);
std::size_t r_code = 0;
if (r_code = accelmem::a_memcmp(block1, block2, sizeof(block1)))
std::cout << "[-] Memory Integrity Check for block1 memcpy Operation Failed! Invalid Bytes: " << r_code << std::endl;
accelmem::a_memset(
block1,
sizeof(block1),
0xFFui8
);
accelmem::a_memset(
block2,
sizeof(block2),
0xFFui8
);
if(r_code = accelmem::a_memcmp(block1, block2, sizeof(block1)))
std::cout << "[-] Memory Integrity Check for block2 memcpy Operation Failed! Invalid Bytes: " << r_code << std::endl;
crc32 crc;
crc.update_crc(block1, sizeof(block1));
std::cout << "[+] block1 CRC32 Hash: 0x" << std::hex << std::noshowbase << crc.get_crc() << std::endl;
crc.reset_crc();
crc.update_crc(block2, sizeof(block2));
std::cout << "[+] block2 CRC32 Hash: 0x" << crc.get_crc() << std::endl;
crc.reset_crc();
std::uint32_t key[4]{0x12345678, 0xFFFFFFFF, 0xAAAAAAAA, 0xBBBBBBBB};
std::uint32_t iv[4]{0x87654321, 0xEEEEEEEE, 0xDDDDDDDD, 0xCCCCCCCC};
hc128 hc;
hc.encrypt(
block1,
block1,
sizeof(block1),
key,
iv
);
crc.update_crc(
block1,
sizeof(block1)
);
std::cout << "[+] block1 hc128 Encrypted CRC32 Hash: 0x" << crc.get_crc() << std::endl;
crc.reset_crc();
hc.decrypt(
block1,
block1,
sizeof(block1),
key,
iv
);
crc.update_crc(
block1,
sizeof(block1)
);
std::cout << "[+] block1 hc128 Decrypted / Original CRC32 Hash: 0x" << crc.get_crc() << std::endl;
crc.reset_crc();
std::uint64_t aes_iv = 0xFAFAFAFAFAFAFAFA;
aes128_ctr aes(key);
aes.aes128_encrypt(
block1,
block1,
sizeof(block1),
aes_iv
);
crc.update_crc(
block1,
sizeof(block1)
);
std::cout << "[+] block1 aes128-ctr Encrypted CRC32 Hash: 0x" << crc.get_crc() << std::endl;
crc.reset_crc();
aes.aes128_decrypt(
block1,
block1,
sizeof(block1),
aes_iv
);
crc.update_crc(
block1,
sizeof(block1)
);
std::cout << "[+] block1 aes128-ctr Decrypted / Original CRC32 Hash: 0x" << crc.get_crc() << std::endl;
std::uint32_t arr[2]{0, 0};
hc.encrypt((std::uint8_t*)&arr[0], (std::uint8_t*)&arr[0], sizeof(int), key, iv);
std::cout << arr[0] << std::endl;
std::cout << arr[1] << std::endl;
SECURE_ZERO_MEMORY(key, sizeof(key));
SECURE_ZERO_MEMORY(iv, sizeof(iv));
aes_iv = NULL;
return NULL;
}