F1.2: std.hash zero-heap [64]u8 hex API + chunked file + pinned vectors

Make the SHA-256 digest path allocation-free (foundation heap-discipline):

- final() and sha256_hex() now return the 64-char lowercase hex digest as
  a [64]u8 by value on the stack; the cstring(64) heap allocation is gone.
- sha256_file() streams the file in fixed 64KB stack chunks via open_file/
  File.read/File.close (defer-closed on every path) instead of slurping it
  with read_file; peak memory is O(chunk), not O(filesize).

Tests (compare via a zero-copy string view over the [64]u8):
- 0710 updated to the by-value API (output unchanged).
- 0711 known-answer vectors: "", "abc", NIST-56/112, padding boundaries
  {0,55,56,57,63,64,65,119,120}, and 1000 / 1,000,000 'a' repeats, each
  pinned to its published digest (cross-checked with shasum -a 256).
- 0712 streaming equivalence (one-shot == byte-at-a-time == split-mid-block
  == split-on-boundary) plus sha256_file(temp) == in-memory digest.

src/ untouched. zig build && zig build test && tests/run_examples.sh green.
This commit is contained in:
agra
2026-06-04 00:08:46 +03:00
parent ee1e097335
commit f9bc593bb8
10 changed files with 232 additions and 19 deletions

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,15 @@
empty: ok
abc: ok
nist-56: ok
nist-112: ok
len-0: ok
len-55: ok
len-56: ok
len-57: ok
len-63: ok
len-64: ok
len-65: ok
len-119: ok
len-120: ok
a-1000: ok
a-1000000: ok

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,6 @@
oneshot-pinned: ok
byte-at-a-time: ok
split-mid-block: ok
split-on-boundary: ok
file-eq-memory: ok
file-pinned: ok