Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/om/lm1b/sha256.om # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / om / lm1b / sha256.om` 159 lines ยท 3356 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-or-later 2 note Incremental SHA-256 in native Omega. No runtime library calls. 3 note Algorithm and constants checked against Omega seed/atlas/atlas.s2 and src/sha256.c 4 note at seed ancestor `29b12760`. Those files are references, never build inputs. 5 note hmeta: buffered bytes, message bytes, state (0 active, 1 finalized, 2 error). 6 note hfinal exposes 64 lowercase hexadecimal bytes in hd; reset before another message. 7 global hk uint 64 8 global hs uint 8 9 global hm uint 64 10 global hb uchar 64 11 global hd uchar 64 12 global hmeta ulong 3 13 text hconst "`428a2f9871374491b5c0fbcfe9b5dba53956c25b59f111f1923f82a4ab1c5ed5d807aa9812835b01243185be550c7dc372be5d7480deb1fe9bdc06a7c19bf174e49b69c1efbe47860fc19dc6240ca1cc2de92c6f4a7484aa5cb0a9dc76f988da983e5152a831c66db00327c8bf597fc7c6e00bf3d5a7914706ca63511429296727b70a852e1b21384d2c6dfc53380d13650a7354766a0abb81c2c92e92722c85a2bfe8a1a81a664bc24b8b70c76c51a3d192e819d6990624f40e3585106aa07019a4c1161e376c082748774c34b0bcb5391c0cb34ed8aa4a5b9cca4f682e6ff3748f82ee78a5636f84c878148cc7020890befffaa4506cebbef9a3f7c67178f2`" 14 text hseed "`6a09e667bb67ae853c6ef372a54ff53a510e527f9b05688c1f83d9ab5be0cd19`" 15 text hhex "`0123456789abcdef`" 16 17 fn hnibble c uchar to uint 18 if le c 57 19 ret uint sub c 48 20 end 21 ret uint sub c 87 22 end 23 24 fn hreset to void 25 for i ulong 64 26 v = uint 0 27 for j ulong 8 28 v = or shl v 4 hnibble get hconst add mul i 8 j 29 end 30 put hk i v 31 end 32 for i ulong 8 33 v = uint 0 34 for j ulong 8 35 v = or shl v 4 hnibble get hseed add mul i 8 j 36 end 37 put hs i v 38 end 39 for i ulong 3 40 put hmeta i 0 41 end 42 end 43 44 fn hrot x uint n uint to uint 45 ret or shr x n shl x sub 32 n 46 end 47 48 fn hsmall0 x uint to uint 49 ret xor xor hrot x 7 hrot x 18 shr x 3 50 end 51 52 fn hsmall1 x uint to uint 53 ret xor xor hrot x 17 hrot x 19 shr x 10 54 end 55 56 fn hbig0 x uint to uint 57 ret xor xor hrot x 2 hrot x 13 hrot x 22 58 end 59 60 fn hbig1 x uint to uint 61 ret xor xor hrot x 6 hrot x 11 hrot x 25 62 end 63 64 fn hblock to void 65 for i ulong 16 66 v = uint 0 67 for j ulong 4 68 v = or shl v 8 uint get hb add mul i 4 j 69 end 70 put hm i v 71 end 72 for j ulong 48 73 i = add j 16 74 v = add hsmall1 get hm sub i 2 get hm sub i 7 75 v = add v hsmall0 get hm sub i 15 76 put hm i add v get hm sub i 16 77 end 78 a = get hs 0 79 b = get hs 1 80 c = get hs 2 81 d = get hs 3 82 e = get hs 4 83 f = get hs 5 84 g = get hs 6 85 h = get hs 7 86 for i ulong 64 87 t1 = add h hbig1 e 88 t1 = add t1 xor and e f and not e g 89 t1 = add t1 get hk i 90 t1 = add t1 get hm i 91 t2 = hbig0 a 92 t2 = add t2 xor xor and a b and a c and b c 93 h = g 94 g = f 95 f = e 96 e = add d t1 97 d = c 98 c = b 99 b = a 100 a = add t1 t2 101 end 102 put hs 0 add get hs 0 a 103 put hs 1 add get hs 1 b 104 put hs 2 add get hs 2 c 105 put hs 3 add get hs 3 d 106 put hs 4 add get hs 4 e 107 put hs 5 add get hs 5 f 108 put hs 6 add get hs 6 g 109 put hs 7 add get hs 7 h 110 end 111 112 fn hraw c uchar to void 113 n = get hmeta 0 114 put hb n c 115 n = add n 1 116 if eq n 64 117 hblock 118 n = ulong 0 119 end 120 put hmeta 0 n 121 end 122 123 fn hpush c uchar to bool 124 if ne get hmeta 2 0 125 ret false 126 end 127 if eq get hmeta 1 `2305843009213693951` 128 put hmeta 2 2 129 ret false 130 end 131 hraw c 132 put hmeta 1 add get hmeta 1 1 133 ret true 134 end 135 136 fn hfinal to bool 137 if ne get hmeta 2 0 138 ret false 139 end 140 bits = mul get hmeta 1 8 141 hraw 128 142 while ne get hmeta 0 56 143 hraw 0 144 end 145 for i ulong 8 146 shift = mul sub 7 i 8 147 hraw uchar and shr bits shift 255 148 end 149 for i ulong 8 150 v = get hs i 151 for j ulong 8 152 shift = uint mul sub 7 j 4 153 digit = ulong and shr v shift 15 154 put hd add mul i 8 j get hhex digit 155 end 156 end 157 put hmeta 2 1 158 ret true 159 end