Engineering5 min read
How we test our encryption in four languages
We wrote UIMessage’s encryption protocol in Swift, Kotlin, TypeScript and Go, and all four run the same test vectors and whole-device scenarios. In some, a test server breaks the rules on purpose, and each must refuse.
UIMessage runs one encryption protocol on every app, and we wrote it four times. Each app is written mainly in its platform’s language, and so is its protocol code. The iPhone, iPad and Mac apps run the Swift implementation, the Android app runs Kotlin, and UIMessage Web runs TypeScript. In Go, we keep a reference implementation for testing, and our servers use a package with the protocol checks they need.
Four separate implementations have to agree exactly. When the Kotlin code on an Android phone encrypts a message, the Swift code on an iPhone must open it. Your browser has to accept the device list your phone signed, and refuse one it didn’t. So all four run one set of test vectors and the same whole-device scenarios, and must reach the same results.
Two programs make the test vectors, and a third checks them
Two generators, one written in Go and one in Node.js, each produce the shared test vector file, and their outputs match byte for byte. A third program checks the file again with CryptoKit, and all 169 of its checks pass. Five pieces of code then run it: the Go reference, the server’s Go package, the Swift core, UIMessage Web and Android’s crypto core.
- Implementations of our encryption protocol: Swift, Kotlin, TypeScript and Go
- 4
- Whole-device scenarios, each run by all four
- 29
- Shared test vectors, in one file every implementation reads
- 217,888bytes
- Signature edge cases in that file
- 28
Our own code, on standard building blocks
Our messaging encryption is our own code, written for each platform, and we don’t use a messaging-protocol library. Each implementation stands on standard cryptographic building blocks:
- iPhone, iPad and Mac: CryptoKit, Apple’s cryptography framework.
- Go: the standard library and golang.org/x/crypto.
- UIMessage Web: the @noble libraries and an ML-KEM of our own.
- Android: the platform’s ChaCha20-Poly1305, P-256 and SHA-2, beside our own Ed25519, Poly1305, SHA-3 and ML-KEM. Our own X25519 runs on Android 12, and Android 13 and later switch to the platform’s once it passes a self-check.
X25519 and ML-KEM set up shared keys, Ed25519 and P-256 make signatures, ChaCha20-Poly1305 encrypts, with Poly1305 as its tamper check, and SHA-2 and SHA-3 are hash functions. We wrote a building block ourselves where the platform has none we can use, working from its public standard.
The design follows four specifications Signal published: X3DH, its post-quantum upgrade PQXDH, the Double Ratchet and Sesame12. PQXDH sets up a session between two devices, the Double Ratchet gives every message its own key, and Sesame keeps a separate session with each device in a conversation.
One set of test vectors for every platform
A test vector is a fixed input paired with the exact output that correct code must produce. Ours are in one file of 217,888 bytes, and every implementation reads that same file.
Two independent generators produce the file, one written in Go and one in Node.js, and their outputs match byte for byte. The Go one uses Go’s standard library and golang.org/x/crypto; the Node.js one uses the @noble libraries and an ML-KEM we wrote from the standard. A mistake in only one of them would show up as a difference between the two files.
Each generator also works out every verdict in the file with its own code, and stops if one differs from what its case was built to show. A third program then checks the file again, using CryptoKit for all of its cryptography. It reproduces the X25519 and ChaCha20-Poly1305 results, derives the ML-KEM keys and verifies the signatures. All 169 of its checks pass.
The file includes 28 signature edge cases, 19 for P-256 and nine for Ed25519. Most use an unusual signature or key, and each says whether every implementation must accept or refuse it.
Five pieces of code run the file: the four implementations and the Go package on our servers. The Go reference adds a mutation check, which changes each value in turn and fails if no test notices.
| Implementation | Shared vectors | Whole-device scenarios | Other checks |
|---|---|---|---|
| Go reference | Yes, with the mutation check | Yes | |
| Server (Go) | Yes | ||
| Swift core (iPhone, iPad, Mac) | Yes | Yes | |
| iPhone app | Its own vector tests for linking, large media, safety numbers and call encryption | ||
| UIMessage Web (TypeScript) | Yes | Yes | ML-KEM known-answer tests |
| Android crypto core (Kotlin) | Yes | Yes | Wycheproof; ML-KEM known-answer tests |
Our iPhone, iPad and Mac apps take their protocol code from the Swift core, so its run of the shared vectors tests the code those apps use. The iPhone app also runs vector tests of its own, for linking, large media, safety numbers and call encryption.
Whole devices against a test server
Our test vectors pin down values to the byte, while our 29 scenarios check behavior by driving whole devices against a test server. The Go reference and the Swift, TypeScript and Kotlin cores run every one of them.
A scenario is a file: a few accounts with their devices, followed by steps that act and then check the results. Its random choices come from a seed, so a run can be repeated step for step.
Every implementation runs the same files with its own code. They don’t have to produce the same bytes, but they must reach the same outcomes: the same result codes, the same things shown and the same counts.
In some scenarios, the test server breaks the rules on purpose, and the apps must refuse. Together with the shared vectors, the scenarios hold every implementation to these checks:
| When it’s about to… | Every app checks |
|---|---|
| Encrypt to a device | that the device is on the list the account’s phone signed, at the newest version the app has seen |
| Give a group member a key | that they’re in the group’s signed record |
| Accept a change to a group | that it’s signed by the device that made it, and linked by its hash to the change before it |
| Open a message | that it decrypts in the chat and under the message id it was sent with |
| Let someone join by link | that they signed with the link’s secret, and that the link was made after any removal of them |
| Send after you remove a device | that the device is off your signed list, so nothing is encrypted to it |
Extra checks on Android and the web
We wrote building blocks of our own for Android and UIMessage Web, so both also run public test sets. On Android, our own building blocks run the Wycheproof tests, a public collection of test cases for cryptographic code. Both of our ML-KEM implementations, in Kotlin and TypeScript, run ML-KEM known-answer tests: public inputs, each paired with the output a correct implementation must give.
Android’s build also checks every library we declare, and every one the app ships, against an allow-list. The files of every library the build uses must also match the SHA-256 hashes we recorded. A library that isn’t on the list, or whose file has changed, fails the check.
The checks run on every change
The vector checks run on every change to our main code line. That includes the shared vectors in all five pieces of code that run them, the scenarios in all four implementations and the Go reference’s mutation check. The iPhone app’s own vector tests, the Wycheproof tests and the ML-KEM known-answer tests run alongside them.
Sources
- 1.Signal, Quantum resistance and the Signal Protocol (opens in a new tab), Sep 19, 2023. Checked Nov 2026. 1
- 2.Signal, The Sesame algorithm: session management for asynchronous message encryption (opens in a new tab). Checked Nov 2026. 1
More from the newsroom
Security
How UIMessage compares with WhatsApp, Signal, iMessage and Telegram
A feature-by-feature comparison built from each app’s own documents: where UIMessage is ahead, where it’s level, and where other apps do more.
Security
What our servers keep, and for how long
Our servers delete each encrypted message once the devices it was sent to have saved it. This is what else they keep, for how long, and which three companies handle some of your information for us.
Security
How we protect your calls
Every audio and video frame is encrypted on your device before it leaves. Our relays carry calls they can’t decode, and when you call someone outside your contacts, they never see your IP address.