Expand description
Algorithm dispatch and structural validation.
This crate is the runtime seam between an Algorithm
selector and the concrete primitive that implements it. Given an
algorithm value it routes keygen, sign/verify, key agreement, and KEM
encapsulate/decapsulate to the matching primitive adapter, and it binds public keys to their multicodec/multikey
encodings.
Two safety properties are enforced here rather than left to callers:
verify fails closed — an invalid signature is an
AlgorithmError::SignatureInvalid, never Ok(false) — and every
secret returned (generated private keys, shared secrets, decapsulated
secrets) is carried in a zeroizing wrapper. Length and key-shape checks are
performed by the selected primitive’s typed constructors and are exercised
by dispatch-level negative tests so algorithm routing cannot silently
truncate, pad, or reinterpret caller bytes.
Constant-time behavior for authentication comparisons is inherited from the wrapped primitive crates. Dispatch does not reimplement tag, MAC, or signature comparison logic; it routes to the primitive verifier and maps the verifier’s typed failure into this crate’s fail-closed result.
§reallyme-crypto-dispatch
reallyme-crypto-dispatch owns algorithm-selected
signatures, key agreement, key encapsulation, and public-key encoding. It is
normally consumed through the public reallyme-crypto facade.
Dispatch operations fail closed with typed AlgorithmError values. Secret
outputs use zeroizing owners, and primitive crates retain responsibility for
cryptographic validation and constant-time verification.
§Fail-closed signature verification
// This example requires the `ed25519` feature.
use crypto_core::Algorithm;
use crypto_dispatch::{generate_keypair, sign, verify};
let (public, secret) = generate_keypair(Algorithm::Ed25519)?;
let signature = sign(Algorithm::Ed25519, &secret, b"message")?;
verify(Algorithm::Ed25519, &public, b"message", &signature)?;
// Invalid signatures are typed errors, never `Ok(false)`.
assert!(verify(Algorithm::Ed25519, &public, b"tampered", &signature).is_err());§Hash ownership
Hash selection is owned by reallyme_crypto::operations::hash, leaving one
semantic hash selector. Applications should use
reallyme_crypto::dispatch::hash_digest; adapters should call
reallyme_crypto::operations::hash::digest directly.
§MAC ownership
MAC selection is owned by reallyme_crypto::operations::mac, leaving one
semantic MAC selector. Applications should use reallyme_crypto::dispatch::{mac_authenticate, mac_verify}; adapters should call reallyme_crypto::operations::mac directly.
§AEAD ownership
AEAD selection is owned by reallyme_crypto::operations::aead, leaving one
semantic AEAD selector. Applications should use reallyme_crypto::dispatch::{aead_encrypt, aead_decrypt}; adapters should call reallyme_crypto::operations::aead
directly.
Re-exports§
pub use error::AlgorithmError;pub use registry::derive_keypair;pub use registry::generate_keypair;pub use registry::kem_decapsulate;pub use registry::kem_encapsulate;pub use registry::sign;pub use registry::verify;pub use keypair::generate_multikey_keypair;pub use keypair::GeneratedKeypair;pub use multikey::public_key_to_multikey;pub use provider::provider_decision;pub use provider::FallbackPolicy;pub use provider::KeyCopyBoundary;pub use provider::KeyResidency;pub use provider::ProviderDecision;pub use provider::ProviderDisposition;pub use provider::ProviderKind;pub use provider::ProviderLane;pub use provider::ProviderOperation;pub use provider::ProviderOutputPolicy;pub use provider::ProviderPolicyReason;pub use validation::validate_verification_method_multikey;
Modules§
- algorithms
- Per-algorithm adapters wiring selectors to concrete primitives.
- error
- Error type returned by dispatch operations.
- keypair
- Keypair generation with multikey-encoded public keys.
- multikey
- Multicodec/multikey encoding of public keys.
- provider
- Explicit provider selection, custody, lane, and fallback decisions. Inspectable provider decisions for algorithm-selected dispatch.
- registry
- Runtime dispatch entry points for sign/verify, key agreement, and KEM.
- traits
- Adapter traits implemented by each algorithm primitive.
- validation
- Structural validation of verification-method multikeys.