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 / protocol / omnet / om / argon2 / test / driver.om

203 lines · 3533 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note driver.om: program-mode test driver for om/argon2 (concatenated after om/blake2b/blake2b.om,
3note om/argon2/argon2.om and om/argon2/argon2pool.om).
4note
5note Reads one case per line from stdin and writes one line per case on stdout:
6note T M P TL PW SALT KEY AD\n Argon2i (a2hash): decimal t, m KiB, p, tag length, then hex
7note password, salt, secret K and associated data X ("-" = empty);
8note output: 2*TL lowercase hex digits, or "e1" when a2hash returns 1
9note tka SEC\n TKA disablement value (a2tka) of the hex secret SEC ("-" = empty)
10note output: 64 lowercase hex digits
11note Decimals have at most 7 digits; a hex field is at most 65536 bytes (SEC at most 1024) and all
12note four together must fit the 65496-byte input. Exit 0 at end of input, 2 on a malformed line.
13
14global ib uchar 65536
15global ist ulong 2
16
17note next input byte, -1 at end of input
18fn getc to int
19if eq get ist 0 get ist 1
20r = read 0 ib 0 65536
21if le r 0
22ret -1
23end
24put ist 0 0
25put ist 1 ulong r
26end
27p = get ist 0
28put ist 0 add p 1
29ret int get ib p
30end
31
32fn hexv c int to int
33if and ge c 48 le c 57
34ret sub c 48
35end
36if and ge c 97 le c 102
37ret sub c 87
38end
39if and ge c 65 le c 70
40ret sub c 55
41end
42ret -1
43end
44
45fn hexd v ulong to uchar
46if lt v 10
47ret uchar add v 48
48end
49ret uchar add v 87
50end
51
52note a hex field into a[at ..) of at most cap bytes, ended by the byte sep; its length, or -1
53fn rdhex a edit uchar 65536 at ulong cap ulong sep int to long
54c = getc
55if eq c 45
56if eq getc sep
57ret 0
58end
59ret -1
60end
61t = ulong 0
62while ne c sep bound 999999
63if ge t cap
64ret -1
65end
66hi = hexv c
67lo = hexv getc
68if or lt hi 0 lt lo 0
69ret -1
70end
71put a add at t uchar add mul hi 16 lo
72t = add t 1
73c = getc
74end
75if eq t 0
76ret -1
77end
78ret long t
79end
80
81note decimal ended by a space, first byte c already read; -1 when malformed
82fn rddec c int to long
83t = long 0
84k = ulong 0
85d = c
86while ne d 32 bound 16
87if or lt d 48 gt d 57
88ret -1
89end
90if ge k 7
91ret -1
92end
93t = add mul t 10 long sub d 48
94k = add k 1
95d = getc
96end
97if eq k 0
98ret -1
99end
100ret t
101end
102
103note o[0..n) as lowercase hex and a newline
104fn emit o view uchar 1024 n ulong to void
105h = new uchar 2049 0
106for i ulong n
107v = ulong get o i
108put h mul i 2 hexd shr v 4
109put h add mul i 2 1 hexd and v 15
110end
111put h mul n 2 10
112r = write 1 h 0 add mul n 2 1
113if ne r long add mul n 2 1
114trap 1
115end
116end
117
118note "tka SEC" after the t: 0 done, 2 malformed
119fn tkaline to int
120if ne getc 107
121ret 2
122end
123if ne getc 97
124ret 2
125end
126if ne getc 32
127ret 2
128end
129b = new uchar 65536 0
130n = rdhex b 0 1024 10
131if lt n 0
132ret 2
133end
134s = new uchar 1024 0
135for i ulong ulong n
136put s i get b i
137end
138o = new uchar 32 0
139a2tka s ulong n o
140e = new uchar 1024 0
141for i ulong 32
142put e i get o i
143end
144emit e 32
145ret 0
146end
147
148note "T M P TL PW SALT KEY AD" with the first byte c read: 0 done, 2 malformed
149fn hashline c int to int
150prm = new ulong 8 0
151v = rddec c
152for i ulong 4
153if lt v 0
154ret 2
155end
156put prm i ulong v
157if lt i 3
158v = rddec getc
159end
160end
161inp = new uchar 65536 0
162at = ulong 0
163for f ulong 4
164sep = int 32
165if eq f 3
166sep = 10
167end
168n = rdhex inp at sub 65496 at sep
169if lt n 0
170ret 2
171end
172put prm add 4 f ulong n
173at = add at ulong n
174end
175out = new uchar 1024 0
176e = a2hash prm inp out
177if ne e 0
178put out 0 uchar add e 224
179emit out 1
180ret 0
181end
182emit out get prm 3
183ret 0
184end
185
186fn main to int
187while true bound 999999
188c = getc
189if eq c -1
190ret 0
191end
192r = int 0
193if eq c 116
194r = tkaline
195else
196r = hashline c
197end
198if ne r 0
199ret r
200end
201end
202ret 2
203end