solana-ecvrf 0.0.1

ECVRF-EDWARDS25519-SHA512-TAI (RFC 9381) verification for Solana programs using curve25519 and sha512 syscalls
Documentation
//! SHA-512: the `sol_sha512` syscall on-chain (SIMD-0512), the `sha2` crate
//! on the host. Costs 85 CU plus 1 CU per byte on-chain.

pub const HASH_LENGTH: usize = 64;

/// SHA-512 of the concatenation of `data`, without concatenating.
#[cfg(target_os = "solana")]
#[inline(always)]
pub fn hashv(data: &[&[u8]]) -> [u8; HASH_LENGTH] {
    let mut out = core::mem::MaybeUninit::<[u8; HASH_LENGTH]>::uninit();
    unsafe {
        crate::syscalls::sol_sha512(
            data as *const _ as *const u8,
            data.len() as u64,
            out.as_mut_ptr() as *mut u8,
        );
        out.assume_init()
    }
}

#[cfg(not(target_os = "solana"))]
pub fn hashv(data: &[&[u8]]) -> [u8; HASH_LENGTH] {
    use sha2::Digest;
    let mut h = sha2::Sha512::new();
    for d in data {
        h.update(d);
    }
    h.finalize().into()
}