hmac

Generic, pure-Rust implementation of Hash-based Message Authentication Code (HMAC)

Library
Cargo
v0.13.0
375 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
47 /100 Fair
Development Activity 44
Maintenance 0
Community 64
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
82 /100 Excellent
Architecture 86
Code Quality 88
Innovation 80
Learning Curve 75

hmac is RustCrypto’s generic implementation of HMAC (Hash-based Message Authentication Code), the algorithm underlying JWT signing, TLS handshakes, and countless API request-signing schemes. Rather than baking in one hash function, it is generic over any hash implementing the digest crate’s EagerHash trait, so the same Hmac<D> type works with SHA-256, SHA-512, SHA-3, or any other RustCrypto digest by swapping a type parameter.

The crate lives in the RustCrypto/MACs monorepo alongside sibling MAC algorithms (CMAC, PMAC, CBC-MAC, Retail MAC, Belt-MAC), all built on the same shared digest/crypto-common trait foundation that underlies the wider RustCrypto ecosystem. It is #![no_std], making it usable in embedded and constrained environments, and is one of the most widely depended-upon crates in the Rust ecosystem for authenticated message integrity.

What You Get

  • A Hmac<D> type generic over any hash implementing digest::block_api::EagerHash, so switching hash functions is a type-parameter change
  • SimpleHmac and SimpleHmacReset variants for hash functions that don’t implement the EagerHash block-level optimization
  • #![no_std] support for embedded and constrained targets with no heap or OS dependency
  • An optional zeroize feature to securely wipe key material from memory when a Hmac instance is dropped
  • A Reset variant (HmacReset) allowing an HMAC instance to be reused across multiple messages without reallocating state

Common Use Cases

  • Signing and verifying JWTs using the HS256/HS384/HS512 algorithm family
  • Implementing HMAC-based request signing for API authentication (e.g. AWS SigV4-style signing schemes)
  • TLS and other cryptographic protocol implementations that need HMAC as a building block for key derivation (HKDF) or record authentication
  • Embedded firmware needing message authentication without a heap allocator, via the crate’s no_std support

Under The Hood

Architecture - The hmac crate lives in the RustCrypto/MACs workspace (hmac/) alongside sibling crates (cmac/, pmac/, cbc-mac/, retail-mac/, belt-mac/) that share the same digest/crypto-common trait foundation used across all of RustCrypto’s hash and cipher crates. Internally, src/lib.rs defines the public Hmac<D>/HmacReset<D> types via the digest::buffer_fixed! macro, which wires up the generic block-buffering logic once and reuses it for both variants; block_api.rs implements the actual inner/outer-pad HMAC construction at the block level for hashes that support eager block processing, while simple.rs/simple_reset.rs provide a fallback implementation for hashes that don’t.

Tech Stack - Pure Rust, #![no_std], with a single runtime dependency on the digest crate (itself part of the RustCrypto trait ecosystem). Rust edition 2024, MSRV 1.85. Dev-dependencies pull in concrete hash implementations (md-5, sha1, sha2, streebog) purely for testing against known test vectors, not as runtime dependencies of the published crate.

Code Quality - The crate has a dedicated tests/ directory for integration-level test-vector verification in addition to a small, focused src/ implementation (548 total lines across lib.rs, block_api.rs, simple.rs, simple_reset.rs, utils.rs), consistent with RustCrypto’s project-wide convention of validating primitives against published standard test vectors (RFC 2104, FIPS 198-1). Licensed under dual MIT/Apache-2.0, the standard RustCrypto licensing convention, with LICENSE-MIT and LICENSE-APACHE both present in the crate directory.

API Design - The API follows the shared digest/crypto-common trait conventions used across all RustCrypto crates: construct via KeyInit::new_from_slice, feed data via the Mac trait’s update, then finalize via finalize/verify_slice. This trait-based consistency means learning hmac’s API transfers directly to every other RustCrypto MAC or hash crate, at the cost of needing some familiarity with the digest crate’s trait hierarchy up front.

Used by 19 apps in this directory

TypeScript
78%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,733

Open-source AI agent monitoring that catches what will break next before your users do.

View details
87
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 78%
Python 11%
Rust 11%
Updated 6 days ago
Rust
100%
Other

Meilisearch

Search

59,644

Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.

View details
90
Repo Health
88
Technical
67
Dependency
Built with
Rust 100%
Updated 6 days ago
Rust
95%
Apache 2.0

obscura

AI Agents · Developer Tools

29,203

A lightweight, stealthy headless browser written in Rust — drop-in compatible with Puppeteer and Playwright, built for AI agents and web scraping at scale.

View details
83
Repo Health
79
Technical
72
Dependency
Built with
Rust 95%
Updated 1 weeks ago
Rust
97%
Apache 2.0

codex

AI Code Assistants · Developer Tools

130,715

OpenAI's open-source CLI coding agent that reads, edits, and runs code in your terminal using natural language prompts.

View details
89
Repo Health
80
Technical
75
Dependency
Built with
Rust 97%
Updated 6 days ago
TypeScript
90%
MIT

OpenClaw

AI Agents · AI Assistants

392,894

An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.

View details
88
Repo Health
88
Technical
66
Dependency
Built with
TypeScript 90%
Updated 5 days ago
Rust
87%
Apache 2.0

OpenShell

AI Agents · Developer Tools

18,930

The safe, private runtime that lets autonomous AI agents operate in sandboxed environments governed by declarative YAML policies — blocking data exfiltration, credential leaks, and unauthorized network activity before they happen.

View details
84
Repo Health
81
Technical
67
Dependency
Built with
Rust 87%
Updated 5 days ago
Rust
79%
AGPL 3.0

Spacedrive

Collaboration · File Storage

39,292

One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.

View details
84
Repo Health
84
Technical
63
Dependency
Built with
Rust 79%
TypeScript 18%
Updated 2 weeks ago
Rust
66%
Apache 2.0

Temps

Analytics · Devops · Monitoring

865

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.

View details
81
Repo Health
86
Technical
66
Dependency
Built with
Rust 66%
TypeScript 33%
Updated 6 days ago
Python
73%
Apache 2.0

Unsloth

AI Assistants · AI Development

78,493

Run and fine-tune LLMs, diffusion, audio and embedding models on your own hardware, from a native desktop app, a browser UI, or a Python library.

View details
89
Repo Health
83
Technical
70
Dependency
Built with
Python 73%
TypeScript 22%
Updated 5 days ago

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