code wiki / _hdl_build / nx_efivars_enrol.nx

nx_efivars_enrol.nx

buildroot/runtime/_hdl_build/nx_efivars_enrol.nx

21474 B460 linesdepth 11pulls 23 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_efivars_enrol.nx -- F103e RUNG 11b: enrol OUR key into a UEFI variable store. The last software rung. Builds an EFI_SIGNATURE_LIST around our self-signed cert and writes PK, KEK and db into a varstore derived from the EMPTY (setup-mode) OVMF varstore. Booting secboot firmware against it should put the machine in USER MODE with OUR key as the authority -- so the decisive test is a PAIR: our SIGNED image accepted, an UNSIGNED image refused. Either alone proves nothing (a varstore that failed to load would accept both; a broken one would refuse both). ★★★★★★EVERY CONSTANT IS TAKEN FROM THE ARTIFACT, NOT FROM MEMORY. `OVMF_VARS_4M.ms.fd` has PK/KEK/db already enrolled, so the vendor GUIDs, the attribute word, and even EFI_CERT_X509_GUID (which is literally the first 16 bytes of the real `db` data) are READ OUT OF IT. Writing a UEFI GUID from recall is a fabricated constant, and a wrong one here fails in a way that looks like "Secure Boot just doesn't like us". EFI_SIGNATURE_LIST: SignatureType[16] | SignatureListSize[4] | SignatureHeaderSize[4] | SignatureSize[4] | (header) | { SignatureOwner[16] | SignatureData[] }... Usage: nx_efivars_enrol build <empty_vars.fd> <ms_vars.fd> <out_vars.fd> nx_efivars_enrol selftest <empty_vars.fd> <ms_vars.fd> Exit: 0 GREEN | 1 RED | 3 UNPROVEN. license_tier: ORIGINAL

dependencies 18 imports · 0 importers

nx_syscalls.nx nx_sha256.nx nx_u2048.nx nx_u2048_mul.nx nx_rsa2048_mod.nx nx_rsa2048_mod_exp.nx nx_rsa2048_mont.nx nx_rsa2048_mod_exp_big.nx nx_asn1.nx nx_x509.nx nx_efivars_enrol.nx

diagram shows first 10 each side; +8 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_sha256.nxnx_u2048.nxnx_u2048_mul.nxnx_rsa2048_mod.nxnx_rsa2048_mod_exp.nxnx_rsa2048_mont.nxnx_rsa2048_mod_exp_big.nxnx_asn1.nxnx_x509.nxnx_rsa_pkcs1_v1_5_sha256.nxnx_u2048_millerrabin.nxnx_u2048_smallops.nxnx_rsa_keygen.nxnx_rsa_pkcs1_sign.nxnx_x509_emit.nxnx_efivarstore.nxnx_pe_authhash.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main en_eq_str en_selftest sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close en_x509guid_from_ms sys_mmap ↻ ev_first_var ev_r16 ev_r32 ev_walk ev_r32 ↻ ev_r16 ↻ ev_p sys_write ↻ sys_mmap ↻ sys_write ↻ ev_fn sys_mmap ↻ sys_write ↻

structs

none

consts

40const EN_MAGIC_4096: i64 = 4096
41const EN_MAGIC_20260808: i64 = 20260808
42const EN_MAGIC_1024: i64 = 1024
43const EN_MAGIC_8192: i64 = 8192
44const EN_MAGIC_65537: i64 = 65537
45const EN_MAGIC_4097: i64 = 4097
46const EN_MAGIC_16384: i64 = 16384
48const EN_ATTRS: i64 = 39 // MEASURED from the MS varstore: NV|BS|RT|TIME_BASED_AUTH_WRITE

functions

50func en_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
51func en_fp(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
called by 1: en_selftest calls 1: sys_write
52func en_fn(fd: i64, v: i64) -> i64
62func en_eq_str(a: *u8, b: *u8) -> i64
called by 1: main
68func en_w32(b: *u8, o: i64, v: i64) -> i64
76func en_siglist(out: *u8, x509guid: *u8, cert: *u8, certlen: i64) -> i64
called by 2: en_build_hashdben_build calls 1: en_w32
93func en_put_var(b: *u8, off: i64, name: *u8, guid: *u8, data: *u8, dlen: i64) -> i64
called by 2: en_build_hashdben_build calls 1: en_w32
127func en_x509guid_from_ms(ms: *u8, mslen: i64, out16: *u8) -> i64
143func en_vendor_guid(ms: *u8, mslen: i64, name: *u8, nlen: i64, out16: *u8) -> i64
165func en_sha256guid_from_ms(ms: *u8, mslen: i64, out16: *u8) -> i64
183func en_build_hashdb(emptyp: *u8, msp: *u8, imgp: *u8, outp: *u8) -> i64
256func en_build(emptyp: *u8, msp: *u8, outp: *u8, quiet: i64) -> i64
314func en_selftest(emptyp: *u8, msp: *u8) -> i64
445func main(argc: i64, argv: *i64) -> i64