code wiki / (root) / nx_sha256_workspace_t77.nx

nx_sha256_workspace_t77.nx

buildroot/runtime/nx_sha256_workspace_t77.nx

24579 B549 linesdepth 4pulls 4 transitivereach 1 importersview sourcekind librarytopic sha256
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_bits.nx nx_sha256_workspace_t77.nx nx_sha256_workspace_gate_t77.nx

imports: nx_syscalls.nxnx_bits.nx

imported by: nx_sha256_workspace_gate_t77.nx

structs

62struct Sha256 {

consts

60const K_MAGIC_536870912: i64 = 536870912
99const M32: i64 = 0xFFFFFFFF
477const SHA256_WORD_ALIGN: i64 = 8
478const SHA256_BLOCK_BYTES: i64 = 64
479const SHA256_ROUND_WORDS: i64 = 64
480const SHA256_WIDE_WORD: i64 = 8
481const SHA256_PACKED_WORD: i64 = 4
482const SHA256_STATE_WORDS: i64 = 8
483const SHA256_DIGEST_BYTES: i64 = 32
484const SHA256_SIGNED_MAX: i64 = 9223372036854775807
485const SHA256_BITS_PER_BYTE: i64 = 8
486const SHA256_E_INPUT: i64 = 0-1
487const SHA256_E_WORKSPACE: i64 = 0-2
488const SHA256_E_MAPPING: i64 = 0-3
489const SHA256_E_RELEASE: i64 = 0-4

functions

103func rotr32(x: i64, n: i64) -> i64 {
calls 1: nx_bits_rotr32
107func shr32(x: i64, n: i64) -> i64 {
114func sha256_k(i: i64) -> i64 {
184func blk_byte(c: *Sha256, n: i64) -> i64 {
called by 1: blk_word
190func blk_set_byte(c: *Sha256, n: i64, v: i64) -> i64 {
198func blk_word(c: *Sha256, i: i64) -> i64 {
called by 1: sha256_compress calls 1: blk_byte
212func sha256_compress_ni(c: *Sha256) -> i64 {
called by 1: sha256_compress
231func sha256_compress_ni_blocks(c: *Sha256, blocks: i64, nblk: i64) -> i64 {
called by 1: sha256_update
253func sha256_compress(c: *Sha256) -> i64 {
316func sha256_seed_allocated(c: *Sha256) -> i64 {
343func sha256_init(c: *Sha256) -> i64 {
354func sha256_update(c: *Sha256, bytes: *u8, n: i64) -> i64 {
384func sha256_final(c: *Sha256, out: *u8) -> i64 {
454func sha256_destroy(c: *Sha256) -> i64 {
called by 1: sha256_digest calls 1: sys_munmap
463func sha256_digest(bytes: *u8, n: i64, out: *u8) -> i64 {
491func sha256_context_aligned_bytes() -> i64 {
494func sha256_workspace_bytes() -> i64 {
497func sha256_checked_input(bytes: *u8, n: i64, out: *u8) -> i64 {
504func sha256_ranges_overlap(a: i64, an: i64, b: i64, bn: i64) -> i64 {
510func sha256_init_workspace(workspace: *u8, capacity: i64) -> i64 {
521func sha256_digest_workspace(bytes: *u8, n: i64, out: *u8, workspace: *u8, capacity: i64) -> i64 {
535func sha256_digest_mapping_native(bytes: *u8, n: i64, out: *u8, mapping: i64) -> i64 {
544func sha256_digest_checked_native(bytes: *u8, n: i64, out: *u8) -> i64 {