Expand description
§dryoc: Don’t Roll Your Own Crypto™1
dryoc is a high-performance, pure-Rust cryptography library. It provides both a type-safe Rustaceous API and a Classic compatibility surface interoperative with libsodium wire formats.
§Highlights
- High Performance: Native SIMD and assembly kernels (AVX-512, AVX2, NEON, SVE2) with automatic runtime CPU detection.
- Post-Quantum Cryptography: ML-KEM-768 (FIPS 203), X-Wing hybrid
(ML-KEM
- X25519), and RFC 9180 HPKE sealed boxes.
- Type-Safe Rustaceous API: Strongly-typed fixed-size keys, nonces, and containers prevent length and type misuse at compile time.
- Classic Compatibility: Drop-in libsodium-compatible functions
(
crypto_*) and wire formats. - Hardened Memory: Protected memory allocations (page-aligned, locked,
guard pages) on Unix and Windows, plus automatic secret zeroization via
zeroize. - Flexible &
#![no_std]: Fully functional withoutstdorallocusing fixed-size stack arrays; opt-inalloc,serde, andwincodesupport.
Requires Rust 1.89 or newer (Rust 2024 edition).
§APIs
dryoc provides two complementary API surfaces built on the same underlying
cryptographic kernels:
- Rustaceous API (Recommended): Uses strongly-typed, fixed-size array
wrappers (e.g.,
Key,Nonce,DryocSecretBox). Ensures correct key and nonce sizes at compile time and provides convenient helper methods. - Classic API: Low-level byte-slice and array functions matching
libsodium standard signatures (
crypto_box_*,crypto_secretbox_*, etc.).
§Rustaceous Quick Start
use dryoc::dryocsecretbox::*;
use dryoc::types::*;
let key = Key::generate();
let nonce = Nonce::generate();
let message = b"Hello, post-quantum world!";
let box_ = DryocSecretBox::encrypt_to_vecbox(message, &nonce, &key).expect("encryption failed");
let decrypted = box_
.decrypt_to_vec(&nonce, &key)
.expect("authentication failed");
assert_eq!(message, &decrypted[..]);§Feature & API Overview
| Primitive / Operation | Rustaceous API | Classic API |
|---|---|---|
| Public-key authenticated boxes | DryocBox | crypto_box |
| Secret-key authenticated boxes | DryocSecretBox | crypto_secretbox |
| Post-quantum key encapsulation | kem, kem::mlkem768 | crypto_kem |
| Post-quantum sealed boxes (HPKE) | DryocSealedBox | N/A |
| AEAD (ChaCha20-Poly1305-IETF / XChaCha20) | DryocAead | crypto_aead_xchacha20poly1305_ietf |
| Streaming encryption | DryocStream | crypto_secretstream_xchacha20poly1305 |
| Generic hashing (BLAKE2b) | GenericHash | crypto_generichash |
| SHA-2 & SHA-3 hashing | Sha256, Sha3256 | crypto_hash |
| XOF (SHAKE128/256, TurboSHAKE) | Shake128 | crypto_xof |
| Secret-key & HMAC authentication | Auth, Hmac | crypto_auth |
| Key derivation (KDF & HKDF) | Kdf, Hkdf | crypto_kdf |
| Key exchange | Session | crypto_kx |
| Public-key signatures (Ed25519) | SigningKeyPair | crypto_sign |
| Password hashing (Argon2id) | PwHash | crypto_pwhash |
| Protected memory | protected | N/A |
§Cargo Features
| Feature | Default | Description |
|---|---|---|
std | Yes | Enables alloc, runtime CPU detection, and Error::Io. |
alloc | With std | Heap-allocating APIs (Vec<u8> conversions, VecBox types, pwhash). |
protected | Yes | Page-aligned, locked memory allocations on Unix/Windows. |
base64 | Yes | Password-hash string formatting helpers. |
serde | Yes | Serde serialization support for keys, nonces, and containers. |
wincode_0_6 | No | Direct binary serialization via wincode 0.6. |
simd_backend | No | Portable SIMD implementation (requires nightly). |
nightly | No | Nightly compiler features (portable_simd, Allocator impls). |
§Security Notes
dryoc has not undergone a third-party security audit. Defect surface is
minimized through type safety, comprehensive compatibility test suites, and
minimal unsafe usage confined to SIMD/assembly kernels and protected
memory. See unsafe_code for the full unsafe code inventory.
Not actually trademarked. ↩
Modules§
- auth
- Secret-key message authentication
- classic
- Classic API
- constants
- Constant value definitions
- dryocaead
- Authenticated encryption with additional data
- dryocbox
- Public-key authenticated encryption
- dryocsealedbox
- Post-quantum sealed boxes
- dryocsecretbox
- Secret-key authenticated encryption
- dryocstream
- Encrypted streams
- generichash
- Generic hashing
- hkdf
- HKDF key derivation
- hmac
- HMAC authentication
- kdf
- Key derivation functions
- kem
- Key encapsulation
- keypair
- Public/secret keypair tools
- kx
- Key exchange functions
- onetimeauth
- One-time authentication
- precalc
- Precalculated secret key for use with
precalc_*functions incrate::dryocbox::DryocBox - protected
protected - Memory protection utilities
- pwhash
alloc - Password hashing functions
- rng
- Random number generation utilities
- sha3
- SHA-3 hash algorithms
- sha256
- SHA-256 hash algorithm
- sha512
- SHA-512 hash algorithm
- sign
- Public-key signatures
- types
- Base type definitions
- unsafe_
code - Every non-test use of
unsafein dryoc, and why each is sound. - utils
- Various utility functions
- xof
- Extendable-output functions
Enums§
- Error
- Errors generated by Dryoc.
- Error
Context - The input, output, or operation associated with an
Error. - Length
Constraint - A constraint on a byte or buffer length.
- Value
Constraint - A constraint on a numeric parameter.