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