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 / src / source-aware / vendor / sha256.om

175 lines · 3200 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-or-later
2note Exact native TRN1 SHA256 functions; see NOTICE. Buffer declarations bounded for this caller.
3global Buf uchar 8192
4global H uint 8
5global Vv uint 8
6global W uint 64
7global K uint 64
8global Hb uchar 64
9global Hs ulong 2
10global Hash uchar 32
11fn rotate x uint n uint to uint
12ret or shr x n shl x sub 32 n
13end
14
15fn round i ulong to void
16e = get Vv 4
17a = get Vv 0
18s = xor xor rotate e 6 rotate e 11 rotate e 25
19c = xor and e get Vv 5 and not e get Vv 6
20t = add add get Vv 7 s add c add get K i get W i
21s = xor xor rotate a 2 rotate a 13 rotate a 22
22c = and a get Vv 1
23c = xor c and a get Vv 2
24c = xor c and get Vv 1 get Vv 2
25u = add s c
26put Vv 7 get Vv 6
27put Vv 6 get Vv 5
28put Vv 5 e
29put Vv 4 add get Vv 3 t
30put Vv 3 get Vv 2
31put Vv 2 get Vv 1
32put Vv 1 a
33put Vv 0 add t u
34end
35
36fn block to void
37for i ulong 16
38x = uint 0
39for j ulong 4
40x = or shl x 8 uint get Hb add mul i 4 j
41end
42put W i x
43end
44for j ulong 48
45i = add j 16
46x = get W sub i 15
47y = get W sub i 2
48s = xor xor rotate x 7 rotate x 18 shr x 3
49t = xor xor rotate y 17 rotate y 19 shr y 10
50put W i add add get W sub i 16 s add get W sub i 7 t
51end
52for i ulong 8
53put Vv i get H i
54end
55for i ulong 64
56round i
57end
58for i ulong 8
59put H i add get H i get Vv i
60end
61end
62
63fn hinit to void
64put H 0 1779033703
65put H 1 3144134277
66put H 2 1013904242
67put H 3 2773480762
68put H 4 1359893119
69put H 5 2600822924
70put H 6 528734635
71put H 7 1541459225
72put Hs 0 0
73put Hs 1 0
74end
75
76fn hbyte c uchar to void
77p = get Hs 0
78put Hb p c
79p = add p 1
80put Hs 1 add get Hs 1 1
81if eq p 64
82block
83p = 0
84end
85put Hs 0 p
86end
87
88fn update off ulong count ulong to void
89for i ulong count
90hbyte get Buf add off i
91end
92end
93
94fn finish to void
95bits = mul get Hs 1 8
96hbyte 128
97while ne get Hs 0 56
98hbyte 0
99end
100for i ulong 8
101hbyte uchar and shr bits mul sub 7 i 8 255
102end
103for i ulong 32
104x = get H div i 4
105put Hash i uchar and shr x uint mul sub 3 rem i 4 8 255
106end
107end
108
109fn constants to void
110put K 0 1116352408
111put K 1 1899447441
112put K 2 3049323471
113put K 3 3921009573
114put K 4 961987163
115put K 5 1508970993
116put K 6 2453635748
117put K 7 2870763221
118put K 8 3624381080
119put K 9 310598401
120put K 10 607225278
121put K 11 1426881987
122put K 12 1925078388
123put K 13 2162078206
124put K 14 2614888103
125put K 15 3248222580
126put K 16 3835390401
127put K 17 4022224774
128put K 18 264347078
129put K 19 604807628
130put K 20 770255983
131put K 21 1249150122
132put K 22 1555081692
133put K 23 1996064986
134put K 24 2554220882
135put K 25 2821834349
136put K 26 2952996808
137put K 27 3210313671
138put K 28 3336571891
139put K 29 3584528711
140put K 30 113926993
141put K 31 338241895
142put K 32 666307205
143put K 33 773529912
144put K 34 1294757372
145put K 35 1396182291
146put K 36 1695183700
147put K 37 1986661051
148put K 38 2177026350
149put K 39 2456956037
150put K 40 2730485921
151put K 41 2820302411
152put K 42 3259730800
153put K 43 3345764771
154put K 44 3516065817
155put K 45 3600352804
156put K 46 4094571909
157put K 47 275423344
158put K 48 430227734
159put K 49 506948616
160put K 50 659060556
161put K 51 883997877
162put K 52 958139571
163put K 53 1322822218
164put K 54 1537002063
165put K 55 1747873779
166put K 56 1955562222
167put K 57 2024104815
168put K 58 2227730452
169put K 59 2361852424
170put K 60 2428436474
171put K 61 2756734187
172put K 62 3204031479
173put K 63 3329325298
174end
175