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