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 hmac: ot_hm_mac on records T alg KEY MSG TAG V (RFC 4231 cases 1-7 and Wycheproof |
| 2 | note HMAC-SHA-256/384/512). The tag is compared on its first len(TAG) bytes (RFC 4231 case 5 truncates to 128 bits); |
| 3 | note V 1 must match, V 0 must not. Usage: hmac FILE... |
| 4 | text ot_syh_tt "T" |
| 5 | text ot_syh_area "hmac" |
| 6 | note f: key length, message length, tag length, V. |
| 7 | fn ot_syh_rec b view uchar * st edit ulong 10 k edit uchar 65536 m edit uchar 65536 t edit uchar 65536 to bool |
| 8 | f = new long 4 0 |
| 9 | alg = ot_sy_alg ot_sy_ndec b st |
| 10 | put f 0 ot_sy_nhex b st k |
| 11 | put f 1 ot_sy_nhex b st m |
| 12 | put f 2 ot_sy_nhex b st t |
| 13 | put f 3 long ot_sy_ndec b st |
| 14 | bad = or lt get f 0 0 lt get f 1 0 |
| 15 | bad = or bad lt get f 2 0 |
| 16 | if or bad gt get f 2 64 |
| 17 | ret false |
| 18 | end |
| 19 | ret ot_syh_chk alg k m t f |
| 20 | end |
| 21 | fn ot_syh_chk alg ulong k view uchar 65536 m view uchar 65536 t view uchar 65536 f view long 4 to bool |
| 22 | o = new uchar 64 0 |
| 23 | kn = ulong get f 0 |
| 24 | mn = ulong get f 1 |
| 25 | hl = ot_hm_mac alg view part k 0 kn view part m 0 mn o |
| 26 | if eq hl 0 |
| 27 | ret false |
| 28 | end |
| 29 | tn = ulong get f 2 |
| 30 | ok = ot_sy_eq o t tn |
| 31 | if eq get f 3 1 |
| 32 | ret ok |
| 33 | end |
| 34 | ret not ok |
| 35 | end |
| 36 | fn ot_syh_file fd int b edit uchar * r edit ulong 4 to void |
| 37 | st = new ulong 10 0 |
| 38 | k = new uchar 65536 0 |
| 39 | m = new uchar 65536 0 |
| 40 | t = new uchar 65536 0 |
| 41 | while ot_sy_line fd b st bound 9223372036854775807 |
| 42 | n = ot_sy_tok b st |
| 43 | if ot_sy_is b st ot_syh_tt |
| 44 | ot_sy_res r ot_syh_rec b st k m t ot_syh_area st |
| 45 | end |
| 46 | end |
| 47 | if eq get st 2 2 |
| 48 | put r 1 add get r 1 1 |
| 49 | end |
| 50 | end |
| 51 | fn main to int |
| 52 | b = new uchar 1048576 0 |
| 53 | pth = new uchar 4096 0 |
| 54 | r = new ulong 4 0 |
| 55 | st = new ulong 10 0 |
| 56 | na = argcnt |
| 57 | i = ulong 1 |
| 58 | while lt i ulong na bound 4096 |
| 59 | fd = ot_sy_open i pth |
| 60 | if lt fd 0 |
| 61 | put r 1 add get r 1 1 |
| 62 | ot_sy_bad ot_syh_area i st |
| 63 | else |
| 64 | ot_syh_file fd b r |
| 65 | cl = fclose fd |
| 66 | end |
| 67 | i = add i 1 |
| 68 | end |
| 69 | ret ot_sy_done ot_syh_area get r 0 get r 1 |
| 70 | end |