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