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