nx_x25519_wasm.nx
buildroot/runtime/nx_x25519_wasm.nx
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
| 34 | const M25: i64 = 0x1ffffff // 2^25 - 1 |
| 35 | const M26: i64 = 0x3ffffff // 2^26 - 1 |
functions
| 38 | func _fe_get(fe: *u8, i: i64) -> i64 |
| 49 | func _fe_set(fe: *u8, i: i64, v: i64) -> i64 |
| 63 | func _fe_unpack(fe: *u8, bytes: *u8) -> i64 |
| 99 | func _fe_pack(bytes: *u8, fe: *u8) -> i64 |
| 173 | func _fe_copy(dst: *u8, src: *u8) -> i64 |
| 180 | func _fe_add(out: *u8, a: *u8, b: *u8) -> i64 |
| 198 | func _fe_sub(out: *u8, a: *u8, b: *u8) -> i64 |
| 214 | func _fe_mul(out: *u8, a_in: *u8, b_in: *u8) -> i64 |
| 294 | func _fe_sqr(out: *u8, a: *u8) -> i64 |
| 299 | func _fe_mul_a24(out: *u8, a: *u8) -> i64 |
| 339 | func _fe_invert(out: *u8, z: *u8, scratch: *u8) -> i64 |
| 438 | func _fe_cswap(a: *u8, b: *u8, c: i64) -> i64 |
| 466 | func nx_x25519_scalarmult(scalar_ptr: *u8, point_ptr: *u8, |