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

57 lines · 1528 bytes Raw Blame History
1note omtls HKDF (RFC 5869) over HMAC-SHA-256/384/512 (alg 0/1/2).
2note PRK = HMAC(salt, IKM); an empty salt is the same key as hashlen zero bytes (HMAC pads keys with zeros).
3export fn ot_hk_extract alg ulong salt view uchar * ikm view uchar * prk edit uchar 64 to ulong
4ret ot_hm_mac alg salt ikm prk
5end
6note T(k) = HMAC(PRK, T(k-1) || info || k) into t (t holds T(k-1) on entry; empty for k = 1).
7fn ot_hk_blk alg ulong kb view uchar 128 info view uchar * t edit uchar 64 k ulong to void
8c5 = new ulong 32 0
9c2 = new uchar 104 0
10cb = new uchar 1 0
11ot_hm_beg alg kb c5 c2
12if gt k 1
13ot_hm_hu alg c5 c2 view part t 0 ot_hm_hl alg
14end
15ot_hm_hu alg c5 c2 info
16put cb 0 uchar k
17ot_hm_hu alg c5 c2 cb
18ot_hm_end alg kb c5 c2 t
19end
20fn ot_hk_cp t view uchar 64 okm edit uchar * p ulong m ulong to void
21for i ulong m
22put okm add p i get t i
23end
24end
25note okm = the first L bytes of T(1) || T(2) || ... Refusal (false, okm all zero): an unknown alg or
26note L > 255 * hashlen. The PRK is the first hashlen bytes of prk.
27export fn ot_hk_expand alg ulong prk view uchar 64 info view uchar * okm edit uchar * to bool
28hl = ot_hm_hl alg
29kb = new uchar 128 0
30t = new uchar 64 0
31for i ulong len okm
32put okm i 0
33end
34if or eq hl 0 gt len okm mul 255 hl
35ret false
36end
37ot_hm_kb alg view part prk 0 hl kb
38p = ulong 0
39k = ulong 1
40while lt p len okm bound 256
41ot_hk_blk alg kb info t k
42m = sub len okm p
43if gt m hl
44m = hl
45end
46ot_hk_cp t okm p m
47p = add p m
48k = add k 1
49end
50for i ulong 128
51put kb i 0
52end
53for i ulong 64 unroll
54put t i 0
55end
56ret true
57end