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

107 lines · 2814 bytes Raw Blame History
1note omtls test driver hkdf: ot_hk_extract / ot_hk_expand on records P alg SALT IKM PRK (RFC 5869 A.1-A.3 extract)
2note and X alg SALT IKM INFO L OKM V (V 1: expand gives OKM; V 0: expand must refuse, e.g. L > 255 * hashlen).
3note Usage: hkdf FILE...
4text ot_syk_tp "P"
5text ot_syk_tx "X"
6text ot_syk_area "hkdf"
7note f: 0 salt length, 1 ikm length, 2 info length, 3 L, 4 expected length, 5 V, 6 record kind (0 P, 1 X).
8fn ot_syk_rec b view uchar * st edit ulong 10 a edit uchar 65536 c edit uchar 65536 f edit long 8 to bool
9info = new uchar 4096 0
10ex = new uchar 16384 0
11alg = ot_sy_alg ot_sy_ndec b st
12put f 0 ot_sy_nhex b st a
13put f 1 ot_sy_nhex b st c
14if eq get f 6 1
15put f 2 ot_sy_nhex b st info
16put f 3 long ot_sy_ndec b st
17end
18put f 4 ot_sy_nhex b st ex
19put f 5 long ot_sy_ndec b st
20bad = or lt get f 0 0 lt get f 1 0
21bad = or bad lt get f 2 0
22if or bad lt get f 4 0
23ret false
24end
25if eq get f 6 0
26ret ot_syk_p alg a c ex f
27end
28ret ot_syk_xr alg a c info ex f
29end
30fn ot_syk_ext alg ulong a view uchar 65536 c view uchar 65536 f view long 8 prk edit uchar 64 to ulong
31sn = ulong get f 0
32cn = ulong get f 1
33ret ot_hk_extract alg view part a 0 sn view part c 0 cn prk
34end
35fn ot_syk_p alg ulong a view uchar 65536 c view uchar 65536 ex view uchar 16384 f view long 8 to bool
36prk = new uchar 64 0
37hl = ot_syk_ext alg a c f prk
38if or eq hl 0 ne long hl get f 4
39ret false
40end
41ret ot_sy_eq prk ex hl
42end
43fn ot_syk_e3 alg ulong prk view uchar 64 info view uchar 4096 f view long 8 okm edit uchar 16384 to bool
44inn = ulong get f 2
45ln = ulong get f 3
46ret ot_hk_expand alg prk view part info 0 inn part okm 0 ln
47end
48fn ot_syk_xr alg ulong a view uchar 65536 c view uchar 65536 info view uchar 4096 ex view uchar 16384 f view long 8 to bool
49prk = new uchar 64 0
50okm = new uchar 16384 0
51hl = ot_syk_ext alg a c f prk
52if eq hl 0
53ret false
54end
55if gt get f 3 16384
56ret false
57end
58ok = ot_syk_e3 alg prk info f okm
59if eq get f 5 0
60ret not ok
61end
62if not ok
63ret false
64end
65ret and eq get f 3 get f 4 ot_sy_eq okm ex ulong get f 3
66end
67fn ot_syk_file fd int b edit uchar * r edit ulong 4 to void
68st = new ulong 10 0
69a = new uchar 65536 0
70c = new uchar 65536 0
71f = new long 8 0
72while ot_sy_line fd b st bound 9223372036854775807
73n = ot_sy_tok b st
74if ot_sy_is b st ot_syk_tp
75put f 6 0
76put f 2 0
77ot_sy_res r ot_syk_rec b st a c f ot_syk_area st
78end
79if ot_sy_is b st ot_syk_tx
80put f 6 1
81ot_sy_res r ot_syk_rec b st a c f ot_syk_area st
82end
83end
84if eq get st 2 2
85put r 1 add get r 1 1
86end
87end
88fn main to int
89b = new uchar 1048576 0
90pth = new uchar 4096 0
91r = new ulong 4 0
92st = new ulong 10 0
93na = argcnt
94i = ulong 1
95while lt i ulong na bound 4096
96fd = ot_sy_open i pth
97if lt fd 0
98put r 1 add get r 1 1
99ot_sy_bad ot_syk_area i st
100else
101ot_syk_file fd b r
102cl = fclose fd
103end
104i = add i 1
105end
106ret ot_sy_done ot_syk_area get r 0 get r 1
107end