miden-stdlib-sys 0.12.0

Low-level Rust bindings for the Miden standard library
Documentation
#[cfg(not(all(target_family = "wasm", miden)))]
use crate::intrinsics::Word;
#[cfg(all(target_family = "wasm", miden))]
use crate::intrinsics::{Felt, Word};

#[cfg(all(target_family = "wasm", miden))]
unsafe extern "C" {
    #[link_name = "miden::core::crypto::dsa::falcon512_poseidon2::verify"]
    fn extern_rpo_falcon512_verify(
        pk0: Felt,
        pk1: Felt,
        pk2: Felt,
        pk3: Felt,
        msg0: Felt,
        msg1: Felt,
        msg2: Felt,
        msg3: Felt,
    );
}

/// Verifies a signature against a public key and a message. The procedure gets as inputs the hash
/// of the public key and the hash of the message via the operand stack. The signature is expected
/// to be provided via the advice provider. The signature is valid if and only if the procedure
/// returns.
///
/// Where `pk` is the hash of the public key and `msg` is the hash of the message. Both hashes are
/// expected to be computed using Poseidon2.
///
/// The verification expects the signature to be provided by the host via the advice stack.
/// In the current flow, callers should first trigger a signature request event using
/// `crate::emit_falcon_sig_to_stack(msg, pk)` and then call this function. The host must respond by
/// pushing the signature to the advice stack. For production deployments, ensure secret key
/// handling occurs outside the VM.
#[inline(always)]
#[cfg(all(target_family = "wasm", miden))]
pub fn rpo_falcon512_verify(pk: Word, msg: Word) {
    unsafe {
        extern_rpo_falcon512_verify(pk[0], pk[1], pk[2], pk[3], msg[0], msg[1], msg[2], msg[3]);
    }
}

#[inline(always)]
#[cfg(not(all(target_family = "wasm", miden)))]
pub fn rpo_falcon512_verify(_pk: Word, _msg: Word) {
    unimplemented!(
        "miden::core::crypto::dsa bindings are only available when targeting the Miden VM"
    )
}