Skip to main content

Crate libvctrl_sha512

Crate libvctrl_sha512 

Source
Expand description

Zero-dependency cryptographic primitives: SHA-512, HMAC-SHA512, HKDF-SHA512, and optional SHA-384.

§Why this crate exists

libvctrl_sha512 provides a pure Rust, no_std-compatible implementation of several widely used cryptographic algorithms. It is designed to serve as the content-addressing and message-authentication backbone for the larger libvcrtl version control system, while remaining usable as a standalone cryptography crate.

The implementation prioritizes:

  • Auditability — no external dependencies and readable, well-structured code.
  • Security — constant-time verification, zeroization of intermediate state.
  • Performance — aggressive inlining, specialized block processing, and an optional opt_size feature for size-constrained builds.

§Module organization

  • sha512 — SHA-512 hash function.
  • hmac — HMAC keyed-hash message authentication code instantiated with SHA-512.
  • hkdf — HKDF key derivation function instantiated with SHA-512.
  • utils — shared byte-order and verification helpers.
  • sha384 — optional SHA-384 implementation behind the sha384 feature.

The HMAC and HKDF modules are generated using the exported macros impl_hmac! and impl_hkdf!, which allow downstream crates to instantiate these algorithms with other hash functions if needed.

§Examples

Compute a SHA-512 digest:

use libvctrl_sha512::Hash;

let digest = Hash::hash(b"hello world");
assert_eq!(digest.len(), 64);

Compute an HMAC-SHA512 authentication tag:

use libvctrl_sha512::HMAC;

let tag = HMAC::mac(b"message", b"secret-key");
assert_eq!(tag.len(), 64);

Re-exports§

pub use sha512::Hash;
pub use hmac::HMAC;
pub use hkdf::HKDF;
pub use utils::BLOCKBYTES;
pub use utils::BYTES;

Modules§

hkdf
HKDF implementation generated for SHA-512.
hmac
HMAC implementation generated for SHA-512.
sha384
Optional SHA-384 implementation.
sha512
SHA-512 hash function implementation.
utils
Shared byte-order and verification helpers.

Macros§

impl_hkdf
Defines an HKDF (HMAC-based Extract-and-Expand Key Derivation Function) type based on the provided hash struct.
impl_hmac
Defines an HMAC (Hash-based Message Authentication Code) type based on the provided hash struct.