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