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

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