2 * Author......: Jens Steube <jens.steube@gmail.com>
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
16 #include "include/kernel_functions.c"
17 #include "OpenCL/types_ocl.c"
18 #include "OpenCL/common.c"
20 #define COMPARE_S "OpenCL/check_single_comp4.c"
21 #define COMPARE_M "OpenCL/check_multi_comp4.c"
23 __constant u32 k_sha256[64] =
25 SHA256C00, SHA256C01, SHA256C02, SHA256C03,
26 SHA256C04, SHA256C05, SHA256C06, SHA256C07,
27 SHA256C08, SHA256C09, SHA256C0a, SHA256C0b,
28 SHA256C0c, SHA256C0d, SHA256C0e, SHA256C0f,
29 SHA256C10, SHA256C11, SHA256C12, SHA256C13,
30 SHA256C14, SHA256C15, SHA256C16, SHA256C17,
31 SHA256C18, SHA256C19, SHA256C1a, SHA256C1b,
32 SHA256C1c, SHA256C1d, SHA256C1e, SHA256C1f,
33 SHA256C20, SHA256C21, SHA256C22, SHA256C23,
34 SHA256C24, SHA256C25, SHA256C26, SHA256C27,
35 SHA256C28, SHA256C29, SHA256C2a, SHA256C2b,
36 SHA256C2c, SHA256C2d, SHA256C2e, SHA256C2f,
37 SHA256C30, SHA256C31, SHA256C32, SHA256C33,
38 SHA256C34, SHA256C35, SHA256C36, SHA256C37,
39 SHA256C38, SHA256C39, SHA256C3a, SHA256C3b,
40 SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f,
43 static void sha256_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[8])
71 #define ROUND_EXPAND() \
73 w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); \
74 w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); \
75 w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); \
76 w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); \
77 w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); \
78 w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); \
79 w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); \
80 w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); \
81 w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); \
82 w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); \
83 wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); \
84 wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); \
85 wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); \
86 wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); \
87 we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); \
88 wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); \
91 #define ROUND_STEP(i) \
93 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i + 0]); \
94 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i + 1]); \
95 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i + 2]); \
96 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i + 3]); \
97 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i + 4]); \
98 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i + 5]); \
99 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i + 6]); \
100 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i + 7]); \
101 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i + 8]); \
102 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i + 9]); \
103 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
104 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
105 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
106 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
107 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
108 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
114 for (int i = 16; i < 64; i += 16)
116 ROUND_EXPAND (); ROUND_STEP (i);
129 static void hmac_sha256_pad (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 ipad[8], u32 opad[8])
131 w0[0] = w0[0] ^ 0x36363636;
132 w0[1] = w0[1] ^ 0x36363636;
133 w0[2] = w0[2] ^ 0x36363636;
134 w0[3] = w0[3] ^ 0x36363636;
135 w1[0] = w1[0] ^ 0x36363636;
136 w1[1] = w1[1] ^ 0x36363636;
137 w1[2] = w1[2] ^ 0x36363636;
138 w1[3] = w1[3] ^ 0x36363636;
139 w2[0] = w2[0] ^ 0x36363636;
140 w2[1] = w2[1] ^ 0x36363636;
141 w2[2] = w2[2] ^ 0x36363636;
142 w2[3] = w2[3] ^ 0x36363636;
143 w3[0] = w3[0] ^ 0x36363636;
144 w3[1] = w3[1] ^ 0x36363636;
145 w3[2] = w3[2] ^ 0x36363636;
146 w3[3] = w3[3] ^ 0x36363636;
157 sha256_transform (w0, w1, w2, w3, ipad);
159 w0[0] = w0[0] ^ 0x6a6a6a6a;
160 w0[1] = w0[1] ^ 0x6a6a6a6a;
161 w0[2] = w0[2] ^ 0x6a6a6a6a;
162 w0[3] = w0[3] ^ 0x6a6a6a6a;
163 w1[0] = w1[0] ^ 0x6a6a6a6a;
164 w1[1] = w1[1] ^ 0x6a6a6a6a;
165 w1[2] = w1[2] ^ 0x6a6a6a6a;
166 w1[3] = w1[3] ^ 0x6a6a6a6a;
167 w2[0] = w2[0] ^ 0x6a6a6a6a;
168 w2[1] = w2[1] ^ 0x6a6a6a6a;
169 w2[2] = w2[2] ^ 0x6a6a6a6a;
170 w2[3] = w2[3] ^ 0x6a6a6a6a;
171 w3[0] = w3[0] ^ 0x6a6a6a6a;
172 w3[1] = w3[1] ^ 0x6a6a6a6a;
173 w3[2] = w3[2] ^ 0x6a6a6a6a;
174 w3[3] = w3[3] ^ 0x6a6a6a6a;
185 sha256_transform (w0, w1, w2, w3, opad);
188 static void hmac_sha256_run (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 ipad[8], u32 opad[8], u32 digest[8])
199 sha256_transform (w0, w1, w2, w3, digest);
216 w3[3] = (64 + 32) * 8;
227 sha256_transform (w0, w1, w2, w3, digest);
230 __kernel void m06400_init (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha256aix_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global wpa_t *wpa_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
236 const u32 gid = get_global_id (0);
238 if (gid >= gid_max) return;
242 w0[0] = pws[gid].i[ 0];
243 w0[1] = pws[gid].i[ 1];
244 w0[2] = pws[gid].i[ 2];
245 w0[3] = pws[gid].i[ 3];
249 w1[0] = pws[gid].i[ 4];
250 w1[1] = pws[gid].i[ 5];
251 w1[2] = pws[gid].i[ 6];
252 w1[3] = pws[gid].i[ 7];
256 w2[0] = pws[gid].i[ 8];
257 w2[1] = pws[gid].i[ 9];
258 w2[2] = pws[gid].i[10];
259 w2[3] = pws[gid].i[11];
263 w3[0] = pws[gid].i[12];
264 w3[1] = pws[gid].i[13];
265 w3[2] = pws[gid].i[14];
266 w3[3] = pws[gid].i[15];
272 u32 salt_len = salt_bufs[salt_pos].salt_len;
276 salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
277 salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
278 salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
279 salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
283 salt_buf1[0] = salt_bufs[salt_pos].salt_buf[ 4];
284 salt_buf1[1] = salt_bufs[salt_pos].salt_buf[ 5];
285 salt_buf1[2] = salt_bufs[salt_pos].salt_buf[ 6];
286 salt_buf1[3] = salt_bufs[salt_pos].salt_buf[ 7];
290 salt_buf2[0] = salt_bufs[salt_pos].salt_buf[ 8];
291 salt_buf2[1] = salt_bufs[salt_pos].salt_buf[ 9];
292 salt_buf2[2] = salt_bufs[salt_pos].salt_buf[10];
293 salt_buf2[3] = salt_bufs[salt_pos].salt_buf[11];
302 append_0x01_4x4 (salt_buf0, salt_buf1, salt_buf2, salt_buf3, salt_len + 3);
304 append_0x80_4x4 (salt_buf0, salt_buf1, salt_buf2, salt_buf3, salt_len + 4);
310 w0[0] = swap32 (w0[0]);
311 w0[1] = swap32 (w0[1]);
312 w0[2] = swap32 (w0[2]);
313 w0[3] = swap32 (w0[3]);
314 w1[0] = swap32 (w1[0]);
315 w1[1] = swap32 (w1[1]);
316 w1[2] = swap32 (w1[2]);
317 w1[3] = swap32 (w1[3]);
318 w2[0] = swap32 (w2[0]);
319 w2[1] = swap32 (w2[1]);
320 w2[2] = swap32 (w2[2]);
321 w2[3] = swap32 (w2[3]);
322 w3[0] = swap32 (w3[0]);
323 w3[1] = swap32 (w3[1]);
324 w3[2] = swap32 (w3[2]);
325 w3[3] = swap32 (w3[3]);
330 hmac_sha256_pad (w0, w1, w2, w3, ipad, opad);
332 tmps[gid].ipad[0] = ipad[0];
333 tmps[gid].ipad[1] = ipad[1];
334 tmps[gid].ipad[2] = ipad[2];
335 tmps[gid].ipad[3] = ipad[3];
336 tmps[gid].ipad[4] = ipad[4];
337 tmps[gid].ipad[5] = ipad[5];
338 tmps[gid].ipad[6] = ipad[6];
339 tmps[gid].ipad[7] = ipad[7];
341 tmps[gid].opad[0] = opad[0];
342 tmps[gid].opad[1] = opad[1];
343 tmps[gid].opad[2] = opad[2];
344 tmps[gid].opad[3] = opad[3];
345 tmps[gid].opad[4] = opad[4];
346 tmps[gid].opad[5] = opad[5];
347 tmps[gid].opad[6] = opad[6];
348 tmps[gid].opad[7] = opad[7];
350 w0[0] = salt_buf0[0];
351 w0[1] = salt_buf0[1];
352 w0[2] = salt_buf0[2];
353 w0[3] = salt_buf0[3];
354 w1[0] = salt_buf1[0];
355 w1[1] = salt_buf1[1];
356 w1[2] = salt_buf1[2];
357 w1[3] = salt_buf1[3];
358 w2[0] = salt_buf2[0];
359 w2[1] = salt_buf2[1];
360 w2[2] = salt_buf2[2];
361 w2[3] = salt_buf2[3];
362 w3[0] = salt_buf3[0];
363 w3[1] = salt_buf3[1];
364 w3[2] = salt_buf3[2];
365 // w3[3] = salt_buf3[3];
367 w0[0] = swap32 (w0[0]);
368 w0[1] = swap32 (w0[1]);
369 w0[2] = swap32 (w0[2]);
370 w0[3] = swap32 (w0[3]);
371 w1[0] = swap32 (w1[0]);
372 w1[1] = swap32 (w1[1]);
373 w1[2] = swap32 (w1[2]);
374 w1[3] = swap32 (w1[3]);
375 w2[0] = swap32 (w2[0]);
376 w2[1] = swap32 (w2[1]);
377 w2[2] = swap32 (w2[2]);
378 w2[3] = swap32 (w2[3]);
379 w3[0] = swap32 (w3[0]);
380 w3[1] = swap32 (w3[1]);
381 w3[2] = swap32 (w3[2]);
382 w3[3] = (64 + salt_len + 4) * 8;
386 hmac_sha256_run (w0, w1, w2, w3, ipad, opad, dgst);
388 tmps[gid].dgst[0] = dgst[0];
389 tmps[gid].dgst[1] = dgst[1];
390 tmps[gid].dgst[2] = dgst[2];
391 tmps[gid].dgst[3] = dgst[3];
392 tmps[gid].dgst[4] = dgst[4];
393 tmps[gid].dgst[5] = dgst[5];
394 tmps[gid].dgst[6] = dgst[6];
395 tmps[gid].dgst[7] = dgst[7];
397 tmps[gid].out[0] = dgst[0];
398 tmps[gid].out[1] = dgst[1];
399 tmps[gid].out[2] = dgst[2];
400 tmps[gid].out[3] = dgst[3];
401 tmps[gid].out[4] = dgst[4];
402 tmps[gid].out[5] = dgst[5];
403 tmps[gid].out[6] = dgst[6];
404 tmps[gid].out[7] = dgst[7];
407 __kernel void m06400_loop (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha256aix_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global wpa_t *wpa_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
409 const u32 gid = get_global_id (0);
411 if (gid >= gid_max) return;
416 ipad[0] = tmps[gid].ipad[0];
417 ipad[1] = tmps[gid].ipad[1];
418 ipad[2] = tmps[gid].ipad[2];
419 ipad[3] = tmps[gid].ipad[3];
420 ipad[4] = tmps[gid].ipad[4];
421 ipad[5] = tmps[gid].ipad[5];
422 ipad[6] = tmps[gid].ipad[6];
423 ipad[7] = tmps[gid].ipad[7];
425 opad[0] = tmps[gid].opad[0];
426 opad[1] = tmps[gid].opad[1];
427 opad[2] = tmps[gid].opad[2];
428 opad[3] = tmps[gid].opad[3];
429 opad[4] = tmps[gid].opad[4];
430 opad[5] = tmps[gid].opad[5];
431 opad[6] = tmps[gid].opad[6];
432 opad[7] = tmps[gid].opad[7];
437 dgst[0] = tmps[gid].dgst[0];
438 dgst[1] = tmps[gid].dgst[1];
439 dgst[2] = tmps[gid].dgst[2];
440 dgst[3] = tmps[gid].dgst[3];
441 dgst[4] = tmps[gid].dgst[4];
442 dgst[5] = tmps[gid].dgst[5];
443 dgst[6] = tmps[gid].dgst[6];
444 dgst[7] = tmps[gid].dgst[7];
446 out[0] = tmps[gid].out[0];
447 out[1] = tmps[gid].out[1];
448 out[2] = tmps[gid].out[2];
449 out[3] = tmps[gid].out[3];
450 out[4] = tmps[gid].out[4];
451 out[5] = tmps[gid].out[5];
452 out[6] = tmps[gid].out[6];
453 out[7] = tmps[gid].out[7];
455 for (u32 j = 0; j < loop_cnt; j++)
477 w3[3] = (64 + 32) * 8;
479 hmac_sha256_run (w0, w1, w2, w3, ipad, opad, dgst);
491 tmps[gid].dgst[0] = dgst[0];
492 tmps[gid].dgst[1] = dgst[1];
493 tmps[gid].dgst[2] = dgst[2];
494 tmps[gid].dgst[3] = dgst[3];
495 tmps[gid].dgst[4] = dgst[4];
496 tmps[gid].dgst[5] = dgst[5];
497 tmps[gid].dgst[6] = dgst[6];
498 tmps[gid].dgst[7] = dgst[7];
500 tmps[gid].out[0] = out[0];
501 tmps[gid].out[1] = out[1];
502 tmps[gid].out[2] = out[2];
503 tmps[gid].out[3] = out[3];
504 tmps[gid].out[4] = out[4];
505 tmps[gid].out[5] = out[5];
506 tmps[gid].out[6] = out[6];
507 tmps[gid].out[7] = out[7];
510 __kernel void m06400_comp (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha256aix_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global wpa_t *wpa_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
516 const u32 gid = get_global_id (0);
518 if (gid >= gid_max) return;
520 const u32 lid = get_local_id (0);
526 const u32 r0 = tmps[gid].out[DGST_R0];
527 const u32 r1 = tmps[gid].out[DGST_R1];
528 const u32 r2 = tmps[gid].out[DGST_R2];
529 const u32 r3 = tmps[gid].out[DGST_R3];
532 u32 a = tmps[gid].out[0];
533 u32 b = tmps[gid].out[1];
534 u32 c = tmps[gid].out[2];
535 u32 d = tmps[gid].out[3];
536 u32 e = tmps[gid].out[4];
537 u32 f = tmps[gid].out[5];
538 u32 g = tmps[gid].out[6];
539 u32 h = tmps[gid].out[7] & 0xffff03ff;