Pr/xxh3 rrmxmx mixer fix (#1828)

* Fixing the mixer according to the xxHash implementation

* Using Rust xxhash-rust instead of handwritten implementation

* Fixing the mixer according to the xxHash implementation - linking directly, not relying on bolts option

* clippy+fmt

* Removing rotation, as it causes issues

* Not using xxhash directly, relying on bolts

* Fmt
This commit is contained in:
mkravchik 2024-02-14 12:45:47 +02:00 committed by GitHub
parent b9650045f6
commit c837d0df7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 19 deletions

View File

@ -59,23 +59,6 @@ pub const fn integer_sqrt(val: u64) -> u64 {
ret
}
/// Given a u64 number, return a hashed number using this mixing function
/// This function is used to hash an address into a more random number (used in `libafl_frida`).
/// Mixing function: <http://mostlymangling.blogspot.com/2018/07/on-mixing-functions-in-fast-splittable.html>
#[inline]
#[must_use]
pub const fn xxh3_rrmxmx_mixer(v: u64) -> u64 {
let tmp = (v >> 32) + ((v & 0xffffffff) << 32);
let bitflip = 0x1cad21f72c81017c ^ 0xdb979082e96dd4de;
let mut h64 = tmp ^ bitflip;
h64 = h64.rotate_left(49) & h64.rotate_left(24);
h64 = h64.wrapping_mul(0x9FB21C651E98DF25);
h64 ^= (h64 >> 35) + 8;
h64 = h64.wrapping_mul(0x9FB21C651E98DF25);
h64 ^= h64 >> 28;
h64
}
/// Calculates the cumulative sum for a slice, in-place.
/// The values are useful for example for cumulative probabilities.
///

View File

@ -6,7 +6,7 @@ use std::{cell::RefCell, marker::PhantomPinned, pin::Pin, rc::Rc};
use dynasmrt::DynasmLabelApi;
use dynasmrt::{dynasm, DynasmApi};
use frida_gum::{instruction_writer::InstructionWriter, stalker::StalkerOutput, ModuleMap};
use libafl_bolts::math::xxh3_rrmxmx_mixer;
use libafl_bolts::hash_std;
use rangemap::RangeMap;
use crate::helper::FridaRuntime;
@ -186,7 +186,7 @@ impl CoverageRuntime {
/// Emits coverage mapping into the current basic block.
#[inline]
pub fn emit_coverage_mapping(&mut self, address: u64, output: &StalkerOutput) {
let h64 = xxh3_rrmxmx_mixer(address);
let h64 = hash_std(&address.to_le_bytes());
let writer = output.writer();
// Since the AARCH64 instruction set requires that a register be used if