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