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