Skip to main content

Crate rscrypto

Crate rscrypto 

Source
Expand description

Pure Rust cryptography, hardware-accelerated on ten architectures. no_std first.

rscrypto is a single-crate cryptography stack: hashes, AEADs, MACs, KDFs, password hashing, signatures, key exchange, and checksums. Enable one leaf feature for a minimal build (sha2, aes-gcm, ed25519, anything) or full for the entire primitive set. Zero default dependencies; getrandom, serde, and rayon are opt-in.

The portable Rust path is the byte-for-byte authority. SIMD and ASM kernels are accelerators, differential-tested against the portable path on every release. Three-tier dispatch (compile-time target_feature → runtime detection → portable fallback) picks the fastest safe backend at runtime; without std, only the compile-time tier runs.

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

§Guides

§API Shape

  • Checksums: Type::checksum(data) or new / update / finalize.
  • Digests: Type::digest(data) or new / update / finalize.
  • XOFs: Type::xof(data) or new / update / finalize_xof.
  • MACs: Type::mac(key, data) and Type::verify_tag(key, data, tag).
  • AEADs: typed keys and nonces, with combined and detached APIs.

§Quick Start

use rscrypto::{Digest, Sha256};

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

let mut h = Sha256::new();
h.update(b"hello ");
h.update(b"world");
assert_eq!(h.finalize(), digest);

§AEAD

use rscrypto::{Aead, ChaCha20Poly1305, ChaCha20Poly1305Key};

let key = ChaCha20Poly1305Key::from_bytes([0x11; 32]);
let cipher = ChaCha20Poly1305::new(&key);

let mut sealed = [0u8; 4 + ChaCha20Poly1305::TAG_SIZE];
let nonce = cipher.seal_random(b"aad", b"data", &mut sealed)?;

let mut opened = [0u8; 4];
cipher.decrypt(&nonce, b"aad", &sealed, &mut opened)?;
assert_eq!(&opened, b"data");

§Password Hashing

use rscrypto::{Argon2Params, Argon2VerifyPolicy, Argon2id};

let params = Argon2Params::new().build()?;
let encoded = Argon2id::hash_string(&params, b"correct horse battery staple")?;

assert!(
  Argon2id::verify_string_with_policy(
    b"correct horse battery staple",
    &encoded,
    &Argon2VerifyPolicy::default(),
  )
  .is_ok()
);

§Feature Groups

  • checksums: CRC families.
  • hashes: SHA-2, SHA-3, BLAKE2, BLAKE3, Ascon, XXH3, RapidHash.
  • auth: MACs, KDFs, password hashing, ECDSA signing/verification, Ed25519, RSA signing/verification/OAEP, X25519.
  • aead: AES-GCM, AES-GCM-SIV, ChaCha20-Poly1305, XChaCha20-Poly1305, AEGIS-256, Ascon-AEAD128.
  • full: all public primitive families.

Leaf features are available for size-conscious builds.

§Security Posture

Constant-time equality and fixed-width verification checks where the input shape has already reached the primitive boundary. Public structural rejects such as malformed lengths, unsupported algorithms, or out-of-range RSA representatives may fail before the full primitive work. Opaque verification errors leak no failure detail. Zeroize on drop for every secret-bearing type. strict_* arithmetic on counters and lengths; release builds keep overflow-checks = true. Continuous libFuzzer with corpus replay in CI; Miri on the portable backends.

rscrypto is a primitives crate, not a FIPS 140-3 validated module. It exposes FIPS-aligned primitives (AES-256-GCM, SHA-2, SHA-3 / SHAKE, HMAC, KMAC, HKDF, PBKDF2) alongside non-FIPS ones. The portable-only feature makes runtime capability detection report no SIMD/ASM capabilities, so dispatchers that consult runtime caps fall through to portable backends. It is a deployment control, not a substitute for release constant-time evidence. See the security guidance for nonce lifecycle, PHC verification limits, and platform fallback notes.

Re-exports§

pub use aead::AeadBufferError;aead
pub use aead::OpenError;aead
pub use aead::Aegis256;aegis256
pub use aead::Aegis256Key;aegis256
pub use aead::Aegis256Tag;aegis256
pub use aead::Aes128Gcm;aes-gcm
pub use aead::Aes128GcmKey;aes-gcm
pub use aead::Aes128GcmTag;aes-gcm
pub use aead::Aes128GcmSiv;aes-gcm-siv
pub use aead::Aes128GcmSivKey;aes-gcm-siv
pub use aead::Aes128GcmSivTag;aes-gcm-siv
pub use aead::Aes256Gcm;aes-gcm
pub use aead::Aes256GcmKey;aes-gcm
pub use aead::Aes256GcmTag;aes-gcm
pub use aead::Aes256GcmSiv;aes-gcm-siv
pub use aead::Aes256GcmSivKey;aes-gcm-siv
pub use aead::Aes256GcmSivTag;aes-gcm-siv
pub use aead::AsconAead128;ascon-aead
pub use aead::AsconAead128Key;ascon-aead
pub use aead::AsconAead128Tag;ascon-aead
pub use aead::ChaCha20Poly1305;chacha20poly1305
pub use aead::ChaCha20Poly1305Key;chacha20poly1305
pub use aead::ChaCha20Poly1305Tag;chacha20poly1305
pub use aead::XChaCha20Poly1305;xchacha20poly1305
pub use aead::XChaCha20Poly1305Key;xchacha20poly1305
pub use aead::XChaCha20Poly1305Tag;xchacha20poly1305
pub use auth::EcdsaError;ecdsa-p256 or ecdsa-p384
pub use auth::HkdfOutputLengthError;hkdf
pub use auth::Kmac256;kmac
pub use auth::PhcError;phc-strings
pub use auth::diag_ed25519_select_basepoint_cached_limb_digest;diag and ed25519
pub use auth::Argon2Error;argon2
pub use auth::Argon2Params;argon2
pub use auth::Argon2VerifyPolicy;argon2
pub use auth::Argon2Version;argon2
pub use auth::Argon2d;argon2
pub use auth::Argon2i;argon2
pub use auth::Argon2id;argon2
pub use auth::EcdsaP256Keypair;ecdsa-p256
pub use auth::EcdsaP256PublicKey;ecdsa-p256
pub use auth::EcdsaP256SecretKey;ecdsa-p256
pub use auth::EcdsaP256Signature;ecdsa-p256
pub use auth::EcdsaP384Keypair;ecdsa-p384
pub use auth::EcdsaP384PublicKey;ecdsa-p384
pub use auth::EcdsaP384SecretKey;ecdsa-p384
pub use auth::EcdsaP384Signature;ecdsa-p384
pub use auth::Ed25519Keypair;ed25519
pub use auth::Ed25519PublicKey;ed25519
pub use auth::Ed25519SecretKey;ed25519
pub use auth::Ed25519Signature;ed25519
pub use auth::HkdfSha256;hkdf
pub use auth::HkdfSha384;hkdf
pub use auth::HmacSha256;hmac
pub use auth::HmacSha256Tag;hmac
pub use auth::HmacSha384;hmac
pub use auth::HmacSha384Tag;hmac
pub use auth::HmacSha512;hmac
pub use auth::HmacSha512Tag;hmac
pub use auth::MlKem512;ml-kem
pub use auth::MlKem512Ciphertext;ml-kem
pub use auth::MlKem512DecapsulationKey;ml-kem
pub use auth::MlKem512EncapsulationKey;ml-kem
pub use auth::MlKem512PreparedDecapsulationKey;ml-kem
pub use auth::MlKem512PreparedEncapsulationKey;ml-kem
pub use auth::MlKem512SharedSecret;ml-kem
pub use auth::MlKem768;ml-kem
pub use auth::MlKem768Ciphertext;ml-kem
pub use auth::MlKem768DecapsulationKey;ml-kem
pub use auth::MlKem768EncapsulationKey;ml-kem
pub use auth::MlKem768PreparedDecapsulationKey;ml-kem
pub use auth::MlKem768PreparedEncapsulationKey;ml-kem
pub use auth::MlKem768SharedSecret;ml-kem
pub use auth::MlKem1024;ml-kem
pub use auth::MlKem1024Ciphertext;ml-kem
pub use auth::MlKem1024DecapsulationKey;ml-kem
pub use auth::MlKem1024EncapsulationKey;ml-kem
pub use auth::MlKem1024PreparedDecapsulationKey;ml-kem
pub use auth::MlKem1024PreparedEncapsulationKey;ml-kem
pub use auth::MlKem1024SharedSecret;ml-kem
pub use auth::MlKemError;ml-kem
pub use auth::Pbkdf2Error;pbkdf2
pub use auth::Pbkdf2Params;pbkdf2
pub use auth::Pbkdf2Sha256;pbkdf2
pub use auth::Pbkdf2Sha512;pbkdf2
pub use auth::Pbkdf2VerifyPolicy;pbkdf2
pub use auth::RsaEncryptionError;rsa
pub use auth::RsaKeyError;rsa
pub use auth::RsaKeyGenerationContract;rsa
pub use auth::RsaKeyGenerationError;rsa
pub use auth::RsaOaepProfile;rsa
pub use auth::RsaPkcs1v15Profile;rsa
pub use auth::RsaPrivateKey;rsa
pub use auth::RsaPrivateKeyParts;rsa
pub use auth::RsaPrivateOpError;rsa
pub use auth::RsaPrivateScratch;rsa
pub use auth::RsaProtocolAlgorithmError;rsa
pub use auth::RsaPssProfile;rsa
pub use auth::RsaPublicExponent;rsa
pub use auth::RsaPublicExponentPolicy;rsa
pub use auth::RsaPublicKey;rsa
pub use auth::RsaPublicKeyPolicy;rsa
pub use auth::RsaPublicOpError;rsa
pub use auth::RsaPublicScratch;rsa
pub use auth::RsaSignatureProfile;rsa
pub use auth::RsaTlsSignatureSchemes;rsa
pub use auth::RsaX509PublicKey;rsa
pub use auth::RsaX509PublicKeyAlgorithm;rsa
pub use auth::Scrypt;scrypt
pub use auth::ScryptError;scrypt
pub use auth::ScryptParams;scrypt
pub use auth::ScryptVerifyPolicy;scrypt
pub use auth::X25519Error;x25519
pub use auth::X25519PublicKey;x25519
pub use auth::X25519SecretKey;x25519
pub use auth::X25519SharedSecret;x25519
pub use auth::diag_ecdsa_p256_basepoint_blinded_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p256_final_multiply_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p256_nonce_inverse_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p256_nonce_reduce_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p256_order_mul_fixed_r_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p256_reduce_wide_order_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p256_scalar_finish_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p256_select_signing_generator_affine_limb_digest;diag and ecdsa-p256
pub use auth::diag_ecdsa_p384_basepoint_blinded_limb_digest;diag and ecdsa-p384
pub use auth::diag_ecdsa_p384_final_multiply_limb_digest;diag and ecdsa-p384
pub use auth::diag_ecdsa_p384_nonce_inverse_limb_digest;diag and ecdsa-p384
pub use auth::diag_ecdsa_p384_nonce_reduce_limb_digest;diag and ecdsa-p384
pub use auth::diag_ecdsa_p384_order_mul_fixed_r_limb_digest;diag and ecdsa-p384
pub use auth::diag_ecdsa_p384_reduce_wide_order_limb_digest;diag and ecdsa-p384
pub use auth::diag_ecdsa_p384_scalar_finish_limb_digest;diag and ecdsa-p384
pub use auth::diag_ecdsa_p384_select_signing_generator_affine_limb_digest;diag and ecdsa-p384
pub use auth::diag_ed25519_select_basepoint_cached_avx2_limb_digest;x86-64 and diag and ed25519
pub use auth::diag_ed25519_select_basepoint_cached_ifma_limb_digest;x86-64 and diag and ed25519
pub use auth::diag_hkdf_sha256_derive_portable;diag and hkdf
pub use auth::diag_hkdf_sha384_derive_portable;diag and hkdf
pub use auth::diag_hmac_sha256_verify_portable;diag and hmac
pub use auth::diag_hmac_sha384_verify_portable;diag and hmac
pub use auth::diag_hmac_sha512_verify_portable;diag and hmac
pub use auth::diag_mlkem512_keygen_secret_noise_digest;diag and ml-kem
pub use auth::diag_mlkem768_keygen_secret_noise_digest;diag and ml-kem
pub use auth::diag_mlkem1024_keygen_secret_noise_digest;diag and ml-kem
pub use auth::diag_pbkdf2_sha256_verify_portable;diag and pbkdf2
pub use auth::diag_pbkdf2_sha512_verify_portable;diag and pbkdf2
pub use auth::diag_rsa_private_select_window_power_4;diag and rsa
pub use checksum::Crc24OpenPgp;crc24
pub use checksum::Crc16Ccitt;crc16
pub use checksum::Crc16Ibm;crc16
pub use checksum::Crc32;crc32
pub use checksum::Crc32C;crc32
pub use checksum::Crc64;crc64
pub use checksum::Crc64Nvme;crc64
pub use hashes::crypto::ascon::AsconCxofCustomizationError;ascon-hash
pub use hashes::crypto::AsconCxof128;ascon-hash
pub use hashes::crypto::AsconCxof128Reader;ascon-hash
pub use hashes::crypto::AsconHash256;ascon-hash
pub use hashes::crypto::AsconXof;ascon-hash
pub use hashes::crypto::AsconXofReader;ascon-hash
pub use hashes::crypto::Blake2b;blake2b
pub use hashes::crypto::Blake2b256;blake2b
pub use hashes::crypto::Blake2b512;blake2b
pub use hashes::crypto::Blake2bParams;blake2b
pub use hashes::crypto::Blake2s128;blake2s
pub use hashes::crypto::Blake2s256;blake2s
pub use hashes::crypto::Blake2sParams;blake2s
pub use hashes::crypto::Blake3;blake3
pub use hashes::crypto::Blake3KeyedHash;blake3
pub use hashes::crypto::Blake3XofReader;blake3
pub use hashes::crypto::Cshake256;sha3
pub use hashes::crypto::Cshake256XofReader;sha3
pub use hashes::crypto::Sha3_224;sha3
pub use hashes::crypto::Sha3_256;sha3
pub use hashes::crypto::Sha3_384;sha3
pub use hashes::crypto::Sha3_512;sha3
pub use hashes::crypto::Shake128;sha3
pub use hashes::crypto::Shake128XofReader;sha3
pub use hashes::crypto::Shake256;sha3
pub use hashes::crypto::Shake256XofReader;sha3
pub use hashes::crypto::Sha224;sha2
pub use hashes::crypto::Sha256;sha2
pub use hashes::crypto::Sha384;sha2
pub use hashes::crypto::Sha512;sha2
pub use hashes::crypto::Sha512_256;sha2
pub use hashes::fast::RapidBuildHasher;alloc and rapidhash
pub use hashes::fast::RapidHasher;alloc and rapidhash
pub use hashes::fast::RapidHash;rapidhash
pub use hashes::fast::RapidHash128;rapidhash
pub use hashes::fast::RapidHashFast64;rapidhash
pub use hashes::fast::RapidHashFast128;rapidhash
pub use hashes::fast::Xxh3;xxh3
pub use hashes::fast::Xxh3_128;xxh3
pub use hashes::fast::Xxh3BuildHasher;alloc and xxh3
pub use hashes::fast::Xxh3Hasher;alloc and xxh3
pub use traits::Aead;aegis256 or aes-gcm-siv or aes-gcm or ascon-aead or chacha20poly1305 or xchacha20poly1305
pub use traits::Checksum;
pub use traits::ChecksumCombine;
pub use traits::ConstantTimeEq;
pub use traits::Kem;
pub use traits::Mac;
pub use traits::VerificationError;
pub use traits::ct;
pub use traits::Digest;ascon-hash or blake2b or blake2s or blake3 or rapidhash or sha2 or sha3 or xxh3
pub use traits::FastHash;ascon-hash or blake2b or blake2s or blake3 or rapidhash or sha2 or sha3 or xxh3
pub use traits::Xof;ascon-hash or blake2b or blake2s or blake3 or rapidhash or sha2 or sha3 or xxh3

Modules§

aeadaegis256 or aes-gcm-siv or aes-gcm or ascon-aead or chacha20poly1305 or xchacha20poly1305
Authenticated encryption with associated data foundations.
authargon2 or ecdsa-p256 or ecdsa-p384 or ed25519 or hkdf or hmac or kmac or ml-kem or phc-strings or rsa or scrypt or x25519
Authentication and key-derivation primitives.
checksumcrc16 or crc24 or crc32 or crc64
High-performance CRC checksums.
hashesascon-hash or blake2b or blake2s or blake3 or rapidhash or sha2 or sha3 or xxh3
Cryptographic digests and fast non-cryptographic hashes.
platform
CPU detection and capability reporting.
prelude
Trait-first imports for rscrypto user code.
traits
Core cryptographic traits for rscrypto.

Structs§

DisplaySecret(aegis256 or aes-gcm-siv or aes-gcm or ascon-aead or blake3 or chacha20poly1305 or ecdsa-p256 or ecdsa-p384 or ed25519 or ml-kem or x25519 or xchacha20poly1305) and (aegis256 or aes-gcm-siv or aes-gcm or ascon-aead or chacha20poly1305 or ecdsa-p256 or ecdsa-p384 or ed25519 or ml-kem or x25519 or xchacha20poly1305)
Explicit opt-in wrapper for displaying secret key bytes as hex.
SecretBytes
Owned secret bytes that zeroize on drop.

Enums§

InvalidHexError(aegis256 or aes-gcm-siv or aes-gcm or ascon-aead or blake3 or chacha20poly1305 or ecdsa-p256 or ecdsa-p384 or ed25519 or ml-kem or x25519 or xchacha20poly1305) and (aegis256 or aes-gcm-siv or aes-gcm or ascon-aead or chacha20poly1305 or ecdsa-p256 or ecdsa-p384 or ed25519 or ml-kem or x25519 or xchacha20poly1305)
Hex decoding error.

Functions§

diag_curve25519_conditional_swapdiag and x25519 and (ed25519 or x25519)