Initial commit
[hashcat.git] / amd / m00400.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _MD5_
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_SIZE4
17 #endif
18
19 #ifdef  VLIW5
20 #define VECT_SIZE4
21 #endif
22
23 #define DGST_R0 0
24 #define DGST_R1 1
25 #define DGST_R2 2
26 #define DGST_R3 3
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_M "check_multi_vect1_comp4.c"
34 #endif
35
36 #ifdef  VECT_SIZE4
37 #define VECT_COMPARE_M "check_multi_vect4_comp4.c"
38 #endif
39
40 static void md5_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
41 {
42   u32x a = digest[0];
43   u32x b = digest[1];
44   u32x c = digest[2];
45   u32x d = digest[3];
46
47   u32x w0_t = w0[0];
48   u32x w1_t = w0[1];
49   u32x w2_t = w0[2];
50   u32x w3_t = w0[3];
51   u32x w4_t = w1[0];
52   u32x w5_t = w1[1];
53   u32x w6_t = w1[2];
54   u32x w7_t = w1[3];
55   u32x w8_t = w2[0];
56   u32x w9_t = w2[1];
57   u32x wa_t = w2[2];
58   u32x wb_t = w2[3];
59   u32x wc_t = w3[0];
60   u32x wd_t = w3[1];
61   u32x we_t = w3[2];
62   u32x wf_t = 0;
63
64   u32x tmp2;
65
66   MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
67   MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
68   MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
69   MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
70   MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
71   MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
72   MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
73   MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
74   MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
75   MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
76   MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
77   MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
78   MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
79   MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
80   MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
81   MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
82
83   MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
84   MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
85   MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
86   MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
87   MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
88   MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
89   MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
90   MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
91   MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
92   MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
93   MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
94   MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
95   MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
96   MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
97   MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
98   MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
99
100   MD5_STEP (MD5_H1, a, b, c, d, w5_t, MD5C20, MD5S20);
101   MD5_STEP (MD5_H2, d, a, b, c, w8_t, MD5C21, MD5S21);
102   MD5_STEP (MD5_H1, c, d, a, b, wb_t, MD5C22, MD5S22);
103   MD5_STEP (MD5_H2, b, c, d, a, we_t, MD5C23, MD5S23);
104   MD5_STEP (MD5_H1, a, b, c, d, w1_t, MD5C24, MD5S20);
105   MD5_STEP (MD5_H2, d, a, b, c, w4_t, MD5C25, MD5S21);
106   MD5_STEP (MD5_H1, c, d, a, b, w7_t, MD5C26, MD5S22);
107   MD5_STEP (MD5_H2, b, c, d, a, wa_t, MD5C27, MD5S23);
108   MD5_STEP (MD5_H1, a, b, c, d, wd_t, MD5C28, MD5S20);
109   MD5_STEP (MD5_H2, d, a, b, c, w0_t, MD5C29, MD5S21);
110   MD5_STEP (MD5_H1, c, d, a, b, w3_t, MD5C2a, MD5S22);
111   MD5_STEP (MD5_H2, b, c, d, a, w6_t, MD5C2b, MD5S23);
112   MD5_STEP (MD5_H1, a, b, c, d, w9_t, MD5C2c, MD5S20);
113   MD5_STEP (MD5_H2, d, a, b, c, wc_t, MD5C2d, MD5S21);
114   MD5_STEP (MD5_H1, c, d, a, b, wf_t, MD5C2e, MD5S22);
115   MD5_STEP (MD5_H2, b, c, d, a, w2_t, MD5C2f, MD5S23);
116
117   MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
118   MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
119   MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
120   MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
121   MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
122   MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
123   MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
124   MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
125   MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
126   MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
127   MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
128   MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
129   MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
130   MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
131   MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
132   MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
133
134   digest[0] += a;
135   digest[1] += b;
136   digest[2] += c;
137   digest[3] += d;
138 }
139
140 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m00400_init (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global phpass_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global 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 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
141 {
142   /**
143    * base
144    */
145
146   const u32 gid = get_global_id (0);
147
148   if (gid >= gid_max) return;
149
150   u32x w0[4];
151
152   w0[0] = pws[gid].i[ 0];
153   w0[1] = pws[gid].i[ 1];
154   w0[2] = pws[gid].i[ 2];
155   w0[3] = pws[gid].i[ 3];
156
157   u32x w1[4];
158
159   w1[0] = pws[gid].i[ 4];
160   w1[1] = pws[gid].i[ 5];
161   w1[2] = pws[gid].i[ 6];
162   w1[3] = pws[gid].i[ 7];
163
164   u32x w2[4];
165
166   w2[0] = pws[gid].i[ 8];
167   w2[1] = pws[gid].i[ 9];
168   w2[2] = 0;
169   w2[3] = 0;
170
171   const u32 pw_len = pws[gid].pw_len;
172
173   /**
174    * salt
175    */
176
177   u32 salt_buf[2];
178
179   salt_buf[0] = salt_bufs[salt_pos].salt_buf[0];
180   salt_buf[1] = salt_bufs[salt_pos].salt_buf[1];
181
182   /**
183    * init
184    */
185
186   u32 block_len = 8 + pw_len;
187
188   u32x block0[4];
189
190   block0[0] = salt_buf[0];
191   block0[1] = salt_buf[1];
192   block0[2] = w0[0];
193   block0[3] = w0[1];
194
195   u32x block1[4];
196
197   block1[0] = w0[2];
198   block1[1] = w0[3];
199   block1[2] = w1[0];
200   block1[3] = w1[1];
201
202   u32x block2[4];
203
204   block2[0] = w1[2];
205   block2[1] = w1[3];
206   block2[2] = w2[0];
207   block2[3] = w2[1];
208
209   u32x block3[4];
210
211   block3[0] = 0;
212   block3[1] = 0;
213   block3[2] = block_len * 8;
214   block3[3] = 0;
215
216   append_0x80_4 (block0, block1, block2, block3, block_len);
217
218   /**
219    * init
220    */
221
222   u32x digest[4];
223
224   digest[0] = MD5M_A;
225   digest[1] = MD5M_B;
226   digest[2] = MD5M_C;
227   digest[3] = MD5M_D;
228
229   md5_transform (block0, block1, block2, block3, digest);
230
231   tmps[gid].digest_buf[0] = digest[0];
232   tmps[gid].digest_buf[1] = digest[1];
233   tmps[gid].digest_buf[2] = digest[2];
234   tmps[gid].digest_buf[3] = digest[3];
235 }
236
237 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m00400_loop (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global phpass_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global 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 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
238 {
239   /**
240    * base
241    */
242
243   const u32 gid = get_global_id (0);
244
245   if (gid >= gid_max) return;
246
247   u32x w0[4];
248
249   w0[0] = pws[gid].i[ 0];
250   w0[1] = pws[gid].i[ 1];
251   w0[2] = pws[gid].i[ 2];
252   w0[3] = pws[gid].i[ 3];
253
254   u32x w1[4];
255
256   w1[0] = pws[gid].i[ 4];
257   w1[1] = pws[gid].i[ 5];
258   w1[2] = pws[gid].i[ 6];
259   w1[3] = pws[gid].i[ 7];
260
261   u32x w2[4];
262
263   w2[0] = pws[gid].i[ 8];
264   w2[1] = pws[gid].i[ 9];
265   w2[2] = 0;
266   w2[3] = 0;
267
268   const u32 pw_len = pws[gid].pw_len;
269
270   /**
271    * digest
272    */
273
274   u32x digest[4];
275
276   digest[0] = tmps[gid].digest_buf[0];
277   digest[1] = tmps[gid].digest_buf[1];
278   digest[2] = tmps[gid].digest_buf[2];
279   digest[3] = tmps[gid].digest_buf[3];
280
281   /**
282    * loop
283    */
284
285   u32 block_len = (16 + pw_len);
286
287   u32x block0[4];
288
289   block0[0] = 0;
290   block0[1] = 0;
291   block0[2] = 0;
292   block0[3] = 0;
293
294   u32x block1[4];
295
296   block1[0] = w0[0];
297   block1[1] = w0[1];
298   block1[2] = w0[2];
299   block1[3] = w0[3];
300
301   u32x block2[4];
302
303   block2[0] = w1[0];
304   block2[1] = w1[1];
305   block2[2] = w1[2];
306   block2[3] = w1[3];
307
308   u32x block3[4];
309
310   block3[0] = w2[0];
311   block3[1] = w2[1];
312   block3[2] = block_len * 8;
313   block3[3] = 0;
314
315   append_0x80_4 (block0, block1, block2, block3, block_len);
316
317   /**
318    * init
319    */
320
321   for (u32 i = 0; i < loop_cnt; i++)
322   {
323     block0[0] = digest[0];
324     block0[1] = digest[1];
325     block0[2] = digest[2];
326     block0[3] = digest[3];
327
328     digest[0] = MD5M_A;
329     digest[1] = MD5M_B;
330     digest[2] = MD5M_C;
331     digest[3] = MD5M_D;
332
333     md5_transform (block0, block1, block2, block3, digest);
334   }
335
336   tmps[gid].digest_buf[0] = digest[0];
337   tmps[gid].digest_buf[1] = digest[1];
338   tmps[gid].digest_buf[2] = digest[2];
339   tmps[gid].digest_buf[3] = digest[3];
340 }
341
342 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m00400_comp (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global phpass_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global 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 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
343 {
344   /**
345    * modifier
346    */
347
348   const u32 gid = get_global_id (0);
349
350   if (gid >= gid_max) return;
351
352   const u32 lid = get_local_id (0);
353
354   /**
355    * digest
356    */
357
358   const u32x r0 = tmps[gid].digest_buf[DGST_R0];
359   const u32x r1 = tmps[gid].digest_buf[DGST_R1];
360   const u32x r2 = tmps[gid].digest_buf[DGST_R2];
361   const u32x r3 = tmps[gid].digest_buf[DGST_R3];
362
363   #define il_pos 0
364
365   #include VECT_COMPARE_M
366 }