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