2 * Author......: Jens Steube <jens.steube@gmail.com>
10 #include "inc_vendor.cl"
11 #include "inc_hash_constants.h"
12 #include "inc_hash_functions.cl"
13 #include "inc_types.cl"
14 #include "inc_common.cl"
15 #include "inc_simd.cl"
17 __constant u64 keccakf_rndc[24] =
19 0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
20 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
21 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
22 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
23 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
24 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
25 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
26 0x8000000000008080, 0x0000000080000001, 0x8000000080008008
30 #define KECCAK_ROUNDS 24
33 #define Theta1(s) (st[0 + s] ^ st[5 + s] ^ st[10 + s] ^ st[15 + s] ^ st[20 + s])
46 u32 j = keccakf_piln[s]; \
47 u32 k = keccakf_rotc[s]; \
49 st[j] = rotl64 (t, k); \
60 st[0 + s] ^= ~bc1 & bc2; \
61 st[1 + s] ^= ~bc2 & bc3; \
62 st[2 + s] ^= ~bc3 & bc4; \
63 st[3 + s] ^= ~bc4 & bc0; \
64 st[4 + s] ^= ~bc0 & bc1; \
67 __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_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)
73 const u32 lid = get_local_id (0);
79 const u32 gid = get_global_id (0);
81 if (gid >= gid_max) return;
86 pw_buf0[0] = pws[gid].i[0];
87 pw_buf0[1] = pws[gid].i[1];
88 pw_buf0[2] = pws[gid].i[2];
89 pw_buf0[3] = pws[gid].i[3];
90 pw_buf1[0] = pws[gid].i[4];
91 pw_buf1[1] = pws[gid].i[5];
92 pw_buf1[2] = pws[gid].i[6];
93 pw_buf1[3] = pws[gid].i[7];
95 const u32 pw_l_len = pws[gid].pw_len;
101 const u8 keccakf_rotc[24] =
103 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
104 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
107 const u8 keccakf_piln[24] =
109 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
110 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
114 * 0x80 keccak, very special
117 const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
119 const u32 rsiz = 200 - (2 * mdlen);
121 const u32 add80w = (rsiz - 1) / 8;
127 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
129 const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
131 const u32x pw_len = pw_l_len + pw_r_len;
134 * concat password candidate
137 u32x wordl0[4] = { 0 };
138 u32x wordl1[4] = { 0 };
139 u32x wordl2[4] = { 0 };
140 u32x wordl3[4] = { 0 };
142 wordl0[0] = pw_buf0[0];
143 wordl0[1] = pw_buf0[1];
144 wordl0[2] = pw_buf0[2];
145 wordl0[3] = pw_buf0[3];
146 wordl1[0] = pw_buf1[0];
147 wordl1[1] = pw_buf1[1];
148 wordl1[2] = pw_buf1[2];
149 wordl1[3] = pw_buf1[3];
151 u32x wordr0[4] = { 0 };
152 u32x wordr1[4] = { 0 };
153 u32x wordr2[4] = { 0 };
154 u32x wordr3[4] = { 0 };
156 wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
157 wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
158 wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
159 wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
160 wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
161 wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
162 wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
163 wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
165 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
167 switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
171 switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
179 w0[0] = wordl0[0] | wordr0[0];
180 w0[1] = wordl0[1] | wordr0[1];
181 w0[2] = wordl0[2] | wordr0[2];
182 w0[3] = wordl0[3] | wordr0[3];
183 w1[0] = wordl1[0] | wordr1[0];
184 w1[1] = wordl1[1] | wordr1[1];
185 w1[2] = wordl1[2] | wordr1[2];
186 w1[3] = wordl1[3] | wordr1[3];
187 w2[0] = wordl2[0] | wordr2[0];
188 w2[1] = wordl2[1] | wordr2[1];
189 w2[2] = wordl2[2] | wordr2[2];
190 w2[3] = wordl2[3] | wordr2[3];
191 w3[0] = wordl3[0] | wordr3[0];
192 w3[1] = wordl3[1] | wordr3[1];
193 w3[2] = wordl3[2] | wordr3[2];
194 w3[3] = wordl3[3] | wordr3[3];
202 st[ 0] = hl32_to_64 (w0[1], w0[0]);
203 st[ 1] = hl32_to_64 (w0[3], w0[2]);
204 st[ 2] = hl32_to_64 (w1[1], w1[0]);
205 st[ 3] = hl32_to_64 (w1[3], w1[2]);
206 st[ 4] = hl32_to_64 (w2[1], w2[0]);
207 st[ 5] = hl32_to_64 (w2[3], w2[2]);
208 st[ 6] = hl32_to_64 (w3[1], w3[0]);
209 st[ 7] = hl32_to_64 (w3[3], w3[2]);
228 st[add80w] |= 0x8000000000000000;
232 for (round = 0; round < KECCAK_ROUNDS; round++)
236 u64x bc0 = Theta1 (0);
237 u64x bc1 = Theta1 (1);
238 u64x bc2 = Theta1 (2);
239 u64x bc3 = Theta1 (3);
240 u64x bc4 = Theta1 (4);
244 t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
245 t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
246 t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
247 t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
248 t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
289 st[0] ^= keccakf_rndc[round];
292 const u32x r0 = l32_from_64 (st[1]);
293 const u32x r1 = h32_from_64 (st[1]);
294 const u32x r2 = l32_from_64 (st[2]);
295 const u32x r3 = h32_from_64 (st[2]);
297 COMPARE_M_SIMD (r0, r1, r2, r3);
301 __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_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)
305 __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_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)
309 __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_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)
315 const u32 lid = get_local_id (0);
321 const u32 gid = get_global_id (0);
323 if (gid >= gid_max) return;
328 pw_buf0[0] = pws[gid].i[0];
329 pw_buf0[1] = pws[gid].i[1];
330 pw_buf0[2] = pws[gid].i[2];
331 pw_buf0[3] = pws[gid].i[3];
332 pw_buf1[0] = pws[gid].i[4];
333 pw_buf1[1] = pws[gid].i[5];
334 pw_buf1[2] = pws[gid].i[6];
335 pw_buf1[3] = pws[gid].i[7];
337 const u32 pw_l_len = pws[gid].pw_len;
343 const u8 keccakf_rotc[24] =
345 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
346 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
349 const u8 keccakf_piln[24] =
351 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
352 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
356 * 0x80 keccak, very special
359 const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
361 const u32 rsiz = 200 - (2 * mdlen);
363 const u32 add80w = (rsiz - 1) / 8;
369 const u32 search[4] =
371 digests_buf[digests_offset].digest_buf[DGST_R0],
372 digests_buf[digests_offset].digest_buf[DGST_R1],
373 digests_buf[digests_offset].digest_buf[DGST_R2],
374 digests_buf[digests_offset].digest_buf[DGST_R3]
381 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
383 const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
385 const u32x pw_len = pw_l_len + pw_r_len;
388 * concat password candidate
391 u32x wordl0[4] = { 0 };
392 u32x wordl1[4] = { 0 };
393 u32x wordl2[4] = { 0 };
394 u32x wordl3[4] = { 0 };
396 wordl0[0] = pw_buf0[0];
397 wordl0[1] = pw_buf0[1];
398 wordl0[2] = pw_buf0[2];
399 wordl0[3] = pw_buf0[3];
400 wordl1[0] = pw_buf1[0];
401 wordl1[1] = pw_buf1[1];
402 wordl1[2] = pw_buf1[2];
403 wordl1[3] = pw_buf1[3];
405 u32x wordr0[4] = { 0 };
406 u32x wordr1[4] = { 0 };
407 u32x wordr2[4] = { 0 };
408 u32x wordr3[4] = { 0 };
410 wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
411 wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
412 wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
413 wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
414 wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
415 wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
416 wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
417 wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
419 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
421 switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
425 switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
433 w0[0] = wordl0[0] | wordr0[0];
434 w0[1] = wordl0[1] | wordr0[1];
435 w0[2] = wordl0[2] | wordr0[2];
436 w0[3] = wordl0[3] | wordr0[3];
437 w1[0] = wordl1[0] | wordr1[0];
438 w1[1] = wordl1[1] | wordr1[1];
439 w1[2] = wordl1[2] | wordr1[2];
440 w1[3] = wordl1[3] | wordr1[3];
441 w2[0] = wordl2[0] | wordr2[0];
442 w2[1] = wordl2[1] | wordr2[1];
443 w2[2] = wordl2[2] | wordr2[2];
444 w2[3] = wordl2[3] | wordr2[3];
445 w3[0] = wordl3[0] | wordr3[0];
446 w3[1] = wordl3[1] | wordr3[1];
447 w3[2] = wordl3[2] | wordr3[2];
448 w3[3] = wordl3[3] | wordr3[3];
456 st[ 0] = hl32_to_64 (w0[1], w0[0]);
457 st[ 1] = hl32_to_64 (w0[3], w0[2]);
458 st[ 2] = hl32_to_64 (w1[1], w1[0]);
459 st[ 3] = hl32_to_64 (w1[3], w1[2]);
460 st[ 4] = hl32_to_64 (w2[1], w2[0]);
461 st[ 5] = hl32_to_64 (w2[3], w2[2]);
462 st[ 6] = hl32_to_64 (w3[1], w3[0]);
463 st[ 7] = hl32_to_64 (w3[3], w3[2]);
482 st[add80w] |= 0x8000000000000000;
486 for (round = 0; round < KECCAK_ROUNDS; round++)
490 u64x bc0 = Theta1 (0);
491 u64x bc1 = Theta1 (1);
492 u64x bc2 = Theta1 (2);
493 u64x bc3 = Theta1 (3);
494 u64x bc4 = Theta1 (4);
498 t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
499 t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
500 t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
501 t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
502 t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
543 st[0] ^= keccakf_rndc[round];
546 const u32x r0 = l32_from_64 (st[1]);
547 const u32x r1 = h32_from_64 (st[1]);
548 const u32x r2 = l32_from_64 (st[2]);
549 const u32x r3 = h32_from_64 (st[2]);
551 COMPARE_S_SIMD (r0, r1, r2, r3);
555 __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_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)
559 __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_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)