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 / gpu / physics0 / types.om

248 lines · 5858 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/physics0/types.om: PD-0 core constants, structs, and FIPS 180-4 SHA-256 for sealed evidence framing.
3note Converted from src/physics0/{pd0_wire.h,pd0_guard.h,pd0_rng.h,pd0_gen.h,pd0_world.h}.
4
5const PD0_MAX_OBS ulong 4
6const PD0_MAX_CH ulong 2
7const PD0_HASH ulong 32
8const PD0_CH_NONE uchar 255
9const PD0_MICRO long 1000000
10const PD0_IH_SD long 577350
11const PD0_BOUND long 10000000
12const PD0_EPISODE_STEPS uint 100
13
14const PD0_OK uchar 0
15const PD0_REFUSED_RANGE uchar 1
16const PD0_OUT_OF_BOUNDS uchar 2
17const PD0_EPISODE_END uchar 3
18const PD0_BUDGET_EXHAUSTED uchar 4
19
20const PD0_KIND_RESET uchar 0
21const PD0_KIND_STEP uchar 1
22
23const PD0_OP_DESCRIBE uchar 0
24const PD0_OP_RESET uchar 1
25const PD0_OP_STEP uchar 2
26
27const PD0_DESC_REFUSED_V1 int -2
28
29const PD0_L0 int 0
30const PD0_L1 int 1
31const PD0_L2 int 2
32const PD0_L3 int 3
33const PD0_L4 int 4
34const PD0_L5 int 5
35const PD0_L6 int 6
36const PD0_LEVEL_NULL int 7
37
38struct Pd0Desc n_obs uchar n_channels uchar dt_micro long chan_min long 2 chan_max long 2 reset_min long 4 reset_max long 4 episode_max_steps uint budget_steps uint budget_episodes uint end
39
40struct Pd0Rec n_obs uchar status uchar kind uchar channel uchar seq ulong episode uint step_in_episode uint time_micro long requested long applied long before long 4 after long 4 prev_hash uint 8 hash uint 8 end
41
42struct Pd0Gen level int k long 4 sigma_obs long sigma_null long n_hidden int end
43
44struct Pd0World level int seed ulong noise_s ulong null_s ulong s long 4 h long in_episode int step_in_episode uint episodes_used uint steps_used uint episode uint seq ulong last_hash uint 8 end
45
46note ---- FIPS 180-4 SHA-256 for PD0REC1 evidence sealing ----
47
48fn pd0_sha_kinit k edit uint 64 to void
49put k 0 0x428a2f98
50put k 1 0x71374491
51put k 2 0xb5c0fbcf
52put k 3 0xe9b5dba5
53put k 4 0x3956c25b
54put k 5 0x59f111f1
55put k 6 0x923f82a4
56put k 7 0xab1c5ed5
57put k 8 0xd807aa98
58put k 9 0x12835b01
59put k 10 0x243185be
60put k 11 0x550c7dc3
61put k 12 0x72be5d74
62put k 13 0x80deb1fe
63put k 14 0x9bdc06a7
64put k 15 0xc19bf174
65put k 16 0xe49b69c1
66put k 17 0xefbe4786
67put k 18 0x0fc19dc6
68put k 19 0x240ca1cc
69put k 20 0x2de92c6f
70put k 21 0x4a7484aa
71put k 22 0x5cb0a9dc
72put k 23 0x76f988da
73put k 24 0x983e5152
74put k 25 0xa831c66d
75put k 26 0xb00327c8
76put k 27 0xbf597fc7
77put k 28 0xc6e00bf3
78put k 29 0xd5a79147
79put k 30 0x06ca6351
80put k 31 0x14292967
81put k 32 0x27b70a85
82put k 33 0x2e1b2138
83put k 34 0x4d2c6dfc
84put k 35 0x53380d13
85put k 36 0x650a7354
86put k 37 0x766a0abb
87put k 38 0x81c2c92e
88put k 39 0x92722c85
89put k 40 0xa2bfe8a1
90put k 41 0xa81a664b
91put k 42 0xc24b8b70
92put k 43 0xc76c51a3
93put k 44 0xd192e819
94put k 45 0xd6990624
95put k 46 0xf40e3585
96put k 47 0x106aa070
97put k 48 0x19a4c116
98put k 49 0x1e376c08
99put k 50 0x2748774c
100put k 51 0x34b0bcb5
101put k 52 0x391c0cb3
102put k 53 0x4ed8aa4a
103put k 54 0x5b9cca4f
104put k 55 0x682e6ff3
105put k 56 0x748f82ee
106put k 57 0x78a5636f
107put k 58 0x84c87814
108put k 59 0x8cc70208
109put k 60 0x90befffa
110put k 61 0xa4506ceb
111put k 62 0xbef9a3f7
112put k 63 0xc67178f2
113ret
114end
115
116fn pd0_sha_ch x uint y uint z uint to uint
117a = and x y
118b = and not x z
119ret xor a b
120end
121
122fn pd0_sha_maj x uint y uint z uint to uint
123a = and x y
124b = and x z
125c = and y z
126ret xor xor a b c
127end
128
129fn pd0_sha_bs0 x uint to uint
130ret xor xor rotr x 2 rotr x 13 rotr x 22
131end
132
133fn pd0_sha_bs1 x uint to uint
134ret xor xor rotr x 6 rotr x 11 rotr x 25
135end
136
137fn pd0_sha_ss0 x uint to uint
138ret xor xor rotr x 7 rotr x 18 shr x 3
139end
140
141fn pd0_sha_ss1 x uint to uint
142ret xor xor rotr x 17 rotr x 19 shr x 10
143end
144
145fn pd0_sha_be32 buf view uchar 64 off ulong to uint
146b0 = shl uint get buf off 24
147b1 = shl uint get buf add off 1 16
148b2 = shl uint get buf add off 2 8
149b3 = uint get buf add off 3
150ret or or b0 b1 or b2 b3
151end
152
153fn pd0_sha_compress st edit uint 8 blk view uchar 64 k view uint 64 to void
154w = new uint 64 0
155v = new uint 8 0
156for i ulong 16
157put w i pd0_sha_be32 blk mul i 4
158end
159for i ulong 48
160j = add i 16
161s0 = pd0_sha_ss0 get w sub j 15
162s1 = pd0_sha_ss1 get w sub j 2
163val = add add get w sub j 16 s0 add get w sub j 7 s1
164put w j val
165end
166for i ulong 8
167put v i get st i
168end
169for r ulong 64
170t1 = add get v 7 pd0_sha_bs1 get v 4
171t1 = add t1 pd0_sha_ch get v 4 get v 5 get v 6
172t1 = add t1 add get k r get w r
173t2 = add pd0_sha_bs0 get v 0 pd0_sha_maj get v 0 get v 1 get v 2
174put v 7 get v 6
175put v 6 get v 5
176put v 5 get v 4
177put v 4 add get v 3 t1
178put v 3 get v 2
179put v 2 get v 1
180put v 1 get v 0
181put v 0 add t1 t2
182end
183for i ulong 8
184put st i add get st i get v i
185end
186ret
187end
188
189fn pd0_sha_emit st view uint 8 dst edit uchar 32 to void
190for i ulong 8
191word = get st i
192off = mul i 4
193put dst off uchar and shr word 24 0xff
194put dst add off 1 uchar and shr word 16 0xff
195put dst add off 2 uchar and shr word 8 0xff
196put dst add off 3 uchar and word 0xff
197end
198ret
199end
200
201fn pd0_sha256_hash msg view uchar * mlen ulong dst edit uchar 32 to void
202st = new uint 8 0
203k = new uint 64 0
204blk = new uchar 64 0
205pd0_sha_kinit edit k
206put st 0 0x6a09e667
207put st 1 0xbb67ae85
208put st 2 0x3c6ef372
209put st 3 0xa54ff53a
210put st 4 0x510e527f
211put st 5 0x9b05688c
212put st 6 0x1f83d9ab
213put st 7 0x5be0cd19
214pos = ulong 0
215while ge sub mlen pos 64 bound 1024
216for i ulong 64
217put blk i get msg add pos i
218end
219pd0_sha_compress edit st view blk view k
220pos = add pos 64
221end
222rem_len = sub mlen pos
223for i ulong 64
224put blk i uchar 0
225end
226for i ulong rem_len bound 64
227put blk i get msg add pos i
228end
229put blk rem_len uchar 0x80
230if gt rem_len 55
231pd0_sha_compress edit st view blk view k
232for i ulong 64
233put blk i uchar 0
234end
235end
236bits = mul mlen 8
237put blk 56 uchar and shr bits 56 0xff
238put blk 57 uchar and shr bits 48 0xff
239put blk 58 uchar and shr bits 40 0xff
240put blk 59 uchar and shr bits 32 0xff
241put blk 60 uchar and shr bits 24 0xff
242put blk 61 uchar and shr bits 16 0xff
243put blk 62 uchar and shr bits 8 0xff
244put blk 63 uchar and bits 0xff
245pd0_sha_compress edit st view blk view k
246pd0_sha_emit view st dst
247ret
248end