code wiki / (root) / nx_sha512.nx

nx_sha512.nx

buildroot/runtime/nx_sha512.nx

18909 B532 linesdepth 4pulls 4 transitivereach 944 importersview sourcekind tooltopic sha512
docsdependenciesstructsconstsfunctions

about

sha512.nx -- SHA-512 in pure NishiLang (FIPS 180-4 section 6.4). Canonical: this is the substrate-wide canonical SHA-512 implementation per [[feedback-no-tool-proliferation-bit-level]]. SHA-384 / HMAC-SHA-512 / HKDF-SHA-512 / Argon2id compose THIS file's SHA-512 primitive (SHA-384 is SHA-512 with truncated output + different IV; HMAC adds key wrapping; HKDF adds expand+extract; Argon2id uses BLAKE2b which is separate). Re-implementing the SHA-512 K-table or round function inline is refused. Completes the SHA-2 family alongside sha256.nx. Needed for TLS 1.3 cipher suites that negotiate HMAC-SHA-384 or HMAC-SHA-512 (e.g. TLS_AES_256_GCM_SHA384). SHA-512 is also the natural word width for 64-bit targets -- i64 arithmetic is the primitive, no masking required (contrast sha256.nx's constant M32 masking). Structure mirrors FIPS 180-4 exactly: - 128-byte (1024-bit) blocks - 8 x 64-bit hash state words - 80 rounds with cube-roots-of-primes constants - Merkle-Damgård construction with length-padded final block API: sha512_init(*Sha512) sha512_update(*Sha512, *u8, len) sha512_final(*Sha512, *u8 out64) sha512_digest(*u8 bytes, len, *u8 out64) -- one-shot Context is ~256 bytes: 8 state words + 128-byte buffer + index + bit counter. Caller-allocated. Grover's algorithm under quantum attack: SHA-512 collision resistance halves to 256 bits classical = 128 bits effective against a quantum adversary. Still secure for all practical purposes. Output truncated to 32 bytes yields SHA-512/256 (also FIPS 180-4 Appendix A), useful for shorter tags. license_tier: INDEPENDENT_REDERIVE

dependencies 2 imports · 16 importers

nx_syscalls.nx nx_bits.nx nx_sha512.nx _sha512_kat.nx nx_ecdsa_p384_real_bisect_test.nx nx_ed25519.nx nx_ed25519_signature.nx nx_hmac_sha384.nx nx_hmac_sha512.nx nx_https_get_happy_test.nx nx_p384_ecdh.nx nx_rsa_pkcs1_v1_5_k.nx nx_rsa_pkcs1_v1_5_sha384.nx

diagram shows first 10 each side; +0 more imports, +6 more importers in the complete lists below.

imports: nx_syscalls.nxnx_bits.nx

imported by: _sha512_kat.nxnx_ecdsa_p384_real_bisect_test.nxnx_ed25519.nxnx_ed25519_signature.nxnx_hmac_sha384.nxnx_hmac_sha512.nxnx_https_get_happy_test.nxnx_p384_ecdh.nxnx_rsa_pkcs1_v1_5_k.nxnx_rsa_pkcs1_v1_5_sha384.nxnx_rsa_pkcs1_v1_5_sha512.nxnx_sha256_sha384_coexist_kat_test.nxnx_sha384_kat_test.nxnx_tls13_transcript.nxnx_tls13_transcript384_gate.nxnx_x509_verify_ecdsa_p384.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap sha512_digest sys_mmap ↻ sha512_init sha512_update sha512_blk_set_byte blk_get_i64 blk_set_i64 sha512_compress sys_mmap ↻ blk_get_i64 ↻ sha512_gamma0 rotr64_v nx_bits_rotr64 shr64_v sha512_gamma1 rotr64_v ↻ shr64_v ↻ sha512_sigma1 rotr64_v ↻ sha512_ch sha512_k sha512_sigma0 rotr64_v ↻ sha512_maj sha512_final sha512_blk_set_byte ↻ sha512_compress ↻

structs

87struct Sha512

consts

none

functions

74func rotr64_v(x: i64, n: i64) -> i64
79func shr64_v(x: i64, n: i64) -> i64
119func sha512_k(i: i64) -> i64
called by 1: sha512_compress
208func blk_get_i64(c: *Sha512, w: i64) -> i64
227func blk_set_i64(c: *Sha512, w: i64, v: i64) -> i64
called by 1: sha512_blk_set_byte
249func sha512_blk_set_byte(c: *Sha512, n: i64, v: i64) -> i64
265func sha512_sigma0(x: i64) -> i64
called by 1: sha512_compress calls 1: rotr64_v
269func sha512_sigma1(x: i64) -> i64
called by 1: sha512_compress calls 1: rotr64_v
273func sha512_gamma0(x: i64) -> i64
called by 1: sha512_compress calls 2: rotr64_vshr64_v
277func sha512_gamma1(x: i64) -> i64
called by 1: sha512_compress calls 2: rotr64_vshr64_v
281func sha512_ch(x: i64, y: i64, z: i64) -> i64
called by 1: sha512_compress
285func sha512_maj(x: i64, y: i64, z: i64) -> i64
called by 1: sha512_compress
291func sha512_compress(c: *Sha512) -> i64
345func sha512_init(c: *Sha512) -> i64
364func sha512_update(c: *Sha512, bytes: *u8, n: i64) -> i64
379func sha512_final(c: *Sha512, out: *u8) -> i64
430func sha512_digest(bytes: *u8, n: i64, out: *u8) -> i64
456func sha384_init(c: *Sha512) -> i64
470func sha384_digest(bytes: *u8, n: i64, out: *u8) -> i64
494func sha512_256_init(c: *Sha512) -> i64
called by 1: sha512_256_digest
513func sha512_256_digest(bytes: *u8, n: i64, out: *u8) -> i64
527func main() -> i64