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

338 lines · 6493 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note x5io.om: test-driver helpers shared by tests/drv/{tm,der,x509}.om (not part of the library).
3note Output to stdout, a whole vector file in memory, one line at a time split into tokens on
4note spaces and tabs, decimal and hex tokens, and the CONTRACT summary line.
5note Lines that are empty or start with "#" are skipped. A path token is relative to the
6note directory of the vector file that names it.
7global ot_x5_ziob uchar 32
8global ot_x5_zib uchar 8388608
9note ot_x5_zik: token k starts at 2k and has length 2k+1 (k < 32); 64 count; 65 file length;
10note 66 read position; 67 directory prefix length; 68 passes; 69 failures; 70 line number
11global ot_x5_zik ulong 72
12global ot_x5_zip uchar 4096
13note ot_x5_zpf: the directory prefix of the vector file being read
14global ot_x5_zpf uchar 4096
15text ot_x5_zsF "FAIL "
16text ot_x5_zsP "PASS "
17text ot_x5_zsL " line "
18text ot_x5_zsS " "
19text ot_x5_zsC ": "
20text ot_x5_zsN "\n"
21text ot_x5_zsc " cases="
22text ot_x5_zsp " pass="
23text ot_x5_zsf " fail="
24text ot_x5_zsm "-"
25
26note ot_x5_ziw: all of t to stdout; exit 90 when stdout fails
27fn ot_x5_ziw t view uchar * to void
28p = ulong 0
29while lt p len t bound 1000000
30k = write 1 t p sub len t p
31if le k 0
32exit 90
33end
34p = add p ulong k
35end
36end
37
38fn ot_x5_ziwb o ulong n ulong to void
39p = o
40e = add o n
41while lt p e bound 1000000
42k = write 1 ot_x5_zib p sub e p
43if le k 0
44exit 90
45end
46p = add p ulong k
47end
48end
49
50note ot_x5_ziu: v in decimal, no newline
51fn ot_x5_ziu v ulong to void
52i = ulong 31
53n = v
54while true bound 21
55i = sub i 1
56put ot_x5_ziob i uchar add rem n 10 48
57n = div n 10
58if eq n 0
59break
60end
61end
62p = i
63while lt p 31 bound 32
64k = write 1 ot_x5_ziob p sub 31 p
65if le k 0
66exit 90
67end
68p = add p ulong k
69end
70end
71
72note ot_x5_zil: v in decimal with a sign, no newline
73fn ot_x5_zil v long to void
74if lt v 0
75ot_x5_ziw ot_x5_zsm
76ot_x5_ziu add ulong neg add v 1 1
77ret
78end
79ot_x5_ziu ulong v
80end
81
82fn ot_x5_ztk k ulong to ulong
83ret get ot_x5_zik mul k 2
84end
85fn ot_x5_ztl k ulong to ulong
86ret get ot_x5_zik add mul k 2 1
87end
88fn ot_x5_ztn to ulong
89ret get ot_x5_zik 64
90end
91
92note ot_x5_zitw: token k to stdout
93fn ot_x5_zitw k ulong to void
94ot_x5_ziwb ot_x5_ztk k ot_x5_ztl k
95end
96
97note ot_x5_ziread: read the file named by argument a into ot_x5_zib; false when it cannot
98fn ot_x5_ziread a ulong to bool
99k = argread a ot_x5_zip 0 4000
100if lt k 0
101ret false
102end
103n = ulong k
104put ot_x5_zik 67 0
105for i ulong n bound 16777216
106if eq get ot_x5_zip i 47
107put ot_x5_zik 67 add i 1
108end
109end
110for i ulong get ot_x5_zik 67 bound 16777216
111put ot_x5_zpf i get ot_x5_zip i
112end
113fd = fopen ot_x5_zip 0 n 0 0
114if lt fd 0
115ret false
116end
117t = ulong 0
118while true bound 1000000
119r = read int fd ot_x5_zib t sub len ot_x5_zib t
120if lt r 0
121c = fclose int fd
122ret false
123end
124if eq r 0
125break
126end
127t = add t ulong r
128if eq t len ot_x5_zib
129c = fclose int fd
130ret false
131end
132end
133c = fclose int fd
134put ot_x5_zik 65 t
135put ot_x5_zik 66 0
136put ot_x5_zik 70 0
137ret true
138end
139
140note ot_x5_zipath: the directory prefix of the vector file, then token k, in ot_x5_zip; the length
141fn ot_x5_zipath k ulong to ulong
142d = get ot_x5_zik 67
143n = ot_x5_ztl k
144if gt add d n 4000
145ret 0
146end
147for i ulong d bound 16777216
148put ot_x5_zip i get ot_x5_zpf i
149end
150o = ot_x5_ztk k
151for i ulong n bound 16777216
152put ot_x5_zip add d i get ot_x5_zib add o i
153end
154ret add d n
155end
156
157note ot_x5_ziline: the next line that is not empty and not a "#" comment, split into tokens
158fn ot_x5_ziline to bool
159e = get ot_x5_zik 65
160while lt get ot_x5_zik 66 e bound 16777216
161p = get ot_x5_zik 66
162q = p
163while lt q e bound 16777216
164if eq get ot_x5_zib q 10
165break
166end
167q = add q 1
168end
169put ot_x5_zik 66 add q 1
170put ot_x5_zik 70 add get ot_x5_zik 70 1
171ot_x5_zisplit p q
172if gt ot_x5_ztn 0
173if ne get ot_x5_zib ot_x5_ztk 0 35
174ret true
175end
176end
177end
178ret false
179end
180
181fn ot_x5_zisp c uchar to bool
182ret or or eq c 32 eq c 9 eq c 13
183end
184
185fn ot_x5_zisplit p ulong q ulong to void
186n = ulong 0
187i = p
188while lt i q bound 16777216
189if ot_x5_zisp get ot_x5_zib i
190i = add i 1
191else
192s = i
193while lt i q bound 16777216
194if ot_x5_zisp get ot_x5_zib i
195break
196end
197i = add i 1
198end
199if lt n 32
200put ot_x5_zik mul n 2 s
201put ot_x5_zik add mul n 2 1 sub i s
202n = add n 1
203end
204end
205end
206put ot_x5_zik 64 n
207end
208
209note ot_x5_zteq: token k is exactly t
210fn ot_x5_zteq k ulong t view uchar * to bool
211if ge k ot_x5_ztn
212ret false
213end
214if ne ot_x5_ztl k len t
215ret false
216end
217o = ot_x5_ztk k
218for i ulong len t bound 16777216
219if ne get ot_x5_zib add o i get t i
220ret false
221end
222end
223ret true
224end
225
226note ot_x5_ztdec: token k as a signed decimal; 0 with ot_x5_zik 71 set to 1 when it is not one
227fn ot_x5_ztdec k ulong to long
228put ot_x5_zik 71 1
229if ge k ot_x5_ztn
230ret 0
231end
232o = ot_x5_ztk k
233n = ot_x5_ztl k
234ng = false
235if gt n 0
236if eq get ot_x5_zib o 45
237ng = true
238o = add o 1
239n = sub n 1
240end
241end
242if or eq n 0 gt n 18
243ret 0
244end
245v = long 0
246for i ulong n bound 16777216
247c = get ot_x5_zib add o i
248if or lt c 48 gt c 57
249ret 0
250end
251v = add mul v 10 long sub c 48
252end
253put ot_x5_zik 71 0
254if ng
255ret neg v
256end
257ret v
258end
259
260fn ot_x5_zhx c uchar to ulong
261if and ge c 48 le c 57
262ret ulong sub c 48
263end
264if and ge c 97 le c 102
265ret ulong add sub c 97 10
266end
267if and ge c 65 le c 70
268ret ulong add sub c 65 10
269end
270ret 255
271end
272
273note ot_x5_zthex: token k as hex bytes into ot_der_m at offset o; the byte count or -1. "-" is empty.
274fn ot_x5_zthex k ulong o ulong to long
275if ge k ot_x5_ztn
276ret -1
277end
278s = ot_x5_ztk k
279n = ot_x5_ztl k
280if and eq n 1 eq get ot_x5_zib s 45
281ret 0
282end
283if ne rem n 2 0
284ret -1
285end
286m = div n 2
287for i ulong m bound 16777216
288a = ot_x5_zhx get ot_x5_zib add s mul i 2
289b = ot_x5_zhx get ot_x5_zib add s add mul i 2 1
290if or gt a 15 gt b 15
291ret -1
292end
293put ot_der_m add o i uchar or shl a 4 b
294end
295ret long m
296end
297
298note ot_x5_zifail: one FAILED case line: "FAIL <area> line <n> <name>: <why>"
299fn ot_x5_zifail area view uchar * why view uchar * to void
300put ot_x5_zik 69 add get ot_x5_zik 69 1
301ot_x5_ziw ot_x5_zsF
302ot_x5_ziw area
303ot_x5_ziw ot_x5_zsL
304ot_x5_ziu get ot_x5_zik 70
305ot_x5_ziw ot_x5_zsS
306if gt ot_x5_ztn 1
307ot_x5_zitw 1
308end
309ot_x5_ziw ot_x5_zsC
310ot_x5_ziw why
311ot_x5_ziw ot_x5_zsN
312end
313
314fn ot_x5_zipass to void
315put ot_x5_zik 68 add get ot_x5_zik 68 1
316end
317
318note ot_x5_ziend: the CONTRACT summary line; the exit status
319fn ot_x5_ziend area view uchar * to int
320p = get ot_x5_zik 68
321f = get ot_x5_zik 69
322if and eq f 0 gt p 0
323ot_x5_ziw ot_x5_zsP
324ot_x5_ziw area
325ot_x5_ziw ot_x5_zsc
326ot_x5_ziu p
327ot_x5_ziw ot_x5_zsN
328ret 0
329end
330ot_x5_ziw ot_x5_zsF
331ot_x5_ziw area
332ot_x5_ziw ot_x5_zsp
333ot_x5_ziu p
334ot_x5_ziw ot_x5_zsf
335ot_x5_ziu f
336ot_x5_ziw ot_x5_zsN
337ret 1
338end