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