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"
29 #define VECT_COMPARE_M "check_multi_vect1_comp4.c"
32 #define PUTCHAR64_BE(a,p,c) ((u8 *)(a))[(p) ^ 7] = (u8) (c)
33 #define GETCHAR64_BE(a,p) ((u8 *)(a))[(p) ^ 7]
43 __device__ __constant__ u64 k_sha512[80] =
45 SHA512C00, SHA512C01, SHA512C02, SHA512C03,
46 SHA512C04, SHA512C05, SHA512C06, SHA512C07,
47 SHA512C08, SHA512C09, SHA512C0a, SHA512C0b,
48 SHA512C0c, SHA512C0d, SHA512C0e, SHA512C0f,
49 SHA512C10, SHA512C11, SHA512C12, SHA512C13,
50 SHA512C14, SHA512C15, SHA512C16, SHA512C17,
51 SHA512C18, SHA512C19, SHA512C1a, SHA512C1b,
52 SHA512C1c, SHA512C1d, SHA512C1e, SHA512C1f,
53 SHA512C20, SHA512C21, SHA512C22, SHA512C23,
54 SHA512C24, SHA512C25, SHA512C26, SHA512C27,
55 SHA512C28, SHA512C29, SHA512C2a, SHA512C2b,
56 SHA512C2c, SHA512C2d, SHA512C2e, SHA512C2f,
57 SHA512C30, SHA512C31, SHA512C32, SHA512C33,
58 SHA512C34, SHA512C35, SHA512C36, SHA512C37,
59 SHA512C38, SHA512C39, SHA512C3a, SHA512C3b,
60 SHA512C3c, SHA512C3d, SHA512C3e, SHA512C3f,
61 SHA512C40, SHA512C41, SHA512C42, SHA512C43,
62 SHA512C44, SHA512C45, SHA512C46, SHA512C47,
63 SHA512C48, SHA512C49, SHA512C4a, SHA512C4b,
64 SHA512C4c, SHA512C4d, SHA512C4e, SHA512C4f,
67 __device__ static void sha512_transform (const u64x w[16], u64x digest[8])
95 #define ROUND_EXPAND() \
97 w0_t = SHA512_EXPAND (we_t, w9_t, w1_t, w0_t); \
98 w1_t = SHA512_EXPAND (wf_t, wa_t, w2_t, w1_t); \
99 w2_t = SHA512_EXPAND (w0_t, wb_t, w3_t, w2_t); \
100 w3_t = SHA512_EXPAND (w1_t, wc_t, w4_t, w3_t); \
101 w4_t = SHA512_EXPAND (w2_t, wd_t, w5_t, w4_t); \
102 w5_t = SHA512_EXPAND (w3_t, we_t, w6_t, w5_t); \
103 w6_t = SHA512_EXPAND (w4_t, wf_t, w7_t, w6_t); \
104 w7_t = SHA512_EXPAND (w5_t, w0_t, w8_t, w7_t); \
105 w8_t = SHA512_EXPAND (w6_t, w1_t, w9_t, w8_t); \
106 w9_t = SHA512_EXPAND (w7_t, w2_t, wa_t, w9_t); \
107 wa_t = SHA512_EXPAND (w8_t, w3_t, wb_t, wa_t); \
108 wb_t = SHA512_EXPAND (w9_t, w4_t, wc_t, wb_t); \
109 wc_t = SHA512_EXPAND (wa_t, w5_t, wd_t, wc_t); \
110 wd_t = SHA512_EXPAND (wb_t, w6_t, we_t, wd_t); \
111 we_t = SHA512_EXPAND (wc_t, w7_t, wf_t, we_t); \
112 wf_t = SHA512_EXPAND (wd_t, w8_t, w0_t, wf_t); \
115 #define ROUND_STEP(i) \
117 SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha512[i + 0]); \
118 SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha512[i + 1]); \
119 SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha512[i + 2]); \
120 SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha512[i + 3]); \
121 SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha512[i + 4]); \
122 SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha512[i + 5]); \
123 SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha512[i + 6]); \
124 SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha512[i + 7]); \
125 SHA512_STEP (SHA512_F0o, SHA512_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha512[i + 8]); \
126 SHA512_STEP (SHA512_F0o, SHA512_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha512[i + 9]); \
127 SHA512_STEP (SHA512_F0o, SHA512_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha512[i + 10]); \
128 SHA512_STEP (SHA512_F0o, SHA512_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha512[i + 11]); \
129 SHA512_STEP (SHA512_F0o, SHA512_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha512[i + 12]); \
130 SHA512_STEP (SHA512_F0o, SHA512_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha512[i + 13]); \
131 SHA512_STEP (SHA512_F0o, SHA512_F1o, c, d, e, f, g, h, a, b, we_t, k_sha512[i + 14]); \
132 SHA512_STEP (SHA512_F0o, SHA512_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha512[i + 15]); \
137 for (int i = 16; i < 80; i += 16)
139 ROUND_EXPAND (); ROUND_STEP (i);
152 __device__ static void sha512_init (sha512_ctx_t *sha512_ctx)
154 sha512_ctx->state[0] = SHA512M_A;
155 sha512_ctx->state[1] = SHA512M_B;
156 sha512_ctx->state[2] = SHA512M_C;
157 sha512_ctx->state[3] = SHA512M_D;
158 sha512_ctx->state[4] = SHA512M_E;
159 sha512_ctx->state[5] = SHA512M_F;
160 sha512_ctx->state[6] = SHA512M_G;
161 sha512_ctx->state[7] = SHA512M_H;
166 __device__ static void sha512_update (sha512_ctx_t *sha512_ctx, const u64x *buf, int len)
168 int pos = sha512_ctx->len & 0x7f;
170 sha512_ctx->len += len;
172 if ((pos + len) < 128)
174 for (int i = 0; i < len; i++)
176 PUTCHAR64_BE (sha512_ctx->buf, pos++, GETCHAR64_BE (buf, i));
184 for (int i = 0; i < cnt; i++)
186 PUTCHAR64_BE (sha512_ctx->buf, pos++, GETCHAR64_BE (buf, i));
189 sha512_transform (sha512_ctx->buf, sha512_ctx->state);
193 for (int i = 0; i < len; i++)
195 PUTCHAR64_BE (sha512_ctx->buf, i, GETCHAR64_BE (buf, cnt + i));
199 __device__ static void sha512_final (sha512_ctx_t *sha512_ctx)
201 int pos = sha512_ctx->len & 0x7f;
203 for (int i = pos; i < 128; i++)
205 PUTCHAR64_BE (sha512_ctx->buf, i, 0);
208 PUTCHAR64_BE (sha512_ctx->buf, pos, 0x80);
212 sha512_transform (sha512_ctx->buf, sha512_ctx->state);
214 sha512_ctx->buf[ 0] = 0;
215 sha512_ctx->buf[ 1] = 0;
216 sha512_ctx->buf[ 2] = 0;
217 sha512_ctx->buf[ 3] = 0;
218 sha512_ctx->buf[ 4] = 0;
219 sha512_ctx->buf[ 5] = 0;
220 sha512_ctx->buf[ 6] = 0;
221 sha512_ctx->buf[ 7] = 0;
222 sha512_ctx->buf[ 8] = 0;
223 sha512_ctx->buf[ 9] = 0;
224 sha512_ctx->buf[10] = 0;
225 sha512_ctx->buf[11] = 0;
226 sha512_ctx->buf[12] = 0;
227 sha512_ctx->buf[13] = 0;
228 sha512_ctx->buf[14] = 0;
229 sha512_ctx->buf[15] = 0;
232 sha512_ctx->buf[15] = sha512_ctx->len * 8;
234 sha512_transform (sha512_ctx->buf, sha512_ctx->state);
237 extern "C" __global__ void __launch_bounds__ (256, 1) m01800_init (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, sha512crypt_tmp_t *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)
243 const u32 gid = (blockIdx.x * blockDim.x) + threadIdx.x;
245 if (gid >= gid_max) return;
249 w0[0] = pws[gid].i[0];
250 w0[1] = pws[gid].i[1];
251 w0[2] = pws[gid].i[2];
252 w0[3] = pws[gid].i[3];
254 const u32 pw_len = pws[gid].pw_len;
262 salt_buf[0] = salt_bufs[salt_pos].salt_buf[0];
263 salt_buf[1] = salt_bufs[salt_pos].salt_buf[1];
264 salt_buf[2] = salt_bufs[salt_pos].salt_buf[2];
265 salt_buf[3] = salt_bufs[salt_pos].salt_buf[3];
267 u32 salt_len = salt_bufs[salt_pos].salt_len;
275 pw[0] = swap_workaround (hl32_to_64 (w0[1], w0[0]));
276 pw[1] = swap_workaround (hl32_to_64 (w0[3], w0[2]));
280 salt[0] = swap_workaround (hl32_to_64 (salt_buf[1], salt_buf[0]));
281 salt[1] = swap_workaround (hl32_to_64 (salt_buf[3], salt_buf[2]));
287 sha512_ctx_t sha512_ctx;
289 sha512_init (&sha512_ctx);
291 sha512_update (&sha512_ctx, pw, pw_len);
292 sha512_update (&sha512_ctx, salt, salt_len);
293 sha512_update (&sha512_ctx, pw, pw_len);
295 sha512_final (&sha512_ctx);
299 tmp[0] = sha512_ctx.state[0];
300 tmp[1] = sha512_ctx.state[1];
301 tmp[2] = sha512_ctx.state[2];
302 tmp[3] = sha512_ctx.state[3];
303 tmp[4] = sha512_ctx.state[4];
304 tmp[5] = sha512_ctx.state[5];
305 tmp[6] = sha512_ctx.state[6];
306 tmp[7] = sha512_ctx.state[7];
308 sha512_init (&sha512_ctx);
310 sha512_update (&sha512_ctx, pw, pw_len);
311 sha512_update (&sha512_ctx, salt, salt_len);
312 sha512_update (&sha512_ctx, tmp, pw_len);
314 for (u32 j = pw_len; j; j >>= 1)
318 sha512_update (&sha512_ctx, tmp, 64);
322 sha512_update (&sha512_ctx, pw, pw_len);
326 sha512_final (&sha512_ctx);
328 tmps[gid].l_alt_result[0] = sha512_ctx.state[0];
329 tmps[gid].l_alt_result[1] = sha512_ctx.state[1];
330 tmps[gid].l_alt_result[2] = sha512_ctx.state[2];
331 tmps[gid].l_alt_result[3] = sha512_ctx.state[3];
332 tmps[gid].l_alt_result[4] = sha512_ctx.state[4];
333 tmps[gid].l_alt_result[5] = sha512_ctx.state[5];
334 tmps[gid].l_alt_result[6] = sha512_ctx.state[6];
335 tmps[gid].l_alt_result[7] = sha512_ctx.state[7];
339 sha512_init (&sha512_ctx);
341 for (u32 j = 0; j < pw_len; j++)
343 sha512_update (&sha512_ctx, pw, pw_len);
346 sha512_final (&sha512_ctx);
348 tmps[gid].l_p_bytes[0] = sha512_ctx.state[0];
349 tmps[gid].l_p_bytes[1] = sha512_ctx.state[1];
353 sha512_init (&sha512_ctx);
355 for (u32 j = 0; j < 16 + ((tmps[gid].l_alt_result[0] >> 56) & 0xff); j++)
357 sha512_update (&sha512_ctx, salt, salt_len);
360 sha512_final (&sha512_ctx);
362 tmps[gid].l_s_bytes[0] = sha512_ctx.state[0];
363 tmps[gid].l_s_bytes[1] = sha512_ctx.state[1];
366 extern "C" __global__ void __launch_bounds__ (256, 1) m01800_loop (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, sha512crypt_tmp_t *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)
372 const u32 gid = (blockIdx.x * blockDim.x) + threadIdx.x;
374 if (gid >= gid_max) return;
379 l_p_bytes0[0] = tmps[gid].l_p_bytes[0];
380 l_p_bytes0[1] = tmps[gid].l_p_bytes[1];
382 const u32 pw_len = pws[gid].pw_len;
386 l_s_bytes0[0] = tmps[gid].l_s_bytes[0];
387 l_s_bytes0[1] = tmps[gid].l_s_bytes[1];
389 const u32 salt_len = salt_bufs[salt_pos].salt_len;
393 wpc_len[0] = 64 + 0 + 0 + pw_len;
394 wpc_len[1] = pw_len + 0 + 0 + 64;
395 wpc_len[2] = 64 + salt_len + 0 + pw_len;
396 wpc_len[3] = pw_len + salt_len + 0 + 64;
397 wpc_len[4] = 64 + 0 + pw_len + pw_len;
398 wpc_len[5] = pw_len + 0 + pw_len + 64;
399 wpc_len[6] = 64 + salt_len + pw_len + pw_len;
400 wpc_len[7] = pw_len + salt_len + pw_len + 64;
402 u64 wpc[8][16] = { 0 };
404 for (u32 i = 0; i < 8; i++)
410 for (u32 j = 0; j < pw_len; j++)
412 PUTCHAR64_BE (wpc[i], block_len++, GETCHAR64_BE (l_p_bytes0, j));
422 for (u32 j = 0; j < salt_len; j++)
424 PUTCHAR64_BE (wpc[i], block_len++, GETCHAR64_BE (l_s_bytes0, j));
430 for (u32 j = 0; j < pw_len; j++)
432 PUTCHAR64_BE (wpc[i], block_len++, GETCHAR64_BE (l_p_bytes0, j));
442 for (u32 j = 0; j < pw_len; j++)
444 PUTCHAR64_BE (wpc[i], block_len++, GETCHAR64_BE (l_p_bytes0, j));
448 PUTCHAR64_BE (wpc[i], block_len, 0x80);
450 wpc[i][15] = block_len * 8;
457 u64x l_alt_result[8];
459 l_alt_result[0] = tmps[gid].l_alt_result[0];
460 l_alt_result[1] = tmps[gid].l_alt_result[1];
461 l_alt_result[2] = tmps[gid].l_alt_result[2];
462 l_alt_result[3] = tmps[gid].l_alt_result[3];
463 l_alt_result[4] = tmps[gid].l_alt_result[4];
464 l_alt_result[5] = tmps[gid].l_alt_result[5];
465 l_alt_result[6] = tmps[gid].l_alt_result[6];
466 l_alt_result[7] = tmps[gid].l_alt_result[7];
469 /* Repeatedly run the collected hash value through SHA512 to burn
472 for (u32 i = 0, j = loop_pos; i < loop_cnt; i++, j++)
474 const u32 j1 = (j & 1) ? 1 : 0;
475 const u32 j3 = (j % 3) ? 2 : 0;
476 const u32 j7 = (j % 7) ? 4 : 0;
478 const u32 pc = j1 + j3 + j7;
482 block[ 0] = wpc[pc][ 0];
483 block[ 1] = wpc[pc][ 1];
484 block[ 2] = wpc[pc][ 2];
485 block[ 3] = wpc[pc][ 3];
486 block[ 4] = wpc[pc][ 4];
487 block[ 5] = wpc[pc][ 5];
488 block[ 6] = wpc[pc][ 6];
489 block[ 7] = wpc[pc][ 7];
490 block[ 8] = wpc[pc][ 8];
491 block[ 9] = wpc[pc][ 9];
492 block[10] = wpc[pc][10];
493 block[11] = wpc[pc][11];
494 block[12] = wpc[pc][12];
495 block[13] = wpc[pc][13];
496 block[14] = wpc[pc][14];
497 block[15] = wpc[pc][15];
501 const u32 block_len = wpc_len[pc];
504 for (u32 k = 0, p = block_len - 64; k < 64; k++, p++)
506 PUTCHAR64_BE (block, p, GETCHAR64_BE (l_alt_result, k));
511 block[0] = l_alt_result[0];
512 block[1] = l_alt_result[1];
513 block[2] = l_alt_result[2];
514 block[3] = l_alt_result[3];
515 block[4] = l_alt_result[4];
516 block[5] = l_alt_result[5];
517 block[6] = l_alt_result[6];
518 block[7] = l_alt_result[7];
521 l_alt_result[0] = SHA512M_A;
522 l_alt_result[1] = SHA512M_B;
523 l_alt_result[2] = SHA512M_C;
524 l_alt_result[3] = SHA512M_D;
525 l_alt_result[4] = SHA512M_E;
526 l_alt_result[5] = SHA512M_F;
527 l_alt_result[6] = SHA512M_G;
528 l_alt_result[7] = SHA512M_H;
530 sha512_transform (block, l_alt_result);
533 tmps[gid].l_alt_result[0] = l_alt_result[0];
534 tmps[gid].l_alt_result[1] = l_alt_result[1];
535 tmps[gid].l_alt_result[2] = l_alt_result[2];
536 tmps[gid].l_alt_result[3] = l_alt_result[3];
537 tmps[gid].l_alt_result[4] = l_alt_result[4];
538 tmps[gid].l_alt_result[5] = l_alt_result[5];
539 tmps[gid].l_alt_result[6] = l_alt_result[6];
540 tmps[gid].l_alt_result[7] = l_alt_result[7];
543 extern "C" __global__ void __launch_bounds__ (256, 1) m01800_comp (const pw_t *pws, const gpu_rule_t *rules_buf, const comb_t *combs_buf, const bf_t *bfs_buf, sha512crypt_tmp_t *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)
549 const u32 gid = (blockIdx.x * blockDim.x) + threadIdx.x;
551 if (gid >= gid_max) return;
553 const u32 lid = threadIdx.x;
555 const u64x a = swap_workaround (tmps[gid].l_alt_result[0]);
556 const u64x b = swap_workaround (tmps[gid].l_alt_result[1]);
558 const u32x r0 = l32_from_64 (a);
559 const u32x r1 = h32_from_64 (a);
560 const u32x r2 = l32_from_64 (b);
561 const u32x r3 = h32_from_64 (b);
565 #include VECT_COMPARE_M