Skip to main content

tequel/
lib.rs

1/*
2 * Tequel-rs: High-Density 384-bit Cryptographic Hash Engine
3 * Copyright (C) 2026 Gabriel Xavier (dotxav)
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 */
15
16pub mod error;
17pub mod hash;
18pub mod encrypt;
19pub mod rng;
20pub mod avx2_inline;
21
22
23// --- FFI Boundary ---
24
25#[unsafe(no_mangle)]
26pub extern "C" fn tequel_hash_raw(data: *const u8, len: usize, out: *mut u8) {
27    let input = unsafe { std::slice::from_raw_parts(data, len) };
28
29    let mut teq = hash::TequelHash::new();
30    let hash_result = teq.tqlhash_raw(input);
31
32    unsafe {
33        std::ptr::copy_nonoverlapping(hash_result.as_ptr(), out, 48);
34    }
35} 
36
37
38#[unsafe(no_mangle)]
39pub extern "C" fn isv_tequel_hash_raw(hash_ptr: *const u8, input_ptr: *const u8, input_len: usize) -> bool {
40    
41    let hash = unsafe { assert!(!hash_ptr.is_null()); std::slice::from_raw_parts(hash_ptr, 48) };
42    let input = unsafe { assert!(!input_ptr.is_null()); std::slice::from_raw_parts(input_ptr, input_len) };
43
44    let mut teq = hash::TequelHash::new();
45    let curr_hash = teq.tqlhash_raw(input);
46
47    let mut result = 0u8;
48    
49    for i in 0..48 {
50        result |= curr_hash[i] ^ hash[i];
51    }
52
53    result == 0
54
55}