code wiki / (root) / nx_x25519_wasm.nx

nx_x25519_wasm.nx

buildroot/runtime/nx_x25519_wasm.nx

21127 B551 linesdepth 0pulls 0 transitivereach 0 importersview sourcekind orphan librarytopic x25519
docsdependenciesstructsconstsfunctions

about

nx_x25519_wasm.nx -- Curve25519 ECDH (RFC 7748) for WAT target. Field: GF(2^255 - 19). Curve: y^2 = x^3 + 486662*x^2 + x. Only the x-coordinate is needed for the ladder. Field representation: 10 limbs alternating 26 / 25 bits = 255 bits. limb[0] -> bits 0..25 (26-bit slot, but only low 26 used) limb[1] -> bits 26..50 (25 bits) limb[2] -> bits 51..76 (26 bits) ...alternating up to limb[9] which is the high 25 bits. This split (donna 32-bit-style) means each per-limb multiplication result fits comfortably in i64 (max 2^51 ish). Carry chain distributes the overflow back into 26/25-bit form after each round. Reduction: 2^255 mod (2^255 - 19) = 19. Any bit at position 255+ folds back by multiplying by 19. API for the embedder: nx_x25519_scalarmult(scalar_ptr, point_ptr, scratch_ptr, out_ptr) -> i64 scalar_ptr -- 32 bytes (LE). Clamped per RFC 7748 §5 inside. point_ptr -- 32 bytes (LE; the u-coord of the input point). scratch_ptr-- >= 1024 bytes scratch area out_ptr -- 32 bytes (the resulting u-coord) Verified against RFC 7748 §5.2 test vectors. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/ietf/rfc_7748 + daniel_j_bernstein/curve25519_donna lineage_id: nishi_x25519_wasm_q11

dependencies 0 imports · 0 importers

imports: none

imported by: nobody (leaf or entry point)

structs

none

consts

34const M25: i64 = 0x1ffffff // 2^25 - 1
35const M26: i64 = 0x3ffffff // 2^26 - 1

functions

38func _fe_get(fe: *u8, i: i64) -> i64
49func _fe_set(fe: *u8, i: i64, v: i64) -> i64
63func _fe_unpack(fe: *u8, bytes: *u8) -> i64
called by 1: nx_x25519_scalarmult calls 1: _fe_set
99func _fe_pack(bytes: *u8, fe: *u8) -> i64
called by 1: nx_x25519_scalarmult calls 2: _fe_get_fe_set
173func _fe_copy(dst: *u8, src: *u8) -> i64
called by 1: nx_x25519_scalarmult calls 2: _fe_set_fe_get
180func _fe_add(out: *u8, a: *u8, b: *u8) -> i64
called by 1: nx_x25519_scalarmult calls 2: _fe_set_fe_get
198func _fe_sub(out: *u8, a: *u8, b: *u8) -> i64
called by 1: nx_x25519_scalarmult calls 2: _fe_set_fe_get
214func _fe_mul(out: *u8, a_in: *u8, b_in: *u8) -> i64
294func _fe_sqr(out: *u8, a: *u8) -> i64
299func _fe_mul_a24(out: *u8, a: *u8) -> i64
called by 1: nx_x25519_scalarmult calls 2: _fe_get_fe_set
339func _fe_invert(out: *u8, z: *u8, scratch: *u8) -> i64
called by 1: nx_x25519_scalarmult calls 2: _fe_sqr_fe_mul
438func _fe_cswap(a: *u8, b: *u8, c: i64) -> i64
called by 1: nx_x25519_scalarmult calls 2: _fe_get_fe_set
466func nx_x25519_scalarmult(scalar_ptr: *u8, point_ptr: *u8,