अपडेट पर वापस जाएँ
New releaseSep 3, 2026

rscrypto v0.9.0

Rust क्रिप्टोग्राफी शून्य आवश्यक डिप्स के साथ: हैश, चेकसम, MACs, KDFs, पासवर्ड हैशिंग, AEADs, हस्ताक्षर, RSA, कुंजी विनिमय, ML-KEM, और ML-DSA। SIMD और ASM बैकएंड के साथ पोर्टेबल Rust संदर्भ।

साझा करें

rscrypto

Crates.io Docs.rs MSRV 1.100.0 License: Apache-2.0

rscrypto is a Rust library of cryptographic primitives, hashes, password hashing, random generation, and checksums. One feature model controls all of them. Portable Rust is the reference implementation. SIMD and assembly backends make it faster on supported targets. Production builds do not depend on C, FFI, OpenSSL, or system libraries.

The rscrypto crate supplies primitives. The companion rscrypto-rustls supplies TLS and QUIC cryptographic adapters.

Install

rscrypto needs Rust 1.100 or later. Some accelerated POWER, IBM Z, and RISC-V backends need a nightly compiler; builds without their features, and portable-only builds, support the declared MSRV. See Toolchain.

Minimal no_std build with SHA-2 only:

[dependencies]
rscrypto = { version = "0.13", default-features = false, features = ["sha2"] }

All primitives, with operating-system randomness:

[dependencies]
rscrypto = { version = "0.13", features = ["full", "getrandom"] }

The default feature is std. Set default-features = false to remove it. Enable getrandom only for the APIs that get randomness from the operating system, such as key generation, nonces, salts, hedged signing, ML-KEM and X-Wing encapsulation, and RSA blinding. The feature guide explains how to select features. Cargo.toml defines the exact feature graph.

Quick start

Encrypt a message and read it back

[dependencies]
rscrypto = { version = "0.13", features = ["xchacha20poly1305", "getrandom"] }
use rscrypto::{Aead, XChaCha20Poly1305, XChaCha20Poly1305Key};

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let key = XChaCha20Poly1305Key::try_random()?;
  let cipher = XChaCha20Poly1305::new(&key);
  let aad = b"record 42";
  let message = b"meet at noon";
  let (nonce, ciphertext) = cipher.seal_random_to_vec(aad, message)?;
  let plaintext = cipher.decrypt_to_vec(&nonce, aad, &ciphertext)?;
  assert_eq!(plaintext.as_slice(), message);
  Ok(())
}

Store the returned nonce with the ciphertext. Keep the key secret. Use the same key and associated data to decrypt later. The runnable example uses this workflow.

Hash a message

use rscrypto::Sha256;

let one_shot = Sha256::digest(b"hello world");

let mut hasher = Sha256::new();
hasher.update(b"hello ");
hasher.update(b"world");

assert_eq!(hasher.finalize(), one_shot);

Hash types support one-shot and streaming use. examples/README.md has runnable examples for AEAD, signatures, RSA, P-256 and P-384 ECDH, X25519, ML-KEM, password hashing, and backend introspection.

Primitives and features

FamilyPrimitivesFeature
ChecksumsCRC-16, CRC-24, CRC-32, CRC-32C, CRC-64/XZ, CRC-64/NVMe, Adler-32checksums or a leaf feature
Cryptographic hashesSHA-2, SHA-3, SHAKE, cSHAKE, BLAKE2, BLAKE3, Ascon-Hash/XOF/CXOFcrypto-hashes or a leaf feature
Fast hashesXXH3-64/128, XXH32, XXH64, RapidHash V3-64fast-hashes or a leaf feature
MACs and KDFsHMAC-SHA-2/SHA-3, KMAC128/256, Poly1305, SipHash-1-3/2-4 (flood-resistant hash tables), HKDF-SHA-2, PBKDF2-HMAC-SHA-2macs, kdfs, or a leaf feature
Password hashingArgon2d/i/id, scrypt, bounded PHC password recordspassword-hashing or a leaf feature
Signatures and RSAECDSA P-256/P-384, Ed25519, ML-DSA-44/65/87, SLH-DSA (all 12 FIPS 205 sets, pure and HashSLH-DSA), composite ML-DSA-65 with Ed25519 or ECDSA P-256 (draft-ietf-lamps-pq-composite-sigs-19), RSA signing, verification, encryption, and key generationsignatures or a leaf feature
Key exchange and KEMsP-256 ECDH, P-384 ECDH, X25519, ML-KEM-512/768/1024, X-Wing (ML-KEM-768 + X25519, draft-connolly-cfrg-xwing-kem-11), HPKE Base mode (RFC 9180) with the DHKEM(X25519) + AES-128-GCM and X-Wing + ChaCha20Poly1305 suiteskey-exchange or a leaf feature
AEADsAES-GCM, AES-GCM-SIV, AES-SIV-CMAC, ChaCha20-Poly1305, XChaCha20-Poly1305, AEGIS-256, Ascon-AEAD128aead or a leaf feature
Random generationChaCha20Rngchacha20-rng (included in full)

ChaCha20Rng accepts a caller-supplied seed and works without std or alloc. rand_core adds generator traits; getrandom adds operating-system seeding.

Signature and KEM keys import and export standard DER (PKCS #8 and SubjectPublicKeyInfo) for ECDSA, Ed25519, RSA, ML-DSA, composite ML-DSA, ML-KEM, and SLH-DSA.

AeadGather encrypts multiple plaintext slices into one ciphertext, and decrypts one ciphertext in place across ordered segments, for AES-GCM and ChaCha20-Poly1305. With aes-gcm, aead::expert::quic_lb encrypts QUIC-LB connection IDs (draft-ietf-quic-load-balancers-22). BLAKE3 supports reader, file, and batch hashing, and an expert decoder verifies sequential unkeyed Bao combined streams. hashes::expert::BLAKE3_PORTABLE_SOURCE holds the source text of the portable BLAKE3 compression function. The feature guide describes these APIs and their allocation and std requirements.

The WebSocket accept digest exists only for protocol compatibility. It needs the websocket-sha1 feature. No umbrella feature, including full, enables it.

See docs.rs for exact types and methods. The API compatibility notes explain output types, collection seeds, and retained method names. The cryptographic resilience guide explains security assumptions, migration boundaries, and the evidence to review when choosing stronger cryptography.

TLS and QUIC provider

The rscrypto-rustls companion connects these primitives to rustls:

CapabilityCoverage
TLSTLS 1.3; opt-in TLS 1.2 ECDHE suites
Client privacyEncrypted Client Hello with X25519, HKDF-SHA256, and AES-128-GCM
Key exchangeX25519MLKEM768 hybrid (preferred), X25519, P-256, P-384; opt-in SecP256r1MLKEM768, SecP384r1MLKEM1024, MLKEM768, MLKEM1024
AuthenticationECDSA P-256/P-384, Ed25519, RSA; opt-in ML-DSA-44/65/87 (ml-dsa) and composite ML-DSA-65 with Ed25519 or ECDSA P-256 at provisional draft codepoints (mldsa65-ed25519, mldsa65-ecdsa-p256)
QUICQUIC v1 packet and header protection through rustls's QUIC API; Initial keys, Retry tags, connection IDs, and reset and address tokens for any transport

The provider supports mutual authentication, session resumption, stateless tickets, and caller-supplied entropy. rustls owns the TLS protocol and rustls-webpki validates certificate paths. The QUIC transport belongs to the application.

श्रेणियाँ