2 * Author......: Jens Steube <jens.steube@gmail.com>
6 #define _PBKDF2_SHA256_
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
16 #include "include/kernel_functions.c"
18 #include "types_ocl.c"
22 #define COMPARE_M "check_multi_vect1_comp4.c"
25 __constant u32 k_sha256[64] =
27 SHA256C00, SHA256C01, SHA256C02, SHA256C03,
28 SHA256C04, SHA256C05, SHA256C06, SHA256C07,
29 SHA256C08, SHA256C09, SHA256C0a, SHA256C0b,
30 SHA256C0c, SHA256C0d, SHA256C0e, SHA256C0f,
31 SHA256C10, SHA256C11, SHA256C12, SHA256C13,
32 SHA256C14, SHA256C15, SHA256C16, SHA256C17,
33 SHA256C18, SHA256C19, SHA256C1a, SHA256C1b,
34 SHA256C1c, SHA256C1d, SHA256C1e, SHA256C1f,
35 SHA256C20, SHA256C21, SHA256C22, SHA256C23,
36 SHA256C24, SHA256C25, SHA256C26, SHA256C27,
37 SHA256C28, SHA256C29, SHA256C2a, SHA256C2b,
38 SHA256C2c, SHA256C2d, SHA256C2e, SHA256C2f,
39 SHA256C30, SHA256C31, SHA256C32, SHA256C33,
40 SHA256C34, SHA256C35, SHA256C36, SHA256C37,
41 SHA256C38, SHA256C39, SHA256C3a, SHA256C3b,
42 SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f,
45 static void sha256_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[8])
73 #define ROUND_EXPAND() \
75 w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); \
76 w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); \
77 w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); \
78 w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); \
79 w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); \
80 w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); \
81 w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); \
82 w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); \
83 w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); \
84 w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); \
85 wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); \
86 wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); \
87 wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); \
88 wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); \
89 we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); \
90 wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); \
93 #define ROUND_STEP(i) \
95 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i + 0]); \
96 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i + 1]); \
97 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i + 2]); \
98 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i + 3]); \
99 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i + 4]); \
100 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i + 5]); \
101 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i + 6]); \
102 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i + 7]); \
103 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i + 8]); \
104 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i + 9]); \
105 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
106 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
107 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
108 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
109 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
110 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
116 for (int i = 16; i < 64; i += 16)
118 ROUND_EXPAND (); ROUND_STEP (i);
131 static void hmac_sha256_pad (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 ipad[8], u32 opad[8])
133 w0[0] = w0[0] ^ 0x36363636;
134 w0[1] = w0[1] ^ 0x36363636;
135 w0[2] = w0[2] ^ 0x36363636;
136 w0[3] = w0[3] ^ 0x36363636;
137 w1[0] = w1[0] ^ 0x36363636;
138 w1[1] = w1[1] ^ 0x36363636;
139 w1[2] = w1[2] ^ 0x36363636;
140 w1[3] = w1[3] ^ 0x36363636;
141 w2[0] = w2[0] ^ 0x36363636;
142 w2[1] = w2[1] ^ 0x36363636;
143 w2[2] = w2[2] ^ 0x36363636;
144 w2[3] = w2[3] ^ 0x36363636;
145 w3[0] = w3[0] ^ 0x36363636;
146 w3[1] = w3[1] ^ 0x36363636;
147 w3[2] = w3[2] ^ 0x36363636;
148 w3[3] = w3[3] ^ 0x36363636;
159 sha256_transform (w0, w1, w2, w3, ipad);
161 w0[0] = w0[0] ^ 0x6a6a6a6a;
162 w0[1] = w0[1] ^ 0x6a6a6a6a;
163 w0[2] = w0[2] ^ 0x6a6a6a6a;
164 w0[3] = w0[3] ^ 0x6a6a6a6a;
165 w1[0] = w1[0] ^ 0x6a6a6a6a;
166 w1[1] = w1[1] ^ 0x6a6a6a6a;
167 w1[2] = w1[2] ^ 0x6a6a6a6a;
168 w1[3] = w1[3] ^ 0x6a6a6a6a;
169 w2[0] = w2[0] ^ 0x6a6a6a6a;
170 w2[1] = w2[1] ^ 0x6a6a6a6a;
171 w2[2] = w2[2] ^ 0x6a6a6a6a;
172 w2[3] = w2[3] ^ 0x6a6a6a6a;
173 w3[0] = w3[0] ^ 0x6a6a6a6a;
174 w3[1] = w3[1] ^ 0x6a6a6a6a;
175 w3[2] = w3[2] ^ 0x6a6a6a6a;
176 w3[3] = w3[3] ^ 0x6a6a6a6a;
187 sha256_transform (w0, w1, w2, w3, opad);
190 static void hmac_sha256_run (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 ipad[8], u32 opad[8], u32 digest[8])
201 sha256_transform (w0, w1, w2, w3, digest);
218 w3[3] = (64 + 32) * 8;
229 sha256_transform (w0, w1, w2, w3, digest);
232 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10900_init (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pbkdf2_sha256_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 pbkdf2_sha256_t *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 const u32 gid = get_global_id (0);
240 if (gid >= gid_max) return;
244 w0[0] = swap_workaround (pws[gid].i[ 0]);
245 w0[1] = swap_workaround (pws[gid].i[ 1]);
246 w0[2] = swap_workaround (pws[gid].i[ 2]);
247 w0[3] = swap_workaround (pws[gid].i[ 3]);
251 w1[0] = swap_workaround (pws[gid].i[ 4]);
252 w1[1] = swap_workaround (pws[gid].i[ 5]);
253 w1[2] = swap_workaround (pws[gid].i[ 6]);
254 w1[3] = swap_workaround (pws[gid].i[ 7]);
258 w2[0] = swap_workaround (pws[gid].i[ 8]);
259 w2[1] = swap_workaround (pws[gid].i[ 9]);
260 w2[2] = swap_workaround (pws[gid].i[10]);
261 w2[3] = swap_workaround (pws[gid].i[11]);
265 w3[0] = swap_workaround (pws[gid].i[12]);
266 w3[1] = swap_workaround (pws[gid].i[13]);
267 w3[2] = swap_workaround (pws[gid].i[14]);
268 w3[3] = swap_workaround (pws[gid].i[15]);
274 const u32 salt_len = salt_bufs[salt_pos].salt_len;
281 esalt_buf0[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 0]);
282 esalt_buf0[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 1]);
283 esalt_buf0[2] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 2]);
284 esalt_buf0[3] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 3]);
285 esalt_buf1[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 4]);
286 esalt_buf1[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 5]);
287 esalt_buf1[2] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 6]);
288 esalt_buf1[3] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 7]);
289 esalt_buf2[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 8]);
290 esalt_buf2[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 9]);
291 esalt_buf2[2] = swap_workaround (esalt_bufs[salt_pos].salt_buf[10]);
292 esalt_buf2[3] = swap_workaround (esalt_bufs[salt_pos].salt_buf[11]);
293 esalt_buf3[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[12]);
294 esalt_buf3[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[13]);
296 esalt_buf3[3] = (64 + salt_len + 4) * 8;
301 hmac_sha256_pad (w0, w1, w2, w3, ipad, opad);
303 tmps[gid].ipad[0] = ipad[0];
304 tmps[gid].ipad[1] = ipad[1];
305 tmps[gid].ipad[2] = ipad[2];
306 tmps[gid].ipad[3] = ipad[3];
307 tmps[gid].ipad[4] = ipad[4];
308 tmps[gid].ipad[5] = ipad[5];
309 tmps[gid].ipad[6] = ipad[6];
310 tmps[gid].ipad[7] = ipad[7];
312 tmps[gid].opad[0] = opad[0];
313 tmps[gid].opad[1] = opad[1];
314 tmps[gid].opad[2] = opad[2];
315 tmps[gid].opad[3] = opad[3];
316 tmps[gid].opad[4] = opad[4];
317 tmps[gid].opad[5] = opad[5];
318 tmps[gid].opad[6] = opad[6];
319 tmps[gid].opad[7] = opad[7];
321 for (u32 i = 0, j = 1; i < 8; i += 8, j += 1)
325 hmac_sha256_run (esalt_buf0, esalt_buf1, esalt_buf2, esalt_buf3, ipad, opad, dgst);
327 tmps[gid].dgst[i + 0] = dgst[0];
328 tmps[gid].dgst[i + 1] = dgst[1];
329 tmps[gid].dgst[i + 2] = dgst[2];
330 tmps[gid].dgst[i + 3] = dgst[3];
331 tmps[gid].dgst[i + 4] = dgst[4];
332 tmps[gid].dgst[i + 5] = dgst[5];
333 tmps[gid].dgst[i + 6] = dgst[6];
334 tmps[gid].dgst[i + 7] = dgst[7];
336 tmps[gid].out[i + 0] = dgst[0];
337 tmps[gid].out[i + 1] = dgst[1];
338 tmps[gid].out[i + 2] = dgst[2];
339 tmps[gid].out[i + 3] = dgst[3];
340 tmps[gid].out[i + 4] = dgst[4];
341 tmps[gid].out[i + 5] = dgst[5];
342 tmps[gid].out[i + 6] = dgst[6];
343 tmps[gid].out[i + 7] = dgst[7];
347 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10900_loop (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pbkdf2_sha256_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 pbkdf2_sha256_t *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)
349 const u32 gid = get_global_id (0);
351 if (gid >= gid_max) return;
355 ipad[0] = tmps[gid].ipad[0];
356 ipad[1] = tmps[gid].ipad[1];
357 ipad[2] = tmps[gid].ipad[2];
358 ipad[3] = tmps[gid].ipad[3];
359 ipad[4] = tmps[gid].ipad[4];
360 ipad[5] = tmps[gid].ipad[5];
361 ipad[6] = tmps[gid].ipad[6];
362 ipad[7] = tmps[gid].ipad[7];
366 opad[0] = tmps[gid].opad[0];
367 opad[1] = tmps[gid].opad[1];
368 opad[2] = tmps[gid].opad[2];
369 opad[3] = tmps[gid].opad[3];
370 opad[4] = tmps[gid].opad[4];
371 opad[5] = tmps[gid].opad[5];
372 opad[6] = tmps[gid].opad[6];
373 opad[7] = tmps[gid].opad[7];
375 for (u32 i = 0; i < 8; i += 8)
379 dgst[0] = tmps[gid].dgst[i + 0];
380 dgst[1] = tmps[gid].dgst[i + 1];
381 dgst[2] = tmps[gid].dgst[i + 2];
382 dgst[3] = tmps[gid].dgst[i + 3];
383 dgst[4] = tmps[gid].dgst[i + 4];
384 dgst[5] = tmps[gid].dgst[i + 5];
385 dgst[6] = tmps[gid].dgst[i + 6];
386 dgst[7] = tmps[gid].dgst[i + 7];
390 out[0] = tmps[gid].out[i + 0];
391 out[1] = tmps[gid].out[i + 1];
392 out[2] = tmps[gid].out[i + 2];
393 out[3] = tmps[gid].out[i + 3];
394 out[4] = tmps[gid].out[i + 4];
395 out[5] = tmps[gid].out[i + 5];
396 out[6] = tmps[gid].out[i + 6];
397 out[7] = tmps[gid].out[i + 7];
399 for (u32 j = 0; j < loop_cnt; j++)
421 w3[3] = (64 + 32) * 8;
423 hmac_sha256_run (w0, w1, w2, w3, ipad, opad, dgst);
435 tmps[gid].dgst[i + 0] = dgst[0];
436 tmps[gid].dgst[i + 1] = dgst[1];
437 tmps[gid].dgst[i + 2] = dgst[2];
438 tmps[gid].dgst[i + 3] = dgst[3];
439 tmps[gid].dgst[i + 4] = dgst[4];
440 tmps[gid].dgst[i + 5] = dgst[5];
441 tmps[gid].dgst[i + 6] = dgst[6];
442 tmps[gid].dgst[i + 7] = dgst[7];
444 tmps[gid].out[i + 0] = out[0];
445 tmps[gid].out[i + 1] = out[1];
446 tmps[gid].out[i + 2] = out[2];
447 tmps[gid].out[i + 3] = out[3];
448 tmps[gid].out[i + 4] = out[4];
449 tmps[gid].out[i + 5] = out[5];
450 tmps[gid].out[i + 6] = out[6];
451 tmps[gid].out[i + 7] = out[7];
455 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10900_comp (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pbkdf2_sha256_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 pbkdf2_sha256_t *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)
461 const u32 gid = get_global_id (0);
463 if (gid >= gid_max) return;
465 const u32 lid = get_local_id (0);
467 const u32 r0 = tmps[gid].out[DGST_R0];
468 const u32 r1 = tmps[gid].out[DGST_R1];
469 const u32 r2 = tmps[gid].out[DGST_R2];
470 const u32 r3 = tmps[gid].out[DGST_R3];