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 / om / tls / test / fips / entropy.om

63 lines · 1269 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note entropy.om: sample collector for the NIST SP 800-90B entropy assessment (test/fips/run.sh,
3note entropy.sh). Writes N bytes from the `random` word (Linux getrandom, flags 0 = blocking until
4note the kernel pool is ready) to stdout, one 8-bit sample per byte. usage: entropy N (1 .. 16777216).
5note What this grades: the Linux kernel's getrandom output, which the kernel has already
6note conditioned (ChaCha20 CRNG). It is not an Omega noise source; om/tls has none of its own.
7note Exit 0 ok; 2 usage; 3 getrandom error; 4 write error.
8
9global buf uchar 65536
10global ab uchar 16
11
12fn main to int
13if ne argcnt 2
14ret 2
15end
16k = argread 1 ab 0 16
17if le k 0
18ret 2
19end
20if gt k 8
21ret 2
22end
23n = ulong 0
24for i ulong ulong k
25c = ulong get ab i
26if lt c 48
27ret 2
28end
29if gt c 57
30ret 2
31end
32n = add mul n 10 sub c 48
33end
34if eq n 0
35ret 2
36end
37if gt n 16777216
38ret 2
39end
40note every pass writes at least one byte or returns, so n <= 16777216 passes suffice
41done = ulong 0
42while lt done n bound 999999
43m = sub n done
44if gt m 65536
45m = 65536
46end
47r = random buf 0 m 0
48if le r 0
49ret 3
50end
51got = ulong r
52o = ulong 0
53while lt o got bound 999999
54w = write 1 buf o sub got o
55if le w 0
56ret 4
57end
58o = add o ulong w
59end
60done = add done got
61end
62ret 0
63end