code wiki / _hdl_build / nx_doc_crypto.nx

nx_doc_crypto.nx

buildroot/runtime/_hdl_build/nx_doc_crypto.nx

9031 B179 linesdepth 6pulls 10 transitivereach 14 importersview sourcekind librarytopic doc
docsdependenciesstructsconstsfunctions

about

nx_doc_crypto.nx -- ENCRYPTION-AT-REST core for CONFIDENTIAL docportal shards (client -prv-/-secret-/uploads; NOT the public corpus). Envelope encryption (NIST SP 800-57): a master KEK wraps per-tenant DEKs; documents are sealed with the DEK under a REAL AEAD. Grounds ENTIRELY in shipped, KAT-proven sovereign primitives -- invents NO crypto: AEAD = ChaCha20-Poly1305 (RFC 8439 2.8; nx_chacha20_poly1305, KAT-verified vs the 2.8.2 Sunscreen vector) cipher = ChaCha20 (256-bit key) ; MAC = Poly1305 (constant-time compare) CSPRNG = nx_csprng_fill (getrandom(2), /dev/urandom fallback) CRYPTO-SHRED reconciles Rule 13 (never-delete DATA) with GDPR Art 17 (erasure): the DATA store stays additive (ciphertext history preserved), but the KEY store is the ONE place true deletion is correct -- destroying the wrapped DEK erases ACCESS while the ciphertext bytes remain, permanently unrecoverable. So DEKs live in a per-domain FILE (overwrite-with-random + truncate + unlink), NOT the additive seg-store, precisely because the seg-store's never-delete law is wrong for a key that must be destroyable. STANDALONE lib -- wires into no daemon. HONEST LIMITATION: the KEK is a software file (0600) on the NAS, not an HSM/TPM -- root or a disk image can read it (flag for the operator). license_tier: ORIGINAL

dependencies 3 imports · 2 importers

nx_chacha20_poly1305.nx nx_csprng.nx nx_syscalls.nx nx_doc_crypto.nx nx_doc_at_rest.nx nx_doc_crypto_gate.nx

imports: nx_chacha20_poly1305.nxnx_csprng.nxnx_syscalls.nx

imported by: nx_doc_at_rest.nxnx_doc_crypto_gate.nx

structs

none

consts

21const DC_WRAP_BYTES: i64 = 60 // wrapped DEK = nonce(12) || ct(32) || tag(16)
22const DC_MODE_0600: i64 = 0x180 // rw------- : DEK + KEK files are owner-only

functions

24func dc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
25func dc_cat(out: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 } return o }
called by 1: dc_dek_path
27func dc_dek_path(domain: *u8, out: *u8) -> i64
called by 3: dek_gendek_loadcrypto_shred calls 1: dc_cat
35func dc_readfile(path: *u8, buf: *u8, cap: i64) -> i64
50func dc_writefile(path: *u8, buf: *u8, n: i64, mode: i64) -> i64
69func kek_ensure(out32: *u8) -> i64
92func dek_gen(domain: *u8) -> i64
111func dek_load(domain: *u8, out32: *u8) -> i64
125func doc_encrypt(domain: *u8, pt: *u8, ptlen: i64, out: *u8) -> i64
138func doc_decrypt(domain: *u8, ct: *u8, ctlen: i64, out: *u8) -> i64
151func crypto_shred(domain: *u8) -> i64