code wiki / (root) / nx_ed25519.nx

nx_ed25519.nx

buildroot/runtime/nx_ed25519.nx

9295 B225 linesdepth 5pulls 6 transitivereach 2 importersview sourcekind tooltopic ed25519
docsdependenciesstructsconstsfunctions

about

ed25519.nx -- Ed25519 signature verification (RFC 8032). license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/ietf/rfc_8032 VERIFY-ONLY. Signing requires a private key and constant-time scalar reduction we can defer to a later implementation. TLS 1.3 clients verify server cert signatures; they never sign. This is the piece that closes the cert-chain verify gap when paired with x509.nx + sha512.nx. Algorithm: Input: signature (64 bytes = R || S) public key A (32 bytes = compressed Edwards point) message m (arbitrary length) Output: 1 if signature is valid, 0 otherwise. Verify: 1. Decode R from first 32 bytes (Edwards point, y-coordinate with high bit = sign of x). 2. Decode S from last 32 bytes (little-endian scalar, must be < L; otherwise reject). 3. Decode A from public key bytes. 4. Compute h = SHA-512(R_bytes || A_bytes || m) mod L. 5. Compute [S]G - [h]A; if result == R then signature is valid. (Equivalent: [S]G == R + [h]A.) Where: G is the Ed25519 base point. L = 2^252 + 27742317777372353535851937790883648493 (order of G). Curve: twisted Edwards form -x^2 + y^2 = 1 + d*x^2*y^2 where d = -121665/121666 (mod p), p = 2^255 - 19. Relationship to x25519.nx: Same field GF(2^255-19). We re-declare the fe_* operations here because NishiLang currently has no way to share types across imported modules without declaration collisions (the types.nx pattern requires one canonical home). A later refactor can factor GF(p) into its own module.

dependencies 3 imports · 2 importers

nx_syscalls.nx nx_sha512.nx nx_ct.nx nx_ed25519.nx nx_ed25519_sign_bisect_test.nx nx_https_get_happy_test.nx

imports: nx_syscalls.nxnx_sha512.nxnx_ct.nx

imported by: nx_ed25519_sign_bisect_test.nxnx_https_get_happy_test.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap ed25519_verify sys_mmap ↻ ed25519_parse_sig sc_less_than_l sys_mmap ↻ ed25519_transcript sys_mmap ↻ sha512_init sha512_update sha512_blk_set_byte blk_get_i64 blk_set_i64 sha512_compress sys_mmap ↻ blk_get_i64 ↻ sha512_gamma0 rotr64_v shr64_v sha512_gamma1 rotr64_v ↻ shr64_v ↻ sha512_sigma1 rotr64_v ↻ sha512_ch sha512_k sha512_sigma0 rotr64_v ↻ sha512_maj sha512_final sha512_blk_set_byte ↻ sha512_compress ↻

structs

none

consts

108const ED25519_L_BYTES: i64 = 32 // L fits in 32 bytes
189const ED25519_ERR_PENDING: i64 = -100
190const ED25519_ERR_BAD_SIG: i64 = -1

functions

113func sc_less_than_l(s: *u8) -> i64 {
called by 1: ed25519_parse_sig calls 1: sys_mmap
148func ed25519_parse_sig(sig: *u8, r_out: *u8, s_out: *u8) -> i64 {
called by 1: ed25519_verify calls 1: sc_less_than_l
164func ed25519_transcript(r_bytes: *u8, a_bytes: *u8,
192func ed25519_verify(pubkey: *u8, msg: *u8, msg_len: i64,
212func main() -> i64 {