Overview
The Hashing module provides cryptographically secure hash functions, hash-to-curve implementations compliant with RFC 9380, HMAC functions, and key derivation utilities. All functions are designed for constant-time operation and resistance to side-channel attacks.
- RFC 9380 compliant hash-to-curve implementation
- Constant-time HMAC operations
- Multiple hash function support (SHA-256, SHA-512, BLAKE3)
- Secure key derivation functions (HKDF, PBKDF2)
- Domain separation for security
Hash-to-Curve (RFC 9380)
RFC 9380 compliant hash-to-curve implementation for mapping arbitrary data to elliptic curve points.
Basic Hash-to-Curve
use forge_ec::{Point, hashing::hash_to_curve};
fn hash_to_curve_example() -> Result<(), Box> {
// Hash arbitrary data to a curve point
let message = b"Hello, Forge EC!";
let domain_separator = b"FORGE_EC_DEMO";
// Hash to curve point (RFC 9380 compliant)
let point = hash_to_curve(message, domain_separator)?;
println!("Hashed to point: {:?}", point);
// The same input always produces the same point
let point2 = hash_to_curve(message, domain_separator)?;
assert_eq!(point, point2);
// Different domain separator produces different point
let point3 = hash_to_curve(message, b"DIFFERENT_DOMAIN")?;
assert_ne!(point, point3);
Ok(())
}