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

178 lines · 3322 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note tests/drv/der.om: ot_der_ and ot_b64_ cases. Arguments: vector files. Line forms (hex "-" = empty):
3note R <name> OK <tag> <value-length> <hex> | R <name> BAD <hex> ot_der_rd over exactly the bytes;
4note OK also needs the TLV to end at the last byte
5note I|B|O|S <name> OK|BAD <hex of contents> ot_der_okint / okbool / okoid / okbits
6note 6 <name> <hex of the decoded bytes>|BAD <base64 text> ot_b64_dec
7text ot_x5_zar "der"
8text ot_x5_zwR "R"
9text ot_x5_zwI "I"
10text ot_x5_zwB "B"
11text ot_x5_zwO "O"
12text ot_x5_zwS "S"
13text ot_x5_zw6 "6"
14text ot_x5_zwK "OK"
15text ot_x5_zwX "BAD"
16text ot_x5_zm1 "wrong tag or length"
17text ot_x5_zm2 "accepted, expected BAD"
18text ot_x5_zm3 "refused, expected OK"
19text ot_x5_zm4 "malformed vector line"
20text ot_x5_zm5 "cannot read vector file"
21text ot_x5_zm6 "wrong decoded bytes"
22
23note ot_x5_zdres: compare a result with the OK/BAD token 2
24fn ot_x5_zdres r bool to void
25if ot_x5_zteq 2 ot_x5_zwK
26if r
27ot_x5_zipass
28else
29ot_x5_zifail ot_x5_zar ot_x5_zm3
30end
31ret
32end
33if ot_x5_zteq 2 ot_x5_zwX
34if r
35ot_x5_zifail ot_x5_zar ot_x5_zm2
36else
37ot_x5_zipass
38end
39ret
40end
41ot_x5_zifail ot_x5_zar ot_x5_zm4
42end
43
44fn ot_x5_zdR to void
45if ot_x5_zteq 2 ot_x5_zwX
46n = ot_x5_zthex 3 0
47if lt n 0
48ot_x5_zifail ot_x5_zar ot_x5_zm4
49ret
50end
51ot_x5_zdres ot_der_rd 0 ulong n
52ret
53end
54m = ot_x5_zthex 5 0
55if lt m 0
56ot_x5_zifail ot_x5_zar ot_x5_zm4
57ret
58end
59if eq ot_der_rd 0 ulong m false
60ot_x5_zifail ot_x5_zar ot_x5_zm3
61ret
62end
63t = ot_x5_ztdec 3
64l = ot_x5_ztdec 4
65if or ne ot_der_tg ulong t ne ot_der_vl ulong l
66ot_x5_zifail ot_x5_zar ot_x5_zm1
67ret
68end
69if ne ot_der_nd ulong m
70ot_x5_zifail ot_x5_zar ot_x5_zm1
71ret
72end
73ot_x5_zipass
74end
75
76note ot_x5_zdC: content checks; k 1 INTEGER, 2 BOOLEAN, 3 OID, 4 BIT STRING
77fn ot_x5_zdC k ulong to void
78n = ot_x5_zthex 3 0
79if lt n 0
80ot_x5_zifail ot_x5_zar ot_x5_zm4
81ret
82end
83u = ulong n
84r = false
85if eq k 1
86r = ot_der_okint 0 u
87end
88if eq k 2
89r = ot_der_okbool 0 u
90end
91if eq k 3
92r = ot_der_okoid 0 u
93end
94if eq k 4
95r = ot_der_okbits 0 u
96end
97ot_x5_zdres r
98end
99
100note ot_x5_zd6: the base64 token is copied to store offset 65536 and decoded to offset 0; the expected
101note bytes are put at offset 1048576
102fn ot_x5_zd6 to void
103if ne ot_x5_ztn 4
104ot_x5_zifail ot_x5_zar ot_x5_zm4
105ret
106end
107o = ot_x5_ztk 3
108n = ot_x5_ztl 3
109for i ulong n bound 16777216
110put ot_der_m add 65536 i get ot_x5_zib add o i
111end
112r = ot_b64_dec 65536 add 65536 n 0
113if ot_x5_zteq 2 ot_x5_zwX
114if lt r 0
115ot_x5_zipass
116else
117ot_x5_zifail ot_x5_zar ot_x5_zm2
118end
119ret
120end
121x = ot_x5_zthex 2 1048576
122if lt x 0
123ot_x5_zifail ot_x5_zar ot_x5_zm4
124ret
125end
126if lt r 0
127ot_x5_zifail ot_x5_zar ot_x5_zm3
128ret
129end
130if or ne r x eq ot_der_eq 0 1048576 ulong x false
131ot_x5_zifail ot_x5_zar ot_x5_zm6
132ret
133end
134ot_x5_zipass
135end
136
137fn ot_x5_zdline to void
138if ot_x5_zteq 0 ot_x5_zwR
139ot_x5_zdR
140ret
141end
142if ot_x5_zteq 0 ot_x5_zwI
143ot_x5_zdC 1
144ret
145end
146if ot_x5_zteq 0 ot_x5_zwB
147ot_x5_zdC 2
148ret
149end
150if ot_x5_zteq 0 ot_x5_zwO
151ot_x5_zdC 3
152ret
153end
154if ot_x5_zteq 0 ot_x5_zwS
155ot_x5_zdC 4
156ret
157end
158if ot_x5_zteq 0 ot_x5_zw6
159ot_x5_zd6
160ret
161end
162ot_x5_zifail ot_x5_zar ot_x5_zm4
163end
164
165fn main to int
166a = ulong 1
167while lt long a argcnt bound 64
168if eq ot_x5_ziread a false
169ot_x5_zifail ot_x5_zar ot_x5_zm5
170else
171while ot_x5_ziline bound 1000000
172ot_x5_zdline
173end
174end
175a = add a 1
176end
177ret ot_x5_ziend ot_x5_zar
178end