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