SHA-256¶
Module: Std::Hash::Sha256
256-bit SHA-2 cryptographic hash.
Summary¶
Constants¶
| Constant | Value |
|---|---|
BlockSize |
64 |
DigestSize |
32 |
Description¶
SHA-256 is a 256-bit hash function from the SHA-2 family, published by NIST in 2001. It uses a Merkle–Damgård construction with a Davies–Meyer compression function, processing 512-bit blocks through 64 rounds. The algorithm operates on 32-bit words with bitwise operations, modular addition, and eight working state variables.
SHA-256 remains cryptographically secure and is widely recommended as a general-purpose hash function.
The Hash method takes a char8[] and returns a hex-encoded digest string.
Example¶
import Std::Hash::Sha256;
func Main() {
let digest = Sha256::Hash(c8"abc");
PrintLine(digest);
// ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
}
Test Vectors¶
| Input | Expected Digest |
|---|---|
c8"" |
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 |
c8"abc" |
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad |
c8"Hello, World!" |
dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f |