6.7. SHA-256

FIPS 180-4 SHA-256 in pure daslang: one-shot hashing of strings and byte arrays to lowercase hex, plus a streaming init/update/final state for data that arrives in pieces. Content addressing and integrity checks need a collision-resistant hash; the builtin 64-bit hash is not one.

6.7.1. Structures

Sha256State

Streaming hash state. Create with sha256_init; do not mutate directly.

Fields:
  • h : uint[8] - Current hash values (eight 32-bit words).

  • buf : uint8[64] - Pending input block.

  • bufLen : int - Bytes buffered in the pending block.

  • totalBytes : uint64 - Total bytes absorbed so far.

6.7.2. One-shot hashing

6.7.2.1. sha256_hex

sha256_hex(data: array<uint8> ): string

SHA-256 of a byte array, lowercase hex.

Arguments:
  • data : array<uint8>

sha256_hex(s: string ): string

6.7.3. Streaming

sha256_final(st: Sha256State ): uint[8]

Apply FIPS 180-4 padding and return the digest as eight big-endian words. The state is consumed — reuse requires a fresh sha256_init.

Arguments:
sha256_hex_digest(digest: uint const[8] ): string

Digest words → 64-char lowercase hex.

Arguments:
  • digest : uint[8]

sha256_init(): Sha256State

Fresh streaming state (FIPS 180-4 initial hash values).

6.7.3.1. sha256_update

sha256_update(st: Sha256State; b: uint8 )

Absorb one byte.

Arguments:
sha256_update(st: Sha256State; data: array<uint8> )