Initial commit
[hashcat.git] / amd / m08200.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _CLOUDKEY_
7
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
10
11 #ifdef  VLIW1
12 #define VECT_SIZE1
13 #endif
14
15 #ifdef  VLIW4
16 #define VECT_SIZE1
17 #endif
18
19 #ifdef  VLIW5
20 #define VECT_SIZE1
21 #endif
22
23 #define DGST_R0 0
24 #define DGST_R1 1
25 #define DGST_R2 2
26 #define DGST_R3 3
27
28 #include "include/kernel_functions.c"
29 #include "types_amd.c"
30 #include "common_amd.c"
31
32 #ifdef  VECT_SIZE1
33 #define VECT_COMPARE_M "check_multi_vect1_comp4.c"
34 #endif
35
36 __constant u32 k_sha256[64] =
37 {
38   SHA256C00, SHA256C01, SHA256C02, SHA256C03,
39   SHA256C04, SHA256C05, SHA256C06, SHA256C07,
40   SHA256C08, SHA256C09, SHA256C0a, SHA256C0b,
41   SHA256C0c, SHA256C0d, SHA256C0e, SHA256C0f,
42   SHA256C10, SHA256C11, SHA256C12, SHA256C13,
43   SHA256C14, SHA256C15, SHA256C16, SHA256C17,
44   SHA256C18, SHA256C19, SHA256C1a, SHA256C1b,
45   SHA256C1c, SHA256C1d, SHA256C1e, SHA256C1f,
46   SHA256C20, SHA256C21, SHA256C22, SHA256C23,
47   SHA256C24, SHA256C25, SHA256C26, SHA256C27,
48   SHA256C28, SHA256C29, SHA256C2a, SHA256C2b,
49   SHA256C2c, SHA256C2d, SHA256C2e, SHA256C2f,
50   SHA256C30, SHA256C31, SHA256C32, SHA256C33,
51   SHA256C34, SHA256C35, SHA256C36, SHA256C37,
52   SHA256C38, SHA256C39, SHA256C3a, SHA256C3b,
53   SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f,
54 };
55
56 __constant u64 k_sha512[80] =
57 {
58   SHA512C00, SHA512C01, SHA512C02, SHA512C03,
59   SHA512C04, SHA512C05, SHA512C06, SHA512C07,
60   SHA512C08, SHA512C09, SHA512C0a, SHA512C0b,
61   SHA512C0c, SHA512C0d, SHA512C0e, SHA512C0f,
62   SHA512C10, SHA512C11, SHA512C12, SHA512C13,
63   SHA512C14, SHA512C15, SHA512C16, SHA512C17,
64   SHA512C18, SHA512C19, SHA512C1a, SHA512C1b,
65   SHA512C1c, SHA512C1d, SHA512C1e, SHA512C1f,
66   SHA512C20, SHA512C21, SHA512C22, SHA512C23,
67   SHA512C24, SHA512C25, SHA512C26, SHA512C27,
68   SHA512C28, SHA512C29, SHA512C2a, SHA512C2b,
69   SHA512C2c, SHA512C2d, SHA512C2e, SHA512C2f,
70   SHA512C30, SHA512C31, SHA512C32, SHA512C33,
71   SHA512C34, SHA512C35, SHA512C36, SHA512C37,
72   SHA512C38, SHA512C39, SHA512C3a, SHA512C3b,
73   SHA512C3c, SHA512C3d, SHA512C3e, SHA512C3f,
74   SHA512C40, SHA512C41, SHA512C42, SHA512C43,
75   SHA512C44, SHA512C45, SHA512C46, SHA512C47,
76   SHA512C48, SHA512C49, SHA512C4a, SHA512C4b,
77   SHA512C4c, SHA512C4d, SHA512C4e, SHA512C4f,
78 };
79
80 static void sha256_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[8])
81 {
82   u32x a = digest[0];
83   u32x b = digest[1];
84   u32x c = digest[2];
85   u32x d = digest[3];
86   u32x e = digest[4];
87   u32x f = digest[5];
88   u32x g = digest[6];
89   u32x h = digest[7];
90
91   u32x w0_t = w0[0];
92   u32x w1_t = w0[1];
93   u32x w2_t = w0[2];
94   u32x w3_t = w0[3];
95   u32x w4_t = w1[0];
96   u32x w5_t = w1[1];
97   u32x w6_t = w1[2];
98   u32x w7_t = w1[3];
99   u32x w8_t = w2[0];
100   u32x w9_t = w2[1];
101   u32x wa_t = w2[2];
102   u32x wb_t = w2[3];
103   u32x wc_t = w3[0];
104   u32x wd_t = w3[1];
105   u32x we_t = w3[2];
106   u32x wf_t = w3[3];
107
108   #define ROUND_EXPAND()                            \
109   {                                                 \
110     w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t);  \
111     w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t);  \
112     w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t);  \
113     w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t);  \
114     w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t);  \
115     w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t);  \
116     w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t);  \
117     w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t);  \
118     w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t);  \
119     w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t);  \
120     wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t);  \
121     wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t);  \
122     wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t);  \
123     wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t);  \
124     we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t);  \
125     wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t);  \
126   }
127
128   #define ROUND_STEP(i)                                                                   \
129   {                                                                                       \
130     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i +  0]); \
131     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i +  1]); \
132     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i +  2]); \
133     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i +  3]); \
134     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i +  4]); \
135     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i +  5]); \
136     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i +  6]); \
137     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i +  7]); \
138     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i +  8]); \
139     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i +  9]); \
140     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
141     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
142     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
143     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
144     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
145     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
146   }
147
148   ROUND_STEP (0);
149
150   #pragma unroll
151   for (int i = 16; i < 64; i += 16)
152   {
153     ROUND_EXPAND (); ROUND_STEP (i);
154   }
155
156   digest[0] += a;
157   digest[1] += b;
158   digest[2] += c;
159   digest[3] += d;
160   digest[4] += e;
161   digest[5] += f;
162   digest[6] += g;
163   digest[7] += h;
164 }
165
166 static void hmac_sha256_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[8], u32x opad[8])
167 {
168   w0[0] = w0[0] ^ 0x36363636;
169   w0[1] = w0[1] ^ 0x36363636;
170   w0[2] = w0[2] ^ 0x36363636;
171   w0[3] = w0[3] ^ 0x36363636;
172   w1[0] = w1[0] ^ 0x36363636;
173   w1[1] = w1[1] ^ 0x36363636;
174   w1[2] = w1[2] ^ 0x36363636;
175   w1[3] = w1[3] ^ 0x36363636;
176   w2[0] = w2[0] ^ 0x36363636;
177   w2[1] = w2[1] ^ 0x36363636;
178   w2[2] = w2[2] ^ 0x36363636;
179   w2[3] = w2[3] ^ 0x36363636;
180   w3[0] = w3[0] ^ 0x36363636;
181   w3[1] = w3[1] ^ 0x36363636;
182   w3[2] = w3[2] ^ 0x36363636;
183   w3[3] = w3[3] ^ 0x36363636;
184
185   ipad[0] = SHA256M_A;
186   ipad[1] = SHA256M_B;
187   ipad[2] = SHA256M_C;
188   ipad[3] = SHA256M_D;
189   ipad[4] = SHA256M_E;
190   ipad[5] = SHA256M_F;
191   ipad[6] = SHA256M_G;
192   ipad[7] = SHA256M_H;
193
194   sha256_transform (w0, w1, w2, w3, ipad);
195
196   w0[0] = w0[0] ^ 0x6a6a6a6a;
197   w0[1] = w0[1] ^ 0x6a6a6a6a;
198   w0[2] = w0[2] ^ 0x6a6a6a6a;
199   w0[3] = w0[3] ^ 0x6a6a6a6a;
200   w1[0] = w1[0] ^ 0x6a6a6a6a;
201   w1[1] = w1[1] ^ 0x6a6a6a6a;
202   w1[2] = w1[2] ^ 0x6a6a6a6a;
203   w1[3] = w1[3] ^ 0x6a6a6a6a;
204   w2[0] = w2[0] ^ 0x6a6a6a6a;
205   w2[1] = w2[1] ^ 0x6a6a6a6a;
206   w2[2] = w2[2] ^ 0x6a6a6a6a;
207   w2[3] = w2[3] ^ 0x6a6a6a6a;
208   w3[0] = w3[0] ^ 0x6a6a6a6a;
209   w3[1] = w3[1] ^ 0x6a6a6a6a;
210   w3[2] = w3[2] ^ 0x6a6a6a6a;
211   w3[3] = w3[3] ^ 0x6a6a6a6a;
212
213   opad[0] = SHA256M_A;
214   opad[1] = SHA256M_B;
215   opad[2] = SHA256M_C;
216   opad[3] = SHA256M_D;
217   opad[4] = SHA256M_E;
218   opad[5] = SHA256M_F;
219   opad[6] = SHA256M_G;
220   opad[7] = SHA256M_H;
221
222   sha256_transform (w0, w1, w2, w3, opad);
223 }
224
225 static void hmac_sha256_run (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[8], u32x opad[8], u32x digest[8])
226 {
227   digest[0] = ipad[0];
228   digest[1] = ipad[1];
229   digest[2] = ipad[2];
230   digest[3] = ipad[3];
231   digest[4] = ipad[4];
232   digest[5] = ipad[5];
233   digest[6] = ipad[6];
234   digest[7] = ipad[7];
235
236   sha256_transform (w0, w1, w2, w3, digest);
237
238   w0[0] = digest[0];
239   w0[1] = digest[1];
240   w0[2] = digest[2];
241   w0[3] = digest[3];
242   w1[0] = digest[4];
243   w1[1] = digest[5];
244   w1[2] = digest[6];
245   w1[3] = digest[7];
246   w2[0] = 0x80000000;
247   w2[1] = 0;
248   w2[2] = 0;
249   w2[3] = 0;
250   w3[0] = 0;
251   w3[1] = 0;
252   w3[2] = 0;
253   w3[3] = (64 + 32) * 8;
254
255   digest[0] = opad[0];
256   digest[1] = opad[1];
257   digest[2] = opad[2];
258   digest[3] = opad[3];
259   digest[4] = opad[4];
260   digest[5] = opad[5];
261   digest[6] = opad[6];
262   digest[7] = opad[7];
263
264   sha256_transform (w0, w1, w2, w3, digest);
265 }
266
267 static void sha512_transform (const u64 w[16], u64 dgst[8])
268 {
269   u64 a = dgst[0];
270   u64 b = dgst[1];
271   u64 c = dgst[2];
272   u64 d = dgst[3];
273   u64 e = dgst[4];
274   u64 f = dgst[5];
275   u64 g = dgst[6];
276   u64 h = dgst[7];
277
278   u64 w0_t = w[ 0];
279   u64 w1_t = w[ 1];
280   u64 w2_t = w[ 2];
281   u64 w3_t = w[ 3];
282   u64 w4_t = w[ 4];
283   u64 w5_t = w[ 5];
284   u64 w6_t = w[ 6];
285   u64 w7_t = w[ 7];
286   u64 w8_t = w[ 8];
287   u64 w9_t = w[ 9];
288   u64 wa_t = w[10];
289   u64 wb_t = w[11];
290   u64 wc_t = w[12];
291   u64 wd_t = w[13];
292   u64 we_t = w[14];
293   u64 wf_t = w[15];
294
295   #define ROUND512_EXPAND()                         \
296   {                                                 \
297     w0_t = SHA512_EXPAND (we_t, w9_t, w1_t, w0_t);  \
298     w1_t = SHA512_EXPAND (wf_t, wa_t, w2_t, w1_t);  \
299     w2_t = SHA512_EXPAND (w0_t, wb_t, w3_t, w2_t);  \
300     w3_t = SHA512_EXPAND (w1_t, wc_t, w4_t, w3_t);  \
301     w4_t = SHA512_EXPAND (w2_t, wd_t, w5_t, w4_t);  \
302     w5_t = SHA512_EXPAND (w3_t, we_t, w6_t, w5_t);  \
303     w6_t = SHA512_EXPAND (w4_t, wf_t, w7_t, w6_t);  \
304     w7_t = SHA512_EXPAND (w5_t, w0_t, w8_t, w7_t);  \
305     w8_t = SHA512_EXPAND (w6_t, w1_t, w9_t, w8_t);  \
306     w9_t = SHA512_EXPAND (w7_t, w2_t, wa_t, w9_t);  \
307     wa_t = SHA512_EXPAND (w8_t, w3_t, wb_t, wa_t);  \
308     wb_t = SHA512_EXPAND (w9_t, w4_t, wc_t, wb_t);  \
309     wc_t = SHA512_EXPAND (wa_t, w5_t, wd_t, wc_t);  \
310     wd_t = SHA512_EXPAND (wb_t, w6_t, we_t, wd_t);  \
311     we_t = SHA512_EXPAND (wc_t, w7_t, wf_t, we_t);  \
312     wf_t = SHA512_EXPAND (wd_t, w8_t, w0_t, wf_t);  \
313   }
314
315   #define ROUND512_STEP(i)                                                                \
316   {                                                                                       \
317     SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha512[i +  0]); \
318     SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha512[i +  1]); \
319     SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha512[i +  2]); \
320     SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha512[i +  3]); \
321     SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha512[i +  4]); \
322     SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha512[i +  5]); \
323     SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha512[i +  6]); \
324     SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha512[i +  7]); \
325     SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha512[i +  8]); \
326     SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha512[i +  9]); \
327     SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha512[i + 10]); \
328     SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha512[i + 11]); \
329     SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha512[i + 12]); \
330     SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha512[i + 13]); \
331     SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, we_t, k_sha512[i + 14]); \
332     SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha512[i + 15]); \
333   }
334
335   ROUND512_STEP (0);
336
337   //#pragma unroll // kernel fails if used
338   for (int i = 16; i < 80; i += 16)
339   {
340     ROUND512_EXPAND (); ROUND512_STEP (i);
341   }
342
343   dgst[0] += a;
344   dgst[1] += b;
345   dgst[2] += c;
346   dgst[3] += d;
347   dgst[4] += e;
348   dgst[5] += f;
349   dgst[6] += g;
350   dgst[7] += h;
351 }
352
353 static void hmac_sha512_run (const u64 w1[16], const u64 ipad[8], const u64 opad[8], u64 dgst[8])
354 {
355   dgst[0] = ipad[0];
356   dgst[1] = ipad[1];
357   dgst[2] = ipad[2];
358   dgst[3] = ipad[3];
359   dgst[4] = ipad[4];
360   dgst[5] = ipad[5];
361   dgst[6] = ipad[6];
362   dgst[7] = ipad[7];
363
364   sha512_transform (w1, dgst);
365
366   u64 w[16];
367
368   w[ 0] = dgst[0];
369   w[ 1] = dgst[1];
370   w[ 2] = dgst[2];
371   w[ 3] = dgst[3];
372   w[ 4] = dgst[4];
373   w[ 5] = dgst[5];
374   w[ 6] = dgst[6];
375   w[ 7] = dgst[7];
376   w[ 8] = 0x8000000000000000;
377   w[ 9] = 0;
378   w[10] = 0;
379   w[11] = 0;
380   w[12] = 0;
381   w[13] = 0;
382   w[14] = 0;
383   w[15] = (128 + 64) * 8;
384
385   dgst[0] = opad[0];
386   dgst[1] = opad[1];
387   dgst[2] = opad[2];
388   dgst[3] = opad[3];
389   dgst[4] = opad[4];
390   dgst[5] = opad[5];
391   dgst[6] = opad[6];
392   dgst[7] = opad[7];
393
394   sha512_transform (w, dgst);
395 }
396
397 static void hmac_sha512_init (u64 w[16], u64 ipad[8], u64 opad[8])
398 {
399   w[ 0] ^= 0x3636363636363636;
400   w[ 1] ^= 0x3636363636363636;
401   w[ 2] ^= 0x3636363636363636;
402   w[ 3] ^= 0x3636363636363636;
403   w[ 4] ^= 0x3636363636363636;
404   w[ 5] ^= 0x3636363636363636;
405   w[ 6] ^= 0x3636363636363636;
406   w[ 7] ^= 0x3636363636363636;
407   w[ 8] ^= 0x3636363636363636;
408   w[ 9] ^= 0x3636363636363636;
409   w[10] ^= 0x3636363636363636;
410   w[11] ^= 0x3636363636363636;
411   w[12] ^= 0x3636363636363636;
412   w[13] ^= 0x3636363636363636;
413   w[14] ^= 0x3636363636363636;
414   w[15] ^= 0x3636363636363636;
415
416   ipad[0] = SHA512M_A;
417   ipad[1] = SHA512M_B;
418   ipad[2] = SHA512M_C;
419   ipad[3] = SHA512M_D;
420   ipad[4] = SHA512M_E;
421   ipad[5] = SHA512M_F;
422   ipad[6] = SHA512M_G;
423   ipad[7] = SHA512M_H;
424
425   sha512_transform (w, ipad);
426
427   w[ 0] ^= 0x6a6a6a6a6a6a6a6a;
428   w[ 1] ^= 0x6a6a6a6a6a6a6a6a;
429   w[ 2] ^= 0x6a6a6a6a6a6a6a6a;
430   w[ 3] ^= 0x6a6a6a6a6a6a6a6a;
431   w[ 4] ^= 0x6a6a6a6a6a6a6a6a;
432   w[ 5] ^= 0x6a6a6a6a6a6a6a6a;
433   w[ 6] ^= 0x6a6a6a6a6a6a6a6a;
434   w[ 7] ^= 0x6a6a6a6a6a6a6a6a;
435   w[ 8] ^= 0x6a6a6a6a6a6a6a6a;
436   w[ 9] ^= 0x6a6a6a6a6a6a6a6a;
437   w[10] ^= 0x6a6a6a6a6a6a6a6a;
438   w[11] ^= 0x6a6a6a6a6a6a6a6a;
439   w[12] ^= 0x6a6a6a6a6a6a6a6a;
440   w[13] ^= 0x6a6a6a6a6a6a6a6a;
441   w[14] ^= 0x6a6a6a6a6a6a6a6a;
442   w[15] ^= 0x6a6a6a6a6a6a6a6a;
443
444   opad[0] = SHA512M_A;
445   opad[1] = SHA512M_B;
446   opad[2] = SHA512M_C;
447   opad[3] = SHA512M_D;
448   opad[4] = SHA512M_E;
449   opad[5] = SHA512M_F;
450   opad[6] = SHA512M_G;
451   opad[7] = SHA512M_H;
452
453   sha512_transform (w, opad);
454 }
455
456 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08200_init (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pbkdf2_sha512_tmp_t *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 cloudkey_t *esalt_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)
457 {
458   /**
459    * base
460    */
461
462   const u32 gid = get_global_id (0);
463
464   if (gid >= gid_max) return;
465
466   u32x w0[4];
467
468   w0[0] = pws[gid].i[ 0];
469   w0[1] = pws[gid].i[ 1];
470   w0[2] = pws[gid].i[ 2];
471   w0[3] = pws[gid].i[ 3];
472
473   u32x w1[4];
474
475   w1[0] = pws[gid].i[ 4];
476   w1[1] = pws[gid].i[ 5];
477   w1[2] = pws[gid].i[ 6];
478   w1[3] = pws[gid].i[ 7];
479
480   u32x w2[4];
481
482   w2[0] = pws[gid].i[ 8];
483   w2[1] = pws[gid].i[ 9];
484   w2[2] = pws[gid].i[10];
485   w2[3] = pws[gid].i[11];
486
487   u32x w3[4];
488
489   w3[0] = pws[gid].i[12];
490   w3[1] = pws[gid].i[13];
491   w3[2] = pws[gid].i[14];
492   w3[3] = pws[gid].i[15];
493
494   /**
495    * salt
496    */
497
498   u32 salt_buf0[4];
499
500   salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
501   salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
502   salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
503   salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
504
505   u32 salt_buf1[4];
506
507   salt_buf1[0] = salt_bufs[salt_pos].salt_buf[ 4];
508   salt_buf1[1] = salt_bufs[salt_pos].salt_buf[ 5];
509   salt_buf1[2] = 0;
510   salt_buf1[3] = 0;
511
512   const u32 salt_len = salt_bufs[salt_pos].salt_len;
513
514   u64 data_buf[16];
515
516   data_buf[ 0] = ((u64) swap_workaround (salt_buf0[ 0])) << 32 | (u64) swap_workaround (salt_buf0[ 1]);
517   data_buf[ 1] = ((u64) swap_workaround (salt_buf0[ 2])) << 32 | (u64) swap_workaround (salt_buf0[ 3]);
518   data_buf[ 2] = ((u64) swap_workaround (salt_buf1[ 0])) << 32 | (u64) swap_workaround (salt_buf1[ 1]);
519   data_buf[ 3] = 0;
520   data_buf[ 4] = 0;
521   data_buf[ 5] = 0;
522   data_buf[ 6] = 0;
523   data_buf[ 7] = 0;
524   data_buf[ 8] = 0;
525   data_buf[ 9] = 0;
526   data_buf[10] = 0;
527   data_buf[11] = 0;
528   data_buf[12] = 0;
529   data_buf[13] = 0;
530   data_buf[14] = 0;
531   data_buf[15] = (128 + salt_len + 4) * 8;
532
533   u64 w[16];
534
535   w[ 0] = ((u64) swap_workaround (w0[0])) << 32 | (u64) swap_workaround (w0[1]);
536   w[ 1] = ((u64) swap_workaround (w0[2])) << 32 | (u64) swap_workaround (w0[3]);
537   w[ 2] = ((u64) swap_workaround (w1[0])) << 32 | (u64) swap_workaround (w1[1]);
538   w[ 3] = ((u64) swap_workaround (w1[2])) << 32 | (u64) swap_workaround (w1[3]);
539   w[ 4] = ((u64) swap_workaround (w2[0])) << 32 | (u64) swap_workaround (w2[1]);
540   w[ 5] = ((u64) swap_workaround (w2[2])) << 32 | (u64) swap_workaround (w2[3]);
541   w[ 6] = ((u64) swap_workaround (w3[0])) << 32 | (u64) swap_workaround (w3[1]);
542   w[ 7] = ((u64) swap_workaround (w3[2])) << 32 | (u64) swap_workaround (w3[3]);
543   w[ 8] = 0;
544   w[ 9] = 0;
545   w[10] = 0;
546   w[11] = 0;
547   w[12] = 0;
548   w[13] = 0;
549   w[14] = 0;
550   w[15] = 0;
551
552   u64 ipad[8];
553   u64 opad[8];
554
555   hmac_sha512_init (w, ipad, opad);
556
557   tmps[gid].ipad[0] = ipad[0];
558   tmps[gid].ipad[1] = ipad[1];
559   tmps[gid].ipad[2] = ipad[2];
560   tmps[gid].ipad[3] = ipad[3];
561   tmps[gid].ipad[4] = ipad[4];
562   tmps[gid].ipad[5] = ipad[5];
563   tmps[gid].ipad[6] = ipad[6];
564   tmps[gid].ipad[7] = ipad[7];
565
566   tmps[gid].opad[0] = opad[0];
567   tmps[gid].opad[1] = opad[1];
568   tmps[gid].opad[2] = opad[2];
569   tmps[gid].opad[3] = opad[3];
570   tmps[gid].opad[4] = opad[4];
571   tmps[gid].opad[5] = opad[5];
572   tmps[gid].opad[6] = opad[6];
573   tmps[gid].opad[7] = opad[7];
574
575   for (u32 i = 0, j = 1; i < 8; i += 8, j += 1)
576   {
577     u64 dgst[8];
578
579     hmac_sha512_run (data_buf, ipad, opad, dgst);
580
581     tmps[gid].dgst[i + 0] = dgst[0];
582     tmps[gid].dgst[i + 1] = dgst[1];
583     tmps[gid].dgst[i + 2] = dgst[2];
584     tmps[gid].dgst[i + 3] = dgst[3];
585     tmps[gid].dgst[i + 4] = dgst[4];
586     tmps[gid].dgst[i + 5] = dgst[5];
587     tmps[gid].dgst[i + 6] = dgst[6];
588     tmps[gid].dgst[i + 7] = dgst[7];
589
590     tmps[gid].out[i + 0] = dgst[0];
591     tmps[gid].out[i + 1] = dgst[1];
592     tmps[gid].out[i + 2] = dgst[2];
593     tmps[gid].out[i + 3] = dgst[3];
594     tmps[gid].out[i + 4] = dgst[4];
595     tmps[gid].out[i + 5] = dgst[5];
596     tmps[gid].out[i + 6] = dgst[6];
597     tmps[gid].out[i + 7] = dgst[7];
598   }
599 }
600
601 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08200_loop (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pbkdf2_sha512_tmp_t *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 cloudkey_t *esalt_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)
602 {
603   const u32 gid = get_global_id (0);
604
605   if (gid >= gid_max) return;
606
607   u64 ipad[8];
608
609   ipad[0] = tmps[gid].ipad[0];
610   ipad[1] = tmps[gid].ipad[1];
611   ipad[2] = tmps[gid].ipad[2];
612   ipad[3] = tmps[gid].ipad[3];
613   ipad[4] = tmps[gid].ipad[4];
614   ipad[5] = tmps[gid].ipad[5];
615   ipad[6] = tmps[gid].ipad[6];
616   ipad[7] = tmps[gid].ipad[7];
617
618   u64 opad[8];
619
620   opad[0] = tmps[gid].opad[0];
621   opad[1] = tmps[gid].opad[1];
622   opad[2] = tmps[gid].opad[2];
623   opad[3] = tmps[gid].opad[3];
624   opad[4] = tmps[gid].opad[4];
625   opad[5] = tmps[gid].opad[5];
626   opad[6] = tmps[gid].opad[6];
627   opad[7] = tmps[gid].opad[7];
628
629   for (u32 i = 0; i < 8; i += 8)
630   {
631     u64 dgst[8];
632
633     dgst[0] = tmps[gid].dgst[i + 0];
634     dgst[1] = tmps[gid].dgst[i + 1];
635     dgst[2] = tmps[gid].dgst[i + 2];
636     dgst[3] = tmps[gid].dgst[i + 3];
637     dgst[4] = tmps[gid].dgst[i + 4];
638     dgst[5] = tmps[gid].dgst[i + 5];
639     dgst[6] = tmps[gid].dgst[i + 6];
640     dgst[7] = tmps[gid].dgst[i + 7];
641
642     u64 out[8];
643
644     out[0] = tmps[gid].out[i + 0];
645     out[1] = tmps[gid].out[i + 1];
646     out[2] = tmps[gid].out[i + 2];
647     out[3] = tmps[gid].out[i + 3];
648     out[4] = tmps[gid].out[i + 4];
649     out[5] = tmps[gid].out[i + 5];
650     out[6] = tmps[gid].out[i + 6];
651     out[7] = tmps[gid].out[i + 7];
652
653     for (u32 j = 0; j < loop_cnt; j++)
654     {
655       u64 w[16];
656
657       w[ 0] = dgst[0];
658       w[ 1] = dgst[1];
659       w[ 2] = dgst[2];
660       w[ 3] = dgst[3];
661       w[ 4] = dgst[4];
662       w[ 5] = dgst[5];
663       w[ 6] = dgst[6];
664       w[ 7] = dgst[7];
665       w[ 8] = 0x8000000000000000;
666       w[ 9] = 0;
667       w[10] = 0;
668       w[11] = 0;
669       w[12] = 0;
670       w[13] = 0;
671       w[14] = 0;
672       w[15] = (128 + 64) * 8;
673
674       hmac_sha512_run (w, ipad, opad, dgst);
675
676       out[0] ^= dgst[0];
677       out[1] ^= dgst[1];
678       out[2] ^= dgst[2];
679       out[3] ^= dgst[3];
680       out[4] ^= dgst[4];
681       out[5] ^= dgst[5];
682       out[6] ^= dgst[6];
683       out[7] ^= dgst[7];
684     }
685
686     tmps[gid].dgst[i + 0] = dgst[0];
687     tmps[gid].dgst[i + 1] = dgst[1];
688     tmps[gid].dgst[i + 2] = dgst[2];
689     tmps[gid].dgst[i + 3] = dgst[3];
690     tmps[gid].dgst[i + 4] = dgst[4];
691     tmps[gid].dgst[i + 5] = dgst[5];
692     tmps[gid].dgst[i + 6] = dgst[6];
693     tmps[gid].dgst[i + 7] = dgst[7];
694
695     tmps[gid].out[i + 0] = out[0];
696     tmps[gid].out[i + 1] = out[1];
697     tmps[gid].out[i + 2] = out[2];
698     tmps[gid].out[i + 3] = out[3];
699     tmps[gid].out[i + 4] = out[4];
700     tmps[gid].out[i + 5] = out[5];
701     tmps[gid].out[i + 6] = out[6];
702     tmps[gid].out[i + 7] = out[7];
703   }
704 }
705
706 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08200_comp (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pbkdf2_sha512_tmp_t *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 cloudkey_t *esalt_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)
707 {
708   /**
709    * base
710    */
711
712   const u32 gid = get_global_id (0);
713
714   if (gid >= gid_max) return;
715
716   const u32 lid = get_local_id (0);
717
718   u32 w0[4];
719   u32 w1[4];
720   u32 w2[4];
721   u32 w3[4];
722
723   w0[0] = tmps[gid].out[4] >> 32;
724   w0[1] = tmps[gid].out[4] & 0xffffffff;
725   w0[2] = tmps[gid].out[5] >> 32;
726   w0[3] = tmps[gid].out[5] & 0xffffffff;
727   w1[0] = tmps[gid].out[6] >> 32;
728   w1[1] = tmps[gid].out[6] & 0xffffffff;
729   w1[2] = tmps[gid].out[7] >> 32;
730   w1[3] = tmps[gid].out[7] & 0xffffffff;
731   w2[0] = 0;
732   w2[1] = 0;
733   w2[2] = 0;
734   w2[3] = 0;
735   w3[0] = 0;
736   w3[1] = 0;
737   w3[2] = 0;
738   w3[3] = 0;
739
740   u32 ipad[8];
741   u32 opad[8];
742
743   hmac_sha256_pad (w0, w1, w2, w3, ipad, opad);
744
745   int size = esalt_bufs[salt_pos].data_len;
746
747   int left;
748   int off;
749
750   for (left = size, off = 0; left >= 56; left -= 64, off += 16)
751   {
752     w0[0] = esalt_bufs[salt_pos].data_buf[off +  0];
753     w0[1] = esalt_bufs[salt_pos].data_buf[off +  1];
754     w0[2] = esalt_bufs[salt_pos].data_buf[off +  2];
755     w0[3] = esalt_bufs[salt_pos].data_buf[off +  3];
756     w1[0] = esalt_bufs[salt_pos].data_buf[off +  4];
757     w1[1] = esalt_bufs[salt_pos].data_buf[off +  5];
758     w1[2] = esalt_bufs[salt_pos].data_buf[off +  6];
759     w1[3] = esalt_bufs[salt_pos].data_buf[off +  7];
760     w2[0] = esalt_bufs[salt_pos].data_buf[off +  8];
761     w2[1] = esalt_bufs[salt_pos].data_buf[off +  9];
762     w2[2] = esalt_bufs[salt_pos].data_buf[off + 10];
763     w2[3] = esalt_bufs[salt_pos].data_buf[off + 11];
764     w3[0] = esalt_bufs[salt_pos].data_buf[off + 12];
765     w3[1] = esalt_bufs[salt_pos].data_buf[off + 13];
766     w3[2] = esalt_bufs[salt_pos].data_buf[off + 14];
767     w3[3] = esalt_bufs[salt_pos].data_buf[off + 15];
768
769     sha256_transform (w0, w1, w2, w3, ipad);
770   }
771
772   w0[0] = esalt_bufs[salt_pos].data_buf[off +  0];
773   w0[1] = esalt_bufs[salt_pos].data_buf[off +  1];
774   w0[2] = esalt_bufs[salt_pos].data_buf[off +  2];
775   w0[3] = esalt_bufs[salt_pos].data_buf[off +  3];
776   w1[0] = esalt_bufs[salt_pos].data_buf[off +  4];
777   w1[1] = esalt_bufs[salt_pos].data_buf[off +  5];
778   w1[2] = esalt_bufs[salt_pos].data_buf[off +  6];
779   w1[3] = esalt_bufs[salt_pos].data_buf[off +  7];
780   w2[0] = esalt_bufs[salt_pos].data_buf[off +  8];
781   w2[1] = esalt_bufs[salt_pos].data_buf[off +  9];
782   w2[2] = esalt_bufs[salt_pos].data_buf[off + 10];
783   w2[3] = esalt_bufs[salt_pos].data_buf[off + 11];
784   w3[0] = esalt_bufs[salt_pos].data_buf[off + 12];
785   w3[1] = esalt_bufs[salt_pos].data_buf[off + 13];
786   w3[2] = 0;
787   w3[3] = (64 + size) * 8;
788
789   u32x digest[8];
790
791   hmac_sha256_run (w0, w1, w2, w3, ipad, opad, digest);
792
793   const u32x r0 = digest[0];
794   const u32x r1 = digest[1];
795   const u32x r2 = digest[2];
796   const u32x r3 = digest[3];
797
798   #define il_pos 0
799
800   #include VECT_COMPARE_M
801 }