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

62 lines · 1473 bytes Raw Blame History
1note omtls ChaCha20 driver layer (RFC 8439 2.4, 2.6): the stream over any length and the Poly1305 one-time key.
2note Loops and indices depend only on lengths; key and data bytes only reach the CT core.
3fn ot_cc_cpy64 d view uchar * p ulong m ulong b edit uchar 64 to void
4for i ulong m
5put b i get d add p i
6end
7end
8fn ot_cc_put64 b view uchar 64 d edit uchar * p ulong m ulong to void
9for i ulong m
10put d add p i get b i
11end
12end
13note buf ^= the ChaCha20 keystream for key and nonce kn (bytes 0..31 key, 32..43 nonce) from block counter ctr.
14fn ot_cc_xor kn view uchar 44 ctr uint buf edit uchar * to void
15st = new uint 16 0
16x = new uint 16 0
17b = new uchar 64 0
18ot_cc_kn st kn ctr
19n = len buf
20p = ulong 0
21while lt p n bound 9223372036854775807
22ot_cc_blk st x
23m = sub n p
24if gt m 64
25m = 64
26end
27ot_cc_cpy64 buf p m b
28ot_cc_x64 x b
29ot_cc_put64 b buf p m
30p = add p m
31put st 12 add get st 12 1
32end
33for i ulong 16 unroll
34put st i 0
35put x i 0
36end
37for i ulong 64 unroll
38put b i 0
39end
40end
41note The 64-byte keystream block at counter ctr (RFC 8439 2.3), and the Poly1305 key (2.6: block 0, first 32 bytes).
42fn ot_cc_block kn view uchar 44 ctr uint o edit uchar 64 to void
43st = new uint 16 0
44x = new uint 16 0
45ot_cc_kn st kn ctr
46ot_cc_blk st x
47ot_cc_ser x o
48for i ulong 16 unroll
49put st i 0
50put x i 0
51end
52end
53fn ot_cc_pk kn view uchar 44 pk edit uchar 32 to void
54b = new uchar 64 0
55ot_cc_block kn 0 b
56for i ulong 32 unroll
57put pk i get b i
58end
59for i ulong 64 unroll
60put b i 0
61end
62end