sha2
Pure Rust implementation of the SHA-2 hash function family (SHA-224/256/384/512) with hardware-accelerated backends.
Repository Health
Technical Analysis
sha2 is the RustCrypto project’s pure-Rust implementation of the SHA-2 family of cryptographic hash functions, covering SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256. It implements the standard digest crate traits, so it drops into any Rust codebase that already speaks the RustCrypto hashing ecosystem (HMAC, PBKDF2, signature schemes, and so on) without bespoke glue code.
The crate is no_std by default, making it usable in embedded and WebAssembly targets as well as regular server and CLI applications, and it automatically selects hardware-accelerated backends (x86 SHA-NI/AVX2, AArch64 SHA2/SHA3 extensions, experimental RISC-V Zknh) at compile time with a portable software fallback when no acceleration is available.
What You Get
- All six SHA-2 variants: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256
- A unified
Digesttrait API shared with the rest of the RustCrypto hashing ecosystem - Automatic hardware-accelerated backend selection (x86 SHA-NI/AVX2, AArch64 sha2/sha3, LoongArch64 asm, WASM simd128) with a portable
softfallback no_stdsupport by default for embedded, kernel, and WebAssembly targets- Optional
oidfeature exposing ASN.1 object identifiers for each algorithm, andzeroizesupport for secure state wiping
Common Use Cases
- Computing file or blob checksums and content-addressable hashes in Rust services and CLI tools
- Deriving keys or verifying integrity as a building block inside HMAC, PBKDF2, TLS, or blockchain implementations
- Hashing in
no_stdfirmware or WebAssembly modules where a pure-Rust, dependency-light implementation is required - Interoperating with other RustCrypto crates (digest, hmac, pbkdf2, rsa) that expect the shared
Digest/FixedOutputtraits
Under The Hood
Architecture — lib.rs defines the six public hasher types (Sha224/Sha256/Sha384/Sha512/Sha512_224/Sha512_256) via the digest::buffer_fixed! macro, wrapping two shared block-level core types in block_api.rs (Sha256VarCore, Sha512VarCore) that implement the digest crate’s UpdateCore/VariableOutputCore/BlockSizeUser traits. Compression is delegated to compress256/compress512 functions defined in sha256.rs/sha512.rs, which use cfg-if to select, at compile time, one of several backend modules under src/sha256/ and src/sha512/ (soft, x86_sha, aarch64_sha2, aarch64_sha3, x86_avx2, riscv_zknh, loongarch64_asm, wasm32_simd128); initial hash state constants live in consts.rs. Tech Stack — pure Rust, edition 2024, MSRV 1.85, no_std by default; the only mandatory dependencies are digest (0.11, the shared RustCrypto hashing-trait crate) and cfg-if, with cpufeatures pulled in on x86/x86_64/aarch64 for runtime backend detection; optional alloc, zeroize, and oid Cargo features gate extra functionality, and several accelerated backends (e.g. x86_sha.rs, sha512/soft/unroll.rs) use targeted unsafe blocks for SIMD/asm intrinsics. Code Quality — tests/mod.rs drives NIST known-answer-test vectors from tests/data through digest’s own new_test!/fixed_reset_test and hash_serialization_test! macros for all six variants, plus dedicated sha256_rand/sha512_rand tests that hash 16 MiB of pseudorandom data through the incremental API against fixed expected digests — a strong regression net across backend implementations; the crate also enforces #![warn(missing_docs, unreachable_pub)] and ships benches under benches/mod.rs. API Design — the crate exposes the same ergonomic Digest trait shared across the RustCrypto ecosystem, offering both a one-shot Sha256::digest(data) call and an incremental new()/update()/finalize() pattern with no required configuration, so getting started needs only an import and a single method call, and each of the six algorithms is reachable under one canonical, consistently named type.
Used by 75 apps in this directory
Stalwart
Collaboration
All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.
Stalwart
Collaboration
All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.
Stirling PDF
Digital Signiture · Productivity
The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.
Svix
Automation · Developer Tools
Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.
Tabby
AI Code Assistants
Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.
tabularis
Databases · Developer Tools
Open-source desktop SQL workspace with built-in PostgreSQL, MySQL, and SQLite drivers, SQL notebooks, a visual query builder, and a built-in MCP server for AI agents like Claude and Cursor.
Temps
Analytics · Devops · Monitoring
A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.
Temps
Analytics · Devops · Monitoring
A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.
TensorZero
Ab Testing Experimentation · AI Development · Monitoring
TensorZero unifies the LLM gateway, observability, evaluation, optimization, and experimentation stack behind a single OpenAI-compatible API, built in Rust for sub-millisecond p99 latency.