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