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