code wiki / (root) / sha512.nx

sha512.nx

buildroot/runtime/sha512.nx

17430 B482 linesdepth 4pulls 4 transitivereach 5 importersview sourcekind librarytopic sha512
docsdependenciesstructsconstsfunctions

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

syscalls.nx nx_bits.nx sha512.nx ed25519.nx hmac_sha384.nx hmac_sha512.nx

imports: syscalls.nxnx_bits.nx

imported by: ed25519.nxhmac_sha384.nxhmac_sha512.nx

structs

57struct Sha512 {

consts

none

functions

44func rotr64_v(x: i64, n: i64) -> i64 {
49func shr64_v(x: i64, n: i64) -> i64 {
78func sha512_k(i: i64) -> i64 {
167func blk_get_i64(c: *Sha512, w: i64) -> i64 {
186func blk_set_i64(c: *Sha512, w: i64, v: i64) -> i64 {
208func blk_set_byte(c: *Sha512, n: i64, v: i64) -> i64 {
224func sha512_sigma0(x: i64) -> i64 {
228func sha512_sigma1(x: i64) -> i64 {
232func sha512_gamma0(x: i64) -> i64 {
236func sha512_gamma1(x: i64) -> i64 {
240func sha512_ch(x: i64, y: i64, z: i64) -> i64 {
244func sha512_maj(x: i64, y: i64, z: i64) -> i64 {
250func sha512_compress(c: *Sha512) -> i64 {
304func sha512_init(c: *Sha512) -> i64 {
322func sha512_update(c: *Sha512, bytes: *u8, n: i64) -> i64 {
337func sha512_final(c: *Sha512, out: *u8) -> i64 {
388func sha512_digest(bytes: *u8, n: i64, out: *u8) -> i64 {
404func sha384_init(c: *Sha512) -> i64 {
421func sha384_digest(bytes: *u8, n: i64, out: *u8) -> i64 {
445func sha512_256_init(c: *Sha512) -> i64 {
463func sha512_256_digest(bytes: *u8, n: i64, out: *u8) -> i64 {
477func main() -> i64 {