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/omega/allen/vendor/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 / omega / allen / vendor / sha256.om` 213 lines ยท 3921 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-or-later 2 note SHA256 core reused byte-for-byte from native Omega TRN1 at `12251e3403d42931ada27dc1c54b3b610954be5d`. 3 note Reads stdin up to 8 MiB and emits lowercase hex plus LF only after successful EOF. 4 global Buf uchar 8192 5 global H uint 8 6 global Vv uint 8 7 global W uint 64 8 global K uint 64 9 global Hb uchar 64 10 global Hs ulong 2 11 global Hash uchar 32 12 global Out uchar 65 13 text Hex "`0123456789abcdef`" 14 15 fn rotate x uint n uint to uint 16 ret or shr x n shl x sub 32 n 17 end 18 19 fn round i ulong to void 20 e = get Vv 4 21 a = get Vv 0 22 s = xor xor rotate e 6 rotate e 11 rotate e 25 23 c = xor and e get Vv 5 and not e get Vv 6 24 t = add add get Vv 7 s add c add get K i get W i 25 s = xor xor rotate a 2 rotate a 13 rotate a 22 26 c = and a get Vv 1 27 c = xor c and a get Vv 2 28 c = xor c and get Vv 1 get Vv 2 29 u = add s c 30 put Vv 7 get Vv 6 31 put Vv 6 get Vv 5 32 put Vv 5 e 33 put Vv 4 add get Vv 3 t 34 put Vv 3 get Vv 2 35 put Vv 2 get Vv 1 36 put Vv 1 a 37 put Vv 0 add t u 38 end 39 40 fn block to void 41 for i ulong 16 42 x = uint 0 43 for j ulong 4 44 x = or shl x 8 uint get Hb add mul i 4 j 45 end 46 put W i x 47 end 48 for j ulong 48 49 i = add j 16 50 x = get W sub i 15 51 y = get W sub i 2 52 s = xor xor rotate x 7 rotate x 18 shr x 3 53 t = xor xor rotate y 17 rotate y 19 shr y 10 54 put W i add add get W sub i 16 s add get W sub i 7 t 55 end 56 for i ulong 8 57 put Vv i get H i 58 end 59 for i ulong 64 60 round i 61 end 62 for i ulong 8 63 put H i add get H i get Vv i 64 end 65 end 66 67 fn hinit to void 68 put H 0 `1779033703` 69 put H 1 `3144134277` 70 put H 2 `1013904242` 71 put H 3 `2773480762` 72 put H 4 `1359893119` 73 put H 5 `2600822924` 74 put H 6 `528734635` 75 put H 7 `1541459225` 76 put Hs 0 0 77 put Hs 1 0 78 end 79 80 fn hbyte c uchar to void 81 p = get Hs 0 82 put Hb p c 83 p = add p 1 84 put Hs 1 add get Hs 1 1 85 if eq p 64 86 block 87 p = 0 88 end 89 put Hs 0 p 90 end 91 92 fn update off ulong count ulong to void 93 for i ulong count 94 hbyte get Buf add off i 95 end 96 end 97 98 fn finish to void 99 bits = mul get Hs 1 8 100 hbyte 128 101 while ne get Hs 0 56 102 hbyte 0 103 end 104 for i ulong 8 105 hbyte uchar and shr bits mul sub 7 i 8 255 106 end 107 for i ulong 32 108 x = get H div i 4 109 put Hash i uchar and shr x uint mul sub 3 rem i 4 8 255 110 end 111 end 112 113 fn constants to void 114 put K 0 `1116352408` 115 put K 1 `1899447441` 116 put K 2 `3049323471` 117 put K 3 `3921009573` 118 put K 4 `961987163` 119 put K 5 `1508970993` 120 put K 6 `2453635748` 121 put K 7 `2870763221` 122 put K 8 `3624381080` 123 put K 9 `310598401` 124 put K 10 `607225278` 125 put K 11 `1426881987` 126 put K 12 `1925078388` 127 put K 13 `2162078206` 128 put K 14 `2614888103` 129 put K 15 `3248222580` 130 put K 16 `3835390401` 131 put K 17 `4022224774` 132 put K 18 `264347078` 133 put K 19 `604807628` 134 put K 20 `770255983` 135 put K 21 `1249150122` 136 put K 22 `1555081692` 137 put K 23 `1996064986` 138 put K 24 `2554220882` 139 put K 25 `2821834349` 140 put K 26 `2952996808` 141 put K 27 `3210313671` 142 put K 28 `3336571891` 143 put K 29 `3584528711` 144 put K 30 `113926993` 145 put K 31 `338241895` 146 put K 32 `666307205` 147 put K 33 `773529912` 148 put K 34 `1294757372` 149 put K 35 `1396182291` 150 put K 36 `1695183700` 151 put K 37 `1986661051` 152 put K 38 `2177026350` 153 put K 39 `2456956037` 154 put K 40 `2730485921` 155 put K 41 `2820302411` 156 put K 42 `3259730800` 157 put K 43 `3345764771` 158 put K 44 `3516065817` 159 put K 45 `3600352804` 160 put K 46 `4094571909` 161 put K 47 `275423344` 162 put K 48 `430227734` 163 put K 49 `506948616` 164 put K 50 `659060556` 165 put K 51 `883997877` 166 put K 52 `958139571` 167 put K 53 `1322822218` 168 put K 54 `1537002063` 169 put K 55 `1747873779` 170 put K 56 `1955562222` 171 put K 57 `2024104815` 172 put K 58 `2227730452` 173 put K 59 `2361852424` 174 put K 60 `2428436474` 175 put K 61 `2756734187` 176 put K 62 `3204031479` 177 put K 63 `3329325298` 178 end 179 180 note Handwritten stream interface around the pinned native Omega SHA256 core. 181 fn main to int 182 constants 183 hinit 184 total = ulong 0 185 n = read 0 Buf 0 len Buf 186 while gt n 0 187 if gt ulong n sub ulong `8388608` total 188 ret 3 189 end 190 update 0 ulong n 191 total = add total ulong n 192 n = read 0 Buf 0 len Buf 193 end 194 if lt n 0 195 ret 2 196 end 197 finish 198 for i ulong 32 199 c = get Hash i 200 put Out mul i 2 get Hex ulong shr c 4 201 put Out add mul i 2 1 get Hex ulong and c 15 202 end 203 put Out 64 uchar 10 204 sent = ulong 0 205 while lt sent 65 206 w = write 1 Out sent sub ulong 65 sent 207 if le w 0 208 ret 2 209 end 210 sent = add sent ulong w 211 end 212 ret 0 213 end