2 * Author......: Jens Steube <jens.steube@gmail.com>
10 #include "inc_hash_constants.h"
11 #include "inc_vendor.cl"
18 #include "inc_hash_functions.cl"
19 #include "inc_types.cl"
20 #include "inc_common.cl"
21 #include "inc_simd.cl"
23 __constant u32 padding[8] =
35 void md5_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
59 MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
60 MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
61 MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
62 MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
63 MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
64 MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
65 MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
66 MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
67 MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
68 MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
69 MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
70 MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
71 MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
72 MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
73 MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
74 MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
76 MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
77 MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
78 MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
79 MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
80 MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
81 MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
82 MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
83 MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
84 MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
85 MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
86 MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
87 MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
88 MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
89 MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
90 MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
91 MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
93 MD5_STEP (MD5_H , a, b, c, d, w5_t, MD5C20, MD5S20);
94 MD5_STEP (MD5_H , d, a, b, c, w8_t, MD5C21, MD5S21);
95 MD5_STEP (MD5_H , c, d, a, b, wb_t, MD5C22, MD5S22);
96 MD5_STEP (MD5_H , b, c, d, a, we_t, MD5C23, MD5S23);
97 MD5_STEP (MD5_H , a, b, c, d, w1_t, MD5C24, MD5S20);
98 MD5_STEP (MD5_H , d, a, b, c, w4_t, MD5C25, MD5S21);
99 MD5_STEP (MD5_H , c, d, a, b, w7_t, MD5C26, MD5S22);
100 MD5_STEP (MD5_H , b, c, d, a, wa_t, MD5C27, MD5S23);
101 MD5_STEP (MD5_H , a, b, c, d, wd_t, MD5C28, MD5S20);
102 MD5_STEP (MD5_H , d, a, b, c, w0_t, MD5C29, MD5S21);
103 MD5_STEP (MD5_H , c, d, a, b, w3_t, MD5C2a, MD5S22);
104 MD5_STEP (MD5_H , b, c, d, a, w6_t, MD5C2b, MD5S23);
105 MD5_STEP (MD5_H , a, b, c, d, w9_t, MD5C2c, MD5S20);
106 MD5_STEP (MD5_H , d, a, b, c, wc_t, MD5C2d, MD5S21);
107 MD5_STEP (MD5_H , c, d, a, b, wf_t, MD5C2e, MD5S22);
108 MD5_STEP (MD5_H , b, c, d, a, w2_t, MD5C2f, MD5S23);
110 MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
111 MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
112 MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
113 MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
114 MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
115 MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
116 MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
117 MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
118 MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
119 MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
120 MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
121 MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
122 MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
123 MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
124 MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
125 MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
133 __kernel void m10420_m04 (__global pw_t *pws, __global kernel_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 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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
139 const u32 lid = get_local_id (0);
145 const u32 gid = get_global_id (0);
147 if (gid >= gid_max) return;
152 pw_buf0[0] = pws[gid].i[0];
153 pw_buf0[1] = pws[gid].i[1];
154 pw_buf0[2] = pws[gid].i[2];
155 pw_buf0[3] = pws[gid].i[3];
156 pw_buf1[0] = pws[gid].i[4];
157 pw_buf1[1] = pws[gid].i[5];
158 pw_buf1[2] = pws[gid].i[6];
159 pw_buf1[3] = pws[gid].i[7];
161 const u32 pw_l_len = pws[gid].pw_len;
169 o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
170 o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
171 o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
172 o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
173 o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
174 o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
175 o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
176 o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
178 u32 P = pdf_bufs[salt_pos].P;
182 id_buf[0] = pdf_bufs[salt_pos].id_buf[0];
183 id_buf[1] = pdf_bufs[salt_pos].id_buf[1];
184 id_buf[2] = pdf_bufs[salt_pos].id_buf[2];
185 id_buf[3] = pdf_bufs[salt_pos].id_buf[3];
191 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
193 const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
195 const u32x pw_len = pw_l_len + pw_r_len;
198 * concat password candidate
201 u32x wordl0[4] = { 0 };
202 u32x wordl1[4] = { 0 };
203 u32x wordl2[4] = { 0 };
204 u32x wordl3[4] = { 0 };
206 wordl0[0] = pw_buf0[0];
207 wordl0[1] = pw_buf0[1];
208 wordl0[2] = pw_buf0[2];
209 wordl0[3] = pw_buf0[3];
210 wordl1[0] = pw_buf1[0];
211 wordl1[1] = pw_buf1[1];
212 wordl1[2] = pw_buf1[2];
213 wordl1[3] = pw_buf1[3];
215 u32x wordr0[4] = { 0 };
216 u32x wordr1[4] = { 0 };
217 u32x wordr2[4] = { 0 };
218 u32x wordr3[4] = { 0 };
220 wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
221 wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
222 wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
223 wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
224 wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
225 wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
226 wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
227 wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
229 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
231 switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
235 switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
243 w0[0] = wordl0[0] | wordr0[0];
244 w0[1] = wordl0[1] | wordr0[1];
245 w0[2] = wordl0[2] | wordr0[2];
246 w0[3] = wordl0[3] | wordr0[3];
247 w1[0] = wordl1[0] | wordr1[0];
248 w1[1] = wordl1[1] | wordr1[1];
249 w1[2] = wordl1[2] | wordr1[2];
250 w1[3] = wordl1[3] | wordr1[3];
286 switch_buffer_by_offset_le (p0, p1, p2, p3, pw_len);
289 // truncate at 32 is wanted, not a bug!
316 md5_transform (w0, w1, w2, w3, digest);
335 md5_transform (w0, w1, w2, w3, digest);
338 u32x b = digest[1] & 0xff;
342 COMPARE_M_SIMD (a, b, c, d);
346 __kernel void m10420_m08 (__global pw_t *pws, __global kernel_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 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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
350 __kernel void m10420_m16 (__global pw_t *pws, __global kernel_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 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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
354 __kernel void m10420_s04 (__global pw_t *pws, __global kernel_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 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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
360 const u32 lid = get_local_id (0);
366 const u32 gid = get_global_id (0);
368 if (gid >= gid_max) return;
373 pw_buf0[0] = pws[gid].i[0];
374 pw_buf0[1] = pws[gid].i[1];
375 pw_buf0[2] = pws[gid].i[2];
376 pw_buf0[3] = pws[gid].i[3];
377 pw_buf1[0] = pws[gid].i[4];
378 pw_buf1[1] = pws[gid].i[5];
379 pw_buf1[2] = pws[gid].i[6];
380 pw_buf1[3] = pws[gid].i[7];
382 const u32 pw_l_len = pws[gid].pw_len;
390 o_buf[0] = pdf_bufs[salt_pos].o_buf[0];
391 o_buf[1] = pdf_bufs[salt_pos].o_buf[1];
392 o_buf[2] = pdf_bufs[salt_pos].o_buf[2];
393 o_buf[3] = pdf_bufs[salt_pos].o_buf[3];
394 o_buf[4] = pdf_bufs[salt_pos].o_buf[4];
395 o_buf[5] = pdf_bufs[salt_pos].o_buf[5];
396 o_buf[6] = pdf_bufs[salt_pos].o_buf[6];
397 o_buf[7] = pdf_bufs[salt_pos].o_buf[7];
399 u32 P = pdf_bufs[salt_pos].P;
403 id_buf[0] = pdf_bufs[salt_pos].id_buf[0];
404 id_buf[1] = pdf_bufs[salt_pos].id_buf[1];
405 id_buf[2] = pdf_bufs[salt_pos].id_buf[2];
406 id_buf[3] = pdf_bufs[salt_pos].id_buf[3];
412 const u32 search[4] =
414 digests_buf[digests_offset].digest_buf[DGST_R0],
415 digests_buf[digests_offset].digest_buf[DGST_R1],
416 digests_buf[digests_offset].digest_buf[DGST_R2],
417 digests_buf[digests_offset].digest_buf[DGST_R3]
424 for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
426 const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
428 const u32x pw_len = pw_l_len + pw_r_len;
431 * concat password candidate
434 u32x wordl0[4] = { 0 };
435 u32x wordl1[4] = { 0 };
436 u32x wordl2[4] = { 0 };
437 u32x wordl3[4] = { 0 };
439 wordl0[0] = pw_buf0[0];
440 wordl0[1] = pw_buf0[1];
441 wordl0[2] = pw_buf0[2];
442 wordl0[3] = pw_buf0[3];
443 wordl1[0] = pw_buf1[0];
444 wordl1[1] = pw_buf1[1];
445 wordl1[2] = pw_buf1[2];
446 wordl1[3] = pw_buf1[3];
448 u32x wordr0[4] = { 0 };
449 u32x wordr1[4] = { 0 };
450 u32x wordr2[4] = { 0 };
451 u32x wordr3[4] = { 0 };
453 wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
454 wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
455 wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
456 wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
457 wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
458 wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
459 wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
460 wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
462 if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
464 switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
468 switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
476 w0[0] = wordl0[0] | wordr0[0];
477 w0[1] = wordl0[1] | wordr0[1];
478 w0[2] = wordl0[2] | wordr0[2];
479 w0[3] = wordl0[3] | wordr0[3];
480 w1[0] = wordl1[0] | wordr1[0];
481 w1[1] = wordl1[1] | wordr1[1];
482 w1[2] = wordl1[2] | wordr1[2];
483 w1[3] = wordl1[3] | wordr1[3];
519 switch_buffer_by_offset_le (p0, p1, p2, p3, pw_len);
522 // truncate at 32 is wanted, not a bug!
549 md5_transform (w0, w1, w2, w3, digest);
568 md5_transform (w0, w1, w2, w3, digest);
571 u32x b = digest[1] & 0xff;
575 COMPARE_S_SIMD (a, b, c, d);
579 __kernel void m10420_s08 (__global pw_t *pws, __global kernel_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 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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
583 __kernel void m10420_s16 (__global pw_t *pws, __global kernel_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 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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)