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