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 / protocol / uor-gpu / canonical.om

229 lines · 6259 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/uor-gpu/canonical.om: Pure seeded OM-2 UOR-GPU-1 canonical codec (384B header),
3note SHA-256 (uor-addr), BLAKE3 (.holo), ML-BOM binding, and Ed25519 attestation layout.
4note Compose after si/directives/om2.om, om/tls/sha2.om, protocol/uor-gpu/b3_uor.om.
5
6const UOR_GPU_HDR_BYTES ulong 384
7const UOR_GPU_VERSION ulong 1
8const UOR_GPU_ISA_SM121 ulong 1
9const UOR_GPU_ISA_SPIRV ulong 2
10const UOR_GPU_MATH_RN ulong 1
11const UOR_GPU_MATH_FTZ ulong 2
12
13const UOR_LVL_P0 ulong 0
14const UOR_LVL_P1 ulong 1
15const UOR_LVL_P2 ulong 2
16const UOR_LVL_P3 ulong 3
17
18const UOR_VERDICT_PASS ulong 0
19const UOR_ERR_BAD_MAGIC ulong 1
20const UOR_ERR_BAD_TARGET ulong 2
21const UOR_ERR_PAYLOAD_TAMPER ulong 3
22const UOR_ERR_UOR_ID_TAMPER ulong 4
23const UOR_ERR_HOLO_TAMPER ulong 5
24const UOR_ERR_OMC_PIN ulong 6
25const UOR_ERR_LEVEL_LOW ulong 7
26const UOR_ERR_NO_LEAN_PROOF ulong 8
27const UOR_ERR_NO_REPLAY ulong 9
28const UOR_ERR_CAP_DENIED ulong 10
29const UOR_ERR_BAD_SIG ulong 11
30const UOR_ERR_REPLAY_MISMATCH ulong 12
31const UOR_ERR_UNTRUSTED_SIGNER ulong 13
32const UOR_ERR_LEAN_UNPINNED ulong 14
33const UOR_ERR_BAD_ANCHORS ulong 15
34const UOR_ERR_BAD_GRANT ulong 16
35const UOR_ERR_UNSIGNED_LEVEL ulong 17
36const UOR_ERR_BAD_QMD ulong 18
37const UOR_ERR_BAD_SPIRV ulong 19
38const UOR_ERR_REPLAY_FAULT ulong 20
39
40const UOR_SM121_CODE_BYTES ulong 512
41const UOR_SM121_QMD_BYTES ulong 384
42const UOR_SM121_PAYLOAD_BYTES ulong 896
43
44fn uor_put_u32 dst edit uchar * off ulong v ulong to void
45 put dst off uchar and v 255
46 put dst add off 1 uchar and shr v 8 255
47 put dst add off 2 uchar and shr v 16 255
48 put dst add off 3 uchar and shr v 24 255
49end
50
51fn uor_get_u32 src view uchar * off ulong to ulong
52 b0 = ulong get src off
53 b1 = ulong get src add off 1
54 b2 = ulong get src add off 2
55 b3 = ulong get src add off 3
56 r = or b0 shl b1 8
57 r = or r shl b2 16
58 ret or r shl b3 24
59end
60
61fn uor_put_u64 dst edit uchar * off ulong v ulong to void
62 uor_put_u32 dst off v
63 uor_put_u32 dst add off 4 shr v 32
64end
65
66fn uor_get_u64 src view uchar * off ulong to ulong
67 lo = uor_get_u32 src off
68 hi = uor_get_u32 src add off 4
69 ret or lo shl hi 32
70end
71
72fn uor_copy32 dst edit uchar * doff ulong src view uchar * soff ulong to void
73 for i ulong 32
74 put dst add doff i get src add soff i
75 end
76end
77
78fn uor_eq32 a view uchar * aoff ulong b view uchar * boff ulong to ulong
79 diff = ulong 0
80 for i ulong 32
81 x = ulong get a add aoff i
82 y = ulong get b add boff i
83 diff = or diff xor x y
84 end
85 if eq diff 0
86 ret 1
87 end
88 ret 0
89end
90
91fn uor_is_zero32 a view uchar * off ulong to ulong
92 acc = ulong 0
93 for i ulong 32
94 acc = or acc ulong get a add off i
95 end
96 if eq acc 0
97 ret 1
98 end
99 ret 0
100end
101
102fn uor_fill_b3_blk hdr view uchar 384 pay view uchar * blk edit uchar 1024 pos ulong take ulong to void
103 for i ulong take bound 1024
104 g = add pos i
105 if lt g 256
106 put blk i get hdr g
107 else
108 put blk i get pay sub g 256
109 end
110 end
111end
112
113note Compute BLAKE3 over header[0..255] || payload[0..len pay) into dst32.
114fn uor_holo_blake3 hdr view uchar 384 pay view uchar * dst32 edit uchar 32 to void
115 st = new ulong 448 0
116 blk = new uchar 1024 0
117 total = add 256 len pay
118 pos = ulong 0
119 while lt pos total bound 65536
120 take = sub total pos
121 if gt take 1024
122 take = ulong 1024
123 end
124 uor_fill_b3_blk hdr pay blk pos take
125 nxt = add pos take
126 if lt nxt total
127 b3_omb3 st blk 1024 0 dst32
128 else
129 b3_omb3 st blk take 1 dst32
130 end
131 pos = nxt
132 end
133end
134
135note Write canonical UOR-GPU-1 magic and scalar fields into hdr[0..31].
136note meta[5]: 0=isa (1=SM121,2=SPIRV), 1=math (1=RN,2=FTZ), 2=level (0..3), 3=plen, 4=block_x
137fn uor_hdr_write_meta hdr edit uchar 384 meta view ulong 5 to void
138 put hdr 0 uchar 85
139 put hdr 1 uchar 79
140 put hdr 2 uchar 82
141 put hdr 3 uchar 71
142 put hdr 4 uchar 80
143 put hdr 5 uchar 85
144 put hdr 6 uchar 49
145 put hdr 7 uchar 0
146 uor_put_u32 hdr 8 UOR_GPU_VERSION
147 uor_put_u32 hdr 12 get meta 0
148 uor_put_u32 hdr 16 get meta 1
149 uor_put_u32 hdr 20 get meta 2
150 uor_put_u32 hdr 24 get meta 3
151 uor_put_u32 hdr 28 get meta 4
152end
153
154note Seal a 384-byte UOR-GPU-1 header over payload.
155note Caller populates hdr[0..95] (meta+omc+src) and hdr[128..223] (lean+replay+mlbom).
156note Computes payload_sha256 -> [96..127], uor_id_sha256 -> [224..255], holo_blake3 -> [256..287].
157fn uor_hdr_seal hdr edit uchar 384 pay view uchar * to void
158 tmp = new uchar 32 0
159 h224 = new uchar 224 0
160 pdig = sha2_digest 256 pay tmp
161 if eq pdig 32
162 uor_copy32 hdr 96 tmp 0
163 end
164 for i ulong 224
165 put h224 i get hdr i
166 end
167 udig = sha2_digest 256 h224 tmp
168 if eq udig 32
169 uor_copy32 hdr 224 tmp 0
170 end
171 uor_holo_blake3 hdr pay tmp
172 uor_copy32 hdr 256 tmp 0
173end
174
175note Validate magic, version, target ISA, math contract, level, and all 3 digests.
176fn uor_hdr_check hdr view uchar 384 pay view uchar * to ulong
177 if or ne get hdr 0 uchar 85 ne get hdr 1 uchar 79
178 ret UOR_ERR_BAD_MAGIC
179 end
180 if or ne get hdr 2 uchar 82 ne get hdr 3 uchar 71
181 ret UOR_ERR_BAD_MAGIC
182 end
183 if or ne get hdr 4 uchar 80 ne get hdr 5 uchar 85
184 ret UOR_ERR_BAD_MAGIC
185 end
186 if or ne get hdr 6 uchar 49 ne get hdr 7 uchar 0
187 ret UOR_ERR_BAD_MAGIC
188 end
189 if ne uor_get_u32 hdr 8 UOR_GPU_VERSION
190 ret UOR_ERR_BAD_MAGIC
191 end
192 isa = uor_get_u32 hdr 12
193 if and ne isa UOR_GPU_ISA_SM121 ne isa UOR_GPU_ISA_SPIRV
194 ret UOR_ERR_BAD_TARGET
195 end
196 math = uor_get_u32 hdr 16
197 if and ne math UOR_GPU_MATH_RN ne math UOR_GPU_MATH_FTZ
198 ret UOR_ERR_BAD_TARGET
199 end
200 lvl = uor_get_u32 hdr 20
201 if gt lvl UOR_LVL_P3
202 ret UOR_ERR_BAD_TARGET
203 end
204 if or eq len pay 0 ne uor_get_u32 hdr 24 len pay
205 ret UOR_ERR_PAYLOAD_TAMPER
206 end
207 bx = uor_get_u32 hdr 28
208 if or eq bx 0 gt bx 1024
209 ret UOR_ERR_BAD_TARGET
210 end
211 tmp = new uchar 32 0
212 h224 = new uchar 224 0
213 pdig = sha2_digest 256 pay tmp
214 if or ne pdig 32 eq uor_eq32 hdr 96 tmp 0 0
215 ret UOR_ERR_PAYLOAD_TAMPER
216 end
217 for i ulong 224
218 put h224 i get hdr i
219 end
220 udig = sha2_digest 256 h224 tmp
221 if or ne udig 32 eq uor_eq32 hdr 224 tmp 0 0
222 ret UOR_ERR_UOR_ID_TAMPER
223 end
224 uor_holo_blake3 hdr pay tmp
225 if eq uor_eq32 hdr 256 tmp 0 0
226 ret UOR_ERR_HOLO_TAMPER
227 end
228 ret UOR_VERDICT_PASS
229end