Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omnet/blob/main/om/blake2b/README.md # omnet aien-dev/omnet Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omnet / om / blake2b / README.md` 183 lines · 11373 bytes Raw Blame History Rendered 1 # om/blake2b: BLAKE2b in Omega 2 3 BLAKE2b ([RFC 7693](https://www.rfc-editor.org/rfc/rfc7693)), written in Omega (`.om`) and compiled 4 by the pinned seed-born `omc`. It supports unkeyed and keyed hashing, keys of 0..64 bytes, and digest 5 lengths of 1..64 bytes. BLAKE2b-512 is the case with no key and a 64-byte digest. It is the hash 6 inside Argon2 (`om/argon2`). Python appears only in the tests, as an oracle. No other language is on 7 the implementation path. 8 9 ## Files 10 11 | Path | Role | 12 |---|---| 13 | `blake2b.om` | Library unit. It has functions only, no `main` and no globals, and every name starts with `b2b`. | 14 | `test/driver.om` | Program-mode test driver. It is concatenated after the library. | 15 | `test/run.sh` | Test suite. Usage: `sh om/blake2b/test/run.sh OMC`. | 16 | `test/oracle.py` | Vector generator built on python3 `hashlib.blake2b`. It is used only for tests. | 17 | `test/vectors/rfc7693.txt` | The RFC 7693 Appendix A digest of "abc" and the Appendix E `blake2b_res` grand hash. | 18 | `test/vectors/rfc7693.NOTICE` | RFC 7693's Copyright Notice section, verbatim, with a note on what was copied. | 19 | `test/vectors/blake2b-kat.txt` | The official BLAKE2 KAT file, copied verbatim. | 20 | `test/vectors/blake2b-kat.LICENSE` | The BLAKE2 repository's `COPYING` (CC0 1.0), verbatim. | 21 | `test/vectors/boundary.txt` | 60 block-edge and length cases, with digests from `oracle.py boundary`. | 22 23 ## API 24 25 ``` 26 fn b2bhash m view uchar 65536 n ulong k view uchar 64 kn ulong outn ulong o edit uchar 64 to void 27 ``` 28 29 | Parameter | Meaning | 30 |---|---| 31 | `m`, `n` | The message. Only `m[0..n)` is read. `n` is 0..65536. | 32 | `k`, `kn` | The key. Only `k[0..kn)` is read. `kn` is 0..64, and 0 means unkeyed. | 33 | `outn` | Digest length in bytes, 1..64. | 34 | `o` | Receives the digest in `o[0..outn)`. `o[outn..64)` is set to 0. | 35 36 If `n`, `kn` or `outn` is out of range, the call traps 3 (program exit 103) before it writes `o`. 37 This was checked with ad hoc programs (the library plus a `main` calling `b2bhash`): `n=65537`, 38 `kn=65`, `outn=0` and `outn=65` each exit 103; `n=65536, kn=64, outn=64` exits 0. 39 40 The other functions are internal helpers. All of them take the 64-word working array `w`: 41 42 | Function | Purpose | 43 |---|---| 44 | `b2binit` | Sets up the IV and SIGMA. | 45 | `b2bstart` | Sets h and the parameter block. | 46 | `b2bmw` | Selects the message word. | 47 | `b2bg` | The G function. | 48 | `b2bround` | One round. | 49 | `b2bcomp` | The compression function F. | 50 | `b2bbyte` | Returns one byte of the key-block‖message stream. | 51 | `b2bword` | Reads one little-endian 64-bit word of that stream. | 52 | `b2bload` | Loads a block. | 53 | `b2bout` | Writes the digest bytes. | 54 55 ## Standards followed 56 57 These are the sections of RFC 7693: 58 59 | Section | What it defines | How the code uses it | 60 |---|---|---| 61 | 2.1 | BLAKE2b parameters | w=64, r=12, R1..R4 = 32, 24, 16, 63, block 128 bytes. | 62 | 2.6 | IV | The SHA-512 IV, quoted in hex in a `note` beside the decimal values. | 63 | 2.7 | SIGMA | Each row is packed as sixteen 4-bit indexes and quoted in a `note`. Rounds 10 and 11 use rows 0 and 1 (`i mod 10`). | 64 | 3.1 | G | | 65 | 3.2 | F | | 66 | 3.3 | Parameter block and padding | `h[0] ^= 0x01010000 ^ (kk << 8) ^ nn`. The key, zero-padded to 128 bytes, is the first block. The last block is zero-padded and carries `t` = total stream bytes and `f0 = 0xFFFFFFFFFFFFFFFF`. An empty unkeyed message is one zero block with `t = 0`. | 67 68 64-bit words are kept in `ulong` cells; Omega `ulong` addition and left shift wrap modulo 2^64, which 69 is the RFC's arithmetic. The 128-bit counter's high half is always 0, because a stream is at most 70 65536 + 128 bytes. 71 72 ## Test driver protocol 73 74 - `driver` reads one case per line from stdin, in the form `OUTN KEY MSG`. `OUTN` is decimal 1..64. 75 `KEY` and `MSG` are hex (either case, even digit count), or `-` for empty. `KEY` holds at most 64 76 bytes and `MSG` at most 65536 bytes. For each case the driver writes `2*OUTN` lowercase hex digits 77 and a newline. It exits 0 at end of input and 2 on a malformed line. 78 - `driver selftest` runs the RFC 7693 Appendix E BLAKE2b self-test. That test covers digest lengths 79 {20, 32, 48, 64} × input lengths {0, 3, 128, 129, 255, 1024}, unkeyed and keyed, with inputs and 80 keys from `selftest_seq`. The driver prints the grand hash (BLAKE2b with a 32-byte digest of all 48 81 digests concatenated) and exits 0 only if it equals the RFC's `blake2b_res`. 82 83 `run.sh` does the following: 84 85 1. Builds `build/test/blake2b/driver`. 86 2. Converts each vector source to case lines with awk and compares the driver output with `cmp`. 87 3. Runs the self-test. 88 4. If python3 is present, generates the differential corpus at test time. If it is absent, the suite 89 prints `NOTE ... NOT_RUN` and still checks the static vectors. 90 5. Runs five mutants: 91 - one flipped expected digest digit; 92 - IV[0] changed by 1; 93 - the final-block flag removed (`b2bcomp w 1` → `b2bcomp w 0`); 94 - rotation R4 changed from 63 to 62; 95 - 10 rounds instead of 12. 96 97 Each source mutant is rebuilt and run on the RFC case line plus the KAT, and through the 98 self-test. It counts as detected only when every run ended normally and at least one result 99 differs from the expected one. A normal end is either exit 0 with one output line per case, or, 100 for the self-test, its documented mismatch outcome: exit 1 with a 64-digit grand hash. A trap 101 (exit 100+N), a signal, a launch failure or short output makes the mutant FAIL. The runs are 102 not piped, so the exit status is kept. The same rule applies to the expected-digit mutant. 103 Checked by adding a throwaway mutant that traps on every call (`if gt outn 64` → 104 `if gt outn 1`). The suite printed `ran abnormally: cases abnormal (exit 103), selftest abnormal 105 (selftest exit 103, output '') FAIL` and exited 1. The throwaway mutant was then removed. 106 107 `B2B_SEED` sets the differential seed. The default is 7693. 108 109 ## Vector sources 110 111 | Source | Where it comes from | 112 |---|---| 113 | RFC 7693 Appendix A (`"abc"`) and Appendix E (`blake2b_res`) | https://www.rfc-editor.org/rfc/rfc7693.txt, fetched 2026-10-25. The text file's sha256 is ``c943754888364fe29bbd0bb3c71c6658ef392371497eaa4a9d9dde015b0721e5``. | 114 | BLAKE2 KAT, 256 keyed cases | https://github.com/BLAKE2/BLAKE2/blob/master/testvectors/blake2b-kat.txt at commit ``ed1974ea83433eba7b2d95c5dcd9ac33cb847913``, fetched 2026-10-25. The file's sha256 is ``82fcb3cabe8ff6e1452849e3b2a26a3631f1e2b51beb62ffb537892d2b3e364f``. Upstream licenses it under CC0 1.0, the OpenSSL License or Apache-2.0, at the user's choice. Every case uses a 64-byte key and a 64-byte digest; message lengths are 0..255. | 115 | Boundary cases (`boundary.txt`) | Generated once by `python3 test/oracle.py boundary` (CPython 3.12.3 `hashlib.blake2b`). The key is bytes `00 01 ..`; message byte i is `i mod 251`. The message lengths are 0, 1, 111, 112, 127, 128, 129, 255, 256, 257, 383, 384, 385, 1023, 1024, 1025, 65407, 65408, 65409, 65535 and 65536. Each length is run unkeyed and with a 64-byte key. The file also has keys of 1, 32 and 63 bytes, and digest lengths 1, 2, 20, 32, 48 and 63. | 116 | Differential corpus (`oracle.py diff SEED`) | Every length 0..1100 twice: unkeyed with a 64-byte digest, and keyed with `kn = 1 + L%64` and `outn = 64 - L%64`. Then 64 seeded-random cases: lengths 65535, 65536 and 62 random lengths in 0..65536, key length 0..64, outn 1..64. That makes 2266 cases. | 117 118 ## Third-party material and notices 119 120 | Copied material | Owner and terms | Notice file | 121 |---|---|---| 122 | The "abc" digest (Appendix A) and `blake2b_res` (Appendix E) in `vectors/rfc7693.txt`. The self-test procedure in `test/driver.om` (`selftst`, `seqm`, `seqk`, `mdlen`, `inlen`, `wantres`), a translation of the Appendix E C code into Omega. | Copyright (c) 2015 IETF Trust and the persons identified as the document authors. RFC 7693 is an Independent Submission stream RFC, subject to BCP 78 and the IETF Trust Legal Provisions. | `vectors/rfc7693.NOTICE`: the RFC's Copyright Notice section, verbatim (sha256 ``91f11554fcb2e0898435e97667b61c1b44f98af52a14e749ab195db3ef227975``). | 123 | `vectors/blake2b-kat.txt`, verbatim | BLAKE2 authors. Triple-licensed upstream under CC0 1.0, the OpenSSL License or Apache-2.0; this repository takes it under CC0 1.0. | `vectors/blake2b-kat.LICENSE`: upstream `COPYING` at ``ed1974ea``, verbatim (sha256 ``a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499``). | 124 125 The RFC 7693 notice is included for attribution only. Its boilerplate grants no code-component 126 licence. Section 4 of the IETF Trust Legal Provisions (TLP 5.0) is the section that licenses code 127 components. TLP 5.0 §8(f) says it does not apply to Independent Submission stream documents; this 128 was checked against 129 https://trustee.ietf.org/wp-content/uploads/Corrected-TLP-5.0-legal-provsions.pdf, fetched 130 2026-10-25, sha256 ``b5cbd993d1dae273d7b251db4efc397b4de13451b2156b94d5a901c83c0fb48a``. Whether the 131 copied test values and the translated self-test count as code components, and whether attribution 132 is sufficient, has not been determined. 133 134 Not copied: the IV and SIGMA constants in `blake2b.om` are the algorithm's defining values, 135 written out as decimal numbers. The Omega code was written for this unit and contains no copied 136 source text. `boundary.txt` and the differential corpus come from this unit's own generator. 137 138 ## Evidence (2026-10-25, linux arm64 host) 139 140 ``` 141 $ sh om/blake2b/test/run.sh "$(tools/omc.sh)" 142 blake2b: omc sha256 `734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61` 143 blake2b: driver sha256 `a3585a97a5918f854d86d312da60635666e1ecacf59d5c2f81d8065a15f91094` 144 blake2b: rfc7693-appA 1/1 PASS 145 blake2b: rfc7693-appE 1/1 PASS (`c23a7800d98123bd10f506c61e29da5603d763b8bbad2e737f5e765a7bccd475`) 146 blake2b: kat 256/256 PASS 147 blake2b: boundary 60/60 PASS 148 blake2b: differential seed 7693 149 blake2b: differential 2266/2266 PASS 150 blake2b: mutant expected-digit detected PASS 151 blake2b: mutant iv0 detected PASS 152 blake2b: mutant final-flag detected PASS 153 blake2b: mutant rot63 detected PASS 154 blake2b: mutant rounds detected PASS 155 ``` 156 157 The run exited with code 0 and took about 0.3 s. Differential seeds 1..5 gave 2266/2266 each. 158 159 Hashes: 160 161 | Item | Value | 162 |---|---| 163 | omega-mv pin | ``acb3f15cdc691b1b046b48b0dad0f9255a12ba4b`` | 164 | omc sha256 | ``734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61`` | 165 | `blake2b.om` sha256 | ``91299627928a67711e520b454dcde5fd9ce3f7cc4f4eebd01bb068cc564d42fd`` | 166 | `test/driver.om` sha256 | ``7d638023cf195e87da5bf95234c42960529e04f8275d54548770031d2f6372a3`` | 167 | driver binary sha256 | ``a3585a97a5918f854d86d312da60635666e1ecacf59d5c2f81d8065a15f91094`` | 168 169 `note` lines do not change the binary. 170 171 These are host runs only. They are not hardware qualification. 172 173 ## Limits 174 175 - **Not constant-time-audited.** Omega gives no timing guarantee, and no timing was measured. For 176 example, `b2bbyte` branches on the stream position and the lengths. Branching on data values was 177 not audited. 178 - One-shot only: there is no incremental (init/update/final) API. Messages are limited to 65536 179 bytes. 180 - No salt or personalization parameters, and no tree-hashing parameters. The parameter block holds 181 only digest length, key length, fanout 1 and depth 1. 182 - The block loop has a bound of 1000. At most 513 blocks are needed. 183 - Each byte of the stream is fetched through `b2bbyte`, eight calls per word; speed was not a goal.