2 * Author......: Jens Steube <jens.steube@gmail.com>
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
16 #include "include/kernel_functions.c"
17 #include "OpenCL/types_ocl.c"
18 #include "OpenCL/common.c"
20 #define COMPARE_S "OpenCL/check_single_comp4.c"
21 #define COMPARE_M "OpenCL/check_multi_comp4.c"
23 __constant u32 padding[8] =
43 static void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
48 rc4_key->S[i] = rc4_key->S[j];
52 static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
57 __local u32 *ptr = (__local u32 *) rc4_key->S;
60 for (u32 i = 0; i < 64; i++)
68 for (u32 i = 0; i < 16; i++)
76 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
77 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
78 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
79 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
83 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
84 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
85 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
86 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
90 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
91 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
92 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
93 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
97 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
98 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
99 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
100 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
104 static u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const u32 in[4], u32 out[4])
107 for (u32 k = 0; k < 4; k++)
116 swap (rc4_key, i, j);
118 idx = rc4_key->S[i] + rc4_key->S[j];
120 xor4 |= rc4_key->S[idx] << 0;
125 swap (rc4_key, i, j);
127 idx = rc4_key->S[i] + rc4_key->S[j];
129 xor4 |= rc4_key->S[idx] << 8;
134 swap (rc4_key, i, j);
136 idx = rc4_key->S[i] + rc4_key->S[j];
138 xor4 |= rc4_key->S[idx] << 16;
143 swap (rc4_key, i, j);
145 idx = rc4_key->S[i] + rc4_key->S[j];
147 xor4 |= rc4_key->S[idx] << 24;
149 out[k] = in[k] ^ xor4;
155 static void md5_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[4])
181 MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
182 MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
183 MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
184 MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
185 MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
186 MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
187 MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
188 MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
189 MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
190 MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
191 MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
192 MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
193 MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
194 MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
195 MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
196 MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
198 MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
199 MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
200 MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
201 MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
202 MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
203 MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
204 MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
205 MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
206 MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
207 MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
208 MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
209 MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
210 MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
211 MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
212 MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
213 MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
215 MD5_STEP (MD5_H1, a, b, c, d, w5_t, MD5C20, MD5S20);
216 MD5_STEP (MD5_H2, d, a, b, c, w8_t, MD5C21, MD5S21);
217 MD5_STEP (MD5_H1, c, d, a, b, wb_t, MD5C22, MD5S22);
218 MD5_STEP (MD5_H2, b, c, d, a, we_t, MD5C23, MD5S23);
219 MD5_STEP (MD5_H1, a, b, c, d, w1_t, MD5C24, MD5S20);
220 MD5_STEP (MD5_H2, d, a, b, c, w4_t, MD5C25, MD5S21);
221 MD5_STEP (MD5_H1, c, d, a, b, w7_t, MD5C26, MD5S22);
222 MD5_STEP (MD5_H2, b, c, d, a, wa_t, MD5C27, MD5S23);
223 MD5_STEP (MD5_H1, a, b, c, d, wd_t, MD5C28, MD5S20);
224 MD5_STEP (MD5_H2, d, a, b, c, w0_t, MD5C29, MD5S21);
225 MD5_STEP (MD5_H1, c, d, a, b, w3_t, MD5C2a, MD5S22);
226 MD5_STEP (MD5_H2, b, c, d, a, w6_t, MD5C2b, MD5S23);
227 MD5_STEP (MD5_H1, a, b, c, d, w9_t, MD5C2c, MD5S20);
228 MD5_STEP (MD5_H2, d, a, b, c, wc_t, MD5C2d, MD5S21);
229 MD5_STEP (MD5_H1, c, d, a, b, wf_t, MD5C2e, MD5S22);
230 MD5_STEP (MD5_H2, b, c, d, a, w2_t, MD5C2f, MD5S23);
232 MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
233 MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
234 MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
235 MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
236 MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
237 MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
238 MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
239 MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
240 MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
241 MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
242 MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
243 MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
244 MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
245 MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
246 MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
247 MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
255 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10500_init (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf14_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 pdf_t *pdf_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)
261 const u32 gid = get_global_id (0);
262 const u32 lid = get_local_id (0);
264 if (gid >= gid_max) return;
268 w0[0] = pws[gid].i[ 0];
269 w0[1] = pws[gid].i[ 1];
270 w0[2] = pws[gid].i[ 2];
271 w0[3] = pws[gid].i[ 3];
275 w1[0] = pws[gid].i[ 4];
276 w1[1] = pws[gid].i[ 5];
277 w1[2] = pws[gid].i[ 6];
278 w1[3] = pws[gid].i[ 7];
282 w2[0] = pws[gid].i[ 8];
283 w2[1] = pws[gid].i[ 9];
287 const u32 pw_len = pws[gid].pw_len;
293 __local RC4_KEY rc4_keys[64];
295 __local RC4_KEY *rc4_key = &rc4_keys[lid];
303 o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
304 o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
305 o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
306 o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
307 o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
308 o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
309 o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
310 o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
312 u32 P = pdf_bufs[salt_pos].P;
316 id_buf[ 0] = pdf_bufs[salt_pos].id_buf[0];
317 id_buf[ 1] = pdf_bufs[salt_pos].id_buf[1];
318 id_buf[ 2] = pdf_bufs[salt_pos].id_buf[2];
319 id_buf[ 3] = pdf_bufs[salt_pos].id_buf[3];
321 id_buf[ 4] = pdf_bufs[salt_pos].id_buf[4];
322 id_buf[ 5] = pdf_bufs[salt_pos].id_buf[5];
323 id_buf[ 6] = pdf_bufs[salt_pos].id_buf[6];
324 id_buf[ 7] = pdf_bufs[salt_pos].id_buf[7];
331 u32 id_len = pdf_bufs[salt_pos].id_len;
332 u32 id_len4 = id_len / 4;
336 rc4data[0] = pdf_bufs[salt_pos].rc4data[0];
337 rc4data[1] = pdf_bufs[salt_pos].rc4data[1];
339 u32 final_length = 68 + id_len;
344 if (pdf_bufs[salt_pos].enc_md != 1)
352 id_buf[id_len4 + 0] = w11;
353 id_buf[id_len4 + 1] = w12;
364 // max length supported by pdf11 is 32
366 w0_t[0] = padding[0];
367 w0_t[1] = padding[1];
368 w0_t[2] = padding[2];
369 w0_t[3] = padding[3];
370 w1_t[0] = padding[4];
371 w1_t[1] = padding[5];
372 w1_t[2] = padding[6];
373 w1_t[3] = padding[7];
383 switch_buffer_by_offset (w0_t, w1_t, w2_t, w3_t, pw_len);
386 // truncate at 32 is wanted, not a bug!
413 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
416 w0_t[1] = id_buf[ 0];
417 w0_t[2] = id_buf[ 1];
418 w0_t[3] = id_buf[ 2];
419 w1_t[0] = id_buf[ 3];
420 w1_t[1] = id_buf[ 4];
421 w1_t[2] = id_buf[ 5];
422 w1_t[3] = id_buf[ 6];
423 w2_t[0] = id_buf[ 7];
424 w2_t[1] = id_buf[ 8];
425 w2_t[2] = id_buf[ 9];
426 w2_t[3] = id_buf[10];
427 w3_t[0] = id_buf[11];
429 w3_t[2] = final_length * 8;
432 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
434 tmps[gid].digest[0] = digest[0];
435 tmps[gid].digest[1] = digest[1];
436 tmps[gid].digest[2] = digest[2];
437 tmps[gid].digest[3] = digest[3];
439 tmps[gid].out[0] = rc4data[0];
440 tmps[gid].out[1] = rc4data[1];
441 tmps[gid].out[2] = 0;
442 tmps[gid].out[3] = 0;
445 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10500_loop (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf14_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 pdf_t *pdf_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)
451 const u32 gid = get_global_id (0);
452 const u32 lid = get_local_id (0);
454 if (gid >= gid_max) return;
460 __local RC4_KEY rc4_keys[64];
462 __local RC4_KEY *rc4_key = &rc4_keys[lid];
470 digest[0] = tmps[gid].digest[0];
471 digest[1] = tmps[gid].digest[1];
472 digest[2] = tmps[gid].digest[2];
473 digest[3] = tmps[gid].digest[3];
477 out[0] = tmps[gid].out[0];
478 out[1] = tmps[gid].out[1];
479 out[2] = tmps[gid].out[2];
480 out[3] = tmps[gid].out[3];
482 for (u32 i = 0, j = loop_pos; i < loop_cnt; i++, j++)
513 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
517 const u32 x = j - 50;
519 const u32 xv = x << 0
526 tmp[0] = digest[0] ^ xv;
527 tmp[1] = digest[1] ^ xv;
528 tmp[2] = digest[2] ^ xv;
529 tmp[3] = digest[3] ^ xv;
531 rc4_init_16 (rc4_key, tmp);
533 rc4_next_16 (rc4_key, 0, 0, out, out);
537 tmps[gid].digest[0] = digest[0];
538 tmps[gid].digest[1] = digest[1];
539 tmps[gid].digest[2] = digest[2];
540 tmps[gid].digest[3] = digest[3];
542 tmps[gid].out[0] = out[0];
543 tmps[gid].out[1] = out[1];
544 tmps[gid].out[2] = out[2];
545 tmps[gid].out[3] = out[3];
548 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10500_comp (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf14_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 pdf_t *pdf_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)
554 const u32 gid = get_global_id (0);
556 if (gid >= gid_max) return;
558 const u32 lid = get_local_id (0);
564 const u32 r0 = tmps[gid].out[0];
565 const u32 r1 = tmps[gid].out[1];