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 / ct / cc.om

103 lines · 2570 bytes Raw Blame History
1note omtls ChaCha20 constant-time core (RFC 8439 sections 2.1-2.3). uint arithmetic wraps mod 2^32; rotl by a
2note number is one ROR. Every index is a constant; no branch.
3note State: 0..3 the constants, 4..11 the key (little-endian words), 12 the block counter, 13..15 the nonce.
4fn ot_cc_kn st edit uint 16 kn view uchar 44 ctr uint to void
5put st 0 0x61707865
6put st 1 0x3320646e
7put st 2 0x79622d32
8put st 3 0x6b206574
9for i ulong 11 unroll
10w = uint get kn mul i 4
11w = or w shl uint get kn add mul i 4 1 8
12w = or w shl uint get kn add mul i 4 2 16
13w = or w shl uint get kn add mul i 4 3 24
14put st add 4 add i shr i 3 w
15end
16put st 12 ctr
17end
18note The block function: x = st, 20 rounds (10 column + diagonal double rounds), then x += st.
19fn ot_cc_blk st view uint 16 x edit uint 16 to void
20for i ulong 16 unroll
21put x i get st i
22end
23for r ulong 10 unroll
24note column rounds QUARTERROUND(i, 4+i, 8+i, 12+i)
25for i ulong 4 unroll
26a = get x i
27b = get x add 4 i
28c = get x add 8 i
29d = get x add 12 i
30a = add a b
31d = rotl xor d a 16
32c = add c d
33b = rotl xor b c 12
34a = add a b
35d = rotl xor d a 8
36c = add c d
37b = rotl xor b c 7
38put x i a
39put x add 4 i b
40put x add 8 i c
41put x add 12 i d
42end
43note diagonal rounds QUARTERROUND(i, 4+(i+1)%4, 8+(i+2)%4, 12+(i+3)%4)
44for i ulong 4 unroll
45a = get x i
46b = get x add 4 and add i 1 3
47c = get x add 8 and add i 2 3
48d = get x add 12 and add i 3 3
49a = add a b
50d = rotl xor d a 16
51c = add c d
52b = rotl xor b c 12
53a = add a b
54d = rotl xor d a 8
55c = add c d
56b = rotl xor b c 7
57put x i a
58put x add 4 and add i 1 3 b
59put x add 8 and add i 2 3 c
60put x add 12 and add i 3 3 d
61end
62end
63for i ulong 16 unroll
64put x i add get x i get st i
65end
66end
67note One quarter round on four words (RFC 8439 2.1), for the 2.1.1 test vector: q holds a, b, c, d.
68fn ot_cc_qr q edit uint 4 to void
69a = get q 0
70b = get q 1
71c = get q 2
72d = get q 3
73a = add a b
74d = rotl xor d a 16
75c = add c d
76b = rotl xor b c 12
77a = add a b
78d = rotl xor d a 8
79c = add c d
80b = rotl xor b c 7
81put q 0 a
82put q 1 b
83put q 2 c
84put q 3 d
85end
86note b ^= the 64 keystream bytes of block x (word i/4, little-endian byte i mod 4).
87fn ot_cc_x64 x view uint 16 b edit uchar 64 to void
88for w ulong 16 unroll
89v = ulong get x w
90for j ulong 4 unroll
91put b add mul w 4 j xor get b add mul w 4 j ot_ct_lo8 shr v mul j 8
92end
93end
94end
95note The 64 keystream bytes of block x into b (for the 2.3.2 / A.1 block vectors and the Poly1305 key).
96fn ot_cc_ser x view uint 16 b edit uchar 64 to void
97for w ulong 16 unroll
98v = ulong get x w
99for j ulong 4 unroll
100put b add mul w 4 j ot_ct_lo8 shr v mul j 8
101end
102end
103end