CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / om / core / sha256.om
| 1 | note Vendored from aien-dev/omega-mv@acb3f15cdc691b1b046b48b0dad0f9255a12ba4b om/sha256/sha256.om. |
| 2 | note Copyright 2026 Drake Stapleton. Local source; no cross-repository build import. |
| 3 | note SPDX-License-Identifier: Apache-2.0 |
| 4 | note sha256.om: FIPS 180-4 SHA-256 as one function-mode unit, bound through the omega-bridge native |
| 5 | note call ABI (docs/NATIVE-ABI.md) and exported as omega_omsha. It replaces the algorithm of |
| 6 | note src/sha256.c: the C file keeps only the sha256_* entry points that cut caller data into |
| 7 | note pieces of at most 4096 bytes. |
| 8 | note |
| 9 | note The whole hash state lives in the caller's sha256_ctx (104 bytes, src/sha256.h): |
| 10 | note bytes 0..31 state[8], uint32 little endian |
| 11 | note bytes 32..39 count, uint64 little endian (bytes absorbed so far) |
| 12 | note bytes 40..103 buffer, the pending partial block |
| 13 | note omsha c b n op w b8: |
| 14 | note op 0 init: count 0, FIPS initial hash value |
| 15 | note op 1 absorb b[0..n), n <= 4096, with src/sha256.c's buffering rules |
| 16 | note op 2 final: pad, absorb the bit length, the 32-byte digest packed into w[0..4) |
| 17 | note op 3 one shot: the digest of the n < 4096 bytes of b8 packed into w[0..4); c is not used |
| 18 | note w is the caller's scratch for the message schedule (64 words, contents ignored and overwritten): |
| 19 | note Omega writes every word before reading it, so the caller need not clear it. |
| 20 | note Entry refuses n > 4096 with result 3, invalid op with result 9, before state mutation. |
| 21 | note The original explicit traps are represented as refusal results for the pinned bridge-seeded subset. |
| 22 | |
| 23 | note little-endian word of nb bytes at byte offset p of the context |
| 24 | fn getle c edit uchar 104 p ulong nb ulong to ulong |
| 25 | v = ulong 0 |
| 26 | i = nb |
| 27 | while gt i 0 bound 8 |
| 28 | i = sub i 1 |
| 29 | v = or shl v 8 ulong get c add p i |
| 30 | end |
| 31 | ret v |
| 32 | end |
| 33 | |
| 34 | fn putle c edit uchar 104 p ulong nb ulong v ulong to void |
| 35 | x = v |
| 36 | for i ulong nb |
| 37 | put c add p i uchar and x 255 |
| 38 | x = shr x 8 |
| 39 | end |
| 40 | end |
| 41 | |
| 42 | note the hash words of the context into h, and back |
| 43 | fn loadh c edit uchar 104 h edit uint 8 to void |
| 44 | for i ulong 8 |
| 45 | put h i uint getle c mul i 4 4 |
| 46 | end |
| 47 | end |
| 48 | |
| 49 | fn storeh c edit uchar 104 h edit uint 8 to void |
| 50 | for i ulong 8 |
| 51 | putle c mul i 4 4 ulong get h i |
| 52 | end |
| 53 | end |
| 54 | |
| 55 | note big-endian words of the block at byte o of b into w[0..16), then the schedule |
| 56 | fn schedb b view uchar 4096 o ulong w edit ulong 64 to void |
| 57 | for i ulong 16 |
| 58 | q = add o mul i 4 |
| 59 | v = ulong get b q |
| 60 | v = or shl v 8 ulong get b add q 1 |
| 61 | v = or shl v 8 ulong get b add q 2 |
| 62 | v = or shl v 8 ulong get b add q 3 |
| 63 | put w i or v shl v 32 |
| 64 | end |
| 65 | expand w |
| 66 | end |
| 67 | |
| 68 | note big-endian words of the block at byte 40 of b into w[0..16), then the schedule |
| 69 | fn schedc b edit uchar 104 w edit ulong 64 to void |
| 70 | for i ulong 16 |
| 71 | q = add 40 mul i 4 |
| 72 | v = ulong get b q |
| 73 | v = or shl v 8 ulong get b add q 1 |
| 74 | v = or shl v 8 ulong get b add q 2 |
| 75 | v = or shl v 8 ulong get b add q 3 |
| 76 | put w i or v shl v 32 |
| 77 | end |
| 78 | expand w |
| 79 | end |
| 80 | |
| 81 | note the 64 rounds, unrolled with the working words in locals (names rotate instead of moving). |
| 82 | note Same lazy low-32-bit cells and rotate trick as expand; K is an immediate; the eight words are |
| 83 | note reduced to 32 bits only when they are added back into h. |
| 84 | fn rounds h edit uint 8 w view ulong 64 to void |
| 85 | a = ulong get h 0 |
| 86 | b = ulong get h 1 |
| 87 | c = ulong get h 2 |
| 88 | d = ulong get h 3 |
| 89 | e = ulong get h 4 |
| 90 | f = ulong get h 5 |
| 91 | g = ulong get h 6 |
| 92 | x = ulong get h 7 |
| 93 | t = ulong 0 |
| 94 | u = ulong 0 |
| 95 | t = add x add get w 0 1116352408 |
| 96 | u = shl e 32 |
| 97 | u = or u shr u 32 |
| 98 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 99 | t = add t u |
| 100 | t = add t xor g and e xor f g |
| 101 | u = shl a 32 |
| 102 | u = or u shr u 32 |
| 103 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 104 | u = add u xor b and xor a b xor b c |
| 105 | d = add d t |
| 106 | x = add t u |
| 107 | t = add g add get w 1 1899447441 |
| 108 | u = shl d 32 |
| 109 | u = or u shr u 32 |
| 110 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 111 | t = add t u |
| 112 | t = add t xor f and d xor e f |
| 113 | u = shl x 32 |
| 114 | u = or u shr u 32 |
| 115 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 116 | u = add u xor a and xor x a xor a b |
| 117 | c = add c t |
| 118 | g = add t u |
| 119 | t = add f add get w 2 3049323471 |
| 120 | u = shl c 32 |
| 121 | u = or u shr u 32 |
| 122 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 123 | t = add t u |
| 124 | t = add t xor e and c xor d e |
| 125 | u = shl g 32 |
| 126 | u = or u shr u 32 |
| 127 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 128 | u = add u xor x and xor g x xor x a |
| 129 | b = add b t |
| 130 | f = add t u |
| 131 | t = add e add get w 3 3921009573 |
| 132 | u = shl b 32 |
| 133 | u = or u shr u 32 |
| 134 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 135 | t = add t u |
| 136 | t = add t xor d and b xor c d |
| 137 | u = shl f 32 |
| 138 | u = or u shr u 32 |
| 139 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 140 | u = add u xor g and xor f g xor g x |
| 141 | a = add a t |
| 142 | e = add t u |
| 143 | t = add d add get w 4 961987163 |
| 144 | u = shl a 32 |
| 145 | u = or u shr u 32 |
| 146 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 147 | t = add t u |
| 148 | t = add t xor c and a xor b c |
| 149 | u = shl e 32 |
| 150 | u = or u shr u 32 |
| 151 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 152 | u = add u xor f and xor e f xor f g |
| 153 | x = add x t |
| 154 | d = add t u |
| 155 | t = add c add get w 5 1508970993 |
| 156 | u = shl x 32 |
| 157 | u = or u shr u 32 |
| 158 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 159 | t = add t u |
| 160 | t = add t xor b and x xor a b |
| 161 | u = shl d 32 |
| 162 | u = or u shr u 32 |
| 163 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 164 | u = add u xor e and xor d e xor e f |
| 165 | g = add g t |
| 166 | c = add t u |
| 167 | t = add b add get w 6 2453635748 |
| 168 | u = shl g 32 |
| 169 | u = or u shr u 32 |
| 170 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 171 | t = add t u |
| 172 | t = add t xor a and g xor x a |
| 173 | u = shl c 32 |
| 174 | u = or u shr u 32 |
| 175 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 176 | u = add u xor d and xor c d xor d e |
| 177 | f = add f t |
| 178 | b = add t u |
| 179 | t = add a add get w 7 2870763221 |
| 180 | u = shl f 32 |
| 181 | u = or u shr u 32 |
| 182 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 183 | t = add t u |
| 184 | t = add t xor x and f xor g x |
| 185 | u = shl b 32 |
| 186 | u = or u shr u 32 |
| 187 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 188 | u = add u xor c and xor b c xor c d |
| 189 | e = add e t |
| 190 | a = add t u |
| 191 | t = add x add get w 8 3624381080 |
| 192 | u = shl e 32 |
| 193 | u = or u shr u 32 |
| 194 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 195 | t = add t u |
| 196 | t = add t xor g and e xor f g |
| 197 | u = shl a 32 |
| 198 | u = or u shr u 32 |
| 199 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 200 | u = add u xor b and xor a b xor b c |
| 201 | d = add d t |
| 202 | x = add t u |
| 203 | t = add g add get w 9 310598401 |
| 204 | u = shl d 32 |
| 205 | u = or u shr u 32 |
| 206 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 207 | t = add t u |
| 208 | t = add t xor f and d xor e f |
| 209 | u = shl x 32 |
| 210 | u = or u shr u 32 |
| 211 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 212 | u = add u xor a and xor x a xor a b |
| 213 | c = add c t |
| 214 | g = add t u |
| 215 | t = add f add get w 10 607225278 |
| 216 | u = shl c 32 |
| 217 | u = or u shr u 32 |
| 218 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 219 | t = add t u |
| 220 | t = add t xor e and c xor d e |
| 221 | u = shl g 32 |
| 222 | u = or u shr u 32 |
| 223 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 224 | u = add u xor x and xor g x xor x a |
| 225 | b = add b t |
| 226 | f = add t u |
| 227 | t = add e add get w 11 1426881987 |
| 228 | u = shl b 32 |
| 229 | u = or u shr u 32 |
| 230 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 231 | t = add t u |
| 232 | t = add t xor d and b xor c d |
| 233 | u = shl f 32 |
| 234 | u = or u shr u 32 |
| 235 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 236 | u = add u xor g and xor f g xor g x |
| 237 | a = add a t |
| 238 | e = add t u |
| 239 | t = add d add get w 12 1925078388 |
| 240 | u = shl a 32 |
| 241 | u = or u shr u 32 |
| 242 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 243 | t = add t u |
| 244 | t = add t xor c and a xor b c |
| 245 | u = shl e 32 |
| 246 | u = or u shr u 32 |
| 247 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 248 | u = add u xor f and xor e f xor f g |
| 249 | x = add x t |
| 250 | d = add t u |
| 251 | t = add c add get w 13 2162078206 |
| 252 | u = shl x 32 |
| 253 | u = or u shr u 32 |
| 254 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 255 | t = add t u |
| 256 | t = add t xor b and x xor a b |
| 257 | u = shl d 32 |
| 258 | u = or u shr u 32 |
| 259 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 260 | u = add u xor e and xor d e xor e f |
| 261 | g = add g t |
| 262 | c = add t u |
| 263 | t = add b add get w 14 2614888103 |
| 264 | u = shl g 32 |
| 265 | u = or u shr u 32 |
| 266 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 267 | t = add t u |
| 268 | t = add t xor a and g xor x a |
| 269 | u = shl c 32 |
| 270 | u = or u shr u 32 |
| 271 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 272 | u = add u xor d and xor c d xor d e |
| 273 | f = add f t |
| 274 | b = add t u |
| 275 | t = add a add get w 15 3248222580 |
| 276 | u = shl f 32 |
| 277 | u = or u shr u 32 |
| 278 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 279 | t = add t u |
| 280 | t = add t xor x and f xor g x |
| 281 | u = shl b 32 |
| 282 | u = or u shr u 32 |
| 283 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 284 | u = add u xor c and xor b c xor c d |
| 285 | e = add e t |
| 286 | a = add t u |
| 287 | t = add x add get w 16 3835390401 |
| 288 | u = shl e 32 |
| 289 | u = or u shr u 32 |
| 290 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 291 | t = add t u |
| 292 | t = add t xor g and e xor f g |
| 293 | u = shl a 32 |
| 294 | u = or u shr u 32 |
| 295 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 296 | u = add u xor b and xor a b xor b c |
| 297 | d = add d t |
| 298 | x = add t u |
| 299 | t = add g add get w 17 4022224774 |
| 300 | u = shl d 32 |
| 301 | u = or u shr u 32 |
| 302 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 303 | t = add t u |
| 304 | t = add t xor f and d xor e f |
| 305 | u = shl x 32 |
| 306 | u = or u shr u 32 |
| 307 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 308 | u = add u xor a and xor x a xor a b |
| 309 | c = add c t |
| 310 | g = add t u |
| 311 | t = add f add get w 18 264347078 |
| 312 | u = shl c 32 |
| 313 | u = or u shr u 32 |
| 314 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 315 | t = add t u |
| 316 | t = add t xor e and c xor d e |
| 317 | u = shl g 32 |
| 318 | u = or u shr u 32 |
| 319 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 320 | u = add u xor x and xor g x xor x a |
| 321 | b = add b t |
| 322 | f = add t u |
| 323 | t = add e add get w 19 604807628 |
| 324 | u = shl b 32 |
| 325 | u = or u shr u 32 |
| 326 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 327 | t = add t u |
| 328 | t = add t xor d and b xor c d |
| 329 | u = shl f 32 |
| 330 | u = or u shr u 32 |
| 331 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 332 | u = add u xor g and xor f g xor g x |
| 333 | a = add a t |
| 334 | e = add t u |
| 335 | t = add d add get w 20 770255983 |
| 336 | u = shl a 32 |
| 337 | u = or u shr u 32 |
| 338 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 339 | t = add t u |
| 340 | t = add t xor c and a xor b c |
| 341 | u = shl e 32 |
| 342 | u = or u shr u 32 |
| 343 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 344 | u = add u xor f and xor e f xor f g |
| 345 | x = add x t |
| 346 | d = add t u |
| 347 | t = add c add get w 21 1249150122 |
| 348 | u = shl x 32 |
| 349 | u = or u shr u 32 |
| 350 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 351 | t = add t u |
| 352 | t = add t xor b and x xor a b |
| 353 | u = shl d 32 |
| 354 | u = or u shr u 32 |
| 355 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 356 | u = add u xor e and xor d e xor e f |
| 357 | g = add g t |
| 358 | c = add t u |
| 359 | t = add b add get w 22 1555081692 |
| 360 | u = shl g 32 |
| 361 | u = or u shr u 32 |
| 362 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 363 | t = add t u |
| 364 | t = add t xor a and g xor x a |
| 365 | u = shl c 32 |
| 366 | u = or u shr u 32 |
| 367 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 368 | u = add u xor d and xor c d xor d e |
| 369 | f = add f t |
| 370 | b = add t u |
| 371 | t = add a add get w 23 1996064986 |
| 372 | u = shl f 32 |
| 373 | u = or u shr u 32 |
| 374 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 375 | t = add t u |
| 376 | t = add t xor x and f xor g x |
| 377 | u = shl b 32 |
| 378 | u = or u shr u 32 |
| 379 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 380 | u = add u xor c and xor b c xor c d |
| 381 | e = add e t |
| 382 | a = add t u |
| 383 | t = add x add get w 24 2554220882 |
| 384 | u = shl e 32 |
| 385 | u = or u shr u 32 |
| 386 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 387 | t = add t u |
| 388 | t = add t xor g and e xor f g |
| 389 | u = shl a 32 |
| 390 | u = or u shr u 32 |
| 391 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 392 | u = add u xor b and xor a b xor b c |
| 393 | d = add d t |
| 394 | x = add t u |
| 395 | t = add g add get w 25 2821834349 |
| 396 | u = shl d 32 |
| 397 | u = or u shr u 32 |
| 398 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 399 | t = add t u |
| 400 | t = add t xor f and d xor e f |
| 401 | u = shl x 32 |
| 402 | u = or u shr u 32 |
| 403 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 404 | u = add u xor a and xor x a xor a b |
| 405 | c = add c t |
| 406 | g = add t u |
| 407 | t = add f add get w 26 2952996808 |
| 408 | u = shl c 32 |
| 409 | u = or u shr u 32 |
| 410 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 411 | t = add t u |
| 412 | t = add t xor e and c xor d e |
| 413 | u = shl g 32 |
| 414 | u = or u shr u 32 |
| 415 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 416 | u = add u xor x and xor g x xor x a |
| 417 | b = add b t |
| 418 | f = add t u |
| 419 | t = add e add get w 27 3210313671 |
| 420 | u = shl b 32 |
| 421 | u = or u shr u 32 |
| 422 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 423 | t = add t u |
| 424 | t = add t xor d and b xor c d |
| 425 | u = shl f 32 |
| 426 | u = or u shr u 32 |
| 427 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 428 | u = add u xor g and xor f g xor g x |
| 429 | a = add a t |
| 430 | e = add t u |
| 431 | t = add d add get w 28 3336571891 |
| 432 | u = shl a 32 |
| 433 | u = or u shr u 32 |
| 434 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 435 | t = add t u |
| 436 | t = add t xor c and a xor b c |
| 437 | u = shl e 32 |
| 438 | u = or u shr u 32 |
| 439 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 440 | u = add u xor f and xor e f xor f g |
| 441 | x = add x t |
| 442 | d = add t u |
| 443 | t = add c add get w 29 3584528711 |
| 444 | u = shl x 32 |
| 445 | u = or u shr u 32 |
| 446 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 447 | t = add t u |
| 448 | t = add t xor b and x xor a b |
| 449 | u = shl d 32 |
| 450 | u = or u shr u 32 |
| 451 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 452 | u = add u xor e and xor d e xor e f |
| 453 | g = add g t |
| 454 | c = add t u |
| 455 | t = add b add get w 30 113926993 |
| 456 | u = shl g 32 |
| 457 | u = or u shr u 32 |
| 458 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 459 | t = add t u |
| 460 | t = add t xor a and g xor x a |
| 461 | u = shl c 32 |
| 462 | u = or u shr u 32 |
| 463 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 464 | u = add u xor d and xor c d xor d e |
| 465 | f = add f t |
| 466 | b = add t u |
| 467 | t = add a add get w 31 338241895 |
| 468 | u = shl f 32 |
| 469 | u = or u shr u 32 |
| 470 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 471 | t = add t u |
| 472 | t = add t xor x and f xor g x |
| 473 | u = shl b 32 |
| 474 | u = or u shr u 32 |
| 475 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 476 | u = add u xor c and xor b c xor c d |
| 477 | e = add e t |
| 478 | a = add t u |
| 479 | t = add x add get w 32 666307205 |
| 480 | u = shl e 32 |
| 481 | u = or u shr u 32 |
| 482 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 483 | t = add t u |
| 484 | t = add t xor g and e xor f g |
| 485 | u = shl a 32 |
| 486 | u = or u shr u 32 |
| 487 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 488 | u = add u xor b and xor a b xor b c |
| 489 | d = add d t |
| 490 | x = add t u |
| 491 | t = add g add get w 33 773529912 |
| 492 | u = shl d 32 |
| 493 | u = or u shr u 32 |
| 494 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 495 | t = add t u |
| 496 | t = add t xor f and d xor e f |
| 497 | u = shl x 32 |
| 498 | u = or u shr u 32 |
| 499 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 500 | u = add u xor a and xor x a xor a b |
| 501 | c = add c t |
| 502 | g = add t u |
| 503 | t = add f add get w 34 1294757372 |
| 504 | u = shl c 32 |
| 505 | u = or u shr u 32 |
| 506 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 507 | t = add t u |
| 508 | t = add t xor e and c xor d e |
| 509 | u = shl g 32 |
| 510 | u = or u shr u 32 |
| 511 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 512 | u = add u xor x and xor g x xor x a |
| 513 | b = add b t |
| 514 | f = add t u |
| 515 | t = add e add get w 35 1396182291 |
| 516 | u = shl b 32 |
| 517 | u = or u shr u 32 |
| 518 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 519 | t = add t u |
| 520 | t = add t xor d and b xor c d |
| 521 | u = shl f 32 |
| 522 | u = or u shr u 32 |
| 523 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 524 | u = add u xor g and xor f g xor g x |
| 525 | a = add a t |
| 526 | e = add t u |
| 527 | t = add d add get w 36 1695183700 |
| 528 | u = shl a 32 |
| 529 | u = or u shr u 32 |
| 530 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 531 | t = add t u |
| 532 | t = add t xor c and a xor b c |
| 533 | u = shl e 32 |
| 534 | u = or u shr u 32 |
| 535 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 536 | u = add u xor f and xor e f xor f g |
| 537 | x = add x t |
| 538 | d = add t u |
| 539 | t = add c add get w 37 1986661051 |
| 540 | u = shl x 32 |
| 541 | u = or u shr u 32 |
| 542 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 543 | t = add t u |
| 544 | t = add t xor b and x xor a b |
| 545 | u = shl d 32 |
| 546 | u = or u shr u 32 |
| 547 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 548 | u = add u xor e and xor d e xor e f |
| 549 | g = add g t |
| 550 | c = add t u |
| 551 | t = add b add get w 38 2177026350 |
| 552 | u = shl g 32 |
| 553 | u = or u shr u 32 |
| 554 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 555 | t = add t u |
| 556 | t = add t xor a and g xor x a |
| 557 | u = shl c 32 |
| 558 | u = or u shr u 32 |
| 559 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 560 | u = add u xor d and xor c d xor d e |
| 561 | f = add f t |
| 562 | b = add t u |
| 563 | t = add a add get w 39 2456956037 |
| 564 | u = shl f 32 |
| 565 | u = or u shr u 32 |
| 566 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 567 | t = add t u |
| 568 | t = add t xor x and f xor g x |
| 569 | u = shl b 32 |
| 570 | u = or u shr u 32 |
| 571 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 572 | u = add u xor c and xor b c xor c d |
| 573 | e = add e t |
| 574 | a = add t u |
| 575 | t = add x add get w 40 2730485921 |
| 576 | u = shl e 32 |
| 577 | u = or u shr u 32 |
| 578 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 579 | t = add t u |
| 580 | t = add t xor g and e xor f g |
| 581 | u = shl a 32 |
| 582 | u = or u shr u 32 |
| 583 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 584 | u = add u xor b and xor a b xor b c |
| 585 | d = add d t |
| 586 | x = add t u |
| 587 | t = add g add get w 41 2820302411 |
| 588 | u = shl d 32 |
| 589 | u = or u shr u 32 |
| 590 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 591 | t = add t u |
| 592 | t = add t xor f and d xor e f |
| 593 | u = shl x 32 |
| 594 | u = or u shr u 32 |
| 595 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 596 | u = add u xor a and xor x a xor a b |
| 597 | c = add c t |
| 598 | g = add t u |
| 599 | t = add f add get w 42 3259730800 |
| 600 | u = shl c 32 |
| 601 | u = or u shr u 32 |
| 602 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 603 | t = add t u |
| 604 | t = add t xor e and c xor d e |
| 605 | u = shl g 32 |
| 606 | u = or u shr u 32 |
| 607 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 608 | u = add u xor x and xor g x xor x a |
| 609 | b = add b t |
| 610 | f = add t u |
| 611 | t = add e add get w 43 3345764771 |
| 612 | u = shl b 32 |
| 613 | u = or u shr u 32 |
| 614 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 615 | t = add t u |
| 616 | t = add t xor d and b xor c d |
| 617 | u = shl f 32 |
| 618 | u = or u shr u 32 |
| 619 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 620 | u = add u xor g and xor f g xor g x |
| 621 | a = add a t |
| 622 | e = add t u |
| 623 | t = add d add get w 44 3516065817 |
| 624 | u = shl a 32 |
| 625 | u = or u shr u 32 |
| 626 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 627 | t = add t u |
| 628 | t = add t xor c and a xor b c |
| 629 | u = shl e 32 |
| 630 | u = or u shr u 32 |
| 631 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 632 | u = add u xor f and xor e f xor f g |
| 633 | x = add x t |
| 634 | d = add t u |
| 635 | t = add c add get w 45 3600352804 |
| 636 | u = shl x 32 |
| 637 | u = or u shr u 32 |
| 638 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 639 | t = add t u |
| 640 | t = add t xor b and x xor a b |
| 641 | u = shl d 32 |
| 642 | u = or u shr u 32 |
| 643 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 644 | u = add u xor e and xor d e xor e f |
| 645 | g = add g t |
| 646 | c = add t u |
| 647 | t = add b add get w 46 4094571909 |
| 648 | u = shl g 32 |
| 649 | u = or u shr u 32 |
| 650 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 651 | t = add t u |
| 652 | t = add t xor a and g xor x a |
| 653 | u = shl c 32 |
| 654 | u = or u shr u 32 |
| 655 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 656 | u = add u xor d and xor c d xor d e |
| 657 | f = add f t |
| 658 | b = add t u |
| 659 | t = add a add get w 47 275423344 |
| 660 | u = shl f 32 |
| 661 | u = or u shr u 32 |
| 662 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 663 | t = add t u |
| 664 | t = add t xor x and f xor g x |
| 665 | u = shl b 32 |
| 666 | u = or u shr u 32 |
| 667 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 668 | u = add u xor c and xor b c xor c d |
| 669 | e = add e t |
| 670 | a = add t u |
| 671 | t = add x add get w 48 430227734 |
| 672 | u = shl e 32 |
| 673 | u = or u shr u 32 |
| 674 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 675 | t = add t u |
| 676 | t = add t xor g and e xor f g |
| 677 | u = shl a 32 |
| 678 | u = or u shr u 32 |
| 679 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 680 | u = add u xor b and xor a b xor b c |
| 681 | d = add d t |
| 682 | x = add t u |
| 683 | t = add g add get w 49 506948616 |
| 684 | u = shl d 32 |
| 685 | u = or u shr u 32 |
| 686 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 687 | t = add t u |
| 688 | t = add t xor f and d xor e f |
| 689 | u = shl x 32 |
| 690 | u = or u shr u 32 |
| 691 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 692 | u = add u xor a and xor x a xor a b |
| 693 | c = add c t |
| 694 | g = add t u |
| 695 | t = add f add get w 50 659060556 |
| 696 | u = shl c 32 |
| 697 | u = or u shr u 32 |
| 698 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 699 | t = add t u |
| 700 | t = add t xor e and c xor d e |
| 701 | u = shl g 32 |
| 702 | u = or u shr u 32 |
| 703 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 704 | u = add u xor x and xor g x xor x a |
| 705 | b = add b t |
| 706 | f = add t u |
| 707 | t = add e add get w 51 883997877 |
| 708 | u = shl b 32 |
| 709 | u = or u shr u 32 |
| 710 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 711 | t = add t u |
| 712 | t = add t xor d and b xor c d |
| 713 | u = shl f 32 |
| 714 | u = or u shr u 32 |
| 715 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 716 | u = add u xor g and xor f g xor g x |
| 717 | a = add a t |
| 718 | e = add t u |
| 719 | t = add d add get w 52 958139571 |
| 720 | u = shl a 32 |
| 721 | u = or u shr u 32 |
| 722 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 723 | t = add t u |
| 724 | t = add t xor c and a xor b c |
| 725 | u = shl e 32 |
| 726 | u = or u shr u 32 |
| 727 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 728 | u = add u xor f and xor e f xor f g |
| 729 | x = add x t |
| 730 | d = add t u |
| 731 | t = add c add get w 53 1322822218 |
| 732 | u = shl x 32 |
| 733 | u = or u shr u 32 |
| 734 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 735 | t = add t u |
| 736 | t = add t xor b and x xor a b |
| 737 | u = shl d 32 |
| 738 | u = or u shr u 32 |
| 739 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 740 | u = add u xor e and xor d e xor e f |
| 741 | g = add g t |
| 742 | c = add t u |
| 743 | t = add b add get w 54 1537002063 |
| 744 | u = shl g 32 |
| 745 | u = or u shr u 32 |
| 746 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 747 | t = add t u |
| 748 | t = add t xor a and g xor x a |
| 749 | u = shl c 32 |
| 750 | u = or u shr u 32 |
| 751 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 752 | u = add u xor d and xor c d xor d e |
| 753 | f = add f t |
| 754 | b = add t u |
| 755 | t = add a add get w 55 1747873779 |
| 756 | u = shl f 32 |
| 757 | u = or u shr u 32 |
| 758 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 759 | t = add t u |
| 760 | t = add t xor x and f xor g x |
| 761 | u = shl b 32 |
| 762 | u = or u shr u 32 |
| 763 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 764 | u = add u xor c and xor b c xor c d |
| 765 | e = add e t |
| 766 | a = add t u |
| 767 | t = add x add get w 56 1955562222 |
| 768 | u = shl e 32 |
| 769 | u = or u shr u 32 |
| 770 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 771 | t = add t u |
| 772 | t = add t xor g and e xor f g |
| 773 | u = shl a 32 |
| 774 | u = or u shr u 32 |
| 775 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 776 | u = add u xor b and xor a b xor b c |
| 777 | d = add d t |
| 778 | x = add t u |
| 779 | t = add g add get w 57 2024104815 |
| 780 | u = shl d 32 |
| 781 | u = or u shr u 32 |
| 782 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 783 | t = add t u |
| 784 | t = add t xor f and d xor e f |
| 785 | u = shl x 32 |
| 786 | u = or u shr u 32 |
| 787 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 788 | u = add u xor a and xor x a xor a b |
| 789 | c = add c t |
| 790 | g = add t u |
| 791 | t = add f add get w 58 2227730452 |
| 792 | u = shl c 32 |
| 793 | u = or u shr u 32 |
| 794 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 795 | t = add t u |
| 796 | t = add t xor e and c xor d e |
| 797 | u = shl g 32 |
| 798 | u = or u shr u 32 |
| 799 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 800 | u = add u xor x and xor g x xor x a |
| 801 | b = add b t |
| 802 | f = add t u |
| 803 | t = add e add get w 59 2361852424 |
| 804 | u = shl b 32 |
| 805 | u = or u shr u 32 |
| 806 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 807 | t = add t u |
| 808 | t = add t xor d and b xor c d |
| 809 | u = shl f 32 |
| 810 | u = or u shr u 32 |
| 811 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 812 | u = add u xor g and xor f g xor g x |
| 813 | a = add a t |
| 814 | e = add t u |
| 815 | t = add d add get w 60 2428436474 |
| 816 | u = shl a 32 |
| 817 | u = or u shr u 32 |
| 818 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 819 | t = add t u |
| 820 | t = add t xor c and a xor b c |
| 821 | u = shl e 32 |
| 822 | u = or u shr u 32 |
| 823 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 824 | u = add u xor f and xor e f xor f g |
| 825 | x = add x t |
| 826 | d = add t u |
| 827 | t = add c add get w 61 2756734187 |
| 828 | u = shl x 32 |
| 829 | u = or u shr u 32 |
| 830 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 831 | t = add t u |
| 832 | t = add t xor b and x xor a b |
| 833 | u = shl d 32 |
| 834 | u = or u shr u 32 |
| 835 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 836 | u = add u xor e and xor d e xor e f |
| 837 | g = add g t |
| 838 | c = add t u |
| 839 | t = add b add get w 62 3204031479 |
| 840 | u = shl g 32 |
| 841 | u = or u shr u 32 |
| 842 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 843 | t = add t u |
| 844 | t = add t xor a and g xor x a |
| 845 | u = shl c 32 |
| 846 | u = or u shr u 32 |
| 847 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 848 | u = add u xor d and xor c d xor d e |
| 849 | f = add f t |
| 850 | b = add t u |
| 851 | t = add a add get w 63 3329325298 |
| 852 | u = shl f 32 |
| 853 | u = or u shr u 32 |
| 854 | u = xor xor shr u 6 shr u 11 shr u 25 |
| 855 | t = add t u |
| 856 | t = add t xor x and f xor g x |
| 857 | u = shl b 32 |
| 858 | u = or u shr u 32 |
| 859 | u = xor xor shr u 2 shr u 13 shr u 22 |
| 860 | u = add u xor c and xor b c xor c d |
| 861 | e = add e t |
| 862 | a = add t u |
| 863 | t = add ulong get h 0 a |
| 864 | put h 0 uint and t 4294967295 |
| 865 | t = add ulong get h 1 b |
| 866 | put h 1 uint and t 4294967295 |
| 867 | t = add ulong get h 2 c |
| 868 | put h 2 uint and t 4294967295 |
| 869 | t = add ulong get h 3 d |
| 870 | put h 3 uint and t 4294967295 |
| 871 | t = add ulong get h 4 e |
| 872 | put h 4 uint and t 4294967295 |
| 873 | t = add ulong get h 5 f |
| 874 | put h 5 uint and t 4294967295 |
| 875 | t = add ulong get h 6 g |
| 876 | put h 6 uint and t 4294967295 |
| 877 | t = add ulong get h 7 x |
| 878 | put h 7 uint and t 4294967295 |
| 879 | end |
| 880 | |
| 881 | fn tobuf c edit uchar 104 bi ulong b view uchar 4096 bo ulong n ulong to void |
| 882 | for i ulong n |
| 883 | put c add 40 add bi i get b add bo i |
| 884 | end |
| 885 | end |
| 886 | |
| 887 | note absorb b[0..n), n <= 4096, exactly as src/sha256.c sha256_update does for that piece |
| 888 | fn absorb c edit uchar 104 b view uchar 4096 n ulong w edit ulong 64 to void |
| 889 | h = new uint 8 0 |
| 890 | cnt = getle c 32 8 |
| 891 | bi = and cnt 63 |
| 892 | putle c 32 8 add cnt n |
| 893 | off = ulong 0 |
| 894 | if gt bi 0 |
| 895 | lf = sub 64 bi |
| 896 | if lt n lf |
| 897 | tobuf c bi b 0 n |
| 898 | ret |
| 899 | end |
| 900 | tobuf c bi b 0 lf |
| 901 | loadh c h |
| 902 | schedc c w |
| 903 | rounds h w |
| 904 | storeh c h |
| 905 | off = lf |
| 906 | end |
| 907 | if le add off 64 n |
| 908 | loadh c h |
| 909 | while le add off 64 n bound 65 |
| 910 | schedb b off w |
| 911 | rounds h w |
| 912 | off = add off 64 |
| 913 | end |
| 914 | storeh c h |
| 915 | end |
| 916 | tobuf c 0 b off sub n off |
| 917 | end |
| 918 | |
| 919 | fn init c edit uchar 104 to void |
| 920 | putle c 32 8 0 |
| 921 | putle c 0 4 1779033703 |
| 922 | putle c 4 4 3144134277 |
| 923 | putle c 8 4 1013904242 |
| 924 | putle c 12 4 2773480762 |
| 925 | putle c 16 4 1359893119 |
| 926 | putle c 20 4 2600822924 |
| 927 | putle c 24 4 528734635 |
| 928 | putle c 28 4 1541459225 |
| 929 | end |
| 930 | |
| 931 | note compress the context's own block buffer (bytes 40..103) into its hash words |
| 932 | fn compbuf c edit uchar 104 w edit ulong 64 to void |
| 933 | h = new uint 8 0 |
| 934 | loadh c h |
| 935 | schedc c w |
| 936 | rounds h w |
| 937 | storeh c h |
| 938 | end |
| 939 | |
| 940 | note zero buffer bytes s..e-1 (indices into the 64-byte block) |
| 941 | fn zbuf c edit uchar 104 s ulong e ulong to void |
| 942 | i = s |
| 943 | while lt i e bound 64 |
| 944 | put c add 40 i 0 |
| 945 | i = add i 1 |
| 946 | end |
| 947 | end |
| 948 | |
| 949 | note sha256_final of src/sha256.c, padding in place: 0x80, zeros to 56 mod 64 (one more block |
| 950 | note when the pending part is 56 bytes or more), the 64-bit big-endian bit count, then the digest. |
| 951 | note Preserve the public context's count and buffer state, including repeated finalization. |
| 952 | fn final c edit uchar 104 w edit ulong 64 to void |
| 953 | cnt = getle c 32 8 |
| 954 | bi = and cnt 63 |
| 955 | put c add 40 bi 128 |
| 956 | zbuf c add bi 1 64 |
| 957 | if ge bi 56 |
| 958 | compbuf c w |
| 959 | zbuf c 0 56 |
| 960 | end |
| 961 | bits = mul cnt 8 |
| 962 | for i ulong 8 |
| 963 | sh = mul sub 7 i 8 |
| 964 | put c add 96 i uchar and shr bits sh 255 |
| 965 | end |
| 966 | compbuf c w |
| 967 | h = new uint 8 0 |
| 968 | loadh c h |
| 969 | digest8 h w |
| 970 | total = add cnt sub 64 bi |
| 971 | if ge bi 56 |
| 972 | total = add total 64 |
| 973 | end |
| 974 | putle c 32 8 total |
| 975 | end |
| 976 | |
| 977 | note IV into h |
| 978 | fn initiv h edit uint 8 to void |
| 979 | put h 0 uint 1779033703 |
| 980 | put h 1 uint 3144134277 |
| 981 | put h 2 uint 1013904242 |
| 982 | put h 3 uint 2773480762 |
| 983 | put h 4 uint 1359893119 |
| 984 | put h 5 uint 2600822924 |
| 985 | put h 6 uint 528734635 |
| 986 | put h 7 uint 1541459225 |
| 987 | end |
| 988 | |
| 989 | note expand w[0..16) into the full 64-word schedule, unrolled (constant indices need no bounds checks). |
| 990 | note Every schedule word is stored duplicated, the 32-bit value in both halves (d = (x << 32) | x), so |
| 991 | note a rotate right by r is the low half of d >> r and a plain shift right by n is d >> (32 + n); sums |
| 992 | note are formed in the low 32 bits (add, and, xor, or need no masks) and duplicated once on store. |
| 993 | fn expand w edit ulong 64 to void |
| 994 | u = ulong 0 |
| 995 | v = ulong 0 |
| 996 | x = ulong 0 |
| 997 | x = get w 14 |
| 998 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 999 | x = get w 1 |
| 1000 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1001 | u = add u v |
| 1002 | u = add u get w 9 |
| 1003 | u = add u get w 0 |
| 1004 | u = shl u 32 |
| 1005 | put w 16 or u shr u 32 |
| 1006 | x = get w 15 |
| 1007 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1008 | x = get w 2 |
| 1009 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1010 | u = add u v |
| 1011 | u = add u get w 10 |
| 1012 | u = add u get w 1 |
| 1013 | u = shl u 32 |
| 1014 | put w 17 or u shr u 32 |
| 1015 | x = get w 16 |
| 1016 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1017 | x = get w 3 |
| 1018 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1019 | u = add u v |
| 1020 | u = add u get w 11 |
| 1021 | u = add u get w 2 |
| 1022 | u = shl u 32 |
| 1023 | put w 18 or u shr u 32 |
| 1024 | x = get w 17 |
| 1025 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1026 | x = get w 4 |
| 1027 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1028 | u = add u v |
| 1029 | u = add u get w 12 |
| 1030 | u = add u get w 3 |
| 1031 | u = shl u 32 |
| 1032 | put w 19 or u shr u 32 |
| 1033 | x = get w 18 |
| 1034 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1035 | x = get w 5 |
| 1036 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1037 | u = add u v |
| 1038 | u = add u get w 13 |
| 1039 | u = add u get w 4 |
| 1040 | u = shl u 32 |
| 1041 | put w 20 or u shr u 32 |
| 1042 | x = get w 19 |
| 1043 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1044 | x = get w 6 |
| 1045 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1046 | u = add u v |
| 1047 | u = add u get w 14 |
| 1048 | u = add u get w 5 |
| 1049 | u = shl u 32 |
| 1050 | put w 21 or u shr u 32 |
| 1051 | x = get w 20 |
| 1052 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1053 | x = get w 7 |
| 1054 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1055 | u = add u v |
| 1056 | u = add u get w 15 |
| 1057 | u = add u get w 6 |
| 1058 | u = shl u 32 |
| 1059 | put w 22 or u shr u 32 |
| 1060 | x = get w 21 |
| 1061 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1062 | x = get w 8 |
| 1063 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1064 | u = add u v |
| 1065 | u = add u get w 16 |
| 1066 | u = add u get w 7 |
| 1067 | u = shl u 32 |
| 1068 | put w 23 or u shr u 32 |
| 1069 | x = get w 22 |
| 1070 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1071 | x = get w 9 |
| 1072 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1073 | u = add u v |
| 1074 | u = add u get w 17 |
| 1075 | u = add u get w 8 |
| 1076 | u = shl u 32 |
| 1077 | put w 24 or u shr u 32 |
| 1078 | x = get w 23 |
| 1079 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1080 | x = get w 10 |
| 1081 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1082 | u = add u v |
| 1083 | u = add u get w 18 |
| 1084 | u = add u get w 9 |
| 1085 | u = shl u 32 |
| 1086 | put w 25 or u shr u 32 |
| 1087 | x = get w 24 |
| 1088 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1089 | x = get w 11 |
| 1090 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1091 | u = add u v |
| 1092 | u = add u get w 19 |
| 1093 | u = add u get w 10 |
| 1094 | u = shl u 32 |
| 1095 | put w 26 or u shr u 32 |
| 1096 | x = get w 25 |
| 1097 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1098 | x = get w 12 |
| 1099 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1100 | u = add u v |
| 1101 | u = add u get w 20 |
| 1102 | u = add u get w 11 |
| 1103 | u = shl u 32 |
| 1104 | put w 27 or u shr u 32 |
| 1105 | x = get w 26 |
| 1106 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1107 | x = get w 13 |
| 1108 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1109 | u = add u v |
| 1110 | u = add u get w 21 |
| 1111 | u = add u get w 12 |
| 1112 | u = shl u 32 |
| 1113 | put w 28 or u shr u 32 |
| 1114 | x = get w 27 |
| 1115 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1116 | x = get w 14 |
| 1117 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1118 | u = add u v |
| 1119 | u = add u get w 22 |
| 1120 | u = add u get w 13 |
| 1121 | u = shl u 32 |
| 1122 | put w 29 or u shr u 32 |
| 1123 | x = get w 28 |
| 1124 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1125 | x = get w 15 |
| 1126 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1127 | u = add u v |
| 1128 | u = add u get w 23 |
| 1129 | u = add u get w 14 |
| 1130 | u = shl u 32 |
| 1131 | put w 30 or u shr u 32 |
| 1132 | x = get w 29 |
| 1133 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1134 | x = get w 16 |
| 1135 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1136 | u = add u v |
| 1137 | u = add u get w 24 |
| 1138 | u = add u get w 15 |
| 1139 | u = shl u 32 |
| 1140 | put w 31 or u shr u 32 |
| 1141 | x = get w 30 |
| 1142 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1143 | x = get w 17 |
| 1144 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1145 | u = add u v |
| 1146 | u = add u get w 25 |
| 1147 | u = add u get w 16 |
| 1148 | u = shl u 32 |
| 1149 | put w 32 or u shr u 32 |
| 1150 | x = get w 31 |
| 1151 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1152 | x = get w 18 |
| 1153 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1154 | u = add u v |
| 1155 | u = add u get w 26 |
| 1156 | u = add u get w 17 |
| 1157 | u = shl u 32 |
| 1158 | put w 33 or u shr u 32 |
| 1159 | x = get w 32 |
| 1160 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1161 | x = get w 19 |
| 1162 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1163 | u = add u v |
| 1164 | u = add u get w 27 |
| 1165 | u = add u get w 18 |
| 1166 | u = shl u 32 |
| 1167 | put w 34 or u shr u 32 |
| 1168 | x = get w 33 |
| 1169 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1170 | x = get w 20 |
| 1171 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1172 | u = add u v |
| 1173 | u = add u get w 28 |
| 1174 | u = add u get w 19 |
| 1175 | u = shl u 32 |
| 1176 | put w 35 or u shr u 32 |
| 1177 | x = get w 34 |
| 1178 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1179 | x = get w 21 |
| 1180 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1181 | u = add u v |
| 1182 | u = add u get w 29 |
| 1183 | u = add u get w 20 |
| 1184 | u = shl u 32 |
| 1185 | put w 36 or u shr u 32 |
| 1186 | x = get w 35 |
| 1187 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1188 | x = get w 22 |
| 1189 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1190 | u = add u v |
| 1191 | u = add u get w 30 |
| 1192 | u = add u get w 21 |
| 1193 | u = shl u 32 |
| 1194 | put w 37 or u shr u 32 |
| 1195 | x = get w 36 |
| 1196 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1197 | x = get w 23 |
| 1198 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1199 | u = add u v |
| 1200 | u = add u get w 31 |
| 1201 | u = add u get w 22 |
| 1202 | u = shl u 32 |
| 1203 | put w 38 or u shr u 32 |
| 1204 | x = get w 37 |
| 1205 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1206 | x = get w 24 |
| 1207 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1208 | u = add u v |
| 1209 | u = add u get w 32 |
| 1210 | u = add u get w 23 |
| 1211 | u = shl u 32 |
| 1212 | put w 39 or u shr u 32 |
| 1213 | x = get w 38 |
| 1214 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1215 | x = get w 25 |
| 1216 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1217 | u = add u v |
| 1218 | u = add u get w 33 |
| 1219 | u = add u get w 24 |
| 1220 | u = shl u 32 |
| 1221 | put w 40 or u shr u 32 |
| 1222 | x = get w 39 |
| 1223 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1224 | x = get w 26 |
| 1225 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1226 | u = add u v |
| 1227 | u = add u get w 34 |
| 1228 | u = add u get w 25 |
| 1229 | u = shl u 32 |
| 1230 | put w 41 or u shr u 32 |
| 1231 | x = get w 40 |
| 1232 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1233 | x = get w 27 |
| 1234 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1235 | u = add u v |
| 1236 | u = add u get w 35 |
| 1237 | u = add u get w 26 |
| 1238 | u = shl u 32 |
| 1239 | put w 42 or u shr u 32 |
| 1240 | x = get w 41 |
| 1241 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1242 | x = get w 28 |
| 1243 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1244 | u = add u v |
| 1245 | u = add u get w 36 |
| 1246 | u = add u get w 27 |
| 1247 | u = shl u 32 |
| 1248 | put w 43 or u shr u 32 |
| 1249 | x = get w 42 |
| 1250 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1251 | x = get w 29 |
| 1252 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1253 | u = add u v |
| 1254 | u = add u get w 37 |
| 1255 | u = add u get w 28 |
| 1256 | u = shl u 32 |
| 1257 | put w 44 or u shr u 32 |
| 1258 | x = get w 43 |
| 1259 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1260 | x = get w 30 |
| 1261 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1262 | u = add u v |
| 1263 | u = add u get w 38 |
| 1264 | u = add u get w 29 |
| 1265 | u = shl u 32 |
| 1266 | put w 45 or u shr u 32 |
| 1267 | x = get w 44 |
| 1268 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1269 | x = get w 31 |
| 1270 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1271 | u = add u v |
| 1272 | u = add u get w 39 |
| 1273 | u = add u get w 30 |
| 1274 | u = shl u 32 |
| 1275 | put w 46 or u shr u 32 |
| 1276 | x = get w 45 |
| 1277 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1278 | x = get w 32 |
| 1279 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1280 | u = add u v |
| 1281 | u = add u get w 40 |
| 1282 | u = add u get w 31 |
| 1283 | u = shl u 32 |
| 1284 | put w 47 or u shr u 32 |
| 1285 | x = get w 46 |
| 1286 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1287 | x = get w 33 |
| 1288 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1289 | u = add u v |
| 1290 | u = add u get w 41 |
| 1291 | u = add u get w 32 |
| 1292 | u = shl u 32 |
| 1293 | put w 48 or u shr u 32 |
| 1294 | x = get w 47 |
| 1295 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1296 | x = get w 34 |
| 1297 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1298 | u = add u v |
| 1299 | u = add u get w 42 |
| 1300 | u = add u get w 33 |
| 1301 | u = shl u 32 |
| 1302 | put w 49 or u shr u 32 |
| 1303 | x = get w 48 |
| 1304 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1305 | x = get w 35 |
| 1306 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1307 | u = add u v |
| 1308 | u = add u get w 43 |
| 1309 | u = add u get w 34 |
| 1310 | u = shl u 32 |
| 1311 | put w 50 or u shr u 32 |
| 1312 | x = get w 49 |
| 1313 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1314 | x = get w 36 |
| 1315 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1316 | u = add u v |
| 1317 | u = add u get w 44 |
| 1318 | u = add u get w 35 |
| 1319 | u = shl u 32 |
| 1320 | put w 51 or u shr u 32 |
| 1321 | x = get w 50 |
| 1322 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1323 | x = get w 37 |
| 1324 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1325 | u = add u v |
| 1326 | u = add u get w 45 |
| 1327 | u = add u get w 36 |
| 1328 | u = shl u 32 |
| 1329 | put w 52 or u shr u 32 |
| 1330 | x = get w 51 |
| 1331 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1332 | x = get w 38 |
| 1333 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1334 | u = add u v |
| 1335 | u = add u get w 46 |
| 1336 | u = add u get w 37 |
| 1337 | u = shl u 32 |
| 1338 | put w 53 or u shr u 32 |
| 1339 | x = get w 52 |
| 1340 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1341 | x = get w 39 |
| 1342 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1343 | u = add u v |
| 1344 | u = add u get w 47 |
| 1345 | u = add u get w 38 |
| 1346 | u = shl u 32 |
| 1347 | put w 54 or u shr u 32 |
| 1348 | x = get w 53 |
| 1349 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1350 | x = get w 40 |
| 1351 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1352 | u = add u v |
| 1353 | u = add u get w 48 |
| 1354 | u = add u get w 39 |
| 1355 | u = shl u 32 |
| 1356 | put w 55 or u shr u 32 |
| 1357 | x = get w 54 |
| 1358 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1359 | x = get w 41 |
| 1360 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1361 | u = add u v |
| 1362 | u = add u get w 49 |
| 1363 | u = add u get w 40 |
| 1364 | u = shl u 32 |
| 1365 | put w 56 or u shr u 32 |
| 1366 | x = get w 55 |
| 1367 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1368 | x = get w 42 |
| 1369 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1370 | u = add u v |
| 1371 | u = add u get w 50 |
| 1372 | u = add u get w 41 |
| 1373 | u = shl u 32 |
| 1374 | put w 57 or u shr u 32 |
| 1375 | x = get w 56 |
| 1376 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1377 | x = get w 43 |
| 1378 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1379 | u = add u v |
| 1380 | u = add u get w 51 |
| 1381 | u = add u get w 42 |
| 1382 | u = shl u 32 |
| 1383 | put w 58 or u shr u 32 |
| 1384 | x = get w 57 |
| 1385 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1386 | x = get w 44 |
| 1387 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1388 | u = add u v |
| 1389 | u = add u get w 52 |
| 1390 | u = add u get w 43 |
| 1391 | u = shl u 32 |
| 1392 | put w 59 or u shr u 32 |
| 1393 | x = get w 58 |
| 1394 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1395 | x = get w 45 |
| 1396 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1397 | u = add u v |
| 1398 | u = add u get w 53 |
| 1399 | u = add u get w 44 |
| 1400 | u = shl u 32 |
| 1401 | put w 60 or u shr u 32 |
| 1402 | x = get w 59 |
| 1403 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1404 | x = get w 46 |
| 1405 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1406 | u = add u v |
| 1407 | u = add u get w 54 |
| 1408 | u = add u get w 45 |
| 1409 | u = shl u 32 |
| 1410 | put w 61 or u shr u 32 |
| 1411 | x = get w 60 |
| 1412 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1413 | x = get w 47 |
| 1414 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1415 | u = add u v |
| 1416 | u = add u get w 55 |
| 1417 | u = add u get w 46 |
| 1418 | u = shl u 32 |
| 1419 | put w 62 or u shr u 32 |
| 1420 | x = get w 61 |
| 1421 | u = xor xor shr x 17 shr x 19 shr x 42 |
| 1422 | x = get w 48 |
| 1423 | v = xor xor shr x 7 shr x 18 shr x 35 |
| 1424 | u = add u v |
| 1425 | u = add u get w 56 |
| 1426 | u = add u get w 47 |
| 1427 | u = shl u 32 |
| 1428 | put w 63 or u shr u 32 |
| 1429 | end |
| 1430 | |
| 1431 | note Word access for the aligned paths. b8 is the caller's 8-byte-aligned copy of the input lent a |
| 1432 | note second time as ulong cells (b views the same bytes), so one load brings 8 bytes. Swapping the |
| 1433 | note bytes inside each 32-bit half (two mask-and-shift steps; the constants stay in registers) turns |
| 1434 | note little-endian bytes b0..b7 into the big-endian words b0..b3 (low half) and b4..b7 (high half). |
| 1435 | note Each word is stored duplicated, as expand requires. |
| 1436 | fn blk8 b8 view ulong 512 q ulong w edit ulong 64 to void |
| 1437 | for i ulong 8 |
| 1438 | x = get b8 add q i |
| 1439 | y = or shl and x 71777214294589695 8 and shr x 8 71777214294589695 |
| 1440 | y = or shl and y 281470681808895 16 and shr y 16 281470681808895 |
| 1441 | j = mul i 2 |
| 1442 | t = shl y 32 |
| 1443 | put w j or t shr t 32 |
| 1444 | put w add j 1 or and y 18446744069414584320 shr y 32 |
| 1445 | end |
| 1446 | end |
| 1447 | |
| 1448 | note the padded tail b[off..n) (less than 64 bytes), read as words through b8 (the bytes past n |
| 1449 | note are inside the caller's 4096-byte copy and are masked off here): the word holding byte n keeps |
| 1450 | note its k valid bytes and gets 0x80 after them, later words are zero, the 64-bit bit count goes in |
| 1451 | note words 14 and 15; a second block when the tail is 56 bytes or more |
| 1452 | fn tail8 h edit uint 8 b8 view ulong 512 off ulong n ulong w edit ulong 64 to void |
| 1453 | blk8 b8 shr off 3 w |
| 1454 | r = sub n off |
| 1455 | fw = shr r 2 |
| 1456 | k = and r 3 |
| 1457 | sh = mul k 8 |
| 1458 | v = get w fw |
| 1459 | v = and v shl 4294967295 sub 32 sh |
| 1460 | v = and v 4294967295 |
| 1461 | v = or v shl 128 sub 24 sh |
| 1462 | put w fw or v shl v 32 |
| 1463 | i = add fw 1 |
| 1464 | while lt i 16 bound 16 |
| 1465 | put w i 0 |
| 1466 | i = add i 1 |
| 1467 | end |
| 1468 | if ge r 56 |
| 1469 | expand w |
| 1470 | rounds h w |
| 1471 | for j ulong 14 |
| 1472 | put w j 0 |
| 1473 | end |
| 1474 | end |
| 1475 | bits = mul n 8 |
| 1476 | v = shr bits 32 |
| 1477 | put w 14 or v shl v 32 |
| 1478 | v = and bits 4294967295 |
| 1479 | put w 15 or v shl v 32 |
| 1480 | expand w |
| 1481 | rounds h w |
| 1482 | end |
| 1483 | |
| 1484 | note the digest of h as 32 bytes packed little endian into w[0..4): word i holds the big-endian |
| 1485 | note bytes of h[2i] then h[2i+1], so the caller copies the digest out of w with memcpy |
| 1486 | fn digest8 h edit uint 8 w edit ulong 64 to void |
| 1487 | for i ulong 4 |
| 1488 | j = mul i 2 |
| 1489 | x = or ulong get h j shl ulong get h add j 1 32 |
| 1490 | y = or shl and x 71777214294589695 8 and shr x 8 71777214294589695 |
| 1491 | y = or shl and y 281470681808895 16 and shr y 16 281470681808895 |
| 1492 | put w i y |
| 1493 | end |
| 1494 | end |
| 1495 | |
| 1496 | note SHA-256 of the n < 4096 bytes in b8, state in locals only (sha256_hash's short path) |
| 1497 | fn oneshot b8 view ulong 512 n ulong w edit ulong 64 to void |
| 1498 | h = new uint 8 0 |
| 1499 | initiv h |
| 1500 | off = ulong 0 |
| 1501 | while le add off 64 n bound 64 |
| 1502 | blk8 b8 shr off 3 w |
| 1503 | expand w |
| 1504 | rounds h w |
| 1505 | off = add off 64 |
| 1506 | end |
| 1507 | tail8 h b8 off n w |
| 1508 | digest8 h w |
| 1509 | end |
| 1510 | |
| 1511 | note Local adaptation: bridge-seeded does not lower explicit trap statements. |
| 1512 | note Return refusal codes before mutation; internal helpers are reached only through omsha. |
| 1513 | fn omsha c edit uchar 104 b view uchar 4096 n ulong op ulong w edit ulong 64 b8 view ulong 512 to ulong |
| 1514 | if or gt n 4096 and eq op 3 eq n 4096 |
| 1515 | ret 3 |
| 1516 | end |
| 1517 | if eq op 0 |
| 1518 | init c |
| 1519 | ret 0 |
| 1520 | end |
| 1521 | if eq op 1 |
| 1522 | absorb c b n w |
| 1523 | ret 0 |
| 1524 | end |
| 1525 | if eq op 2 |
| 1526 | final c w |
| 1527 | ret 0 |
| 1528 | end |
| 1529 | if eq op 3 |
| 1530 | oneshot b8 n w |
| 1531 | ret 0 |
| 1532 | end |
| 1533 | ret 9 |
| 1534 | end |