Cryptography
The Miden SDK exposes cryptographic primitives for signature verification and hashing. These are low-level functions used by authentication components and anywhere message digests or hash-based commitments are needed.
Falcon-512 Poseidon2 verification
The core function for signature verification:
use miden::rpo_falcon512_verify;
// Verify a Falcon512 signature
// pk: Poseidon2 hash of the public key
// msg: Poseidon2 hash of the message
rpo_falcon512_verify(pk, msg);
| Parameter | Type | Description |
|---|---|---|
pk | Word | Poseidon2 hash of the signer's public key |
msg | Word | Poseidon2 hash of the message being verified |
The function panics (proof generation fails) if the signature is invalid.
The actual signature data is loaded onto the advice stack by the host. The Rust helper is still named rpo_falcon512_verify for compatibility, but the v0.15 verifier uses Falcon-512 over Poseidon2. You don't pass the signature as an argument.
Hashing
hash_words creates a message digest from a slice of Words:
use miden::hash_words;
// Hash multiple Words into a Digest
let words = [commitment, nonce_word, extra_data];
let digest: Word = hash_words(&words).into();
Other available hash functions:
use miden::{blake3_hash, sha256_hash};
// BLAKE3 (32-byte input -> 32-byte output)
let hash: [u8; 32] = blake3_hash(input_bytes);
// SHA256 (32-byte input -> 32-byte output)
let hash: [u8; 32] = sha256_hash(input_bytes);
Related
- Authentication — auth component pattern and nonce management
- Advice Provider — supplying auxiliary data during proof generation