2 * Author......: Jens Steube <jens.steube@gmail.com>
10 #include "include/constants.h"
11 #include "include/kernel_vendor.h"
18 #include "include/kernel_functions.c"
19 #include "OpenCL/types_ocl.c"
20 #include "OpenCL/common.c"
21 #include "OpenCL/simd.c"
23 __constant u64 keccakf_rndc[24] =
25 0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
26 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
27 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
28 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
29 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
30 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
31 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
32 0x8000000000008080, 0x0000000080000001, 0x8000000080008008
35 __constant u8 keccakf_rotc[24] =
37 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
38 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
41 __constant u8 keccakf_piln[24] =
43 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
44 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
48 #define KECCAK_ROUNDS 24
51 #define Theta1(s) (st[0 + s] ^ st[5 + s] ^ st[10 + s] ^ st[15 + s] ^ st[20 + s])
64 u32 j = keccakf_piln[s]; \
65 u32 k = keccakf_rotc[s]; \
67 st[j] = rotl64 (t, k); \
78 st[0 + s] ^= ~bc1 & bc2; \
79 st[1 + s] ^= ~bc2 & bc3; \
80 st[2 + s] ^= ~bc3 & bc4; \
81 st[3 + s] ^= ~bc4 & bc0; \
82 st[4 + s] ^= ~bc0 & bc1; \
85 __kernel void m05000_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)
91 const u32 lid = get_local_id (0);
97 const u32 gid = get_global_id (0);
99 if (gid >= gid_max) return;
104 pw_buf0[0] = pws[gid].i[0];
105 pw_buf0[1] = pws[gid].i[1];
106 pw_buf0[2] = pws[gid].i[2];
107 pw_buf0[3] = pws[gid].i[3];
108 pw_buf1[0] = pws[gid].i[4];
109 pw_buf1[1] = pws[gid].i[5];
110 pw_buf1[2] = pws[gid].i[6];
111 pw_buf1[3] = pws[gid].i[7];
113 const u32 pw_l_len = pws[gid].pw_len;
116 * 0x80 keccak, very special
119 const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
121 const u32 rsiz = 200 - (2 * mdlen);
123 const u32 add80w = (rsiz - 1) / 8;
129 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
131 const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
133 const u32x pw_len = pw_l_len + pw_r_len;
136 * concat password candidate
139 u32x wordl0[4] = { 0 };
140 u32x wordl1[4] = { 0 };
141 u32x wordl2[4] = { 0 };
142 u32x wordl3[4] = { 0 };
144 wordl0[0] = pw_buf0[0];
145 wordl0[1] = pw_buf0[1];
146 wordl0[2] = pw_buf0[2];
147 wordl0[3] = pw_buf0[3];
148 wordl1[0] = pw_buf1[0];
149 wordl1[1] = pw_buf1[1];
150 wordl1[2] = pw_buf1[2];
151 wordl1[3] = pw_buf1[3];
153 u32x wordr0[4] = { 0 };
154 u32x wordr1[4] = { 0 };
155 u32x wordr2[4] = { 0 };
156 u32x wordr3[4] = { 0 };
158 wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
159 wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
160 wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
161 wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
162 wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
163 wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
164 wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
165 wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
167 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
169 switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
173 switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
181 w0[0] = wordl0[0] | wordr0[0];
182 w0[1] = wordl0[1] | wordr0[1];
183 w0[2] = wordl0[2] | wordr0[2];
184 w0[3] = wordl0[3] | wordr0[3];
185 w1[0] = wordl1[0] | wordr1[0];
186 w1[1] = wordl1[1] | wordr1[1];
187 w1[2] = wordl1[2] | wordr1[2];
188 w1[3] = wordl1[3] | wordr1[3];
189 w2[0] = wordl2[0] | wordr2[0];
190 w2[1] = wordl2[1] | wordr2[1];
191 w2[2] = wordl2[2] | wordr2[2];
192 w2[3] = wordl2[3] | wordr2[3];
193 w3[0] = wordl3[0] | wordr3[0];
194 w3[1] = wordl3[1] | wordr3[1];
195 w3[2] = wordl3[2] | wordr3[2];
196 w3[3] = wordl3[3] | wordr3[3];
204 st[ 0] = hl32_to_64 (w0[1], w0[0]);
205 st[ 1] = hl32_to_64 (w0[3], w0[2]);
206 st[ 2] = hl32_to_64 (w1[1], w1[0]);
207 st[ 3] = hl32_to_64 (w1[3], w1[2]);
208 st[ 4] = hl32_to_64 (w2[1], w2[0]);
209 st[ 5] = hl32_to_64 (w2[3], w2[2]);
210 st[ 6] = hl32_to_64 (w3[1], w3[0]);
211 st[ 7] = hl32_to_64 (w3[3], w3[2]);
230 st[add80w] |= 0x8000000000000000;
234 for (round = 0; round < KECCAK_ROUNDS; round++)
238 u64x bc0 = Theta1 (0);
239 u64x bc1 = Theta1 (1);
240 u64x bc2 = Theta1 (2);
241 u64x bc3 = Theta1 (3);
242 u64x bc4 = Theta1 (4);
246 t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
247 t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
248 t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
249 t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
250 t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
291 st[0] ^= keccakf_rndc[round];
294 const u32x r0 = l32_from_64 (st[1]);
295 const u32x r1 = h32_from_64 (st[1]);
296 const u32x r2 = l32_from_64 (st[2]);
297 const u32x r3 = h32_from_64 (st[2]);
299 COMPARE_M_SIMD (r0, r1, r2, r3);
303 __kernel void m05000_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)
307 __kernel void m05000_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)
311 __kernel void m05000_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)
317 const u32 lid = get_local_id (0);
323 const u32 gid = get_global_id (0);
325 if (gid >= gid_max) return;
330 pw_buf0[0] = pws[gid].i[0];
331 pw_buf0[1] = pws[gid].i[1];
332 pw_buf0[2] = pws[gid].i[2];
333 pw_buf0[3] = pws[gid].i[3];
334 pw_buf1[0] = pws[gid].i[4];
335 pw_buf1[1] = pws[gid].i[5];
336 pw_buf1[2] = pws[gid].i[6];
337 pw_buf1[3] = pws[gid].i[7];
339 const u32 pw_l_len = pws[gid].pw_len;
342 * 0x80 keccak, very special
345 const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
347 const u32 rsiz = 200 - (2 * mdlen);
349 const u32 add80w = (rsiz - 1) / 8;
355 const u32 search[4] =
357 digests_buf[digests_offset].digest_buf[DGST_R0],
358 digests_buf[digests_offset].digest_buf[DGST_R1],
359 digests_buf[digests_offset].digest_buf[DGST_R2],
360 digests_buf[digests_offset].digest_buf[DGST_R3]
367 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
369 const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
371 const u32x pw_len = pw_l_len + pw_r_len;
374 * concat password candidate
377 u32x wordl0[4] = { 0 };
378 u32x wordl1[4] = { 0 };
379 u32x wordl2[4] = { 0 };
380 u32x wordl3[4] = { 0 };
382 wordl0[0] = pw_buf0[0];
383 wordl0[1] = pw_buf0[1];
384 wordl0[2] = pw_buf0[2];
385 wordl0[3] = pw_buf0[3];
386 wordl1[0] = pw_buf1[0];
387 wordl1[1] = pw_buf1[1];
388 wordl1[2] = pw_buf1[2];
389 wordl1[3] = pw_buf1[3];
391 u32x wordr0[4] = { 0 };
392 u32x wordr1[4] = { 0 };
393 u32x wordr2[4] = { 0 };
394 u32x wordr3[4] = { 0 };
396 wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
397 wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
398 wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
399 wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
400 wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
401 wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
402 wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
403 wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
405 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
407 switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
411 switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
419 w0[0] = wordl0[0] | wordr0[0];
420 w0[1] = wordl0[1] | wordr0[1];
421 w0[2] = wordl0[2] | wordr0[2];
422 w0[3] = wordl0[3] | wordr0[3];
423 w1[0] = wordl1[0] | wordr1[0];
424 w1[1] = wordl1[1] | wordr1[1];
425 w1[2] = wordl1[2] | wordr1[2];
426 w1[3] = wordl1[3] | wordr1[3];
427 w2[0] = wordl2[0] | wordr2[0];
428 w2[1] = wordl2[1] | wordr2[1];
429 w2[2] = wordl2[2] | wordr2[2];
430 w2[3] = wordl2[3] | wordr2[3];
431 w3[0] = wordl3[0] | wordr3[0];
432 w3[1] = wordl3[1] | wordr3[1];
433 w3[2] = wordl3[2] | wordr3[2];
434 w3[3] = wordl3[3] | wordr3[3];
442 st[ 0] = hl32_to_64 (w0[1], w0[0]);
443 st[ 1] = hl32_to_64 (w0[3], w0[2]);
444 st[ 2] = hl32_to_64 (w1[1], w1[0]);
445 st[ 3] = hl32_to_64 (w1[3], w1[2]);
446 st[ 4] = hl32_to_64 (w2[1], w2[0]);
447 st[ 5] = hl32_to_64 (w2[3], w2[2]);
448 st[ 6] = hl32_to_64 (w3[1], w3[0]);
449 st[ 7] = hl32_to_64 (w3[3], w3[2]);
468 st[add80w] |= 0x8000000000000000;
472 for (round = 0; round < KECCAK_ROUNDS; round++)
476 u64x bc0 = Theta1 (0);
477 u64x bc1 = Theta1 (1);
478 u64x bc2 = Theta1 (2);
479 u64x bc3 = Theta1 (3);
480 u64x bc4 = Theta1 (4);
484 t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
485 t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
486 t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
487 t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
488 t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
529 st[0] ^= keccakf_rndc[round];
532 const u32x r0 = l32_from_64 (st[1]);
533 const u32x r1 = h32_from_64 (st[1]);
534 const u32x r2 = l32_from_64 (st[2]);
535 const u32x r3 = h32_from_64 (st[2]);
537 COMPARE_S_SIMD (r0, r1, r2, r3);
541 __kernel void m05000_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)
545 __kernel void m05000_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)