2 * Author......: Jens Steube <jens.steube@gmail.com>
6 #define _PBKDF2_SHA256_
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
28 #include "include/kernel_functions.c"
30 #include "types_amd.c"
31 #include "common_amd.c"
34 #define VECT_COMPARE_M "check_multi_vect1_comp4.c"
37 __constant u32 k_sha256[64] =
39 SHA256C00, SHA256C01, SHA256C02, SHA256C03,
40 SHA256C04, SHA256C05, SHA256C06, SHA256C07,
41 SHA256C08, SHA256C09, SHA256C0a, SHA256C0b,
42 SHA256C0c, SHA256C0d, SHA256C0e, SHA256C0f,
43 SHA256C10, SHA256C11, SHA256C12, SHA256C13,
44 SHA256C14, SHA256C15, SHA256C16, SHA256C17,
45 SHA256C18, SHA256C19, SHA256C1a, SHA256C1b,
46 SHA256C1c, SHA256C1d, SHA256C1e, SHA256C1f,
47 SHA256C20, SHA256C21, SHA256C22, SHA256C23,
48 SHA256C24, SHA256C25, SHA256C26, SHA256C27,
49 SHA256C28, SHA256C29, SHA256C2a, SHA256C2b,
50 SHA256C2c, SHA256C2d, SHA256C2e, SHA256C2f,
51 SHA256C30, SHA256C31, SHA256C32, SHA256C33,
52 SHA256C34, SHA256C35, SHA256C36, SHA256C37,
53 SHA256C38, SHA256C39, SHA256C3a, SHA256C3b,
54 SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f,
57 static void sha256_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[8])
85 #define ROUND_EXPAND() \
87 w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); \
88 w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); \
89 w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); \
90 w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); \
91 w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); \
92 w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); \
93 w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); \
94 w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); \
95 w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); \
96 w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); \
97 wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); \
98 wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); \
99 wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); \
100 wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); \
101 we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); \
102 wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); \
105 #define ROUND_STEP(i) \
107 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i + 0]); \
108 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i + 1]); \
109 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i + 2]); \
110 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i + 3]); \
111 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i + 4]); \
112 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i + 5]); \
113 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i + 6]); \
114 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i + 7]); \
115 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i + 8]); \
116 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i + 9]); \
117 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
118 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
119 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
120 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
121 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
122 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
128 for (int i = 16; i < 64; i += 16)
130 ROUND_EXPAND (); ROUND_STEP (i);
143 static void hmac_sha256_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[8], u32x opad[8])
145 w0[0] = w0[0] ^ 0x36363636;
146 w0[1] = w0[1] ^ 0x36363636;
147 w0[2] = w0[2] ^ 0x36363636;
148 w0[3] = w0[3] ^ 0x36363636;
149 w1[0] = w1[0] ^ 0x36363636;
150 w1[1] = w1[1] ^ 0x36363636;
151 w1[2] = w1[2] ^ 0x36363636;
152 w1[3] = w1[3] ^ 0x36363636;
153 w2[0] = w2[0] ^ 0x36363636;
154 w2[1] = w2[1] ^ 0x36363636;
155 w2[2] = w2[2] ^ 0x36363636;
156 w2[3] = w2[3] ^ 0x36363636;
157 w3[0] = w3[0] ^ 0x36363636;
158 w3[1] = w3[1] ^ 0x36363636;
159 w3[2] = w3[2] ^ 0x36363636;
160 w3[3] = w3[3] ^ 0x36363636;
171 sha256_transform (w0, w1, w2, w3, ipad);
173 w0[0] = w0[0] ^ 0x6a6a6a6a;
174 w0[1] = w0[1] ^ 0x6a6a6a6a;
175 w0[2] = w0[2] ^ 0x6a6a6a6a;
176 w0[3] = w0[3] ^ 0x6a6a6a6a;
177 w1[0] = w1[0] ^ 0x6a6a6a6a;
178 w1[1] = w1[1] ^ 0x6a6a6a6a;
179 w1[2] = w1[2] ^ 0x6a6a6a6a;
180 w1[3] = w1[3] ^ 0x6a6a6a6a;
181 w2[0] = w2[0] ^ 0x6a6a6a6a;
182 w2[1] = w2[1] ^ 0x6a6a6a6a;
183 w2[2] = w2[2] ^ 0x6a6a6a6a;
184 w2[3] = w2[3] ^ 0x6a6a6a6a;
185 w3[0] = w3[0] ^ 0x6a6a6a6a;
186 w3[1] = w3[1] ^ 0x6a6a6a6a;
187 w3[2] = w3[2] ^ 0x6a6a6a6a;
188 w3[3] = w3[3] ^ 0x6a6a6a6a;
199 sha256_transform (w0, w1, w2, w3, opad);
202 static void hmac_sha256_run (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[8], u32x opad[8], u32x digest[8])
213 sha256_transform (w0, w1, w2, w3, digest);
230 w3[3] = (64 + 32) * 8;
241 sha256_transform (w0, w1, w2, w3, digest);
244 __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)
250 const u32 gid = get_global_id (0);
252 if (gid >= gid_max) return;
256 w0[0] = swap_workaround (pws[gid].i[ 0]);
257 w0[1] = swap_workaround (pws[gid].i[ 1]);
258 w0[2] = swap_workaround (pws[gid].i[ 2]);
259 w0[3] = swap_workaround (pws[gid].i[ 3]);
263 w1[0] = swap_workaround (pws[gid].i[ 4]);
264 w1[1] = swap_workaround (pws[gid].i[ 5]);
265 w1[2] = swap_workaround (pws[gid].i[ 6]);
266 w1[3] = swap_workaround (pws[gid].i[ 7]);
270 w2[0] = swap_workaround (pws[gid].i[ 8]);
271 w2[1] = swap_workaround (pws[gid].i[ 9]);
272 w2[2] = swap_workaround (pws[gid].i[10]);
273 w2[3] = swap_workaround (pws[gid].i[11]);
277 w3[0] = swap_workaround (pws[gid].i[12]);
278 w3[1] = swap_workaround (pws[gid].i[13]);
279 w3[2] = swap_workaround (pws[gid].i[14]);
280 w3[3] = swap_workaround (pws[gid].i[15]);
286 const u32 salt_len = salt_bufs[salt_pos].salt_len;
293 esalt_buf0[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 0]);
294 esalt_buf0[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 1]);
295 esalt_buf0[2] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 2]);
296 esalt_buf0[3] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 3]);
297 esalt_buf1[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 4]);
298 esalt_buf1[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 5]);
299 esalt_buf1[2] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 6]);
300 esalt_buf1[3] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 7]);
301 esalt_buf2[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 8]);
302 esalt_buf2[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[ 9]);
303 esalt_buf2[2] = swap_workaround (esalt_bufs[salt_pos].salt_buf[10]);
304 esalt_buf2[3] = swap_workaround (esalt_bufs[salt_pos].salt_buf[11]);
305 esalt_buf3[0] = swap_workaround (esalt_bufs[salt_pos].salt_buf[12]);
306 esalt_buf3[1] = swap_workaround (esalt_bufs[salt_pos].salt_buf[13]);
308 esalt_buf3[3] = (64 + salt_len + 4) * 8;
313 hmac_sha256_pad (w0, w1, w2, w3, ipad, opad);
315 tmps[gid].ipad[0] = ipad[0];
316 tmps[gid].ipad[1] = ipad[1];
317 tmps[gid].ipad[2] = ipad[2];
318 tmps[gid].ipad[3] = ipad[3];
319 tmps[gid].ipad[4] = ipad[4];
320 tmps[gid].ipad[5] = ipad[5];
321 tmps[gid].ipad[6] = ipad[6];
322 tmps[gid].ipad[7] = ipad[7];
324 tmps[gid].opad[0] = opad[0];
325 tmps[gid].opad[1] = opad[1];
326 tmps[gid].opad[2] = opad[2];
327 tmps[gid].opad[3] = opad[3];
328 tmps[gid].opad[4] = opad[4];
329 tmps[gid].opad[5] = opad[5];
330 tmps[gid].opad[6] = opad[6];
331 tmps[gid].opad[7] = opad[7];
333 for (u32 i = 0, j = 1; i < 8; i += 8, j += 1)
337 hmac_sha256_run (esalt_buf0, esalt_buf1, esalt_buf2, esalt_buf3, ipad, opad, dgst);
339 tmps[gid].dgst[i + 0] = dgst[0];
340 tmps[gid].dgst[i + 1] = dgst[1];
341 tmps[gid].dgst[i + 2] = dgst[2];
342 tmps[gid].dgst[i + 3] = dgst[3];
343 tmps[gid].dgst[i + 4] = dgst[4];
344 tmps[gid].dgst[i + 5] = dgst[5];
345 tmps[gid].dgst[i + 6] = dgst[6];
346 tmps[gid].dgst[i + 7] = dgst[7];
348 tmps[gid].out[i + 0] = dgst[0];
349 tmps[gid].out[i + 1] = dgst[1];
350 tmps[gid].out[i + 2] = dgst[2];
351 tmps[gid].out[i + 3] = dgst[3];
352 tmps[gid].out[i + 4] = dgst[4];
353 tmps[gid].out[i + 5] = dgst[5];
354 tmps[gid].out[i + 6] = dgst[6];
355 tmps[gid].out[i + 7] = dgst[7];
359 __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)
361 const u32 gid = get_global_id (0);
363 if (gid >= gid_max) return;
367 ipad[0] = tmps[gid].ipad[0];
368 ipad[1] = tmps[gid].ipad[1];
369 ipad[2] = tmps[gid].ipad[2];
370 ipad[3] = tmps[gid].ipad[3];
371 ipad[4] = tmps[gid].ipad[4];
372 ipad[5] = tmps[gid].ipad[5];
373 ipad[6] = tmps[gid].ipad[6];
374 ipad[7] = tmps[gid].ipad[7];
378 opad[0] = tmps[gid].opad[0];
379 opad[1] = tmps[gid].opad[1];
380 opad[2] = tmps[gid].opad[2];
381 opad[3] = tmps[gid].opad[3];
382 opad[4] = tmps[gid].opad[4];
383 opad[5] = tmps[gid].opad[5];
384 opad[6] = tmps[gid].opad[6];
385 opad[7] = tmps[gid].opad[7];
387 for (u32 i = 0; i < 8; i += 8)
391 dgst[0] = tmps[gid].dgst[i + 0];
392 dgst[1] = tmps[gid].dgst[i + 1];
393 dgst[2] = tmps[gid].dgst[i + 2];
394 dgst[3] = tmps[gid].dgst[i + 3];
395 dgst[4] = tmps[gid].dgst[i + 4];
396 dgst[5] = tmps[gid].dgst[i + 5];
397 dgst[6] = tmps[gid].dgst[i + 6];
398 dgst[7] = tmps[gid].dgst[i + 7];
402 out[0] = tmps[gid].out[i + 0];
403 out[1] = tmps[gid].out[i + 1];
404 out[2] = tmps[gid].out[i + 2];
405 out[3] = tmps[gid].out[i + 3];
406 out[4] = tmps[gid].out[i + 4];
407 out[5] = tmps[gid].out[i + 5];
408 out[6] = tmps[gid].out[i + 6];
409 out[7] = tmps[gid].out[i + 7];
411 for (u32 j = 0; j < loop_cnt; j++)
433 w3[3] = (64 + 32) * 8;
435 hmac_sha256_run (w0, w1, w2, w3, ipad, opad, dgst);
447 tmps[gid].dgst[i + 0] = dgst[0];
448 tmps[gid].dgst[i + 1] = dgst[1];
449 tmps[gid].dgst[i + 2] = dgst[2];
450 tmps[gid].dgst[i + 3] = dgst[3];
451 tmps[gid].dgst[i + 4] = dgst[4];
452 tmps[gid].dgst[i + 5] = dgst[5];
453 tmps[gid].dgst[i + 6] = dgst[6];
454 tmps[gid].dgst[i + 7] = dgst[7];
456 tmps[gid].out[i + 0] = out[0];
457 tmps[gid].out[i + 1] = out[1];
458 tmps[gid].out[i + 2] = out[2];
459 tmps[gid].out[i + 3] = out[3];
460 tmps[gid].out[i + 4] = out[4];
461 tmps[gid].out[i + 5] = out[5];
462 tmps[gid].out[i + 6] = out[6];
463 tmps[gid].out[i + 7] = out[7];
467 __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)
473 const u32 gid = get_global_id (0);
475 if (gid >= gid_max) return;
477 const u32 lid = get_local_id (0);
479 const u32x r0 = tmps[gid].out[DGST_R0];
480 const u32x r1 = tmps[gid].out[DGST_R1];
481 const u32x r2 = tmps[gid].out[DGST_R2];
482 const u32x r3 = tmps[gid].out[DGST_R3];
486 #include VECT_COMPARE_M