Upgrade kernel to support dynamic local work sizes
[hashcat.git] / OpenCL / m08700_a0.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _LOTUS6_
7
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
10
11 #define DGST_R0 0
12 #define DGST_R1 1
13 #define DGST_R2 2
14 #define DGST_R3 3
15
16 #include "include/kernel_functions.c"
17 #include "OpenCL/types_ocl.c"
18 #include "OpenCL/common.c"
19 #include "include/rp_kernel.h"
20 #include "OpenCL/rp.c"
21
22 #define COMPARE_S "OpenCL/check_single_comp4.c"
23 #define COMPARE_M "OpenCL/check_multi_comp4.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 #define uint_to_hex_upper8(i) l_bin2asc[(i)]
64
65 static void lotus_mix (u32 *in, __local u32 s_lotus_magic_table[256])
66 {
67   u32 p = 0;
68
69   for (int i = 0; i < 18; i++)
70   {
71     u32 s = 48;
72
73     #pragma unroll
74     for (int j = 0; j < 12; j++)
75     {
76       u32 tmp_in = in[j];
77       u32 tmp_out = 0;
78
79       p = (p + s--) & 0xff; p = ((tmp_in >>  0) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p <<  0;
80       p = (p + s--) & 0xff; p = ((tmp_in >>  8) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p <<  8;
81       p = (p + s--) & 0xff; p = ((tmp_in >> 16) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p << 16;
82       p = (p + s--) & 0xff; p = ((tmp_in >> 24) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p << 24;
83
84       in[j] = tmp_out;
85     }
86   }
87 }
88
89 static void lotus_transform_password (u32 in[4], u32 out[4], __local u32 s_lotus_magic_table[256])
90 {
91   u32 t = out[3] >> 24;
92
93   u32 c;
94
95   //#pragma unroll // kernel fails if used
96   for (int i = 0; i < 4; i++)
97   {
98     t ^= (in[i] >>  0) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c <<  0; t = ((out[i] >>  0) & 0xff);
99     t ^= (in[i] >>  8) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c <<  8; t = ((out[i] >>  8) & 0xff);
100     t ^= (in[i] >> 16) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c << 16; t = ((out[i] >> 16) & 0xff);
101     t ^= (in[i] >> 24) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c << 24; t = ((out[i] >> 24) & 0xff);
102   }
103 }
104
105 static void pad (u32 w[4], const u32 len)
106 {
107   const u32 val = 16 - len;
108
109   const u32 mask1 = val << 24;
110
111   const u32 mask2 = val << 16
112                    | val << 24;
113
114   const u32 mask3 = val <<  8
115                    | val << 16
116                    | val << 24;
117
118   const u32 mask4 = val <<  0
119                    | val <<  8
120                    | val << 16
121                    | val << 24;
122
123   switch (len)
124   {
125     case  0:  w[0]  = mask4;
126               w[1]  = mask4;
127               w[2]  = mask4;
128               w[3]  = mask4;
129               break;
130     case  1:  w[0] |= mask3;
131               w[1]  = mask4;
132               w[2]  = mask4;
133               w[3]  = mask4;
134               break;
135     case  2:  w[0] |= mask2;
136               w[1]  = mask4;
137               w[2]  = mask4;
138               w[3]  = mask4;
139               break;
140     case  3:  w[0] |= mask1;
141               w[1]  = mask4;
142               w[2]  = mask4;
143               w[3]  = mask4;
144               break;
145     case  4:  w[1]  = mask4;
146               w[2]  = mask4;
147               w[3]  = mask4;
148               break;
149     case  5:  w[1] |= mask3;
150               w[2]  = mask4;
151               w[3]  = mask4;
152               break;
153     case  6:  w[1] |= mask2;
154               w[2]  = mask4;
155               w[3]  = mask4;
156               break;
157     case  7:  w[1] |= mask1;
158               w[2]  = mask4;
159               w[3]  = mask4;
160               break;
161     case  8:  w[2]  = mask4;
162               w[3]  = mask4;
163               break;
164     case  9:  w[2] |= mask3;
165               w[3]  = mask4;
166               break;
167     case 10:  w[2] |= mask2;
168               w[3]  = mask4;
169               break;
170     case 11:  w[2] |= mask1;
171               w[3]  = mask4;
172               break;
173     case 12:  w[3]  = mask4;
174               break;
175     case 13:  w[3] |= mask3;
176               break;
177     case 14:  w[3] |= mask2;
178               break;
179     case 15:  w[3] |= mask1;
180               break;
181   }
182 }
183
184 static void mdtransform_norecalc (u32 state[4], u32 block[4], __local u32 s_lotus_magic_table[256])
185 {
186   u32 x[12];
187
188   x[ 0] = state[0];
189   x[ 1] = state[1];
190   x[ 2] = state[2];
191   x[ 3] = state[3];
192   x[ 4] = block[0];
193   x[ 5] = block[1];
194   x[ 6] = block[2];
195   x[ 7] = block[3];
196   x[ 8] = state[0] ^ block[0];
197   x[ 9] = state[1] ^ block[1];
198   x[10] = state[2] ^ block[2];
199   x[11] = state[3] ^ block[3];
200
201   lotus_mix (x, s_lotus_magic_table);
202
203   state[0] = x[0];
204   state[1] = x[1];
205   state[2] = x[2];
206   state[3] = x[3];
207 }
208
209 static void mdtransform (u32 state[4], u32 checksum[4], u32 block[4], __local u32 s_lotus_magic_table[256])
210 {
211   mdtransform_norecalc (state, block, s_lotus_magic_table);
212
213   lotus_transform_password (block, checksum, s_lotus_magic_table);
214 }
215
216 static void domino_big_md (const u32 saved_key[16], const u32 size, u32 state[4], __local u32 s_lotus_magic_table[256])
217 {
218   u32 checksum[4];
219
220   checksum[0] = 0;
221   checksum[1] = 0;
222   checksum[2] = 0;
223   checksum[3] = 0;
224
225   u32 block[4];
226
227   block[0] = 0;
228   block[1] = 0;
229   block[2] = 0;
230   block[3] = 0;
231
232   u32 curpos;
233   u32 idx;
234
235   for (curpos = 0, idx = 0; curpos + 16 < size; curpos += 16, idx += 4)
236   {
237     block[0] = saved_key[idx + 0];
238     block[1] = saved_key[idx + 1];
239     block[2] = saved_key[idx + 2];
240     block[3] = saved_key[idx + 3];
241
242     mdtransform (state, checksum, block, s_lotus_magic_table);
243   }
244
245   block[0] = saved_key[idx + 0];
246   block[1] = saved_key[idx + 1];
247   block[2] = saved_key[idx + 2];
248   block[3] = saved_key[idx + 3];
249
250   mdtransform (state, checksum, block, s_lotus_magic_table);
251
252   mdtransform_norecalc (state, checksum, s_lotus_magic_table);
253 }
254
255 __kernel void m08700_m04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
256 {
257   /**
258    * base
259    */
260
261   const u32 gid = get_global_id (0);
262   const u32 lid = get_local_id (0);
263   const u32 lsz = get_local_size (0);
264
265   /**
266    * sbox
267    */
268
269   __local u32 s_lotus_magic_table[256];
270
271   for (u32 i = lid; i < 256; i += lsz)
272   {
273     s_lotus_magic_table[i] = lotus_magic_table[i];
274   }
275
276   __local u32 l_bin2asc[256];
277
278   for (u32 i = lid; i < 256; i += lsz)
279   {
280     const u32 i0 = (i >> 0) & 15;
281     const u32 i1 = (i >> 4) & 15;
282
283     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
284                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
285   }
286
287   barrier (CLK_LOCAL_MEM_FENCE);
288
289   if (gid >= gid_max) return;
290
291   /**
292    * base
293    */
294
295   u32 pw_buf0[4];
296
297   pw_buf0[0] = pws[gid].i[ 0];
298   pw_buf0[1] = pws[gid].i[ 1];
299   pw_buf0[2] = pws[gid].i[ 2];
300   pw_buf0[3] = pws[gid].i[ 3];
301
302   u32 pw_buf1[4];
303
304   pw_buf1[0] = pws[gid].i[ 4];
305   pw_buf1[1] = pws[gid].i[ 5];
306   pw_buf1[2] = pws[gid].i[ 6];
307   pw_buf1[3] = pws[gid].i[ 7];
308
309   const u32 pw_len = pws[gid].pw_len;
310
311   /**
312    * salt
313    */
314
315   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
316   const u32 salt1 = salt_bufs[salt_pos].salt_buf[1] & 0xff | '(' << 8;
317
318   /**
319    * loop
320    */
321
322   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
323   {
324     u32 w0[4];
325
326     w0[0] = pw_buf0[0];
327     w0[1] = pw_buf0[1];
328     w0[2] = pw_buf0[2];
329     w0[3] = pw_buf0[3];
330
331     u32 w1[4];
332
333     w1[0] = pw_buf1[0];
334     w1[1] = pw_buf1[1];
335     w1[2] = pw_buf1[2];
336     w1[3] = pw_buf1[3];
337
338     u32 w2[4];
339
340     w2[0] = 0;
341     w2[1] = 0;
342     w2[2] = 0;
343     w2[3] = 0;
344
345     u32 w3[4];
346
347     w3[0] = 0;
348     w3[1] = 0;
349     w3[2] = 0;
350     w3[3] = 0;
351
352     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
353
354     u32 w[16];
355
356     w[ 0] = w0[0];
357     w[ 1] = w0[1];
358     w[ 2] = w0[2];
359     w[ 3] = w0[3];
360     w[ 4] = w1[0];
361     w[ 5] = w1[1];
362     w[ 6] = w1[2];
363     w[ 7] = w1[3];
364     w[ 8] = w2[0];
365     w[ 9] = w2[1];
366     w[10] = w2[2];
367     w[11] = w2[3];
368     w[12] = w3[0];
369     w[13] = w3[1];
370     w[14] = w3[2];
371     w[15] = w3[3];
372
373     u32 state[4];
374
375     state[0] = 0;
376     state[1] = 0;
377     state[2] = 0;
378     state[3] = 0;
379
380     /**
381      * padding
382      */
383
384     if (pw_len < 16)
385     {
386       pad (&w[ 0], pw_len & 0xf);
387     }
388     else if (pw_len < 32)
389     {
390       pad (&w[ 4], pw_len & 0xf);
391     }
392     else if (pw_len < 48)
393     {
394       pad (&w[ 8], pw_len & 0xf);
395     }
396     else if (pw_len < 64)
397     {
398       pad (&w[12], pw_len & 0xf);
399     }
400
401     domino_big_md (w, pw_len, state, s_lotus_magic_table);
402
403     const u32 w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
404                      | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
405     const u32 w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
406                      | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
407     const u32 w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
408                      | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
409     const u32 w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
410                      | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
411     const u32 w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
412                      | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
413     const u32 w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
414                      | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
415     const u32 w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
416                      | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
417     //const u32 w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
418     //                 | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
419
420     const u32 pade = 0x0e0e0e0e;
421
422     w[ 0] = salt0;
423     w[ 1] = salt1      | w0_t << 16;
424     w[ 2] = w0_t >> 16 | w1_t << 16;
425     w[ 3] = w1_t >> 16 | w2_t << 16;
426     w[ 4] = w2_t >> 16 | w3_t << 16;
427     w[ 5] = w3_t >> 16 | w4_t << 16;
428     w[ 6] = w4_t >> 16 | w5_t << 16;
429     w[ 7] = w5_t >> 16 | w6_t << 16;
430     w[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
431     w[ 9] = pade;
432     w[10] = pade;
433     w[11] = pade;
434     w[12] = 0;
435     w[13] = 0;
436     w[14] = 0;
437     w[15] = 0;
438
439     state[0] = 0;
440     state[1] = 0;
441     state[2] = 0;
442     state[3] = 0;
443
444     domino_big_md (w, 34, state, s_lotus_magic_table);
445
446     u32 a = state[0] & 0xffffffff;
447     u32 b = state[1] & 0xffffffff;
448     u32 c = state[2] & 0x000000ff;
449     u32 d = state[3] & 0x00000000;
450
451     const u32 r0 = a;
452     const u32 r1 = b;
453     const u32 r2 = c;
454     const u32 r3 = d;
455
456     #include COMPARE_M
457   }
458 }
459
460 __kernel void m08700_m08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
461 {
462 }
463
464 __kernel void m08700_m16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
465 {
466 }
467
468 __kernel void m08700_s04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
469 {
470   /**
471    * base
472    */
473
474   const u32 gid = get_global_id (0);
475   const u32 lid = get_local_id (0);
476   const u32 lsz = get_local_size (0);
477
478   /**
479    * sbox
480    */
481
482   __local u32 s_lotus_magic_table[256];
483
484   for (u32 i = lid; i < 256; i += lsz)
485   {
486     s_lotus_magic_table[i] = lotus_magic_table[i];
487   }
488
489   __local u32 l_bin2asc[256];
490
491   for (u32 i = lid; i < 256; i += lsz)
492   {
493     const u32 i0 = (i >> 0) & 15;
494     const u32 i1 = (i >> 4) & 15;
495
496     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
497                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
498   }
499
500   barrier (CLK_LOCAL_MEM_FENCE);
501
502   if (gid >= gid_max) return;
503
504   /**
505    * base
506    */
507
508   u32 pw_buf0[4];
509
510   pw_buf0[0] = pws[gid].i[ 0];
511   pw_buf0[1] = pws[gid].i[ 1];
512   pw_buf0[2] = pws[gid].i[ 2];
513   pw_buf0[3] = pws[gid].i[ 3];
514
515   u32 pw_buf1[4];
516
517   pw_buf1[0] = pws[gid].i[ 4];
518   pw_buf1[1] = pws[gid].i[ 5];
519   pw_buf1[2] = pws[gid].i[ 6];
520   pw_buf1[3] = pws[gid].i[ 7];
521
522   const u32 pw_len = pws[gid].pw_len;
523
524   /**
525    * salt
526    */
527
528   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
529   const u32 salt1 = salt_bufs[salt_pos].salt_buf[1] & 0xff | '(' << 8;
530
531   /**
532    * digest
533    */
534
535   const u32 search[4] =
536   {
537     digests_buf[digests_offset].digest_buf[DGST_R0],
538     digests_buf[digests_offset].digest_buf[DGST_R1],
539     digests_buf[digests_offset].digest_buf[DGST_R2],
540     digests_buf[digests_offset].digest_buf[DGST_R3]
541   };
542
543   /**
544    * loop
545    */
546
547   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
548   {
549     u32 w0[4];
550
551     w0[0] = pw_buf0[0];
552     w0[1] = pw_buf0[1];
553     w0[2] = pw_buf0[2];
554     w0[3] = pw_buf0[3];
555
556     u32 w1[4];
557
558     w1[0] = pw_buf1[0];
559     w1[1] = pw_buf1[1];
560     w1[2] = pw_buf1[2];
561     w1[3] = pw_buf1[3];
562
563     u32 w2[4];
564
565     w2[0] = 0;
566     w2[1] = 0;
567     w2[2] = 0;
568     w2[3] = 0;
569
570     u32 w3[4];
571
572     w3[0] = 0;
573     w3[1] = 0;
574     w3[2] = 0;
575     w3[3] = 0;
576
577     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
578
579     u32 w[16];
580
581     w[ 0] = w0[0];
582     w[ 1] = w0[1];
583     w[ 2] = w0[2];
584     w[ 3] = w0[3];
585     w[ 4] = w1[0];
586     w[ 5] = w1[1];
587     w[ 6] = w1[2];
588     w[ 7] = w1[3];
589     w[ 8] = w2[0];
590     w[ 9] = w2[1];
591     w[10] = w2[2];
592     w[11] = w2[3];
593     w[12] = w3[0];
594     w[13] = w3[1];
595     w[14] = w3[2];
596     w[15] = w3[3];
597
598     u32 state[4];
599
600     state[0] = 0;
601     state[1] = 0;
602     state[2] = 0;
603     state[3] = 0;
604
605     /**
606      * padding
607      */
608
609     if (pw_len < 16)
610     {
611       pad (&w[ 0], pw_len & 0xf);
612     }
613     else if (pw_len < 32)
614     {
615       pad (&w[ 4], pw_len & 0xf);
616     }
617     else if (pw_len < 48)
618     {
619       pad (&w[ 8], pw_len & 0xf);
620     }
621     else if (pw_len < 64)
622     {
623       pad (&w[12], pw_len & 0xf);
624     }
625
626     domino_big_md (w, pw_len, state, s_lotus_magic_table);
627
628     const u32 w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
629                      | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
630     const u32 w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
631                      | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
632     const u32 w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
633                      | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
634     const u32 w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
635                      | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
636     const u32 w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
637                      | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
638     const u32 w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
639                      | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
640     const u32 w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
641                      | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
642     //const u32 w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
643     //                 | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
644
645     const u32 pade = 0x0e0e0e0e;
646
647     w[ 0] = salt0;
648     w[ 1] = salt1      | w0_t << 16;
649     w[ 2] = w0_t >> 16 | w1_t << 16;
650     w[ 3] = w1_t >> 16 | w2_t << 16;
651     w[ 4] = w2_t >> 16 | w3_t << 16;
652     w[ 5] = w3_t >> 16 | w4_t << 16;
653     w[ 6] = w4_t >> 16 | w5_t << 16;
654     w[ 7] = w5_t >> 16 | w6_t << 16;
655     w[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
656     w[ 9] = pade;
657     w[10] = pade;
658     w[11] = pade;
659     w[12] = 0;
660     w[13] = 0;
661     w[14] = 0;
662     w[15] = 0;
663
664     state[0] = 0;
665     state[1] = 0;
666     state[2] = 0;
667     state[3] = 0;
668
669     domino_big_md (w, 34, state, s_lotus_magic_table);
670
671     u32 a = state[0] & 0xffffffff;
672     u32 b = state[1] & 0xffffffff;
673     u32 c = state[2] & 0x000000ff;
674     u32 d = state[3] & 0x00000000;
675
676     const u32 r0 = a;
677     const u32 r1 = b;
678     const u32 r2 = c;
679     const u32 r3 = d;
680
681     #include COMPARE_S
682   }
683 }
684
685 __kernel void m08700_s08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
686 {
687 }
688
689 __kernel void m08700_s16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
690 {
691 }