nx_p256_comb_gen.nx source
↩ module page · 23 lines · 803 B
1// nx_p256_comb_gen.nx -- build the P-256 fixed-base comb table once and
2// write it to NX_P256_COMB_PATH. Deterministic (multiples of G), so it
3// is generated a single time and read thereafter by the ECDSA signer.
4import "nx_syscalls.nx"
5import "nx_p256_comb.nx"
6
7func main() -> i64 {
8 let table: *i64 = (sys_mmap(NX_P256_COMB_BYTES)) as *i64
9 p256_comb_build(table)
10 let fd: i64 = sys_openat_wr(NX_P256_COMB_PATH, 420)
11 if fd < 0 {
12 sys_write(1, "comb_gen: open failed\n" as *u8, 22)
13 return 2
14 }
15 let w: i64 = sys_write(fd, table as *u8, NX_P256_COMB_BYTES)
16 sys_close(fd)
17 if w == NX_P256_COMB_BYTES {
18 sys_write(1, "comb_gen: table written OK\n" as *u8, 27)
19 return 0
20 }
21 sys_write(1, "comb_gen: short write\n" as *u8, 22)
22 return 3
23}