vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use crate::ir::DataType;
use crate::ops::Backend;
use crate::ops::{IntrinsicDescriptor, OpSpec};

// WGSL lowering source for `hash.hkdf_expand`.

/// Shared WGSL helpers for HKDF expand.
pub const WGSL: &str = include_str!("wgsl_shaders/sha256.wgsl");

/// Compute RFC 5869 HKDF-Expand with HMAC-SHA-256.
///
/// # Errors
///
/// Returns an actionable error when `length` exceeds 8160 bytes.
pub fn hkdf_expand(prk: &[u8], info: &[u8], length: u32) -> Result<Vec<u8>, String> {
    crate::ops::hash::reference::kdf::hkdf_expand(prk, info, length)
}

pub const INPUTS: &[DataType] = &[DataType::Bytes, DataType::Bytes, DataType::U32];

pub const LAWS: &[crate::ops::AlgebraicLaw] = &[];

pub const OUTPUTS: &[DataType] = &[DataType::Bytes];

/// Declarative operation specification for `hash.hkdf_expand`.
pub const SPEC: OpSpec = OpSpec::intrinsic(
    "hash.hkdf_expand",
    INPUTS,
    OUTPUTS,
    LAWS,
    wgsl_only,
    IntrinsicDescriptor::new(
        "hash.hkdf_expand.wgsl",
        "wgsl-hkdf-expand-sha256",
        crate::ops::hash::cpu_refs::hkdf_expand,
    ),
);

pub fn wgsl_only(backend: &Backend) -> bool {
    matches!(backend, Backend::Wgsl)
}