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 / seed / omc / sites / found-arrarg-3.om

261 lines · 6449 bytes Raw Blame History
1note sites: found by a one-token change of a tracked program (121 to 300 lines); reaches the omc error site in arrarg (code 20)
2note SPDX-License-Identifier: Apache-2.0
3note b3unit.om: BLAKE3 (default unkeyed hash, 32-byte output) as one function-mode unit, bound
4note through the omega-bridge native call ABI and exported as omega_omb3. It replaces the algorithm of
5note src/omega_blake3.c, which keeps only omega_blake3_hash: that cuts the input into 1024-byte chunks.
6note The tree logic follows om/blake3/blake3.om (the program form, kept for files and stdin).
7note
8note omb3 st b n fin o:
9note st caller state, zeroed before the first call: rows 0..53 of 8 words are the chaining-value
10note stack, word 440 its depth, word 441 the number of chunks absorbed
11note fin 0 b holds a whole chunk that is not the last one (n must be 1024): its chaining value is
12note merged into the stack
13note fin 1 b[0..n) is the last chunk (n 0..1024): the tree is finished and the root hash goes to o
14note A wrong n traps 3.
15note
16note Working words w (one array because globals are program-mode only):
17note 0..15 state s, 16..31 message m, 32..47 permute scratch, 48..55 input chaining value,
18note 56..71 compression output, 72 block length, 73 counter, 74 flags, 75..82 node chaining value,
19note 83..90 IV, 91..106 message permutation
20
21fn initw w edit ulong 128 to void
22put w 83 1779033703
23put w 84 3144134277
24put w 85 1013904242
25put w 86 2773480762
26put w 87 1359893119
27put w 88 2600822924
28put w 89 528734635
29put w 90 1541459225
30put w 91 2
31put w 92 6
32put w 93 3
33put w 94 10
34put w 95 7
35put w 96 0
36put w 97 4
37put w 98 13
38put w 99 1
39put w 100 11
40put w 101 12
41put w 102 5
42put w 103 9
43put w 104 14
44put w 105 15
45put w 106 8
46end
47
48note the G mixing function on state words a b c d with message words 2j and 2j+1
49fn g w edit ulong 128 a ulong b ulong c ulong d ulong j ulong to void
50x = get w add 16 mul j 2
51t = add get w a get w b
52put w a and add t x 4294967295
53t = xor get w d get w a
54put w d and or shr t 16 shl t 16 4294967295
55put w c and add get w c get w d 4294967295
56t = xor get w b get w c
57put w b and or shr t 12 shl t 20 4294967295
58x = get w add 17 mul j 2
59t = add get w a get w b
60put w a and add t x 4294967295
61t = xor get w d get w a
62put w d and or shr t 8 shl t 24 4294967295
63put w c and add get w c get w d 4294967295
64t = xor get w b get w c
65put w b and or shr t 7 shl t 25 4294967295
66end
67
68fn round w edit ulong 128 to void
69g w 0 4 8 12 0
70g w 1 5 9 13 1
71g w 2 6 10 14 2
72g w 3 7 11 15 3
73g w 0 5 10 15 4
74g w 1 6 11 12 5
75g w 2 7 8 13 6
76g w 3 4 9 14 7
77end
78
79fn permute w edit ulong 128 to void
80for i ulong 16
81put w add 32 i get w add 16 get w add 91 i
82end
83for i ulong 16
84put w add 16 i get w add 32 i
85end
86end
87
88note the 16 little-endian words of blk into m
89fn loadm w edit ulong 128 blk edit uchar 64 to void
90for i ulong 16
91o = mul i 4
92v = ulong get blk add o 3
93v = or shl v 8 ulong get blk add o 2
94v = or shl v 8 ulong get blk add o 1
95v = or shl v 8 ulong get blk o
96put w add 16 i v
97end
98end
99
100note compress (input chaining value, blk, block length, counter, flags) into the output words
101fn compress w edit ulong 128 blk edit uchar 64 to void
102loadm w blk
103for i ulong 8
104put w i get w add 48 i
105put w add i 8 get w add 83 i
106end
107put w 12 and get w 73 4294967295
108put w 13 and shr get w 73 32 4294967295
109put w 14 get w 72
110put w 15 get w 74
111for r ulong 7
112round w
113permute w
114end
115for i ulong 8
116put w add 56 i xor get w i get w add i 8
117put w add 64 i xor get w add i 8 get w add 48 i
118end
119end
120
121note compress, then the node chaining value is the first 8 output words
122fn nodecv w edit ulong 128 blk edit uchar 64 to void
123compress view blk
124for i ulong 8
125put w add 75 i get w add 56 i
126end
127end
128
129note copy cnt bytes of b from offset o into blk, zero the rest
130fn loadblk blk edit uchar 64 b view uchar 1024 o ulong cnt ulong to void
131for i ulong 64
132if lt i cnt
133put blk i get b add o i
134else
135put blk i 0
136end
137end
138end
139
140fn setnb w edit ulong 128 bl ulong ctr ulong fl ulong to void
141put w 72 bl
142put w 73 ctr
143put w 74 fl
144end
145
146note chunk ctr holding b[0..cnt): every block but the last compressed, the last left set up
147fn chunk w edit ulong 128 blk edit uchar 64 b view uchar 1024 cnt ulong ctr ulong to void
148for i ulong 8
149put w add 48 i get w add 83 i
150end
151nblk = ulong 1
152if gt cnt 0
153nblk = div add cnt 63 64
154end
155k = ulong 0
156while lt add k 1 nblk bound 16
157loadblk blk b mul k 64 64
158fl = ulong 0
159if eq k 0
160fl = 1
161end
162setnb w 64 ctr fl
163compress w blk
164for i ulong 8
165put w add 48 i get w add 56 i
166end
167k = add k 1
168end
169bo = mul sub nblk 1 64
170loadblk blk b bo sub cnt bo
171fl = ulong 2
172if eq nblk 1
173fl = 3
174end
175setnb w sub cnt bo ctr fl
176end
177
178note parent node of stack row r (left) and the node chaining value (right), set up to compress
179fn parentn w edit ulong 128 blk edit uchar 64 st edit ulong 448 r ulong to void
180for i ulong 8
181put w add 48 i get w add 83 i
182end
183for i ulong 8
184l = get st add mul r 8 i
185v = get w add 75 i
186for k ulong 4
187sh = mul k 8
188q = add mul i 4 k
189put blk q uchar and shr l sh 255
190put blk add 32 q uchar and shr v sh 255
191end
192end
193setnb w 64 0 4
194end
195
196fn push w edit ulong 128 st edit ulong 448 to void
197p = get st 440
198for i ulong 8
199put st add mul p 8 i get w add 75 i
200end
201put st 440 add p 1
202end
203
204note a whole chunk that is not the last: merge completed subtrees, then push its chaining value
205fn midchk w edit ulong 128 blk edit uchar 64 st edit ulong 448 b view uchar 1024 to void
206ctr = get st 441
207chunk w blk b 1024 ctr
208nodecv w blk
209tot = add ctr 1
210while eq and tot 1 0 bound 64
211d = sub get st 440 1
212put st 440 d
213parentn w blk st d
214nodecv w blk
215tot = shr tot 1
216end
217push w st
218put st 441 add ctr 1
219end
220
221note the last chunk: fold the stack into the root and write its 32 little-endian bytes into o
222fn lastchk w edit ulong 128 blk edit uchar 64 st edit ulong 448 b view uchar 1024 n ulong o edit uchar 32 to void
223chunk w blk b n get st 441
224while gt get st 440 0 bound 64
225nodecv w blk
226d = sub get st 440 1
227put st 440 d
228parentn w blk st d
229end
230put w 74 or get w 74 8
231compress w blk
232outle w o
233end
234
235note the first 8 output words, little endian, into o
236fn outle w edit ulong 128 o edit uchar 32 to void
237for i ulong 8
238v = get w add 56 i
239for k ulong 4
240q = add mul i 4 k
241put o q uchar and shr v mul k 8 255
242end
243end
244end
245
246fn omb3 st edit ulong 448 b view uchar 1024 n ulong fin ulong o edit uchar 32 to void
247w = new ulong 128 0
248blk = new uchar 64 0
249initw w
250if gt n 1024
251trap 3
252end
253if eq fin 0
254if ne n 1024
255trap 3
256end
257midchk w blk st b
258ret
259end
260lastchk w blk st b n o
261end