interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / tls / test / chacha / bench.om

91 lines · 1961 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note bench.om: 1 MiB AEAD_CHACHA20_POLY1305 round trip, built as `om2`, chacha.om, bench.om.
3note key = bytes 0..31, nonce = bytes 32..43 (kn[i] = i), aad = 12 bytes 160..171, plaintext byte i =
4note (31 i + 7) mod 256. Writes the sealed buffer (1 MiB ciphertext || tag) to stdout once, then
5note opens and reseals it ROUNDS times, checking every open returns 0 with the plaintext restored
6note and the resealed buffer equal to the first. Exit 0 when all checks hold, 1 otherwise. run.sh
7note compares the stdout bytes with an independent oracle and times the whole run:
8note (1 + 2 ROUNDS) MiB pass through the AEAD.
9
10const BROUNDS ulong 16
11
12note fill b[0..1 MiB) with the pattern
13fn bfill b edit uchar * to void
14for h ulong 16
15for l ulong 65536
16i = add shl h 16 l
17put b i uchar and add mul i 31 7 255
18end
19end
20end
21
22note number of bytes of b[0..1 MiB) that differ from the pattern
23fn bcheck b view uchar * to ulong
24d = ulong 0
25for h ulong 16
26for l ulong 65536
27i = add shl h 16 l
28if ne get b i uchar and add mul i 31 7 255
29d = add d 1
30end
31end
32end
33ret d
34end
35
36note number of bytes where a and b differ (same length)
37fn bdiff a view uchar * b view uchar * to ulong
38d = ulong 0
39for h ulong 17
40for l ulong 65536
41i = add shl h 16 l
42if lt i len a
43if ne get a i get b i
44d = add d 1
45end
46end
47end
48end
49ret d
50end
51
52fn main to int
53b = new uchar 1048592 0
54c = new uchar 1048592 0
55kn = new uchar 44 0
56ad = new uchar 12 0
57for i ulong 44
58put kn i uchar i
59end
60for i ulong 12
61put ad i uchar add i 160
62end
63bfill b
64bad = aead_chacha_seal kn ad b
65for h ulong 17
66for l ulong 65536
67i = add shl h 16 l
68if lt i len b
69put c i get b i
70end
71end
72end
73t = ulong 0
74while lt t len b bound 999999
75w = write 1 b t sub len b t
76if le w 0
77ret 1
78end
79t = add t ulong w
80end
81for j ulong BROUNDS
82bad = or bad aead_chacha_open kn ad b
83bad = or bad bcheck part b 0 1048576
84bad = or bad aead_chacha_seal kn ad b
85bad = or bad bdiff b c
86end
87if ne bad 0
88ret 1
89end
90ret 0
91end