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