Encryption keys that change during a transfer with no pause

7 min read | KEIBIDROP Series | November 2026

By Marius-Florin Cristian

KEIBIDROP changes the key of a session while a transfer runs: the writer moves to the next key on its own frame and writes the new epoch into that frame's nonce, so the reader follows on the same frame and no frame waits for a round trip. Once per connection an ephemeral post-quantum exchange, the fold, adds fresh key material to every lane. On an Intel MacBook Pro, two peers in one process with no network read a 64 MiB file in 256 KiB reads while the key was forced to rotate every 1 MiB. The 63 reads that coincided with a rotation took 2.36 ms at the median against 2.18 ms for the other 193, and the slowest read took 4.2 ms. A 32 MiB clip paced at 40 Mbps crossed 9 rotations with no underrun; its slowest fetch took 171 ms against a 2 s buffer. One run of each test, 21 July 2026.

The writer moves to the next key on its own frame, and the nonce tells the reader

The rotation happens in band: each direction of each lane counts its own bytes, messages and seconds, and when one of them reaches its threshold the writer derives the next key and uses it on its very next frame. Press Play, or step through it with Next and Back, the arrow keys or space. Every step is written out below the drawing, so the page reads the same without scripts.

Writer Reader threshold due next key, old wiped frame, new epoch in nonce same key, no wait fold request fold answer, about 3.2 KB staged, all lanes staged, all lanes new handshake, epoch 0

  1. One direction of a lane reaches a threshold: 1 GiB sent, 2^20 messages, or 60 s since its last rotation (secureconn.go).
  2. The writer derives the next chain key and message key with HKDF-SHA512, salted with its 4-byte direction prefix and the new 2-byte epoch, and wipes the old keys (ratchet.go).
  3. The writer seals its next frame with the new message key and writes the new epoch into bytes 4 and 5 of that frame's 12-byte nonce.
  4. The reader sees the higher epoch in the nonce, derives the same keys itself and opens the frame, so no frame waits for a round trip.
  5. Once per connection, the device with the lower fingerprint sends an ephemeral ML-KEM-1024 key and an ephemeral X25519 key over the Rekey call (fold.go).
  6. The other device answers with the ML-KEM ciphertext and its own X25519 key, about 3.2 KB for the two messages together.
  7. Both devices stage the new secret on the TCP lane and on the QUIC lane, where it enters the chain at that lane's next rotation.
  8. Near the end of the 16-bit epoch space, an idle session runs a new handshake and starts again at epoch 0.

Marius put the design goal in one breath in his Pass the SALT talk:

"And also I rekey either at 1 million messages that happen or at one gigabyte transferred. So basically there should not be any catastrophic nonce reuse."

One direction of one lane, frame by frame, shows where the epoch lives

The drawing below plays the same mechanism at the level of single frames, as the architecture map shows it: each key epoch has its own colour, a dashed frame is the first one under a fold, and the nonce at the bottom shows the prefix, the epoch and the counter of the frame in flight.

The writer moves to the next key on its own frame and puts the epoch in the nonce; the reader follows on the first frame of the new epoch, and a staged fold rotates on the very next frame. Writer SecureConn.Write Reader openRatcheted one direction of one lane writer keys reader keys bytes messages time A threshold rotates the key, and a staged fold rotates it first. Demo scale: the bars fill in a few frames. the nonce of the last frame sent e0:57 e1:1 CK0 CK1+fold CK0 4F 55 54 42 00 01 00 00 00 00 00 01 prefix "OUTB" epoch 1 counter 1

The writer has just rotated on frame e1:1, under the fold. Its old chain key is wiped. The reader still holds CK0 and follows when that frame arrives with epoch 1 in its nonce.

One direction of one lane, frame by frame. Each key epoch has its own colour; a dashed frame is the first one under a fold.

The nonce carries the direction, the epoch and the counter in 12 bytes

Every frame on the wire is a length, a 12-byte nonce, the ciphertext and a 16-byte tag. The nonce is built in symmetric.go from a 4-byte direction prefix and one 64-bit value that holds the 16-bit epoch above a 48-bit counter, so a new epoch changes the nonce and the key together and two directions never share nonce space.

Bytes of the nonceFieldWhat it holds
0 to 3direction prefixOUTB on one side's outbound frames and INBD on the other's, so the two directions never collide
4 and 5epochthe key generation, big-endian; the reader moves to the next key when it rises
6 to 11counterthe frame number inside the epoch, 48 bits

The thresholds bound every key by bytes, messages and time

The table below lists the limits in the code at the tag v0.5.1, read from the code as constants and rules; the 0.6.0 pull request keeps the same values.

LimitValueWhere
Bytes on one direction before a rotation1 GiBdefaultRekeyBytes, secureconn.go
Messages on one direction before a rotation2^20, about a milliondefaultRekeyMsgs
Time on a quiet direction before a rotation60 sRekeyTimeCadence
Epochs per session16 bits; a new handshake starts a little below the limitepochRehandshakeThreshold
The fold exchangeabout 3.2 KB: 1,568 bytes of ML-KEM-1024 key and 32 of X25519 one way, 1,568 of ciphertext and 32 backfold.go; sizes from FIPS 203, Table 3

The keys come from HKDF over SHA-512, the construction of RFC 5869:

"HKDF follows the "extract-then-expand" paradigm, where the KDF logically consists of two modules."

H. Krawczyk and P. Eronen, RFC 5869, checked on 30 November 2026

A rotation added a fraction of a millisecond to a read during playback

We forced a rotation every 1 MiB so that a short file crosses many epochs, which is a test setting: the product rotates after 1 GiB or about a million messages. On an Intel MacBook Pro, two peers in one process with no network read a 64 MiB file in 256 KiB reads, and the 63 reads that coincided with a rotation took 2.36 ms at the median against 2.18 ms for the other 193, with the slowest read at 4.2 ms. A 32 MiB clip paced at 40 Mbps crossed 9 rotations with no underrun, and its slowest fetch took 171 ms against a 2 s buffer. One run of each test, 21 July 2026, on the loopback, so the figures say what a rotation adds to a read on one machine and nothing about a WAN.

Limits. The handshake alone is not forward-secret: frames sent before a direction folds rest on the handshake keys, and the fold is what makes the session forward-secret.

The fold is best effort. If it fails or times out, the session stays on the plain ratchet over the handshake key until the next connect or reconnect, when the device with the lower fingerprint runs a new fold.

The measurement is one machine with no network and one run of each test; a rerun at the 0.6.0 tag is one command, because both tests are in the tree.

A key that leaks later opens nothing that was sent before

What does forward secrecy mean?

A key that leaks later cannot open traffic that was recorded earlier. In KEIBIDROP the ratchet wipes each old key as it moves on, and the fold adds a secret that never crossed the network in the handshake, so frames sent before a leak stay closed.

What is secret key rotation?

Replacing a key while it is in use. Here each direction of each lane rotates on its own frame after 1 GiB, 2^20 messages or 60 s, and the reader learns the change from the epoch in the frame's nonce.

What are the best practices for encryption key rotation?

Three rules carry this design: rotate on volume and on time, keep every nonce unique under its key, and let the receiver learn about the change from the data itself, so that no frame waits for an agreement.

Checked on 30 November 2026 against KEIBIDROP 0.5.1 and the 0.6.0 pull request.

Related: how KEIBIDROP works, the series by theme, rekey while the video plays, across TCP and QUIC, forward secrecy: automatic key rotation during sessions, the security model on keibidrop.com