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 / speed.om

242 lines · 4485 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note tests/drv/speed.om: handshakes per second and bulk throughput of the client.
3note usage: build/drv_speed FIXTURE-DIR hs N SUITE [PORT] N full handshakes (SUITE 4865 or 4867)
4note build/drv_speed FIXTURE-DIR bulk MIB SUITE [PORT] one connection, MIB MiB of application data sent
5note Without PORT the peer is the test server (tests/srv/tlssrv.om) forked on a private loopback port, so the time
6note includes the server's work on the same machine; with PORT the peer is an external server on 127.0.0.1 (for
7note example `openssl s_server`) presenting a mail.test certificate from FIXTURE-DIR's root.
8note Prints one line: "SPEED hs suite=S n=N ns=T per_second=R" or "SPEED bulk suite=S bytes=B ns=T mib_per_second=R"
9global sp_v ulong 16
10global sp_dir uchar 4096
11text sp_host "mail.test"
12text sp_via "127.0.0.1"
13text sp_none ""
14text sp_root "/root.pem"
15text sp_key "/leaf-key.txt"
16text sp_good "/leaf-good.der"
17text sp_l1 "SPEED hs suite="
18text sp_l2 "SPEED bulk suite="
19text sp_n " n="
20text sp_b " bytes="
21text sp_ns " ns="
22text sp_ps " per_second="
23text sp_mps " mib_per_second_x1000="
24text sp_nl "\n"
25text sp_fail "SPEED FAIL error="
26
27fn sp_say t view uchar * to void
28k = write 1 t 0 len t
29end
30fn sp_num n ulong to void
31d = new uchar 24 0
32v = n
33i = ulong 24
34while true bound 30
35i = sub i 1
36put d i uchar add 48 rem v 10
37v = div v 10
38if eq v 0
39break
40end
41end
42k = write 1 d i sub 24 i
43end
44fn sp_arg i ulong b edit uchar 4096 to ulong
45if ge i ulong argcnt
46ret 0
47end
48k = argread i b 0 4096
49if lt k 0
50ret 0
51end
52ret ulong k
53end
54fn sp_argnum i ulong to ulong
55b = new uchar 4096 0
56n = sp_arg i b
57v = ulong 0
58for j ulong n
59c = get b j
60if or lt c 48 gt c 57
61ret 0
62end
63v = add mul v 10 ulong sub c 48
64end
65ret v
66end
67fn sp_path p edit uchar 4096 t view uchar * to ulong
68n = get sp_v 0
69for i ulong n
70put p i get sp_dir i
71end
72for i ulong len t
73put p add n i get t i
74end
75ret add n len t
76end
77fn sp_listen pa edit ulong 1 to long
78sa = new uchar 16 0
79rnd = new uchar 2 0
80for tries ulong 50
81k = random rnd 0 2 0
82pt = add 40000 rem or shl ulong get rnd 0 8 ulong get rnd 1 20000
83put sa 0 2
84put sa 2 uchar shr pt 8
85put sa 3 uchar and pt 255
86put sa 4 127
87put sa 7 1
88fd = socknew 2 524289 0
89b = bind int fd sa 0 16
90if eq b 0
91if eq listen int fd 64 0
92put pa 0 pt
93ret fd
94end
95end
96z = fclose int fd
97end
98ret -1
99end
100note the forked server: `count` connections; for bulk it reads until close_notify
101fn sp_server lfd int count ulong suite ulong to void
102p = new uchar 4096 0
103q = new uchar 4096 0
104n = sp_path p sp_good
105m = sp_path q sp_key
106if not ot_ts_load part p 0 n part q 0 m
107exit 90
108end
109ot_ts_mode 0 suite 0
110b = new uchar 65536 0
111for i ulong count
112fd = accept lfd 0
113if lt fd 0
114exit 91
115end
116c = ot_ts_accept int fd
117if eq c 0
118while true bound 9223372036854775807
119r = ot_tl_read b
120if le r 0
121break
122end
123end
124ot_tl_close
125else
126z = fclose int fd
127end
128end
129exit 0
130end
131fn sp_hs n ulong port ulong to bool
132t0 = monons
133for i ulong n
134c = ot_tl_connect sp_host port sp_none
135if ne c 0
136sp_say sp_fail
137sp_num ulong c
138sp_say sp_nl
139ret false
140end
141ot_tl_close
142end
143t = ulong sub monons t0
144sp_say sp_l1
145sp_num ot_tl_suite
146sp_say sp_n
147sp_num n
148sp_say sp_ns
149sp_num t
150sp_say sp_ps
151sp_num div mul n 1000000000 t
152sp_say sp_nl
153ret true
154end
155fn sp_bulk mib ulong port ulong to bool
156b = new uchar 1048576 7
157c = ot_tl_connect sp_host port sp_none
158if ne c 0
159sp_say sp_fail
160sp_num ulong c
161sp_say sp_nl
162ret false
163end
164t0 = monons
165for i ulong mib
166if not ot_tl_write b
167sp_say sp_fail
168sp_num ulong ot_tl_err
169sp_say sp_nl
170ret false
171end
172end
173ot_tl_close
174t = ulong sub monons t0
175sp_say sp_l2
176sp_num ot_tl_suite
177sp_say sp_b
178sp_num mul mib 1048576
179sp_say sp_ns
180sp_num t
181sp_say sp_mps
182sp_num div mul mib 1000000000000 t
183sp_say sp_nl
184ret true
185end
186fn sp_setup to bool
187p = new uchar 4096 0
188n = sp_path p sp_root
189if le ot_tl_roots part p 0 n 0
190ret false
191end
192ret ot_tl_via sp_via
193end
194fn main to int
195k = argread 1 sp_dir 0 4000
196if le k 0
197ret 2
198end
199put sp_v 0 ulong k
200mb = new uchar 4096 0
201ml = sp_arg 2 mb
202hs = and eq ml 2 eq get mb 0 104
203n = sp_argnum 3
204suite = sp_argnum 4
205port = sp_argnum 5
206if not sp_setup
207ret 2
208end
209ot_tl_deadline 60000000000
210pid = long 0
211pa = new ulong 1 0
212wb = new uchar 4 0
213if eq port 0
214lfd = sp_listen pa
215if lt lfd 0
216ret 3
217end
218port = get pa 0
219cnt = ulong 1
220if hs
221cnt = n
222end
223pid = fork
224if eq pid 0
225sp_server int lfd cnt suite
226end
227z = fclose int lfd
228end
229ok = false
230if hs
231ok = sp_hs n port
232else
233ok = sp_bulk n port
234end
235if gt pid 0
236w = waitpid int pid wb 0 4 0
237end
238if ok
239ret 0
240end
241ret 1
242end