From fff0b5ade274c1102e1c91b3ea8e4f2fff298efb Mon Sep 17 00:00:00 2001 From: qasikfwn <51647241+qasikfwn@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:15:33 +1100 Subject: [PATCH] Create mode for murmurhash64a with zero seed --- OpenCL/m90010_a0-optimized.cl | 249 ++++++++++++++++++ OpenCL/m90010_a1-optimized.cl | 364 ++++++++++++++++++++++++++ OpenCL/m90010_a3-optimized.cl | 472 ++++++++++++++++++++++++++++++++++ src/modules/module_90010.c | 174 +++++++++++++ tools/test_modules/m90010.pm | 152 +++++++++++ 5 files changed, 1411 insertions(+) create mode 100644 OpenCL/m90010_a0-optimized.cl create mode 100644 OpenCL/m90010_a1-optimized.cl create mode 100644 OpenCL/m90010_a3-optimized.cl create mode 100644 src/modules/module_90010.c create mode 100644 tools/test_modules/m90010.pm diff --git a/OpenCL/m90010_a0-optimized.cl b/OpenCL/m90010_a0-optimized.cl new file mode 100644 index 000000000..5b1768733 --- /dev/null +++ b/OpenCL/m90010_a0-optimized.cl @@ -0,0 +1,249 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp_optimized.h) +#include M2S(INCLUDE_PATH/inc_rp_optimized.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#endif + +DECLSPEC u64 MurmurHash64A_round (PRIVATE_AS const u8 *data, u64 hash, const u32 cur_pos) { + #define M 0xc6a4a7935bd1e995 + #define R 47 + + u64 k = ((u64) data[cur_pos]) + | ((u64) data[cur_pos + 1] << 8) + | ((u64) data[cur_pos + 2] << 16) + | ((u64) data[cur_pos + 3] << 24) + | ((u64) data[cur_pos + 4] << 32) + | ((u64) data[cur_pos + 5] << 40) + | ((u64) data[cur_pos + 6] << 48) + | ((u64) data[cur_pos + 7] << 56); + + k *= M; + k ^= k >> R; + k *= M; + + hash ^= k; + hash *= M; + + #undef M + #undef R + + return hash; +} + +DECLSPEC u64 MurmurHash64A_final (PRIVATE_AS const u8 *data, u64 hash, const u32 cur_pos, const u32 len) { + #define M 0xc6a4a7935bd1e995 + #define R 47 + + const u32 overflow = len & 7; + + switch (overflow) { + case 7: hash ^= ((u64) data[cur_pos + 6]) << 48; + case 6: hash ^= ((u64) data[cur_pos + 5]) << 40; + case 5: hash ^= ((u64) data[cur_pos + 4]) << 32; + case 4: hash ^= ((u64) data[cur_pos + 3]) << 24; + case 3: hash ^= ((u64) data[cur_pos + 2]) << 16; + case 2: hash ^= ((u64) data[cur_pos + 1]) << 8; + case 1: hash ^= ((u64) data[cur_pos]); + hash *= M; + } + + hash ^= hash >> R; + hash *= M; + hash ^= hash >> R; + + #undef M + #undef R + + return hash; +} + +DECLSPEC u64 MurmurHash64A (PRIVATE_AS const u32 *data, const u32 len) +{ + #define M 0xc6a4a7935bd1e995 + #define R 47 + + //Initialize hash + u64 hash = 0 ^ (len * M); + + //const u64 INITIAL = hash; + + const u32 endpos = len - (len & 7); + + //const u32 nBlocks = len >> 3; // number of 8 byte blocks + const u8 *data2 = (const u8*) data; + + //u64 MIDDLE_OF_BLOCK = 0; + + // Loop over blocks of 8 bytes + u32 i = 0; + while (i != endpos) { + hash = MurmurHash64A_round(data2, hash, i); + + i += 8; + } + + // Overflow + + //const u64 BEFORE_FINAL = hash; + + hash = MurmurHash64A_final (data2, hash, i, len); + + //const u64 AFTER_FINAL = hash; + + //printf("debug: %016lx:%016lx:%c%c%c%c%c%c%c%c%c%c len: %d INITIAL: %016lx MIDDLE_O_BLK: %016lx B4FINAL: %016lx overflow: %d AFTER_FINAL: %016lx\n", hash, seed, data2[0], data2[1], data2[2], data2[3], data2[4], data2[5], data2[6], data2[7], data2[8], data2[9], len, INITIAL, MIDDLE_OF_BLOCK, BEFORE_FINAL, overflow, AFTER_FINAL); + //printf("data2 = %.2s, len = %d\n", data2[0], len); + + #undef M + #undef R + + return hash; +} + + + +KERNEL_FQ void m90000_m04 (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) 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 + */ + + /** + * 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); + + u64x hash = MurmurHash64A (w, out_len); + + const u32x r0 = l32_from_64(hash); + const u32x r1 = h32_from_64(hash); + const u32x z = 0; + + COMPARE_M_SIMD (r0, r1, z, z); + } +} + +KERNEL_FQ void m90000_m08 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m90000_m16 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m90000_s04 (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) 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_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + 0, + 0 + }; + + /** + * seed + */ + + /** + * 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); + + u64x hash = MurmurHash64A (w, out_len); + + const u32x r0 = l32_from_64(hash); + const u32x r1 = h32_from_64(hash); + const u32x z = 0; + + COMPARE_S_SIMD (r0, r1, z, z); + } +} + +KERNEL_FQ void m90000_s08 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m90000_s16 (KERN_ATTR_RULES ()) +{ +} diff --git a/OpenCL/m90010_a1-optimized.cl b/OpenCL/m90010_a1-optimized.cl new file mode 100644 index 000000000..788145981 --- /dev/null +++ b/OpenCL/m90010_a1-optimized.cl @@ -0,0 +1,364 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//too much register pressure +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#endif + +DECLSPEC u64 MurmurHash64A_round (PRIVATE_AS const u8 *data, u64 hash, const u32 cur_pos) { + #define M 0xc6a4a7935bd1e995 + #define R 47 + + u64 k = ((u64) data[cur_pos]) + | ((u64) data[cur_pos + 1] << 8) + | ((u64) data[cur_pos + 2] << 16) + | ((u64) data[cur_pos + 3] << 24) + | ((u64) data[cur_pos + 4] << 32) + | ((u64) data[cur_pos + 5] << 40) + | ((u64) data[cur_pos + 6] << 48) + | ((u64) data[cur_pos + 7] << 56); + + k *= M; + k ^= k >> R; + k *= M; + + hash ^= k; + hash *= M; + + #undef M + #undef R + + return hash; +} + +DECLSPEC u64 MurmurHash64A_final (PRIVATE_AS const u8 *data, u64 hash, const u32 cur_pos, const u32 len) { + #define M 0xc6a4a7935bd1e995 + #define R 47 + + const u32 overflow = len & 7; + + switch (overflow) { + case 7: hash ^= ((u64) data[cur_pos + 6]) << 48; + case 6: hash ^= ((u64) data[cur_pos + 5]) << 40; + case 5: hash ^= ((u64) data[cur_pos + 4]) << 32; + case 4: hash ^= ((u64) data[cur_pos + 3]) << 24; + case 3: hash ^= ((u64) data[cur_pos + 2]) << 16; + case 2: hash ^= ((u64) data[cur_pos + 1]) << 8; + case 1: hash ^= ((u64) data[cur_pos]); + hash *= M; + } + + hash ^= hash >> R; + hash *= M; + hash ^= hash >> R; + + #undef M + #undef R + + return hash; +} + +DECLSPEC u64 MurmurHash64A (PRIVATE_AS const u32 *data, const u32 len) +{ + #define M 0xc6a4a7935bd1e995 + #define R 47 + + //Initialize hash + u64 hash = 0 ^ (len * M); + + //const u64 INITIAL = hash; + + const u32 endpos = len - (len & 7); + + //const u32 nBlocks = len >> 3; // number of 8 byte blocks + const u8 *data2 = (const u8*) data; + + //u64 MIDDLE_OF_BLOCK = 0; + + // Loop over blocks of 8 bytes + u32 i = 0; + while (i != endpos) { + hash = MurmurHash64A_round(data2, hash, i); + + i += 8; + } + + // Overflow + + //const u64 BEFORE_FINAL = hash; + + hash = MurmurHash64A_final (data2, hash, i, len); + + //const u64 AFTER_FINAL = hash; + + //printf("debug: %016lx:%016lx:%c%c%c%c%c%c%c%c%c%c len: %d INITIAL: %016lx MIDDLE_O_BLK: %016lx B4FINAL: %016lx overflow: %d AFTER_FINAL: %016lx\n", hash, seed, data2[0], data2[1], data2[2], data2[3], data2[4], data2[5], data2[6], data2[7], data2[8], data2[9], len, INITIAL, MIDDLE_OF_BLOCK, BEFORE_FINAL, overflow, AFTER_FINAL); + //printf("data2 = %.2s, len = %d\n", data2[0], len); + + #undef M + #undef R + + return hash; +} + +KERNEL_FQ void m90000_m04 (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + + if (gid >= GID_CNT) 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 + */ + + /** + * 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]; + + u64x hash = MurmurHash64A (w, pw_len); + + const u32x r0 = l32_from_64(hash); + const u32x r1 = h32_from_64(hash); + const u32x z = 0; + + COMPARE_M_SIMD (r0, r1, z, z); + } +} + +KERNEL_FQ void m90000_m08 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m90000_m16 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m90000_s04 (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + + if (gid >= GID_CNT) 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 + */ + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + 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]; + + u64 hash = MurmurHash64A (w, pw_len); + + const u32 r0 = l32_from_64(hash); + const u32 r1 = h32_from_64(hash); + const u32 z = 0; + + COMPARE_S_SIMD (r0, r1, z, z); + } +} + +KERNEL_FQ void m90000_s08 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m90000_s16 (KERN_ATTR_BASIC ()) +{ +} diff --git a/OpenCL/m90010_a3-optimized.cl b/OpenCL/m90010_a3-optimized.cl new file mode 100644 index 000000000..92ff3edaa --- /dev/null +++ b/OpenCL/m90010_a3-optimized.cl @@ -0,0 +1,472 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#endif + + +DECLSPEC u64x MurmurHash64A (PRIVATE_AS const u32x *data, const u32 len) +{ + #define M 0xc6a4a7935bd1e995 + #define R 47 + + //Initialize hash + u64x hash = 0 ^ (len * M); + + //printf("INITIAL = %08x%08x\n", h32_from_64(hash), l32_from_64(hash)); + + const u32 endpos = len - (len & 7); + + const u8 *data2 = (const u8*) data; + + //printf("seed = %08x%08x\n", h32_from_64(seed), l32_from_64(seed)); + //printf("data2 = %c%c%c%c%c%c%c%c\n", data2[0], data2[1], data2[2], data2[3], data2[4], data2[5], data2[6], data2[7]); + //printf("len = %d\n", len); + + + // Loop over blocks of 8 bytes + u32 i = 0; + while (i != endpos) { + u64x k = ((u64) data2[i]) + | ((u64) data2[i + 1] << 8) + | ((u64) data2[i + 2] << 16) + | ((u64) data2[i + 3] << 24) + | ((u64) data2[i + 4] << 32) + | ((u64) data2[i + 5] << 40) + | ((u64) data2[i + 6] << 48) + | ((u64) data2[i + 7] << 56); + + k *= M; + k ^= k >> R; + k *= M; + + hash ^= k; + hash *= M; + + i += 8; + } + //printf("BEFORE_OVERFLOW = %08x%08x\n", h32_from_64(hash), l32_from_64(hash)); + + // Overflow + + const u32 overflow = len & 7; + + //printf("OVERFLOW = %d\n", overflow); + + switch (overflow) { + case 7: hash ^= ((u64) data2[i + 6]) << 48; + case 6: hash ^= ((u64) data2[i + 5]) << 40; + case 5: hash ^= ((u64) data2[i + 4]) << 32; + case 4: hash ^= ((u64) data2[i + 3]) << 24; + case 3: hash ^= ((u64) data2[i + 2]) << 16; + case 2: hash ^= ((u64) data2[i + 1]) << 8; + case 1: hash ^= ((u64) data2[i]); + hash *= M; + } + + //printf("AFTER_OVERFLOW = %08x%08x\n", h32_from_64(hash), l32_from_64(hash)); + + hash ^= hash >> R; + hash *= M; + hash ^= hash >> R; + + #undef M + #undef R + + //printf("hash = %08x%08x\n", h32_from_64(hash), l32_from_64(hash)); + + return hash; +} + +DECLSPEC void m90000m (PRIVATE_AS const u32 *data, const u32 pw_len, KERN_ATTR_FUNC_VECTOR ()) +{ + /** + * modifiers are taken from args + */ + + /** + * seed + */ + + /** + * base + */ + + u32x w[16]; + + w[ 0] = data[ 0]; + w[ 1] = data[ 1]; + w[ 2] = data[ 2]; + w[ 3] = data[ 3]; + w[ 4] = data[ 4]; + w[ 5] = data[ 5]; + w[ 6] = data[ 6]; + w[ 7] = data[ 7]; + w[ 8] = data[ 8]; + w[ 9] = data[ 9]; + w[10] = data[10]; + w[11] = data[11]; + w[12] = data[12]; + w[13] = data[13]; + w[14] = data[14]; + w[15] = data[15]; + + //const u8 *data2 = (const u8*) data; + //printf("w = %c%c%c%c%c%c%c%c\n", data2[0], data2[1], data2[2], data2[3], data2[4], data2[5], data2[6], data2[7]); + + /** + * loop + */ + + u32x 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; + + w[0] = w0; + + //printf("seed = %08x%08x\n", seed_hi, seed_lo); + + const u64x hash = MurmurHash64A (w, pw_len); + + const u32x r0 = l32_from_64(hash); + const u32x r1 = h32_from_64(hash); + const u32x z = 0; + + //printf("hash = %08x%08x\n", r1, r0); + + COMPARE_M_SIMD (r0, r1, z, z); + } +} + +DECLSPEC void m90000s (PRIVATE_AS const u32 *data, const u32 pw_len, KERN_ATTR_FUNC_VECTOR ()) +{ + /** + * modifiers are taken from args + */ + + /** + * digest + */ + + //printf("Hello world m90000s\n"); + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + 0, + 0 + }; + + /** + * seed + */ + + /** + * base + */ + + u32x w[16]; + + w[ 0] = data[ 0]; + w[ 1] = data[ 1]; + w[ 2] = data[ 2]; + w[ 3] = data[ 3]; + w[ 4] = data[ 4]; + w[ 5] = data[ 5]; + w[ 6] = data[ 6]; + w[ 7] = data[ 7]; + w[ 8] = data[ 8]; + w[ 9] = data[ 9]; + w[10] = data[10]; + w[11] = data[11]; + w[12] = data[12]; + w[13] = data[13]; + w[14] = data[14]; + w[15] = data[15]; + + /** + * loop + */ + + u32x 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; + + w[0] = w0; + + const u64x hash = MurmurHash64A (w, pw_len); + + const u32x r0 = l32_from_64(hash); + const u32x r1 = h32_from_64(hash); + const u32x z = 0; + + //printf("r1 = %08x r0 = %08x\n", r1, r0); + //printf("hash = %08x%08x\n", r1, r0); + + COMPARE_S_SIMD (r0, r1, z, z); + } +} + +KERNEL_FQ void m90000_m04 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + //printf("Hello world m90000_m04\n"); + + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) 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] = 0; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + //printf("pws[gid].pw_len = %d\n", pws[gid].pw_len); + + /** + * main + */ + + m90000m (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, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m90000_m08 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + //printf("Hello world m90000_m08\n"); + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) 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] = 0; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m90000m (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, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m90000_m16 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) 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 + */ + + m90000m (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, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m90000_s04 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) 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] = 0; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m90000s (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, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m90000_s08 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) 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] = 0; + w[15] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m90000s (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, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m90000_s16 (KERN_ATTR_VECTOR ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) 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 + */ + + m90000s (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, kernel_param, gid, lid, lsz); +} diff --git a/src/modules/module_90010.c b/src/modules/module_90010.c new file mode 100644 index 000000000..953a722e9 --- /dev/null +++ b/src/modules/module_90010.c @@ -0,0 +1,174 @@ +/** + * 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_8_2; +static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH; +static const char *HASH_NAME = "MurmurHash64A Zero Seed"; +static const u64 KERN_TYPE = 90010; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE + | OPTI_TYPE_USES_BITS_64; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_SUGGEST_KG; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "73f8142b4326d36a"; + +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; } + +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) +{ + u64 *digest = (u64 *) digest_buf; + + hc_token_t token; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 1; + + token.len[0] = 16; + token.attr[0] = TOKEN_ATTR_FIXED_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]; + // we have 16 chars (hash hex string, big endian) + + + digest[0] = ((hex_to_u64 (&hash_pos[0]))); + digest[1] = 0; + + digest[0] = byte_swap_64 (digest[0]); + + // now `digest` contains a proper little endian u64 + + 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 u64 *digest = (const u64 *) digest_buf; + + // we can not change anything in the original buffer, otherwise destroying sorting + // therefore create some local buffer + + u8 *out_buf = (u8 *) line_buf; + + const int out_len = 16; + + u64_to_hex (byte_swap_64 (digest[0]), out_buf); + + return out_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_charset = 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_deprecated_notice = 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_extra_tuningdb_block = 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_postprocess = 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_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + 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/m90010.pm b/tools/test_modules/m90010.pm new file mode 100644 index 000000000..af5e2e581 --- /dev/null +++ b/tools/test_modules/m90010.pm @@ -0,0 +1,152 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; +use Math::BigInt; + +sub module_constraints { [[0, 256], [-1, -1], [0, 63], [-1, -1], [0, 63]] } + +sub wrapping_mul +{ + my $a = shift; + my $b = shift; + + # 2**64 + my $width = Math::BigInt->new("0x10000000000000000"); + + return ($a * $b)->bmod($width); +} + +sub murmurhash64a +{ + use integer; + + my $word = shift; + my $seed = 0; + + # https://gitlab.com/lschwiderski/vt2_bundle_unpacker/-/blob/master/src/murmur/murmurhash64.rs + # 'm' and 'r' are mixing constants generated offline. + # They're not really 'magic', they just happen to work well. + + my $m = Math::BigInt->new("0xc6a4a7935bd1e995"); + #my $m = 0xc6a4a7935bd1e995; + my $r = 47; + + my @chars = unpack ("C*", $word); + my $len = length $word; + + my $hash = $seed ^ wrapping_mul ($len, $m); + + my $endpos = $len - ($len & 7); + my $i; + + for ($i = 0; $i < $endpos; $i += 8) + { + my $c0 = $chars[$i + 0]; + my $c1 = $chars[$i + 1]; + my $c2 = $chars[$i + 2]; + my $c3 = $chars[$i + 3]; + my $c4 = $chars[$i + 4]; + my $c5 = $chars[$i + 5]; + my $c6 = $chars[$i + 6]; + my $c7 = $chars[$i + 7]; + + my $k = ($c0 << 0) + | ($c1 << 8) + | ($c2 << 16) + | ($c3 << 24) + | ($c4 << 32) + | ($c5 << 40) + | ($c6 << 48) + | ($c7 << 56); + + $k = wrapping_mul ($k, $m); + $k ^= $k >> $r; + $k = wrapping_mul ($k, $m); + + $hash ^= $k; + $hash = wrapping_mul ($hash, $m); + } + + my $overflow = $len & 7; + + if ($overflow == 7) + { + $hash ^= $chars[$i + 6] << 48; + } + if ($overflow >= 6) + { + $hash ^= $chars[$i + 5] << 40; + } + if ($overflow >= 5) + { + $hash ^= $chars[$i + 4] << 32; + } + if ($overflow >= 4) + { + $hash ^= $chars[$i + 3] << 24; + } + if ($overflow >= 3) + { + $hash ^= $chars[$i + 2] << 16; + } + if ($overflow >= 2) + { + $hash ^= $chars[$i + 1] << 8; + } + if ($overflow >= 1) + { + $hash ^= $chars[$i + 0] << 0; + } + + if ($overflow > 0) + { + $hash = wrapping_mul ($hash, $m); + } + + $hash ^= $hash >> $r; + $hash = wrapping_mul ($hash, $m); + $hash ^= $hash >> $r; + + return $hash; +} + +sub module_generate_hash +{ + my $word = shift; + + my $digest = murmurhash64a ($word); + + $digest = unpack ("H*", pack ("Q>", $digest)); + + my $hash = sprintf ("%s", $digest); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $word) = split (':', $line, 2); + + return unless defined $hash; + return unless defined $word; + + return unless length $hash == 16; + + return unless ($hash =~ m/^[0-9a-fA-F]{16}$/); + + my $word_packed = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word_packed); + + return ($new_hash, $word); +} + +1;