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