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 / tests / searchtrace / test_st_holdout.om

686 lines · 22528 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note tests/searchtrace/test_st_holdout.om: Pure seeded OM-2 G3 sealed-holdout
4note commitment format v1 unit + refusal + CLI tests (port of test_st_holdout.c).
5
6text th_pass "PASS "
7text th_fail "FAIL "
8text th_nl "\n"
9text th_sum1 "st_holdout: "
10text th_sum2 "/"
11text th_sum3 " PASS\n"
12
13text th_kat_id "g3-kat-1"
14text th_kat_ts "task alpha\ntask beta\n"
15text th_kat_sd "731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4"
16text th_kat_cm "7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d"
17text th_kat_end "f241a91082e4ee19e4612c4fb7a3c6108182449c515bee35be6797bd8ef387ee"
18text th_kat_rd "20ba763127e9ffd0b563365d1db13f7d3b813f39c9d3b215c1447a48e9f39a28"
19text th_kat_rec "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\nend f241a91082e4ee19e4612c4fb7a3c6108182449c515bee35be6797bd8ef387ee\n"
20
21text th_x "x"
22text th_notasks "hello\n ask\n"
23text th_badlbl "a b"
24text th_lbl65 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
25text th_tcrule "task a\n\ntask\n task b\ntask c"
26text th_longtail "\ntask x"
27
28text th_b_ver "OMEGA-G3-HOLDOUT-COMMIT v2\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
29text th_b_mag "OMEGA-G4-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
30text th_b_dom "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v2\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
31text th_b_miss "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
32text th_b_ext "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\nnote x\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
33text th_b_reord "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntaskset_len 21\ntask_count 2\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
34text th_b_bhex "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest g31be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
35text th_b_shex "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e\n"
36text th_b_uhex "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574E68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
37text th_b_blbl "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3/kat\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
38text th_b_elbl "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id \ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
39text th_b_zt "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 0\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
40text th_b_lz "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 02\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
41text th_b_ovf "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 4294967296\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
42text th_b_sm "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 9\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
43text th_b_noend "OMEGA-G3-HOLDOUT-COMMIT v1\ndomain omega.g3.holdout.commit.v1\nholdout_id g3-kat-1\ntask_count 2\ntaskset_len 21\nsalt_digest 731be661741f6bbf7b8ed2dc8150a6a35238d7b133817bdf1347415bff4ec4a4\ncommitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
44
45text th_n_magic "magic"
46text th_n_dom "domain"
47text th_n_tlen "taskset_len"
48text th_n_exp "expected field"
49text th_n_bhex "bad hex"
50text th_n_64 "64"
51text th_n_up "uppercase"
52text th_n_lbl "label"
53text th_n_zt "zero tasks"
54text th_n_dec "decimal"
55text th_n_rng "range"
56text th_n_sm "too small"
57text th_n_cr "CR"
58text th_n_trunc "truncated"
59text th_n_trail "trailing"
60text th_n_nul "NUL"
61
62text th_rev_ext "task alpha\ntask beta\ntask gamma\n"
63text th_rev_cnt "task alpha\nxask beta\n"
64text th_rev_com "task alphb\ntask beta\n"
65
66text th_gc "0123456789abcdef0123456789abcdef01234567"
67text th_gc39 "0123456789abcdef0123456789abcdef0123456"
68text th_gcup "0123456789ABCDEF0123456789abcdef01234567"
69text th_gc41 "0123456789abcdef0123456789abcdef012345678"
70text th_rc_vpass "verdict PASS\n"
71text th_rc_cm "commitment 7008574e68b49d88b0debe5101eec7823a0f11a99833cb5e6aedc9262822b20d\n"
72text th_rc_rd "record_digest 20ba763127e9ffd0b563365d1db13f7d3b813f39c9d3b215c1447a48e9f39a28\n"
73text th_rc_hid "holdout_id g3-kat-1\n"
74text th_xyz "XYZ"
75text th_frob "frob"
76
77text th_dir_pfx "/tmp/st_holdout_om_"
78text th_f_ts "/taskset.txt"
79text th_f_sp "/salt.bin"
80text th_f_sp31 "/salt31.bin"
81text th_f_bog "/bogus.txt"
82
83text th_t1 "commit ok"
84text th_t2 "kat record bytes"
85text th_t3 "deterministic bytes"
86text th_t4 "commit refuses zero tasks"
87text th_t5 "commit refuses empty taskset"
88text th_t6 "commit refuses bad label"
89text th_t7 "commit refuses 65-char label"
90text th_t8 "commit refuses small buffer"
91text th_t9 "task count rule"
92text th_t10 "task after a million-byte line"
93text th_t11 "parse ok + kat record digest"
94text th_t12 "kat commitment hex"
95text th_t13 "truncation at every length refused"
96text th_t14 "single-byte mutation at every offset refused"
97text th_t15 "wrong version"
98text th_t16 "wrong magic"
99text th_t17 "wrong domain"
100text th_t18 "missing field"
101text th_t19 "extra field"
102text th_t20 "reordered fields"
103text th_t21 "bad hex"
104text th_t22 "short hex"
105text th_t23 "uppercase hex"
106text th_t24 "bad label char"
107text th_t25 "empty label"
108text th_t26 "zero tasks"
109text th_t27 "leading zero decimal"
110text th_t28 "task_count overflow"
111text th_t29 "len too small for count"
112text th_t30 "CRLF line endings"
113text th_t31 "missing end line refused"
114text th_t32 "end digest mismatch"
115text th_t33 "trailing bytes refused"
116text th_t34 "trailing garbage refused"
117text th_t35 "NUL byte refused"
118text th_t36 "reveal round trip PASS"
119text th_t37 "reveal refuses swapped salt byte"
120text th_t38 "reveal refuses extra task line"
121text th_t39 "reveal refuses count mismatch (same length)"
122text th_t40 "reveal refuses commitment mismatch"
123text th_t41 "receipt refuses 39-char commit"
124text th_t42 "receipt refuses uppercase commit"
125text th_t43 "receipt refuses 41-char commit"
126text th_t44 "receipt deterministic + names fields"
127text th_t45 "receipt end digest valid"
128text th_t46 "cli usage: unknown subcommand"
129text th_t47 "cli usage: wrong argc"
130text th_t48 "cli commit refuses 31-byte salt"
131text th_t49 "cli commit writes content-addressed file"
132text th_t50 "cli commit idempotent"
133text th_t51 "cli verify ok"
134text th_t52 "cli reveal refuses unset OMEGA_REPO_COMMIT"
135text th_t53 "cli reveal refuses bad OMEGA_REPO_COMMIT"
136text th_t54 "cli reveal refuses wrong taskset"
137text th_t55 "cli reveal PASS"
138text th_t56 "cli reveal receipt content-addressed"
139text th_t57 "cli verify refuses corrupted record"
140text th_t58 "cli commit refuses existing different bytes"
141
142global th_run ulong 1
143global th_ok ulong 1
144global th_long uchar 1000012
145global th_rec1 uchar 1024
146global th_rl1 ulong 1
147global th_rc1 uchar 1024
148global th_r1 ulong 1
149
150fn th_num v ulong to void
151 b = new uchar 24 0
152 p = ulong 24
153 x = v
154 while true bound 24
155 p = sub p 1
156 put b p uchar add 48 rem x 10
157 x = div x 10
158 if eq x 0
159 break
160 end
161 end
162 r = write 1 b p sub 24 p
163end
164
165fn th_chk name view uchar * ok bool to void
166 put th_run 0 add get th_run 0 1
167 if ok
168 put th_ok 0 add get th_ok 0 1
169 sth_wr 1 th_pass
170 else
171 sth_wr 1 th_fail
172 end
173 sth_wr 1 name
174 sth_wr 1 th_nl
175end
176
177fn th_substr hay view uchar * hlen ulong ndl view uchar * to bool
178 nl = len ndl
179 if gt nl hlen
180 ret false
181 end
182 lim = add sub hlen nl 1
183 for i ulong lim bound 2048
184 m = ulong 1
185 for j ulong nl bound 128
186 if ne get hay add i j get ndl j
187 m = 0
188 break
189 end
190 end
191 if eq m 1
192 ret true
193 end
194 end
195 ret false
196end
197
198fn th_why_has ndl view uchar * to bool
199 wl = get sth_whylen 0
200 wb = new uchar 128 0
201 for i ulong wl bound 128
202 put wb i get sth_why i
203 end
204 ret th_substr wb wl ndl
205end
206
207fn th_hex_eq32 d view uchar 32 hx view uchar * to bool
208 if ne len hx 64
209 ret false
210 end
211 for i ulong 32
212 b = ulong get d i
213 if ne sth_hex_nib shr b 4 get hx mul i 2
214 ret false
215 end
216 if ne sth_hex_nib and b 15 get hx add mul i 2 1
217 ret false
218 end
219 end
220 ret true
221end
222
223fn th_reseal_parse body view uchar * to long
224 bl = len body
225 rec = new uchar 1024 0
226 for i ulong bl bound 1024
227 put rec i get body i
228 put sh_dat i get body i
229 end
230 sh_all bl
231 put rec bl 101
232 put rec add bl 1 110
233 put rec add bl 2 100
234 put rec add bl 3 32
235 off = add bl 4
236 for i ulong 32
237 b = ulong get sh_dig i
238 q = add off mul i 2
239 put rec q sth_hex_nib shr b 4
240 put rec add q 1 sth_hex_nib and b 15
241 end
242 put rec add bl 68 10
243 ret sth_parse rec add bl 69
244end
245
246fn th_refuse name view uchar * body view uchar * ndl view uchar * to void
247 r = th_reseal_parse body
248 ok = and lt r 0 th_why_has ndl
249 th_chk name ok
250end
251
252fn th_test_commit to void
253 salt = new uchar 32 0
254 for i ulong 32
255 put salt i uchar i
256 end
257 r = sth_commit th_kat_id th_kat_ts salt STH_REC_MAX
258 rl = get sth_reclen 0
259 put th_rl1 0 rl
260 for i ulong rl bound 1024
261 put th_rec1 i get sth_rec i
262 end
263 th_chk th_t1 eq r 0
264 same_kat = and eq r 0 eq rl len th_kat_rec
265 if same_kat
266 for i ulong rl bound 1024
267 if ne get th_rec1 i get th_kat_rec i
268 same_kat = false
269 end
270 end
271 end
272 th_chk th_t2 same_kat
273 r2 = sth_commit th_kat_id th_kat_ts salt STH_REC_MAX
274 rl2 = get sth_reclen 0
275 det = and eq r2 0 eq rl rl2
276 if det
277 for i ulong rl bound 1024
278 if ne get th_rec1 i get sth_rec i
279 det = false
280 end
281 end
282 end
283 th_chk th_t3 det
284 th_chk th_t4 eq sth_commit th_x th_notasks salt STH_REC_MAX STH_ENOTASKS
285 emp = new uchar 1 0
286 th_chk th_t5 eq sth_commit th_x part emp 0 0 salt STH_REC_MAX STH_ENOTASKS
287 th_chk th_t6 eq sth_commit th_badlbl th_kat_ts salt STH_REC_MAX STH_ELABEL
288 th_chk th_t7 eq sth_commit th_lbl65 th_kat_ts salt STH_REC_MAX STH_ELABEL
289 th_chk th_t8 eq sth_commit th_kat_id th_kat_ts salt sub rl 1 STH_ECAP
290 th_chk th_t9 eq sth_count_tasks th_tcrule len th_tcrule 2
291 for i ulong 1000012 bound 1000012
292 put th_long i 120
293 end
294 for i ulong 7
295 put th_long add 1000005 i get th_longtail i
296 end
297 note Copy th_long in chunks is avoided; count directly using sth_count_tasks via local? No, 1MB local fits in 4MB stack!
298 ln = new uchar 1000012 120
299 for i ulong 7
300 put ln add 1000005 i get th_longtail i
301 end
302 th_chk th_t10 eq sth_count_tasks ln 1000012 1
303end
304
305fn th_test_parse_basic to void
306 rl = get th_rl1 0
307 rec = new uchar 1024 0
308 rec2 = new uchar 1024 0
309 for i ulong rl bound 1024
310 put rec i get th_rec1 i
311 end
312 r = sth_parse rec rl
313 rd = new uchar 32 0
314 for i ulong 32
315 put rd i get sth_c_rd i
316 end
317 ok = and eq r 0 th_hex_eq32 rd th_kat_rd
318 if ne get sth_c_tcnt 0 2
319 ok = false
320 end
321 if ne get sth_c_tlen 0 21
322 ok = false
323 end
324 if ne get sth_c_idlen 0 len th_kat_id
325 ok = false
326 else
327 for i ulong len th_kat_id bound 64
328 if ne get sth_c_id i get th_kat_id i
329 ok = false
330 end
331 end
332 end
333 th_chk th_t11 ok
334 for i ulong 32
335 put rd i get sth_c_cm i
336 end
337 th_chk th_t12 and eq r 0 th_hex_eq32 rd th_kat_cm
338 ok = true
339 for n ulong rl bound 1024
340 if ge sth_parse rec n 0
341 ok = false
342 end
343 end
344 th_chk th_t13 ok
345 ok = true
346 for i ulong rl bound 1024
347 for j ulong rl bound 1024
348 put rec2 j get rec j
349 end
350 put rec2 i xor get rec2 i 1
351 if ge sth_parse rec2 rl 0
352 ok = false
353 end
354 end
355 th_chk th_t14 ok
356end
357
358fn th_test_parse_refusals to void
359 th_refuse th_t15 th_b_ver th_n_magic
360 th_refuse th_t16 th_b_mag th_n_magic
361 th_refuse th_t17 th_b_dom th_n_dom
362 th_refuse th_t18 th_b_miss th_n_tlen
363 th_refuse th_t19 th_b_ext th_n_exp
364 th_refuse th_t20 th_b_reord th_n_exp
365 th_refuse th_t21 th_b_bhex th_n_bhex
366 th_refuse th_t22 th_b_shex th_n_64
367 th_refuse th_t23 th_b_uhex th_n_up
368 th_refuse th_t24 th_b_blbl th_n_lbl
369 th_refuse th_t25 th_b_elbl th_n_lbl
370 th_refuse th_t26 th_b_zt th_n_zt
371 th_refuse th_t27 th_b_lz th_n_dec
372 th_refuse th_t28 th_b_ovf th_n_rng
373 th_refuse th_t29 th_b_sm th_n_sm
374 note CRLF test: insert CR before LF on line 1
375 bl = len th_b_noend
376 crlf = new uchar 1024 0
377 p = ulong 0
378 for i ulong bl bound 1024
379 c = get th_b_noend i
380 if eq ulong c 10
381 put crlf p 13
382 p = add p 1
383 end
384 put crlf p c
385 p = add p 1
386 end
387 th_refuse th_t30 part crlf 0 p th_n_cr
388 r = sth_parse th_b_noend len th_b_noend
389 th_chk th_t31 and lt r 0 th_why_has th_n_trunc
390 rl = get th_rl1 0
391 rec2 = new uchar 1024 0
392 for i ulong rl bound 1024
393 put rec2 i get th_rec1 i
394 end
395 idx = sub rl 2
396 if eq ulong get rec2 idx 48
397 put rec2 idx 49
398 else
399 put rec2 idx 48
400 end
401 th_chk th_t32 eq sth_parse rec2 rl STH_EDIGEST
402 for i ulong rl bound 1024
403 put rec2 i get th_rec1 i
404 end
405 put rec2 rl 10
406 r = sth_parse rec2 add rl 1
407 th_chk th_t33 and lt r 0 th_why_has th_n_trail
408 put rec2 rl 120
409 th_chk th_t34 lt sth_parse rec2 add rl 1 0
410 put rec2 70 0
411 r = sth_parse rec2 rl
412 th_chk th_t35 and lt r 0 th_why_has th_n_nul
413end
414
415fn th_test_receipt_only to void
416 th_chk th_t41 eq sth_reveal_receipt th_gc39 len th_gc39 STH_REC_MAX STH_ECOMMITID
417 th_chk th_t42 eq sth_reveal_receipt th_gcup len th_gcup STH_REC_MAX STH_ECOMMITID
418 th_chk th_t43 eq sth_reveal_receipt th_gc41 len th_gc41 STH_REC_MAX STH_ECOMMITID
419 a = sth_reveal_receipt th_gc len th_gc STH_REC_MAX
420 r1 = get sth_rcptlen 0
421 put th_r1 0 r1
422 rc1 = new uchar 1024 0
423 for i ulong r1 bound 1024
424 put rc1 i get sth_rcpt i
425 put th_rc1 i get sth_rcpt i
426 end
427 b = sth_reveal_receipt th_gc len th_gc STH_REC_MAX
428 ok = and eq a 0 and eq b 0 eq r1 get sth_rcptlen 0
429 if ok
430 for i ulong r1 bound 1024
431 if ne get rc1 i get sth_rcpt i
432 ok = false
433 end
434 end
435 end
436 if not th_substr rc1 r1 th_rc_vpass
437 ok = false
438 end
439 if not th_substr rc1 r1 th_rc_cm
440 ok = false
441 end
442 if not th_substr rc1 r1 th_rc_rd
443 ok = false
444 end
445 if not th_substr rc1 r1 th_rc_hid
446 ok = false
447 end
448 if not th_substr rc1 r1 th_gc
449 ok = false
450 end
451 th_chk th_t44 ok
452 d = new uchar 32 0
453 blen = sub r1 69
454 sth_sha256_buf rc1 blen d
455 ok = and eq a 0 sth_slice_eq rc1 blen 4 sth_t_endsp
456 if ok
457 for i ulong 32
458 bv = ulong get d i
459 q = add add blen 4 mul i 2
460 if ne sth_hex_nib shr bv 4 get rc1 q
461 ok = false
462 end
463 if ne sth_hex_nib and bv 15 get rc1 add q 1
464 ok = false
465 end
466 end
467 end
468 th_chk th_t45 ok
469end
470
471fn th_test_reveal_receipt to void
472 rl = get th_rl1 0
473 rec = new uchar 1024 0
474 for i ulong rl bound 1024
475 put rec i get th_rec1 i
476 end
477 r = sth_parse rec rl
478 salt = new uchar 32 0
479 bad = new uchar 32 0
480 for i ulong 32
481 put salt i uchar i
482 put bad i uchar i
483 end
484 put bad 7 xor get bad 7 0x80
485 th_chk th_t36 and eq r 0 eq sth_reveal th_kat_ts len th_kat_ts salt 0
486 th_chk th_t37 eq sth_reveal th_kat_ts len th_kat_ts bad STH_ESALT
487 th_chk th_t38 eq sth_reveal th_rev_ext len th_rev_ext salt STH_ELEN
488 th_chk th_t39 eq sth_reveal th_rev_cnt len th_rev_cnt salt STH_ECOUNT
489 th_chk th_t40 eq sth_reveal th_rev_com len th_rev_com salt STH_ECOMMIT
490 th_test_receipt_only
491end
492
493fn th_mkpath dir view uchar 512 dlen ulong suf view uchar * dst edit uchar 512 to ulong
494 p = ulong 0
495 for i ulong dlen bound 400
496 put dst p get dir i
497 p = add p 1
498 end
499 sl = len suf
500 for i ulong sl bound 100
501 put dst p get suf i
502 p = add p 1
503 end
504 ret p
505end
506
507fn th_write_f pth view uchar 512 plen ulong dat view uchar * dlen ulong to void
508 fd = fopen pth 0 plen 577 384
509 if ge fd 0
510 w = write int fd dat 0 dlen
511 c = fclose int fd
512 end
513end
514
515fn th_file_eq pth view uchar 512 plen ulong dat view uchar * dlen ulong to bool
516 r = sth_read_file pth plen 1
517 if ne r long dlen
518 ret false
519 end
520 for i ulong dlen bound 2048
521 if ne get sth_fbuf2 i get dat i
522 ret false
523 end
524 end
525 ret true
526end
527
528fn th_test_cli_a dir view uchar 512 dl ulong recp view uchar 512 recpl ulong to void
529 p = new uchar 512 0
530 p2 = new uchar 512 0
531 salt = new uchar 32 0
532 for i ulong 32
533 put salt i uchar i
534 end
535 pl = th_mkpath dir dl th_f_ts p
536 th_write_f p pl th_kat_ts len th_kat_ts
537 pl = th_mkpath dir dl th_f_sp p
538 th_write_f p pl salt 32
539 pl = th_mkpath dir dl th_f_sp31 p
540 th_write_f p pl salt 31
541 pl = th_mkpath dir dl th_f_bog p
542 th_write_f p pl th_rev_com len th_rev_com
543
544 put sth_argc 0 1
545 sth_arg_set 0 th_frob len th_frob
546 th_chk th_t46 eq sth_cli_run 1
547
548 put sth_argc 0 2
549 sth_arg_set 0 sth_t_cmd_commit len sth_t_cmd_commit
550 sth_arg_set 1 th_x len th_x
551 th_chk th_t47 eq sth_cli_run 1
552
553 put sth_argc 0 5
554 sth_arg_set 0 sth_t_cmd_commit len sth_t_cmd_commit
555 sth_arg_set 1 th_kat_id len th_kat_id
556 pl = th_mkpath dir dl th_f_ts p
557 sth_arg_set 2 p pl
558 p2l = th_mkpath dir dl th_f_sp31 p2
559 sth_arg_set 3 p2 p2l
560 sth_arg_set 4 dir dl
561 th_chk th_t48 eq sth_cli_run 2
562
563 p2l = th_mkpath dir dl th_f_sp p2
564 sth_arg_set 3 p2 p2l
565 c1 = sth_cli_run
566 th_chk th_t49 and eq c1 0 th_file_eq recp recpl th_kat_rec len th_kat_rec
567 th_chk th_t50 eq sth_cli_run 0
568
569 put sth_argc 0 2
570 sth_arg_set 0 sth_t_cmd_verify len sth_t_cmd_verify
571 sth_arg_set 1 recp recpl
572 th_chk th_t51 eq sth_cli_run 0
573end
574
575fn th_test_cli_b dir view uchar 512 dl ulong recp view uchar 512 recpl ulong to void
576 p = new uchar 512 0
577 p2 = new uchar 512 0
578 put sth_env_mode 0 1
579 put sth_argc 0 5
580 sth_arg_set 0 sth_t_cmd_reveal len sth_t_cmd_reveal
581 sth_arg_set 1 recp recpl
582 pl = th_mkpath dir dl th_f_ts p
583 sth_arg_set 2 p pl
584 p2l = th_mkpath dir dl th_f_sp p2
585 sth_arg_set 3 p2 p2l
586 sth_arg_set 4 dir dl
587 th_chk th_t52 eq sth_cli_run 2
588
589 put sth_env_mode 0 2
590 for i ulong len th_xyz bound 16
591 put sth_env_val i get th_xyz i
592 end
593 put sth_env_len 0 len th_xyz
594 th_chk th_t53 eq sth_cli_run 2
595
596 for i ulong len th_gc bound 64
597 put sth_env_val i get th_gc i
598 end
599 put sth_env_len 0 len th_gc
600 pl = th_mkpath dir dl th_f_bog p
601 sth_arg_set 2 p pl
602 th_chk th_t54 eq sth_cli_run 2
603
604 pl = th_mkpath dir dl th_f_ts p
605 sth_arg_set 2 p pl
606 th_chk th_t55 eq sth_cli_run 0
607
608 r1 = get th_r1 0
609 rc1 = new uchar 1024 0
610 for i ulong r1 bound 1024
611 put rc1 i get th_rc1 i
612 end
613 rd2 = new uchar 32 0
614 sth_sha256_buf rc1 r1 rd2
615 p2l = sth_make_out_path dir dl sth_t_p_reveal rd2 p2
616 th_chk th_t56 th_file_eq p2 p2l rc1 r1
617
618 kl = len th_kat_rec
619 for i ulong kl bound 1024
620 put rc1 i get th_kat_rec i
621 end
622 put rc1 kl 120
623 th_write_f recp recpl rc1 add kl 1
624 put sth_argc 0 2
625 sth_arg_set 0 sth_t_cmd_verify len sth_t_cmd_verify
626 sth_arg_set 1 recp recpl
627 th_chk th_t57 eq sth_cli_run 2
628
629 put sth_argc 0 5
630 sth_arg_set 0 sth_t_cmd_commit len sth_t_cmd_commit
631 sth_arg_set 1 th_kat_id len th_kat_id
632 pl = th_mkpath dir dl th_f_ts p
633 sth_arg_set 2 p pl
634 pl = th_mkpath dir dl th_f_sp p
635 sth_arg_set 3 p pl
636 sth_arg_set 4 dir dl
637 th_chk th_t58 eq sth_cli_run 2
638
639 u = unlink p2 0 p2l
640 u = unlink recp 0 recpl
641 pl = th_mkpath dir dl th_f_ts p
642 u = unlink p 0 pl
643 pl = th_mkpath dir dl th_f_sp p
644 u = unlink p 0 pl
645 pl = th_mkpath dir dl th_f_sp31 p
646 u = unlink p 0 pl
647 pl = th_mkpath dir dl th_f_bog p
648 u = unlink p 0 pl
649 u = rmdir dir 0 dl
650end
651
652fn th_test_cli to void
653 dir = new uchar 512 0
654 dl = len th_dir_pfx
655 for i ulong dl bound 64
656 put dir i get th_dir_pfx i
657 end
658 dl = sth_append_u64_buf dir dl ulong getpid
659 mr = makedir dir 0 dl 448
660 rd = new uchar 32 0
661 rp = sth_parse th_kat_rec len th_kat_rec
662 for i ulong 32
663 put rd i get sth_c_rd i
664 end
665 recp = new uchar 512 0
666 recpl = sth_make_out_path dir dl sth_t_p_commit rd recp
667 th_test_cli_a dir dl recp recpl
668 th_test_cli_b dir dl recp recpl
669end
670
671fn main to int
672 th_test_commit
673 th_test_parse_basic
674 th_test_parse_refusals
675 th_test_reveal_receipt
676 th_test_cli
677 sth_wr 1 th_sum1
678 th_num get th_ok 0
679 sth_wr 1 th_sum2
680 th_num get th_run 0
681 sth_wr 1 th_sum3
682 if eq get th_ok 0 get th_run 0
683 ret 0
684 end
685 ret 1
686end