nx_sha256_workspace_t77.nx
buildroot/runtime/nx_sha256_workspace_t77.nx
about
sha256.nx -- SHA-256 in pure NishiLang (Phase G9, FIPS 180-4).
Canonical: this is the substrate-wide canonical SHA-256
implementation per [[feedback-no-tool-proliferation-bit-level]].
HMAC-SHA256 / HKDF-SHA256 / DRBG-SHA256 etc. compose THIS file's
sha256 primitive; they're distinct primitives (different specs:
FIPS 198-1 HMAC, RFC 5869 HKDF, NIST SP 800-90A DRBG) but all
share THIS sha256 as their SHA-256 backbone. Re-implementing
the SHA-256 K-table or round function inline is refused.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/nist/fips_180_4
Used for: content-addressed build artifacts (F6), session tokens
(rand.nx + sha256 = HMAC), TLS 1.3 handshake (G15), Git-style
object addressing, reproducible-build attestation.
Implementation follows FIPS 180-4 section 6.2 exactly -- no
precomputed tables beyond the standard K[0..63] round constants.
Pure i64 arithmetic; all 32-bit ops masked with 0xFFFFFFFF.
API:
sha256_init(*ctx) — reset a fresh Sha256 context
sha256_update(*ctx, *u8 bytes, len) — feed input chunks
sha256_final(*ctx, *u8 out32) — write 32-byte digest
sha256_digest(*u8 bytes, len, *u8 out32) — one-shot convenience
The context is ~128 bytes: 8 words of hash state + 64-byte partial
block buffer + 8-byte length counter + an index. Caller allocates
(stack or heap) and passes pointer.
nx_safety_envelope: (schema: nishi-library/seeds/safety-critical-standards.toml)
intended_use: "SHA-256 cryptographic hash -- HMAC + HKDF
+ content-addressed storage + digital
signatures + Wheeler-DDC integrity chain"
sil_target: SIL3 (integrity primitive; collision or
preimage attack = signature forgery)
asil_target: QM
dal_target: DAL B
iec_62304_class: B
dependencies 2 imports · 1 importers
imports: nx_syscalls.nxnx_bits.nx
imported by: nx_sha256_workspace_gate_t77.nx
structs
| 62 | struct Sha256 { |
consts
| 60 | const K_MAGIC_536870912: i64 = 536870912 |
| 99 | const M32: i64 = 0xFFFFFFFF |
| 477 | const SHA256_WORD_ALIGN: i64 = 8 |
| 478 | const SHA256_BLOCK_BYTES: i64 = 64 |
| 479 | const SHA256_ROUND_WORDS: i64 = 64 |
| 480 | const SHA256_WIDE_WORD: i64 = 8 |
| 481 | const SHA256_PACKED_WORD: i64 = 4 |
| 482 | const SHA256_STATE_WORDS: i64 = 8 |
| 483 | const SHA256_DIGEST_BYTES: i64 = 32 |
| 484 | const SHA256_SIGNED_MAX: i64 = 9223372036854775807 |
| 485 | const SHA256_BITS_PER_BYTE: i64 = 8 |
| 486 | const SHA256_E_INPUT: i64 = 0-1 |
| 487 | const SHA256_E_WORKSPACE: i64 = 0-2 |
| 488 | const SHA256_E_MAPPING: i64 = 0-3 |
| 489 | const SHA256_E_RELEASE: i64 = 0-4 |
functions
| 103 | func rotr32(x: i64, n: i64) -> i64 {
calls 1: nx_bits_rotr32 |
| 107 | func shr32(x: i64, n: i64) -> i64 { |
| 114 | func sha256_k(i: i64) -> i64 {
called by 1: sha256_seed_allocated |
| 184 | func blk_byte(c: *Sha256, n: i64) -> i64 {
called by 1: blk_word |
| 190 | func blk_set_byte(c: *Sha256, n: i64, v: i64) -> i64 { |
| 198 | func blk_word(c: *Sha256, i: i64) -> i64 { |
| 212 | func sha256_compress_ni(c: *Sha256) -> i64 {
called by 1: sha256_compress |
| 231 | func sha256_compress_ni_blocks(c: *Sha256, blocks: i64, nblk: i64) -> i64 {
called by 1: sha256_update |
| 253 | func sha256_compress(c: *Sha256) -> i64 { |
| 316 | func sha256_seed_allocated(c: *Sha256) -> i64 { |
| 343 | func sha256_init(c: *Sha256) -> i64 { |
| 354 | func sha256_update(c: *Sha256, bytes: *u8, n: i64) -> i64 {
called by 3: mainsha256_digestsha256_digest_workspace calls 3: sha256_compress_ni_blocksblk_set_bytesha256_compress |
| 384 | func sha256_final(c: *Sha256, out: *u8) -> i64 { |
| 454 | func sha256_destroy(c: *Sha256) -> i64 { |
| 463 | func sha256_digest(bytes: *u8, n: i64, out: *u8) -> i64 {
called by 2: sg_vectormain calls 6: sys_mmapsha256_initsha256_updatesha256_finalsha256_destroysys_munmap |
| 491 | func sha256_context_aligned_bytes() -> i64 { |
| 494 | func sha256_workspace_bytes() -> i64 { |
| 497 | func sha256_checked_input(bytes: *u8, n: i64, out: *u8) -> i64 { |
| 504 | func sha256_ranges_overlap(a: i64, an: i64, b: i64, bn: i64) -> i64 {
called by 1: sha256_digest_workspace |
| 510 | func sha256_init_workspace(workspace: *u8, capacity: i64) -> i64 { |
| 521 | func sha256_digest_workspace(bytes: *u8, n: i64, out: *u8, workspace: *u8, capacity: i64) -> i64 { |
| 535 | func sha256_digest_mapping_native(bytes: *u8, n: i64, out: *u8, mapping: i64) -> i64 {
called by 2: mainsha256_digest_checked_native calls 3: sha256_workspace_bytessha256_digest_workspacesys_munmap |
| 544 | func sha256_digest_checked_native(bytes: *u8, n: i64, out: *u8) -> i64 { |