From 4870a4b24722664eab4ca235b03da35aeedebce2 Mon Sep 17 00:00:00 2001 From: philsmd Date: Sat, 11 Jun 2022 11:27:25 +0200 Subject: [PATCH] fixes vector bug in -m 27800 = MurmurHash 3 with -a 3 --- OpenCL/m27800_a0-optimized.cl | 28 +++++++++------- OpenCL/m27800_a1-optimized.cl | 28 +++++++++------- OpenCL/m27800_a3-optimized.cl | 60 ++++++++++++++++++++--------------- docs/changes.txt | 3 +- 4 files changed, 70 insertions(+), 49 deletions(-) diff --git a/OpenCL/m27800_a0-optimized.cl b/OpenCL/m27800_a0-optimized.cl index 1d36d02ab..2286664ab 100644 --- a/OpenCL/m27800_a0-optimized.cl +++ b/OpenCL/m27800_a0-optimized.cl @@ -15,22 +15,25 @@ #include M2S(INCLUDE_PATH/inc_simd.cl) #endif -DECLSPEC u32 Murmur32_Scramble(u32 k) +DECLSPEC u32 Murmur32_Scramble (u32 k) { k = (k * 0x16A88000) | ((k * 0xCC9E2D51) >> 17); + return (k * 0x1B873593); } -DECLSPEC u32 MurmurHash3(const u32 seed, PRIVATE_AS const u32 *data, const u32 size) +DECLSPEC u32 MurmurHash3 (const u32 seed, PRIVATE_AS const u32 *data, const u32 size) { u32 checksum = seed; const u32 nBlocks = (size / 4); - if (size >= 4) //Hash blocks, sizes of 4 + + if (size >= 4) // Hash blocks, sizes of 4 { for (u32 i = 0; i < nBlocks; i++) { - checksum ^= Murmur32_Scramble(data[i]); + checksum ^= Murmur32_Scramble (data[i]); + checksum = (checksum >> 19) | (checksum << 13); //rotateRight(checksum, 19) checksum = (checksum * 5) + 0xE6546B64; } @@ -38,21 +41,23 @@ DECLSPEC u32 MurmurHash3(const u32 seed, PRIVATE_AS const u32 *data, const u32 s if (size % 4) { - PRIVATE_AS const u8 *remainder = (PRIVATE_AS u8 *)(data + nBlocks); + const u32 remainder = data[nBlocks]; + u32 val = 0; - switch(size & 3) //Hash remaining bytes as size isn't always aligned by 4 + switch (size & 3) //Hash remaining bytes as size isn't always aligned by 4 { case 3: - val ^= (remainder[2] << 16); + val ^= remainder & 0x00ff0000; case 2: - val ^= (remainder[1] << 8); + val ^= remainder & 0x0000ff00; case 1: - val ^= remainder[0]; - checksum ^= Murmur32_Scramble(val); + val ^= remainder & 0x000000ff; + + checksum ^= Murmur32_Scramble (val); default: break; - }; + } } checksum ^= size; @@ -60,6 +65,7 @@ DECLSPEC u32 MurmurHash3(const u32 seed, PRIVATE_AS const u32 *data, const u32 s checksum *= 0x85EBCA6B; checksum ^= checksum >> 13; checksum *= 0xC2B2AE35; + return checksum ^ (checksum >> 16); } diff --git a/OpenCL/m27800_a1-optimized.cl b/OpenCL/m27800_a1-optimized.cl index 877560560..cf6240bf2 100644 --- a/OpenCL/m27800_a1-optimized.cl +++ b/OpenCL/m27800_a1-optimized.cl @@ -13,22 +13,25 @@ #include M2S(INCLUDE_PATH/inc_simd.cl) #endif -DECLSPEC u32 Murmur32_Scramble(u32 k) +DECLSPEC u32 Murmur32_Scramble (u32 k) { k = (k * 0x16A88000) | ((k * 0xCC9E2D51) >> 17); + return (k * 0x1B873593); } -DECLSPEC u32 MurmurHash3(const u32 seed, PRIVATE_AS const u32 *data, const u32 size) +DECLSPEC u32 MurmurHash3 (const u32 seed, PRIVATE_AS const u32 *data, const u32 size) { u32 checksum = seed; const u32 nBlocks = (size / 4); - if (size >= 4) //Hash blocks, sizes of 4 + + if (size >= 4) // Hash blocks, sizes of 4 { for (u32 i = 0; i < nBlocks; i++) { - checksum ^= Murmur32_Scramble(data[i]); + checksum ^= Murmur32_Scramble (data[i]); + checksum = (checksum >> 19) | (checksum << 13); //rotateRight(checksum, 19) checksum = (checksum * 5) + 0xE6546B64; } @@ -36,21 +39,23 @@ DECLSPEC u32 MurmurHash3(const u32 seed, PRIVATE_AS const u32 *data, const u32 s if (size % 4) { - PRIVATE_AS const u8 *remainder = (PRIVATE_AS u8 *)(data + nBlocks); + const u32 remainder = data[nBlocks]; + u32 val = 0; - switch(size & 3) //Hash remaining bytes as size isn't always aligned by 4 + switch (size & 3) //Hash remaining bytes as size isn't always aligned by 4 { case 3: - val ^= (remainder[2] << 16); + val ^= remainder & 0x00ff0000; case 2: - val ^= (remainder[1] << 8); + val ^= remainder & 0x0000ff00; case 1: - val ^= remainder[0]; - checksum ^= Murmur32_Scramble(val); + val ^= remainder & 0x000000ff; + + checksum ^= Murmur32_Scramble (val); default: break; - }; + } } checksum ^= size; @@ -58,6 +63,7 @@ DECLSPEC u32 MurmurHash3(const u32 seed, PRIVATE_AS const u32 *data, const u32 s checksum *= 0x85EBCA6B; checksum ^= checksum >> 13; checksum *= 0xC2B2AE35; + return checksum ^ (checksum >> 16); } diff --git a/OpenCL/m27800_a3-optimized.cl b/OpenCL/m27800_a3-optimized.cl index 54cafd6e3..3f6f71861 100644 --- a/OpenCL/m27800_a3-optimized.cl +++ b/OpenCL/m27800_a3-optimized.cl @@ -13,72 +13,79 @@ #include M2S(INCLUDE_PATH/inc_simd.cl) #endif -DECLSPEC u32x Murmur32_Scramble(u32x k) +DECLSPEC u32x Murmur32_Scramble (u32x k) { k = (k * 0x16A88000) | ((k * 0xCC9E2D51) >> 17); + return (k * 0x1B873593); } -DECLSPEC u32x MurmurHash3(const u32 seed, const u32x w0, PRIVATE_AS const u32 *data, const u32 size) +DECLSPEC u32x MurmurHash3 (const u32 seed, const u32x w0, PRIVATE_AS const u32 *data, const u32 size) { u32x checksum = seed; - if (size >= 4) + if (size >= 4) // Hash blocks, sizes of 4 { - checksum ^= Murmur32_Scramble(w0); + checksum ^= Murmur32_Scramble (w0); + checksum = (checksum >> 19) | (checksum << 13); //rotateRight(checksum, 19) checksum = (checksum * 5) + 0xE6546B64; const u32 nBlocks = (size / 4); - if (size >= 4) //Hash blocks, sizes of 4 + + // if (size >= 4) // size didn't change, why should we check it again ? + // { + for (u32 i = 1; i < nBlocks; i++) { - for (u32 i = 1; i < nBlocks; i++) - { - checksum ^= Murmur32_Scramble(data[i]); - checksum = (checksum >> 19) | (checksum << 13); //rotateRight(checksum, 19) - checksum = (checksum * 5) + 0xE6546B64; - } + checksum ^= Murmur32_Scramble (data[i]); + + checksum = (checksum >> 19) | (checksum << 13); //rotateRight(checksum, 19) + checksum = (checksum * 5) + 0xE6546B64; } + //} if (size % 4) { - PRIVATE_AS const u8 *remainder = (PRIVATE_AS u8 *)(data + nBlocks); + const u32x remainder = data[nBlocks]; + u32x val = 0; - switch(size & 3) //Hash remaining bytes as size isn't always aligned by 4 + switch (size & 3) //Hash remaining bytes as size isn't always aligned by 4 { case 3: - val ^= (remainder[2] << 16); + val ^= remainder & 0x00ff0000; case 2: - val ^= (remainder[1] << 8); + val ^= remainder & 0x0000ff00; case 1: - val ^= remainder[0]; - checksum ^= Murmur32_Scramble(val); + val ^= remainder & 0x000000ff; + + checksum ^= Murmur32_Scramble (val); default: break; - }; + } } } - else { if (size % 4) { - PRIVATE_AS const u8 *remainder = (PRIVATE_AS u8 *)(&w0); + const u32x remainder = w0; + u32x val = 0; - switch(size & 3) + switch (size & 3) { case 3: - val ^= (remainder[2] << 16); + val ^= remainder & 0x00ff0000; case 2: - val ^= (remainder[1] << 8); + val ^= remainder & 0x0000ff00; case 1: - val ^= remainder[0]; - checksum ^= Murmur32_Scramble(val); + val ^= remainder & 0x000000ff; + + checksum ^= Murmur32_Scramble (val); default: break; - }; + } } } @@ -87,6 +94,7 @@ DECLSPEC u32x MurmurHash3(const u32 seed, const u32x w0, PRIVATE_AS const u32 *d checksum *= 0x85EBCA6B; checksum ^= checksum >> 13; checksum *= 0xC2B2AE35; + return checksum ^ (checksum >> 16); } diff --git a/docs/changes.txt b/docs/changes.txt index 9c2f22d38..37efafbc0 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -44,9 +44,10 @@ - Fixed display problem of incorrect negative values in case of large numbers - Fixed display problem of the "Optimizers applied" list for algorithms using Register-Limit - Fixed example password output of --hash-info: force uppercase if OPTS_TYPE_PT_UPPER is set -- Fixed false negative on hash-types 4510 and 4710 for hashes with long salts - Fixed false negative on Unit Test in case of out-of-memory with grep in single mode - Fixed false negative on Unit Test with hash-type 25400 +- Fixed false negative on hash-type 27800 if using vector width greater than 1 and -a 3 +- Fixed false negative on hash-types 4510 and 4710 for hashes with long salts - Fixed false negative on hash-types 8900, 15700, 22700, 27700 and 28200 if using the HIP backend - Fixed functional error when nonce-error-corrections that were set on the command line in hash-mode 22000/22001 were not accepted - Fixed handling of devices in benchmark mode for "kernel build error". Instead of canceling, skip the device and move on to the next