interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / quiet / qn2bind.om

393 lines · 5814 bytes Raw Blame History
1note quiet/qn2bind.om: FORGE-EVIDENCE v1 bind. The six field lines are hashed; the bind line is not.
2note Both forge-contribute and the patch page call qncanon, so a stale bind cannot pass.
3text tqev1 "FORGE-EVIDENCE v1"
4text tqcmt "commit="
5text tqtre "tree="
6text tqcmdk "cmd="
7text tqrck "rc="
8text tqoutk "out="
9text tqagk2 "agent="
10text tqbnd "bind="
11global qnrc uchar 1024
12global qnrcl ulong 1
13global qncm uchar 40
14global qntr uchar 40
15global qncmd uchar 200
16global qncmdl ulong 1
17global qnrcn ulong 1
18global qnout64 uchar 64
19global qnag uchar 40
20global qnagl ulong 1
21global qnbd uchar 64
22global qncan uchar 512
23global qncanl ulong 1
24global qnst ulong 1
25fn qnhexd c uchar to bool
26if and ge c 48 le c 57
27ret true
28end
29ret and ge c 97 le c 102
30end
31fn qnhxb v uchar to uchar
32if lt v 10
33ret add v 48
34end
35ret add v 87
36end
37fn qncanb c uchar to void
38n = get qncanl 0
39if lt n 511
40put qncan n c
41put qncanl 0 add n 1
42end
43end
44fn qncant t view uchar * to void
45for i ulong len t bound 16
46qncanb get t i
47end
48end
49note qncanh: n is 40 (commit, tree), 64 (out), at most 39 (agent) or at most 200 (cmd: qncopy and
50note qncanon refuse more), so the bound is 200, the largest. It was 64: a cmd of 65 bytes was trap 4.
51fn qncanh a ulong n ulong src ulong to void
52for i ulong n bound 200
53if eq src 0
54qncanb get qncm i
55end
56if eq src 1
57qncanb get qntr i
58end
59if eq src 2
60qncanb get qnout64 i
61end
62if eq src 3
63qncanb get qnag i
64end
65if eq src 4
66qncanb get qncmd i
67end
68end
69end
70fn qncand v ulong to void
71if ge v 10
72qncand div v 10
73end
74qncanb add 48 uchar rem v 10
75end
76fn qncanon to bool
77put qncanl 0 0
78if ne get qncmdl 0 0
79if gt get qncmdl 0 200
80ret false
81end
82end
83if or eq get qnagl 0 0 gt get qnagl 0 39
84ret false
85end
86if gt get qnrcn 0 255
87ret false
88end
89qncant tqcmt
90qncanh 0 40 0
91qncanb 10
92qncant tqtre
93qncanh 0 40 1
94qncanb 10
95qncant tqcmdk
96qncanh 0 get qncmdl 0 4
97qncanb 10
98qncant tqrck
99qncand get qnrcn 0
100qncanb 10
101qncant tqoutk
102qncanh 0 64 2
103qncanb 10
104qncant tqagk2
105qncanh 0 get qnagl 0 3
106qncanb 10
107if gt get qncanl 0 511
108ret false
109end
110ret true
111end
112fn qnsha hh edit uchar * to void
113b = new uchar 512 0
114n = get qncanl 0
115for i ulong n bound 512
116put b i get qncan i
117end
118k = sha2_digest 256 view part b 0 n hh
119end
120fn qnseal to bool
121if not qncanon
122ret false
123end
124h = new uchar 32 0
125qnsha h
126put qnrcl 0 0
127for i ulong len tqev1
128put qnrc i get tqev1 i
129end
130put qnrcl 0 len tqev1
131put qnrc get qnrcl 0 10
132put qnrcl 0 add get qnrcl 0 1
133for i ulong get qncanl 0 bound 512
134put qnrc add get qnrcl 0 i get qncan i
135end
136put qnrcl 0 add get qnrcl 0 get qncanl 0
137for i ulong len tqbnd
138put qnrc add get qnrcl 0 i get tqbnd i
139end
140put qnrcl 0 add get qnrcl 0 len tqbnd
141for i ulong 32
142v = get h i
143put qnrc add get qnrcl 0 mul i 2 qnhxb shr v 4
144put qnrc add add get qnrcl 0 mul i 2 1 qnhxb and v 15
145end
146put qnrcl 0 add get qnrcl 0 64
147put qnrc get qnrcl 0 10
148put qnrcl 0 add get qnrcl 0 1
149ret true
150end
151fn qnlnat p ulong to ulong
152q = p
153while lt q get qnrcl 0 bound 1024
154if eq get qnrc q 10
155ret q
156end
157q = add q 1
158end
159ret get qnrcl 0
160end
161fn qnpre p ulong t view uchar * to bool
162if gt add p len t get qnrcl 0
163ret false
164end
165for i ulong len t bound 16
166if ne get qnrc add p i get t i
167ret false
168end
169end
170ret true
171end
172fn qncopy p ulong n ulong dst ulong to bool
173if eq dst 0
174if ne n 40
175ret false
176end
177for i ulong 40
178c = get qnrc add p i
179if not qnhexd c
180ret false
181end
182put qncm i c
183end
184ret true
185end
186if eq dst 1
187if ne n 40
188ret false
189end
190for i ulong 40
191c = get qnrc add p i
192if not qnhexd c
193ret false
194end
195put qntr i c
196end
197ret true
198end
199if eq dst 2
200if or eq n 0 gt n 200
201ret false
202end
203for i ulong n bound 200
204c = get qnrc add p i
205if or lt c 32 eq c 127
206ret false
207end
208put qncmd i c
209end
210put qncmdl 0 n
211ret true
212end
213if eq dst 3
214if or eq n 0 gt n 3
215ret false
216end
217v = ulong 0
218for i ulong n bound 3
219c = get qnrc add p i
220if not and ge c 48 le c 57
221ret false
222end
223v = add mul v 10 sub ulong c 48
224end
225if gt v 255
226ret false
227end
228if and gt n 1 eq get qnrc p 48
229ret false
230end
231put qnrcn 0 v
232ret true
233end
234if eq dst 4
235if ne n 64
236ret false
237end
238for i ulong 64
239c = get qnrc add p i
240if not qnhexd c
241ret false
242end
243put qnout64 i c
244end
245ret true
246end
247if eq dst 5
248if or eq n 0 gt n 39
249ret false
250end
251for i ulong n bound 39
252c = get qnrc add p i
253ok = false
254if and ge c 48 le c 57
255ok = true
256end
257if and ge c 97 le c 122
258ok = true
259end
260if eq c 45
261ok = true
262end
263if not ok
264ret false
265end
266put qnag i c
267end
268put qnagl 0 n
269ret true
270end
271if eq dst 6
272if ne n 64
273ret false
274end
275for i ulong 64
276c = get qnrc add p i
277if not qnhexd c
278ret false
279end
280put qnbd i c
281end
282ret true
283end
284ret false
285end
286fn qnmark to ulong
287n = get qnrcl 0
288m = len tqev1
289p = ulong 0
290while lt p n bound 1024
291e = qnlnat p
292if eq sub e p m
293hit = true
294for i ulong m bound 20
295if ne get qnrc add p i get tqev1 i
296hit = false
297end
298end
299if hit
300if eq e n
301ret 9999
302end
303ret add e 1
304end
305end
306p = add e 1
307if eq e n
308p = n
309end
310end
311ret 9999
312end
313fn qnfield p ulong t view uchar * dst ulong to ulong
314e = qnlnat p
315if not qnpre p t
316ret 9999
317end
318a = add p len t
319if gt a e
320ret 9999
321end
322if not qncopy a sub e a dst
323ret 9999
324end
325if eq e get qnrcl 0
326ret e
327end
328ret add e 1
329end
330fn qnparse to bool
331p = qnmark
332if eq p 9999
333put qnst 0 0
334ret false
335end
336p = qnfield p tqcmt 0
337if eq p 9999
338put qnst 0 2
339ret false
340end
341p = qnfield p tqtre 1
342if eq p 9999
343put qnst 0 2
344ret false
345end
346p = qnfield p tqcmdk 2
347if eq p 9999
348put qnst 0 2
349ret false
350end
351p = qnfield p tqrck 3
352if eq p 9999
353put qnst 0 2
354ret false
355end
356p = qnfield p tqoutk 4
357if eq p 9999
358put qnst 0 2
359ret false
360end
361p = qnfield p tqagk2 5
362if eq p 9999
363put qnst 0 2
364ret false
365end
366p = qnfield p tqbnd 6
367if eq p 9999
368put qnst 0 2
369ret false
370end
371ret true
372end
373fn qnbindok to bool
374if not qncanon
375put qnst 0 2
376ret false
377end
378h = new uchar 32 0
379qnsha h
380hex = new uchar 64 0
381for i ulong 32
382v = get h i
383put hex mul i 2 qnhxb shr v 4
384put hex add mul i 2 1 qnhxb and v 15
385end
386for i ulong 64
387if ne get hex i get qnbd i
388put qnst 0 3
389ret false
390end
391end
392ret true
393end