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