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