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
16
17pub mod hash;
18pub mod rng;
19pub mod avx2_inline;
20mod entropy_test;
21
22
23
24
25
26
27
28
29// --- FFI Boundary ---
30
31#[unsafe(no_mangle)]
32pub unsafe extern "C" fn tequel_tqlhash(data: *const u8, len: usize, out: *mut u8) {
33
34    if out.is_null() { return; }
35    
36    let mut teq = hash::TequelHash::new();
37
38    let input = if len == 0 || data.is_null() {
39        &[]
40    } else {
41        unsafe { std::slice::from_raw_parts(data, len) }
42    };
43
44    let hr = teq.tqlhash_raw(input);
45
46    to_out(&hr, out);
47
48} 
49
50
51#[unsafe(no_mangle)]
52pub extern "C" fn isv_tequel_hash_raw(hash_ptr: *const u8, input_ptr: *const u8, input_len: usize) -> bool {
53    
54    let hash = unsafe { assert!(!hash_ptr.is_null()); std::slice::from_raw_parts(hash_ptr, 48) };
55    let input = unsafe { assert!(!input_ptr.is_null()); std::slice::from_raw_parts(input_ptr, input_len) };
56
57    let mut teq = hash::TequelHash::new();
58    let curr_hash = teq.tqlhash_raw(input);
59
60    let mut result = 0u8;
61    
62    for i in 0..48 {
63        result |= curr_hash[i] ^ hash[i];
64    }
65
66    result == 0
67
68}
69
70
71
72fn to_out(hash_r: &[u8], out: *mut u8) {
73    unsafe {
74        std::ptr::copy_nonoverlapping(
75            hash_r.as_ptr(), 
76            out, 
77            48
78        );
79    }
80}