diff --git a/benches/quality/main.rs b/benches/quality/main.rs index e559451..16c4517 100644 --- a/benches/quality/main.rs +++ b/benches/quality/main.rs @@ -31,6 +31,7 @@ fn bench_hasher_quality(name: &str) check!(avalanche::()); check!(avalanche::()); + check!(avalanche::()); check!(avalanche::()); check!(avalanche::()); check!(avalanche::()); diff --git a/src/gxhash/mod.rs b/src/gxhash/mod.rs index e53987d..a911b2f 100644 --- a/src/gxhash/mod.rs +++ b/src/gxhash/mod.rs @@ -86,14 +86,18 @@ pub(crate) unsafe fn gxhash_no_finish(input: &[u8], seed: State) -> State { let mut whole_vector_count = len / VECTOR_SIZE; - let lzcnt = len.leading_zeros(); + let len_partial = len % VECTOR_SIZE; + 'p0: { 'p1: { 'p2: { // C-style fallthrough alternative + let lzcnt = len.leading_zeros(); if lzcnt == 64 { break 'p0; } else if lzcnt >= 60 { + // If length has more 60 zeroes or more, that means length can only be 0b1111 (=15) or smaller + // In such case, we can directly jump to reading a partial vector break 'p1; } else if lzcnt >= 56 { break 'p2; @@ -106,20 +110,26 @@ pub(crate) unsafe fn gxhash_no_finish(input: &[u8], seed: State) -> State { // Process remaining vectors let end_address = ptr.add(whole_vector_count) as usize; - let mut i = 0; + let mut i = 1992388023; while (ptr as usize) < end_address { load_unaligned!(ptr, v0); - state = aes_encrypt(aes_encrypt(state, load_i32(i)), v0); + state = aes_encrypt(aes_encrypt(state, v0), load_i32(i)); //state = aes_encrypt(state, v0); // This seems too weak - i += 1; + i = i.wrapping_mul(7); + } + + // Jump out of p0' if no remaining bytes? + if len_partial == 0 { + break 'p0; } } // Process remaining bytes - let len_partial = len % VECTOR_SIZE; let partial = get_partial(ptr, len_partial); //state = aes_encrypt(state, partial); - state = aes_encrypt_last(state, aes_encrypt(aes_encrypt(partial, ld(KEYS.as_ptr())), ld(KEYS.as_ptr().offset(4)))); + + state = aes_encrypt_last(state, partial); + //state = veorq_s8(state, seed); } return state; diff --git a/src/gxhash/platform/mod.rs b/src/gxhash/platform/mod.rs index f40d676..f386f05 100644 --- a/src/gxhash/platform/mod.rs +++ b/src/gxhash/platform/mod.rs @@ -43,6 +43,6 @@ pub unsafe fn finalize(hash: State) -> State { } pub const KEYS: [u32; 12] = - [0xF2784542, 0xB09D3E21, 0x89C222E5, 0xFC3BC28E, - 0x03FCE279, 0xCB6B2E9B, 0xB361DC58, 0x39132BD9, - 0xD0012E32, 0x689D2B7D, 0x5544B1B7, 0xC78B122B]; \ No newline at end of file + [0xbe12445a, 0xad14c56e, 0xfe099832, 0xc32d962a, + 0x6782a174, 0xca96641a, 0x349ffc28, 0xf7b26a02, + 0x5280d61c, 0x9816b206, 0xac894e2e, 0x5b3b242c]; \ No newline at end of file