Skip to main content

Crate dryoc

Crate dryoc 

Source
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 without std or alloc using fixed-size stack arrays; opt-in alloc, serde, and wincode support.

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 / OperationRustaceous APIClassic API
Public-key authenticated boxesDryocBoxcrypto_box
Secret-key authenticated boxesDryocSecretBoxcrypto_secretbox
Post-quantum key encapsulationkem, kem::mlkem768crypto_kem
Post-quantum sealed boxes (HPKE)DryocSealedBoxN/A
AEAD (ChaCha20-Poly1305-IETF / XChaCha20)DryocAeadcrypto_aead_xchacha20poly1305_ietf
Streaming encryptionDryocStreamcrypto_secretstream_xchacha20poly1305
Generic hashing (BLAKE2b)GenericHashcrypto_generichash
SHA-2 & SHA-3 hashingSha256, Sha3256crypto_hash
XOF (SHAKE128/256, TurboSHAKE)Shake128crypto_xof
Secret-key & HMAC authenticationAuth, Hmaccrypto_auth
Key derivation (KDF & HKDF)Kdf, Hkdfcrypto_kdf
Key exchangeSessioncrypto_kx
Public-key signatures (Ed25519)SigningKeyPaircrypto_sign
Password hashing (Argon2id)PwHashcrypto_pwhash
Protected memoryprotectedN/A

§Cargo Features

FeatureDefaultDescription
stdYesEnables alloc, runtime CPU detection, and Error::Io.
allocWith stdHeap-allocating APIs (Vec<u8> conversions, VecBox types, pwhash).
protectedYesPage-aligned, locked memory allocations on Unix/Windows.
base64YesPassword-hash string formatting helpers.
serdeYesSerde serialization support for keys, nonces, and containers.
wincode_0_6NoDirect binary serialization via wincode 0.6.
simd_backendNoPortable SIMD implementation (requires nightly).
nightlyNoNightly 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.


  1. 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 in crate::dryocbox::DryocBox
protectedprotected
Memory protection utilities
pwhashalloc
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 unsafe in dryoc, and why each is sound.
utils
Various utility functions
xof
Extendable-output functions

Enums§

Error
Errors generated by Dryoc.
ErrorContext
The input, output, or operation associated with an Error.
LengthConstraint
A constraint on a byte or buffer length.
ValueConstraint
A constraint on a numeric parameter.