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

189 lines · 4743 bytes Raw Blame History
1note omtls test driver chacha: ChaCha20 (quarter round, block, stream), Poly1305, the Poly1305 key, and
2note AEAD_CHACHA20_POLY1305 through ot_ae_seal / ot_ae_open (alg 3).
3note Records: tests/vectors/chacha/rfc8439-sym.txt (Q B E P K D, see its header) and Wycheproof
4note "A KN AAD MSG CT||TAG CODE" (code 0 valid, 1 invalid, 2 nonce not 12 bytes: the API takes only a 12-byte
5note nonce, so such a case cannot be expressed and counts as refused). Usage: chacha FILE...
6text ot_syc_area "chacha"
7text ot_syc_q "Q"
8text ot_syc_b "B"
9text ot_syc_e "E"
10text ot_syc_p "P"
11text ot_syc_k "K"
12text ot_syc_d "D"
13text ot_syc_a "A"
14fn ot_syc_w b view uchar * st edit ulong 10 to uint
15t = new uchar 4 0
16n = ot_sy_nhex b st t
17v = shl uint get t 0 24
18v = or v shl uint get t 1 16
19v = or v shl uint get t 2 8
20ret or v uint get t 3
21end
22fn ot_syc_qr b view uchar * st edit ulong 10 to bool
23q = new uint 4 0
24for i ulong 4 unroll
25put q i ot_syc_w b st
26end
27ot_cc_qr q
28ok = true
29for i ulong 4 unroll
30ok = and ok eq get q i ot_syc_w b st
31end
32ret ok
33end
34note B KN CTR BLOCK
35fn ot_syc_bk b view uchar * st edit ulong 10 to bool
36kn = new uchar 44 0
37o = new uchar 64 0
38ex = new uchar 64 0
39n = ot_sy_nhex b st kn
40c = uint ot_sy_ndec b st
41m = ot_sy_nhex b st ex
42ot_cc_block kn c o
43ret and eq n 44 and eq m 64 ot_sy_eq o ex 64
44end
45note E KN CTR PT CT
46fn ot_syc_en b view uchar * st edit ulong 10 p edit uchar 65536 c edit uchar 65536 to bool
47kn = new uchar 44 0
48n = ot_sy_nhex b st kn
49ctr = uint ot_sy_ndec b st
50pn = ot_sy_nhex b st p
51cn = ot_sy_nhex b st c
52if or ne n 44 or lt pn 0 ne pn cn
53ret false
54end
55ot_cc_xor kn ctr part p 0 ulong pn
56ret ot_sy_eq p c ulong pn
57end
58note P KEY MSG TAG
59fn ot_syc_po b view uchar * st edit ulong 10 p edit uchar 65536 to bool
60k = new uchar 32 0
61t = new uchar 16 0
62ex = new uchar 16 0
63n = ot_sy_nhex b st k
64pn = ot_sy_nhex b st p
65m = ot_sy_nhex b st ex
66if or ne n 32 or lt pn 0 ne m 16
67ret false
68end
69ot_p1_mac k view part p 0 ulong pn t
70ret ot_sy_eq t ex 16
71end
72note K KN OTK
73fn ot_syc_ok b view uchar * st edit ulong 10 to bool
74kn = new uchar 44 0
75o = new uchar 32 0
76ex = new uchar 32 0
77n = ot_sy_nhex b st kn
78m = ot_sy_nhex b st ex
79ot_cc_pk kn o
80ret and eq n 44 and eq m 32 ot_sy_eq o ex 32
81end
82note D KN AAD PT CT TAG (RFC) or A KN AAD MSG CT||TAG CODE (Wycheproof): fields into a, p, c and f.
83fn ot_syc_ae b view uchar * st edit ulong 10 a edit uchar 65536 p edit uchar 65536 c edit uchar 65536 to bool
84kn = new uchar 44 0
85g = new long 8 0
86put g 0 ot_sy_nhex b st kn
87put g 1 ot_sy_nhex b st a
88put g 2 ot_sy_nhex b st p
89put g 3 ot_sy_nhex b st c
90if eq get st 9 1
91if or lt get g 3 0 gt get g 3 65520
92ret false
93end
94cl = ulong get g 3
95put g 4 ot_sy_nhex b st part c cl 16
96if ne get g 4 16
97ret false
98end
99put g 3 add get g 3 16
100put g 5 0
101else
102put g 4 0
103put g 5 long ot_sy_ndec b st
104end
105ret ot_syc_ae2 kn a p c g
106end
107note g: 0 KN length, 1 aad, 2 pt, 3 ct with its tag, 4 the separate tag length (D records), 5 Wycheproof code.
108fn ot_syc_ae2 kn view uchar 44 a edit uchar 65536 p view uchar 65536 c edit uchar 65536 g view long 8 to bool
109f = new ulong 8 0
110if eq get g 5 2
111ret ne get g 0 44
112end
113bad = or lt get g 1 0 lt get g 2 0
114bad = or bad or lt get g 3 0 lt get g 4 0
115if or bad ne get g 0 44
116ret false
117end
118put f 0 ulong get g 1
119put f 1 ulong get g 2
120put f 2 ulong get g 3
121put f 3 1
122if eq get g 5 1
123put f 3 0
124end
125put f 4 1
126ret ot_sye_run 3 kn a p c f
127end
128fn ot_syc_rec b view uchar * st edit ulong 10 a edit uchar 65536 p edit uchar 65536 c edit uchar 65536 to bool
129if ot_sy_is b st ot_syc_q
130ret ot_syc_qr b st
131end
132if ot_sy_is b st ot_syc_b
133ret ot_syc_bk b st
134end
135if ot_sy_is b st ot_syc_e
136ret ot_syc_en b st p c
137end
138if ot_sy_is b st ot_syc_p
139ret ot_syc_po b st p
140end
141if ot_sy_is b st ot_syc_k
142ret ot_syc_ok b st
143end
144put st 9 0
145if ot_sy_is b st ot_syc_d
146put st 9 1
147end
148ret ot_syc_ae b st a p c
149end
150fn ot_syc_kind b view uchar * st view ulong 10 to bool
151r = or or ot_sy_is b st ot_syc_q ot_sy_is b st ot_syc_b ot_sy_is b st ot_syc_e
152r = or r or ot_sy_is b st ot_syc_p ot_sy_is b st ot_syc_k
153ret or r or ot_sy_is b st ot_syc_d ot_sy_is b st ot_syc_a
154end
155fn ot_syc_file fd int b edit uchar * r edit ulong 4 to void
156st = new ulong 10 0
157a = new uchar 65536 0
158p = new uchar 65536 0
159c = new uchar 65536 0
160while ot_sy_line fd b st bound 9223372036854775807
161n = ot_sy_tok b st
162if ot_syc_kind b st
163ot_sy_res r ot_syc_rec b st a p c ot_syc_area st
164end
165end
166if eq get st 2 2
167put r 1 add get r 1 1
168end
169end
170fn main to int
171b = new uchar 1048576 0
172pth = new uchar 4096 0
173r = new ulong 4 0
174st = new ulong 10 0
175na = argcnt
176i = ulong 1
177while lt i ulong na bound 4096
178fd = ot_sy_open i pth
179if lt fd 0
180put r 1 add get r 1 1
181ot_sy_bad ot_syc_area i st
182else
183ot_syc_file fd b r
184cl = fclose fd
185end
186i = add i 1
187end
188ret ot_sy_done ot_syc_area get r 0 get r 1
189end