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.pbkdf2_sha256`.

/// Shared WGSL helpers for PBKDF2-HMAC-SHA-256.
pub const WGSL: &str = include_str!("wgsl_shaders/sha256.wgsl");

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

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

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

/// Derive bytes with PBKDF2-HMAC-SHA-256.
///
/// # Errors
///
/// Returns an actionable error for zero iterations, iteration counts above
/// 1,000,000, or output sizes beyond the RFC 8018 limit.
pub fn pbkdf2_sha256(
    password: &[u8],
    salt: &[u8],
    iterations: u32,
    dk_len: u32,
) -> Result<Vec<u8>, String> {
    crate::ops::hash::reference::kdf::pbkdf2_sha256(password, salt, iterations, dk_len)
}

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

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