nuntius — Java
An unfinished Java port of the nuntius v4 protocol specification. The primitives, the key
types and the protocol KDFs are implemented and tested; X3DH and the Double Ratchet — the two layers
the protocol is named for — are stubs.
Experimental: for research only, not for production
These projects are experimental. They are for research, and they are not recommended for
production environments.
They were built for learning purposes and for the fun of it. Writing a normative specification, a
frozen conformance corpus, a complete reference implementation and three ports of a two-stage
cryptographic protocol — the ports still partial, and interoperation demonstrated only as far as
each one is written — is a scope that LLM-assisted development made reachable for one person, and
that is part of what this project is about. It is said here plainly rather than left to be
inferred.
The engineering is real — the specification, the corpus, and the defects they caught are all real
— and none of that substitutes for a security review. Specifically:
- No external security review or audit has been performed. SPEC §17.7 names the
transcript-hash binding in particular: folding
TH into the X3DH info rests on an informal
argument that "SHOULD be reviewed by someone who did not write this document before any of the
four implementations ships". Nobody has reviewed it.
- The specification carries known open risks and deliberate non-goals, enumerated in SPEC §17:
no header encryption (§17.4), no post-quantum component (§17.5), best-effort JVM zeroization
(§17.1), state rollback mitigated rather than solved (§17.2), replay of a no-OPK initial message
(§17.3), and verifier strictness that differs across platforms (§17.8).
- Cross-implementation interoperability is verified against the frozen corpus only as far as
each port is actually implemented, and the ports are incomplete. Two implementations that stop
at the same layer agreeing with each other says nothing about the layers above it.
- This port is deliberately incomplete. 14 of the 88 conformance vectors run; 74 are skipped,
each naming the unimplemented SPEC section it waits on. X3DH (§6), the Double Ratchet (§7), the
wire codec (§9–§10), session lifecycle (§11) and state serialization (§12) are honest stubs. The
suite reports 215 tests, of which those 74 skips are part — the green covers the primitives and
the substrate, not the protocol.
- The predecessor protocol (v3) shipped for years with a fatal, silent defect its own green test
suite could not see: the key agreement had collapsed to a single Diffie-Hellman while every
test passed (§15.1). That is the most honest argument available for the first line of this
block. A careful, thoroughly tested, unaudited cryptography library is still an unaudited
cryptography library, and thorough testing is precisely the evidence that put the predecessor
into production.
🚧 Work in progress — an LLM-assisted experiment, still being written
This port is unfinished, and it is not on a schedule. It is a work in progress in the literal
sense: the foundation is built and tested, the protocol on top of it is not written yet, and there
is no commitment about when or whether it will be.
Where it actually stands today:
| Layer |
State |
| Substrate, nominal key types, error taxonomy, byte IO |
implemented, tested |
| Crypto seam + Bouncy Castle provider (HKDF, HMAC, SHA-256, X25519, Ed25519, ChaCha20-Poly1305) |
implemented, verified against RFC 5869 / 7748 / 8032 / 8439 |
Protocol KDFs — KDF_RK, KDF_CK, KDF_MK (SPEC §7.2, §7.3, §8.1) |
implemented, tested |
| X3DH (§5, §6) |
stub |
| Double Ratchet (§7) |
stub |
| Wire codec and parsing gates (§9, §10) |
stub |
| Session lifecycle (§11) |
stub |
| State serialization (§12) |
stub |
14 of the 88 conformance vectors run. 74 are skipped, each naming the SPEC section it waits
on. The 215-test suite is green, and that green covers the primitives and the substrate — it says
nothing about the protocol, because most of the protocol is not here.
The stubs are deliberate. Unverified cryptographic code that looks finished is worse than an
honest stub, because the next reader trusts it — so nothing is written here until the frozen
corpus can grade it.
This is also, plainly, an experiment in LLM-assisted development. A normative specification, a
reference implementation, a frozen conformance corpus and three ports is not a scope one person
would previously have taken on for fun. That it was reachable at all is part of the point — and it
is exactly why the audit disclaimer above is not boilerplate.
This is one of four implementations — Objective-C (the reference), Java, Kotlin and Swift — that
must interoperate byte-for-byte on the basis of spec/SPEC.md alone. Where the
specification and this code disagree, the specification is correct and this code has a bug.
The protocol is written from the published X3DH and Double Ratchet specification documents and from
the author's own Objective-C implementation.
Status: partial, and deliberately so
This port is not conformant and does not claim to be. What is here is the layer that can be
verified today against sources outside itself. What is not here is the layer that cannot.
Implemented and verified
| Area |
SPEC |
Verified against |
| HKDF-SHA256 (Extract, Expand, one-shot) |
§3.2 |
RFC 5869 A.1–A.3, transcribed from the RFC text |
| X25519 |
§3.2, §4.2, §4.4 |
RFC 7748 §5.2 and §6.1 |
| Ed25519 — pure, RFC 8032 §5.1 |
§3.2, §3.4 |
RFC 8032 §7.1, all five vectors |
| ChaCha20-Poly1305, IETF |
§3.2, §8.2 |
RFC 8439 §2.8.2 and Appendix A.5 |
| SHA-256, HMAC-SHA256, constant-time compare, CSPRNG |
§3.2, §13.1 |
RFC 5869 (through HKDF), unit tests |
KDF_RK, KDF_CK, KDF_MK, SK derivation |
§7.2, §7.3, §8.1, §6.3 |
An independent JDK-based HKDF oracle |
| Nominal key types |
§4.3 |
An in-process javac required to reject wrong assignments |
| Public key validation |
§4.4 |
RFC 7748 vectors plus negative cases |
| Error taxonomy, exact numeric codes |
§10.5 |
The §10.5 table, code by code |
| Constants |
§18 |
§18's published hex and field sums |
| Bounds-checked byte reader/writer |
§3.1, §9, §10.4, §16.3 |
Unit tests for every unsigned width |
| Zeroization |
§13.3, §17.1 |
Unit tests — see the honest limits below |
Not implemented
X3DH (§6), the Double Ratchet (§7), the wire format (§9–§10), session lifecycle (§11) and state
serialization (§12). Each is a documented TODO in
NotYetImplemented.java, naming the
SPEC sections and the platform traps that apply.
Why they are absent rather than written and untested. They were written against nothing for as
long as the frozen conformance corpus that SPEC §15 specifies did not exist — §15.6 has the
Objective-C reference generate it after reaching conformance, and that has now happened. Writing the
key agreement, the ratchet and the wire codec ahead of it would have produced a large amount of
plausible, self-consistent, unverified cryptographic code; they will be written against the corpus
instead, and each landing turns a block of the skip ledger below into passes.
That is not a hypothetical risk. §15.1 records that the reference implementation's own v3 test suite
could not detect regressions on its two most serious defects: it asserted that both parties
derived equal 32-byte shared keys, which holds perfectly when the key agreement has silently
collapsed to a single Diffie-Hellman — which is exactly what had happened, for years, under a green
build. §15.1's conclusion is the operating principle of this repository:
Positive round-trip tests certify nothing about this protocol.
Conformance status: 14 of 88, and NOT conformant
The frozen §15 corpus is vendored into spec/vectors/ verbatim — six files, 88
vectors, checksummed in spec/CHECKSUMS.txt. ConformanceRunnerTest loads and
parses all six on every run and dispatches all 88.
|
Vectors |
|
| Run and pass |
14 |
every kind: "primitive" vector — HKDF, X25519 with §4.4's checks, pure Ed25519, ChaCha20-Poly1305 and the three protocol KDFs |
| Skipped, §6 |
16 |
X3DH key agreement |
| Skipped, §7 |
23 |
the Double Ratchet |
| Skipped, §9–§10 |
27 |
the wire format and its codec |
| Skipped, §12 |
8 |
state blob serialization |
The 74 skips are grouped here by each vector's own kind. The Kotlin port groups the same 74 by the
layer whose absence blocks each vector, and so reports 27 / 22 / 17 / 8 rather than 16 / 23 / 27 /
8. Both are correct and both total 74; they answer different questions, and neither port has
miscounted. See nuntius-kotlin's conformance section for that grouping and why it chose it.
§15.6 step 5 makes a port conformant only when "all pass and none are skipped without an explicit,
reviewed reason", and the dangerous half of that sentence is the second one: a silent skip and a pass
are indistinguishable in a summary line. So the skip list is an asserted artefact rather than a side
effect. A skip can only be produced by a member of a closed enum of unimplemented SPEC sections —
there is no free-text reason anyone can write at the moment of skipping to get a build green — the
totals are pinned, a kind: "primitive" vector that no evaluator recognises is a hard failure rather
than a skip, and the full ledger is printed in CI.
Per §15.1, this port is not conformant and will not claim to be until every vector passes.
Zeroization on the JVM is best-effort, and this port says so
SPEC §17.1 requires this section to exist, and requires it to be honest rather than reassuring:
Arrays.fill is not guaranteed against JIT dead-store elimination, and a relocating GC may have
already copied a byte[] before the wipe runs, leaving an unreachable copy. There is no JVM
equivalent of sodium_malloc's guard pages.
The Java and Kotlin ports are therefore strictly weaker than the Objective-C and Swift ports on
defect 8, and MUST say so in their READMEs rather than paper over it.
What this port does about it, within what the platform allows:
- All key material lives in
SecretBytes — a mutable byte[] with an explicit wipe(). Never a
String, never a boxed type, never a record that hands its array out by reference.
SecretBytes is AutoCloseable, so try-with-resources covers the failure path — the one §13.3
cares most about and the one a hand-written wipe forgets.
- Using a wiped secret throws rather than silently operating on 32 zero bytes.
- Secrets refuse
hashCode() and Object.equals(); comparison is constant-time and typed.
- Key lifetimes are kept short and the material exists in exactly one array wherever possible.
What it cannot do: guarantee the bytes are gone. A memory-dump adversary is outside what this port
can defend against, and no amount of Arrays.fill changes that.
Requirements
- Java 17+ (the Gradle toolchain targets 17; CI runs 17 and 21)
- BouncyCastle
bcprov-jdk18on — the only runtime dependency
SPEC §16.3: "Pin one provider — providers differ on small-order and non-canonical Ed25519 point
handling." This port uses BouncyCastle's lightweight API for every primitive and does not mix in
the JDK's JCA providers for some and BouncyCastle for others. The one deliberate exception is in the
test suite, where the JDK's javax.crypto.Mac serves as an independent oracle for the protocol
KDFs — the whole value of which is that it is a second implementation.
Build and test
./gradlew build # compile, test, javadoc, jars
./gradlew test # tests only
./gradlew test --tests '*Rfc*' # just the RFC known-answer tests
# SPEC §15.6's future-clock run
./gradlew test -PclockOffsetSeconds=315360000
There is no released artifact. Maven coordinates are wired
(com.ivrodriguez:nuntius:0.1.0-SNAPSHOT), but this repository has no tags, no publishing repository
configured and nothing published to Maven Central or anywhere else — so there is no dependency line
to copy into a build file, and no version that would resolve if you wrote one. Build from source, or
./gradlew publishToMavenLocal to put a snapshot in your local repository.
Layout
spec/SPEC.md Vendored copy of the normative specification (NOT canonical)
spec/CHECKSUMS.txt SHA-256 of everything vendored under spec/. Asserted every run.
spec/vectors/ The frozen §15 corpus, vendored verbatim: 6 files, 88 vectors
src/main/java/…/nuntius/ The library, one package
src/test/java/…/nuntius/ Tests, same package (so they can see package-private internals)
src/test/resources/synthetic-vectors/
Synthetic fixtures for the §15.5 envelope rules. NOT vectors.
The library is a single flat package on purpose: SecretBytes.array()