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/seed/qualification/om2/baseline/sha256-main.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 / seed / qualification / om2 / baseline / sha256-main.om` 70 lines ยท 1638 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note OM-2 qualification driver for the CURRENT consumer om/sha256/sha256.om (baseline `acb3f15`). 3 note The gate concatenates this file with om/sha256/sha256.om into one program-mode unit. It is 4 note test scaffolding, not a SHA implementation: every hash operation is the consumer's omsha. 5 note stdin the message, read to end of file 6 note arg 1 optional piece size 1..4096 (default 4096): each read asks for at most that many bytes 7 note and every byte read is absorbed with op 1, so the split points are exercised 8 note stdout the digest as 64 lowercase hex digits and a newline; exit 0 9 note Exit 90: bad argument; 91: read error; 92: short stdout write. 10 note digest byte j: the consumer packs the 32 digest bytes little endian into w[0..4) 11 fn dbyte w view ulong 64 j ulong to ulong 12 v = get w div j 8 13 ret and shr v mul rem j 8 8 255 14 end 15 text hexdig "`0123456789abcdef`" 16 fn piece to ulong 17 if eq argcnt 1 18 ret 4096 19 end 20 a = new uchar 8 0 21 r = argread 1 a 0 8 22 if or lt r 1 gt r 4 23 exit 90 24 end 25 v = ulong 0 26 for i ulong ulong r 27 d = get a i 28 if or lt d 48 gt d 57 29 exit 90 30 end 31 v = add mul v 10 ulong sub d 48 32 end 33 if or eq v 0 gt v 4096 34 exit 90 35 end 36 ret v 37 end 38 fn main to int 39 c = new uchar 104 0 40 b = new uchar 4096 0 41 w = new ulong 64 0 42 b8 = new ulong 512 0 43 o = new uchar 65 10 44 k = piece 45 omsha c b 0 0 w b8 46 go = true 47 while go 48 r = read 0 b 0 k 49 if lt r 0 50 ret 91 51 end 52 if eq r 0 53 go = false 54 else 55 omsha c b ulong r 1 w b8 56 end 57 end 58 omsha c b 0 2 w b8 59 for j ulong 32 60 x = dbyte w j 61 p = mul j 2 62 put o p get hexdig shr x 4 63 put o add p 1 get hexdig and x 15 64 end 65 r = write 1 o 0 65 66 if ne r 65 67 ret 92 68 end 69 ret 0 70 end