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/cert-sha384.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 / cert-sha384.om` 333 lines ยท 9177 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Modified 2026-10-25: SHA384 from aien-dev/omnet om/sha512/sha512.om. 3 note Source `a14ff7efc94ea56530a61e0d91675dc970e7d806`; file SHA256 4 note `069a54b75484221bc7dbacfbea744ca9002c295f4f34f2c3905b0776450e3ce2`. 5 note SHA384 IV per FIPS180-4 section 5.3.4; only first48 output bytes are SHA384. 6 note Compression/padding reused; names cs384, no signing. CERT-APACHE-LICENSE applies. 7 note SPDX-License-Identifier: Apache-2.0 8 note sha512.om: SHA-512 (FIPS 180-4 section 6.4) as a library unit: functions only, no main, no 9 note globals. Every function name starts with cs384. 10 note 11 note API (one shot): 12 note fn cs384hash m view uchar 65536 n ulong o edit uchar 64 to void 13 note writes SHA-512(m[0..n)) as 64 bytes to o[0..64); n > 65536 traps 3. 14 note fn cs384pre p view uchar 64 m view uchar 65536 n ulong o edit uchar 64 to void 15 note writes SHA-512(p[0..64) || m[0..n)) to o[0..64); n > 65536 traps 3. 16 note 17 note Words are ulong (64-bit unsigned, wrapping add is the mod 2^64 addition of FIPS 180-4 section 3.2). 18 note Omega has no rotate word, so ROTR^r(x) = (x >> r) | (x << (64 - r)) (FIPS 180-4 section 3.2 item 4). 19 note Not constant-time audited. 20 21 note K{512}[0..80): first 64 bits of the fractional parts of the cube roots of the first 80 primes 22 note (FIPS 180-4 section 4.2.3) 23 fn cs384k k edit ulong 80 to void 24 put k 0 `4794697086780616226` 25 put k 1 `8158064640168781261` 26 put k 2 `13096744586834688815` 27 put k 3 `16840607885511220156` 28 put k 4 `4131703408338449720` 29 put k 5 `6480981068601479193` 30 put k 6 `10538285296894168987` 31 put k 7 `12329834152419229976` 32 put k 8 `15566598209576043074` 33 put k 9 `1334009975649890238` 34 put k 10 `2608012711638119052` 35 put k 11 `6128411473006802146` 36 put k 12 `8268148722764581231` 37 put k 13 `9286055187155687089` 38 put k 14 `11230858885718282805` 39 put k 15 `13951009754708518548` 40 put k 16 `16472876342353939154` 41 put k 17 `17275323862435702243` 42 put k 18 `1135362057144423861` 43 put k 19 `2597628984639134821` 44 put k 20 `3308224258029322869` 45 put k 21 `5365058923640841347` 46 put k 22 `6679025012923562964` 47 put k 23 `8573033837759648693` 48 put k 24 `10970295158949994411` 49 put k 25 `12119686244451234320` 50 put k 26 `12683024718118986047` 51 put k 27 `13788192230050041572` 52 put k 28 `14330467153632333762` 53 put k 29 `15395433587784984357` 54 put k 30 `489312712824947311` 55 put k 31 `1452737877330783856` 56 put k 32 `2861767655752347644` 57 put k 33 `3322285676063803686` 58 put k 34 `5560940570517711597` 59 put k 35 `5996557281743188959` 60 put k 36 `7280758554555802590` 61 put k 37 `8532644243296465576` 62 put k 38 `9350256976987008742` 63 put k 39 `10552545826968843579` 64 put k 40 `11727347734174303076` 65 put k 41 `12113106623233404929` 66 put k 42 `14000437183269869457` 67 put k 43 `14369950271660146224` 68 put k 44 `15101387698204529176` 69 put k 45 `15463397548674623760` 70 put k 46 `17586052441742319658` 71 put k 47 `1182934255886127544` 72 put k 48 `1847814050463011016` 73 put k 49 `2177327727835720531` 74 put k 50 `2830643537854262169` 75 put k 51 `3796741975233480872` 76 put k 52 `4115178125766777443` 77 put k 53 `5681478168544905931` 78 put k 54 `6601373596472566643` 79 put k 55 `7507060721942968483` 80 put k 56 `8399075790359081724` 81 put k 57 `8693463985226723168` 82 put k 58 `9568029438360202098` 83 put k 59 `10144078919501101548` 84 put k 60 `10430055236837252648` 85 put k 61 `11840083180663258601` 86 put k 62 `13761210420658862357` 87 put k 63 `14299343276471374635` 88 put k 64 `14566680578165727644` 89 put k 65 `15097957966210449927` 90 put k 66 `16922976911328602910` 91 put k 67 `17689382322260857208` 92 put k 68 `500013540394364858` 93 put k 69 `748580250866718886` 94 put k 70 `1242879168328830382` 95 put k 71 `1977374033974150939` 96 put k 72 `2944078676154940804` 97 put k 73 `3659926193048069267` 98 put k 74 `4368137639120453308` 99 put k 75 `4836135668995329356` 100 put k 76 `5532061633213252278` 101 put k 77 `6448918945643986474` 102 put k 78 `6902733635092675308` 103 put k 79 `7801388544844847127` 104 end 105 106 note H(0) for SHA-512: first 64 bits of the fractional parts of the square roots of the first 8 primes 107 note (FIPS 180-4 section 5.3.5) 108 fn cs384iv h edit ulong 8 to void 109 put h 0 `14680500436340154072` 110 put h 1 `7105036623409894663` 111 put h 2 `10473403895298186519` 112 put h 3 `1526699215303891257` 113 put h 4 `7436329637833083697` 114 put h 5 `10282925794625328401` 115 put h 6 `15784041429090275239` 116 put h 7 `5167115440072839076` 117 end 118 119 note upper-case Sigma0{512}(x) = ROTR^28 ^ ROTR^34 ^ ROTR^39 (FIPS 180-4 section 4.1.3, (4.10)) 120 fn cs384bs0 x ulong to ulong 121 r = or shr x 28 shl x 36 122 r = xor r or shr x 34 shl x 30 123 r = xor r or shr x 39 shl x 25 124 ret r 125 end 126 127 note upper-case Sigma1{512}(x) = ROTR^14 ^ ROTR^18 ^ ROTR^41 (section 4.1.3, (4.11)) 128 fn cs384bs1 x ulong to ulong 129 r = or shr x 14 shl x 50 130 r = xor r or shr x 18 shl x 46 131 r = xor r or shr x 41 shl x 23 132 ret r 133 end 134 135 note lower-case sigma0{512}(x) = ROTR^1 ^ ROTR^8 ^ SHR^7 (section 4.1.3, (4.12)) 136 fn cs384ss0 x ulong to ulong 137 r = or shr x 1 shl x 63 138 r = xor r or shr x 8 shl x 56 139 r = xor r shr x 7 140 ret r 141 end 142 143 note lower-case sigma1{512}(x) = ROTR^19 ^ ROTR^61 ^ SHR^6 (section 4.1.3, (4.13)) 144 fn cs384ss1 x ulong to ulong 145 r = or shr x 19 shl x 45 146 r = xor r or shr x 61 shl x 3 147 r = xor r shr x 6 148 ret r 149 end 150 151 note Ch(x,y,z) = (x and y) xor (not x and z), written as z xor (x and (y xor z)) (section 4.1.3, (4.8)) 152 fn cs384ch x ulong y ulong z ulong to ulong 153 ret xor z and x xor y z 154 end 155 156 note Maj(x,y,z) = (x and y) xor (x and z) xor (y and z), written as (x and y) or (z and (x or y)) 157 note (section 4.1.3, (4.9)) 158 fn cs384mj x ulong y ulong z ulong to ulong 159 ret or and x y and z or x y 160 end 161 162 note big-endian 64-bit word of the 8 bytes at m[q..q+8) (section 3.1 item 3) 163 fn cs384bem m view uchar 65536 q ulong to ulong 164 v = ulong 0 165 for j ulong 8 166 v = or shl v 8 ulong get m add q j 167 end 168 ret v 169 end 170 171 note the same for the 256-byte padding buffer 172 fn cs384bep p view uchar 256 q ulong to ulong 173 v = ulong 0 174 for j ulong 8 175 v = or shl v 8 ulong get p add q j 176 end 177 ret v 178 end 179 180 note the same for the 64-byte prefix 181 fn cs384bex p view uchar 64 q ulong to ulong 182 v = ulong 0 183 for j ulong 8 184 v = or shl v 8 ulong get p add q j 185 end 186 ret v 187 end 188 189 note message block M(i) at byte o of the stream p[0..pl) || m into w[0..16) (section 6.4.2 step 1, 190 note t = 0..15). pl is 0 or 64 and o is a multiple of 128, so every word lies wholly in p or in m. 191 fn cs384ldm p view uchar 64 pl ulong m view uchar 65536 o ulong w edit ulong 80 to void 192 for i ulong 16 193 q = add o mul i 8 194 if lt q pl 195 put w i cs384bex p q 196 else 197 put w i cs384bem m sub q pl 198 end 199 end 200 end 201 202 note the block at byte o of the padding buffer pb into w[0..16) 203 fn cs384ldp pb view uchar 256 o ulong w edit ulong 80 to void 204 for i ulong 16 205 put w i cs384bep pb add o mul i 8 206 end 207 end 208 209 note one SHA-512 compression (section 6.4.2 steps 1-4); w[0..16) holds the block on entry 210 fn cs384blk h edit ulong 8 w edit ulong 80 k view ulong 80 to void 211 for i ulong 64 212 t = add i 16 213 v = cs384ss1 get w sub t 2 214 v = add v get w sub t 7 215 v = add v cs384ss0 get w sub t 15 216 v = add v get w i 217 put w t v 218 end 219 a = get h 0 220 b = get h 1 221 c = get h 2 222 d = get h 3 223 e = get h 4 224 f = get h 5 225 g = get h 6 226 x = get h 7 227 for i ulong 80 228 t = add x cs384bs1 e 229 t = add t cs384ch e f g 230 t = add t get k i 231 t = add t get w i 232 u = add cs384bs0 a cs384mj a b c 233 x = g 234 g = f 235 f = e 236 e = add d t 237 d = c 238 c = b 239 b = a 240 a = add t u 241 end 242 put h 0 add get h 0 a 243 put h 1 add get h 1 b 244 put h 2 add get h 2 c 245 put h 3 add get h 3 d 246 put h 4 add get h 4 e 247 put h 5 add get h 5 f 248 put h 6 add get h 6 g 249 put h 7 add get h 7 x 250 end 251 252 note Padding (section 5.1.2) of the stream p[0..pl) || m, tot bytes long, whose bytes from off on 253 note (fewer than 128) are not yet compressed: they go to pb[0..r), then one 1 bit (byte 128), zero bytes 254 note up to 112 mod 128, then l = 8 * tot as a 128-bit big-endian integer. pb must be all zero on entry. 255 note Returns the padded length, 128 when r < 112, else 256. The upper 64 bits of l are always 0 here 256 note because tot <= 65600. 257 fn cs384pad p view uchar 64 pl ulong m view uchar 65536 off ulong tot ulong pb edit uchar 256 to ulong 258 r = sub tot off 259 for i ulong r 260 q = add off i 261 if lt q pl 262 put pb i get p q 263 else 264 put pb i get m sub q pl 265 end 266 end 267 put pb r 128 268 e = ulong 128 269 if ge r 112 270 e = 256 271 end 272 cs384len pb e mul tot 8 273 ret e 274 end 275 276 note the low 64 bits of the 128-bit big-endian length field ending at pb[e-1] 277 fn cs384len pb edit uchar 256 e ulong bits ulong to void 278 for i ulong 8 279 y = sub sub e 1 i 280 put pb y uchar and shr bits mul i 8 255 281 end 282 end 283 284 note H(N) as the 64-byte big-endian digest (section 6.4.2, final hash value) 285 fn cs384out h view ulong 8 o edit uchar 64 to void 286 for i ulong 8 287 v = get h i 288 for j ulong 8 289 put o add mul i 8 j uchar and shr v mul sub 7 j 8 255 290 end 291 end 292 end 293 294 note SHA-512 of the stream p[0..pl) || m[0..n), pl 0 or 64 (else trap 3), n <= 65536 (else trap 3), 295 note digest to o[0..64). 296 fn cs384core p view uchar 64 pl ulong m view uchar 65536 n ulong o edit uchar 64 to void 297 if gt n 65536 298 trap 3 299 end 300 if ne pl 0 301 if ne pl 64 302 trap 3 303 end 304 end 305 h = new ulong 8 0 306 w = new ulong 80 0 307 k = new ulong 80 0 308 pb = new uchar 256 0 309 cs384k k 310 cs384iv h 311 tot = add pl n 312 off = ulong 0 313 while le add off 128 tot bound 514 314 cs384ldm p pl m off w 315 cs384blk h w k 316 off = add off 128 317 end 318 e = cs384pad p pl m off tot pb 319 cs384ldp pb 0 w 320 cs384blk h w k 321 if eq e 256 322 cs384ldp pb 128 w 323 cs384blk h w k 324 end 325 cs384out h o 326 end 327 328 note SHA-512(m[0..n)), n <= 65536 (else trap 3), digest to o[0..64) 329 fn cs384hash m view uchar 65536 n ulong o edit uchar 64 to void 330 z = new uchar 64 0 331 cs384core z 0 m n o 332 end 333