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