capsule

Demos

Try three parts of capsule in this page.

Nothing here is a mock-up. The dashboard is the page capsule serves, the levels follow the code's own rules, and the cipher is computed in your browser and checked against the answers the Go code gives.

The dashboard, on recorded telemetry

Open it full size

Ten capsules ran on a test host while faults were injected: loops that spin, leaks, crashes, a disk filling. This is what capsule dashboard shows of them. Pick a capsule, change the period, move the pointer over a chart.

On a host the page reads again every five seconds. Here it answers from a recording whose times are moved to now, so it does not advance.

What still holds when a kind of mathematics falls

capsule never rests on one scheme. Choose a key level, then give the attacker what you fear they will have one day. A signature is forged, or a capsule's key opened, only when every wall of that level is down.

The attacker can

None of this helps once a host's own secret is taken from it: whoever holds that is the host. The walls are about what an attacker can do from outside, including with traffic and seals recorded today and a better computer later.

capsule's own cipher, computed here

A small neural network in whole numbers: twelve layers of eight units. Its weights are the key. Fed a counter, it gives 64 bytes of keystream per block. capsule seal -outer lays it over an encrypted capsule's AES-256-GCM. Since 0.15.0 this is version 2: two number systems instead of one, a 512-bit key, a nonce for each archive, and a tag of its own.

Do not protect anything with this. Nobody but its author has tried to break it. In capsule it is only ever a layer over AES-256-GCM, under a separate key, so that it can add a wall and never take one away. This page lets you see it work; it is not a tool for encrypting. If you would like to try breaking it, there is a specification and a challenge.

How it works

  1. One key becomes two. Every sealed capsule gets a content key of its own, 64 bytes. HKDF-SHA-512 draws two keys out of it under different names: one for AES, one of 512 bits for this cipher. Knowing either tells nothing of the other.
  2. AES-256-GCM goes first, exactly as without -outer. What comes out is already ciphertext, and already checked against change.
  3. The key and a nonce become a network. SHAKE-256 stretches them into 892 numbers: the weights and biases of twelve layers of eight units. Nothing is trained and no model is shipped. Another key is another network, and the nonce, new for every archive, makes it another one each time.
  4. The network is fed a counter, and counts in two ways. Even layers work modulo 264 and bend every sum with v·(2v+1), a rotation and a shift. Odd layers work modulo the prime 264−59 and bend with the cube. Every layer can be undone; none loses anything.
  5. The input is added back to the last layer, which makes the whole a step that cannot be run backwards even with the key. That gives 64 bytes.
  6. Those bytes are XORed onto the AES ciphertext, and a tag of 32 bytes over the whole archive, made with the same network, is put at its end. Opening takes this layer off, then AES checks and decrypts as always, then the tag is compared.
content key AES key outer key + nonce HKDF, two names the files AES-256-GCMthe standard 12 × 8 networktwo number systemsturn by turn XOR 64 bytes a block + nonce, + tag rootfs.enc
Solid green: published standards. Dashed: capsule's own layer, under a key of its own.
Why two number systems?Modulo 264, the low bits of a product never hear from the high ones. Modulo a prime there are no bits at all, but everything is a polynomial. Each is close to arbitrary in the other's terms, so an attack has to carry its pattern through both.
How long would a quantum computer need?For the key, 512 bits: about 2256 steps of Grover's algorithm, one after another. On a host of level 7 or 9 the way the key travels is as wide: the host's secret, the secret it shares and the wrap all have 512 bits. An attack on the design itself is the real question, and it is open.
Why is adding it safe?Its input is ciphertext and its key is separate. Take the layer away entirely and what is left is the archive AES made, checked as before. A weak outer cipher costs nothing.
What does the tag do?Four polynomials over the prime field, each in a secret point, are taken over the archive and put through the network. A changed, shortened or lengthened archive gives another tag. AES-GCM underneath notices too, and first.
What changed from version 1?One number system became two, 6 layers became 12, the key went from 256 to 512 bits, and a nonce and a tag were added. Version 1's matrices also lost 7 bits a layer; these lose none. What version 1 sealed still opens.
Why is it written twice?In Go inside capsule, and in Rust as a program beside it, with no dependencies. The Rust one is about twice as fast (259 against 117 MB/s on a four-core server) and capsule uses it when it is installed. Two implementations that must agree on every byte also check each other.
What is not claimed?That it is strong. Its statistics are those of noise from 2 of its 12 layers on, and four implementations (Go, Rust, Python and this page) agree on every byte. Only people trying to break it could show more, and nobody has yet.

Try it

Checking this page's arithmetic against the Go code's known answers…

In capsule the key is drawn from the capsule's content key with HKDF, never typed.

The network on this block

The top row is the input, then one row per layer; one square per unit. Rows marked 2⁶⁴ count modulo 264, rows marked p modulo the prime. A square is filled by how large its number is; the two characters are its highest byte. Pick a square to see its arithmetic.

The 64 bytes it gives

Since the last change

Change the key, the nonce or the block to see how many of the 512 bits turn over. A cipher should turn about half.

How it is built, and what is and is not claimed for it: the README. The specification has everything needed to implement or attack it; the code is outer2.go, and there is a challenge with keystream under keys nobody has.

On a machine of your own

The repository has scripts that make their own capsules in a temporary folder, show each step as it happens, and remove everything when they end. They need a Linux host with capsule installed and busybox.

A recording of what demo/first.sh prints, step by step