code wiki / (root) / nx_bigint_lib.nx

nx_bigint_lib.nx

buildroot/runtime/nx_bigint_lib.nx

5884 B174 linesdepth 0pulls 0 transitivereach 23 importersview sourcekind librarytopic bigint
docsdependenciesstructsconstsfunctions

about

nx_bigint_lib.nx -- multi-precision integer PRIMITIVES (unsigned), the IMPORTABLE library. Split 2026-07-09 from the nx_bigint.nx / bigint.nx twins (which were code-identical and BOTH carried a main() KAT battery, making them unimportable into any main-bearing binary -- the nx_qa_score_lib precedent). The twins now import THIS lib and keep their main() gates; new consumers (e.g. nx_swcompare_bench) import the lib directly. ZERO imports by design: every primitive is pure limb math on caller-owned buffers (BI3), so this lib is syscall-module-agnostic (safe under both syscalls.nx and nx_syscalls.nx import chains). Representation: array of u32 limbs in LITTLE-ENDIAN order (limb 0 is least-significant 32 bits), stored in i64 slots (low 32 bits used) so 32x32 products and carried sums fit in i64 without overflow. Invariants (from the original): BI1 Limbs past the declared length are never read; callers pass explicit lengths. BI2 Results are written with LENGTH HINTS the caller allocates for (bi_add output needs n+1 limbs). BI3 No heap allocation inside primitives -- caller owns limb buffers. BI4 Comparison returns -1 / 0 / +1 like strcmp. BI5 Arithmetic is UNSIGNED; signed lives at the caller's layer. license_tier: ORIGINAL

dependencies 0 imports · 3 importers

nx_bigint_lib.nx bigint.nx nx_bigint.nx nx_swcompare_bench.nx

imports: none

imported by: bigint.nxnx_bigint.nxnx_swcompare_bench.nx

structs

none

consts

20const LIMB_BITS: i64 = 32
21const LIMB_MASK: i64 = 0xFFFFFFFF

functions

24func bi_copy(dst: *i64, src: *i64, n: i64) -> i64
called by 1: bi_modexp
31func bi_zero(dst: *i64, n: i64) -> i64
39func bi_cmp(a: *i64, b: *i64, n: i64) -> i64
called by 1: bi_mod
53func bi_add(r: *i64, a: *i64, b: *i64, n: i64) -> i64
called by 3: mainmainmain
69func bi_sub(r: *i64, a: *i64, b: *i64, n: i64) -> i64
called by 1: bi_mod
84func bi_shl1(r: *i64, n: i64) -> i64
called by 1: bi_mod
98func bi_shr1(r: *i64, n: i64, carry_in: i64) -> i64
114func bi_mul(r: *i64, a: *i64, a_len: i64, b: *i64, b_len: i64) -> i64
called by 4: mainmainbi_modexpmain calls 1: bi_zero
142func bi_from_bytes_be(r: *i64, n_limbs: i64,
159func bi_to_bytes_be(out: *u8, n_bytes: i64,