2 * Author......: Jens Steube <jens.steube@gmail.com>
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
24 #include "include/kernel_functions.c"
26 #include "common_nv.c"
27 #include "include/rp_gpu.h"
31 #define VECT_COMPARE_S "check_single_vect1_comp4.c"
32 #define VECT_COMPARE_M "check_multi_vect1_comp4.c"
36 #define VECT_COMPARE_S "check_single_vect2_comp4.c"
37 #define VECT_COMPARE_M "check_multi_vect2_comp4.c"
41 #define VECT_COMPARE_S "check_single_vect4_comp4.c"
42 #define VECT_COMPARE_M "check_multi_vect4_comp4.c"
45 __device__ __constant__ u32 k_sha256[64] =
47 SHA256C00, SHA256C01, SHA256C02, SHA256C03,
48 SHA256C04, SHA256C05, SHA256C06, SHA256C07,
49 SHA256C08, SHA256C09, SHA256C0a, SHA256C0b,
50 SHA256C0c, SHA256C0d, SHA256C0e, SHA256C0f,
51 SHA256C10, SHA256C11, SHA256C12, SHA256C13,
52 SHA256C14, SHA256C15, SHA256C16, SHA256C17,
53 SHA256C18, SHA256C19, SHA256C1a, SHA256C1b,
54 SHA256C1c, SHA256C1d, SHA256C1e, SHA256C1f,
55 SHA256C20, SHA256C21, SHA256C22, SHA256C23,
56 SHA256C24, SHA256C25, SHA256C26, SHA256C27,
57 SHA256C28, SHA256C29, SHA256C2a, SHA256C2b,
58 SHA256C2c, SHA256C2d, SHA256C2e, SHA256C2f,
59 SHA256C30, SHA256C31, SHA256C32, SHA256C33,
60 SHA256C34, SHA256C35, SHA256C36, SHA256C37,
61 SHA256C38, SHA256C39, SHA256C3a, SHA256C3b,
62 SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f,
65 __device__ __constant__ gpu_rule_t c_rules[1024];
67 __device__ static void sha256_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[8])
95 #define ROUND_EXPAND() \
97 w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); \
98 w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); \
99 w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); \
100 w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); \
101 w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); \
102 w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); \
103 w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); \
104 w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); \
105 w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); \
106 w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); \
107 wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); \
108 wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); \
109 wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); \
110 wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); \
111 we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); \
112 wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); \
115 #define ROUND_STEP(i) \
117 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i + 0]); \
118 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i + 1]); \
119 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i + 2]); \
120 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i + 3]); \
121 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i + 4]); \
122 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i + 5]); \
123 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i + 6]); \
124 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i + 7]); \
125 SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i + 8]); \
126 SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i + 9]); \
127 SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
128 SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
129 SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
130 SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
131 SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
132 SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
137 for (int i = 16; i < 64; i += 16)
139 ROUND_EXPAND (); ROUND_STEP (i);
152 __device__ static void hmac_sha256_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[8], u32x opad[8])
154 w0[0] = w0[0] ^ 0x36363636;
155 w0[1] = w0[1] ^ 0x36363636;
156 w0[2] = w0[2] ^ 0x36363636;
157 w0[3] = w0[3] ^ 0x36363636;
158 w1[0] = w1[0] ^ 0x36363636;
159 w1[1] = w1[1] ^ 0x36363636;
160 w1[2] = w1[2] ^ 0x36363636;
161 w1[3] = w1[3] ^ 0x36363636;
162 w2[0] = w2[0] ^ 0x36363636;
163 w2[1] = w2[1] ^ 0x36363636;
164 w2[2] = w2[2] ^ 0x36363636;
165 w2[3] = w2[3] ^ 0x36363636;
166 w3[0] = w3[0] ^ 0x36363636;
167 w3[1] = w3[1] ^ 0x36363636;
168 w3[2] = w3[2] ^ 0x36363636;
169 w3[3] = w3[3] ^ 0x36363636;
180 sha256_transform (w0, w1, w2, w3, ipad);
182 w0[0] = w0[0] ^ 0x6a6a6a6a;
183 w0[1] = w0[1] ^ 0x6a6a6a6a;
184 w0[2] = w0[2] ^ 0x6a6a6a6a;
185 w0[3] = w0[3] ^ 0x6a6a6a6a;
186 w1[0] = w1[0] ^ 0x6a6a6a6a;
187 w1[1] = w1[1] ^ 0x6a6a6a6a;
188 w1[2] = w1[2] ^ 0x6a6a6a6a;
189 w1[3] = w1[3] ^ 0x6a6a6a6a;
190 w2[0] = w2[0] ^ 0x6a6a6a6a;
191 w2[1] = w2[1] ^ 0x6a6a6a6a;
192 w2[2] = w2[2] ^ 0x6a6a6a6a;
193 w2[3] = w2[3] ^ 0x6a6a6a6a;
194 w3[0] = w3[0] ^ 0x6a6a6a6a;
195 w3[1] = w3[1] ^ 0x6a6a6a6a;
196 w3[2] = w3[2] ^ 0x6a6a6a6a;
197 w3[3] = w3[3] ^ 0x6a6a6a6a;
208 sha256_transform (w0, w1, w2, w3, opad);
211 __device__ 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])
222 sha256_transform (w0, w1, w2, w3, digest);
239 w3[3] = (64 + 32) * 8;
250 sha256_transform (w0, w1, w2, w3, digest);
253 extern "C" __global__ void __launch_bounds__ (256, 1) m01460_m04 (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, const void *tmps, void *hooks, const u32 *bitmaps_buf_s1_a, const u32 *bitmaps_buf_s1_b, const u32 *bitmaps_buf_s1_c, const u32 *bitmaps_buf_s1_d, const u32 *bitmaps_buf_s2_a, const u32 *bitmaps_buf_s2_b, const u32 *bitmaps_buf_s2_c, const u32 *bitmaps_buf_s2_d, plain_t *plains_buf, const digest_t *digests_buf, u32 *hashes_shown, const salt_t *salt_bufs, const void *esalt_bufs, u32 *d_return_buf, 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)
259 const u32 lid = threadIdx.x;
265 const u32 gid = (blockIdx.x * blockDim.x) + threadIdx.x;
267 if (gid >= gid_max) return;
271 pw_buf0[0] = pws[gid].i[ 0];
272 pw_buf0[1] = pws[gid].i[ 1];
273 pw_buf0[2] = pws[gid].i[ 2];
274 pw_buf0[3] = pws[gid].i[ 3];
278 pw_buf1[0] = pws[gid].i[ 4];
279 pw_buf1[1] = pws[gid].i[ 5];
280 pw_buf1[2] = pws[gid].i[ 6];
281 pw_buf1[3] = pws[gid].i[ 7];
283 const u32 pw_len = pws[gid].pw_len;
291 salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
292 salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
293 salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
294 salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
298 salt_buf1[0] = salt_bufs[salt_pos].salt_buf[ 4];
299 salt_buf1[1] = salt_bufs[salt_pos].salt_buf[ 5];
300 salt_buf1[2] = salt_bufs[salt_pos].salt_buf[ 6];
301 salt_buf1[3] = salt_bufs[salt_pos].salt_buf[ 7];
309 w0_t[0] = swap_workaround (salt_buf0[0]);
310 w0_t[1] = swap_workaround (salt_buf0[1]);
311 w0_t[2] = swap_workaround (salt_buf0[2]);
312 w0_t[3] = swap_workaround (salt_buf0[3]);
316 w1_t[0] = swap_workaround (salt_buf1[0]);
317 w1_t[1] = swap_workaround (salt_buf1[1]);
318 w1_t[2] = swap_workaround (salt_buf1[2]);
319 w1_t[3] = swap_workaround (salt_buf1[3]);
338 hmac_sha256_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
344 for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
374 const u32 out_len = apply_rules (c_rules[il_pos].cmds, w0, w1, pw_len);
376 append_0x80_2 (w0, w1, out_len);
378 w0_t[0] = swap_workaround (w0[0]);
379 w0_t[1] = swap_workaround (w0[1]);
380 w0_t[2] = swap_workaround (w0[2]);
381 w0_t[3] = swap_workaround (w0[3]);
382 w1_t[0] = swap_workaround (w1[0]);
383 w1_t[1] = swap_workaround (w1[1]);
384 w1_t[2] = swap_workaround (w1[2]);
385 w1_t[3] = swap_workaround (w1[3]);
393 w3_t[3] = (64 + out_len) * 8;
397 hmac_sha256_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
399 const u32x r0 = digest[3];
400 const u32x r1 = digest[7];
401 const u32x r2 = digest[2];
402 const u32x r3 = digest[6];
404 #include VECT_COMPARE_M
408 extern "C" __global__ void __launch_bounds__ (256, 1) m01460_m08 (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, const void *tmps, void *hooks, const u32 *bitmaps_buf_s1_a, const u32 *bitmaps_buf_s1_b, const u32 *bitmaps_buf_s1_c, const u32 *bitmaps_buf_s1_d, const u32 *bitmaps_buf_s2_a, const u32 *bitmaps_buf_s2_b, const u32 *bitmaps_buf_s2_c, const u32 *bitmaps_buf_s2_d, plain_t *plains_buf, const digest_t *digests_buf, u32 *hashes_shown, const salt_t *salt_bufs, const void *esalt_bufs, u32 *d_return_buf, 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)
412 extern "C" __global__ void __launch_bounds__ (256, 1) m01460_m16 (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, const void *tmps, void *hooks, const u32 *bitmaps_buf_s1_a, const u32 *bitmaps_buf_s1_b, const u32 *bitmaps_buf_s1_c, const u32 *bitmaps_buf_s1_d, const u32 *bitmaps_buf_s2_a, const u32 *bitmaps_buf_s2_b, const u32 *bitmaps_buf_s2_c, const u32 *bitmaps_buf_s2_d, plain_t *plains_buf, const digest_t *digests_buf, u32 *hashes_shown, const salt_t *salt_bufs, const void *esalt_bufs, u32 *d_return_buf, 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)
416 extern "C" __global__ void __launch_bounds__ (256, 1) m01460_s04 (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, const void *tmps, void *hooks, const u32 *bitmaps_buf_s1_a, const u32 *bitmaps_buf_s1_b, const u32 *bitmaps_buf_s1_c, const u32 *bitmaps_buf_s1_d, const u32 *bitmaps_buf_s2_a, const u32 *bitmaps_buf_s2_b, const u32 *bitmaps_buf_s2_c, const u32 *bitmaps_buf_s2_d, plain_t *plains_buf, const digest_t *digests_buf, u32 *hashes_shown, const salt_t *salt_bufs, const void *esalt_bufs, u32 *d_return_buf, 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)
422 const u32 lid = threadIdx.x;
428 const u32 gid = (blockIdx.x * blockDim.x) + threadIdx.x;
430 if (gid >= gid_max) return;
434 pw_buf0[0] = pws[gid].i[ 0];
435 pw_buf0[1] = pws[gid].i[ 1];
436 pw_buf0[2] = pws[gid].i[ 2];
437 pw_buf0[3] = pws[gid].i[ 3];
441 pw_buf1[0] = pws[gid].i[ 4];
442 pw_buf1[1] = pws[gid].i[ 5];
443 pw_buf1[2] = pws[gid].i[ 6];
444 pw_buf1[3] = pws[gid].i[ 7];
446 const u32 pw_len = pws[gid].pw_len;
454 salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
455 salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
456 salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
457 salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
461 salt_buf1[0] = salt_bufs[salt_pos].salt_buf[ 4];
462 salt_buf1[1] = salt_bufs[salt_pos].salt_buf[ 5];
463 salt_buf1[2] = salt_bufs[salt_pos].salt_buf[ 6];
464 salt_buf1[3] = salt_bufs[salt_pos].salt_buf[ 7];
472 w0_t[0] = swap_workaround (salt_buf0[0]);
473 w0_t[1] = swap_workaround (salt_buf0[1]);
474 w0_t[2] = swap_workaround (salt_buf0[2]);
475 w0_t[3] = swap_workaround (salt_buf0[3]);
479 w1_t[0] = swap_workaround (salt_buf1[0]);
480 w1_t[1] = swap_workaround (salt_buf1[1]);
481 w1_t[2] = swap_workaround (salt_buf1[2]);
482 w1_t[3] = swap_workaround (salt_buf1[3]);
501 hmac_sha256_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
507 const u32 search[4] =
509 digests_buf[digests_offset].digest_buf[DGST_R0],
510 digests_buf[digests_offset].digest_buf[DGST_R1],
511 digests_buf[digests_offset].digest_buf[DGST_R2],
512 digests_buf[digests_offset].digest_buf[DGST_R3]
519 for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
549 const u32 out_len = apply_rules (c_rules[il_pos].cmds, w0, w1, pw_len);
551 append_0x80_2 (w0, w1, out_len);
553 w0_t[0] = swap_workaround (w0[0]);
554 w0_t[1] = swap_workaround (w0[1]);
555 w0_t[2] = swap_workaround (w0[2]);
556 w0_t[3] = swap_workaround (w0[3]);
557 w1_t[0] = swap_workaround (w1[0]);
558 w1_t[1] = swap_workaround (w1[1]);
559 w1_t[2] = swap_workaround (w1[2]);
560 w1_t[3] = swap_workaround (w1[3]);
568 w3_t[3] = (64 + out_len) * 8;
572 hmac_sha256_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
574 const u32x r0 = digest[3];
575 const u32x r1 = digest[7];
576 const u32x r2 = digest[2];
577 const u32x r3 = digest[6];
579 #include VECT_COMPARE_S
583 extern "C" __global__ void __launch_bounds__ (256, 1) m01460_s08 (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, const void *tmps, void *hooks, const u32 *bitmaps_buf_s1_a, const u32 *bitmaps_buf_s1_b, const u32 *bitmaps_buf_s1_c, const u32 *bitmaps_buf_s1_d, const u32 *bitmaps_buf_s2_a, const u32 *bitmaps_buf_s2_b, const u32 *bitmaps_buf_s2_c, const u32 *bitmaps_buf_s2_d, plain_t *plains_buf, const digest_t *digests_buf, u32 *hashes_shown, const salt_t *salt_bufs, const void *esalt_bufs, u32 *d_return_buf, 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)
587 extern "C" __global__ void __launch_bounds__ (256, 1) m01460_s16 (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, const void *tmps, void *hooks, const u32 *bitmaps_buf_s1_a, const u32 *bitmaps_buf_s1_b, const u32 *bitmaps_buf_s1_c, const u32 *bitmaps_buf_s1_d, const u32 *bitmaps_buf_s2_a, const u32 *bitmaps_buf_s2_b, const u32 *bitmaps_buf_s2_c, const u32 *bitmaps_buf_s2_d, plain_t *plains_buf, const digest_t *digests_buf, u32 *hashes_shown, const salt_t *salt_bufs, const void *esalt_bufs, u32 *d_return_buf, 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)