2 * Author......: Jens Steube <jens.steube@gmail.com>
6 #define _PBKDF2_SHA512_
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 w[16], u64 dgst[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_run (const u64 w1[16], const u64 ipad[8], const u64 opad[8], u64 dgst[8])
140 sha512_transform (w1, dgst);
152 w[ 8] = 0x8000000000000000;
159 w[15] = (128 + 64) * 8;
170 sha512_transform (w, dgst);
173 void hmac_run_x (const u64 ipad[8], const u64 opad[8], u64 dgst[8])
185 w[ 8] = 0x8000000000000000;
192 w[15] = (128 + 64) * 8;
203 sha512_transform (w, dgst);
223 sha512_transform (w, dgst);
226 void hmac_init (u64 w[16], u64 ipad[8], u64 opad[8])
228 w[ 0] ^= 0x3636363636363636;
229 w[ 1] ^= 0x3636363636363636;
230 w[ 2] ^= 0x3636363636363636;
231 w[ 3] ^= 0x3636363636363636;
232 w[ 4] ^= 0x3636363636363636;
233 w[ 5] ^= 0x3636363636363636;
234 w[ 6] ^= 0x3636363636363636;
235 w[ 7] ^= 0x3636363636363636;
236 w[ 8] ^= 0x3636363636363636;
237 w[ 9] ^= 0x3636363636363636;
238 w[10] ^= 0x3636363636363636;
239 w[11] ^= 0x3636363636363636;
240 w[12] ^= 0x3636363636363636;
241 w[13] ^= 0x3636363636363636;
242 w[14] ^= 0x3636363636363636;
243 w[15] ^= 0x3636363636363636;
254 sha512_transform (w, ipad);
256 w[ 0] ^= 0x6a6a6a6a6a6a6a6a;
257 w[ 1] ^= 0x6a6a6a6a6a6a6a6a;
258 w[ 2] ^= 0x6a6a6a6a6a6a6a6a;
259 w[ 3] ^= 0x6a6a6a6a6a6a6a6a;
260 w[ 4] ^= 0x6a6a6a6a6a6a6a6a;
261 w[ 5] ^= 0x6a6a6a6a6a6a6a6a;
262 w[ 6] ^= 0x6a6a6a6a6a6a6a6a;
263 w[ 7] ^= 0x6a6a6a6a6a6a6a6a;
264 w[ 8] ^= 0x6a6a6a6a6a6a6a6a;
265 w[ 9] ^= 0x6a6a6a6a6a6a6a6a;
266 w[10] ^= 0x6a6a6a6a6a6a6a6a;
267 w[11] ^= 0x6a6a6a6a6a6a6a6a;
268 w[12] ^= 0x6a6a6a6a6a6a6a6a;
269 w[13] ^= 0x6a6a6a6a6a6a6a6a;
270 w[14] ^= 0x6a6a6a6a6a6a6a6a;
271 w[15] ^= 0x6a6a6a6a6a6a6a6a;
282 sha512_transform (w, opad);
285 __kernel void m12300_init (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global oraclet_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 void *esalt_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)
291 const u32 gid = get_global_id (0);
293 if (gid >= gid_max) return;
297 w0[0] = swap32 (pws[gid].i[ 0]);
298 w0[1] = swap32 (pws[gid].i[ 1]);
299 w0[2] = swap32 (pws[gid].i[ 2]);
300 w0[3] = swap32 (pws[gid].i[ 3]);
304 w1[0] = swap32 (pws[gid].i[ 4]);
305 w1[1] = swap32 (pws[gid].i[ 5]);
306 w1[2] = swap32 (pws[gid].i[ 6]);
307 w1[3] = swap32 (pws[gid].i[ 7]);
311 w2[0] = swap32 (pws[gid].i[ 8]);
312 w2[1] = swap32 (pws[gid].i[ 9]);
313 w2[2] = swap32 (pws[gid].i[10]);
314 w2[3] = swap32 (pws[gid].i[11]);
318 w3[0] = swap32 (pws[gid].i[12]);
319 w3[1] = swap32 (pws[gid].i[13]);
320 w3[2] = swap32 (pws[gid].i[14]);
321 w3[3] = swap32 (pws[gid].i[15]);
329 data[ 0] = hl32_to_64 (salt_bufs[salt_pos].salt_buf[0], salt_bufs[salt_pos].salt_buf[1]);
330 data[ 1] = hl32_to_64 (salt_bufs[salt_pos].salt_buf[2], salt_bufs[salt_pos].salt_buf[3]);
331 data[ 2] = 0x415554485f50424b;
332 data[ 3] = 0x4446325f53504545;
333 data[ 4] = 0x44595f4b45590000;
334 data[ 5] = 0x0001800000000000;
344 data[15] = (128 + 16 + 22 + 4) * 8;
348 w[ 0] = hl32_to_64 (w0[0], w0[1]);
349 w[ 1] = hl32_to_64 (w0[2], w0[3]);
350 w[ 2] = hl32_to_64 (w1[0], w1[1]);
351 w[ 3] = hl32_to_64 (w1[2], w1[3]);
352 w[ 4] = hl32_to_64 (w2[0], w2[1]);
353 w[ 5] = hl32_to_64 (w2[2], w2[3]);
354 w[ 6] = hl32_to_64 (w3[0], w3[1]);
355 w[ 7] = hl32_to_64 (w3[2], w3[3]);
368 hmac_init (w, ipad, opad);
370 tmps[gid].ipad[0] = ipad[0];
371 tmps[gid].ipad[1] = ipad[1];
372 tmps[gid].ipad[2] = ipad[2];
373 tmps[gid].ipad[3] = ipad[3];
374 tmps[gid].ipad[4] = ipad[4];
375 tmps[gid].ipad[5] = ipad[5];
376 tmps[gid].ipad[6] = ipad[6];
377 tmps[gid].ipad[7] = ipad[7];
379 tmps[gid].opad[0] = opad[0];
380 tmps[gid].opad[1] = opad[1];
381 tmps[gid].opad[2] = opad[2];
382 tmps[gid].opad[3] = opad[3];
383 tmps[gid].opad[4] = opad[4];
384 tmps[gid].opad[5] = opad[5];
385 tmps[gid].opad[6] = opad[6];
386 tmps[gid].opad[7] = opad[7];
388 for (u32 i = 0, j = 1; i < 8; i += 8, j += 1)
392 hmac_run (data, ipad, opad, dgst);
394 tmps[gid].dgst[i + 0] = dgst[0];
395 tmps[gid].dgst[i + 1] = dgst[1];
396 tmps[gid].dgst[i + 2] = dgst[2];
397 tmps[gid].dgst[i + 3] = dgst[3];
398 tmps[gid].dgst[i + 4] = dgst[4];
399 tmps[gid].dgst[i + 5] = dgst[5];
400 tmps[gid].dgst[i + 6] = dgst[6];
401 tmps[gid].dgst[i + 7] = dgst[7];
403 tmps[gid].out[i + 0] = dgst[0];
404 tmps[gid].out[i + 1] = dgst[1];
405 tmps[gid].out[i + 2] = dgst[2];
406 tmps[gid].out[i + 3] = dgst[3];
407 tmps[gid].out[i + 4] = dgst[4];
408 tmps[gid].out[i + 5] = dgst[5];
409 tmps[gid].out[i + 6] = dgst[6];
410 tmps[gid].out[i + 7] = dgst[7];
414 __kernel void m12300_loop (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global oraclet_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 void *esalt_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)
416 const u32 gid = get_global_id (0);
418 if (gid >= gid_max) return;
422 ipad[0] = tmps[gid].ipad[0];
423 ipad[1] = tmps[gid].ipad[1];
424 ipad[2] = tmps[gid].ipad[2];
425 ipad[3] = tmps[gid].ipad[3];
426 ipad[4] = tmps[gid].ipad[4];
427 ipad[5] = tmps[gid].ipad[5];
428 ipad[6] = tmps[gid].ipad[6];
429 ipad[7] = tmps[gid].ipad[7];
433 opad[0] = tmps[gid].opad[0];
434 opad[1] = tmps[gid].opad[1];
435 opad[2] = tmps[gid].opad[2];
436 opad[3] = tmps[gid].opad[3];
437 opad[4] = tmps[gid].opad[4];
438 opad[5] = tmps[gid].opad[5];
439 opad[6] = tmps[gid].opad[6];
440 opad[7] = tmps[gid].opad[7];
444 dgst[0] = tmps[gid].dgst[0];
445 dgst[1] = tmps[gid].dgst[1];
446 dgst[2] = tmps[gid].dgst[2];
447 dgst[3] = tmps[gid].dgst[3];
448 dgst[4] = tmps[gid].dgst[4];
449 dgst[5] = tmps[gid].dgst[5];
450 dgst[6] = tmps[gid].dgst[6];
451 dgst[7] = tmps[gid].dgst[7];
453 for (u32 j = 0; j < loop_cnt; j++)
455 hmac_run_x (ipad, opad, dgst);
457 tmps[gid].out[0] ^= dgst[0];
458 tmps[gid].out[1] ^= dgst[1];
459 tmps[gid].out[2] ^= dgst[2];
460 tmps[gid].out[3] ^= dgst[3];
461 tmps[gid].out[4] ^= dgst[4];
462 tmps[gid].out[5] ^= dgst[5];
463 tmps[gid].out[6] ^= dgst[6];
464 tmps[gid].out[7] ^= dgst[7];
467 tmps[gid].dgst[0] = dgst[0];
468 tmps[gid].dgst[1] = dgst[1];
469 tmps[gid].dgst[2] = dgst[2];
470 tmps[gid].dgst[3] = dgst[3];
471 tmps[gid].dgst[4] = dgst[4];
472 tmps[gid].dgst[5] = dgst[5];
473 tmps[gid].dgst[6] = dgst[6];
474 tmps[gid].dgst[7] = dgst[7];
477 __kernel void m12300_comp (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global oraclet_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 void *esalt_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)
483 const u32 gid = get_global_id (0);
485 if (gid >= gid_max) return;
487 const u32 lid = get_local_id (0);
491 w[ 0] = tmps[gid].out[0];
492 w[ 1] = tmps[gid].out[1];
493 w[ 2] = tmps[gid].out[2];
494 w[ 3] = tmps[gid].out[3];
495 w[ 4] = tmps[gid].out[4];
496 w[ 5] = tmps[gid].out[5];
497 w[ 6] = tmps[gid].out[6];
498 w[ 7] = tmps[gid].out[7];
499 w[ 8] = hl32_to_64 (salt_bufs[salt_pos].salt_buf[0], salt_bufs[salt_pos].salt_buf[1]);
500 w[ 9] = hl32_to_64 (salt_bufs[salt_pos].salt_buf[2], salt_bufs[salt_pos].salt_buf[3]);
501 w[10] = 0x8000000000000000;
506 w[15] = (64 + 16) * 8;
519 sha512_transform (w, dgst);
521 const u32 r0 = h32_from_64 (dgst[0]);
522 const u32 r1 = l32_from_64 (dgst[0]);
523 const u32 r2 = h32_from_64 (dgst[1]);
524 const u32 r3 = l32_from_64 (dgst[1]);