From 23bbe457a009257f1e23ff1e9d338af60eaf4685 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Fri, 21 May 2021 11:24:43 +0200 Subject: [PATCH] RAR3-hp Plugin: Replaced naive with true UTF8 to UTF16 conversion in optimized and pure kernel --- OpenCL/m12500-optimized.cl | 30 ++++++++++++++------- OpenCL/m12500-pure.cl | 51 ++++++++++-------------------------- docs/changes.txt | 1 + src/modules/module_12500.c | 7 ++--- tools/test_modules/m12500.pm | 2 +- 5 files changed, 40 insertions(+), 51 deletions(-) diff --git a/OpenCL/m12500-optimized.cl b/OpenCL/m12500-optimized.cl index 89071057f..63ff55dd5 100644 --- a/OpenCL/m12500-optimized.cl +++ b/OpenCL/m12500-optimized.cl @@ -54,15 +54,20 @@ KERNEL_FQ void m12500_loop (KERN_ATTR_TMPS (rar3_tmp_t)) if (gid >= gid_max) return; - u32 pw_buf[5]; + u32 pw_buf[10]; pw_buf[0] = pws[gid].i[0]; pw_buf[1] = pws[gid].i[1]; pw_buf[2] = pws[gid].i[2]; pw_buf[3] = pws[gid].i[3]; pw_buf[4] = pws[gid].i[4]; + pw_buf[5] = pws[gid].i[5]; + pw_buf[6] = pws[gid].i[6]; + pw_buf[7] = pws[gid].i[7]; + pw_buf[8] = pws[gid].i[8]; + pw_buf[9] = pws[gid].i[9]; - const u32 pw_len = MIN (pws[gid].pw_len, 20); + const u32 pw_len = MIN (pws[gid].pw_len, 40); u32 salt_buf[2]; @@ -81,7 +86,7 @@ KERNEL_FQ void m12500_loop (KERN_ATTR_TMPS (rar3_tmp_t)) for (u32 i = 0, p = 0; i < 64; i++) { - for (u32 j = 0; j < pw_len; j++, p += 2) + for (u32 j = 0; j < pw_len; j++, p += 1) { PUTCHAR_BE (largeblock, p, GETCHAR (pw_buf, j)); } @@ -96,9 +101,9 @@ KERNEL_FQ void m12500_loop (KERN_ATTR_TMPS (rar3_tmp_t)) p += 3; } - const u32 p2 = (pw_len * 2) + salt_len; + const u32 p2 = pw_len + salt_len; - const u32 p3 = (pw_len * 2) + salt_len + 3; + const u32 p3 = pw_len + salt_len + 3; const u32 init_pos = loop_pos / (ROUNDS / 16); @@ -295,11 +300,11 @@ KERNEL_FQ void m12500_comp (KERN_ATTR_TMPS (rar3_tmp_t)) * base */ - const u32 pw_len = MIN (pws[gid].pw_len, 20); + const u32 pw_len = MIN (pws[gid].pw_len, 40); const u32 salt_len = 8; - const u32 p3 = (pw_len * 2) + salt_len + 3; + const u32 p3 = pw_len + salt_len + 3; u32 w0[4]; u32 w1[4]; @@ -364,13 +369,18 @@ KERNEL_FQ void m12500_comp (KERN_ATTR_TMPS (rar3_tmp_t)) for (int i = 0; i < 16; i++) { - u32 pw_buf[5]; + u32 pw_buf[10]; pw_buf[0] = pws[gid].i[0]; pw_buf[1] = pws[gid].i[1]; pw_buf[2] = pws[gid].i[2]; pw_buf[3] = pws[gid].i[3]; pw_buf[4] = pws[gid].i[4]; + pw_buf[5] = pws[gid].i[5]; + pw_buf[6] = pws[gid].i[6]; + pw_buf[7] = pws[gid].i[7]; + pw_buf[8] = pws[gid].i[8]; + pw_buf[9] = pws[gid].i[9]; //const u32 pw_len = pws[gid].pw_len; @@ -381,7 +391,7 @@ KERNEL_FQ void m12500_comp (KERN_ATTR_TMPS (rar3_tmp_t)) //const u32 salt_len = 8; - //const u32 p3 = (pw_len * 2) + salt_len + 3; + //const u32 p3 = pw_len + salt_len + 3; u32 w[16]; @@ -404,7 +414,7 @@ KERNEL_FQ void m12500_comp (KERN_ATTR_TMPS (rar3_tmp_t)) u32 p = 0; - for (u32 j = 0; j < pw_len; j++, p += 2) + for (u32 j = 0; j < pw_len; j++, p += 1) { PUTCHAR_BE (w, p, GETCHAR (pw_buf, j)); } diff --git a/OpenCL/m12500-pure.cl b/OpenCL/m12500-pure.cl index 46a7100ce..ce1b2cb53 100644 --- a/OpenCL/m12500-pure.cl +++ b/OpenCL/m12500-pure.cl @@ -741,38 +741,17 @@ KERNEL_FQ void m12500_init (KERN_ATTR_TMPS (rar3_tmp_t)) const u32 pw_len = pws[gid].pw_len; - // first set the utf16le pass: - u32 w[80] = { 0 }; - for (u32 i = 0, j = 0, k = 0; i < pw_len; i += 16, j += 4, k += 8) + for (int i = 0, j = 0; i < pw_len; i += 4, j += 1) { - u32 a[4]; - - a[0] = pws[gid].i[j + 0]; - a[1] = pws[gid].i[j + 1]; - a[2] = pws[gid].i[j + 2]; - a[3] = pws[gid].i[j + 3]; - - u32 b[4]; - u32 c[4]; - - make_utf16le (a, b, c); - - w[k + 0] = hc_swap32_S (b[0]); - w[k + 1] = hc_swap32_S (b[1]); - w[k + 2] = hc_swap32_S (b[2]); - w[k + 3] = hc_swap32_S (b[3]); - w[k + 4] = hc_swap32_S (c[0]); - w[k + 5] = hc_swap32_S (c[1]); - w[k + 6] = hc_swap32_S (c[2]); - w[k + 7] = hc_swap32_S (c[3]); + w[j] = hc_swap32_S (pws[gid].i[j]); } // append salt: - const u32 salt_idx = (pw_len * 2) / 4; - const u32 salt_off = (pw_len * 2) & 3; + const u32 salt_idx = pw_len / 4; + const u32 salt_off = pw_len & 3; u32 salt_buf[3]; @@ -789,10 +768,9 @@ KERNEL_FQ void m12500_init (KERN_ATTR_TMPS (rar3_tmp_t)) salt_buf[0] = (salt_buf[0] >> 16); } - w[salt_idx] |= salt_buf[0]; - - w[salt_idx + 1] = salt_buf[1]; - w[salt_idx + 2] = salt_buf[2]; + w[salt_idx + 0] |= salt_buf[0]; + w[salt_idx + 1] = salt_buf[1]; + w[salt_idx + 2] = salt_buf[2]; // store initial w[] (pass and salt) in tmps: @@ -819,17 +797,17 @@ KERNEL_FQ void m12500_loop (KERN_ATTR_TMPS (rar3_tmp_t)) * base */ - const u32 pw_len = pws[gid].pw_len; + const u32 pw_len = pws[gid].pw_len & 255; const u32 salt_len = 8; - const u32 pw_salt_len = (pw_len * 2) + salt_len; + const u32 pw_salt_len = pw_len + salt_len; const u32 p3 = pw_salt_len + 3; - u32 w[80] = { 0 }; // 64 byte aligned + u32 w[80] = { 0 }; - for (u32 i = 0; i < 66; i++) // unroll ? + for (u32 i = 0; i < 66; i++) { w[i] = tmps[gid].w[i]; } @@ -856,7 +834,6 @@ KERNEL_FQ void m12500_loop (KERN_ATTR_TMPS (rar3_tmp_t)) ctx_iv.len += 3; - // copy the context from ctx_iv to ctx: sha1_ctx_t ctx; @@ -917,7 +894,7 @@ KERNEL_FQ void m12500_loop (KERN_ATTR_TMPS (rar3_tmp_t)) // only needed if pw_len > 28: - for (u32 i = 0; i < 66; i++) // unroll ? + for (u32 i = 0; i < 66; i++) { tmps[gid].w[i] = w[i]; } @@ -986,11 +963,11 @@ KERNEL_FQ void m12500_comp (KERN_ATTR_TMPS (rar3_tmp_t)) * base */ - const u32 pw_len = pws[gid].pw_len; + const u32 pw_len = pws[gid].pw_len & 255; const u32 salt_len = 8; - const u32 pw_salt_len = (pw_len * 2) + salt_len; + const u32 pw_salt_len = pw_len + salt_len; const u32 p3 = pw_salt_len + 3; diff --git a/docs/changes.txt b/docs/changes.txt index 962152833..3f56c22d2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -16,6 +16,7 @@ - CUDA Backend: Do not warn about missing CUDA SDK installation if --stdout is used - Performance Monitor: Add -S as a user suggestion to improve cracking performance in specific attack configurations - Status Screen: Show currently running kernel type (pure, optimized) and generator type (host, device) +- RAR3-hp Plugin: Replaced naive with true UTF8 to UTF16 conversion in optimized and pure kernel ## ## Technical diff --git a/src/modules/module_12500.c b/src/modules/module_12500.c index 728b4ddbf..4210b4866 100644 --- a/src/modules/module_12500.c +++ b/src/modules/module_12500.c @@ -20,7 +20,8 @@ static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; static const char *HASH_NAME = "RAR3-hp"; static const u64 KERN_TYPE = 12500; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; -static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE; +static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_POST_AMP_UTF16LE; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; static const char *ST_HASH = "$RAR3$*0*45109af8ab5f297a*adbf6c5385d7a40373e8f77d7b89d317"; @@ -100,7 +101,7 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con { const bool optimized_kernel = (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL); - u32 pw_max = 127; + u32 pw_max = 64; if (optimized_kernel == true) { @@ -112,7 +113,7 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con const char *module_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { - const char *mask = "?b?b?b?b?b"; + const char *mask = "?l?l?l?l?l"; return mask; } diff --git a/tools/test_modules/m12500.pm b/tools/test_modules/m12500.pm index 155683a15..9e6729b9a 100644 --- a/tools/test_modules/m12500.pm +++ b/tools/test_modules/m12500.pm @@ -12,7 +12,7 @@ use Digest::SHA; use Crypt::CBC; use Encode; -sub module_constraints { [[0, 127], [8, 8], [0, 20], [8, 8], [-1, -1]] } +sub module_constraints { [[0, 64], [8, 8], [0, 20], [8, 8], [-1, -1]] } my $ITERATIONS = 0x40000;