interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / argon2 / README.md

332 lines · 17725 bytes Raw Blame History Rendered
1# om/argon2: Argon2i in Omega
2
3Argon2i, version 0x13 ([RFC 9106](https://www.rfc-editor.org/rfc/rfc9106)), written in Omega (`.om`)
4and compiled by the pinned seed-born `omc`. It hashes with `om/blake2b`. It takes every RFC input:
5password P, salt S, secret K, associated data X, passes t, memory m, lanes p and tag length T.
6It also computes the Tailnet Lock disablement value. Tailscale defines that value as
7`argon2.Key(secret, "tailscale network-lock disablement salt", 4, 16*1024, 4, 32)`, from
8golang.org/x/crypto/argon2, at `tka/state.go:116,129` in tailscale.com v1.102.0. The TKA server
9recomputes it to check a submitted disablement secret.
10
11Only Argon2i is implemented. Argon2d and Argon2id are not, because TKA does not use them. Go and
12Python appear only in the tests: Go as the referee, Python as the generator of the vector file.
13
14## Why the unit is split in two files
15
16The matrix for the TKA parameters is 16384 blocks of 1024 bytes, which is 16 MiB. Four limits of the
17pinned `omc` decide where that memory can live. Each was checked with a probe program on 2026-10-25:
18
19| Probe | Result |
20|---|---|
21| `a = new ulong 2097152 0` in `main` (a 16 MiB local array) | `omc: error 23`. Local arrays are capped at 4 MiB per function, and program-mode stack is 8 MiB (OMEGESE 9.2, 9.4). |
22| `global g ulong 2097152`, passed as `f g` to `fn f a edit ulong 2097152` | `omc: error 19`. A global is never passed (OMEGESE 9.4). |
23| `global g ulong 2097152`, read and written by name inside a function | Builds. Exits 7, the value it wrote at index 2097151. |
24| A 4 MiB local in one function plus 3.2 MiB in its caller | Builds and runs. The cap is per function. |
25
26So no library function can be handed 16 MiB, and no program can build a 16 MiB array except as a
27global. The unit is split along that line:
28
29- `argon2.om` is a library unit in the usual form: functions only, no globals, no `main`. It holds
30 everything that does not touch the matrix: parameter checks, H0, H', the first blocks, the
31 compression G, the Argon2i address blocks, the reference-index computation and the tag.
32- `argon2pool.om` is a program-mode companion. It declares the matrix as
33 `global a2mem ulong 2097152` (16 MiB), and the read-only salt as `text a2tsalt`. It holds the
34 functions that name them: block load and store, the segment loop, `a2hash` and `a2tka`. A program
35 includes it once, after `blake2b.om` and `argon2.om`. A future tkad program does the same.
36
37Lanes run one after another, in slice order. Within a slice no lane reads another lane's current
38segment (RFC 9106 3.4.1.1), so the result equals the parallel computation. The Go referee runs lanes
39in parallel goroutines, and the corpus below matches it.
40
41## Files
42
43| Path | Role |
44|---|---|
45| `argon2.om` | Library unit, prefix `a2`. Concatenate it after `om/blake2b/blake2b.om`. |
46| `argon2pool.om` | Program-mode companion with the 16 MiB matrix. It provides `a2hash` and `a2tka`. |
47| `test/driver.om` | Program-mode test driver. |
48| `test/trap.om` | Contract-violation program, used by `run.sh`. |
49| `test/run.sh` | Test suite. Usage: `sh om/argon2/test/run.sh OMC`. |
50| `test/gen/oracle/` | Go referee (`main.go`, `go.mod`, `go.sum`) on golang.org/x/crypto v0.54.0. Test only. |
51| `test/gen/vectors.py` | Builds the case list and runs the referee on it. Test only. |
52| `test/vectors/rfc9106.txt` | RFC 9106 section 5.2, the Argon2i test vector. |
53| `test/vectors/rfc9106.NOTICE` | RFC 9106's Copyright Notice section, verbatim, with a note on what was copied. |
54| `test/vectors/go-diff.txt` | 31 parameter sets and 10 TKA secrets, with tags from the Go referee. |
55| `test/vectors/reject.txt` | 11 out-of-range parameter sets that must return 1. |
56
57## API
58
59Build order: `cat om/blake2b/blake2b.om om/argon2/argon2.om om/argon2/argon2pool.om main.om | omc`.
60
61```
62fn a2hash prm view ulong 8 inp view uchar 65536 out edit uchar 1024 to ulong
63fn a2tka sec view uchar 1024 sn ulong o edit uchar 32 to void
64```
65
66`a2hash` computes the Argon2i tag:
67
68| Parameter | Meaning |
69|---|---|
70| `prm` | `[t, m (KiB), p, T, |P|, |S|, |K|, |X|]`. |
71| `inp` | `P ‖ S ‖ K ‖ X` back to back, with lengths taken from `prm`. Empty fields are allowed. |
72| `out` | Receives the tag in `out[0..T)`. `out[T..1024)` is set to 0. |
73| return | 0 on success. 1 if a parameter is out of range, in which case `out` is not written. |
74
75Accepted ranges, checked by `a2setup`:
76
77| Parameter | Range | Source |
78|---|---|---|
79| t | 1..999999 | RFC: ≥ 1. The upper bound is the unit's loop bound. |
80| p | ≥ 1 | RFC. |
81| m | 8p..16384 | RFC: ≥ 8p. The upper bound is the matrix capacity. m' = 4p·⌊m/4p⌋. |
82| T | 4..1024 | RFC: ≥ 4. The upper bound is the `out` capacity. |
83
84Caller contract, enforced with trap 3 (exit 103): each of |P|, |S|, |K|, |X| is at most 65536, and
85their sum is at most 65496. H0's input is 40 bytes of length fields plus the four fields, and it must
86fit one 65536-byte `b2bhash` message.
87
88`a2tka` computes the TKA disablement value:
89
90| Parameter | Meaning |
91|---|---|
92| `sec`, `sn` | The secret. Only `sec[0..sn)` is read. `sn` is 0..1024. If `sn > 1024` the call traps 3. |
93| `o` | Receives the 32-byte value `Argon2i(P = secret, S = "tailscale network-lock disablement salt", t = 4, m = 16384, p = 4, T = 32)`. |
94
95Clients generate 32-byte secrets (`cmd/tailscale/cli/tailnet-lock.go:168,178`, v1.102.0). The secret
96in a disable request is attacker-controlled, so the request layer must reject a secret longer than
971024 bytes before it calls `a2tka`. A trap would refuse the request, which is a denial of service.
98Comparing the result with the stored disablement values is the caller's job.
99
100The matrix is shared by every call, and calls run one after another (Omega has no threads). Each call
101overwrites every block it later reads: pass 0 writes all m' blocks before any is read. So nothing
102from an earlier call reaches a later result. Blocks past m' keep old contents but are never read.
103The matrix is not wiped after a call.
104
105Library functions in `argon2.om`:
106
107| Function | Purpose |
108|---|---|
109| `a2setup` | Range checks. Fills the state array `st`: t, m', p, q, segment length, pass, slice, lane, T, m, y. |
110| `a2h0` | H0 (RFC 9106 3.2 step 1). |
111| `a2hp` | H' (3.3). |
112| `a2first` | B[l][0] and B[l][1] (3.2 steps 3-4). |
113| `a2fm`, `a2gb`, `a2ix`, `a2p` | BlaMka GB and the permutation P on rows and columns (3.6). |
114| `a2comp` | G(X, Y), plus the version 0x13 XOR into the old block (3.5, 3.2 step 6). |
115| `a2zin`, `a2addr` | The Argon2i address input block and the next address block G(0, G(0, Z)) (3.4.1.2). |
116| `a2rlane`, `a2area`, `a2ref` | Reference lane, reference area and the mapping of J1 to a column (3.4.1.1, 3.4.2). |
117| `a2tag` | H'^T over the XOR of the last column (3.2 steps 7-8). |
118| `a2le32`, `a2cp`, `a2cp64`, `a2b2w` | Byte helpers. |
119
120`argon2pool.om` adds:
121
122| Function | Purpose |
123|---|---|
124| `a2get`, `a2put` | Load and store a matrix block. |
125| `a2i0`, `a2abs`, `a2prev` | Segment start, absolute block number and previous block. |
126| `a2blk` | Computes one block. |
127| `a2seg` | Runs one segment. |
128| `a2init`, `a2fill`, `a2fin` | The phases of `a2hash`. |
129| `a2hash`, `a2tka` | The entry points. |
130
131## Standards followed
132
133These are the sections of RFC 9106:
134
135| Section | What it defines | Where the code uses it |
136|---|---|---|
137| 3.1 | Input ranges | `a2setup`. |
138| 3.2 | H0, m', first blocks, passes, final XOR, tag | `a2h0`, `a2setup`, `a2first`, `a2fill`, `a2seg`, `a2blk`, `a2fin`, `a2tag`. Later passes XOR the new block into the old one, which is version 0x13 behaviour. |
139| 3.3 | H' | `a2hp`. Takes r = ⌈T/32⌉ − 2 and emits 32-byte prefixes of V1..Vr, then V(r+1) of T − 32r bytes. |
140| 3.4.1.2 | Argon2i J1, J2 | `a2zin` and `a2addr`. Z = (r, l, s, m', t, y, counter). A new address block is made at the first index of a segment and at every multiple of 128. |
141| 3.4.1.1, 3.4.2 | Reference lane, reference set, J1 mapping | `a2rlane`, `a2area`, `a2ref`. x = J1²/2³², y = (\|R\| · x)/2³², zz = \|R\| − 1 − y, offset by the start of the area. |
142| 3.5 | Compression G | `a2comp`. |
143| 3.6 | Permutation P and GB, with the BlaMka multiply 2·lo32(a)·lo32(b) | `a2p`, `a2gb`, `a2fm`. Rotations right by 32, 24, 16, 63. Rows are words 16i..16i+15; columns are the 16-byte registers i, i+8, …, i+56. |
144
145The Go referee follows the same steps: golang.org/x/crypto v0.54.0, `argon2/argon2.go`, `deriveKey`,
146`indexAlpha` and `phi`.
147
148## Test driver protocol
149
150`driver` reads one case per line from stdin and writes one line per case:
151
152| Input line | Output |
153|---|---|
154| `T M P TL PW SALT KEY AD` | Decimal t, m, p and tag length, then hex P, S, K and X (`-` for empty). Prints `2*TL` lowercase hex digits, or `e1` when `a2hash` returns 1. |
155| `tka SEC` | Hex secret, or `-` for empty. Prints the 64-hex-digit `a2tka` value. |
156
157It exits 0 at end of input and 2 on a malformed line.
158
159`run.sh` does the following:
160
1611. Builds `build/test/argon2/driver`.
1622. Checks the RFC vector, the Go corpus and the reject list.
1633. If `ARGON2_ORACLE` names a built referee, checks a fresh random Go corpus of `ARGON2_N` cases
164 (default 200) from seed `ARGON2_SEED` (default 9106). Without it, that step prints `NOT_RUN`.
1654. Runs `trap.om` three times, and each run must exit 103:
166 - `a2tka` with `sn = 1025`;
167 - `|P| = 65537`;
168 - fields that sum to 65497.
1695. Runs nine mutants. Each source mutant is rebuilt and run on the RFC vector plus the Go corpus.
170 It counts as detected only when the run ended normally (exit 0, one output line per case) and at
171 least one tag differs from the expected one. A trap (exit 100+N), a signal, a launch failure or
172 short output makes the mutant FAIL. The runs are not piped, so the exit status is kept. The same
173 rule applies to the expected-digit mutant. Checked by adding two throwaway mutants and then
174 removing them. One trapped on the first case (`if gt s 65496` → `if gt s 0`). The other trapped
175 only at the first non-empty `tka` line, after 33 of 42 output lines (`if gt sn 1024` →
176 `if gt sn 0`). The suite printed `ran abnormal (exit 103) FAIL` for both and exited 1.
177
178| Mutant | Change |
179|---|---|
180| expected digit | One flipped expected digit. |
181| version | Version 0x13 → 0x10 in H0. |
182| type | Type y = 1 → 2 in H0. |
183| blamka | BlaMka multiply dropped (plain addition). |
184| column | Column permutation replaced by row indexing. |
185| area | Reference area not reduced by 1. |
186| counter | Address counter not incremented. |
187| xor13 | No XOR into the old block in later passes (the version 0x10 rule). |
188| addr128 | No new address block at index multiples of 128. |
189
190## Vector sources
191
192**RFC 9106 section 5.2 (Argon2i).** From https://www.rfc-editor.org/rfc/rfc9106.txt, fetched
1932026-10-25. The file's sha256 is `855c06f060379e34285e83a217e9069b5c72e161a1e54df9af5cd88dbb231f31`.
194Parameters: t=3, m=32, p=4, T=32, P = 32 × 01, S = 16 × 02, K = 8 × 03, X = 12 × 04.
195Tag: `c814d9d1dc7f37aa13f0d77f2494bda1c8de6b016dd388d29952a4c4672b6ce8`.
196
197**Go corpus (`go-diff.txt`).** Generated by `python3 test/gen/vectors.py ORACLE` from seed 9106.
198Generating it again with the same referee gives identical bytes; this was checked with `cmp`. The
199referee is `test/gen/oracle`, built with go1.26.0 linux/arm64 against golang.org/x/crypto v0.54.0.
200tailscale.com v1.102.0 pins that same version in its `go.mod`.
201
202- Lines with K = X = empty call the public `argon2.Key`.
203- Lines with K or X call the package's internal `deriveKey`, the function `Key` wraps, through
204 `go:linkname`, because the public API has no K or X. On every line with K = X = empty, the referee
205 also checks that `argon2.Key` and `deriveKey` agree.
206
207The 31 parameter sets:
208
209| Cases | What they cover |
210|---|---|
211| m=8, p=1 | The smallest memory. |
212| Empty password | |
213| RFC shape with random bytes | |
214| m = 37, 63, 100 | m not a multiple of 4p. |
215| p = 3, 5, 8, 16 | |
216| m = 512, 1024, 1536, 2048, 4096 | Segments of 128, 256 and 1024 blocks, which need one to eight address blocks. |
217| T = 4, 5, 63, 64, 65, 96, 100, 128, 129, 512, 1024 | Both sides of every H' branch. |
218| Long fields | P = 4000 and X = 4000, and P + S at the 65496-byte H0 capacity. |
219| m = 16384 with p = 1 and p = 4, and m = 16383 with p = 4 | The full 16 MiB matrix. |
220| t=4, m=16384, p=4, T=32 | The TKA cost parameters with a random salt. |
221
222The 10 `tka` lines use secrets of 0, 1, 16, 32 (×4), 33, 64 and 1024 bytes.
223
224**Reject list (`reject.txt`).** Hand-written from the RFC 3.1 ranges and this unit's limits:
225
226| Case | Value |
227|---|---|
228| t | 0, 1000000 |
229| p | 0, 2049 |
230| m | 31 with p = 4, 7 with p = 1, 16385, 9999999 |
231| T | 0, 3, 1025 |
232
233To regenerate:
234
235```
236cd om/argon2/test/gen/oracle && go build -o /tmp/argon2-oracle .
237python3 om/argon2/test/gen/vectors.py /tmp/argon2-oracle > om/argon2/test/vectors/go-diff.txt
238```
239
240## Third-party material and notices
241
242| Copied material | Owner and terms | Notice file |
243|---|---|---|
244| Parameters, inputs and tag of RFC 9106 section 5.2, in `vectors/rfc9106.txt` | Copyright (c) 2021 IETF Trust and the persons identified as the document authors. RFC 9106 is an IRTF stream RFC (Crypto Forum Research Group), subject to BCP 78 and the IETF Trust Legal Provisions. | `vectors/rfc9106.NOTICE`: the RFC's Copyright Notice section, verbatim (sha256 `8704dbca8266c2115313362127842fa324523027c10a862dd1d754828537606a`). |
245
246The RFC 9106 notice is included for attribution only. Its boilerplate grants no code-component
247licence. Section 4 of the IETF Trust Legal Provisions (TLP 5.0) is the section that licenses code
248components. TLP 5.0 §8(g) says it does not apply to IRTF stream documents; this was checked against
249https://trustee.ietf.org/wp-content/uploads/Corrected-TLP-5.0-legal-provsions.pdf, fetched
2502026-10-25, sha256 `b5cbd993d1dae273d7b251db4efc397b4de13451b2156b94d5a901c83c0fb48a`. Whether the
251copied test values count as code components, and whether attribution is sufficient, has not been
252determined.
253
254Not copied:
255
256- The tags in `go-diff.txt` are outputs of the Go referee, not text taken from any source.
257- `gen/oracle/main.go` calls golang.org/x/crypto (BSD 3-clause) as a module dependency. It vendors
258 none of its source; it only declares the `deriveKey` signature for `go:linkname`.
259- The Omega code was written for this unit and contains no copied source text. Go's sources are
260 cited by file and function name only.
261- The salt `"tailscale network-lock disablement salt"` in `argon2pool.om` is the 39-byte constant
262 from tailscale.com `tka/state.go:116`, reproduced because interoperability requires it.
263
264## Evidence (2026-10-25, linux arm64 host)
265
266```
267$ ARGON2_ORACLE=<built test/gen/oracle> sh om/argon2/test/run.sh "$(tools/omc.sh)"
268argon2: omc sha256 734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61
269argon2: driver sha256 00da3121dc5c5368fa5a040c75747326fb7543a3bd22c6deeb7aa0e6cd0d93f4
270argon2: rfc9106 1/1 PASS
271argon2: go-diff 41/41 PASS
272argon2: go-diff has 31 parameter sets and 10 tka secrets
273argon2: reject 11/11 PASS
274argon2: random seed 9106
275argon2: random 200/200 PASS
276argon2: trap 1 exit 103 PASS
277argon2: trap 2 exit 103 PASS
278argon2: trap 3 exit 103 PASS
279argon2: mutant expected-digit detected PASS
280argon2: mutant version detected PASS
281argon2: mutant type detected PASS
282argon2: mutant blamka detected PASS
283argon2: mutant column detected PASS
284argon2: mutant area detected PASS
285argon2: mutant counter detected PASS
286argon2: mutant xor13 detected PASS
287argon2: mutant addr128 detected PASS
288```
289
290The run exited 0 in about 31 s. Most of that time is the eight source mutants, each of which runs
291the whole RFC vector and Go corpus to completion. Other runs:
292
293| Run | Result |
294|---|---|
295| Random seeds 1, 2 and 3 with `ARGON2_N=500` | 500/500 each. |
296| Without `ARGON2_ORACLE` | The random step prints NOT_RUN, everything else passes, exit 0. |
297
298**Runtime of one TKA disablement evaluation**, measured with `/usr/bin/time` on this host:
299
300| Command | Wall time | Max RSS |
301|---|---|---|
302| `driver <<< "tka 0011…eeff"`, 5 runs | 0.25 to 0.27 s | 16.5 MiB |
303| 10 `tka` lines in one process | 2.54 s, about 0.25 s each | |
304| Go referee, same 10 lines, `GOMAXPROCS=1` | 0.38 s | |
305| Go referee, same 10 lines, default `GOMAXPROCS` | 0.19 s | |
306
307Hashes:
308
309| Item | Value |
310|---|---|
311| omega-mv pin | `acb3f15cdc691b1b046b48b0dad0f9255a12ba4b` |
312| omc sha256 | `734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61` |
313| `argon2.om` sha256 | `bf1984ec4735fac106ca3e5f08ddeab6b1dc3826780f93a532794e5ef46189ec` |
314| `argon2pool.om` sha256 | `247617c3055ad8fae77871d2a761cba69aa1c0c386596dc70bc0bed1aaca3ce1` |
315| `test/driver.om` sha256 | `3a652fd707248bdf9eddd20fedcbacc85a8337d4af717ef7648aa87ade57aeb8` |
316| driver binary sha256 (with `blake2b.om` `91299627…42fd`) | `00da3121dc5c5368fa5a040c75747326fb7543a3bd22c6deeb7aa0e6cd0d93f4` |
317
318These are host runs only. They are not hardware qualification.
319
320## Limits
321
322- **Not constant-time-audited.** Omega gives no timing guarantee, and no timing side channel was
323 measured. Argon2i's memory access pattern does not depend on the password, by design
324 (RFC 9106 3.4.1.2). The code was not audited for data-dependent branches.
325- Argon2i only. There is no Argon2d or Argon2id.
326- m is at most 16384 KiB, which is the matrix capacity. T is at most 1024. t is at most 999999. The
327 four inputs together are at most 65496 bytes.
328- `argon2pool.om` declares a global, so it works only in program mode, once per program. Calls must
329 not overlap. Omega has no threads, so they cannot.
330- The matrix is not wiped after a call. Its contents, derived from the secret, stay in process memory
331 until the next call overwrites them.
332- Lanes are computed one after another. There is no parallel speed-up.