Skip to content

Commit

Permalink
rust fixups: bad wyhash seeds, no whirlpool 512 bits
Browse files Browse the repository at this point in the history
I couldnt make a 256 slice work
  • Loading branch information
rurban committed Sep 16, 2023
1 parent ce39090 commit 934ad1a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Hashes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,3 +1317,11 @@ void polymur_test ( const void *key, int len, uint32_t seed, void *out) {
*(uint64_t*)out = polymur_hash((const uint8_t*)key, (size_t)len, &g_polymurhashparams,
(uint64_t)seed);
}

#ifdef RUST_ENABLED
void wyhash_rs_seed_init (uint32_t &seed) {
if (wyhash_rs_badseed (seed))
seed++;
}
#endif

8 changes: 8 additions & 0 deletions Hashes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1367,3 +1367,11 @@ void khashv64_test ( const void *key, int len, uint32_t seed, void *out);
extern PolymurHashParams g_polymurhashparams;
void polymur_seed_init (size_t &seed);
void polymur_test ( const void *key, int len, uint32_t seed, void *out);

#ifdef RUST_ENABLED
// rust crate wyhash 0.5.0
static bool wyhash_rs_badseed(const uint32_t seed) {
return (0x52e45cf4 == seed || 0x9d4d660c == seed);
}
void wyhash_rs_seed_init (uint32_t &seed);
#endif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SMhasher
| [asconhashv12_64](doc/asconhashv12_64.txt) | 159.68 | 386.90 | 480.86 (4) |6490 | |
| [sha3-256](doc/sha3-256.txt) | 100.58 | 3877.18 |4159.79 (37)| | PerlinNoise |
| [sha3-256_64](doc/sha3-256_64.txt) | 100.57 | 3909.00 |4174.63 (16)| | PerlinNoise |
| [FxHash32](doc/FxHash32.txt) | 0.00 | 0.00 | 0.00 (0) | | rust, fixed seed |
| [FxHash32](doc/FxHash32.txt) | 3080.54 | 29.35 | 401.61 (2) | | rust, fixed seed |
| [FxHash64](doc/FxHash64.txt) | 0.00 | 0.00 | 0.00 (0) | | rust, fixed seed |
| [hasshe2](doc/hasshe2.txt) | 2773.89 | 64.35 | 282.30 (3) | 445 | Permutation,TwoBytes,Zeroes,Seed|
| [poly_1_mersenne](doc/poly_1_mersenne.txt) | 1369.21 | 61.59 | 248.86 (4) | 479 | fails most tests |
Expand Down
14 changes: 12 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ HashInfo g_hashes[] =
#endif
{ komihash_test, 64, 0x8157FF6D, "komihash", "komihash 5.7", GOOD, {} },
{ polymur_test, 64, 0x4F894810, "polymur", "github.com/orlp/polymur-hash v1", GOOD, {} },

#ifdef RUST_ENABLED
{ adler_rs, 32, 0x6E8E8F4D, "Adler_rs", "Adler-32 checksum implementation (used by `zlib`, crate `adler`)", GOOD, {} },
// instable verif, as the library
Expand Down Expand Up @@ -818,8 +819,9 @@ HashInfo g_hashes[] =
{ siphash24_rs, 64, 0x57B661ED, "SipHash_2-4_rs", "SipHash with 2 rounds and 4 finalization rounds (crate `siphasher`)", GOOD, {} },
{ siphash128_13_rs, 64, 0x8E66D3B7, "SipHash128_1-3_rs", "SipHash128 with 1 round and 3 finalization rounds (crate `siphasher`)", GOOD, {} },
{ siphash128_24_rs, 64, 0xA158D579, "SipHash128_2-4_rs", "SipHash128 with 2 rounds and 4 finalization rounds (crate `siphasher`)", GOOD, {} },
{ whirlpool_rs, 512, 0xF7E0FD50, "Whirlpool_rs", "Whirlpool algorithm (crate `whirlpool`)", GOOD, {} },
{ wyhash_rs, 64, 0x1196BB84, "WyHash_rs", "WyHash algorithm (crate `wyhash`)", POOR, {} },
//{ whirlpool_rs, 512, 0xF7E0FD50, "Whirlpool_rs", "Whirlpool algorithm (crate `whirlpool`)", GOOD, {} },
//{ whirlpool256_rs, 256, 0xF7E0FD50, "Whirlpool256_rs", "Whirlpool algorithm (256 bits) (crate `whirlpool`)", GOOD, {} },
{ wyhash_rs, 64, 0x1196BB84, "WyHash_rs", "WyHash 0.5.0 (crate `wyhash`)", GOOD, { 0x52e45cf4, 0x9d4d660c } },
{ xxhash3_rs, 64, 0x9A636405, "xxHash3_rs", "64-bit xxHash implementation (crate `xxhash-rust`)", POOR, {} },
{ xxhash128_rs, 128, 0x88B45661, "xxHash128_rs", "128-bit xxHash implementation (crate `xxhash-rust`)", POOR, {} },
{ xxhash32_rs, 32, 0xBA88B743, "xxHash32_rs", "32-bit xxHash implementation (crate `xxhash-rust`)", POOR, {} },
Expand Down Expand Up @@ -929,6 +931,10 @@ void Bad_Seed_init (pfHash hash, uint32_t &seed) {
else if(hash == wyhash32low)
wyhash32low_seed_init(seed);
#endif
#ifdef RUST_ENABLED
else if (hash == wyhash_rs)
wyhash_rs_seed_init (seed);
#endif
#ifdef HAVE_INT64
else if(hash == mirhash_test)
mirhash_seed_init(seed);
Expand Down Expand Up @@ -962,6 +968,10 @@ bool Hash_Seed_init (pfHash hash, size_t seed) {
// VHASH_seed_init(seed);
if(hash == tabulation_32_test)
tabulation_32_seed_init(seed);
#ifdef RUST_ENABLED
else if (hash == wyhash_rs)
wyhash_rs_seed_init (seed32);
#endif
#ifdef __SIZEOF_INT128__
else if(hash == multiply_shift || hash == pair_multiply_shift)
multiply_shift_seed_init(seed32);
Expand Down
2 changes: 2 additions & 0 deletions rust-hashes/rust_hashes.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ void siphash128_24_rs(const void *blob, int len, unsigned int seed, void *out);

void whirlpool_rs(const void *blob, int len, unsigned int seed, void *out);

void whirlpool256_rs(const void *blob, int len, unsigned int seed, void *out);

void wyhash_rs(const void *blob, int len, unsigned int seed, void *out);

void xxhash3_rs(const void *blob, int len, unsigned int seed, void *out);
Expand Down
9 changes: 7 additions & 2 deletions rust-hashes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use digest::{Digest, ExtendableOutput, XofReader};
/// Default domain separation
const TURBO_DOMAIN_SEP: u8 = 0x1f;

/// This maco does the following:
/// This macro does the following:
/// - Accepts a repeating list of `identifer: function`
/// - Creates a C function with that identifier
/// - Turn data into a Rust slice
Expand Down Expand Up @@ -161,7 +161,12 @@ hashes! {
siphash128_24_rs: seeded_wrapper(|seed: u32|
siphasher::sip128::SipHasher24::new_with_keys(seed.into(), 0)
),
whirlpool_rs: digest_wrapper::<whirlpool::Whirlpool>,
//whirlpool_rs: digest_wrapper::<whirlpool::Whirlpool>,
//whirlpool256_rs: |buf, _seed, out: *mut c_void| {
// let mut hash = whirlpool::Whirlpool::new();
// hash.update(buf);
// hash.finalize_into(unsafe { &mut *out.cast() });
//},
wyhash_rs: seeded_wrapper(wyhash::WyHash::with_seed),
xxhash3_rs: seeded_wrapper(xxhash_rust::xxh3::Xxh3::with_seed),
xxhash128_rs: |buf, _seed, out: *mut c_void| unsafe {
Expand Down

0 comments on commit 934ad1a

Please sign in to comment.