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