You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pure Rust cryptography. Hardware-accelerated. Zero dependencies.
Quick Start
Minimal install:
[dependencies]
rscrypto = { version = "0.1", default-features = false, features = ["crc32"] }
Targeted bundle installs:
[dependencies]
# MACs onlyrscrypto = { version = "0.1", default-features = false, features = ["macs"] }
# Signatures onlyrscrypto = { version = "0.1", default-features = false, features = ["signatures"] }
# X25519 onlyrscrypto = { version = "0.1", default-features = false, features = ["key-exchange"] }
Full install:
[dependencies]
rscrypto = { version = "0.1", features = ["full"] }
Feature selection rules:
Pick a leaf when size matters most: crc32, sha2, hmac, hkdf, ed25519, x25519, chacha20poly1305, etc.
Pick a bundle when you want the whole category: checksums, crypto-hashes, fast-hashes, hashes, macs, kdfs, signatures, key-exchange, auth, aead, full.
Keep default = ["std"] unless you explicitly need no_std.
use rscrypto::{Aead,Blake3,Checksum,ChaCha20Poly1305,ChaCha20Poly1305Key,Crc32C,Digest,Ed25519Keypair,Ed25519SecretKey,HkdfSha256,HmacSha256,Kmac256,Mac,Sha256,Shake256,X25519SecretKey,Xof,Xxh3, aead::Nonce96,};// Checksumlet crc = Crc32C::checksum(b"data");// Digest (one-shot and streaming)let hash = Sha256::digest(b"data");letmut h = Sha256::new();
h.update(b"da"); h.update(b"ta");assert_eq!(h.finalize(), hash);// HMAClet tag = HmacSha256::mac(b"key",b"data");assert!(HmacSha256::verify_tag(b"key",b"data",&tag).is_ok());// HKDFletmut okm = [0u8;32];HkdfSha256::new(b"salt",b"ikm").expand(b"info",&mut okm)?;// XOFletmut xof = Shake256::xof(b"data");letmut out = [0u8;64];
xof.squeeze(&mut out);// KMAC256letmut kmac = Kmac256::new(b"key",b"domain=v1");
kmac.update(b"data");letmut tag32 = [0u8;32];
kmac.finalize_into(&mut tag32);// Ed25519let kp = Ed25519Keypair::from_secret_key(Ed25519SecretKey::from_bytes([7u8;32]));let sig = kp.sign(b"data");assert!(kp.public_key().verify(b"data",&sig).is_ok());// X25519let alice = X25519SecretKey::from_bytes([7u8;32]);let bob = X25519SecretKey::from_bytes([9u8;32]);assert_eq!(alice.diffie_hellman(&bob.public_key())?, bob.diffie_hellman(&alice.public_key())?);// AEADlet cipher = ChaCha20Poly1305::new(&ChaCha20Poly1305Key::from_bytes([0x11;32]));let nonce = Nonce96::from_bytes([0x22;12]);letmut buf = *b"data";let tag = cipher.encrypt_in_place(&nonce,b"aad",&mut buf);
cipher.decrypt_in_place(&nonce,b"aad",&mut buf,&tag)?;assert_eq!(&buf,b"data");// Fast hashes (non-cryptographic)let _ = Xxh3::hash(b"data");let _ = rscrypto::RapidHash::hash(b"data");
# Ok::<(),Box<dyn std::error::Error>>(())
Purpose
Single-crate crypto and checksum toolbox. No C FFI, no vendored C/C++, no_std first. Portable fallback is authoritative; ISA-specific kernels are accelerators, not separate APIs.
API Conventions
Checksums use Type::checksum(data) plus new / update / finalize / reset.
Fixed-output digests use Type::digest(data); XOFs use Type::xof(data) and finalize_xof().
MACs use Type::mac(key, data) and Type::verify_tag(key, data, tag); KMAC uses finalize_into because output length is caller-chosen.
HKDF uses new(salt, ikm) followed by expand / expand_array, with one-shot derive / derive_array.
Signature, key-exchange, nonce, key, and tag wrappers round-trip through from_bytes / to_bytes / as_bytes.
AEADs use encrypt / decrypt for combined buffers and encrypt_in_place / decrypt_in_place for detached-tag flows.
Invariants
Invariant
What breaks if violated
Portable fallback is the authority
Wrong digest/checksum/ciphertext output
All backends produce identical bytes
Silent data corruption
Verification errors are opaque
Timing and oracle attacks
Secret material zeroized on drop
Key retention in memory
Official vectors and differential tests stay green
Interoperability failures
Complete Root Inventory
Traits
Trait
Purpose
Source
Checksum
Stateful and one-shot checksum
traits/checksum.rs:51
ChecksumCombine
Parallel CRC combine
traits/checksum.rs:280
Digest
Fixed-output hash
traits/digest.rs:11
Xof
Variable-output squeeze
traits/xof.rs:7
Mac
Keyed streaming MAC
traits/mac.rs:13
FastHash
One-shot seeded hash
traits/fast_hash.rs:13
Aead
Authenticated encryption
traits/aead.rs:20
AEAD (feature: aead or AEAD leaves)
Cipher
Key
Nonce
Tag
Source
Aes256Gcm
32B
Nonce96 (12B)
16B
aead/aes256gcm.rs
Aes256GcmSiv
32B
Nonce96 (12B)
16B
aead/aes256gcmsiv.rs
ChaCha20Poly1305
32B
Nonce96 (12B)
16B
aead/chacha20poly1305.rs
XChaCha20Poly1305
32B
Nonce192 (24B)
16B
aead/xchacha20poly1305.rs
AsconAead128
16B
Nonce128 (16B)
16B
aead/ascon128.rs
Aegis256
32B
Nonce256 (32B)
16B
aead/aegis256.rs
Each cipher has typed *Key and *Tag wrappers. Nonces: Nonce96, Nonce128, Nonce192, Nonce256 in rscrypto::aead.