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 / interplane / v03 / aien_adapter.om

187 lines · 4947 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/interplane/v03/aien_adapter.om: pure-Omega port of interplane-mv adapters/aien.
3note Composes AIEN's existing gates and mints nothing:
4note - SPECS enrollment: read_file (READ_FS), list_dir (READ_FS), write_file (WORLD_MUT), bash_eval (SPAWN|WORLD_MUT)
5note - Fail-closed decide() when aegis gate is absent
6note - HMAC-SHA256 ApprovalBinding under DeskKey (RFC 2104 / RFC 4231)
7note - Two-phase approval spend (reserve / commit / release) with single-use grant replay refusal
8note - Provenance bundle digest commitment
9note Compose after si/directives/om2.om, om/tls/sha2.om, and protocol/interplane/v03/crossveil.om.
10
11const AIEN_CAP_READ_FILE ulong 1
12const AIEN_CAP_LIST_DIR ulong 2
13const AIEN_CAP_WRITE_FILE ulong 3
14const AIEN_CAP_BASH_EVAL ulong 4
15
16const AIEN_EFF_READ_FS ulong 1
17const AIEN_EFF_WORLD_MUT ulong 2
18const AIEN_EFF_SPAWN_PROC ulong 4
19
20const GRANT_UNUSED ulong 0
21const GRANT_RESERVED ulong 1
22const GRANT_SPENT ulong 2
23const GRANT_REVOKED ulong 3
24
25const AIEN_OK ulong 0
26const AIEN_ERR_UNKNOWN_CAP ulong 1
27const AIEN_ERR_GATE_UNAVAIL ulong 2
28const AIEN_ERR_BAD_MAC ulong 3
29const AIEN_ERR_GRANT_STATE ulong 4
30const AIEN_ERR_GRANT_REPLAY ulong 5
31const AIEN_ERR_GRANT_REVOKED ulong 6
32
33text aien_runtime_id "aien"
34text aien_engine_effect "aien-mcp.EffectClassAuthority"
35text aien_bind_ver "approval-binding/v1"
36
37note Capability enrollment (SPECS from adapters/aien/src/lib.rs)
38fn aien_cap_effects cap_id ulong to ulong
39if eq cap_id AIEN_CAP_READ_FILE
40ret AIEN_EFF_READ_FS
41end
42if eq cap_id AIEN_CAP_LIST_DIR
43ret AIEN_EFF_READ_FS
44end
45if eq cap_id AIEN_CAP_WRITE_FILE
46ret AIEN_EFF_WORLD_MUT
47end
48if eq cap_id AIEN_CAP_BASH_EVAL
49ret or AIEN_EFF_SPAWN_PROC AIEN_EFF_WORLD_MUT
50end
51ret ulong 0
52end
53
54note Fail-closed decide():
55note gate_linked: 0 -> always DENIED (UNAVAILABLE); 1 -> translates AIEN gate answer.
56note gate_allow: 1 -> AUTHORIZED (for pure read_fs) or REQUIRES_APPROVAL (for world_mut/spawn unless approved_grant=1).
57fn aien_decide cap_id ulong gate_linked ulong gate_allow ulong approved_grant ulong to ulong
58eff = aien_cap_effects cap_id
59if eq eff ulong 0
60ret CV_DEC_DENIED
61end
62if eq gate_linked ulong 0
63ret CV_DEC_DENIED
64end
65if eq gate_allow ulong 0
66ret CV_DEC_DENIED
67end
68note Pure read-only filesystem capability: AIEN gate Ok -> AUTHORIZED
69if eq eff AIEN_EFF_READ_FS
70ret CV_DEC_AUTHORIZED
71end
72note World mutation / process spawn requires an explicit AIEN-minted approval grant
73if eq approved_grant ulong 1
74ret CV_DEC_AUTHORIZED
75end
76ret CV_DEC_REQUIRES_APPROVAL
77end
78
79note --- RFC 2104 HMAC-SHA256 (for ApprovalBinding with DeskKey) ---
80fn aien_hmac_prep_key key view uchar * kblk edit uchar 64 to void
81kctx = new ulong 40 0
82kdig = new uchar 32 0
83klen = len key
84if gt klen ulong 64
85sha256_init kctx
86sha256_update kctx key
87sha256_final kctx kdig
88for i ulong 32
89put kblk i get kdig i
90end
91else
92i = ulong 0
93while lt i klen bound 64
94put kblk i get key i
95i = add i ulong 1
96end
97end
98end
99
100fn aien_hmac_inner kblk view uchar 64 msg view uchar * inner edit uchar 32 to void
101ipad = new uchar 64 0
102ictx = new ulong 40 0
103for j ulong 64
104put ipad j xor get kblk j uchar 0x36
105end
106sha256_init ictx
107sha256_update ictx ipad
108sha256_update ictx msg
109sha256_final ictx inner
110end
111
112fn aien_hmac_outer kblk view uchar 64 inner view uchar 32 mac edit uchar 32 to void
113opad = new uchar 64 0
114octx = new ulong 40 0
115for j ulong 64
116put opad j xor get kblk j uchar 0x5c
117end
118sha256_init octx
119sha256_update octx opad
120sha256_update octx inner
121sha256_final octx mac
122end
123
124fn aien_hmac_sha256 key view uchar * msg view uchar * mac edit uchar 32 to void
125kblk = new uchar 64 0
126inner = new uchar 32 0
127aien_hmac_prep_key key kblk
128aien_hmac_inner kblk msg inner
129aien_hmac_outer kblk inner mac
130end
131
132fn aien_mac_eq a view uchar 32 b view uchar 32 to bool
133diff = uchar 0
134for i ulong 32
135diff = or diff xor get a i get b i
136end
137ret eq diff uchar 0
138end
139
140note Two-phase single-use approval grant state machine (sovereign-core #260 / adapters/aien):
141note UNUSED -> RESERVED (reserve) -> SPENT (commit)
142note RESERVED -> UNUSED (release on aborted compose)
143note UNUSED -> REVOKED (revoke before spend; spent grants cannot be un-spent)
144fn aien_grant_reserve st edit ulong 1 to ulong
145cur = get st 0
146if eq cur GRANT_SPENT
147ret AIEN_ERR_GRANT_REPLAY
148end
149if eq cur GRANT_REVOKED
150ret AIEN_ERR_GRANT_REVOKED
151end
152if ne cur GRANT_UNUSED
153ret AIEN_ERR_GRANT_STATE
154end
155put st 0 GRANT_RESERVED
156ret AIEN_OK
157end
158
159fn aien_grant_commit st edit ulong 1 to ulong
160cur = get st 0
161if eq cur GRANT_SPENT
162ret AIEN_ERR_GRANT_REPLAY
163end
164if ne cur GRANT_RESERVED
165ret AIEN_ERR_GRANT_STATE
166end
167put st 0 GRANT_SPENT
168ret AIEN_OK
169end
170
171fn aien_grant_release st edit ulong 1 to ulong
172cur = get st 0
173if ne cur GRANT_RESERVED
174ret AIEN_ERR_GRANT_STATE
175end
176put st 0 GRANT_UNUSED
177ret AIEN_OK
178end
179
180fn aien_grant_revoke st edit ulong 1 to ulong
181cur = get st 0
182if eq cur GRANT_SPENT
183ret AIEN_ERR_GRANT_REPLAY
184end
185put st 0 GRANT_REVOKED
186ret AIEN_OK
187end