tequel-rs 2.0.0

A high-performance 2x Loop Unrolling SIMD/AVX2 integrity engine and hash function, built in pure Rust for modern x86_64 architectures.
Documentation
/*
 * Tequel-rs: High-Density 384-bit Cryptographic Hash Engine
 * Copyright (C) 2026 Gabriel Xavier (dotxav)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 */


pub mod hash;
pub mod rng;
pub mod avx2_inline;
mod entropy_test;








// --- FFI Boundary ---

#[unsafe(no_mangle)]
pub unsafe extern "C" fn tequel_tqlhash(data: *const u8, len: usize, out: *mut u8) {

    if out.is_null() { return; }
    
    let mut teq = hash::TequelHash::new();

    let input = if len == 0 || data.is_null() {
        &[]
    } else {
        unsafe { std::slice::from_raw_parts(data, len) }
    };

    let hr = teq.tqlhash_raw(input);

    to_out(&hr, out);

} 


#[unsafe(no_mangle)]
pub extern "C" fn isv_tequel_hash_raw(hash_ptr: *const u8, input_ptr: *const u8, input_len: usize) -> bool {
    
    let hash = unsafe { assert!(!hash_ptr.is_null()); std::slice::from_raw_parts(hash_ptr, 48) };
    let input = unsafe { assert!(!input_ptr.is_null()); std::slice::from_raw_parts(input_ptr, input_len) };

    let mut teq = hash::TequelHash::new();
    let curr_hash = teq.tqlhash_raw(input);

    let mut result = 0u8;
    
    for i in 0..48 {
        result |= curr_hash[i] ^ hash[i];
    }

    result == 0

}



fn to_out(hash_r: &[u8], out: *mut u8) {
    unsafe {
        std::ptr::copy_nonoverlapping(
            hash_r.as_ptr(), 
            out, 
            48
        );
    }
}