ihash 0.1.2

World's fastest high-quality non-cryptographic hash, deterministic cross-platform XOF, and seekable stream cipher
Documentation
macro_rules! unroll4 {
  ($i:ident => $body:expr) => {
    [
      {
        const $i: usize = 0;
        $body
      },
      {
        const $i: usize = 1;
        $body
      },
      {
        const $i: usize = 2;
        $body
      },
      {
        const $i: usize = 3;
        $body
      },
    ]
  };
}

macro_rules! unroll8 {
  ($i:ident => $body:expr) => {
    [
      {
        const $i: usize = 0;
        $body
      },
      {
        const $i: usize = 1;
        $body
      },
      {
        const $i: usize = 2;
        $body
      },
      {
        const $i: usize = 3;
        $body
      },
      {
        const $i: usize = 4;
        $body
      },
      {
        const $i: usize = 5;
        $body
      },
      {
        const $i: usize = 6;
        $body
      },
      {
        const $i: usize = 7;
        $body
      },
    ]
  };
}

pub(crate) mod aes128;
pub(crate) mod ctr;
pub(crate) mod group;
pub(crate) mod mode;
pub(crate) mod tree;

use crate::arch::Active;

/// Platform-level hashing and seekable CTR contract shielding ISA differences from public APIs.
pub(crate) trait Platform {
  fn hash32<const SEED0: bool>(data: &[u8], seed: u64) -> u32;
  fn hash64<const SEED0: bool>(data: &[u8], seed: u64) -> u64;
  fn hash128<const SEED0: bool>(data: &[u8], seed: u64) -> u128;
  fn hash256<const SEED0: bool>(data: &[u8], seed: u64) -> [u8; 32];
  fn ctr<const XOR: bool>(root: &[u8; 32], blk: u64, buf: &mut [u8]);
}

/// Zero-cost backend trait unifying hardware (`Active`) and pure-CPU (`fearless_simd::Level`) execution.
pub(crate) trait DigestBackend: Copy {
  fn hash64(self, data: &[u8], seed: u64) -> u64;
  fn ctr<const XOR: bool>(self, root: &[u8; 32], blk: u64, buf: &mut [u8]);
}

#[derive(Clone, Copy)]
pub(crate) struct ActiveBackend;

impl DigestBackend for ActiveBackend {
  #[inline(always)]
  fn hash64(self, data: &[u8], seed: u64) -> u64 {
    Active::hash64::<false>(data, seed)
  }

  #[inline(always)]
  fn ctr<const XOR: bool>(self, root: &[u8; 32], blk: u64, buf: &mut [u8]) {
    Active::ctr::<XOR>(root, blk, buf);
  }
}