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/omega-mv/blob/main/gpu/nvidia/om/cache/digest.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / nvidia / om / cache / digest.om` 252 lines ยท 5603 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note OM-1 bounded SHA256 adaptation of omega-mv `6999fa9e` om/sha256. 3 note Constants copied from filed sha256-k.dec and sha256-iv.dec; no generated constants. 4 note Exact used bytes only; no identity schema and no implicit padding. 5 fn kc_rotr x uint n uint to uint 6 ret or shr x n shl x sub uint 32 n 7 end 8 fn kc_k k edit uint 64 to void 9 put k 0 `1116352408` 10 put k 1 `1899447441` 11 put k 2 `3049323471` 12 put k 3 `3921009573` 13 put k 4 `961987163` 14 put k 5 `1508970993` 15 put k 6 `2453635748` 16 put k 7 `2870763221` 17 put k 8 `3624381080` 18 put k 9 `310598401` 19 put k 10 `607225278` 20 put k 11 `1426881987` 21 put k 12 `1925078388` 22 put k 13 `2162078206` 23 put k 14 `2614888103` 24 put k 15 `3248222580` 25 put k 16 `3835390401` 26 put k 17 `4022224774` 27 put k 18 `264347078` 28 put k 19 `604807628` 29 put k 20 `770255983` 30 put k 21 `1249150122` 31 put k 22 `1555081692` 32 put k 23 `1996064986` 33 put k 24 `2554220882` 34 put k 25 `2821834349` 35 put k 26 `2952996808` 36 put k 27 `3210313671` 37 put k 28 `3336571891` 38 put k 29 `3584528711` 39 put k 30 `113926993` 40 put k 31 `338241895` 41 put k 32 `666307205` 42 put k 33 `773529912` 43 put k 34 `1294757372` 44 put k 35 `1396182291` 45 put k 36 `1695183700` 46 put k 37 `1986661051` 47 put k 38 `2177026350` 48 put k 39 `2456956037` 49 put k 40 `2730485921` 50 put k 41 `2820302411` 51 put k 42 `3259730800` 52 put k 43 `3345764771` 53 put k 44 `3516065817` 54 put k 45 `3600352804` 55 put k 46 `4094571909` 56 put k 47 `275423344` 57 put k 48 `430227734` 58 put k 49 `506948616` 59 put k 50 `659060556` 60 put k 51 `883997877` 61 put k 52 `958139571` 62 put k 53 `1322822218` 63 put k 54 `1537002063` 64 put k 55 `1747873779` 65 put k 56 `1955562222` 66 put k 57 `2024104815` 67 put k 58 `2227730452` 68 put k 59 `2361852424` 69 put k 60 `2428436474` 70 put k 61 `2756734187` 71 put k 62 `3204031479` 72 put k 63 `3329325298` 73 end 74 fn kc_iv s edit uint 8 to void 75 put s 0 `1779033703` 76 put s 1 `3144134277` 77 put s 2 `1013904242` 78 put s 3 `2773480762` 79 put s 4 `1359893119` 80 put s 5 `2600822924` 81 put s 6 `528734635` 82 put s 7 `1541459225` 83 end 84 note Full blocks are read directly, not copied or zero-filled into an artifact-sized temporary. 85 fn kc_sched w edit uint 64 m view uchar 4096 o ulong to void 86 q = ulong 0 87 x = uint 0 88 for i ulong 16 89 q = add o mul i 4 90 x = uint get m q 91 x = or shl x 8 uint get m add q 1 92 x = or shl x 8 uint get m add q 2 93 put w i or shl x 8 uint get m add q 3 94 end 95 kc_expand w 96 end 97 note Fixed-array signatures require separate readers at the OM-1 production pin. 98 fn kc_codesched w edit uint 64 m view uchar 16384 o ulong to void 99 q = ulong 0 100 x = uint 0 101 for i ulong 16 102 q = add o mul i 4 103 x = uint get m q 104 x = or shl x 8 uint get m add q 1 105 x = or shl x 8 uint get m add q 2 106 put w i or shl x 8 uint get m add q 3 107 end 108 kc_expand w 109 end 110 fn kc_padsched w edit uint 64 m view uchar 128 o ulong to void 111 q = ulong 0 112 x = uint 0 113 for i ulong 16 114 q = add o mul i 4 115 x = uint get m q 116 x = or shl x 8 uint get m add q 1 117 x = or shl x 8 uint get m add q 2 118 put w i or shl x 8 uint get m add q 3 119 end 120 kc_expand w 121 end 122 fn kc_expand w edit uint 64 to void 123 x = uint 0 124 y = uint 0 125 for i ulong 48 126 x = get w add i 1 127 y = get w add i 14 128 x = add add get w i get w add i 9 xor xor kc_rotr x 7 kc_rotr x 18 shr x 3 129 put w add i 16 add x xor xor kc_rotr y 17 kc_rotr y 19 shr y 10 130 end 131 end 132 133 note The 64 rounds on the chaining value s. uint arithmetic wraps mod 2^32. 134 note Ch(e,f,g) = (e and f) xor (not e and g) is written g xor (e and (f xor g)); Maj(a,b,c) = 135 note (a and b) xor (a and c) xor (b and c) is written (a and b) or (c and (a or b)). Both are bitwise 136 note identities. h first becomes T1, then T1 + T2, which is the next a; the names then shift by one. 137 note The sums are built a term per line and each Sigma in two lines through t: 12 names are live, and 138 note omc hands out 16 registers with no spilling (error 12 under compiler-s1/s2 for longer lines). 139 fn kc_rounds s edit uint 8 w view uint 64 kt view uint 64 to void 140 a = get s 0 141 b = get s 1 142 c = get s 2 143 d = get s 3 144 e = get s 4 145 f = get s 5 146 g = get s 6 147 h = get s 7 148 t = uint 0 149 for i ulong 64 150 h = add h get kt i 151 h = add h get w i 152 t = xor kc_rotr e 6 kc_rotr e 11 153 t = xor t kc_rotr e 25 154 h = add h t 155 h = add h xor g and e xor f g 156 d = add d h 157 t = xor kc_rotr a 2 kc_rotr a 13 158 t = xor t kc_rotr a 22 159 h = add h t 160 t = and c or a b 161 h = add h or and a b t 162 t = h 163 h = g 164 g = f 165 f = e 166 e = d 167 d = c 168 c = b 169 b = a 170 a = t 171 end 172 put s 0 add get s 0 a 173 put s 1 add get s 1 b 174 put s 2 add get s 2 c 175 put s 3 add get s 3 d 176 put s 4 add get s 4 e 177 put s 5 add get s 5 f 178 put s 6 add get s 6 g 179 put s 7 add get s 7 h 180 end 181 fn kc_output s view uint 8 dst edit uchar 32 to void 182 for i ulong 8 183 for j ulong 4 184 q = add mul i 4 j 185 v = shr get s i mul sub ulong 3 j 8 186 put dst q uchar and v 255 187 end 188 end 189 end 190 fn kc_finish s edit uint 8 w edit uint 64 kt view uint 64 buf edit uchar 128 n ulong to void 191 used = rem n 64 192 put buf used 128 193 nb = ulong 64 194 if ge used 56 195 nb = 128 196 end 197 for i ulong 8 198 q = sub nb add i 1 199 v = shr shl n 3 mul i 8 200 put buf q uchar and v 255 201 end 202 kc_padsched w buf 0 203 kc_rounds s w kt 204 if eq nb 128 205 kc_padsched w buf 64 206 kc_rounds s w kt 207 end 208 end 209 fn kc_sha data view uchar 4096 n ulong dst edit uchar 32 to int 210 buf = new uchar 128 0 211 s = new uint 8 0 212 w = new uint 64 0 213 kt = new uint 64 0 214 if gt n 4096 215 ret -1 216 end 217 kc_k kt 218 kc_iv s 219 for off ulong div n 64 220 kc_sched w data mul off 64 221 kc_rounds s w kt 222 end 223 base = mul div n 64 64 224 for i ulong rem n 64 225 put buf i get data add base i 226 end 227 kc_finish s w kt buf n 228 kc_output s dst 229 ret 0 230 end 231 fn kc_codesha data view uchar 16384 n ulong dst edit uchar 32 to int 232 buf = new uchar 128 0 233 s = new uint 8 0 234 w = new uint 64 0 235 kt = new uint 64 0 236 if gt n 16384 237 ret -1 238 end 239 kc_k kt 240 kc_iv s 241 for off ulong div n 64 242 kc_codesched w data mul off 64 243 kc_rounds s w kt 244 end 245 base = mul div n 64 64 246 for i ulong rem n 64 247 put buf i get data add base i 248 end 249 kc_finish s w kt buf n 250 kc_output s dst 251 ret 0 252 end