interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / osc-unit-artifact / tools / make-vectors.sh

367 lines · 21728 bytes Raw Blame History
1#!/bin/bash
2# make-vectors.sh: regenerate the OSC unit artifact container v1 conformance
3# vectors. Contract: ../OSC_UNIT_ARTIFACT.md. Shell, xxd, sha256sum and
4# openssl (Ed25519) only. No Python.
5#
6# Usage: make-vectors.sh OUT_DIR [KEYS_DIR]
7# OUT_DIR normally specs/osc-unit-artifact/vectors
8# KEYS_DIR where to write the two public keys (default ../keys)
9#
10# Inputs (../src): min.osc, and its real compiler output min.ir (the canonical
11# IR, version byte 5) and min.code (A64 bytes), produced by omega `oscc` at
12# osh/osc-ext-bytes d64ccb3 (ir_sha256 and code_sha256 as `oscc` prints them).
13#
14# Keys: two THROWAWAY TEST keys derived from fixed labels (so vectors are
15# reproducible). They protect nothing and are not any AIEN key. Never reuse
16# them. "test1" signs class TEST; "owner1" is a TEST key standing in for an
17# OWNER key in OWNER-class vectors.
18#
19# Every structural mutant is re-signed so the refusal is attributable to the
20# intended check, not to a stale signature.
21set -eu
22export LC_ALL=C
23here=$(cd "$(dirname "$0")" && pwd)
24OUT=${1:?OUT_DIR}
25KEYS=${2:-$here/../keys}
26SRC=$here/../src
27mkdir -p "$OUT" "$KEYS"
28rm -f "$OUT"/*.unit
29tmp=$(mktemp -d)
30trap 'rm -rf "$tmp"' EXIT
31
32# ---- byte helpers ---------------------------------------------------------
33u8() { printf "\\x$(printf %02x "$1")"; }
34le16() { u8 $(($1 & 255)); u8 $((($1 >> 8) & 255)); }
35le32() { for s in 0 8 16 24; do u8 $((($1 >> s) & 255)); done; }
36le64() { le32 $(($1 & 0xffffffff)); le32 $((($1 >> 32) & 0xffffffff)); }
37hex2bin() { printf '%s' "$1" | xxd -r -p; }
38zeros() { head -c "$1" /dev/zero; }
39sha() { sha256sum | cut -d' ' -f1; }
40align16() { echo $((($1 + 15) / 16 * 16)); }
41# patch FILE OFFSET HEX... : copy of FILE with bytes replaced at OFFSET
42patch() {
43 local f=$1 off=$2
44 shift 2
45 head -c "$off" "$f"
46 for h in "$@"; do printf "\\x$h"; done
47 tail -c +$((off + 1 + $#)) "$f"
48}
49
50# ---- throwaway TEST keys --------------------------------------------------
51mkkey() { # NAME LABEL -> $tmp/NAME.pem, $KEYS/NAME.pub (64 hex chars)
52 local seed
53 seed=$(printf '%s' "$2" | sha)
54 { printf '302e020100300506032b657004220420'; printf '%s' "$seed"; } | xxd -r -p >"$tmp/$1.der"
55 openssl pkey -inform DER -in "$tmp/$1.der" -out "$tmp/$1.pem" 2>/dev/null
56 openssl pkey -in "$tmp/$1.pem" -pubout -outform DER 2>/dev/null | tail -c 32 | xxd -p -c 64 >"$KEYS/$1.pub"
57}
58mkkey test1 "AIEN OSC UNIT ARTIFACT V1 THROWAWAY TEST KEY 1 (TEST ONLY, NOT A REAL KEY)"
59mkkey owner1 "AIEN OSC UNIT ARTIFACT V1 THROWAWAY TEST KEY 2 (TEST ONLY, NOT A REAL KEY)"
60fp() { hex2bin "$(cat "$KEYS/$1.pub")" | sha; }
61
62# resign FILE KEY : recompute the signature over header+table, replace last 64 bytes
63resign() {
64 local f=$1 key=$2 n digest
65 n=$(stat -c %s "$f")
66 digest=$(head -c 320 "$f" | { printf 'AIENOS-OSC-UNIT-V1\0'; cat; } | sha)
67 { printf 'AIENOS-OSC-UNIT-SIGNATURE-V1\0'; hex2bin "$digest"; } >"$tmp/msg"
68 openssl pkeyutl -sign -inkey "$tmp/$key.pem" -rawin -in "$tmp/msg" -out "$tmp/sig" 2>/dev/null
69 { head -c $((n - 64)) "$f"; cat "$tmp/sig"; } >"$f.new"
70 mv "$f.new" "$f"
71}
72
73# ---- entry table (real functions of min.osc, from the compiler) -----------
74namehash() { { printf 'AIENOS-OSC-FN-NAME-V1\0'; printf '%s' "$1"; } | sha | head -c 32; }
75# entry FN_INDEX NREGS RET K0 K1 K2 K3 K4 K5 CODE_OFFSET NAME [HASH_HEX] [NAMELEN]
76# 96-byte record: 32-byte fixed part (name_hash is an index only) then name_len u8 and name[63]
77entry() {
78 local name=${11} h=${12:-} nl=${13:-${#11}}
79 [ -n "$h" ] || h=$(namehash "$name")
80 le16 "$1"; u8 "$2"; u8 "$3"; u8 "$4"; u8 "$5"; u8 "$6"; u8 "$7"; u8 "$8"; u8 "$9"; le16 0
81 le32 "${10}"; hex2bin "$h"
82 u8 "$nl"; printf '%s' "$name"; zeros $((63 - ${#name}))
83}
84entries_min() { entry 0 2 5 5 5 0 0 0 0 0 add; entry 1 2 5 11 5 0 0 0 0 60 first_byte; }
85
86# ---- caps section ---------------------------------------------------------
87caps_none() { le16 0; zeros 6; }
88# cap KIND ID RIGHTS BOUNDS_KIND MAXOPS MAXBYTES OFF LEN DOMAIN GENERATION
89cap() {
90 le16 "$1"; le16 0; le32 "$2"; le32 "$3"; le32 "$4"; le32 "$5"; le32 0
91 le64 "$6"; le64 "$7"; le64 "$8"; le16 "$9"; le16 0; le32 0; le64 "${10}"
92}
93
94# ---- container builder ----------------------------------------------------
95# build OUT KEYNAME CLASS UFV ABI NFN IRFILE CODEFILE ENTFILE CAPFILE
96build() {
97 local out=$1 key=$2 class=$3 ufv=$4 abi=$5 nfn=$6 irf=$7 codef=$8 entf=$9 capf=${10}
98 local o1 o2 o3 o4 l1 l2 l3 l4 end total
99 l1=$(stat -c %s "$irf"); l2=$(stat -c %s "$codef"); l3=$(stat -c %s "$entf"); l4=$(stat -c %s "$capf")
100 o1=320; o2=$(align16 $((o1 + l1))); o3=$(align16 $((o2 + l2))); o4=$(align16 $((o3 + l3)))
101 end=$((o4 + l4)); total=$((end + 64))
102 {
103 printf 'OSCUNIT\0'; le16 1; le16 128; le16 "$ufv"; le16 "$abi"; le32 0; le32 "$total"
104 le32 128; le16 4; le16 48; le16 "$nfn"; le16 0
105 le32 65536; le64 1000000; le16 0; le16 0; le32 0
106 le16 "$class"; le16 1; le32 0; hex2bin "$(fp "$key")"; zeros 32
107 local k=1 o l f
108 for f in "$irf" "$codef" "$entf" "$capf"; do
109 case $k in 1) o=$o1; l=$l1 ;; 2) o=$o2; l=$l2 ;; 3) o=$o3; l=$l3 ;; 4) o=$o4; l=$l4 ;; esac
110 le16 $k; le16 0; le32 $o; le32 $l; le32 0; hex2bin "$(sha <"$f")"
111 k=$((k + 1))
112 done
113 cat "$irf"; zeros $((o2 - o1 - l1))
114 cat "$codef"; zeros $((o3 - o2 - l2))
115 cat "$entf"; zeros $((o4 - o3 - l3))
116 cat "$capf"
117 zeros 64
118 } >"$out"
119 resign "$out" "$key"
120}
121
122cp "$SRC/min.ir" "$tmp/ir"; cp "$SRC/min.code" "$tmp/code"
123entries_min >"$tmp/ent"; caps_none >"$tmp/caps0"
124# one object READ request, kernel domain (1), generation 7
125{ le16 1; zeros 6; cap 3 1 1 1 4 4096 0 4096 1 7; } >"$tmp/caps1"
126# hosted-domain (2) request with a generation above 2^32
127{ le16 1; zeros 6; cap 3 1 1 1 4 4096 0 4096 2 1099511627777; } >"$tmp/caps2"
128# kernel-domain request whose generation does not fit 32 bits
129{ le16 1; zeros 6; cap 3 1 1 1 4 4096 0 4096 1 4294967296; } >"$tmp/capsbig"
130
131V=$OUT
132build "$V/a01_valid_min.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/caps0"
133build "$V/a02_valid_caps_kernel_domain.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/caps1"
134build "$V/a03_valid_hosted_domain.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/caps2"
135build "$V/a04_valid_owner_class.unit" owner1 2 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/caps0"
136base=$V/a01_valid_min.unit
137sz=$(stat -c %s "$base")
138
139m() { # NAME OFFSET HEX... : patch base, then re-sign with test1
140 local name=$1 off=$2
141 shift 2
142 patch "$base" "$off" "$@" >"$V/$name"
143 resign "$V/$name" test1
144}
145m r01_bad_magic.unit 0 58
146m r02_container_version_2.unit 8 02
147m r03_unit_format_6.unit 12 06
148m r04_abi_version_2.unit 14 02
149m r05_unknown_flags.unit 16 01
150m r06_header_field_reserved.unit 34 01
151head -c $((sz - 100)) "$base" >"$V/r07_truncated_file.unit"
152# section 2 (code) claims a length that runs past the signature
153m r08_section_bounds.unit 184 ff ff 00 00
154# section 2 (code) starts inside section 1 (IR)
155m r09_section_overlap.unit 180 50 01 00 00
156m r10_section_layout_offset.unit 180 b8 01 00 00
157m r11_too_many_functions.unit 32 21 00
158# content tampered, table untouched (signature still valid over the table)
159patch "$base" 440 $(printf %02x $(($(xxd -p -s 440 -l 1 "$base" | head -c2 | sed 's/^/0x/' | xargs printf %d) ^ 1))) >"$V/r12_code_hash_mismatch.unit"
160patch "$base" 330 $(printf %02x $(($(xxd -p -s 330 -l 1 "$base" | head -c2 | sed 's/^/0x/' | xargs printf %d) ^ 1))) >"$V/r13_ir_hash_mismatch.unit"
161# last signature byte flipped
162patch "$base" $((sz - 1)) $(printf %02x $(($(xxd -p -s $((sz - 1)) -l 1 "$base" | sed 's/^/0x/' | xargs printf %d) ^ 1))) >"$V/r14_bad_signature.unit"
163# IR version byte (offset 327 = 320 + 7) disagrees with the header
164{
165 cp "$tmp/ir" "$tmp/ir_v4"
166 patch "$tmp/ir" 7 04 >"$tmp/ir_v4"
167 build "$V/r15_ir_version_mismatch.unit" test1 1 5 1 2 "$tmp/ir_v4" "$tmp/code" "$tmp/ent" "$tmp/caps0"
168}
169# entry table: function 1 claims an unaligned code offset (61)
170{
171 { entry 0 2 5 5 5 0 0 0 0 0 add; entry 1 2 5 11 5 0 0 0 0 61 first_byte; } >"$tmp/ent_bad"
172 build "$V/r16_entry_table_unaligned.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_bad" "$tmp/caps0"
173}
174# 33 functions: a real 33-entry table, header count 33
175{
176 for i in $(seq 0 32); do entry "$i" 0 0 0 0 0 0 0 0 $((i * 4)) "f$i"; done >"$tmp/ent33"
177 head -c 132 "$tmp/code" >"$tmp/code33"
178 build "$V/r17_too_many_functions.unit" test1 1 5 1 33 "$tmp/ir" "$tmp/code33" "$tmp/ent33" "$tmp/caps0"
179}
180build "$V/r18_gen_not_representable.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/capsbig"
181# same bytes as a01; the verdict differs only by loader mode (see expected.txt)
182cp "$base" "$V/r19_test_signer_release.unit"
183cp "$V/a03_valid_hosted_domain.unit" "$V/r20_domain_unsupported.unit"
184cp "$V/a04_valid_owner_class.unit" "$V/r21_untrusted_owner_signer.unit"
185# unsigned trailing byte
186{ cat "$base"; printf '\0'; } >"$V/r22_trailing_byte.unit"
187
188# ---- entry name rules (bounded exact-match names; hash is only an index) ---
189ent_with() { # NAME_OF_FILE ENTRY1_ARGS... : entry 0 (add) then a custom entry 1
190 local out=$1; shift
191 { entry 0 2 5 5 5 0 0 0 0 0 add; entry "$@"; } >"$out"
192}
193ent_with "$tmp/ent_charset" 1 2 5 11 5 0 0 0 0 60 "bad name"
194ent_with "$tmp/ent_empty" 1 2 5 11 5 0 0 0 0 60 ""
195ent_with "$tmp/ent_long" 1 2 5 11 5 0 0 0 0 60 first_byte "" 64
196ent_with "$tmp/ent_dup" 1 2 5 11 5 0 0 0 0 60 add
197ent_with "$tmp/ent_hashshare" 1 2 5 11 5 0 0 0 0 60 first_byte "$(namehash add)"
198ent_with "$tmp/ent_hashshare_case" 1 2 5 11 5 0 0 0 0 60 ADD "$(namehash add)"
199entries_min >"$tmp/ent_pad"
200# nonzero byte in the padding after "add" (entry 0: name_len at 32, name at 33..35, padding from 36)
201patch "$tmp/ent_pad" 38 41 >"$tmp/ent_pad2"
202build "$V/r23_entry_name_charset.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_charset" "$tmp/caps0"
203build "$V/r24_entry_name_empty.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_empty" "$tmp/caps0"
204build "$V/r25_entry_name_too_long.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_long" "$tmp/caps0"
205build "$V/r26_entry_name_padding.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_pad2" "$tmp/caps0"
206build "$V/r27_entry_name_duplicate.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_dup" "$tmp/caps0"
207build "$V/r28_entry_hash_shared_other_name.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_hashshare" "$tmp/caps0"
208build "$V/r48_entry_hash_shared_case_variant.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_hashshare_case" "$tmp/caps0"
209
210# ---- review-driven vectors (aien-protocols#17 line review) -----------------
211flip() { # FILE OFFSET : copy of FILE with the byte at OFFSET xor 1
212 local b
213 b=$(xxd -p -s "$2" -l 1 "$1")
214 patch "$1" "$2" "$(printf %02x $((0x$b ^ 1)))"
215}
216m r29_total_length_low.unit 20 40 00 00 00
217m r30_section_table_kind.unit 128 09 00
218flip "$base" 700 >"$V/r31_entry_hash_mismatch.unit"
219flip "$base" 806 >"$V/r32_caps_hash_mismatch.unit"
220{ le16 1; zeros 6; cap 3 1 64 1 4 4096 0 4096 1 7; } >"$tmp/caps_rights"
221build "$V/r33_caps_table_bad_rights.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/caps_rights"
222m r34_signer_class_3.unit 56 03 00
223m r35_signature_algorithm_2.unit 58 02 00
224# two records: a too-wide generation in domain 1 first, an unsupported domain 2 second.
225# One first refusal for the whole table: all domains are checked before any generation (27, not 28).
226{ le16 2; zeros 6; cap 3 1 1 1 4 4096 0 4096 1 4294967296; cap 3 1 1 1 4 4096 0 4096 2 1; } >"$tmp/caps_order"
227build "$V/r36_domain_before_generation.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/caps_order"
228codeplus() { # NAME LE_WORD_HEX : min.code plus one trailing instruction word
229 { cat "$tmp/code"; hex2bin "$2"; } >"$tmp/code_$1"
230 build "$V/$3" test1 1 5 1 2 "$tmp/ir" "$tmp/code_$1" "$tmp/ent" "$tmp/caps0"
231}
232codeplus svc 010000d4 r37_code_svc.unit
233codeplus hvc 020000d4 r38_code_hvc.unit
234codeplus smc 030000d4 r39_code_smc.unit
235codeplus msr 40d01bd5 r40_code_msr_sysreg.unit
236codeplus mrs 40d03bd5 r41_code_mrs_sysreg.unit
237codeplus brk0 000020d4 r42_code_brk_imm0.unit
238codeplus brk15 e00120d4 r43_code_brk_imm15.unit
239{ le16 2; zeros 6; cap 3 2 1 1 4 4096 0 4096 1 7; cap 3 1 1 1 4 4096 0 4096 1 7; } >"$tmp/caps_disorder"
240build "$V/r44_caps_disorder.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent" "$tmp/caps_disorder"
241# non-canonical signature: same R, S replaced by S + L (L = ed25519 group order)
242L=1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed
243sbe=$(tail -c 32 "$base" | xxd -p -c 32 | fold -w2 | tac | tr -d '\n' | tr a-f A-F)
244sum=$(printf 'obase=16\nibase=16\n%s+%s\n' "$sbe" "$(echo $L | tr a-f A-F)" | bc | tr -d '\\\n')
245sum=$(printf '%064s' "$sum" | tr ' ' 0 | tr A-F a-f)
246{ head -c $((sz - 32)) "$base"; hex2bin "$(echo "$sum" | fold -w2 | tac | tr -d '\n')"; } >"$V/r45_signature_s_not_canonical.unit"
247patch "$base" 184 e0 ff ff ff >"$V/r46_section_bounds_u32_wrap.unit"
248resign "$V/r46_section_bounds_u32_wrap.unit" test1
249# slice entry kinds (bytes / cells) are valid only for unit format 5
250cp "$tmp/ir" "$tmp/ir_v4"; patch "$tmp/ir" 7 04 >"$tmp/ir_v4"
251build "$V/r47_slice_kind_in_format_4.unit" test1 1 4 1 2 "$tmp/ir_v4" "$tmp/code" "$tmp/ent" "$tmp/caps0"
252{ entry 0 2 5 5 5 0 0 0 0 0 add; entry 1 2 5 12 5 0 0 0 0 60 fill_cells; } >"$tmp/ent_cells"
253build "$V/a05_valid_cells_entry.unit" test1 1 5 1 2 "$tmp/ir" "$tmp/code" "$tmp/ent_cells" "$tmp/caps0"
254# declared-limit bounds (section 4.1 ranges are inclusive): one over each maximum, and all three exactly at the maximum
255m r49_cpu_ticks_over_max.unit 40 01 ca 9a 3b 00 00 00 00
256m r50_stack_over_max.unit 36 10 00 10 00
257m r51_pool_slots_over_max.unit 48 41 00
258patch "$base" 36 00 00 10 00 >"$tmp/at_max1"; patch "$tmp/at_max1" 40 00 ca 9a 3b 00 00 00 00 >"$tmp/at_max2"; patch "$tmp/at_max2" 48 40 00 >"$V/a06_valid_limits_at_max.unit"
259resign "$V/a06_valid_limits_at_max.unit" test1
260
261# ---- expected verdicts ----------------------------------------------------
262# columns: vector mode domains anchors verdict
263udig() { head -c 320 "$1" | { printf 'AIENOS-OSC-UNIT-V1\0'; cat; } | sha; }
264irid=$(sha <"$SRC/min.ir")
265{
266 echo "# vector mode domains anchors verdict (anchors: T TEST anchor present, O OWNER anchor present, - none)"
267 echo "a01_valid_min.unit qualification 1 T ACCEPT unit_digest=$(udig "$V/a01_valid_min.unit") program_id=$irid"
268 echo "a02_valid_caps_kernel_domain.unit qualification 1 T ACCEPT unit_digest=$(udig "$V/a02_valid_caps_kernel_domain.unit") program_id=$irid"
269 echo "a03_valid_hosted_domain.unit qualification 1,2 T ACCEPT unit_digest=$(udig "$V/a03_valid_hosted_domain.unit") program_id=$irid"
270 echo "a04_valid_owner_class.unit release 1 O ACCEPT unit_digest=$(udig "$V/a04_valid_owner_class.unit") program_id=$irid"
271 echo "r01_bad_magic.unit qualification 1 T REFUSED BAD_MAGIC 2"
272 echo "r02_container_version_2.unit qualification 1 T REFUSED CONTAINER_VERSION 3"
273 echo "r03_unit_format_6.unit qualification 1 T REFUSED UNIT_FORMAT 5"
274 echo "r04_abi_version_2.unit qualification 1 T REFUSED ABI_VERSION 6"
275 echo "r05_unknown_flags.unit qualification 1 T REFUSED UNKNOWN_FLAGS 7"
276 echo "r06_header_field_reserved.unit qualification 1 T REFUSED HEADER_FIELD 4"
277 echo "r07_truncated_file.unit qualification 1 T REFUSED TRUNCATED 1"
278 echo "r08_section_bounds.unit qualification 1 T REFUSED SECTION_BOUNDS 11"
279 echo "r09_section_overlap.unit qualification 1 T REFUSED SECTION_OVERLAP 12"
280 echo "r10_section_layout_offset.unit qualification 1 T REFUSED SECTION_LAYOUT 13"
281 echo "r11_too_many_functions.unit qualification 1 T REFUSED LIMIT_EXCEEDED 14"
282 echo "r12_code_hash_mismatch.unit qualification 1 T REFUSED CODE_HASH_MISMATCH 16"
283 echo "r13_ir_hash_mismatch.unit qualification 1 T REFUSED IR_HASH_MISMATCH 15"
284 echo "r14_bad_signature.unit qualification 1 T REFUSED BAD_SIGNATURE 26"
285 echo "r15_ir_version_mismatch.unit qualification 1 T REFUSED IR_MALFORMED 19"
286 echo "r16_entry_table_unaligned.unit qualification 1 T REFUSED ENTRY_TABLE 20"
287 echo "r17_too_many_functions.unit qualification 1 T REFUSED LIMIT_EXCEEDED 14"
288 echo "r18_gen_not_representable.unit qualification 1 T REFUSED CAP_GEN_NOT_REPRESENTABLE 28"
289 echo "r19_test_signer_release.unit release 1 T REFUSED TEST_SIGNER_IN_RELEASE 24"
290 echo "r20_domain_unsupported.unit qualification 1 T REFUSED CAP_DOMAIN_UNSUPPORTED 27"
291 echo "r21_untrusted_owner_signer.unit release 1 - REFUSED UNTRUSTED_SIGNER 25"
292 echo "r22_trailing_byte.unit qualification 1 T REFUSED TRAILING_BYTES 8"
293 echo "r23_entry_name_charset.unit qualification 1 T REFUSED ENTRY_NAME 31"
294 echo "r24_entry_name_empty.unit qualification 1 T REFUSED ENTRY_NAME 31"
295 echo "r25_entry_name_too_long.unit qualification 1 T REFUSED ENTRY_NAME 31"
296 echo "r26_entry_name_padding.unit qualification 1 T REFUSED ENTRY_NAME 31"
297 echo "r27_entry_name_duplicate.unit qualification 1 T REFUSED ENTRY_NAME_DUPLICATE 33"
298 echo "r28_entry_hash_shared_other_name.unit qualification 1 T REFUSED ENTRY_NAME_HASH 32"
299 echo "a05_valid_cells_entry.unit qualification 1 T ACCEPT unit_digest=$(udig "$V/a05_valid_cells_entry.unit") program_id=$irid"
300 echo "r29_total_length_low.unit qualification 1 T REFUSED TOTAL_LENGTH 9"
301 echo "r30_section_table_kind.unit qualification 1 T REFUSED SECTION_TABLE 10"
302 echo "r31_entry_hash_mismatch.unit qualification 1 T REFUSED ENTRY_HASH_MISMATCH 17"
303 echo "r32_caps_hash_mismatch.unit qualification 1 T REFUSED CAPS_HASH_MISMATCH 18"
304 echo "r33_caps_table_bad_rights.unit qualification 1 T REFUSED CAPS_TABLE 21"
305 echo "r34_signer_class_3.unit qualification 1 T REFUSED SIGNER_CLASS 22"
306 echo "r35_signature_algorithm_2.unit qualification 1 T REFUSED SIGNATURE_ALGORITHM 23"
307 echo "r36_domain_before_generation.unit qualification 1 T REFUSED CAP_DOMAIN_UNSUPPORTED 27"
308 echo "r37_code_svc.unit qualification 1 T REFUSED CODE_INSTRUCTION 34"
309 echo "r38_code_hvc.unit qualification 1 T REFUSED CODE_INSTRUCTION 34"
310 echo "r39_code_smc.unit qualification 1 T REFUSED CODE_INSTRUCTION 34"
311 echo "r40_code_msr_sysreg.unit qualification 1 T REFUSED CODE_INSTRUCTION 34"
312 echo "r41_code_mrs_sysreg.unit qualification 1 T REFUSED CODE_INSTRUCTION 34"
313 echo "r42_code_brk_imm0.unit qualification 1 T REFUSED CODE_INSTRUCTION 34"
314 echo "r43_code_brk_imm15.unit qualification 1 T REFUSED CODE_INSTRUCTION 34"
315 echo "r44_caps_disorder.unit qualification 1 T REFUSED CAPS_TABLE 21"
316 echo "r45_signature_s_not_canonical.unit qualification 1 T REFUSED BAD_SIGNATURE 26"
317 echo "r46_section_bounds_u32_wrap.unit qualification 1 T REFUSED SECTION_BOUNDS 11"
318 echo "r47_slice_kind_in_format_4.unit qualification 1 T REFUSED ENTRY_TABLE 20"
319 echo "r48_entry_hash_shared_case_variant.unit qualification 1 T REFUSED ENTRY_NAME_HASH 32"
320 echo "r49_cpu_ticks_over_max.unit qualification 1 T REFUSED LIMIT_EXCEEDED 14"
321 echo "r50_stack_over_max.unit qualification 1 T REFUSED LIMIT_EXCEEDED 14"
322 echo "r51_pool_slots_over_max.unit qualification 1 T REFUSED LIMIT_EXCEEDED 14"
323 echo "a06_valid_limits_at_max.unit qualification 1 T ACCEPT unit_digest=$(udig "$V/a06_valid_limits_at_max.unit") program_id=$irid"
324} >"$V/expected.txt"
325
326# ---- lookup-by-name expectations (exact match; hash is only an index) ------
327{
328 echo "# vector mode domains anchors name verdict"
329 echo "a01_valid_min.unit qualification 1 T add ACCEPT fn_index=0"
330 echo "a01_valid_min.unit qualification 1 T first_byte ACCEPT fn_index=1"
331 echo "a01_valid_min.unit qualification 1 T ADD REFUSED LAUNCH_BAD_ENTRY 40"
332 echo "a01_valid_min.unit qualification 1 T ad REFUSED LAUNCH_BAD_ENTRY 40"
333 echo "a01_valid_min.unit qualification 1 T first_byt REFUSED LAUNCH_BAD_ENTRY 40"
334 echo "a01_valid_min.unit qualification 1 T missing REFUSED LAUNCH_BAD_ENTRY 40"
335} >"$V/lookups.txt"
336
337# ---- loader-state scenarios (admission codes 29 and 30 need loader state) ---
338# columns: vector mode domains anchors state verdict
339# state: gens=dom:kind:id=currentgen (resource generation the loader holds) | noreserve (reservation fails)
340{
341 echo "# vector mode domains anchors state verdict"
342 echo "a02_valid_caps_kernel_domain.unit qualification 1 T gens=1:3:1=7 ACCEPT unit_digest=$(udig "$V/a02_valid_caps_kernel_domain.unit") program_id=$irid"
343 echo "a02_valid_caps_kernel_domain.unit qualification 1 T gens=1:3:1=8 REFUSED CAP_GENERATION_STALE 29"
344 echo "a01_valid_min.unit qualification 1 T noreserve REFUSED RESOURCE_UNAVAILABLE 30"
345} >"$V/state.txt"
346
347# ---- launch-argument scenarios (launch code 41), judged by tools/osc-launch-check.c ----
348# columns: kinds(comma, OscScalar numbers per register) args(comma, decimal or 0x hex u64) verdict
349{
350 echo "# kinds args verdict (kinds: 1 bool 2 u8 3 u16 4 u32 5 u64 6 i8 7 i16 8 i32 9 i64 11 bytes 12 cells)"
351 echo "11,5 0x1000,16 OK"
352 echo "11,5 0,0 OK"
353 echo "5,5 7,9 OK"
354 echo "11,5 0x1000 REFUSED LAUNCH_ARG_SHAPE 41"
355 echo "11,5 0,4 REFUSED LAUNCH_ARG_SHAPE 41"
356 echo "12,5 0x1004,2 REFUSED LAUNCH_ARG_SHAPE 41"
357 echo "12,5 0x1000,0x2000000000000000 REFUSED LAUNCH_ARG_SHAPE 41"
358 echo "11,5 0xfffffffffffffff0,32 REFUSED LAUNCH_ARG_SHAPE 41"
359 echo "11,5,11,5 0x1000,16,0x1008,16 OK"
360 echo "12,5,11,5 0x1000,2,0x1008,8 REFUSED LAUNCH_ARG_SHAPE 41"
361 echo "12,5,12,5 0x1000,2,0x1008,2 REFUSED LAUNCH_ARG_SHAPE 41"
362 echo "12,5,12,5 0x1000,2,0x1010,2 OK"
363 echo "12,5,11,5 0x1000,0,0x1000,8 OK"
364 echo "2,5 256,0 REFUSED LAUNCH_ARG_SHAPE 41"
365 echo "6,5 0xffffffffffffff80,0 OK"
366 echo "6,5 0x80,0 REFUSED LAUNCH_ARG_SHAPE 41"
367} >"$V/launch.txt"