Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omtls/blob/main/src/hkdf.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtls / src / hkdf.om` 57 lines ยท 1528 bytes Raw Blame History 1 note omtls HKDF (RFC 5869) over HMAC-SHA-256/384/512 (alg 0/1/2). 2 note PRK = HMAC(salt, IKM); an empty salt is the same key as hashlen zero bytes (HMAC pads keys with zeros). 3 export fn ot_hk_extract alg ulong salt view uchar * ikm view uchar * prk edit uchar 64 to ulong 4 ret ot_hm_mac alg salt ikm prk 5 end 6 note T(k) = HMAC(PRK, T(k-1) || info || k) into t (t holds T(k-1) on entry; empty for k = 1). 7 fn ot_hk_blk alg ulong kb view uchar 128 info view uchar * t edit uchar 64 k ulong to void 8 c5 = new ulong 32 0 9 c2 = new uchar 104 0 10 cb = new uchar 1 0 11 ot_hm_beg alg kb c5 c2 12 if gt k 1 13 ot_hm_hu alg c5 c2 view part t 0 ot_hm_hl alg 14 end 15 ot_hm_hu alg c5 c2 info 16 put cb 0 uchar k 17 ot_hm_hu alg c5 c2 cb 18 ot_hm_end alg kb c5 c2 t 19 end 20 fn ot_hk_cp t view uchar 64 okm edit uchar * p ulong m ulong to void 21 for i ulong m 22 put okm add p i get t i 23 end 24 end 25 note okm = the first L bytes of T(1) || T(2) || ... Refusal (false, okm all zero): an unknown alg or 26 note L > 255 * hashlen. The PRK is the first hashlen bytes of prk. 27 export fn ot_hk_expand alg ulong prk view uchar 64 info view uchar * okm edit uchar * to bool 28 hl = ot_hm_hl alg 29 kb = new uchar 128 0 30 t = new uchar 64 0 31 for i ulong len okm 32 put okm i 0 33 end 34 if or eq hl 0 gt len okm mul 255 hl 35 ret false 36 end 37 ot_hm_kb alg view part prk 0 hl kb 38 p = ulong 0 39 k = ulong 1 40 while lt p len okm bound 256 41 ot_hk_blk alg kb info t k 42 m = sub len okm p 43 if gt m hl 44 m = hl 45 end 46 ot_hk_cp t okm p m 47 p = add p m 48 k = add k 1 49 end 50 for i ulong 128 51 put kb i 0 52 end 53 for i ulong 64 unroll 54 put t i 0 55 end 56 ret true 57 end