hmac-sha512
A small, self-contained implementation of SHA512, HMAC-SHA512, SHA384, and HMAC-SHA384 in Rust.
Features
- Minimal dependencies
no_stdcompatible for embedded systems- Small code size with optional size optimizations
- Optional support for the
Digesttrait from thedigestcrate - Constant-time verification for HMAC results to prevent timing attacks
Optional Features
sha384(enabled by default): Includes SHA384 and HMAC-SHA384 implementationsopt_size: Optimizes for binary size at a slight performance cost (reduces text section size by ~75% with ~16% performance hit)traits: Enables support for theDigesttrait from thedigestcratetraits09: Support fordigestcrate v0.9.xtraits010: Support fordigestcrate v0.10.x
Usage
Add this to your Cargo.toml:
[]
= "1.1.6"
SHA512 Hashing
use Hash;
// Compute SHA512 hash
let hash = hash;
HMAC-SHA512
use HMAC;
// Compute HMAC-SHA512
let mac = HMACmac;
// Verify HMAC-SHA512
let expected = ; // Replace with actual expected MAC
let is_valid = HMACverify;
SHA384 Hashing (when enabled)
use Hash;
// Compute SHA384 hash
let hash = hash;
HMAC-SHA384 (when enabled)
use HMAC;
// Compute HMAC-SHA384
let mac = HMACmac;
// Verify HMAC-SHA384
let expected = ; // Replace with actual expected MAC
let is_valid = HMACverify;
With Digest Trait (when enabled)
use Hash;
use Digest; // Requires the digest crate
let mut hasher = new;
hasher.update;
let result = hasher.finalize;
Building and Testing
# Build with default features
# Build with release optimizations
# Build with specific features
# Run all tests
License
This project is licensed under the ISC License.