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_vect2_comp4.c"
41 #define VECT_COMPARE_M "check_multi_vect4_comp4.c"
44 __constant u32 k_sha256[64] =
46 SHA256C00, SHA256C01, SHA256C02, SHA256C03,
47 SHA256C04, SHA256C05, SHA256C06, SHA256C07,
48 SHA256C08, SHA256C09, SHA256C0a, SHA256C0b,
49 SHA256C0c, SHA256C0d, SHA256C0e, SHA256C0f,
50 SHA256C10, SHA256C11, SHA256C12, SHA256C13,
51 SHA256C14, SHA256C15, SHA256C16, SHA256C17,
52 SHA256C18, SHA256C19, SHA256C1a, SHA256C1b,
53 SHA256C1c, SHA256C1d, SHA256C1e, SHA256C1f,
54 SHA256C20, SHA256C21, SHA256C22, SHA256C23,
55 SHA256C24, SHA256C25, SHA256C26, SHA256C27,
56 SHA256C28, SHA256C29, SHA256C2a, SHA256C2b,
57 SHA256C2c, SHA256C2d, SHA256C2e, SHA256C2f,
58 SHA256C30, SHA256C31, SHA256C32, SHA256C33,
59 SHA256C34, SHA256C35, SHA256C36, SHA256C37,
60 SHA256C38, SHA256C39, SHA256C3a, SHA256C3b,
61 SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f,
64 static void sha256_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[8])
92 #define ROUND_EXPAND() \
94 w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); \
95 w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); \
96 w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); \
97 w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); \
98 w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); \
99 w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); \
100 w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); \
101 w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); \
102 w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); \
103 w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); \
104 wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); \
105 wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); \
106 wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); \
107 wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); \
108 we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); \
109 wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); \
112 #define ROUND_STEP(i) \
114 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i + 0]); \
115 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i + 1]); \
116 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i + 2]); \
117 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i + 3]); \
118 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i + 4]); \
119 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i + 5]); \
120 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i + 6]); \
121 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i + 7]); \
122 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i + 8]); \
123 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i + 9]); \
124 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
125 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
126 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
127 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
128 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
129 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
135 for (int i = 16; i < 64; i += 16)
137 ROUND_EXPAND (); ROUND_STEP (i);
150 static void hmac_sha256_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[8], u32x opad[8])
152 w0[0] = w0[0] ^ 0x36363636;
153 w0[1] = w0[1] ^ 0x36363636;
154 w0[2] = w0[2] ^ 0x36363636;
155 w0[3] = w0[3] ^ 0x36363636;
156 w1[0] = w1[0] ^ 0x36363636;
157 w1[1] = w1[1] ^ 0x36363636;
158 w1[2] = w1[2] ^ 0x36363636;
159 w1[3] = w1[3] ^ 0x36363636;
160 w2[0] = w2[0] ^ 0x36363636;
161 w2[1] = w2[1] ^ 0x36363636;
162 w2[2] = w2[2] ^ 0x36363636;
163 w2[3] = w2[3] ^ 0x36363636;
164 w3[0] = w3[0] ^ 0x36363636;
165 w3[1] = w3[1] ^ 0x36363636;
166 w3[2] = w3[2] ^ 0x36363636;
167 w3[3] = w3[3] ^ 0x36363636;
178 sha256_transform (w0, w1, w2, w3, ipad);
180 w0[0] = w0[0] ^ 0x6a6a6a6a;
181 w0[1] = w0[1] ^ 0x6a6a6a6a;
182 w0[2] = w0[2] ^ 0x6a6a6a6a;
183 w0[3] = w0[3] ^ 0x6a6a6a6a;
184 w1[0] = w1[0] ^ 0x6a6a6a6a;
185 w1[1] = w1[1] ^ 0x6a6a6a6a;
186 w1[2] = w1[2] ^ 0x6a6a6a6a;
187 w1[3] = w1[3] ^ 0x6a6a6a6a;
188 w2[0] = w2[0] ^ 0x6a6a6a6a;
189 w2[1] = w2[1] ^ 0x6a6a6a6a;
190 w2[2] = w2[2] ^ 0x6a6a6a6a;
191 w2[3] = w2[3] ^ 0x6a6a6a6a;
192 w3[0] = w3[0] ^ 0x6a6a6a6a;
193 w3[1] = w3[1] ^ 0x6a6a6a6a;
194 w3[2] = w3[2] ^ 0x6a6a6a6a;
195 w3[3] = w3[3] ^ 0x6a6a6a6a;
206 sha256_transform (w0, w1, w2, w3, opad);
209 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])
220 sha256_transform (w0, w1, w2, w3, digest);
237 w3[3] = (64 + 32) * 8;
248 sha256_transform (w0, w1, w2, w3, digest);
251 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m06400_init (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha256aix_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 wpa_t *wpa_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)
257 const u32 gid = get_global_id (0);
259 if (gid >= gid_max) return;
263 w0[0] = pws[gid].i[ 0];
264 w0[1] = pws[gid].i[ 1];
265 w0[2] = pws[gid].i[ 2];
266 w0[3] = pws[gid].i[ 3];
270 w1[0] = pws[gid].i[ 4];
271 w1[1] = pws[gid].i[ 5];
272 w1[2] = pws[gid].i[ 6];
273 w1[3] = pws[gid].i[ 7];
277 w2[0] = pws[gid].i[ 8];
278 w2[1] = pws[gid].i[ 9];
279 w2[2] = pws[gid].i[10];
280 w2[3] = pws[gid].i[11];
284 w3[0] = pws[gid].i[12];
285 w3[1] = pws[gid].i[13];
286 w3[2] = pws[gid].i[14];
287 w3[3] = pws[gid].i[15];
293 u32 salt_len = salt_bufs[salt_pos].salt_len;
297 salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
298 salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
299 salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
300 salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
304 salt_buf1[0] = salt_bufs[salt_pos].salt_buf[ 4];
305 salt_buf1[1] = salt_bufs[salt_pos].salt_buf[ 5];
306 salt_buf1[2] = salt_bufs[salt_pos].salt_buf[ 6];
307 salt_buf1[3] = salt_bufs[salt_pos].salt_buf[ 7];
311 salt_buf2[0] = salt_bufs[salt_pos].salt_buf[ 8];
312 salt_buf2[1] = salt_bufs[salt_pos].salt_buf[ 9];
313 salt_buf2[2] = salt_bufs[salt_pos].salt_buf[10];
314 salt_buf2[3] = salt_bufs[salt_pos].salt_buf[11];
323 append_0x01_4 (salt_buf0, salt_buf1, salt_buf2, salt_buf3, salt_len + 3);
325 append_0x80_4 (salt_buf0, salt_buf1, salt_buf2, salt_buf3, salt_len + 4);
331 w0[0] = swap_workaround (w0[0]);
332 w0[1] = swap_workaround (w0[1]);
333 w0[2] = swap_workaround (w0[2]);
334 w0[3] = swap_workaround (w0[3]);
335 w1[0] = swap_workaround (w1[0]);
336 w1[1] = swap_workaround (w1[1]);
337 w1[2] = swap_workaround (w1[2]);
338 w1[3] = swap_workaround (w1[3]);
339 w2[0] = swap_workaround (w2[0]);
340 w2[1] = swap_workaround (w2[1]);
341 w2[2] = swap_workaround (w2[2]);
342 w2[3] = swap_workaround (w2[3]);
343 w3[0] = swap_workaround (w3[0]);
344 w3[1] = swap_workaround (w3[1]);
345 w3[2] = swap_workaround (w3[2]);
346 w3[3] = swap_workaround (w3[3]);
351 hmac_sha256_pad (w0, w1, w2, w3, ipad, opad);
353 tmps[gid].ipad[0] = ipad[0];
354 tmps[gid].ipad[1] = ipad[1];
355 tmps[gid].ipad[2] = ipad[2];
356 tmps[gid].ipad[3] = ipad[3];
357 tmps[gid].ipad[4] = ipad[4];
358 tmps[gid].ipad[5] = ipad[5];
359 tmps[gid].ipad[6] = ipad[6];
360 tmps[gid].ipad[7] = ipad[7];
362 tmps[gid].opad[0] = opad[0];
363 tmps[gid].opad[1] = opad[1];
364 tmps[gid].opad[2] = opad[2];
365 tmps[gid].opad[3] = opad[3];
366 tmps[gid].opad[4] = opad[4];
367 tmps[gid].opad[5] = opad[5];
368 tmps[gid].opad[6] = opad[6];
369 tmps[gid].opad[7] = opad[7];
371 w0[0] = salt_buf0[0];
372 w0[1] = salt_buf0[1];
373 w0[2] = salt_buf0[2];
374 w0[3] = salt_buf0[3];
375 w1[0] = salt_buf1[0];
376 w1[1] = salt_buf1[1];
377 w1[2] = salt_buf1[2];
378 w1[3] = salt_buf1[3];
379 w2[0] = salt_buf2[0];
380 w2[1] = salt_buf2[1];
381 w2[2] = salt_buf2[2];
382 w2[3] = salt_buf2[3];
383 w3[0] = salt_buf3[0];
384 w3[1] = salt_buf3[1];
385 w3[2] = salt_buf3[2];
386 // w3[3] = salt_buf3[3];
388 w0[0] = swap_workaround (w0[0]);
389 w0[1] = swap_workaround (w0[1]);
390 w0[2] = swap_workaround (w0[2]);
391 w0[3] = swap_workaround (w0[3]);
392 w1[0] = swap_workaround (w1[0]);
393 w1[1] = swap_workaround (w1[1]);
394 w1[2] = swap_workaround (w1[2]);
395 w1[3] = swap_workaround (w1[3]);
396 w2[0] = swap_workaround (w2[0]);
397 w2[1] = swap_workaround (w2[1]);
398 w2[2] = swap_workaround (w2[2]);
399 w2[3] = swap_workaround (w2[3]);
400 w3[0] = swap_workaround (w3[0]);
401 w3[1] = swap_workaround (w3[1]);
402 w3[2] = swap_workaround (w3[2]);
403 w3[3] = (64 + salt_len + 4) * 8;
407 hmac_sha256_run (w0, w1, w2, w3, ipad, opad, dgst);
409 tmps[gid].dgst[0] = dgst[0];
410 tmps[gid].dgst[1] = dgst[1];
411 tmps[gid].dgst[2] = dgst[2];
412 tmps[gid].dgst[3] = dgst[3];
413 tmps[gid].dgst[4] = dgst[4];
414 tmps[gid].dgst[5] = dgst[5];
415 tmps[gid].dgst[6] = dgst[6];
416 tmps[gid].dgst[7] = dgst[7];
418 tmps[gid].out[0] = dgst[0];
419 tmps[gid].out[1] = dgst[1];
420 tmps[gid].out[2] = dgst[2];
421 tmps[gid].out[3] = dgst[3];
422 tmps[gid].out[4] = dgst[4];
423 tmps[gid].out[5] = dgst[5];
424 tmps[gid].out[6] = dgst[6];
425 tmps[gid].out[7] = dgst[7];
428 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m06400_loop (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha256aix_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 wpa_t *wpa_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)
430 const u32 gid = get_global_id (0);
432 if (gid >= gid_max) return;
437 ipad[0] = tmps[gid].ipad[0];
438 ipad[1] = tmps[gid].ipad[1];
439 ipad[2] = tmps[gid].ipad[2];
440 ipad[3] = tmps[gid].ipad[3];
441 ipad[4] = tmps[gid].ipad[4];
442 ipad[5] = tmps[gid].ipad[5];
443 ipad[6] = tmps[gid].ipad[6];
444 ipad[7] = tmps[gid].ipad[7];
446 opad[0] = tmps[gid].opad[0];
447 opad[1] = tmps[gid].opad[1];
448 opad[2] = tmps[gid].opad[2];
449 opad[3] = tmps[gid].opad[3];
450 opad[4] = tmps[gid].opad[4];
451 opad[5] = tmps[gid].opad[5];
452 opad[6] = tmps[gid].opad[6];
453 opad[7] = tmps[gid].opad[7];
458 dgst[0] = tmps[gid].dgst[0];
459 dgst[1] = tmps[gid].dgst[1];
460 dgst[2] = tmps[gid].dgst[2];
461 dgst[3] = tmps[gid].dgst[3];
462 dgst[4] = tmps[gid].dgst[4];
463 dgst[5] = tmps[gid].dgst[5];
464 dgst[6] = tmps[gid].dgst[6];
465 dgst[7] = tmps[gid].dgst[7];
467 out[0] = tmps[gid].out[0];
468 out[1] = tmps[gid].out[1];
469 out[2] = tmps[gid].out[2];
470 out[3] = tmps[gid].out[3];
471 out[4] = tmps[gid].out[4];
472 out[5] = tmps[gid].out[5];
473 out[6] = tmps[gid].out[6];
474 out[7] = tmps[gid].out[7];
476 for (u32 j = 0; j < loop_cnt; j++)
498 w3[3] = (64 + 32) * 8;
500 hmac_sha256_run (w0, w1, w2, w3, ipad, opad, dgst);
512 tmps[gid].dgst[0] = dgst[0];
513 tmps[gid].dgst[1] = dgst[1];
514 tmps[gid].dgst[2] = dgst[2];
515 tmps[gid].dgst[3] = dgst[3];
516 tmps[gid].dgst[4] = dgst[4];
517 tmps[gid].dgst[5] = dgst[5];
518 tmps[gid].dgst[6] = dgst[6];
519 tmps[gid].dgst[7] = dgst[7];
521 tmps[gid].out[0] = out[0];
522 tmps[gid].out[1] = out[1];
523 tmps[gid].out[2] = out[2];
524 tmps[gid].out[3] = out[3];
525 tmps[gid].out[4] = out[4];
526 tmps[gid].out[5] = out[5];
527 tmps[gid].out[6] = out[6];
528 tmps[gid].out[7] = out[7];
531 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m06400_comp (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global sha256aix_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 wpa_t *wpa_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)
537 const u32 gid = get_global_id (0);
539 if (gid >= gid_max) return;
541 const u32 lid = get_local_id (0);
547 const u32x r0 = tmps[gid].out[DGST_R0];
548 const u32x r1 = tmps[gid].out[DGST_R1];
549 const u32x r2 = tmps[gid].out[DGST_R2];
550 const u32x r3 = tmps[gid].out[DGST_R3];
553 u32x a = tmps[gid].out[0];
554 u32x b = tmps[gid].out[1];
555 u32x c = tmps[gid].out[2];
556 u32x d = tmps[gid].out[3];
557 u32x e = tmps[gid].out[4];
558 u32x f = tmps[gid].out[5];
559 u32x g = tmps[gid].out[6];
560 u32x h = tmps[gid].out[7] & 0xffff03ff;
565 #include VECT_COMPARE_M