code wiki / _hdl_build / nx_vault_shamir.nx

nx_vault_shamir.nx

buildroot/runtime/_hdl_build/nx_vault_shamir.nx

2323 B60 linesdepth 2pulls 2 transitivereach 8 importersview sourcekind librarytopic vault
docsdependenciesstructsconstsfunctions

about

nx_vault_shamir.nx -- sovereign SHAMIR threshold secret sharing (HashiCorp Vault "Shamir seal/unseal" gap from vault_capability_census.tsv) -- the iconic multi-operator unseal: split a master key into N shares; ANY K reconstruct it; K-1 shares reveal a WRONG value (no quorum -> no unseal). Real finite-field math over GF(p), p = 2^31-1 (Mersenne prime): products of two field elements stay < 2^62 so they fit i64 with no overflow. Shares = poly(1..N); reconstruct = Lagrange interpolation at x=0. license_tier: ORIGINAL

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_vault_shamir.nx nx_social_recovery.nx nx_vault_shamir_test.nx nx_vault_suite_test.nx

imports: nx_syscalls.nx

imported by: nx_social_recovery.nxnx_vault_shamir_test.nxnx_vault_suite_test.nx

structs

none

consts

8const SH_P: i64 = 2147483647 // 2^31 - 1 (Mersenne prime); secrets must be < SH_P

functions

10func sh_mod(x: i64) -> i64 { var r: i64 = x % SH_P; if r < 0 { r = r + SH_P } return r }
11func sh_add(a: i64, b: i64) -> i64 { return sh_mod(a + b) }
called by 3: sh_evalsh_reconstructmain calls 1: sh_mod
12func sh_sub(a: i64, b: i64) -> i64 { return sh_mod(a - b) }
called by 1: sh_reconstruct calls 1: sh_mod
13func sh_mul(a: i64, b: i64) -> i64 { return sh_mod(a * b) } // a,b < 2^31 -> a*b < 2^62, fits i64
called by 2: sh_evalsh_reconstruct calls 1: sh_mod
16func sh_inv(a: i64) -> i64
called by 1: sh_reconstruct calls 1: sh_mod
33func sh_eval(coeffs: *i64, k: i64, x: i64) -> i64
called by 3: nx_sr_splitmainmain calls 2: sh_addsh_mul
41func sh_reconstruct(xs: *i64, ys: *i64, k: i64) -> i64