std::cryptoCryptographic hashing and utilities.
Provides SHA-2 hash functions (SHA-256, SHA-384, SHA-512), HMAC-SHA-256 message authentication, secure random byte generation, and constant-time comparison.
import std::crypto::crypto;
import std::encoding::hex;
fn main() {
let data: bytes = bytes::new();
data.push(65); // 'A'
let hash = crypto.sha256(data);
println(hex.encode(hash));
}
sha256Compute the SHA-256 hash of data, returning a 32-byte bytes value.
sha384Compute the SHA-384 hash of data, returning a 48-byte bytes value.
sha512Compute the SHA-512 hash of data, returning a 64-byte bytes value.
hmac_sha256Compute HMAC-SHA-256 with the given key and data.
Returns a 32-byte bytes value.
random_bytesGenerate len cryptographically random bytes.
constant_time_eqCompare two bytes values in constant time.
Returns true if they are equal (same length and same content).
Always runs in time proportional to the length to avoid timing leaks.