2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
4 * magnum <john.magnum@hushmail.com>
11 //too much register pressure
12 //#define NEW_SIMD_CODE
14 #include "inc_vendor.cl"
15 #include "inc_hash_constants.h"
16 #include "inc_hash_functions.cl"
17 #include "inc_types.cl"
18 #include "inc_common.cl"
21 #include "inc_simd.cl"
26 #define BOX(S,n,i) (S)[(n)][(i)]
28 #define BOX(S,n,i) (u64x) ((S)[(n)][(i).s0], (S)[(n)][(i).s1])
30 #define BOX(S,n,i) (u64x) ((S)[(n)][(i).s0], (S)[(n)][(i).s1], (S)[(n)][(i).s2], (S)[(n)][(i).s3])
32 #define BOX(S,n,i) (u64x) ((S)[(n)][(i).s0], (S)[(n)][(i).s1], (S)[(n)][(i).s2], (S)[(n)][(i).s3], (S)[(n)][(i).s4], (S)[(n)][(i).s5], (S)[(n)][(i).s6], (S)[(n)][(i).s7])
34 #define BOX(S,n,i) (u64x) ((S)[(n)][(i).s0], (S)[(n)][(i).s1], (S)[(n)][(i).s2], (S)[(n)][(i).s3], (S)[(n)][(i).s4], (S)[(n)][(i).s5], (S)[(n)][(i).s6], (S)[(n)][(i).s7], (S)[(n)][(i).s8], (S)[(n)][(i).s9], (S)[(n)][(i).sa], (S)[(n)][(i).sb], (S)[(n)][(i).sc], (S)[(n)][(i).sd], (S)[(n)][(i).se], (S)[(n)][(i).sf])
37 #define SBOG_LPSti64 \
38 BOX (s_sbob_sl64, 0, ((t[0] >> (i * 8)) & 0xff)) ^ \
39 BOX (s_sbob_sl64, 1, ((t[1] >> (i * 8)) & 0xff)) ^ \
40 BOX (s_sbob_sl64, 2, ((t[2] >> (i * 8)) & 0xff)) ^ \
41 BOX (s_sbob_sl64, 3, ((t[3] >> (i * 8)) & 0xff)) ^ \
42 BOX (s_sbob_sl64, 4, ((t[4] >> (i * 8)) & 0xff)) ^ \
43 BOX (s_sbob_sl64, 5, ((t[5] >> (i * 8)) & 0xff)) ^ \
44 BOX (s_sbob_sl64, 6, ((t[6] >> (i * 8)) & 0xff)) ^ \
45 BOX (s_sbob_sl64, 7, ((t[7] >> (i * 8)) & 0xff))
49 __constant u64 sbob_sl64[8][256] =
2117 __constant u64 sbob_rc64[12][8] =
2241 void streebog_g (u64x h[8], const u64x m[8], __local u64 (*s_sbob_sl64)[256])
2250 for (int i = 0; i < 8; i++)
2255 for (int i = 0; i < 8; i++)
2257 k[i] = SBOG_LPSti64;
2263 for (int i = 0; i < 8; i++)
2268 for (int r = 0; r < 12; r++)
2273 for (int i = 0; i < 8; i++)
2281 for (int i = 0; i < 8; i++)
2283 s[i] = SBOG_LPSti64;
2286 for (int i = 0; i < 8; i++)
2288 t[i] = k[i] ^ sbob_rc64[r][i];
2294 for (int i = 0; i < 8; i++)
2296 k[i] = SBOG_LPSti64;
2303 for (int i = 0; i < 8; i++)
2305 h[i] ^= s[i] ^ k[i] ^ m[i];
2309 __kernel void m11800_m04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *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_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)
2315 const u32 gid = get_global_id (0);
2316 const u32 lid = get_local_id (0);
2317 const u32 lsz = get_local_size (0);
2320 * shared lookup table
2323 __local u64 s_sbob_sl64[8][256];
2325 for (u32 i = lid; i < 256; i += lsz)
2327 s_sbob_sl64[0][i] = sbob_sl64[0][i];
2328 s_sbob_sl64[1][i] = sbob_sl64[1][i];
2329 s_sbob_sl64[2][i] = sbob_sl64[2][i];
2330 s_sbob_sl64[3][i] = sbob_sl64[3][i];
2331 s_sbob_sl64[4][i] = sbob_sl64[4][i];
2332 s_sbob_sl64[5][i] = sbob_sl64[5][i];
2333 s_sbob_sl64[6][i] = sbob_sl64[6][i];
2334 s_sbob_sl64[7][i] = sbob_sl64[7][i];
2337 barrier (CLK_LOCAL_MEM_FENCE);
2339 if (gid >= gid_max) return;
2348 pw_buf0[0] = pws[gid].i[ 0];
2349 pw_buf0[1] = pws[gid].i[ 1];
2350 pw_buf0[2] = pws[gid].i[ 2];
2351 pw_buf0[3] = pws[gid].i[ 3];
2352 pw_buf1[0] = pws[gid].i[ 4];
2353 pw_buf1[1] = pws[gid].i[ 5];
2354 pw_buf1[2] = pws[gid].i[ 6];
2355 pw_buf1[3] = pws[gid].i[ 7];
2357 const u32 pw_len = pws[gid].pw_len;
2363 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
2370 const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
2372 append_0x01_2x4_VV (w0, w1, out_len);
2398 * reverse message block
2403 m[0] = hl32_to_64 (w[15], w[14]);
2404 m[1] = hl32_to_64 (w[13], w[12]);
2405 m[2] = hl32_to_64 (w[11], w[10]);
2406 m[3] = hl32_to_64 (w[ 9], w[ 8]);
2407 m[4] = hl32_to_64 (w[ 7], w[ 6]);
2408 m[5] = hl32_to_64 (w[ 5], w[ 4]);
2409 m[6] = hl32_to_64 (w[ 3], w[ 2]);
2410 m[7] = hl32_to_64 (w[ 1], w[ 0]);
2412 m[0] = swap64 (m[0]);
2413 m[1] = swap64 (m[1]);
2414 m[2] = swap64 (m[2]);
2415 m[3] = swap64 (m[3]);
2416 m[4] = swap64 (m[4]);
2417 m[5] = swap64 (m[5]);
2418 m[6] = swap64 (m[6]);
2419 m[7] = swap64 (m[7]);
2421 // state buffer (hash)
2434 streebog_g (h, m, s_sbob_sl64);
2445 z[7] = swap64 ((u64) (pw_len * 8));
2447 streebog_g (h, z, s_sbob_sl64);
2448 streebog_g (h, m, s_sbob_sl64);
2450 const u32x r0 = l32_from_64 (h[0]);
2451 const u32x r1 = h32_from_64 (h[0]);
2452 const u32x r2 = l32_from_64 (h[1]);
2453 const u32x r3 = h32_from_64 (h[1]);
2455 COMPARE_M_SIMD (r0, r1, r2, r3);
2459 __kernel void m11800_m08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *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_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)
2463 __kernel void m11800_m16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *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_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)
2467 __kernel void m11800_s04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *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_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)
2473 const u32 gid = get_global_id (0);
2474 const u32 lid = get_local_id (0);
2475 const u32 lsz = get_local_size (0);
2478 * shared lookup table
2481 __local u64 s_sbob_sl64[8][256];
2483 for (u32 i = lid; i < 256; i += lsz)
2485 s_sbob_sl64[0][i] = sbob_sl64[0][i];
2486 s_sbob_sl64[1][i] = sbob_sl64[1][i];
2487 s_sbob_sl64[2][i] = sbob_sl64[2][i];
2488 s_sbob_sl64[3][i] = sbob_sl64[3][i];
2489 s_sbob_sl64[4][i] = sbob_sl64[4][i];
2490 s_sbob_sl64[5][i] = sbob_sl64[5][i];
2491 s_sbob_sl64[6][i] = sbob_sl64[6][i];
2492 s_sbob_sl64[7][i] = sbob_sl64[7][i];
2495 barrier (CLK_LOCAL_MEM_FENCE);
2497 if (gid >= gid_max) return;
2506 pw_buf0[0] = pws[gid].i[ 0];
2507 pw_buf0[1] = pws[gid].i[ 1];
2508 pw_buf0[2] = pws[gid].i[ 2];
2509 pw_buf0[3] = pws[gid].i[ 3];
2510 pw_buf1[0] = pws[gid].i[ 4];
2511 pw_buf1[1] = pws[gid].i[ 5];
2512 pw_buf1[2] = pws[gid].i[ 6];
2513 pw_buf1[3] = pws[gid].i[ 7];
2515 const u32 pw_len = pws[gid].pw_len;
2521 const u32 search[4] =
2523 digests_buf[digests_offset].digest_buf[DGST_R0],
2524 digests_buf[digests_offset].digest_buf[DGST_R1],
2525 digests_buf[digests_offset].digest_buf[DGST_R2],
2526 digests_buf[digests_offset].digest_buf[DGST_R3]
2533 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
2540 const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
2542 append_0x01_2x4_VV (w0, w1, out_len);
2568 * reverse message block
2573 m[0] = hl32_to_64 (w[15], w[14]);
2574 m[1] = hl32_to_64 (w[13], w[12]);
2575 m[2] = hl32_to_64 (w[11], w[10]);
2576 m[3] = hl32_to_64 (w[ 9], w[ 8]);
2577 m[4] = hl32_to_64 (w[ 7], w[ 6]);
2578 m[5] = hl32_to_64 (w[ 5], w[ 4]);
2579 m[6] = hl32_to_64 (w[ 3], w[ 2]);
2580 m[7] = hl32_to_64 (w[ 1], w[ 0]);
2582 m[0] = swap64 (m[0]);
2583 m[1] = swap64 (m[1]);
2584 m[2] = swap64 (m[2]);
2585 m[3] = swap64 (m[3]);
2586 m[4] = swap64 (m[4]);
2587 m[5] = swap64 (m[5]);
2588 m[6] = swap64 (m[6]);
2589 m[7] = swap64 (m[7]);
2591 // state buffer (hash)
2604 streebog_g (h, m, s_sbob_sl64);
2615 z[7] = swap64 ((u64) (pw_len * 8));
2617 streebog_g (h, z, s_sbob_sl64);
2618 streebog_g (h, m, s_sbob_sl64);
2620 const u32x r0 = l32_from_64 (h[0]);
2621 const u32x r1 = h32_from_64 (h[0]);
2622 const u32x r2 = l32_from_64 (h[1]);
2623 const u32x r3 = h32_from_64 (h[1]);
2625 COMPARE_S_SIMD (r0, r1, r2, r3);
2629 __kernel void m11800_s08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *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_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)
2633 __kernel void m11800_s16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *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_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)