Skip to main content

Crate sriracha_mayo

Crate sriracha_mayo 

Source
Expand description

§sriracha-mayo

GitHub Actions Workflow Status Crates.io License Crates.io MSRV Crates.io Version docs.rs

Safe Rust bindings for MAYO-C.

The API is intentionally small:

use sriracha_mayo::{Mayo1, SecretKey};
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;

let message = b"message";
let mut rng = ChaCha20Rng::from_seed([7; 32]);
let (public_key, secret_key) = SecretKey::<Mayo1>::random(&mut rng)?;
let signature = secret_key.sign(message)?;

assert!(signature.verify(&public_key, message));

§Benchmarks

Criterion benchmarks from cargo bench on aarch64-apple-darwin (Apple M4 Max 2024) with rustc 1.96.0 and neon enabled.

Parameter setKeygenSignVerifyVerify 128Batch add + verify 128
MAYO-130.541 us107.59 us49.652 us6.0463 ms2.8870 ms
MAYO-229.344 us71.456 us17.376 us2.2614 ms746.01 us
MAYO-392.266 us259.03 us111.27 us14.358 ms8.2259 ms
MAYO-5219.51 us575.34 us237.43 us30.534 ms17.256 ms

§Feature Flags

The default feature set enables std. Build with --no-default-features for no_std consumers; the crate still requires alloc for owned byte buffers and batch verification.

Enable serde to derive Serialize and Deserialize for PublicKey, SecretKey, and Signature. The encoded form is the compact MAYO-C key encoding for keys and the detached signature bytes for signatures.

No backend feature is enabled by default. The opt, avx2, and neon features select a MAYO-C backend explicitly when exactly one is enabled. If more than one backend feature is enabled, build.rs falls back to platform auto-detection so standard additive Cargo builds such as --all-features still work.

cargo build --no-default-features
cargo build --features serde
cargo build --features neon

§Parameter Sets

Use Mayo1, Mayo2, Mayo3, or Mayo5 as the type parameter for PublicKey, SecretKey, and Signature.

use sriracha_mayo::{Mayo3, SecretKey};
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;

let mut rng = ChaCha20Rng::from_seed([7; 32]);
let (public_key, secret_key) = SecretKey::<Mayo3>::random(&mut rng)?;
let message = b"hello";
let signature = secret_key.sign(message)?;

assert!(signature.verify(&public_key, message));

§Random Key Generation

Use SecretKey::random when key generation should draw randomness from a caller-provided rand_core RNG.

use sriracha_mayo::{Mayo1, SecretKey};
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;

let mut rng = ChaCha20Rng::from_seed([7; 32]);
let (public_key, secret_key) = SecretKey::<Mayo1>::random(&mut rng)?;

let message = b"message";
let signature = secret_key.sign(message)?;
assert!(signature.verify(&public_key, message));

§Backend Selection

If no backend feature is selected, build.rs chooses avx2 or neon when the target supports it, and falls back to opt.

Use an explicit backend feature when you need a reproducible backend choice:

cargo build --features neon

§Submodule

This crate builds and statically links MAYO-C from the root-level MAYO-C submodule. If the submodule is missing, initialize it before building:

git submodule update --init --recursive

Structs§

BatchVerifier
Verifies many signatures while reusing expanded public keys.
Mayo1
MAYO-1 marker type.
Mayo2
MAYO-2 marker type.
Mayo3
MAYO-3 marker type.
Mayo5
MAYO-5 marker type.
PublicKey
A compact MAYO public key.
SecretKey
A compact MAYO secret key.
Signature
A detached MAYO signature.

Enums§

Error
A MAYO operation failed.
MayoError
A typed MAYO-C error code.

Traits§

ParameterSet
A marker trait for MAYO parameter sets.