Merge pull request #183 from gm4tr1x/updateTestScript
[hashcat.git] / OpenCL / m08700_a3.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 #define NEW_SIMD_CODE
11
12 #include "include/constants.h"
13 #include "include/kernel_vendor.h"
14
15 #define DGST_R0 0
16 #define DGST_R1 1
17 #define DGST_R2 2
18 #define DGST_R3 3
19
20 #include "include/kernel_functions.c"
21 #include "OpenCL/types_ocl.c"
22 #include "OpenCL/common.c"
23 #include "OpenCL/simd.c"
24
25 __constant u32 lotus_magic_table[256] =
26 {
27   0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
28   0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
29   0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
30   0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
31   0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
32   0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
33   0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
34   0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
35   0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
36   0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
37   0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
38   0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
39   0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
40   0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
41   0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
42   0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
43   0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
44   0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
45   0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
46   0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
47   0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
48   0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
49   0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
50   0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
51   0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
52   0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
53   0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
54   0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
55   0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
56   0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
57   0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
58   0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab,
59 };
60
61 #define BOX(S,i) (S)[(i)]
62
63 #if   VECT_SIZE == 1
64 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i)])
65 #elif VECT_SIZE == 2
66 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1])
67 #elif VECT_SIZE == 4
68 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3])
69 #elif VECT_SIZE == 8
70 #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])
71 #endif
72
73 #if   VECT_SIZE == 1
74 #define BOX1(S,i) (S)[(i)]
75 #elif VECT_SIZE == 2
76 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1])
77 #elif VECT_SIZE == 4
78 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3])
79 #elif VECT_SIZE == 8
80 #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])
81 #endif
82
83 static void lotus_mix (u32x *in, __local u32 *s_lotus_magic_table)
84 {
85   u32x p = 0;
86
87   for (int i = 0; i < 18; i++)
88   {
89     u32 s = 48;
90
91     #pragma unroll 12
92     for (int j = 0; j < 12; j++)
93     {
94       u32x tmp_in = in[j];
95       u32x tmp_out = 0;
96
97       p = (p + s--) & 0xff; p = ((tmp_in >>  0) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  0;
98       p = (p + s--) & 0xff; p = ((tmp_in >>  8) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  8;
99       p = (p + s--) & 0xff; p = ((tmp_in >> 16) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 16;
100       p = (p + s--) & 0xff; p = ((tmp_in >> 24) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 24;
101
102       in[j] = tmp_out;
103     }
104   }
105 }
106
107 static void lotus_transform_password (u32x in[4], u32x out[4], __local u32 *s_lotus_magic_table)
108 {
109   u32x t = out[3] >> 24;
110
111   u32x c;
112
113   #pragma unroll 4
114   for (int i = 0; i < 4; i++)
115   {
116     t ^= (in[i] >>  0) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  0; t = ((out[i] >>  0) & 0xff);
117     t ^= (in[i] >>  8) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  8; t = ((out[i] >>  8) & 0xff);
118     t ^= (in[i] >> 16) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 16; t = ((out[i] >> 16) & 0xff);
119     t ^= (in[i] >> 24) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 24; t = ((out[i] >> 24) & 0xff);
120   }
121 }
122
123 static void pad (u32 w[4], const u32 len)
124 {
125   const u32 val = 16 - len;
126
127   const u32 mask1 = val << 24;
128
129   const u32 mask2 = val << 16
130                    | val << 24;
131
132   const u32 mask3 = val <<  8
133                    | val << 16
134                    | val << 24;
135
136   const u32 mask4 = val <<  0
137                    | val <<  8
138                    | val << 16
139                    | val << 24;
140
141   switch (len)
142   {
143     case  0:  w[0]  = mask4;
144               w[1]  = mask4;
145               w[2]  = mask4;
146               w[3]  = mask4;
147               break;
148     case  1:  w[0] |= mask3;
149               w[1]  = mask4;
150               w[2]  = mask4;
151               w[3]  = mask4;
152               break;
153     case  2:  w[0] |= mask2;
154               w[1]  = mask4;
155               w[2]  = mask4;
156               w[3]  = mask4;
157               break;
158     case  3:  w[0] |= mask1;
159               w[1]  = mask4;
160               w[2]  = mask4;
161               w[3]  = mask4;
162               break;
163     case  4:  w[1]  = mask4;
164               w[2]  = mask4;
165               w[3]  = mask4;
166               break;
167     case  5:  w[1] |= mask3;
168               w[2]  = mask4;
169               w[3]  = mask4;
170               break;
171     case  6:  w[1] |= mask2;
172               w[2]  = mask4;
173               w[3]  = mask4;
174               break;
175     case  7:  w[1] |= mask1;
176               w[2]  = mask4;
177               w[3]  = mask4;
178               break;
179     case  8:  w[2]  = mask4;
180               w[3]  = mask4;
181               break;
182     case  9:  w[2] |= mask3;
183               w[3]  = mask4;
184               break;
185     case 10:  w[2] |= mask2;
186               w[3]  = mask4;
187               break;
188     case 11:  w[2] |= mask1;
189               w[3]  = mask4;
190               break;
191     case 12:  w[3]  = mask4;
192               break;
193     case 13:  w[3] |= mask3;
194               break;
195     case 14:  w[3] |= mask2;
196               break;
197     case 15:  w[3] |= mask1;
198               break;
199   }
200 }
201
202 static void mdtransform_norecalc (u32x state[4], u32x block[4], __local u32 *s_lotus_magic_table)
203 {
204   u32x x[12];
205
206   x[ 0] = state[0];
207   x[ 1] = state[1];
208   x[ 2] = state[2];
209   x[ 3] = state[3];
210   x[ 4] = block[0];
211   x[ 5] = block[1];
212   x[ 6] = block[2];
213   x[ 7] = block[3];
214   x[ 8] = state[0] ^ block[0];
215   x[ 9] = state[1] ^ block[1];
216   x[10] = state[2] ^ block[2];
217   x[11] = state[3] ^ block[3];
218
219   lotus_mix (x, s_lotus_magic_table);
220
221   state[0] = x[0];
222   state[1] = x[1];
223   state[2] = x[2];
224   state[3] = x[3];
225 }
226
227 static void mdtransform (u32x state[4], u32x checksum[4], u32x block[4], __local u32 *s_lotus_magic_table)
228 {
229   mdtransform_norecalc (state, block, s_lotus_magic_table);
230
231   lotus_transform_password (block, checksum, s_lotus_magic_table);
232 }
233
234 static void domino_big_md (const u32x saved_key[16], const u32 size, u32x state[4], __local u32 *s_lotus_magic_table)
235 {
236   u32x checksum[4];
237
238   checksum[0] = 0;
239   checksum[1] = 0;
240   checksum[2] = 0;
241   checksum[3] = 0;
242
243   u32x block[4];
244
245   block[0] = 0;
246   block[1] = 0;
247   block[2] = 0;
248   block[3] = 0;
249
250   u32 curpos;
251   u32 idx;
252
253   for (curpos = 0, idx = 0; curpos + 16 < size; curpos += 16, idx += 4)
254   {
255     block[0] = saved_key[idx + 0];
256     block[1] = saved_key[idx + 1];
257     block[2] = saved_key[idx + 2];
258     block[3] = saved_key[idx + 3];
259
260     mdtransform (state, checksum, block, s_lotus_magic_table);
261   }
262
263   block[0] = saved_key[idx + 0];
264   block[1] = saved_key[idx + 1];
265   block[2] = saved_key[idx + 2];
266   block[3] = saved_key[idx + 3];
267
268   mdtransform (state, checksum, block, s_lotus_magic_table);
269
270   mdtransform_norecalc (state, checksum, s_lotus_magic_table);
271 }
272
273 static void m08700m (__local u32 *s_lotus_magic_table, __local u32 *l_bin2asc, u32 w[16], const u32 pw_len, __global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset)
274 {
275   /**
276    * modifier
277    */
278
279   const u32 gid = get_global_id (0);
280   const u32 lid = get_local_id (0);
281
282   /**
283    * padding
284    */
285
286   if (pw_len < 16)
287   {
288     pad (&w[ 0], pw_len & 0xf);
289   }
290   else if (pw_len < 32)
291   {
292     pad (&w[ 4], pw_len & 0xf);
293   }
294   else if (pw_len < 48)
295   {
296     pad (&w[ 8], pw_len & 0xf);
297   }
298   else if (pw_len < 64)
299   {
300     pad (&w[12], pw_len & 0xf);
301   }
302
303   /**
304    * salt
305    */
306
307   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
308   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
309
310   /**
311    * loop
312    */
313
314   u32 w0l = w[0];
315
316   for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos += VECT_SIZE)
317   {
318     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
319
320     const u32x w0 = w0l | w0r;
321
322     u32x w_tmp[16];
323
324     w_tmp[ 0] = w0;
325     w_tmp[ 1] = w[ 1];
326     w_tmp[ 2] = w[ 2];
327     w_tmp[ 3] = w[ 3];
328     w_tmp[ 4] = w[ 4];
329     w_tmp[ 5] = w[ 5];
330     w_tmp[ 6] = w[ 6];
331     w_tmp[ 7] = w[ 7];
332     w_tmp[ 8] = w[ 8];
333     w_tmp[ 9] = w[ 9];
334     w_tmp[10] = w[10];
335     w_tmp[11] = w[11];
336     w_tmp[12] = w[12];
337     w_tmp[13] = w[13];
338     w_tmp[14] = w[14];
339     w_tmp[15] = w[15];
340
341     u32x state[4];
342
343     state[0] = 0;
344     state[1] = 0;
345     state[2] = 0;
346     state[3] = 0;
347
348     domino_big_md (w_tmp, pw_len, state, s_lotus_magic_table);
349
350     const u32x w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
351                     | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
352     const u32x w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
353                     | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
354     const u32x w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
355                     | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
356     const u32x w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
357                     | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
358     const u32x w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
359                     | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
360     const u32x w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
361                     | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
362     const u32x w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
363                     | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
364     //const u32x w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
365     //                | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
366
367     const u32x pade = 0x0e0e0e0e;
368
369     w_tmp[ 0] = salt0;
370     w_tmp[ 1] = salt1      | w0_t << 16;
371     w_tmp[ 2] = w0_t >> 16 | w1_t << 16;
372     w_tmp[ 3] = w1_t >> 16 | w2_t << 16;
373     w_tmp[ 4] = w2_t >> 16 | w3_t << 16;
374     w_tmp[ 5] = w3_t >> 16 | w4_t << 16;
375     w_tmp[ 6] = w4_t >> 16 | w5_t << 16;
376     w_tmp[ 7] = w5_t >> 16 | w6_t << 16;
377     w_tmp[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
378     w_tmp[ 9] = pade;
379     w_tmp[10] = pade;
380     w_tmp[11] = pade;
381     w_tmp[12] = 0;
382     w_tmp[13] = 0;
383     w_tmp[14] = 0;
384     w_tmp[15] = 0;
385
386     state[0] = 0;
387     state[1] = 0;
388     state[2] = 0;
389     state[3] = 0;
390
391     domino_big_md (w_tmp, 34, state, s_lotus_magic_table);
392
393     u32x a = state[0] & 0xffffffff;
394     u32x b = state[1] & 0xffffffff;
395     u32x c = state[2] & 0x000000ff;
396     u32x d = state[3] & 0x00000000;
397
398     COMPARE_M_SIMD (a, b, c, d);
399   }
400 }
401
402 static void m08700s (__local u32 *s_lotus_magic_table, __local u32 *l_bin2asc, u32 w[16], const u32 pw_len, __global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset)
403 {
404   /**
405    * modifier
406    */
407
408   const u32 gid = get_global_id (0);
409   const u32 lid = get_local_id (0);
410
411   /**
412    * base
413    */
414
415   if (pw_len < 16)
416   {
417     pad (&w[ 0], pw_len & 0xf);
418   }
419   else if (pw_len < 32)
420   {
421     pad (&w[ 4], pw_len & 0xf);
422   }
423   else if (pw_len < 48)
424   {
425     pad (&w[ 8], pw_len & 0xf);
426   }
427   else if (pw_len < 64)
428   {
429     pad (&w[12], pw_len & 0xf);
430   }
431
432   /**
433    * salt
434    */
435
436   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
437   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
438
439   /**
440    * digest
441    */
442
443   const u32 search[4] =
444   {
445     digests_buf[digests_offset].digest_buf[DGST_R0],
446     digests_buf[digests_offset].digest_buf[DGST_R1],
447     digests_buf[digests_offset].digest_buf[DGST_R2],
448     digests_buf[digests_offset].digest_buf[DGST_R3]
449   };
450
451   /**
452    * loop
453    */
454
455   u32 w0l = w[0];
456
457   for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos += VECT_SIZE)
458   {
459     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
460
461     const u32x w0 = w0l | w0r;
462
463     u32x w_tmp[16];
464
465     w_tmp[ 0] = w0;
466     w_tmp[ 1] = w[ 1];
467     w_tmp[ 2] = w[ 2];
468     w_tmp[ 3] = w[ 3];
469     w_tmp[ 4] = w[ 4];
470     w_tmp[ 5] = w[ 5];
471     w_tmp[ 6] = w[ 6];
472     w_tmp[ 7] = w[ 7];
473     w_tmp[ 8] = w[ 8];
474     w_tmp[ 9] = w[ 9];
475     w_tmp[10] = w[10];
476     w_tmp[11] = w[11];
477     w_tmp[12] = w[12];
478     w_tmp[13] = w[13];
479     w_tmp[14] = w[14];
480     w_tmp[15] = w[15];
481
482     u32x state[4];
483
484     state[0] = 0;
485     state[1] = 0;
486     state[2] = 0;
487     state[3] = 0;
488
489     domino_big_md (w_tmp, pw_len, state, s_lotus_magic_table);
490
491     const u32x w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
492                     | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
493     const u32x w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
494                     | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
495     const u32x w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
496                     | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
497     const u32x w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
498                     | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
499     const u32x w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
500                     | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
501     const u32x w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
502                     | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
503     const u32x w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
504                     | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
505     //const u32x w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
506     //                | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
507
508     const u32x pade = 0x0e0e0e0e;
509
510     w_tmp[ 0] = salt0;
511     w_tmp[ 1] = salt1      | w0_t << 16;
512     w_tmp[ 2] = w0_t >> 16 | w1_t << 16;
513     w_tmp[ 3] = w1_t >> 16 | w2_t << 16;
514     w_tmp[ 4] = w2_t >> 16 | w3_t << 16;
515     w_tmp[ 5] = w3_t >> 16 | w4_t << 16;
516     w_tmp[ 6] = w4_t >> 16 | w5_t << 16;
517     w_tmp[ 7] = w5_t >> 16 | w6_t << 16;
518     w_tmp[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
519     w_tmp[ 9] = pade;
520     w_tmp[10] = pade;
521     w_tmp[11] = pade;
522     w_tmp[12] = 0;
523     w_tmp[13] = 0;
524     w_tmp[14] = 0;
525     w_tmp[15] = 0;
526
527     state[0] = 0;
528     state[1] = 0;
529     state[2] = 0;
530     state[3] = 0;
531
532     domino_big_md (w_tmp, 34, state, s_lotus_magic_table);
533
534     u32x a = state[0] & 0xffffffff;
535     u32x b = state[1] & 0xffffffff;
536     u32x c = state[2] & 0x000000ff;
537     u32x d = state[3] & 0x00000000;
538
539     COMPARE_S_SIMD (a, b, c, d);
540   }
541 }
542
543 __kernel void m08700_m04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
544 {
545   /**
546    * base
547    */
548
549   const u32 gid = get_global_id (0);
550   const u32 lid = get_local_id (0);
551   const u32 lsz = get_local_size (0);
552
553   /**
554    * sbox
555    */
556
557   __local u32 s_lotus_magic_table[256];
558
559   for (u32 i = lid; i < 256; i += lsz)
560   {
561     s_lotus_magic_table[i] = lotus_magic_table[i];
562   }
563
564   __local u32 l_bin2asc[256];
565
566   for (u32 i = lid; i < 256; i += lsz)
567   {
568     const u32 i0 = (i >> 0) & 15;
569     const u32 i1 = (i >> 4) & 15;
570
571     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
572                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
573   }
574
575   barrier (CLK_LOCAL_MEM_FENCE);
576
577   if (gid >= gid_max) return;
578
579   /**
580    * base
581    */
582
583   u32 w[16];
584
585   w[ 0] = pws[gid].i[ 0];
586   w[ 1] = pws[gid].i[ 1];
587   w[ 2] = pws[gid].i[ 2];
588   w[ 3] = pws[gid].i[ 3];
589   w[ 4] = 0;
590   w[ 5] = 0;
591   w[ 6] = 0;
592   w[ 7] = 0;
593   w[ 8] = 0;
594   w[ 9] = 0;
595   w[10] = 0;
596   w[11] = 0;
597   w[12] = 0;
598   w[13] = 0;
599   w[14] = 0;
600   w[15] = 0;
601
602   const u32 pw_len = pws[gid].pw_len;
603
604   /**
605    * main
606    */
607
608   m08700m (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, bfs_cnt, digests_cnt, digests_offset);
609 }
610
611 __kernel void m08700_m08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
612 {
613   /**
614    * base
615    */
616
617   const u32 gid = get_global_id (0);
618   const u32 lid = get_local_id (0);
619   const u32 lsz = get_local_size (0);
620
621   /**
622    * sbox
623    */
624
625   __local u32 s_lotus_magic_table[256];
626
627   for (u32 i = lid; i < 256; i += lsz)
628   {
629     s_lotus_magic_table[i] = lotus_magic_table[i];
630   }
631
632   __local u32 l_bin2asc[256];
633
634   for (u32 i = lid; i < 256; i += lsz)
635   {
636     const u32 i0 = (i >> 0) & 15;
637     const u32 i1 = (i >> 4) & 15;
638
639     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
640                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
641   }
642
643   barrier (CLK_LOCAL_MEM_FENCE);
644
645   if (gid >= gid_max) return;
646
647   /**
648    * base
649    */
650
651   u32 w[16];
652
653   w[ 0] = pws[gid].i[ 0];
654   w[ 1] = pws[gid].i[ 1];
655   w[ 2] = pws[gid].i[ 2];
656   w[ 3] = pws[gid].i[ 3];
657   w[ 4] = pws[gid].i[ 4];
658   w[ 5] = pws[gid].i[ 5];
659   w[ 6] = pws[gid].i[ 6];
660   w[ 7] = pws[gid].i[ 7];
661   w[ 8] = 0;
662   w[ 9] = 0;
663   w[10] = 0;
664   w[11] = 0;
665   w[12] = 0;
666   w[13] = 0;
667   w[14] = 0;
668   w[15] = 0;
669
670   const u32 pw_len = pws[gid].pw_len;
671
672   /**
673    * main
674    */
675
676   m08700m (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, bfs_cnt, digests_cnt, digests_offset);
677 }
678
679 __kernel void m08700_m16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
680 {
681   /**
682    * base
683    */
684
685   const u32 gid = get_global_id (0);
686   const u32 lid = get_local_id (0);
687   const u32 lsz = get_local_size (0);
688
689   /**
690    * sbox
691    */
692
693   __local u32 s_lotus_magic_table[256];
694
695   for (u32 i = lid; i < 256; i += lsz)
696   {
697     s_lotus_magic_table[i] = lotus_magic_table[i];
698   }
699
700   __local u32 l_bin2asc[256];
701
702   for (u32 i = lid; i < 256; i += lsz)
703   {
704     const u32 i0 = (i >> 0) & 15;
705     const u32 i1 = (i >> 4) & 15;
706
707     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
708                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
709   }
710
711   barrier (CLK_LOCAL_MEM_FENCE);
712
713   if (gid >= gid_max) return;
714
715   /**
716    * base
717    */
718
719   u32 w[16];
720
721   w[ 0] = pws[gid].i[ 0];
722   w[ 1] = pws[gid].i[ 1];
723   w[ 2] = pws[gid].i[ 2];
724   w[ 3] = pws[gid].i[ 3];
725   w[ 4] = pws[gid].i[ 4];
726   w[ 5] = pws[gid].i[ 5];
727   w[ 6] = pws[gid].i[ 6];
728   w[ 7] = pws[gid].i[ 7];
729   w[ 8] = pws[gid].i[ 8];
730   w[ 9] = pws[gid].i[ 9];
731   w[10] = pws[gid].i[10];
732   w[11] = pws[gid].i[11];
733   w[12] = pws[gid].i[12];
734   w[13] = pws[gid].i[13];
735   w[14] = pws[gid].i[14];
736   w[15] = pws[gid].i[15];
737
738   const u32 pw_len = pws[gid].pw_len;
739
740   /**
741    * main
742    */
743
744   m08700m (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, bfs_cnt, digests_cnt, digests_offset);
745 }
746
747 __kernel void m08700_s04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
748 {
749   /**
750    * base
751    */
752
753   const u32 gid = get_global_id (0);
754   const u32 lid = get_local_id (0);
755   const u32 lsz = get_local_size (0);
756
757   /**
758    * sbox
759    */
760
761   __local u32 s_lotus_magic_table[256];
762
763   for (u32 i = lid; i < 256; i += lsz)
764   {
765     s_lotus_magic_table[i] = lotus_magic_table[i];
766   }
767
768   __local u32 l_bin2asc[256];
769
770   for (u32 i = lid; i < 256; i += lsz)
771   {
772     const u32 i0 = (i >> 0) & 15;
773     const u32 i1 = (i >> 4) & 15;
774
775     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
776                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
777   }
778
779   barrier (CLK_LOCAL_MEM_FENCE);
780
781   if (gid >= gid_max) return;
782
783   /**
784    * base
785    */
786
787   u32 w[16];
788
789   w[ 0] = pws[gid].i[ 0];
790   w[ 1] = pws[gid].i[ 1];
791   w[ 2] = pws[gid].i[ 2];
792   w[ 3] = pws[gid].i[ 3];
793   w[ 4] = 0;
794   w[ 5] = 0;
795   w[ 6] = 0;
796   w[ 7] = 0;
797   w[ 8] = 0;
798   w[ 9] = 0;
799   w[10] = 0;
800   w[11] = 0;
801   w[12] = 0;
802   w[13] = 0;
803   w[14] = 0;
804   w[15] = 0;
805
806   const u32 pw_len = pws[gid].pw_len;
807
808   /**
809    * main
810    */
811
812   m08700s (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, bfs_cnt, digests_cnt, digests_offset);
813 }
814
815 __kernel void m08700_s08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
816 {
817   /**
818    * base
819    */
820
821   const u32 gid = get_global_id (0);
822   const u32 lid = get_local_id (0);
823   const u32 lsz = get_local_size (0);
824
825   /**
826    * sbox
827    */
828
829   __local u32 s_lotus_magic_table[256];
830
831   for (u32 i = lid; i < 256; i += lsz)
832   {
833     s_lotus_magic_table[i] = lotus_magic_table[i];
834   }
835
836   __local u32 l_bin2asc[256];
837
838   for (u32 i = lid; i < 256; i += lsz)
839   {
840     const u32 i0 = (i >> 0) & 15;
841     const u32 i1 = (i >> 4) & 15;
842
843     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
844                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
845   }
846
847   barrier (CLK_LOCAL_MEM_FENCE);
848
849   if (gid >= gid_max) return;
850
851   /**
852    * base
853    */
854
855   u32 w[16];
856
857   w[ 0] = pws[gid].i[ 0];
858   w[ 1] = pws[gid].i[ 1];
859   w[ 2] = pws[gid].i[ 2];
860   w[ 3] = pws[gid].i[ 3];
861   w[ 4] = pws[gid].i[ 4];
862   w[ 5] = pws[gid].i[ 5];
863   w[ 6] = pws[gid].i[ 6];
864   w[ 7] = pws[gid].i[ 7];
865   w[ 8] = 0;
866   w[ 9] = 0;
867   w[10] = 0;
868   w[11] = 0;
869   w[12] = 0;
870   w[13] = 0;
871   w[14] = 0;
872   w[15] = 0;
873
874   const u32 pw_len = pws[gid].pw_len;
875
876   /**
877    * main
878    */
879
880   m08700s (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, bfs_cnt, digests_cnt, digests_offset);
881 }
882
883 __kernel void m08700_s16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
884 {
885   /**
886    * base
887    */
888
889   const u32 gid = get_global_id (0);
890   const u32 lid = get_local_id (0);
891   const u32 lsz = get_local_size (0);
892
893   /**
894    * sbox
895    */
896
897   __local u32 s_lotus_magic_table[256];
898
899   for (u32 i = lid; i < 256; i += lsz)
900   {
901     s_lotus_magic_table[i] = lotus_magic_table[i];
902   }
903
904   __local u32 l_bin2asc[256];
905
906   for (u32 i = lid; i < 256; i += lsz)
907   {
908     const u32 i0 = (i >> 0) & 15;
909     const u32 i1 = (i >> 4) & 15;
910
911     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
912                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
913   }
914
915   barrier (CLK_LOCAL_MEM_FENCE);
916
917   if (gid >= gid_max) return;
918
919   /**
920    * base
921    */
922
923   u32 w[16];
924
925   w[ 0] = pws[gid].i[ 0];
926   w[ 1] = pws[gid].i[ 1];
927   w[ 2] = pws[gid].i[ 2];
928   w[ 3] = pws[gid].i[ 3];
929   w[ 4] = pws[gid].i[ 4];
930   w[ 5] = pws[gid].i[ 5];
931   w[ 6] = pws[gid].i[ 6];
932   w[ 7] = pws[gid].i[ 7];
933   w[ 8] = pws[gid].i[ 8];
934   w[ 9] = pws[gid].i[ 9];
935   w[10] = pws[gid].i[10];
936   w[11] = pws[gid].i[11];
937   w[12] = pws[gid].i[12];
938   w[13] = pws[gid].i[13];
939   w[14] = pws[gid].i[14];
940   w[15] = pws[gid].i[15];
941
942   const u32 pw_len = pws[gid].pw_len;
943
944   /**
945    * main
946    */
947
948   m08700s (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, bfs_cnt, digests_cnt, digests_offset);
949 }