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