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