interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / tka / tkastate.om

335 lines · 5989 bytes Raw Blame History
1note SPDX-License-Identifier: BSD-3-Clause
2note Copyright (c) Tailscale Inc & contributors. See tailscale.LICENSE.
3note Functions are separated for compiler register pressure; concatenate after tka.om.
4fn tkaxeq a view uchar 65536 t view ulong 131074 x ulong b view uchar 65536 u view ulong 131074 y ulong to ulong
5if ne tkablen t x tkablen u y
6ret 0
7end
8n = tkablen t x
9x = cbrpoff t x
10y = cbrpoff u y
11for i ulong n
12v = get a add x i
13if ne v get b add y i
14ret 0
15end
16end
17ret 1
18end
19
20fn tkakey a view uchar 65536 t view ulong 131074 id ulong s view uchar 65536 u view ulong 131074 to ulong
21r = cbrmfind u 0 3
22j = add r 1
23for i ulong tkalen u 0 3
24if ne tkaxeq a t id s u cbrmfind u j 3 0
25ret j
26end
27j = cbrnext u j
28end
29ret 0
30end
31
32fn tkasigok a view uchar 65536 t view ulong 131074 r ulong s view uchar 65536 u view ulong 131074 msg view uchar 65536 to ulong
33k = tkakey a t cbrmfind t r 1 s u
34if eq k 0
35ret 0
36end
37p = cbrmfind u k 3
38if ne cbrval u p 32
39ret 0
40end
41pk = new uchar 32 0
42sg = new uchar 64 0
43for i ulong 32
44put pk i get s add cbrpoff u p i
45end
46p = cbrmfind t r 2
47for i ulong 64
48put sg i get a add cbrpoff t p i
49end
50ret edverify pk msg 32 sg 1
51end
52
53fn tkaauth a view uchar 65536 t view ulong 131074 s view uchar 65536 u view ulong 131074 to ulong
54r = cbrmfind t 0 23
55if eq r 0
56ret 65540
57end
58if eq cbrval t r 0
59ret 65540
60end
61h = new uchar 32 0
62z = tkahash a cbrinlen t 1 h
63if ne z 0
64ret z
65end
66m = new uchar 65536 0
67for i ulong 32
68put m i get h i
69end
70j = add r 1
71for i ulong cbrval t r
72if eq tkasigok a t j s u m 0
73ret 65540
74end
75j = cbrnext t j
76end
77ret 0
78end
79
80fn tkaweight a view uchar 65536 t view ulong 131074 s view uchar 65536 u view ulong 131074 to ulong
81r = cbrmfind t 0 23
82if eq r 0
83ret 0
84end
85j = add r 1
86weight = ulong 0
87for i ulong cbrval t r
88seen = ulong 0
89k = add r 1
90for h ulong i
91if ne tkaeq a t cbrmfind t j 1 cbrmfind t k 1 0
92seen = 1
93end
94k = cbrnext t k
95end
96if eq seen 0
97k = tkakey a t cbrmfind t j 1 s u
98if ne k 0
99weight = add weight tkalen u k 2
100end
101end
102j = cbrnext t j
103end
104ret weight
105end
106
107fn tkaraw d view uchar 65536 t view ulong 131074 r ulong o edit uchar 65536 w edit ulong 4 to void
108tkacopy d cbrhoff t r cbrspan t r o w
109end
110
111fn tkaupkey a view uchar 65536 t view ulong 131074 s view uchar 65536 u view ulong 131074 r ulong o edit uchar 65536 to ulong
112w = new ulong 4 0
113m = cbrmfind t 0 7
114if eq m 0
115m = cbrmfind u r 12
116end
117n = ulong 3
118if ne m 0
119n = 4
120end
121tkaheadw o w 5 n
122for f ulong 3
123tkaheadw o w 0 add f 1
124if and eq f 1 ne cbrmfind t 0 6 0
125tkaraw a t cbrmfind t 0 6 o w
126else
127tkaraw s u cbrmfind u r add f 1 o w
128end
129end
130if ne m 0
131tkaheadw o w 0 12
132if ne cbrmfind t 0 7 0
133tkaraw a t m o w
134else
135tkaraw s u m o w
136end
137end
138if ne get w 1 0
139ret get w 1
140end
141ret get w 0
142end
143
144fn tkaemitup a view uchar 65536 t view ulong 131074 s view uchar 65536 u view ulong 131074 o edit uchar 65536 w edit ulong 4 to void
145b = new uchar 65536 0
146v = new ulong 131074 0
147z = tkaupkey a t s u get w 3 b
148if gt z 65536
149put w 1 z
150ret
151end
152x = cbrdec b z v
153if ne tkakvalid b v 0 0
154put w 1 65539
155ret
156end
157tkacopy b 0 z o w
158end
159
160fn tkawkeys a view uchar 65536 t view ulong 131074 s view uchar 65536 u view ulong 131074 o edit uchar 65536 w edit ulong 4 to void
161kind = tkalen t 0 1
162r = cbrmfind u 0 3
163cnt = cbrval u r
164key = ulong 0
165if or eq kind 2 eq kind 4
166key = tkakey a t cbrmfind t 0 4 s u
167if eq key 0
168put w 1 65541
169ret
170end
171end
172if eq kind 1
173k = cbrmfind t 0 3
174if ne tkakey a t cbrmfind t k 3 s u 0
175put w 1 65541
176ret
177end
178if ge cnt 512
179put w 1 65538
180ret
181end
182cnt = add cnt 1
183end
184if eq kind 2
185if eq cnt 1
186put w 1 65541
187ret
188end
189cnt = sub cnt 1
190end
191tkaheadw o w 4 cnt
192j = add r 1
193for i ulong cbrval u r
194if ne j key
195tkaraw s u j o w
196else
197if eq kind 4
198put w 3 j
199tkaemitup a t s u o w
200end
201end
202j = cbrnext u j
203end
204if eq kind 1
205tkaraw a t cbrmfind t 0 3 o w
206end
207end
208
209fn tkawhash h view uchar 32 o edit uchar 65536 w edit ulong 4 to void
210tkaheadw o w 2 32
211if or ne get w 1 0 gt get w 0 65504
212put w 1 65538
213ret
214end
215for i ulong 32
216put o get w 0 get h i
217put w 0 add get w 0 1
218end
219end
220
221
222fn tkacp a view uchar 65536 t view ulong 131074 u view ulong 131074 o edit uchar 65536 h view uchar 32 to ulong
223w = new ulong 4 0
224r = cbrmfind t 0 5
225for f ulong 2
226if ne tkalen t r add f 4 tkalen u 0 add f 4
227ret 65541
228end
229end
230tkaheadw o w 5 cbrval t r
231j = add r 1
232for i ulong cbrval t r
233f = cbrval t j
234tkaheadw o w 0 f
235j = cbrnext t j
236if eq f 1
237tkawhash h o w
238else
239tkaraw a t j o w
240end
241j = cbrnext t j
242end
243if ne get w 1 0
244ret get w 1
245end
246ret get w 0
247end
248
249fn tkaapply a view uchar 65536 t view ulong 131074 s view uchar 65536 u view ulong 131074 o edit uchar 65536 to ulong
250w = new ulong 4 0
251h = new uchar 32 0
252z = tkahash a cbrinlen t 0 h
253if ne z 0
254ret z
255end
256if eq tkalen t 0 1 5
257ret tkacp a t u o h
258end
259tkaheadw o w 5 cbrval u 0
260j = ulong 1
261for i ulong cbrval u 0
262f = cbrval u j
263tkaheadw o w 0 f
264j = cbrnext u j
265if eq f 1
266tkawhash h o w
267else
268if eq f 3
269tkawkeys a t s u o w
270else
271tkaraw s u j o w
272end
273end
274j = cbrnext u j
275end
276if ne get w 1 0
277ret get w 1
278end
279ret get w 0
280end
281
282fn tkaparent a view uchar 65536 t view ulong 131074 s view uchar 65536 u view ulong 131074 to ulong
283p = cbrmfind t 0 2
284q = cbrmfind u 0 1
285if ne cbrval t p 32
286ret 65541
287end
288if eq tkaxeq a t p s u q 0
289ret 65541
290end
291ret 0
292end
293
294fn tkatrusted a view uchar 65536 n ulong s view uchar 65536 sn ulong o edit uchar 65536 genesis ulong to ulong
295z = tkavalid a n
296if ne z 0
297ret z
298end
299b = new uchar 65536 0
300z = tkamodel a n 1 b 1
301t = new ulong 131074 0
302z = cbrdec b z t
303u = new ulong 131074 0
304if ne cbrdec s sn u 0
305ret 65537
306end
307if eq genesis 0
308z = tkaparent b t s u
309if ne z 0
310ret z
311end
312end
313z = tkaauth b t s u
314if ne z 0
315ret z
316end
317ret tkaapply b t s u o
318end
319
320fn tkatrans a view uchar 65536 n ulong s view uchar 65536 sn ulong o edit uchar 65536 genesis ulong to ulong
321b = new uchar 65536 0
322z = tkamodel s sn 3 b 1
323if gt z 65536
324ret z
325end
326ret tkatrusted a n b z o genesis
327end
328
329fn tkaweightbuf a view uchar 65536 n ulong s view uchar 65536 sn ulong to ulong
330t = new ulong 131074 0
331u = new ulong 131074 0
332z = cbrdec a n t
333z = cbrdec s sn u
334ret tkaweight a t s u
335end