code wiki / _hdl_build / nx_doc_crypto.nx
nx_doc_crypto.nx
buildroot/runtime/_hdl_build/nx_doc_crypto.nx
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
imports: nx_chacha20_poly1305.nxnx_csprng.nxnx_syscalls.nx
imported by: nx_doc_at_rest.nxnx_doc_crypto_gate.nx
structs
| none |
consts
| 21 | const DC_WRAP_BYTES: i64 = 60 // wrapped DEK = nonce(12) || ct(32) || tag(16) |
| 22 | const DC_MODE_0600: i64 = 0x180 // rw------- : DEK + KEK files are owner-only |
functions
| 24 | func dc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 25 | func 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 |
| 27 | func dc_dek_path(domain: *u8, out: *u8) -> i64 |
| 35 | func dc_readfile(path: *u8, buf: *u8, cap: i64) -> i64 |
| 50 | func dc_writefile(path: *u8, buf: *u8, n: i64, mode: i64) -> i64 |
| 69 | func kek_ensure(out32: *u8) -> i64 |
| 92 | func dek_gen(domain: *u8) -> i64 called by 2: dek_ensuremain calls 7: sys_mmapkek_ensurenx_csprng_fillnx_chacha20_poly1305_encryptdc_slendc_dek_path+1 |
| 111 | func dek_load(domain: *u8, out32: *u8) -> i64 |
| 125 | func doc_encrypt(domain: *u8, pt: *u8, ptlen: i64, out: *u8) -> i64 |
| 138 | func doc_decrypt(domain: *u8, ct: *u8, ctlen: i64, out: *u8) -> i64 |
| 151 | func crypto_shred(domain: *u8) -> i64 called by 2: mainmain calls 10: sys_mmapdc_dek_pathsys_openat_rdwrnx_csprng_fillsys_lseeksys_write+4 |