# MoonWire Verification & Test Evidence Report

- **Date**: 2026-11-30
- **Project / Version**: `TZH-nh/moonwire` `0.1.0`
- **Host Environment**: Windows x86_64 (MSVC `cl.exe` `19.44.35207`, Node.js `v22.15.0` with OpenSSL `3.0.16`)
- **MoonBit Toolchain (`moon version --all`)**:
  - `moon 0.1.20261126 (ccd306a 2026-11-26)`
  - `moonc v1.0.0-rc1+3c0520448 (2026-11-26)`
  - `moonrun 0.1.20261126 (ccd306a 2026-11-26)`
  - Dependencies: `moonbitlang/core` (bundled) + `moonbitlang/async@0.22.11` (imported solely by `cmd/moonwire` on `native`; all 7 library packages have zero third-party dependencies).

---

## 1. Multi-Backend Check & Test Matrix

All checks executed with `--deny-warn` (0 warnings, 0 errors). Library unit tests (17 test blocks across 7 `*_test.mbt` files) and `README.mbt.md` executable documentation test (1 `mbt check` test block) are reported by `moon test` as 18 total tests:

| Command | Target / Mode | Library Tests | Doc Tests (`README.mbt.md`) | Result |
|---|---|---:|---:|---|
| `moon check --deny-warn` | `wasm-gc` (canonical) | — | — | **PASS** (0 warnings, 0 errors) |
| `moon check --deny-warn --target native` | `native` (incl. `cmd/moonwire`) | — | — | **PASS** (0 warnings, 0 errors) |
| `moon test --target wasm-gc` | `wasm-gc` (debug) | 17 | 1 | **18 / 18 PASS** |
| `moon test --target wasm` | `wasm` (debug) | 17 | 1 | **18 / 18 PASS** |
| `moon test --target js` | `js` (debug, Node.js) | 17 | 1 | **18 / 18 PASS** |
| `moon test --target native` | `native` (debug, MSVC x64) | 17 | 1 | **18 / 18 PASS** |
| `moon test --target wasm-gc --release` | `wasm-gc` (release) | 17 | 1 | **18 / 18 PASS** |
| `moon test --target native --release` | `native` (release, MSVC x64) | 17 | 1 | **18 / 18 PASS** |

Independent archive consumer verification (separate module `consumer/smoke` consuming the extracted `_build/publish/TZH-nh-moonwire-0.1.0.zip` archive, not the source working tree):
- `moon test --target wasm-gc` in `release-local/consumer-smoke`: **1 / 1 PASS**
- `moon test --target js` in `release-local/consumer-smoke`: **1 / 1 PASS**

GitHub Actions cross-OS verification (`ubuntu-latest`, `macos-latest`, `windows-latest`, running `moon check --deny-warn`, `moon check --deny-warn --target native`, `moon fmt --check`, and `moon test` on `wasm-gc`, `wasm`, `js`, and `native`) is configured in `.github/workflows/ci.yml` and passes on https://github.com/TZH-nh/moonwire/actions .

---

## 2. Independent Oracle & Real-World Sample Verification

Synthetic/generated test vectors and real-world Linux kernel captures are strictly separated below:

### 2.1 Official IETF RFC & Academic Test Vectors (Embedded in `crypto/crypto_test.mbt`)
- **RFC 7693 (`BLAKE2s`)**: Unkeyed empty & `"abc"` vectors, multi-block chunked streaming equivalence, keyed 32-byte and 16-byte MACs, and `HKDF-BLAKE2s` (`Kdf1`/`Kdf2`/`Kdf3`).
- **RFC 8439 & `draft-irtf-cfrg-xchacha`**: `Poly1305` §2.5.2 vector, `ChaCha20-Poly1305` §2.8.2 vector + AAD tamper rejection, `HChaCha20` §2.2.1 subkey vector, and `XChaCha20-Poly1305` Appendix A.3.1 vector.
- **RFC 7748 (`X25519`)**: §5.2 scalar multiplication vector, §6.1 Alice-Bob Diffie-Hellman shared secret, **1-iteration and 1,000-iteration** Montgomery ladder vectors (`422c8e7a...` and `684cf59b...`), and §6.1 all-zero / order-4 low-order point rejection.
- **SipHash-2-4**: Aumasson & Bernstein official empty and 15-byte reference vectors.

### 2.2 Independent OpenSSL 3.0.16 Differential & Live Windows UDP Interoperability
Executed via `scripts/verify_with_openssl.mjs` (Node.js `node:crypto` OpenSSL `3.0.16` + `node:dgram` UDP sockets):
1. **Transcript Differential Test** (`protocol/noise_test.mbt`): Verifies exact byte-for-byte agreement with OpenSSL 3.0.16 on `C_0`, `H_0`, `encrypted_static` (48B), `encrypted_timestamp` (28B), `encrypted_nothing` (16B), `T_i_send` (32B), and `T_r_send` (32B) with 32-byte PSK.
2. **Clean-Room OpenSSL PCAP Fixture** (`fixtures/openssl-wg-session.pcap` + `fixtures/openssl-wg-session.keys`, Apache-2.0): 5-frame capture generated independently by OpenSSL; `moonwire inspect-pcap` verifies `[mac1=OK]` and decrypts **5 / 5** frames (Initiation, Response, IPv4 ICMP Echo Request/Reply, Keepalive).
3. **Live Cross-Process Windows Localhost UDP Interop** (`node scripts/verify_with_openssl.mjs interop ...`):
   - Spawns an OpenSSL 3.0.16 WireGuard UDP responder on `127.0.0.1:<ephemeral_port>` with freshly generated random X25519 keys + random 32-byte PSK;
   - Runs native `moonwire.exe udp-client`, completing live `Noise_IKpsk2` handshake over Windows UDP sockets, encrypting an inner IPv4 ICMP Echo Request (`interop-openssl-moonwire`), authenticating/decrypting it in OpenSSL, returning an OpenSSL-encrypted ICMP Echo Reply, and authenticating/decrypting the reply in `moonwire.exe` (`PASS`).

### 2.3 Real-World Linux Kernel WireGuard Captures (Local Verification Only, Not Redistributed)
Fetched locally into git-ignored `release-local/external-captures/` from the official Wireshark repository (`gitlab.com/wireshark/wireshark/-/raw/master/test/captures/` and `test/suite_decryption.py`, GPL-2.0-or-later — excluded from repository and Mooncakes package archive for license hygiene):
1. **`wireguard-ping-tcp.pcap` (Real Linux kernel WireGuard v1 capture, 22 UDP frames)**:
   - Command: `moonwire inspect-pcap release-local/external-captures/wireguard-ping-tcp.pcap --keylog release-local/external-captures/wireguard-ping-tcp.keys`
   - Result: **22 / 22 WireGuard frames authenticated (`[mac1=OK]`) and decrypted** directly from raw static + ephemeral private keys (`init=2`, `resp=2`, `data=18`), recovering inner `ICMPv4` pings (`10.10.0.2 <-> 10.10.0.1`), `UDP 53` DNS queries to `1.1.1.1`, mid-stream session rekey (`0x30d037d8 -> 0xbffd41c5`), and `TCP 443` packets.
2. **`wireguard-psk.pcap` (Real Linux kernel WireGuard v1 PSK capture, 4 UDP frames)**:
   - Command: `moonwire inspect-pcap release-local/external-captures/wireguard-psk.pcap --keylog release-local/external-captures/wireguard-psk.keys`
   - Result: **4 / 4 handshake frames authenticated (`[mac1=OK]`) and decrypted** (`init=2`, `resp=2`) using both distinct pre-shared keys.
3. **`8-trace.pcap` + `8-trace.keys` (`Lekensteyn/wireguard-dissector`, 1,476,788 bytes, 1,222 UDP frames)**:
   - Result: **1,222 / 1,222 frames decrypted** (`init=5`, `resp=5`, `data=1212`), recovering inner ICMPv4, Keepalive, and HTTP/iperf TCP streams.

---

## 3. Codebase Size Breakdown (Separated by Role)

Measured across git-tracked source files (`non-blank non-comment SLOC` excludes blank lines and `//` comment lines; generated `.mbti` files are separated from hand-written MoonBit source):

| Category | Files | Physical Lines | Non-Blank Non-Comment SLOC |
|---|---:|---:|---:|
| Pure MoonBit Library Implementation (`crypto`, `packet`, `replay`, `routing`, `config`, `protocol`, `pcap`, root) | 19 | 5,983 | 5,162 |
| Native CLI Implementation (`cmd/moonwire/main.mbt`) | 1 | 530 | 487 |
| MoonBit Unit & Integration Tests (`*_test.mbt` + `README.mbt.md`) | 10 | 994 | 859 |
| Compiler-Generated Public Interfaces (`*.mbti`) | 9 | 788 | 525 |
| Independent OpenSSL Verification Script (`scripts/verify_with_openssl.mjs`) | 1 | 327 | 299 |

---

## 4. Platform Scope & Explicit Limitations

- **Verified Platforms**: Windows x86_64 (`wasm-gc`, `wasm`, `js`, and `native` via MSVC `cl.exe` + Windows Winsock UDP).
- **Explicitly Out of Scope**: OS kernel virtual network interface mounting (`wintun.dll` on Windows, `/dev/net/tun` on Linux, `utun` on macOS) and execution of `wg-quick` `PreUp`/`PostUp`/`PreDown`/`PostDown` shell hooks.
