nx_sha512.nx
buildroot/runtime/nx_sha512.nx
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
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
structs
| 87 | struct Sha512 |
consts
| none |
functions
| 74 | func rotr64_v(x: i64, n: i64) -> i64 |
| 79 | func shr64_v(x: i64, n: i64) -> i64 |
| 119 | func sha512_k(i: i64) -> i64 called by 1: sha512_compress |
| 208 | func blk_get_i64(c: *Sha512, w: i64) -> i64 |
| 227 | func blk_set_i64(c: *Sha512, w: i64, v: i64) -> i64 called by 1: sha512_blk_set_byte |
| 249 | func sha512_blk_set_byte(c: *Sha512, n: i64, v: i64) -> i64 |
| 265 | func sha512_sigma0(x: i64) -> i64 |
| 269 | func sha512_sigma1(x: i64) -> i64 |
| 273 | func sha512_gamma0(x: i64) -> i64 |
| 277 | func sha512_gamma1(x: i64) -> i64 |
| 281 | func sha512_ch(x: i64, y: i64, z: i64) -> i64 called by 1: sha512_compress |
| 285 | func sha512_maj(x: i64, y: i64, z: i64) -> i64 called by 1: sha512_compress |
| 291 | func sha512_compress(c: *Sha512) -> i64 called by 2: sha512_updatesha512_final calls 9: sys_mmapblk_get_i64sha512_gamma0sha512_gamma1sha512_sigma1sha512_ch+3 |
| 345 | func sha512_init(c: *Sha512) -> i64 |
| 364 | func sha512_update(c: *Sha512, bytes: *u8, n: i64) -> i64 |
| 379 | func sha512_final(c: *Sha512, out: *u8) -> i64 |
| 430 | func sha512_digest(bytes: *u8, n: i64, out: *u8) -> i64 |
| 456 | func sha384_init(c: *Sha512) -> i64 |
| 470 | func sha384_digest(bytes: *u8, n: i64, out: *u8) -> i64 |
| 494 | func sha512_256_init(c: *Sha512) -> i64 called by 1: sha512_256_digest |
| 513 | func sha512_256_digest(bytes: *u8, n: i64, out: *u8) -> i64 |
| 527 | func main() -> i64 |