Shared Merkle–Damgård framing for the SHA family (P3-1).
SHA-1 and SHA-256 differ only in state size and compression function;
the 64-byte block buffering, 0x80 padding, and big-endian bit-length
trailer are identical and live here. Subclasses implement compress
over one 64-byte block.
The usage model matches core's Crc32: feed chunks with add, then
finish once. copy snapshots the running state, needed by KDFs that
take intermediate digests mid-stream (RAR4's, via P3-5) and by HMAC's
precomputed pad states.
Constructors
- BlockHash()
- Creates a hash in its initial state.
- BlockHash.fromState(BlockHash source)
-
Copies the running state of
source(buffered bytes included).
Properties
- digestSize → int
-
Digest length in bytes (20 for SHA-1, 32 for SHA-256).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
Uint8List chunk, [int start = 0, int? end]) → void -
Updates the hash with
chunk[start..end). -
compress(
Uint8List block, int offset) → void -
Compresses the 64 bytes at
block[offset..offset+64)into the state. -
copy(
) → BlockHash - Returns an independent copy of the running state.
-
finish(
) → Uint8List - Pads, compresses the final block(s), and returns the digest. The hash cannot be updated afterwards; snapshot with copy first to continue a running stream.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
writeDigest(
Uint8List out) → void -
Writes the state words to
outbig-endian.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited