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