-
Notifications
You must be signed in to change notification settings - Fork 35
/
crackalack_unit_tests.c
272 lines (219 loc) · 7.66 KB
/
crackalack_unit_tests.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
* Rainbow Crackalack: crackalack_unit_tests.c
* Copyright (C) 2018-2019 Joe Testa <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms version 3 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <string.h>
#include "opencl_setup.h"
#include "shared.h"
#include "test_chain.h"
#include "test_chain_ntlm9.h"
#include "test_hash.h"
#include "test_hash_ntlm9.h"
#include "test_hash_to_index.h"
#include "test_hash_to_index_ntlm9.h"
#include "test_index_to_plaintext.h"
#include "test_index_to_plaintext_ntlm9.h"
#include "version.h"
#define PRINT_PASSED() printf("%spassed.%s\n", GREEN, CLR);
#define PRINT_FAILED() printf("%sFAILED!%s\n", RED, CLR);
int main(int ac, char **av) {
cl_platform_id platforms[MAX_NUM_PLATFORMS];
cl_device_id devices[MAX_NUM_DEVICES];
cl_context context;
cl_program program;
cl_kernel kernel;
int err = 0;
cl_uint num_platforms = 0, num_devices = 0;
int ret = 0;
unsigned int hash_type = HASH_UNDEFINED, all_tests_passed = 1;
ENABLE_CONSOLE_COLOR();
PRINT_PROJECT_HEADER();
#ifndef _WIN32
setenv("CUDA_CACHE_DISABLE", "1", 1); /* Disables kernel caching. */
setenv("HSA_ENABLE_SDMA", "0", 1); /* The ROCm driver on AMD Vega 64 doesn't work without this. */
#endif
get_platforms_and_devices(-1, MAX_NUM_PLATFORMS, platforms, &num_platforms, MAX_NUM_DEVICES, devices, &num_devices, 1);
context = rc_clCreateContext(NULL, num_devices, devices, context_callback, NULL, &err);
if (err < 0) {
fprintf(stderr, "Failed to create context: %d\n", err);
exit(-1);
}
/* PRNG test */
/*
load_kernel(context, num_devices, devices, "test_prng.cl", "test_prng", &program, &kernel);
printf("Running PRNG test... ");
if (!test_prng(devices[0], context, kernel)) {
ret = -1;
all_tests_passed = 0;
printf("FAILED!\n");
} else
printf("passed.\n");
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
*/
/* DES test */
/*
load_kernel(context, num_devices, devices, "test_des.cl", "test_des", &program, &kernel);
printf("Running DES tests... ");
if (!test_des(devices[0], context, kernel)) {
ret = -1;
all_tests_passed = 0;
printf("FAILED!\n");
} else
printf("passed.\n");
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
*/
/* index_to_plaintext() tests. */
hash_type = HASH_NTLM;
load_kernel(context, num_devices, devices, "test_index_to_plaintext.cl", "test_index_to_plaintext", &program, &kernel, hash_type);
printf("Running NTLM index_to_plaintext() tests... "); fflush(stdout);
if (!test_index_to_plaintext(devices[0], context, kernel)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
/* index_to_plaintext_ntlm9() tests. */
load_kernel(context, num_devices, devices, "test_index_to_plaintext_ntlm9.cl", "test_index_to_plaintext_ntlm9", &program, &kernel, hash_type);
printf("Running NTLM9 index_to_plaintext_ntlm9() tests... "); fflush(stdout);
if (!test_index_to_plaintext_ntlm9(devices[0], context, kernel)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
/* Hash tests. */
/*
printf("Running LM hash tests... "); fflush(stdout);
hash_type = HASH_LM;
load_kernel(context, num_devices, devices, "test_hash.cl", "test_hash", &program, &kernel, hash_type);
if (!test_hash(devices[0], context, kernel, hash_type)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
*/
printf("Running NTLM hash tests... "); fflush(stdout);
hash_type = HASH_NTLM;
load_kernel(context, num_devices, devices, "test_hash.cl", "test_hash", &program, &kernel, hash_type);
if (!test_hash(devices[0], context, kernel, hash_type)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
printf("Running NTLM9 hash tests... "); fflush(stdout);
load_kernel(context, num_devices, devices, "test_hash_ntlm9.cl", "test_hash_ntlm9", &program, &kernel, hash_type);
if (!test_hash_ntlm9(devices[0], context, kernel)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
/* hash_to_index() tests. */
/*
printf("Running LM hash_to_index() tests... "); fflush(stdout);
hash_type = HASH_LM;
load_kernel(context, num_devices, devices, "test_hash_to_index.cl", "test_hash_to_index", &program, &kernel, hash_type);
if (!test_h2i(devices[0], context, kernel, hash_type)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
*/
printf("Running NTLM hash_to_index() tests... "); fflush(stdout);
hash_type = HASH_NTLM;
load_kernel(context, num_devices, devices, "test_hash_to_index.cl", "test_hash_to_index", &program, &kernel, hash_type);
if (!test_h2i(devices[0], context, kernel, hash_type)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
printf("Running NTLM9 hash_to_index() tests... "); fflush(stdout);
load_kernel(context, num_devices, devices, "test_hash_to_index_ntlm9.cl", "test_hash_to_index_ntlm9", &program, &kernel, hash_type);
if (!test_h2i_ntlm9(devices[0], context, kernel)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
/* Chain tests. */
/*
printf("Running LM chain tests... "); fflush(stdout);
hash_type = HASH_LM;
load_kernel(context, num_devices, devices, "test_chain.cl", "test_chain", &program, &kernel, hash_type);
if (!test_chain(devices[0], context, kernel, hash_type)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
*/
printf("Running NTLM chain tests... "); fflush(stdout);
hash_type = HASH_NTLM;
load_kernel(context, num_devices, devices, "test_chain.cl", "test_chain", &program, &kernel, hash_type);
if (!test_chain(devices[0], context, kernel, hash_type)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
printf("Running NTLM9 chain tests... "); fflush(stdout);
hash_type = HASH_NTLM;
/*load_kernel(context, num_devices, devices, "test_chain_ntlm9.cl", "test_chain_ntlm9", &program, &kernel, hash_type);*/
load_kernel(context, num_devices, devices, "crackalack_ntlm9.cl", "crackalack_ntlm9", &program, &kernel, hash_type);
if (!test_chain_ntlm9(devices[0], context, kernel)) {
ret = -1;
all_tests_passed = 0;
PRINT_FAILED();
} else
PRINT_PASSED();
CLRELEASEKERNEL(kernel);
CLRELEASEPROGRAM(program);
if (all_tests_passed)
printf("\n\t%sALL UNIT TESTS PASS!%s\n\n", GREENB, CLR);
else
printf("\n\t%sSome unit tests failed!%s :(\n\n", REDB, CLR);
CLRELEASECONTEXT(context);
return ret;
}