7c53c3b2a85d66fe0bf735832c2f7490b2616e68
[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 #define NEW_SIMD_CODE
9
10 #include "inc_hash_constants.h"
11 #include "inc_vendor.cl"
12
13 #define DGST_R0 0
14 #define DGST_R1 3
15 #define DGST_R2 2
16 #define DGST_R3 1
17
18 #include "inc_hash_functions.cl"
19 #include "inc_types.cl"
20 #include "inc_common.cl"
21 #include "inc_simd.cl"
22
23 void md5_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
24 {
25   u32x a = digest[0];
26   u32x b = digest[1];
27   u32x c = digest[2];
28   u32x d = digest[3];
29
30   u32x w0_t = w0[0];
31   u32x w1_t = w0[1];
32   u32x w2_t = w0[2];
33   u32x w3_t = w0[3];
34   u32x w4_t = w1[0];
35   u32x w5_t = w1[1];
36   u32x w6_t = w1[2];
37   u32x w7_t = w1[3];
38   u32x w8_t = w2[0];
39   u32x w9_t = w2[1];
40   u32x wa_t = w2[2];
41   u32x wb_t = w2[3];
42   u32x wc_t = w3[0];
43   u32x wd_t = w3[1];
44   u32x we_t = w3[2];
45   u32x 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 void hmac_md5_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[4], u32x 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 void hmac_md5_run (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[4], u32x opad[4], u32x 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 il_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    * base
242    */
243
244   u32 pw_buf0[4];
245   u32 pw_buf1[4];
246
247   pw_buf0[0] = pws[gid].i[0];
248   pw_buf0[1] = pws[gid].i[1];
249   pw_buf0[2] = pws[gid].i[2];
250   pw_buf0[3] = pws[gid].i[3];
251   pw_buf1[0] = pws[gid].i[4];
252   pw_buf1[1] = pws[gid].i[5];
253   pw_buf1[2] = pws[gid].i[6];
254   pw_buf1[3] = pws[gid].i[7];
255
256   const u32 pw_l_len = pws[gid].pw_len;
257
258   /**
259    * salt
260    */
261
262   const u32 nr_len  = ikepsk_bufs[salt_pos].nr_len;
263   const u32 msg_len = ikepsk_bufs[salt_pos].msg_len;
264
265   /**
266    * loop
267    */
268
269   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
270   {
271     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
272
273     const u32x pw_len = pw_l_len + pw_r_len;
274
275     /**
276      * concat password candidate
277      */
278
279     u32x wordl0[4] = { 0 };
280     u32x wordl1[4] = { 0 };
281     u32x wordl2[4] = { 0 };
282     u32x wordl3[4] = { 0 };
283
284     wordl0[0] = pw_buf0[0];
285     wordl0[1] = pw_buf0[1];
286     wordl0[2] = pw_buf0[2];
287     wordl0[3] = pw_buf0[3];
288     wordl1[0] = pw_buf1[0];
289     wordl1[1] = pw_buf1[1];
290     wordl1[2] = pw_buf1[2];
291     wordl1[3] = pw_buf1[3];
292
293     u32x wordr0[4] = { 0 };
294     u32x wordr1[4] = { 0 };
295     u32x wordr2[4] = { 0 };
296     u32x wordr3[4] = { 0 };
297
298     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
299     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
300     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
301     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
302     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
303     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
304     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
305     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
306
307     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
308     {
309       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
310     }
311     else
312     {
313       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
314     }
315
316     u32x w0[4];
317     u32x w1[4];
318     u32x w2[4];
319     u32x w3[4];
320
321     w0[0] = wordl0[0] | wordr0[0];
322     w0[1] = wordl0[1] | wordr0[1];
323     w0[2] = wordl0[2] | wordr0[2];
324     w0[3] = wordl0[3] | wordr0[3];
325     w1[0] = wordl1[0] | wordr1[0];
326     w1[1] = wordl1[1] | wordr1[1];
327     w1[2] = wordl1[2] | wordr1[2];
328     w1[3] = wordl1[3] | wordr1[3];
329     w2[0] = wordl2[0] | wordr2[0];
330     w2[1] = wordl2[1] | wordr2[1];
331     w2[2] = wordl2[2] | wordr2[2];
332     w2[3] = wordl2[3] | wordr2[3];
333     w3[0] = wordl3[0] | wordr3[0];
334     w3[1] = wordl3[1] | wordr3[1];
335     w3[2] = wordl3[2] | wordr3[2];
336     w3[3] = wordl3[3] | wordr3[3];
337
338     /**
339      * pads
340      */
341
342     u32x ipad[4];
343     u32x opad[4];
344
345     hmac_md5_pad (w0, w1, w2, w3, ipad, opad);
346
347     w0[0] = w_s[ 0];
348     w0[1] = w_s[ 1];
349     w0[2] = w_s[ 2];
350     w0[3] = w_s[ 3];
351     w1[0] = w_s[ 4];
352     w1[1] = w_s[ 5];
353     w1[2] = w_s[ 6];
354     w1[3] = w_s[ 7];
355     w2[0] = w_s[ 8];
356     w2[1] = w_s[ 9];
357     w2[2] = w_s[10];
358     w2[3] = w_s[11];
359     w3[0] = w_s[12];
360     w3[1] = w_s[13];
361     w3[2] = (64 + nr_len) * 8;
362     w3[3] = 0;
363
364     u32x digest[4];
365
366     hmac_md5_run (w0, w1, w2, w3, ipad, opad, digest);
367
368     w0[0] = digest[0];
369     w0[1] = digest[1];
370     w0[2] = digest[2];
371     w0[3] = digest[3];
372     w1[0] = 0;
373     w1[1] = 0;
374     w1[2] = 0;
375     w1[3] = 0;
376     w2[0] = 0;
377     w2[1] = 0;
378     w2[2] = 0;
379     w2[3] = 0;
380     w3[0] = 0;
381     w3[1] = 0;
382     w3[2] = 0;
383     w3[3] = 0;
384
385     hmac_md5_pad (w0, w1, w2, w3, ipad, opad);
386
387     int left;
388     int off;
389
390     for (left = ikepsk_bufs[salt_pos].msg_len, off = 0; left >= 56; left -= 64, off += 16)
391     {
392       w0[0] = s_msg_buf[off +  0];
393       w0[1] = s_msg_buf[off +  1];
394       w0[2] = s_msg_buf[off +  2];
395       w0[3] = s_msg_buf[off +  3];
396       w1[0] = s_msg_buf[off +  4];
397       w1[1] = s_msg_buf[off +  5];
398       w1[2] = s_msg_buf[off +  6];
399       w1[3] = s_msg_buf[off +  7];
400       w2[0] = s_msg_buf[off +  8];
401       w2[1] = s_msg_buf[off +  9];
402       w2[2] = s_msg_buf[off + 10];
403       w2[3] = s_msg_buf[off + 11];
404       w3[0] = s_msg_buf[off + 12];
405       w3[1] = s_msg_buf[off + 13];
406       w3[2] = s_msg_buf[off + 14];
407       w3[3] = s_msg_buf[off + 15];
408
409       md5_transform (w0, w1, w2, w3, ipad);
410     }
411
412     w0[0] = s_msg_buf[off +  0];
413     w0[1] = s_msg_buf[off +  1];
414     w0[2] = s_msg_buf[off +  2];
415     w0[3] = s_msg_buf[off +  3];
416     w1[0] = s_msg_buf[off +  4];
417     w1[1] = s_msg_buf[off +  5];
418     w1[2] = s_msg_buf[off +  6];
419     w1[3] = s_msg_buf[off +  7];
420     w2[0] = s_msg_buf[off +  8];
421     w2[1] = s_msg_buf[off +  9];
422     w2[2] = s_msg_buf[off + 10];
423     w2[3] = s_msg_buf[off + 11];
424     w3[0] = s_msg_buf[off + 12];
425     w3[1] = s_msg_buf[off + 13];
426     w3[2] = (64 + msg_len) * 8;
427     w3[3] = 0;
428
429     hmac_md5_run (w0, w1, w2, w3, ipad, opad, digest);
430
431     COMPARE_M_SIMD (digest[0], digest[3], digest[2], digest[1]);
432   }
433 }
434
435 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
436 {
437 }
438
439 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
440 {
441 }
442
443 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
444 {
445   /**
446    * modifier
447    */
448
449   const u32 gid = get_global_id (0);
450   const u32 lid = get_local_id (0);
451   const u32 lsz = get_local_size (0);
452
453   /**
454    * s_msg
455    */
456
457   __local u32 w_s[16];
458
459   for (u32 i = lid; i < 16; i += lsz)
460   {
461     w_s[i] = ikepsk_bufs[salt_pos].nr_buf[i];
462   }
463
464   barrier (CLK_LOCAL_MEM_FENCE);
465
466   __local u32 s_msg_buf[128];
467
468   for (u32 i = lid; i < 128; i += lsz)
469   {
470     s_msg_buf[i] = ikepsk_bufs[salt_pos].msg_buf[i];
471   }
472
473   barrier (CLK_LOCAL_MEM_FENCE);
474
475   if (gid >= gid_max) return;
476
477   /**
478    * base
479    */
480
481   u32 pw_buf0[4];
482   u32 pw_buf1[4];
483
484   pw_buf0[0] = pws[gid].i[0];
485   pw_buf0[1] = pws[gid].i[1];
486   pw_buf0[2] = pws[gid].i[2];
487   pw_buf0[3] = pws[gid].i[3];
488   pw_buf1[0] = pws[gid].i[4];
489   pw_buf1[1] = pws[gid].i[5];
490   pw_buf1[2] = pws[gid].i[6];
491   pw_buf1[3] = pws[gid].i[7];
492
493   const u32 pw_l_len = pws[gid].pw_len;
494
495   /**
496    * salt
497    */
498
499   const u32 nr_len  = ikepsk_bufs[salt_pos].nr_len;
500   const u32 msg_len = ikepsk_bufs[salt_pos].msg_len;
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    * loop
516    */
517
518   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
519   {
520     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
521
522     const u32x pw_len = pw_l_len + pw_r_len;
523
524     /**
525      * concat password candidate
526      */
527
528     u32x wordl0[4] = { 0 };
529     u32x wordl1[4] = { 0 };
530     u32x wordl2[4] = { 0 };
531     u32x wordl3[4] = { 0 };
532
533     wordl0[0] = pw_buf0[0];
534     wordl0[1] = pw_buf0[1];
535     wordl0[2] = pw_buf0[2];
536     wordl0[3] = pw_buf0[3];
537     wordl1[0] = pw_buf1[0];
538     wordl1[1] = pw_buf1[1];
539     wordl1[2] = pw_buf1[2];
540     wordl1[3] = pw_buf1[3];
541
542     u32x wordr0[4] = { 0 };
543     u32x wordr1[4] = { 0 };
544     u32x wordr2[4] = { 0 };
545     u32x wordr3[4] = { 0 };
546
547     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
548     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
549     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
550     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
551     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
552     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
553     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
554     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
555
556     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
557     {
558       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
559     }
560     else
561     {
562       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
563     }
564
565     u32x w0[4];
566     u32x w1[4];
567     u32x w2[4];
568     u32x w3[4];
569
570     w0[0] = wordl0[0] | wordr0[0];
571     w0[1] = wordl0[1] | wordr0[1];
572     w0[2] = wordl0[2] | wordr0[2];
573     w0[3] = wordl0[3] | wordr0[3];
574     w1[0] = wordl1[0] | wordr1[0];
575     w1[1] = wordl1[1] | wordr1[1];
576     w1[2] = wordl1[2] | wordr1[2];
577     w1[3] = wordl1[3] | wordr1[3];
578     w2[0] = wordl2[0] | wordr2[0];
579     w2[1] = wordl2[1] | wordr2[1];
580     w2[2] = wordl2[2] | wordr2[2];
581     w2[3] = wordl2[3] | wordr2[3];
582     w3[0] = wordl3[0] | wordr3[0];
583     w3[1] = wordl3[1] | wordr3[1];
584     w3[2] = wordl3[2] | wordr3[2];
585     w3[3] = wordl3[3] | wordr3[3];
586
587     /**
588      * pads
589      */
590
591     u32x ipad[4];
592     u32x opad[4];
593
594     hmac_md5_pad (w0, w1, w2, w3, ipad, opad);
595
596     w0[0] = w_s[ 0];
597     w0[1] = w_s[ 1];
598     w0[2] = w_s[ 2];
599     w0[3] = w_s[ 3];
600     w1[0] = w_s[ 4];
601     w1[1] = w_s[ 5];
602     w1[2] = w_s[ 6];
603     w1[3] = w_s[ 7];
604     w2[0] = w_s[ 8];
605     w2[1] = w_s[ 9];
606     w2[2] = w_s[10];
607     w2[3] = w_s[11];
608     w3[0] = w_s[12];
609     w3[1] = w_s[13];
610     w3[2] = (64 + nr_len) * 8;
611     w3[3] = 0;
612
613     u32x digest[4];
614
615     hmac_md5_run (w0, w1, w2, w3, ipad, opad, digest);
616
617     w0[0] = digest[0];
618     w0[1] = digest[1];
619     w0[2] = digest[2];
620     w0[3] = digest[3];
621     w1[0] = 0;
622     w1[1] = 0;
623     w1[2] = 0;
624     w1[3] = 0;
625     w2[0] = 0;
626     w2[1] = 0;
627     w2[2] = 0;
628     w2[3] = 0;
629     w3[0] = 0;
630     w3[1] = 0;
631     w3[2] = 0;
632     w3[3] = 0;
633
634     hmac_md5_pad (w0, w1, w2, w3, ipad, opad);
635
636     int left;
637     int off;
638
639     for (left = ikepsk_bufs[salt_pos].msg_len, off = 0; left >= 56; left -= 64, off += 16)
640     {
641       w0[0] = s_msg_buf[off +  0];
642       w0[1] = s_msg_buf[off +  1];
643       w0[2] = s_msg_buf[off +  2];
644       w0[3] = s_msg_buf[off +  3];
645       w1[0] = s_msg_buf[off +  4];
646       w1[1] = s_msg_buf[off +  5];
647       w1[2] = s_msg_buf[off +  6];
648       w1[3] = s_msg_buf[off +  7];
649       w2[0] = s_msg_buf[off +  8];
650       w2[1] = s_msg_buf[off +  9];
651       w2[2] = s_msg_buf[off + 10];
652       w2[3] = s_msg_buf[off + 11];
653       w3[0] = s_msg_buf[off + 12];
654       w3[1] = s_msg_buf[off + 13];
655       w3[2] = s_msg_buf[off + 14];
656       w3[3] = s_msg_buf[off + 15];
657
658       md5_transform (w0, w1, w2, w3, ipad);
659     }
660
661     w0[0] = s_msg_buf[off +  0];
662     w0[1] = s_msg_buf[off +  1];
663     w0[2] = s_msg_buf[off +  2];
664     w0[3] = s_msg_buf[off +  3];
665     w1[0] = s_msg_buf[off +  4];
666     w1[1] = s_msg_buf[off +  5];
667     w1[2] = s_msg_buf[off +  6];
668     w1[3] = s_msg_buf[off +  7];
669     w2[0] = s_msg_buf[off +  8];
670     w2[1] = s_msg_buf[off +  9];
671     w2[2] = s_msg_buf[off + 10];
672     w2[3] = s_msg_buf[off + 11];
673     w3[0] = s_msg_buf[off + 12];
674     w3[1] = s_msg_buf[off + 13];
675     w3[2] = (64 + msg_len) * 8;
676     w3[3] = 0;
677
678     hmac_md5_run (w0, w1, w2, w3, ipad, opad, digest);
679
680     COMPARE_S_SIMD (digest[0], digest[3], digest[2], digest[1]);
681   }
682 }
683
684 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
685 {
686 }
687
688 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
689 {
690 }