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