Prepare _a0 kernel for SIMD
[hashcat.git] / OpenCL / m08700_a0.cl
1 /**
2  * Authors.....: Jens Steube <jens.steube@gmail.com>
3  *               Gabriele Gristina <matrix@hashcat.net>
4  *
5  * License.....: MIT
6  */
7
8 #define _LOTUS6_
9
10 #include "include/constants.h"
11 #include "include/kernel_vendor.h"
12
13 #define DGST_R0 0
14 #define DGST_R1 1
15 #define DGST_R2 2
16 #define DGST_R3 3
17
18 #include "include/kernel_functions.c"
19 #include "OpenCL/types_ocl.c"
20 #include "OpenCL/common.c"
21 #include "include/rp_kernel.h"
22 #include "OpenCL/rp.c"
23
24 #define COMPARE_S "OpenCL/check_single_comp4.c"
25 #define COMPARE_M "OpenCL/check_multi_comp4.c"
26
27 __constant u32 lotus_magic_table[256] =
28 {
29   0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
30   0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
31   0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
32   0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
33   0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
34   0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
35   0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
36   0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
37   0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
38   0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
39   0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
40   0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
41   0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
42   0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
43   0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
44   0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
45   0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
46   0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
47   0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
48   0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
49   0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
50   0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
51   0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
52   0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
53   0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
54   0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
55   0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
56   0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
57   0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
58   0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
59   0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
60   0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab,
61 };
62
63 #define BOX(S,i) (S)[(i)]
64
65 #if   VECT_SIZE == 1
66 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i)])
67 #elif VECT_SIZE == 2
68 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1])
69 #elif VECT_SIZE == 4
70 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3])
71 #elif VECT_SIZE == 8
72 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7])
73 #endif
74
75 #if   VECT_SIZE == 1
76 #define BOX1(S,i) (S)[(i)]
77 #elif VECT_SIZE == 2
78 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1])
79 #elif VECT_SIZE == 4
80 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3])
81 #elif VECT_SIZE == 8
82 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3], (S)[(i).s4], (S)[(i).s5], (S)[(i).s6], (S)[(i).s7])
83 #endif
84
85 static void lotus_mix (u32 *in, __local u32 *s_lotus_magic_table)
86 {
87   u32 p = 0;
88
89   for (int i = 0; i < 18; i++)
90   {
91     u32 s = 48;
92
93     #pragma unroll
94     for (int j = 0; j < 12; j++)
95     {
96       u32 tmp_in = in[j];
97       u32 tmp_out = 0;
98
99       p = (p + s--) & 0xff; p = ((tmp_in >>  0) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p <<  0;
100       p = (p + s--) & 0xff; p = ((tmp_in >>  8) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p <<  8;
101       p = (p + s--) & 0xff; p = ((tmp_in >> 16) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p << 16;
102       p = (p + s--) & 0xff; p = ((tmp_in >> 24) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p << 24;
103
104       in[j] = tmp_out;
105     }
106   }
107 }
108
109 static void lotus_transform_password (u32 in[4], u32 out[4], __local u32 *s_lotus_magic_table)
110 {
111   u32 t = out[3] >> 24;
112
113   u32 c;
114
115   //#pragma unroll // kernel fails if used
116   for (int i = 0; i < 4; i++)
117   {
118     t ^= (in[i] >>  0) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c <<  0; t = ((out[i] >>  0) & 0xff);
119     t ^= (in[i] >>  8) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c <<  8; t = ((out[i] >>  8) & 0xff);
120     t ^= (in[i] >> 16) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c << 16; t = ((out[i] >> 16) & 0xff);
121     t ^= (in[i] >> 24) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c << 24; t = ((out[i] >> 24) & 0xff);
122   }
123 }
124
125 static void pad (u32 w[4], const u32 len)
126 {
127   const u32 val = 16 - len;
128
129   const u32 mask1 = val << 24;
130
131   const u32 mask2 = val << 16
132                    | val << 24;
133
134   const u32 mask3 = val <<  8
135                    | val << 16
136                    | val << 24;
137
138   const u32 mask4 = val <<  0
139                    | val <<  8
140                    | val << 16
141                    | val << 24;
142
143   switch (len)
144   {
145     case  0:  w[0]  = mask4;
146               w[1]  = mask4;
147               w[2]  = mask4;
148               w[3]  = mask4;
149               break;
150     case  1:  w[0] |= mask3;
151               w[1]  = mask4;
152               w[2]  = mask4;
153               w[3]  = mask4;
154               break;
155     case  2:  w[0] |= mask2;
156               w[1]  = mask4;
157               w[2]  = mask4;
158               w[3]  = mask4;
159               break;
160     case  3:  w[0] |= mask1;
161               w[1]  = mask4;
162               w[2]  = mask4;
163               w[3]  = mask4;
164               break;
165     case  4:  w[1]  = mask4;
166               w[2]  = mask4;
167               w[3]  = mask4;
168               break;
169     case  5:  w[1] |= mask3;
170               w[2]  = mask4;
171               w[3]  = mask4;
172               break;
173     case  6:  w[1] |= mask2;
174               w[2]  = mask4;
175               w[3]  = mask4;
176               break;
177     case  7:  w[1] |= mask1;
178               w[2]  = mask4;
179               w[3]  = mask4;
180               break;
181     case  8:  w[2]  = mask4;
182               w[3]  = mask4;
183               break;
184     case  9:  w[2] |= mask3;
185               w[3]  = mask4;
186               break;
187     case 10:  w[2] |= mask2;
188               w[3]  = mask4;
189               break;
190     case 11:  w[2] |= mask1;
191               w[3]  = mask4;
192               break;
193     case 12:  w[3]  = mask4;
194               break;
195     case 13:  w[3] |= mask3;
196               break;
197     case 14:  w[3] |= mask2;
198               break;
199     case 15:  w[3] |= mask1;
200               break;
201   }
202 }
203
204 static void mdtransform_norecalc (u32 state[4], u32 block[4], __local u32 *s_lotus_magic_table)
205 {
206   u32 x[12];
207
208   x[ 0] = state[0];
209   x[ 1] = state[1];
210   x[ 2] = state[2];
211   x[ 3] = state[3];
212   x[ 4] = block[0];
213   x[ 5] = block[1];
214   x[ 6] = block[2];
215   x[ 7] = block[3];
216   x[ 8] = state[0] ^ block[0];
217   x[ 9] = state[1] ^ block[1];
218   x[10] = state[2] ^ block[2];
219   x[11] = state[3] ^ block[3];
220
221   lotus_mix (x, s_lotus_magic_table);
222
223   state[0] = x[0];
224   state[1] = x[1];
225   state[2] = x[2];
226   state[3] = x[3];
227 }
228
229 static void mdtransform (u32 state[4], u32 checksum[4], u32 block[4], __local u32 *s_lotus_magic_table)
230 {
231   mdtransform_norecalc (state, block, s_lotus_magic_table);
232
233   lotus_transform_password (block, checksum, s_lotus_magic_table);
234 }
235
236 static void domino_big_md (const u32 saved_key[16], const u32 size, u32 state[4], __local u32 *s_lotus_magic_table)
237 {
238   u32 checksum[4];
239
240   checksum[0] = 0;
241   checksum[1] = 0;
242   checksum[2] = 0;
243   checksum[3] = 0;
244
245   u32 block[4];
246
247   block[0] = 0;
248   block[1] = 0;
249   block[2] = 0;
250   block[3] = 0;
251
252   u32 curpos;
253   u32 idx;
254
255   for (curpos = 0, idx = 0; curpos + 16 < size; curpos += 16, idx += 4)
256   {
257     block[0] = saved_key[idx + 0];
258     block[1] = saved_key[idx + 1];
259     block[2] = saved_key[idx + 2];
260     block[3] = saved_key[idx + 3];
261
262     mdtransform (state, checksum, block, s_lotus_magic_table);
263   }
264
265   block[0] = saved_key[idx + 0];
266   block[1] = saved_key[idx + 1];
267   block[2] = saved_key[idx + 2];
268   block[3] = saved_key[idx + 3];
269
270   mdtransform (state, checksum, block, s_lotus_magic_table);
271
272   mdtransform_norecalc (state, checksum, s_lotus_magic_table);
273 }
274
275 __kernel void m08700_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 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
276 {
277   /**
278    * base
279    */
280
281   const u32 gid = get_global_id (0);
282   const u32 lid = get_local_id (0);
283   const u32 lsz = get_local_size (0);
284
285   /**
286    * sbox
287    */
288
289   __local u32 s_lotus_magic_table[256];
290
291   for (u32 i = lid; i < 256; i += lsz)
292   {
293     s_lotus_magic_table[i] = lotus_magic_table[i];
294   }
295
296   __local u32 l_bin2asc[256];
297
298   for (u32 i = lid; i < 256; i += lsz)
299   {
300     const u32 i0 = (i >> 0) & 15;
301     const u32 i1 = (i >> 4) & 15;
302
303     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
304                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
305   }
306
307   barrier (CLK_LOCAL_MEM_FENCE);
308
309   if (gid >= gid_max) return;
310
311   /**
312    * base
313    */
314
315   u32 pw_buf0[4];
316
317   pw_buf0[0] = pws[gid].i[ 0];
318   pw_buf0[1] = pws[gid].i[ 1];
319   pw_buf0[2] = pws[gid].i[ 2];
320   pw_buf0[3] = pws[gid].i[ 3];
321
322   u32 pw_buf1[4];
323
324   pw_buf1[0] = pws[gid].i[ 4];
325   pw_buf1[1] = pws[gid].i[ 5];
326   pw_buf1[2] = pws[gid].i[ 6];
327   pw_buf1[3] = pws[gid].i[ 7];
328
329   const u32 pw_len = pws[gid].pw_len;
330
331   /**
332    * salt
333    */
334
335   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
336   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
337
338   /**
339    * loop
340    */
341
342   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
343   {
344     u32 w0[4];
345
346     w0[0] = pw_buf0[0];
347     w0[1] = pw_buf0[1];
348     w0[2] = pw_buf0[2];
349     w0[3] = pw_buf0[3];
350
351     u32 w1[4];
352
353     w1[0] = pw_buf1[0];
354     w1[1] = pw_buf1[1];
355     w1[2] = pw_buf1[2];
356     w1[3] = pw_buf1[3];
357
358     u32 w2[4];
359
360     w2[0] = 0;
361     w2[1] = 0;
362     w2[2] = 0;
363     w2[3] = 0;
364
365     u32 w3[4];
366
367     w3[0] = 0;
368     w3[1] = 0;
369     w3[2] = 0;
370     w3[3] = 0;
371
372     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
373
374     u32 w[16];
375
376     w[ 0] = w0[0];
377     w[ 1] = w0[1];
378     w[ 2] = w0[2];
379     w[ 3] = w0[3];
380     w[ 4] = w1[0];
381     w[ 5] = w1[1];
382     w[ 6] = w1[2];
383     w[ 7] = w1[3];
384     w[ 8] = w2[0];
385     w[ 9] = w2[1];
386     w[10] = w2[2];
387     w[11] = w2[3];
388     w[12] = w3[0];
389     w[13] = w3[1];
390     w[14] = w3[2];
391     w[15] = w3[3];
392
393     u32 state[4];
394
395     state[0] = 0;
396     state[1] = 0;
397     state[2] = 0;
398     state[3] = 0;
399
400     /**
401      * padding
402      */
403
404     if (pw_len < 16)
405     {
406       pad (&w[ 0], pw_len & 0xf);
407     }
408     else if (pw_len < 32)
409     {
410       pad (&w[ 4], pw_len & 0xf);
411     }
412     else if (pw_len < 48)
413     {
414       pad (&w[ 8], pw_len & 0xf);
415     }
416     else if (pw_len < 64)
417     {
418       pad (&w[12], pw_len & 0xf);
419     }
420
421     domino_big_md (w, pw_len, state, s_lotus_magic_table);
422
423     const u32 w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
424                      | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
425     const u32 w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
426                      | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
427     const u32 w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
428                      | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
429     const u32 w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
430                      | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
431     const u32 w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
432                      | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
433     const u32 w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
434                      | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
435     const u32 w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
436                      | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
437     //const u32 w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
438     //                 | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
439
440     const u32 pade = 0x0e0e0e0e;
441
442     w[ 0] = salt0;
443     w[ 1] = salt1      | w0_t << 16;
444     w[ 2] = w0_t >> 16 | w1_t << 16;
445     w[ 3] = w1_t >> 16 | w2_t << 16;
446     w[ 4] = w2_t >> 16 | w3_t << 16;
447     w[ 5] = w3_t >> 16 | w4_t << 16;
448     w[ 6] = w4_t >> 16 | w5_t << 16;
449     w[ 7] = w5_t >> 16 | w6_t << 16;
450     w[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
451     w[ 9] = pade;
452     w[10] = pade;
453     w[11] = pade;
454     w[12] = 0;
455     w[13] = 0;
456     w[14] = 0;
457     w[15] = 0;
458
459     state[0] = 0;
460     state[1] = 0;
461     state[2] = 0;
462     state[3] = 0;
463
464     domino_big_md (w, 34, state, s_lotus_magic_table);
465
466     u32 a = state[0] & 0xffffffff;
467     u32 b = state[1] & 0xffffffff;
468     u32 c = state[2] & 0x000000ff;
469     u32 d = state[3] & 0x00000000;
470
471     const u32 r0 = a;
472     const u32 r1 = b;
473     const u32 r2 = c;
474     const u32 r3 = d;
475
476     #include COMPARE_M
477   }
478 }
479
480 __kernel void m08700_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
481 {
482 }
483
484 __kernel void m08700_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
485 {
486 }
487
488 __kernel void m08700_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 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
489 {
490   /**
491    * base
492    */
493
494   const u32 gid = get_global_id (0);
495   const u32 lid = get_local_id (0);
496   const u32 lsz = get_local_size (0);
497
498   /**
499    * sbox
500    */
501
502   __local u32 s_lotus_magic_table[256];
503
504   for (u32 i = lid; i < 256; i += lsz)
505   {
506     s_lotus_magic_table[i] = lotus_magic_table[i];
507   }
508
509   __local u32 l_bin2asc[256];
510
511   for (u32 i = lid; i < 256; i += lsz)
512   {
513     const u32 i0 = (i >> 0) & 15;
514     const u32 i1 = (i >> 4) & 15;
515
516     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
517                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
518   }
519
520   barrier (CLK_LOCAL_MEM_FENCE);
521
522   if (gid >= gid_max) return;
523
524   /**
525    * base
526    */
527
528   u32 pw_buf0[4];
529
530   pw_buf0[0] = pws[gid].i[ 0];
531   pw_buf0[1] = pws[gid].i[ 1];
532   pw_buf0[2] = pws[gid].i[ 2];
533   pw_buf0[3] = pws[gid].i[ 3];
534
535   u32 pw_buf1[4];
536
537   pw_buf1[0] = pws[gid].i[ 4];
538   pw_buf1[1] = pws[gid].i[ 5];
539   pw_buf1[2] = pws[gid].i[ 6];
540   pw_buf1[3] = pws[gid].i[ 7];
541
542   const u32 pw_len = pws[gid].pw_len;
543
544   /**
545    * salt
546    */
547
548   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
549   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
550
551   /**
552    * digest
553    */
554
555   const u32 search[4] =
556   {
557     digests_buf[digests_offset].digest_buf[DGST_R0],
558     digests_buf[digests_offset].digest_buf[DGST_R1],
559     digests_buf[digests_offset].digest_buf[DGST_R2],
560     digests_buf[digests_offset].digest_buf[DGST_R3]
561   };
562
563   /**
564    * loop
565    */
566
567   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
568   {
569     u32 w0[4];
570
571     w0[0] = pw_buf0[0];
572     w0[1] = pw_buf0[1];
573     w0[2] = pw_buf0[2];
574     w0[3] = pw_buf0[3];
575
576     u32 w1[4];
577
578     w1[0] = pw_buf1[0];
579     w1[1] = pw_buf1[1];
580     w1[2] = pw_buf1[2];
581     w1[3] = pw_buf1[3];
582
583     u32 w2[4];
584
585     w2[0] = 0;
586     w2[1] = 0;
587     w2[2] = 0;
588     w2[3] = 0;
589
590     u32 w3[4];
591
592     w3[0] = 0;
593     w3[1] = 0;
594     w3[2] = 0;
595     w3[3] = 0;
596
597     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
598
599     u32 w[16];
600
601     w[ 0] = w0[0];
602     w[ 1] = w0[1];
603     w[ 2] = w0[2];
604     w[ 3] = w0[3];
605     w[ 4] = w1[0];
606     w[ 5] = w1[1];
607     w[ 6] = w1[2];
608     w[ 7] = w1[3];
609     w[ 8] = w2[0];
610     w[ 9] = w2[1];
611     w[10] = w2[2];
612     w[11] = w2[3];
613     w[12] = w3[0];
614     w[13] = w3[1];
615     w[14] = w3[2];
616     w[15] = w3[3];
617
618     u32 state[4];
619
620     state[0] = 0;
621     state[1] = 0;
622     state[2] = 0;
623     state[3] = 0;
624
625     /**
626      * padding
627      */
628
629     if (pw_len < 16)
630     {
631       pad (&w[ 0], pw_len & 0xf);
632     }
633     else if (pw_len < 32)
634     {
635       pad (&w[ 4], pw_len & 0xf);
636     }
637     else if (pw_len < 48)
638     {
639       pad (&w[ 8], pw_len & 0xf);
640     }
641     else if (pw_len < 64)
642     {
643       pad (&w[12], pw_len & 0xf);
644     }
645
646     domino_big_md (w, pw_len, state, s_lotus_magic_table);
647
648     const u32 w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
649                      | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
650     const u32 w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
651                      | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
652     const u32 w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
653                      | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
654     const u32 w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
655                      | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
656     const u32 w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
657                      | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
658     const u32 w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
659                      | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
660     const u32 w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
661                      | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
662     //const u32 w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
663     //                 | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
664
665     const u32 pade = 0x0e0e0e0e;
666
667     w[ 0] = salt0;
668     w[ 1] = salt1      | w0_t << 16;
669     w[ 2] = w0_t >> 16 | w1_t << 16;
670     w[ 3] = w1_t >> 16 | w2_t << 16;
671     w[ 4] = w2_t >> 16 | w3_t << 16;
672     w[ 5] = w3_t >> 16 | w4_t << 16;
673     w[ 6] = w4_t >> 16 | w5_t << 16;
674     w[ 7] = w5_t >> 16 | w6_t << 16;
675     w[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
676     w[ 9] = pade;
677     w[10] = pade;
678     w[11] = pade;
679     w[12] = 0;
680     w[13] = 0;
681     w[14] = 0;
682     w[15] = 0;
683
684     state[0] = 0;
685     state[1] = 0;
686     state[2] = 0;
687     state[3] = 0;
688
689     domino_big_md (w, 34, state, s_lotus_magic_table);
690
691     u32 a = state[0] & 0xffffffff;
692     u32 b = state[1] & 0xffffffff;
693     u32 c = state[2] & 0x000000ff;
694     u32 d = state[3] & 0x00000000;
695
696     const u32 r0 = a;
697     const u32 r1 = b;
698     const u32 r2 = c;
699     const u32 r3 = d;
700
701     #include COMPARE_S
702   }
703 }
704
705 __kernel void m08700_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
706 {
707 }
708
709 __kernel void m08700_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
710 {
711 }