interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / sha512

3635cf7 fix(blake2s,sha512): strict mutant detection and third-party notices AIEN committed 2026-10-25
..
test/
README.md10231
sha512.om8985

README.md

om/sha512: SHA-512 in Omega

SHA-512 as defined in FIPS 180-4, section 6.4, written in Omega (.om). The library takes one message of up to 65536 bytes and writes its 64-byte digest. It exists for Ed25519, which needs SHA-512(R || A || M) (RFC 8032, section 5.1.7).

sha512.om is a library unit: it holds only functions, with no fn main and no globals. Every function name starts with s512. To use it, concatenate it before the program that calls it.

API

fn s512hash m view uchar 65536 n ulong o edit uchar 64 to void
fn s512pre p view uchar 64 m view uchar 65536 n ulong o edit uchar 64 to void
  • s512hash writes SHA-512(m[0..n)) to o[0..64).
  • s512pre writes SHA-512(p[0..64) || m[0..n)) to o[0..64). For Ed25519, p holds R || A, so the caller does not have to copy M.
  • If n > 65536, both functions trap 3 (in program mode the process exits 103). Bytes of m past n are never read.
  • The digest is the usual big-endian byte string, H0 first (FIPS 180-4, section 6.4.2).
  • Omega refuses to pass the same array as two arguments of one call (error 19), so m and o are always separate storage.
  • Globals cannot be passed to functions (error 19). A program-mode caller copies its message into a local array first, such as buf = new uchar 65536 0 in the function's outermost block. The pinned omc accepts that 65536-element local even though OMEGESE.md section 3 lists new lengths as 1..64. omc's own limit is 4 MiB of local arrays (OMEGESE.md section 9.4).

The other functions are internal: compression, padding, and big-endian loads. The constants come straight from FIPS 180-4: K (section 4.2.3), H(0) (section 5.3.5), Ch, Maj, Σ0, Σ1, σ0 and σ1 (section 4.1.3, equations 4.8-4.13), and padding (section 5.1.2). Words are ulong, and unsigned arithmetic wraps mod 2^64. Omega has no rotate word, so ROTR^r(x) is written (x >> r) | (x << (64 - r)) (section 3.2).

In the source, K and H(0) are decimal literals, because Omega has no hex literals. They were checked against the hex tables in FIPS 180-4 sections 4.2.3 and 5.3.5: all 80 K words matched the extracted table, and so did the cube-root and square-root derivation. Changing one bit of K[0] makes every NIST example fail (see "mutant-constant" below).

Tests

sh om/sha512/test/run.sh "$(tools/omc.sh)"

run.sh concatenates sha512.om with test/driver.om, builds build/test/sha512/driver, and feeds it vector records on stdin. The driver's record format is described in its header. The script exits 0 only if every vector passes and every negative check is rejected.

CheckRecordsSource
nist-examples10vectors/nist-examples.txt: 'abc' and the 896-bit two-block message from NIST SHA512.pdf, and SHA-512 items #1-#8 from NIST SHA2_Additional.pdf (0 bytes; 111, 112, 113 and 122 zero bytes; 1000 zero bytes; 1000 'A'; 1005 'U'). Items #9-#12 are 10^6 bytes or more, beyond the capacity.
cavp-short129vectors/SHA512ShortMsg.rsp, unmodified (0 to 1024 bits)
cavp-long128vectors/SHA512LongMsg.rsp, unmodified (1816 to 102400 bits, all within the capacity)
cavp-monte100vectors/SHA512Monte.rsp, unmodified: the SHAVS Monte Carlo chain, 100 checkpoints of 1000 hashes each
oracle-static52vectors/oracle.txt, generated by gen_vectors.py static with python3 hashlib.sha512 as the oracle. It covers the 448-bit "abcdbcdec…nopq" message, lengths 0, 1, 55, 56, 63, 64, 110-113, 119, 120, 126-129, 239-241, 255-257 and 1023-1025, all-0x00 and all-0xff messages of 111/112/127/128 bytes, n = 65536, and 17 s512pre records
hashlib-diff1125Generated at test time: every length 0..1100, plus 65536, 65535, 65519, 65408, 65407, 65520, 32768, 32767 and 16 random lengths up to 65536. Random bytes from random.Random(seed), oracle python3 hashlib.sha512
hashlib-pre313Generated at test time: s512pre with every length 0..300, plus 65536, 65535, 65472, 65471 and 8 random lengths

The seed defaults to 1 and can be changed with S512_SEED. Without python3 the two hashlib checks are skipped and a NOTE line is printed. The committed vectors still run.

Negative checks (each must be detected):

  • mutant-expected: one hex digit of the expected 'abc' digest is changed. Must produce exactly 1 failure.
  • mutant-constant: K[0] in a copy of the library is changed by one. Must produce failures on all 10 NIST examples.
  • malformed-record: a record with an odd number of hex digits. Must be refused as BAD and not hashed.
  • over-capacity: test/trap.om calls s512hash with n = 65537. Must exit 103 (trap 3).

The first three count as detected only when the driver finished normally and reported the difference. That means exit status exactly 1, which is the driver's own "a check failed" return, and a complete last line sha512 driver: C checks, F failed with the expected C (all records) and F > 0. A trap (exit 100+N), a signal (128+N), a launch failure (126/127), exit 0 or a truncated summary all fail the run. A passing check likewise needs exit 0 and a complete ... 0 failed line. Exit statuses are taken directly from the driver, never through a pipeline. This was checked on 2026-10-25 by temporarily replacing the K[0] mutant with one that traps 3 on every call (put k 0 get k add 80 get k 1). run.sh reported FAIL mutant-constant: expected exit 1 and "sha512 driver: 10 checks, 10 failed", got exit 103, ended with sha512: FAIL and exited 1. The real mutant was then restored.

Evidence (2026-10-25)

  • omc: seed-born from omega-mv acb3f15c, sha256 734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61
  • sha512.om sha256 069a54b75484221bc7dbacfbea744ca9002c295f4f34f2c3905b0776450e3ce2 (332 lines)
  • driver binary sha256 a45c2e051c1cd106490c744bd42ec7884d3c01b131f0c0dbbbbe5349d56a2670
  • sh om/sha512/test/run.sh "$(tools/omc.sh)": every check above PASS, ending with sha512: PASS (1857 vector checks), exit 0. All four negative checks were detected (mutant-constant: 10 of 10 failed). The run takes about 0.6 s on an arm64 Linux host.
  • S512_SEED = 2, 3, 4 and 5 each passed 1125 + 313 differential records.
  • With python3 removed from PATH: 419 vector checks PASS, the NOTE was printed, and all negative checks were rejected.

Vector sources (fetched 2026-10-25)

Third-party material and notices

copied materialowner and termsnotice file
vectors/SHA512ShortMsg.rsp, SHA512LongMsg.rsp, SHA512Monte.rsp, byte-for-byte copies from the CAVP zip aboveNIST, a US Government agency. Under 17 U.S.C. §105, works of NIST employees are not subject to copyright protection in the United States and may be subject to foreign copyright. NIST grants a worldwide royalty-free right to copy, modify and distribute, asks that NIST be acknowledged, and provides the data "AS IS" (https://www.nist.gov/open/license, "Fair Use of Other NIST Data/Works")vectors/NIST.NOTICE
digests and message descriptions in vectors/nist-examples.txt, transcribed from NIST SHA512.pdf and SHA2_Additional.pdf (modified on 2026-10-25: values copied into the record format, the PDF layout and intermediate values dropped)NIST, same termsvectors/NIST.NOTICE, which also records the change, as NIST's terms ask

vectors/NIST.NOTICE quotes NIST's recommended statement for non-SRD data/works verbatim from https://www.nist.gov/open/license (fetched 2026-10-25), names the source URLs, and states what was changed. The header of nist-examples.txt points to it. The .rsp files carry no notice of their own and are kept unmodified.

FIPS 180-4 (also a NIST work) is cited by section only. Its K and H(0) values appear in sha512.om as decimal constants, and the standard defines them as cube- and square-root fractions. The 448-bit message in oracle.txt is the standard's sample text. No other third-party material is included: oracle.txt and the differential corpus are this unit's own output, with python3 hashlib used only as the reference.

Limits

  • Messages are at most 65536 bytes (CAP). For s512pre that is 64 + 65536 bytes. There is no streaming (init/update/final) interface.
  • The code is NOT constant-time audited. Omega gives no timing guarantee, and nothing here was measured for timing. SHA-512 has no secret-dependent branches on its input by design, but this implementation's machine code was not inspected for that property.
  • Each call recomputes the K table (80 stores) and uses about 1.7 KiB of stack for local arrays.
  • Only tested on the host CPU (arm64 Linux, program mode). Function-mode / IR-mode use was not exercised.