Merge pull request #183 from gm4tr1x/updateTestScript
[hashcat.git] / OpenCL / m10400_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 _MD5_
9
10 #include "include/constants.h"
11 #include "include/kernel_vendor.h"
12
13 #define DGST_R0 0
14 #define DGST_R1 1
15 #define DGST_R2 2
16 #define DGST_R3 3
17
18 #include "include/kernel_functions.c"
19 #include "OpenCL/types_ocl.c"
20 #include "OpenCL/common.c"
21 #include "include/rp_kernel.h"
22 #include "OpenCL/rp.c"
23
24 #define COMPARE_S "OpenCL/check_single_comp4.c"
25 #define COMPARE_M "OpenCL/check_multi_comp4.c"
26
27 __constant u32 padding[8] =
28 {
29   0x5e4ebf28,
30   0x418a754e,
31   0x564e0064,
32   0x0801faff,
33   0xb6002e2e,
34   0x803e68d0,
35   0xfea90c2f,
36   0x7a695364
37 };
38
39 typedef struct
40 {
41   u8 S[256];
42
43   u32 wtf_its_faster;
44
45 } RC4_KEY;
46
47 static void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
48 {
49   u8 tmp;
50
51   tmp           = rc4_key->S[i];
52   rc4_key->S[i] = rc4_key->S[j];
53   rc4_key->S[j] = tmp;
54 }
55
56 static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
57 {
58   u32 v = 0x03020100;
59   u32 a = 0x04040404;
60
61   __local u32 *ptr = (__local u32 *) rc4_key->S;
62
63   #pragma unroll
64   for (u32 i = 0; i < 64; i++)
65   {
66     ptr[i] = v; v += a;
67   }
68
69   const u32 d0 = data[0] >>  0;
70   const u32 d1 = data[0] >>  8;
71   const u32 d2 = data[0] >> 16;
72   const u32 d3 = data[0] >> 24;
73   const u32 d4 = data[1] >>  0;
74
75   u32 j = 0;
76
77   #pragma unroll
78   for (u32 i = 0; i < 255; i += 5)
79   {
80     j += rc4_key->S[i + 0] + d0; swap (rc4_key, i + 0, j);
81     j += rc4_key->S[i + 1] + d1; swap (rc4_key, i + 1, j);
82     j += rc4_key->S[i + 2] + d2; swap (rc4_key, i + 2, j);
83     j += rc4_key->S[i + 3] + d3; swap (rc4_key, i + 3, j);
84     j += rc4_key->S[i + 4] + d4; swap (rc4_key, i + 4, j);
85   }
86
87   j += rc4_key->S[255] + d0; swap (rc4_key, 255, j);
88 }
89
90 static u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, __constant u32 *in, u32 out[4])
91 {
92   #pragma unroll 4
93   for (u32 k = 0; k < 4; k++)
94   {
95     u32 xor4 = 0;
96
97     u8 idx;
98
99     i += 1;
100     j += rc4_key->S[i];
101
102     swap (rc4_key, i, j);
103
104     idx = rc4_key->S[i] + rc4_key->S[j];
105
106     xor4 |= rc4_key->S[idx] <<  0;
107
108     i += 1;
109     j += rc4_key->S[i];
110
111     swap (rc4_key, i, j);
112
113     idx = rc4_key->S[i] + rc4_key->S[j];
114
115     xor4 |= rc4_key->S[idx] <<  8;
116
117     i += 1;
118     j += rc4_key->S[i];
119
120     swap (rc4_key, i, j);
121
122     idx = rc4_key->S[i] + rc4_key->S[j];
123
124     xor4 |= rc4_key->S[idx] << 16;
125
126     i += 1;
127     j += rc4_key->S[i];
128
129     swap (rc4_key, i, j);
130
131     idx = rc4_key->S[i] + rc4_key->S[j];
132
133     xor4 |= rc4_key->S[idx] << 24;
134
135     out[k] = in[k] ^ xor4;
136   }
137
138   return j;
139 }
140
141 static void md5_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[4])
142 {
143   u32 a = digest[0];
144   u32 b = digest[1];
145   u32 c = digest[2];
146   u32 d = digest[3];
147
148   u32 w0_t = w0[0];
149   u32 w1_t = w0[1];
150   u32 w2_t = w0[2];
151   u32 w3_t = w0[3];
152   u32 w4_t = w1[0];
153   u32 w5_t = w1[1];
154   u32 w6_t = w1[2];
155   u32 w7_t = w1[3];
156   u32 w8_t = w2[0];
157   u32 w9_t = w2[1];
158   u32 wa_t = w2[2];
159   u32 wb_t = w2[3];
160   u32 wc_t = w3[0];
161   u32 wd_t = w3[1];
162   u32 we_t = w3[2];
163   u32 wf_t = w3[3];
164
165   MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
166   MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
167   MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
168   MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
169   MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
170   MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
171   MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
172   MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
173   MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
174   MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
175   MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
176   MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
177   MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
178   MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
179   MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
180   MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
181
182   MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
183   MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
184   MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
185   MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
186   MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
187   MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
188   MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
189   MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
190   MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
191   MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
192   MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
193   MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
194   MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
195   MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
196   MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
197   MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
198
199   MD5_STEP (MD5_H , a, b, c, d, w5_t, MD5C20, MD5S20);
200   MD5_STEP (MD5_H , d, a, b, c, w8_t, MD5C21, MD5S21);
201   MD5_STEP (MD5_H , c, d, a, b, wb_t, MD5C22, MD5S22);
202   MD5_STEP (MD5_H , b, c, d, a, we_t, MD5C23, MD5S23);
203   MD5_STEP (MD5_H , a, b, c, d, w1_t, MD5C24, MD5S20);
204   MD5_STEP (MD5_H , d, a, b, c, w4_t, MD5C25, MD5S21);
205   MD5_STEP (MD5_H , c, d, a, b, w7_t, MD5C26, MD5S22);
206   MD5_STEP (MD5_H , b, c, d, a, wa_t, MD5C27, MD5S23);
207   MD5_STEP (MD5_H , a, b, c, d, wd_t, MD5C28, MD5S20);
208   MD5_STEP (MD5_H , d, a, b, c, w0_t, MD5C29, MD5S21);
209   MD5_STEP (MD5_H , c, d, a, b, w3_t, MD5C2a, MD5S22);
210   MD5_STEP (MD5_H , b, c, d, a, w6_t, MD5C2b, MD5S23);
211   MD5_STEP (MD5_H , a, b, c, d, w9_t, MD5C2c, MD5S20);
212   MD5_STEP (MD5_H , d, a, b, c, wc_t, MD5C2d, MD5S21);
213   MD5_STEP (MD5_H , c, d, a, b, wf_t, MD5C2e, MD5S22);
214   MD5_STEP (MD5_H , b, c, d, a, w2_t, MD5C2f, MD5S23);
215
216   MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
217   MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
218   MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
219   MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
220   MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
221   MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
222   MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
223   MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
224   MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
225   MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
226   MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
227   MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
228   MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
229   MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
230   MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
231   MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
232
233   digest[0] += a;
234   digest[1] += b;
235   digest[2] += c;
236   digest[3] += d;
237 }
238
239 __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_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)
240 {
241   /**
242    * modifier
243    */
244
245   const u32 lid = get_local_id (0);
246
247   /**
248    * base
249    */
250
251   const u32 gid = get_global_id (0);
252
253   if (gid >= gid_max) return;
254
255   u32 pw_buf0[4];
256
257   pw_buf0[0] = pws[gid].i[ 0];
258   pw_buf0[1] = pws[gid].i[ 1];
259   pw_buf0[2] = pws[gid].i[ 2];
260   pw_buf0[3] = pws[gid].i[ 3];
261
262   u32 pw_buf1[4];
263
264   pw_buf1[0] = pws[gid].i[ 4];
265   pw_buf1[1] = pws[gid].i[ 5];
266   pw_buf1[2] = pws[gid].i[ 6];
267   pw_buf1[3] = pws[gid].i[ 7];
268
269   const u32 pw_len = pws[gid].pw_len;
270
271   /**
272    * key
273    */
274
275   __local RC4_KEY rc4_keys[64];
276
277   __local RC4_KEY *rc4_key = &rc4_keys[lid];
278
279   /**
280    * U_buf
281    */
282
283   u32 o_buf[8];
284
285   o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
286   o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
287   o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
288   o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
289   o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
290   o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
291   o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
292   o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
293
294   u32 P = pdf_bufs[salt_pos].P;
295
296   u32 id_buf[4];
297
298   id_buf[0] = pdf_bufs[salt_pos].id_buf[0];
299   id_buf[1] = pdf_bufs[salt_pos].id_buf[1];
300   id_buf[2] = pdf_bufs[salt_pos].id_buf[2];
301   id_buf[3] = pdf_bufs[salt_pos].id_buf[3];
302
303   /**
304    * loop
305    */
306
307   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
308   {
309     u32 w0[4];
310
311     w0[0] = pw_buf0[0];
312     w0[1] = pw_buf0[1];
313     w0[2] = pw_buf0[2];
314     w0[3] = pw_buf0[3];
315
316     u32 w1[4];
317
318     w1[0] = pw_buf1[0];
319     w1[1] = pw_buf1[1];
320     w1[2] = pw_buf1[2];
321     w1[3] = pw_buf1[3];
322
323     u32 w2[4];
324
325     w2[0] = 0;
326     w2[1] = 0;
327     w2[2] = 0;
328     w2[3] = 0;
329
330     u32 w3[4];
331
332     w3[0] = 0;
333     w3[1] = 0;
334     w3[2] = 0;
335     w3[3] = 0;
336
337     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
338
339     u32 w0_t[4];
340     u32 w1_t[4];
341     u32 w2_t[4];
342     u32 w3_t[4];
343
344     // max length supported by pdf11 is 32
345
346     w0_t[0] = padding[0];
347     w0_t[1] = padding[1];
348     w0_t[2] = padding[2];
349     w0_t[3] = padding[3];
350     w1_t[0] = padding[4];
351     w1_t[1] = padding[5];
352     w1_t[2] = padding[6];
353     w1_t[3] = padding[7];
354     w2_t[0] = 0;
355     w2_t[1] = 0;
356     w2_t[2] = 0;
357     w2_t[3] = 0;
358     w3_t[0] = 0;
359     w3_t[1] = 0;
360     w3_t[2] = 0;
361     w3_t[3] = 0;
362
363     switch_buffer_by_offset_le (w0_t, w1_t, w2_t, w3_t, pw_len);
364
365     // add password
366     // truncate at 32 is wanted, not a bug!
367     // add o_buf
368
369     w0_t[0] |= w0[0];
370     w0_t[1] |= w0[1];
371     w0_t[2] |= w0[2];
372     w0_t[3] |= w0[3];
373     w1_t[0] |= w1[0];
374     w1_t[1] |= w1[1];
375     w1_t[2] |= w1[2];
376     w1_t[3] |= w1[3];
377     w2_t[0]  = o_buf[0];
378     w2_t[1]  = o_buf[1];
379     w2_t[2]  = o_buf[2];
380     w2_t[3]  = o_buf[3];
381     w3_t[0]  = o_buf[4];
382     w3_t[1]  = o_buf[5];
383     w3_t[2]  = o_buf[6];
384     w3_t[3]  = o_buf[7];
385
386     u32 digest[4];
387
388     digest[0] = MD5M_A;
389     digest[1] = MD5M_B;
390     digest[2] = MD5M_C;
391     digest[3] = MD5M_D;
392
393     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
394
395     w0_t[0] = P;
396     w0_t[1] = id_buf[0];
397     w0_t[2] = id_buf[1];
398     w0_t[3] = id_buf[2];
399     w1_t[0] = id_buf[3];
400     w1_t[1] = 0x80;
401     w1_t[2] = 0;
402     w1_t[3] = 0;
403     w2_t[0] = 0;
404     w2_t[1] = 0;
405     w2_t[2] = 0;
406     w2_t[3] = 0;
407     w3_t[0] = 0;
408     w3_t[1] = 0;
409     w3_t[2] = 84 * 8;
410     w3_t[3] = 0;
411
412     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
413
414     // now the RC4 part
415
416     u32 key[4];
417
418     key[0] = digest[0];
419     key[1] = digest[1] & 0xff;
420     key[2] = 0;
421     key[3] = 0;
422
423     rc4_init_16 (rc4_key, key);
424
425     u32 out[4];
426
427     rc4_next_16 (rc4_key, 0, 0, padding, out);
428
429     const u32 r0 = out[0];
430     const u32 r1 = out[1];
431     const u32 r2 = out[2];
432     const u32 r3 = out[3];
433
434     #include COMPARE_M
435   }
436 }
437
438 __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_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)
439 {
440 }
441
442 __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_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)
443 {
444 }
445
446 __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_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)
447 {
448   /**
449    * modifier
450    */
451
452   const u32 lid = get_local_id (0);
453
454   /**
455    * base
456    */
457
458   const u32 gid = get_global_id (0);
459
460   if (gid >= gid_max) return;
461
462   u32 pw_buf0[4];
463
464   pw_buf0[0] = pws[gid].i[ 0];
465   pw_buf0[1] = pws[gid].i[ 1];
466   pw_buf0[2] = pws[gid].i[ 2];
467   pw_buf0[3] = pws[gid].i[ 3];
468
469   u32 pw_buf1[4];
470
471   pw_buf1[0] = pws[gid].i[ 4];
472   pw_buf1[1] = pws[gid].i[ 5];
473   pw_buf1[2] = pws[gid].i[ 6];
474   pw_buf1[3] = pws[gid].i[ 7];
475
476   const u32 pw_len = pws[gid].pw_len;
477
478   /**
479    * key
480    */
481
482   __local RC4_KEY rc4_keys[64];
483
484   __local RC4_KEY *rc4_key = &rc4_keys[lid];
485
486   /**
487    * digest
488    */
489
490   const u32 search[4] =
491   {
492     digests_buf[digests_offset].digest_buf[DGST_R0],
493     digests_buf[digests_offset].digest_buf[DGST_R1],
494     digests_buf[digests_offset].digest_buf[DGST_R2],
495     digests_buf[digests_offset].digest_buf[DGST_R3]
496   };
497
498   /**
499    * U_buf
500    */
501
502   u32 o_buf[8];
503
504   o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
505   o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
506   o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
507   o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
508   o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
509   o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
510   o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
511   o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
512
513   u32 P = pdf_bufs[salt_pos].P;
514
515   u32 id_buf[4];
516
517   id_buf[0] = pdf_bufs[salt_pos].id_buf[0];
518   id_buf[1] = pdf_bufs[salt_pos].id_buf[1];
519   id_buf[2] = pdf_bufs[salt_pos].id_buf[2];
520   id_buf[3] = pdf_bufs[salt_pos].id_buf[3];
521
522   /**
523    * loop
524    */
525
526   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
527   {
528     u32 w0[4];
529
530     w0[0] = pw_buf0[0];
531     w0[1] = pw_buf0[1];
532     w0[2] = pw_buf0[2];
533     w0[3] = pw_buf0[3];
534
535     u32 w1[4];
536
537     w1[0] = pw_buf1[0];
538     w1[1] = pw_buf1[1];
539     w1[2] = pw_buf1[2];
540     w1[3] = pw_buf1[3];
541
542     u32 w2[4];
543
544     w2[0] = 0;
545     w2[1] = 0;
546     w2[2] = 0;
547     w2[3] = 0;
548
549     u32 w3[4];
550
551     w3[0] = 0;
552     w3[1] = 0;
553     w3[2] = 0;
554     w3[3] = 0;
555
556     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
557
558     u32 w0_t[4];
559     u32 w1_t[4];
560     u32 w2_t[4];
561     u32 w3_t[4];
562
563     // max length supported by pdf11 is 32
564
565     w0_t[0] = padding[0];
566     w0_t[1] = padding[1];
567     w0_t[2] = padding[2];
568     w0_t[3] = padding[3];
569     w1_t[0] = padding[4];
570     w1_t[1] = padding[5];
571     w1_t[2] = padding[6];
572     w1_t[3] = padding[7];
573     w2_t[0] = 0;
574     w2_t[1] = 0;
575     w2_t[2] = 0;
576     w2_t[3] = 0;
577     w3_t[0] = 0;
578     w3_t[1] = 0;
579     w3_t[2] = 0;
580     w3_t[3] = 0;
581
582     switch_buffer_by_offset_le (w0_t, w1_t, w2_t, w3_t, pw_len);
583
584     // add password
585     // truncate at 32 is wanted, not a bug!
586     // add o_buf
587
588     w0_t[0] |= w0[0];
589     w0_t[1] |= w0[1];
590     w0_t[2] |= w0[2];
591     w0_t[3] |= w0[3];
592     w1_t[0] |= w1[0];
593     w1_t[1] |= w1[1];
594     w1_t[2] |= w1[2];
595     w1_t[3] |= w1[3];
596     w2_t[0]  = o_buf[0];
597     w2_t[1]  = o_buf[1];
598     w2_t[2]  = o_buf[2];
599     w2_t[3]  = o_buf[3];
600     w3_t[0]  = o_buf[4];
601     w3_t[1]  = o_buf[5];
602     w3_t[2]  = o_buf[6];
603     w3_t[3]  = o_buf[7];
604
605     u32 digest[4];
606
607     digest[0] = MD5M_A;
608     digest[1] = MD5M_B;
609     digest[2] = MD5M_C;
610     digest[3] = MD5M_D;
611
612     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
613
614     w0_t[0] = P;
615     w0_t[1] = id_buf[0];
616     w0_t[2] = id_buf[1];
617     w0_t[3] = id_buf[2];
618     w1_t[0] = id_buf[3];
619     w1_t[1] = 0x80;
620     w1_t[2] = 0;
621     w1_t[3] = 0;
622     w2_t[0] = 0;
623     w2_t[1] = 0;
624     w2_t[2] = 0;
625     w2_t[3] = 0;
626     w3_t[0] = 0;
627     w3_t[1] = 0;
628     w3_t[2] = 84 * 8;
629     w3_t[3] = 0;
630
631     md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
632
633     // now the RC4 part
634
635     u32 key[4];
636
637     key[0] = digest[0];
638     key[1] = digest[1] & 0xff;
639     key[2] = 0;
640     key[3] = 0;
641
642     rc4_init_16 (rc4_key, key);
643
644     u32 out[4];
645
646     rc4_next_16 (rc4_key, 0, 0, padding, out);
647
648     const u32 r0 = out[0];
649     const u32 r1 = out[1];
650     const u32 r2 = out[2];
651     const u32 r3 = out[3];
652
653     #include COMPARE_S
654   }
655 }
656
657 __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_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)
658 {
659 }
660
661 __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_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)
662 {
663 }