ling-crypto 2030.0.0

Cryptography primitives for Ling — hashing, signing, and symmetric encryption
Documentation
//! Blake3 cryptographic hashing stub.

pub struct Blake3;

impl Blake3 {
    /// Compute the 32-byte Blake3 hash of `data`.
    pub fn hash(data: &[u8]) -> [u8; 32] {
        // TODO: wire to blake3 crate when feature is enabled
        // Simple djb2-style placeholder that at least varies by input.
        let mut h = 5381u64;
        for &b in data {
            h = h.wrapping_mul(33).wrapping_add(b as u64);
        }
        let mut out = [0u8; 32];
        for i in 0..4 {
            let word = h.wrapping_mul((i as u64 + 1).wrapping_mul(0x517cc1b727220a95));
            out[i * 8..(i + 1) * 8].copy_from_slice(&word.to_le_bytes());
        }
        out
    }

    /// Compute a keyed Blake3 hash.
    pub fn keyed_hash(key: &[u8; 32], data: &[u8]) -> [u8; 32] {
        let mut combined = key.to_vec();
        combined.extend_from_slice(data);
        Self::hash(&combined)
    }
}