sha512.nx
buildroot/runtime/sha512.nx
about
sha512.nx -- SHA-512 in pure NishiLang (FIPS 180-4 section 6.4).
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.
dependencies 2 imports · 3 importers
imports: syscalls.nxnx_bits.nx
imported by: ed25519.nxhmac_sha384.nxhmac_sha512.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 57 | struct Sha512 { |
consts
| none |
functions
| 44 | func rotr64_v(x: i64, n: i64) -> i64 { |
| 49 | func shr64_v(x: i64, n: i64) -> i64 { |
| 78 | func sha512_k(i: i64) -> i64 {
called by 1: sha512_compress |
| 167 | func blk_get_i64(c: *Sha512, w: i64) -> i64 { |
| 186 | func blk_set_i64(c: *Sha512, w: i64, v: i64) -> i64 {
called by 1: blk_set_byte |
| 208 | func blk_set_byte(c: *Sha512, n: i64, v: i64) -> i64 { |
| 224 | func sha512_sigma0(x: i64) -> i64 { |
| 228 | func sha512_sigma1(x: i64) -> i64 { |
| 232 | func sha512_gamma0(x: i64) -> i64 { |
| 236 | func sha512_gamma1(x: i64) -> i64 { |
| 240 | func sha512_ch(x: i64, y: i64, z: i64) -> i64 {
called by 1: sha512_compress |
| 244 | func sha512_maj(x: i64, y: i64, z: i64) -> i64 {
called by 1: sha512_compress |
| 250 | func sha512_compress(c: *Sha512) -> i64 {
called by 2: sha512_updatesha512_final calls 8: blk_get_i64sha512_gamma0sha512_gamma1sha512_sigma1sha512_chsha512_k+2 |
| 304 | func sha512_init(c: *Sha512) -> i64 { |
| 322 | func sha512_update(c: *Sha512, bytes: *u8, n: i64) -> i64 { |
| 337 | func sha512_final(c: *Sha512, out: *u8) -> i64 { |
| 388 | func sha512_digest(bytes: *u8, n: i64, out: *u8) -> i64 { |
| 404 | func sha384_init(c: *Sha512) -> i64 { |
| 421 | func sha384_digest(bytes: *u8, n: i64, out: *u8) -> i64 { |
| 445 | func sha512_256_init(c: *Sha512) -> i64 {
called by 1: sha512_256_digest |
| 463 | func sha512_256_digest(bytes: *u8, n: i64, out: *u8) -> i64 { |
| 477 | func main() -> i64 {
calls 1: sha512_digest |