clm-kernel 0.0.8

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
//! Layer 0: Stateless Kenotic Cryptographic Hashing
//! Canonical Path: kernel/clm_rust_core/src/layer0/hash.rs


pub const BLAKE3_PREFIX: &str = "blake3:";
pub const SHA256_PREFIX: &str = "sha256:";

/// Compute raw BLAKE3 64-character lowercase hex digest over arbitrary bytes.
pub fn compute_blake3(bytes: &[u8]) -> String {
    crate::hash::raw_hash_bytes_for("blake3", bytes)
        .expect("the central registry must contain the legacy BLAKE3 provider")
}

/// Compute raw SHA-256 64-character lowercase hex digest over arbitrary bytes.
pub fn compute_sha256(bytes: &[u8]) -> String {
    crate::hash::raw_hash_bytes_for("sha256", bytes)
        .expect("the central registry must contain the SHA-256 provider")
}

/// Compute prefixed hash using default algorithm (BLAKE3).
pub fn prefixed_hash(bytes: &[u8]) -> String {
    format!("{}{}", BLAKE3_PREFIX, compute_blake3(bytes))
}

/// Verify that an arbitrary byte payload matches the expected hash.
/// Supports prefixed ("blake3:<hex>", "sha256:<hex>") or unprefixed 64-char hex strings (assumed BLAKE3).
pub fn verify_hash(bytes: &[u8], expected_hash: &str) -> bool {
    crate::hash::verify_hash(expected_hash.trim(), bytes).is_ok()
}