Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / OpenCL / m08400_a0.cl
1 /**
2  * Authors.....: Jens Steube <jens.steube@gmail.com>
3  *               magnum <john.magnum@hushmail.com>
4  *
5  * License.....: MIT
6  */
7
8 #define _SHA1_
9
10 #define NEW_SIMD_CODE
11
12 #include "inc_vendor.cl"
13 #include "inc_hash_constants.h"
14 #include "inc_hash_functions.cl"
15 #include "inc_types.cl"
16 #include "inc_common.cl"
17 #include "inc_rp.h"
18 #include "inc_rp.cl"
19 #include "inc_simd.cl"
20
21 #if   VECT_SIZE == 1
22 #define uint_to_hex_lower8_le(i) (u32x) (l_bin2asc[(i)])
23 #elif VECT_SIZE == 2
24 #define uint_to_hex_lower8_le(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1])
25 #elif VECT_SIZE == 4
26 #define uint_to_hex_lower8_le(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3])
27 #elif VECT_SIZE == 8
28 #define uint_to_hex_lower8_le(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7])
29 #elif VECT_SIZE == 16
30 #define uint_to_hex_lower8_le(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7], l_bin2asc[(i).s8], l_bin2asc[(i).s9], l_bin2asc[(i).sa], l_bin2asc[(i).sb], l_bin2asc[(i).sc], l_bin2asc[(i).sd], l_bin2asc[(i).se], l_bin2asc[(i).sf])
31 #endif
32
33 void sha1_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[5])
34 {
35   u32x A = digest[0];
36   u32x B = digest[1];
37   u32x C = digest[2];
38   u32x D = digest[3];
39   u32x E = digest[4];
40
41   u32x w0_t = w0[0];
42   u32x w1_t = w0[1];
43   u32x w2_t = w0[2];
44   u32x w3_t = w0[3];
45   u32x w4_t = w1[0];
46   u32x w5_t = w1[1];
47   u32x w6_t = w1[2];
48   u32x w7_t = w1[3];
49   u32x w8_t = w2[0];
50   u32x w9_t = w2[1];
51   u32x wa_t = w2[2];
52   u32x wb_t = w2[3];
53   u32x wc_t = w3[0];
54   u32x wd_t = w3[1];
55   u32x we_t = w3[2];
56   u32x wf_t = w3[3];
57
58   #undef K
59   #define K SHA1C00
60
61   SHA1_STEP (SHA1_F0o, A, B, C, D, E, w0_t);
62   SHA1_STEP (SHA1_F0o, E, A, B, C, D, w1_t);
63   SHA1_STEP (SHA1_F0o, D, E, A, B, C, w2_t);
64   SHA1_STEP (SHA1_F0o, C, D, E, A, B, w3_t);
65   SHA1_STEP (SHA1_F0o, B, C, D, E, A, w4_t);
66   SHA1_STEP (SHA1_F0o, A, B, C, D, E, w5_t);
67   SHA1_STEP (SHA1_F0o, E, A, B, C, D, w6_t);
68   SHA1_STEP (SHA1_F0o, D, E, A, B, C, w7_t);
69   SHA1_STEP (SHA1_F0o, C, D, E, A, B, w8_t);
70   SHA1_STEP (SHA1_F0o, B, C, D, E, A, w9_t);
71   SHA1_STEP (SHA1_F0o, A, B, C, D, E, wa_t);
72   SHA1_STEP (SHA1_F0o, E, A, B, C, D, wb_t);
73   SHA1_STEP (SHA1_F0o, D, E, A, B, C, wc_t);
74   SHA1_STEP (SHA1_F0o, C, D, E, A, B, wd_t);
75   SHA1_STEP (SHA1_F0o, B, C, D, E, A, we_t);
76   SHA1_STEP (SHA1_F0o, A, B, C, D, E, wf_t);
77   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F0o, E, A, B, C, D, w0_t);
78   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F0o, D, E, A, B, C, w1_t);
79   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F0o, C, D, E, A, B, w2_t);
80   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F0o, B, C, D, E, A, w3_t);
81
82   #undef K
83   #define K SHA1C01
84
85   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w4_t);
86   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w5_t);
87   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w6_t);
88   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w7_t);
89   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w8_t);
90   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w9_t);
91   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wa_t);
92   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, wb_t);
93   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, wc_t);
94   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, wd_t);
95   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, we_t);
96   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wf_t);
97   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w0_t);
98   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w1_t);
99   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w2_t);
100   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w3_t);
101   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w4_t);
102   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w5_t);
103   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w6_t);
104   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w7_t);
105
106   #undef K
107   #define K SHA1C02
108
109   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, w8_t);
110   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, w9_t);
111   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, wa_t);
112   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, wb_t);
113   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, wc_t);
114   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, wd_t);
115   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, we_t);
116   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, wf_t);
117   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, w0_t);
118   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, w1_t);
119   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, w2_t);
120   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, w3_t);
121   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, w4_t);
122   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, w5_t);
123   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, w6_t);
124   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, w7_t);
125   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, w8_t);
126   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, w9_t);
127   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, wa_t);
128   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, wb_t);
129
130   #undef K
131   #define K SHA1C03
132
133   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, wc_t);
134   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wd_t);
135   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, we_t);
136   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, wf_t);
137   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w0_t);
138   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w1_t);
139   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w2_t);
140   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w3_t);
141   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w4_t);
142   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w5_t);
143   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w6_t);
144   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w7_t);
145   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w8_t);
146   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w9_t);
147   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, wa_t);
148   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, wb_t);
149   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wc_t);
150   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, wd_t);
151   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, we_t);
152   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, wf_t);
153
154   digest[0] += A;
155   digest[1] += B;
156   digest[2] += C;
157   digest[3] += D;
158   digest[4] += E;
159 }
160
161 __kernel void m08400_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
162 {
163   /**
164    * modifier
165    */
166
167   const u32 gid = get_global_id (0);
168   const u32 lid = get_local_id (0);
169   const u32 lsz = get_local_size (0);
170
171   /**
172    * shared
173    */
174
175   __local u32 l_bin2asc[256];
176
177   for (u32 i = lid; i < 256; i += lsz)
178   {
179     const u32 i0 = (i >> 0) & 15;
180     const u32 i1 = (i >> 4) & 15;
181
182     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0
183                  | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8;
184   }
185
186   barrier (CLK_LOCAL_MEM_FENCE);
187
188   if (gid >= gid_max) return;
189
190   /**
191    * base
192    */
193
194   u32 pw_buf0[4];
195   u32 pw_buf1[4];
196
197   pw_buf0[0] = pws[gid].i[0];
198   pw_buf0[1] = pws[gid].i[1];
199   pw_buf0[2] = pws[gid].i[2];
200   pw_buf0[3] = pws[gid].i[3];
201   pw_buf1[0] = pws[gid].i[4];
202   pw_buf1[1] = pws[gid].i[5];
203   pw_buf1[2] = pws[gid].i[6];
204   pw_buf1[3] = pws[gid].i[7];
205
206   const u32 pw_len = pws[gid].pw_len;
207
208   /**
209    * salt
210    */
211
212   u32 salt_buf0[4];
213   u32 salt_buf1[4];
214   u32 salt_buf2[4];
215
216   salt_buf0[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 0]);
217   salt_buf0[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 1]);
218   salt_buf0[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 2]);
219   salt_buf0[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 3]);
220   salt_buf1[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 4]);
221   salt_buf1[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 5]);
222   salt_buf1[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 6]);
223   salt_buf1[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 7]);
224   salt_buf2[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 8]);
225   salt_buf2[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 9]);
226   salt_buf2[2] = 0;
227   salt_buf2[3] = 0;
228
229   const u32 salt_len = salt_bufs[salt_pos].salt_len;
230
231   /**
232    * loop
233    */
234
235   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
236   {
237     u32x w0[4] = { 0 };
238     u32x w1[4] = { 0 };
239     u32x w2[4] = { 0 };
240     u32x w3[4] = { 0 };
241
242     const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
243
244     append_0x80_2x4_VV (w0, w1, out_len);
245
246     /**
247      * SHA1
248      */
249
250     w0[0] = swap32 (w0[0]);
251     w0[1] = swap32 (w0[1]);
252     w0[2] = swap32 (w0[2]);
253     w0[3] = swap32 (w0[3]);
254     w1[0] = swap32 (w1[0]);
255     w1[1] = swap32 (w1[1]);
256     w1[2] = swap32 (w1[2]);
257     w1[3] = swap32 (w1[3]);
258     w2[0] = swap32 (w2[0]);
259     w2[1] = swap32 (w2[1]);
260     w2[2] = swap32 (w2[2]);
261     w2[3] = swap32 (w2[3]);
262     w3[0] = swap32 (w3[0]);
263     w3[1] = swap32 (w3[1]);
264     w3[2] = 0;
265     w3[3] = out_len * 8;
266
267     u32x digest[5];
268
269     digest[0] = SHA1M_A;
270     digest[1] = SHA1M_B;
271     digest[2] = SHA1M_C;
272     digest[3] = SHA1M_D;
273     digest[4] = SHA1M_E;
274
275     sha1_transform (w0, w1, w2, w3, digest);
276
277     u32x a;
278     u32x b;
279     u32x c;
280     u32x d;
281     u32x e;
282
283     a = digest[0];
284     b = digest[1];
285     c = digest[2];
286     d = digest[3];
287     e = digest[4];
288
289     w0[0] = salt_buf0[0];
290     w0[1] = salt_buf0[1];
291     w0[2] = salt_buf0[2];
292     w0[3] = salt_buf0[3];
293     w1[0] = salt_buf1[0];
294     w1[1] = salt_buf1[1];
295     w1[2] = salt_buf1[2];
296     w1[3] = salt_buf1[3];
297     w2[0] = salt_buf2[0];
298     w2[1] = salt_buf2[1];
299     w2[2] = uint_to_hex_lower8_le ((a >> 16) & 255) <<  0
300           | uint_to_hex_lower8_le ((a >> 24) & 255) << 16;
301     w2[3] = uint_to_hex_lower8_le ((a >>  0) & 255) <<  0
302           | uint_to_hex_lower8_le ((a >>  8) & 255) << 16;
303     w3[0] = uint_to_hex_lower8_le ((b >> 16) & 255) <<  0
304           | uint_to_hex_lower8_le ((b >> 24) & 255) << 16;
305     w3[1] = uint_to_hex_lower8_le ((b >>  0) & 255) <<  0
306           | uint_to_hex_lower8_le ((b >>  8) & 255) << 16;
307     w3[2] = uint_to_hex_lower8_le ((c >> 16) & 255) <<  0
308           | uint_to_hex_lower8_le ((c >> 24) & 255) << 16;
309     w3[3] = uint_to_hex_lower8_le ((c >>  0) & 255) <<  0
310           | uint_to_hex_lower8_le ((c >>  8) & 255) << 16;
311
312     digest[0] = SHA1M_A;
313     digest[1] = SHA1M_B;
314     digest[2] = SHA1M_C;
315     digest[3] = SHA1M_D;
316     digest[4] = SHA1M_E;
317
318     sha1_transform (w0, w1, w2, w3, digest);
319
320     w0[0] = uint_to_hex_lower8_le ((d >> 16) & 255) <<  0
321           | uint_to_hex_lower8_le ((d >> 24) & 255) << 16;
322     w0[1] = uint_to_hex_lower8_le ((d >>  0) & 255) <<  0
323           | uint_to_hex_lower8_le ((d >>  8) & 255) << 16;
324     w0[2] = uint_to_hex_lower8_le ((e >> 16) & 255) <<  0
325           | uint_to_hex_lower8_le ((e >> 24) & 255) << 16;
326     w0[3] = uint_to_hex_lower8_le ((e >>  0) & 255) <<  0
327           | uint_to_hex_lower8_le ((e >>  8) & 255) << 16;
328     w1[0] = 0x80000000;
329     w1[1] = 0;
330     w1[2] = 0;
331     w1[3] = 0;
332     w2[0] = 0;
333     w2[1] = 0;
334     w2[2] = 0;
335     w2[3] = 0;
336     w3[0] = 0;
337     w3[1] = 0;
338     w3[2] = 0;
339     w3[3] = 80 * 8;
340
341     sha1_transform (w0, w1, w2, w3, digest);
342
343     a = digest[0];
344     b = digest[1];
345     c = digest[2];
346     d = digest[3];
347     e = digest[4];
348
349     w0[0] = salt_buf0[0];
350     w0[1] = salt_buf0[1];
351     w0[2] = salt_buf0[2];
352     w0[3] = salt_buf0[3];
353     w1[0] = salt_buf1[0];
354     w1[1] = salt_buf1[1];
355     w1[2] = salt_buf1[2];
356     w1[3] = salt_buf1[3];
357     w2[0] = salt_buf2[0];
358     w2[1] = salt_buf2[1];
359     w2[2] = uint_to_hex_lower8_le ((a >> 16) & 255) <<  0
360           | uint_to_hex_lower8_le ((a >> 24) & 255) << 16;
361     w2[3] = uint_to_hex_lower8_le ((a >>  0) & 255) <<  0
362           | uint_to_hex_lower8_le ((a >>  8) & 255) << 16;
363     w3[0] = uint_to_hex_lower8_le ((b >> 16) & 255) <<  0
364           | uint_to_hex_lower8_le ((b >> 24) & 255) << 16;
365     w3[1] = uint_to_hex_lower8_le ((b >>  0) & 255) <<  0
366           | uint_to_hex_lower8_le ((b >>  8) & 255) << 16;
367     w3[2] = uint_to_hex_lower8_le ((c >> 16) & 255) <<  0
368           | uint_to_hex_lower8_le ((c >> 24) & 255) << 16;
369     w3[3] = uint_to_hex_lower8_le ((c >>  0) & 255) <<  0
370           | uint_to_hex_lower8_le ((c >>  8) & 255) << 16;
371
372     digest[0] = SHA1M_A;
373     digest[1] = SHA1M_B;
374     digest[2] = SHA1M_C;
375     digest[3] = SHA1M_D;
376     digest[4] = SHA1M_E;
377
378     sha1_transform (w0, w1, w2, w3, digest);
379
380     w0[0] = uint_to_hex_lower8_le ((d >> 16) & 255) <<  0
381           | uint_to_hex_lower8_le ((d >> 24) & 255) << 16;
382     w0[1] = uint_to_hex_lower8_le ((d >>  0) & 255) <<  0
383           | uint_to_hex_lower8_le ((d >>  8) & 255) << 16;
384     w0[2] = uint_to_hex_lower8_le ((e >> 16) & 255) <<  0
385           | uint_to_hex_lower8_le ((e >> 24) & 255) << 16;
386     w0[3] = uint_to_hex_lower8_le ((e >>  0) & 255) <<  0
387           | uint_to_hex_lower8_le ((e >>  8) & 255) << 16;
388     w1[0] = 0x80000000;
389     w1[1] = 0;
390     w1[2] = 0;
391     w1[3] = 0;
392     w2[0] = 0;
393     w2[1] = 0;
394     w2[2] = 0;
395     w2[3] = 0;
396     w3[0] = 0;
397     w3[1] = 0;
398     w3[2] = 0;
399     w3[3] = 80 * 8;
400
401     sha1_transform (w0, w1, w2, w3, digest);
402
403     COMPARE_M_SIMD (digest[3], digest[4], digest[2], digest[1]);
404   }
405 }
406
407 __kernel void m08400_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
408 {
409 }
410
411 __kernel void m08400_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
412 {
413 }
414
415 __kernel void m08400_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
416 {
417   /**
418    * modifier
419    */
420
421   const u32 gid = get_global_id (0);
422   const u32 lid = get_local_id (0);
423   const u32 lsz = get_local_size (0);
424
425   /**
426    * shared
427    */
428
429   __local u32 l_bin2asc[256];
430
431   for (u32 i = lid; i < 256; i += lsz)
432   {
433     const u32 i0 = (i >> 0) & 15;
434     const u32 i1 = (i >> 4) & 15;
435
436     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0
437                  | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8;
438   }
439
440   barrier (CLK_LOCAL_MEM_FENCE);
441
442   if (gid >= gid_max) return;
443
444   /**
445    * base
446    */
447
448   u32 pw_buf0[4];
449   u32 pw_buf1[4];
450
451   pw_buf0[0] = pws[gid].i[0];
452   pw_buf0[1] = pws[gid].i[1];
453   pw_buf0[2] = pws[gid].i[2];
454   pw_buf0[3] = pws[gid].i[3];
455   pw_buf1[0] = pws[gid].i[4];
456   pw_buf1[1] = pws[gid].i[5];
457   pw_buf1[2] = pws[gid].i[6];
458   pw_buf1[3] = pws[gid].i[7];
459
460   const u32 pw_len = pws[gid].pw_len;
461
462   /**
463    * salt
464    */
465
466   u32 salt_buf0[4];
467   u32 salt_buf1[4];
468   u32 salt_buf2[4];
469
470   salt_buf0[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 0]);
471   salt_buf0[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 1]);
472   salt_buf0[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 2]);
473   salt_buf0[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 3]);
474   salt_buf1[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 4]);
475   salt_buf1[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 5]);
476   salt_buf1[2] = swap32_S (salt_bufs[salt_pos].salt_buf[ 6]);
477   salt_buf1[3] = swap32_S (salt_bufs[salt_pos].salt_buf[ 7]);
478   salt_buf2[0] = swap32_S (salt_bufs[salt_pos].salt_buf[ 8]);
479   salt_buf2[1] = swap32_S (salt_bufs[salt_pos].salt_buf[ 9]);
480   salt_buf2[2] = 0;
481   salt_buf2[3] = 0;
482
483   const u32 salt_len = salt_bufs[salt_pos].salt_len;
484
485   /**
486    * digest
487    */
488
489   const u32 search[4] =
490   {
491     digests_buf[digests_offset].digest_buf[DGST_R0],
492     digests_buf[digests_offset].digest_buf[DGST_R1],
493     digests_buf[digests_offset].digest_buf[DGST_R2],
494     digests_buf[digests_offset].digest_buf[DGST_R3]
495   };
496
497   /**
498    * loop
499    */
500
501   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
502   {
503     u32x w0[4] = { 0 };
504     u32x w1[4] = { 0 };
505     u32x w2[4] = { 0 };
506     u32x w3[4] = { 0 };
507
508     const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
509
510     append_0x80_2x4_VV (w0, w1, out_len);
511
512     /**
513      * SHA1
514      */
515
516     w0[0] = swap32 (w0[0]);
517     w0[1] = swap32 (w0[1]);
518     w0[2] = swap32 (w0[2]);
519     w0[3] = swap32 (w0[3]);
520     w1[0] = swap32 (w1[0]);
521     w1[1] = swap32 (w1[1]);
522     w1[2] = swap32 (w1[2]);
523     w1[3] = swap32 (w1[3]);
524     w2[0] = swap32 (w2[0]);
525     w2[1] = swap32 (w2[1]);
526     w2[2] = swap32 (w2[2]);
527     w2[3] = swap32 (w2[3]);
528     w3[0] = swap32 (w3[0]);
529     w3[1] = swap32 (w3[1]);
530     w3[2] = 0;
531     w3[3] = out_len * 8;
532
533     u32x digest[5];
534
535     digest[0] = SHA1M_A;
536     digest[1] = SHA1M_B;
537     digest[2] = SHA1M_C;
538     digest[3] = SHA1M_D;
539     digest[4] = SHA1M_E;
540
541     sha1_transform (w0, w1, w2, w3, digest);
542
543     u32x a;
544     u32x b;
545     u32x c;
546     u32x d;
547     u32x e;
548
549     a = digest[0];
550     b = digest[1];
551     c = digest[2];
552     d = digest[3];
553     e = digest[4];
554
555     w0[0] = salt_buf0[0];
556     w0[1] = salt_buf0[1];
557     w0[2] = salt_buf0[2];
558     w0[3] = salt_buf0[3];
559     w1[0] = salt_buf1[0];
560     w1[1] = salt_buf1[1];
561     w1[2] = salt_buf1[2];
562     w1[3] = salt_buf1[3];
563     w2[0] = salt_buf2[0];
564     w2[1] = salt_buf2[1];
565     w2[2] = uint_to_hex_lower8_le ((a >> 16) & 255) <<  0
566           | uint_to_hex_lower8_le ((a >> 24) & 255) << 16;
567     w2[3] = uint_to_hex_lower8_le ((a >>  0) & 255) <<  0
568           | uint_to_hex_lower8_le ((a >>  8) & 255) << 16;
569     w3[0] = uint_to_hex_lower8_le ((b >> 16) & 255) <<  0
570           | uint_to_hex_lower8_le ((b >> 24) & 255) << 16;
571     w3[1] = uint_to_hex_lower8_le ((b >>  0) & 255) <<  0
572           | uint_to_hex_lower8_le ((b >>  8) & 255) << 16;
573     w3[2] = uint_to_hex_lower8_le ((c >> 16) & 255) <<  0
574           | uint_to_hex_lower8_le ((c >> 24) & 255) << 16;
575     w3[3] = uint_to_hex_lower8_le ((c >>  0) & 255) <<  0
576           | uint_to_hex_lower8_le ((c >>  8) & 255) << 16;
577
578     digest[0] = SHA1M_A;
579     digest[1] = SHA1M_B;
580     digest[2] = SHA1M_C;
581     digest[3] = SHA1M_D;
582     digest[4] = SHA1M_E;
583
584     sha1_transform (w0, w1, w2, w3, digest);
585
586     w0[0] = uint_to_hex_lower8_le ((d >> 16) & 255) <<  0
587           | uint_to_hex_lower8_le ((d >> 24) & 255) << 16;
588     w0[1] = uint_to_hex_lower8_le ((d >>  0) & 255) <<  0
589           | uint_to_hex_lower8_le ((d >>  8) & 255) << 16;
590     w0[2] = uint_to_hex_lower8_le ((e >> 16) & 255) <<  0
591           | uint_to_hex_lower8_le ((e >> 24) & 255) << 16;
592     w0[3] = uint_to_hex_lower8_le ((e >>  0) & 255) <<  0
593           | uint_to_hex_lower8_le ((e >>  8) & 255) << 16;
594     w1[0] = 0x80000000;
595     w1[1] = 0;
596     w1[2] = 0;
597     w1[3] = 0;
598     w2[0] = 0;
599     w2[1] = 0;
600     w2[2] = 0;
601     w2[3] = 0;
602     w3[0] = 0;
603     w3[1] = 0;
604     w3[2] = 0;
605     w3[3] = 80 * 8;
606
607     sha1_transform (w0, w1, w2, w3, digest);
608
609     a = digest[0];
610     b = digest[1];
611     c = digest[2];
612     d = digest[3];
613     e = digest[4];
614
615     w0[0] = salt_buf0[0];
616     w0[1] = salt_buf0[1];
617     w0[2] = salt_buf0[2];
618     w0[3] = salt_buf0[3];
619     w1[0] = salt_buf1[0];
620     w1[1] = salt_buf1[1];
621     w1[2] = salt_buf1[2];
622     w1[3] = salt_buf1[3];
623     w2[0] = salt_buf2[0];
624     w2[1] = salt_buf2[1];
625     w2[2] = uint_to_hex_lower8_le ((a >> 16) & 255) <<  0
626           | uint_to_hex_lower8_le ((a >> 24) & 255) << 16;
627     w2[3] = uint_to_hex_lower8_le ((a >>  0) & 255) <<  0
628           | uint_to_hex_lower8_le ((a >>  8) & 255) << 16;
629     w3[0] = uint_to_hex_lower8_le ((b >> 16) & 255) <<  0
630           | uint_to_hex_lower8_le ((b >> 24) & 255) << 16;
631     w3[1] = uint_to_hex_lower8_le ((b >>  0) & 255) <<  0
632           | uint_to_hex_lower8_le ((b >>  8) & 255) << 16;
633     w3[2] = uint_to_hex_lower8_le ((c >> 16) & 255) <<  0
634           | uint_to_hex_lower8_le ((c >> 24) & 255) << 16;
635     w3[3] = uint_to_hex_lower8_le ((c >>  0) & 255) <<  0
636           | uint_to_hex_lower8_le ((c >>  8) & 255) << 16;
637
638     digest[0] = SHA1M_A;
639     digest[1] = SHA1M_B;
640     digest[2] = SHA1M_C;
641     digest[3] = SHA1M_D;
642     digest[4] = SHA1M_E;
643
644     sha1_transform (w0, w1, w2, w3, digest);
645
646     w0[0] = uint_to_hex_lower8_le ((d >> 16) & 255) <<  0
647           | uint_to_hex_lower8_le ((d >> 24) & 255) << 16;
648     w0[1] = uint_to_hex_lower8_le ((d >>  0) & 255) <<  0
649           | uint_to_hex_lower8_le ((d >>  8) & 255) << 16;
650     w0[2] = uint_to_hex_lower8_le ((e >> 16) & 255) <<  0
651           | uint_to_hex_lower8_le ((e >> 24) & 255) << 16;
652     w0[3] = uint_to_hex_lower8_le ((e >>  0) & 255) <<  0
653           | uint_to_hex_lower8_le ((e >>  8) & 255) << 16;
654     w1[0] = 0x80000000;
655     w1[1] = 0;
656     w1[2] = 0;
657     w1[3] = 0;
658     w2[0] = 0;
659     w2[1] = 0;
660     w2[2] = 0;
661     w2[3] = 0;
662     w3[0] = 0;
663     w3[1] = 0;
664     w3[2] = 0;
665     w3[3] = 80 * 8;
666
667     sha1_transform (w0, w1, w2, w3, digest);
668
669     COMPARE_S_SIMD (digest[3], digest[4], digest[2], digest[1]);
670   }
671 }
672
673 __kernel void m08400_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
674 {
675 }
676
677 __kernel void m08400_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
678 {
679 }