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_S "check_single_vect1_comp4.c"
34 #define VECT_COMPARE_M "check_multi_vect1_comp4.c"
38 #define VECT_COMPARE_S "check_single_vect2_comp4.c"
39 #define VECT_COMPARE_M "check_multi_vect2_comp4.c"
43 #define VECT_COMPARE_S "check_single_vect4_comp4.c"
44 #define VECT_COMPARE_M "check_multi_vect4_comp4.c"
55 static void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
60 rc4_key->S[i] = rc4_key->S[j];
64 static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
69 __local u32 *ptr = (__local u32 *) rc4_key->S;
72 for (u32 i = 0; i < 64; i++)
80 for (u32 i = 0; i < 16; i++)
88 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
89 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
90 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
91 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
95 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
96 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
97 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
98 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
102 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
103 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
104 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
105 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
109 j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
110 j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
111 j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
112 j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
116 static u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const u32 in[4], u32 out[4])
119 for (u32 k = 0; k < 4; k++)
128 swap (rc4_key, i, j);
130 idx = rc4_key->S[i] + rc4_key->S[j];
132 xor4 |= rc4_key->S[idx] << 0;
137 swap (rc4_key, i, j);
139 idx = rc4_key->S[i] + rc4_key->S[j];
141 xor4 |= rc4_key->S[idx] << 8;
146 swap (rc4_key, i, j);
148 idx = rc4_key->S[i] + rc4_key->S[j];
150 xor4 |= rc4_key->S[idx] << 16;
155 swap (rc4_key, i, j);
157 idx = rc4_key->S[i] + rc4_key->S[j];
159 xor4 |= rc4_key->S[idx] << 24;
161 out[k] = in[k] ^ xor4;
167 static void md5_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
191 MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
192 MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
193 MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
194 MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
195 MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
196 MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
197 MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
198 MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
199 MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
200 MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
201 MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
202 MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
203 MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
204 MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
205 MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
206 MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
208 MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
209 MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
210 MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
211 MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
212 MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
213 MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
214 MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
215 MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
216 MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
217 MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
218 MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
219 MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
220 MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
221 MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
222 MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
223 MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
225 MD5_STEP (MD5_H , a, b, c, d, w5_t, MD5C20, MD5S20);
226 MD5_STEP (MD5_H , d, a, b, c, w8_t, MD5C21, MD5S21);
227 MD5_STEP (MD5_H , c, d, a, b, wb_t, MD5C22, MD5S22);
228 MD5_STEP (MD5_H , b, c, d, a, we_t, MD5C23, MD5S23);
229 MD5_STEP (MD5_H , a, b, c, d, w1_t, MD5C24, MD5S20);
230 MD5_STEP (MD5_H , d, a, b, c, w4_t, MD5C25, MD5S21);
231 MD5_STEP (MD5_H , c, d, a, b, w7_t, MD5C26, MD5S22);
232 MD5_STEP (MD5_H , b, c, d, a, wa_t, MD5C27, MD5S23);
233 MD5_STEP (MD5_H , a, b, c, d, wd_t, MD5C28, MD5S20);
234 MD5_STEP (MD5_H , d, a, b, c, w0_t, MD5C29, MD5S21);
235 MD5_STEP (MD5_H , c, d, a, b, w3_t, MD5C2a, MD5S22);
236 MD5_STEP (MD5_H , b, c, d, a, w6_t, MD5C2b, MD5S23);
237 MD5_STEP (MD5_H , a, b, c, d, w9_t, MD5C2c, MD5S20);
238 MD5_STEP (MD5_H , d, a, b, c, wc_t, MD5C2d, MD5S21);
239 MD5_STEP (MD5_H , c, d, a, b, wf_t, MD5C2e, MD5S22);
240 MD5_STEP (MD5_H , b, c, d, a, w2_t, MD5C2f, MD5S23);
242 MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
243 MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
244 MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
245 MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
246 MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
247 MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
248 MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
249 MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
250 MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
251 MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
252 MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
253 MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
254 MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
255 MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
256 MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
257 MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
265 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m09710_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 oldoffice01_t *oldoffice01_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)
271 const u32 lid = get_local_id (0);
273 __local RC4_KEY rc4_keys[64];
275 __local RC4_KEY *rc4_key = &rc4_keys[lid];
281 const u32 gid = get_global_id (0);
283 if (gid >= gid_max) return;
287 wordl0[0] = pws[gid].i[ 0];
288 wordl0[1] = pws[gid].i[ 1];
289 wordl0[2] = pws[gid].i[ 2];
290 wordl0[3] = pws[gid].i[ 3];
294 wordl1[0] = pws[gid].i[ 4];
295 wordl1[1] = pws[gid].i[ 5];
296 wordl1[2] = pws[gid].i[ 6];
297 wordl1[3] = pws[gid].i[ 7];
313 const u32 pw_l_len = pws[gid].pw_len;
315 if (combs_mode == COMBINATOR_MODE_BASE_RIGHT)
317 switch_buffer_by_offset (wordl0, wordl1, wordl2, wordl3, combs_buf[0].pw_len);
324 const u32 version = oldoffice01_bufs[salt_pos].version;
326 u32 encryptedVerifier[4];
328 encryptedVerifier[0] = oldoffice01_bufs[salt_pos].encryptedVerifier[0];
329 encryptedVerifier[1] = oldoffice01_bufs[salt_pos].encryptedVerifier[1];
330 encryptedVerifier[2] = oldoffice01_bufs[salt_pos].encryptedVerifier[2];
331 encryptedVerifier[3] = oldoffice01_bufs[salt_pos].encryptedVerifier[3];
337 for (u32 il_pos = 0; il_pos < combs_cnt; il_pos++)
339 const u32 pw_r_len = combs_buf[il_pos].pw_len;
341 const u32 pw_len = pw_l_len + pw_r_len;
345 wordr0[0] = combs_buf[il_pos].i[0];
346 wordr0[1] = combs_buf[il_pos].i[1];
347 wordr0[2] = combs_buf[il_pos].i[2];
348 wordr0[3] = combs_buf[il_pos].i[3];
352 wordr1[0] = combs_buf[il_pos].i[4];
353 wordr1[1] = combs_buf[il_pos].i[5];
354 wordr1[2] = combs_buf[il_pos].i[6];
355 wordr1[3] = combs_buf[il_pos].i[7];
371 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
373 switch_buffer_by_offset (wordr0, wordr1, wordr2, wordr3, pw_l_len);
376 // first md5 to generate RC4 128 bit key
383 w0_t[0] = wordl0[0] | wordr0[0];
384 w0_t[1] = (wordl0[1] | wordr0[1]) & 0xff;
407 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
418 rc4_init_16 (rc4_key, key);
422 u8 j = rc4_next_16 (rc4_key, 0, 0, encryptedVerifier, out);
446 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
448 rc4_next_16 (rc4_key, 16, j, digest, out);
450 const u32x r0 = out[0];
451 const u32x r1 = out[1];
452 const u32x r2 = out[2];
453 const u32x r3 = out[3];
455 #include VECT_COMPARE_M
459 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m09710_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 oldoffice01_t *oldoffice01_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)
463 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m09710_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 oldoffice01_t *oldoffice01_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)
467 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m09710_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 oldoffice01_t *oldoffice01_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)
473 const u32 lid = get_local_id (0);
475 __local RC4_KEY rc4_keys[64];
477 __local RC4_KEY *rc4_key = &rc4_keys[lid];
483 const u32 gid = get_global_id (0);
485 if (gid >= gid_max) return;
489 wordl0[0] = pws[gid].i[ 0];
490 wordl0[1] = pws[gid].i[ 1];
491 wordl0[2] = pws[gid].i[ 2];
492 wordl0[3] = pws[gid].i[ 3];
496 wordl1[0] = pws[gid].i[ 4];
497 wordl1[1] = pws[gid].i[ 5];
498 wordl1[2] = pws[gid].i[ 6];
499 wordl1[3] = pws[gid].i[ 7];
515 const u32 pw_l_len = pws[gid].pw_len;
517 if (combs_mode == COMBINATOR_MODE_BASE_RIGHT)
519 switch_buffer_by_offset (wordl0, wordl1, wordl2, wordl3, combs_buf[0].pw_len);
526 const u32 search[4] =
528 digests_buf[digests_offset].digest_buf[DGST_R0],
529 digests_buf[digests_offset].digest_buf[DGST_R1],
530 digests_buf[digests_offset].digest_buf[DGST_R2],
531 digests_buf[digests_offset].digest_buf[DGST_R3]
538 const u32 version = oldoffice01_bufs[salt_pos].version;
540 u32 encryptedVerifier[4];
542 encryptedVerifier[0] = oldoffice01_bufs[salt_pos].encryptedVerifier[0];
543 encryptedVerifier[1] = oldoffice01_bufs[salt_pos].encryptedVerifier[1];
544 encryptedVerifier[2] = oldoffice01_bufs[salt_pos].encryptedVerifier[2];
545 encryptedVerifier[3] = oldoffice01_bufs[salt_pos].encryptedVerifier[3];
551 for (u32 il_pos = 0; il_pos < combs_cnt; il_pos++)
553 const u32 pw_r_len = combs_buf[il_pos].pw_len;
555 const u32 pw_len = pw_l_len + pw_r_len;
559 wordr0[0] = combs_buf[il_pos].i[0];
560 wordr0[1] = combs_buf[il_pos].i[1];
561 wordr0[2] = combs_buf[il_pos].i[2];
562 wordr0[3] = combs_buf[il_pos].i[3];
566 wordr1[0] = combs_buf[il_pos].i[4];
567 wordr1[1] = combs_buf[il_pos].i[5];
568 wordr1[2] = combs_buf[il_pos].i[6];
569 wordr1[3] = combs_buf[il_pos].i[7];
585 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
587 switch_buffer_by_offset (wordr0, wordr1, wordr2, wordr3, pw_l_len);
590 // first md5 to generate RC4 128 bit key
597 w0_t[0] = wordl0[0] | wordr0[0];
598 w0_t[1] = (wordl0[1] | wordr0[1]) & 0xff;
621 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
632 rc4_init_16 (rc4_key, key);
636 u8 j = rc4_next_16 (rc4_key, 0, 0, encryptedVerifier, out);
660 md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
662 rc4_next_16 (rc4_key, 16, j, digest, out);
664 const u32x r0 = out[0];
665 const u32x r1 = out[1];
666 const u32x r2 = out[2];
667 const u32x r3 = out[3];
669 #include VECT_COMPARE_S
673 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m09710_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 oldoffice01_t *oldoffice01_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)
677 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m09710_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 oldoffice01_t *oldoffice01_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)