042753ed16774b7a17d2af53aedc4cb050be3e76
[hashcat.git] / OpenCL / m01460_a1.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _SHA256_
7
8 #define NEW_SIMD_CODE
9
10 #include "inc_hash_constants.h"
11 #include "inc_vendor.cl"
12
13 #define DGST_R0 3
14 #define DGST_R1 7
15 #define DGST_R2 2
16 #define DGST_R3 6
17
18 #include "inc_hash_functions.cl"
19 #include "inc_types.cl"
20 #include "inc_common.cl"
21 #include "inc_simd.cl"
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 void sha256_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[8])
44 {
45   u32x a = digest[0];
46   u32x b = digest[1];
47   u32x c = digest[2];
48   u32x d = digest[3];
49   u32x e = digest[4];
50   u32x f = digest[5];
51   u32x g = digest[6];
52   u32x h = digest[7];
53
54   u32x w0_t = w0[0];
55   u32x w1_t = w0[1];
56   u32x w2_t = w0[2];
57   u32x w3_t = w0[3];
58   u32x w4_t = w1[0];
59   u32x w5_t = w1[1];
60   u32x w6_t = w1[2];
61   u32x w7_t = w1[3];
62   u32x w8_t = w2[0];
63   u32x w9_t = w2[1];
64   u32x wa_t = w2[2];
65   u32x wb_t = w2[3];
66   u32x wc_t = w3[0];
67   u32x wd_t = w3[1];
68   u32x we_t = w3[2];
69   u32x wf_t = w3[3];
70
71   #define ROUND_EXPAND()                            \
72   {                                                 \
73     w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t);  \
74     w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t);  \
75     w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t);  \
76     w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t);  \
77     w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t);  \
78     w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t);  \
79     w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t);  \
80     w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t);  \
81     w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t);  \
82     w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t);  \
83     wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t);  \
84     wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t);  \
85     wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t);  \
86     wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t);  \
87     we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t);  \
88     wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t);  \
89   }
90
91   #define ROUND_STEP(i)                                                                   \
92   {                                                                                       \
93     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i +  0]); \
94     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i +  1]); \
95     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i +  2]); \
96     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i +  3]); \
97     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i +  4]); \
98     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i +  5]); \
99     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i +  6]); \
100     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i +  7]); \
101     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i +  8]); \
102     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i +  9]); \
103     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
104     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
105     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
106     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
107     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
108     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
109   }
110
111   ROUND_STEP (0);
112
113   #ifdef _unroll
114   #pragma unroll
115   #endif
116   for (int i = 16; i < 64; i += 16)
117   {
118     ROUND_EXPAND (); ROUND_STEP (i);
119   }
120
121   digest[0] += a;
122   digest[1] += b;
123   digest[2] += c;
124   digest[3] += d;
125   digest[4] += e;
126   digest[5] += f;
127   digest[6] += g;
128   digest[7] += h;
129 }
130
131 void hmac_sha256_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[8], u32x opad[8])
132 {
133   w0[0] = w0[0] ^ 0x36363636;
134   w0[1] = w0[1] ^ 0x36363636;
135   w0[2] = w0[2] ^ 0x36363636;
136   w0[3] = w0[3] ^ 0x36363636;
137   w1[0] = w1[0] ^ 0x36363636;
138   w1[1] = w1[1] ^ 0x36363636;
139   w1[2] = w1[2] ^ 0x36363636;
140   w1[3] = w1[3] ^ 0x36363636;
141   w2[0] = w2[0] ^ 0x36363636;
142   w2[1] = w2[1] ^ 0x36363636;
143   w2[2] = w2[2] ^ 0x36363636;
144   w2[3] = w2[3] ^ 0x36363636;
145   w3[0] = w3[0] ^ 0x36363636;
146   w3[1] = w3[1] ^ 0x36363636;
147   w3[2] = w3[2] ^ 0x36363636;
148   w3[3] = w3[3] ^ 0x36363636;
149
150   ipad[0] = SHA256M_A;
151   ipad[1] = SHA256M_B;
152   ipad[2] = SHA256M_C;
153   ipad[3] = SHA256M_D;
154   ipad[4] = SHA256M_E;
155   ipad[5] = SHA256M_F;
156   ipad[6] = SHA256M_G;
157   ipad[7] = SHA256M_H;
158
159   sha256_transform (w0, w1, w2, w3, ipad);
160
161   w0[0] = w0[0] ^ 0x6a6a6a6a;
162   w0[1] = w0[1] ^ 0x6a6a6a6a;
163   w0[2] = w0[2] ^ 0x6a6a6a6a;
164   w0[3] = w0[3] ^ 0x6a6a6a6a;
165   w1[0] = w1[0] ^ 0x6a6a6a6a;
166   w1[1] = w1[1] ^ 0x6a6a6a6a;
167   w1[2] = w1[2] ^ 0x6a6a6a6a;
168   w1[3] = w1[3] ^ 0x6a6a6a6a;
169   w2[0] = w2[0] ^ 0x6a6a6a6a;
170   w2[1] = w2[1] ^ 0x6a6a6a6a;
171   w2[2] = w2[2] ^ 0x6a6a6a6a;
172   w2[3] = w2[3] ^ 0x6a6a6a6a;
173   w3[0] = w3[0] ^ 0x6a6a6a6a;
174   w3[1] = w3[1] ^ 0x6a6a6a6a;
175   w3[2] = w3[2] ^ 0x6a6a6a6a;
176   w3[3] = w3[3] ^ 0x6a6a6a6a;
177
178   opad[0] = SHA256M_A;
179   opad[1] = SHA256M_B;
180   opad[2] = SHA256M_C;
181   opad[3] = SHA256M_D;
182   opad[4] = SHA256M_E;
183   opad[5] = SHA256M_F;
184   opad[6] = SHA256M_G;
185   opad[7] = SHA256M_H;
186
187   sha256_transform (w0, w1, w2, w3, opad);
188 }
189
190 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])
191 {
192   digest[0] = ipad[0];
193   digest[1] = ipad[1];
194   digest[2] = ipad[2];
195   digest[3] = ipad[3];
196   digest[4] = ipad[4];
197   digest[5] = ipad[5];
198   digest[6] = ipad[6];
199   digest[7] = ipad[7];
200
201   sha256_transform (w0, w1, w2, w3, digest);
202
203   w0[0] = digest[0];
204   w0[1] = digest[1];
205   w0[2] = digest[2];
206   w0[3] = digest[3];
207   w1[0] = digest[4];
208   w1[1] = digest[5];
209   w1[2] = digest[6];
210   w1[3] = digest[7];
211   w2[0] = 0x80000000;
212   w2[1] = 0;
213   w2[2] = 0;
214   w2[3] = 0;
215   w3[0] = 0;
216   w3[1] = 0;
217   w3[2] = 0;
218   w3[3] = (64 + 32) * 8;
219
220   digest[0] = opad[0];
221   digest[1] = opad[1];
222   digest[2] = opad[2];
223   digest[3] = opad[3];
224   digest[4] = opad[4];
225   digest[5] = opad[5];
226   digest[6] = opad[6];
227   digest[7] = opad[7];
228
229   sha256_transform (w0, w1, w2, w3, digest);
230 }
231
232 __kernel void m01460_m04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *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)
233 {
234   /**
235    * modifier
236    */
237
238   const u32 lid = get_local_id (0);
239
240   /**
241    * base
242    */
243
244   const u32 gid = get_global_id (0);
245
246   if (gid >= gid_max) return;
247
248   u32 pw_buf0[4];
249   u32 pw_buf1[4];
250
251   pw_buf0[0] = pws[gid].i[0];
252   pw_buf0[1] = pws[gid].i[1];
253   pw_buf0[2] = pws[gid].i[2];
254   pw_buf0[3] = pws[gid].i[3];
255   pw_buf1[0] = pws[gid].i[4];
256   pw_buf1[1] = pws[gid].i[5];
257   pw_buf1[2] = pws[gid].i[6];
258   pw_buf1[3] = pws[gid].i[7];
259
260   const u32 pw_l_len = pws[gid].pw_len;
261
262   /**
263    * salt
264    */
265
266   u32 salt_buf0[4];
267   u32 salt_buf1[4];
268   u32 salt_buf2[4];
269   u32 salt_buf3[4];
270
271   salt_buf0[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 0]);
272   salt_buf0[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 1]);
273   salt_buf0[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 2]);
274   salt_buf0[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 3]);
275   salt_buf1[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 4]);
276   salt_buf1[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 5]);
277   salt_buf1[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 6]);
278   salt_buf1[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 7]);
279   salt_buf2[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 8]);
280   salt_buf2[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 9]);
281   salt_buf2[2] = swap32_S (salt_bufs[salt_pos].salt_buf[10]);
282   salt_buf2[3] = swap32_S (salt_bufs[salt_pos].salt_buf[11]);
283   salt_buf3[0] = swap32_S (salt_bufs[salt_pos].salt_buf[12]);
284   salt_buf3[1] = swap32_S (salt_bufs[salt_pos].salt_buf[13]);
285   salt_buf3[2] = swap32_S (salt_bufs[salt_pos].salt_buf[14]);
286   salt_buf3[3] = swap32_S (salt_bufs[salt_pos].salt_buf[15]);
287
288   const u32 salt_len = salt_bufs[salt_pos].salt_len;
289
290   /**
291    * pads
292    */
293
294   u32x w0_t[4];
295   u32x w1_t[4];
296   u32x w2_t[4];
297   u32x w3_t[4];
298
299   w0_t[0] = salt_buf0[0];
300   w0_t[1] = salt_buf0[1];
301   w0_t[2] = salt_buf0[2];
302   w0_t[3] = salt_buf0[3];
303   w1_t[0] = salt_buf1[0];
304   w1_t[1] = salt_buf1[1];
305   w1_t[2] = salt_buf1[2];
306   w1_t[3] = salt_buf1[3];
307   w2_t[0] = salt_buf2[0];
308   w2_t[1] = salt_buf2[1];
309   w2_t[2] = salt_buf2[2];
310   w2_t[3] = salt_buf2[3];
311   w3_t[0] = salt_buf3[0];
312   w3_t[1] = salt_buf3[1];
313   w3_t[2] = salt_buf3[2];
314   w3_t[3] = salt_buf3[3];
315
316   u32x ipad[8];
317   u32x opad[8];
318
319   hmac_sha256_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
320
321   /**
322    * loop
323    */
324
325   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
326   {
327     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
328
329     const u32x pw_len = pw_l_len + pw_r_len;
330
331     /**
332      * concat password candidate
333      */
334
335     u32x wordl0[4] = { 0 };
336     u32x wordl1[4] = { 0 };
337     u32x wordl2[4] = { 0 };
338     u32x wordl3[4] = { 0 };
339
340     wordl0[0] = pw_buf0[0];
341     wordl0[1] = pw_buf0[1];
342     wordl0[2] = pw_buf0[2];
343     wordl0[3] = pw_buf0[3];
344     wordl1[0] = pw_buf1[0];
345     wordl1[1] = pw_buf1[1];
346     wordl1[2] = pw_buf1[2];
347     wordl1[3] = pw_buf1[3];
348
349     u32x wordr0[4] = { 0 };
350     u32x wordr1[4] = { 0 };
351     u32x wordr2[4] = { 0 };
352     u32x wordr3[4] = { 0 };
353
354     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
355     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
356     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
357     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
358     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
359     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
360     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
361     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
362
363     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
364     {
365       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
366     }
367     else
368     {
369       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
370     }
371
372     u32x w0[4];
373     u32x w1[4];
374     u32x w2[4];
375     u32x w3[4];
376
377     w0[0] = wordl0[0] | wordr0[0];
378     w0[1] = wordl0[1] | wordr0[1];
379     w0[2] = wordl0[2] | wordr0[2];
380     w0[3] = wordl0[3] | wordr0[3];
381     w1[0] = wordl1[0] | wordr1[0];
382     w1[1] = wordl1[1] | wordr1[1];
383     w1[2] = wordl1[2] | wordr1[2];
384     w1[3] = wordl1[3] | wordr1[3];
385     w2[0] = wordl2[0] | wordr2[0];
386     w2[1] = wordl2[1] | wordr2[1];
387     w2[2] = wordl2[2] | wordr2[2];
388     w2[3] = wordl2[3] | wordr2[3];
389     w3[0] = wordl3[0] | wordr3[0];
390     w3[1] = wordl3[1] | wordr3[1];
391     w3[2] = wordl3[2] | wordr3[2];
392     w3[3] = wordl3[3] | wordr3[3];
393
394     append_0x80_4x4_VV (w0, w1, w2, w3, pw_len);
395
396     w0[0] = swap32 (w0[0]);
397     w0[1] = swap32 (w0[1]);
398     w0[2] = swap32 (w0[2]);
399     w0[3] = swap32 (w0[3]);
400     w1[0] = swap32 (w1[0]);
401     w1[1] = swap32 (w1[1]);
402     w1[2] = swap32 (w1[2]);
403     w1[3] = swap32 (w1[3]);
404     w2[0] = swap32 (w2[0]);
405     w2[1] = swap32 (w2[1]);
406     w2[2] = swap32 (w2[2]);
407     w2[3] = swap32 (w2[3]);
408     w3[0] = swap32 (w3[0]);
409     w3[1] = swap32 (w3[1]);
410     w3[2] = 0;
411     w3[3] = (64 + pw_len) * 8;
412
413     u32x digest[8];
414
415     hmac_sha256_run (w0, w1, w2, w3, ipad, opad, digest);
416
417     COMPARE_M_SIMD (digest[3], digest[7], digest[2], digest[6]);
418   }
419 }
420
421 __kernel void m01460_m08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *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)
422 {
423 }
424
425 __kernel void m01460_m16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *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)
426 {
427 }
428
429 __kernel void m01460_s04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *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)
430 {
431   /**
432    * modifier
433    */
434
435   const u32 lid = get_local_id (0);
436
437   /**
438    * base
439    */
440
441   const u32 gid = get_global_id (0);
442
443   if (gid >= gid_max) return;
444
445   u32 pw_buf0[4];
446   u32 pw_buf1[4];
447
448   pw_buf0[0] = pws[gid].i[0];
449   pw_buf0[1] = pws[gid].i[1];
450   pw_buf0[2] = pws[gid].i[2];
451   pw_buf0[3] = pws[gid].i[3];
452   pw_buf1[0] = pws[gid].i[4];
453   pw_buf1[1] = pws[gid].i[5];
454   pw_buf1[2] = pws[gid].i[6];
455   pw_buf1[3] = pws[gid].i[7];
456
457   const u32 pw_l_len = pws[gid].pw_len;
458
459   /**
460    * salt
461    */
462
463   u32 salt_buf0[4];
464   u32 salt_buf1[4];
465   u32 salt_buf2[4];
466   u32 salt_buf3[4];
467
468   salt_buf0[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 0]);
469   salt_buf0[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 1]);
470   salt_buf0[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 2]);
471   salt_buf0[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 3]);
472   salt_buf1[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 4]);
473   salt_buf1[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 5]);
474   salt_buf1[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 6]);
475   salt_buf1[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 7]);
476   salt_buf2[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 8]);
477   salt_buf2[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 9]);
478   salt_buf2[2] = swap32_S (salt_bufs[salt_pos].salt_buf[10]);
479   salt_buf2[3] = swap32_S (salt_bufs[salt_pos].salt_buf[11]);
480   salt_buf3[0] = swap32_S (salt_bufs[salt_pos].salt_buf[12]);
481   salt_buf3[1] = swap32_S (salt_bufs[salt_pos].salt_buf[13]);
482   salt_buf3[2] = swap32_S (salt_bufs[salt_pos].salt_buf[14]);
483   salt_buf3[3] = swap32_S (salt_bufs[salt_pos].salt_buf[15]);
484
485   const u32 salt_len = salt_bufs[salt_pos].salt_len;
486
487   /**
488    * pads
489    */
490
491   u32x w0_t[4];
492   u32x w1_t[4];
493   u32x w2_t[4];
494   u32x w3_t[4];
495
496   w0_t[0] = salt_buf0[0];
497   w0_t[1] = salt_buf0[1];
498   w0_t[2] = salt_buf0[2];
499   w0_t[3] = salt_buf0[3];
500   w1_t[0] = salt_buf1[0];
501   w1_t[1] = salt_buf1[1];
502   w1_t[2] = salt_buf1[2];
503   w1_t[3] = salt_buf1[3];
504   w2_t[0] = salt_buf2[0];
505   w2_t[1] = salt_buf2[1];
506   w2_t[2] = salt_buf2[2];
507   w2_t[3] = salt_buf2[3];
508   w3_t[0] = salt_buf3[0];
509   w3_t[1] = salt_buf3[1];
510   w3_t[2] = salt_buf3[2];
511   w3_t[3] = salt_buf3[3];
512
513   u32x ipad[8];
514   u32x opad[8];
515
516   hmac_sha256_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
517
518   /**
519    * digest
520    */
521
522   const u32 search[4] =
523   {
524     digests_buf[digests_offset].digest_buf[DGST_R0],
525     digests_buf[digests_offset].digest_buf[DGST_R1],
526     digests_buf[digests_offset].digest_buf[DGST_R2],
527     digests_buf[digests_offset].digest_buf[DGST_R3]
528   };
529
530   /**
531    * loop
532    */
533
534   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
535   {
536     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
537
538     const u32x pw_len = pw_l_len + pw_r_len;
539
540     /**
541      * concat password candidate
542      */
543
544     u32x wordl0[4] = { 0 };
545     u32x wordl1[4] = { 0 };
546     u32x wordl2[4] = { 0 };
547     u32x wordl3[4] = { 0 };
548
549     wordl0[0] = pw_buf0[0];
550     wordl0[1] = pw_buf0[1];
551     wordl0[2] = pw_buf0[2];
552     wordl0[3] = pw_buf0[3];
553     wordl1[0] = pw_buf1[0];
554     wordl1[1] = pw_buf1[1];
555     wordl1[2] = pw_buf1[2];
556     wordl1[3] = pw_buf1[3];
557
558     u32x wordr0[4] = { 0 };
559     u32x wordr1[4] = { 0 };
560     u32x wordr2[4] = { 0 };
561     u32x wordr3[4] = { 0 };
562
563     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
564     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
565     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
566     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
567     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
568     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
569     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
570     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
571
572     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
573     {
574       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
575     }
576     else
577     {
578       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
579     }
580
581     u32x w0[4];
582     u32x w1[4];
583     u32x w2[4];
584     u32x w3[4];
585
586     w0[0] = wordl0[0] | wordr0[0];
587     w0[1] = wordl0[1] | wordr0[1];
588     w0[2] = wordl0[2] | wordr0[2];
589     w0[3] = wordl0[3] | wordr0[3];
590     w1[0] = wordl1[0] | wordr1[0];
591     w1[1] = wordl1[1] | wordr1[1];
592     w1[2] = wordl1[2] | wordr1[2];
593     w1[3] = wordl1[3] | wordr1[3];
594     w2[0] = wordl2[0] | wordr2[0];
595     w2[1] = wordl2[1] | wordr2[1];
596     w2[2] = wordl2[2] | wordr2[2];
597     w2[3] = wordl2[3] | wordr2[3];
598     w3[0] = wordl3[0] | wordr3[0];
599     w3[1] = wordl3[1] | wordr3[1];
600     w3[2] = wordl3[2] | wordr3[2];
601     w3[3] = wordl3[3] | wordr3[3];
602
603     append_0x80_4x4_VV (w0, w1, w2, w3, pw_len);
604
605     w0[0] = swap32 (w0[0]);
606     w0[1] = swap32 (w0[1]);
607     w0[2] = swap32 (w0[2]);
608     w0[3] = swap32 (w0[3]);
609     w1[0] = swap32 (w1[0]);
610     w1[1] = swap32 (w1[1]);
611     w1[2] = swap32 (w1[2]);
612     w1[3] = swap32 (w1[3]);
613     w2[0] = swap32 (w2[0]);
614     w2[1] = swap32 (w2[1]);
615     w2[2] = swap32 (w2[2]);
616     w2[3] = swap32 (w2[3]);
617     w3[0] = swap32 (w3[0]);
618     w3[1] = swap32 (w3[1]);
619     w3[2] = 0;
620     w3[3] = (64 + pw_len) * 8;
621
622     u32x digest[8];
623
624     hmac_sha256_run (w0, w1, w2, w3, ipad, opad, digest);
625
626     COMPARE_S_SIMD (digest[3], digest[7], digest[2], digest[6]);
627   }
628 }
629
630 __kernel void m01460_s08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *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)
631 {
632 }
633
634 __kernel void m01460_s16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global void *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)
635 {
636 }