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