digest

Core RustCrypto traits for cryptographic hash functions and message authentication codes

Library
Cargo
v0.11.3
751stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
79/100Good
Development Activity92
Maintenance52
Community84
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture90
Code Quality88
Innovation80
Learning Curve66

digest is the foundational trait crate of the RustCrypto ecosystem, defining the interfaces that cryptographic hash functions and message authentication codes implement. Rather than providing a specific algorithm, it specifies the common Digest, Update, FixedOutput, ExtendableOutput, and MAC traits so that every hasher, from SHA-256 to BLAKE2 to SHA-3, presents the same update/finalize API.

This shared abstraction lets application and library code be written generically over any hash function, swap algorithms without rewrites, and compose hashing into higher-level protocols. It is a no_std crate depending only on crypto-common, with optional features for block-level APIs, MAC support, zeroization, and OID metadata.

What You Get

  • The high-level Digest trait plus Update, FixedOutput, and Reset building blocks
  • Extendable-output-function (XOF) traits for algorithms like SHAKE
  • Message authentication code (MAC) traits including constant-time output comparison
  • A block-level API for implementing new hash functions with less boilerplate
  • Optional zeroize, const-oid, and blobby-based test-vector support

Common Use Cases

  • Writing functions generic over any hash algorithm via the Digest trait bound
  • Implementing a new cryptographic hash function against a standard interface
  • Building MAC-based authentication with a uniform verification API
  • Swapping hash algorithms in a protocol without changing call sites

Under The Hood

Architecture - The crate layers its abstractions: digest.rs defines the high-level object-safe Digest trait built from the lower-level Update/FixedOutput/Reset traits in lib.rs, mac.rs adds authentication-code traits with constant-time output types, xof_fixed.rs covers extendable-output functions, and block_api.rs plus buffer_macros.rs provide a reusable block-processing scaffold (backed by block-buffer) for implementers. A dev.rs/dev/ module supplies test-vector harnesses.

Tech Stack - Rust edition 2024 (MSRV 1.85), one crate in the RustCrypto/traits Cargo workspace. Its only required dependency is crypto-common; optional dependencies include block-buffer, const-oid, zeroize, ctutils, and blobby, each behind a feature flag, and it is no_std with an opt-in alloc feature.

Code Quality - As a keystone crate depended on by nearly the entire Rust hashing ecosystem, it is held to a high bar: it ships dev macros and blobby-driven known-answer test infrastructure (tests/, src/dev/), uses sha2 as a dev-dependency to validate the traits end to end, and follows RustCrypto’s strict MSRV and API-stability conventions.

API Design - The design is deliberately minimal and composable: most users only touch Digest::new/update/finalize (usually re-exported by a concrete hash crate like sha2), while implementers pick the exact sub-traits their algorithm supports. Generic bounds like impl Digest make algorithm-agnostic code natural; the learning curve is mainly in the generic-array/typenum output types.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search