From aa7c579736c4f1cd5e3fdb3b15df31c184e56ce2 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Tue, 18 May 2021 10:58:13 +0200 Subject: [PATCH] Added hash-mode: MurmurHash --- OpenCL/m25700_a0-optimized.cl | 199 +++++++++++++++++ OpenCL/m25700_a1-optimized.cl | 310 +++++++++++++++++++++++++++ OpenCL/m25700_a3-optimized.cl | 392 ++++++++++++++++++++++++++++++++++ docs/changes.txt | 1 + docs/readme.txt | 1 + src/modules/module_25700.c | 190 ++++++++++++++++ tools/test_modules/m25700.pm | 148 +++++++++++++ 7 files changed, 1241 insertions(+) create mode 100644 OpenCL/m25700_a0-optimized.cl create mode 100644 OpenCL/m25700_a1-optimized.cl create mode 100644 OpenCL/m25700_a3-optimized.cl create mode 100644 src/modules/module_25700.c create mode 100644 tools/test_modules/m25700.pm diff --git a/OpenCL/m25700_a0-optimized.cl b/OpenCL/m25700_a0-optimized.cl new file mode 100644 index 000000000..bbd9747e2 --- /dev/null +++ b/OpenCL/m25700_a0-optimized.cl @@ -0,0 +1,199 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_platform.cl" +#include "inc_common.cl" +#include "inc_rp_optimized.h" +#include "inc_rp_optimized.cl" +#include "inc_simd.cl" +#endif + +DECLSPEC u32 MurmurHash (const u32 seed, const u32 *w, const int pw_len) +{ + u32 hash = seed; + + #define M 0x7fd652ad + #define R 16 + + hash += 0xdeadbeef; + + int i; + int j; + + for (i = 0, j = 0; i < pw_len - 3; i += 4, j += 1) + { + const u32 tmp = w[j]; + + hash += tmp; + hash *= M; + hash ^= hash >> R; + } + + if (pw_len & 3) + { + const u32 tmp = w[j]; + + hash += tmp; + hash *= M; + hash ^= hash >> R; + } + + hash *= M; + hash ^= hash >> 10; + hash *= M; + hash ^= hash >> 17; + + #undef M + #undef R + + return hash; +} + +KERNEL_FQ void m25700_m04 (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * seed + */ + + const u32 seed = salt_bufs[SALT_POS].salt_buf[0]; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + u32x w[16] = { 0 }; + + const u32x out_len = apply_rules_vect_optimized (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w + 0, w + 4); + + u32x hash = MurmurHash (seed, w, out_len); + + const u32x r0 = hash; + const u32x r1 = 0; + const u32x r2 = 0; + const u32x r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m25700_m08 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m25700_m16 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m25700_s04 (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R0], + 0, + 0, + 0 + }; + + /** + * seed + */ + + const u32 seed = salt_bufs[SALT_POS].salt_buf[0]; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + u32x w[16] = { 0 }; + + const u32x out_len = apply_rules_vect_optimized (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w + 0, w + 4); + + u32x hash = MurmurHash (seed, w, out_len); + + const u32x r0 = hash; + const u32x r1 = 0; + const u32x r2 = 0; + const u32x r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m25700_s08 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m25700_s16 (KERN_ATTR_RULES ()) +{ +} diff --git a/OpenCL/m25700_a1-optimized.cl b/OpenCL/m25700_a1-optimized.cl new file mode 100644 index 000000000..2d83f0cad --- /dev/null +++ b/OpenCL/m25700_a1-optimized.cl @@ -0,0 +1,310 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//too much register pressure +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_platform.cl" +#include "inc_common.cl" +#include "inc_simd.cl" +#endif + +DECLSPEC u32 MurmurHash (const u32 seed, const u32 *w, const int pw_len) +{ + u32 hash = seed; + + #define M 0x7fd652ad + #define R 16 + + hash += 0xdeadbeef; + + int i; + int j; + + for (i = 0, j = 0; i < pw_len - 3; i += 4, j += 1) + { + const u32 tmp = w[j]; + + hash += tmp; + hash *= M; + hash ^= hash >> R; + } + + if (pw_len & 3) + { + const u32 tmp = w[j]; + + hash += tmp; + hash *= M; + hash ^= hash >> R; + } + + hash *= M; + hash ^= hash >> 10; + hash *= M; + hash ^= hash >> 17; + + #undef M + #undef R + + return hash; +} + +KERNEL_FQ void m25700_m04 (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + + if (gid >= gid_max) return; + + /** + * base + */ + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_l_len = pws[gid].pw_len & 63; + + /** + * seed + */ + + const u32 seed = salt_bufs[SALT_POS].salt_buf[0]; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32 pw_r_len = pwlenx_create_combt (combs_buf, il_pos) & 63; + + const u32 pw_len = (pw_l_len + pw_r_len) & 63; + + /** + * concat password candidate + */ + + u32 wordl0[4] = { 0 }; + u32 wordl1[4] = { 0 }; + u32 wordl2[4] = { 0 }; + u32 wordl3[4] = { 0 }; + + wordl0[0] = pw_buf0[0]; + wordl0[1] = pw_buf0[1]; + wordl0[2] = pw_buf0[2]; + wordl0[3] = pw_buf0[3]; + wordl1[0] = pw_buf1[0]; + wordl1[1] = pw_buf1[1]; + wordl1[2] = pw_buf1[2]; + wordl1[3] = pw_buf1[3]; + + u32 wordr0[4] = { 0 }; + u32 wordr1[4] = { 0 }; + u32 wordr2[4] = { 0 }; + u32 wordr3[4] = { 0 }; + + wordr0[0] = ix_create_combt (combs_buf, il_pos, 0); + wordr0[1] = ix_create_combt (combs_buf, il_pos, 1); + wordr0[2] = ix_create_combt (combs_buf, il_pos, 2); + wordr0[3] = ix_create_combt (combs_buf, il_pos, 3); + wordr1[0] = ix_create_combt (combs_buf, il_pos, 4); + wordr1[1] = ix_create_combt (combs_buf, il_pos, 5); + wordr1[2] = ix_create_combt (combs_buf, il_pos, 6); + wordr1[3] = ix_create_combt (combs_buf, il_pos, 7); + + if (combs_mode == COMBINATOR_MODE_BASE_LEFT) + { + switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len); + } + else + { + switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len); + } + + u32 w[16]; + + w[ 0] = wordl0[0] | wordr0[0]; + w[ 1] = wordl0[1] | wordr0[1]; + w[ 2] = wordl0[2] | wordr0[2]; + w[ 3] = wordl0[3] | wordr0[3]; + w[ 4] = wordl1[0] | wordr1[0]; + w[ 5] = wordl1[1] | wordr1[1]; + w[ 6] = wordl1[2] | wordr1[2]; + w[ 7] = wordl1[3] | wordr1[3]; + w[ 8] = wordl2[0] | wordr2[0]; + w[ 9] = wordl2[1] | wordr2[1]; + w[10] = wordl2[2] | wordr2[2]; + w[11] = wordl2[3] | wordr2[3]; + w[12] = wordl3[0] | wordr3[0]; + w[13] = wordl3[1] | wordr3[1]; + w[14] = wordl3[2] | wordr3[2]; + w[15] = wordl3[3] | wordr3[3]; + + const u32 r = MurmurHash (seed, w, pw_len); + + const u32 z = 0; + + COMPARE_M_SIMD (r, z, z, z); + } +} + +KERNEL_FQ void m25700_m08 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m25700_m16 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m25700_s04 (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + + if (gid >= gid_max) return; + + /** + * base + */ + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_l_len = pws[gid].pw_len & 63; + + /** + * seed + */ + + const u32 seed = salt_bufs[SALT_POS].salt_buf[0]; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R0], + 0, + 0, + 0 + }; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32 pw_r_len = pwlenx_create_combt (combs_buf, il_pos) & 63; + + const u32 pw_len = (pw_l_len + pw_r_len) & 63; + + /** + * concat password candidate + */ + + u32 wordl0[4] = { 0 }; + u32 wordl1[4] = { 0 }; + u32 wordl2[4] = { 0 }; + u32 wordl3[4] = { 0 }; + + wordl0[0] = pw_buf0[0]; + wordl0[1] = pw_buf0[1]; + wordl0[2] = pw_buf0[2]; + wordl0[3] = pw_buf0[3]; + wordl1[0] = pw_buf1[0]; + wordl1[1] = pw_buf1[1]; + wordl1[2] = pw_buf1[2]; + wordl1[3] = pw_buf1[3]; + + u32 wordr0[4] = { 0 }; + u32 wordr1[4] = { 0 }; + u32 wordr2[4] = { 0 }; + u32 wordr3[4] = { 0 }; + + wordr0[0] = ix_create_combt (combs_buf, il_pos, 0); + wordr0[1] = ix_create_combt (combs_buf, il_pos, 1); + wordr0[2] = ix_create_combt (combs_buf, il_pos, 2); + wordr0[3] = ix_create_combt (combs_buf, il_pos, 3); + wordr1[0] = ix_create_combt (combs_buf, il_pos, 4); + wordr1[1] = ix_create_combt (combs_buf, il_pos, 5); + wordr1[2] = ix_create_combt (combs_buf, il_pos, 6); + wordr1[3] = ix_create_combt (combs_buf, il_pos, 7); + + if (combs_mode == COMBINATOR_MODE_BASE_LEFT) + { + switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len); + } + else + { + switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len); + } + + u32 w[16]; + + w[ 0] = wordl0[0] | wordr0[0]; + w[ 1] = wordl0[1] | wordr0[1]; + w[ 2] = wordl0[2] | wordr0[2]; + w[ 3] = wordl0[3] | wordr0[3]; + w[ 4] = wordl1[0] | wordr1[0]; + w[ 5] = wordl1[1] | wordr1[1]; + w[ 6] = wordl1[2] | wordr1[2]; + w[ 7] = wordl1[3] | wordr1[3]; + w[ 8] = wordl2[0] | wordr2[0]; + w[ 9] = wordl2[1] | wordr2[1]; + w[10] = wordl2[2] | wordr2[2]; + w[11] = wordl2[3] | wordr2[3]; + w[12] = wordl3[0] | wordr3[0]; + w[13] = wordl3[1] | wordr3[1]; + w[14] = wordl3[2] | wordr3[2]; + w[15] = wordl3[3] | wordr3[3]; + + const u32 r = MurmurHash (seed, w, pw_len); + + const u32 z = 0; + + COMPARE_S_SIMD (r, z, z, z); + } +} + +KERNEL_FQ void m25700_s08 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m25700_s16 (KERN_ATTR_BASIC ()) +{ +} diff --git a/OpenCL/m25700_a3-optimized.cl b/OpenCL/m25700_a3-optimized.cl new file mode 100644 index 000000000..2cc5455ee --- /dev/null +++ b/OpenCL/m25700_a3-optimized.cl @@ -0,0 +1,392 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_platform.cl" +#include "inc_common.cl" +#include "inc_simd.cl" +#include "inc_hash_md5.cl" +#endif + +DECLSPEC u32x MurmurHash_w0 (const u32 seed, const u32x w0, const u32 *w, const int pw_len) +{ + u32x hash = seed; + + #define M 0x7fd652ad + #define R 16 + + hash += 0xdeadbeef; + + u32x tmp = w0; + + if (pw_len >= 4) + { + hash += w0; + hash *= M; + hash ^= hash >> R; + + int i; + int j; + + for (i = 4, j = 1; i < pw_len - 3; i += 4, j += 1) + { + tmp = w[j]; + + hash += tmp; + hash *= M; + hash ^= hash >> R; + } + + if (pw_len & 3) + { + tmp = w[j]; + + hash += tmp; + hash *= M; + hash ^= hash >> R; + } + } + else + { + if (pw_len & 3) + { + tmp = w0; + + hash += tmp; + hash *= M; + hash ^= hash >> R; + } + } + + hash *= M; + hash ^= hash >> 10; + hash *= M; + hash ^= hash >> 17; + + #undef M + #undef R + + return hash; +} + +DECLSPEC void m25700m (const u32 *w, const u32 pw_len, KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + + /** + * seed + */ + + const u32 seed = salt_bufs[SALT_POS].salt_buf[0]; + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + const u32x hash = MurmurHash_w0 (seed, w0, w, pw_len); + + const u32x r0 = hash; + const u32x r1 = 0; + const u32x r2 = 0; + const u32x r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +DECLSPEC void m25700s (const u32 *w, const u32 pw_len, KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R0], + 0, + 0, + 0 + }; + + /** + * seed + */ + + const u32 seed = salt_bufs[SALT_POS].salt_buf[0]; + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + const u32x hash = MurmurHash_w0 (seed, w0, w, pw_len); + + const u32x r0 = hash; + const u32x r1 = 0; + const u32x r2 = 0; + const u32x r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m25700_m04 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 w[16]; + + w[ 0] = pws[gid].i[ 0]; + w[ 1] = pws[gid].i[ 1]; + w[ 2] = pws[gid].i[ 2]; + w[ 3] = pws[gid].i[ 3]; + w[ 4] = 0; + w[ 5] = 0; + w[ 6] = 0; + w[ 7] = 0; + w[ 8] = 0; + w[ 9] = 0; + w[10] = 0; + w[11] = 0; + w[12] = 0; + w[13] = 0; + w[14] = pws[gid].i[14]; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m25700m (w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, SALT_POS, loop_pos, loop_cnt, il_cnt, digests_cnt, DIGESTS_OFFSET, combs_mode, salt_repeat, pws_pos, gid_max); +} + +KERNEL_FQ void m25700_m08 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 w[16]; + + w[ 0] = pws[gid].i[ 0]; + w[ 1] = pws[gid].i[ 1]; + w[ 2] = pws[gid].i[ 2]; + w[ 3] = pws[gid].i[ 3]; + w[ 4] = pws[gid].i[ 4]; + w[ 5] = pws[gid].i[ 5]; + w[ 6] = pws[gid].i[ 6]; + w[ 7] = pws[gid].i[ 7]; + w[ 8] = 0; + w[ 9] = 0; + w[10] = 0; + w[11] = 0; + w[12] = 0; + w[13] = 0; + w[14] = pws[gid].i[14]; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m25700m (w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, SALT_POS, loop_pos, loop_cnt, il_cnt, digests_cnt, DIGESTS_OFFSET, combs_mode, salt_repeat, pws_pos, gid_max); +} + +KERNEL_FQ void m25700_m16 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 w[16]; + + w[ 0] = pws[gid].i[ 0]; + w[ 1] = pws[gid].i[ 1]; + w[ 2] = pws[gid].i[ 2]; + w[ 3] = pws[gid].i[ 3]; + w[ 4] = pws[gid].i[ 4]; + w[ 5] = pws[gid].i[ 5]; + w[ 6] = pws[gid].i[ 6]; + w[ 7] = pws[gid].i[ 7]; + w[ 8] = pws[gid].i[ 8]; + w[ 9] = pws[gid].i[ 9]; + w[10] = pws[gid].i[10]; + w[11] = pws[gid].i[11]; + w[12] = pws[gid].i[12]; + w[13] = pws[gid].i[13]; + w[14] = pws[gid].i[14]; + w[15] = pws[gid].i[15]; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m25700m (w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, SALT_POS, loop_pos, loop_cnt, il_cnt, digests_cnt, DIGESTS_OFFSET, combs_mode, salt_repeat, pws_pos, gid_max); +} + +KERNEL_FQ void m25700_s04 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 w[16]; + + w[ 0] = pws[gid].i[ 0]; + w[ 1] = pws[gid].i[ 1]; + w[ 2] = pws[gid].i[ 2]; + w[ 3] = pws[gid].i[ 3]; + w[ 4] = 0; + w[ 5] = 0; + w[ 6] = 0; + w[ 7] = 0; + w[ 8] = 0; + w[ 9] = 0; + w[10] = 0; + w[11] = 0; + w[12] = 0; + w[13] = 0; + w[14] = pws[gid].i[14]; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m25700s (w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, SALT_POS, loop_pos, loop_cnt, il_cnt, digests_cnt, DIGESTS_OFFSET, combs_mode, salt_repeat, pws_pos, gid_max); +} + +KERNEL_FQ void m25700_s08 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 w[16]; + + w[ 0] = pws[gid].i[ 0]; + w[ 1] = pws[gid].i[ 1]; + w[ 2] = pws[gid].i[ 2]; + w[ 3] = pws[gid].i[ 3]; + w[ 4] = pws[gid].i[ 4]; + w[ 5] = pws[gid].i[ 5]; + w[ 6] = pws[gid].i[ 6]; + w[ 7] = pws[gid].i[ 7]; + w[ 8] = 0; + w[ 9] = 0; + w[10] = 0; + w[11] = 0; + w[12] = 0; + w[13] = 0; + w[14] = pws[gid].i[14]; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m25700s (w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, SALT_POS, loop_pos, loop_cnt, il_cnt, digests_cnt, DIGESTS_OFFSET, combs_mode, salt_repeat, pws_pos, gid_max); +} + +KERNEL_FQ void m25700_s16 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= gid_max) return; + + u32 w[16]; + + w[ 0] = pws[gid].i[ 0]; + w[ 1] = pws[gid].i[ 1]; + w[ 2] = pws[gid].i[ 2]; + w[ 3] = pws[gid].i[ 3]; + w[ 4] = pws[gid].i[ 4]; + w[ 5] = pws[gid].i[ 5]; + w[ 6] = pws[gid].i[ 6]; + w[ 7] = pws[gid].i[ 7]; + w[ 8] = pws[gid].i[ 8]; + w[ 9] = pws[gid].i[ 9]; + w[10] = pws[gid].i[10]; + w[11] = pws[gid].i[11]; + w[12] = pws[gid].i[12]; + w[13] = pws[gid].i[13]; + w[14] = pws[gid].i[14]; + w[15] = pws[gid].i[15]; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m25700s (w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, SALT_POS, loop_pos, loop_cnt, il_cnt, digests_cnt, DIGESTS_OFFSET, combs_mode, salt_repeat, pws_pos, gid_max); +} diff --git a/docs/changes.txt b/docs/changes.txt index 67f4e257b..df91bfd2c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -6,6 +6,7 @@ - Added hash-mode: bcrypt(md5($pass)) / bcryptmd5 - Added hash-mode: Linux Kernel Crypto API (2.4) +- Added hash-mode: MurmurHash ## ## Improvements diff --git a/docs/readme.txt b/docs/readme.txt index 30fed128c..0877c422b 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -113,6 +113,7 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or - sha512($salt.utf16le($pass)) - sha512(utf16le($pass).$salt) - Ruby on Rails Restful-Authentication +- MurmurHash - HMAC-MD5 (key = $pass) - HMAC-MD5 (key = $salt) - HMAC-SHA1 (key = $pass) diff --git a/src/modules/module_25700.c b/src/modules/module_25700.c new file mode 100644 index 000000000..cc6f1f27d --- /dev/null +++ b/src/modules/module_25700.c @@ -0,0 +1,190 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH_SALTED; +static const char *HASH_NAME = "MurmurHash"; +static const u64 KERN_TYPE = 25700; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; +static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_SUGGEST_KG; +static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "b69e7687:05094309"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +u32 module_salt_max (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 u32 pw_max = 4; + + return pw_max; +} + +u32 module_salt_min (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 u32 pw_min = 4; + + return pw_min; +} + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + u32 *digest = (u32 *) digest_buf; + + token_t token; + + token.token_cnt = 2; + + token.len_min[0] = 8; + token.len_max[0] = 8; + token.sep[0] = hashconfig->separator; + token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + token.len_min[1] = 8; + token.len_max[1] = 8; + token.sep[1] = hashconfig->separator; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + // digest + + const u8 *hash_pos = token.buf[0]; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[0]); + digest[1] = 0; + digest[2] = 0; + digest[3] = 0; + + digest[0] = byte_swap_32 (digest[0]); + + // salt + + const u8 *salt_pos = token.buf[1]; + const int salt_len = token.len[1]; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[0]); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + + salt->salt_len = salt_len / 2; // 4 + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + const int line_len = snprintf (line_buf, line_size, "%08x%c%08x", digest[0], hashconfig->separator, salt->salt_buf[0]); + + return line_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = MODULE_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hashes_count_min = MODULE_DEFAULT; + module_ctx->module_hashes_count_max = MODULE_DEFAULT; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_size = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_init = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_term = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = module_salt_max; + module_ctx->module_salt_min = module_salt_min; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/tools/test_modules/m25700.pm b/tools/test_modules/m25700.pm new file mode 100644 index 000000000..d5c2e2424 --- /dev/null +++ b/tools/test_modules/m25700.pm @@ -0,0 +1,148 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +sub module_constraints { [[0, 256], [8, 8], [0, 55], [8, 8], [-1, -1]] } + +sub MurmurHash +{ + use integer; + + my $word = shift; + my $seed = shift; + + # https://tanjent.livejournal.com/756623.html + + my $m = 0x7fd652ad; + my $r = 16; + + my $hash = $seed; + + $hash += 0xdeadbeef; + + my @chars = unpack ("c*", $word); + + my $len = length $word; + + my $i; + + for ($i = 0; $i < $len - 3; $i += 4) + { + my $c0 = $chars[$i + 0]; + my $c1 = $chars[$i + 1]; + my $c2 = $chars[$i + 2]; + my $c3 = $chars[$i + 3]; + + my $l = ($c0 << 0) + | ($c1 << 8) + | ($c2 << 16) + | ($c3 << 24); + + $hash += $l; + $hash *= $m; + $hash ^= ($hash & 0xffffffff) >> $r; + } + + my $rem = $len & 3; + + if ($rem == 3) + { + my $c0 = $chars[$i + 0]; + my $c1 = $chars[$i + 1]; + my $c2 = $chars[$i + 2]; + my $c3 = 0; + + my $l = ($c0 << 0) + | ($c1 << 8) + | ($c2 << 16) + | ($c3 << 24); + + $hash += $l; + $hash *= $m; + $hash ^= ($hash & 0xffffffff) >> $r; + } + elsif ($rem == 2) + { + my $c0 = $chars[$i + 0]; + my $c1 = $chars[$i + 1]; + my $c2 = 0; + my $c3 = 0; + + my $l = ($c0 << 0) + | ($c1 << 8) + | ($c2 << 16) + | ($c3 << 24); + + $hash += $l; + $hash *= $m; + $hash ^= ($hash & 0xffffffff) >> $r; + } + elsif ($rem == 1) + { + my $c0 = $chars[$i + 0]; + my $c1 = 0; + my $c2 = 0; + my $c3 = 0; + + my $l = ($c0 << 0) + | ($c1 << 8) + | ($c2 << 16) + | ($c3 << 24); + + $hash += $l; + $hash *= $m; + $hash ^= ($hash & 0xffffffff) >> $r; + } + + $hash *= $m; + $hash ^= ($hash & 0xffffffff) >> 10; + $hash *= $m; + $hash ^= ($hash & 0xffffffff) >> 17; + + return $hash & 0xffffffff; +} + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $salt_bin = pack ("H*", $salt); + + my $seed = unpack ("N", $salt_bin); # or maybe "L" ? not enought example data to clarify + + my $digest = MurmurHash ($word, $seed); + + my $hash = sprintf ("%08x:%08x", $digest, $seed); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $salt, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $word; + return unless defined $salt; + + return unless length $hash == 8; + return unless length $salt == 8; + + my $word_packed = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word_packed, $salt); + + return ($new_hash, $word); +} + +1; +