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