code wiki / (root) / nx_u256.nx

nx_u256.nx

buildroot/runtime/nx_u256.nx

13460 B355 linesdepth 2pulls 2 transitivereach 993 importersview sourcekind tooltopic u256
docsdependenciesstructsconstsfunctions

about

nx_u256.nx -- 256-bit unsigned big-integer primitives. Phase 0b §I.3 of the Nishi TLS 1.3 stack -- foundation for the ECDSA-P256 arc (which is the biggest single remaining blocker for public-HTTPS-fetch per task #21). Web PKI cert chains for google.com + Cloudflare + every modern CDN sign with ECDSA over NIST P-256, and verifying those sigs requires: 1. 256-bit big-int arithmetic (THIS primitive) 2. P-256 prime-field math (queued: nx_p256_field.nx) 3. P-256 curve-point math (queued: nx_p256_point.nx) 4. P-256 scalar math mod n (queued: nx_p256_scalar.nx) 5. ECDSA verify orchestrator (queued: nx_ecdsa_p256.nx) This module ships ONLY the raw unsigned 256-bit arithmetic + byte-order helpers. No field reduction, no curve, no signature. Representation: U256 is an 8-element i64 array where each element holds a 32-bit limb in its low bits and zeros in its high bits. Little-endian limb order: limb[0] is the least- significant 32 bits, limb[7] is the most-significant 32 bits. Why 8 x 32-bit limbs (not 4 x 64-bit): - Avoids signed-vs-unsigned i64 comparison hell that 4-limb would require for carry detection on (i64+i64) overflow. - 32-bit add/sub fits in i64 without overflow, so carry can be extracted with a clean (sum >> 32) & 1 instead of an unsigned-compare workaround. - 32-bit mul also fits in i64 (32 + 32 = 64 < 63 bits), so the upcoming p256_field_mul can use standard schoolbook limb-by-limb multiplication without 128-bit intermediates. - Matches BoringSSL's u32-limb P-256 implementation, which is the modern reference for non-vector platforms. Byte-order: X.509 / TLS / DER carry integers BIG-ENDIAN. All load/store helpers convert between BE byte buffers and our little-endian limb layout. What this primitive does: - u256_zero / u256_one / u256_copy / u256_alloc - u256_load_be (32-byte BE -> 8-limb LE)

dependencies 1 imports · 64 importers

nx_syscalls.nx nx_u256.nx _u256_cmov_gate.nx nx_bench_comb.nx nx_bench_kg.nx nx_bench_sign.nx nx_bench_verify.nx nx_cert_gen.nx nx_crypto_bench_full.nx nx_dev_api_build_probe.nx nx_ecdsa_p256.nx nx_ecdsa_p256_sign.nx

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

imports: nx_syscalls.nx

imported by: _u256_cmov_gate.nxnx_bench_comb.nxnx_bench_kg.nxnx_bench_sign.nxnx_bench_verify.nxnx_cert_gen.nxnx_crypto_bench_full.nxnx_dev_api_build_probe.nxnx_ecdsa_p256.nxnx_ecdsa_p256_sign.nxnx_ecdsa_p256_sign_test.nxnx_ecdsa_p256_test.nxnx_ecdsa_p384_real_bisect_test.nxnx_ecdsa_sig_der.nxnx_ecdsa_sig_der_test.nxnx_h2c_p256.nxnx_https_pipeline_e2e_test.nxnx_jose_es256.nxnx_jwk_ec.nxnx_login_e2e_probe.nxnx_opaque_core.nxnx_opaque_pake.nxnx_p256_comb.nxnx_p256_ecdh.nxnx_p256_field.nxnx_p256_field_inv.nxnx_p256_field_inv_test.nxnx_p256_field_mul.nxnx_p256_field_mul_oracle_test.nxnx_p256_field_mul_test.nxnx_p256_field_test.nxnx_p256_fieldmul_bench.nxnx_p256_keyshare_test.nxnx_p256_modn.nxnx_p256_modn_test.nxnx_p256_point.nxnx_p256_point_add.nxnx_p256_point_add_test.nxnx_p256_point_test.nxnx_p256_pointloop_bench.nxnx_p256_scalar_mul.nxnx_p256_scalar_mul_test.nxnx_p256_scalar_mul_wnaf.nxnx_p256_solinas_difftest.nxnx_p256_solinas_timing.nxnx_p256_verify_bench.nxnx_p256_verify_timing.nxnx_tls12_client_session.nxnx_tls13_client_verify_cv.nxnx_tls13_server_recv_client_cv.nxnx_tls13_server_session_emit_cv.nxnx_u256_mul.nxnx_u256_mul4_fuzz.nxnx_u256_mul_test.nxnx_u256_test.nxnx_voprf.nxnx_x25519.nxnx_x509_build.nxnx_x509_pubkey_ec.nxnx_x509_pubkey_ec_test.nxnx_x509_verify_ecdsa.nxnx_x509_verify_ecdsa_test.nxnx_x509_verify_under_issuer.nxnx_x509_verify_under_issuer_test.nx

structs

none

consts

76const NX_U256_LIMBS: i64 = 8
77const NX_U256_BYTES: i64 = 32
78const NX_U256_LIMB_BITS: i64 = 32
79const NX_U256_LIMB_MASK: i64 = 0xFFFFFFFF
112const NX_SCRATCH_BLOCK: i64 = 1048576 // 1 MiB per block
113const NX_SCRATCH_MAXBLOCKS: i64 = 8192 // 8 GiB ceiling (pathological-leak backstop only)

functions

119func nx_scratch_init() -> i64
called by 2: nx_scratchnx_scratch_save calls 1: sys_mmap
135func nx_scratch_oom(msg: *u8, mlen: i64) -> i64
called by 1: nx_scratch calls 2: sys_writesys_exit
142func nx_scratch(n: i64) -> *u8
178func nx_scratch_save() -> i64
183func nx_scratch_restore(mark: i64) -> i64
190func u256_alloc() -> *i64
195func u256_zero(out: *i64) -> i64
205func u256_one(out: *i64) -> i64
212func u256_copy(out: *i64, src: *i64) -> i64
228func u256_load_be(out: *i64, bytes: *u8) -> i64
245func u256_store_be(bytes: *u8, src: *i64) -> i64
264func u256_add_with_carry(out: *i64, a: *i64, b: *i64) -> i64
280func u256_sub_with_borrow(out: *i64, a: *i64, b: *i64) -> i64
303func u256_cmp(a: *i64, b: *i64) -> i64
316func u256_is_zero(a: *i64) -> i64
330func u256_cmov(dst: *i64, src: *i64, flag: i64) -> i64
called by 1: main
341func u256_eq(a: *i64, b: *i64) -> i64
353func main() -> i64