2 * Author......: Jens Steube <jens.steube@gmail.com>
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
28 #include "include/kernel_functions.c"
29 #include "types_amd.c"
30 #include "common_amd.c"
33 #define VECT_COMPARE_M "check_multi_vect1_comp4.c"
37 #define VECT_COMPARE_M "check_multi_vect4_comp4.c"
40 __constant u32 padding[8] =
60 static void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
65 rc4_key->S[i] = rc4_key->S[j];
69 static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
74 __local u32 *ptr = (__local u32 *) rc4_key->S;
77 for (u32 i = 0; i < 64; i++)
85 for (u32 i = 0; i < 16; i++)
93 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
94 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
95 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
96 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
100 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
101 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
102 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
103 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
107 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
108 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
109 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
110 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
114 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
115 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
116 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
117 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
121 static u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const u32 in[4], u32 out[4])
124 for (u32 k = 0; k < 4; k++)
133 swap (rc4_key, i, j);
135 idx = rc4_key->S[i] + rc4_key->S[j];
137 xor4 |= rc4_key->S[idx] << 0;
142 swap (rc4_key, i, j);
144 idx = rc4_key->S[i] + rc4_key->S[j];
146 xor4 |= rc4_key->S[idx] << 8;
151 swap (rc4_key, i, j);
153 idx = rc4_key->S[i] + rc4_key->S[j];
155 xor4 |= rc4_key->S[idx] << 16;
160 swap (rc4_key, i, j);
162 idx = rc4_key->S[i] + rc4_key->S[j];
164 xor4 |= rc4_key->S[idx] << 24;
166 out[k] = in[k] ^ xor4;
172 static void md5_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
198 MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
199 MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
200 MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
201 MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
202 MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
203 MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
204 MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
205 MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
206 MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
207 MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
208 MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
209 MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
210 MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
211 MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
212 MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
213 MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
215 MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
216 MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
217 MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
218 MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
219 MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
220 MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
221 MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
222 MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
223 MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
224 MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
225 MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
226 MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
227 MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
228 MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
229 MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
230 MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
232 MD5_STEP (MD5_H1, a, b, c, d, w5_t, MD5C20, MD5S20);
233 MD5_STEP (MD5_H2, d, a, b, c, w8_t, MD5C21, MD5S21);
234 MD5_STEP (MD5_H1, c, d, a, b, wb_t, MD5C22, MD5S22);
235 MD5_STEP (MD5_H2, b, c, d, a, we_t, MD5C23, MD5S23);
236 MD5_STEP (MD5_H1, a, b, c, d, w1_t, MD5C24, MD5S20);
237 MD5_STEP (MD5_H2, d, a, b, c, w4_t, MD5C25, MD5S21);
238 MD5_STEP (MD5_H1, c, d, a, b, w7_t, MD5C26, MD5S22);
239 MD5_STEP (MD5_H2, b, c, d, a, wa_t, MD5C27, MD5S23);
240 MD5_STEP (MD5_H1, a, b, c, d, wd_t, MD5C28, MD5S20);
241 MD5_STEP (MD5_H2, d, a, b, c, w0_t, MD5C29, MD5S21);
242 MD5_STEP (MD5_H1, c, d, a, b, w3_t, MD5C2a, MD5S22);
243 MD5_STEP (MD5_H2, b, c, d, a, w6_t, MD5C2b, MD5S23);
244 MD5_STEP (MD5_H1, a, b, c, d, w9_t, MD5C2c, MD5S20);
245 MD5_STEP (MD5_H2, d, a, b, c, wc_t, MD5C2d, MD5S21);
246 MD5_STEP (MD5_H1, c, d, a, b, wf_t, MD5C2e, MD5S22);
247 MD5_STEP (MD5_H2, b, c, d, a, w2_t, MD5C2f, MD5S23);
249 MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
250 MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
251 MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
252 MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
253 MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
254 MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
255 MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
256 MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
257 MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
258 MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
259 MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
260 MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
261 MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
262 MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
263 MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
264 MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
272 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10500_init (__global pw_t *pws, __global gpu_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)
278 const u32 gid = get_global_id (0);
279 const u32 lid = get_local_id (0);
281 if (gid >= gid_max) return;
285 w0[0] = pws[gid].i[ 0];
286 w0[1] = pws[gid].i[ 1];
287 w0[2] = pws[gid].i[ 2];
288 w0[3] = pws[gid].i[ 3];
292 w1[0] = pws[gid].i[ 4];
293 w1[1] = pws[gid].i[ 5];
294 w1[2] = pws[gid].i[ 6];
295 w1[3] = pws[gid].i[ 7];
299 w2[0] = pws[gid].i[ 8];
300 w2[1] = pws[gid].i[ 9];
304 const u32 pw_len = pws[gid].pw_len;
310 __local RC4_KEY rc4_keys[64];
312 __local RC4_KEY *rc4_key = &rc4_keys[lid];
320 o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
321 o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
322 o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
323 o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
324 o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
325 o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
326 o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
327 o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
329 u32 P = pdf_bufs[salt_pos].P;
333 id_buf[ 0] = pdf_bufs[salt_pos].id_buf[0];
334 id_buf[ 1] = pdf_bufs[salt_pos].id_buf[1];
335 id_buf[ 2] = pdf_bufs[salt_pos].id_buf[2];
336 id_buf[ 3] = pdf_bufs[salt_pos].id_buf[3];
338 id_buf[ 4] = pdf_bufs[salt_pos].id_buf[4];
339 id_buf[ 5] = pdf_bufs[salt_pos].id_buf[5];
340 id_buf[ 6] = pdf_bufs[salt_pos].id_buf[6];
341 id_buf[ 7] = pdf_bufs[salt_pos].id_buf[7];
348 u32 id_len = pdf_bufs[salt_pos].id_len;
349 u32 id_len4 = id_len / 4;
353 rc4data[0] = pdf_bufs[salt_pos].rc4data[0];
354 rc4data[1] = pdf_bufs[salt_pos].rc4data[1];
356 u32 final_length = 68 + id_len;
361 if (pdf_bufs[salt_pos].enc_md != 1)
369 id_buf[id_len4 + 0] = w11;
370 id_buf[id_len4 + 1] = w12;
381 // max length supported by pdf11 is 32
383 w0_t[0] = padding[0];
384 w0_t[1] = padding[1];
385 w0_t[2] = padding[2];
386 w0_t[3] = padding[3];
387 w1_t[0] = padding[4];
388 w1_t[1] = padding[5];
389 w1_t[2] = padding[6];
390 w1_t[3] = padding[7];
400 switch_buffer_by_offset (w0_t, w1_t, w2_t, w3_t, pw_len);
403 // truncate at 32 is wanted, not a bug!
430 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
433 w0_t[1] = id_buf[ 0];
434 w0_t[2] = id_buf[ 1];
435 w0_t[3] = id_buf[ 2];
436 w1_t[0] = id_buf[ 3];
437 w1_t[1] = id_buf[ 4];
438 w1_t[2] = id_buf[ 5];
439 w1_t[3] = id_buf[ 6];
440 w2_t[0] = id_buf[ 7];
441 w2_t[1] = id_buf[ 8];
442 w2_t[2] = id_buf[ 9];
443 w2_t[3] = id_buf[10];
444 w3_t[0] = id_buf[11];
446 w3_t[2] = final_length * 8;
449 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
451 tmps[gid].digest[0] = digest[0];
452 tmps[gid].digest[1] = digest[1];
453 tmps[gid].digest[2] = digest[2];
454 tmps[gid].digest[3] = digest[3];
456 tmps[gid].out[0] = rc4data[0];
457 tmps[gid].out[1] = rc4data[1];
458 tmps[gid].out[2] = 0;
459 tmps[gid].out[3] = 0;
462 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10500_loop (__global pw_t *pws, __global gpu_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)
468 const u32 gid = get_global_id (0);
469 const u32 lid = get_local_id (0);
471 if (gid >= gid_max) return;
477 __local RC4_KEY rc4_keys[64];
479 __local RC4_KEY *rc4_key = &rc4_keys[lid];
487 digest[0] = tmps[gid].digest[0];
488 digest[1] = tmps[gid].digest[1];
489 digest[2] = tmps[gid].digest[2];
490 digest[3] = tmps[gid].digest[3];
494 out[0] = tmps[gid].out[0];
495 out[1] = tmps[gid].out[1];
496 out[2] = tmps[gid].out[2];
497 out[3] = tmps[gid].out[3];
499 for (u32 i = 0, j = loop_pos; i < loop_cnt; i++, j++)
530 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
534 const u32 x = j - 50;
536 const u32 xv = x << 0
543 tmp[0] = digest[0] ^ xv;
544 tmp[1] = digest[1] ^ xv;
545 tmp[2] = digest[2] ^ xv;
546 tmp[3] = digest[3] ^ xv;
548 rc4_init_16 (rc4_key, tmp);
550 rc4_next_16 (rc4_key, 0, 0, out, out);
554 tmps[gid].digest[0] = digest[0];
555 tmps[gid].digest[1] = digest[1];
556 tmps[gid].digest[2] = digest[2];
557 tmps[gid].digest[3] = digest[3];
559 tmps[gid].out[0] = out[0];
560 tmps[gid].out[1] = out[1];
561 tmps[gid].out[2] = out[2];
562 tmps[gid].out[3] = out[3];
565 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10500_comp (__global pw_t *pws, __global gpu_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)
571 const u32 gid = get_global_id (0);
573 if (gid >= gid_max) return;
575 const u32 lid = get_local_id (0);
581 const u32x r0 = tmps[gid].out[0];
582 const u32x r1 = tmps[gid].out[1];
588 #include VECT_COMPARE_M