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 / gpu / runtime / zsha.om

81 lines · 1724 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/runtime/zsha.om: streaming SHA-256 over seed/ng/sha256.om's block buffer sh_dat, so a stream of any
3note length hashes (sh_all alone stops at len sh_dat). Composed after seed/ng/sha256.om (OM-2 program mode) by
4note gpu/runtime/inventory.om and gpu/runtime/gate.om. zbeg, then zbyte / zfd any number of times, then zend
5note leaves the digest in sh_dig. zs_n 0 is the bytes held in sh_dat, zs_n 1 the stream length.
6global zs_n ulong 2
7fn zbeg to void
8sh_init
9for j ulong 8
10put sh_h j get sh_k add j 64
11end
12put zs_n 0 0
13put zs_n 1 0
14end
15note hash every whole block held, keep the tail at the front of sh_dat
16fn zdrain to void
17f = get zs_n 0
18nb = div f 64
19for b ulong nb bound 9223372036854775807
20sh_blk 0 mul b 64
21end
22o = mul nb 64
23for j ulong sub f o bound 64
24put sh_dat j get sh_dat add o j
25end
26put zs_n 0 sub f o
27end
28fn zbyte c ulong to void
29f = get zs_n 0
30put sh_dat f uchar c
31put zs_n 0 add f 1
32put zs_n 1 add get zs_n 1 1
33if ge add f 1 len sh_dat
34zdrain
35end
36end
37note hash everything readable from fd into the stream; false on a read error (fd stays open)
38fn zfd fd int to bool
39while true bound 9223372036854775807
40f = get zs_n 0
41if ge f len sh_dat
42zdrain
43f = get zs_n 0
44end
45x = read fd sh_dat f sub len sh_dat f
46if lt x 0
47ret false
48end
49if eq x 0
50ret true
51end
52put zs_n 0 add f ulong x
53put zs_n 1 add get zs_n 1 ulong x
54end
55ret true
56end
57fn zend to void
58zdrain
59r = get zs_n 0
60n = get zs_n 1
61for j ulong 128
62put sh_pad j 0
63end
64for j ulong r bound 64
65put sh_pad j get sh_dat j
66end
67put sh_pad r 128
68e = ulong 64
69if ge r 56
70e = 128
71end
72bits = mul n 8
73for j ulong 8
74put sh_pad sub sub e 1 j uchar and shr bits mul j 8 255
75end
76sh_blk 1 0
77if eq e 128
78sh_blk 1 64
79end
80sh_out
81end