2 * Author......: Jens Steube <jens.steube@gmail.com>
8 #include "inc_vendor.cl"
9 #include "inc_hash_constants.h"
10 #include "inc_hash_functions.cl"
11 #include "inc_types.cl"
12 #include "inc_common.cl"
14 #define COMPARE_S "inc_comp_single.cl"
15 #define COMPARE_M "inc_comp_multi.cl"
17 __constant u64 k_sha512[80] =
19 SHA512C00, SHA512C01, SHA512C02, SHA512C03,
20 SHA512C04, SHA512C05, SHA512C06, SHA512C07,
21 SHA512C08, SHA512C09, SHA512C0a, SHA512C0b,
22 SHA512C0c, SHA512C0d, SHA512C0e, SHA512C0f,
23 SHA512C10, SHA512C11, SHA512C12, SHA512C13,
24 SHA512C14, SHA512C15, SHA512C16, SHA512C17,
25 SHA512C18, SHA512C19, SHA512C1a, SHA512C1b,
26 SHA512C1c, SHA512C1d, SHA512C1e, SHA512C1f,
27 SHA512C20, SHA512C21, SHA512C22, SHA512C23,
28 SHA512C24, SHA512C25, SHA512C26, SHA512C27,
29 SHA512C28, SHA512C29, SHA512C2a, SHA512C2b,
30 SHA512C2c, SHA512C2d, SHA512C2e, SHA512C2f,
31 SHA512C30, SHA512C31, SHA512C32, SHA512C33,
32 SHA512C34, SHA512C35, SHA512C36, SHA512C37,
33 SHA512C38, SHA512C39, SHA512C3a, SHA512C3b,
34 SHA512C3c, SHA512C3d, SHA512C3e, SHA512C3f,
35 SHA512C40, SHA512C41, SHA512C42, SHA512C43,
36 SHA512C44, SHA512C45, SHA512C46, SHA512C47,
37 SHA512C48, SHA512C49, SHA512C4a, SHA512C4b,
38 SHA512C4c, SHA512C4d, SHA512C4e, SHA512C4f,
41 void sha512_transform (const u64 w0[4], const u64 w1[4], const u64 w2[4], const u64 w3[4], u64 digest[8])
69 #define ROUND_EXPAND() \
71 w0_t = SHA512_EXPAND (we_t, w9_t, w1_t, w0_t); \
72 w1_t = SHA512_EXPAND (wf_t, wa_t, w2_t, w1_t); \
73 w2_t = SHA512_EXPAND (w0_t, wb_t, w3_t, w2_t); \
74 w3_t = SHA512_EXPAND (w1_t, wc_t, w4_t, w3_t); \
75 w4_t = SHA512_EXPAND (w2_t, wd_t, w5_t, w4_t); \
76 w5_t = SHA512_EXPAND (w3_t, we_t, w6_t, w5_t); \
77 w6_t = SHA512_EXPAND (w4_t, wf_t, w7_t, w6_t); \
78 w7_t = SHA512_EXPAND (w5_t, w0_t, w8_t, w7_t); \
79 w8_t = SHA512_EXPAND (w6_t, w1_t, w9_t, w8_t); \
80 w9_t = SHA512_EXPAND (w7_t, w2_t, wa_t, w9_t); \
81 wa_t = SHA512_EXPAND (w8_t, w3_t, wb_t, wa_t); \
82 wb_t = SHA512_EXPAND (w9_t, w4_t, wc_t, wb_t); \
83 wc_t = SHA512_EXPAND (wa_t, w5_t, wd_t, wc_t); \
84 wd_t = SHA512_EXPAND (wb_t, w6_t, we_t, wd_t); \
85 we_t = SHA512_EXPAND (wc_t, w7_t, wf_t, we_t); \
86 wf_t = SHA512_EXPAND (wd_t, w8_t, w0_t, wf_t); \
89 #define ROUND_STEP(i) \
91 SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha512[i + 0]); \
92 SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha512[i + 1]); \
93 SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha512[i + 2]); \
94 SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha512[i + 3]); \
95 SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha512[i + 4]); \
96 SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha512[i + 5]); \
97 SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha512[i + 6]); \
98 SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha512[i + 7]); \
99 SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha512[i + 8]); \
100 SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha512[i + 9]); \
101 SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha512[i + 10]); \
102 SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha512[i + 11]); \
103 SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha512[i + 12]); \
104 SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha512[i + 13]); \
105 SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, we_t, k_sha512[i + 14]); \
106 SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha512[i + 15]); \
114 for (int i = 16; i < 80; i += 16)
116 ROUND_EXPAND (); ROUND_STEP (i);
129 void hmac_sha512_pad (u64 w0[4], u64 w1[4], u64 w2[4], u64 w3[4], u64 ipad[8], u64 opad[8])
131 w0[0] = w0[0] ^ 0x3636363636363636;
132 w0[1] = w0[1] ^ 0x3636363636363636;
133 w0[2] = w0[2] ^ 0x3636363636363636;
134 w0[3] = w0[3] ^ 0x3636363636363636;
135 w1[0] = w1[0] ^ 0x3636363636363636;
136 w1[1] = w1[1] ^ 0x3636363636363636;
137 w1[2] = w1[2] ^ 0x3636363636363636;
138 w1[3] = w1[3] ^ 0x3636363636363636;
139 w2[0] = w2[0] ^ 0x3636363636363636;
140 w2[1] = w2[1] ^ 0x3636363636363636;
141 w2[2] = w2[2] ^ 0x3636363636363636;
142 w2[3] = w2[3] ^ 0x3636363636363636;
143 w3[0] = w3[0] ^ 0x3636363636363636;
144 w3[1] = w3[1] ^ 0x3636363636363636;
145 w3[2] = w3[2] ^ 0x3636363636363636;
146 w3[3] = w3[3] ^ 0x3636363636363636;
157 sha512_transform (w0, w1, w2, w3, ipad);
159 w0[0] = w0[0] ^ 0x6a6a6a6a6a6a6a6a;
160 w0[1] = w0[1] ^ 0x6a6a6a6a6a6a6a6a;
161 w0[2] = w0[2] ^ 0x6a6a6a6a6a6a6a6a;
162 w0[3] = w0[3] ^ 0x6a6a6a6a6a6a6a6a;
163 w1[0] = w1[0] ^ 0x6a6a6a6a6a6a6a6a;
164 w1[1] = w1[1] ^ 0x6a6a6a6a6a6a6a6a;
165 w1[2] = w1[2] ^ 0x6a6a6a6a6a6a6a6a;
166 w1[3] = w1[3] ^ 0x6a6a6a6a6a6a6a6a;
167 w2[0] = w2[0] ^ 0x6a6a6a6a6a6a6a6a;
168 w2[1] = w2[1] ^ 0x6a6a6a6a6a6a6a6a;
169 w2[2] = w2[2] ^ 0x6a6a6a6a6a6a6a6a;
170 w2[3] = w2[3] ^ 0x6a6a6a6a6a6a6a6a;
171 w3[0] = w3[0] ^ 0x6a6a6a6a6a6a6a6a;
172 w3[1] = w3[1] ^ 0x6a6a6a6a6a6a6a6a;
173 w3[2] = w3[2] ^ 0x6a6a6a6a6a6a6a6a;
174 w3[3] = w3[3] ^ 0x6a6a6a6a6a6a6a6a;
185 sha512_transform (w0, w1, w2, w3, opad);
188 void hmac_sha512_run (u64 w0[4], u64 w1[4], u64 w2[4], u64 w3[4], u64 ipad[8], u64 opad[8], u64 digest[8])
199 sha512_transform (w0, w1, w2, w3, digest);
209 w2[0] = 0x8000000000000000;
216 w3[3] = (128 + 64) * 8;
227 sha512_transform (w0, w1, w2, w3, digest);
230 void hmac_sha512_run_x (u64 ipad[8], u64 opad[8], u64 digest[8])
245 w2[0] = 0x8000000000000000;
252 w3[3] = (128 + 64) * 8;
263 sha512_transform (w0, w1, w2, w3, digest);
283 sha512_transform (w0, w1, w2, w3, digest);
286 __kernel void m06500_init (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha512aix_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
292 const u32 gid = get_global_id (0);
294 if (gid >= gid_max) return;
298 w0[0] = pws[gid].i[ 0];
299 w0[1] = pws[gid].i[ 1];
300 w0[2] = pws[gid].i[ 2];
301 w0[3] = pws[gid].i[ 3];
305 w1[0] = pws[gid].i[ 4];
306 w1[1] = pws[gid].i[ 5];
307 w1[2] = pws[gid].i[ 6];
308 w1[3] = pws[gid].i[ 7];
312 w2[0] = pws[gid].i[ 8];
313 w2[1] = pws[gid].i[ 9];
314 w2[2] = pws[gid].i[10];
315 w2[3] = pws[gid].i[11];
319 w3[0] = pws[gid].i[12];
320 w3[1] = pws[gid].i[13];
321 w3[2] = pws[gid].i[14];
322 w3[3] = pws[gid].i[15];
328 u32 salt_len = salt_bufs[salt_pos].salt_len;
332 salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
333 salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
334 salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
335 salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
339 salt_buf1[0] = salt_bufs[salt_pos].salt_buf[ 4];
340 salt_buf1[1] = salt_bufs[salt_pos].salt_buf[ 5];
341 salt_buf1[2] = salt_bufs[salt_pos].salt_buf[ 6];
342 salt_buf1[3] = salt_bufs[salt_pos].salt_buf[ 7];
346 salt_buf2[0] = salt_bufs[salt_pos].salt_buf[ 8];
347 salt_buf2[1] = salt_bufs[salt_pos].salt_buf[ 9];
348 salt_buf2[2] = salt_bufs[salt_pos].salt_buf[10];
349 salt_buf2[3] = salt_bufs[salt_pos].salt_buf[11];
358 append_0x01_4x4 (salt_buf0, salt_buf1, salt_buf2, salt_buf3, salt_len + 3);
360 append_0x80_4x4 (salt_buf0, salt_buf1, salt_buf2, salt_buf3, salt_len + 4);
366 w0[0] = swap32 (w0[0]);
367 w0[1] = swap32 (w0[1]);
368 w0[2] = swap32 (w0[2]);
369 w0[3] = swap32 (w0[3]);
370 w1[0] = swap32 (w1[0]);
371 w1[1] = swap32 (w1[1]);
372 w1[2] = swap32 (w1[2]);
373 w1[3] = swap32 (w1[3]);
374 w2[0] = swap32 (w2[0]);
375 w2[1] = swap32 (w2[1]);
376 w2[2] = swap32 (w2[2]);
377 w2[3] = swap32 (w2[3]);
378 w3[0] = swap32 (w3[0]);
379 w3[1] = swap32 (w3[1]);
380 w3[2] = swap32 (w3[2]);
381 w3[3] = swap32 (w3[3]);
388 w0l[0] = (u64) (w0[0]) << 32 | (u64) (w0[1]);
389 w0l[1] = (u64) (w0[2]) << 32 | (u64) (w0[3]);
390 w0l[2] = (u64) (w1[0]) << 32 | (u64) (w1[1]);
391 w0l[3] = (u64) (w1[2]) << 32 | (u64) (w1[3]);
392 w1l[0] = (u64) (w2[0]) << 32 | (u64) (w2[1]);
393 w1l[1] = (u64) (w2[2]) << 32 | (u64) (w2[3]);
394 w1l[2] = (u64) (w3[0]) << 32 | (u64) (w3[1]);
395 w1l[3] = (u64) (w3[2]) << 32 | (u64) (w3[3]);
408 hmac_sha512_pad (w0l, w1l, w2l, w3l, ipad, opad);
410 tmps[gid].ipad[0] = ipad[0];
411 tmps[gid].ipad[1] = ipad[1];
412 tmps[gid].ipad[2] = ipad[2];
413 tmps[gid].ipad[3] = ipad[3];
414 tmps[gid].ipad[4] = ipad[4];
415 tmps[gid].ipad[5] = ipad[5];
416 tmps[gid].ipad[6] = ipad[6];
417 tmps[gid].ipad[7] = ipad[7];
419 tmps[gid].opad[0] = opad[0];
420 tmps[gid].opad[1] = opad[1];
421 tmps[gid].opad[2] = opad[2];
422 tmps[gid].opad[3] = opad[3];
423 tmps[gid].opad[4] = opad[4];
424 tmps[gid].opad[5] = opad[5];
425 tmps[gid].opad[6] = opad[6];
426 tmps[gid].opad[7] = opad[7];
428 w0l[0] = (u64) salt_buf0[1] << 32 | (u64) salt_buf0[0];
429 w0l[1] = (u64) salt_buf0[3] << 32 | (u64) salt_buf0[2];
430 w0l[2] = (u64) salt_buf1[1] << 32 | (u64) salt_buf1[0];
431 w0l[3] = (u64) salt_buf1[3] << 32 | (u64) salt_buf1[2];
432 w1l[0] = (u64) salt_buf2[1] << 32 | (u64) salt_buf2[0];
433 w1l[1] = (u64) salt_buf2[3] << 32 | (u64) salt_buf2[2];
434 w1l[2] = (u64) salt_buf3[1] << 32 | (u64) salt_buf3[0];
435 w1l[3] = (u64) salt_buf3[3] << 32 | (u64) salt_buf3[2];
445 w0l[0] = swap64 (w0l[0]);
446 w0l[1] = swap64 (w0l[1]);
447 w0l[2] = swap64 (w0l[2]);
448 w0l[3] = swap64 (w0l[3]);
449 w1l[0] = swap64 (w1l[0]);
450 w1l[1] = swap64 (w1l[1]);
451 w1l[2] = swap64 (w1l[2]);
452 w1l[3] = swap64 (w1l[3]);
460 w3l[3] = (128 + salt_len + 4) * 8;
464 hmac_sha512_run (w0l, w1l, w2l, w3l, ipad, opad, dgst);
466 tmps[gid].dgst[0] = dgst[0];
467 tmps[gid].dgst[1] = dgst[1];
468 tmps[gid].dgst[2] = dgst[2];
469 tmps[gid].dgst[3] = dgst[3];
470 tmps[gid].dgst[4] = dgst[4];
471 tmps[gid].dgst[5] = dgst[5];
472 tmps[gid].dgst[6] = dgst[6];
473 tmps[gid].dgst[7] = dgst[7];
475 tmps[gid].out[0] = dgst[0];
476 tmps[gid].out[1] = dgst[1];
477 tmps[gid].out[2] = dgst[2];
478 tmps[gid].out[3] = dgst[3];
479 tmps[gid].out[4] = dgst[4];
480 tmps[gid].out[5] = dgst[5];
481 tmps[gid].out[6] = dgst[6];
482 tmps[gid].out[7] = dgst[7];
485 __kernel void m06500_loop (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha512aix_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
487 const u32 gid = get_global_id (0);
489 if (gid >= gid_max) return;
494 ipad[0] = tmps[gid].ipad[0];
495 ipad[1] = tmps[gid].ipad[1];
496 ipad[2] = tmps[gid].ipad[2];
497 ipad[3] = tmps[gid].ipad[3];
498 ipad[4] = tmps[gid].ipad[4];
499 ipad[5] = tmps[gid].ipad[5];
500 ipad[6] = tmps[gid].ipad[6];
501 ipad[7] = tmps[gid].ipad[7];
503 opad[0] = tmps[gid].opad[0];
504 opad[1] = tmps[gid].opad[1];
505 opad[2] = tmps[gid].opad[2];
506 opad[3] = tmps[gid].opad[3];
507 opad[4] = tmps[gid].opad[4];
508 opad[5] = tmps[gid].opad[5];
509 opad[6] = tmps[gid].opad[6];
510 opad[7] = tmps[gid].opad[7];
514 dgst[0] = tmps[gid].dgst[0];
515 dgst[1] = tmps[gid].dgst[1];
516 dgst[2] = tmps[gid].dgst[2];
517 dgst[3] = tmps[gid].dgst[3];
518 dgst[4] = tmps[gid].dgst[4];
519 dgst[5] = tmps[gid].dgst[5];
520 dgst[6] = tmps[gid].dgst[6];
521 dgst[7] = tmps[gid].dgst[7];
523 for (u32 j = 0; j < loop_cnt; j++)
525 hmac_sha512_run_x (ipad, opad, dgst);
527 tmps[gid].out[0] ^= dgst[0];
528 tmps[gid].out[1] ^= dgst[1];
529 tmps[gid].out[2] ^= dgst[2];
530 tmps[gid].out[3] ^= dgst[3];
531 tmps[gid].out[4] ^= dgst[4];
532 tmps[gid].out[5] ^= dgst[5];
533 tmps[gid].out[6] ^= dgst[6];
534 tmps[gid].out[7] ^= dgst[7];
537 tmps[gid].dgst[0] = dgst[0];
538 tmps[gid].dgst[1] = dgst[1];
539 tmps[gid].dgst[2] = dgst[2];
540 tmps[gid].dgst[3] = dgst[3];
541 tmps[gid].dgst[4] = dgst[4];
542 tmps[gid].dgst[5] = dgst[5];
543 tmps[gid].dgst[6] = dgst[6];
544 tmps[gid].dgst[7] = dgst[7];
547 __kernel void m06500_comp (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha512aix_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
553 const u32 gid = get_global_id (0);
555 if (gid >= gid_max) return;
557 const u32 lid = get_local_id (0);
564 u64 a = tmps[gid].out[0];
565 u64 b = tmps[gid].out[1];
566 u64 c = tmps[gid].out[2];
567 u64 d = tmps[gid].out[3];
568 u64 e = tmps[gid].out[4];
569 u64 f = tmps[gid].out[5];
570 u64 g = tmps[gid].out[6];
571 u64 h = tmps[gid].out[7] & 0xffffffffffffff00;
574 const u32 r0 = l32_from_64 (tmps[gid].out[0]);
575 const u32 r1 = h32_from_64 (tmps[gid].out[0]);
576 const u32 r2 = l32_from_64 (tmps[gid].out[1]);
577 const u32 r3 = h32_from_64 (tmps[gid].out[1]);