Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / OpenCL / m10400_a3.cl
1 /**
2  * Authors.....: Jens Steube <jens.steube@gmail.com>
3  *               Gabriele Gristina <matrix@hashcat.net>
4  *
5  * License.....: MIT
6  */
7
8 #define _MD5_
9
10 //too much register pressure
11 //#define NEW_SIMD_CODE
12
13 #include "inc_vendor.cl"
14 #include "inc_hash_constants.h"
15 #include "inc_hash_functions.cl"
16 #include "inc_types.cl"
17 #include "inc_common.cl"
18 #include "inc_simd.cl"
19
20 __constant u32 padding[8] =
21 {
22   0x5e4ebf28,
23   0x418a754e,
24   0x564e0064,
25   0x0801faff,
26   0xb6002e2e,
27   0x803e68d0,
28   0xfea90c2f,
29   0x7a695364
30 };
31
32 typedef struct
33 {
34   u8 S[256];
35
36   u32 wtf_its_faster;
37
38 } RC4_KEY;
39
40 void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
41 {
42   u8 tmp;
43
44   tmp           = rc4_key->S[i];
45   rc4_key->S[i] = rc4_key->S[j];
46   rc4_key->S[j] = tmp;
47 }
48
49 void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
50 {
51   u32 v = 0x03020100;
52   u32 a = 0x04040404;
53
54   __local u32 *ptr = (__local u32 *) rc4_key->S;
55
56   #ifdef _unroll
57   #pragma unroll
58   #endif
59   for (u32 i = 0; i < 64; i++)
60   {
61     ptr[i] = v; v += a;
62   }
63
64   const u32 d0 = data[0] >>  0;
65   const u32 d1 = data[0] >>  8;
66   const u32 d2 = data[0] >> 16;
67   const u32 d3 = data[0] >> 24;
68   const u32 d4 = data[1] >>  0;
69
70   u32 j = 0;
71
72   #ifdef _unroll
73   #pragma unroll
74   #endif
75   for (u32 i = 0; i < 255; i += 5)
76   {
77     j += rc4_key->S[i + 0] + d0; swap (rc4_key, i + 0, j);
78     j += rc4_key->S[i + 1] + d1; swap (rc4_key, i + 1, j);
79     j += rc4_key->S[i + 2] + d2; swap (rc4_key, i + 2, j);
80     j += rc4_key->S[i + 3] + d3; swap (rc4_key, i + 3, j);
81     j += rc4_key->S[i + 4] + d4; swap (rc4_key, i + 4, j);
82   }
83
84   j += rc4_key->S[255] + d0; swap (rc4_key, 255, j);
85 }
86
87 u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, __constant u32 *in, u32 out[4])
88 {
89   #ifdef _unroll
90   #pragma unroll
91   #endif
92   for (u32 k = 0; k < 4; k++)
93   {
94     u32 xor4 = 0;
95
96     u8 idx;
97
98     i += 1;
99     j += rc4_key->S[i];
100
101     swap (rc4_key, i, j);
102
103     idx = rc4_key->S[i] + rc4_key->S[j];
104
105     xor4 |= rc4_key->S[idx] <<  0;
106
107     i += 1;
108     j += rc4_key->S[i];
109
110     swap (rc4_key, i, j);
111
112     idx = rc4_key->S[i] + rc4_key->S[j];
113
114     xor4 |= rc4_key->S[idx] <<  8;
115
116     i += 1;
117     j += rc4_key->S[i];
118
119     swap (rc4_key, i, j);
120
121     idx = rc4_key->S[i] + rc4_key->S[j];
122
123     xor4 |= rc4_key->S[idx] << 16;
124
125     i += 1;
126     j += rc4_key->S[i];
127
128     swap (rc4_key, i, j);
129
130     idx = rc4_key->S[i] + rc4_key->S[j];
131
132     xor4 |= rc4_key->S[idx] << 24;
133
134     out[k] = in[k] ^ xor4;
135   }
136
137   return j;
138 }
139
140 void md5_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[4])
141 {
142   u32 a = digest[0];
143   u32 b = digest[1];
144   u32 c = digest[2];
145   u32 d = digest[3];
146
147   u32 w0_t = w0[0];
148   u32 w1_t = w0[1];
149   u32 w2_t = w0[2];
150   u32 w3_t = w0[3];
151   u32 w4_t = w1[0];
152   u32 w5_t = w1[1];
153   u32 w6_t = w1[2];
154   u32 w7_t = w1[3];
155   u32 w8_t = w2[0];
156   u32 w9_t = w2[1];
157   u32 wa_t = w2[2];
158   u32 wb_t = w2[3];
159   u32 wc_t = w3[0];
160   u32 wd_t = w3[1];
161   u32 we_t = w3[2];
162   u32 wf_t = w3[3];
163
164   MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
165   MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
166   MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
167   MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
168   MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
169   MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
170   MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
171   MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
172   MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
173   MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
174   MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
175   MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
176   MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
177   MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
178   MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
179   MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
180
181   MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
182   MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
183   MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
184   MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
185   MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
186   MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
187   MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
188   MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
189   MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
190   MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
191   MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
192   MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
193   MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
194   MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
195   MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
196   MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
197
198   MD5_STEP (MD5_H , a, b, c, d, w5_t, MD5C20, MD5S20);
199   MD5_STEP (MD5_H , d, a, b, c, w8_t, MD5C21, MD5S21);
200   MD5_STEP (MD5_H , c, d, a, b, wb_t, MD5C22, MD5S22);
201   MD5_STEP (MD5_H , b, c, d, a, we_t, MD5C23, MD5S23);
202   MD5_STEP (MD5_H , a, b, c, d, w1_t, MD5C24, MD5S20);
203   MD5_STEP (MD5_H , d, a, b, c, w4_t, MD5C25, MD5S21);
204   MD5_STEP (MD5_H , c, d, a, b, w7_t, MD5C26, MD5S22);
205   MD5_STEP (MD5_H , b, c, d, a, wa_t, MD5C27, MD5S23);
206   MD5_STEP (MD5_H , a, b, c, d, wd_t, MD5C28, MD5S20);
207   MD5_STEP (MD5_H , d, a, b, c, w0_t, MD5C29, MD5S21);
208   MD5_STEP (MD5_H , c, d, a, b, w3_t, MD5C2a, MD5S22);
209   MD5_STEP (MD5_H , b, c, d, a, w6_t, MD5C2b, MD5S23);
210   MD5_STEP (MD5_H , a, b, c, d, w9_t, MD5C2c, MD5S20);
211   MD5_STEP (MD5_H , d, a, b, c, wc_t, MD5C2d, MD5S21);
212   MD5_STEP (MD5_H , c, d, a, b, wf_t, MD5C2e, MD5S22);
213   MD5_STEP (MD5_H , b, c, d, a, w2_t, MD5C2f, MD5S23);
214
215   MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
216   MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
217   MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
218   MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
219   MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
220   MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
221   MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
222   MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
223   MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
224   MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
225   MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
226   MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
227   MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
228   MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
229   MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
230   MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
231
232   digest[0] += a;
233   digest[1] += b;
234   digest[2] += c;
235   digest[3] += d;
236 }
237
238 void m10400m (__local RC4_KEY *rc4_keys, u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], const u32 pw_len, __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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset)
239 {
240   /**
241    * modifier
242    */
243
244   const u32 gid = get_global_id (0);
245   const u32 lid = get_local_id (0);
246
247   /**
248    * shared
249    */
250
251   __local RC4_KEY *rc4_key = &rc4_keys[lid];
252
253   /**
254    * U_buf
255    */
256
257   u32 o_buf[8];
258
259   o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
260   o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
261   o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
262   o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
263   o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
264   o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
265   o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
266   o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
267
268   u32 P = pdf_bufs[salt_pos].P;
269
270   u32 id_buf[4];
271
272   id_buf[0] = pdf_bufs[salt_pos].id_buf[0];
273   id_buf[1] = pdf_bufs[salt_pos].id_buf[1];
274   id_buf[2] = pdf_bufs[salt_pos].id_buf[2];
275   id_buf[3] = pdf_bufs[salt_pos].id_buf[3];
276
277   u32 p0[4];
278   u32 p1[4];
279   u32 p2[4];
280   u32 p3[4];
281
282   p0[0] = padding[0];
283   p0[1] = padding[1];
284   p0[2] = padding[2];
285   p0[3] = padding[3];
286   p1[0] = padding[4];
287   p1[1] = padding[5];
288   p1[2] = padding[6];
289   p1[3] = padding[7];
290   p2[0] = 0;
291   p2[1] = 0;
292   p2[2] = 0;
293   p2[3] = 0;
294   p3[0] = 0;
295   p3[1] = 0;
296   p3[2] = 0;
297   p3[3] = 0;
298
299   switch_buffer_by_offset_le (p0, p1, p2, p3, pw_len);
300
301   w0[0] |= p0[0];
302   w0[1] |= p0[1];
303   w0[2] |= p0[2];
304   w0[3] |= p0[3];
305   w1[0] |= p1[0];
306   w1[1] |= p1[1];
307   w1[2] |= p1[2];
308   w1[3] |= p1[3];
309   w2[0] |= p2[0];
310   w2[1] |= p2[1];
311   w2[2] |= p2[2];
312   w2[3] |= p2[3];
313   w3[0] |= p3[0];
314   w3[1] |= p3[1];
315   w3[2] |= p3[2];
316   w3[3] |= p3[3];
317
318   /**
319    * loop
320    */
321
322   u32 w0l = w0[0];
323
324   for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
325   {
326     const u32 w0r = ix_create_bft (bfs_buf, il_pos);
327
328     w0[0] = w0l | w0r;
329
330     /**
331      * pdf
332      */
333
334     u32 w0_t[4];
335     u32 w1_t[4];
336     u32 w2_t[4];
337     u32 w3_t[4];
338
339     // add password
340     // truncate at 32 is wanted, not a bug!
341     // add o_buf
342
343     w0_t[0] = w0[0];
344     w0_t[1] = w0[1];
345     w0_t[2] = w0[2];
346     w0_t[3] = w0[3];
347     w1_t[0] = w1[0];
348     w1_t[1] = w1[1];
349     w1_t[2] = w1[2];
350     w1_t[3] = w1[3];
351     w2_t[0] = o_buf[0];
352     w2_t[1] = o_buf[1];
353     w2_t[2] = o_buf[2];
354     w2_t[3] = o_buf[3];
355     w3_t[0] = o_buf[4];
356     w3_t[1] = o_buf[5];
357     w3_t[2] = o_buf[6];
358     w3_t[3] = o_buf[7];
359
360     u32 digest[4];
361
362     digest[0] = MD5M_A;
363     digest[1] = MD5M_B;
364     digest[2] = MD5M_C;
365     digest[3] = MD5M_D;
366
367     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
368
369     w0_t[0] = P;
370     w0_t[1] = id_buf[0];
371     w0_t[2] = id_buf[1];
372     w0_t[3] = id_buf[2];
373     w1_t[0] = id_buf[3];
374     w1_t[1] = 0x80;
375     w1_t[2] = 0;
376     w1_t[3] = 0;
377     w2_t[0] = 0;
378     w2_t[1] = 0;
379     w2_t[2] = 0;
380     w2_t[3] = 0;
381     w3_t[0] = 0;
382     w3_t[1] = 0;
383     w3_t[2] = 84 * 8;
384     w3_t[3] = 0;
385
386     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
387
388     // now the RC4 part
389
390     digest[1] = digest[1] & 0xff;
391     digest[2] = 0;
392     digest[3] = 0;
393
394     rc4_init_16 (rc4_key, digest);
395
396     u32 out[4];
397
398     rc4_next_16 (rc4_key, 0, 0, padding, out);
399
400     COMPARE_M_SIMD (out[0], out[1], out[2], out[3]);
401   }
402 }
403
404 void m10400s (__local RC4_KEY *rc4_keys, u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], const u32 pw_len, __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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset)
405 {
406   /**
407    * modifier
408    */
409
410   const u32 gid = get_global_id (0);
411   const u32 lid = get_local_id (0);
412
413   /**
414    * shared
415    */
416
417   __local RC4_KEY *rc4_key = &rc4_keys[lid];
418
419   /**
420    * U_buf
421    */
422
423   u32 o_buf[8];
424
425   o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
426   o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
427   o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
428   o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
429   o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
430   o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
431   o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
432   o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
433
434   u32 P = pdf_bufs[salt_pos].P;
435
436   u32 id_buf[4];
437
438   id_buf[0] = pdf_bufs[salt_pos].id_buf[0];
439   id_buf[1] = pdf_bufs[salt_pos].id_buf[1];
440   id_buf[2] = pdf_bufs[salt_pos].id_buf[2];
441   id_buf[3] = pdf_bufs[salt_pos].id_buf[3];
442
443   u32 p0[4];
444   u32 p1[4];
445   u32 p2[4];
446   u32 p3[4];
447
448   p0[0] = padding[0];
449   p0[1] = padding[1];
450   p0[2] = padding[2];
451   p0[3] = padding[3];
452   p1[0] = padding[4];
453   p1[1] = padding[5];
454   p1[2] = padding[6];
455   p1[3] = padding[7];
456   p2[0] = 0;
457   p2[1] = 0;
458   p2[2] = 0;
459   p2[3] = 0;
460   p3[0] = 0;
461   p3[1] = 0;
462   p3[2] = 0;
463   p3[3] = 0;
464
465   switch_buffer_by_offset_le (p0, p1, p2, p3, pw_len);
466
467   w0[0] |= p0[0];
468   w0[1] |= p0[1];
469   w0[2] |= p0[2];
470   w0[3] |= p0[3];
471   w1[0] |= p1[0];
472   w1[1] |= p1[1];
473   w1[2] |= p1[2];
474   w1[3] |= p1[3];
475   w2[0] |= p2[0];
476   w2[1] |= p2[1];
477   w2[2] |= p2[2];
478   w2[3] |= p2[3];
479   w3[0] |= p3[0];
480   w3[1] |= p3[1];
481   w3[2] |= p3[2];
482   w3[3] |= p3[3];
483
484   /**
485    * digest
486    */
487
488   const u32 search[4] =
489   {
490     digests_buf[digests_offset].digest_buf[DGST_R0],
491     digests_buf[digests_offset].digest_buf[DGST_R1],
492     digests_buf[digests_offset].digest_buf[DGST_R2],
493     digests_buf[digests_offset].digest_buf[DGST_R3]
494   };
495
496   /**
497    * loop
498    */
499
500   u32 w0l = w0[0];
501
502   for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
503   {
504     const u32 w0r = ix_create_bft (bfs_buf, il_pos);
505
506     w0[0] = w0l | w0r;
507
508     /**
509      * pdf
510      */
511
512     u32 w0_t[4];
513     u32 w1_t[4];
514     u32 w2_t[4];
515     u32 w3_t[4];
516
517     // add password
518     // truncate at 32 is wanted, not a bug!
519     // add o_buf
520
521     w0_t[0] = w0[0];
522     w0_t[1] = w0[1];
523     w0_t[2] = w0[2];
524     w0_t[3] = w0[3];
525     w1_t[0] = w1[0];
526     w1_t[1] = w1[1];
527     w1_t[2] = w1[2];
528     w1_t[3] = w1[3];
529     w2_t[0] = o_buf[0];
530     w2_t[1] = o_buf[1];
531     w2_t[2] = o_buf[2];
532     w2_t[3] = o_buf[3];
533     w3_t[0] = o_buf[4];
534     w3_t[1] = o_buf[5];
535     w3_t[2] = o_buf[6];
536     w3_t[3] = o_buf[7];
537
538     u32 digest[4];
539
540     digest[0] = MD5M_A;
541     digest[1] = MD5M_B;
542     digest[2] = MD5M_C;
543     digest[3] = MD5M_D;
544
545     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
546
547     w0_t[0] = P;
548     w0_t[1] = id_buf[0];
549     w0_t[2] = id_buf[1];
550     w0_t[3] = id_buf[2];
551     w1_t[0] = id_buf[3];
552     w1_t[1] = 0x80;
553     w1_t[2] = 0;
554     w1_t[3] = 0;
555     w2_t[0] = 0;
556     w2_t[1] = 0;
557     w2_t[2] = 0;
558     w2_t[3] = 0;
559     w3_t[0] = 0;
560     w3_t[1] = 0;
561     w3_t[2] = 84 * 8;
562     w3_t[3] = 0;
563
564     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
565
566     // now the RC4 part
567
568     digest[1] = digest[1] & 0xff;
569     digest[2] = 0;
570     digest[3] = 0;
571
572     rc4_init_16 (rc4_key, digest);
573
574     u32 out[4];
575
576     rc4_next_16 (rc4_key, 0, 0, padding, out);
577
578     COMPARE_S_SIMD (out[0], out[1], out[2], out[3]);
579   }
580 }
581
582 __kernel void m10400_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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
583 {
584   /**
585    * base
586    */
587
588   const u32 gid = get_global_id (0);
589
590   if (gid >= gid_max) return;
591
592   u32 w0[4];
593
594   w0[0] = pws[gid].i[ 0];
595   w0[1] = pws[gid].i[ 1];
596   w0[2] = pws[gid].i[ 2];
597   w0[3] = pws[gid].i[ 3];
598
599   u32 w1[4];
600
601   w1[0] = 0;
602   w1[1] = 0;
603   w1[2] = 0;
604   w1[3] = 0;
605
606   u32 w2[4];
607
608   w2[0] = 0;
609   w2[1] = 0;
610   w2[2] = 0;
611   w2[3] = 0;
612
613   u32 w3[4];
614
615   w3[0] = 0;
616   w3[1] = 0;
617   w3[2] = 0;
618   w3[3] = 0;
619
620   const u32 pw_len = pws[gid].pw_len;
621
622   /**
623    * main
624    */
625
626   __local RC4_KEY rc4_keys[64];
627
628   m10400m (rc4_keys, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, 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, pdf_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
629 }
630
631 __kernel void m10400_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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
632 {
633   /**
634    * base
635    */
636
637   const u32 gid = get_global_id (0);
638
639   if (gid >= gid_max) return;
640
641   u32 w0[4];
642
643   w0[0] = pws[gid].i[ 0];
644   w0[1] = pws[gid].i[ 1];
645   w0[2] = pws[gid].i[ 2];
646   w0[3] = pws[gid].i[ 3];
647
648   u32 w1[4];
649
650   w1[0] = pws[gid].i[ 4];
651   w1[1] = pws[gid].i[ 5];
652   w1[2] = pws[gid].i[ 6];
653   w1[3] = pws[gid].i[ 7];
654
655   u32 w2[4];
656
657   w2[0] = 0;
658   w2[1] = 0;
659   w2[2] = 0;
660   w2[3] = 0;
661
662   u32 w3[4];
663
664   w3[0] = 0;
665   w3[1] = 0;
666   w3[2] = 0;
667   w3[3] = 0;
668
669   const u32 pw_len = pws[gid].pw_len;
670
671   /**
672    * main
673    */
674
675   __local RC4_KEY rc4_keys[64];
676
677   m10400m (rc4_keys, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, 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, pdf_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
678 }
679
680 __kernel void m10400_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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
681 {
682   /**
683    * base
684    */
685
686   const u32 gid = get_global_id (0);
687
688   if (gid >= gid_max) return;
689
690   u32 w0[4];
691
692   w0[0] = pws[gid].i[ 0];
693   w0[1] = pws[gid].i[ 1];
694   w0[2] = pws[gid].i[ 2];
695   w0[3] = pws[gid].i[ 3];
696
697   u32 w1[4];
698
699   w1[0] = pws[gid].i[ 4];
700   w1[1] = pws[gid].i[ 5];
701   w1[2] = pws[gid].i[ 6];
702   w1[3] = pws[gid].i[ 7];
703
704   u32 w2[4];
705
706   w2[0] = pws[gid].i[ 8];
707   w2[1] = pws[gid].i[ 9];
708   w2[2] = pws[gid].i[10];
709   w2[3] = pws[gid].i[11];
710
711   u32 w3[4];
712
713   w3[0] = pws[gid].i[12];
714   w3[1] = pws[gid].i[13];
715   w3[2] = 0;
716   w3[3] = 0;
717
718   const u32 pw_len = pws[gid].pw_len;
719
720   /**
721    * main
722    */
723
724   __local RC4_KEY rc4_keys[64];
725
726   m10400m (rc4_keys, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, 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, pdf_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
727 }
728
729 __kernel void m10400_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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
730 {
731   /**
732    * base
733    */
734
735   const u32 gid = get_global_id (0);
736
737   if (gid >= gid_max) return;
738
739   u32 w0[4];
740
741   w0[0] = pws[gid].i[ 0];
742   w0[1] = pws[gid].i[ 1];
743   w0[2] = pws[gid].i[ 2];
744   w0[3] = pws[gid].i[ 3];
745
746   u32 w1[4];
747
748   w1[0] = 0;
749   w1[1] = 0;
750   w1[2] = 0;
751   w1[3] = 0;
752
753   u32 w2[4];
754
755   w2[0] = 0;
756   w2[1] = 0;
757   w2[2] = 0;
758   w2[3] = 0;
759
760   u32 w3[4];
761
762   w3[0] = 0;
763   w3[1] = 0;
764   w3[2] = 0;
765   w3[3] = 0;
766
767   const u32 pw_len = pws[gid].pw_len;
768
769   /**
770    * main
771    */
772
773   __local RC4_KEY rc4_keys[64];
774
775   m10400s (rc4_keys, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, 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, pdf_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
776 }
777
778 __kernel void m10400_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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
779 {
780   /**
781    * base
782    */
783
784   const u32 gid = get_global_id (0);
785
786   if (gid >= gid_max) return;
787
788   u32 w0[4];
789
790   w0[0] = pws[gid].i[ 0];
791   w0[1] = pws[gid].i[ 1];
792   w0[2] = pws[gid].i[ 2];
793   w0[3] = pws[gid].i[ 3];
794
795   u32 w1[4];
796
797   w1[0] = pws[gid].i[ 4];
798   w1[1] = pws[gid].i[ 5];
799   w1[2] = pws[gid].i[ 6];
800   w1[3] = pws[gid].i[ 7];
801
802   u32 w2[4];
803
804   w2[0] = 0;
805   w2[1] = 0;
806   w2[2] = 0;
807   w2[3] = 0;
808
809   u32 w3[4];
810
811   w3[0] = 0;
812   w3[1] = 0;
813   w3[2] = 0;
814   w3[3] = 0;
815
816   const u32 pw_len = pws[gid].pw_len;
817
818   /**
819    * main
820    */
821
822   __local RC4_KEY rc4_keys[64];
823
824   m10400s (rc4_keys, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, 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, pdf_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
825 }
826
827 __kernel void m10400_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 pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
828 {
829   /**
830    * base
831    */
832
833   const u32 gid = get_global_id (0);
834
835   if (gid >= gid_max) return;
836
837   u32 w0[4];
838
839   w0[0] = pws[gid].i[ 0];
840   w0[1] = pws[gid].i[ 1];
841   w0[2] = pws[gid].i[ 2];
842   w0[3] = pws[gid].i[ 3];
843
844   u32 w1[4];
845
846   w1[0] = pws[gid].i[ 4];
847   w1[1] = pws[gid].i[ 5];
848   w1[2] = pws[gid].i[ 6];
849   w1[3] = pws[gid].i[ 7];
850
851   u32 w2[4];
852
853   w2[0] = pws[gid].i[ 8];
854   w2[1] = pws[gid].i[ 9];
855   w2[2] = pws[gid].i[10];
856   w2[3] = pws[gid].i[11];
857
858   u32 w3[4];
859
860   w3[0] = pws[gid].i[12];
861   w3[1] = pws[gid].i[13];
862   w3[2] = 0;
863   w3[3] = 0;
864
865   const u32 pw_len = pws[gid].pw_len;
866
867   /**
868    * main
869    */
870
871   __local RC4_KEY rc4_keys[64];
872
873   m10400s (rc4_keys, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, 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, pdf_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
874 }