Module sha2
The SHA-2 cryptographic hash functions.
sha2 provides implementations of the SHA-2 family of cryptographic hash functions.
The SHA-2 family includes six hash functions: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256. These are cryptographic hash functions standardized by NIST, producing fixed-size digests from arbitrary input data. SHA-256 and SHA-512 are the most commonly used variants.
The crate implements the Digest trait,
providing both one-shot hashing via Digest::digest
and incremental hashing via Digest::new, Digest::update, and Digest::finalize.
Examples
Basic SHA-256 hashing:
use ;
let result = digest;
println!;
Incremental hashing:
use ;
let mut hasher = new;
hasher.update;
hasher.update;
let result = hasher.finalize;
// Verify it matches one-shot hashing
assert_eq!;
Using different SHA-2 variants:
use ;
let sha512_result = digest;
println!;
Type Aliases
- Sha224 SHA-224 hasher.
- Sha256 SHA-256 hasher.
- Sha384 SHA-384 hasher.
- Sha512 SHA-512 hasher.
- Sha512_224 SHA-512/224 hasher.
- Sha512_256 SHA-512/256 hasher.