pub struct Sha256 { /* private fields */ }Expand description
Streaming SHA-256 hash context (FIPS 180-4, Section 6.2).
Internal state and partial input blocks are automatically zeroized on drop. Once finalized,
further Sha256::try_update or Sha256::try_finalize_into calls are rejected until
Sha256::reset is called.
Implementations§
Source§impl Sha256
impl Sha256
Sourcepub const DIGEST_LEN: usize = 32
pub const DIGEST_LEN: usize = 32
Output digest length in bytes (32 bytes / 256 bits).
Sourcepub const MAX_MESSAGE_BYTES: u64
pub const MAX_MESSAGE_BYTES: u64
Maximum supported message length in bytes (2^61 - 1, matching FIPS 180-4 §5.1.1’s
strict < 2^64 bits ceiling without bit-counter wraparound).
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new SHA-256 hasher initialized to FIPS 180-4 Section 5.3.3 H^(0).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets this hasher in place to FIPS 180-4 Section 5.3.3 H^(0) after zeroizing prior state.
Sourcepub fn try_update(&mut self, data: &[u8]) -> Result<()>
pub fn try_update(&mut self, data: &[u8]) -> Result<()>
Absorbs data into the SHA-256 compression state, checking post-finalize misuse and the
FIPS 180-4 Section 5.1.1 < 2^64 bits (MAX_MESSAGE_BYTES) ceiling.
Sourcepub fn update(&mut self, data: &[u8])
pub fn update(&mut self, data: &[u8])
Absorbs data into the SHA-256 compression state.
Prefer Self::try_update when callers need fallible checking of the 2^61 - 1 byte
FIPS 180-4 message limit or post-finalize misuse.
Sourcepub fn try_finalize_into(&mut self, out: &mut [u8; 32]) -> Result<()>
pub fn try_finalize_into(&mut self, out: &mut [u8; 32]) -> Result<()>
Finalizes the digest directly into out, zeroizes internal state, and marks the hasher
finalized so subsequent updates or double-finalizations fail until Self::reset.
Sourcepub fn finalize_into(&mut self, out: &mut [u8; 32])
pub fn finalize_into(&mut self, out: &mut [u8; 32])
Finalizes the digest directly into out and marks the hasher finalized.
If already finalized or overflowed, zeroes out without emitting stale state.
Sourcepub fn finalize(self) -> [u8; 32]
pub fn finalize(self) -> [u8; 32]
Finalizes the hash and returns the 32-byte SHA-256 digest.
For secret-derived digests, prefer Self::finalize_into or Self::digest_into to
write directly into caller-owned zeroized storage without an intermediate return copy.
Sourcepub fn digest_into(data: &[u8], out: &mut [u8; 32])
pub fn digest_into(data: &[u8], out: &mut [u8; 32])
Computes SHA-256(data) directly into out without a by-value digest copy.
Sourcepub fn digest_chunks_into(chunks: &[&[u8]], out: &mut [u8; 32])
pub fn digest_chunks_into(chunks: &[&[u8]], out: &mut [u8; 32])
Computes SHA-256(chunks[0] || chunks[1] || ...) directly into out.
Sourcepub fn digest_chunks(chunks: &[&[u8]]) -> [u8; 32]
pub fn digest_chunks(chunks: &[&[u8]]) -> [u8; 32]
Computes SHA-256(chunks[0] || chunks[1] || ...) in one shot.