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