Enable unrolling of SHA512 with HMAC on NV
[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   #pragma unroll
138   for (int i = 16; i < 64; i += 16)
139   {
140     ROUND_EXPAND (); ROUND_STEP (i);
141   }
142
143   digest[0] += a;
144   digest[1] += b;
145   digest[2] += c;
146   digest[3] += d;
147   digest[4] += e;
148   digest[5] += f;
149   digest[6] += g;
150   digest[7] += h;
151 }
152
153 void hmac_sha256_pad (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 ipad[8], u32 opad[8])
154 {
155   w0[0] = w0[0] ^ 0x36363636;
156   w0[1] = w0[1] ^ 0x36363636;
157   w0[2] = w0[2] ^ 0x36363636;
158   w0[3] = w0[3] ^ 0x36363636;
159   w1[0] = w1[0] ^ 0x36363636;
160   w1[1] = w1[1] ^ 0x36363636;
161   w1[2] = w1[2] ^ 0x36363636;
162   w1[3] = w1[3] ^ 0x36363636;
163   w2[0] = w2[0] ^ 0x36363636;
164   w2[1] = w2[1] ^ 0x36363636;
165   w2[2] = w2[2] ^ 0x36363636;
166   w2[3] = w2[3] ^ 0x36363636;
167   w3[0] = w3[0] ^ 0x36363636;
168   w3[1] = w3[1] ^ 0x36363636;
169   w3[2] = w3[2] ^ 0x36363636;
170   w3[3] = w3[3] ^ 0x36363636;
171
172   ipad[0] = SHA256M_A;
173   ipad[1] = SHA256M_B;
174   ipad[2] = SHA256M_C;
175   ipad[3] = SHA256M_D;
176   ipad[4] = SHA256M_E;
177   ipad[5] = SHA256M_F;
178   ipad[6] = SHA256M_G;
179   ipad[7] = SHA256M_H;
180
181   sha256_transform (w0, w1, w2, w3, ipad);
182
183   w0[0] = w0[0] ^ 0x6a6a6a6a;
184   w0[1] = w0[1] ^ 0x6a6a6a6a;
185   w0[2] = w0[2] ^ 0x6a6a6a6a;
186   w0[3] = w0[3] ^ 0x6a6a6a6a;
187   w1[0] = w1[0] ^ 0x6a6a6a6a;
188   w1[1] = w1[1] ^ 0x6a6a6a6a;
189   w1[2] = w1[2] ^ 0x6a6a6a6a;
190   w1[3] = w1[3] ^ 0x6a6a6a6a;
191   w2[0] = w2[0] ^ 0x6a6a6a6a;
192   w2[1] = w2[1] ^ 0x6a6a6a6a;
193   w2[2] = w2[2] ^ 0x6a6a6a6a;
194   w2[3] = w2[3] ^ 0x6a6a6a6a;
195   w3[0] = w3[0] ^ 0x6a6a6a6a;
196   w3[1] = w3[1] ^ 0x6a6a6a6a;
197   w3[2] = w3[2] ^ 0x6a6a6a6a;
198   w3[3] = w3[3] ^ 0x6a6a6a6a;
199
200   opad[0] = SHA256M_A;
201   opad[1] = SHA256M_B;
202   opad[2] = SHA256M_C;
203   opad[3] = SHA256M_D;
204   opad[4] = SHA256M_E;
205   opad[5] = SHA256M_F;
206   opad[6] = SHA256M_G;
207   opad[7] = SHA256M_H;
208
209   sha256_transform (w0, w1, w2, w3, opad);
210 }
211
212 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])
213 {
214   digest[0] = ipad[0];
215   digest[1] = ipad[1];
216   digest[2] = ipad[2];
217   digest[3] = ipad[3];
218   digest[4] = ipad[4];
219   digest[5] = ipad[5];
220   digest[6] = ipad[6];
221   digest[7] = ipad[7];
222
223   sha256_transform (w0, w1, w2, w3, digest);
224
225   w0[0] = digest[0];
226   w0[1] = digest[1];
227   w0[2] = digest[2];
228   w0[3] = digest[3];
229   w1[0] = digest[4];
230   w1[1] = digest[5];
231   w1[2] = digest[6];
232   w1[3] = digest[7];
233   w2[0] = 0x80000000;
234   w2[1] = 0;
235   w2[2] = 0;
236   w2[3] = 0;
237   w3[0] = 0;
238   w3[1] = 0;
239   w3[2] = 0;
240   w3[3] = (64 + 32) * 8;
241
242   digest[0] = opad[0];
243   digest[1] = opad[1];
244   digest[2] = opad[2];
245   digest[3] = opad[3];
246   digest[4] = opad[4];
247   digest[5] = opad[5];
248   digest[6] = opad[6];
249   digest[7] = opad[7];
250
251   sha256_transform (w0, w1, w2, w3, digest);
252 }
253
254 void sha512_transform (const u64 w[16], u64 dgst[8])
255 {
256   u64 a = dgst[0];
257   u64 b = dgst[1];
258   u64 c = dgst[2];
259   u64 d = dgst[3];
260   u64 e = dgst[4];
261   u64 f = dgst[5];
262   u64 g = dgst[6];
263   u64 h = dgst[7];
264
265   u64 w0_t = w[ 0];
266   u64 w1_t = w[ 1];
267   u64 w2_t = w[ 2];
268   u64 w3_t = w[ 3];
269   u64 w4_t = w[ 4];
270   u64 w5_t = w[ 5];
271   u64 w6_t = w[ 6];
272   u64 w7_t = w[ 7];
273   u64 w8_t = w[ 8];
274   u64 w9_t = w[ 9];
275   u64 wa_t = w[10];
276   u64 wb_t = w[11];
277   u64 wc_t = w[12];
278   u64 wd_t = w[13];
279   u64 we_t = w[14];
280   u64 wf_t = w[15];
281
282   #define ROUND512_EXPAND()                         \
283   {                                                 \
284     w0_t = SHA512_EXPAND (we_t, w9_t, w1_t, w0_t);  \
285     w1_t = SHA512_EXPAND (wf_t, wa_t, w2_t, w1_t);  \
286     w2_t = SHA512_EXPAND (w0_t, wb_t, w3_t, w2_t);  \
287     w3_t = SHA512_EXPAND (w1_t, wc_t, w4_t, w3_t);  \
288     w4_t = SHA512_EXPAND (w2_t, wd_t, w5_t, w4_t);  \
289     w5_t = SHA512_EXPAND (w3_t, we_t, w6_t, w5_t);  \
290     w6_t = SHA512_EXPAND (w4_t, wf_t, w7_t, w6_t);  \
291     w7_t = SHA512_EXPAND (w5_t, w0_t, w8_t, w7_t);  \
292     w8_t = SHA512_EXPAND (w6_t, w1_t, w9_t, w8_t);  \
293     w9_t = SHA512_EXPAND (w7_t, w2_t, wa_t, w9_t);  \
294     wa_t = SHA512_EXPAND (w8_t, w3_t, wb_t, wa_t);  \
295     wb_t = SHA512_EXPAND (w9_t, w4_t, wc_t, wb_t);  \
296     wc_t = SHA512_EXPAND (wa_t, w5_t, wd_t, wc_t);  \
297     wd_t = SHA512_EXPAND (wb_t, w6_t, we_t, wd_t);  \
298     we_t = SHA512_EXPAND (wc_t, w7_t, wf_t, we_t);  \
299     wf_t = SHA512_EXPAND (wd_t, w8_t, w0_t, wf_t);  \
300   }
301
302   #define ROUND512_STEP(i)                                                                \
303   {                                                                                       \
304     SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha512[i +  0]); \
305     SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha512[i +  1]); \
306     SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha512[i +  2]); \
307     SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha512[i +  3]); \
308     SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha512[i +  4]); \
309     SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha512[i +  5]); \
310     SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha512[i +  6]); \
311     SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha512[i +  7]); \
312     SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha512[i +  8]); \
313     SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha512[i +  9]); \
314     SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha512[i + 10]); \
315     SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha512[i + 11]); \
316     SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha512[i + 12]); \
317     SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha512[i + 13]); \
318     SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, we_t, k_sha512[i + 14]); \
319     SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha512[i + 15]); \
320   }
321
322   ROUND512_STEP (0);
323
324   #ifdef IS_AMD
325   // #pragma unroll
326   // breaks compiler
327   #else
328   #pragma unroll
329   #endif
330   for (int i = 16; i < 80; i += 16)
331   {
332     ROUND512_EXPAND (); ROUND512_STEP (i);
333   }
334
335   dgst[0] += a;
336   dgst[1] += b;
337   dgst[2] += c;
338   dgst[3] += d;
339   dgst[4] += e;
340   dgst[5] += f;
341   dgst[6] += g;
342   dgst[7] += h;
343 }
344
345 void hmac_sha512_run (const u64 w1[16], const u64 ipad[8], const u64 opad[8], u64 dgst[8])
346 {
347   dgst[0] = ipad[0];
348   dgst[1] = ipad[1];
349   dgst[2] = ipad[2];
350   dgst[3] = ipad[3];
351   dgst[4] = ipad[4];
352   dgst[5] = ipad[5];
353   dgst[6] = ipad[6];
354   dgst[7] = ipad[7];
355
356   sha512_transform (w1, dgst);
357
358   u64 w[16];
359
360   w[ 0] = dgst[0];
361   w[ 1] = dgst[1];
362   w[ 2] = dgst[2];
363   w[ 3] = dgst[3];
364   w[ 4] = dgst[4];
365   w[ 5] = dgst[5];
366   w[ 6] = dgst[6];
367   w[ 7] = dgst[7];
368   w[ 8] = 0x8000000000000000;
369   w[ 9] = 0;
370   w[10] = 0;
371   w[11] = 0;
372   w[12] = 0;
373   w[13] = 0;
374   w[14] = 0;
375   w[15] = (128 + 64) * 8;
376
377   dgst[0] = opad[0];
378   dgst[1] = opad[1];
379   dgst[2] = opad[2];
380   dgst[3] = opad[3];
381   dgst[4] = opad[4];
382   dgst[5] = opad[5];
383   dgst[6] = opad[6];
384   dgst[7] = opad[7];
385
386   sha512_transform (w, dgst);
387 }
388
389 void hmac_sha512_init (u64 w[16], u64 ipad[8], u64 opad[8])
390 {
391   w[ 0] ^= 0x3636363636363636;
392   w[ 1] ^= 0x3636363636363636;
393   w[ 2] ^= 0x3636363636363636;
394   w[ 3] ^= 0x3636363636363636;
395   w[ 4] ^= 0x3636363636363636;
396   w[ 5] ^= 0x3636363636363636;
397   w[ 6] ^= 0x3636363636363636;
398   w[ 7] ^= 0x3636363636363636;
399   w[ 8] ^= 0x3636363636363636;
400   w[ 9] ^= 0x3636363636363636;
401   w[10] ^= 0x3636363636363636;
402   w[11] ^= 0x3636363636363636;
403   w[12] ^= 0x3636363636363636;
404   w[13] ^= 0x3636363636363636;
405   w[14] ^= 0x3636363636363636;
406   w[15] ^= 0x3636363636363636;
407
408   ipad[0] = SHA512M_A;
409   ipad[1] = SHA512M_B;
410   ipad[2] = SHA512M_C;
411   ipad[3] = SHA512M_D;
412   ipad[4] = SHA512M_E;
413   ipad[5] = SHA512M_F;
414   ipad[6] = SHA512M_G;
415   ipad[7] = SHA512M_H;
416
417   sha512_transform (w, ipad);
418
419   w[ 0] ^= 0x6a6a6a6a6a6a6a6a;
420   w[ 1] ^= 0x6a6a6a6a6a6a6a6a;
421   w[ 2] ^= 0x6a6a6a6a6a6a6a6a;
422   w[ 3] ^= 0x6a6a6a6a6a6a6a6a;
423   w[ 4] ^= 0x6a6a6a6a6a6a6a6a;
424   w[ 5] ^= 0x6a6a6a6a6a6a6a6a;
425   w[ 6] ^= 0x6a6a6a6a6a6a6a6a;
426   w[ 7] ^= 0x6a6a6a6a6a6a6a6a;
427   w[ 8] ^= 0x6a6a6a6a6a6a6a6a;
428   w[ 9] ^= 0x6a6a6a6a6a6a6a6a;
429   w[10] ^= 0x6a6a6a6a6a6a6a6a;
430   w[11] ^= 0x6a6a6a6a6a6a6a6a;
431   w[12] ^= 0x6a6a6a6a6a6a6a6a;
432   w[13] ^= 0x6a6a6a6a6a6a6a6a;
433   w[14] ^= 0x6a6a6a6a6a6a6a6a;
434   w[15] ^= 0x6a6a6a6a6a6a6a6a;
435
436   opad[0] = SHA512M_A;
437   opad[1] = SHA512M_B;
438   opad[2] = SHA512M_C;
439   opad[3] = SHA512M_D;
440   opad[4] = SHA512M_E;
441   opad[5] = SHA512M_F;
442   opad[6] = SHA512M_G;
443   opad[7] = SHA512M_H;
444
445   sha512_transform (w, opad);
446 }
447
448 __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)
449 {
450   /**
451    * base
452    */
453
454   const u32 gid = get_global_id (0);
455
456   if (gid >= gid_max) return;
457
458   u32 w0[4];
459
460   w0[0] = pws[gid].i[ 0];
461   w0[1] = pws[gid].i[ 1];
462   w0[2] = pws[gid].i[ 2];
463   w0[3] = pws[gid].i[ 3];
464
465   u32 w1[4];
466
467   w1[0] = pws[gid].i[ 4];
468   w1[1] = pws[gid].i[ 5];
469   w1[2] = pws[gid].i[ 6];
470   w1[3] = pws[gid].i[ 7];
471
472   u32 w2[4];
473
474   w2[0] = pws[gid].i[ 8];
475   w2[1] = pws[gid].i[ 9];
476   w2[2] = pws[gid].i[10];
477   w2[3] = pws[gid].i[11];
478
479   u32 w3[4];
480
481   w3[0] = pws[gid].i[12];
482   w3[1] = pws[gid].i[13];
483   w3[2] = pws[gid].i[14];
484   w3[3] = pws[gid].i[15];
485
486   /**
487    * salt
488    */
489
490   u32 salt_buf0[4];
491
492   salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
493   salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
494   salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
495   salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
496
497   u32 salt_buf1[4];
498
499   salt_buf1[0] = salt_bufs[salt_pos].salt_buf[ 4];
500   salt_buf1[1] = salt_bufs[salt_pos].salt_buf[ 5];
501   salt_buf1[2] = 0;
502   salt_buf1[3] = 0;
503
504   const u32 salt_len = salt_bufs[salt_pos].salt_len;
505
506   u64 data_buf[16];
507
508   data_buf[ 0] = ((u64) swap32 (salt_buf0[ 0])) << 32 | (u64) swap32 (salt_buf0[ 1]);
509   data_buf[ 1] = ((u64) swap32 (salt_buf0[ 2])) << 32 | (u64) swap32 (salt_buf0[ 3]);
510   data_buf[ 2] = ((u64) swap32 (salt_buf1[ 0])) << 32 | (u64) swap32 (salt_buf1[ 1]);
511   data_buf[ 3] = 0;
512   data_buf[ 4] = 0;
513   data_buf[ 5] = 0;
514   data_buf[ 6] = 0;
515   data_buf[ 7] = 0;
516   data_buf[ 8] = 0;
517   data_buf[ 9] = 0;
518   data_buf[10] = 0;
519   data_buf[11] = 0;
520   data_buf[12] = 0;
521   data_buf[13] = 0;
522   data_buf[14] = 0;
523   data_buf[15] = (128 + salt_len + 4) * 8;
524
525   u64 w[16];
526
527   w[ 0] = ((u64) swap32 (w0[0])) << 32 | (u64) swap32 (w0[1]);
528   w[ 1] = ((u64) swap32 (w0[2])) << 32 | (u64) swap32 (w0[3]);
529   w[ 2] = ((u64) swap32 (w1[0])) << 32 | (u64) swap32 (w1[1]);
530   w[ 3] = ((u64) swap32 (w1[2])) << 32 | (u64) swap32 (w1[3]);
531   w[ 4] = ((u64) swap32 (w2[0])) << 32 | (u64) swap32 (w2[1]);
532   w[ 5] = ((u64) swap32 (w2[2])) << 32 | (u64) swap32 (w2[3]);
533   w[ 6] = ((u64) swap32 (w3[0])) << 32 | (u64) swap32 (w3[1]);
534   w[ 7] = ((u64) swap32 (w3[2])) << 32 | (u64) swap32 (w3[3]);
535   w[ 8] = 0;
536   w[ 9] = 0;
537   w[10] = 0;
538   w[11] = 0;
539   w[12] = 0;
540   w[13] = 0;
541   w[14] = 0;
542   w[15] = 0;
543
544   u64 ipad[8];
545   u64 opad[8];
546
547   hmac_sha512_init (w, ipad, opad);
548
549   tmps[gid].ipad[0] = ipad[0];
550   tmps[gid].ipad[1] = ipad[1];
551   tmps[gid].ipad[2] = ipad[2];
552   tmps[gid].ipad[3] = ipad[3];
553   tmps[gid].ipad[4] = ipad[4];
554   tmps[gid].ipad[5] = ipad[5];
555   tmps[gid].ipad[6] = ipad[6];
556   tmps[gid].ipad[7] = ipad[7];
557
558   tmps[gid].opad[0] = opad[0];
559   tmps[gid].opad[1] = opad[1];
560   tmps[gid].opad[2] = opad[2];
561   tmps[gid].opad[3] = opad[3];
562   tmps[gid].opad[4] = opad[4];
563   tmps[gid].opad[5] = opad[5];
564   tmps[gid].opad[6] = opad[6];
565   tmps[gid].opad[7] = opad[7];
566
567   for (u32 i = 0, j = 1; i < 8; i += 8, j += 1)
568   {
569     u64 dgst[8];
570
571     hmac_sha512_run (data_buf, ipad, opad, dgst);
572
573     tmps[gid].dgst[i + 0] = dgst[0];
574     tmps[gid].dgst[i + 1] = dgst[1];
575     tmps[gid].dgst[i + 2] = dgst[2];
576     tmps[gid].dgst[i + 3] = dgst[3];
577     tmps[gid].dgst[i + 4] = dgst[4];
578     tmps[gid].dgst[i + 5] = dgst[5];
579     tmps[gid].dgst[i + 6] = dgst[6];
580     tmps[gid].dgst[i + 7] = dgst[7];
581
582     tmps[gid].out[i + 0] = dgst[0];
583     tmps[gid].out[i + 1] = dgst[1];
584     tmps[gid].out[i + 2] = dgst[2];
585     tmps[gid].out[i + 3] = dgst[3];
586     tmps[gid].out[i + 4] = dgst[4];
587     tmps[gid].out[i + 5] = dgst[5];
588     tmps[gid].out[i + 6] = dgst[6];
589     tmps[gid].out[i + 7] = dgst[7];
590   }
591 }
592
593 __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)
594 {
595   const u32 gid = get_global_id (0);
596
597   if (gid >= gid_max) return;
598
599   u64 ipad[8];
600
601   ipad[0] = tmps[gid].ipad[0];
602   ipad[1] = tmps[gid].ipad[1];
603   ipad[2] = tmps[gid].ipad[2];
604   ipad[3] = tmps[gid].ipad[3];
605   ipad[4] = tmps[gid].ipad[4];
606   ipad[5] = tmps[gid].ipad[5];
607   ipad[6] = tmps[gid].ipad[6];
608   ipad[7] = tmps[gid].ipad[7];
609
610   u64 opad[8];
611
612   opad[0] = tmps[gid].opad[0];
613   opad[1] = tmps[gid].opad[1];
614   opad[2] = tmps[gid].opad[2];
615   opad[3] = tmps[gid].opad[3];
616   opad[4] = tmps[gid].opad[4];
617   opad[5] = tmps[gid].opad[5];
618   opad[6] = tmps[gid].opad[6];
619   opad[7] = tmps[gid].opad[7];
620
621   for (u32 i = 0; i < 8; i += 8)
622   {
623     u64 dgst[8];
624
625     dgst[0] = tmps[gid].dgst[i + 0];
626     dgst[1] = tmps[gid].dgst[i + 1];
627     dgst[2] = tmps[gid].dgst[i + 2];
628     dgst[3] = tmps[gid].dgst[i + 3];
629     dgst[4] = tmps[gid].dgst[i + 4];
630     dgst[5] = tmps[gid].dgst[i + 5];
631     dgst[6] = tmps[gid].dgst[i + 6];
632     dgst[7] = tmps[gid].dgst[i + 7];
633
634     u64 out[8];
635
636     out[0] = tmps[gid].out[i + 0];
637     out[1] = tmps[gid].out[i + 1];
638     out[2] = tmps[gid].out[i + 2];
639     out[3] = tmps[gid].out[i + 3];
640     out[4] = tmps[gid].out[i + 4];
641     out[5] = tmps[gid].out[i + 5];
642     out[6] = tmps[gid].out[i + 6];
643     out[7] = tmps[gid].out[i + 7];
644
645     for (u32 j = 0; j < loop_cnt; j++)
646     {
647       u64 w[16];
648
649       w[ 0] = dgst[0];
650       w[ 1] = dgst[1];
651       w[ 2] = dgst[2];
652       w[ 3] = dgst[3];
653       w[ 4] = dgst[4];
654       w[ 5] = dgst[5];
655       w[ 6] = dgst[6];
656       w[ 7] = dgst[7];
657       w[ 8] = 0x8000000000000000;
658       w[ 9] = 0;
659       w[10] = 0;
660       w[11] = 0;
661       w[12] = 0;
662       w[13] = 0;
663       w[14] = 0;
664       w[15] = (128 + 64) * 8;
665
666       hmac_sha512_run (w, ipad, opad, dgst);
667
668       out[0] ^= dgst[0];
669       out[1] ^= dgst[1];
670       out[2] ^= dgst[2];
671       out[3] ^= dgst[3];
672       out[4] ^= dgst[4];
673       out[5] ^= dgst[5];
674       out[6] ^= dgst[6];
675       out[7] ^= dgst[7];
676     }
677
678     tmps[gid].dgst[i + 0] = dgst[0];
679     tmps[gid].dgst[i + 1] = dgst[1];
680     tmps[gid].dgst[i + 2] = dgst[2];
681     tmps[gid].dgst[i + 3] = dgst[3];
682     tmps[gid].dgst[i + 4] = dgst[4];
683     tmps[gid].dgst[i + 5] = dgst[5];
684     tmps[gid].dgst[i + 6] = dgst[6];
685     tmps[gid].dgst[i + 7] = dgst[7];
686
687     tmps[gid].out[i + 0] = out[0];
688     tmps[gid].out[i + 1] = out[1];
689     tmps[gid].out[i + 2] = out[2];
690     tmps[gid].out[i + 3] = out[3];
691     tmps[gid].out[i + 4] = out[4];
692     tmps[gid].out[i + 5] = out[5];
693     tmps[gid].out[i + 6] = out[6];
694     tmps[gid].out[i + 7] = out[7];
695   }
696 }
697
698 __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)
699 {
700   /**
701    * base
702    */
703
704   const u32 gid = get_global_id (0);
705
706   if (gid >= gid_max) return;
707
708   const u32 lid = get_local_id (0);
709
710   u32 w0[4];
711   u32 w1[4];
712   u32 w2[4];
713   u32 w3[4];
714
715   w0[0] = tmps[gid].out[4] >> 32;
716   w0[1] = tmps[gid].out[4] & 0xffffffff;
717   w0[2] = tmps[gid].out[5] >> 32;
718   w0[3] = tmps[gid].out[5] & 0xffffffff;
719   w1[0] = tmps[gid].out[6] >> 32;
720   w1[1] = tmps[gid].out[6] & 0xffffffff;
721   w1[2] = tmps[gid].out[7] >> 32;
722   w1[3] = tmps[gid].out[7] & 0xffffffff;
723   w2[0] = 0;
724   w2[1] = 0;
725   w2[2] = 0;
726   w2[3] = 0;
727   w3[0] = 0;
728   w3[1] = 0;
729   w3[2] = 0;
730   w3[3] = 0;
731
732   u32 ipad[8];
733   u32 opad[8];
734
735   hmac_sha256_pad (w0, w1, w2, w3, ipad, opad);
736
737   int size = esalt_bufs[salt_pos].data_len;
738
739   int left;
740   int off;
741
742   for (left = size, off = 0; left >= 56; left -= 64, off += 16)
743   {
744     w0[0] = esalt_bufs[salt_pos].data_buf[off +  0];
745     w0[1] = esalt_bufs[salt_pos].data_buf[off +  1];
746     w0[2] = esalt_bufs[salt_pos].data_buf[off +  2];
747     w0[3] = esalt_bufs[salt_pos].data_buf[off +  3];
748     w1[0] = esalt_bufs[salt_pos].data_buf[off +  4];
749     w1[1] = esalt_bufs[salt_pos].data_buf[off +  5];
750     w1[2] = esalt_bufs[salt_pos].data_buf[off +  6];
751     w1[3] = esalt_bufs[salt_pos].data_buf[off +  7];
752     w2[0] = esalt_bufs[salt_pos].data_buf[off +  8];
753     w2[1] = esalt_bufs[salt_pos].data_buf[off +  9];
754     w2[2] = esalt_bufs[salt_pos].data_buf[off + 10];
755     w2[3] = esalt_bufs[salt_pos].data_buf[off + 11];
756     w3[0] = esalt_bufs[salt_pos].data_buf[off + 12];
757     w3[1] = esalt_bufs[salt_pos].data_buf[off + 13];
758     w3[2] = esalt_bufs[salt_pos].data_buf[off + 14];
759     w3[3] = esalt_bufs[salt_pos].data_buf[off + 15];
760
761     sha256_transform (w0, w1, w2, w3, ipad);
762   }
763
764   w0[0] = esalt_bufs[salt_pos].data_buf[off +  0];
765   w0[1] = esalt_bufs[salt_pos].data_buf[off +  1];
766   w0[2] = esalt_bufs[salt_pos].data_buf[off +  2];
767   w0[3] = esalt_bufs[salt_pos].data_buf[off +  3];
768   w1[0] = esalt_bufs[salt_pos].data_buf[off +  4];
769   w1[1] = esalt_bufs[salt_pos].data_buf[off +  5];
770   w1[2] = esalt_bufs[salt_pos].data_buf[off +  6];
771   w1[3] = esalt_bufs[salt_pos].data_buf[off +  7];
772   w2[0] = esalt_bufs[salt_pos].data_buf[off +  8];
773   w2[1] = esalt_bufs[salt_pos].data_buf[off +  9];
774   w2[2] = esalt_bufs[salt_pos].data_buf[off + 10];
775   w2[3] = esalt_bufs[salt_pos].data_buf[off + 11];
776   w3[0] = esalt_bufs[salt_pos].data_buf[off + 12];
777   w3[1] = esalt_bufs[salt_pos].data_buf[off + 13];
778   w3[2] = 0;
779   w3[3] = (64 + size) * 8;
780
781   u32 digest[8];
782
783   hmac_sha256_run (w0, w1, w2, w3, ipad, opad, digest);
784
785   const u32 r0 = digest[0];
786   const u32 r1 = digest[1];
787   const u32 r2 = digest[2];
788   const u32 r3 = digest[3];
789
790   #define il_pos 0
791
792   #include COMPARE_M
793 }