F1.1: std.hash — streaming SHA-256 in library/modules/std/hash.sx
Add a pure-sx streaming SHA-256 (FIPS 180-4) stdlib module, importable as `#import "modules/std/hash.sx";`. All 32-bit word arithmetic is done in s64 and masked back with `& MASK32`, so digests are deterministic and platform-independent — no shelling out, no native crypto. API: - init() -> Sha256 (by-value *self pattern) - update(*Sha256, string) (multi-block + partial-block buffering) - final(*Sha256) -> string (32-byte digest as lowercase hex) - sha256_hex(string) -> string (one-shot) - sha256_file([:0]u8) -> ?string (digest of a file via fs.read_file) Verified against FIPS/NIST known-answer vectors and `shasum -a 256`: "" , "abc", the 56- and 112-byte multi-block vectors, 1000×'a', and the 64/65-byte block boundaries; chunked update() matches the one-shot call. examples/0710-modules-sha256.sx pins the KAT vectors + the streaming invariant; gate green (zig build, zig build test, run_examples 370/0/0/0).
This commit is contained in:
1
examples/expected/0710-modules-sha256.exit
Normal file
1
examples/expected/0710-modules-sha256.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/0710-modules-sha256.stderr
Normal file
1
examples/expected/0710-modules-sha256.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
4
examples/expected/0710-modules-sha256.stdout
Normal file
4
examples/expected/0710-modules-sha256.stdout
Normal file
@@ -0,0 +1,4 @@
|
||||
empty: ok
|
||||
abc: ok
|
||||
multi: ok
|
||||
stream-eq-oneshot: ok
|
||||
Reference in New Issue
Block a user