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 / aien-protocols / ext / probe.om

108 lines · 2807 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/aien-protocols/ext/probe.om: pure-Omega port of aien-probe
3note Implements probe request validation, challenge-response attestation hashing,
4note response verification, and deterministic SLA verdict classification.
5note Compose after si/directives/om2.om, om/tls/sha2.om, and protocol/aien-protocols/core/types.om.
6
7const PRB_OK ulong 0
8const PRB_ERR_KIND ulong 1
9const PRB_ERR_TARGET ulong 2
10const PRB_ERR_NONCE ulong 3
11const PRB_ERR_TIMEOUT ulong 4
12const PRB_ERR_ATTEST ulong 5
13
14const PRB_KIND_LIVENESS ulong 1
15const PRB_KIND_CAPABILITY ulong 2
16const PRB_KIND_LATENCY ulong 3
17const PRB_KIND_INTEGRITY ulong 4
18
19const PRB_VERDICT_PASS ulong 1
20const PRB_VERDICT_DEGRADED ulong 2
21const PRB_VERDICT_FAIL ulong 3
22const PRB_VERDICT_TIMEOUT ulong 4
23
24const PRB_MAX_TARGET_LEN ulong 256
25const PRB_MAX_TIMEOUT_MS ulong 300000
26
27text prb_dom_attest "aien-probe:v1|"
28text prb_sep "|"
29
30fn prb_kind_valid k ulong to bool
31ret and ge k PRB_KIND_LIVENESS le k PRB_KIND_INTEGRITY
32end
33
34fn prb_target_valid target view uchar * to bool
35n = len target
36if or eq n ulong 0 gt n PRB_MAX_TARGET_LEN
37ret false
38end
39i = ulong 0
40while lt i n bound 256
41b = get target i
42if or lt b uchar 33 gt b uchar 126
43ret false
44end
45i = add i ulong 1
46end
47ret true
48end
49
50fn prb_validate_request kind ulong target view uchar * nonce view uchar 16 timeout_ms ulong to ulong
51if not prb_kind_valid kind
52ret PRB_ERR_KIND
53end
54if not prb_target_valid target
55ret PRB_ERR_TARGET
56end
57if uuid_is_nil nonce
58ret PRB_ERR_NONCE
59end
60if or eq timeout_ms ulong 0 gt timeout_ms PRB_MAX_TIMEOUT_MS
61ret PRB_ERR_TIMEOUT
62end
63ret PRB_OK
64end
65
66fn prb_attest_head ctx edit ulong 40 kind ulong target view uchar * nonce view uchar 16 to void
67sha256_init ctx
68sha256_update ctx prb_dom_attest
69kb = new uchar 8 0
70klen = pt_put_u64_le kb ulong 0 kind
71sha256_update ctx part kb ulong 0 klen
72sha256_update ctx target
73sha256_update ctx prb_sep
74sha256_update ctx nonce
75end
76
77fn prb_attest_finish ctx edit ulong 40 status_code ulong rtt_us ulong dst edit uchar 32 to void
78buf = new uchar 16 0
79p0 = pt_put_u64_le buf ulong 0 status_code
80p1 = pt_put_u64_le buf p0 rtt_us
81sha256_update ctx part buf ulong 0 p1
82sha256_final ctx dst
83end
84
85fn prb_verify_attestation ctx edit ulong 40 status_code ulong rtt_us ulong claimed view uchar 32 to ulong
86exp = new uchar 32 0
87prb_attest_finish ctx status_code rtt_us exp
88if not digest_eq exp claimed
89ret PRB_ERR_ATTEST
90end
91ret PRB_OK
92end
93
94fn prb_classify_verdict status_code ulong rtt_us ulong soft_sla_us ulong hard_sla_us ulong to ulong
95if or eq hard_sla_us ulong 0 gt soft_sla_us hard_sla_us
96ret PRB_VERDICT_FAIL
97end
98if gt rtt_us hard_sla_us
99ret PRB_VERDICT_TIMEOUT
100end
101if ne status_code ulong 0
102ret PRB_VERDICT_FAIL
103end
104if gt rtt_us soft_sla_us
105ret PRB_VERDICT_DEGRADED
106end
107ret PRB_VERDICT_PASS
108end