Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omtls/blob/main/src/aead.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtls / src / aead.om` 87 lines ยท 2206 bytes Raw Blame History 1 note omtls AEAD front (CONTRACT Interfaces): alg 1 AES-128-GCM, 2 AES-256-GCM, 3 ChaCha20-Poly1305 (RFC 8439 2.8). 2 note kn: key in bytes 0..31 (AES-128 uses 0..15), 12-byte nonce in 32..43. buf: text in buf[0 .. len-16], tag in the 3 note last 16 bytes. Refusals are defined, never traps: len buf < 16 or an unknown alg (seal writes zeros; open 4 note returns false with buf zeroed); a bad tag (buf zeroed, false). Open verifies the tag before any decryption. 5 note The ChaCha20-Poly1305 tag: Poly1305 under the block-0 key over aad || pad16 || ct || pad16 || le64 || le64. 6 fn ot_ae_cptag kn view uchar 44 aad view uchar * ct view uchar * tag edit uchar 16 to void 7 pk = new uchar 32 0 8 st = new ulong 24 0 9 lb = new uchar 16 0 10 ot_cc_pk kn pk 11 ot_p1_key st pk 12 ot_p1_upd st aad true 13 ot_p1_upd st ct true 14 na = len aad 15 nc = len ct 16 for i ulong 8 unroll 17 put lb i uchar and shr na mul i 8 255 18 put lb add 8 i uchar and shr nc mul i 8 255 19 end 20 ot_p1_blk st lb 1 21 ot_p1_tag st tag 22 for i ulong 32 unroll 23 put pk i 0 24 end 25 for i ulong 24 unroll 26 put st i 0 27 end 28 end 29 fn ot_ae_zero buf edit uchar * to void 30 for i ulong len buf 31 put buf i 0 32 end 33 end 34 fn ot_ae_cpseal kn view uchar 44 aad view uchar * buf edit uchar * to void 35 t = new uchar 16 0 36 m = sub len buf 16 37 ot_cc_xor kn 1 part buf 0 m 38 ot_ae_cptag kn aad view part buf 0 m t 39 for i ulong 16 unroll 40 put buf add m i get t i 41 end 42 end 43 fn ot_ae_cpopen kn view uchar 44 aad view uchar * buf edit uchar * to bool 44 t = new uchar 16 0 45 rt = new uchar 16 0 46 m = sub len buf 16 47 ot_ae_cptag kn aad view part buf 0 m t 48 for i ulong 16 unroll 49 put rt i get buf add m i 50 end 51 ok = ot_ct_eq16 t rt 52 if not ok 53 ot_ae_zero buf 54 ret false 55 end 56 ot_cc_xor kn 1 part buf 0 m 57 ret true 58 end 59 export fn ot_ae_seal alg ulong kn view uchar 44 aad view uchar * buf edit uchar * to void 60 if lt len buf 16 61 ot_ae_zero buf 62 ret 63 end 64 if eq alg 3 65 ot_ae_cpseal kn aad buf 66 ret 67 end 68 if or eq alg 1 eq alg 2 69 ot_gcm_seal eq alg 2 kn aad buf 70 ret 71 end 72 ot_ae_zero buf 73 end 74 export fn ot_ae_open alg ulong kn view uchar 44 aad view uchar * buf edit uchar * to bool 75 if lt len buf 16 76 ot_ae_zero buf 77 ret false 78 end 79 if eq alg 3 80 ret ot_ae_cpopen kn aad buf 81 end 82 if or eq alg 1 eq alg 2 83 ret ot_gcm_open eq alg 2 kn aad buf 84 end 85 ot_ae_zero buf 86 ret false 87 end