interplane.Get Omega
Read in your language

omtls

omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

omtls / tests / drv / x25519.om

115 lines · 2574 bytes Raw Blame History
1note omtls test driver x25519: ot_x25_mul / ot_x25_base on tests/vectors/x25519/rfc7748.txt (X R K U O: the output
2note must be O and, when R is 1, all zero by ot_ct_zero32; B K O; I N O: N iterations from k = u = 9, RFC 7748 5.2)
3note and Wycheproof x25519 (X R K U O, R 1 for the ZeroSharedSecret cases). The rfc7748.txt "L" lines check the
4note length refusals of an API with run-time lengths; this API takes sized 32-byte arrays, so a wrong length cannot
5note be passed (compile-time error 7) and those lines are not counted. Usage: x25519 FILE...
6text ot_syx_area "x25519"
7text ot_syx_x "X"
8text ot_syx_b "B"
9text ot_syx_i "I"
10fn ot_syx_xr b view uchar * st edit ulong 10 to bool
11k = new uchar 32 0
12u = new uchar 32 0
13e = new uchar 32 0
14o = new uchar 32 0
15r = ot_sy_ndec b st
16kl = ot_sy_nhex b st k
17ul = ot_sy_nhex b st u
18el = ot_sy_nhex b st e
19if or ne kl 32 or ne ul 32 ne el 32
20ret false
21end
22ot_x25_mul o k u
23z = ot_ct_zero32 o
24if ne z eq r 1
25ret false
26end
27ret ot_ct_eq32 o e
28end
29fn ot_syx_br b view uchar * st edit ulong 10 to bool
30k = new uchar 32 0
31e = new uchar 32 0
32o = new uchar 32 0
33kl = ot_sy_nhex b st k
34el = ot_sy_nhex b st e
35if or ne kl 32 ne el 32
36ret false
37end
38ot_x25_base o k
39ret ot_ct_eq32 o e
40end
41note RFC 7748 5.2: k = u = 9; repeat N times: (k, u) = (X25519(k, u), k).
42fn ot_syx_it b view uchar * st edit ulong 10 to bool
43k = new uchar 32 0
44u = new uchar 32 0
45o = new uchar 32 0
46e = new uchar 32 0
47n = ot_sy_ndec b st
48el = ot_sy_nhex b st e
49if ne el 32
50ret false
51end
52put k 0 9
53put u 0 9
54j = ulong 0
55while lt j n bound 9223372036854775807
56ot_x25_mul o k u
57for i ulong 32 unroll
58put u i get k i
59put k i get o i
60end
61j = add j 1
62end
63ret ot_ct_eq32 k e
64end
65fn ot_syx_line b view uchar * st edit ulong 10 to bool
66if ot_sy_is b st ot_syx_x
67ret ot_syx_xr b st
68end
69if ot_sy_is b st ot_syx_b
70ret ot_syx_br b st
71end
72if ot_sy_is b st ot_syx_i
73ret ot_syx_it b st
74end
75put st 9 1
76ret true
77end
78fn ot_syx_file fd int b edit uchar * r edit ulong 4 to void
79st = new ulong 10 0
80while ot_sy_line fd b st bound 9223372036854775807
81n = ot_sy_tok b st
82if gt n 0
83if ne get b get st 6 35
84put st 9 0
85ok = ot_syx_line b st
86if eq get st 9 0
87ot_sy_res r ok ot_syx_area st
88end
89end
90end
91end
92if eq get st 2 2
93put r 1 add get r 1 1
94end
95end
96fn main to int
97b = new uchar 1048576 0
98pth = new uchar 4096 0
99r = new ulong 4 0
100st = new ulong 10 0
101na = argcnt
102i = ulong 1
103while lt i ulong na bound 4096
104fd = ot_sy_open i pth
105if lt fd 0
106put r 1 add get r 1 1
107ot_sy_bad ot_syx_area i st
108else
109ot_syx_file fd b r
110cl = fclose fd
111end
112i = add i 1
113end
114ret ot_sy_done ot_syx_area get r 0 get r 1
115end