interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / qualification / om2 / baseline / sha256-main.om

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