This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Katzenpost Documentation

ANSI wizard casting a spell, by Zeus

For users

Client applications, packages, and a public mixnet.

Title Description
🐈 Namenlos public mixnet A public Katzenpost mix network that anyone may use, without the burden of operating their own. katzenqt connects to it out of the box; live network health is on the status page.
💬 katzenqt group chat A decentralised group chat application running over the Katzenpost mix network and the Pigeonhole storage services. Pre-built packages forthcoming. Build and run from source in the meantime.

For operators

You wish to run your own Katzenpost mix network with friends and collaborators.

Title Description
📖 Admin Guide Deploying and operating Katzenpost servers: installation, configuration, the Docker test mixnet, NAT considerations, and a full configuration appendix.
🐳 Run a Mix Server in Docker A focused recipe for running a single Katzenpost mix server inside a Docker container, intended for operators who wish to participate in an existing mix network.
🔧 Build from source Pinned versions of the Katzenpost stack and brief instructions for building the components users and operators run (kpclientd, katzenqt, server-side) from source.

For application developers

You wish to build software that integrates with Katzenpost.

Title Description
📘 Thin Client API Reference Complete API reference for the Go, Rust, and Python thin client libraries.
📗 Thin Client How-to Guide Task-oriented guides for accomplishing common operations with the thin client API.
🧭 Pigeonhole Protocols How-to Guide Building your own protocol or mixnet service with the pigeonhole_protocols library: when a plain channel is enough, why most protocols should ride on the group chat protocol, and how services bootstrap through the directory and voucher routers.
🕊️ Understanding Pigeonhole A high-level introduction to the Pigeonhole anonymous storage protocol for application developers.
📌 Pinned versions The single source of truth for the mutually compatible set of release tags across the katzenpost, thin_client, and katzenqt repositories.

For core developers

You wish to contribute code to Katzenpost itself.

Title Description
🛠️ Design Specifications The protocol specifications that the implementation must honour: Sphinx, KEMSphinx, the wire protocol, the directory authority, replay detection, and more.
📝 Writing READMEs The checklist every Katzenpost repository README follows: audience first, a quick start, then links out to the rest of the documentation.
Source Repository The Katzenpost monorepo on GitHub: server, dirauth, client, courier, replica, and core. Issues, pull requests, and discussions live here.

For academics

You are a mathematician, computer scientist, security researcher, or hacker investigating the design.

Read in the order below. Seasoned mixnet researchers may skip ahead to the Echomix paper.

Title Description
📚 1. Literature Review (last updated April 2024) Start here if you are new to mixnet research. Field context, attack taxonomy, and the conceptual positions the Echomix paper builds on.
arXiv 2. Echomix paper Echomix: a Strong Anonymity System with Messaging. Katzenpost’s design, presented as research (arXiv).
🔒 3. Threat Model (PDF) Detailed security assumptions and mitigations specific to the deployed system.

Supplementary reading:

Title Description
🎧 Audio Engineering Considerations (PDF) A technical report on the challenges of carrying voice traffic through a modern mix network, with attention to usability and scalability.

1 -

Administration guide

Use the documentation in this section to explore how the mixnet works and to implement your own.

Title Description Link(s)
📖 Admin Guide Detailed guide for deploying and managing Katzenpost servers, including setting up a local Docker-based mixnet. PDF

1.1 -

Quickstart guide

Quickstart guide


This topic provides collects basic commands for installed Katzenpost server components in a single convenient place. All system commands require superuser privileges.

The commands in this topic do not apply to the Katzenpost Docker image, which has its own controls. For more information, see Using the Katzenpost Docker test network.

Systemd commands

These commands match the suggested systemd setup described in Installing Katzenpost.

Table 1. Systemd control commands for Katzenpost

Task

Command

Start a mix node.

systemctl start katzenpost-mixserver

Stop a mix node.

systemctl stop katzenpost-mixserver

Restart a mix node.

systemctl restart katzenpost-mixserver

Start a directory authority node.

systemctl start katzenpost-authority

Stop a directory authority node.

systemctl stop katzenpost-authority

Restart a directory authority node.

systemctl restart katzenpost-authority


Server CLI commands

The primary Katzenpost server binaries are katzenpost-mixserver, which instantiates a mix node, gateway node, or service provider depending on its configuration, and katzenpost-authority, which instantiates a directory authority.

Table 2. Command options for the Katzenpost server binaries

Task

Command

Control a mix node.

Run katzenpost-mixserver -h for options.

$ katzenpost-mixserver -h
Usage of katzenpost-mixserver:
  -f string
    	Path to the authority config file. (default "katzenpost.toml")
  -g	Generate the keys and exit immediately.
  -v	Get version info.

The -f parameter can be used to specify a customized path and filename for the server configuration file, which is typically /etc/katzenpost-mixserver/katzenpost.toml.

The -g option is used to generate the public and private signing and link keys. By default, these must be manually copied to the directory defined by the DataDir parameter in /etc/katzenpost-mixserver/katzenpost.toml.

Control a directory authority.

Run katzenpost-authority -h for options.

$ katzenpost-authority -h
Usage of katzenpost-authority:
  -f string
    	Path to the authority config file. (default "authority.toml")
  -g	Generate the keys and exit immediately.
  -v	Get version info.

The -f parameter can be used to specify a customized path and filename for the server configuration file, which is typically /etc/katzenpost-authority/authority.toml.

The -g option is used to generate the public and private signing and link keys. By default, these must be manually copied to the directory defined by the DataDir parameter in /etc/katzenpost-authority/authority.toml.


Management interface

Katzenpost provides a management interface that is accessed through a unix domain socket. The interface supports run-time changes to nodes without requiring a restart. By default, the management interface is disabled. To enable it, change the Management section of the node's configuration file so that Enable = true:

[Management]
   Enable = true
   Path = "/node_datadir/management_sock"

For more information about management configuration, see the details for your node type in Components and configuration of the Katzenpost mixnet.

Use the socat command-line utility to connect to the management socket and issue commands, with the following syntax:

# socat unix:/node-datadir/management_sock STDOUT

The following commands are supported.

  • QUIT - Exit the management socket session.

  • SHUTDOWN - Shut down the server gracefully.

  • ADD_USER - Add a user and associate it with a public link key provided in either hexadecimal or Base64 format.

    ADD_USER userkey
  • UPDATE_USER - Update a user's link key.

    UPDATE_USER userkey
  • REMOVE_USER - Remove a user.

    REMOVE_USER user
  • SET_USER_IDENTITY - Set a user's identity key.

    SET_USER_IDENTITY userkey
  • REMOVE_USER_IDENTITY - Remove a user's identity key. This command must be followed up with a REMOVE_USER command.

    REMOVE_USER_IDENTITY user
  • USER_IDENTITY - Retrieve a user's identity key.

    USER_IDENTITY user
  • SEND_RATE - Set the packet rate limit to a per-minute integer value.

    SEND_RATE value
  • SEND_BURST - Set the packet burst-rate limit to a per-minute integer value.

    SEND_BURST value

Monitoring

Katzenpost logging information can be viewed in real time with the following commands:

# journalctl -u katzenpost-mixserver -f -n 2000

or

# journalctl -u katzenpost-authority -f -n 2000

Logging levels include ERROR, WARNING, NOTICE, INFO, and DEBUG, with INFO as the default. For information about setting the log level, see the documentation for each node type in Components and configuration of the Katzenpost mixnet.

1.2 -

Installing Katzenpost

Installing Katzenpost


The section provides an overview of how to download Katzenpost, set up a development environment, build the code, install the Katzenpost binaries, and configure the components.

Requirements

An up-to-date Debian or Ubuntu Linux system is assumed as the build and hosting environment for all Katzenpost server-side components. Required packages include the following:

  • git

  • gcc

  • build-essential

  • libc-dev-bin

Obtain the Katzenpost code

Complete the following steps to set up a local Katzenpost git repository.

  1. Clone Katzenpost.

    $ git clone git@github.com:katzenpost/katzenpost.git

  2. Get the latest tagged commit of the Katzenpost with the following commands.

    $ git fetch --tags$ tag=$(git describe --tags `git rev-list --tags --max-count=1`)$ git checkout $tag

Install the latest Go version

Download the latest version of the Go programming language from https://go.dev/dl and unzip it in a suitable location. As root, set the necessary environment variables:

# export PATH=$PATH:/<your Go location>/bin# export GO111MODULE=on# export CGO_CFLAGS_ALLOW="-DPARAMS=sphincs-shake-256f"

The go/bin path must be included in your user $PATH environment variable.

[Note] Note

Do not use the Debian/Ubuntu golang packages. They are probably too old.

Build server components

To build a Katzenpost server component, navigate to the directory containing its source code and run go build. The paths shown are relative to the Katzenpost repository root.

Table 1. Server component directories

Component Source code directory Binary
Mix, gateway, or service node server/cmd/server/ server
Directory authority authority/cmd/dirauth/ dirauth

Build clients

The Katzenpost client components are useful for testing an operational mixnet. To build them, navigate to the directory containing each component's source code and run go build. The paths shown are relative to the Katzenpost repository root.

[Note] Note

The Katzen chat client is under development and not currently functional. For more information about the clients generally, see Clients.

Table 2. Client directories

Component Source code directory Binary or application

Ping

ping/ ping

Fetch

authority/cmd/fetch/

fetch

Status

Obtain from GitHub repository katzenpost/status. status.py

Worldmap

Obtain from GitHub repository katzenpost/worldmap world_map.py

Install the server components

To install the server binaries, run the following commands from the katzenpost repository root.

# cp server/cmd/server/server /usr/local/bin/katzenpost-mixserver
# cp authority/cmd/dirauth/dirauth /usr/local/bin/katzenpost-authority

Create service accounts

Create a service account account for each of the node types that you deploy.

To create a service user for a directory authority. 

# adduser \
    --disabled-login \
    --disabled-password \ 
    --system \
    --group \
    --home /var/lib/katzenpost-authority \
    katzenpost-authority

To create a service user for a mix, gateway, or service node. 

# adduser \
    --disabled-login \
    --disabled-password \ 
    --system \
    --group \
    --home /var/lib/katzenpost-mixserver \
    katzenpost-mixserver

Create configuration files

The best way currently to construct a node configuration file is to use one of the samples in Appendix: Configuration files from the Docker test mixnet, and to modify it based on the published component parameters, combined with attention to the latest state of the code tree. Bear in mind that the IP address:port scheme used in the Docker image is specific to that container environment, and is not transferable to a production network without modification.

Katzenpost currently has no configuration automation tool that is ready for general use.

Configure systemd

If you are running your Katzenpost components under systemd, create and install a systemd service file for each node type that you plan to deploy. The following scripts are examples of how to do this.

To create a systemd service file for a directory authority. 

#!/bin/bash -x

cat << EOF > /etc/systemd/system/katzenpost-mixserver.service
[Unit]
Description=Katzenpost Mix Server
After=network.target

[Service]
IPAccounting=yes
Type=simple
User=katzenpost-mixserver
WorkingDirectory=/var/lib/katzenpost-mixserver
ExecStart=/usr/local/bin/katzenpost-mixserver -f /etc/katzenpost-mixserver/katzenpost.toml
PrivateTmp=yes
NoNewPrivileges=yes
# RestartSec=5
Restart=on-failure

[Install]
WantedBy=default.target
EOF

To create a systemd service file for a mix, gateway, or service node. 

#!/bin/bash -x

cat << EOF > /etc/systemd/system/katzenpost-authority.service
[Unit]
Description=Katzenpost Authority
After=network.target

[Service]
Type=simple
IPAccounting=yes
User=katzenpost-authority
WorkingDirectory=/var/lib/katzenpost-authority
ExecStart=/usr/local/bin/katzenpost-authority -f /etc/katzenpost-authority/authority.toml
PrivateTmp=yes
NoNewPrivileges=yes
Restart=on-failure

[Install]
WantedBy=default.target
EOF

Generate keys

The first time that you run a server binary directly or using systemd, identity and encryption keys are automatically generated and installed if they are not already present. The key location is specified by the value of DataDir in the [Server] section of the configuration. For configuration parameter details, see Components and configuration of the Katzenpost mixnet. For server binary commandline options, see the Quickstart guide.

Once the keys are in place, restart the server to begin operations.

1.3 -

Using the Katzenpost Docker test network

Using the Katzenpost Docker test network


Katzenpost provides a ready-to-deploy Docker image for developers who need a non-production test environment for developing and testing client applications and server side plugins. By running this image on a single computer, you avoid the need to build and manage a complex multi-node mix net. The image can also be run using Podman

The test mix network includes the following components:

  • Three directory authority (PKI) nodes

  • Six mix nodes, including one node serving also as both gateway and service provider

  • A ping utility, run-ping

Requirements

Before running the Katzenpost docker image, make sure that the following software is installed.

On Debian/Ubuntu, these software requirements can be installed with the following commands (running as superuser). Apt will pull in the needed dependencies.

# apt update# apt install git golang make podman podman-compose

Note: You can also install Docker and docker-compose instead of Podman, but Podman is recommended as it runs rootless by default.

Preparing to run the container image

Complete the following procedure to obtain, build, and deploy the Katzenpost test network.

  1. Install the Katzenpost code repository, hosted at https://github.com/katzenpost. The main Katzenpost repository contains code for the server components as well as the docker image. Clone the repository with the following command (your directory location may vary):

    ~$ git clone https://github.com/katzenpost/katzenpost.git
  2. Navigate to the new katzenpost subdirectory and ensure that the code is up to date.

    ~$ cd katzenpost~/katzenpost$ git checkout main~/katzenpost$ git pull

  3. (Optional) Create a development branch and check it out.

    ~/katzenpost$ git checkout -b devel

  4. (Optional) If you are using Podman, enable the Podman socket service:

    1. Enable and start the Podman socket service (as regular user, no superuser privileges needed):

      $ systemctl --user enable --now podman.socket
    [Note] Note

    Modern Podman automatically handles the DOCKER_HOST environment variable and socket configuration. The Makefile will detect and use Podman automatically.

Operating the test mixnet

Navigate to katzenpost/docker. The Makefile contains target operations to create, manage, and test the self-contained Katzenpost container network. To invoke a target, run a command with the using the following pattern:

~/katzenpost/docker$ make target

Running make with no target specified returns a list of available targets.

Table 1. Table 1: Makefile targets

[none]

Display this list of targets.

start

Run the test network in the background.

stop

Stop the test network.

wait

Wait for the test network to have consensus.

watch

Display live log entries until Ctrl-C.

status

Show test network consensus status.

show-latest-vote

Show latest consensus vote.

run-ping

Send a ping over the test network.

clean-bin

Stop all components and delete binaries.

clean-local

Stop all components, delete binaries, and delete data.

clean-local-dryrun

Show what clean-local would delete.

clean

Same as clean-local, but also deletes go_deps image.


Starting and monitoring the mixnet

The first time that you run make start, the Docker image is downloaded, built, installed, and started. This takes several minutes. When the build is complete, the command exits while the network remains running in the background.

~/katzenpost/docker$ make start

Subsequent runs of make start either start or restart the network without building the components from scratch. The exception to this is when you delete any of the Katzenpost binaries (dirauth.alpine, server.alpine, etc.). In that case, make start rebuilds just the parts of the network dependent on the deleted binary. For more information about the files created during the Docker build, see the section called “Network topology and components”.

[Note] Note

When running make start , be aware of the following considerations:

  • If you are using Podman (recommended), no superuser privileges are required. Simply run make start as a regular user.

  • If you intend to use Docker instead of Podman, you may need to run make as superuser depending on your Docker configuration. You can override the automatic Podman selection by adding the argument docker=docker to the command:

    ~/katzenpost/docker$ make start docker=docker

After the make start command exits, the mixnet runs in the background, and you can run make watch to display a live log of the network activity.

~/katzenpost/docker$ make watch
    ...
    <output>
    ...

When installation is complete, the mix servers vote and reach a consensus. You can use the wait target to wait for the mixnet to get consensus and be ready to use. This can also take several minutes:

~/katzenpost/docker$ make wait
    ...
    <output>
    ...

You can confirm that installation and configuration are complete by issuing the status command from the same or another terminal. When the network is ready for use, status begins returning consensus information similar to the following:

~/katzenpost/docker$ make status
    ...
    00:15:15.003 NOTI state: Consensus made for epoch 1851128 with 3/3 signatures: &{Epoch: 1851128 GenesisEpoch: 1851118
    ...

Testing the mixnet

At this point, you should have a locally running mix network. You can test whether it is working correctly by using run-ping, which launches a packet into the network and watches for a successful reply. Run the following command:

~/katzenpost/docker$ make run-ping

If the network is functioning properly, the resulting output contains lines similar to the following:

19:29:53.541 INFO gateway1_client: sending loop decoy
    !19:29:54.108 INFO gateway1_client: sending loop decoy
    19:29:54.632 INFO gateway1_client: sending loop decoy
    19:29:55.160 INFO gateway1_client: sending loop decoy
    !19:29:56.071 INFO gateway1_client: sending loop decoy
    !19:29:59.173 INFO gateway1_client: sending loop decoy
    !Success rate is 100.000000 percent 10/10)

lf run-ping fails to receive a reply, it eventually times out with an error message. If this happens, try the command again.

[Note] Note

If you attempt use run-ping too quickly after starting the mixnet, and consensus has not been reached, the utility may crash with an error message or hang indefinitely. If this happens, issue (if necessary) a Ctrl-C key sequence to abort, check the consensus status with the status command, and then retry run-ping.

Shutting down the mixnet

The mix network continues to run in the terminal where you started it until you issue a Ctrl-C key sequence, or until you issue the following command in another terminal:

~/katzenpost/docker$ make stop

When you stop the network, the binaries and data are left in place. This allows for a quick restart.

Uninstalling and cleaning up

Several command targets can be used to uninstall the Docker image and restore your system to a clean state. The following examples demonstrate the commands and their output.

  • clean-bin

    To stop the network and delete the compiled binaries, run the following command:

    ~/katzenpost/docker$ make clean-bin
        
        [ -e voting_mixnet ] && cd voting_mixnet && DOCKER_HOST=unix:///run/user/1000/podman/podman.sock docker-compose down --remove-orphans; rm -fv running.stamp
        Stopping voting_mixnet_auth3_1        ... done
        Stopping voting_mixnet_servicenode1_1 ... done
        Stopping voting_mixnet_metrics_1      ... done
        Stopping voting_mixnet_mix3_1         ... done
        Stopping voting_mixnet_auth2_1        ... done
        Stopping voting_mixnet_mix2_1         ... done
        Stopping voting_mixnet_gateway1_1     ... done
        Stopping voting_mixnet_auth1_1        ... done
        Stopping voting_mixnet_mix1_1         ... done
        Removing voting_mixnet_auth3_1        ... done
        Removing voting_mixnet_servicenode1_1 ... done
        Removing voting_mixnet_metrics_1      ... done
        Removing voting_mixnet_mix3_1         ... done
        Removing voting_mixnet_auth2_1        ... done
        Removing voting_mixnet_mix2_1         ... done
        Removing voting_mixnet_gateway1_1     ... done
        Removing voting_mixnet_auth1_1        ... done
        Removing voting_mixnet_mix1_1         ... done
        removed 'running.stamp'
        rm -vf ./voting_mixnet/*.alpine
        removed './voting_mixnet/echo_server.alpine'
        removed './voting_mixnet/fetch.alpine'
        removed './voting_mixnet/memspool.alpine'
        removed './voting_mixnet/panda_server.alpine'
        removed './voting_mixnet/pigeonhole.alpine'
        removed './voting_mixnet/ping.alpine'
        removed './voting_mixnet/reunion_katzenpost_server.alpine'
        removed './voting_mixnet/server.alpine'
        removed './voting_mixnet/voting.alpine'

    This command leaves in place the cryptographic keys, the state data, and the logs.

  • clean-local-dryrun

    To display a preview of what clean-local would remove, without actually deleting anything, run the following command:

    ~/katzenpost/docker$ make clean-local-dryrun
  • clean-local

    To delete both compiled binaries and data, run the following command:

    ~/katzenpost/docker$ make clean-local
                            
        [ -e voting_mixnet ] && cd voting_mixnet && DOCKER_HOST=unix:///run/user/1000/podman/podman.sock docker-compose down --remove-orphans; rm -fv running.stamp
        Removing voting_mixnet_mix2_1         ... done
        Removing voting_mixnet_auth1_1        ... done
        Removing voting_mixnet_auth2_1        ... done
        Removing voting_mixnet_gateway1_1     ... done
        Removing voting_mixnet_mix1_1         ... done
        Removing voting_mixnet_auth3_1        ... done
        Removing voting_mixnet_mix3_1         ... done
        Removing voting_mixnet_servicenode1_1 ... done
        Removing voting_mixnet_metrics_1      ... done
        removed 'running.stamp'
        rm -vf ./voting_mixnet/*.alpine
        removed './voting_mixnet/echo_server.alpine'
        removed './voting_mixnet/fetch.alpine'
        removed './voting_mixnet/memspool.alpine'
        removed './voting_mixnet/panda_server.alpine'
        removed './voting_mixnet/pigeonhole.alpine'
        removed './voting_mixnet/reunion_katzenpost_server.alpine'
        removed './voting_mixnet/server.alpine'
        removed './voting_mixnet/voting.alpine'
        git clean -f -x voting_mixnet
        Removing voting_mixnet/
        git status .
        On branch main
        Your branch is up to date with 'origin/main'.
  • clean

    To stop the the network and delete the binaries, the data, and the go_deps image, run the following command as superuser:

    ~/katzenpost/docker$ sudo make clean

Network topology and components

The Docker image deploys a working mixnet with all components and component groups needed to perform essential mixnet functions:

  • message mixing (including packet reordering, timing randomization, injection of decoy traffic, obfuscation of senders and receivers, and so on)

  • service provisioning

  • internal authentication and integrity monitoring

  • interfacing with external clients

[Warning] Warning

While suited for client development and testing, the test mixnet omits performance and security redundancies. Do not use it in production.

The following diagram illustrates the components and their network interactions. The gray blocks represent nodes, and the arrows represent information transfer.

Figure 1. Test network topology


On the left, the Client transmits a message (shown by purple arrows) through the Gateway node, across three mix node layers, to the Service node. The Service node processes the request and responds with a reply (shown by the green arrows) that traverses the mix node layers before exiting the mixnet via the Gateway node and arriving at the Client.

On the right, directory authorities Dirauth 1, Dirauth 2, and Dirauth 3 provide PKI services. The directory authorities receive mix descriptors from the other nodes, collate these into a consensus document containing validated network status and authentication materials , and make that available to the other nodes.

The elements in the topology diagram map to the mixnet's component nodes as shown in the following table. Note that all nodes share the same IP address (127.0.0.1, i.e., localhost), but are accessed through different ports. Each node type links to additional information in Components and configuration of the Katzenpost mixnet.

Table 2. Table 2: Test mixnet hosts

Node type Docker ID Diagram label IP address TCP port

Directory authority

auth1 Dirauth1

127.0.0.1 (localhost)

30001

auth2

Dirauth 2

30002

auth3

Dirauth 3

30003

Gateway node gateway1 Gateway node 30004

Service node

servicenode1

Service node

30006

Mix node

mix1

Layer 1 mix node

30008

mix2

Layer 2 mix node

30010

mix3

Layer 3 mix node

30012


The Docker file tree

The following tree output shows the location, relative to the katzenpost repository root, of the files created by the Docker build. During testing and use, you would normally touch only the TOML configuration file associated with each node, as highlighted in the listing. For help in understanding these files and a complete list of configuration options, follow the links in Table 2: Test mixnet hosts.

katzenpost/docker/voting_mixnet/
|---auth1
|   |---authority.toml
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---link.private.pem
|   |---link.public.pem
|   |---persistence.db
|---auth2
|   |---authority.toml
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---link.private.pem
|   |---link.public.pem
|   |---persistence.db
|---auth3
|   |---authority.toml
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---link.private.pem
|   |---link.public.pem
|   |---persistence.db
|---client
|   |---client.toml
|---client2
|   |---client.toml
|---dirauth.alpine
|---docker-compose.yml
|---echo_server.alpine
|---fetch.alpine
|---gateway1
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---katzenpost.toml
|   |---link.private.pem
|   |---link.public.pem
|   |---management_sock
|   |---spool.db
|   |---users.db
|---memspool.alpine
|---mix1
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---katzenpost.toml
|   |---link.private.pem
|   |---link.public.pem
|---mix2
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---katzenpost.toml
|   |---link.private.pem
|   |---link.public.pem
|---mix3
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---katzenpost.toml
|   |---link.private.pem
|   |---link.public.pem
|---panda_server.alpine
|---pigeonhole.alpine
|---ping.alpine
|---prometheus.yml
|---proxy_client.alpine
|---proxy_server.alpine
|---running.stamp
|---server.alpine
|---servicenode1
|   |---identity.private.pem
|   |---identity.public.pem
|   |---katzenpost.log
|   |---katzenpost.toml
|   |---link.private.pem
|   |---link.public.pem
|   |---management_sock
|   |---map.storage
|   |---memspool.13.log
|   |---memspool.storage
|   |---panda.25.log
|   |---panda.storage
|   |---pigeonHole.19.log
|   |---proxy.31.log
|---voting_mixnet

Examples of complete TOML configuration files are provided in Appendix: Configuration files from the Docker test mixnet.

1.4 -

Components and configuration of the Katzenpost mixnet

Components and configuration of the Katzenpost mixnet


This section of the Katzenpost technical documentation provides an introduction to the software components that make up Katzenpost and guidance on how to configure each component. The intended reader is a system administrator who wants to implement a working, production Katzenpost network.

For a quickly deployable, non-production test network (primarily for use by developers), Using the Katzenpost Docker test network.

Understanding the Katzenpost components

The core of Katzenpost consists of two program executables, dirauth and server. Running the dirauth command runs a directory authority node, or dirauth, that functions as part of the mixnet's public-key infrastructure (PKI). Running the server runs either a mix node, a gateway node, or a service node, depending on the configuration. Configuration settings are provided in an associated katzenpost-authority.toml or katzenpost.toml file respectively.

In addition to the server components, Katzenpost also supports connections to client applications hosted externally to the mix network and communicating with it through gateway nodes.

A model mix network is shown in Figure 1.

Figure 1. The pictured element types correspond to discrete client and server programs that Katzenpost requires to function.


The mix network contains an n-layer topology of mix-nodes, with three nodes per layer in this example. Sphinx packets traverse the network in one direction only. The gateway nodes allow clients to interact with the mix network. The service nodes provide mix network services that mix network clients can interact with. All messages sent by clients are handed to a connector daemon hosted on the client system, passed across the Internet to a gateway, and then relayed to a service node by way of the nine mix nodes. The service node sends its reply back across the mix-node layers to a gateway, which transmits it across the Internet to be received by the targeted client. The mix, gateway, and service nodes send mix descriptors to the dirauths and retrieve a consensus document from them, described below.

In addition to the server components, Katzenpost supports connections to client applications hosted externally to the mix network and communicating with it through gateway nodes and, in some cases, a client connector.

Directory authorities (dirauths)

Dirauths compose the decentralized public key infrastructure (PKI) that serves as the root of security for the entire mix network. Clients, mix nodes, gateways nodes, and service nodes rely on the PKI/dirauth system to maintain and sign an up-to-date consensus document, providing a view of the network including connection information and public cryptographic key materials and signatures.

Every 20 minutes (the current value for an epoch), each mix, gateway, and service node signs a mix descriptor and uploads it to the dirauths. The dirauths then vote on a new consensus document. If consensus is reached, each dirauth signs the document. Clients and nodes download the document as needed and verify the signatures. Consensus fails when 1/2 + 1 nodes fail, which yields greater fault tolerance than, for example, Byzantine Fault Tolerance, which fails when 1/3 + 1 of the nodes fail.

The PKI signature scheme is fully configurable by the dirauths. Our recommendation is to use a hybrid signature scheme consisting of classical Ed25519 and the post-quantum, stateless, hash-based signature scheme known as Sphincs+ (with the parameters: "sphincs-shake-256f"), which is designated in Katzenpost configurations as "Ed25519 Sphincs+". Examples are provided below.

Mix nodes

The mix node is the fundamental building block of the mix network.

Katzenpost mix nodes are arranged in a layered topology to achieve the best levels of anonymity and ease of analysis while being flexible enough to scale with traffic demands.

Gateway nodes

Gateway nodes provide external client access to the mix network. Because gateways are uniquely positioned to identify clients, they are designed to have as little information about client behavior as possible. Gateways are randomly selected and have no persistent relationship with clients and no knowledge of whether a client's packets are decoys or not. When client traffic through a gateway is slow, the node additionally generates decoy traffic.

Service nodes

Service nodes provide functionality requested by clients. They are logically positioned at the deepest point of the mix network, with incoming queries and outgoing replies both needing to traverse all n layers of mix nodes. A service node's functionality may involve storing messages, publishing information outside of the mixnet, interfacing with a blockchain node, and so on. Service nodes also process decoy packets.

Clients

Client applications should be designed so that the following conditions are met:

  • Separate service requests from a client are unlinkable. Repeating the same request may be lead to linkability.

  • Service nodes and clients have no persistent relationship.

  • Clients generate a stream of packets addressed to random or pseudorandom services regardless of whether a real service request is being made. Most of these packets will be decoy traffic.

  • Traffic from a client to a service node must be correctly coupled with decoy traffic. This can mean that the service node is chosen independently from traffic history, or that the transmitted packet replaces a decoy packet that was meant to go to the desired service.

Katzenpost currently includes several client applications. All applications make extensive use of Sphinx single-use reply blocks (SURBs), which enable service nodes to send replies without knowing the location of the client. Newer clients require a connection through the client connector, which provides multiplexing and privilege separation with a consequent reduction in processing overhead.

The following client applications are available.

Table 1. Katzenpost clients

Name

Needs connector

Description

Code

Ping

no

The mix network equivalent of an ICMP ping utility, used for network testing.

GitHub: ping

Fetch

no

Fetches the PKI document containing peer information.

GitHub: fetch

Katzen

no

A text chat client with file-transfer support.

GitHub: katzen

Status

yes

An HTML page containing status information about the mix network.

GitHub: status

Worldmap

yes

An HTML page with a world map showing geographic locations of mix network nodes.

GitHub: worldmap


Configuring Katzenpost

This section documents the configuration parameters for each type of Katzenpost server node. Each node has its own configuration file in TOML format.

Configuring directory authorities

The following configuration is drawn from the reference implementation in katzenpost/docker/dirauth_mixnet/auth1/authority.toml. In a real-world mixnet, the component hosts would not be sharing a single IP address. For more information about the test mixnet, see Using the Katzenpost Docker test network.


Dirauth: Server section

The Server section configures mandatory basic parameters for each directory authority.

[Server]
    Identifier = "auth1"
    WireKEMScheme = "xwing"
    PKISignatureScheme = "Ed25519 Sphincs+"
    Addresses = ["tcp://127.0.0.1:30001"]
    DataDir = "/dirauth_mixnet/auth1"
  • Identifier

    Specifies the human-readable identifier for a node, and must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • WireKEMScheme

    Specifies the key encapsulation mechanism (KEM) scheme for the PQ Noise-based wire protocol (link layer) that nodes use to communicate with each other. PQ Noise is a post-quantum variation of the Noise protocol framework, which algebraically transforms ECDH handshake patterns into KEM encapsulate/decapsulate operations.

    This configuration option supports the optional use of hybrid post-quantum cryptography to strengthen security. The following KEM schemes are supported:

    • Classical: "x25519", "x448"

      [Note] Note

      X25519 and X448 are actually non-interactive key-exchanges (NIKEs), not KEMs. Katzenpost uses a hashed ElGamal cryptographic construction to convert them from NIKEs to KEMs.

    • Post-quantum: "mlkem768","sntrup4591761", "frodo640shake", "mceliece348864", "mceliece348864f", "mceliece460896", "mceliece460896f", "mceliece6688128", "mceliece6688128f", "mceliece6960119", "mceliece6960119f", "mceliece8192128", "mceliece8192128f", "CTIDH511", "CTIDH512", "CTIDH1024", "CTIDH2048",

    • Hybrid post-quantum: "xwing", "Kyber768-X25519", "MLKEM768-X25519", "MLKEM768-X448", "FrodoKEM-640-SHAKE-X448", "sntrup4591761-X448", "mceliece348864-X25519", "mceliece348864f-X25519", "mceliece460896-X25519", "mceliece460896f-X25519", "mceliece6688128-X25519", "mceliece6688128f-X25519", "mceliece6960119-X25519", "mceliece6960119f-X25519", "mceliece8192128-X25519", "mceliece8192128f-X25519", "CTIDH512-X25519", "CTIDH512-X25519"

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme which will be used by all components of the mix network when interacting with the PKI system. Mix nodes sign their descriptors using this signature scheme, and dirauth nodes similarly sign PKI documents using the same scheme.

    The following signature schemes are supported: "ed25519", "ed448", "Ed25519 Sphincs+", "Ed448-Sphincs+", "Ed25519-Dilithium2", "Ed448-Dilithium3"

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the node will bind to for incoming connections. Katzenpost supports URLs with that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"].

    Type: []string

    Required: Yes

  • DataDir

    Specifies the absolute path to a node's state directory. This is where persistence.db is written to disk and where a node stores its cryptographic key materials when started with the "-g" command-line option.

    Type: string

    Required: Yes

Dirauth: Authorities section

An Authorities section is configured for each peer authority. We recommend using TOML's style for multi-line quotations for key materials.

[[Authorities]]
    Identifier = "auth1"
    IdentityPublicKey = """
-----BEGIN ED25519 PUBLIC KEY-----
dYpXpbozjFfqhR45ZC2q97SOOsXMANdHaEdXrP42CJk=
-----END ED25519 PUBLIC KEY-----
"""
    PKISignatureScheme = "Ed25519"
    LinkPublicKey = """
-----BEGIN XWING PUBLIC KEY-----
ooQBPYNdmfwnxXmvnljPA2mG5gWgurfHhbY87DMRY2tbMeZpinJ5BlSiIecprnmm
QqxcS9o36IS62SVMlOUkw+XEZGVvc9wJqHpgEgVJRAs1PCR8cUAdM6QIYLWt/lkf
SPKDCtZ3GiSIOzMuaglo2tarIPEv1AY7r9B0xXOgSKMkGyBkCfw1VBZf46MM26NL
...
gHtNyQJnXski52O03JpZRIhR40pFOhAAcMMAZDpMTVoxlcdR6WA4SlBiSceeJBgY
Yp9PlGhCimx9am99TrdLoLCdTHB6oowt8tss3POpIOxaSlguyeym/sBhkUrnXOgN
ldMtDsvvc9KUfE4I0+c+XQ==
-----END XWING PUBLIC KEY-----
    """
    WireKEMScheme = "xwing"
    Addresses = ["tcp://127.0.0.1:30001"]
  • Identifier

    Specifies the human-readable identifier for the node which must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • IdentityPublicKey

    String containing the node's public identity key in PEM format. IdentityPublicKey is the node's permanent identifier and is used to verify cryptographic signatures produced by its private identity key.

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme used by all directory authority nodes. PKISignatureScheme must match the scheme specified in the Server section of the configuration.

    Type: string

    Required: Yes

  • LinkPublicKey

    String containing the peer's public link-layer key in PEM format. LinkPublicKey must match the specified WireKEMScheme.

    Type: string

    Required: Yes

  • WireKEMScheme

    Specifies the key encapsulation mechanism (KEM) scheme for the PQ Noise-based wire protocol (link layer) that nodes use to communicate with each other. PQ Noise is a post-quantum variation of the Noise protocol framework, which algebraically transforms ECDH handshake patterns into KEM encapsulate/decapsulate operations.

    This configuration option supports the optional use of hybrid post-quantum cryptography to strengthen security. The following KEM schemes are supported:

    • Classical: "x25519", "x448"

      [Note] Note

      X25519 and X448 are actually non-interactive key-exchanges (NIKEs), not KEMs. Katzenpost uses a hashed ElGamal cryptographic construction to convert them from NIKEs to KEMs.

    • Post-quantum: "mlkem768","sntrup4591761", "frodo640shake", "mceliece348864", "mceliece348864f", "mceliece460896", "mceliece460896f", "mceliece6688128", "mceliece6688128f", "mceliece6960119", "mceliece6960119f", "mceliece8192128", "mceliece8192128f", "CTIDH511", "CTIDH512", "CTIDH1024", "CTIDH2048",

    • Hybrid post-quantum: "xwing", "Kyber768-X25519", "MLKEM768-X25519", "MLKEM768-X448", "FrodoKEM-640-SHAKE-X448", "sntrup4591761-X448", "mceliece348864-X25519", "mceliece348864f-X25519", "mceliece460896-X25519", "mceliece460896f-X25519", "mceliece6688128-X25519", "mceliece6688128f-X25519", "mceliece6960119-X25519", "mceliece6960119f-X25519", "mceliece8192128-X25519", "mceliece8192128f-X25519", "CTIDH512-X25519", "CTIDH512-X25519"

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the node will bind to for incoming connections. Katzenpost supports URLs with that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"].

    Type: []string

    Required: Yes

Dirauth: Logging section

The Logging configuration section controls logging behavior across Katzenpost.

[Logging]
                Disable = false
                File = "katzenpost.log"
                Level = "INFO"
  • Disable

    If true, logging is disabled.

    Type: bool

    Required: No

  • File

    Specifies the log file. If omitted, stdout is used.

    An absolute or relative file path can be specified. A relative path is relative to the DataDir specified in the Server section of the configuration.

    Type: string

    Required: No

  • Level

    Supported logging level values are ERROR | WARNING | NOTICE |INFO | DEBUG.

    Type: string

    Required: No

    [Warning] Warning

    The DEBUG log level is unsafe for production use.

Dirauth: Parameters section

The Parameters section contains the network parameters.

[Parameters]
    SendRatePerMinute = 0
    Mu = 0.005
    MuMaxDelay = 1000
    LambdaP = 0.001
    LambdaPMaxDelay = 1000
    LambdaL = 0.0005
    LambdaLMaxDelay = 1000
    LambdaD = 0.0005
    LambdaDMaxDelay = 3000
    LambdaM = 0.0005
    LambdaG = 0.0
    LambdaMMaxDelay = 100
    LambdaGMaxDelay = 100
  • SendRatePerMinute

    Specifies the maximum allowed rate of packets per client per gateway node. Rate limiting is done on the gateway nodes.

    Type: uint64

    Required: Yes

  • Mu

    Specifies the inverse of the mean of the exponential distribution from which the Sphinx packet per-hop mixing delay will be sampled.

    Type: float64

    Required: Yes

  • MuMaxDelay

    Specifies the maximum Sphinx packet per-hop mixing delay in milliseconds.

    Type: uint64

    Required: Yes

  • LambdaP

    Specifies the inverse of the mean of the exponential distribution that clients sample to determine the time interval between sending messages, whether actual messages from the FIFO egress queue or decoy messages if the queue is empty.

    Type: float64

    Required: Yes

  • LambdaPMaxDelay

    Specifies the maximum send delay interval for LambdaP in milliseconds.

    Type: uint64

    Required: Yes

  • LambdaL

    Specifies the inverse of the mean of the exponential distribution that clients sample to determine the delay interval between loop decoys.

    Type: float64

    Required: Yes

  • LambdaLMaxDelay

    Specifies the maximum send delay interval for LambdaL in milliseconds.

    Type: uint64

    Required: Yes

  • LambdaD

    LambdaD is the inverse of the mean of the exponential distribution that clients sample to determine the delay interval between decoy drop messages.

    Type: float64

    Required: Yes

  • LambdaDMaxDelay

    Specifies the maximum send interval in for LambdaD in milliseconds.

    Type: uint64

    Required: Yes

  • LambdaM

    LambdaM is the inverse of the mean of the exponential distribution that mix nodes sample to determine the delay between mix loop decoys.

    Type: float64

    Required: Yes

  • LambdaG

    LambdaG is the inverse of the mean of the exponential distribution that gateway nodes to select the delay between gateway node decoys.

    [Warning] Warning

    Do not set this value manually in the TOML configuration file. The field is used internally by the dirauth server state machine.

    Type: float64

    Required: Yes

  • LambdaMMaxDelay

    Specifies the maximum delay for LambdaM in milliseconds.

    Type: uint64

    Required: Yes

  • LambdaGMaxDelay

    Specifies the maximum delay for LambdaG in milliseconds.

    Type: uint64

    Required: Yes

Dirauth: Debug section

[Debug]
    Layers = 3
    MinNodesPerLayer = 1
    GenerateOnly = false
  • Layers

    Specifies the number of non-service-provider layers in the network topology.

    Type: int

    Required: Yes

  • MinNodesrPerLayer

    Specifies the minimum number of nodes per layer required to form a valid consensus document.

    Type: int

    Required: Yes

  • GenerateOnly

    If true, the server halts and cleans up the data directory immediately after long-term key generation.

    Type: bool

    Required: No

Dirauth: Mixes sections

The Mixes configuration sections list mix nodes that are known to the authority.

[[Mixes]]
    Identifier = "mix1"
    IdentityPublicKeyPem = "../mix1/identity.public.pem"

[[Mixes]]
    Identifier = "mix2"
    IdentityPublicKeyPem = "../mix2/identity.public.pem"

[[Mixes]]
    Identifier = "mix3"
    IdentityPublicKeyPem = "../mix3/identity.public.pem"
  • Identifier

    Specifies the human-readable identifier for a mix node, and must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • IdentityPublicKeyPem

    Path and file name of a mix node's public identity signing key, also known as the identity key, in PEM format.

    Type: string

    Required: Yes

Dirauth: GatewayNodes section

The GatewayNodes sections list gateway nodes that are known to the authority.

[[GatewayNodes]]
    Identifier = "gateway1"
    IdentityPublicKeyPem = "../gateway1/identity.public.pem"
  • Identifier

    Specifies the human-readable identifier for a gateway node, and must be unique per mixnet. Identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • IdentityPublicKeyPem

    Path and file name of a gateway node's public identity signing key, also known as the identity key, in PEM format.

    Type: string

    Required: Yes

Dirauth: ServiceNodes sections

The ServiceNodes sections list service nodes that are known to the authority.

[[ServiceNodes]]
    Identifier = "servicenode1"
    IdentityPublicKeyPem = "../servicenode1/identity.public.pem"
  • Identifier

    Specifies the human-readable identifier for a service node, and must be unique per mixnet. Identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • IdentityPublicKeyPem

    Path and file name of a service node's public identity signing key, also known as the identity key, in PEM format.

    Type: string

    Required: Yes

Dirauth: Topology section

The Topology section defines the layers of the mix network and the mix nodes in each layer.

[Topology]
                    
    [[Topology.Layers]]
    
        [[Topology.Layers.Nodes]]
            Identifier = "mix1"
            IdentityPublicKeyPem = "../mix1/identity.public.pem"
    
    [[Topology.Layers]]
    
        [[Topology.Layers.Nodes]]
            Identifier = "mix2"
            IdentityPublicKeyPem = "../mix2/identity.public.pem"
    
    [[Topology.Layers]]
    
        [[Topology.Layers.Nodes]]
            Identifier = "mix3"
            IdentityPublicKeyPem = "../mix3/identity.public.pem"
  • Identifier

    Specifies the human-readable identifier for a node, and must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

  • IdentityPublicKeyPem

    Path and file name of a mix node's public identity signing key, also known as the identity key, in PEM format.

    Type: string

    Required: Yes

Dirauth: SphinxGeometry section

Sphinx is an encrypted nested-packet format designed primarily for mixnets. The original Sphinx paper described a non-interactive key exchange (NIKE) employing classical encryption. The Katzenpost implementation strongly emphasizes configurability, supporting key encapsulation mechanisms (KEMs) as well as NIKEs, and enabling the use of either classical or hybrid post-quantum cryptography. Hybrid constructions offset the newness of post-quantum algorithms by offering heavily tested classical algorithms as a fallback.

[Note] Note

Sphinx, the nested-packet format, should not be confused with Sphincs or Sphincs+, which are post-quantum signature schemes.

Katzenpost Sphinx also relies on the following classical cryptographic primitives:

  • CTR-AES256, a stream cipher

  • HMAC-SHA256, a message authentication code (MAC) function

  • HKDF-SHA256, a key derivation function (KDF)

  • AEZv5, a strong pseudorandom permutation (SPRP)

All dirauths must be configured to use the same SphinxGeometry parameters. Any geometry not advertised by the PKI document will fail. Each dirauth publishes the hash of its SphinxGeometry parameters in the PKI document for validation by its peer dirauths.

The SphinxGeometry section defines parameters for the Sphinx encrypted nested-packet format used internally by Katzenpost.

The settings in this section are generated by the gensphinx utility, which computes the Sphinx geometry based on the following user-supplied directives:

  • The number of mix node layers (not counting gateway and service nodes)

  • The length of the application-usable packet payload

  • The selected NIKE or KEM scheme

[Warning] Warning

The values in the SphinxGeometry configuration section must be programmatically generated by gensphinx. Many of the parameters are interdependent and cannot be individually modified. Do not modify the these values by hand.

The gensphinx output in TOML should then be pasted unchanged into the node's configuration file, as shown below.

[SphinxGeometry]
                PacketLength = 3082
                NrHops = 5
                HeaderLength = 476
                RoutingInfoLength = 410
                PerHopRoutingInfoLength = 82
                SURBLength = 572
                SphinxPlaintextHeaderLength = 2
                PayloadTagLength = 32
                ForwardPayloadLength = 2574
                UserForwardPayloadLength = 2000
                NextNodeHopLength = 65
                SPRPKeyMaterialLength = 64
                NIKEName = "x25519"
                KEMName = ""
  • PacketLength

    The length of a Sphinx packet in bytes.

    Type: int

    Required: Yes

  • NrHops

    The number of hops a Sphinx packet takes through the mixnet. Because packet headers hold destination information for each hop, the size of the header increases linearly with the number of hops.

    Type: int

    Required: Yes

  • HeaderLength

    The total length of the Sphinx packet header in bytes.

    Type: int

    Required: Yes

  • RoutingInfoLength

    The total length of the routing information portion of the Sphinx packet header.

    Type: int

    Required: Yes

  • PerHopRoutingInfoLength

    The length of the per-hop routing information in the Sphinx packet header.

    Type: int

    Required: Yes

  • SURBLength

    The length of a single-use reply block (SURB).

    Type: int

    Required: Yes

  • SphinxPlaintextHeaderLength

    The length of the plaintext Sphinx packet header.

    Type: int

    Required: Yes

  • PayloadTagLength

    The length of the payload tag.

    Type: int

    Required: Yes

  • ForwardPayloadLength

    The total size of the payload.

    Type: int

    Required: Yes

  • UserForwardPayloadLength

    The size of the usable payload.

    Type: int

    Required: Yes

  • NextNodeHopLength

    The NextNodeHopLength is derived from the largest routing-information block that we expect to encounter. Other packets have NextNodeHop + NodeDelay sections, or a Recipient section, both of which are shorter.

    Type: int

    Required: Yes

  • SPRPKeyMaterialLength

    The length of the strong pseudo-random permutation (SPRP) key.

    Type: int

    Required: Yes

  • NIKEName

    The name of the non-interactive key exchange (NIKE) scheme used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

  • KEMName

    The name of the key encapsulation mechanism (KEM) used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

Configuring mix nodes

The following configuration is drawn from the reference implementation in katzenpost/docker/dirauth_mixnet/mix1/katzenpost.toml. In a real-world mixnet, the component hosts would not be sharing a single IP address. For more information about the test mixnet, see Using the Katzenpost Docker test network.


Mix node: Server section

The Server section configures mandatory basic parameters for each server node.

[Server]
  Identifier = "mix1"
  WireKEM = "xwing"
  PKISignatureScheme = "Ed25519"
  Addresses = ["127.0.0.1:30008"]
  OnlyAdvertiseAltAddresses = false
  MetricsAddress = "127.0.0.1:30009"
  DataDir = "/dirauth_mixnet/mix1"
  IsGatewayNode = false
  IsServiceNode = false
  [Server.AltAddresses]

  • Identifier

    Specifies the human-readable identifier for a node, and must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • WireKEM

    WireKEM specifies the key encapsulation mechanism (KEM) scheme for the PQ Noise-based wire protocol (link layer) that nodes use to communicate with each other. PQ Noise is a post-quantum variation of the Noise protocol framework, which algebraically transforms ECDH handshake patterns into KEM encapsulate/decapsulate operations.

    This configuration option supports the optional use of hybrid post-quantum cryptography to strengthen security. The following KEM schemes are supported:

    • Classical: "x25519", "x448"

      [Note] Note

      X25519 and X448 are actually non-interactive key-exchanges (NIKEs), not KEMs. Katzenpost uses a hashed ElGamal cryptographic construction to convert them from NIKEs to KEMs.

    • Post-quantum: "mlkem768","sntrup4591761", "frodo640shake", "mceliece348864", "mceliece348864f", "mceliece460896", "mceliece460896f", "mceliece6688128", "mceliece6688128f", "mceliece6960119", "mceliece6960119f", "mceliece8192128", "mceliece8192128f", "CTIDH511", "CTIDH512", "CTIDH1024", "CTIDH2048",

    • Hybrid post-quantum: "xwing", "Kyber768-X25519", "MLKEM768-X25519", "MLKEM768-X448", "FrodoKEM-640-SHAKE-X448", "sntrup4591761-X448", "mceliece348864-X25519", "mceliece348864f-X25519", "mceliece460896-X25519", "mceliece460896f-X25519", "mceliece6688128-X25519", "mceliece6688128f-X25519", "mceliece6960119-X25519", "mceliece6960119f-X25519", "mceliece8192128-X25519", "mceliece8192128f-X25519", "CTIDH512-X25519", "CTIDH512-X25519"

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme that will be used by all components of the mix network when interacting with the PKI system. Mix nodes sign their descriptors using this signature scheme, and dirauth nodes similarly sign PKI documents using the same scheme.

    The following signature schemes are supported:

    • Classical: "ed25519", "ed448"

    • Hybrid post-quantum: "Ed25519 Sphincs+", "Ed448-Sphincs+", "Ed25519-Dilithium2", "Ed448-Dilithium3"

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the server will bind to for incoming connections. Katzenpost supports URLs with that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"].

    Addresses is overridden if BindAddresses is true. In that scenario, one or more advertised, external addresses is provided as the value of Addresses, and is advertised in the PKI document.

    Note that BindAddresses, below, holds the address values for non-advertised, internal-only listeners. The addition of BindAddresses to the node configuration is required for hosts connecting to the Internet through network address translation (NAT).

    Type: []string

    Required: Yes

  • BindAddresses

    If true, allows setting of listener addresses that the server will bind to and accept connections on. These addresses are not advertised in the PKI document. For more information, see Addresses, above.

    Type: bool, []string

    Required: No

  • MetricsAddress

    Specifies the address/port to bind the Prometheus metrics endpoint to.

    Type: string

    Required: No

  • DataDir

    Specifies the absolute path to a node's state directory. This is where persistence.db is written to disk and where a node stores its cryptographic key materials when started with the "-g" command-line option.

    Type: string

    Required: Yes

  • IsGatewayNode

    If true, the server is a gateway node.

    Type: bool

    Required: No

  • IsServiceNode

    If true, the server is a service node.

    Type: bool

    Required: No

Mix node: Logging section

The Logging configuration section controls logging behavior across Katzenpost.

[Logging]
                Disable = false
                File = "katzenpost.log"
                Level = "INFO"
  • Disable

    If true, logging is disabled.

    Type: bool

    Required: No

  • File

    Specifies the log file. If omitted, stdout is used.

    An absolute or relative file path can be specified. A relative path is relative to the DataDir specified in the Server section of the configuration.

    Type: string

    Required: No

  • Level

    Supported logging level values are ERROR | WARNING | NOTICE |INFO | DEBUG.

    Type: string

    Required: No

    [Warning] Warning

    The DEBUG log level is unsafe for production use.

Mix node: PKI section

The PKI section contains the directory authority configuration for a mix, gateway, or service node.

[PKI]
[PKI.dirauth]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth1"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
tqN6tpOVotHWXKCszVn2kS7vAZjQpvJjQF3Qz/Qwhyg=
-----END ED25519 PUBLIC KEY-----
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """-----BEGIN XWING PUBLIC KEY-----
JnJ8ztQEIjAkKJcpuZvJAdkWjBim/5G5d8yoosEQHeGJeeBqNPdm2AitUbpiQPcd
tNCo9DxuC9Ieqmsfw0YpV6AtOOsaInA6QnHDYcuBfZcQL5MU4+t2TzpBZQYlrSED
hPCKrAG+8GEUl6akseG371WQzEtPpEWWCJCJOiS/VDFZT7eKrldlumN6gfiB84sR
...
arFh/WKwYJUj+aGBsFYSqGdzC6MdY4x/YyFe2ze0MJEjThQE91y1d/LCQ3Sb7Ri+
u6PBi3JU2qzlPEejDKwK0t5tMNEAkq8iNrpRTdD/hS0gR+ZIN8Z9QKh7Xf94FWG2
H+r8OaqImQhgHabrWRDyLg==
-----END XWING PUBLIC KEY-----
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30001"]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth2"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
O51Ty2WLu4C1ETMa29s03bMXV72gnjJfTfwLV++LVBI=
-----END ED25519 PUBLIC KEY-----	
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """-----BEGIN XWING PUBLIC KEY-----
TtQkg2XKUnY602FFBaPJ+zpN0Twy20cwyyFxh7FNUjaXA9MAJXs0vUwFbJc6BjYv
f+olKnlIKFSmDvcF74U6w1F0ObugwTNKNxeYKPKhX4FiencUbRwkHoYHdtZdSctz
TKy08qKQyCAccqCRpdo6ZtYXPAU+2rthjYTOL7Zn+7SHUKCuJClcPnvEYjVcJxtZ
...
ubJIe5U4nMJbBkOqr7Kq6niaEkiLODa0tkpB8tKMYTMBdcYyHSXCzpo7U9sb6LAR
HktiTBDtRXviu2vbw7VRXhkMW2kjYZDtReQ5sAse04DvmD49zgTp1YxYW+wWFaL3
37X7/SNuLdHX4PHZXIWHBQ==
-----END XWING PUBLIC KEY-----	
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30002"]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth3"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
zQvydRYJq3npeLcg1NqIf+SswEKE5wFmiwNsI9Z1whQ=
-----END ED25519 PUBLIC KEY-----
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """
-----BEGIN XWING PUBLIC KEY-----
OYK9FiC53xwZ1VST3jDOO4tR+cUMSVRSekmigZMChSjDCPZbKut8TblxtlUfc/yi
Ugorz4NIvYPMWUt3QPwS2UWq8/HMWXNGPUiAevg12+oV+jOJXaJeCfY24UekJnSw
TNcdGaFZFSR0FocFcPBBnrK1M2B8w8eEUKQIsXRDM3x/8aRIuDif+ve8rSwpgKeh
...
OdVD3yw7OOS8uPZLORGQFyJbHtVmFPVvwja4G/o2gntAoHUZ2LiJJakpVhhlSyrI
yuzvwwFtZVfWtNb5gAKZCyg0aduR3qgd7MPerRF+YopZk3OCRpC02YxfUZrHv398
FZWJFK0R8iU52CEUxVpXTA==
-----END XWING PUBLIC KEY-----	
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30003"]
  • Identifier

    Specifies the human-readable identifier for a node, which must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • IdentityPublicKey

    String containing the node's public identity key in PEM format. IdentityPublicKey is the node's permanent identifier and is used to verify cryptographic signatures produced by its private identity key.

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme that will be used by all components of the mix network when interacting with the PKI system. Mix nodes sign their descriptors using this signature scheme, and dirauth nodes similarly sign PKI documents using the same scheme.

    Type: string

    Required: Yes

  • LinkPublicKey

    String containing the peer's public link-layer key in PEM format. LinkPublicKey must match the specified WireKEMScheme.

    Type: string

    Required: Yes

  • WireKEMScheme

    The name of the wire protocol key-encapsulation mechanism (KEM) to use.

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the server will bind to for incoming connections. Katzenpost supports URLs that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"]. The value of Addresses is advertised in the PKI document.

    Type: []string

    Required: Yes

Mix node: Management section

The Management section specifies connectivity information for the Katzenpost control protocol which can be used to make run-time configuration changes. A configuration resembles the following, substituting the node's configured DataDir value as part of the Path value:

[Management]
   Enable = false
   Path = "/node_datadir/management_sock"
  • Enable

    If true, the management interface is enabled.

    Type: bool

    Required: No

  • Path

    Specifies the path to the management interface socket. If left empty, then management_sock is located in the configuration's defined DataDir.

    Type: string

    Required: No

Mix node: SphinxGeometry section

The SphinxGeometry section defines parameters for the Sphinx encrypted nested-packet format used internally by Katzenpost.

The settings in this section are generated by the gensphinx utility, which computes the Sphinx geometry based on the following user-supplied directives:

  • The number of mix node layers (not counting gateway and service nodes)

  • The length of the application-usable packet payload

  • The selected NIKE or KEM scheme

[Warning] Warning

The values in the SphinxGeometry configuration section must be programmatically generated by gensphinx. Many of the parameters are interdependent and cannot be individually modified. Do not modify the these values by hand.

The gensphinx output in TOML should then be pasted unchanged into the node's configuration file, as shown below.

[SphinxGeometry]
                PacketLength = 3082
                NrHops = 5
                HeaderLength = 476
                RoutingInfoLength = 410
                PerHopRoutingInfoLength = 82
                SURBLength = 572
                SphinxPlaintextHeaderLength = 2
                PayloadTagLength = 32
                ForwardPayloadLength = 2574
                UserForwardPayloadLength = 2000
                NextNodeHopLength = 65
                SPRPKeyMaterialLength = 64
                NIKEName = "x25519"
                KEMName = ""
  • PacketLength

    The length of a Sphinx packet in bytes.

    Type: int

    Required: Yes

  • NrHops

    The number of hops a Sphinx packet takes through the mixnet. Because packet headers hold destination information for each hop, the size of the header increases linearly with the number of hops.

    Type: int

    Required: Yes

  • HeaderLength

    The total length of the Sphinx packet header in bytes.

    Type: int

    Required: Yes

  • RoutingInfoLength

    The total length of the routing information portion of the Sphinx packet header.

    Type: int

    Required: Yes

  • PerHopRoutingInfoLength

    The length of the per-hop routing information in the Sphinx packet header.

    Type: int

    Required: Yes

  • SURBLength

    The length of a single-use reply block (SURB).

    Type: int

    Required: Yes

  • SphinxPlaintextHeaderLength

    The length of the plaintext Sphinx packet header.

    Type: int

    Required: Yes

  • PayloadTagLength

    The length of the payload tag.

    Type: int

    Required: Yes

  • ForwardPayloadLength

    The total size of the payload.

    Type: int

    Required: Yes

  • UserForwardPayloadLength

    The size of the usable payload.

    Type: int

    Required: Yes

  • NextNodeHopLength

    The NextNodeHopLength is derived from the largest routing-information block that we expect to encounter. Other packets have NextNodeHop + NodeDelay sections, or a Recipient section, both of which are shorter.

    Type: int

    Required: Yes

  • SPRPKeyMaterialLength

    The length of the strong pseudo-random permutation (SPRP) key.

    Type: int

    Required: Yes

  • NIKEName

    The name of the non-interactive key exchange (NIKE) scheme used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

  • KEMName

    The name of the key encapsulation mechanism (KEM) used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

Mix node: Debug section

The Debug section is the Katzenpost server debug configuration for advanced tuning.

[Debug]
                NumSphinxWorkers = 16
                NumServiceWorkers = 3
                NumGatewayWorkers = 3
                NumKaetzchenWorkers = 3
                SchedulerExternalMemoryQueue = false
                SchedulerQueueSize = 0
                SchedulerMaxBurst = 16
                UnwrapDelay = 250
                GatewayDelay = 500
                ServiceDelay = 500
                KaetzchenDelay = 750
                SchedulerSlack = 150
                SendSlack = 50
                DecoySlack = 15000
                ConnectTimeout = 60000
                HandshakeTimeout = 30000
                ReauthInterval = 30000
                SendDecoyTraffic = false
                DisableRateLimit = false
                GenerateOnly = false
  • NumSphinxWorkers

    Specifies the number of worker instances to use for inbound Sphinx packet processing.

    Type: int

    Required: No

  • NumProviderWorkers

    Specifies the number of worker instances to use for provider specific packet processing.

    Type: int

    Required: No

  • NumKaetzchenWorkers

    Specifies the number of worker instances to use for Kaetzchen-specific packet processing.

    Type: int

    Required: No

  • SchedulerExternalMemoryQueue

    If true, the experimental disk-backed external memory queue is enabled.

    Type: bool

    Required: No

  • SchedulerQueueSize

    Specifies the maximum scheduler queue size before random entries will start getting dropped. A value less than or equal to zero is treated as unlimited.

    Type: int

    Required: No

  • SchedulerMaxBurst

    Specifies the maximum number of packets that will be dispatched per scheduler wakeup event.

    Type:

    Required: No

  • UnwrapDelay

    Specifies the maximum unwrap delay due to queueing in milliseconds.

    Type: int

    Required: No

  • GatewayDelay

    Specifies the maximum gateway node worker delay due to queueing in milliseconds.

    Type: int

    Required: No

  • ServiceDelay

    Specifies the maximum provider delay due to queueing in milliseconds.

    Type: int

    Required: No

  • KaetzchenDelay

    Specifies the maximum kaetzchen delay due to queueing in milliseconds.

    Type: int

    Required: No

  • SchedulerSlack

    Specifies the maximum scheduler slack due to queueing and/or processing in milliseconds.

    Type: int

    Required: No

  • SendSlack

    Specifies the maximum send-queue slack due to queueing and/or congestion in milliseconds.

    Type: int

    Required: No

  • DecoySlack

    Specifies the maximum decoy sweep slack due to external delays such as latency before a loop decoy packet will be considered lost.

    Type: int

    Required: No

  • ConnectTimeout

    Specifies the maximum time a connection can take to establish a TCP/IP connection in milliseconds.

    Type: int

    Required: No

  • HandshakeTimeout

    Specifies the maximum time a connection can take for a link-protocol handshake in milliseconds.

    Type: int

    Required: No

  • ReauthInterval

    Specifies the interval at which a connection will be reauthenticated in milliseconds.

    Type: int

    Required: No

  • SendDecoyTraffic

    If true, decoy traffic is enabled. This parameter is experimental and untuned, and is disabled by default.

    [Note] Note

    This option will be removed once decoy traffic is fully implemented.

    Type: bool

    Required: No

  • DisableRateLimit

    If true, the per-client rate limiter is disabled.

    [Note] Note

    This option should only be used for testing.

    Type: bool

    Required: No

  • GenerateOnly

    If true, the server immediately halts and cleans up after long-term key generation.

    Type: bool

    Required: No

Configuring gateway nodes

The following configuration is drawn from the reference implementation in katzenpost/docker/dirauth_mixnet/gateway1/katzenpost.toml. In a real-world mixnet, the component hosts would not be sharing a single IP address. For more information about the test mixnet, see Using the Katzenpost Docker test network.


Gateway node: Server section

The Server section configures mandatory basic parameters for each server node.

[Server]
    Identifier = "gateway1"
    WireKEM = "xwing"
    PKISignatureScheme = "Ed25519"
    Addresses = ["127.0.0.1:30004"]
    OnlyAdvertiseAltAddresses = false
    MetricsAddress = "127.0.0.1:30005"
    DataDir = "/dirauth_mixnet/gateway1"
    IsGatewayNode = true
    IsServiceNode = false
    [Server.AltAddresses]
        TCP = ["localhost:30004"]
  • Identifier

    Specifies the human-readable identifier for a node, and must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • WireKEM

    WireKEM specifies the key encapsulation mechanism (KEM) scheme for the PQ Noise-based wire protocol (link layer) that nodes use to communicate with each other. PQ Noise is a post-quantum variation of the Noise protocol framework, which algebraically transforms ECDH handshake patterns into KEM encapsulate/decapsulate operations.

    This configuration option supports the optional use of hybrid post-quantum cryptography to strengthen security. The following KEM schemes are supported:

    • Classical: "x25519", "x448"

      [Note] Note

      X25519 and X448 are actually non-interactive key-exchanges (NIKEs), not KEMs. Katzenpost uses a hashed ElGamal cryptographic construction to convert them from NIKEs to KEMs.

    • Post-quantum: "mlkem768","sntrup4591761", "frodo640shake", "mceliece348864", "mceliece348864f", "mceliece460896", "mceliece460896f", "mceliece6688128", "mceliece6688128f", "mceliece6960119", "mceliece6960119f", "mceliece8192128", "mceliece8192128f", "CTIDH511", "CTIDH512", "CTIDH1024", "CTIDH2048",

    • Hybrid post-quantum: "xwing", "Kyber768-X25519", "MLKEM768-X25519", "MLKEM768-X448", "FrodoKEM-640-SHAKE-X448", "sntrup4591761-X448", "mceliece348864-X25519", "mceliece348864f-X25519", "mceliece460896-X25519", "mceliece460896f-X25519", "mceliece6688128-X25519", "mceliece6688128f-X25519", "mceliece6960119-X25519", "mceliece6960119f-X25519", "mceliece8192128-X25519", "mceliece8192128f-X25519", "CTIDH512-X25519", "CTIDH512-X25519"

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme that will be used by all components of the mix network when interacting with the PKI system. Mix nodes sign their descriptors using this signature scheme, and dirauth nodes similarly sign PKI documents using the same scheme.

    The following signature schemes are supported:

    • Classical: "ed25519", "ed448"

    • Hybrid post-quantum: "Ed25519 Sphincs+", "Ed448-Sphincs+", "Ed25519-Dilithium2", "Ed448-Dilithium3"

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the server will bind to for incoming connections. Katzenpost supports URLs with that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"].

    Addresses is overridden if BindAddresses is true. In that scenario, one or more advertised, external addresses is provided as the value of Addresses, and is advertised in the PKI document.

    Note that BindAddresses, below, holds the address values for non-advertised, internal-only listeners. The addition of BindAddresses to the node configuration is required for hosts connecting to the Internet through network address translation (NAT).

    Type: []string

    Required: Yes

  • BindAddresses

    If true, allows setting of listener addresses that the server will bind to and accept connections on. These addresses are not advertised in the PKI document. For more information, see Addresses, above.

    Type: bool, []string

    Required: No

  • MetricsAddress

    Specifies the address/port to bind the Prometheus metrics endpoint to.

    Type: string

    Required: No

  • DataDir

    Specifies the absolute path to a node's state directory. This is where persistence.db is written to disk and where a node stores its cryptographic key materials when started with the "-g" command-line option.

    Type: string

    Required: Yes

  • IsGatewayNode

    If true, the server is a gateway node.

    Type: bool

    Required: No

  • IsServiceNode

    If true, the server is a service node.

    Type: bool

    Required: No

Gateway node: Logging section

The Logging configuration section controls logging behavior across Katzenpost.

[Logging]
                Disable = false
                File = "katzenpost.log"
                Level = "INFO"
  • Disable

    If true, logging is disabled.

    Type: bool

    Required: No

  • File

    Specifies the log file. If omitted, stdout is used.

    An absolute or relative file path can be specified. A relative path is relative to the DataDir specified in the Server section of the configuration.

    Type: string

    Required: No

  • Level

    Supported logging level values are ERROR | WARNING | NOTICE |INFO | DEBUG.

    Type: string

    Required: No

    [Warning] Warning

    The DEBUG log level is unsafe for production use.

Gateway node: Gateway section

The Gateway section of the configuration is required for configuring a Gateway node. The section must contain UserDB and SpoolDB definitions. Bolt is an embedded database library for the Go programming language that Katzenpost has used in the past for its user and spool databases. Because Katzenpost currently persists data on Service nodes instead of Gateways, these databases will probably be deprecated in favour of in-memory concurrency structures. In the meantime, it remains necessary to configure a Gateway node as shown below, only changing the file paths as needed:

[Gateway]
    [Gateway.UserDB]
        Backend = "bolt"
            [Gateway.UserDB.Bolt]
                UserDB = "/dirauth_mixnet/gateway1/users.db"
    [Gateway.SpoolDB]
        Backend = "bolt"
            [Gateway.SpoolDB.Bolt]
                SpoolDB = "/dirauth_mixnet/gateway1/spool.db"

Gateway node: PKI section

The PKI section contains the directory authority configuration for a mix, gateway, or service node.

[PKI]
[PKI.dirauth]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth1"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
tqN6tpOVotHWXKCszVn2kS7vAZjQpvJjQF3Qz/Qwhyg=
-----END ED25519 PUBLIC KEY-----
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """-----BEGIN XWING PUBLIC KEY-----
JnJ8ztQEIjAkKJcpuZvJAdkWjBim/5G5d8yoosEQHeGJeeBqNPdm2AitUbpiQPcd
tNCo9DxuC9Ieqmsfw0YpV6AtOOsaInA6QnHDYcuBfZcQL5MU4+t2TzpBZQYlrSED
hPCKrAG+8GEUl6akseG371WQzEtPpEWWCJCJOiS/VDFZT7eKrldlumN6gfiB84sR
...
arFh/WKwYJUj+aGBsFYSqGdzC6MdY4x/YyFe2ze0MJEjThQE91y1d/LCQ3Sb7Ri+
u6PBi3JU2qzlPEejDKwK0t5tMNEAkq8iNrpRTdD/hS0gR+ZIN8Z9QKh7Xf94FWG2
H+r8OaqImQhgHabrWRDyLg==
-----END XWING PUBLIC KEY-----
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30001"]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth2"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
O51Ty2WLu4C1ETMa29s03bMXV72gnjJfTfwLV++LVBI=
-----END ED25519 PUBLIC KEY-----	
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """-----BEGIN XWING PUBLIC KEY-----
TtQkg2XKUnY602FFBaPJ+zpN0Twy20cwyyFxh7FNUjaXA9MAJXs0vUwFbJc6BjYv
f+olKnlIKFSmDvcF74U6w1F0ObugwTNKNxeYKPKhX4FiencUbRwkHoYHdtZdSctz
TKy08qKQyCAccqCRpdo6ZtYXPAU+2rthjYTOL7Zn+7SHUKCuJClcPnvEYjVcJxtZ
...
ubJIe5U4nMJbBkOqr7Kq6niaEkiLODa0tkpB8tKMYTMBdcYyHSXCzpo7U9sb6LAR
HktiTBDtRXviu2vbw7VRXhkMW2kjYZDtReQ5sAse04DvmD49zgTp1YxYW+wWFaL3
37X7/SNuLdHX4PHZXIWHBQ==
-----END XWING PUBLIC KEY-----	
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30002"]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth3"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
zQvydRYJq3npeLcg1NqIf+SswEKE5wFmiwNsI9Z1whQ=
-----END ED25519 PUBLIC KEY-----
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """
-----BEGIN XWING PUBLIC KEY-----
OYK9FiC53xwZ1VST3jDOO4tR+cUMSVRSekmigZMChSjDCPZbKut8TblxtlUfc/yi
Ugorz4NIvYPMWUt3QPwS2UWq8/HMWXNGPUiAevg12+oV+jOJXaJeCfY24UekJnSw
TNcdGaFZFSR0FocFcPBBnrK1M2B8w8eEUKQIsXRDM3x/8aRIuDif+ve8rSwpgKeh
...
OdVD3yw7OOS8uPZLORGQFyJbHtVmFPVvwja4G/o2gntAoHUZ2LiJJakpVhhlSyrI
yuzvwwFtZVfWtNb5gAKZCyg0aduR3qgd7MPerRF+YopZk3OCRpC02YxfUZrHv398
FZWJFK0R8iU52CEUxVpXTA==
-----END XWING PUBLIC KEY-----	
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30003"]
  • Identifier

    Specifies the human-readable identifier for a node, which must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • IdentityPublicKey

    String containing the node's public identity key in PEM format. IdentityPublicKey is the node's permanent identifier and is used to verify cryptographic signatures produced by its private identity key.

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme that will be used by all components of the mix network when interacting with the PKI system. Mix nodes sign their descriptors using this signature scheme, and dirauth nodes similarly sign PKI documents using the same scheme.

    Type: string

    Required: Yes

  • LinkPublicKey

    String containing the peer's public link-layer key in PEM format. LinkPublicKey must match the specified WireKEMScheme.

    Type: string

    Required: Yes

  • WireKEMScheme

    The name of the wire protocol key-encapsulation mechanism (KEM) to use.

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the server will bind to for incoming connections. Katzenpost supports URLs that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"]. The value of Addresses is advertised in the PKI document.

    Type: []string

    Required: Yes

Gateway node: Management section

The Management section specifies connectivity information for the Katzenpost control protocol which can be used to make run-time configuration changes. A configuration resembles the following, substituting the node's configured DataDir value as part of the Path value:

[Management]
   Enable = false
   Path = "/node_datadir/management_sock"
  • Enable

    If true, the management interface is enabled.

    Type: bool

    Required: No

  • Path

    Specifies the path to the management interface socket. If left empty, then management_sock is located in the configuration's defined DataDir.

    Type: string

    Required: No

Gateway node: SphinxGeometry section

The SphinxGeometry section defines parameters for the Sphinx encrypted nested-packet format used internally by Katzenpost.

The settings in this section are generated by the gensphinx utility, which computes the Sphinx geometry based on the following user-supplied directives:

  • The number of mix node layers (not counting gateway and service nodes)

  • The length of the application-usable packet payload

  • The selected NIKE or KEM scheme

[Warning] Warning

The values in the SphinxGeometry configuration section must be programmatically generated by gensphinx. Many of the parameters are interdependent and cannot be individually modified. Do not modify the these values by hand.

The gensphinx output in TOML should then be pasted unchanged into the node's configuration file, as shown below.

[SphinxGeometry]
                PacketLength = 3082
                NrHops = 5
                HeaderLength = 476
                RoutingInfoLength = 410
                PerHopRoutingInfoLength = 82
                SURBLength = 572
                SphinxPlaintextHeaderLength = 2
                PayloadTagLength = 32
                ForwardPayloadLength = 2574
                UserForwardPayloadLength = 2000
                NextNodeHopLength = 65
                SPRPKeyMaterialLength = 64
                NIKEName = "x25519"
                KEMName = ""
  • PacketLength

    The length of a Sphinx packet in bytes.

    Type: int

    Required: Yes

  • NrHops

    The number of hops a Sphinx packet takes through the mixnet. Because packet headers hold destination information for each hop, the size of the header increases linearly with the number of hops.

    Type: int

    Required: Yes

  • HeaderLength

    The total length of the Sphinx packet header in bytes.

    Type: int

    Required: Yes

  • RoutingInfoLength

    The total length of the routing information portion of the Sphinx packet header.

    Type: int

    Required: Yes

  • PerHopRoutingInfoLength

    The length of the per-hop routing information in the Sphinx packet header.

    Type: int

    Required: Yes

  • SURBLength

    The length of a single-use reply block (SURB).

    Type: int

    Required: Yes

  • SphinxPlaintextHeaderLength

    The length of the plaintext Sphinx packet header.

    Type: int

    Required: Yes

  • PayloadTagLength

    The length of the payload tag.

    Type: int

    Required: Yes

  • ForwardPayloadLength

    The total size of the payload.

    Type: int

    Required: Yes

  • UserForwardPayloadLength

    The size of the usable payload.

    Type: int

    Required: Yes

  • NextNodeHopLength

    The NextNodeHopLength is derived from the largest routing-information block that we expect to encounter. Other packets have NextNodeHop + NodeDelay sections, or a Recipient section, both of which are shorter.

    Type: int

    Required: Yes

  • SPRPKeyMaterialLength

    The length of the strong pseudo-random permutation (SPRP) key.

    Type: int

    Required: Yes

  • NIKEName

    The name of the non-interactive key exchange (NIKE) scheme used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

  • KEMName

    The name of the key encapsulation mechanism (KEM) used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

Gateway node: Debug section

The Debug section is the Katzenpost server debug configuration for advanced tuning.

[Debug]
                NumSphinxWorkers = 16
                NumServiceWorkers = 3
                NumGatewayWorkers = 3
                NumKaetzchenWorkers = 3
                SchedulerExternalMemoryQueue = false
                SchedulerQueueSize = 0
                SchedulerMaxBurst = 16
                UnwrapDelay = 250
                GatewayDelay = 500
                ServiceDelay = 500
                KaetzchenDelay = 750
                SchedulerSlack = 150
                SendSlack = 50
                DecoySlack = 15000
                ConnectTimeout = 60000
                HandshakeTimeout = 30000
                ReauthInterval = 30000
                SendDecoyTraffic = false
                DisableRateLimit = false
                GenerateOnly = false
  • NumSphinxWorkers

    Specifies the number of worker instances to use for inbound Sphinx packet processing.

    Type: int

    Required: No

  • NumProviderWorkers

    Specifies the number of worker instances to use for provider specific packet processing.

    Type: int

    Required: No

  • NumKaetzchenWorkers

    Specifies the number of worker instances to use for Kaetzchen-specific packet processing.

    Type: int

    Required: No

  • SchedulerExternalMemoryQueue

    If true, the experimental disk-backed external memory queue is enabled.

    Type: bool

    Required: No

  • SchedulerQueueSize

    Specifies the maximum scheduler queue size before random entries will start getting dropped. A value less than or equal to zero is treated as unlimited.

    Type: int

    Required: No

  • SchedulerMaxBurst

    Specifies the maximum number of packets that will be dispatched per scheduler wakeup event.

    Type:

    Required: No

  • UnwrapDelay

    Specifies the maximum unwrap delay due to queueing in milliseconds.

    Type: int

    Required: No

  • GatewayDelay

    Specifies the maximum gateway node worker delay due to queueing in milliseconds.

    Type: int

    Required: No

  • ServiceDelay

    Specifies the maximum provider delay due to queueing in milliseconds.

    Type: int

    Required: No

  • KaetzchenDelay

    Specifies the maximum kaetzchen delay due to queueing in milliseconds.

    Type: int

    Required: No

  • SchedulerSlack

    Specifies the maximum scheduler slack due to queueing and/or processing in milliseconds.

    Type: int

    Required: No

  • SendSlack

    Specifies the maximum send-queue slack due to queueing and/or congestion in milliseconds.

    Type: int

    Required: No

  • DecoySlack

    Specifies the maximum decoy sweep slack due to external delays such as latency before a loop decoy packet will be considered lost.

    Type: int

    Required: No

  • ConnectTimeout

    Specifies the maximum time a connection can take to establish a TCP/IP connection in milliseconds.

    Type: int

    Required: No

  • HandshakeTimeout

    Specifies the maximum time a connection can take for a link-protocol handshake in milliseconds.

    Type: int

    Required: No

  • ReauthInterval

    Specifies the interval at which a connection will be reauthenticated in milliseconds.

    Type: int

    Required: No

  • SendDecoyTraffic

    If true, decoy traffic is enabled. This parameter is experimental and untuned, and is disabled by default.

    [Note] Note

    This option will be removed once decoy traffic is fully implemented.

    Type: bool

    Required: No

  • DisableRateLimit

    If true, the per-client rate limiter is disabled.

    [Note] Note

    This option should only be used for testing.

    Type: bool

    Required: No

  • GenerateOnly

    If true, the server immediately halts and cleans up after long-term key generation.

    Type: bool

    Required: No

Configuring service nodes

The following configuration is drawn from the reference implementation in katzenpost/docker/dirauth_mixnet/servicenode1/authority.toml. In a real-world mixnet, the component hosts would not be sharing a single IP address. For more information about the test mixnet, see Using the Katzenpost Docker test network.


Service node: Server section

The Server section configures mandatory basic parameters for each server node.

[Server]
    Identifier = "servicenode1"
    WireKEM = "xwing"
    PKISignatureScheme = "Ed25519"
    Addresses = ["127.0.0.1:30006"]
    OnlyAdvertiseAltAddresses = false
    MetricsAddress = "127.0.0.1:30007"
    DataDir = "/dirauth_mixnet/servicenode1"
    IsGatewayNode = false
    IsServiceNode = true
    [Server.AltAddresses]
  • Identifier

    Specifies the human-readable identifier for a node, and must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • WireKEM

    WireKEM specifies the key encapsulation mechanism (KEM) scheme for the PQ Noise-based wire protocol (link layer) that nodes use to communicate with each other. PQ Noise is a post-quantum variation of the Noise protocol framework, which algebraically transforms ECDH handshake patterns into KEM encapsulate/decapsulate operations.

    This configuration option supports the optional use of hybrid post-quantum cryptography to strengthen security. The following KEM schemes are supported:

    • Classical: "x25519", "x448"

      [Note] Note

      X25519 and X448 are actually non-interactive key-exchanges (NIKEs), not KEMs. Katzenpost uses a hashed ElGamal cryptographic construction to convert them from NIKEs to KEMs.

    • Post-quantum: "mlkem768","sntrup4591761", "frodo640shake", "mceliece348864", "mceliece348864f", "mceliece460896", "mceliece460896f", "mceliece6688128", "mceliece6688128f", "mceliece6960119", "mceliece6960119f", "mceliece8192128", "mceliece8192128f", "CTIDH511", "CTIDH512", "CTIDH1024", "CTIDH2048",

    • Hybrid post-quantum: "xwing", "Kyber768-X25519", "MLKEM768-X25519", "MLKEM768-X448", "FrodoKEM-640-SHAKE-X448", "sntrup4591761-X448", "mceliece348864-X25519", "mceliece348864f-X25519", "mceliece460896-X25519", "mceliece460896f-X25519", "mceliece6688128-X25519", "mceliece6688128f-X25519", "mceliece6960119-X25519", "mceliece6960119f-X25519", "mceliece8192128-X25519", "mceliece8192128f-X25519", "CTIDH512-X25519", "CTIDH512-X25519"

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme that will be used by all components of the mix network when interacting with the PKI system. Mix nodes sign their descriptors using this signature scheme, and dirauth nodes similarly sign PKI documents using the same scheme.

    The following signature schemes are supported:

    • Classical: "ed25519", "ed448"

    • Hybrid post-quantum: "Ed25519 Sphincs+", "Ed448-Sphincs+", "Ed25519-Dilithium2", "Ed448-Dilithium3"

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the server will bind to for incoming connections. Katzenpost supports URLs with that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"].

    Addresses is overridden if BindAddresses is true. In that scenario, one or more advertised, external addresses is provided as the value of Addresses, and is advertised in the PKI document.

    Note that BindAddresses, below, holds the address values for non-advertised, internal-only listeners. The addition of BindAddresses to the node configuration is required for hosts connecting to the Internet through network address translation (NAT).

    Type: []string

    Required: Yes

  • BindAddresses

    If true, allows setting of listener addresses that the server will bind to and accept connections on. These addresses are not advertised in the PKI document. For more information, see Addresses, above.

    Type: bool, []string

    Required: No

  • MetricsAddress

    Specifies the address/port to bind the Prometheus metrics endpoint to.

    Type: string

    Required: No

  • DataDir

    Specifies the absolute path to a node's state directory. This is where persistence.db is written to disk and where a node stores its cryptographic key materials when started with the "-g" command-line option.

    Type: string

    Required: Yes

  • IsGatewayNode

    If true, the server is a gateway node.

    Type: bool

    Required: No

  • IsServiceNode

    If true, the server is a service node.

    Type: bool

    Required: No

Service node: Logging section

The Logging configuration section controls logging behavior across Katzenpost.

[Logging]
                Disable = false
                File = "katzenpost.log"
                Level = "INFO"
  • Disable

    If true, logging is disabled.

    Type: bool

    Required: No

  • File

    Specifies the log file. If omitted, stdout is used.

    An absolute or relative file path can be specified. A relative path is relative to the DataDir specified in the Server section of the configuration.

    Type: string

    Required: No

  • Level

    Supported logging level values are ERROR | WARNING | NOTICE |INFO | DEBUG.

    Type: string

    Required: No

    [Warning] Warning

    The DEBUG log level is unsafe for production use.

Service node: ServiceNode section

The ServiceNode section contains configurations for each network service that Katzenpost supports.

Services, termed Kaetzchen, can be divided into built-in and external services. External services are provided through the CBORPlugin, a Go programming language implementation of the Concise Binary Object Representation (CBOR), a binary data serialization format. While native services need simply to be activated, external services are invoked by a separate command and connected to the mixnet over a Unix socket. The plugin allows mixnet services to be added in any programming language.

[ServiceNode]
                    
    [[ServiceNode.Kaetzchen]]
        Capability = "echo"
        Endpoint = "+echo"
        Disable = false
    
    [[ServiceNode.CBORPluginKaetzchen]]
        Capability = "spool"
        Endpoint = "+spool"
        Command = "/dirauth_mixnet/memspool.alpine"
        MaxConcurrency = 1
        Disable = false
        [ServiceNode.CBORPluginKaetzchen.Config]
            data_store = "/dirauth_mixnet/servicenode1/memspool.storage"
            log_dir = "/dirauth_mixnet/servicenode1"
    
    [[ServiceNode.CBORPluginKaetzchen]]
        Capability = "pigeonhole"
        Endpoint = "+pigeonhole"
        Command = "/dirauth_mixnet/pigeonhole.alpine"
        MaxConcurrency = 1
        Disable = false
        [ServiceNode.CBORPluginKaetzchen.Config]
            db = "/dirauth_mixnet/servicenode1/map.storage"
            log_dir = "/dirauth_mixnet/servicenode1"
    
    [[ServiceNode.CBORPluginKaetzchen]]
        Capability = "panda"
        Endpoint = "+panda"
        Command = "/dirauth_mixnet/panda_server.alpine"
        MaxConcurrency = 1
        Disable = false
        [ServiceNode.CBORPluginKaetzchen.Config]
            fileStore = "/dirauth_mixnet/servicenode1/panda.storage"
            log_dir = "/dirauth_mixnet/servicenode1"
            log_level = "INFO"
    
    [[ServiceNode.CBORPluginKaetzchen]]
        Capability = "http"
        Endpoint = "+http"
        Command = "/dirauth_mixnet/proxy_server.alpine"
        MaxConcurrency = 1
        Disable = false
        [ServiceNode.CBORPluginKaetzchen.Config]
            host = "localhost:4242"
            log_dir = "/dirauth_mixnet/servicenode1"
            log_level = "DEBUG"

Common parameters:

  • Capability

    Specifies the protocol capability exposed by the agent.

    Type: string

    Required: Yes

  • Endpoint

    Specifies the provider-side Endpoint where the agent will accept requests. While not required by the specification, this server only supports Endpoints that are lower-case local parts of an email address.

    Type: string

    Required: Yes

  • Command

    Specifies the full path to the external plugin program that implements this Kaetzchen service.

    Type: string

    Required: Yes

  • MaxConcurrency

    Specifies the number of worker goroutines to start for this service.

    Type: int

    Required: Yes

  • Config

    Specifies extra per-agent arguments to be passed to the agent's initialization routine.

    Type: map[string]interface{}

    Required: Yes

  • Disable

    If true, disables a configured agent.

    Type: bool

    Required: No

Per-service parameters:

  • echo

    The internal echo service must be enabled on every service node of a production mixnet for decoy traffic to work properly.

  • spool

    The spool service supports the catshadow storage protocol, which is required by the Katzen chat client. The example configuration above shows spool enabled with the setting:

    Disable = false
    [Note] Note

    Spool, properly memspool, should not be confused with the spool database on gateway nodes.

    • data_store

      Specifies the full path to the service database file.

      Type: string

      Required: Yes

    • log_dir

      Specifies the path to the node's log directory.

      Type: string

      Required: Yes

  • pigeonhole

    The pigeonhole courier service supports the Blinding-and-Capability scheme (BACAP)-based unlinkable messaging protocols detailed in Place-holder for research paper link. Most of our future protocols will use the pigeonhole courier service.

    • db

      Specifies the full path to the service database file.

      Type: string

      Required: Yes

    • log_dir

      Specifies the path to the node's log directory.

      Type: string

      Required: Yes

  • panda

    The panda storage and authentication service currently does not work properly.

    • fileStore

      Specifies the full path to the service database file.

      Type: string

      Required: Yes

    • log_dir

      Specifies the path to the node's log directory.

      Type: string

      Required: Yes

    • log_level

      Supported values are ERROR | WARNING | NOTICE |INFO | DEBUG.

      [Warning] Warning

      The DEBUG log level is unsafe for production use.

      Type: string

      Required: Yes

      Required: Yes

  • http

    The http service is completely optional, but allows the mixnet to be used as an HTTP proxy. This may be useful for integrating with existing software systems.

    • host

      The host name and TCP port of the service.

      Type: string

      Required: Yes

    • log_dir

      Specifies the path to the node's log directory.

      Type: string

      Required: Yes

    • log_level

      Supported values are ERROR | WARNING | NOTICE |INFO | DEBUG.

      Type: string

      Required: Yes

      Required: Yes

      [Warning] Warning

      The DEBUG log level is unsafe for production use.

      Type: string

      Required: Yes

Service node: PKI section

The PKI section contains the directory authority configuration for a mix, gateway, or service node.

[PKI]
[PKI.dirauth]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth1"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
tqN6tpOVotHWXKCszVn2kS7vAZjQpvJjQF3Qz/Qwhyg=
-----END ED25519 PUBLIC KEY-----
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """-----BEGIN XWING PUBLIC KEY-----
JnJ8ztQEIjAkKJcpuZvJAdkWjBim/5G5d8yoosEQHeGJeeBqNPdm2AitUbpiQPcd
tNCo9DxuC9Ieqmsfw0YpV6AtOOsaInA6QnHDYcuBfZcQL5MU4+t2TzpBZQYlrSED
hPCKrAG+8GEUl6akseG371WQzEtPpEWWCJCJOiS/VDFZT7eKrldlumN6gfiB84sR
...
arFh/WKwYJUj+aGBsFYSqGdzC6MdY4x/YyFe2ze0MJEjThQE91y1d/LCQ3Sb7Ri+
u6PBi3JU2qzlPEejDKwK0t5tMNEAkq8iNrpRTdD/hS0gR+ZIN8Z9QKh7Xf94FWG2
H+r8OaqImQhgHabrWRDyLg==
-----END XWING PUBLIC KEY-----
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30001"]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth2"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
O51Ty2WLu4C1ETMa29s03bMXV72gnjJfTfwLV++LVBI=
-----END ED25519 PUBLIC KEY-----	
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """-----BEGIN XWING PUBLIC KEY-----
TtQkg2XKUnY602FFBaPJ+zpN0Twy20cwyyFxh7FNUjaXA9MAJXs0vUwFbJc6BjYv
f+olKnlIKFSmDvcF74U6w1F0ObugwTNKNxeYKPKhX4FiencUbRwkHoYHdtZdSctz
TKy08qKQyCAccqCRpdo6ZtYXPAU+2rthjYTOL7Zn+7SHUKCuJClcPnvEYjVcJxtZ
...
ubJIe5U4nMJbBkOqr7Kq6niaEkiLODa0tkpB8tKMYTMBdcYyHSXCzpo7U9sb6LAR
HktiTBDtRXviu2vbw7VRXhkMW2kjYZDtReQ5sAse04DvmD49zgTp1YxYW+wWFaL3
37X7/SNuLdHX4PHZXIWHBQ==
-----END XWING PUBLIC KEY-----	
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30002"]

    [[PKI.dirauth.Authorities]]
        Identifier = "auth3"
        IdentityPublicKey = """-----BEGIN ED25519 PUBLIC KEY-----
zQvydRYJq3npeLcg1NqIf+SswEKE5wFmiwNsI9Z1whQ=
-----END ED25519 PUBLIC KEY-----
"""
        PKISignatureScheme = "Ed25519"
        LinkPublicKey = """
-----BEGIN XWING PUBLIC KEY-----
OYK9FiC53xwZ1VST3jDOO4tR+cUMSVRSekmigZMChSjDCPZbKut8TblxtlUfc/yi
Ugorz4NIvYPMWUt3QPwS2UWq8/HMWXNGPUiAevg12+oV+jOJXaJeCfY24UekJnSw
TNcdGaFZFSR0FocFcPBBnrK1M2B8w8eEUKQIsXRDM3x/8aRIuDif+ve8rSwpgKeh
...
OdVD3yw7OOS8uPZLORGQFyJbHtVmFPVvwja4G/o2gntAoHUZ2LiJJakpVhhlSyrI
yuzvwwFtZVfWtNb5gAKZCyg0aduR3qgd7MPerRF+YopZk3OCRpC02YxfUZrHv398
FZWJFK0R8iU52CEUxVpXTA==
-----END XWING PUBLIC KEY-----	
"""
        WireKEMScheme = "xwing"
        Addresses = ["127.0.0.1:30003"]
  • Identifier

    Specifies the human-readable identifier for a node, which must be unique per mixnet. The identifier can be an FQDN but does not have to be.

    Type: string

    Required: Yes

  • IdentityPublicKey

    String containing the node's public identity key in PEM format. IdentityPublicKey is the node's permanent identifier and is used to verify cryptographic signatures produced by its private identity key.

    Type: string

    Required: Yes

  • PKISignatureScheme

    Specifies the cryptographic signature scheme that will be used by all components of the mix network when interacting with the PKI system. Mix nodes sign their descriptors using this signature scheme, and dirauth nodes similarly sign PKI documents using the same scheme.

    Type: string

    Required: Yes

  • LinkPublicKey

    String containing the peer's public link-layer key in PEM format. LinkPublicKey must match the specified WireKEMScheme.

    Type: string

    Required: Yes

  • WireKEMScheme

    The name of the wire protocol key-encapsulation mechanism (KEM) to use.

    Type: string

    Required: Yes

  • Addresses

    Specifies a list of one or more address URLs in a format that contains the transport protocol, IP address, and port number that the server will bind to for incoming connections. Katzenpost supports URLs that start with either "tcp://" or "quic://" such as: ["tcp://192.168.1.1:30001"] and ["quic://192.168.1.1:40001"]. The value of Addresses is advertised in the PKI document.

    Type: []string

    Required: Yes

Service node: Management section

The Management section specifies connectivity information for the Katzenpost control protocol which can be used to make run-time configuration changes. A configuration resembles the following, substituting the node's configured DataDir value as part of the Path value:

[Management]
   Enable = false
   Path = "/node_datadir/management_sock"
  • Enable

    If true, the management interface is enabled.

    Type: bool

    Required: No

  • Path

    Specifies the path to the management interface socket. If left empty, then management_sock is located in the configuration's defined DataDir.

    Type: string

    Required: No

Service node: SphinxGeometry section

The SphinxGeometry section defines parameters for the Sphinx encrypted nested-packet format used internally by Katzenpost.

The settings in this section are generated by the gensphinx utility, which computes the Sphinx geometry based on the following user-supplied directives:

  • The number of mix node layers (not counting gateway and service nodes)

  • The length of the application-usable packet payload

  • The selected NIKE or KEM scheme

[Warning] Warning

The values in the SphinxGeometry configuration section must be programmatically generated by gensphinx. Many of the parameters are interdependent and cannot be individually modified. Do not modify the these values by hand.

The gensphinx output in TOML should then be pasted unchanged into the node's configuration file, as shown below.

[SphinxGeometry]
                PacketLength = 3082
                NrHops = 5
                HeaderLength = 476
                RoutingInfoLength = 410
                PerHopRoutingInfoLength = 82
                SURBLength = 572
                SphinxPlaintextHeaderLength = 2
                PayloadTagLength = 32
                ForwardPayloadLength = 2574
                UserForwardPayloadLength = 2000
                NextNodeHopLength = 65
                SPRPKeyMaterialLength = 64
                NIKEName = "x25519"
                KEMName = ""
  • PacketLength

    The length of a Sphinx packet in bytes.

    Type: int

    Required: Yes

  • NrHops

    The number of hops a Sphinx packet takes through the mixnet. Because packet headers hold destination information for each hop, the size of the header increases linearly with the number of hops.

    Type: int

    Required: Yes

  • HeaderLength

    The total length of the Sphinx packet header in bytes.

    Type: int

    Required: Yes

  • RoutingInfoLength

    The total length of the routing information portion of the Sphinx packet header.

    Type: int

    Required: Yes

  • PerHopRoutingInfoLength

    The length of the per-hop routing information in the Sphinx packet header.

    Type: int

    Required: Yes

  • SURBLength

    The length of a single-use reply block (SURB).

    Type: int

    Required: Yes

  • SphinxPlaintextHeaderLength

    The length of the plaintext Sphinx packet header.

    Type: int

    Required: Yes

  • PayloadTagLength

    The length of the payload tag.

    Type: int

    Required: Yes

  • ForwardPayloadLength

    The total size of the payload.

    Type: int

    Required: Yes

  • UserForwardPayloadLength

    The size of the usable payload.

    Type: int

    Required: Yes

  • NextNodeHopLength

    The NextNodeHopLength is derived from the largest routing-information block that we expect to encounter. Other packets have NextNodeHop + NodeDelay sections, or a Recipient section, both of which are shorter.

    Type: int

    Required: Yes

  • SPRPKeyMaterialLength

    The length of the strong pseudo-random permutation (SPRP) key.

    Type: int

    Required: Yes

  • NIKEName

    The name of the non-interactive key exchange (NIKE) scheme used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

  • KEMName

    The name of the key encapsulation mechanism (KEM) used by Sphinx packets.

    NIKEName and KEMName are mutually exclusive.

    Type: string

    Required: Yes

Service node: Debug section

The Debug section is the Katzenpost server debug configuration for advanced tuning.

[Debug]
                NumSphinxWorkers = 16
                NumServiceWorkers = 3
                NumGatewayWorkers = 3
                NumKaetzchenWorkers = 3
                SchedulerExternalMemoryQueue = false
                SchedulerQueueSize = 0
                SchedulerMaxBurst = 16
                UnwrapDelay = 250
                GatewayDelay = 500
                ServiceDelay = 500
                KaetzchenDelay = 750
                SchedulerSlack = 150
                SendSlack = 50
                DecoySlack = 15000
                ConnectTimeout = 60000
                HandshakeTimeout = 30000
                ReauthInterval = 30000
                SendDecoyTraffic = false
                DisableRateLimit = false
                GenerateOnly = false
  • NumSphinxWorkers

    Specifies the number of worker instances to use for inbound Sphinx packet processing.

    Type: int

    Required: No

  • NumProviderWorkers

    Specifies the number of worker instances to use for provider specific packet processing.

    Type: int

    Required: No

  • NumKaetzchenWorkers

    Specifies the number of worker instances to use for Kaetzchen-specific packet processing.

    Type: int

    Required: No

  • SchedulerExternalMemoryQueue

    If true, the experimental disk-backed external memory queue is enabled.

    Type: bool

    Required: No

  • SchedulerQueueSize

    Specifies the maximum scheduler queue size before random entries will start getting dropped. A value less than or equal to zero is treated as unlimited.

    Type: int

    Required: No

  • SchedulerMaxBurst

    Specifies the maximum number of packets that will be dispatched per scheduler wakeup event.

    Type:

    Required: No

  • UnwrapDelay

    Specifies the maximum unwrap delay due to queueing in milliseconds.

    Type: int

    Required: No

  • GatewayDelay

    Specifies the maximum gateway node worker delay due to queueing in milliseconds.

    Type: int

    Required: No

  • ServiceDelay

    Specifies the maximum provider delay due to queueing in milliseconds.

    Type: int

    Required: No

  • KaetzchenDelay

    Specifies the maximum kaetzchen delay due to queueing in milliseconds.

    Type: int

    Required: No

  • SchedulerSlack

    Specifies the maximum scheduler slack due to queueing and/or processing in milliseconds.

    Type: int

    Required: No

  • SendSlack

    Specifies the maximum send-queue slack due to queueing and/or congestion in milliseconds.

    Type: int

    Required: No

  • DecoySlack

    Specifies the maximum decoy sweep slack due to external delays such as latency before a loop decoy packet will be considered lost.

    Type: int

    Required: No

  • ConnectTimeout

    Specifies the maximum time a connection can take to establish a TCP/IP connection in milliseconds.

    Type: int

    Required: No

  • HandshakeTimeout

    Specifies the maximum time a connection can take for a link-protocol handshake in milliseconds.

    Type: int

    Required: No

  • ReauthInterval

    Specifies the interval at which a connection will be reauthenticated in milliseconds.

    Type: int

    Required: No

  • SendDecoyTraffic

    If true, decoy traffic is enabled. This parameter is experimental and untuned, and is disabled by default.

    [Note] Note

    This option will be removed once decoy traffic is fully implemented.

    Type: bool

    Required: No

  • DisableRateLimit

    If true, the per-client rate limiter is disabled.

    [Note] Note

    This option should only be used for testing.

    Type: bool

    Required: No

  • GenerateOnly

    If true, the server immediately halts and cleans up after long-term key generation.

    Type: bool

    Required: No

1.5 -

NAT considerations for Katzenpost servers

NAT considerations for Katzenpost servers


Any Katzenpost server node can be configured to run behind a properly configured router that supports network address translation (NAT) and similar network topologies that traverse public and private network boundaries. This applies to directory authorities, gateways that allow clients to connect to the network, mix nodes, and service nodes that provide protocols over the mix network such as ping and spool services for storing messages or rendezvous information.

Typically, the router connecting a LAN with the Internet blocks incoming connections by default, and must be configured to forward traffic from the Internet to a destination host based on port number. These target addresses are most often drawn from RFC 6598 private address space, although more exotic topologies involving public IP address may also be targeted. (Router configuration for NAT topologies in general is beyond the scope of this topic.) For such cases, where the host listens on a LAN-side address:port but is accessed publicly using a different address:port, Katzenpost provides mechanisms to specify both addresses.

[Note] Note

Katzenpost does not support NAT penetration protocols such as NATPMP, STUN, TURN, and UPnP.

Addresses and BindAddresses

In a direct network connection, the values defined in the server Addresses parameter define the addresses on which the node listens for incoming connections, and which are advertised to other mixnet components in the PKI document. By supplying the optional BindAddresses parameter, you can define a second address group: LAN-side addresses that are not advertised in the PKI document. This is useful for NAT scenarios, which involve both public and private address spaces.

[Note] Note

The Addresses and BindAddresses parameters are closely analogous to Tor's Address and ORPort parameters. For more information, see the torrc man page.

The following table shows the details for these two parameters. For more information about node configuration, see Components and configuration of the Katzenpost mixnet.

Table 1. Addresses and BindAddresses parameters

Parameter Required Description
Addresses Yes

Specifies a list of one or more address URIs in a format that contains the transport protocol (typically TCP), an IP address, and a port number that the node will bind to for incoming connections. This value is advertised in the PKI document.

BindAddresses No

If true (that is, if this parameter is present), this parameter sets listener address:port values that the server will bind to and accept connections on, but that are not advertised in the PKI document. In this case, Addresses defines public addresses on the Internet side of a NAT router, while BindAddresses defines a different set of addresses behind the NAT router.


[Note] Note

Directory authorities do not support the BindAddresses parameter, but can still be used behind NAT. For more information, see Hosting a directory authority behind NAT

Hosting mix, gateway, and service nodes behind NAT

This section provides an example of a Katzenpost topology that make use of the BindAddresses parameter. In this scenario, a mix node behind NAT listens on local addresses for connections, while advertising a public address and port to its peer, a directory authority, that is assumed to have a publicly routable address.

Figure 1. Accessing a mix node behind NAT


Enlarge diagram

Key observations

  • The configuration file on the NATed mix node is katzenpost.toml.

  • The relevant section of the configuration file is [Server].

  • The Addresses parameter specifies the publicly routable address:port, 203.0.113.10:1234, over which the mix node can be reached from the Internet. This value is periodically advertised in the PKI document to other components of the mix network.

  • The BindAddresses parameter specifies the LAN address:port, 192.168.0.2:1234, on which the node listens for incoming Sphinx packets from peers.

  • The NAT router has two configured addresses, public address 203.0.113.10 and private LAN address 192.168.0.1.

  • The NAT router forwards traffic for 203.0.113.10:1234 to the mix node's LAN address:port, 192.168.0.2:1234, where the configured listener is bound.

The configuration in this example applies equally well to a NATed gateway node or service provider. A NATed gateway node would also be reachable by a client with knowledge of the gateway's public address.

Hosting a directory authority behind NAT

Directory authorities have no support for the BindAddresses parameter. They also do not advertise an address in the PKI document, because peers must already know the address in order to fetch the document, which means that addresses for dirauths must be provided out-of-band.

Consequently, the Addresses parameter for dirauths performs the same function as BindAddresses on the other node types, that is, to define the node's listening address:port values, but not an advertised address. In a NAT scenario, these addresses can refer to any target that is situated on the LAN side of the NAT router.

Figure 2. Accessing a directory authority behind NAT


Enlarge diagram

Key observations

  • The configuration file on the NATed dirauth is authority.toml.

  • The relevant section of the configuration file is [Server].

  • The Addresses parameter specifies a private RFC 6598address:port, 192.168.0.2:1234. By definition, this address cannot be reached directly from the Internet.

  • There is no BindAddresses parameter.

  • The NAT device has two configured addresses, public address 198.51.100.50, and LAN address 192.168.0.1.

  • The NAT device routes traffic targeting 198.51.100.50:1234 to the address:port specified in Addresses, 192.168.0.2:1234.

  • The dirauth does not advertise its address on the mix network. The address must provided to peers out-of-band.

1.6 -

Appendix: Configuration files from the Docker test mixnet

Appendix: Configuration files from the Docker test mixnet


As an aid to administrators implementing a Katzenpost mixnet, this appendix provides lightly edited examples of configuration files for each Katzenpost node type. These files are drawn from a built instance of the Docker test mixnet. These code listings are meant to be used as a reference alongside the detailed configuration documentation in Components and configuration of the Katzenpost mixnet. You cannot use these listings as a drop-in solution in your own mixnets for reasons explained in the Network topology and components section of the Docker test mixnet documentation.

Directory authority

Source: ../katzenpost/docker/voting_mixnet/auth1/authority.toml

[Server]
  Identifier = "auth1"
  WireKEMScheme = "xwing"
  PKISignatureScheme = "Ed448-Dilithium3"
  Addresses = ["tcp://127.0.0.1:30001"]
  DataDir = "/voting_mixnet/auth1"

[[Authorities]]
  Identifier = "auth1"
  IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nfvcvAfUpeu7lMHjQBw [...] Gpi8ovBXl9ENIHLwA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
  PKISignatureScheme = "Ed448-Dilithium3"
  LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nsxxS04mftoEmwjxE/w [...] expP2fbERpGQwVNg==\n-----END XWING PUBLIC KEY-----\n"
  WireKEMScheme = "xwing"
  Addresses = ["tcp://127.0.0.1:30001"]

[[Authorities]]
  Identifier = "auth2"
  IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\n5nsy6uFQ1782fZ+iYn [...] Sdr2xoinylYJr/3AA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
  PKISignatureScheme = "Ed448-Dilithium3"
  LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nkQzCJvaS6jg06szLea [...] PG1Bzx1JwHGFxRBQ==\n-----END XWING PUBLIC KEY-----\n"
  WireKEMScheme = "xwing"
  Addresses = ["tcp://127.0.0.1:30002"]

[[Authorities]]
  Identifier = "auth3"
  IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nJzkFpS035de1PmA2MM [...] jo6Z7is9GLs0YxVQA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
  PKISignatureScheme = "Ed448-Dilithium3"
  LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\n+pIUsgEGwHa8k4GZcb [...] 1mxoc+4kcgZWuOAg==\n-----END XWING PUBLIC KEY-----\n"
  WireKEMScheme = "xwing"
  Addresses = ["tcp://127.0.0.1:30003"]

[Logging]
  Disable = false
  File = "katzenpost.log"
  Level = "INFO"

[Parameters]
  SendRatePerMinute = 0
  Mu = 0.005
  MuMaxDelay = 1000
  LambdaP = 0.001
  LambdaPMaxDelay = 1000
  LambdaL = 0.0005
  LambdaLMaxDelay = 1000
  LambdaD = 0.0005
  LambdaDMaxDelay = 3000
  LambdaM = 0.0005
  LambdaG = 0.0
  LambdaMMaxDelay = 100
  LambdaGMaxDelay = 100

[Debug]
  Layers = 3
  MinNodesPerLayer = 1
  GenerateOnly = false

[[Mixes]]
  Identifier = "mix1"
  IdentityPublicKeyPem = "../mix1/identity.public.pem"

[[Mixes]]
  Identifier = "mix2"
  IdentityPublicKeyPem = "../mix2/identity.public.pem"

[[Mixes]]
  Identifier = "mix3"
  IdentityPublicKeyPem = "../mix3/identity.public.pem"

[[GatewayNodes]]
  Identifier = "gateway1"
  IdentityPublicKeyPem = "../gateway1/identity.public.pem"

[[ServiceNodes]]
  Identifier = "servicenode1"
  IdentityPublicKeyPem = "../servicenode1/identity.public.pem"

[Topology]

  [[Topology.Layers]]

    [[Topology.Layers.Nodes]]
      Identifier = "mix1"
      IdentityPublicKeyPem = "../mix1/identity.public.pem"

  [[Topology.Layers]]

    [[Topology.Layers.Nodes]]
      Identifier = "mix2"
      IdentityPublicKeyPem = "../mix2/identity.public.pem"

  [[Topology.Layers]]

    [[Topology.Layers.Nodes]]
      Identifier = "mix3"
      IdentityPublicKeyPem = "../mix3/identity.public.pem"

[SphinxGeometry]
  PacketLength = 3082
  NrHops = 5
  HeaderLength = 476
  RoutingInfoLength = 410
  PerHopRoutingInfoLength = 82
  SURBLength = 572
  SphinxPlaintextHeaderLength = 2
  PayloadTagLength = 32
  ForwardPayloadLength = 2574
  UserForwardPayloadLength = 2000
  NextNodeHopLength = 65
  SPRPKeyMaterialLength = 64
  NIKEName = "x25519"
  KEMName = ""

Mix node

Source: ../katzenpost/docker/voting_mixnet/mix1/katzenpost.toml

[Server]
  Identifier = "mix1"
  WireKEM = "xwing"
  PKISignatureScheme = "Ed448-Dilithium3"
  Addresses = ["tcp://127.0.0.1:30010", "quic://[::1]:30011"]
  MetricsAddress = "127.0.0.1:30012"
  DataDir = "/voting_mixnet/mix1"
  IsGatewayNode = false
  IsServiceNode = false

[Logging]
  Disable = false
  File = "katzenpost.log"
  Level = "INFO"

[PKI]
  [PKI.Voting]

    [[PKI.Voting.Authorities]]
      Identifier = "auth1"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nfvcvAfUpeu7lMHjQBw [...] Gpi8ovBXl9ENIHLwA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nsxxS04mftoEmwjxE/w [...] expP2fbERpGQwVNg==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30001"]

    [[PKI.Voting.Authorities]]
      Identifier = "auth2"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\n5nsy6uFQ1782fZ+iYn [...] Sdr2xoinylYJr/3AA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nkQzCJvaS6jg06szLea [...] PG1Bzx1JwHGFxRBQ==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30002"]

    [[PKI.Voting.Authorities]]
      Identifier = "auth3"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nJzkFpS035de1PmA2M [...] jo6Z7is9GLs0YxVQA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\n+pIUsgEGwHa8k4GZcb [...] 1mxoc+4kcgZWuOAg==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30003"]

[Management]
  Enable = false
  Path = "/voting_mixnet/mix1/management_sock"

[SphinxGeometry]
  PacketLength = 3082
  NrHops = 5
  HeaderLength = 476
  RoutingInfoLength = 410
  PerHopRoutingInfoLength = 82
  SURBLength = 572
  SphinxPlaintextHeaderLength = 2
  PayloadTagLength = 32
  ForwardPayloadLength = 2574
  UserForwardPayloadLength = 2000
  NextNodeHopLength = 65
  SPRPKeyMaterialLength = 64
  NIKEName = "x25519"
  KEMName = ""

[Debug]
  NumSphinxWorkers = 16
  NumServiceWorkers = 3
  NumGatewayWorkers = 3
  NumKaetzchenWorkers = 3
  SchedulerExternalMemoryQueue = false
  SchedulerQueueSize = 0
  SchedulerMaxBurst = 16
  UnwrapDelay = 250
  GatewayDelay = 500
  ServiceDelay = 500
  KaetzchenDelay = 750
  SchedulerSlack = 150
  SendSlack = 50
  DecoySlack = 15000
  ConnectTimeout = 60000
  HandshakeTimeout = 30000
  ReauthInterval = 30000
  SendDecoyTraffic = false
  DisableRateLimit = false
  GenerateOnly = false

Gateway node

Source: ../katzenpost/docker/voting_mixnet/gateway1/katzenpost.toml

[Server]
  Identifier = "gateway1"
  WireKEM = "xwing"
  PKISignatureScheme = "Ed448-Dilithium3"
  Addresses = ["tcp://127.0.0.1:30004", "quic://[::1]:30005", "onion://thisisjustatestoniontoverifythatconfigandpkiworkproperly.onion:4242"]
  BindAddresses = ["tcp://127.0.0.1:30004", "quic://[::1]:30005"]
  MetricsAddress = "127.0.0.1:30006"
  DataDir = "/voting_mixnet/gateway1"
  IsGatewayNode = true
  IsServiceNode = false

[Logging]
  Disable = false
  File = "katzenpost.log"
  Level = "INFO"

[Gateway]
  [Gateway.UserDB]
    Backend = "bolt"
    [Gateway.UserDB.Bolt]
      UserDB = "/voting_mixnet/gateway1/users.db"
  [Gateway.SpoolDB]
    Backend = "bolt"
    [Gateway.SpoolDB.Bolt]
      SpoolDB = "/voting_mixnet/gateway1/spool.db"

[PKI]
  [PKI.Voting]

    [[PKI.Voting.Authorities]]
      Identifier = "auth1"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nfvcvAfUpeu7lMHjQBw [...] Gpi8ovBXl9ENIHLwA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nsxxS04mftoEmwjxE/w [...] expP2fbERpGQwVNg==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30001"]

    [[PKI.Voting.Authorities]]
      Identifier = "auth2"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\n5nsy6uFQ1782fZ+iYn [...] Sdr2xoinylYJr/3AA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nkQzCJvaS6jg06szLea [...] PG1Bzx1JwHGFxRBQ==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30002"]

    [[PKI.Voting.Authorities]]
      Identifier = "auth3"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nJzkFpS035de1PmA2MM [...] jo6Z7is9GLs0YxVQA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\n+pIUsgEGwHa8k4GZcb [...] 1mxoc+4kcgZWuOAg==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30003"]

[Management]
  Enable = true
  Path = "/voting_mixnet/gateway1/management_sock"

[SphinxGeometry]
  PacketLength = 3082
  NrHops = 5
  HeaderLength = 476
  RoutingInfoLength = 410
  PerHopRoutingInfoLength = 82
  SURBLength = 572
  SphinxPlaintextHeaderLength = 2
  PayloadTagLength = 32
  ForwardPayloadLength = 2574
  UserForwardPayloadLength = 2000
  NextNodeHopLength = 65
  SPRPKeyMaterialLength = 64
  NIKEName = "x25519"
  KEMName = ""

[Debug]
  NumSphinxWorkers = 16
  NumServiceWorkers = 3
  NumGatewayWorkers = 3
  NumKaetzchenWorkers = 3
  SchedulerExternalMemoryQueue = false
  SchedulerQueueSize = 0
  SchedulerMaxBurst = 16
  UnwrapDelay = 250
  GatewayDelay = 500
  ServiceDelay = 500
  KaetzchenDelay = 750
  SchedulerSlack = 150
  SendSlack = 50
  DecoySlack = 15000
  ConnectTimeout = 60000
  HandshakeTimeout = 30000
  ReauthInterval = 30000
  SendDecoyTraffic = false
  DisableRateLimit = false
  GenerateOnly = false

Service node

Source: ../katzenpost/docker/voting_mixnet/servicenode1/katzenpost.toml

[Server]
  Identifier = "servicenode1"
  WireKEM = "xwing"
  PKISignatureScheme = "Ed448-Dilithium3"
  Addresses = ["tcp://127.0.0.1:30007", "quic://[::1]:30008"]
  MetricsAddress = "127.0.0.1:30009"
  DataDir = "/voting_mixnet/servicenode1"
  IsGatewayNode = false
  IsServiceNode = true

[Logging]
  Disable = false
  File = "katzenpost.log"
  Level = "INFO"

[ServiceNode]

  [[ServiceNode.Kaetzchen]]
    Capability = "echo"
    Endpoint = "+echo"
    Disable = false

  [[ServiceNode.Kaetzchen]]
    Capability = "testdest"
    Endpoint = "+testdest"
    Disable = false

  [[ServiceNode.CBORPluginKaetzchen]]
    Capability = "spool"
    Endpoint = "+spool"
    Command = "/voting_mixnet/memspool.alpine"
    MaxConcurrency = 1
    Disable = false
    [ServiceNode.CBORPluginKaetzchen.Config]
      data_store = "/voting_mixnet/servicenode1/memspool.storage"
      log_dir = "/voting_mixnet/servicenode1"

  [[ServiceNode.CBORPluginKaetzchen]]
    Capability = "pigeonhole"
    Endpoint = "+pigeonhole"
    Command = "/voting_mixnet/pigeonhole.alpine"
    MaxConcurrency = 1
    Disable = false
    [ServiceNode.CBORPluginKaetzchen.Config]
      db = "/voting_mixnet/servicenode1/map.storage"
      log_dir = "/voting_mixnet/servicenode1"

  [[ServiceNode.CBORPluginKaetzchen]]
    Capability = "panda"
    Endpoint = "+panda"
    Command = "/voting_mixnet/panda_server.alpine"
    MaxConcurrency = 1
    Disable = false
    [ServiceNode.CBORPluginKaetzchen.Config]
      fileStore = "/voting_mixnet/servicenode1/panda.storage"
      log_dir = "/voting_mixnet/servicenode1"
      log_level = "INFO"

  [[ServiceNode.CBORPluginKaetzchen]]
    Capability = "http"
    Endpoint = "+http"
    Command = "/voting_mixnet/proxy_server.alpine"
    MaxConcurrency = 1
    Disable = false
    [ServiceNode.CBORPluginKaetzchen.Config]
      host = "localhost:4242"
      log_dir = "/voting_mixnet/servicenode1"
      log_level = "DEBUG"

[PKI]
  [PKI.Voting]

    [[PKI.Voting.Authorities]]
      Identifier = "auth1"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nfvcvAfUpeu7lMHjQBw [...] Gpi8ovBXl9ENIHLwA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nsxxS04mftoEmwjxE/w [...] expP2fbERpGQwVNg==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30001"]

    [[PKI.Voting.Authorities]]
      Identifier = "auth2"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\n5nsy6uFQ1782fZ+iYn [...] Sdr2xoinylYJr/3AA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\nkQzCJvaS6jg06szLea [...] PG1Bzx1JwHGFxRBQ==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30002"]

    [[PKI.Voting.Authorities]]
      Identifier = "auth3"
      IdentityPublicKey = "-----BEGIN ED448-DILITHIUM3 PUBLIC KEY-----\nJzkFpS035de1PmA2MM [...] jo6Z7is9GLs0YxVQA=\n-----END ED448-DILITHIUM3 PUBLIC KEY-----\n"
      PKISignatureScheme = "Ed448-Dilithium3"
      LinkPublicKey = "-----BEGIN XWING PUBLIC KEY-----\n+pIUsgEGwHa8k4GZcb [...] 1mxoc+4kcgZWuOAg==\n-----END XWING PUBLIC KEY-----\n"
      WireKEMScheme = "xwing"
      Addresses = ["tcp://127.0.0.1:30003"]

[Management]
  Enable = true
  Path = "/voting_mixnet/servicenode1/management_sock"

[SphinxGeometry]
  PacketLength = 3082
  NrHops = 5
  HeaderLength = 476
  RoutingInfoLength = 410
  PerHopRoutingInfoLength = 82
  SURBLength = 572
  SphinxPlaintextHeaderLength = 2
  PayloadTagLength = 32
  ForwardPayloadLength = 2574
  UserForwardPayloadLength = 2000
  NextNodeHopLength = 65
  SPRPKeyMaterialLength = 64
  NIKEName = "x25519"
  KEMName = ""

[Debug]
  NumSphinxWorkers = 16
  NumServiceWorkers = 3
  NumGatewayWorkers = 3
  NumKaetzchenWorkers = 4
  SchedulerExternalMemoryQueue = false
  SchedulerQueueSize = 0
  SchedulerMaxBurst = 16
  UnwrapDelay = 250
  GatewayDelay = 500
  ServiceDelay = 500
  KaetzchenDelay = 750
  SchedulerSlack = 150
  SendSlack = 50
  DecoySlack = 15000
  ConnectTimeout = 60000
  HandshakeTimeout = 30000
  ReauthInterval = 30000
  SendDecoyTraffic = false
  DisableRateLimit = false
  GenerateOnly = false

2 -







Specifications

These technical specifications describe the specifics of Katzenpost protocols and implementations, and are aimed primarily at software developers.

Title Description Links
📖 Pigeonhole replicas over Reticulum Pigeonhole storage replicas on a Reticulum mesh, and groups shared between Reticulum and the mixnet HTML
📖 Pigeonhole protocols over Reticulum How a client on a Reticulum mesh reads and writes Pigeonhole boxes: replicas, requests, BACAP, tombstones and epochs, for any protocol built on boxes HTML
📖 katzenqt1 chat over Reticulum How to write a group chat app for a Reticulum mesh that interoperates with katzenrns: the katzenqt1 protocol over Pigeonhole boxes HTML
📖 Autoresponder extension Autoresponder agent that runs on service nodes HTML / PDF
📖 Certificate format PKI certificate format HTML / PDF
📖 Contact voucher design Contact voucher design HTML / PDF
📖 Contact voucher protocol narration An implementation-oriented narration of the Contact Voucher protocol. HTML
📖 Directory authority (PKI) The directory authority protocol at v0.0.107, with versioned implementation links HTML
📖 Group chat design Katzenpost group chat design HTML / PDF
📖 KEM Sphinx packet format The KEM Sphinx variation of Sphinx HTML / PDF
📖 Mix decoy stats propagation Mix decoy stats propagation HTML / PDF
📖 Mixnet design Describes the overall mixnet design HTML / PDF
📖 Pigeonhole design Pigeonhole design specification HTML / PDF
📖 Pigeonhole services How clients discover and connect to pigeonhole services HTML
📖 Pigeonhole courier and replica decoy traffic Decoy traffic design for Pigeonhole couriers and replicas HTML
📖 Public key infrastructure (deprecated) Deprecated original PKI design, kept for reference. See the Directory authority specification for the current design HTML / PDF
📖 Sphinx packet format Sphinx packet format, a nested cryptographic packet format designed for mix networks HTML / PDF
📖 Sphinx replay detection Sphinx packet replay detection HTML / PDF
📖 Thin client Thin client library design HTML / PDF
📖 Wire protocol PQ Noise transport encryption between clients, mix servers, and directory authorities HTML / PDF
📖 Glossary Consolidated list of terms defined in the specifications HTML / PDF
📖 References Consolidated list of references cited in the specifications HTML / PDF

2.1 - Contact Voucher Protocol Narration

Introduction

The voucher spec was very difficult for me to read and it overloads variable names and doesn’t make certain facts explicit enough. I wrote this spec for my own understanding of the design as an implementation guide for myself.

Streams

There is no separate reply stream. Alice replies on the very same stream Bob used to mint the voucher.

  • MessageStream: Bob writes; the group reads. This is the stream whose live messages the protocol must protect.
  • VoucherStream: the rendezvous, derived entirely from the Voucher. Box 0 holds Bob’s VoucherPayload; box 1 holds Alice’s VoucherReply.
  • the group’s other streams: each existing member has their own MessageStream, just like Bob’s.

Stream Objects

  • MessageStream: .WriteCap (Bob keeps), .ReadCap (travels in VoucherPayload, inside SignedPleaseAdd).
  • VoucherStream: read and write caps derivable by anyone holding the Voucher.
  • VoucherKeypair: VoucherSecretKey (Bob keeps), VoucherPublicKey (travels in VoucherPayload). This is the MKEM keypair under which Alice seals the reply to Bob.

Messages

  • SignedPleaseAdd is Bob’s signed self-introduction: a serialized PleaseAdd (his DisplayName and MessageStream.ReadCap) plus a signature over it produced by MessageStream.WriteCap.
// PleaseAdd is a member's request to join, carrying their display name
// and the read cap that lets others read their messages.
type PleaseAdd struct {
    // DisplayName is the party's name to be displayed in chat clients.
    DisplayName string

    // UniversalReadCap is the BACAP read cap for this member's
    // MessageStream, letting others read all messages posted by them.
    UniversalReadCap *bacap.UniversalReadCap
}

// SignedPleaseAdd binds a PleaseAdd to a signature made by the member's
// write cap, so any party can verify the name-and-cap binding.
type SignedPleaseAdd struct {
    // PleaseAdd contains the CBOR serialized PleaseAdd struct.
    PleaseAdd []byte

    // Signature contains the cryptographic signature over the PleaseAdd field.
    Signature []byte
}
  • WhoReply := the existing members’ MessageStream read caps (one or more), each unchanged and paired with a start index, so Bob can read everyone already in the group. Each index is the box after Alice’s last published acknowledgement of that stream; Alice’s own starts at her Introduction of Bob.
  • VoucherReply := WhoReply || VoucherSalt, MKEM-sealed to VoucherPublicKey and written to VoucherStream box 1. Box 1 is an ordinary BACAP box, so the payload is BACAP-encrypted as a stream box and then additionally MKEM-encrypted to Bob’s VoucherPublicKey; only Bob, holding VoucherSecretKey, can open it.
  • Introduction := Bob’s display name, his MessageStream read cap unchanged, and his salted start index, published to the existing group so the members can read Bob. The group receives the salted index directly and never the salt.
VoucherPayload := SignedPleaseAdd || VoucherPublicKey
Voucher        := Hash(VoucherPayload)

The VoucherSalt: re-seeding the MessageStream

VoucherSalt is the heart of the protocol. It is not a nonce and it does not modify BACAP. It is a value that replaces the KDF state inside a MessageStream’s MessageBoxIndex, which re-seeds the index chain and so moves the stream to a fresh, unpredictable sequence of box IDs. Only two parties ever touch it. Bob mutates his MessageStream.WriteCap by the salt and writes his real messages at the mutated position. Alice applies the same salt once to the index she pairs with Bob’s MessageStream.ReadCap, leaving the read cap itself unchanged, so writer and readers meet at the mutated position. The group never learns the salt; it only ever receives the already-salted index.

That is why the spec says derive Bob’s read capability from VoucherPayload + VoucherSalt: the read cap published in box 0 is only half of it. That derivation is Alice’s alone. The read cap in box 0 names Bob’s original stream; the salted index says where Bob’s real messages actually go. She performs the derivation once and hands the result to the group.

The salt is the one secret a voucher snoop never receives. It is born at induction, not at mint: Alice mints it and seals it inside the MKEM-encrypted VoucherReply. It is never written to box 0, so Bob’s PleaseAdd carries only his original read cap, never the salt. An interceptor of the out-of-band Voucher can derive the VoucherStream, read box 0, and check that the voucher was spent, but he holds only the read cap and its unsalted index. He cannot compute the salted box IDs, so he cannot read a single one of Bob’s actual messages. That is exactly the spec’s stated confidentiality goal.

Because the salt re-seeds rather than decorates the stream, it is a per-member fact known only to that member and to whoever inducted them. A mature group mixes voucher-joined members (each on their own salt-mutated index) with seed members (on the unmutated index), and no member needs to carry any salt: every index that circulates beside a read cap is already salted. WhoReply hands Bob the existing members’ read caps with their start indexes, and the Introduction hands the group Bob’s read cap with the index Alice salted.

Steps

  1. Bob mints. He generates his MessageStream (keeping MessageStream.WriteCap) and a VoucherKeypair (keeping VoucherSecretKey). He forms SignedPleaseAdd = {DisplayName, MessageStream.ReadCap} signed by MessageStream.WriteCap; sets VoucherPayload := SignedPleaseAdd || VoucherPublicKey; Voucher := Hash(VoucherPayload).
  2. Bob publishes. The Voucher derives the VoucherStream; Bob writes VoucherPayload to box 0.
  3. Bob → Alice (OOB). He hands over only the Voucher.
  4. Alice reads and verifies. From Voucher she derives the VoucherStream, reads box 0, checks Hash(VoucherPayload) == Voucher, and verifies the SignedPleaseAdd signature against its read cap’s rootPK.
  5. Alice replies. She mints VoucherSalt, assembles WhoReply from the start positions above, forms VoucherReply := WhoReply || VoucherSalt, and MKEM-seals it to VoucherPublicKey. She publishes no acknowledgements between this step and the commit.
  6. Alice commits (all-or-nothing COPY). She first derives Bob’s start index by applying the VoucherSalt to his read cap’s index, leaving the read cap unchanged. Then, in one operation: write the sealed VoucherReply to VoucherStream box 1; publish the Introduction (Bob’s display name, his read cap, and his salted start index) to her group, which never sees the salt itself; tombstone box 0 against reuse. Because no acknowledgement separates the start positions from this commit, there is no race: every member keeps each box Alice had not acknowledged at the Introduction until Bob acknowledges it (see Joining in the group chat spec). She rewrites box 1 each replica epoch until Bob’s first message appears, for at most the Sent-box retention window; a Bob later than that needs a new voucher.
  7. Bob finishes. He polls VoucherStream box 1, MKEM-opens the VoucherReply with VoucherSecretKey, and recovers WhoReply and VoucherSalt. He mutates his MessageStream.WriteCap by the salt and begins writing real messages there. The group already holds his read cap and salted start index, so they read him without ever learning the salt. Both sides now share the live streams.

2.2 -

Gateway-side autoresponder extension (Kaetzchen) specification

Yawning Angel

Kali Kaneko

David Stainton

Abstract

This interface is meant to provide support for various autoresponder agents “Kaetzchen” that run on Katzenpost gateway instances, thus bypassing the need to run a discrete client instance to provide functionality. The use-cases for such agents include, but are not limited to, user identity key lookup, a discard address, and a loop-back responder for the purpose of cover traffic.


Conventions used in this document

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC2119.

Terminology

The following terms are used in this specification.

BlockSphinxPlaintext
The payload structure that is encapsulated by the Sphinx body.

gateway
A mix node on the edge of the mixnet that is the first hop for messages coming from clients. The gateway authenticates client connections and queues reply messages (SURBs) for retrieval.

SURB
Single use reply block. SURBs are used to achieve recipient anonymity, that is to say, SURBs function as a cryptographic delivery token that you can give to another client entity so that they can send you a message without them knowing your identity or location on the network. See SPHINXSPEC and SPHINX.

Extension overview

Each Kaetzchen agent will register as a potential recipient on its gateway. When the gateway receives a forward packet destined for a Kaetzchen instance, it will hand off the fully unwrapped packet along with its corresponding SURB to the agent, which will then act on the packet and optionally reply utilizing the SURB.

Agent requirements

  • Each agent operation MUST be idempotent.

  • Each agent operation request and response MUST fit within one Sphinx packet.

  • Each agent SHOULD register a recipient address that consists of an RFC5322 dot-atom value, and MUST register recipient addresses that are at most 64 octets in length.

  • The first byte of the agent’s response payload MUST be 0x01 to allow clients to easily differentiate between SURB-ACKs and agent responses.

Mix message formats

Messages from clients to Kaetzchen use the following payload format in the forward Sphinx packet:

struct {
uint8_t flags;
uint8_t reserved; /* Set to 0x00. */
select (flags) {
case 0:
opaque padding[sizeof(SphinxSURB)];
case 1:
SphinxSURB surb;
}
opaque plaintext[];
} KaetzchenMessage;

The plaintext component of a KaetzchenMessage MUST be padded by appending “0x00” bytes to make the final total size of a KaetzchenMessage equal to that of a BlockSphinxPlaintext.

Messages (replies) from the Kaetzchen to client use the following payload format in the SURB generated packet:

struct {
opaque plaintext[];
} KaetzchenReply;

The plaintext component of a KaetzchenReply MUST be padded by appending “0x00” bytes to make the final total size of a KaetzchenReply equal to that of a BlockSphinxPlaintext

PKI extensions

Each gateway SHOULD publish the list of publicly accessible Kaetzchen agent endpoints in its MixDescriptor, along with any other information required to utilize the agent.

The gateway should make this information available in the form of a map in which the keys are the label used to identify a given service, and the value is a map with arbitrary keys.

Valid service names refer to the services defined in extensions to this specification. Every service MUST be implemented by one and only one Kaetzchen agent.

For each service, the gateway MUST advertise a field for the endpoint at which the Kaetzchen agent can be reached, as a key value pair where the key is endpoint, and the value is the gateway side endpoint identifier.

{ "kaetzchen":
{ "keyserver" : {
"endpoint": "+keyserver",
"version" : 1 } },
{ "discard" : {
"endpoint": "+discard", } },
{ "loop" : {
"endpoint": "+loopback",
"restrictedToUsers": true } },
}

Anonymity considerations

In the event that the mix keys for the entire return path are compromised, it is possible for adversaries to unwrap the SURB and determine the final recipient of the reply.

Depending on what sort of operations a given agent implements, there may be additional anonymity impact that requires separate consideration.

Clients MUST NOT have predictable retransmission otherwise this makes active confirmations attacks possible which could be used to discover the ingress gateway of the client.

Security considerations

It is possible to use this mechanism to flood a victim with unwanted traffic by constructing a request with a SURB destined for the target.

Depending on the operations implemented by each agent, the added functionality may end up being a vector for denial-of-service attacks in the form of CPU or network overload.

Unless the agent implements additional encryption, message integrity and privacy is limited to that which is provided by the base Sphinx packet format and parameterization.

Acknowledgments

The inspiration for this extension comes primarily from a design by Vincent Breitmoser.

References

KATZMIXPKI

Angel, Y., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Public Key Infrastructure Specification”, December 2017, https://katzenpost.network/docs/specs/pdf/pki.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC5322

Resnick, P., Ed., “Internet Message Format”, RFC 5322, DOI 10.17487/RFC5322, October 2008, https://www.rfc-editor.org/info/rfc5322.

SPHINX09

Danezis, G., Goldberg, I., “Sphinx: A Compact and Provably Secure Mix Format”, DOI 10.1109/SP.2009.15, May 2009, https://cypherpunks.ca/~iang/pubs/Sphinx_Oakland09.pdf.

SPHINXSPEC

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Sphinx Mix Network Cryptographic Packet Format Specification”, July 2017, https://katzenpost.network/docs/specs/pdf/sphinx.pdf.

2.3 -

The main text preserves the original certificate design and key-delegation proposals. The identity signature profile defines the v0.0.107 hybrid signature and key encodings. Current directory certificate envelopes use epoch-based expiration and a map of signatures.

Certificate format

David Stainton

Abstract

This document proposes a certificate format that Katzenpost mix server, directory authority server and clients will use.


Conventions used in this document

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC2119.

Introduction

Mix servers and directory authority servers need to have key agility in the sense of operational abilities such as key rotation and key revocation. That is, we wish for mixes and authorities to periodically utilize a long-term signing key for generating certificates for new short-term signing keys.

Yet another use-case for these certificate is to replace the use of JOSE RFC7515 in the voting directory authority system KATZMIXPKI for the multi-signature documents exchanged for voting and consensus.

Certificate format

The CBOR RFC7049 serialization format is used to serialize certificates:

Signature is a cryptographic signature which has an associated signer ID.

type Signature struct {
// Identity is the identity of the signer.
Identity []byte
// Signature is the actual signature value.
Signature []byte
}

Certificate structure for serializing certificates.

type certificate struct {
// Version is the certificate format version.
Version uint32

// Expiration is seconds since Unix epoch.
Expiration int64

// KeyType indicates the type of key
// that is certified by this certificate.
KeyType string

// Certified is the data that is certified by
// this certificate.
Certified []byte

// Signatures are the signature of the certificate.
Signatures []Signature
}

That is, one or more signatures sign the certificate. However the Certified field is not the only information that is signed. The Certified field along with the other non-signature fields are all concatenated together and signed. Before serialization the signatures are sorted by their identity so that the output is binary deterministic.

Certificate types

The certificate type field indicates the type of certificate. So far we have only two types:

  • identity key certificate

  • directory authority certificate

Both mixes and directory authority servers have a secret, long-term identity key. This key is ideally stored encrypted and offline, it’s used to sign key certificate documents. Key certificates contain a medium-term signing key that is used to sign other documents. In the case of an “authority signing key”, it is used to sign vote and consensus documents whereas the “mix singing key” is used to sign mix descriptors which are uploaded to the directory authority servers.

Certificate key types

It’s more practical to continue using Ed25519 ED25519 keys but it’s also possible that in the future we could upgrade to a stateless hash based post quantum cryptographic signature scheme such as SPHINCS-256 or SPHINCS+. SPHINCS256

Golang API

Our golang implementation is agnostic to the specific cryptographic signature scheme which is used. Cert can handle single and multiple signatures per document and has a variety of helper functions that ease use for multi signature use cases.

Acknowledgments

This specification was inspired by Tor Project’s certificate format specification document:

References

ED25519

https://www.rfc-editor.org/rfc/rfc8032.

KATZMIXPKI

Angel, Y., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Public Key Infrastructure Specification”, December 2017, https://katzenpost.network/docs/specs/pdf/pki.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC7049

C. Bormann, P. Hoffman, “Concise Binary Object Representation (CBOR)”, Internet Engineering Task Force (IETF), October 2013, https://www.rfc-editor.org/info/rfc7049.

RFC7515

Jones, M., Bradley, J., Sakimura, N., “JSON Web Signature (JWS)”, May 2015, https://www.rfc-editor.org/info/rfc7515.

RFC7693

Saarinen, M-J., Ed., and J-P. Aumasson, “The BLAKE2 Cryptographic Hash and Message Authentication Code (MAC)”, RFC 7693, DOI 10.17487/RFC7693, November 2015, http://www.rfc-editor.org/info/rfc7693.

SPHINCS256

Bernstein, D., Hopwood, D., Hulsing, A., Lange, T., Niederhagen, R., Papachristodoulou, L., Schwabe, P., Wilcox O’Hearn, Z., “SPHINCS: practical stateless hash-based signatures”, http://sphincs.cr.yp.to/sphincs-20141001.pdf.

Appendix: Identity signature profile

This profile defines identity signatures and key encodings for Namenlos with Katzenpost v0.0.107. Its rules apply to the current directory certificate envelopes. The main text above preserves the original certificate design.

Here, || means byte concatenation. CBOR fields carry raw public keys as byte strings. The key bytes have no ASN.1 wrapper, length prefix, or text encoding.

Key Value Explanation
Signature scheme Ed25519 Sphincs+ Use this exact name in the baseline certificate KeyType and document PKISignatureScheme. The space is significant.
Public key 96 bytes Ed25519 public key, 32 bytes, followed by SPHINCS+ public key, 64 bytes.
Private key 192 bytes Ed25519 seed, 32 bytes, Ed25519 public key, 32 bytes, then SPHINCS+ secret key, 128 bytes.
Identity hash BLAKE2b-256(identity_public_key) Hash the 96 raw public-key bytes. The result is 32 raw bytes.

The signature scheme definition fixes the name and component order. Identity hashes use sequential BLAKE2b from RFC 7693 with a 32-byte output. Do not truncate BLAKE2b-512 to produce BLAKE2b-256.

Key files

The public PEM label is ED25519 SPHINCS+ PUBLIC KEY. The private PEM label is ED25519 SPHINCS+ PRIVATE KEY. A PEM payload is the base64 encoding of the corresponding raw key. There are no PEM headers or ASN.1 fields.

The signature private payload is Ed25519_seed[32] || Ed25519_public[32] || SPHINCS_secret[128]. This encoding permits import of reference key files. An implementation can use its own internal storage format. The PEM codec wraps the raw private bytes.

Signature algorithm

Use pure Ed25519 from RFC 8032, Section 5.1 and SPHINCS+ round 3.1, parameter set SPHINCS+-SHAKE-256f-robust. The SPHINCS+ parameters are n=32, h=68, d=17, FORS height=9, FORS trees=35, and Winternitz w=16. Use the robust tweakable hashes. The public key is PUB_SEED[32] || root[32]. The secret key is SK_SEED[32] || SK_PRF[32] || PUB_SEED[32] || root[32].

Let M be the exact byte string to sign. Directory objects use their specified signing inputs. Both component algorithms sign the same M:

signature = Ed25519.Sign(ed_sk, M) || SPHINCS+.Sign(spx_sk, M)

The first signature is 64 bytes. The second is 49856 bytes. The complete signature is 49920 bytes.

The SPHINCS+ signature contains its 32-byte R, FORS signature, and hypertree signature in the order defined by the primitive specification. The signer uses fresh 32-byte optrand for SPHINCS+. Do not add an external prehash, context, message prefix, or length field. In particular, this profile uses neither Ed25519ph nor SLH-DSA. Verification MUST reject an incorrect signature length. It MUST accept only when both component signatures verify against M.

The implementation composes the two signatures and the two public keys in this order. Its SPHINCS+ selection fixes SHAKE-256f and robust hashing, the parameters, and the key and signature encodings.

2.4 -

Contact voucher specification

Threebit Hacker

Leif Ryge

Abstract


In order to join or initiate a conversation securely, participants need to exchange cryptographic key material. To address this problem, we created a slightly unusual design: contact vouchers.

Voucher design

In many systems, an invitation to communicate flows from an existing member of a conversation to the user being invited. In our contact voucher protocol, this flow is reversed: Bob, who wishes to join a conversation, hands a contact voucher (out-of-band) to existing member Alice, who then inducts Bob into the group.

This design mitigates two potential problems with the conventional way of doing things:

  1. A third party who observes the contact voucher does not get to read either participant’s actual messages. However,

    • A passive adversary learns that the voucher was spent, but does not get to observe further interactions.

    • An active adversary can create a new fake group to induct the member into, but does not learn anything about the existing group.

    In the future, to prevent this one-way impersonation, we could require that Alice and Bob both bring something on paper to their meeting.

    • Bob brings the contact voucher.

    • Alice brings a fingerprint for the VoucherReplyPublicKey (thwarting the active attacker).

  2. Only one thing that needs to delivered out-of-band to achieve a two-pass protocol (instead of a three-pass protocol):

    • One of the parties needs to bring key material to a meeting in order to establish contact.

The following diagram illustrates the contact voucher authentication handshake.

Figure 1. Contact voucher handshake

Bob and Alice exchange cryptographic information with the mixnet as proxy. They never have direct contact again after their initial meeting in real life.

Self-authenticating BACAP payload

The first message sent, the VoucherPayload, is authenticated in the following manner:

  1. The VoucherPayload is computed.

  2. A cryptographic hash of the VoucherPayload is computed. This hash is the Voucher.

  3. The Voucher is used to derive a BACAP read/write capability set.

  4. The VoucherPayload is uploaded to the BACAP sequence described by the capability (at index 0).

  5. Anyone who intercepts the Voucher can read and write the sequence.

  6. But: Since the Voucher is a hash over the VoucherPayload, writing the sequence with anything but the VoucherPayload will be detectable by the recipient.

  7. This means that the contents cannot be modified undetectably by the interceptor.

2.5 - Pigeonhole services

How clients discover and connect to pigeonhole services through the service directory and the voucher router

This document explains how three components work together to let a client reach a pigeonhole service it has never talked to. Two are programs that mixnet operators run; the third is a library for writing pigeonhole services.

  • The service directory (capability service_directory) holds a descriptor for each pigeonhole service, saying how to reach it. It is the service-directory program in katzenpost, under cmd/service-directory, built on the pigeonservice/directory package. Operators run it as a plugin on a service node.
  • The voucher router (capability voucher_router) relays a client’s first message to a pigeonhole service. It is the voucher-router program in katzenpost, under cmd/voucher-router, built on the pigeonservice/router package. Operators run it as a plugin on a service node.
  • The pigeonhole service library is for writing pigeonhole services, and the clients that reach them, in Go or Rust. A pigeonhole service is the responder side of an initiator–responder protocol over Pigeonhole: it accepts new connections from clients and then speaks its own protocol over each one, such as a bot that joins group chats, or a binary protocol no human reads. The Go library is the pigeonservice package in katzenpost; the Rust library is the services module of the pigeonhole_protocols crate in pigeonhole_protocols, which also has ELIZA, a pigeonhole service written with it. The two speak the same wire format.
Part Where Status
This specification website #246 in review
Service directory katzenpost cmd/service-directory #1247 in review
Voucher router katzenpost cmd/voucher-router #1247 in review
Go library katzenpost pigeonservice #1247 in review
Rust library pigeonhole_protocols src/services #11 in review
ELIZA pigeonhole_protocols src/bin/eliza.rs #11 in review
Rust thin client thin_client #100 in review

A pigeonhole service has no address and no open port; everything it sends or receives is a box on the storage replicas. The directory and the router bootstrap the first contact.

Many operators should run the directory and the router. If one operator ran the only instance of each, that operator would be a single point of failure for every pigeonhole service. With two or more there is none: a pigeonhole service registers with every router and advertises in every directory the PKI document lists, and a client can look it up in any directory and route through any of a service’s routers. A pigeonhole service notices when a new PKI document lists more routers or directories, and starts using them.

The bootstrap of a connection

Afterwards the client and the service share a connection of two Pigeonhole streams, one written by each, and each holds the other’s read cap. The router and the directory take no further part. Every party reaches the mixnet through a client daemon, kpclientd, which does all the cryptography that involves keys.

Contact vouchers

Every connection starts from a contact voucher: one side mints it, the other uses it, and both end up holding each other’s read cap. A voucher can be used once. The protocol is specified in Contact voucher and narrated in Contact voucher protocol narration. Here it matters only who mints the voucher and how it travels.

A client could instead send a service a read cap and a write cap directly. Vouchers are used because:

  • Forward secrecy. Routers keep forwarded messages for days, sealed to the service’s long-term key. Caps in them would stay valid for anyone who later gets that key; a used voucher is worthless, since its payload is tombstoned and its reply is sealed to a key only the client holds.
  • Each side makes its own stream. No one holds a write cap to the other’s stream.
  • The client knows it was accepted. The voucher reply confirms the connection; with bare caps the client cannot tell an idle service from one that never got them.
  • One token for every path. The same short, single-use token is routed, offered, or pasted into a chat app.

The cost is a few extra round trips before the first message.

Identity

A service is known by its NIKE keypair, x25519-ctidh1024, kept in its data directory so it survives restarts. Its ServiceID is the BLAKE2b-256 hash of the public key, written as 64 hex digits.

The router and the directory publish their NIKE public keys in the PKI document, as the parameters nikeScheme and publicKey of their service node entry. A client trusts a router or a directory because the PKI lists it, and trusts nothing a directory says without checking it against the PKI.

Registering with routers

A service mints a voucher and sends it to each voucher router in the PKI in a RegisterRequest, with its public key and a MAC. The router uses the voucher, and the connection that results is the service’s link with that router. The router writes every sealed voucher addressed to the service to the link as a LinkMessage, and keeps them for seven days, so a service that was offline still receives them.

The authorities publish a new PKI document once an epoch, and the client daemon tells its thin clients about each one. On each new document a service registers with any router listed in it that it has no link with. A registration that fails, and a link whose reader fails, are forgotten, so the next document registers with that router again.

Advertising and discovery

Once a service holds a link, it advertises its ServiceDescriptor in every directory in the PKI: its public key and the routers it holds links with. An AdvertiseRequest carries a MAC and a sequence number, the time in nanoseconds; the directory keeps only the descriptor with the highest. A WithdrawRequest removes it, and its sequence number stays, so a replayed older advertisement cannot bring it back.

A client finds one service with a LookupRequest, asking each directory in turn and checking that the descriptor it gets is the service’s. A ListRequest instead returns the read cap of a snapshot stream, where the directory writes all its descriptors whenever one changes; a client merges the lists of every directory, so no single directory can hide a service’s routers.

Dialing a service

A client mints a voucher, seals it to the service’s public key, and sends it to one of the service’s routers in a RouteRequest. It tries only routers the PKI lists, five minutes each. The router forwards the sealed voucher over its link without being able to open it; the service opens it, uses it, and answers in the voucher reply. The router learns which service is being contacted and when, but not by whom, since the request travels over Sphinx with a reply SURB.

A chat app that cannot route vouchers itself can mint one and hand it to pigeonhole-voucher send SERVICE_IDENTITY VOUCHER_TOKEN.

The other direction needs no router or directory: a service mints a voucher and offers it, for a client to use.

Connections

Each side writes its messages, one per box, to its own stream, and reads the peer’s stream box by box. A message is at most one box. Replicas keep a box for one to two replica epochs, so a connection rewrites everything it sent in the last seven days once a replica epoch, and saves its state after every send and receive: either side can be offline for days, or restart.

Request authentication

RegisterRequest, AdvertiseRequest and WithdrawRequest carry a MAC that proves the request comes from the holder of the service’s private key, without a challenge round:

ss  = DH(servicePriv, pluginPub) = DH(pluginPriv, servicePub)
key = HKDF-BLAKE2b-256(ss, salt = none, info = "katzenpost-pigeonservice-mac-v1" || pluginPub || servicePub)
mac = BLAKE2b-256(key = key, msg = canonical CBOR of the request with MAC null)

pluginPub is the router’s or the directory’s public key from the PKI. An all-zero shared secret is rejected, and MACs are compared in constant time.

Messages

Requests are the payloads of Sphinx queries to the plugin’s endpoint, and replies come back in the reply SURB. Every message is canonical CBOR, a map keyed by the Go field names. A decoder accepts the zero padding Sphinx adds after the item. The daemon retransmits a request until a reply arrives, so the router and the directory treat a repeated request as one.

const (
	RouterCapability    = "voucher_router"
	DirectoryCapability = "service_directory"
	ParamNIKEScheme     = "nikeScheme"
	ParamPublicKey      = "publicKey"
)

const (
	StatusOK uint8 = iota
	StatusInvalidRequest
	StatusBadMAC
	StatusUnknownService
	StatusStale
	StatusBusy
	StatusInternalError
)

type ServiceID [32]byte

type RouterRef struct {
	NodeIDHash [32]byte
	Endpoint   string
}

type ServiceDescriptor struct {
	NIKEScheme string
	PublicKey  []byte
	Routers    []RouterRef
}

// To a voucher router; exactly one field is set.
type RouterRequest struct {
	Route    *RouteRequest    `cbor:",omitempty"`
	Register *RegisterRequest `cbor:",omitempty"`
}

type RouteRequest struct {
	ServiceID  ServiceID
	Ciphertext []byte // the voucher, sealed to the service
}

type RegisterRequest struct {
	NIKEScheme string
	PublicKey  []byte
	Voucher    []byte
	MAC        []byte
}

type RouterReply struct {
	Status uint8
}

// One box on the router's stream of a link.
type LinkMessage struct {
	Forward []byte `cbor:",omitempty"` // a client's sealed voucher
}

// To a service directory; exactly one field is set.
type DirectoryRequest struct {
	Advertise *AdvertiseRequest `cbor:",omitempty"`
	Withdraw  *WithdrawRequest  `cbor:",omitempty"`
	Lookup    *LookupRequest    `cbor:",omitempty"`
	List      *ListRequest      `cbor:",omitempty"`
}

type AdvertiseRequest struct {
	Descriptor ServiceDescriptor
	Seq        uint64
	MAC        []byte
}

type WithdrawRequest struct {
	ServiceID ServiceID
	Seq       uint64
	MAC       []byte
}

type LookupRequest struct {
	ServiceID ServiceID
}

type ListRequest struct{}

type DirectoryReply struct {
	Status     uint8
	Descriptor *ServiceDescriptor `cbor:",omitempty"` // for Lookup
	ReadCap    []byte             `cbor:",omitempty"` // for List: the snapshot stream
	StartIndex []byte             `cbor:",omitempty"`
}

// A snapshot stream holds a 4-byte big-endian length, then this.
type Snapshot struct {
	Seq         uint64
	Descriptors []ServiceDescriptor
}

// The voucher reply, in the shape of katzenqt's ReplyWho with one member.
type whoReply struct {
	PleaseAdds []pleaseAdd `cbor:"please_adds"`
}

type pleaseAdd struct {
	DisplayName string `cbor:"display_name"`
	ReadCap     []byte `cbor:"read_cap"`
}
pub const ROUTER_CAPABILITY: &str = "voucher_router";
pub const DIRECTORY_CAPABILITY: &str = "service_directory";
pub const PARAM_NIKE_SCHEME: &str = "nikeScheme";
pub const PARAM_PUBLIC_KEY: &str = "publicKey";

#[repr(u8)]
pub enum Status { Ok = 0, InvalidRequest, BadMac, UnknownService, Stale, Busy, InternalError }

pub struct ServiceId(pub [u8; 32]);

pub struct RouterRef {
    pub node_id_hash: [u8; 32],
    pub endpoint: String,
}

pub struct ServiceDescriptor {
    pub nike_scheme: String,
    pub public_key: Vec<u8>,
    pub routers: Vec<RouterRef>,
}

pub enum RouterRequest {
    Route(RouteRequest),
    Register(RegisterRequest),
}

pub struct RouteRequest {
    pub service_id: ServiceId,
    pub ciphertext: Vec<u8>, // the voucher, sealed to the service
}

pub struct RegisterRequest {
    pub nike_scheme: String,
    pub public_key: Vec<u8>,
    pub voucher: Vec<u8>,
    pub mac: Option<Vec<u8>>,
}

pub enum DirectoryRequest {
    Advertise(AdvertiseRequest),
    Withdraw(WithdrawRequest),
    Lookup(ServiceId),
    List,
}

pub struct AdvertiseRequest {
    pub descriptor: ServiceDescriptor,
    pub seq: u64,
    pub mac: Option<Vec<u8>>,
}

pub struct WithdrawRequest {
    pub service_id: ServiceId,
    pub seq: u64,
    pub mac: Option<Vec<u8>>,
}

pub struct DirectoryReply {
    pub status: u8,
    pub descriptor: Option<ServiceDescriptor>, // for Lookup
    pub read_cap: Vec<u8>,                     // for List: the snapshot stream
    pub start_index: Vec<u8>,
}

pub struct Snapshot {
    pub seq: u64,
    pub descriptors: Vec<ServiceDescriptor>,
}

// The router reply, the link message and the voucher reply have no type of
// their own; these encode and decode them.
pub fn encode_router_reply(status: Status) -> Vec<u8>;
pub fn decode_status(raw: &[u8]) -> Result<u8, Error>;
pub fn encode_link_message(forward: &[u8]) -> Vec<u8>;
pub fn decode_link_message(raw: &[u8]) -> Result<Vec<u8>, Error>;
pub(crate) fn encode_who_reply(display_name: &str, read_cap: &[u8]) -> Vec<u8>;

Interfaces

The mixnet

A service reaches the mixnet through one interface, which the thin client implements and tests replace with an in-memory network.

type Pigeonhole interface {
	NewStream() (*bacap.WriteCap, *bacap.ReadCap, *bacap.MessageBoxIndex, error)
	Write(ctx context.Context, writeCap *bacap.WriteCap, idx *bacap.MessageBoxIndex, plaintext []byte) (*bacap.MessageBoxIndex, error)
	Read(ctx context.Context, readCap *bacap.ReadCap, idx *bacap.MessageBoxIndex) ([]byte, *bacap.MessageBoxIndex, error)
	Tombstone(ctx context.Context, writeCap *bacap.WriteCap, idx *bacap.MessageBoxIndex) error
	WritePayload(ctx context.Context, writeCap *bacap.WriteCap, idx *bacap.MessageBoxIndex, payload []byte) (*bacap.MessageBoxIndex, error)
	MaxPlaintext() int

	VoucherMint(messageWriteCap []byte, displayName string) (*MintResult, error)
	VoucherInduct(voucher, payload, whoReply []byte) (*InductResult, error)
	VoucherOpen(secretKey, sealedReply, messageWriteCap []byte) (*OpenResult, error)
	VoucherDeriveStream(voucher []byte) (writeCap, readCap []byte, err error)

	BoxSeal(nikeScheme string, publicKey, plaintext []byte) ([]byte, error)

	Request(ctx context.Context, node *[32]byte, endpoint []byte, payload []byte) ([]byte, error)
	Services(capability string) ([]ServiceNode, error)
}

func NewThinPigeonhole(c *thin.ThinClient) Pigeonhole
pub trait Backend: Send + Sync + 'static {
    fn new_keypair(&self) -> impl Future<Output = Result<Keypair>> + Send;
    fn write_box(&self, write_cap: &[u8], index: &[u8], plaintext: &[u8]) -> impl Future<Output = Result<()>> + Send;
    fn read_box(&self, read_cap: &[u8], index: &[u8]) -> impl Future<Output = Result<Read>> + Send;
    fn replica_epoch(&self) -> impl Future<Output = Result<u64>> + Send;
    fn max_plaintext(&self) -> impl Future<Output = Result<usize>> + Send;

    fn voucher_mint(&self, write_cap: &[u8], name: &str) -> impl Future<Output = Result<Minted>> + Send;
    fn voucher_derive_stream(&self, voucher: &[u8]) -> impl Future<Output = Result<(Secret, Secret)>> + Send;
    fn voucher_induct(&self, voucher: &[u8], payload: &[u8], who_reply: &[u8]) -> impl Future<Output = Result<Inducted>> + Send;
    fn voucher_open(&self, secret_key: &[u8], sealed_reply: &[u8], write_cap: &[u8]) -> impl Future<Output = Result<Opened>> + Send;

    fn request(&self, node: &[u8; 32], endpoint: &[u8], payload: &[u8]) -> impl Future<Output = Result<Vec<u8>>> + Send;
    fn services(&self, capability: &str) -> impl Future<Output = Result<Vec<ServiceNode>>> + Send;

    fn nike_generate_key_pair(&self, scheme: &str) -> impl Future<Output = Result<(Vec<u8>, Secret)>> + Send;
    fn nike_derive_secret(&self, scheme: &str, private: &[u8], public: &[u8]) -> impl Future<Output = Result<Secret>> + Send;
    fn box_seal(&self, scheme: &str, public: &[u8], plaintext: &[u8]) -> impl Future<Output = Result<Vec<u8>>> + Send;
    fn box_open(&self, scheme: &str, private: &[u8], ciphertext: &[u8]) -> impl Future<Output = Result<Vec<u8>>> + Send;
}

// `daemon` is `@name` for an abstract unix socket, a socket path, or `host:port`.
impl ThinClientBackend {
    pub async fn dial(daemon: &str) -> Result<ThinClientBackend, Box<dyn std::error::Error>>;
}

Writing a service

A service runs a handler for each client’s session. A session is a connection, and ends when its handler returns. Closing the service keeps its sessions on disk for the next start.

func LoadServiceKey(dataDir string) (*ServiceKey, error)
func NewService(cfg Config, ph Pigeonhole) (*Service, error)

func (s *Service) ID() ServiceID
func (s *Service) Descriptor() *ServiceDescriptor
func (s *Service) Run(ctx context.Context, h Handler) error
func (s *Service) Close() error

type Handler interface {
	OnSession(ctx context.Context, s *Session)
}

type Session struct {
	*Conn
	// ...
}

func (c *Conn) Send(ctx context.Context, msg []byte) error
func (c *Conn) Recv(ctx context.Context) ([]byte, error)
impl<B: Backend> Service<B> {
    pub fn new(cfg: Config, ph: Arc<B>) -> Result<Self, Error>;
    pub fn id(&self) -> ServiceId;
    pub fn descriptor(&self) -> ServiceDescriptor;
    pub async fn run<F, Fut>(&self, handler: F) -> Result<(), Error>
    where
        F: Fn(Session<B>) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = ()> + Send + 'static;
    pub async fn offer(&self) -> Result<Vec<u8>, Error>;
    pub async fn close(&self);
}

// A Session derefs to its Conn.
impl<B: Backend> Conn<B> {
    pub async fn send(&self, msg: &[u8]) -> Result<(), Error>;
    pub async fn recv(&self) -> Result<Vec<u8>, Error>;
}

Reaching a service

type Discoverer interface {
	Lookup(ctx context.Context, id ServiceID) (*ServiceDescriptor, error)
	List(ctx context.Context) ([]ServiceDescriptor, error)
}

type Advertiser interface {
	Advertise(ctx context.Context, d *ServiceDescriptor) error
	Withdraw(ctx context.Context, id ServiceID) error
}

// Package directory: both, over every directory in the PKI.
func NewAll(ph ps.Pigeonhole, key *ps.ServiceKey, pollInterval time.Duration) (*All, error)

// Mints a voucher, routes it to the service and waits for its reply.
func Dial(ctx context.Context, ph Pigeonhole, d *ServiceDescriptor, displayName string, pollInterval time.Duration) (*Conn, error)
// Routes a voucher someone else minted.
func Route(ctx context.Context, ph Pigeonhole, d *ServiceDescriptor, voucher []byte) error
// Uses a voucher a service offered.
func Induct(ctx context.Context, ph Pigeonhole, voucher []byte, displayName string, pollInterval time.Duration) (*Conn, error)
// One per directory in the PKI.
impl<B: Backend> Directory<B> {
    pub async fn all(ph: Arc<B>, key: Option<Keypair>, poll: Duration) -> Result<Vec<Self>, Error>;
    pub async fn lookup(&self, id: ServiceId) -> Result<ServiceDescriptor, Error>;
    pub async fn list(&self) -> Result<Vec<ServiceDescriptor>, Error>;
    pub async fn advertise(&self, d: &ServiceDescriptor) -> Result<(), Error>;
    pub async fn withdraw(&self, id: ServiceId) -> Result<(), Error>;
}

/// Mints a voucher, routes it to the service and waits for its reply.
pub async fn dial<B: Backend>(ph: Arc<B>, d: &ServiceDescriptor, display_name: &str, poll: Duration) -> Result<Conn<B>, Error>;
/// Routes a voucher someone else minted.
pub async fn route<B: Backend>(ph: &B, d: &ServiceDescriptor, voucher: &[u8]) -> Result<(), Error>;
/// Uses a voucher a service offered.
pub async fn induct<B: Backend>(ph: Arc<B>, voucher: &[u8], display_name: &str, poll: Duration) -> Result<Conn<B>, Error>;

Programs

Program Where What it does
voucher-router katzenpost cmd/voucher-router the voucher router plugin
service-directory katzenpost cmd/service-directory the service directory plugin
pigeonhole-voucher katzenpost cmd/pigeonhole-voucher list the services; send a service a voucher
pigeonhole-echo katzenpost cmd/pigeonhole-echo a service that sends back each message
eliza pigeonhole_protocols src/bin/eliza.rs ELIZA, in katzenqt’s chat framing
motd-service pigeonhole_protocols cmd/motd-service a Go service that answers each request with the message of the day, read from a file
motd pigeonhole_protocols cmd/motd fetches the message of the day from a motd-service

Talking to ELIZA

ELIZA can be dialed from any of our chat clients: katzenqt, jam, frank_chat or hushphone. Generate a voucher in the client, find ELIZA’s service identity among the services pigeonhole-voucher list shows, and send ELIZA the voucher token:

pigeonhole-voucher --thin_config thinclient.toml list
pigeonhole-voucher --thin_config thinclient.toml send SERVICE_IDENTITY VOUCHER_TOKEN

ELIZA inducts you into a new chat, opens it with a greeting, and answers each message you send.

Running the router and the directory

The voucher router and the service directory run on a service node: a special kind of mix node in a Katzenpost mix network that delivers Sphinx packet payloads to services and sends their answers back in SURB replies. The node runs each service as a plugin, beside others such as the courier. An operator adds the two plugins to the [ServiceNode] section of the node’s configuration:

[[ServiceNode.CBORPluginKaetzchen]]
  Capability = "voucher_router"
  Endpoint = "voucher_router"
  Command = "/usr/local/bin/voucher-router"
  MaxConcurrency = 1
  [ServiceNode.CBORPluginKaetzchen.Config]
    data_dir = "/var/lib/katzenpost-servicenode/voucher_router"
    log_dir = "/var/log/katzenpost/voucher_router"
    thin_config = "/etc/katzenpost-servicenode/pigeonservice-thinclient.toml"

[[ServiceNode.CBORPluginKaetzchen]]
  Capability = "service_directory"
  Endpoint = "service_directory"
  Command = "/usr/local/bin/service-directory"
  MaxConcurrency = 1
  [ServiceNode.CBORPluginKaetzchen.Config]
    data_dir = "/var/lib/katzenpost-servicenode/service_directory"
    log_dir = "/var/log/katzenpost/service_directory"
    thin_config = "/etc/katzenpost-servicenode/pigeonservice-thinclient.toml"

Capability is the name the plugin is listed under in the PKI document, and Endpoint the name a client addresses its requests to. Each plugin has its own data directory, for its key and database, and its own log directory. Because the router and the directory also read and write Pigeonhole streams, each reaches the mixnet through a client daemon, kpclientd, named by its thin client configuration. On first start a plugin generates its NIKE keypair, and the node publishes the public key in the PKI document.

2.6 -

Group chat specification

Threebit Hacker

David Stainton

Abstract


Prerequisites

This design specification is dependent on the BACAP and Pigeonhole protocol designs from our paper Echomix: A Strong Anonymity System with Messaging, which describes

  • the BACAP (blinded and capability) in §4 and

  • the Pigeonhole protocol in §5.

The source code and API docs for BACAP are available on pkg.go.dev.

Introduction

The Pigeonhole protocol establishes anonymous cryptographic communication channels which have a readcap (read capability) and a writecap (write capability). For example, if Alice and Bob want to communicate, they can each create their own Pigeonhole/BACAP channels and exchange readcaps on those channels. Now when Bob writes to his channel, Alice can read those messages because she has Bob’s readcap. Likewise, when Alice writes to her channel, Bob can read those messages because he has Alice’s readcap. This is the most basic construction using BACAP and Pigeonhole.

Here we extend this basic design to work as a minimal group-chat protocol, without key rotation.

BACAP primitives give us two message types:

  • SingleMessage

  • AllOrNothingMessage (used for big messages: upload n chunks to a temporary stream and then put a pointer to that in your own stream as a single message.)

The group state consists of:

  • a MembershipCap for each member, containing:

    • a BACAP readcap

    • the index of the next box to read, kept separately from the readcap

    • a nickname

  • a MembershipHash (a hash over the members’ read caps)

The group chat is completely decentralized. Each member must keep track of every other member.

Group chat message types

All messages are SingleMessage if they fit in one BACAP slot, or an AllOrNothingMessage if they are too big.

  • Text type payloads are normal chat text messages.
// TextPayload encapsulates a normal text message.
type TextPayload struct {
    // Payload contains a normal UTF-8 text message to be displayed inline.
    Payload []byte
}
  • Introduction type messages introduce new group members.
// Introduction introduces a new member to the group.
type Introduction struct {
    // DisplayName is the party's name to be displayed in chat clients.
    DisplayName string
    
    // UniversalReadCap is the BACAP UniversalReadCap
    // which lets you read all messages posted by this user.
    UniversalReadCap *bacap.UniversalReadCap
}
  • FileUpload type

A FileUpload can be used for various purposes such as uploading an image to be displayed inline by the chat client. Likewise, a sound bite could be made visible in the chat along with a play-button. Beyond that, we can support arbitrary file attachments.

// FileUpload encapsulates several file types
// which result in different client behaviors.
type FileUpload struct {
    // Payload contains the file payload.
    Payload []byte
    
    // FileType is the identifier for each file type.
    // Valid file types are:
    // "image"
    // "sound"
    // "arbitrary"
    FileType string
}
  • Who type

The Who message type is used to query who is currently in the group.

// Who is used to query the group chat to find out the member read capabilities.
type Who struct {}
  • ReplyWho type

The ReplyWho message answers the Who query with an AllOrNothingMessage BACAP stream containing readcaps for all group chat members, each with the index to start reading at.

type ReplyWho struct {
    Payload *bacap.BacapStream
}
  • GroupChatMessage type

The GroupChatMessage message encapsulates all of the above-mentioned message types and is serialized with CBOR.

// GroupChatMessage encapsulates all chat message types.
type GroupChatMessage struct {
    // Version is used to ensure we can change this message type in the future.
    Version int

    // MembershipHash is the sender's view of who is in the group.
    MembershipHash [32]byte

    TextPayload *TextPayload
    Introduction *Introduction
    FileUpload *FileUpload
    Who *Who
    ReplyWho *ReplyWho
}

Every message carries the sender’s MembershipHash: SHA-256 over the domain separator KP:membership:v1 followed by the 32-byte public key of each active member’s read cap, the sender’s own included, without repeats and in ascending byte order. An Introduction carries the hash of the group as it stood before the member it introduces, and a reader compares it with its own view less that member, whether or not it holds the member yet: the reader may be the member introduced. A reader reports a mismatch; it never drops a message for one. It is the one sign that two members disagree about who is in the group.

Protocol flow

The protocol flow for making a new group from scratch (using whatever authentication protocol) is essentially for everybody to exchange PleaseAdd messages.

// PleaseAdd is a message used by a client to try and gain access to a chat group.
type PleaseAdd struct {
    // DisplayName is the party's name to be displayed in chat clients.
    DisplayName string
    
    // UniversalReadCap is the BACAP UniversalReadCap
    // which lets you read all messages posted by this user.
    UniversalReadCap *bacap.UniversalReadCap
}

type SignedPleaseAdd struct {
    // PleaseAdd contains the CBOR serialized PleaseAdd struct.
    PleaseAdd []byte
    
    // Signature contains the cryptographic signature over the PleaseAdd field.
    Signature []byte
}

For introduction to an existing group over an existing channel between an introducer member and new member, an Invitation message is used.

type Invitation struct {
    GroupName string
}

The Invitation protocol flow works as follows.

  1. There exists a group called YoloGroup. A member of the group invites a potential new member with an Invitation message.

  2. If the invited party wants to join, then they reply with a SignedPleaseAdd message meaning “I want to join your group.” This provides the invited party’s BACAP universal readcap, their display name, and a cryptographic signature produced by their BACAP writecap.

  3. The introducer receives the SignedPleaseAdd message.

    1. If the introducer does not like the DisplayName, they reply to the invited party with a PleaseReviseDisplayName message that contains the original SignedPleaseAdd. Then they wait for a new SignedPleaseAdd.

    2. If the introducer approves of the DisplayName, then:

      • Because existing members need the new member’s readcap, the introducer publishes the SignedPleaseAdd to their own BACAP stream for the rest of the group to read.

      • Because the new member needs existing members’ readcaps, the introducer replies to the new member with ReplyWho message containing readcaps for all existing members, each with the index to start reading at.

        IMPORTANT: The content of both replies must be sent in the same AllOrNothingMessage, despite the SignedPleaseAdd being written to the introducer’s own BACAP stream for the group and the ReplyWho being written to the BACAP stream the introducer is using to communicate with the new member.

        NOTE: We could send all of this information as part of the initial Invitation, but that would allow silent members to read other members’ streams without them knowing it, which is an anti-goal.

Opportunistic acknowledgements and backfill

Pigeonhole boxes are garbage-collected after one to two weeks (see “Ephemeral” in Understanding Pigeonhole). After that, only the author has the content. Acknowledgements tell the author what to restore.

Any group message may carry acknowledgements. None is sent on its own. GroupChatMessage gains one field:

type GroupChatMessage struct {
    Version int
    MembershipHash [32]byte

    TextPayload *TextPayload
    Introduction *Introduction
    FileUpload *FileUpload
    Who *Who
    ReplyWho *ReplyWho

    Acks []byte
    Numbers []byte
    IntroducedAt []byte
}

This new Acks field is a mapping from roster indexes (see Rosters below) to BACAP Idx64 values. Its encoding is described in Acks wire format. Acks is nil when we don’t have anything to acknowledge. Numbers and IntroducedAt keep rosters in step; they are described under Rosters below.

TextPayload and FileUpload are content. Introduction, Numbers and IntroducedAt are control. A message carries either content or control, never both. The retention policy deletes content only (see Disappearing messages), so a message that changes a roster stays readable for as long as its Sent-box record lasts.

Throughout this specification we use roster indexes as the channel identities. Alice keeps a list of the channels she has numbered and refers to each by its place in that list, counting from 0: 0 is Alice herself, 1 is the next member she numbered, and so on. One byte names a member, which keeps acknowledgements small.

  • Each value in the key-value mapping is the Idx64 of a box on that member’s stream. It acknowledges that box and every earlier box from where the acknowledging member started reading the stream, so a member acknowledges a box only once it has read it and every box before it: the end of the unbroken run it has read. A box read as a tombstone counts as read, since its plaintext is gone for every reader. A box a scan stepped past without reading (see Rewrite and scan) is not read until a recheck reads it, and until then the member’s acknowledgements of that stream stop just before it.
  • The acknowledging member is whoever’s stream carried the message.
  • A stream owner checks each claimed Idx64 against its Sent-box records and ignores one matching no box it wrote.

A MessageBoxIndex is the whole BACAP derivation state for one box. Its first 8 bytes, little-endian, are the box’s Idx64. BACAP’s derivation adds one to the Idx64 at each step and never wraps: a stream ends rather than reach 264. On one stream an Idx64 therefore names exactly one box, and orders the stream’s boxes as they were written. Every member holds every member’s read cap, and so each stream’s first index, from which BACAP’s AdvanceIndexTo derives the box at any later Idx64. An acknowledgement names a box by its Idx64, 8 bytes instead of 104. An Idx64 means nothing without the stream it belongs to, so a reader MUST resolve an acknowledgement’s roster index before reading its value. IntroducedAt and the reply to a new member name a box by its whole MessageBoxIndex.

Rosters. Members are named by one-byte roster indexes, not public keys, to save bytes on constrained transports such as LoRa.

  • Roster. Each member keeps an ordered list of the members it has numbered, itself included. A member’s roster index is its position in that list. Entries are never moved or reused, so a roster holds at most 256 members ever. Every member keeps a copy of every other member’s roster. A member’s identity is its read-cap public key.

  • Starting. A lone founder’s roster holds only itself. Co-founders each start with all founders in ascending order of read-cap public key. A new member starts with a copy of its introducer’s roster as of the Introduction announcing it.

  • Numbering. A member numbers another by appending it to its roster, taking its next unused index, and announcing the assignment in the Numbers field of a control message. Members read Introductions on different streams in different orders, so only the member itself knows which index it gave whom; Numbers says so. A message numbers members at consecutive indexes and names each by the first 8 bytes of its read-cap public key: enough to tell a group’s members apart, and too many for a joiner to choose a key matching another member’s. An introducer numbers the new member in the message carrying its Introduction, which needs only the index assigned. Every other member numbers a new member after reading its Introduction, and MUST do so before acknowledging the new member’s stream.

  • Watching. A reader learns each sender’s roster from that sender’s Numbers. Until the reader knows a member whose key begins with an entry’s prefix, from an Introduction it has read or from the reply that inducted it, the member at that index is unresolved.

  • Introduced at. A new member learns where its Introduction landed by reading its introducer’s stream, and its next message after that is a control message carrying IntroducedAt: its introducer’s roster index and the MessageBoxIndex of the Introduction it joined through. A member can be introduced more than once, so readers take the new member’s starting roster from the Introduction that IntroducedAt names: the introducer’s roster up to and including the index that Introduction assigned. Indexes are assigned in order and never change, so that is the introducer’s roster as it stood then. Until readers have read that Introduction, the new member’s roster is unknown and its acknowledgements are skipped.

  • Repeats. A member already in a roster is never added again.

  • Reply to a new member. The introducer hands the new member the group privately, in its last message of the contact voucher protocol: the VoucherReply, written in the same all-or-nothing commit as the Introduction. Its WhoReply (ReplyWho here) is built before the new member’s Introduction has a MessageBoxIndex, so it names the new member only by the roster index it will take. It carries:

    • every member’s read cap, each with its start index (see Joining), in the introducer’s roster order, so a member’s place in the list is its roster index. A removed member’s slot is sent empty.
    • every member’s roster, as the introducer has followed it.
    • every Introduction the introducer has read: the roster index of the member that wrote it, its MessageBoxIndex, and the roster index of the member it introduced. An IntroducedAt names an Introduction, and the new member never reads the boxes before its start indexes, so without these it could never resolve one naming an Introduction written before it joined.
    // Rosters holds each member's roster, in introducer roster order.
    // Each byte is the introducer's roster index for that entry.
    Rosters [][]byte
    
    // Introductions holds each Introduction the introducer has read.
    Introductions []IntroductionRef
    
    type IntroductionRef struct {
        // Introducer is the roster index of the member that wrote it.
        Introducer byte
        // Index is the MessageBoxIndex of the box it was written in.
        Index [104]byte
        // Member is the roster index of the member it introduced.
        Member byte
    }
    

    Roster indexes in the reply are the introducer’s.

  • Reading. Resolve each index against the sender’s roster. Skip values at unresolved indexes. Roster indexes MUST NOT be compared across senders.

  • Skipped boxes. A reader that skips a box may miss a Numbers field. Every field states its first index, so later ones still land in place, and the missed indexes stay unresolved.

  • Removal. A member may silently stop reading a stream. It keeps the roster entry, MUST NOT acknowledge that index again, and MUST NOT reuse it. An entry still named only by a key prefix is the removed member’s only if the prefix matches no other member it knows. It no longer waits for the removed member’s acknowledgements before discarding plaintext. The removed member keeps its read caps.

Sent-box records. A stream owner records, for each box it wrote and under its Idx64, its MessageBoxIndex and its plaintext until every member has acknowledged it or its retention policy deletes the plaintext (see Disappearing messages). How far each member has acknowledged the owner’s stream is the Idx64 of the last box it acknowledged.

  • Retention. Once every other active member has acknowledged a box, its plaintext MAY be discarded, but its record is kept. A record is kept for as long as the retention policy keeps sent content, and for good when the policy keeps it for good, so an acknowledgement that arrives late still finds its box. Under a policy that deletes sent content, a record MUST be discarded after a bounded window exceeding one replica epoch.
  • Backfill. Once per replica epoch the owner rewrites every recorded box some active member has not acknowledged: with its plaintext if it still has it, otherwise as a tombstone, so the box still reads as written. A box every member has acknowledged is written once more as a tombstone when its plaintext is gone, to erase it from the replicas, and never again. When nobody is behind, nothing is written. Rewrites are idempotent since Pigeonhole writes are content-idempotent and BACAP encryption is deterministic. Acknowledgements never trigger a rewrite.
  • Rate limit. Implementations SHOULD NOT rewrite a box more than once per replica epoch.
  • Timing. A client takes the replica epoch from the PKI document, not its clock: the epoch most storage replicas publish envelope keys around. It takes up each epoch at a point in the epoch’s first half that only it can work out, so that members do not all rewrite at the same moment, and at once if it has missed a whole epoch.

Joining. A new member receives its introducer’s view of the group as of the Introduction, privately in the introducer’s VoucherReply: a read cap and a start index for every member’s stream in the introducer’s roster, the rosters the introducer knew about, and the Introductions it had read (see Reply to a new member). Read caps are sent unchanged; the index travels beside them and is advanced separately.

  • Catching up. Before an invitation begins, the introducer reads every stream as far as it can.
  • Start indexes. Each start index is the index of the next box the introducer had to read on that stream when the invitation began, and the introducer’s own is the next box it writes, no later than the Introduction.
  • Holding back. From the start of an invitation until the all-or-nothing commit that writes the Introduction, the introducer sends no acknowledgements and numbers no one. Its published acknowledgements then stop short of every start index, and its roster stays as the reply describes it.
  • Waiting. Before building the reply, the introducer waits until every message it has composed has been written. One composed earlier may number a member, taking the index the reply would otherwise give the new member.
  • Retention. A member that reads an Introduction keeps every box of its own stream that the introducer had not acknowledged at that point, until the new member acknowledges it or the member’s retention policy deletes it.
  • No race. Members read the introducer’s stream in order, so each sees the Introduction before any acknowledgement that would let it discard a box the new member was given.
  • History. Older history is sent from the introducer’s own copy, never by starting a stream earlier.

Acks wire format

We encode the Acks mapping by hand as a byte slice rather than as a CBOR map. The motivation is to let this protocol run over constrained pipes, such as LoRa radio links, where every byte counts.

Let n be the number of entries. Every value is an 8-byte Idx64, so the values cost 8n bytes in any encoding. Only the cost of naming the keys varies.

  • Simplest. A list of (roster index, value) pairs. The keys cost one byte each, n bytes in total.
  • Bitmap. A bitmap with one bit per roster index, followed by the values in ascending roster index order. Let b be the bytes a bitmap needs to reach the highest acknowledged index; b is at most 32. The keys cost b bytes. This beats the list when many members are acknowledged at once.
  • Most compact. Use whichever of the two key encodings is shorter: min(n, b) bytes, the list when they tie. Keys can be longer than one value, so the field length alone no longer says how many values follow: the field begins with one byte holding n - 1. This is the encoding Acks uses.

For example, if the highest acknowledged index is 19, the bitmap is 3 bytes. Acknowledging 3 members then costs 3 key bytes either way; acknowledging 10 costs 10 as a list but only 3 as a bitmap, and the whole field 1 + 3 + 80 bytes.

The most compact encoding is defined as follows.

  • Layout. Acks is one byte holding n - 1, then the keys, then the values in ascending roster index order, each little-endian. If n <= b, the keys are a list of n index bytes in ascending order. Otherwise they are a b-byte bitmap where index i is bit i mod 8, counting from the most significant bit, of byte i div 8.
  • Parsing. The first byte plus one is n. The key length is the field length less one, less 8n. A key length equal to n means a list; smaller means a bitmap. A parser MUST ignore the whole field if the key length is negative or exceeds n, a list is not strictly ascending, a bitmap’s last byte is zero, a bitmap does not have exactly n bits set, or a bitmap exceeds 32 bytes.

Numbers and IntroducedAt wire format

Numbers and IntroducedAt are encoded by hand for the same constrained pipes as Acks.

  • Numbers. In a message carrying an Introduction, a single byte: the roster index assigned to the member that Introduction introduces. Otherwise the first roster index assigned (1 byte), then the first 8 bytes of each member’s read-cap public key, one per consecutive index from the first: 1 + 8n bytes. Numbering alice’s next two members, erin and dave, takes 17 bytes. A parser MUST ignore the whole field if its length is neither of these, if it would assign an index above 255, or if a prefix appears twice.
  • IntroducedAt. One entry without its first byte: 105 bytes.

Rewrite and scan

A reader cannot tell a quiet stream from one stuck behind a garbage-collected box by reading it: both return BoxIDNotFound. Nor can it tell when a missing box will read again: that happens only once its owner, who may be offline, rewrites it. So a client never scans on its own.

  1. Periodic rewrite. Well within each replica epoch, the stream owner rewrites due boxes (see Backfill), keeping every recorded box populated.

  2. Kept indexes. A reader keeps the MessageBoxIndex of each box a scan stepped past without reading it, until a recheck reads it. BACAP indexes cannot be derived backward, so an index is kept as it is passed. A reader MAY drop kept indexes to bound what it keeps. A box whose index it drops is lost to it, and its acknowledgements of that stream never pass that box.

  3. Scan. The reader rechecks its kept indexes and ingests any box now readable, data or tombstone. If members have acknowledged boxes the reader has not yet reached, it advances its stream from the box it expects next to the furthest acknowledged Idx64, keeping the indexes it passes. The advance MUST be bounded: an acknowledged Idx64 beyond the bound is ignored, and not looked for again. The reader then probes forward without waiting between boxes: data is ingested, a tombstone is skipped, and the first BoxIDNotFound becomes the box it expects next, ending the scan.

  4. When to scan. A scan runs only when the user asks for one, one stream at a time. The client MAY show how long a stream has been quiet, whether other members have acknowledged boxes on it the reader has not reached, and how many boxes a scan stepped past are still unread.

A reader’s acknowledgements of a stream stop just before the first box it has not read, so the owner keeps that box’s plaintext and goes on rewriting it until its Sent-box record is discarded. A scan the user asks for before then delivers it. Two members stuck behind gaps in each other’s streams resynchronise once both scan within the owners’ retention windows. A box gone for good is lost to the reader: after a scan it reads on past it, and its acknowledgements of that stream stay before it.

Disappearing messages

Disappearing messages is the feature that causes a user’s client to remove messages from the client’s state database based on a user specified message retention policy. For example, a client’s message retention policy could keep decrypted plaintext messages from other members for X number of days. Likewise policy could retain sent message plaintext for Y number of days.

The retention policy applies to content only. Control messages are kept for as long as their Sent-box records last, so a message that disappears never takes a roster change with it.

Once a client makes a message “disappear” as per this feature, then after that point in time the client can never retransmit that box. Backfill rewrites it as a tombstone instead. The tombstone in place of the box is still very useful for resyncing. A member that reaches a tombstone in place of a box it has not yet read can also tell from it that it didn’t read your message in time before your client’s retention policy purged the plaintext data.

Addenda

GOOD QUESTION: If we are adding a lot of people at once,do we really need to upload all of the members n times?

OPEN PROBLEM: Our BACAP API defines a ReadCap type as containing the master public key AND the start index. Therefore whenever we send a readcap over the wire we are needlessly sending a start index even when we don’t need it anymore. We should probably fix this, especially given that our goal is to be as bandwidth efficient as possible.

FUTURE WORK: Forward secrecy. We can add two extensions that allow transmitting public keys + stuff encrypted under those public keys. We can also refer to the Reunion protocol which is a n-way PAKE with strong anonymity properties. Reunion is described in Communication in a world of pervasive surveillance: Sources and methods: Counter-strategies against pervasive surveillance architecture. Currently, Python and Go implementations of Reunion are available.

2.7 -

For distribution of epoch keys and agreement on the packet geometry, see the directory authority specification. That page distinguishes configured KEM Sphinx networks from the NIKE Sphinx values used in its namenlos example.

KEMSphinx specification

David Stainton

Abstract

Here I present a modification of the Sphinx cryptographic packet format that uses a KEM instead of a NIKE whilst preserving the properties of bitwise unlinkability, constant packet size and route length hiding.


Introduction

We’ll express our KEM Sphinx header in pseudo code. The Sphinx body will be exactly the same as SPHINXSPEC. Our basic KEM API has three functions:

  • PRIV_KEY, PUB_KEY = GEN_KEYPAIR(RNG)

  • ct, ss = ENCAP(PUB_KEY) - Encapsulate generates a shared secret, ss, for the public key and encapsulates it into a ciphertext.

  • ss = DECAP(PRIV_KEY, ct) - Decapsulate computes the shared key, ss, encapsulated in the ciphertext, ct, for the private key.

Additional notation includes:

  • || = concatenate two binary blobs together

  • PRF(key, message) = pseudo random function, a keyed cryptographic hash function, e.g. keyed Blake2b.

  • KEM_CIPHERTEXT_LENGTH = the size of a KEM ciphertext in bytes

A KEM ciphertext cannot be blinded and reused from hop to hop the way the Sphinx group element is. Therefore we must embed these KEM ciphertexts in the KEMSphinx header, one KEM ciphertext per mix hop.

Post-quantum hybrid KEM

Special care must be taken in order to correctly compose a hybrid post-quantum KEM that is IND-CCA2 robust.

The hybrid post quantum KEMs found in Cloudflare’s circl library are suitable to be used with Noise or TLS but not with KEM Sphinx because they are not IND-CCA2 robust. Noise and TLS achieve IND-CCA2 security by mixing in the public keys and ciphertexts into the hash object and therefore do not require an IND-CCA2 KEM.

Firstly, our post quantum KEM is IND-CCA2 however we must specifically take care to make our NIKE to KEM adapter have semantic security. Secondly, we must make a security preserving KEM combiner.

NIKE to KEM adapter

We easily achieve our IND-CCA2 security by means of hashing together the DH shared secret along with both of the public keys. The DH shared secret is the PRF key, and the message is the recipient’s public key followed by the ephemeral public key. The ephemeral public key is the KEM ciphertext:

func ENCAPSULATE(their_pubkey publickey) ([]byte, []byte) {
my_privkey, my_pubkey = GEN_KEYPAIR(RNG)
ss = DH(my_privkey, their_pubkey)
ss2 = PRF(ss, their_pubkey || my_pubkey)
return my_pubkey, ss2
}

func DECAPSULATE(my_privkey, ct []byte) []byte {
their_pubkey = ct
my_pubkey = PUBLIC_KEY(my_privkey)
ss = DH(my_privkey, their_pubkey)
shared_key = PRF(ss, my_pubkey || their_pubkey)
return shared_key
}

Both functions return an error if the DH shared secret is all zeros.

KEM combiner

The KEM Combiners paper KEMCOMB makes the observation that if a KEM combiner is not security preserving then the resulting hybrid KEM will not have IND-CCA2 security if one of the composing KEMs does not have IND-CCA2 security. Likewise the paper points out that when using a security preserving KEM combiner, if only one of the composing KEMs has IND-CCA2 security then the resulting hybrid KEM will have IND-CCA2 security.

Our KEM combiner uses the split PRF design from the paper when combining two KEM shared secrets together we use a hash function to also mix in the values of both KEM ciphertexts. In this pseudo code example we are hashing together the two shared secrets from the two underlying KEMs, ss1 and ss2. Additionally the two ciphertexts from the underlying KEMs, cct1 and cct2, are also hashed together. Each shared secret is the key of a PRF over both ciphertexts:

func SplitPRF(ss1, ss2, cct1, cct2 []byte) []byte {
cct := cct1 || cct2
return PRF(ss1, cct) XOR PRF(ss2, cct)
}

In our implementation the PRF is BLAKE2b-256, keyed by the BLAKE2b-256 hash of the shared secret. The message is the label splitprf-v1, then the number of KEMs as a 32 bit big endian integer, then each ciphertext preceded by its length as a 32 bit big endian integer.

The Split PRF can be used to combine an arbitrary number of KEMs. Here’s what it looks like with three KEMs:

func SplitPRF(ss1, ss2, ss3, cct1, cct2, cct3 []byte) []byte {
cct := cct1 || cct2 || cct3
return PRF(ss1, cct) XOR PRF(ss2, cct) XOR PRF(ss3, cct)
}

KEMSphinx header design

NIKE Sphinx header elements:

  1. Version number (MACed but not encrypted)

  2. Group element

  3. Encrypted per routing commands

  4. MAC for this hop (authenticates header fields 1 thru 3)

KEM Sphinx header elements:

  1. Version number (MACed but not encrypted)

  2. One KEM ciphertext for use with the next hop

  3. Encrypted per routing commands AND KEM ciphertexts, one for each additional hop

  4. MAC for this hop (authenticates header fields 1 through 3)

We can say that KEMSphinx differs from NIKE Sphinx by replacing the header’s group element (e.g. an X25519 public key) field with the KEM ciphertext. Subsequent KEM ciphertexts for each hop are stored inside the “routing information” section of the Sphinx packet header.

First we must have a data type to express a mix hop, and we can use lists of these hops to express a route:

type PathHop struct {
id [NODE_ID_LENGTH]byte
public_key kem.PublicKey
routing_commands Commands
}

The id is the node identifier. The header construction uses the id of the next hop to build each non-terminal hop’s NextNodeHop command.

Here’s how we construct a KEMSphinx packet header where path is a list of PathHop, and indicates the route through the network:

  1. Derive the KEM ciphertexts for each hop.
route_keys = []
route_kems = []
for i := 0; i < num_hops; i++ {
kem_ct, ss := ENCAP(path[i].public_key)
route_kems += kem_ct
route_keys += Sphinx_KDF(KDF_INFO, ss)
}

The KDF is the same as in SPHINXSPEC and produces the same output. There is no blinding in KEMSphinx, so the blinding seed at the end of the KDF output is unused.

  1. Derive the routing_information keystream and encrypted padding for each hop.

Same as in SPHINXSPEC except for the fact that each routing info slot is now increased by the size of the KEM ciphertext: PER_HOP_RI_LENGTH includes the size of one KEM ciphertext.

  1. Create the routing_information block.

Here we modify the Sphinx implementation to pack the next KEM ciphertext into each routing information block. Each of these blocks is decrypted for each mix hop which will decrypt the KEM ciphertext for the next hop in the route.

Each hop’s routing information block is PER_HOP_RI_LENGTH bytes. The routing commands are at the front, followed by zero padding. In every non-terminal hop’s block the last KEM_CIPHERTEXT_LENGTH bytes hold the next hop’s KEM ciphertext. The routing commands of a hop, including the NextNodeHop command, MUST therefore fit in the PER_HOP_RI_LENGTH - KEM_CIPHERTEXT_LENGTH bytes before it:

ri_fragment = cmds_to_encode |
ZEROBYTES( PER_HOP_RI_LENGTH - LEN( cmds_to_encode ) )
if i < num_hops - 1:
ri_fragment[PER_HOP_RI_LENGTH - KEM_CIPHERTEXT_LENGTH:] = route_kems[i+1]

The MAC is computed as in SPHINXSPEC, with the hop’s KEM ciphertext in place of the group element. It covers the version, the KEM ciphertext, the routing information and, for every hop but the first, the encrypted padding:

if i > 0:
mac = MAC( route_keys[i].header_mac, version | route_kems[i] |
routing_info | ri_padding[i-1] )
else:
mac = MAC( route_keys[i].header_mac, version | route_kems[i] |
routing_info )
  1. Assemble the completed Sphinx Packet Header and Sphinx Packet Payload SPRP key vector. Same as in SPHINXSPEC except the kem_element field is set to the first KEM ciphertext, route_kems[0]:
var sphinx_header SphinxHeader
sphinx_header.additional_data = version
sphinx_header.kem_element = route_kems[0]
sphinx_header.routing_info = routing_info
sphinx_header.mac = mac

KEMSphinx unwrap operation

Most of the design here will be exactly the same as in SPHINXSPEC. However there are a few notable differences:

  1. The shared secret is derived from the KEM ciphertext instead of a DH.

  2. Next hop’s KEM ciphertext stored in the encrypted routing information.

The mix decapsulates the header’s kem_element to get the shared secret. The replay tag is the hash of that KEM ciphertext. The MAC is verified over the version, the KEM ciphertext and the routing information.

After decrypting the routing information, the mix parses its routing commands only from the first PER_HOP_RI_LENGTH - KEM_CIPHERTEXT_LENGTH bytes of its block. If there is a NextNodeHop command, the mix copies the last KEM_CIPHERTEXT_LENGTH bytes of the block into the header’s kem_element field for the next hop. There is no blinding step.

Acknowledgments

I would like to thank Peter Schwabe for the original idea of simply replacing the Sphinx NIKE with a KEM and for answering all my questions. I’d also like to thank Bas Westerbaan for answering questions.

References

KEMCOMB

Federico Giacon, Felix Heuer, Bertram Poettering, “KEM Combiners”, 2018, https://link.springer.com/chapter/10.1007/978-3-319-76578-5_7

SPHINX09

Danezis, G., Goldberg, I., “Sphinx: A Compact and Provably Secure Mix Format”, DOI 10.1109/SP.2009.15, May 2009, https://cypherpunks.ca/~iang/pubs/Sphinx_Oakland09.pdf.

SPHINXSPEC

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Sphinx Mix Network Cryptographic Packet Format Specification”, July 2017, https://katzenpost.network/docs/specs/pdf/sphinx.pdf.

2.8 -

This page describes the packet-loss statistics design. See directory descriptor uploads for the current signed upload structure and its LoopStats field. At v0.0.107, carrying these statistics does not make them inputs to the directory tally.

Propagation of mix decoy loop statistics

David Stainton

Eva Infeld

Leif Ryge

Abstract

In the context of continuous time mixing strategies such as the memoryless mix used by Katzenpost, n-1 attacks may use strategic packet loss. Nodes can also fail for benign reasons. Determining whether or not it’s an n-1 attack is outside the scope of this work. This document describes how we will communicate statistics from mix nodes to mix network directory authorities which tells them about the packet loss they are observing.


Terminology

The following terms are used in this specification.

epoch
A fixed-time interval with a current default value of 20 minutes. A new PKI document containing public key material is published for each epoch and is valid only for that epoch. For more information, see Sphinx mix and provider key rotation.

wire protocol
Refers to our PQ Noise-based protocol that currently uses TCP but in the near future will optionally use QUIC. This protocol has messages known as wire protocol commands, which are used for various mixnet functions such as sending or retrieving a message and dirauth voting. For more information, see our wire protocol specification.

Design overview

Nodes (mixes, gateways, and providers) need to upload packet-loss statistics to the directory authorities, so that authorities can label malfunctioning nodes as such in the consensus in the next epoch.

Nodes currently sign and upload a Descriptor in each epoch.

In the future, they would instead upload an UploadDescStats containing:

  • Descriptor

  • Stats

  • Signature

Contains a map from pairs-of-mixes to the ratio of count-of-loops-sent vs. count-of-loops-received.

Tracking packet loss and detecting faulty mixes

Katzenpost lets different elements in the network track whether other elements are functioning correctly. A node A will do this by sending packets in randomly generated loops through the network, and tracking whether the loop comes back or not. When it comes back, it will mark that as evidence, that the nodes on the path of that loop are functioning correctly.

Experimental setup, node A:

  • Data: each network node A collects a record of emitted test loops in a certain epoch, their paths and whether they returned or not. Importantly, each loop is the same length and includes l steps.

  • A segment is defined as a possible connection from a device in the network to another, for example from a node in the layer k to a node in the layer k+1. Each loop is a sequence of such segments.

  • Each node A will create 3 hashmaps, sent_loops_A, completed_loops_A and ratios_A. Each of these will use a pair of concatenated mix node ID’s as the key. The ordering of the ID’s will be from lesser topology layer to greater, e.g. the two-tuple (n, n+1) which is represented here as a 64 byte array:

    var sent_loops_A map[[64]byte]int
    var completed_loops_A map[[64]byte]int
    var ratios_A map[[64]byte]float64
    
  • Every time the node A sends out a test loop, for each segment in the loop path, it will increment the value in sent_loops_A.

  • When a test loop returns, for each step in the loop path, it will increment the value in completed_loops_A.

  • Generate a new map entry in ratios_A for each mix-node-pair p, if sent_loops_A[p]==0 set ratios_A[p]=1. Else ratios_A[p] = completed_loops_A[p]/sent_loops_A[p]

  • Plot the resulting distribution, and calculate the standard deviation to detect anomalies. Have the node report significant anomalies after a sufficient time period as to not leak information on the route of individual loops.

  • Anomalies may have to be discarded if the corresponding sent_loops_A[p] is small.

You would expect the distribution of values in completed_loops to approximate a binomial distribution. In an absence of faulty nodes, ratios should be 1, and when there are some faulty nodes values at faulty nodes should approach 0 (if the node doesn’t work at all), and be binomially distributed at nodes that can share a loop with faulty nodes.

Therefore each mix node generates a statistics report to upload to the dirauth nodes, of the struct type:

type LoopStats struct {
Epoch           uint64
MixIdentityHash *[32]byte
Ratios          map[[64]byte]float64
}

The report is subsequently uploaded to the directory authorities, which combine the reports of individual nodes into a health status of the network and arrive at a consensus decision about the topology of the network.

Uploading stats to dirauths

Stats reports are uploaded along with the mix descriptor every Epoch. A cryptographic signature covers both of these fields:

type UploadDescStats struct {
Descriptor []byte
StatsReport []byte
Signature []byte
}    

Statistics reports collected during the XXX period of time, that is, the time between descriptor N+1 upload and descriptor N+2 upload, are what will affect the topology choices in epoch N+2 if the dirauths collectively decide to act on the very latest statistics reports in order to determine for example if a mix node should be removed from the network:

| ---------------- epoch N ---------------- | ---------------- epoch N+1 ---------------- | ---------------- epoch N+2 ---------------- |
| ----------- UD_N+1 ---------------------- | ------------ UD N+2 ----------------------- | ----------- UD N+3 ------------------------ |             | ------------------ XXX ---------------- |  

2.9 -

For node descriptors, directory voting and the signed network parameters used by clients, see the directory authority specification. Its client overview connects applications, kpclientd and gateways.

Mix network specification

Yawning Angel

George Danezis

Claudia Diaz

Ania Piotrowska

David Stainton

Abstract

This document describes the high level architecture and detailed protocols and behavior required of mix nodes participating in the Katzenpost mix network.


Terminology

The following terms are used in this specification.

classes of traffic
We distinguish the following classes of traffic:

  • SURB replies (sometimes referred to as ACKs)

  • Forwarded messages

client
Software run by a user on their local device to participate in the mixnet. A client is not considered a node in the network for purposes of analysis of the core mnixnet protocols.

entry mix, entry node
A mix node that has some additional features:

  • An entry mix is always the first hop in routes where the message originates from a client.

  • An entry mix authenticates client’s direct connections via the mixnet’s wire protocol.

  • An entry mix queues reply messages and allows clients to retrieve them later.

KiB
Defined as 1024 8 bit octets.

message
A variable-length sequence of octets sent anonymously through the network. Short messages are sent in a single packet; long messages are fragmented across multiple packets.

mix node
A cryptographic router that is used to compose a mixnet. Mix nodes use a cryptographic operation on messages being routed which provides bitwise unlinkability with respect to input versus output messages. Katzenpost is a decryption mixnet that uses the Sphinx cryptographic packet format.

mixnet
A mixnet, or mix network, is a network of mix servers that can be used to build various privacy-preserving protocols.

MSL
Maximum segment lifetime, currently set to 120 seconds.

node
Clients are NOT considered nodes in the mix network. However, network protocols are often layered. In our design documents, we describe “mixnet hidden services” that can be operated by mixnet clients. Therefore if you are using the term “node” in some adherence to mathematical terminology, one could conceivably designate a client as a node. However, in discussion of our core mixnet protocol, it is inappropriate to refer to clients as nodes.

packet
A Sphinx packet, of fixed length for each class of traffic, carrying a message payload and metadata for routing. Packets are routed anonymously through the mixnet and cryptographically transformed at each hop.

payload
The fixed-length portion of a packet containing an encrypted message or part of a message, to be delivered anonymously.

service node
A service node is a mix node with additional features:

  • A service node is always the last hop in routes where the message originates from a client.

  • A service node runs mixnet services which use a Sphinx SURB-based protocol.

user
An agent using the Katzenpost system.

Conventions used in this document

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC2119

Introduction

This specification provides the design of a mix network meant provide an anonymous messaging protocol between clients and public mixnet services.

Various system components such as client software, end to end messaging protocols, Sphinx cryptographic packet format and wire protocol are described in their own specification documents.

System overview

The presented system design is based on LOOPIX Below, we present the system overview.

The entry mixes are responsible for authenticating clients, accepting packets from the client, and forwarding them to the mix network, which then relays packets to the destination service mix. Our network design uses a strict topology where forward message traverse the network from entry mix to service mix. Service mixes can optionally reply if the forward message contained a Single Use Reply Block (see SPHINXSPEC.

The PKI system that handles the distribution of various network wide parameters, and information required for each participant to participate in the network such as IP address/port combinations that each node can be reached at, and cryptographic public keys. The specification for the PKI is beyond the scope of this document and is instead covered in KATZMIXPKI.

The mix network provides neither reliable nor in-order delivery semantics. The described mix network is neither a user facing messaging system nor is it an application. It is intended to be a low level protocol which can be composed to form more elaborate mixnet protocols with stronger more useful privacy notions.

Threat model

Here we cannot present the threat model to the higher level mixnet protocols. However this low level core mixnet protocol does have it’s own threat model which we attempt to elucidate here.

We assume that the clients only talk to mixnet services. These services make use of a client provided delivery token known as a SURB (Single Use Reply Block) to send their replies to the client without knowing the client’s entry mix. This system guarantees third-party anonymity, meaning that no parties other than client and the service are able to learn that the client and service are communicating. Note that this is in contrast with other designs, such as Mixminion, which provide sender anonymity towards recipients as well as anonymous replies.

Mixnet clients will randomly select an entry node to use and may reconnect if disconnected for under a duration threshold. The entry mix can determine the approximate message volume originating from and destined to a given client. We consider the entry mix follows the protocol and might be an honest-but-curious adversary.

External local network observers can not determine the number of Packets traversing their region of the network because of the use of decoy traffic sent by the clients. Global observers will not be able to de-anonymize packet paths if there are enough packets traversing the mix network. Longer term statistical disclosure attacks are likely possible in order to link senders and receivers.

A malicious mix only has the ability to remember which input packets correspond to the output packets. To discover the entire path all of the mixes in the path would have to be malicious. Moreover, the malicious mixes can drop, inject, modify or delay the packets for more or less time than specified.

Network topology

The Katzenpost mix network uses a layered topology consisting of a fixed number of layers, each containing a set of mixes. At any given time each Mix MUST only be assigned to one specific layer. Each Mix in a given layer N is connected to every other Mix in the previous and next layer, and or every participating Provider in the case of the mixes in layer 0 or layer N (first and last layer). :

Layer 0          Layer 1        Layer 2        Layer 3           Layer 4
+-----------+      +-------+      +-------+      +-------+      +-------------+
+-> | entry mix | -+-> |  Mix  | -+-> |  Mix  | -+-> |  Mix  | -+-> | service mix |
|   +-----------+  |   +-------+  |   +-------+  |   +-------+  |   +-------------+
|                  |              |              |              |
|   +-----------+  |   +-------+  |   +-------+  |   +-------+  |   +-------------+
+-> | entry mix | -+-> |  Mix  | -+-> |  Mix  | -+-> |  Mix  | -+-> | service mix |
|   +-----------+  |   +-------+  |   +-------+  |   +-------+  |   +-------------+
|                  |              |              |              |
|                  |   +-------+  |   +-------+  |   +-------+  |   +-------------+
|                  +-> |  Mix  | -+-> |  Mix  | -+-> |  Mix  | -+-> | service mix |
|                      +-------+      +-------+      +-------+  |   +-------------+
|                                                               |
+---------------------------------------------------------------+

Note: Multiple distinct connections are collapsed in the figure for sake of brevity/clarity.

The network topology MUST also maximize the number of security domains traversed by the packets. This can be achieved by not allowing mixes from the same security domain to be in different layers.

Requirements for the topology:

  • Should allow for non-uniform throughput of each mix (Get bandwidth weights from the PKI).

  • Should maximize distribution among security domains, in this case the mix descriptor specified family field would indicate the security domain or entity operating the mix.

  • Other legal jurisdictional region awareness for increasing the cost of compulsion attacks.

Packet format overview

For the packet format of the transported messages we use the Sphinx cryptographic packet format. The detailed description of the packet format, construction, processing and security / anonymity considerations see SPHINXSPEC, “The Sphinx mix network cryptographic packet format specification”.

As the Sphinx packet format is generic, the Katzenpost mix network must provide a concrete instantiation of the format, as well as additional Sphinx per-hop routing information commands.

Sphinx cryptographic primitives

For the current version of the Katzenpost mix network, let the following cryptographic primitives be used as described in the Sphinx specification.

  • H(M) - As the output of this primitive is only used locally to a Mix, any suitable primitive may be used.

  • MAC(K, M) - HMAC-SHA256 RFC6234, M_KEY_LENGTH of 32 bytes (256 bits), and MAC_LENGTH of 32 bytes (256 bits).

  • KDF(SALT, IKM) - HKDF-SHA256, HKDF-Expand only, with SALT used as the info parameter.

  • S(K, IV) - CTR-AES256 [SP80038A], S_KEY_LENGTH of 32 bytes (256 bits), and S_IV_LENGTH of 16 bytes (128 bits), with the IV used as the initial 16 byte counter block.

  • SPRP_Encrypt(K, IV, M)/SPRP_Decrypt(K, IV, M) - AEZv5 AEZV5, SPRP_KEY_LENGTH of 48 bytes (384 bits). As there is a disconnect between AEZv5 as specified and the Sphinx usage, let the following be the AEZv5 parameters:

    • nonce - 16 bytes, reusing the per-hop Sphinx header IV.

    • additional_data - Unused.

    • tau - 0 bytes.

  • EXP(X, Y) - X25519 RFC7748 scalar multiply, GROUP_ELEMENT_LENGTH of 32 bytes (256 bits), G is the X25519 base point.

Sphinx packet parameters

The following parameters are used as for the Katzenpost mix network instantiation of the Sphinx Packet Format:

  • AD_SIZE - 2 bytes.

  • SECURITY_PARAMETER - 32 bytes. (except for our SPRP which we plan to upgrade)

  • PER_HOP_RI_SIZE - (XXX/ya: Addition is hard, let’s go shopping.)

  • NODE_ID_SIZE - 32 bytes, the size of the Ed25519 public key, used as Node identifiers.

  • RECIPIENT_ID_SIZE - 32 bytes.

  • SURB_ID_SIZE - Single Use Reply Block ID size, 16 bytes.

  • MAX_HOPS - 5, the ingress provider, a set of three mixes, and the egress provider.

  • PAYLOAD_SIZE - (XXX/ya: Subtraction is hard, let’s go shopping.)

  • KDF_INFO - The byte string katzenpost-kdf-v0-hkdf-sha256.

The Sphinx Packet Header additional_data field is specified as follows:

struct {
uint8_t version;  /* 0x00 */
uint8_t reserved; /* 0x00 */
} KatzenpostAdditionalData;

Double check to ensure that this causes the rest of the packet header to be 4 byte aligned, when wrapped in the wire protocol command and framing. This might need to have 3 bytes reserved instead.

All nodes MUST reject Sphinx Packets that have additional_data that is not as specified in the header.

Design decision.

  • We can eliminate a trial decryption step per packet around the epoch transitions by having a command that rewrites the AD on a per-hop basis and including an epoch identifier.

I am uncertain as to if the additional complexity is worth it for a situation that can happen for a few minutes out of every epoch.

Sphinx per-hop routing information extensions

The following extensions are added to the Sphinx Per-Hop Routing Information commands.

Let the following additional routing commands be defined in the extension RoutingCommandType range (0x80 - 0xff):

enum {
mix_delay(0x80),
} KatzenpostCommandType;

The mix_delay command structure is as follows:

struct {
uint32_t delay_ms;
} NodeDelayCommand;

Mix node operation

All Mixes behave in the following manner:

All Nodes are identified by their link protocol signing key, for the purpose of the Sphinx packet source routing hop identifier.

All Nodes participating in the mix network MUST share a common view of time, via NTP or similar time synchronization mechanism.

All communication to and from participants in the Katzenpost mix network is done via the Katzenpost mix network wire protocol KATZMIXWIRE.

Nodes are responsible for establishing the connection to the next hop, for example, a mix in layer 0 will accept inbound connections from all Providers listed in the PKI, and will proactively establish connections to each mix in layer 1.

Nodes MAY accept inbound connections from unknown Nodes, but MUST not relay any traffic until they became known via listing in the PKI document, and MUST terminate the connection immediately if authentication fails for any other reason.

Nodes MUST impose an exponential backoff when reconnecting if a link layer connection gets terminated, and the minimum retry interval MUST be no shorter than 5 seconds.

Nodes MAY rate limit inbound connections as required to keep load and or resource use at a manageable level, but MUST be prepared to handle at least one persistent long lived connection per potentially eligible peer at all times.

Sphinx mix- and service-node key rotation

Each Node MUST rotate the key pair used for Sphinx packet processing periodically for forward secrecy reasons and to keep the list of seen packet tags short. The Katzenpost mix network uses a fixed interval (epoch), so that key rotations happen simultaneously throughout the network, at predictable times.

Let each epoch be exactly 10800 seconds (3 hours) in duration, and the 0th Epoch begin at 2017-06-01 00:00 UTC. For more details see our “Katzenpost mix network public key infrastructure specification” document. KATZMIXPKI

Sphinx packet processing

The detailed processing of the Sphinx packet is described in the Sphinx specification: “The Sphinx mix network cryptographic packet format specification”. Below, we present an overview of the steps which the node is performing upon receiving the packet:

  1. Records the time of reception.

  2. Perform a Sphinx_Unwrap operation to authenticate and decrypt a packet, discarding it immediately if the operation fails.

  3. Apply replay detection to the packet, discarding replayed packets immediately.

  4. Act on the routing commands.

All packets processed by Mixes MUST contain the following commands.

  • NextNodeHopCommand, specifying the next Mix or Provider that the packet will be forwarded to.

  • NodeDelayCommand, specifying the delay in milliseconds to be applied to the packet, prior to forwarding it to the Node specified by the NextNodeHopCommand, as measured from the time of reception.

Mixes MUST discard packets that have any commands other than a NextNodeHopCommand or a NodeDelayCommand. Note that this does not apply to Providers or Clients, which have additional commands related to recipient and SURB (Single Use Reply Block) processing.

Nodes MUST continue to accept the previous epoch’s key for up to 1MSL past the epoch transition, to tolerate latency and clock skew, and MUST start accepting the next epoch’s key 1MSL prior to the epoch transition where it becomes the current active key.

Upon the final expiration of a key (1MSL past the epoch transition), Nodes MUST securely destroy the private component of the expired Sphinx packet processing key along with the backing store used to maintain replay information associated with the expired key.

Nodes MAY discard packets at any time, for example to keep congestion and or load at a manageable level, however assuming the Sphinx_Unwrap operation was successful, the packet MUST be fed into the replay detection mechanism.

Nodes MUST ensure that the time a packet is forwarded to the next Node is around the time of reception plus the delay specified in NodeDelayCommand. Since exact millisecond processing is unpractical, implementations MAY tolerate a small window around that time for packets to be forwarded. That tolerance window SHOULD be kept minimal.

Nodes MUST discard packets that have been delayed for significantly more time than specified by the NodeDelayCommand.

Anonymity considerations

Topology

Layered topology is used because it offers the best level of anonymity and ease of analysis, while being flexible enough to scale up traffic. Whereas most mixnet papers discuss their security properties in the context of a cascade topology, which does not scale well, or a free-route network, which quickly becomes intractable to analyze when the network grows, while providing slightly worse anonymity than a layered topology. MIXTOPO10

Important considerations when assigning mixes to layers, in order of decreasing importance, are:

  1. Security: do not allow mixes from one security domain to be in different layers to maximise the number of security domains traversed by a packet

  2. Performance: arrange mixes in layers to maximise the capacity of the layer with the lowest capacity (the bottleneck layer)

  3. Security: arrange mixes in layers to maximise the number of jurisdictions traversed by a packet (this is harder to do really well than it seems, requires understanding of legal agreements such as MLATs).

Mixing strategy

As a mixing technique the Poisson mix strategy LOOPIX and KESDOGAN98 is used, which REQUIRES that a packet at each hop in the route is delayed by some amount of time, randomly selected by the sender from an exponential distribution. This strategy allows to prevent the timing correlation of the incoming and outgoing traffic from each node. Additionally, the parameters of the distribution used for generating the delay can be tuned up and down depending on the amount of traffic in the network and the application for which the system is deployed.

Security considerations

The source of all authority in the mixnet system comes from the directory authority system which is also known as the mixnet PKI. This system gives the mixes and clients a consistent view of the network while allowing human intervention when needed. All public mix key material and network connection information is distributed by this directory authority system.

References

AEZV5

Hoang, V., Krovetz, T., Rogaway, P., “AEZ v5: Authenticated Encryption by Enciphering”, March 2017, http://web.cs.ucdavis.edu/~rogaway/aez/aez.pdf.

KATZMIXPKI

Angel, Y., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Public Key Infrastructure Specification”, December 2017, https://katzenpost.network/docs/specs/pdf/pki.pdf.

KATZMIXWIRE

Angel, Y., “Katzenpost Mix Network Wire Protocol Specification”, June 2017, https://katzenpost.network/docs/specs/pdf/wire.pdf.

KESDOGAN98

Kesdogan, D., Egner, J., and Büschkes, R., “Stop-and-Go-MIXes Providing Probabilistic Anonymity in an Open System”, Information Hiding, 1998, https://www.freehaven.net/anonbib/cache/stop-and-go.pdf.

LOOPIX

Piotrowska, A., Hayes, J., Elahi, T., Meiser, S., Danezis, G., “The Loopix Anonymity System”USENIX, August 2017, https://arxiv.org/pdf/1703.00536.pdf.

MIXTOPO10

Diaz, C., Murdoch, S., Troncoso, C., “Impact of Network Topology on Anonymity and Overhead in Low-Latency Anonymity Networks”, PETS, July 2010, https://www.esat.kuleuven.be/cosic/publications/article-1230.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC5246

Dierks, T. and E. Rescorla, “The Transport Layer Security (TLS) Protocol Version 1.2”, RFC 5246, DOI 10.17487/RFC5246, August 2008, http://www.rfc-editor.org/info/rfc5246.

RFC6234

Eastlake 3rd, D. and T. Hansen, “US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)”, RFC 6234, DOI 10.17487/RFC6234, May 2011, https://www.rfc-editor.org/info/rfc6234.

RFC7748

Langley, A., Hamburg, M., and S. Turner, “Elliptic Curves for Security”, RFC 7748, January 2016, https://www.rfc-editor.org/info/rfc7748.

SP80038A

Dworkin, M., “Recommendation for Block Cipher Modes of Operation”, SP800-38A, 10.6028/NIST.SP.800, December 2001, https://doi.org/10.6028/NIST.SP.800-38A.

SPHINXSPEC

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Sphinx Mix Network Cryptographic Packet Format Specification”, July 2017, https://katzenpost.network/docs/specs/pdf/sphinx.pdf.

2.10 -

The directory authority specification describes how service nodes advertise courier endpoints and how replicas publish descriptors. Its clock and key-retention rules distinguish mixnet epochs from storage-replica epochs.

Pigeonhole protocol specification

Threebit Hacker

David Stainton

Abstract

In this specification we describe the components and protocols that compose Pigeonhole scattered storage. We define the behavior of communication clients that send and retrieve individual messages, BACAP streams, and AllOrNothing streams. Client actions are mediated through courier services that interact with storage replicas.


Introduction

Pigeonhole scattered storage enables persistent anonymous communication in which participants experience a coherent sequence of messages or a continuous data stream, but where user relationships and relations between data blocks are unlinkable not only from the perspective of third-party observers, but also from that of the mixnet components. This latter attribute provides resilience against deanonymization by compromised mixnet nodes.

The data blocks that Pigeonhole stores are supplied by the BACAP (Blinding-and-Capability) scheme. The Pigeonhole protocol scatters messages around many storage servers and among a space of BACAP box IDs. From a passive network observer’s perspective, all of this is seemingly random. All communication among users consists of user-generated read or write queries to Pigeonhole storage, never directly to other users.

Many derivative protocols can be composed using Pigeonhole communication channels, including group communications. For details about the protocol specified here, see “§5.6. End-to-end reliable group channels” in our paper Echomix: a Strong Anonymity System with Messaging. For more information about BACAP, see §4 of the paper. For an understanding of how the core BACAP primitives are implemented, see bacap.go.

Message-layout snippets in this specification are given in the trunnel binary-format description language (matching pigeonhole/pigeonhole_messages.trunnel); code snippets showing in-memory courier or replica state are given in Go.

Terminology

The following terms are used in this specification.

box
BACAP’s unit of data storage. Each box has a box ID (which also serves as its public key), a signature, and a ciphertext-signed payload.

courier
Service that runs on a service node and interacts with storage replicas. Proxies requests from clients and routes replies back to clients (via SURBs).

envelope hash
BLAKE2b-256(CourierEnvelope.sender_pubkey || CourierEnvelope.ciphertext). Used by the courier for deduplication of retransmissions and for demultiplexing replica replies.

MKEM
Multi-recipient KEM addressed to the pair of intermediate replicas. One MKEM ciphertext carries, for each recipient, a separate DEK encapsulation (Dek1, Dek2); either recipient may decapsulate and recover the padded ReplicaInnerMessage.

replica epoch
A one-week period, distinct from the 20-minute mixnet PKI epoch, during which a given replica-side MKEM envelope keypair is valid. For more information, see Epochs.

storage replicas
“Intermediate replicas are chosen independently of the two final replicas for that box ID which are derived using the sharding scheme. The reason Alice designates intermediate replicas, as opposed to addressing the final replicas directly, is to avoid revealing to the courier which shard the box falls into.” (From “§5.4.1 “Writing messages” in Echomix: a Strong Anonymity System with Messaging. A designated replica (a.k.a. final replica or shard replica) is one of the two replicas selected deterministically for a given box ID by the Shard2 consistent-hash algorithm. The intermediate replicas write through to the designated replicas.

SURB
Single use reply block. SURBs are used to achieve recipient anonymity, that is to say, SURBs function as a cryptographic delivery token that you can give to another client entity so that they can send you a message without them knowing your identity or location on the network. See SPHINXSPEC and SPHINX.

Storage deployment requirements

A conforming deployment MUST run at least four storage replicas (n ≥ 4). The enables the intermediate-replica unlinkability property described above and in §5.4.1 of the Echomix: a Strong Anonymity System with Messaging: for each CourierEnvelope, the client picks two intermediate replicas which MUST be disjoint from the two final (sharded) replicas that hold the box. Disjointness is what prevents the courier from learning which shard the box falls into.

A conformant deployment and its undesirable alternatives can be compared as follows.

  • n ≥ 4: At least two non-shard replicas exist, so the intermediate set can be drawn uniformly at random from the non-shard subset, and disjointness is preserved.

  • n = 3: Only one replica sits outside any given two-shard set, so the client cannot pick two independent non-shard intermediates. Implementations in this case fall back to an intermediate set that includes at least one shard replica, which tells the courier that replica is one of the two shards for the box.

    The resulting information exposure is bounded:

    • The courier does NOT learn the box ID. The box ID lives inside the MKEM-encrypted inner message addressed to the intermediate replicas; only the replicas can decrypt it.

    • The courier does NOT learn the other shard member. Knowing one element of the two-element shard set does not constrain the identity of the other among the remaining replicas.

    • The courier does NOT gain a way to link boxes in the same sequence. BACAP’s unlinkability of consecutive box IDs (paper §4) is a property of the capability-derivation scheme and is independent of sharding.

  • n = 2: There is only one possible shard set, and the intermediate set is necessarily identical to it.

Consequently, the main unlinkability properties of Pigeonhole are not lost at n = 3, but the defense-in-depth margin provided by disjoint intermediate replicas is. Operators SHOULD treat n ≥ 4 as the minimum supported configuration.

Epochs

Katzenpost has two distinct notions of “epoch” that operate on very different timescales, and Pigeonhole touches both:

  • Mixnet epoch (a.k.a. normal epoch, PKI epoch): the short cadence on which the directory authorities publish a new PKI document. The default is 20 minutes. Mix nodes, gateways, service nodes, and clients all synchronise on this epoch. Sphinx replay keys on mix nodes rotate once per mixnet epoch.

  • Pigeonhole storage-replica epoch: the long cadence on which each storage replica rotates its MKEM envelope keypair. The default is one week. A replica publishes, in every mixnet-epoch PKI descriptor, two envelope public keys: the current replica-epoch key and the next replica-epoch key.

Epoch tolerance for CourierEnvelope

A CourierEnvelope carries an epoch field that identifies the replica epoch whose envelope key the client used to encrypt the MKEM ciphertext. Conforming couriers and storage replicas MUST accept epoch ∈ {current − 1, current, current + 1} where current is the courier’s / replica’s own view of the current replica epoch.

The current − 1 tolerance handles the grace window immediately after a replica-epoch boundary, when a client with a slightly stale PKI view still encrypts to the previous envelope public key. Combined with current, this gives a two replica-epoch data TTL — roughly two weeks — because the future replica-epoch key is by definition a key that hasn’t started being used yet, so current and current − 1 are the epochs where actual data flows.

The current + 1 tolerance handles the same boundary seen from the other side: a client whose clock or PKI view is slightly ahead of the courier / replica.

Envelopes outside this three-epoch window MUST be rejected, because by definition no replica still holds the matching decapsulation key:

  • Older than current − 1: the envelope public key has been pruned from replicas (see the replica’s envelope-key GC worker). The replica cannot decrypt and the courier can fail fast rather than forward a doomed request.

  • Newer than current + 1: no replica has generated that envelope key yet (replicas generate current and current + 1 only).

Couriers SHOULD reject with a dedicated envelope-level error code (EnvelopeErrorInvalidEpoch) so clients can distinguish “stale encryption” from other courier-side rejections.

Pigeonhole message format and constants

The Pigeonhole message types are defined in trunnel at pigeonhole/pigeonhole_messages.trunnel; the Go bindings live in pigeonhole/trunnel_messages.go. All integer fields are big-endian and all variable-length fields carry an explicit length prefix. This trunnel encoding replaces the earlier CBOR encoding with a fixed-overhead binary format whose serialized size can be computed deterministically from the Sphinx geometry.

Carriage of these messages differs by hop:

  • Client → Courier: a CourierQuery is carried inside a Sphinx packet payload. (See the section called “CourierQuery” for details.) The reverse direction uses a SURB supplied by the client.

  • Courier → Replica and Replica → Replica: the courier and replicas do not use Sphinx packets between themselves. They communicate over the Katzenpost wire protocol defined in core/wire and core/wire/commands; the relevant commands are ReplicaMessage, ReplicaMessageReply, ReplicaWrite, and ReplicaWriteReply. Some of these commands embed trunnel-serialized pigeonhole blobs as their payload.

Fundamental size constants

**Table 1. **

Key Value Explanation
BACAP_BOX_ID_SIZE 32 bytes Ed25519 public key
BACAP_SIGNATURE_SIZE 64 bytes Ed25519 signature
HASH_SIZE 32 bytes BLAKE2b-256
MKEM_DEK_SIZE 60 bytes mkem.DEKSize
CTIDH-1024 public key 128 bytes hpqc/nike/ctidh/ctidh1024
X25519 public key 32 bytes hpqc/nike/x25519
Hybrid CTIDH-1024 × X25519 NIKE public key 160 bytes X25519[32], then CTIDH-1024[128]. Tagged encoding.
BACAP payload encryption overhead 16 bytes ChaCha20-Poly1305 AEAD
MKEM encapsulation overhead 28 bytes ChaCha20-Poly1305 nonce (12) + tag (16)

Maximum BACAP payload

The maximum plaintext BACAP payload a single box can carry is derived backwards from the Sphinx UserForwardPayloadLength by subtracting every layer of framing and cryptographic overhead that sits between the Sphinx payload and the BACAP plaintext. The authoritative calculation is performed by NewGeometryFromSphinx in pigeonhole/geo/geometry_impl.go.

Informally:

MaxPlaintextPayloadLength
  = UserForwardPayloadLength
    − CourierQuery framing (1 byte: query_type discriminator)
    − CourierEnvelope header (intermediate_replicas[2] + Dek1 + Dek2
                              + reply_index + epoch + sender_pubkey_len
                              + sender_pubkey + ciphertext_len)
    − MKEM AEAD overhead (28 bytes)
    − ReplicaInnerMessage framing (1 byte: message_type discriminator)
    − ReplicaWrite header (box_id + signature + payload_len = 100 bytes)
    − BACAP AEAD overhead (16 bytes)
    - BACAP length prefix (4 bytes)
    - ReplicaInnerMessage length prefix (4 bytes)

With the 160-byte CTIDH1024-X25519 public key, this write-path overhead is 451 bytes. The tagged geometry calculation includes both four-byte length prefixes.

The CourierEnvelope as seen by the courier

The courier, upon unwrapping the Sphinx payload of a client’s packet, sees a CourierQuery whose content is a CourierEnvelope with the following layout:

struct courier_envelope {
    u8  intermediate_replicas[2];          // replica indices in the PKI
    u8  dek1[MKEM_DEK_SIZE];               // DEK encapsulation for replica 0
    u8  dek2[MKEM_DEK_SIZE];               // DEK encapsulation for replica 1
    u8  reply_index;                       // which replica's reply to prefer
    u64 epoch;                             // replica-epoch under which the
                                           //   MKEM ciphertext was produced
    u16 sender_pubkey_len;
    u8  sender_pubkey[sender_pubkey_len];  // client's ephemeral hybrid NIKE pk
    u32 ciphertext_len;
    u8  ciphertext[ciphertext_len];        // MKEM-encrypted ReplicaInnerMessage
} 

Notable points:

  • The ciphertext is opaque to the courier. It is an MKEM envelope addressed to the pair of intermediate replicas; either replica can decapsulate using its own DEK (dek1 or dek2 respectively).

  • The epoch field names the replica-epoch whose envelope keys were used to produce the MKEM ciphertext. See the section called “Epochs” for the tolerance window.

  • Prior to encryption, the inner ReplicaInnerMessage is zero-padded to ReplicaInnerMessageWriteSize() so that reads, writes and tombstones produce MKEM ciphertexts of identical length.

The ReplicaInnerMessage as seen by a replica

Once an intermediate replica decrypts the MKEM envelope, it obtains a ReplicaInnerMessage — a discriminated union over message_type:

struct replica_inner_message {
    u8 message_type IN [0, 1];    // 0 = read, 1 = write
    union content[message_type] {
        0: struct replica_read  read_msg;   // { box_id[32] }
        1: struct replica_write write_msg;  // { box_id[32], signature[64],
                                            //   payload_len[u32], payload[] }
    };
} 

A ReplicaWrite with payload_len == 0 is a tombstone.

Message types and interactions

Overview

  • A client sends a CourierQuery inside a Sphinx packet payload. The courier’s reply travels back to the client by means of a SURB the client also supplied.

  • A client always designates two intermediate replicas per CourierEnvelope. The courier dispatches the corresponding pair of ReplicaMessage wire commands, one to each intermediate, and collects up to two ReplicaMessageReply results.

  • The reply_index field is a preference indicating which of the two replica replies the client would like forwarded first. It is not a strict selector: should the preferred slot still be empty when the courier is ready to respond, the courier falls back to whichever reply it does hold, and indicates in the CourierEnvelopeReply the actual index that was served (see courier/server/plugin.go).

  • Clients MUST resend identical CourierEnvelope bodies — same sender_pubkey and ciphertext — until they receive a reply. The courier deduplicates resends by EnvelopeHash. Only the Sphinx-layer SURB is rotated between retransmissions.

CourierQuery

A CourierQuery is the top-level discriminated union that a client places into a Sphinx packet payload for the courier:

struct courier_query {
    u8 query_type IN [0, 1];
    union content[query_type] {
        0: struct courier_envelope envelope;      // read or write a single box
        1: struct copy_command     copy_command;  // AllOrNothing copy
    };
}  

The symmetric reply is a CourierQueryReply:

struct courier_query_reply {
    u8 reply_type IN [0, 1];
    union content[reply_type] {
        0: struct courier_envelope_reply envelope_reply;
        1: struct copy_command_reply     copy_command_reply;
    };
}  

CourierEnvelope

The CourierEnvelope layout was given in the section called “The CourierEnvelope as seen by the courier”. The client constructs one CourierEnvelope per read or write. The courier performs the following actions.

  1. Computes EnvelopeHash = BLAKE2b-256(sender_pubkey || ciphertext).

  2. Verifies epoch ∈ {current − 1, current, current + 1} per the replica-epoch tolerance window, otherwise rejecting with EnvelopeErrorInvalidEpoch.

  3. Looks EnvelopeHash up in its dedup cache. If present, the courier returns the cached reply (or an ACK if no reply has yet arrived) without re-dispatching to replicas.

  4. On a cache miss, the courier constructs two ReplicaMessage wire commands — one bound for intermediate_replicas[0] carrying dek1, the other for intermediate_replicas[1] carrying dek2 — and forwards them over the wire protocol.

  5. The courier immediately sends an ACK reply to the client so it may stop retransmitting.

ReplicaMessage (wire command)

ReplicaMessage is not a trunnel pigeonhole type; it is the core/wire/commands command sent from a courier to a replica. Its payload fields are copied verbatim from the matching CourierEnvelope:

// core/wire/commands
type ReplicaMessage struct {
    SenderEPubKey []byte     // copied from CourierEnvelope.sender_pubkey
    DEK           *[MKEM_DEK_SIZE]byte  // dek1 or dek2, depending on destination
    Ciphertext    []byte     // copied from CourierEnvelope.ciphertext
}

The recipient replica decapsulates the MKEM envelope using the replica-epoch key that corresponds to CourierEnvelope.epoch (trying each of the three keys in its tolerance window), yielding a padded ReplicaInnerMessage. The replica then dispatches on message_type to ReplicaRead or ReplicaWrite handling.

ReplicaMessageReply (wire command)

In response to a ReplicaMessage, the courier expects an asynchronous ReplicaMessageReply wire command from the replica:

// core/wire/commands
type ReplicaMessageReply struct {
    ErrorCode     uint8                 // see the replica error-code table below
    EnvelopeHash  *[HASH_SIZE]byte      // lets the courier demultiplex the reply
    EnvelopeReply []byte                // MKEM-encrypted ReplicaMessageReplyInnerMessage
}

The EnvelopeReply byte blob is produced by the replica via the MKEM scheme’s EnvelopeReply() method (see replica/handlers.go). It carries a ReplicaMessageReplyInnerMessage — a discriminated union over either a ReplicaReadReply or a ReplicaWriteReply — padded to ReplicaReplyInnerMessageReadSize() so that read replies and write replies are indistinguishable in size, and encrypted to the client’s ephemeral NIKE public key under the replica’s envelope keypair.

CourierBookKeeping

For each outstanding EnvelopeHash, the courier maintains an in-memory dedup entry. Its actual structure is:

// courier/server/plugin.go
type CourierBookKeeping struct {
    Epoch                uint64        // replica-epoch at cache insertion
    CreatedAt            time.Time     // for TTL eviction (~5 minutes)
    QueryType            uint8         // the query_type that produced this entry
    IntermediateReplicas [2]uint8
    EnvelopeReplies      [2]*commands.ReplicaMessageReply
}  

Note that the courier does not cache SURBs or SURB timestamps. A client’s SURB is consumed by the Sphinx-layer plugin infrastructure at the moment the courier emits a reply and is not retained by the courier’s Pigeonhole state. Should the client not receive that reply, it is expected to retransmit a fresh Sphinx packet carrying a fresh SURB but the identical CourierEnvelope body; the courier, recognising the EnvelopeHash, replies using the new SURB.

The dedup cache has a TTL of 5 minutes (DedupCacheTTL in courier/server/plugin.go).

CourierEnvelopeReply

The courier’s reply to a CourierEnvelope has the following trunnel layout:

struct courier_envelope_reply {
    u8  envelope_hash[HASH_SIZE];       // identifies the originating envelope
    u8  reply_index;                    // which intermediate replica's reply
                                        //   is being returned (may differ
                                        //   from the client's requested index)
    u8  reply_type IN [0, 1];           // 0 = ACK, 1 = PAYLOAD
    u32 payload_len;
    u8  payload[payload_len];           // the MKEM-encrypted EnvelopeReply,
                                        //   present iff reply_type == PAYLOAD
    u8  error_code;                     // see envelope error codes below
}

A reply_type of ACK (0) indicates the courier has received the envelope and dispatched it to the replicas but has not yet received a reply for the requested index. A reply_type of PAYLOAD (1) indicates the payload field carries the MKEM-encrypted EnvelopeReply produced by a replica.

Embedded pigeonhole types

These trunnel structs are not carried on the wire in isolation; they are embedded inside MKEM envelopes and their replies.

ReplicaRead

Embedded inside the MKEM-encrypted ReplicaInnerMessage a client sends to a replica (via the courier) for a read operation.

struct replica_read {
    u8 box_id[BACAP_BOX_ID_SIZE];
}  

ReplicaReadReply

Embedded inside the MKEM-encrypted ReplicaMessageReplyInnerMessage a replica returns for a successful read. Padding is applied at the outer ReplicaMessageReplyInnerMessage level; this struct carries no padding of its own.

struct replica_read_reply {
    u8  error_code;
    u8  box_id[BACAP_BOX_ID_SIZE];
    u8  signature[BACAP_SIGNATURE_SIZE];
    u32 payload_len;
    u8  payload[payload_len];
}

ReplicaWrite

Used both (a) embedded inside the MKEM-encrypted ReplicaInnerMessage for a client write, and (b) carried directly as a core/wire/commands command between replicas during replication.

struct replica_write {
    u8  box_id[BACAP_BOX_ID_SIZE];
    u8  signature[BACAP_SIGNATURE_SIZE];
    u32 payload_len;
    u8  payload[payload_len];
}

A ReplicaWrite with payload_len == 0 is a tombstone. Replicas treat tombstone writes as overwrites: an existing box at the same box_id is replaced by the tombstone, and subsequent reads return ReplicaErrorTombstone.

ReplicaWriteReply

Embedded inside a ReplicaMessageReplyInnerMessage on the client reply path, and also used as the core/wire/commands reply to inter-replica replication.

struct replica_write_reply {
    u8 error_code;
}

Tombstones

A ReplicaWrite whose payload_len == 0 is a tombstone. It marks a box as deleted without revealing that fact to the courier.

  • Replicas treat a tombstone write as an ordinary overwrite. An existing Box at the same box_id is replaced by the tombstone, and subsequent reads of that box_id return ReplicaErrorTombstone. (See the section called “Replica error codes”.)

  • ReplicaErrorTombstone is an expected outcome rather than a failure; it positively confirms that the box was deleted, as distinct from ReplicaErrorBoxNotFound.

  • Because the inner ReplicaInnerMessage is zero-padded to ReplicaInnerMessageWriteSize() before MKEM encryption (as described in the section called “The CourierEnvelope as seen by the courier”), a tombstone write produces an MKEM ciphertext of exactly the same length as a non-empty write or a read. A passive observer therefore cannot distinguish deletion from any other operation.

Tombstones are also used by the AllOrNothing copy protocol. After processing a CopyCommand, the courier overwrites every box of the temporary stream with tombstones.

EnvelopeHash

The EnvelopeHash uniquely identifies a CourierEnvelope for the purposes of deduplication and reply demultiplexing. It is computed as:

EnvelopeHash = BLAKE2b-256(sender_pubkey || ciphertext)

where sender_pubkey and ciphertext are the corresponding fields of the CourierEnvelope. The implementation is CourierEnvelope.EnvelopeHash() in pigeonhole/helpers.go.

A retransmitted CourierEnvelope carries the same sender_pubkey and ciphertext as the original, and therefore hashes to the same value; only the surrounding Sphinx packet (and its SURB) changes between attempts.

Error codes

All error codes are defined in pigeonhole/errors.go.

Replica error codes

Returned by a replica in ReplicaMessageReply.ErrorCode, ReplicaReadReply.error_code, and ReplicaWriteReply.error_code.

**Table 2. **

Code Name Meaning
0 ReplicaSuccess Operation completed successfully
1 ReplicaErrorBoxIDNotFound Read miss (expected outcome)
2 ReplicaErrorInvalidBoxID Malformed box ID
3 ReplicaErrorInvalidSignature BACAP signature verification failed
4 ReplicaErrorDatabaseFailure Transient RocksDB error
5 ReplicaErrorInvalidPayload Malformed payload
6 ReplicaErrorStorageFull Storage capacity exceeded
7 ReplicaErrorInternalError Internal server error
8 ReplicaErrorInvalidEpoch Replica-epoch envelope key unavailable
9 ReplicaErrorReplicationFailed Replication to shard peer failed
10 ReplicaErrorBoxAlreadyExists Idempotent-write outcome (expected)
11 ReplicaErrorTombstone Read returned a tombstone (expected)

Codes 1, 10 and 11 are “expected outcomes” — they correspond to normal protocol states rather than faults. The thin-client helper thin.IsExpectedOutcome(err) treats these three codes as non-errors.

Courier envelope error codes

Returned by the courier in CourierEnvelopeReply.error_code.

**Table 3. **

Code Name Meaning
0 EnvelopeErrorSuccess Operation completed.
1 EnvelopeErrorInvalidEnvelope Malformed envelope (e.g. reply_index > 1)
2 EnvelopeErrorCacheCorruption Internal cache inconsistency
3 EnvelopeErrorPropagationError Failed to dispatch to replicas.
4 EnvelopeErrorInvalidEpoch CourierEnvelope.epoch outside tolerance window.

Copy command status codes

Returned by the courier in CopyCommandReply.status (see below).

Returned by the courier in the status field of a CopyCommandReply. (See the section called “CopyCommandReply” for more information.)

**Table 4. **

Code Name Meaning
0 CopyStatusSucceeded All destination writes completed.
1 CopyStatusInProgress Courier has accepted the command; processing continues.
2 CopyStatusFailed Aborted; see error_code + failed_envelope_index.

Sharding and replica selection

For each box, two designated (final) replicas are derived deterministically from the box ID using the Shard2 consistent-hash algorithm, as shown in the following pseudo-code.

for each online replica r with identity key k_r:
    h_r = BLAKE2b-256(k_r || box_id)
return the two replicas whose h_r values are smallest

For more information about sharding, see replica/common/shard.go.

The two intermediate replicas chosen by the client for a given CourierEnvelope are drawn independently of the designated replicas, per pigeonhole.GetRandomIntermediateReplicas:

  • n ≥ 4 replicas: two intermediates are drawn uniformly at random from the replicas that are not in the designated (shard) set — preserving the disjointness invariant described in the section called “Storage deployment requirements”.

  • n = 3: fallback — at least one intermediate must coincide with a designated replica; this weakens the intermediate/final disjointness guarantee but does not compromise box unlinkability.

  • n < 3: rejected.

Intermediate replicas, upon accepting a ReplicaWrite, compute the designated replicas themselves and forward the ReplicaWrite to them via the core/wire/commands``ReplicaWrite command. For more information, see replica/connector.go.

Protocol sequence visualizations

For simplicity, the following diagrams omit replication while illustrating the Pigeonhole write and read operations.

Pigeonhole write operation

Figure 1. Annotated writes

Protocol annotation image of writes.

Pigeonhole read operation

Figure 2. Annotated reads

Protocol annotation image of reads.

Pigeonhole AllOrNothing protocol

The AllOrNothing delivery mechanism ensures that a set of associated BACAP writes either succeeds or fails atomically from the point of view of a replica or second-party client reader. This behavior prevents an adversary from detecting a correlation between (A) the sending client’s failure to transmit multiple messages at once with (B) a network interruption on the sending client’s side of the network. Regardless of the number of messages in the set, the adversary gets to observe “at most once” that the sending client interacted with the network.

The protocol works as follows.

Step 1

The client uploads a temporary Pigeonhole stream.

The stream is sequence of CourierEnvelopes. Each CourierEnvelope is serialized and prefixed with a single 4-byte (u32) length field giving the size of that one envelope; the resulting length-prefixed blobs are concatenated back-to-back into one continuous byte stream.

That byte stream is then split across the BACAP Boxes of the temporary stream. A serialized CourierEnvelope is strictly larger than the maximum BACAP box payload (it wraps a full box payload plus its own metadata), so a single envelope does not fit in one box and the concatenated stream necessarily spans several boxes. Envelope boundaries therefore do not align with box boundaries. The precise framing is given in the section called “Temporary stream data format”.

Step 2

The client sends a random courier the copy command which encapsulates the write capability to the temporary Pigeonhole stream written in Step 1 above. When the courier receives this copy command it extracts the ReadCap from the given WriteCap and uses it to read the stream of data. The courier then reads a box at a time and tries to extract 0 or 1 envelopes from each accumulation of stream segments.

After processing the command, the courier then overwrites the temporary stream with tombstones.

Temporary stream data format

Each box in the temporary stream is a serialized CopyStreamElement. Defined in trunnel as:

// CopyStreamElement - wraps a CourierEnvelope chunk with stream position flags.
// Overhead: 1 byte (flags) + 4 bytes (envelope_len) = 5 bytes
struct copy_stream_element {
    // Flags: bit 0 = isStart, bit 1 = isFinal
    u8 flags;
  
    // The CourierEnvelope serialized bytes
    u32 envelope_len;
    u8 envelope_data[envelope_len];
}

Here it is in golang:

type CopyStreamElement struct {
    Flags        uint8
    EnvelopeLen  uint32
    EnvelopeData []uint8
}

The purpose of this specific format is to use the isStart and isFinal flags to tell the courier the first box and last box of the stream to process. The payload encapsulated within the EnvelopeData fields of many of these CopyStreamElements is itself a stream of data which contains CourierEnvelopes with four-byte prefixes.

A key property of this encoding is that envelope boundaries do not align with box boundaries. Each BACAP box payload has a maximum size of N bytes, but a serialized CourierEnvelope (which contains a full box payload plus metadata) exceeds N bytes. Therefore envelopes are serialized into a continuous byte stream and split across multiple boxes in the temporary copy stream:

TEMPORARY COPY STREAM BOXES (each holds N bytes):
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│    Box 0    │ │    Box 1    │ │    Box 2    │ │    Box 3    │ │    Box 4    │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
SERIALIZED ENVELOPE DATA (envelope boundaries don't align with box boundaries):
┌─────────────────────────┐┌────────────────────┐┌──────────────────────────┐
│       Envelope 1        ││     Envelope 2     ││       Envelope 3         │
└─────────────────────────┘└────────────────────┘└──────────────────────────┘
|         |         |         |         |         |
     Box 0     Box 1     Box 2     Box 3     Box 4

The courier reads the stream box by box, accumulating data until it can extract complete envelopes. The isStart and isFinal flags on the CopyStreamElement wrappers tell the courier where the stream begins and ends.

Each embedded CourierEnvelope is processed as a normal write and results in a ReplicaMessage being dispatched to the intermediate replicas over the wire protocol.

The courier does NOT need to keep track of the EnvelopeHash for each contained CourierEnvelope for the purpose of replying to the client (the “client” of these envelopes being, in this case, the courier itself), but it does need to keep resending them until the intermediate replicas have ACKed them.

The courier MUST keep track of the hash of the CopyCommand (computed as BLAKE2b-256(write_cap)) and MUST NOT process a given command more than once. This dedup cache has a TTL of 30 minutes (CopyDedupCacheTTL in courier/server/plugin.go).

CopyCommand

CopyCommand is sent by a client to its chosen courier after the client has successfully uploaded every box of the temporary stream. The trunnel layout is:

struct copy_command {
    u32 write_cap_len;
    u8  write_cap[write_cap_len];   // serialized BACAP BoxOwnerCap
}

On receipt, the courier:

  1. Computes copyKey = BLAKE2b-256(write_cap).

  2. Consults its copy dedup cache. If an in-progress entry is found, the courier responds immediately with CopyStatusInProgress. If a completed entry within its TTL is found, the courier returns the cached terminal reply.

  3. Otherwise, the courier reconstructs the BACAP WriteCap from the bytes, derives the corresponding ReadCap, and reads the temporary stream box by box, feeding the decrypted BACAP payloads into a CopyStreamEnvelopeDecoder.

  4. Each complete CourierEnvelope emitted by the decoder is dispatched to its two intermediate replicas; the courier waits for acknowledgements with bounded retries and exponential backoff.

  5. Upon processing the box bearing the isFinal flag (or upon an unrecoverable failure), the courier attempts — on a best-effort basis — to overwrite every box of the temporary stream with a tombstone.

Replica error handling during a CopyCommand is classified as temporary or permanent by courier/server/copy_errors.go: transient errors (storage full, database failure, internal error, replication failed, box-ID not found) trigger bounded retries against the same shard before failover; permanent errors (invalid box ID, invalid signature, invalid payload, invalid epoch, box already exists, tombstone) cause immediate failover or abort.

CopyCommandReply

The courier’s reply to a CopyCommand has the following trunnel layout:

struct copy_command_reply {
    u8  status;                   // CopyStatus{Succeeded, InProgress, Failed}
    u8  error_code;               // replica error code (meaningful iff status == Failed)
    u64 failed_envelope_index;    // 1-based sequential position in the
                                  //   CourierEnvelope stream at which processing
                                  //   stopped (meaningful iff status == Failed)
}  

The status codes are enumerated in “Copy command status codes” above. failed_envelope_index counts envelopes within the stream, not boxes: the first envelope in the first box of the temporary stream is index 1.

A client receiving CopyStatusInProgress should continue polling — i.e. resend the same CopyCommand via a fresh SURB after a short interval (CopyPollInterval, currently 5 seconds) — until it receives either CopyStatusSucceeded or CopyStatusFailed. Because the courier’s copy dedup cache keys on BLAKE2b-256(write_cap), these repeated polls will not cause the CopyCommand to be processed more than once.

Potential use cases of AllOrNothing

In no particular order:

  • Atomically writing to two or more boxes.

    • The boxes can reside on distinct streams (or not); the courier doesn’t know anything about streams of CourierEnvelope.
  • Sending long messages that span more than one BACAP payload, like a file / document / picture.

  • Group chat join uses AllOrNothing when adding a new member to the group:

    • The person introducing a new member writes to their group chat stream.

    • The person introducing a new member also writes to the existing conversation stream that the new member can already read.

  • Group chat uses AllOrNothing in all cases where it needs to send long messages – files, pictures, audio, long cryptographic keys such as the group membership list, and so on.

Protocol narration example

Alice wants to send a message to Bob, who is already connected to Alice. That is, Alice will write to a box with ID 12345 that Bob is trying to read from.

  1. Alice sends:

    1. SPHINX packet containing:

      • SPHINX header

        • Routing commands to make it arrive at a courier (on a service provider)
      • SPHINX payload

        • Reply SURB

        • CourierEnvelope encrypted for a courier chosen at random. The envelope tells the courier about two randomly chosen replicas (“intermediate replicas”).

    2. Alice doesn’t know if the packet makes it through the network. Until she receives a reply, she keeps resending the CourierEnvelope to the same courier.

  2. The courier receives the CourierEnvelope from Alice.

    1. The courier records the EnvelopeHash of the CourierEnvelope in its CourierBookKeeping datastructure.

    2. If the courier has already seen that hash, GOTO step 4.

  3. The courier sends an ACK to Alice using the SURB on file for Alice, telling her to stop resending the CourierEnvelope. If there’s no SURB, the Courier waits for the next re-sent CourierEnvelope from Alice matching the EnvelopeHash.

    1. The courier constructs two ReplicaMessage objects and puts them in its outgoing queue for the two intermediate replicas. (Note that each courier maintains constant-rate traffic with all replicas).

    2. The courier keeps doing this for each intermediate replica until it receives an ACK from that replica.

Alice’s actions are now complete.

  1. The two intermediate replicas receive the two ReplicaMessage objects.

    1. They decrypt them and compute the “designated replicas” based on the BACAP box ID.

    2. The replicas put ACKs in their outgoing queues for the courier saying “we have received these messages” (see step 3.2), referencing the EnvelopeHash. This tells the courier to stop resending to the intermediate replicas.

    3. They put the decrypted contents (a ReplicaWrite BACAP tuple: box ID 12345; signature; encrypted payload) in their outgoing queues for the “designated replicas”.

    4. Each replica waits for a reply from its designated replica.

    5. When an intermediate replica receives its ACK from the designated replica, the intermediate replica has no more tasks.

Bob now wants to check if Alice has written a message at box 12345.

  1. Similar to step 1, Bob sends a SPHINX packet to a courier chosen at random.

    1. SPHINX packet containing:

      • SPHINX header

        • Routing commands to make it arrive at a courier (on a service provider).
      • SPHINX payload

        • The envelope tells the courier about two randomly chosen replicas (“intermediate replicas”).

        • CourierEnvelope encrypted for a courier chosen at random. Its encrypted payload is a ReplicaRead command (reference box ID 12345).

    2. Bob doesn’t know if the packet makes it through the network. Until he receives a reply, he keeps resending the CourierEnvelope to the same courier.

  2. The courier receives Bob’s CourierEnvelope. (Similar to step 2).

  3. The courier sends an ACK to Bob. (Similar to step 3.)

  4. The two intermediate replicas receive the two ReplicaMessage objects containing Bob’s ReplicaRead.

    1. Similar to 4.A.

    2. Similar to 4.B.

    3. Similar to 4.C.

    4. Similar to 4.D.

    5. When the intermediate replica receives its ACK from the designated replica, it will include the (perhaps confusingly named) ReplicaWrite (BACAP tuple).

    6. The intermediate replica wraps it in a ReplicaMessageReply encrypted for Bob’s ReplicaMessage.EPubKey and puts it in its outgoing queue for the Courier.

  5. The Courier receives two ReplicaMessageReply wire commands from the two intermediate replicas.

    1. It matches ReplicaMessageReply.EnvelopeHash to its recorded bookkeeping state (step 2.1).

    2. It wraps the replica’s EnvelopeReply blob (the MKEM-encrypted ReplicaMessageReplyInnerMessage) into a CourierEnvelopeReply with reply_type = PAYLOAD, and — if Bob’s latest retransmission arrived with a fresh Sphinx SURB — forwards the resulting CourierQueryReply back through the mixnet to Bob.

    3. Either way the courier retains the ReplicaMessageReply in its dedup cache for the cache TTL (5 minutes), so that a subsequently-arriving retransmission of the same envelope can be served from cache without re-dispatching to replicas.

  6. Bob keeps resending his CourierEnvelope from step 5 until he receives a CourierEnvelopeReply with reply_type = PAYLOAD.

    1. Bob decapsulates the MKEM EnvelopeReply with the private key corresponding to the sender_pubkey he put in his CourierEnvelope, obtaining the padded ReplicaMessageReplyInnerMessage.

    2. Once unpadded, the inner message is either a ReplicaReadReply carrying the BACAP tuple (box ID, signature, ciphertext) or a non-success error_code. If the code is ReplicaErrorBoxIDNotFound, Bob waits and polls again (i.e. returns to step 5). If it is ReplicaErrorTombstone, Alice has deleted the message. Otherwise Bob BACAP-decrypts and verifies the payload.

Bob can now read Alice’s message.

2.11 -

Abstract

In this document we describe the traffic shaping and decoy traffic design for the direct connections among Pigeonhole couriers and storage replicas. These links exist outside of the mix network proper: couriers maintain persistent connections to every storage replica, and replicas maintain persistent connections to one another. Because these connections are direct, they receive none of the protections of the Sphinx packet format or the mixing strategy, and their traffic patterns must instead be protected by rate discipline and decoy traffic. This document specifies the send pacing, the decoy generation rules, the reply scheduling, the link liveness rules, and the capacity semantics that follow from them. It complements our mix decoy loop specification and the Pigeonhole protocol specification, and corresponds to §5 of our paper Echomix: a Strong Anonymity System with Messaging, in particular the fixed-throughput connections described there and the reply delays of §5.4.

1. Introduction

Every client interaction with Pigeonhole storage traverses two very different kinds of network path. The path from the client through the mix network to a courier is protected by Sphinx packets, per-hop mixing delays, and the client’s own Poisson decoy processes. The onward path from the courier to the storage replicas, and among the replicas themselves, is a set of plain, long-lived, mutually authenticated PQ Noise connections. An adversary observing one of these direct links sees neither box IDs nor payload contents, but without further measures it would see the one thing we have promised to hide: when, and how much, real work the network is doing.

Our answer is the classic one, applied uniformly: each such link is a fixed-throughput channel. Its send rate is a public constant drawn from the PKI document, its slots are filled with decoys whenever no real work is queued, and its observable behavior is therefore independent of client activity. The rest of this document makes that principle precise, and records the queueing-theoretic reasoning behind the two mechanisms that implement it: a Poisson send clock on the originator side of each connection, and independently jittered replies on the responder side.

A guiding rule throughout: dimensionless ratios may live in code; timescales come from the PKI document. Every delay, deadline, and rate in this design is derived from the consensus parameters, chiefly LambdaR, so that operators tune the network in one place and every component follows.

2. Roles: originator and responder

Each direct connection has exactly one originator and one responder, fixed for the life of the connection:

  • A courier is the originator on each of its connections to the R storage replicas.
  • A replica is the originator on each of its connections to its R−1 replica peers, used for write replication and proxying.
  • The responder is whichever party accepted the connection. Replicas respond to couriers and to peer replicas.

The two roles have deliberately asymmetric traffic rules, described next. The asymmetry is not incidental: the originator’s job is rate discipline, the responder’s job is unlinkability of replies, and as we show in §4, using the originator’s mechanism on the responder side is not merely unnecessary but mathematically unsound.

3. Originator: the Poisson send clock

The originator paces every transmission on the link, real or decoy, with a single pseudorandom clock: inter-send intervals are drawn from the exponential distribution with rate LambdaR (events per millisecond), taken from the PKI document’s Parameters section. Sampled intervals are clamped at the (1 − 10⁻¹²) quantile of that same distribution, our standard sampling safety cap, so the realized process is indistinguishable from the unclamped exponential in any honest measurement window.

In front of the clock sits a FIFO queue of real commands. On each tick the originator sends the oldest queued real command; if the queue is empty it sends a decoy command instead. A real message therefore replaces a decoy in its slot, and the wire carries a constant-rate Poisson stream at LambdaR regardless of load. The responder can distinguish decoys from real commands (it must, to answer them), but a passive observer of the link cannot, and the link’s rate reveals nothing about how busy the courier or replica is.

Two consequences deserve emphasis:

  • Sends are never gated on replies. An earlier revision of the courier made each send wait for the previous command’s reply, as a form of flow control. This coupled the link’s observable timing to replica processing latency, silenced decoy slots exactly when a replica was slow, and head-of-line blocked the link behind a single lost reply. It also provided no capacity that the Poisson clock does not already provide: LambdaR is a hard, deterministic ceiling on the send rate, which is a stronger guarantee against overrunning a replica than any reply-coupled scheme. The clock is the sole pacing authority; replies are matched to commands by envelope hash and may arrive in any order, at any time.

  • Load shedding is provisioning, not backpressure. Nothing any client does can push a replica beyond (C + R − 1) × LambdaR inbound messages per second, where C is the number of couriers and R the number of replicas. Keeping up is therefore decided once, when LambdaR is provisioned, not negotiated at runtime. §6 gives the arithmetic.

4. Responder: one-for-one echo with uniform jitter

The responder never originates traffic. It answers each received command with exactly one reply: a real reply to a real command, a decoy reply to a decoy command. Its outbound rate is thus pinned to the originator’s LambdaR by one-to-one correspondence, and the link is symmetric and constant-rate in both directions.

Each reply is held for an independently sampled delay drawn from the uniform distribution on [0, J], where J = 1/LambdaR, one mean link slot, computed from the PKI document. The delay is drawn from a cryptographic randomness source, since a predictable jitter defends nothing. Replies wait in a timer queue keyed by their ready-at time; by Little’s Law the expected queue depth is LambdaR × J / 2, which with J = 1/LambdaR is one half of one reply at any rate.

This generalizes the reply delays of §5.4 of the paper, whose purpose is to prevent a courier from linking replies that pertain to the same box, and to hide the processing-time variance that would otherwise distinguish, say, a cheap decoy echo from a write that waited on a storage compaction.

Two questions about this design have principled answers worth recording:

Why is the responder not paced by its own Poisson clock, like the originator? Because its production rate is pinned at LambdaR by the echo rule, a paced drain at the same LambdaR would place the reply queue exactly at the M/M/1 boundary, utilization ρ = 1. A queue at ρ = 1 is null-recurrent: it possesses no stationary distribution and its depth wanders upward without bound. We observed precisely this in practice, as sustained per-connection backlogs of fifty to ninety replies, before replacing the responder’s paced sender with the delayed-reply emitter. A paced drain strictly faster than LambdaR would be sound but pointless, since the output would simply track the input. There is no rate for a responder-side clock that is both useful and correct.

Why uniform jitter rather than exponential? By the displacement theorem for Poisson processes, displacing each event of a Poisson stream by an independent, identically distributed delay yields another Poisson stream of the same rate, whatever the delay distribution. The reply stream therefore inherits its Poisson character from the command stream for free, and the jitter distribution influences only two things: the worst-case added latency, and how thoroughly nearby replies are decorrelated within that latency budget. Replies sit on an interactive path, so the budget is a hard cap, and the uniform distribution is the maximum-entropy distribution under a hard cap. An exponential jitter would buy an unbounded latency tail and, by the displacement theorem, nothing else.

A fixed-throughput link doubles as its own failure detector. When decoy traffic is enabled, inter-arrival gaps on a healthy link are exponential with rate LambdaR, so we set the wire session’s read deadline to the same (1 − 10⁻¹²) quantile used as the sampling safety cap, roughly 27.6 / LambdaR milliseconds. A peer silent for that long is dead with overwhelming probability, and the connection is torn down and redialed. There is no separate keepalive machinery: the decoy stream is the keepalive.

When decoy traffic is disabled, as in our continuous integration and other testing postures, an idle link is legitimate and protocol silence implies nothing. No idle read deadline is imposed at all. Dead peers are instead detected by TCP keepalive at the kernel, which errors out a blocked read on a vanished peer, and writes remain bounded by the wire session’s write deadline. Disabling decoys trades away the metadata protections; it does not have to trade away link stability.

6. Capacity semantics

LambdaR is not merely a decoy rate; it is the provisioned capacity of every link, made literal by the design: with decoys on, each link carries exactly LambdaR messages per second, and real traffic consumes slots that decoys would otherwise fill.

The stability condition is the elementary single-server queueing bound: the real offered load on each link must stay below LambdaR, with headroom, because queueing delay grows as 1/(LambdaR − load) as the load approaches capacity. In terms of network parameters, with X clients each producing pigeonhole operations at LambdaP, C couriers, and R replicas:

  • Each operation is one courier envelope, dispatched as two replica messages, one to each client-chosen intermediate replica. Per courier-to-replica link the offered load is X × LambdaP × 2 / (C × R), and stability requires this to remain below LambdaR.
  • Each write additionally causes the intermediate replicas to replicate or proxy toward the box’s two final shard replicas, costing between one and four messages on the replica-to-replica mesh depending on shard coincidences, spread over R × (R − 1) directed links, each likewise paced at LambdaR.

The worst-case inbound rate at any single replica is (C + R − 1) × LambdaR, a quantity fixed entirely by public consensus values. Replicas are sized for it once.

Because a link’s rate never varies with demand, capacity planning is deliberately an over-provisioning exercise: LambdaR is chosen for a target user population comfortably above the expected one. We must never derive LambdaR from measured load; a demand-adaptive rate would broadcast the network’s activity level in the consensus itself, defeating the purpose of the fixed-throughput design. A future refinement is to have the directory authorities compute LambdaR at voting time from a declared target capacity together with the topology, in the same manner that LambdaG is computed from the Coupon Collector’s Bound, so that the provisioning intent is stated once and the rate follows the topology automatically.

7. Summary of parameters and derivations

Quantity Value Source
Originator send pacing Exp(LambdaR), safety-capped PKI document
Decoy generation on tick, when FIFO empty originator only
Reply rate 1:1 echo of command rate responder rule
Reply jitter bound J 1/LambdaR (uniform on [0, J]) PKI document
Read deadline, decoys on SafetyCap(LambdaR) ≈ 27.6/LambdaR PKI document
Read deadline, decoys off none (TCP keepalive detects dead peers) posture
Worst-case replica ingress (C + R − 1) × LambdaR topology + PKI document

The only constants living in code are dimensionless: the choice of one mean slot for the jitter bound, and the 10⁻¹² tail probability shared with every other exponential sampler in Katzenpost.

Appendix A: the theory, briefly

Poisson process. Events occurring independently at a constant average rate λ. The gaps between events follow the exponential distribution with mean 1/λ, and the process is memoryless: having waited a while tells you nothing about how much longer you will wait. This is what makes it the natural shape for traffic that must reveal nothing.

M/M/1. The simplest queue: Poisson arrivals, exponential service times, one server. Its behavior is governed by the utilization ρ, the arrival rate divided by the service rate. For ρ < 1 the queue is stable and keeps returning to empty; the average wait grows as 1/(service − arrival), so it explodes as ρ approaches 1.

The M/M/1 boundary (ρ = 1). The server keeps up exactly on average, and intuition says the queue should hold steady. It does not. At ρ = 1 the queue length is a fair coin-flip walk with no restoring force; the floor at zero clips its downward excursions but not its upward ones, so it drifts up roughly like the square root of elapsed time and never settles. Formally the queue is null recurrent: it always eventually empties, but the expected time to do so is infinite. This is why the responder must not pace replies at the same rate they are produced, and why offered load must sit well below LambdaR.

Little’s Law. In any stable system, average occupancy equals arrival rate times average time spent inside: L = λW. With reply jitter uniform on [0, J] the average wait is J/2, so the emitter’s timer queue holds LambdaR × J/2 items, which for J = 1/LambdaR is one half of one reply at any rate.

Displacement theorem. Delay each event of a Poisson stream by an independent random amount, drawn from any distribution, and the result is again a Poisson stream at the same rate. Hence reply jitter cannot and need not shape the aggregate traffic; its only job is to decorrelate individual replies, so we choose the jitter distribution purely for that.

Maximum entropy. Among all distributions confined to [0, J], the uniform is the least predictable; among all with a fixed mean on unbounded support, the exponential is. Replies live under a hard latency budget, so uniform is the correct choice; an exponential jitter would buy an unbounded tail and, by the displacement theorem, nothing else.

SafetyCap. Sampling from an exponential distribution occasionally yields absurdly long delays, and a real system must bound them, yet any visible truncation would distort the distribution an adversary observes. SafetyCap(λ) resolves the tension by capping at the (1 − 10⁻¹²) quantile: solving e^(−λt) = 10⁻¹² gives t = ln(10¹²)/λ ≈ 27.63/λ. A draw is clamped once per trillion samples, so the realized traffic is statistically indistinguishable from the pure exponential, while the system still holds a hard bound. The same number serves as the dead-peer test on a decoy-bearing link: under the healthy hypothesis, silence longer than the cap has probability 10⁻¹², so observing it is overwhelming evidence the peer is gone. One dimensionless constant, two duties, zero hardcoded timescales.

2.12 -

Deprecated. This page describes the original PKI design and it no longer matches the current network.

For the current design, see the Directory authority specification.

Public key infrastructure specification

Yawning Angel

Claudia Diaz

Ania Piotrowska

David Stainton

Masala

Abstract

to do


Terminology

The following terms are used in this specification.

directory authority system
Refers to PKI schemes used by Mixminion and Tor.

family
Identifier of security domains or entities operating one or more mix nodes in the network. This is used to inform the path selection algorithm.

gateway
A mix node on the edge of the mixnet that is the first hop for messages coming from clients. The gateway authenticates client connections and queues reply messages (SURBs) for retrieval.

layer
The layer value indicates which network topology layer a particular mix node resides in.

mix descriptor
A database record that describes a mixnet server component.

MSL
Maximum segment lifetime, currently set to 120 seconds.

nickname
A component nickname string that must be unique in the consensus document.

PKI
Public key infrastructure.

Conventions used in this document

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC2119.

The “C” style Presentation Language as described in RFC5246 Section 4 is used to represent data structures for additional cryptographic wire protocol commands. KATZMIXWIRE

Introduction

Mixnets are designed with the assumption that a public key infrastructure (PKI) exists and it gives each client the same view of the network. This specification is inspired by the Tor and Mixminion directory authority systems MIXMINIONDIRAUTHTORDIRAUTH whose main features are precisely what we need for our PKI. These are decentralized systems meant to be collectively operated by multiple entities.

The mix network directory authority system (PKI) is essentially a cooperative decentralized database and voting system that is used to produce network consensus documents which mix clients periodically retrieve and use for their path selection algorithm when creating Sphinx packets. These network consensus documents are derived from a voting process between the directory authority servers.

This design prevents mix clients from using only a partial view of the network for their path selection so as to avoid fingerprinting and bridging attacks FINGERPRINTING, BRIDGING, and LOCALVIEW.

The PKI is also used by authority operators to specify network-wide parameters, for example in the Katzenpost decryption mix network KATZMIXNET the Poisson mix strategy is used and, therefore, all clients must use the same lambda parameter for their exponential distribution function when choosing hop delays in the path selection. The mix network directory authority system, aka PKI, SHALL be used to distribute such network-wide parameters in the network consensus document that have an impact on security and performance.

Security properties overview

This directory authority system has the following feature goals and security properties:

  • All directory authority servers must agree with each other on the set of directory authorities.

  • All directory authority servers must agree with each other on the set of mixes.

  • This system is intentionally designed to provide identical network consensus documents to each mix client. This mitigates epistemic attacks against the client path selection algorithm such as fingerprinting and bridge attacks FINGERPRINTINGBRIDGING.

  • This system is NOT byzantine-fault-tolerant, it instead allows for manual intervention upon consensus fault by the directory authority operators. Further, these operators are responsible for expelling bad acting operators from the system.

  • This system enforces the network policies such as mix join policy wherein intentionally closed mixnets will prevent arbitrary hosts from joining the network by authenticating all descriptor signatures with a list of allowed public keys.

  • The directory authority system for a given mix network is essentially the root of all authority.

Differences from Tor and Mixminion directory authority systems

In this document we specify a directory authority system which is different from that of Tor’s and Mixminion’s in a number of ways:

  • The list of valid mixes is expressed in an allow-list. For the time being there is no specified “bandwidth authority” system which verifies the health of mixes (Further research required in this area).

  • There’s no non-directory channel to inform clients that a node is down, so it will end up being a lot of packet loss, since clients will continue to include the missing node in their path selection until keys published by the node expire and it falls out of the consensus.

  • The schema of the mix descriptors is different from that used in Mixminion and Tor, including a change which allows our mix descriptor to express n Sphinx mix routing public keys in a single mix descriptor whereas in the Tor and Mixminion directory authority systems, n descriptors are used.

  • The serialization format of mix descriptors is different from that used in Mixminion and Tor.

  • The shared random number computation is performed every voting round, and is required for a vote to be accepted by each authority. The shared random number is used to deterministically generate the network topology.

Overview of mix PKI interaction

Each Mix MUST rotate the key pair used for Sphinx packet processing periodically for forward secrecy reasons and to keep the list of seen packet tags short. SPHINX09SPHINXSPEC The Katzenpost mix network uses a fixed interval (epoch), so that key rotations happen simultaneously throughout the network, at predictable times.

Each directory authority server MUST use some time synchronization protocol in order to correctly use this protocol. This directory authority system requires time synchronization to within a few minutes.

Let each epoch be exactly 1200 seconds (20 minutes) in duration, and the 0th Epoch begin at 2017-06-01 00:00 UTC.

To facilitate smooth operation of the network and to allow for delays that span across epoch boundaries, Mixes MUST publish keys to the PKI for at least 3 epochs in advance, unless the mix will be otherwise unavailable in the near future due to planned downtime.

At an epoch boundary, messages encrypted to keys from the previous epoch are accepted for a grace period of 2 minutes.

Thus, at any time, keys for all Mixes for the Nth through N + 2nd epoch will be available, allowing for a maximum round trip (forward message + SURB) delay + transit time of 40 minutes. SURB lifetime is limited to a single epoch because of the key rotation epoch, however this shouldn’t present any usability problems since SURBs are only used for sending ACK messages from the destination Provider to the sender.

PKI protocol schedule

There are two main constraints to authority schedule:

  1. There MUST be enough key material extending into the future so that clients are able to construct Sphinx packets with a forward and reply paths.

  2. All participants should have enough time to participate in the protocol; upload descriptors, vote, generate documents, download documents, establish connections for user traffic.

The epoch duration of 20 minutes is more than adequate for these two constraints.

NOTE: perhaps we should make it shorter? but first let’s do some scaling and bandwidth calculations to see how bad it gets…

Directory authority server schedule

directory authority server interactions are conducted according to the following schedule, where T is the beginning of the current epoch, and P is the length of the epoch period.

  • T - Epoch begins

  • T + P/2 - Vote exchange

  • T + (5/8)*P - Reveal exchange

  • T + (6/8)*P - Tabulation and signature exchange

  • T + (7/8)*P - Publish consensus

Mix schedule

Mix PKI interactions are conducted according to the following schedule, where T is the beginning of the current epoch.

T + P/8 - Deadline for publication of all mixes documents for the next epoch.

T + (7/8)*P - This marks the beginning of the period where mixes perform staggered fetches of the PKI consensus document.

T + (8/9)*P - Start establishing connections to the new set of relevant mixes in advance of the next epoch.

T + P - 1MSL - Start accepting new Sphinx packets encrypted to the next epoch’s keys.

T + P + 1MSL - Stop accepting new Sphinx packets encrypted to the previous epoch’s keys, close connections to peers no longer listed in the PKI documents and erase the list of seen packet tags.

Mix layer changes are controlled by the directory authorities and therefore a mix can be reassigned to a different layer in our stratified topology at any new epoch. Mixes will maintain incoming and outgoing connections to the various nodes until all mix keys have expired, iff the node is still listed anywhere in the current document.

Voting for consensus protocol

In our directory authority protocol, all the actors conduct their behavior according to a common schedule as outlined in section “2.1 PKI Protocol Schedule”. The directory authority servers exchange messages to reach consensus about the network. Other tasks they perform include collecting mix descriptor uploads from each mix for each key rotation epoch, voting, shared random number generation, signature exchange and publishing of the network consensus documents.

Protocol messages

There are only two document types in this protocol:

  • mix_descriptor: A mix descriptor describes a mix.

  • directory: A directory contains a list of descriptors and other information that describe the mix network.

Mix descriptor and directory documents MUST be properly signed.

Mix descriptor and directory signing

Mixes MUST compose mix descriptors which are signed using their private identity key, an ed25519 key. Directories are signed by one or more directory authority servers using their authority key, also an ed25519 key. In all cases, signing is done using JWS RFC7515.

Vote exchange

As described in section “2.1 PKI Protocol Schedule”, the directory authority servers begin the voting process 1/8 of an epoch period after the start of a new epoch. Each authority exchanges vote directory messages with each other.

Authorities archive votes from other authorities and make them available for retrieval. Upon receiving a new vote, the authority examines it for new descriptors and includes any valid descriptors in its view of the network.

Each authority includes in its vote a hashed value committing to a choice of a random number for the vote. See section 4.3 for more details.

3.2.1 Voting wire protocol commands

The Katzenpost wire protocol as described in KATZMIXWIRE is used by authorities to exchange votes. We define additional wire protocol commands for sending votes:

enum {

:   vote(22), vote_status(23),

} Command;

The structures of these commands are defined as follows:

struct {
:   uint64_t epoch_number; opaque public_key[ED25519_KEY_LENGTH];
opaque payload[];

} VoteCommand;

struct {
:   uint8 error_code;

} VoteStatusCommand;

3.2.2 The vote Command

The vote command is used to send a PKI document to a peer authority during the voting period of the PKI schedule.

The payload field contains the signed and serialized PKI document representing the sending authority’s vote. The public_key field contains the public identity key of the sending authority which the receiving authority can use to verify the signature of the payload. The epoch_number field is used by the receiving party to quickly check the epoch for the vote before deserializing the payload.

Each authority MUST include its commit value for the shared random computation in this phase along with its signed vote. This computation is derived from the Tor Shared Random Subsystem, TORSRV.

3.2.3 The vote_status command

The vote_status command is used to reply to a vote command. The error_code field indicates if there was a failure in the receiving of the PKI document.

enum {

:   vote_ok(0), /\* None error condition. */ vote_too_early(1), /*
The Authority should try again later. */ vote_too_late(2), /*
This round of voting was missed. \*/
}

The epoch_number field of the vote struct is compared with the epoch that is currently being voted on. vote_too_early and vote_too_late are replied back to the voter to report that their vote was not accepted.

Reveal exchange

As described in section “2.1 PKI Protocol Schedule”, the directory authority servers exchange the reveal values after they have exchanged votes which contain a commit value. Each authority exchanges reveal messages with each other.

3.3.1 Reveal wire protocol commands

The Katzenpost wire protocol as described in KATZMIXWIRE is used by authorities to exchange reveal values previously committed to in their votes. We define additional wire protocol commands for exchanging reveals:

enum {
:   reveal(25), reveal_status(26),
} Command;

The structures of these commands are defined as follows:

struct {
:   uint64_t epoch_number; opaque public_key[ED25519_KEY_LENGTH];
opaque payload[];

} RevealCommand;

struct {
:   uint8 error_code;

} RevealStatusCommand;

3.3.2 The reveal Command

The reveal command is used to send a reveal value to a peer authority during the reveal period of the PKI schedule.

The payload field contains the signed and serialized reveal value. The public_key field contains the public identity key of the sending authority which the receiving authority can use to verify the signature of the payload. The epoch_number field is used by the receiving party to quickly check the epoch for the reveal before deserializing the payload.

3.3.3 The reveal_status Command

The reveal_status command is used to reply to a reveal command. The error_code field indicates if there was a failure in the receiving of the shared random reveal value.

enum {

:   reveal_ok(8), /* None error condition. */ reveal_too_early(9), 
/* The Authority should try again later. */
reveal_not_authorized(10), /* The Authority was rejected. */
reveal_already_received(11), /* The Authority has already revealed
this round. */ reveal_too_late(12) /* This round of revealing was
missed. */

} Errorcodes;

The epoch_number field of the reveal struct is compared with the epoch that is currently being voted on. The reveal_too_early and reveal_too_late codes are replied back to the authority to report their reveal was not accepted. The status code reveal_not_authorized is used if the authority is rejected. The reveal_already_received is used to report that a valid reveal command was already received for this round.

Cert exchange

The Cert command is the same as a Vote but contains the set of Reveal values as seen by the voting peer. In order to ensure that a misconfigured or malicious authority operator cannot amplify their ability to influence the threshold voting process, after Reveal messages have been exchanged, authorities vote again, including the Reveals seen by them. Authorities may not introduce new MixDescriptors at this phase in the protocol.

Otherwise, a consensus partition can be obtained by withholding Reveal values from a threshold number of peers. In the case of an even-number of authorities, a denial of service by a single authority was observed.

Vote tabulation for consensus computation

The main design constraint of the vote tabulation algorithm is that it MUST be a deterministic process that produces the same result for each directory authority server. This result is known as a network consensus file.

A network consensus file is a well formed directory struct where the status field is set to consensus and contains 0 or more descriptors, the mix directory is signed by 0 or more directory authority servers. If signed by the full voting group then this is called a fully signed consensus.

  1. Validate each vote directory:
  • that the liveness fields correspond to the following epoch

  • status is vote

  • version number matches ours

  1. Compute a consensus directory:

Here we include a modified section from the Mixminion PKI spec MIXMINIONDIRAUTH:

For each distinct mix identity in any vote directory:

  • If there are multiple nicknames for a given identity, do not include any descriptors for that identity.

  • If half or fewer of the votes include the identity, do not include any descriptors for the identity. This also guarantees that there will be only one identity per nickname.

  • If we are including the identity, then for each distinct descriptor that appears in any vote directory:

    • Do not include the descriptor if it will have expired on the date the directory will be published.

    • Do not include the descriptor if it is superseded by other descriptors for this identity.

    • Do not include the descriptor if it not valid in the next epoch.

    • Otherwise, include the descriptor.

  • Sort the list of descriptors by the signature field so that creation of the consensus is reproducible.

  • Set directory status field to consensus.

  1. Compute a shared random number from the values revealed in the “Reveal” step. Authorities whose reveal value does not verify their commit value MUST be excluded from the consensus round. Authorities ensure that their peers MUST participate in commit-and-reveal, and MUST use correct Reveal values obtained from other peers as part of the “Cert” exchange.

  2. Generate or update the network topology using the shared random number as a seed to a deterministic random number generator that determines the order that new mixes are placed into the topology.

Signature collection

Each authority signs their view of consensus, and exchanges detached Signatures with each other. Upon receiving each Signature it is added to the signatures on the Consensus if it validates the Consensus. The authority SHOULD warn the administrator if network partition is detected.

If there is disagreement about the consensus directory, each authority collects signatures from only the servers which it agrees with about the final consensus.

// TODO: consider exchanging peers votes amongst authorities (or hashes thereof) to // ensure that an authority has distributed one and only unique vote amongst its peers.

Publication

If the consensus is signed by a majority of members of the voting group then it’s a valid consensus and it is published.

PKI protocol data structures

Mix descriptor format

Note that there is no signature field. This is because mix descriptors are serialized and signed using JWS. The IdentityKey field is a public ed25519 key. The MixKeys field is a map from epoch to public X25519 keys which is what the Sphinx packet format uses.

{
"Version": 0,
"Name": "",
"Family": "",
"Email": "",
"AltContactInfo":"",
"IdentityKey": "",
"LinkKey":"",
"MixKeys": {
"Epoch": "EpochPubKey",
},
"Addresses": ["IP:Port"],
"Layer": 0,
"LoadWeight":0,
"AuthenticationType":""
}

Scheduling mix downtime

Mix operators can publish a half empty mix descriptor for future epochs to schedule downtime. The mix descriptor fields that MUST be populated are:

  • Version

  • Name

  • Family

  • Email

  • Layer

  • IdentityKey

  • MixKeys

The map in the field called “MixKeys” should reflect the scheduled downtime for one or more epochs by not have those epochs as keys in the map.

Directory format

{
"Signatures": [],
"Version": 0,
"Status": "vote",
"Lambda" : 0.274,
"MaxDelay" : 30,
"Topology" : [],
"Providers" : [],
}

Shared random value structure

Katzenpost’s shared random value computation is inspired by Tor’s shared random subsystem TORSRV.

Each voting round a commit value is included in the votes sent to other authorities. These are produced as follows:

H = blake2b-256

COMMIT = Uint64(epoch) | H(REVEAL) REVEAL = Uint64(epoch) | H(RN)

After the votes are collected from the voting round, and before signature exchange, the Shared Random Value field of the consensus document is the output of H over the input string calculated as follows:

  1. Validated Reveal commands received including the authorities own reveal are sorted by reveal value in ascending order and appended to the input in format IdentityPublicKeyBytes_n | RevealValue_n

However instead of the identity public key bytes we instead encode the reveal with the blake2b 256 bit hash of the public key bytes.

  1. If a SharedRandomValue for the previous epoch exists, it is appended to the input string, otherwise 32 NUL (x00) bytes are used.
REVEALS = ID_a \| R_a \| ID_b \| R_b \| \... SharedRandomValue =
H("shared-random" | Uint64(epoch) | REVEALS | PREVIOUS_SRV)

PKI wire protocol

The Katzenpost wire protocol as described in KATZMIXWIRE is used by both clients and by directory authority peers. In the following section we describe additional wire protocol commands for publishing mix descriptors, voting and consensus retrieval.

Mix descriptor publication

The following commands are used for publishing mix descriptors and setting mix descriptor status:

enum {
/* Extending the wire protocol Commands. */
post_descriptor(20),
post_descriptor_status(21),
}

The structures of these command are defined as follows:

struct {
uint64_t epoch_number;
opaque payload[];
} PostDescriptor;

struct {
uint8 error_code;
} PostDescriptorStatus;

The post_descriptor command

The post_descriptor command allows mixes to publish their descriptors.

The post_descriptor_status command

The post_descriptor_status command is sent in response to a post_descriptor command, and uses the following error codes:

enum {
descriptor_ok(0),
descriptor_invalid(1),
descriptor_conflict(2),
descriptor_forbidden(3),
} ErrorCodes;

Voting

The following commands are used by authorities to exchange votes:

enum {
vote(22),
vote_status(23),
get_vote(24),
} Command;

The structures of these commands are defined as follows:

struct {
uint64_t epoch_number;
opaque public_key[ED25519_KEY_LENGTH];
opaque payload[];
} VoteCommand;

struct {
uint8 error_code;
} VoteStatusCommand;

The vote command

The vote command is used to send a PKI document to a peer authority during the voting period of the PKI schedule.

The payload field contains the signed and serialized PKI document representing the sending authority’s vote. The public_key field contains the public identity key of the sending authority which the receiving authority can use to verify the signature of the payload. The epoch_number field is used by the receiving party to quickly check the epoch for the vote before deserializing the payload.

The vote_status command

The vote_status command is used to reply to a vote command. The error_code field indicates if there was a failure in the receiving of the PKI document.

enum {
vote_ok(0),               /* None error condition. */
vote_too_early(1),        /* The Authority should try again later. */
vote_too_late(2),         /* This round of voting was missed. */
vote_not_authorized(3),   /* The voter's key is not authorized. */
vote_not_signed(4),       /* The vote signature verification failed */
vote_malformed(5),        /* The vote payload was invalid */
vote_already_received(6), /* The vote was already received */
vote_not_found(7),        /* The vote was not found */
}

The epoch_number field of the vote struct is compared with the epoch that is currently being voted on. vote_too_early and vote_too_late are replied back to the voter to report that their vote was not accepted.

The get_vote command

The get_vote command is used to request a PKI document (vote) from a peer authority. The epoch field contains the epoch from which to request the vote, and the public_key field contains the public identity key of the authority of the requested vote. A successful query is responded to with a vote command, and queries that fail are responded to with a vote_status command with error_code value of vote_not_found.

Retrieval of consensus

Providers in the Katzenpost mix network system KATZMIXNET may cache validated network consensus files and serve them to clients over the mix network’s link layer wire protocol KATZMIXWIRE. We define additional wire protocol commands for requesting and sending PKI consensus documents:

enum {
/* Extending the wire protocol Commands. */
get_consensus(18),
consensus(19),
} Command;

The structures of these commands are defined as follows:
struct {
uint64_t epoch_number;
} GetConsensusCommand;

struct {
uint8 error_code;
opaque payload[];
} ConsensusCommand;

The get_consensus command

The get_consensus command is a command that is used to retrieve a recent consensus document. If a given get_consensus command contains an Epoch value that is either too big or too small then a reply consensus command is sent with an empty payload. Otherwise if the consensus request is valid then a consensus command containing a recent consensus document is sent in reply.

Initiators MUST terminate the session immediately upon reception of a get_consensus command.

The consensus command

The consensus command is a command that is used to send a recent consensus document. The error_code field indicates if there was a failure in retrieval of the PKI consensus document.

enum {
consensus_ok(0),        /* None error condition and SHOULD be accompanied with
a valid consensus payload. */
consensus_not_found(1), /* The client should try again later. */
consensus_gone(2),      /* The consensus will not be available in the future. */
} ErrorCodes;

The Cert command

The cert command is used to send a PKI document to a peer authority during the voting period of the PKI schedule. It is the same as the vote command, but must contain the set of SharedRandomCommit and SharedRandomReveal values as seen by the authority during the voting process.

The CertStatus command

The cert_status command is the response to a cert command, and is the same as a vote_status response, other than the command identifier. Responses are CertOK, CertTooEarly, CertNotAuthorized, CertNotSigned, CertAlreadyReceived, CertTooLate.

8. Signature exchange

Signatures exchange is the final round of the consensus protocol and consists of the Sig and SigStatus commands.

The sig command

The sig command contains a detached signature from PublicKey of Consensus for Epoch.

The sig_status command

The sig_status command is the response to a sig command. Responses are SigOK, SigNotAuthorized, SigNotSigned, SigTooEarly, SigTooLate, SigAlreadyReceived, and SigInvalid.

Scalability considerations

TODO: notes on scaling, bandwidth usage etc.

Future work

  • Byzantine fault tolerance

  • PQ crypto signatures for all PKI documents: mix descriptors and directories. SPHINCS256 could be used, we already have a golang implementation: https://github.com/Yawning/sphincs256/

  • Make a bandwidth authority system to measure health of the network. Also perform load balancing as described in PEERFLOW?

  • Implement byzantine attack defenses as described in MIRANDA and MIXRELIABLE where mix link performance proofs are recorded and used in a reputation system.

  • Choose a different serialization/schema language?

  • Use a append only Merkle tree instead of this voting protocol.

Anonymity considerations

  • This system is intentionally designed to provide identical network consensus documents to each mix client. This mitigates epistemic attacks against the client path selection algorithm such as fingerprinting and bridge attacks FINGERPRINTING, BRIDGING.

  • If consensus has failed and thus there is more than one consensus file, clients MUST NOT use this compromised consensus and refuse to run.

  • We try to avoid randomizing the topology because doing so splits the anonymity sets on each mix into two. That is, packets belonging to the previous topology versus the current topology are trivially distinguishable. On the other hand if enough mixes fall out of consensus eventually the mixnet will need to be rebalanced to avoid an attacker compromised path selection. One example of this would be the case where the adversary controls the only mix is one layer of the network topology.

Security considerations

  • The directory authority / PKI system for a given mix network is essentially the root of all authority in the system. The PKI controls the contents of the network consensus documents that mix clients download and use to inform their path selection. Therefore if the PKI as a whole becomes compromised then so will the rest of the system in terms of providing the main security properties described as traffic analysis resistance. Therefore a decentralized voting protocol is used so that the system is more resilient when attacked, in accordance with the principle of least authority. SECNOTSEP

  • Short epoch durations make it is more practical to make corrections to network state using the PKI voting rounds.

  • Fewer epoch keys published in advance is a more conservative security policy because it implies reduced exposure to key compromise attacks.

  • A bad-acting directory authority who lies on each vote and votes inconsistently can trivially cause a denial of service for each voting round.

Acknowledgements

We would like to thank Nick Mathewson for answering design questions and thorough design review.

References

BRIDGING

Danezis, G., Syverson, P., “Bridging and Fingerprinting: Epistemic Attacks on Route Selection”, Proceedings of PETS 2008, Leuven, Belgium, July 2008, https://www.freehaven.net/anonbib/cache/danezis-pet2008.pdf.

FINGERPRINTING

Danezis, G., Clayton, R., “Route Finger printing in Anonymous Communications”, https://www.cl.cam.ac.uk/~rnc1/anonroute.pdf.

KATZMIXNET

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Specification”, June 2017, https://katzenpost.network/docs/specs/pdf/mixnet.pdf.

KATZMIXWIRE

Angel, Y., “Katzenpost Mix Network Wire Protocol Specification”, June 2017, https://katzenpost.network/docs/specs/pdf/wire.pdf.

LOCALVIEW

Gogolewski, M., Klonowski, M., Kutylowsky, M., “Local View Attack on Anonymous Communication”, https://cs.pwr.edu.pl/kutylowski/articles/LocalView-WWW.pdf.

MIRANDA

Leibowitz, H., Piotrowska, A., Danezis, G., Herzberg, A., “No right to remain silent: Isolating Malicious Mixes”, 2017, https://eprint.iacr.org/2017/1000.pdf.

MIXMINIONDIRAUTH

Danezis, G., Dingledine, R., Mathewson, N., “Type III (Mixminion) Mix Directory Specification”, December 2005, https://www.mixminion.net/dir-spec.txt.

MIXRELIABLE

Dingledine, R., Freedman, M., Hopwood, D., Molnar, D., “A Reputation System to Increase MIX-Net Reliability”, 2001, Information Hiding, 4th International Workshop, https://www.freehaven.net/anonbib/cache/mix-acc.pdf.

PEERFLOW

Johnson, A., Jansen, R., Segal, A., Syverson, P., “PeerFlow: Secure Load Balancing in Tor”, July 2017, Proceedings on Privacy Enhancing Technologies, https://petsymposium.org/2017/papers/issue2/paper12-2017-2-source.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC5246

Dierks, T. and E. Rescorla, “The Transport Layer Security (TLS) Protocol Version 1.2”, RFC 5246, DOI 10.17487/RFC5246, August 2008, http://www.rfc-editor.org/info/rfc5246.

RFC7515

Jones, M., Bradley, J., Sakimura, N., “JSON Web Signature (JWS)”, May 2015, https://www.rfc-editor.org/info/rfc7515.

SECNOTSEP

Miller, M., Tulloh, B., Shapiro, J., “The Structure of Authority: Why Security Is not a Separable Concer”, http://www.erights.org/talks/no-sep/secnotsep.pdf.

SPHINCS256

Bernstein, D., Hopwood, D., Hulsing, A., Lange, T., Niederhagen, R., Papachristodoulou, L., Schwabe, P., Wilcox O’Hearn, Z., “SPHINCS: practical stateless hash-based signatures”, http://sphincs.cr.yp.to/sphincs-20141001.pdf.

SPHINX09

Danezis, G., Goldberg, I., “Sphinx: A Compact and Provably Secure Mix Format”, DOI 10.1109/SP.2009.15, May 2009, https://cypherpunks.ca/~iang/pubs/Sphinx_Oakland09.pdf.

SPHINXSPEC

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Sphinx Mix Network Cryptographic Packet Format Specification”, July 2017, https://katzenpost.network/docs/specs/pdf/sphinx.pdf.

TORDIRAUTH

“Tor directory protocol, version 3”, https://spec.torproject.org/dir-spec/index.html.

TORSRV

“Tor Shared Random Subsystem Specification”, https://spec.torproject.org/srv-spec/index.html.

2.13 -

The Katzenpost directory authority protocol.

Directory authority specification

Introduction

Katzenpost is a project for building mixnets tuned to different uses1. Each network starts with a fixed group of computers called directory authorities (DAs). We usually call them dirauths. Different parties operate these dirauths, whether or not they trust one another. Their shared configuration defines the network and which nodes may join it.

Namenlos, the first public post-quantum hybrid mixnet, is one Katzenpost deployment2. Operators create other networks by choosing parameters and allowed nodes, then distributing configurations to authorities, other servers, and end users.

The dirauths publish a signed network consensus document, or consensus, for each epoch, a fixed-length time period. Publication requires a simple majority to sign the same document and the network constraints to be met. The consensus gives users the network’s agreed view for that epoch. It supplies node keys, topology, and traffic rates for Katzenpost Sphinx packets. It is the network’s public-key infrastructure (PKI) document.

Nodes submit signed descriptors that announce their identities, addresses, keys, and roles. Authorities accept announcements only from allowed identities and include those that receive enough votes. Applications on one host SHOULD share one local kpclientd daemon. The daemon verifies the consensus before it uses the network. Nodes renew their announcements, and authorities repeat the process for the next epoch.

Namenlos network map

Configured Namenlos nodes and packet paths
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: network
    accTitle: Configured Namenlos nodes and packet paths
    accDescr: Six configured directory authorities publish a consensus with at least four signatures. Users verify it through kpclientd. Packets use one of four gateways and one mix per layer. The mix layers contain two, two, and three mixes. Four service nodes host mixnet services. Courier services use four storage replicas. Each node role has its own icon and each node has its configured name.
    subgraph CONTROL["Directory authorities"]
        direction TB
        CONFIG["Shared authority configuration<br/>and allowed node identities"] --> AUTH["6 directory authorities<span class='node-roster authorities'><span class='node-badge role-authority'>annares</span><span class='node-badge role-authority'>gnunet</span><span class='node-badge role-authority'>luscus</span><span class='node-badge role-authority'>respectmy</span><span class='node-badge role-authority'>wauland</span><span class='node-badge role-authority'>windfall</span></span>"]
        AUTH -->|"4 or more matching signatures"| CONS["<img src='/docs/specs/dirauth/icons/directory.svg' alt='' width='32' height='32'/><br/>Consensus for one epoch<br/>Node keys, topology, and rates"]
    end
    subgraph PATH["Mixnet packet paths"]
        direction TB
        CLIENT["<img src='/docs/specs/dirauth/icons/client.svg' alt='' width='32' height='32'/><br/>User applications<br/>through kpclientd"] -->|"choose one gateway"| GW["4 gateways<span class='node-roster'><span class='node-badge role-gateway'>allmixedup</span><span class='node-badge role-gateway'>gnunet</span><span class='node-badge role-gateway'>haywood</span><span class='node-badge role-gateway'>waulandgateway</span></span>"]
        GW --> L1["Mix layer 1<span class='node-roster'><span class='node-badge role-mix'>windfall</span><span class='node-badge role-mix'>cryptonymity</span></span>"]
        L1 --> L2["Mix layer 2<span class='node-roster'><span class='node-badge role-mix'>omelas</span><span class='node-badge role-mix'>mixy</span></span>"]
        L2 --> L3["Mix layer 3<span class='node-roster'><span class='node-badge role-mix'>oneeyedman</span><span class='node-badge role-mix'>reed</span><span class='node-badge role-mix'>wauland</span></span>"]
        L3 -->|"choose one service node"| SN["4 service nodes<span class='node-roster'><span class='node-badge role-service'>annares</span><span class='node-badge role-service'>lilly</span><span class='node-badge role-service'>waulandservice</span><span class='node-badge role-service'>windfallservice</span></span>"]
        SN -. "courier storage requests" .-> REP["4 storage replicas<span class='node-roster'><span class='node-badge role-replica'>storagereplica0</span><span class='node-badge role-replica'>storagereplica1</span><span class='node-badge role-replica'>storagereplica2</span><span class='node-badge role-replica'>storagereplica3</span></span>"]
    end
    CONS -. "Consensus to client<br/>via gateway" .-> CLIENT
    class CONFIG,CLIENT local
    class AUTH,CONS directory
    class GW,L1,L2,L3,SN,REP link
    linkStyle 1,8 stroke:#f3bd66,stroke-width:2px
    linkStyle 2,3,4,5,6 stroke:#c3abff,stroke-width:2px
    linkStyle 7 stroke:#7acee9,stroke-width:2px
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

This network uses the Namenlos configuration. Six dirauths require four matching signatures. Packet routes use one gateway, one mix per layer, and one service node. Only allowed nodes with enough votes enter the consensus. Prerequisites distinguish configured counts from publication minimums.

History

This protocol continues the original Katzenpost PKI design, described in KATZMIXPKI. That design already used configured authorities, node allow-lists, and a majority-signed consensus. The post-quantum hybrid protocol adds new key schemes, encodings, node roles, and voting phases.

Conventions

The glossary defines shared terms. MUST, MUST NOT, SHOULD, SHOULD NOT, and MAY have the meanings in RFC 2119. Reference tables and requirements appear in linked appendices.

The post-quantum hybrid protocol

The network configuration fixes membership and keys. In each voting round, dirauths agree on a consensus of signed directory data. Participants exchange that data over authenticated connections under the security requirements.

Network membership and node roles

Configured authority keys define which directory authorities a participant trusts. The authorities’ shared allow-lists define which other nodes can enter the consensus.

Node roles

The node roles include gateways, which connect clients to the mixnet. Mixes relay packets through layers, and service nodes host application endpoints. Storage replicas support Pigeonhole. The topology groups mixes into ordered layers. Node keys follow the cryptographic schemes.

Prerequisites

Clients need a usable consensus to reach mixnet services under the network prerequisites. Authorities can publish that consensus only when the network requirements are met.

All parties in a network MUST use the same epoch duration, cryptographic schemes, and packet geometry.

Layers is the configured number of mix layers. MinNodesPerLayer is the minimum configured mix count per layer.

At startup and reload, an authority MUST require at least Layers * MinNodesPerLayer configured mixes, one gateway, and one service node. A fixed topology MUST also meet MinNodesPerLayer in each layer. At signing, every mix layer MUST be non-empty. At least one gateway and one service node MUST remain (R-16-6).

One authority cannot complete voting, which needs at least two contributors. Let A be the number of configured authorities. Publication requires floor(A/2)+1 matching signatures (threshold). Replica requirements depend on the storage service (Pigeonhole).

Namenlos configures six authorities, seven mixes across three layers, four gateways, four service nodes, and four storage replicas. Its fixed layers contain two, two, and three mixes.

Client software and configuration

Applications on one host SHOULD share one local kpclientd daemon through the thin_client interface.

kpclientd fetches the consensus through a configured gateway. It MUST verify the consensus before use. The client configuration supplies gateway pins and the authority verification keys. The Namenlos configurations give example values.

Mixnet services

A mixnet service provides an application endpoint on a service node. Clients use an accepted consensus to find the mixnet service and select a route to it.

A service node lists its mixnet services in its descriptor’s Kaetzchen field. Each entry names a capability and a client endpoint. Clients reach the service through the mixnet without revealing their network addresses to it. Authorities copy Kaetzchen into the consensus under R-5-9. Mixnet services have no separate descriptor.

The courier service forwards requests to Pigeonhole storage replicas. Couriers and replicas can fetch the consensus directly from authorities.

Epochs and timing

Epoch boundaries set deadlines for uploads, votes, and publication. Each consensus names the epoch it describes.

Constants and notation

Each consensus covers one fixed-length time period, called an epoch. The current epoch has a number, denoted N. Each epoch has the same duration, denoted P. T is the instant that epoch N starts. Elapsed time is t = now - T. An authority prepares a document for a voting epoch, denoted V. In a normal round, the voting epoch is the next epoch: V = N+1.

The notation reference gives definitions and Namenlos example values.

Time

The network divides time into epochs. Every participant MUST use the same epoch length and starting point.

Epoch 0 starts at Z = 2017-06-01 00:00:00 UTC. Epoch N starts at Z + N*P. The next epoch starts at Z + (N+1)*P. P ranges from 2 minutes to 7 days, with a default of 1200 seconds. R-9-3 defines how a party selects P. Namenlos leaves EpochDuration unset, which selects the default unless the environment overrides it.

Phase boundaries scale with P. operation defaults indexes operation defaults and fixed time values.

Repeating epoch cycle
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: clock
    accTitle: Repeating epoch cycle
    accDescr: Epoch 0 starts at Z. Each turn lasts P, which is 1200 seconds or 20 minutes in the Namenlos configuration. At each boundary the epoch number increases, the start time advances by P, and elapsed time resets to zero.
    ZERO["Epoch 0 starts at Z<br/>N = 0, T = Z"] --> START(("Start epoch N<br/>at T<br/>t = 0"))
    START --> ELAPSED(("During epoch N<br/>0 <= t < P<br/>P = 20 min<br/>in Namenlos"))
    ELAPSED --> BOUNDARY(("After P seconds<br/>N = N + 1<br/>T = T + P"))
    BOUNDARY -->|"Next epoch<br/>t = 0"| START
    class ZERO,START,ELAPSED,BOUNDARY local
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

An epoch includes its start and excludes its end. The exact end boundary belongs to the next epoch. The clock also gives till, the time until the next epoch. At an absolute instant now at or after Z, the epoch clock is:

Epoch clock
N       = floor((now - Z) / P)
T       = Z + N * P
t       = now - T
till    = P - t

Requirements R-9-1 through R-9-6.

Directory objects and signatures

Nodes announce their keys in descriptors. Authorities exchange signed proposals and publish a signed consensus. Producers MUST use canonical Concise Binary Object Representation (CBOR). Receivers MUST apply the decoding rules.

Descriptors

A descriptor announces one node’s identity, addresses, and keys. The node signs its upload so authorities can verify who sent it.

Mixes, gateways, and service nodes post a MixDescriptor. Storage replicas post a ReplicaDescriptor.

Descriptor fields

A node announces its identity, addresses, keys, and role in the descriptor fields. Its role determines the required fields.

An authority keeps SoftwareVersion and ContactInfo only when [Server].AcceptDescriptorMetadata is true, which defaults to false. Otherwise, it removes both fields after signature verification, before validation, storage, voting, and comparison.

Upload encoding and signatures

Mix servers and storage replicas use different upload structures. Each structure binds the descriptor to the node’s signature.

The upload types are SignedUpload and SignedReplicaUpload. LoopStats contains MixIdentityHash (32 bytes or null), Epoch (uint64), and SegmentRatios (64-byte segment ID to float64). To verify a signature, the authority decodes the upload, sets Signature to null, and re-encodes it canonically. The consensus preserves these descriptor encodings.

Validation stages

Authorities verify an upload before they admit its descriptor. Consumers also parse keys when they use them.

The upload handler parses the identity key and verifies the signature and session binding. Descriptor validation verifies names, addresses, roles, and the current mix key. An upload receiver accepts empty future mix-key values, but their indexes MUST remain within NumMixKeys. Replica uploads require a non-empty envelope-key map with non-empty values. Upload validation imposes no replica-epoch window. Consumers parse other keys when they use them. Authorities verify retained metadata at upload.

Length and parsing alone do not establish that a public key is non-degenerate. The X25519 parser and X448 parser require the scheme’s public-key length. Sphinx rejects an all-zero derived shared secret during packet construction and unwrapping (construction, unwrapping). CTIDH parsing also rejects the base curve E0 and verifies supersingularity.

Requirements R-5-1 through R-5-11.

Votes and voting certificates

A vote is an authority’s signed proposal for the next consensus. It contains node announcements, traffic rates, notices, and a commitment to a random contribution.

A commitment fixes the contribution before its reveal. A reveal opens that commitment so peers can verify the contribution.

A voting certificate carries a tallied document and the matched signed commitment/reveal pairs the sender holds. Peers use these certificates to reconcile contributions before computing the shared random value.

The consensus document

The consensus describes the network for one epoch. Nodes and clients use it to select peers and apply shared settings.

A consensus lists allowed nodes whose descriptors receive enough votes (R-16-2). It records the full configured set only for replicas. A consumer MUST NOT infer other configured node sets from it. Missing nodes can have failed to upload.

Traffic rates

Traffic rates control packet frequency and mix delays. Authorities vote on the rates that the consensus publishes.

A traffic rate measures events per millisecond. Its inverse is the mean waiting time in an exponential distribution. Rates use float64 values. R-16-3 tallies five rates. R-16-8 derives LambdaG. The mixing strategy defines how these rates control traffic. Authority configuration replaces zero with 0.00025 for each voted rate and rejects negative values. It does not test finiteness (defaults and validation).

Signed document fields

The consensus stores the network description in one signed body. Votes and voting certificates use the same document structure.

The Document structure defines the signed fields. Document validation verifies them in votes, voting certificates, and the consensus.

Full document validation rejects duplicate identities across Topology, GatewayNodes, and ServiceNodes, but not StorageReplicas. An empty PriorSharedRandom is valid only when GenesisEpoch equals Epoch. Consumer validation differs by fetch path (gateway consensus transfer).

The decoder treats null and absent keys as empty. An encoder MUST preserve the distinctions in the field reference.

Votes supply five rates, descriptors, and notices. Reconciled commit/reveal pairs supply the shared random value (SRV), which seeds automatic topology assignment. Epoch is V. R-18-7 to R-18-9 define genesis and history. LambdaG, geometry hash, scheme, and configured replicas come from local configuration and MUST agree across authorities. Signatures remain outside the body in its certificate envelope. Descriptor nesting follows upload encoding. Commit/reveal map values contain serialized certificate envelopes.

R-6-5 limits mixing delays. SafetyCap is 27632 milliseconds at Mu = 0.001 and 110525 at Mu = 0.00025. Debug.DisableServicePreDelay disables the service-node hold. The authority’s [Notice] table defaults to empty.

Deterministic CBOR

Producers MUST encode equal data as identical bytes. Deterministic CBOR defines the encoding that every participant uses.

Producers MUST encode descriptors, documents, and certificate envelopes with deterministic CBOR.

Requirements R-6-1 through R-6-7.

Keys and schemes

Identity signatures authenticate directory data. Link and Sphinx keys protect different parts of mixnet communication.

Nodes and authorities have identity signing keys and link key encapsulation mechanism (KEM) keys. Mix servers also have Sphinx keys per epoch. Replicas have envelope non-interactive key exchange (NIKE) keys per replica epoch. Sphinx uses NIKE or KEM keys. Every network uses the same replica envelope scheme. Parties MUST configure matching schemes. Signature scheme details give component sizes and platform defaults. The Namenlos profile defines the deployed byte formats.

Certificate envelopes and signing

A certificate envelope holds data and the signatures that authenticate it. Several authorities can sign the same data.

Envelope fields

The envelope separates the payload from its signatures. Authorities can add signatures without changing the payload.

A certificate envelope holds a payload and its signatures. The implementation defines five fields:

  • Version, a uint32 that is 0
  • Expiration, an epoch
  • KeyType, the scheme name
  • Certified, a byte string containing the payload bytes
  • Signatures, a map from signer hash to PublicKeySum256 and Payload

Producers MUST use canonical CBOR and the configured signature scheme name. Receiver decoding and envelope verification define accepted encodings and signature verification. The decoded envelope Version MUST be zero. KeyType MUST be nonempty and forms part of the signed message. The document schema has a separate Version field, “v1”.

Certificate signature input
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: signer
    accTitle: Certificate signature input
    accDescr: Version, expiration, scheme name, and certified payload form the signed message. The envelope stores signatures outside that message.
    META["Version<br/>Expiration<br/>KeyType<br/>Certified: payload bytes"] --> MSG["signed message bytes"]
    MSG --> SIGN["sign with the identity key"]
    SIGN --> SIG["store signature in Signatures"]
    class META,MSG,SIG local
    class SIGN directory
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

Certified contains document CBOR, a raw 40-byte commit/reveal, or one CBOR cert.Signature for sig commands. Descriptor uploads use separate structures.

Signature input

Every signature covers the same four envelope fields. The signature map itself remains outside that input.

The signed message concatenates four fields with no separator and no length prefix:

signed_message = LE_uint32(Version)
              || LE_uint64(Expiration)
              || KeyType, the UTF-8 bytes of the scheme name
              || Certified

Requirements R-7-1 through R-7-7.

Byte identity

Authorities can combine signatures only when they build identical consensus bytes. Shared encoding, ordering, and configuration make this possible.

Four threshold gates and consensus byte identity
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: authority
    accTitle: Four threshold gates and consensus byte identity
    accDescr: With six authorities, require four matching parameter votes, four voting certificates, four surviving commit/reveal pairs, and four valid signatures. Local configuration and history also enter the signed bytes.
    QV{"4 matching parameter<br/>votes"} --> QC{"4 voting certificates"}
    QC --> QR{"4 surviving commit/reveal<br/>pairs"}
    INPUTS["Inputs<br/>Voted and reconciled values<br/>Carried history<br/>Local configuration"]
    QR --> INPUTS
    INPUTS --> BODY["Build the signed body"]
    BODY --> CBOR["Canonical CBOR bytes"]
    CBOR --> MSG["Certificate signing bytes"]
    MSG --> SIG["Signatures over identical bytes"]
    SIG --> TH{"4 valid signatures over<br/>identical bytes"}
    TH --> PUB["<img src='/docs/specs/dirauth/icons/directory.svg' alt='' width='32' height='32'/><br/>Published consensus"]
    class QV,QC,QR,BODY,SIG,TH directory
    class INPUTS,CBOR,MSG,PUB local
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

Namenlos has A = 6. The general threshold is floor(A/2)+1. Document inputs, CBOR, signature input, SRV ordering and wire encoding MUST produce identical bytes. Different configuration or history can prevent signatures from combining.

Requirements R-26-1 through R-26-8.

A successful voting round

Nodes announce their keys for the next epoch. In a successful round, dirauths agree on one signed consensus. Clients fetch it through gateways and verify it before use.

Directory round
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
sequenceDiagram
    %% panel: network
    %% actors: N=other-servers,D=authority,G=gateway,C=client
    accTitle: Directory round
    accDescr: Mixes, service nodes, replicas, and gateways upload signed descriptors. Dirauths compare votes, reveal randomness, and collect majority signatures. Servers fetch the signed consensus. Clients fetch it through gateways and verify it before use. Each role follows its configured fetch schedule.
    autonumber
    box rgb(26,40,48)
        participant N as Mixes<br/>Service nodes<br/>Replicas
    end
    box rgb(49,38,23)
        participant D as Dirauths
    end
    box rgb(26,40,48)
        participant G as Gateway
    end
    box rgb(45,48,54)
        participant C as Client<br/>kpclientd
    end
    loop One successful round
        N->>D: Upload signed<br/>descriptors
        G->>D: Upload signed<br/>descriptor
        D->>D: Compare votes
        D->>D: Reveal randomness
        D->>D: Sign the same<br/>consensus
        D->>D: Publish at majority
        N->>D: Fetch consensus
        D-->>N: Signed consensus
        G->>D: Fetch consensus
        D-->>G: Signed consensus
        C->>G: Fetch consensus
        G-->>C: Signed consensus
        C->>C: Verify consensus
    end

Phases

Each voting round follows a fixed schedule. Different phases collect node announcements, exchange votes, and publish the next consensus.

The authority state machine starts each phase’s sends and computations at its boundary. The diagram uses P = 1200 seconds. Its times are offsets after T. Phase fractions measure elapsed time from T as a share of P.

Authority phases, node uploads and fetches.

Fetch retries follow R-10-9 to R-10-11. The descriptor upload rules are in R-10-3.

Epoch phase schedule
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
sequenceDiagram
    %% panel: clock
    %% actors: N=other-servers,D=authority,G=gateway,C=client
    accTitle: Epoch phase schedule
    accDescr: Node uploads end at 125 seconds during Phase_DESC. Dirauth phases advance at 150-second boundaries. Mixes, gateways, and service nodes fetch at 750 seconds. Couriers, replicas, and clients fetch at 825 seconds. Clients fetch through gateways. Mixes, gateways, and service nodes admit next-epoch peers strictly after 1050 seconds. The next epoch starts at 1200 seconds.
    box rgb(26,40,48)
        participant N as Mixes<br/>Service nodes<br/>Replicas
    end
    box rgb(49,38,23)
        participant D as Dirauths
    end
    box rgb(26,40,48)
        participant G as Gateway
    end
    box rgb(45,48,54)
        participant C as Client<br/>kpclientd
    end
    Note over N,C: 0-150 s: Phase_DESC
    N->>D: Until 125 s:<br/>signed descriptors
    G->>D: Until 125 s:<br/>signed descriptor
    Note over D: 150-300 s:<br/>Phase_VOTE
    D->>D: Send votes
    Note over D: 300-450 s:<br/>Phase_REVEAL
    D->>D: Send reveals
    Note over D: 450-600 s:<br/>Phase_CERT
    D->>D: Tally and send<br/>certificates
    Note over D: 600-750 s:<br/>Phase_SIG
    D->>D: Build and sign<br/>the consensus<br/>Exchange<br/>signatures
    Note over N,C: 750-1050 s: Phase_PUB
    D->>D: Publish N+1<br/>at threshold
    N->>D: Mixes and<br/>service nodes:<br/>fetch N+1<br/>from 750 s
    D-->>N: Consensus N+1
    G->>D: Fetch N+1<br/>from 750 s
    D-->>G: Consensus N+1
    N->>D: Couriers and<br/>replicas:<br/>fetch N+1<br/>from 825 s
    D-->>N: Consensus N+1
    C->>G: Fetch N+1<br/>from 825 s
    G-->>C: Consensus N+1
    Note over N,C: 1050-1200 s: Phase_TAIL
    N->>N: Mixes and<br/>service nodes:<br/>admit N+1 peers<br/>strictly after<br/>1050 s
    G->>G: Admit N+1 peers<br/>strictly after<br/>1050 s
    D->>D: Gone if N+1<br/>is missing
    Note over N,C: 1200 s: Epoch N+1 starts

Each send window starts at its phase boundary and ends according to R-10-1 and R-10-8.

Requirements R-10-1 through R-10-14.

Phase_DESC. Descriptor upload

Nodes MUST attempt descriptor uploads to every configured authority. Retries MAY omit authorities that already accepted that descriptor. Nodes MAY fetch a consensus from any configured authority.

Nodes send signed announcements with post_descriptor or post_replica_descriptor. After upload validation, the authority applies the descriptor storage rules. It compares an existing descriptor before it tests whether it voted or published.

Descriptor storage and replay
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
stateDiagram-v2
    %% panel: authority
    direction TB
    accTitle: Descriptor storage and replay
    accDescr: A dirauth stores one live descriptor per command epoch and node identity after upload validation. The authority persists an accepted upload before retaining its descriptor. Identical canonical descriptors succeed even after voting or publication. A finality race can persist an upload without retaining its descriptor.
    state "No live descriptor" as Empty
    state "Descriptor retained" as Stored
    [*] --> Empty
    Empty --> Stored: No own vote<br/>or consensus:<br/>persist and retain,<br/>DescriptorOk 0
    Empty --> Empty: Own vote or consensus<br/>before or after writing:<br/>DescriptorConflict 2
    Stored --> Stored: Same: DescriptorOk 0<br/>Changed:<br/>DescriptorConflict 2

An authority MUST serialize uploads per node identity across epochs. Different identities MAY proceed concurrently. DescriptorInternalError triggers an uploader retry. A failure to persist the upload is fatal to the authority. DescriptorInvalid, DescriptorForbidden, and DescriptorConflict are final for that authority, as is a strict QUIC pin mismatch (R-24-11). R-14-10 defines durable storage before acknowledgment.

Requirements R-14-1 through R-14-10.

Phase_VOTE, Phase_REVEAL. Commit and reveal

Authorities exchange random contributions in two steps. Each authority commits to a value before it reveals that value.

With RN a 32-byte random value and H = BLAKE2b-256, each commit or reveal is 40 bytes:

Commit and reveal values
RN     = 32 bytes from the random source
REVEAL = BE_uint64(epoch) || H(RN)
COMMIT = BE_uint64(epoch) || H(REVEAL)
Commit and reveal exchange
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
sequenceDiagram
    %% panel: authority
    %% actors: A=authority,B=authority
    accTitle: Commit and reveal exchange
    accDescr: Dirauth 1 sends its vote and commitment to Dirauth 2. During the reveal phase it sends the signed reveal. Dirauth 2 checks the reveal against the stored commitment and returns the relevant status.
    box rgb(49,38,23)
        participant A as Dirauth 1
    end
    box rgb(49,38,23)
        participant B as Dirauth 2
    end
    Note over A,B: Phase_VOTE, from P/8
    A->>B: vote 22, Epoch V, PublicKey<br/>Document with one commit
    B-->>A: vote_status 23, VoteOk 0
    Note over A,B: Phase_REVEAL, from 2/8
    A->>B: reveal 25, PublicKey<br/>Signed 40-byte reveal
    B->>B: Verify reveal<br/>against stored<br/>commit
    B-->>A: reveal_status 26, RevealOk 8
    Note over B: No stored commit:<br/>RevealTooEarly 9<br/>From 3/8:<br/>RevealTooLate 13

R-15-8 prevents an authority from contributing a late commit during the reveal phase. Without this restriction, it could observe other reveals before deciding whether to contribute its own committed value.

Requirements R-15-1 through R-15-8.

Phase_CERT, Phase_SIG. Tabulation

Each authority counts votes for node announcements and traffic settings. Only results with enough matching votes enter the consensus.

The tally compares descriptor and parameter bytes. R-16-3 keeps signed zeros separate and groups NaNs. History comes from the prior consensus, not a vote tally. R-16-6 separates startup provisioning from per-epoch topology usability.

Requirements R-16-1 through R-16-8.

Phase_CERT. Voting certificates

Authorities exchange certificates that summarize the contributions they received. Other authorities verify this evidence before they compute the shared random value.

A voting certificate contains the tallied document and commit/reveal pairs in a signed envelope. Authorities send it between the reveal and signature phases. The receiver verifies voting certificates before it computes the SRV.

Voting certificate exchange
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
sequenceDiagram
    %% panel: authority
    %% actors: A=authority,B=authority
    accTitle: Voting certificate exchange
    accDescr: Dirauth 1 tallies its votes and sends its voting certificate. Dirauth 2 verifies the cited signatures and pairs under the document validation rules, then returns a certificate status.
    box rgb(49,38,23)
        participant A as Dirauth 1
    end
    box rgb(49,38,23)
        participant B as Dirauth 2
    end
    Note over A,B: Phase_CERT, from 3/8
    A->>A: Tally votes<br/>Build full<br/>document
    A->>B: cert 29, Epoch V, PublicKey<br/>Document with every held pair
    B->>B: Verify cited<br/>signatures from<br/>authorized<br/>authorities
    B->>B: Validate reveals<br/>against commits
    B-->>A: cert_status 30, CertOk 14
    Note over B: Validation failure:<br/>CertNotSigned 17<br/>Sender's vote<br/>missing:<br/>CertTooEarly 19<br/>From 4/8:<br/>CertTooLate 15

Document validation treats exactly one commit as a vote and rejects a reveal alongside it. A certificate built from matched commitments and reveals needs at least two pairs to pass validation. The zero-commit receiver case does not inspect reveals. A one-authority network cannot complete this phase. An authority sends no voting certificate if its tally lacks a usable topology or it has exactly one pair. It still advances to the next phase.

Reconciliation compares complete serialized commit and reveal certificate envelopes, after signature verification. Equal 40-byte payloads do not establish envelope equality. Differences in signatures or other envelope bytes can produce a conflict. R-6-1 permits an additional signature during individual-envelope verification. It does not change the equality comparison during reconciliation. The SRV calculation uses the extracted 40-byte reveal, not its envelope.

Requirements R-17-1 through R-17-9.

Phase_SIG. Shared random value and topology

Authorities combine verified random contributions into one shared value. This value controls automatic mix placement and links the round to the previous round.

The authority needs at least a threshold of voting certificates before reconciliation. It needs the same threshold of surviving commit/reveal pairs before it computes the SRV. The epoch in this calculation is the voting epoch V. H is BLAKE2b-256 and PREV is the previous epoch’s SRV or 32 zero bytes. The authority computes the shared random value as follows:

SRV = H( "shared-random"
      || BE_uint64(epoch)
      || identity_hash(1) || reveal(1)
      || ...
      || identity_hash(k) || reveal(k)
      || PREV )

Each reveal is the 40-byte certified payload of that authority’s signed reveal. R-18-2 gives the order of the k pairs.

The Namenlos authority config pins three fixed layers. With gateways configured, document construction requires a fixed Topology. Omitting it reaches a nil topology during LambdaG calculation. The automatic assignment subroutine defines automatic layer placement. An empty resulting layer prevents signing.

Shared random value and automatic topology
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: authority
    accTitle: Shared random value and automatic topology
    accDescr: Hash the domain label, voting epoch, ordered identity and reveal pairs, and previous shared random value. The output seeds the automatic topology draw, which also uses prior placement when available.
    INPUT["Inputs in byte order:<br/>label shared-random<br/>BE_uint64(V)<br/>identity / reveal pairs in R-18-2 order<br/>previous SRV or 32 zero bytes"] --> HASH["BLAKE2b-256"]
    HASH --> SRV["SharedRandomValue:<br/>32 bytes"]
    SRV --> STREAM["ChaCha20:<br/>8-byte zero nonce"]
    STREAM --> DRAW["Automatic topology draw<br/>with prior placement, if held"]
    DRAW --> TOPOLOGY["Topology:<br/>mix layers"]
    class INPUT,HASH,SRV,STREAM,DRAW,TOPOLOGY directory
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

Requirements R-18-1 through R-18-10.

The topology draw and layer assignment define the complete automatic placement algorithms.

Phase_SIG, Phase_PUB. Signatures and publication

Each authority signs the consensus it built. Matching signatures let the authorities publish that document for the network.

Signature receipt and publication
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
sequenceDiagram
    %% panel: network
    %% actors: A=authority,B=authority,N=publisher
    accTitle: Signature receipt and publication
    accDescr: Each dirauth signs its own consensus and sends the signature to every peer. A receiver verifies the envelope before storing the inner signature. At publication it attaches only signatures that authenticate its own consensus, then publishes at threshold.
    box rgb(49,38,23)
        participant A as Dirauth 1
    end
    box rgb(49,38,23)
        participant B as Dirauth 2
    end
    box rgb(26,40,48)
        participant N as Fetching node
    end
    Note over A,B: Phase_SIG, from 4/8
    A->>A: Tally votes<br/>Compute SRV<br/>Build and sign<br/>doc V
    A->>B: sig 27, Epoch V<br/>Signed cert.Signature envelope
    B->>B: Verify envelope<br/>Parse and store<br/>inner signature
    B-->>A: sig_status 28, SigOk 20
    Note over A,B: Every dirauth sends to every peer
    Note over A,B: Phase_PUB, at 5/8
    A->>A: Verify stored<br/>inner signatures<br/>against own<br/>consensus
    A->>A: Attach valid<br/>signatures<br/>At threshold:<br/>publish and<br/>persist doc V
    N->>A: get_consensus 18, Epoch N+1
    A-->>N: consensus 19, ConsensusOk 0

Requirements R-19-1 through R-19-4.

Receiver states, failures, and retention

Receiver state controls message acceptance. Epoch windows limit how long documents and keys remain usable.

The authority state machine

After startup or restart, an authority enters bootstrap to select its voting epoch. Each authority runs the same sequence of voting steps. Timers move the authority from one step to the next. If processing misses a deadline, the next timer fires immediately. Remaining phases run in sequence. If an action panics, the authority recovers and retries that state after one second.

Authority state machine
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
stateDiagram-v2
    %% panel: authority
    accTitle: Authority state machine
    accDescr: Bootstrap selects a voting epoch. Descriptor, vote, reveal, certificate, and signature states advance on timers. Publication succeeds at threshold or returns to bootstrap.
    state "Signatures" as accept_signature
    [*] --> bootstrap: start or<br/>restart
    bootstrap --> accept_desc: t <= P/8, V =<br/>N+1
    bootstrap --> bootstrap: t > P/8, wait<br/>for next epoch
    accept_desc --> accept_vote: 1/8, send vote
    accept_vote --> accept_reveal: 2/8, send<br/>reveal
    accept_reveal --> accept_cert: 3/8, tally and<br/>send cert
    accept_cert --> accept_signature: 4/8, build and<br/>sign consensus
    accept_signature --> accept_desc: 5/8, threshold<br/>reached,<br/>publish
    accept_signature --> bootstrap: 5/8, no<br/>threshold

Requirements R-12-1 through R-12-5.

Acceptance windows and status codes

An authority accepts messages only for the round it is processing. Response codes tell a sender whether to retry or stop.

An authority can publish consensus N during the preceding epoch, N-1. Its scheduled publication time is T - 3*P/8, before epoch N starts. After successful publication, it advances V to N+1 and can accept votes and commits for that voting epoch.

Vote, reveal, cert, and sig handlers use V and authority state to decide acceptance. They do not compare elapsed time. Handlers evaluate phase and duplicate status only for messages at epoch V. Vote, voting certificate, and signature handlers verify the command’s Epoch field. The reveal handler verifies the epoch in the signed payload and ignores the command’s Epoch field.

After building its voting certificate, an authority can still accept a valid vote for the consensus tally until it enters the signature state. Its existing voting certificate does not change. NotFound permits a retry. Gone is final for N+1 and past epochs. A courier also retries Gone for its current epoch.

Requirements R-13-1 through R-13-3.

Clocks and retention

Authorities manage clock and retention settings outside this protocol. Operators SHOULD keep clocks within a few seconds of UTC. The timing margins depend on delivery time, retries, and successful preceding phases. They are not clock synchronization targets.

A reveal, detached-signature envelope, or commit for N+1 passes expiration verification only through the receiver’s epoch N. A document, vote, or voting certificate for N remains unexpired through epoch N+4. Other validation rules still apply.

The replica clock gives RE = floor((now - Z) / 604800 seconds), independently of P. A client MAY adjust its clock from the gateway handshake.

Independent epoch and key lifetimes
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: clock
    accTitle: Independent epoch and key lifetimes
    accDescr: Mixnet epochs have length P. Mix servers retain keys N-1 through N+3 and publish N+1 through N+3. Replica epochs always last seven days. Shared-random history rotates every 504 mixnet epochs, except initialization takes precedence.
    subgraph M["<img src='/docs/specs/dirauth/icons/mix.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/gateway.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/service.svg' alt='' width='32' height='32'/><br/>Mixes, gateways, and service nodes<br/>Mix keys: epoch length P"]
        direction TB
        MK["Retain mix keys N-1 through N+3"]
        MK --> USE["Unwrap with N-1, N, and N+1"]
        USE --> ADV["Advertise N+1 through N+3"]
    end
    subgraph R["<img src='/docs/specs/dirauth/icons/replica.svg' alt='' width='32' height='32'/><br/>Replica clock: 7 days"]
        RK["Publish RE and RE+1,<br/>plus RE-1 while retained"]
        RK --> DEL["Older key deletion:<br/>3-hour grace"]
    end
    subgraph H["<img src='/docs/specs/dirauth/icons/authority.svg' alt='' width='32' height='32'/><br/>Dirauth shared-random history"]
        INIT["Initialize at genesis or empty history"]
        INIT --> ROT["Otherwise rotate every 504 epochs"]
    end
    M ~~~ R ~~~ H
    class MK,USE,ADV packet
    class RK,DEL local
    class INIT,ROT directory
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

504 epochs equal seven days only at P = 1200 seconds. Replica epochs do not scale with P.

Requirements R-11-1 through R-11-6.

Connections and messages

Directory commands travel over encrypted links. Each connection also applies peer authorization and resource limits.

Transport layers

Directory commands carry signed CBOR objects directly over PQ Noise, outside Sphinx packets. The direct consensus reply gives the directory encoding and link records. PQ Noise protects each connection over TCP or QUIC.

Descriptor map keys and URL schemes select transports and address protocols. The mix server’s address conversion places tcp:// IPv4 addresses under tcp4 and tcp:// IPv6 addresses under tcp6.

Mix-server dialing selects map keys tcp4, tcp6, and quic (transport selectors). A tcp entry alone cannot provide a mix-server destination. Replicas instead preserve the lowercased URL scheme as the descriptor map key (replica conversion). Their outgoing connections use ClientTransports, which includes tcp (replica dialing). Upload validation accepts more URL schemes than mix servers publish (R-5-6).

Authorities use configured address lists, not descriptors. Their listeners accept tcp:// and quic:// URLs only (listeners). Mixes, gateways, and service nodes MUST advertise a reachable tcp4 or tcp6 entry. Replicas MUST advertise a reachable tcp entry. Authorities MUST advertise a reachable tcp:// endpoint. A dialer uses QUIC only with the peer’s pinned QUIC key hash (QUIC transport).

PQ Noise carries commands over each transport. An authority PKI session carries one command and one reply unless configuration enables persistent peer connections (R-22-15). kpclientd uses a persistent gateway session for packets, replies, and consensus retrieval (connection loop).

An authority MUST accept only commands allowed for the sender’s role. It MUST drop others without reply (R-23-4).

Wire protocol

A command carries one request or response. PQ Noise encrypts each command and its length before it sends them.

Commands travel over the PQ Noise link: pattern PqXX, ChaChaPoly, BLAKE2b-512, the configured KEM and a one-byte prologue 0x03. The handshake profile defines its four flights. The responder MUST send NoOp as its first transport command. Each command uses two encrypted Noise transport messages in the data-transfer phase. The first encrypts the four-byte big-endian command-ciphertext length. Its tag makes this header 20 bytes. The second encrypts the command with a separate 16-byte tag. The length includes the second tag. Each endpoint MUST rekey the affected direction after both encrypted messages (sender, receiver).

Before encryption, a command has a 6-byte header, command_id (1) || reserved (1, zero) || BE_uint32(body_length), and a body. PublicKey is the sender’s full marshaled identity key. The command reference defines each Payload type.

Six-byte plaintext command header
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: data
    accTitle: Six-byte plaintext command header
    accDescr: Byte zero is command_id. Byte one is zero. Bytes two through five are the unsigned big-endian body length. The declared body follows, then any zero padding.
    CID["Byte 0<br/>command_id: 1 byte"] --> ZERO["Byte 1<br/>reserved: zero"]
    ZERO --> LENGTH["Bytes 2-5<br/>body length: uint32, big-endian"]
    LENGTH --> BODY["Body: the declared number of bytes"]
    BODY --> PADDING["Optional zero padding"]
    class CID,ZERO,LENGTH,BODY local
    class PADDING local
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

The wire session selects the Noise primitives. Noise uses BLAKE2b-512. The directory’s H is BLAKE2b-256. The command encoders define the bodies and command constants define their IDs.

Direct authority fetchers send empty additional data to identify an unauthenticated client. kpclientd’s gateway handshake carries a generated queue identifier and keeps the session open.

Gateway consensus transfer

Clients fetch the consensus through their gateway connection. The gateway compresses the document and sends it in chunks.

kpclientd MUST fetch the consensus through a configured gateway with get_consensus2. It uses its existing gateway connection. On success, the gateway gzip-compresses the signed consensus envelope and sends consensus2 chunks numbered 0 through ChunkTotal-1. The chunk capacity comes from the connection’s configured packet geometry. An error uses one empty chunk, ChunkNum 0 and ChunkTotal 1, with the consensus status code below (gateway handler).

The client MUST verify chunk order, totals, and sizes before it decompresses the envelope. It MUST verify the authority signature threshold, requested epoch, and local geometry before using the consensus. Chunks carry one document. Gateway commands have separate padding and size bounds from direct authority sessions.

The direct authority fetcher also calls IsDocumentWellFormed before accepting a consensus (fetch validation). kpclientd’s gateway path uses Deserialize to verify the signature threshold and decode the document (Deserialize). It also verifies epoch and geometry, but does not call IsDocumentWellFormed (client verification).

A client reports Gone only when replies from queried authorities make a signing threshold impossible. With fewer Gone replies, it can retry.

Receive size ceiling

A size ceiling bounds the largest directory command a receiver accepts. The default ceiling depends on network size and cryptographic sizes.

R-22-17 uses EstimateConsensusSize. The ceiling bounds the command ciphertext, including its 16-byte tag. The encrypted 20-byte length header is separate. Let sign and sig be the PKI scheme’s public-key and signature sizes. Let link, sphinx and envelope be the public-key sizes of the wire KEM, Sphinx scheme, and replica NIKE. Let nodes, replicas, and authorities be their counts.

mix      = sign + link + 3 * sphinx + 4096
replica  = sign + link + 3 * envelope + 4096
unsigned = 8192 + nodes * mix + replicas * replica
signed   = unsigned + authorities * (sig + 96)
                   + 2 * authorities * (sig + 96 + 40)
ceiling  = min(500000000, max(262144, 2 * signed))

The factor 3 counts per-epoch keys. The 4096 and 8192 allowances cover names, addresses, service data and framing. The 96 covers the signature key hash and framing. The 40 counts a shared-random value. The second authority term includes commit and reveal envelopes in a voting certificate. The final factor 2 provides headroom.

An authority uses its configured counts of mixes, gateways, service nodes, replicas, and authorities. Before its first consensus, a client uses 64 nodes and 16 replicas. A configured MaxConsensusSize above zero replaces the calculated ceiling for that party.

Requirements R-22-1 through R-22-18.

Authentication and authorization

Authorities distinguish configured nodes from unauthenticated clients. Each role has its own permitted commands.

The authority listener authorizes peers by role. Gateway clients use a separate path. Allow-lists map identity hashes to names, adding ReplicaID for replicas and a pinned link key for authorities. Lookup order is mix/gateway/service, authority, then replica. Unauthenticated fetchers, including couriers and replicas, send empty additional data and a fresh random link key. R-23-7 permits unpinned nodes to upload. Their identity signature and session-key binding remain mandatory.

Requirements R-23-1 through R-23-7.

Authority message delivery

Authorities send each voting message to every peer. A retry loop handles temporary failures while the voting schedule continues.

All four message families use one retry loop. Default backoff starts at 10 ms. A 3-second cap applies before 0.2 jitter, so delays can approach 3.6 seconds (calculation). Phase sends use the deadline, with an additional retry cap when PeerRetryMaxAttempts is positive. Bootstrap defaults to 20 retries plus the initial attempt. After a bounded wait, the loop can start an attempt without testing the deadline again. The state machine advances independently of delivery. A peer needs the sender’s vote and commit before it can accept the reveal.

Requirements R-21-1 through R-21-4.

QUIC transport

A node or authority MAY listen on QUIC as well as TCP. PQ Noise authenticates the peer over one QUIC stream. QUIC also requires a pinned TLS key. The dialer MUST compare SHA-256 of the certificate’s SubjectPublicKeyInfo with QUICKeyHash. For nodes, the hash comes from the descriptor. Authorities use configured hashes. Before its first consensus, a client uses its configured gateway hash.

Mixes, service nodes, and replicas rotate TLS keys each epoch. Each key comes from a random Ed25519 seed in DataDir/quic. Gateways with QUIC listeners and authorities keep one long-term key in DataDir/quic-tls.key. The authority’s -g option writes this key and quic-tls.hash. TCP-only authorities neither read nor create the key file.

The QUIC configuration supplies defaults for ALPN, CurvePreferences, AddressValidation, KeepAlivePeriod, KeepAliveJitter, PinMismatch, and CloseLinger.

Requirements R-24-1 through R-24-15.

Connection bounds and operation

One listener carries descriptor uploads, voting, and consensus retrieval. The listener applies connection limits and deadlines before and after the handshake.

An authority MUST refuse connections above a nonzero pool cap before the handshake. Each epoch, it updates the peer pool from consensus and configured authority addresses. A failed refresh keeps the previous set. A panic in one connection handler MUST NOT stop the authority. Persistent authority connections default to off.

Stored state carries a schema version. An authority MUST refuse to start if that version differs from the expected version. It MUST also refuse to start unless its configured authority list contains its own identity and link key.

An operator MAY reload the authorized node set. Every authority MUST reload the same set in the same epoch, or their votes disagree. An authority MUST reject a reload that would fail startup validation (R-16-6) and keep the old set.

Mixnet packet paths

Sphinx packets protect routing information and payloads through successive hops. For a client forward path, Namenlos uses a gateway, three mixes, and a service node. Each relay removes one Sphinx layer and forwards the packet over a separately authenticated PQ Noise link.

The forward path selects these five hops from the consensus. Sphinx protection spans the route. PQ Noise protects only one neighbor connection. Sphinx packets retain their configured length as each hop unwraps them. The Sphinx packet format defines the byte layout.

Security considerations

Clients trust the configured authority keys. A threshold of authorities can sign a network view that clients accept.

  • Any two signing quorums overlap in at least 2*threshold - A authorities. With a simple majority, this minimum is two for even A and one for odd A. Quorum intersection prevents conflicting signed consensuses only if the overlap exceeds the number of dishonest authorities and honest authorities sign once per epoch. At A = 3 or A = 5, one dishonest signer can belong to both quorums. A simple majority cannot guarantee agreement with two dishonest authorities, regardless of A. Crash and omission faults do not create conflicting signed consensuses if honest authorities sign once per epoch.
  • Verified conflicting commits or reveals exclude their signer from the SRV calculation only (R-17-4). A dishonest authority can still send different descriptor sets to different peers and prevent matching consensus bytes.
  • Authorities with different PriorSharedRandom rules can sign different bytes at multiples of 504. Only a group with threshold matching signatures can publish its document.
  • Nodes can authenticate peers with descriptors from N, N-1, and N-2. A superseded link key can remain valid for up to three epochs while the current consensus still lists that node. Removing a node from all authority allow-lists prevents its inclusion in later consensuses. Nodes reject its older descriptors when they apply a current consensus that omits it (authentication). A key listed only in N+1 becomes eligible strictly after 7/8 of N (R-11-2). A peer key that cannot be marshaled MUST fail authentication without stopping the node.
  • A consensus records accepted descriptors, not live node availability. Clients can select a failed node from a cached document and lose packets sent to it. An absent descriptor can mean a missing upload, insufficient votes, or removal from the allow-lists.
  • A mix creates a Sphinx key pair for each epoch and removes expired keys. The key manager maintains this window. Forward secrecy depends on erasing expired private keys, including any copies. Epoch changes also limit the lifetime of the replay cache.
  • A node retains peer connections while the peer remains authorized by the applicable documents (R-11-2). Authentication and permission to send can change at an epoch boundary.
  • Five authorities require three signatures. Six require four. Both configurations can publish with two authorities unavailable, but not three. Quorum overlap determines agreement when authorities sign conflicting documents.
  • Without node link-key pinning (authentication and authorization) anyone could present a node’s identity hash, hold its per-identity slots and keep it from uploading.
  • With fresh authority connections and no retries, each send phase can require A*(A-1) peer handshakes. Retries can increase this count. HandshakeTimeoutSec defaults to 3 seconds. Persistent authority connections can reduce the count (connection bounds and operation).

Appendix A. Formats and validation

Producers MUST encode CBOR objects using CDDL. Command and transport-record encodings MUST follow ABNF. Encoding and validation rules also govern canonical bytes, signatures, authorization, and epoch acceptance.

Key Value Explanation
Fields Descriptors, documents, envelopes, CDDL Field names, types, null, and omission
Byte identity R-6-3, signature input, R-26-2 through R-26-8, conformance vectors Canonical byte identity
Key validation R-5-1 through R-5-4, R-14-2 through R-14-8, R-23-6 Key sizes, parsing, and identity/session binding
Descriptor fields R-5-5 through R-5-11 Names, roles, addresses, services, and metadata
Network configuration prerequisites, R-16-6, R-26-1 Authority configuration and topology minima
Time time through acceptance windows and status codes, R-18-8, R-18-9 Clock, phase, expiry, and retention windows
Wire protocol wire protocol, ABNF Receive ceiling, command fields, and status values
Retries authority message delivery, R-22-18 Retries and operation budgets
QUIC QUIC transport, option limits below QUIC pinning, streams, rotation, and options
Connections connection bounds and operation Connection pools, handlers, identity slots, and first-command deadline

Configuration defaults and limits come from authority configuration and QUIC options.

Key Value Explanation
Mu, LambdaP, LambdaL, LambdaM, LambdaR 0.00025 Zero selects the default. Negative values fail configuration validation. Finiteness is not tested.
Layers / MinNodesPerLayer 3 / 2 Values at most zero select the defaults. Layers above 3 fail. R-16-6 defines provisioning minima.
AcceptDescriptorMetadata / Notice false / empty
AllowHostnameAddresses false Authority URL addresses require IP literals, except onion URLs. Metrics addresses require IP literals too (policy).
PeerRetryBaseDelay / PeerRetryMaxDelay / PeerRetryJitter 10 ms / 3 s / 0.2 Zero selects the defaults. Jitter follows the delay cap.
QUIC ALPN h3 Empty selects the default. Maximum 255 bytes.
QUIC KeepAlivePeriod / KeepAliveJitter 45 s, or 20 s for clients / 0.25 The period MUST be non-negative. Jitter MUST be at least 0 and less than 1.
QUIC CloseLinger / PinMismatch / AddressValidation 30 s / fallback / always 0 / empty / empty select the defaults. Negative linger fails. Other modes follow R-24-11 and R-24-14.
QUIC CurvePreferences TLS defaults Empty selects the defaults. No duplicate or unknown names.

TLS curve names are X25519, X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024, CurveP256, CurveP384, and CurveP521. These local settings do not replace network-wide scheme agreement.

Let M be the positive decompressed limit. Set C = M + 18 + 5 * (floor(M/16384) + 2). The dechunker requires:

  • Sequential chunk numbers starting at zero, with one constant total between 1 and C.
  • A non-empty first payload of size S and total at most ceil(C/S).
  • Every non-final payload exactly S bytes, and the final payload between 1 and S bytes.
  • At most C compressed bytes and M decompressed bytes.

Error responses use a single empty chunk instead. Signature, epoch, and geometry verification follow reassembly.

Appendix B. Existing TLA+ models

Katzenpost includes TLA+ models for authority voting, node state, key retention, and client retransmission.

Key Value Explanation
VotingAuthority VotingAuthority.tla, guide Voting, quorum agreement, equivocation, and chained epochs.
MixNode MixNode.tla, guide Packet processing and scheduler state.
MixKeys MixKeys.tla, guide Key retention, replay state, and restart.
ClientARQ ClientARQ.tla, guide Retransmission and connection changes.

Appendix C. Field and encoding reference

Descriptors and consensus documents carry node identities, network parameters, and cryptographic material. Their encodings determine the signed bytes.

Directory formation overview

Nodes submit descriptors, and authorities reconcile contributions before signing a consensus.

Directory publication
%%{init: {"flowchart":{"diagramPadding":6,"useMaxWidth":false},"gantt":{"useMaxWidth":false},"look":"classic","packet":{"bitWidth":7,"bitsPerRow":48,"rowHeight":48,"useMaxWidth":false},"sequence":{"actorFontSize":14,"actorMargin":24,"diagramMarginX":24,"height":96,"messageFontSize":14,"messageMargin":22,"noteMargin":10,"useMaxWidth":false,"width":128,"wrap":false},"state":{"useMaxWidth":false},"theme":"base","themeCSS":".edgeLabel p { font-family: sans-serif; font-size: 13px; line-height: 1.4; color: #e6edf3; background-color: #34383d; border: 1px solid #c3cbd5; border-radius: 4px; padding: 3px 7px; margin: 0; } .edgeLabel .labelBkg { fill: #34383d; }","themeVariables":{"activationBkgColor":"#48351f","activationBorderColor":"#f3bd66","activeTaskBkgColor":"#48351f","activeTaskBorderColor":"#f3bd66","actorBkg":"#1c3c4c","actorBorder":"#7acee9","actorLineColor":"#7acee9","actorTextColor":"#e6edf3","altSectionBkgColor":"#24282d","background":"#24282d","clusterBkg":"#24282d","clusterBorder":"#c3cbd5","darkMode":true,"edgeLabelBackground":"#24282d","fontFamily":"sans-serif","fontSize":"14px","gridColor":"#59616b","labelBoxBkgColor":"#34383d","labelBoxBorderColor":"#c3cbd5","labelTextColor":"#e6edf3","lineColor":"#c3cbd5","noteBkgColor":"#34383d","noteBorderColor":"#c3cbd5","noteTextColor":"#e6edf3","packet":{"blockFillColor":"#48351f","blockStrokeColor":"#f3bd66","endByteColor":"#c3cbd5","labelColor":"#e6edf3","startByteColor":"#c3cbd5","titleColor":"#e6edf3"},"primaryBorderColor":"#c3cbd5","primaryColor":"#34383d","primaryTextColor":"#e6edf3","secondaryColor":"#34383d","secondaryTextColor":"#e6edf3","sectionBkgColor":"#34383d","sectionBkgColor2":"#1c3c4c","signalColor":"#7acee9","signalTextColor":"#e6edf3","taskBkgColor":"#48351f","taskBorderColor":"#f3bd66","taskTextColor":"#e6edf3","taskTextOutsideColor":"#e6edf3","tertiaryColor":"#24282d","tertiaryTextColor":"#e6edf3","textColor":"#e6edf3","todayLineColor":"#f3bd66"}} }%%
flowchart TB
    %% panel: network
    accTitle: Directory publication
    accDescr: Nodes upload descriptors. Authorities reconcile votes and random contributions, exchange signatures, and serve a threshold-signed consensus.
    N(["<img src='/docs/specs/dirauth/icons/mix.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/gateway.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/service.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/replica.svg' alt='' width='32' height='32'/><br/>Mixes, gateways,<br/>service nodes, and replicas"])
    subgraph D["<img src='/docs/specs/dirauth/icons/authority.svg' alt='' width='32' height='32'/><br/>Dirauths"]
        direction TB
        V["Exchange votes and reveals"] --> C["Reconcile commit and reveal pairs"]
        C --> B["Build the local consensus bytes"]
        B --> S["Exchange signatures"]
        S --> P["Publish at the signing threshold"]
    end
    N -- "Signed descriptors" --> D
    D --> CONS["<img src='/docs/specs/dirauth/icons/directory.svg' alt='' width='32' height='32'/><br/>Signed consensus"]
    CONS -- "get_consensus responses" --> R["<img src='/docs/specs/dirauth/icons/mix.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/gateway.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/service.svg' alt='' width='32' height='32'/><img src='/docs/specs/dirauth/icons/replica.svg' alt='' width='32' height='32'/><br/>Nodes and couriers"]
    class N,R link
    class V,C,B,S,P directory
    class CONS local
classDef directory fill:#48351f,stroke:#f3bd66,color:#ffffff
classDef packet fill:#342b4c,stroke:#c3abff,color:#ffffff
classDef link fill:#1c3c4c,stroke:#7acee9,color:#ffffff
classDef local fill:#34383d,stroke:#c3cbd5,color:#ffffff

The network map includes all configured node roles.

Descriptor fields

Mixes, gateways, and service nodes use MixDescriptor. Storage replicas use ReplicaDescriptor.

Required fields describe producer output. Receiver decoding, descriptor validation, and upload validation define acceptance of missing fields and alternate encodings.

Key Value Explanation
Name text Required in both types.
Epoch uint64 Required in both types.
IdentityKey byte string Required in both types.
LinkKey byte string Required in both types.
MixKeys map from uint64 to byte string Required in MixDescriptor. Maps epochs to keys.
EnvelopeKeys map from uint64 to byte string Required in ReplicaDescriptor. Maps replica epochs to keys.
Addresses map from text to a list of text Required in both types. Maps transports to addresses. Replicas cannot advertise onion addresses.
Kaetzchen map from text to a map from text to any MixDescriptor, null when unset. Service nodes only (R-5-9).
KaetzchenAdvertizedData map from text to a map from text to any MixDescriptor, null when unset.
IsGatewayNode boolean Required in MixDescriptor.
IsServiceNode boolean Required in MixDescriptor.
LoadWeight uint8 Required in MixDescriptor. Reserved.
AuthenticationType text Required in MixDescriptor. Gateways use “tofu”, other nodes use empty text.
Version text MixDescriptor only. The standard producer emits empty text. Receivers also accept other text, including “v0”. ReplicaDescriptor omits this field.
ReplicaID uint8 Required in ReplicaDescriptor.
SoftwareVersion text Both types, omitted when empty. Retained only under AcceptDescriptorMetadata (R-5-11).
ContactInfo text Both types, omitted when empty. Retained only under AcceptDescriptorMetadata (R-5-11).
QUICKeyHash byte string Both types, omitted when empty. Zero to three 32-byte hashes (QUIC transport).

Traffic rates

Consensus traffic rates control packet delays and transmission frequency.

Key Value Explanation
Mu 0.001 Per-hop delay rate.
LambdaP 0.001 Client send rate, with drop decoys when its queue is empty.
LambdaL 0.0005 Client loop decoy rate.
LambdaM 0.0005 Mix loop decoy rate.
LambdaR 0.02 Courier and replica decoy rate.
LambdaG derived (R-16-8) Gateway loop decoy rate.

Signed document fields

The document body contains the topology, traffic rates, and signed directory contributions.

Key Value Explanation
Epoch unsigned integer Required.
GenesisEpoch unsigned integer Required, nonzero.
Mu, LambdaP, LambdaL, LambdaM, LambdaR float Required.
LambdaG float Required.
Topology array of arrays of byte strings Required. One entry per layer, mixes only. An empty layer is null, valid only in a vote.
GatewayNodes, ServiceNodes array of byte strings Required, [] when empty.
StorageReplicas array of descriptor maps Required, [] when empty.
ConfiguredReplicaIDs byte string Omitted when empty.
ConfiguredReplicaIdentityKeys array of byte strings Omitted when empty.
SharedRandomCommit map from a 32-byte string to a byte string Consensus: null. Vote: one commit. Voting certificate: each available commit/reveal pair.
SharedRandomReveal map from a 32-byte string to a byte string Consensus and vote: null. Voting certificate: each available commit/reveal pair.
SharedRandomValue byte string Required, 32 bytes. All zero in votes and voting certificates (shared random value and topology).
PriorSharedRandom array of byte strings Required. Two history values, rotated every 504 epochs. [] in a vote without history (shared random value and topology).
SphinxGeometryHash byte string Required. BLAKE2b-256 of canonical Sphinx geometry.
Version text Required, “v1”.
PKISignatureScheme text Required.
MinClientVersion, ClientNotice text Omitted when empty.

Transport addresses

Descriptor address maps select link transports and endpoint URLs.

Key Value Explanation
tcp4 tcp://, Namenlos: every mix, gateway, and service node TCP over IPv4 for mixes, gateways, and service nodes
tcp6 tcp://, Namenlos: some mixes, gateways, and service nodes TCP over IPv6 for mixes, gateways, and service nodes
tcp tcp://, Namenlos: every storage replica TCP for storage replicas. Also a client transport selector
quic quic://, Namenlos: none QUIC over UDP, with a pinned TLS key (QUIC transport)
onion onion://, Namenlos: one gateway gateway endpoint for clients through Tor
ws ws://, Namenlos: none additional client transport selector

Directory commands

Directory peers exchange descriptors, votes, reveals, certificates, and signatures through numbered wire commands.

Key Value Explanation
get_consensus ID 18. BE_uint64(Epoch) Sent by client, mix, gateway, service node, authority. A replica and a courier send it as clients (authentication and authorization)
consensus ID 19. ErrorCode (1) || Payload: consensus certificate envelope on success Sent by authority, gateway
post_descriptor ID 20. BE_uint64(Epoch) || Payload: SignedUpload CBOR Sent by mix, gateway, service node
post_descriptor_status ID 21. ErrorCode (1) Sent by authority
post_replica_descriptor ID 11. BE_uint64(Epoch) || Payload: SignedReplicaUpload CBOR Sent by replica
post_replica_descriptor_status ID 10. ErrorCode (1) Sent by authority
vote, reveal, cert, sig ID 22, 25, 29, 27. BE_uint64(Epoch) || PublicKey || Payload: certificate envelope Sent by authority
vote_status, reveal_status, cert_status, sig_status ID 23, 26, 30, 28. ErrorCode (1) Sent by authority
get_consensus2 ID 32. BE_uint64(Epoch), upstream padded Sent by kpclientd to gateway
consensus2 ID 31. ErrorCode (1) || BE_uint32(ChunkNum) || BE_uint32(ChunkTotal) || Payload, downstream padded Sent by gateway to kpclientd
get_vote ID 24. reserved

Connection limits

Limits bound message sizes, timeouts, connection pools, and concurrent handlers.

Key Value Explanation
PKI message ceiling when not derived 2 MiB Fallback ceiling.
receive chunk 64 KiB Maximum chunk size.
handshake, receive, and send deadlines 3 seconds, 30 seconds, 30 seconds Operation deadlines.
persistent-connection idle 2 minutes Idle timeout.
accept pools by source address: client, peer, loopback 1024 each 0 means unlimited.
per-address cap in the client and peer pools, IPv6 by /64 64 Client and peer pool limit, with IPv6 grouped by /64.
concurrent handlers 64 A client runs only below half of them, and never blocks.
connections per proven identity 8 Per-identity connection limit.
first-command deadline 5 seconds Time to receive the first command.
hostname resolution per lookup 2 seconds A party never resolves an onion address.

Signature schemes

Ed25519 Sphincs+ concatenates an Ed25519 signature and a SPHINCS+ signature. Ed25519 has a 32-byte public key and a 64-byte signature. SPHINCS+ runs at the sphincs-shake-256f parameter set, with a 64-byte public key and a 49856-byte signature (parameter selection, sizes). The hybrid implementation adds the component sizes. A verifier MUST verify both components (verification). On Windows the authority default is Ed25519 alone. A network that mixes platforms MUST configure the same signature scheme explicitly.

Deterministic CBOR

R-6-3 applies these encoding requirements to descriptors, documents, and certificate envelopes:

  • Map keys MUST use the descriptor fields, document fields, and envelope fields. They MUST be sorted by encoded key length first, then bytewise. This is the canonical order of RFC 7049 section 3.9, retained in RFC 8949 section 4.2.6.
  • Integers MUST use their shortest form. All lengths MUST be definite.
  • Floats MUST use the shortest of float16, float32, and float64 that represents them exactly. NaN MUST be 0xf97e00. Infinities MUST use float16.
  • Each field MUST be present, omitted, or null as the field tables specify. A nil map or list encodes as null. An empty map encodes as {}, and an empty list as []. These are distinct byte sequences.

RFC 8949 section 4.2.3 sorts keys bytewise without comparing length first. A library that supports both orders MUST use the length-first order here.

Reply status codes

A response status tells the sender whether its command succeeded or why it failed.

Key Value Explanation
consensus ConsensusOk 0, ConsensusNotFound 1, ConsensusGone 2 Response conditions.
descriptor DescriptorOk 0, DescriptorInvalid 1, DescriptorConflict 2, DescriptorForbidden 3, DescriptorInternalError 4 Response conditions.
vote VoteOk 0, VoteTooEarly 1, VoteTooLate 2, VoteNotAuthorized 3, VoteNotSigned 4, VoteMalformed 5, VoteAlreadyReceived 6, VoteNotFound 7 Response conditions.
reveal RevealOk 8, RevealTooEarly 9, RevealNotAuthorized 10, RevealNotSigned 11, RevealAlreadyReceived 12, RevealTooLate 13 Response conditions.
cert CertOk 14, CertTooLate 15, CertNotAuthorized 16, CertNotSigned 17, CertAlreadyReceived 18, CertTooEarly 19 Response conditions.
sig SigOk 20, SigNotAuthorized 21, SigNotSigned 22, SigTooLate 23, SigTooEarly 24, SigAlreadyReceived 25, SigInvalid 26 Response conditions.

Protocol components

The protocol combines network configuration, voting, signed objects, and authenticated transport.

Key Value Explanation
Configuration constants and notation, prerequisites constants and prerequisites
Roles services, roles, keys, and schemes services, keys, and schemes
Formats descriptors to certificate envelopes and signing descriptors, documents, and envelopes
Clients client software and configuration applications and kpclientd
Time time to clocks and retention epochs, phases, and clocks
Phases the authority state machine to signatures and publication the authority state machine
Transport transport layers to connection bounds and operation delivery, wire, authentication, and QUIC
Properties byte identity, security considerations byte identity and security

Constants and notation

Epoch and quorum parameters set the voting schedule and signature threshold.

Key Value Explanation
A 6 Number of authorities.
N runtime Current epoch number.
T Z + N * P Start time of epoch N.
threshold 4 floor(A/2)+1. Matching votes or valid signatures required.
dissenters 2 floor(A/2)-1. Logging only, without effect on the result.
P 1200 seconds, default Epoch duration. EpochDuration is unset.
epoch 0 2017-06-01 00:00:00 UTC Start of the first epoch.
V N+1 in a healthy round Authority voting epoch.
t 0 to less than P Elapsed time in N. A fraction such as 5/8 means t = 5P/8.
W 150 seconds P/8. Phase width.
buf 5 seconds Authority retry-loop deadline margin, when time permits.
U 125 seconds 5P/48. Descriptor upload cutoff.
F 825 seconds 11P/16. Client, courier, and storage replica fetch time.
H BLAKE2b-256 Hash function.
identity hash 32 bytes H of the marshaled identity public key.
Layers 3 Number of mix layers.
topology mode fixed: 2, 2, 3 Mixes in each layer.
MinNodesPerLayer 1 Startup minimum per layer.
NumMixKeys 3 Sphinx key epochs per descriptor.
Mu 0.001 Per-hop mixing delay rate.
LambdaP 0.001 Client send rate.
LambdaL 0.0005 Client loop rate.
LambdaM 0.0005 Mix loop rate.
LambdaR 0.02 Courier and replica decoy rate.
PKISignatureScheme Ed25519 Sphincs+ Descriptor and directory signatures.
WireKEMScheme KYBER768-X25519 Link key KEM.
SphinxGeometry.NIKEName x25519 Sphinx mix key scheme.
EnvelopeScheme CTIDH1024-X25519 Replica envelope NIKE, fixed for every network.
NrHops 5 Hops per Sphinx path.
UserForwardPayloadLength 2000 bytes Maximum user payload.

Prerequisites

A network’s configuration supplies trusted authorities, allowed nodes, cryptographic schemes, and transport addresses.

Key Value Explanation
Authorities 6: annares, gnunet, luscus, respectmy, wauland, windfall Fixed and known to every party before the first round.
threshold 4 of 6 Each round needs 4 reachable authorities in agreement, or no consensus.
clocks not specified in these configs Operators synchronize clocks under the clock and skew rules.
EpochDuration unset, default 1200 seconds Select P under R-9-3. Runtime overrides can change it.
allow-lists 7 mixes, 4 gateways, 4 service nodes, 4 replicas Authorities MUST hold identical lists and reload them in the same epoch (connection bounds and operation).
PKISignatureScheme Ed25519 Sphincs+ Descriptor and directory signatures (roles, keys, and schemes).
WireKEMScheme KYBER768-X25519 PQ Noise link key KEM.
SphinxGeometry.NIKEName / KEMName x25519 / empty Selects NIKE Sphinx.
SphinxGeometry 5 hops, 3082-byte packets, 2000-byte user payload All geometry fields MUST agree (byte identity).
link protocol PqXX, ChaCha20-Poly1305, BLAKE2b-512, prologue 0x03 Every party MUST use this PQ Noise protocol and the configured wire KEM (wire protocol).
Addresses IPv4 TCP: all nodes and authorities. IPv6 TCP: some. Nodes and authorities MUST publish a reachable TCP address. IPv6-only peers need IPv6 (transport layers).
authority key pins 6 identity and link key pairs per authority Each authority MUST hold every authority’s identity key and pin its link key, including its own (connection bounds and operation).
DataDir annares: /var/lib/katzenpost/authority/annares-pq-authority Authorities MUST store descriptors and documents durably and stop on storage failure (R-14-10).

Mixnet services

Service nodes advertise mixnet services through the Kaetzchen descriptor field.

Key Value Explanation
echo capability echo, endpoint +echo, 4 service nodes Returns the request payload. The ping tool uses it to test a route and measure delay.
courier capability courier, endpoint courier, 3 service nodes Forwards client read and write requests to Pigeonhole storage replicas and returns their replies.

Node roles

Descriptors identify node roles and their published keys.

Key Value Explanation
mix MixDescriptor Listed in Topology layers.
gateway node MixDescriptor with IsGatewayNode Listed in GatewayNodes.
service node MixDescriptor with IsServiceNode Listed in ServiceNodes.
storage replica ReplicaDescriptor Listed in StorageReplicas.
authority none Listed in every configuration.

Key schemes

Parties use identity signatures, link KEMs, Sphinx keys, and replica envelope keys for separate tasks.

Key Value Explanation
PKI signature Ed25519 Sphincs+. Sizes: public key 96 bytes, private key 192 bytes, signature 49920 bytes. signs descriptors, votes, reveals, voting certificates, and the consensus
wire KEM configured, no default. Sizes: by scheme. the KEM of the PQ Noise link key
Sphinx NIKE or KEM configured, no default. Sizes: by scheme. the scheme of a mix key
replica envelope NIKE CTIDH1024-X25519, public key 160 bytes Fixed for every network.

Client software and configuration

The client daemon loads its listeners, gateway pins, and authority keys from client.toml.

Key Value Explanation
thinclient.toml Dial.Unix.Address = @katzenpost Selects the daemon’s socket through [Dial.Unix] or [Dial.Tcp].
client.toml Listen.Unix.Address = @katzenpost Sets kpclientd’s listener, pinned gateways, authority keys, cryptographic schemes, and Sphinx geometry.

Authority phases

Authorities collect descriptors and exchange voting material on the epoch schedule. The times below are fractions of the epoch duration P. Each phase includes its start and excludes its end.

Key Value Explanation
Phase_DESC 0 to before 1/8 Accept descriptors for N+1.
Phase_VOTE 1/8 to before 2/8 Build and send the vote for V.
Phase_REVEAL 2/8 to before 3/8 Send the reveal.
Phase_CERT 3/8 to before 4/8 Consume reveals, tally, and send the voting certificate.
Phase_SIG 4/8 to before 5/8 Verify voting certificates, compute the SRV, tally again, sign, and send the signature.
Phase_PUB 5/8 to before 7/8 Combine signatures, publish N+1, and set V = N+2.
Phase_TAIL 7/8 to before 1 Answer Gone for N+1 if no document is available.

Phases: Mix, gateway, service node

Mixes, gateways, and service nodes upload next-epoch descriptors before they fetch the next consensus.

Key Value Explanation
Mix, gateway, service node 0 Rotate keys and upload for N+1 until U.
Storage replica Until U Upload the replica descriptor.
Mix, gateway, service node 5/8 Fetch N+1.
Replica, courier, client F Fetch N+1.
Mix, gateway, service node After 7/8 Admit N+1 peers.

Clocks and retention

Epoch windows determine key retention, document expiry, and retry timing.

Key Value Explanation
authority behind a peer, for reveal, cert, sig 145 seconds W - buf - delivery
authority behind a peer, for a vote 295 seconds, 445 seconds 2W - buf - delivery to reach the voting certificate, 3W - buf - delivery to reach the consensus
authority ahead of a peer 600 seconds 4W for a vote. Other messages can receive TooEarly. All four families retry under authority message delivery
node behind an authority 25 seconds P/48, from U to P/8
node ahead of an authority 112.5 seconds U minus P/96
mix ahead of every authority, fetching at 5/8 300 seconds 2W with retries
client ahead of its gateway 75 seconds P/16 minus the gateway’s fetch latency

Clocks and retention: authority

Authorities retain voting state and limit retries using separate timing settings.

Key Value Explanation
authority N-3 to N N+1 from 5/8
mix, gateway, service node N-2 to N N+1 from 5/8
replica, courier N-2 to N N+1 from F
client N-1, N N+1 from F

Acceptance windows and status codes

Receivers use the request epoch and local state to select a response status.

Key Value Explanation
descriptor Phase_DESC of N receives DescriptorOk Outside {N-1, N, N+1}: DescriptorInvalid. After vote construction: DescriptorConflict. Byte-identical re-upload: DescriptorOk.
vote 5/8 of N-1 to 4/8 of N receives VoteOk or VoteAlreadyReceived Epoch errors. Accepted duplicate: VoteAlreadyReceived. Closed phase: VoteTooLate.
reveal from the sender’s vote to 3/8 receives RevealOk Epoch errors. Accepted duplicate: RevealAlreadyReceived. Closed phase: RevealTooLate. Missing sender commit: RevealTooEarly.
cert from the sender’s vote to 4/8 receives CertOk Epoch errors. Accepted duplicate: CertAlreadyReceived. Closed phase: CertTooLate. Missing sender vote: CertTooEarly.
sig 5/8 of N-1 to 5/8 of N: SigOk Epoch errors.
GetConsensus(e), e at most N held: ConsensusOk Missing document: ConsensusGone.
GetConsensus(N+1) from 5/8: ConsensusOk Before 5/8: ConsensusNotFound. Missing after 7/8: ConsensusGone.
GetConsensus(e), e at least N+2 ConsensusNotFound No acceptance window.

Commands by role

The authenticated peer role determines which directory commands the receiver accepts.

Key Value Explanation
kpclientd gateway node Commands: get_consensus2
gateway node kpclientd Commands: consensus2
unauthenticated authority client authority Commands: get_consensus
mix, gateway node, service node authority Commands: get_consensus, post_descriptor
storage replica authority Commands: post_replica_descriptor, and get_consensus as a client
courier authority Commands: get_consensus as a client
authority authority Commands: get_consensus, vote, reveal, cert, sig

Appendix D. Requirements

R-s-n identifies requirement n in group R-s. For example, R-6-3 is the third requirement in R-6. The consensus document.

R-5. Descriptors

Nodes publish signed descriptors with identity keys, addresses, and role fields.

Key Value Explanation
R-5-1 node / on build A producer MUST include a non-empty IdentityKey, LinkKey, each MixKeys value, and each EnvelopeKeys value required by its descriptor type. A mix upload MUST include a MixKeys value for the command epoch.
R-5-2 node / on build Each key field MUST be exactly the public key size of its scheme.
R-5-3 node / on build Each key field MUST parse under its scheme.
R-5-4 Sphinx sender or receiver / on key use NIKE Sphinx MUST reject an all-zero derived shared secret. X25519 and X448 parsing alone does not reject small-order points. CTIDH parsing rejects the base curve E0, the all-zero encoding, and non-supersingular curves. Upload verification follows the validation stages.
R-5-5 node / on build, on upload The name MUST contain 1 to 32 bytes. This is a byte limit, not a character count.
R-5-6 node / on build, authority / on upload A descriptor MUST list at least one transport, with no empty address list. Producers MUST use the map keys and URL schemes in transport layers. Upload validation MUST apply AddressShape. It accepts tcp, tcp4, tcp6, ws, and quic URLs if the host component permits separation into host and port. It accepts onion URLs in gateway descriptors only. This syntax rule does not require a numeric port or equality between the map key and URL scheme.
R-5-7 mix / on build, authority / on upload A producer MUST include a mix key for its descriptor epoch and none outside the NumMixKeys window that starts there. An upload receiver MUST select that window from the command epoch, require a nonempty key for that epoch, and reject keys outside that window. It does not compare the descriptor’s Epoch with the command epoch or require nonempty future key values (descriptor validation).
R-5-8 node / on build, on upload A descriptor MUST NOT set both IsGatewayNode and IsServiceNode.
R-5-9 node / on build, on upload Only service nodes MAY carry non-null Kaetzchen. Others MUST NOT supply even an empty map. Each capability MUST have a non-empty name and a parameter map containing endpoint text of 1 to 32 bytes, RecipientIDLength. Capabilities MAY share an endpoint.
R-5-10 storage replica / on build, on upload A replica MUST publish envelope keys for RE and RE+1, plus RE-1 when retained. These are replica epochs, independent of mixnet Epoch (clocks and retention). Upload verification requires a non-empty map with non-empty values, but imposes no replica-epoch window (producer).
R-5-11 authority / on upload, on restore, on encode With AcceptDescriptorMetadata false, an authority MUST remove SoftwareVersion and ContactInfo after signature verification, before validation, in-memory storage, voting, and comparison. The persisted signed upload retains its original bytes. Otherwise, SoftwareVersion MUST contain at most 128 printable ASCII bytes and ContactInfo at most 256, in 0x20..0x7e. Producers MUST omit empty metadata fields when encoding. Invalid retained metadata MUST receive DescriptorInvalid when the ordered upload procedure reach metadata validation.

R-6. The consensus document

Nodes and clients use the consensus to select peers and apply network settings.

Key Value Explanation
R-6-1 authority / on build, on validation Producers MUST use BLAKE2b-256 of the signer’s identity public key as each SharedRandomCommit and SharedRandomReveal map key. Each producer envelope MUST carry a valid signature by that identity. Receivers MUST apply the document-validation algorithm, including its zero-commit and one-commit cases. An additional signature by another identity does not invalidate the required signature (envelope verification).
R-6-2 authority / Phase_PUB A published consensus MUST carry no commits and no reveals.
R-6-3 producer / on encode Descriptors, documents, and certificate envelopes MUST use the deterministic CBOR encoding. Receiver decoding defines acceptance and re-encoding.
R-6-4 authority / on build Detached signatures MUST NOT be part of the signed body.
R-6-5 mix, gateway, service node / on packet handling Before subtracting queue dwell time, forwarding nodes MUST drop packets whose advertised delay exceeds P * NumMixKeys. Mixes and gateways MUST drop packets whose remaining per-hop delay exceeds the limit. With service pre-delay enabled, service nodes MUST apply that limit to the advertised last-hop delay (delay queue). The selected cap MUST be SafetyCap(consensus Mu) when nonzero. Otherwise, it MUST be a positive configured fallback, or the built-in SafetyCap(0.001) of 27632 ms if none is positive. The final limit MUST be min(selected cap, P * NumMixKeys) (selection). Both paths SHOULD warn if fallback or consensus caps differ from the built-in value by more than a factor of 4 (scheduler, service).
R-6-6 consumer / on fetch A consumer MUST treat a SphinxGeometryHash mismatch in a threshold-signed consensus as a failed fetch, not a fatal error.
R-6-7 authority, client / at startup, Phase_CERT, Phase_SIG MinClientVersion MUST be at most 32 bytes and ClientNotice at most 512, both printable ASCII 0x20..0x7e. An authority MUST propose its configured pair and reject invalid startup values. It MUST tally the pair separately from rates. It MUST publish a pair present in at least threshold well-formed votes. Otherwise it MUST omit the notice without preventing consensus. It MUST log malformed vote pairs and exclude them from this tally only. Clients MUST NOT act on either field.

R-7. Certificate envelopes and signing

A certificate envelope binds a payload to one or more identity signatures.

Key Value Explanation
R-7-1 any party / on build A certificate envelope MUST carry Version, Expiration, KeyType, Certified, and Signatures.
R-7-2 any party / on sign, on verify The signed message MUST be the signature-input concatenation, with little-endian integers and no length prefixes.
R-7-3 any party / on verify A verifier MUST accept a signature only while its current epoch is less than Expiration.
R-7-4 authority / on build A document’s Expiration MUST be Epoch + 5.
R-7-5 any party / on build A party MUST verify each signature over the same message before adding it by signer hash to a multi-signed document.
R-7-6 any party / on parse A parser MUST reject a certificate envelope whose decoded Version is not 0. An absent or null Version decodes to 0 under the receiver decoding rules. Producers MUST include Version under R-7-1.
R-7-7 producer, document validator / on build, on validation A producer MUST set document Version to “v1”. Full document validation MUST reject any other value. ParseDocument alone does not enforce this requirement, and kpclientd’s gateway path does not repeat it (gateway consensus transfer).

R-9. Time

Participants use the same epoch clock to select current and next-epoch data.

Key Value Explanation
R-9-1 any party / at startup P MUST be the EpochDuration selected by R-9-3. Epoch 0 starts at 2017-06-01 00:00:00 UTC.
R-9-2 any party / at startup P MUST be a whole number of seconds from 2 minutes to 7 days. A party MUST refuse to start on any other value.
R-9-3 any party / at startup A party MUST set P once per process, before any epoch arithmetic. It MUST use the configured value. Without one, it MUST use the environment value and log a deprecation warning. Without either, it MUST use the default. A party MUST refuse to start if configuration and environment values differ, or if it receives a second, different value.
R-9-4 any party / always All parties in a network MUST use the same P. No document or message carries it.
R-9-5 any party / always The epoch number N, elapsed time t, and remaining time till MUST follow the clock formula. The start instant belongs to the epoch. A time before epoch 0 is an error.
R-9-6 authority / always The PriorSharedRandom rotation period MUST be 504 epochs at every P (one week only at 1200 seconds).

R-10. Phases

The voting phases schedule uploads, authority exchanges, and consensus publication.

Key Value Explanation
R-10-1 authority / every send phase An authority MUST calculate its retry deadline from the time until the phase boundary, treating negative time as zero. It MUST subtract buf only when more than buf remains. This deadline does not cancel in-progress attempts (authority message delivery).
R-10-2 any party / always Phase boundaries MUST use the phase fractions and the acting party’s clock. Each phase includes its start. Bootstrap skips the round only after P/8. Gone and N+1 peer authentication apply strictly after 7/8. The sender upload cutoff U is exclusive. Authorities may accept uploads after U until vote construction (R-10-5). Each timer MUST target its phase boundary.
R-10-3 node / Phase_DESC, before U A node MUST upload its descriptor for N+1 at or after the start of N and before U. A replica MUST retry every second. After an unsuccessful post, a node MUST post again every P/96 while the window is open. A DescriptorConflict from an authority that accepted an earlier attempt counts as acceptance.
R-10-4 authority / Phase_VOTE, at P/8 An authority MUST build its vote for N+1 at P/8 from exactly the descriptors it holds at that instant.
R-10-5 authority / on upload After the live validation pass, an authority MUST apply the ordered upload-storage procedure. It MUST answer DescriptorConflict to a new descriptor for an epoch whose document or own vote it already holds. It MUST first compare an existing descriptor, returning DescriptorOk for the same canonical descriptor bytes and DescriptorConflict for a change.
R-10-6 authority / on receive An authority MUST apply the state and error precedence in message acceptance. New reveals close in accept_cert and accept_signature. New votes and voting certificates close in accept_signature. The sig handler has no state gate. The stored voting epoch controls its epoch comparisons. State-machine transitions normally place these cuts at 3/8, 4/8, and advancement of V at 5/8.
R-10-7 authority / at 3/8, 4/8, 5/8 An authority MUST tally votes at 3/8 for its voting certificate and again at 4/8 for its consensus. It MUST process collected reveals at 3/8, voting certificates at 4/8, and signatures at 5/8. Each action MUST run at the corresponding state-machine wake.
R-10-8 authority / every send phase Each authority MUST start delivery at the corresponding phase wake. Retry-deadline targets are 2/8 for votes, 3/8 for reveals, 4/8 for voting certificates, and 5/8 for signatures. R-10-1 applies the buffer. These targets do not guarantee completion before the boundary.
R-10-9 mix, gateway node, service node / Phase_PUB, from 5/8 A mix, a gateway, or a service node MUST first request doc N+1 at 5/8. It MUST retry every P/16 until it holds the document or it receives Gone. While doc N is missing it MUST fetch every P/96 until it posts its descriptor, and every P/16 after that.
R-10-10 courier, storage replica / Phase_PUB, from F A courier or a replica MUST first request doc N+1 at F, and MUST retry every P/32 until it holds the document or receives Gone. While doc N is missing it MUST fetch every P/32.
R-10-11 client / Phase_PUB, from F A client MUST first request doc N+1 from its gateway at F. It MUST retry every P/16 until it receives the document or Gone. While doc N is missing it MUST request it every P/16, and MUST use doc N-1 if available.
R-10-12 mix, gateway, service node, courier, replica, client / every fetch pass Mixes, gateways, service nodes, couriers, and replicas MUST use min(3 minutes, P/8) for each fetch pass. kpclientd MUST use a separate 30-second timeout per document. Authority bootstrap uses R-12-2’s retry budget.
R-10-13 mix, gateway, service node / epoch boundary At the start of epoch N these nodes MUST retain mix keys N-1 through N+3. They MUST publish N+1 through N+3 in their descriptors. They MUST unwrap with keys N-1, N, and N+1.
R-10-14 client / epoch boundary A client MUST wake at the epoch boundary and adopt doc N+1 there, without refetching a cached document it already verified.

R-11. Clocks and retention

Authorities, nodes, and clients apply separate clock and retention limits.

Key Value Explanation
R-11-1 authority / every wake An authority MUST drop documents older than N-3 at every state-machine wake.
R-11-2 node / on authentication, after 7/8 A node MUST authenticate a peer from documents N, N-1, and N-2, and, strictly after 7/8, from N+1. An incoming peer that only N+1 lists MAY send from that instant. A node MUST evaluate an outgoing link’s send permission again at the epoch boundary.
R-11-3 courier, storage replica / on authentication A courier or replica MUST authenticate peers from documents N-1, N, and N+1.
R-11-4 client / on clock adjustment A client that adjusts its clock MUST record skew = local - responder. It MUST then use local - skew. It MUST NOT apply a skew larger than P/8.
R-11-5 authority / on build A signature, a commit, and a reveal MUST carry Expiration V. A vote, a voting certificate, and a document MUST carry Expiration Epoch + 5.
R-11-6 node, client / always A node MUST keep documents for epochs at or above N-2 and a client at or above N-1.

R-12. The authority state machine

Each authority advances through voting states on the epoch schedule.

Key Value Explanation
R-12-1 authority / always The authority MUST implement the bootstrap, descriptor, vote, reveal, certificate, and signature acceptance states. The state labels identify the reference transitions.
R-12-2 authority / bootstrap For each missing document N-1 and N, an authority MUST start a background fetch with a 2-minute retry budget. The budget does not cancel an in-progress attempt. It MUST decide V by R-12-4 without waiting for those fetches.
R-12-3 authority / Phase_PUB, at 5/8 At 5/8 an authority that holds a threshold-signed document MUST store doc V, set V = V + 1, and wake at P/8 of N+1. An authority that holds none MUST enter bootstrap, set V = N+2, and wake at the boundary.
R-12-4 authority / bootstrap In bootstrap, at t of at most P/8, an authority MUST set V = N+1 and wake at P/8. At t greater than P/8 it MUST stay in bootstrap, set V = N+2, and wake at the boundary.
R-12-5 authority / on restart A restarted authority MUST start in bootstrap and attempt restoration for N-1, N, and N+1. For each persisted document, it MUST run threshold verification, parse the document, compare its epoch with its storage key, and skip failures. It MUST apply descriptor restoration to persisted signed uploads and use the current AcceptDescriptorMetadata setting. Restoration does not repeat live session binding, QUICKeyHash validation, or the live late-upload cut. A late conflict can reject an upload after persistence, so storage does not prove prior acceptance.

R-13. Acceptance windows and status codes

Message acceptance windows determine the status returned to a sender.

Key Value Explanation
R-13-1 authority / on get_consensus An authority MUST answer GetConsensus under the availability table: Ok when held, NotFound for N+1 through 7/8 and for N+2 on, Gone otherwise.
R-13-2 gateway node / on consensus retrieval A gateway MUST answer ConsensusGone for an epoch below N-1 or an epoch marked as a permanent fetch failure. Permanent failures are an authority’s Gone response, a Sphinx geometry mismatch, or failure to build the document cache. For other epochs, it MUST answer ConsensusOk if it has the document, and ConsensusNotFound otherwise.
R-13-3 authority / on every rejection An authority MUST log every epoch-gated rejection of a peer message with the local epoch, the elapsed time, and the phase. It MUST log a rejected descriptor upload with that upload’s epoch.

R-14. Phase_DESC. Descriptor upload

Authorities accept descriptor uploads from authorized nodes.

Key Value Explanation
R-14-1 authority / Phase_DESC, on upload An authority MUST accept descriptor uploads only for epochs N-1, N, and N+1, and answer DescriptorInvalid otherwise.
R-14-2 authority / Phase_DESC, on upload The descriptor’s identity hash MUST be pinned for the claimed role and the announced name MUST match the pinned name.
R-14-3 authority / Phase_DESC, on upload A replica’s ReplicaID MUST match the pinned identifier.
R-14-4 authority / on upload SignedUpload and SignedReplicaUpload signature verification MUST use the canonical encoding of the decoded upload with Signature set to null (upload validation). This verification MUST succeed. It does not verify the upload signature’s PublicKeySum256.
R-14-5 authority / Phase_DESC, on upload The identity hash presented on the link MUST equal the descriptor’s identity hash.
R-14-6 authority / Phase_DESC, on upload An authority MUST verify the identity key length against the scheme before it parses the key.
R-14-7 authority / on upload After live validation succeeds, an authority MUST compare re-uploads for the same command epoch and identity using canonical descriptor bytes after the metadata policy. It MUST return DescriptorConflict for a changed descriptor and DescriptorOk for an unchanged descriptor. The comparison excludes the upload signature and LoopStats (storage order).
R-14-8 authority / on upload An authority MUST apply the ordered live upload procedure and storage procedure. Core descriptor validation and its caller-selected epoch follow descriptor validation. Key parsing and degeneracy tests at key use follow R-5-4.
R-14-9 authority / always Every authority MUST use the same AcceptDescriptorMetadata setting in an epoch. With mixed settings, a descriptor containing metadata needs threshold authorities to retain it or threshold authorities to remove it. Otherwise, neither form reaches the identical-bytes threshold of R-16-2.
R-14-10 authority / on upload For a new upload, an authority MUST persist the original signed upload before it returns DescriptorOk. Persistence MUST also precede insertion into the in-memory upload set. The authority MUST recheck the vote and document cut before that insertion. A cut reached during persistence produces DescriptorConflict. An unchanged existing descriptor returns DescriptorOk without a new write. Storage failure MUST produce DescriptorInternalError and trigger fatal shutdown (storage algorithm).

R-15. Phase_VOTE, Phase_REVEAL. Commit and reveal

Authorities commit to random values before revealing them.

Key Value Explanation
R-15-1 authority / on build, on receive Producers MUST use the commit and reveal formulas, each with exactly 40 bytes: an 8-byte epoch and a 32-byte digest or value. A reveal receiver MUST reject fewer than 8 certified bytes before reading the epoch. It MUST apply the later 40-byte and commitment-opening requirements in the order specified by message acceptance.
R-15-2 authority / Phase_VOTE, on receive A vote MUST carry the sender’s commit, or be answered VoteMalformed.
R-15-3 authority / on receive When the ordered reveal procedure reach commitment verification, the reveal MUST open the sender’s stored commitment for the same epoch. Failure at that condition MUST produce RevealNotSigned.
R-15-4 authority / Phase_VOTE, Phase_REVEAL, on build Commit and reveal MUST each be signed with the sender’s identity key.
R-15-5 authority / Phase_VOTE, Phase_REVEAL, on send An authority MUST send identical signed commit envelopes and identical signed reveal envelopes to every peer. Conflicting verified envelope bytes exclude the signer from the SRV calculation under R-17-4.
R-15-6 authority / on receive A receiver MUST store a reveal only if it holds the sender’s commitment. If earlier conditions hold and that commitment is missing, it MUST return RevealTooEarly under the ordered reveal procedure.
R-15-7 authority / on receive A vote MUST pass VoteDocument, which omits the usable-topology requirement. It MUST also contain exactly one commitment under the sender’s identity hash and no reveals. Failure at these conditions MUST produce VoteMalformed, after the preceding conditions in message acceptance.
R-15-8 authority / on receive A receiver MUST store a received vote’s commitment only in accept_desc or accept_vote. If it accepts a vote in bootstrap, accept_reveal, or accept_cert, it MUST store the vote without its commitment and log a warning. A later reveal follows message acceptance, including state closure before the commitment-presence test.

R-16. Phase_CERT, Phase_SIG. Tabulation

Authorities tally votes for descriptors and traffic rates.

Key Value Explanation
R-16-1 authority / Phase_CERT, Phase_SIG Tabulation MUST require at least threshold votes for the epoch.
R-16-2 authority / Phase_CERT, Phase_SIG An authority MUST include a descriptor only if its allow-list authorizes it and at least threshold votes contain identical serialized bytes.
R-16-3 authority / Phase_CERT, Phase_SIG An authority MUST adopt a parameter set only with at least threshold votes. It groups the votes by the canonical CBOR map {Mu, LambdaP, LambdaL, LambdaM, LambdaR}, with keys in canonical order and floats as in R-6-3. Two sets group together if and only if each rate is bit-identical to its counterpart, or both of that pair are NaN.
R-16-4 authority / Phase_CERT, Phase_SIG dissenters MUST be floor(A/2)-1, and it MUST NOT decide any output. An authority logs a parameter set that has fewer than threshold votes and at least dissenters votes.
R-16-5 authority / Phase_CERT, Phase_SIG An authority MUST sort included nodes and replicas by identity-key hash.
R-16-6 authority / at startup, on reload, on sign Layers defaults to 3 and MinNodesPerLayer defaults to 2. An authority MUST reject Layers above 3. At startup and reload, the allow-lists MUST contain at least Layers * MinNodesPerLayer mixes, one gateway, and one service node. A fixed topology MUST contain at least MinNodesPerLayer mixes per layer. At signing, a topology MUST have non-empty layers, a gateway, and a service node. It does not require MinNodesPerLayer.
R-16-7 authority / Phase_SIG, on sign An authority MUST refuse to sign a document that is not well formed.
R-16-8 authority / on document construction Each authority MUST derive LambdaG from its configured topology, gateway count, and rates using gateway rate arithmetic. This value is outside the voted parameter key. With gateways present, the tagged document builder requires a fixed topology.

R-17. Phase_CERT. Voting certificates

Authorities verify voting certificates before reconciling random contributions.

Key Value Explanation
R-17-1 authority / Phase_CERT An authority MUST send its voting certificate between the reveal and signature phases. It MUST include only pairs for which it has both the commit and reveal. R-17-6 defines when it sends none.
R-17-2 authority / Phase_SIG, on verify Each commit and reveal cited in a voting certificate MUST be signed by an authorized authority.
R-17-3 authority / Phase_SIG, on verify Each cited reveal MUST open its commit for the matching epoch.
R-17-4 authority / Phase_SIG During ordered reconciliation, two encountered verified current-epoch commit or reveal envelopes with different serialized bytes MUST exclude their signer from the SRV calculation (R-17-8). The comparison includes envelope metadata and signatures, not only Certified. The SRV MUST use the pairs that survive ordered reconciliation.
R-17-5 authority / on receive A voting-certificate upload MUST pass the ordered certificate procedure. These bind its declared key to the connected peer. They compare its document epoch with V and require a nonempty reveal map. They require a stored vote from the sender before full document validation.
R-17-6 authority / Phase_CERT, on send A voting certificate MUST contain the tallied document. An authority MUST send it only if that document passes validation, including the usable-topology requirement. Otherwise, it MUST send none.
R-17-7 authority / Phase_SIG, on verify An authority MUST follow ordered reconciliation, including its empty accumulators, sorted traversal, exclusions, skips, early exits, and final deletion.
R-17-8 authority / Phase_SIG, on verify An encountered entry that fails verification MUST exclude the voting certificate’s author and stop that certificate’s entry loop. An authority MUST exclude a cited authority only for two verified current-epoch commits or reveals that differ under that authority’s own key.
R-17-9 authority / on receive A receiver MUST run FullDocument at the point specified by certificate acceptance. Failure there MUST reject the whole certificate with CertNotSigned and log the sender, epoch, failed rule, and cited authorities. With two or more commitments, this verifies a matching reveal for every commitment. With zero commitments, the validator does not inspect the reveal map.

R-18. Phase_SIG. Shared random value and topology

Authorities derive the shared random value and assign mix layers.

Key Value Explanation
R-18-1 authority / Phase_SIG, at 4/8 The SRV MUST use the shared-random digest.
R-18-2 authority / Phase_SIG, at 4/8 An authority MUST sort reveals by descending certified bytes, breaking ties by ascending identity hash. Each pair contributes the identity hash followed by the reveal.
R-18-3 authority / Phase_SIG, at 4/8 PREV MUST be the previous epoch’s SRV if held, else 32 zero bytes.
R-18-4 authority / Phase_SIG, at 4/8 An authority MUST hold voting certificates from at least threshold authorities before reconciliation. It MUST compute the SRV only if at least threshold commit/reveal pairs remain after reconciliation.
R-18-5 authority / Phase_SIG, at 4/8 Automatic assignment MUST seed its generator with the SRV and follow layer assignment. Fixed assignment MUST preserve configured order and use no random draws.
R-18-6 authority / Phase_SIG, on build PriorSharedRandom MUST be restored from the previous consensus and carried unchanged, except for initialization under R-18-8 and rotation under R-18-9.
R-18-7 authority / Phase_VOTE, at P/8 At vote construction, an authority MUST copy GenesisEpoch from document V-1 if available, or use V otherwise. An older retained document MUST NOT supply this value. It restores shared-random history from V-1 when available. GenesisEpoch remains fixed for the round. Later document construction reads the stored history and prior topology.
R-18-8 authority / Phase_SIG, on build With an empty history or at the genesis epoch, PriorSharedRandom MUST be [srv, srv].
R-18-9 authority / Phase_SIG, on build Initialization under R-18-8 MUST take precedence. Otherwise, at V mod 504 = 0, an authority MUST set PriorSharedRandom to [srv, previous first element]. It MUST rotate once, using the real SRV.
R-18-10 authority / Phase_SIG, on build Topology generation MUST read only those layers of the prior consensus that exist in the configured layer count.

R-19. Phase_SIG, Phase_PUB. Signatures and publication

Authorities exchange consensus signatures and publish when the threshold is met.

Key Value Explanation
R-19-1 authority / Phase_SIG, at 4/8 Each authority MUST sign its own consensus and send the detached signature to every peer.
R-19-2 authority / on receipt, on publication On receipt, an authority MUST follow ReceiveSig. It MUST run verification on the enclosing certificate, then verify for an existing message. For a new message, it MUST decode and store the inner Signature. SigOk acknowledges receipt, not agreement on consensus bytes. At publication, it MUST attach only inner signatures whose verification over its own consensus succeeds (attachment).
R-19-3 authority / Phase_PUB, at 5/8 An authority MUST publish and persist a consensus with at least threshold valid signatures.
R-19-4 client / on fetch A client MUST apply the same threshold verification when it fetches a consensus.

R-21. Authority message delivery

Authorities deliver voting messages through peer connections and retry within phase deadlines.

Key Value Explanation
R-21-1 authority / every send Each candidate address MUST use the configured DialTimeoutSec, 30 seconds by default. The retry deadline limits waits between attempts, but does not cancel an in-progress attempt.
R-21-2 authority / on retry Votes, reveals, voting certificates, and signatures MUST retry transient errors and their matching TooEarly responses under the shared retry policy. A non-TooEarly response MUST end that send.
R-21-3 authority / every send Phase sends MUST use R-10-1’s retry deadline. Bootstrap MUST use R-12-2’s 2-minute retry budget. Both MUST use PeerRetryMaxAttempts when positive, permitting an initial attempt plus that many retries. Without this setting, bootstrap defaults to 20 retries per peer.
R-21-4 authority / on retry Each retry MUST preserve the command’s serialized payload bytes. Commit and reveal envelopes MUST also be byte-identical across peers, including their metadata and signatures. The sender MUST reuse these bytes rather than sign them again.

R-22. Wire protocol

Directory wire commands carry signed protocol objects over PQ Noise.

Key Value Explanation
R-22-1 any party / always Status codes MUST use the reply status reference for their reply-command family. Different families reuse some numeric values.
R-22-2 authority / on receive Epoch comparison MUST follow the ordered message procedure. At that step, an epoch below V MUST produce the command’s TooLate code. An epoch above V MUST produce its TooEarly code. A reveal uses the epoch in its verified signed body. The command Epoch field has no effect on that comparison.
R-22-3 authority / on receive Vote, reveal, cert, and sig handlers MUST require the stored voting epoch V, with the command-specific state conditions in message acceptance. These handlers do not compare elapsed time with phase deadlines. The sig handler has no state gate.
R-22-4 authority / on receive An authority MUST answer NotAuthorized unless a vote, reveal, cert, or sig declares an authorized authority key matching the link-authenticated peer.
R-22-5 authority / on receive The first accepted vote, reveal, certificate, or signature from an identity for V MUST retain its slot. A duplicate MUST produce AlreadyReceived only when the ordered message procedure reach that command’s duplicate test. Earlier authorization, epoch, state, parsing, or verification can produce another status.
R-22-6 authority / on build, on receive At a signature-verification failure, the ordered message procedure MUST return the command’s NotSigned status. For a new sig message, failure to decode the verified body as Signature MUST return SigInvalid. A producer MUST encode that body as canonical CBOR containing PublicKeySum256, a 32-byte value, and Payload, the signature bytes. Canonical order places Payload first. Receiver acceptance follows CBOR decoding.
R-22-7 authority / Phase_DESC, on upload Descriptor uploads MUST be answered with DescriptorInvalid, DescriptorConflict, and DescriptorForbidden as descriptor uploads and authentication and authorization specify.
R-22-8 any party / on build, on parse Every command MUST use the 6-byte header, big-endian integers, and zero padding.
R-22-9 any party / on build, on parse Command bodies MUST follow the command reference, with the full identity public key in vote, reveal, cert, and sig.
R-22-10 any party / on send A sender MUST NOT pad a command on a direct authority PKI link. Gateway get_consensus2 and consensus2 commands MUST use the upstream and downstream padding of their connection, respectively.
R-22-11 authority client / after get_consensus The initiator MUST end a direct authority consensus-fetch session after get_consensus. This does not close kpclientd’s persistent gateway session after get_consensus2.
R-22-12 authority, client / on handshake The responder MUST send NoOp as the first encrypted command. The client MUST reject any other command there.
R-22-13 client / on handshake A client MUST authenticate an authority with AD[:32] = H(identity key) and the pinned static link key. It MUST reject additional data shorter than 32 bytes before it reads that data.
R-22-14 any party / every command Each command MUST use the two encrypted Noise messages: a 20-byte encrypted length header, then the command ciphertext. The header’s four-byte big-endian value MUST include the command’s 16-byte tag. The sender MUST rekey its sending direction after both messages. The receiver MUST rekey its receiving direction after authenticating both messages.
R-22-15 any party / every command An authority PKI session MUST carry one command and one reply on a fresh connection. Configuration may enable persistent authority peer connections. Client-gateway sessions remain persistent and carry multiple commands.
R-22-16 client / on fetch A direct authority fetcher MUST use get_consensus and require a threshold-signed, well-formed document matching the requested epoch. kpclientd MUST use get_consensus2 through its gateway and verify the signature threshold, requested epoch, and local geometry. Its gateway path does not call IsDocumentWellFormed.
R-22-17 any party / on receive An authority PKI session MUST bound received commands by the receive size ceiling. It MUST read the body in chunks of at most 64 KiB.
R-22-18 authority / every send An authority MUST use configured HandshakeTimeoutSec and ResponseTimeoutSec, which default to 3 and 30 seconds. These operation budgets do not inherit the phase retry deadline.

R-23. Authentication and authorization

Session authentication and authorization bind commands to configured identities and roles.

Key Value Explanation
R-23-1 authority / always Allow-lists MUST be keyed by BLAKE2b-256 of the marshaled identity key (roles, keys, and schemes).
R-23-2 authority, node / on handshake An authority MUST treat a peer with zero-length additional data as an unauthenticated client. A node MUST present a 32-byte hash that an allow-list holds. An authority MUST also present its pinned link key.
R-23-3 authority / Phase_DESC, on upload A descriptor upload MUST come from an authenticated node of the descriptor’s kind.
R-23-4 authority / on receive Allowed commands MUST follow commands by role. An authority MUST drop unauthorized commands without reply and close unless this is a persistent authority connection. Authorization follows body parsing, so R-22-17’s ceiling applies before dispatch.
R-23-5 authority / on handshake The responder MUST read one command from every connection that completes the handshake. It MUST read that command before it applies per-command authorization. It MUST drop a connection that sends no command within the first-command deadline.
R-23-6 authority / Phase_DESC, on upload An authority MUST answer DescriptorForbidden unless the descriptor’s LinkKey matches the session’s link key in a constant-time comparison.
R-23-7 authority / on handshake An authority MUST NOT pin a node session unless its link key matches an accepted descriptor for that identity in N-1, N, or N+1. An authority MUST allocate per-identity slots to authorities and pinned nodes only. Unpinned nodes MUST use global and per-address bounds only, permitting first uploads and key rotation. A claimed identity hash alone does not establish pinning.

R-24. QUIC transport

Peers authenticate QUIC endpoints with pinned keys.

Key Value Explanation
R-24-1 node, authority / Phase_DESC, on upload A descriptor MAY carry QUICKeyHash, a concatenation of zero to three 32-byte hashes. A descriptor omits it when empty, so a TCP-only descriptor does not change. An authority MUST answer DescriptorInvalid to any other length. It verifies the length at upload only, after the link-key verification of R-23-6 and before authorization. R-5-11 does not remove the field.
R-24-2 node, authority / at startup A QUIC listener’s TLS key MUST be an Ed25519 key from a random seed kept on disk, and QUICKeyHash MUST be SHA-256 of its SubjectPublicKeyInfo.
R-24-3 any party / on dial A dialer MUST NOT dial a QUIC address of a peer for which it holds no QUIC key hash. It MUST abort a QUIC connection whose certificate SubjectPublicKeyInfo hash matches none of the hashes it holds. It MUST compare them in constant time.
R-24-4 authority / at startup, on dial An authority entry MAY carry one 32-byte QUICKeyHash, written in hex. A dialer MUST pin it, and MUST NOT dial that authority over QUIC without it. An authority that listens on QUIC and whose own entry carries one MUST refuse to start unless its QUIC key file exists and matches it.
R-24-5 gateway node, authority / on build, at startup For common TCP reachability, a gateway MUST advertise a tcp4 or tcp6 map entry with a tcp:// URL. An authority MUST configure tcp:// in its [Server] Addresses and own [[Authorities]] entry. Authority listeners support tcp:// and quic:// only. Gateways MAY advertise onion endpoints for clients. An authority warns about a QUIC gateway descriptor without a TCP or onion alternative. The authority PKI client randomizes addresses, while inter-authority sends use filtered configuration order (client, peer sends).
R-24-6 node, authority / at startup A QUIC listener’s stateless reset key MUST derive from its identity private key through HKDF-SHA256. The derivation MUST use no salt and the label “katzenpost quic stateless reset”. This preserves reset-key continuity across restarts.
R-24-7 any party / every connection A QUIC connection MUST carry one stream: a listener MUST allow one incoming stream and a dialer none, and a second stream MUST be refused.
R-24-8 any party / every connection A QUIC link MUST select a keepalive period per connection. The default is 45 seconds for nodes and authorities, or 20 seconds for clients, multiplied by 1 +/- 0.25. quic-go limits the period to half the idle timeout. QUIC MaxIdleTimeout defaults to 2 minutes. Wire read deadlines can be shorter. The client configures 15 seconds. The handshake MUST use the connect deadline.
R-24-9 mix, service node, storage replica / on build A mix, a service node, or a replica with a QUIC listener MUST present one QUIC key for each epoch. In the descriptor for epoch e it MUST publish the hashes of the keys it holds for e-1, e, and e+1.
R-24-10 gateway node, node / at startup, on build A gateway with a QUIC listener MUST present one long-term QUIC key. It MUST publish that key’s single hash in every descriptor. It MUST refuse to start without that key file. A node without a QUIC listener MUST NOT set QUICKeyHash.
R-24-11 any party / on dial After a pin mismatch a dialer MUST choose one behaviour for the rest of that epoch. Under fallback, the default, it dials that peer at non-QUIC addresses only. Under strict, it dials that peer over pinned QUIC only. A node under strict MUST count the mismatch as final for its upload to that authority in that epoch.
R-24-12 node / on build A node MUST omit QUICKeyHash from its descriptor unless every authority entry in its configuration carries a QUICKeyHash. No authority that drops the field then receives it (R-26-8).
R-24-13 any party / on close A QUIC close MUST close the stream’s send side and allow data to drain before connection closure. This wait MUST end when the peer closes or CloseLinger expires. CloseLinger defaults to 30 seconds, and 0 selects that default. Close does not guarantee delivery.
R-24-14 any party / at startup, every connection All parties in a network MUST offer the same ALPN, which defaults to “h3”. A listener MUST answer a new connection with a Retry unless its configuration says otherwise. AddressValidation takes three values. The default is always. Under-load starts at 128 handshakes in flight. The third value is off.
R-24-15 client, any party / on dial A party whose links go through a proxy MUST NOT dial QUIC. A client MUST dial QUIC only when its PreferedTransports lists quic. It MUST then pin the QUICKeyHash of the gateway’s descriptor, or of its PinnedGateways entry before it holds a consensus.

R-26. Byte identity

Authorities require identical consensus bytes before combining signatures.

Key Value Explanation
R-26-1 authority, client / always An authority’s threshold MUST be floor(A/2)+1 over the authority identity keys deduplicated by hash, its own key included. A client MUST use floor(A/2)+1 over its configured authority list without deduplication, so a list that names one authority twice raises its threshold.
R-26-2 any party / on build, on parse SphinxGeometryHash MUST be BLAKE2b-256 of canonical Geometry CBOR (hash, structure). Its 12 integer fields and text fields NIKEName and KEMName appear in the conformance vectors and the CDDL schema. Field names are map keys. R-6-3’s length-first order applies.
R-26-3 node / on build A SignedUpload MUST be the canonical CBOR of Signature, MixDescriptor, and LoopStats. A SignedReplicaUpload MUST be the canonical CBOR of Signature and ReplicaDescriptor, with no LoopStats. Both MUST be signed with Signature nil. The MixDescriptor value MUST be a byte string that holds the descriptor’s own canonical CBOR, and the ReplicaDescriptor value MUST be an inline map.
R-26-4 authority / Phase_SIG, on build The automatic topology generator MUST be ChaCha20 keyed by the SRV with an 8-byte zero nonce and initial counter zero. The generated topology is in the signed body (byte identity), so a party MUST use the draw algorithm.
R-26-5 any party / on handshake The link handshake MUST be PqXX with the one-byte prologue 0x03.
R-26-6 any party / every frame A session MUST serialize nonce use and message operations separately in each direction. Concurrent operations on one direction can reuse a nonce.
R-26-7 authority / on build ConfiguredReplicaIDs and ConfiguredReplicaIdentityKeys MUST carry the full configured replica set sorted by identity key. ConfiguredReplicaIDs is one byte string of the identifiers in that order, not an array of integers, because its Go type is a byte slice. the consensus document gives the encoding.
R-26-8 authority, operator / always A new descriptor or document field MUST be omitted when empty. It MUST remain empty unless an authority configuration option enables it. That option MUST be false or empty by default. Operators MUST wait until every authority can decode the field before enabling it. Otherwise, an older authority can discard the unknown field and sign different bytes. This applies to retained descriptor metadata and notices. AcceptDescriptorMetadata defaults to false, and the [Notice] table defaults to empty.

Appendix E. Cryptographic configuration

Namenlos uses hybrid identity signatures and post-quantum link keys.

Key Value Explanation
PKISignatureScheme Ed25519 Sphincs+ The identity signature profile defines signatures, raw keys, PEM files, and identity hashes.
WireKEMScheme KYBER768-X25519 The wire profile defines the KEM and keys. The handshake profile defines the four flights.
SphinxGeometry.NIKEName x25519 Sphinx uses 32-byte X25519 public keys.
Replica envelope NIKE CTIDH1024-X25519 This fixed scheme uses the 160-byte hybrid NIKE encoding.

Appendix F. Receiver and construction algorithms

Receivers parse signed inputs, authorize senders, verify epochs, and construct the consensus. A receiver can accept an input that violates a producer requirement.

Receivers MUST evaluate the applicable algorithm’s conditions in order and return its first failure. A later condition does not change an earlier status. Decoded maps have no iteration order unless an operation sorts them.

Go reference implementation

The Katzenpost reference implementation uses the Go programming language. Internal data types and library calls can differ between languages. Compatible implementations MUST produce the same accepted values, canonical bytes, and consensus fields.

The Go CBOR library determines conversion and normalization behavior for received objects. The conversion of binary64 values to int64 can depend on the Go runtime and target architecture. The receiver decoding rules retain those distinctions.

Go’s math.Log computes the natural logarithm for the gateway rate. Other mathematics libraries can round the result differently. A different LambdaG encoding changes the signed consensus bytes. Compatible results require the binary64 evaluation order and logarithm constants.

CBOR decoding

The reference uses github.com/fxamacker/cbor/v2 v2.9.1 with DecOptions{} for these objects (pinned dependency). Encoding with CanonicalEncOptions does not configure the decoder. Each Unmarshal call first verifies the structure and limits of one complete CBOR item. It rejects trailing bytes, then decodes that item into the destination type. If either step returns an error, the caller rejects the result, including any fields set before the error (decoder).

Key Value Explanation
Nesting limit 32 The structural checker starts at depth zero. Each array or map adds one. In a consecutive run of tags, each tag after the first adds one. The first tag does not add a level. The checker examines the content at that depth.
Array limit 131072 elements This applies to each definite-length or indefinite-length array, including arrays in skipped fields.
Map limit 131072 pairs This applies to each definite-length or indefinite-length map, before the decoder collapses duplicate keys.
Byte and text string limits No separate decoder option The available input and the wire message ceiling limit their encoded size. The decoder permits indefinite-length strings.
Canonical form Not required by the decoder The decoder accepts non-minimal integer and length encodings, non-canonical map order, and supported wider floating-point encodings. This does not permit malformed CBOR.
Indefinite lengths Allowed Arrays, maps, byte strings, and text strings can use the indefinite-length form.
Tags Allowed When decoded, tag 0 requires text, tag 1 requires an integer or float, and tags 2 and 3 require bytes. The decoder removes self-described CBOR tags. Other tags around ordinary typed fields decode through to their content after pointer allocation. Untyped values retain unrecognized tags. Only structural validation applies to tags in skipped values.
Unknown struct fields Ignored The decoder skips unmatched text keys, unmatched integer keys that fit int64, and their values. It rejects byte strings, arrays, maps, and other unsupported types as struct field names.
Struct field matching Exact name, then case-insensitive fallback Matching uses the field name or its CBOR tag. For example, the document history field uses PriorSharedRandom.
Duplicate struct fields Retain the first matched field The decoder skips later keys that match the same destination field, including differently capitalized keys. A malformed value in the first occurrence still causes a decoding error.
Duplicate map entries Retain the last decoded entry This applies after conversion of the key to its destination type. The decoder does not return a duplicate-key error. A type error in an earlier entry still causes a decoding error.
Absent fields Unchanged destination value These receivers decode into new objects, so absent fields have their zero value: zero, false, an empty string, or a nil pointer, map, or slice. The later algorithms enforce field presence.
null and undefined Nil, or no change When untagged, they set pointers, maps, slices, and interface values to nil. For scalar values, fixed arrays, and ordinary structs, they leave the destination unchanged without a type error. A new scalar or struct therefore remains zero-valued.
Tagged pointers Allocate before removing tags The decoder allocates and dereferences pointers before it removes tags. An otherwise accepted tag around null or undefined leaves a new ordinary struct pointer allocated, with zero-valued fields.
Scalar map temporaries Retain the preceding decoded value Each map uses separate key and value temporaries. Booleans, integers, floats, and strings reuse their temporary across entries. Each temporary starts at zero. A null or undefined scalar therefore retains the preceding decoded key or value. Other destination types reset between entries.
Empty containers Distinct from nil containers An empty map or array decodes as an allocated empty map or slice. This distinction affects conditions such as Kaetzchen == nil and subsequent canonical encoding.
Text UTF-8 when decoded Decoded text strings, including field names, MUST contain valid UTF-8. The decoder verifies the CBOR structure of values in unknown or duplicate struct fields, but skips their text decoding. The default decoder does not convert byte strings to string fields.
Unsigned integer fields A supported numeric value that fits the destination Unsigned integers, unsigned bignums that fit uint64, and unassigned simple values 0 through 19 or 32 through 255 convert to the destination integer. Negative integers and floats fail. A uint8 field therefore receives only 0 through 255, apart from the null behavior above.
Floating-point fields CBOR integers, floats, and supported numeric conversions Unsigned integers through uint64, negative integers through int64, corresponding bignums within those ranges, and the simple values above convert to the destination float. The decoder permits NaN and positive or negative infinity.
Byte slices Byte strings or arrays of byte values Arrays decode element by element using the uint8 conversion above. Tags 2 and 3 around bytes can also decode their contained bytes into a byte slice or fixed byte array.
Fixed byte arrays Copy, truncate, or zero-fill A byte string or array can decode into [32]byte. The decoder discards extra elements and zero-fills a short value. It does not require an encoded length of 32 for a hash field or hash map key.
Arbitrary parameter scalars Default interface decoding Booleans remain booleans. Positive integers become uint64. Negative integers become int64, or big.Int if necessary. Floats become float64. Bytes become byte slices.
Arbitrary parameter containers Default interface decoding Arrays become interface slices. Maps become maps with interface keys and values. Byte-string map keys use the comparable cbor.ByteString type. Unhashable map keys fail.
Arbitrary parameter tags and simple values Default interface decoding Tags 0 and 1 decode as time values. Tags 2 and 3 decode as bignums. Unrecognized tags decode as cbor.Tag. Unassigned simple values decode as cbor.SimpleValue.

These settings follow the decoder options, struct field rules, map decoding, byte conversion, and structural conditions. The limits apply again when the receiver decodes an embedded byte string as another CBOR object. They do not impose a combined nesting limit across separate decodes of an envelope, its certified payload, and an embedded descriptor.

The producer encodes a MixDescriptor as a byte string containing its CBOR map. The receiver invokes MixDescriptor.UnmarshalBinary on that byte string. The default decoder also accepts a direct CBOR map for this destination type. A ReplicaDescriptor has no UnmarshalBinary method and uses a direct map. Its Unmarshal method does not give it the byte-string conversion used for a mix descriptor. Descriptor methods, replica methods.

Canonical encoding after decoding

Upload verification and descriptor tallying encode decoded values again. Arbitrary mixnet service parameters therefore use these conversions before canonical encoding.

Key Value Explanation
Time tags 0 and 1 Untagged whole Unix seconds Tag 0 parses RFC 3339 text. Tag 1 converts numeric seconds. Both produce a time value. Encoding discards its fractional seconds.
Fractional numeric time Truncate, then normalize Split the binary64 value into whole seconds truncated toward zero and a signed fractional remainder. Multiply the fraction by 1000000000. Truncate that product toward zero for nanoseconds. Normalize negative nanoseconds into the preceding second. Encode the resulting whole seconds.
Time bounds Signed 64-bit integer seconds Integer input outside this range fails. For finite floats, compare whole seconds against binary64 -2^63 and +2^63. Values outside those bounds fail. Conversion at exactly +2^63 depends on the Go implementation. Go 1.26.10 on Linux/amd64 converts it to -2^63.
Zero and nonfinite times CBOR null The zero time is 0001-01-01T00:00:00Z. Tag 1 NaN and either infinity decode to that zero time.
Bignums Shortest integer or bignum Tags 2 and 3 decode to integers. Encode them without a tag when major type 0 or 1 can represent them. Otherwise, encode the shortest bignum magnitude.
Unrecognized tags Tag number and encoded content Preserve the tag number and recursively encode the decoded content.
Simple values Original simple value, or null Preserve unassigned simple values. Undefined decodes to nil and encodes as null.

The time decoder, time encoder, and encoding defaults define these conversions. The map decoder defines scalar reuse. These byte examples use hexadecimal CBOR. The receiver tests verify them against the pinned decoder.

Key Value Explanation
c1f93e00 01 Time 1.5 becomes integer 1.
c1f9b800 20 Time -0.5 becomes integer -1.
c1fbbddb7cdfd9d7bdbb 00 Time -0.0000000001 truncates to zero nanoseconds.
c074303030312d30312d30315430303a30303a30305a f6 The zero time becomes null.
c1f97e00, c1f97c00, c1f9fc00 f6 NaN and either infinity become null.
c24101 01 Bignum 1 becomes integer 1.
d903e8f7 d903e8f6 An unknown tag retains its number. Its undefined content becomes null.
LoopStats: d903e8f6, d9d9f7f6, d903e8f7, d9d9f7f7 a36545706f6368006d5365676d656e74526174696f73f66f4d69784964656e7469747948617368f6 Tagged null or undefined allocates a zero-valued LoopStats. Upload verification uses this map instead of null. Bare f6 or f7 leaves the pointer nil and encodes as f6.
a2054161f64162 or a2054161f74162 a1054162 A map with unsigned integer keys reuses key 5 for null or undefined. The last entry replaces its bytes.
a26161f93c006162f6 a26161f93c006162f93c00 A map with text keys and floating-point values reuses value 1 for null.

Certificate parsing and signature verification

Certificate operations verify the signed payload and its expiration. H(key) is the hash of the serialized identity public key. N is the current local epoch number at verification.

Envelope(raw):
    Decode raw into a new Certificate, using receiver-decoding.
    Require Version == 0.
    Require N < Expiration.
    Require KeyType to be nonempty.
    Require Certified to be nonempty.
    Replace a nil Signatures map with an empty map.
    Return the decoded certificate.

VerifyEnvelope(key, raw):
    c = Envelope(raw).
    For each signature value s in c.Signatures, in unspecified map order:
        If s.PublicKeySum256 == H(key):
            Require len(s.Payload) == key.scheme.SignatureSize.
            Require key.scheme.Verify(key,
                LE32(c.Version) || LE64(c.Expiration) ||
                UTF8(c.KeyType) || c.Certified, s.Payload).
            Return c.Certified.
    Fail because no signature value identifies key.

ParseDocument(raw):
    c = Envelope(raw).
    Require at least one entry in c.Signatures.
    Create a new Document, with an empty detached-signature map.
    For each signature value s in c.Signatures:
        Set document.Signatures[s.PublicKeySum256] = s.
    Decode c.Certified into the document body, using receiver-decoding.
    Return the document.

ParseDocument does not run outer signature verification or document validation. In the reference, it calls GetCertified and GetSignatures separately. Each call decodes the envelope and repeats its validity tests before body decoding (envelope validation). The body excludes the detached Signatures field (document parsing).

Envelope verification does not compare the envelope map key with the inner signature’s PublicKeySum256. It searches signature values. It also does not compare KeyType with the verifier’s configured scheme name. It requires a nonempty KeyType and includes that string in the signed message (signature search).

If different map entries contain signatures with the same inner identity hash, the first matching value visited controls verification. Conflicting entries can therefore give an order-dependent result. Producers use matching outer and inner identity hashes and one signature per identity.

Threshold verification calls VerifyEnvelope for each configured verifier and counts distinct hashes of successful verifier keys. Unknown or invalid signatures do not invalidate an otherwise sufficient threshold. A threshold greater than the number of supplied verifier entries fails before verification. Duplicate configured keys cannot provide more than one successful identity. Threshold verification.

Descriptor validation

A dirauth applies MixShape(d, e) to mix descriptors and ReplicaShape(d, e) to replica descriptors. The caller supplies e. MixShape uses it for the key window. Neither algorithm uses the descriptor’s Epoch.

MixShape(d, e):
    Require d != nil.
    Require 1 <= byte_length(d.Name) <= 32.
    Require d.LinkKey and d.IdentityKey to be nonempty.
    Require d.MixKeys[e] to be nonempty.
    For each key epoch k in d.MixKeys:
        Require e <= k < e + 3.
    Require d.Addresses to be nonempty.
    For each address list in d.Addresses:
        Require the list to be nonempty.
        Check each URL with AddressShape(URL, d.IsGatewayNode, true).
    Require that IsGatewayNode and IsServiceNode are not both true.
    If IsServiceNode is false:
        Require Kaetzchen == nil.
    Otherwise, for each capability and parameter map in Kaetzchen:
        Require a nonempty capability name and a non-nil parameter map.
        Require parameter "endpoint" to exist and to be a string.
        Require 1 <= byte_length(endpoint) <= 32.

ReplicaShape(d, e):
    Require d != nil.
    Require 1 <= byte_length(d.Name) <= 32.
    Require d.LinkKey and d.IdentityKey to be nonempty.
    Require d.EnvelopeKeys to be nonempty.
    Require each EnvelopeKeys value to be nonempty.
    Require d.Addresses to be nonempty.
    For each address list in d.Addresses:
        Require the list to be nonempty.
        Check each URL with AddressShape(URL, false, false).

AddressShape(URL, isGateway, allowOnion):
    Parse the URL with the reference URL syntax.
    If its scheme is tcp, tcp4, tcp6, ws, or quic:
        Require its host component to split into host and port.
    Else if its scheme is onion:
        Require allowOnion and isGateway.
    Else:
        Fail.

The URL syntax is that of Go net/url.Parse, and host-port splitting is that of net.SplitHostPort. This is a syntax rule. It does not require a nonempty host, a numeric nonempty port, a particular address family, or equality between the address-map key and the URL scheme. The onion branch omits host-port validation. Additional URL components are not rejected by this validator. Address validation.

MixShape permits missing or empty future key values when their epoch lies in the permitted window. It does not require a consecutive set of three keys. It does not verify d.Epoch, d.Version, key lengths, or key decoding. A service can have nil or empty Kaetzchen, and multiple capabilities can use the same endpoint. Other capability parameters and KaetzchenAdvertizedData have no additional shape validation here. ReplicaShape does not use its epoch argument, does not verify envelope-key epochs, and does not verify ReplicaID against configuration. A replica descriptor has no Version field. Mix validation, replica validation.

Live descriptor uploads

Upload validation starts after the wire session and command parser accept the command. peerID is the session’s authenticated identity hash, peerLinkKey is its authenticated link public key, and e is the command epoch. The handler uses the same sequence for mix and replica uploads.

Key Value Explanation
1. Command epoch DescriptorInvalid on failure Require e to be the current local epoch minus one, the current epoch, or the current epoch plus one.
2. Decode upload DescriptorInvalid on failure Decode SignedUpload or SignedReplicaUpload, and require its descriptor pointer to be non-nil.
3. Session identity DescriptorForbidden on failure Require H(descriptor.IdentityKey) == peerID.
4. Identity-key length DescriptorInvalid on failure Require the public-key size of the configured PKI signature scheme. This precedes key decoding.
5. Decode identity key DescriptorForbidden on failure Decode the identity key with the configured PKI signature scheme.
6. Upload signature DescriptorForbidden on failure Run signature verification on the decoded upload as specified below.
7. Session link key DescriptorForbidden on failure Require byte equality between the descriptor’s link key and peerLinkKey.
8. QUIC hash length DescriptorInvalid on failure Require the byte length of QUICKeyHash to be 0, 32, 64, or 96.
9. Current authorization DescriptorForbidden on failure Verify identity, role, and pinned name. For a replica, also verify the pinned ReplicaID.
10. Metadata policy and shape DescriptorInvalid on failure Apply the metadata policy, then run MixShape(d, e) or ReplicaShape(d, e), and the metadata conditions below.
11. Store Status from storage Return DescriptorOk, DescriptorConflict, or DescriptorInternalError according to the storage algorithm below.

For step 6, require a non-nil signature with the configured scheme’s exact signature size. Make a new upload object with Signature = nil. Retain the decoded descriptor and, for a mix upload, the decoded LoopStats. Encode this new object canonically. Run signature verification on Signature.Payload over those bytes with the decoded descriptor identity key (upload signature operations).

This operation does not verify the upload signature’s PublicKeySum256 or include it in the preimage. The decoder already discarded unknown fields. The receiver therefore verifies the canonical encoding of the decoded object, rather than the received upload bytes.

For step 9, a mix descriptor with only IsGatewayNode set uses the gateway authorization map. A descriptor with only IsServiceNode set uses the service map. A descriptor with neither flag set uses the mix map. Both flags set cause rejection. The selected map MUST contain the identity hash and the exact descriptor name. A replica MUST have an identity hash, name, and ReplicaID that match one current storage-replica entry. Authorization.

For step 10, if AcceptDescriptorMetadata is false, clear ContactInfo and SoftwareVersion before validation and storage. Otherwise, retain them. Require SoftwareVersion to contain at most 128 bytes and ContactInfo to contain at most 256 bytes. Each retained byte MUST be in the inclusive range 0x20 through 0x7e. Empty strings are valid (printable-string validation).

The implementation evaluates the core shape validation, the software-version validation, and the contact-information validation, and joins their errors. Any error gives the same wire status. The signature verification always occurs before metadata removal (metadata policy).

The handler does not compare descriptor.Epoch with e. For a mix, e selects the required mix key and its permitted window. For a replica, shape validation leaves both descriptor and envelope-key epochs unchecked. Storage uses e in both cases.

The command handlers do not require QUICKeyHash to match a QUIC session key (replica upload order). They also do not require a gateway to advertise a TCP or onion address. A QUIC-only gateway can produce a warning after acceptance (mix upload order).

Upload storage and replay

Storage serializes upload decisions for an identity hash. After metadata policy, the receiver compares the incoming descriptor with any descriptor stored for (command epoch, identity hash). Comparison uses canonical descriptor bytes, and excludes the upload signature and LoopStats.

StoreUpload(e, identity, rawUpload, decodedDescriptor):
    If a descriptor already exists at (e, identity):
        Canonically encode both descriptors.
        If either encoding fails: return DescriptorInternalError.
        If the encodings differ: return DescriptorConflict.
        Return DescriptorOk.
    If a document for e exists, or this authority's own vote for e exists:
        Return DescriptorConflict.

    Persist the original rawUpload at (e, identity).
    If persistence fails:
        Report a fatal persistence error, and return DescriptorInternalError.

    Recheck state while committing the in-memory descriptor:
        If a descriptor now exists at (e, identity): return DescriptorOk.
        If a document or this authority's own vote now exists for e:
            Return DescriptorConflict.
        Store decodedDescriptor, and notify the state worker.
    Return DescriptorOk.

An unchanged upload can therefore succeed after the authority votes or publishes, because comparison precedes the late-upload condition. The nominal upload deadline causes a warning. It is not itself a rejection condition. Persistence can succeed before a later finality comparison produces DescriptorConflict, so a conflict response does not prove the absence of a write. The live descriptor has the applied metadata policy, while the stored signed upload preserves its original bytes (storage and vote cut).

Document validation

The shared base validator operates on a parsed body and a set of verifier keys. It does not authenticate the document envelope. VerifyEnvelope includes the current-epoch expiration condition for each embedded commitment or reveal.

BaseDocument(d, verifiers):
    Require d.Version == "v1".
    Require d.GenesisEpoch != 0.
    If PriorSharedRandom is empty:
        Require d.GenesisEpoch == d.Epoch.
    Build verifierByHash from verifiers.

    For each (identity, signedCommit) in SharedRandomCommit:
        Require verifierByHash[identity] to exist.
        commit = VerifyEnvelope(verifierByHash[identity], signedCommit).
        Require len(commit) == 40.
        Require BE64(commit[0:8]) == d.Epoch.
        If SharedRandomCommit has exactly one entry:
            Require SharedRandomReveal to have zero entries.
        Otherwise:
            Require reveal count == commitment count.
            Require SharedRandomReveal[identity] to exist.
            reveal = VerifyEnvelope(verifierByHash[identity], that entry).
            Require len(reveal) == 40.
            Require BE64(reveal[0:8]) == BE64(commit[0:8]).
            Require H(reveal) == commit[8:40].

    seen = empty identity-hash set.
    For each descriptor in Topology, in layer and list order:
        Run MixShape(descriptor, d.Epoch).
        Require H(descriptor.IdentityKey) not in seen, then add it.
    For each descriptor in GatewayNodes:
        Run MixShape(descriptor, d.Epoch).
        Require descriptor.IsGatewayNode.
        Require H(descriptor.IdentityKey) not in seen, then add it.
    For each descriptor in ServiceNodes:
        Run MixShape(descriptor, d.Epoch).
        Require descriptor.IsServiceNode.
        Require H(descriptor.IdentityKey) not in seen, then add it.
    For each descriptor in StorageReplicas:
        Run ReplicaShape(descriptor, d.Epoch).

VoteDocument(d, verifiers):
    Run BaseDocument(d, verifiers).

FullDocument(d, verifiers):
    Run BaseDocument(d, verifiers).
    Require Topology to contain at least one layer.
    Require every layer to contain at least one descriptor.
    Require GatewayNodes to contain at least one descriptor.
    Require ServiceNodes to contain at least one descriptor.

If SharedRandomCommit is empty, the commitment loop does not run. The base validator then neither rejects nonempty SharedRandomReveal nor runs verification on it. The one-commit case rejects every nonempty reveal map. The two-or-more-commit case requires the same identity set and a valid matching reveal for each commitment (commitment opening). The vote handler adds its own exact count and sender conditions below (document validators).

The base validator does not require role flags to be clear for entries in Topology. It does require the appropriate flag for entries in the gateway and service lists, and the core descriptor validation rejects contradictory flags. It rejects repeated identity hashes across those three collections. It does not verify replica identity uniqueness, replica-ID uniqueness, or identity overlap with replicas. It does not consult the receiver’s node authorization tables.

This document validator omits descriptor metadata and QUIC hash lengths. It does not parse descriptor keys, compare descriptor epochs, or require a configured topology size. It also omits delay and rate ranges, floating-point finiteness, SharedRandomValue length, and geometry-hash length or equality. It does not constrain the body PKI scheme name, notice text, or the length and contents of nonempty PriorSharedRandom. Such producer rules or conditions in a later consumer are distinct from this validator (complete base-validation body).

Authority message acceptance

Authority message validation starts after wire command decoding and authority-role dispatch. Command decoding verifies the minimum command length. It takes the declared key from the fixed-size public-key field, then decodes it with the configured signature scheme. A decoding failure does not reach these handlers (command decoding).

The session role controls command dispatch (role dispatch):

  • A client session can request consensus.
  • A mix, gateway, or service session can request consensus or post a mix descriptor.
  • A replica session can only post a replica descriptor.
  • An authority session can request consensus or send Vote, Reveal, Cert, or Sig.

An unsupported command for the session role receives no command status.

V is the receiver’s current votingEpoch, and S is its current state. Message authorization first compares H(command.PublicKey) with the session identity hash, then verifies membership in the configured authority authorization map. Either failure returns that command’s NotAuthorized status. Message validation and storage are atomic with respect to the state machine.

ReceiveVote(command):
    Check authorization; otherwise return VoteNotAuthorized.
    If command.Epoch < V: return VoteTooLate.
    If command.Epoch > V: return VoteTooEarly.
    Ensure the vote and commitment maps for V exist.
    If this sender already has a vote for V: return VoteAlreadyReceived.
    If S == accept_signature: return VoteTooLate.
    VerifyEnvelope(command.PublicKey, command.Payload);
        on failure, return VoteNotSigned.
    d = ParseDocument(command.Payload);
        on failure, return VoteNotSigned.
    If d.Epoch != V: return VoteMalformed.
    Run VoteDocument(d, verifiers);
        on failure, return VoteMalformed.
    Require exactly one commitment and zero reveals;
        otherwise return VoteMalformed.
    Require the commitment map to contain this sender's identity;
        otherwise return VoteMalformed.
    Store d as this sender's vote for V.
    If S == accept_desc or S == accept_vote:
        Store the sender's commitment for V.
    Return VoteOk.

ReceiveReveal(command):
    Check authorization; otherwise return RevealNotAuthorized.
    reveal = VerifyEnvelope(command.PublicKey, command.Payload);
        on failure, return RevealNotSigned.
    If len(reveal) < 8: return RevealNotSigned.
    e = BE64(reveal[0:8]).
    If e < V: return RevealTooLate.
    If e > V: return RevealTooEarly.
    If S == accept_cert or S == accept_signature:
        If this sender already has a reveal for V:
            Return RevealAlreadyReceived.
        Return RevealTooLate.
    If no commitment exists for this sender at V: return RevealTooEarly.
    commit = VerifyEnvelope(command.PublicKey, the stored commitment);
        on failure, return RevealNotSigned.
    Require len(commit) == 40 and len(reveal) == 40,
        equal eight-byte epoch prefixes, and H(reveal) == commit[8:40];
        otherwise return RevealNotSigned.
    If this sender already has a reveal for V: return RevealAlreadyReceived.
    Store command.Payload as this sender's signed reveal for V.
    Return RevealOk.

ReceiveCert(command):
    Check authorization; otherwise return CertNotAuthorized.
    If command.Epoch < V: return CertTooLate.
    If command.Epoch > V: return CertTooEarly.
    If S == accept_signature:
        If this sender already has a certificate for V:
            Return CertAlreadyReceived.
        Return CertTooLate.
    VerifyEnvelope(command.PublicKey, command.Payload);
        on failure, return CertNotSigned.
    d = ParseDocument(command.Payload);
        on failure, return CertNotSigned.
    If d.Epoch != V: return CertNotSigned.
    If d.SharedRandomReveal is empty: return CertNotSigned.
    If this sender has no stored vote for V: return CertTooEarly.
    Run FullDocument(d, verifiers);
        on failure, return CertNotSigned.
    If this sender already has a certificate for V: return CertAlreadyReceived.
    Store d as this sender's certificate for V.
    Return CertOk.

ReceiveSig(command):
    Check authorization; otherwise return SigNotAuthorized.
    If command.Epoch < V: return SigTooLate.
    If command.Epoch > V: return SigTooEarly.
    body = VerifyEnvelope(command.PublicKey, command.Payload);
        on failure, return SigNotSigned.
    If this sender already has a signature for V: return SigAlreadyReceived.
    Decode body into a new Signature, using receiver-decoding;
        on failure, return SigInvalid.
    Store that Signature under this sender's identity for V.
    Return SigOk.

The reveal handler does not use command.Epoch for its epoch decision. It uses the signed body’s epoch prefix. It verifies the full 40-byte length only after the epoch, state, and stored-commitment conditions (vote and reveal handlers).

The signature handler has no state gate. It verifies the outer envelope signature before the duplicate test, but it does not decode a duplicate’s inner signature. For a new signature, it omits inner-signature verification, sender-hash comparison, and payload-length conditions at receipt. A valid outer envelope whose certified body is CBOR null can therefore decode to a zero-valued inner Signature and receive SigOk. Publication verifies whether collected signatures authenticate the locally constructed consensus (signature handler).

There is no general rule that limits a command to the state named after that command. For a matching epoch, the receiver can store a new valid vote in bootstrap, accept_desc, accept_vote, accept_reveal, or accept_cert. It stores the commitment only in accept_desc and accept_vote. It can store a valid certificate before accept_cert if its sender’s vote already exists (certificate handler). It can store a reveal before accept_reveal if its commitment exists.

The explicit closed-state conditions still apply. Bootstrap does not reject all messages.

When t <= P/8, the bootstrap transition sets V to N+1. When t > P/8, it sets V to N+2 and remains in bootstrap until the next epoch. Successful publication increments V. Failed publication sets it to N+2 and returns to bootstrap (publication transition). Epoch comparisons use this stored V, rather than a fresh calculation from the nominal phase deadline.

Consensus reception and restoration

Network retrieval, client deserialization, and restoration apply different validation sequences.

Key Value Explanation
Network fetch Threshold, parse, full validation, epoch The standalone client and authority background fetch first require a successful Consensus response. They run threshold verification, parse the document, run FullDocument, and then require the requested epoch, in that order.
Client Deserialize Threshold, then parse This operation does not run FullDocument or compare against a requested epoch.
Persisted consensus Threshold, parse, storage epoch Restoration verifies the threshold, parses the document, and compares its epoch with the database epoch key. It does not run FullDocument.

The network fetch operations do not compare the geometry hash in this sequence. An application that verifies its local geometry does so separately. Client fetch and deserialize, authority fetch, consensus restoration.

Descriptor restoration and node reload

At startup, the reference restores descriptor and document records for the current local epoch minus one, the current epoch, and the current epoch plus one. It creates fresh in-memory vote, commitment, reveal, certificate, and signature maps. It does not restore these round messages. It then starts in bootstrap (state initialization).

For each descriptor record, the database bucket supplies the upload epoch e, and the record key supplies the expected identity hash. The restoration sequence is:

RestoreUpload(rawUpload, e, storedIdentity):
    Decode the corresponding signed upload.
    Require a non-nil descriptor.
    Require the configured identity public-key length, and decode the key.
    Verify the signed upload over its canonical unsigned form.
    Apply the current AcceptDescriptorMetadata policy.
    Run MixShape(descriptor, e) or ReplicaShape(descriptor, e),
        and validate retained SoftwareVersion and ContactInfo.
    Require H(descriptor.IdentityKey) == storedIdentity.
    Require current identity, role, name, and, for replicas, ReplicaID authorization.
    Insert the descriptor under (e, storedIdentity).

A failed descriptor validation discards that record and allows restoration to continue. A database record key whose identity-hash length is not 32 bytes causes a panic before these descriptor validations (restoration loop). Restoration does not recheck QUICKeyHash, bind the descriptor to a live session link key, or apply the live late-upload cut. The receiver runs signature verification before metadata removal. Thus, a different AcceptDescriptorMetadata setting can change the restored in-memory metadata without a change to the stored upload (restored-upload validation).

A node reload verifies the new node counts using the running layer and minimum-node settings (node-count validation). It loads all proposed node identity keys. It then replaces the mix, gateway, service, replica, and reverse-key tables as one operation. Any failure retains the current tables (node reload).

Reload does not change the startup-only Server, Authorities, Logging, Parameters, Debug, Topology, or SphinxGeometry settings. It also does not remove accepted descriptors or existing round messages. New uploads use the new authorization tables. Descriptor selection from the vote tally verifies current authorization again. Thus an accepted descriptor can remain in memory after a reload but fail later selection (tally authorization).

Document construction

Votes, voting certificates, and consensuses share the document body format. Their inputs differ as follows. V is the stored voting epoch.

Key Value Explanation
Vote Local descriptors, configured rates and notice, zero[32] SRV Copy GenesisEpoch and prior-random history from document V-1 if present. Otherwise set GenesisEpoch to V and retain stored history. Include this authority’s signed commitment only. Leave reveals null.
Voting certificate Tallied descriptors, rates and notice, zero[32] SRV Include only locally held commitments with a matching held reveal. Both maps are present, including when empty. Sign, then run FullDocument before storing or sending it.
Consensus Tallied descriptors, rates and notice, computed SRV First require the certificate threshold, reconcile pairs, and require the surviving-pair threshold. Compute SRV and update history. Build, run FullDocument and the configured topology test, then sign. Leave commit and reveal maps null.

The builder sets Version to “v1”, Epoch to V, and GenesisEpoch to the stored genesis epoch. It copies the supplied five voted rates. LambdaG comes from local configuration under gateway rate arithmetic. It copies the configured PKISignatureScheme and geometry hash, the supplied notice, and stored prior-random history. Configured replica IDs and keys include the full authorized set in R-26-7 order. Empty optional fields follow the field reference.

Split mix descriptors by flags: gateway first, then service node, then ordinary mix. Place ordinary mixes by the configured fixed topology order. Gateway and service lists retain the supplied descriptor order. Replica descriptors retain their supplied order. The vote uses locally collected descriptors. Tallying sorts the included descriptors and replicas for certificate and consensus construction. Voting documents therefore need not share one descriptor order across different authors.

Before building the consensus, initialize history to [SRV, SRV] when history is empty or V equals GenesisEpoch. Otherwise, at V modulo 504 equal to zero, set history to [SRV, old_history[0]]. Other rounds preserve history. This update precedes tallying and final document validation. It changes stored state even if a later construction condition fails.

The tagged constructors and common builder implement these steps.

Ordered reconciliation

Reconciliation processes accepted voting certificates. It compares signed envelope bytes, not only their certified payloads. Certificate authors and cited identities use ascending 32-byte identity-hash order.

Start with empty commit and reveal maps. Do not seed them from separately received votes or reveals. For each entry, verify these conditions in order:

  1. The cited identity is an authorized authority.
  2. Its commit envelope passes certificate verification.
  3. A reveal envelope exists under the same identity.
  4. That reveal envelope passes certificate verification under that identity’s key.
  5. Both certified payloads have 40 bytes and start with BE_uint64(V).
  6. The commit’s last 32 bytes equal H of the entire reveal payload.

A failed condition excludes the certificate author and stops its entry loop. A verified pair enters reconciliation.

bad = empty set
commits = empty map
reveals = empty map

for author in sorted(certificate authors):
    if author in bad:
        continue
    certificate = certificates[author]
    for signer in sorted(certificate.commit identities):
        if signer in bad:
            continue
        if the ordered pair checks fail:
            bad.add(author)
            break
        commit = certificate.commits[signer]
        reveal = certificate.reveals[signer]
        if signer not in commits:
            commits[signer] = commit
        else if commits[signer] != commit:
            bad.add(signer)
        if signer not in reveals:
            reveals[signer] = reveal
        else if reveals[signer] != reveal:
            bad.add(signer)

for signer in bad:
    delete commits[signer]
    delete reveals[signer]

The reveal comparison still runs when the commit comparison excludes its signer. An exclusion does not remove earlier entries attributed to other identities. A certificate author excluded during its own entry loop does not automatically stop that loop. Only a failed pair condition stops it. At each certificate’s turn, skip its author if already excluded.

The resulting maps supply the surviving-pair threshold and SRV. The tagged reconciliation implements this order.

The topology draw

The shared random value seeds one deterministic generator. Every authority MUST consume that generator in the same order.

The generator uses original ChaCha20 with a 256-bit SRV key, an eight-byte zero nonce, and initial 64-bit block counter zero. It reads consecutive keystream bytes without reset. It MUST stop before the counter wraps. Every draw from the topology generator MUST use this integer algorithm.

  • One draw, called Int63, reads 8 bytes of keystream and clears the top bit of the last byte. It then reads those 8 bytes as a little-endian unsigned 64-bit integer.
  • Int31 is Int63 shifted right by 32 and read as a signed 32-bit integer.
  • Intn(n), for n of at least 1 and at most 2^31-1, is as follows. When n is a power of two, it is Int31 masked with n-1. In every other case the party draws Int31 again while the value is above 2^31-1-(2^31 mod n), and then takes the value modulo n. A larger n is outside this definition. n is the size of the input list, which may include all mixes.
  • The permutation of n items MUST iterate i from 0 to n-1 inclusive. At each step it draws j = Intn(i+1), then sets m[i] to m[j], then sets m[j] to i.

The iteration at i = 0 MUST NOT be skipped. It assigns m[0] = 0 and consumes one draw. Skipping it changes all later draws.

Layer assignment

The assignment algorithm places accepted mixes into layers. A fixed topology takes precedence over automatic placement.

R-18-5 uses the following assignment algorithms. Sort input mix descriptors by identity-key hash (R-16-5). The prior consensus is the document for V-1. An older retained document does not select this algorithm. Layer indexes start at zero. Each append preserves the layer’s order.

With no prior consensus and no configured fixed topology, an authority MUST:

  1. Start a fresh generator keyed by the SRV and draw Perm(number of input mixes).
  2. Read mixes in that permutation order. Append each to successive layers, wrapping from the last layer back to layer zero.

With a prior consensus and no configured fixed topology, an authority MUST:

  1. Start one fresh generator keyed by the SRV. Create Layers empty output lists and a pending set containing every input mix, keyed by identity hash.
  2. Set target = floor(number of input mixes / Layers). Set priorLayers to the smaller of the prior layer count and Layers.
  3. Visit prior layers 0 through priorLayers-1 in order. For each layer, draw Perm of its full prior list, including absent nodes. Visit entries in that order. If the output layer contains target nodes, stop visiting entries in that layer. Otherwise, append a prior entry’s current descriptor if its identity remains pending. Remove each appended identity from the pending set.
  4. Sort the remaining descriptors by identity hash. Draw Perm of this pending list with the same generator. Keep one cursor into that permutation for the next steps.
  5. Visit output layers 0 through priorLayers-1. Fill each to target by appending the next pending descriptor and advancing the cursor.
  6. Starting at layer zero, append each remaining pending descriptor to successive layers, wrapping to layer zero after the last layer. Preserve descriptors already appended in steps 3 and 5.

An empty permutation consumes no draws. Draw each prior-layer permutation in full, even when target is zero or the algorithm uses few entries. Then draw the pending permutation from the same generator.

With a configured fixed topology, an authority MUST visit configured layers and their identity lists in configuration order. It appends the current descriptor for each included identity and skips identities with no included descriptor. It uses no random draws for this assignment. This case takes precedence over prior-consensus placement.

Gateway rate arithmetic

LambdaG uses the configured largest layer size n and configured gateway count g. It does not use the number of surviving descriptors. If g is zero or n is at most one, add configured LambdaP and LambdaL. Otherwise, evaluate (((n * n) * Log(n)) * Mu) / g from left to right. Convert n and g to binary64 first. Mu, LambdaP, and LambdaL are binary64 configuration values.

Round every arithmetic operation to binary64 with nearest-even rounding. Do not fuse multiply-add operations. The recorded bit patterns come from separate multiply and add operations. Go can emit fused multiply-add on arm64. On such a platform, evaluate each product and sum separately. Parentheses fix evaluation order. The logarithm constants are binary64 bit patterns.

Key Value Explanation
SQRT_HALF 3fe6a09e667f3bcd Reduction boundary, sqrt(2)/2.
LN2_HI 3fe62e42fee00000 High part of ln(2).
LN2_LO 3dea39ef35793c76 Low part of ln(2).
C1 3fe5555555555593 Polynomial coefficient.
C2 3fd999999997fa04 Polynomial coefficient.
C3 3fd2492494229359 Polynomial coefficient.
C4 3fcc71c51d8e78af Polynomial coefficient.
C5 3fc7466496cb03de Polynomial coefficient.
C6 3fc39a09d078c69f Polynomial coefficient.
C7 3fc2f112df3e5244 Polynomial coefficient.

For positive integer n of at least two, define Log as follows. Decompose its binary64 value exactly as fraction * 2^exponent, with 0.5 <= fraction < 1.

if fraction < SQRT_HALF:
    fraction = fraction * 2
    exponent = exponent - 1
f = fraction - 1
k = binary64(exponent)
s = f / (2 + f)
z = s * s
w = z * z
a = z * (C1 + w * (C3 + w * (C5 + w * C7)))
b = w * (C2 + w * (C4 + w * C6))
r = a + b
q = (0.5 * f) * f
Log(n) = (k * LN2_HI) - ((q - ((s * (q + r)) + (k * LN2_LO))) - f)

The Go logarithm uses this reduction and polynomial. For n = 3, Log(n) has bits 3ff193ea7aad030a. The tagged rate calculation uses these configured inputs.

Appendix G. References

Network operation depends on the packet, transport, client, storage, and certificate protocols.

Key Value Explanation
KATZMIXNET Mix network design Routing, mixing, and cover traffic.
KATZKEMSPHINX KEM Sphinx Packet headers using a KEM.
KATZTHINCLIENT Thin client The local library and daemon interface.
KATZDECOY Mix decoy statistics The design behind LoopStats.
KATZREPLAY Replay detection Epoch keys and replay caches.
KATZGLOSSARY Glossary Terms shared across the specifications.
KATZPKI Original PKI specification, KATZMIXPKI citation The original design, which this protocol continues.
KATZWIRE Katzenpost Wire Protocol Specification. /docs/specs/wireprotocol The PQ Noise link this protocol runs over.
KATZSPHINX Sphinx Packet Format Specification. /docs/specs/sphinx The packet format the Sphinx keys and the geometry of byte identity belong to.
KATZPIGEON Pigeonhole Specification. /docs/specs/pigeonhole The storage system the courier service and the storage replicas serve.
KATZCERT Certificate Format Specification. /docs/specs/certificate The certificate envelope.
RFC2119 Bradner, S. Key words for use in RFCs to Indicate Requirement Levels. RFC 2119, March 1997.
RFC7049 Bormann, C., Hoffman, P. Concise Binary Object Representation (CBOR). RFC 7049, October 2013. Section 3.9 gives the canonical map key order this protocol uses.
RFC8949 Bormann, C., Hoffman, P. Concise Binary Object Representation (CBOR). RFC 8949, December 2020.
RFC9000 Iyengar, J., Thomson, M. QUIC, a UDP-Based Multiplexed and Secure Transport. RFC 9000, May 2021.
RFC5869 Krawczyk, H., Eronen, P. HMAC-based Extract-and-Expand Key Derivation Function (HKDF). RFC 5869, May 2010.
PQNOISE Angel, Y., Dowling, B., Hulsing, A., Schwabe, P., Weber, F. Post Quantum Noise. The PqXX pattern.
SPHINCSPLUS Bernstein, P., Hulsing, A., Kolbl, S., Niederhagen, R., Rijneveld, J., Schwabe, P. SPHINCS+. The signature half of Ed25519 Sphincs+.
TORSRV Tor Shared Random Subsystem Specification. The commit-and-reveal design of shared random value and topology follows it.
BLAKE2 Aumasson, J., Neves, S., Wilcox-O’Hearn, Z., Winnerlein, C. BLAKE2. RFC 7693 H in constants and notation.

Appendix H. Conformance and vectors

Conformance testing MUST cover:

  1. A named test passes for every protocol requirement.
  2. A mixed network with the reference implementation produces matching, threshold-signed consensuses under successful-round conditions. This test includes an epoch divisible by 504.
epoch   245448 (245448 mod 504 == 0; 2026-10-01 00:00 UTC)
RN      0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
REVEAL  000000000003bec8441edc56cebc8e285d02267aa650819f15add7b06ef9b41b2690128dce655924
COMMIT  000000000003bec8e95138c6f44dfe875fa3daa92364a1ece9b315f25a7c7777f6f2064745a254c0

KEY_A   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
REV_A   000000000003bec8f15f1ea681af55bcdc2aff6ae09ca8ca122c84c4770d9571293f73e5d1e032f3
KEY_B   bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
REV_B   000000000003bec8afa49d096346b9834fdc42890e35cae35b3ff4546094e747aa5468fe7a961334
PREV    (absent: 32 zero bytes)
order   A then B (descending by reveal bytes)
SRV     702b1bb93f15155761dc058d56edd07d2a5127478566f520366fb4b490a5e8ae

BODY contains the Certified bytes of a document’s envelope, encoded under R-6-3. This encoding fixture has one empty layer, no nodes, no commits, no reveals, and short byte strings. It is not a well-formed document.

Epoch 245448, GenesisEpoch 245439, Mu 0.001, LambdaP 0.5, LambdaL 0.0005,
LambdaM 0.0005, LambdaG 0.25, LambdaR 0.02, Topology [nil], GatewayNodes [],
ServiceNodes [], StorageReplicas [], SharedRandomValue 00000000,
PriorSharedRandom [01, 02], SphinxGeometryHash aa, Version "v1",
PKISignatureScheme "Ed25519", every other field empty or nil

BODY
b3624d75fb3f50624dd2f1a9fc6545706f63681a0003bec8674c616d62646147
f93400674c616d6264614cfb3f40624dd2f1a9fc674c616d6264614dfb3f4062
4dd2f1a9fc674c616d62646150f93800674c616d62646152fb3f947ae147ae14
7b6756657273696f6e62763168546f706f6c6f677981f66c476174657761794e
6f646573806c47656e6573697345706f63681a0003bebf6c536572766963654e
6f646573806f53746f726167655265706c6963617380715072696f7253686172
656452616e646f6d82410141027153686172656452616e646f6d56616c756544
0000000072504b495369676e6174757265536368656d65674564323535313972
53686172656452616e646f6d436f6d6d6974f67253686172656452616e646f6d
52657665616cf672537068696e7847656f6d657472794861736841aa

PARAMKEY groups the example network’s five voted rates under R-16-3.

Mu 0.001, LambdaP 0.001, LambdaL 0.0005, LambdaM 0.0005, LambdaR 0.02

PARAMKEY (81 bytes)
a5624d75fb3f50624dd2f1a9fc674c616d6264614cfb3f40624dd2f1a9fc674c
616d6264614dfb3f40624dd2f1a9fc674c616d62646150fb3f50624dd2f1a9fc
674c616d62646152fb3f947ae147ae147b

GEOMETRY_CBOR and SPHINXGEOMETRYHASH encode the example network’s Sphinx geometry (R-26-2). The list gives the 14 fields in struct order. CBOR uses the length-first key order of R-6-3.

NrHops 5, PacketLength 3082, HeaderLength 476, RoutingInfoLength 410,
PerHopRoutingInfoLength 82, SURBLength 572, SphinxPlaintextHeaderLength 2,
PayloadTagLength 32, ForwardPayloadLength 2574, UserForwardPayloadLength 2000,
NextNodeHopLength 65, SPRPKeyMaterialLength 64, NIKEName "x25519", KEMName ""

GEOMETRY_CBOR (273 bytes)
ae664e72486f707305674b454d4e616d6560684e494b454e616d656678323535
31396a535552424c656e67746819023c6c4865616465724c656e6774681901dc
6c5061636b65744c656e677468190c0a705061796c6f61645461674c656e6774
681820714e6578744e6f6465486f704c656e677468184171526f7574696e6749
6e666f4c656e67746819019a74466f72776172645061796c6f61644c656e6774
68190a0e75535052504b65794d6174657269616c4c656e677468184077506572
486f70526f7574696e67496e666f4c656e6774681852781855736572466f7277
6172645061796c6f61644c656e6774681907d0781b537068696e78506c61696e
746578744865616465724c656e67746802

SPHINXGEOMETRYHASH (32 bytes)
ed57ca3bc2165a0483e0d16d97511e15f318ed5cedfc3e7388c85ee8a2c0fb47

The message ceiling is 264512 bytes for these synthetic inputs. The synthetic key sizes differ from the Namenlos keys.

sign 32, sig 64, link 1216, sphinx 32, envelope 1024
nodes 16, replicas 4, authorities 6

mix      = 32 + 1216 + 3 * 32 + 4096            = 5440
replica  = 32 + 1216 + 3 * 1024 + 4096          = 8416
unsigned = 8192 + 16 * 5440 + 4 * 8416          = 128896
signed   = 128896 + 6 * (64 + 96)
                  + 2 * 6 * (64 + 96 + 40)      = 132256
ceiling  = 2 * 132256 = 264512, above the 262144 floor

CERT_CBOR holds REVEAL in an envelope with an artificial expiration and a short signature. It tests encoding only. Signature verification fails.

Version 0, Expiration 245453, KeyType "Ed25519", Certified = REVEAL above,
one signature keyed by 32 bytes of 0xaa, with Payload 01020304

CERT_CBOR (204 bytes)
a5674b65795479706567456432353531396756657273696f6e00694365727469
666965645828000000000003bec8441edc56cebc8e285d02267aa650819f15ad
d7b06ef9b41b2690128dce6559246a45787069726174696f6e1a0003becd6a53
69676e617475726573a15820aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaa2675061796c6f616444010203046f5075626c69
634b657953756d3235365820aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaa

SIGNEDUPLOAD_CBOR uses the upload encoding. Its MixDescriptor byte string starts with 0x58cb, which encodes a length of 203 bytes. The contents are the descriptor’s own canonical CBOR. Signature and LoopStats are inline maps.

Signature {PublicKeySum256 32 bytes of 0xbb, Payload 0506}
MixDescriptor {Name "mix1", Epoch 245448, IdentityKey bb, LinkKey cc,
  MixKeys {245448: dd}, Addresses {"tcp": ["tcp://127.0.0.1:1"]},
  every other field empty, nil, or false}
LoopStats {MixIdentityHash 32 bytes of 0xbb, Epoch 245448,
  SegmentRatios {01 then 63 zero bytes: 0.5}}

SIGNEDUPLOAD_CBOR (448 bytes)
a3694c6f6f705374617473a36545706f63681a0003bec86d5365676d656e7452
6174696f73a15840010000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000f938006f4d69784964656e74697479486173685820bbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb695369
676e6174757265a2675061796c6f61644205066f5075626c69634b657953756d
3235365820bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbb6d4d697844657363726970746f7258cbad644e616d65646d697831
6545706f63681a0003bec8674c696e6b4b657941cc674d69784b657973a11a00
03bec841dd6756657273696f6e6069416464726573736573a163746370817174
63703a2f2f3132372e302e302e313a31694b6165747a6368656ef66a4c6f6164
576569676874006b4964656e746974794b657941bb6d4973476174657761794e
6f6465f46d4973536572766963654e6f6465f47241757468656e746963617469
6f6e5479706560774b6165747a6368656e416476657274697a656444617461f6

Automatic topology assignment starts with this SRV, no prior consensus, six mixes, and Layers 3. The authority permutes all six mixes and assigns them to successive layers, under the layer assignment algorithm. The mix numbers 0 through 5 represent ascending identity-key hash order (R-16-5).

SRV     702b1bb93f15155761dc058d56edd07d2a5127478566f520366fb4b490a5e8ae
Perm(6) = [1 5 2 4 3 0]

layer 0 = mix 1, mix 4
layer 1 = mix 5, mix 3
layer 2 = mix 2, mix 0

Direct consensus reply

A successful direct fetch from the Namenlos dirauth annares returns a consensus command. Let B be the byte length of its certificate envelope.

The Namenlos authority configuration sets the address and cryptographic schemes. The consensus command encoder adds the status and command header. The session encoder adds the two encrypted records after the PQ Noise handshake. TCP segments carry slices of the encrypted stream inside IPv4 datagrams. Their boundaries need not align with directory commands. IPv4 datagrams can fragment in transit. Directory commands travel directly between peers, outside Sphinx packets. The gateway consensus commands use different framing.


  1. Reference implementation: Katzenpost v0.0.107. ↩︎

  2. Namenlos started in 2022, as recorded in the 37C3 talk description. ↩︎

2.14 -

For publication of epoch keys and their retention across epoch boundaries, see directory clocks and retention. The directory security considerations also describe key rotation and node removal.

Sphinx packet replay detection

David Stainton

Abstract

This document defines the replay detection for any protocol that uses the Sphinx cryptographic packet format. This document is meant to serve as an implementation guide and to document the existing replay protection for deployed mix networks.


Terminology

The following terms are used in this specification.

epoch
A fixed-time interval with a current default value of 20 minutes. A new PKI document containing public key material is published for each epoch and is valid only for that epoch. For more information, see Sphinx mix and provider key rotation.

group
A finite set of elements and a binary operation that satisfy the properties of closure, associativity, invertability, and the presence of an identity element.

group element
An individual element of a group.

group generator
A group element capable of generating any other element of a group, via repeated applications of the generator and the group operation.

header
The packet header consisting of several components which convey the information necessary to verify packet integrity and to correctly process the packet.

packet
A Sphinx packet, of fixed length for each class of traffic, carrying a message payload and metadata for routing. Packets are routed anonymously through the mixnet and cryptographically transformed at each hop.

payload
The fixed-length portion of a packet containing an encrypted message or part of a message, to be delivered anonymously.

SEDA
Staged Event Driven Architecture. 1. A highly parallelizable computation model. 2. A computational pipeline composed of multiple stages connected by queues utilizing active queue-management algorithms that can evict items from a queue based on dwell time or other criteria where each stage is a thread pool. 3. The only correct way to efficiently implement a software based router on general purpose computing hardware.

Conventions used in this document

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC2119.

Introduction

The Sphinx cryptographic packet format is a compact and provably secure design introduced by George Danezis and Ian Goldberg in SPHINX09. Although it supports replay detection, the exact mechanism of replay detection is neither described in SPHINX09 nor is it described in our SPHINXSPEC. Therefore we detail here how to efficiently detect Sphinx packet replay attacks.

Sphinx cryptographic primitives

This specification borrows the following cryptographic primitive constants from our SPHINXSPEC:

  • H(M) - A cryptographic hash function which takes a byte array M to produce a digest consisting of a HASH_LENGTH byte array. H(M) MUST be pre-image and collision resistant.

  • EXP(X, Y) - An exponentiation function which takes the GROUP_ELEMENT_LENGTH byte array group elements X and Y, and returns X ^^ Y as a GROUP_ELEMENT_LENGTH byte array.

Let G denote the generator of the group, and EXP_KEYGEN() return a GROUP_ELEMENT_LENGTH byte array group element usable as a private key.

The group defined by G and EXP(X, Y) MUST satisfy the decisional Diffie-Hellman assumption.

Sphinx parameter constants

  • HASH_LENGTH - 32 bytes. Katzenpost currently uses SHA-512/256. RFC6234

  • GROUP_ELEMENT_LENGTH - 32 bytes. Katzenpost currently uses X25519. RFC7748

System overview

Mixnets as currently deployed have two modes of operation:

  • Sphinx routing keys and replay caches are persisted to disk.

  • Sphinx routing keys and replay caches are persisted to memory.

These two modes of operation fundamentally represent a tradeoff between mix server availability and notional compulsion attack resistance. Choosing a mode is the mix operator’s decision to make since the security and availability of the mix servers are affected. Since mix networks are vulnerable to various types of compulsion attack (see Compulsion Threat Considerations in the Sphinx cryptographic packet format specification) there is some advantage to not persisting the Sphinx routing keys to disk. The mix server operator can simply power-off the servers before seizure rather than physically destroying disks in order to prevent capture of the Sphinx routing keys. An argument can be made for using full disk encryption, but this may not be practical for servers hosted in remote locations.

On the other hand, persisting Sphinx routing keys and replay caches to disk is useful because it allows mix operators to shut down their server for maintenance purposes without loosing the Sphinx routing keys and replay caches. This means that as soon as the maintenance operation is completed, the server is able to rejoin the network. Our current PKI system, described in KATZMIXPKI, does not provide a mechanism to notify directory authorities of outages or maintenance periods. Consequently if the Sphinx routing keys are lost, a mix server outage occurs until the next epoch.

Both modes of operation completely prevent replay attacks after a system restart. In the case of disk persistence, replay attacks are prevented because all packets traversing the server have their replay tags persisted to disk cache. This cache is therefore once again used to prevent replays after a system restart. In the case of memory persistence, replays are prevented upon restart because the Sphinx routing keys are destroyed and therefore the mix will not participate in the network at all until at least the next epoch rotation. However, availability of the mix server may require two epoch rotations because (in accordance with KATZMIXPKI) the servers publish future epoch keys so that Sphinx packets flowing through the network can seamlessly straddle epoch boundaries.

Sphinx packet replay cache

Sphinx replay tag composition

The following excerpt from our SPHINXSPEC shows how the replay tag is calculated.

hdr = sphinx_packet.header
shared_secret = EXP( hdr.group_element, private_routing_key )
replay_tag = H( shared_secret )

However, this tag is not utilized in replay detection until the rest of the Sphinx packet is fully processed and its header is MAC-verified as described in SPHINXSPEC.

Sphinx replay tag caching

Although it would be sufficient to check a key-value store or hashmap to detect duplicate replay tags, we additionally employ a bloom filter to increase performance. Sphinx keys must periodically be rotated and destroyed to mitigate compulsion attacks, and our replay caches must likewise be rotated. This kind of key erasure scheme limits the time window during which an adversary can perform a compulsion attack. See our PKI specification KATZMIXPKI for more details regarding epoch key rotation and the grace period before and after the epoch boundary.

We tune our bloom filter for line-speed; that is to say, the bloom filter for a given replay cache is tuned for the maximum number of Sphinx packets that can be sent on the wire during the epoch duration of the Sphinx routing key. The tuning must take into account the size of the Sphinx packets as well as the maximum line speed of the network interface. This is a conservative tuning heuristic given that there must be more than this maximum number of Sphinx packets in order for there to be duplicate packets.

Our bloom-filter-with-hashmap replay detection cache looks like this:

Figure 1. Replay cache

Replay cache

This diagram does not express the full complexity of the replay caching system. In particular, it does not describe how entries are entered into the bloom filter and hashmap. Upon either bloom filter mismatch or hashmap mismatch, both data structures must be locked and the replay tag inserted into each.

For the disk persistence mode of operation, the hashmap can simply be replaced with an efficient key-value store. Persistent stores may use a write-back cache and other techniques for efficiency.

Epoch boundaries

Since mix servers publish future epoch keys, our replay detection forms a special kind of double-bloom-filter system. During the epoch grace period, servers perform a trial decryption of Sphinx packets. The replay cache used is the one associated with the Sphinx routing key that was successfully used to decrypt (unwrap transform) the Sphinx packet. This is not a double-bloom filter in the normal sense of the term since each bloom filter used is distinct and associated with its own cache. Furthermore, replay tags are only inserted into one cache and one bloom filter.

Cost of checking replays

The cost of checking a replay tag from a single replay cache is the sum of the following operations:

  1. Sphinx packet unwrap operation

  2. Bloom filter lookup

  3. Hashmap or cache lookup

These operations are roughly O(1) in complexity. However, Sphinx packets processed near epoch boundaries will not be constant time due to trial decryption with two Sphinx routing keys as mentioned above in the section called “Epoch boundaries”.

Concurrent processing of Sphinx packet replay tags

The best way to implement a software-based router is with a SEDA computational pipeline. We therefore need a mechanism to allow multiple threads to reference our rotating Sphinx keys and the associated replay caches. Here we shall describe how the mix server uses a shadow memory system such that the individual worker threads always have a reference to the current set of candidate mix keys and associated replay caches.

PKI updates

The mix server periodically updates its knowledge of the network by downloading a new consensus document as described in KATZMIXPKI. The individual threads in the cryptoworker thread pool that process Sphinx packets make use of a MixKey data structure consisting of the following:

  • A Sphinx routing key material (public and private X25519 keys)

  • A replay cache

  • A reference counter

Each of these cryptoworker threads has its own hashmap associating epochs with a reference to the MixKey. The mix server PKI thread maintains a single hashmap which associates the epochs with the corresponding MixKey. We refer to this hashmap as MixKeys. After a new MixKey is added to MixKeys, a reshadow operation is performed for each cryptoworker thread. The reshadow operation performs two tasks:

  • Removes entries from each cryptoworker thread’s hashmap that are no longer present in MixKeys and decrements the MixKey reference counter.

  • Adds entries present in MixKeys but not present in the thread’s hashmap and increments the MixKey reference counter.

Once a given MixKey reference counter is decremented to zero, the MixKey and its associated on-disk data are purged.

Although we do not discuss synchronization primitives, it should be obvious that updating the replay cache should likely make use of a mutex or similar primitive to avoid data races between cryptoworker threads.

References

COMPULS05

Danezis, G., Clulow, J., “Compulsion Resistant Anonymous Communications”, Proceedings of Information Hiding Workshop, June 2005, https://www.freehaven.net/anonbib/cache/ih05-danezisclulow.pdf.

KATZMIXNET

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Specification”, June 2017, https://katzenpost.network/docs/specs/pdf/mixnet.pdf.

KATZMIXPKI

Angel, Y., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Public Key Infrastructure Specification”, December 2017, https://katzenpost.network/docs/specs/pdf/pki.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC6234

Eastlake 3rd, D. and T. Hansen, “US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)”, RFC 6234, DOI 10.17487/RFC6234, May 2011, https://www.rfc-editor.org/info/rfc6234.

RFC7748

Langley, A., Hamburg, M., and S. Turner, “Elliptic Curves for Security”, RFC 7748, January 2016, https://www.rfc-editor.org/info/rfc7748.

SEDA

Welsh, M., Culler, D., Brewer, E., “SEDA: An Architecture for Well-Conditioned, Scalable Internet Services”, 2001, ACM Symposium on Operating Systems Principles, http://www.sosp.org/2001/papers/welsh.pdf.

SPHINX09

Danezis, G., Goldberg, I., “Sphinx: A Compact and Provably Secure Mix Format”, DOI 10.1109/SP.2009.15, May 2009, https://cypherpunks.ca/~iang/pubs/Sphinx_Oakland09.pdf.

SPHINXSPEC

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Sphinx Mix Network Cryptographic Packet Format Specification”, July 2017, https://katzenpost.network/docs/specs/pdf/sphinx.pdf.

2.15 -

Directory authorities publish Sphinx public keys and a hash of the packet geometry. See descriptors and geometry hashing in the directory authority specification for the v0.0.107 encoding and validation rules.

Sphinx cryptographic packet format specification

Yawning Angel

George Danezis

Claudia Diaz

Ania Piotrowska

David Stainton

Abstract

This document defines the Sphinx cryptographic packet format for decryption mix networks, and provides a parameterization based around generic cryptographic primitives types. This document does not introduce any new crypto, but is meant to serve as an implementation guide.


Terminology

The following terms are used in this specification.

group element
An individual element of a group.

group generator
A group element capable of generating any other element of a group, via repeated applications of the generator and the group operation.

header
The packet header consisting of several components which convey the information necessary to verify packet integrity and to correctly process the packet.

message
A variable-length sequence of octets sent anonymously through the network. Short messages are sent in a single packet; long messages are fragmented across multiple packets.

payload
The fixed-length portion of a packet containing an encrypted message or part of a message, to be delivered anonymously.

packet
A Sphinx packet, of fixed length for each class of traffic, carrying a message payload and metadata for routing. Packets are routed anonymously through the mixnet and cryptographically transformed at each hop.

Conventions used in this document

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC2119.

The C style Presentation Language, as described in §4 of RFC5246, is used to represent data structures, except for cryptographic attributes, which are specified as opaque byte vectors.

  • x | y denotes the concatenation of x and y.

  • x ^ y denotes the bitwise XOR of x and y.

  • byte an 8-bit octet.

  • x[a:b] denotes the sub-vector of x where a/b denote the start/end byte indexes (inclusive-exclusive); a/b may be omitted to signify the start/end of the vector x respectively.

  • x[y] denotes the yth element of list x.

  • x.len denotes the length of list x.

  • ZEROBYTES(N) denotes N bytes of 0x00.

  • RNG(N) denotes N bytes of cryptographic random data.

  • LEN(N) denotes the length in bytes of N.

  • CONSTANT_TIME_CMP(x, y) denotes a constant time comparison between the byte vectors x and y, returning true iff x and y are equal.

Introduction

The Sphinx cryptographic packet format is a compact and provably secure design introduced by George Danezis and Ian Goldberg SPHINX09. It supports a full set of security features: indistinguishable replies, hiding the path length and relay position, detection of tagging attacks and replay attacks, as well as providing unlinkability for each leg of the packet’s journey over the network.

Cryptographic primitives

This specification uses the following cryptographic primitives as the foundational building blocks for Sphinx:

  • H(M) – A cryptographic hash function which takes an octet array M to produce a digest consisting of a HASH_LENGTH byte octet array. H(M) MUST be pre-image and collision resistant.

  • MAC(K, M) – A cryptographic message authentication code function which takes a M_KEY_LENGTH byte octet array key K and arbitrary length octet array message M to produce an authentication tag consisting of a MAC_LENGTH byte octet array.

  • KDF(SALT, IKM) – A key derivation function which takes an arbitrary length octet array salt SALT and an arbitrary length octet array initial key IKM, to produce an octet array of arbitrary length.

  • S(K, IV) – A pseudo-random generator (stream cipher) which takes a S_KEY_LENGTH byte octet array key K and a S_IV_LENGTH byte octet array initialization vector IV to produce an octet array key stream of arbitrary length.

  • SPRP_Encrypt(K, IV, M)/SPRP_Decrypt(K, IV, M) – A strong pseudo-random permutation (SPRP) which takes a SPRP_KEY_LENGTH byte octet array key K, a SPRP_IV_LENGTH byte octet array initialization vector IV and arbitrary length message M, and produces the encrypted ciphertext or decrypted plaintext respectively.

    When used with the default payload authentication mechanism, the SPRP MUST be “fragile” in that any amount of modifications to M results in a large number of unpredictable changes across the whole message upon a SPRP_Encrypt() or SPRP_Decrypt() operation.

  • EXP(X, Y) – An exponentiation function which takes the GROUP_ELEMENT_LENGTH byte octet array group element X and the private key (a scalar) Y, and returns X ^^ Y as a GROUP_ELEMENT_LENGTH byte octet array.

    Let G denote the generator of the group, and EXP_KEYGEN() return a scalar usable as private key.

    The group defined by G and EXP(X, Y) MUST satisfy the Decision Diffie-Hellman problem.

  • EXP_KEYGEN() – Returns a new “suitable” private key for EXP().

  • EXP_KEYGEN_SEEDED(SEED) – Returns the private key that EXP_KEYGEN() generates when all of its randomness is read from the ChaCha20 keystream keyed by the 32 byte octet array SEED, with an all-zero 8 byte nonce. The same SEED always gives the same private key.

The lengths HASH_LENGTH, MAC_LENGTH, M_KEY_LENGTH, S_KEY_LENGTH, S_IV_LENGTH, SPRP_KEY_LENGTH, SPRP_IV_LENGTH and GROUP_ELEMENT_LENGTH are fixed by the choice of primitives. The primitives and lengths used by the Katzenpost mix network are given in the Katzenpost mix network specification.

Sphinx key derivation function

Sphinx packet creation and processing uses a common Key Derivation Function (KDF) to derive the required MAC and symmetric cryptographic keys from a per-hop shared secret.

The output of the KDF is partitioned according to the following structure:

struct {
opaque header_mac[M_KEY_LENGTH];
opaque header_encryption[S_KEY_LENGTH];
opaque header_encryption_iv[S_IV_LENGTH];
opaque payload_encryption[SPRP_KEY_LENGTH];
opaque blinding_seed[32];
} SphinxPacketKeys;

Sphinx_KDF( info, shared_secret ) -> packet_keys

Inputs:

  • info – The optional context and application specific information.

  • shared_secret – The per-hop shared secret derived from the Diffie-Hellman key exchange.

Outputs:

  • packet_keys The SphinxPacketKeys required to handle packet creation or processing.

The output packet_keys is calculated as follows:

kdf_out = KDF( info, shared_secret )
packet_keys = kdf_out[:LEN( SphinxPacketKeys )]

The per-hop blinding factor is not taken from the KDF output directly, because some groups cannot make a private key from arbitrary bytes: their key generation needs a source of randomness. The blinding factor is instead the private key generated from the blinding_seed:

blinding_factor = EXP_KEYGEN_SEEDED( packet_keys.blinding_seed )

In the pseudo-code below, the blinding_factor of a SphinxPacketKeys denotes this value.

The payload SPRP uses the payload_encryption key together with the header_encryption_iv as its IV, so SPRP_IV_LENGTH equals S_IV_LENGTH.

Sphinx packet parameters

Sphinx parameter constants

The Sphinx packet Format is parameterized by the implementation based on the application and security requirements.

  • AD_LENGTH – The constant amount of per-packet unencrypted additional data in bytes.

  • PAYLOAD_TAG_LENGTH – The length of the message payload authentication tag in bytes. This SHOULD be set to at least 16 bytes (128 bits).

  • PER_HOP_RI_LENGTH – The length of the the section called “Per-hop routing information” in bytes.

  • NODE_ID_LENGTH – The node identifier length in bytes.

  • RECIPIENT_ID_LENGTH – The recipient identifier length in bytes.

  • SURB_ID_LENGTH – The single use reply block identifier length in bytes.

  • MAX_HOPS – The maximum number of hops a packet can traverse.

  • PAYLOAD_LENGTH – The per-packet message payload length in bytes, including a PAYLOAD_TAG_LENGTH byte authentication tag.

  • KDF_INFO – A constant opaque byte vector used as the info parameter to the KDF for the purpose of domain separation.

Sphinx packet geometry

The Sphinx packet geometry is derived from the the section called “Sphinx parameter constants”. These are all derived parameters, and are primarily of interest to implementers.

  • ROUTING_INFO_LENGTH – The total length of the “routing information” Sphinx packet header component in bytes:
ROUTING_INFO_LENGTH = PER_HOP_RI_LENGTH * MAX_HOPS
  • HEADER_LENGTH – The length of the Sphinx packet header in bytes:
HEADER_LENGTH = AD_LENGTH + GROUP_ELEMENT_LENGTH + ROUTING_INFO_LENGTH + MAC_LENGTH
  • PACKET_LENGTH – The length of the Sphinx packet in bytes:
PACKET_LENGTH = HEADER_LENGTH + PAYLOAD_LENGTH

The Sphinx cryptographic packet Structure

Each Sphinx packet consists of two parts: the Sphinx packet header and the Sphinx packet payload:

struct {
opaque header[HEADER_LENGTH];
opaque payload[PAYLOAD_LENGTH];
} SphinxPacket;
  • header – The packet header consists of several components, which convey the information necessary to verify packet integrity and correctly process the packet.

  • payload – The application message data.

Sphinx packet header

The Sphinx packet header refers to the block of data immediately preceding the Sphinx packet payload in a Sphinx packet.

The structure of the Sphinx packet header is defined as follows:

struct {
opaque additional_data[AD_LENGTH]; /* Unencrypted. */
opaque group_element[GROUP_ELEMENT_LENGTH];
opaque routing_information[ROUTING_INFO_LENGTH];
opaque MAC[MAC_LENGTH];
} SphinxHeader;
  • additional_data – Unencrypted per-packet additional data (AD) that is visible to every hop. The AD is authenticated on a per-hop basis.

    As the additional_data is sent in the clear and traverses the network unaltered, implementations MUST take care to ensure that the field cannot be used to track individual packets.

    The Katzenpost mix network fixes the additional_data to a 2 byte version value, and its nodes reject any other value; see the Sphinx packet parameters of the Katzenpost mix network specification.

  • group_element – An element of the cyclic group, used to derive the per-hop key material required to authenticate and process the rest of the SphinxHeader and decrypt a single layer of the Sphinx packet payload encryption.

  • routing_information – A vector of per-hop routing information, encrypted and authenticated in a nested manner. Each element of the vector consists of a series of routing commands, specifying all of the information required to process the packet.

    The precise encoding format is specified in the section called “Per-hop routing information”.

  • MAC – A message authentication code tag covering the additional_data, group_element, and routing_information.

Per-hop routing information

The routing information component of the Sphinx packet header contains a vector of per-hop routing information. When processing a packet, the per-hop processing is set up such that the first element in the vector contains the routing commands for the current hop.

The structure of the routing information is as follows:

struct {
opaque routing_commands[PER_HOP_RI_LENGTH];
opaque encrypted_routing_commands[ROUTING_INFO_LENGTH - PER_HOP_RI_LENGTH];
} RoutingInformation;

The routing_commands element is a fixed block of exactly PER_HOP_RI_LENGTH bytes. It holds the RoutingCommands for the current hop, concatenated one after another. Neither the block nor any command in it carries a length prefix. The commands end at a NullCommand or at the end of the block.

The structure of a single RoutingCommand is as follows:

struct {
RoutingCommandType command;
select (RoutingCommandType) {
case null:               NullCommand;
case next_node_hop:      NextNodeHopCommand;
case recipient:          RecipientCommand;
case surb_reply:         SURBReplyCommand;
};
} RoutingCommand;

The following routing commands are currently defined:

enum {
null(0),
next_node_hop(1),
recipient(2),
surb_reply(3),

/* Routing commands between 0 and 0x7f are reserved. */

(255)
} RoutingCommandType;

The Katzenpost mix network adds a node delay command (0x80); see the per-hop routing information extensions of the Katzenpost mix network specification.

The NullCommand structure is as follows:

struct {
/* Zero bytes filling the rest of the routing_commands
block. This is not a length-prefixed vector. */
opaque padding[];
} NullCommand;

The NextNodeHopCommand structure is as follows:

struct {
opaque next_hop[NODE_ID_LENGTH];
opaque MAC[MAC_LENGTH];
} NextNodeHopCommand;

The RecipientCommand structure is as follows:

struct {
opaque recipient[RECIPIENT_ID_LENGTH];
} RecipientCommand;

The SURBReplyCommand structure is as follows:

struct {
opaque id[SURB_ID_LENGTH];
} SURBReplyCommand;

The NullCommand padding MUST be zero filled, and a node MUST reject a packet in which a NullCommand is followed by any non-zero byte. The choice of 0x00 as the terminal NullCommand is deliberate to ease implementation, as ZEROBYTES(N) produces a valid NullCommand RoutingCommand, resulting in “appending zero filled padding” producing valid output.

Implementations MUST pad the RoutingCommands vector so that it is exactly PER_HOP_RI_LENGTH bytes, by appending a terminal NullCommand if necessary.

Every non-terminal hop’s RoutingCommands MUST include a NextNodeHopCommand.

A hop’s RoutingCommands MUST NOT contain more than one NextNodeHopCommand, nor more than one SURBReplyCommand. A node MUST reject a packet that does.

Sphinx packet payload

The Sphinx packet payload refers to the block of data immediately following the Sphinx packet header in a Sphinx packet.

For most purposes the structure of the Sphinx packet payload can be treated as a single contiguous byte vector of opaque data.

Upon packet creation, the payload is repeatedly encrypted (unless it is a SURB reply as described in the section called “Single-use reply block (SURB) creation”) using keys derived from the Diffie-Hellman key exchange between the packet’s group_element and the public key of each node in the path.

Authentication of packet integrity is done by prepending a tag set to a known value to the plaintext prior to the first encrypt operation. By virtue of the fragile nature of the SPRP function, any alteration to the encrypted payload as it traverses the network will result in an irrecoverably corrupted plaintext when the payload is decrypted by the recipient.

Sphinx packet creation

For the sake of brevity, the pseudo-code for all of the operations will take a vector of the following PathHop structure as a parameter named path[] to specify the path a packet will traverse, along with the per-hop routing commands and per-hop public keys.

struct {
/* There is no need for a node_id here, as
routing_commands[0].next_hop specifies that
information for all non-terminal hops. */
opaque public_key[GROUP_ELEMENT_LENGTH];
RoutingCommand routing_commands[]; /* A list, not a wire encoding. */
} PathHop;

It is assumed that each RoutingCommands vector except for the terminal entry contains at least a RoutingCommand consisting of a partially assembled NextNodeHopCommand with the next_hop element filled in with the identifier of the next hop.

Create a Sphinx packet header

Both the creation of a Sphinx packet and the creation of a SURB requires the generation of a Sphinx packet header, so it is specified as a distinct operation.

Sphinx_Create_Header( additional_data, path[] ) -> sphinx_header,
               payload_keys

Inputs:

  • additional_data – The additional data that is visible to every node along the path in the header.

  • path – The vector of PathHop structures in hop order, specifying the node id, public key, and routing commands for each hop.

Outputs:

  • sphinx_header – The resulting Sphinx packet header.

  • payload_keys – The vector of SPRP keys and IVs used to encrypt the Sphinx packet payload, in hop order.

The Sphinx_Create_Header operation consists of the following steps:

  1. Derive the key material for each hop.
num_hops = path.len
route_keys = [ ]
route_group_elements = [ ]
priv_key = EXP_KEYGEN()

/* Calculate the key material for the 0th hop. */
group_element = EXP( G, priv_key )
route_group_elements += group_element
shared_secret = EXP( path[0].public_key, priv_key )
route_keys += Sphinx_KDF( KDF_INFO, shared_secret )
blinding_factor = route_keys[0].blinding_factor

/* Calculate the key material for rest of the hops. */
for i = 1; i < num_hops; ++i:
shared_secret = EXP( path[i].public_key, priv_key )
for j = 0; j < i; ++j:
shared_secret = EXP( shared_secret, route_keys[j].blinding_factor )
route_keys += Sphinx_KDF( KDF_INFO, shared_secret )
group_element = EXP( group_element, route_keys[i-1].blinding_factor )
route_group_elements += group_element

At the conclusion of the derivation process:

  • route_keys – A vector of per-hop SphinxPacketKeys.

  • route_group_elements – A vector of per-hop group elements.

  1. Derive the routing_information keystream and encrypted padding for each hop.

    ri_keystream = [ ]
    ri_padding = [ ]
    
    for i = 0; i < num_hops; ++i:
    keystream = ZEROBYTES( ROUTING_INFO_LENGTH + PER_HOP_RI_LENGTH ) ^
    S( route_keys[i].header_encryption,
    route_keys[i].header_encryption_iv )
    ks_len = LEN( keystream ) - (i + 1) * PER_HOP_RI_LENGTH
    
    padding = keystream[ks_len:]
    if i > 0:
    prev_pad_len = LEN( ri_padding[i-1] )
    padding = padding[:prev_pad_len] ^ ri_padding[i-1] |
    padding[prev_pad_len:]
    
    ri_keystream += keystream[:ks_len]
    ri_padding += padding
    
    At the conclusion of the derivation process:
    ri_keystream - A vector of per-hop routing_information
    encryption keystreams.
    ri_padding   - The per-hop encrypted routing_information
    padding.
    
  2. Create the routing_information block.

    When the path has fewer than MAX_HOPS hops, the unused space after the terminal hop’s routing commands is filled with random bytes. This padding is encrypted with the terminal hop’s keystream and covered by the terminal hop’s MAC, like the rest of the block.

    /* Start with the terminal hop, and work backwards. */
    i = num_hops - 1
    
    /* Fill the space left unused by a path shorter than
    MAX_HOPS with random padding. */
    routing_info = [ ]
    if num_hops < MAX_HOPS:
    pad_len = (MAX_HOPS - num_hops) * PER_HOP_RI_LENGTH
    routing_info = RNG( pad_len )
    
    /* Encode the terminal hop's routing commands. As the
    terminal hop can never have a NextNodeHopCommand, there
    are no per-hop alterations to be made. */
    ri_fragment = path[i].routing_commands |
    ZEROBYTES( PER_HOP_RI_LENGTH - LEN( path[i].routing_commands ) )
    
    /* Encrypt and MAC. */
    routing_info = ri_fragment | routing_info /* Prepend. */
    routing_info ^= ri_keystream[i]
    if i > 0:
    mac = MAC( route_keys[i].header_mac, additional_data |
    route_group_elements[i] | routing_info |
    ri_padding[i-1] )
    else:
    mac = MAC( route_keys[i].header_mac, additional_data |
    route_group_elements[i] | routing_info )
    
    /* Calculate the routing info for the rest of the hops. */
    for i = num_hops - 2; i >= 0; --i:
    cmds_to_encode = [ ]
    
    /* Find and finalize the NextNodeHopCommand. */
    for j = 0; j < path[i].routing_commands.len; j++:
    cmd = path[i].routing_commands[j]
    if cmd.command == next_node_hop:
    /* Finalize the NextNodeHopCommand. */
    cmd.MAC = mac
    cmds_to_encode = cmds_to_encode + cmd /* Append */
    
    /* Append a terminal NullCommand. */
    ri_fragment = cmds_to_encode |
    ZEROBYTES( PER_HOP_RI_LENGTH - LEN( cmds_to_encode ) )
    
    /* Encrypt and MAC */
    routing_info = ri_fragment | routing_info /* Prepend. */
    routing_info ^= ri_keystream[i]
    if i > 0:
    mac = MAC( route_keys[i].header_mac, additional_data |
    route_group_elements[i] | routing_info |
    ri_padding[i-1] )
    else:
    mac = MAC( route_keys[i].header_mac, additional_data |
    route_group_elements[i] | routing_info )
    
    At the conclusion of the derivation process:
    routing_info - The completed routing_info block.
    mac          - The MAC for the 0th hop.
    
  3. Assemble the completed Sphinx packet header and Sphinx packet payload SPRP key vector.

    /* Assemble the completed Sphinx packet header. */
    SphinxHeader sphinx_header
    sphinx_header.additional_data = additional_data
    sphinx_header.group_element = route_group_elements[0] /* From step 1. */
    sphinx_header.routing_information = routing_info /* From step 3. */
    sphinx_header.MAC = mac                     /* From step 3. */
    
    /* Preserve the Sphinx Payload SPRP keys and IVs, to return
    to the caller. The IV is the hop's header_encryption_iv. */
    payload_keys = [ ]
    for i = 0; i < num_hops; ++i:
    payload_keys += { key: route_keys[i].payload_encryption,
    iv: route_keys[i].header_encryption_iv }
    
    At the conclusion of the assembly process:
    sphinx_header - The completed sphinx_header, to be returned.
    payload_keys  - The vector of SPRP keys and IVs, to be returned.
    

Create a Sphinx packet

Sphinx_Create_Packet( additional_data, path[], payload ) -> sphinx_packet

Inputs:

  • additional_data – The additional data that is visible to every node along the path in the header.

  • path – The vector of PathHop structures in hop order, specifying the node id, public key, and routing commands for each hop.

  • payload – The packet payload message plaintext. It MUST be exactly PAYLOAD_LENGTH - PAYLOAD_TAG_LENGTH bytes long: the caller pads a shorter message to this length, and Sphinx_Create_Packet returns an error for any other length.

Outputs:

  • sphinx_packet – The resulting Sphinx packet.

The Sphinx_Create_Packet operation consists of the following steps:

  1. Create the Sphinx packet header and SPRP key vector.

    sphinx_header, payload_keys =
    Sphinx_Create_Header( additional_data, path )
    
  2. Check the payload length, and prepend the authentication tag.

    if LEN( payload ) != PAYLOAD_LENGTH - PAYLOAD_TAG_LENGTH:
    return ErrorInvalidPayload
    payload = ZEROBYTES( PAYLOAD_TAG_LENGTH ) | payload
    
  3. Encrypt the payload.

    for i = path.len - 1; i >= 0; --i:
    payload = SPRP_Encrypt( payload_keys[i].key, payload_keys[i].iv, payload )
    
  4. Assemble the completed Sphinx packet.

    SphinxPacket sphinx_packet
    sphinx_packet.header = sphinx_header
    sphinx_packet.payload = payload
    

Sphinx packet processing

Mix nodes process incoming packets first by performing the Sphinx_Unwrap operation to authenticate and decrypt the packet, and, if applicable, prepare the packet to be forwarded to the next node.

If Sphinx_Unwrap returns an error for any given packet, the packet MUST be discarded with no additional processing.

After a packet has been unwrapped successfully, a replay detection tag is checked to ensure that the packet has not been seen before. If the packet is a replay, the packet MUST be discarded with no additional processing.

The routing commands for the current hop are interpreted and executed, and finally the packet is forwarded to the next mix node over the network or presented to the application if the current node is the final recipient.

Sphinx_Unwrap operation

The Sphinx_Unwrap operation contains the majority of the per-hop packet processing, handling authentication, decryption, and modifying the packet prior to forwarding it to the next node.

Sphinx_Unwrap( private_routing_key, sphinx_packet ) -> sphinx_packet,
                  routing_commands,
                  replay_tag

Inputs:

  • private_routing_key – The mix node’s private key, a scalar as returned by EXP_KEYGEN().

  • sphinx_packet – A Sphinx packet to unwrap.

Outputs:

  • error – Indicating a unsuccessful unwrap operation if applicable.

  • sphinx_packet – The resulting Sphinx packet.

  • routing_commands – A vector of RoutingCommand, specifying the post unwrap actions to be taken on the packet.

  • replay_tag – A tag used to detect whether this packet was processed before.

The Sphinx_Unwrap operation consists of the following steps:

  1. (Optional) Examine the Sphinx packet header’s additional data.

    hdr = sphinx_packet.header
    shared_secret = EXP( hdr.group_element, private_routing_key )
    if shared_secret == ZEROBYTES( LEN( shared_secret ) ):
    /* MUST abort processing on an all-zero shared secret. */
    return ErrorInvalidHeader
    replay_tag = H( shared_secret )
    

    If the header’s additional_data element contains information required to complete the unwrap operation, such as specifying the packet format version or the cryptographic primitives used examine it now.

    Implementations MUST NOT treat the information in the additional_data element as trusted until after the completion of Step 3 (“Validate the Sphinx packet header”).

  2. Derive the various keys required for packet processing.

    keys = Sphinx_KDF( KDF_INFO, shared_secret )
    
  3. Validate the Sphinx packet header.

    derived_mac = MAC( keys.header_mac, hdr.additional_data |
    hdr.group_element |
    hdr.routing_information )
    if !CONSTANT_TIME_CMP( derived_mac, hdr.MAC):
    /* MUST abort processing if the header is invalid. */
    return ErrorInvalidHeader
    
  4. Extract the per-hop routing commands for the current hop.

    /* Append padding to preserve length-invariance, as the routing
    commands for the current hop will be removed. */
    padding = ZEROBYTES( PER_HOP_RI_LENGTH )
    B = hdr.routing_information | padding
    
    /* Decrypt the entire routing_information block. */
    B = B ^ S( keys.header_encryption, keys.header_encryption_iv ) 
    
  5. Parse the per-hop routing commands.

    cmd_buf = B[:PER_HOP_RI_LENGTH]
    new_routing_information = B[PER_HOP_RI_LENGTH:]
    
    next_mix_command_idx = -1
    seen_surb_reply = false
    routing_commands = [ ]
    idx = 0
    while idx < PER_HOP_RI_LENGTH {
    /* WARNING: Bounds checking omitted for brevity. */
    cmd_type = cmd_buf[idx]
    cmd = NULL
    switch cmd_type {
    case null:
    /* No further commands. MUST abort processing if the
    padding is not zero filled. */
    if cmd_buf[idx:] != ZEROBYTES( PER_HOP_RI_LENGTH - idx ):
    return ErrorInvalidCommand
    goto done
    
    case next_node_hop:
    if next_mix_command_idx != -1:
    /* MUST abort processing on a second NextNodeHopCommand. */
    return ErrorInvalidCommand
    cmd = RoutingCommand( B[idx:idx+1+LEN( NextNodeHopCommand )] )
    next_mix_command_idx = routing_commands.len /* Save for step 7. */
    idx += 1 + LEN( NextNodeHopCommand )
    break
    
    case recipient:
    cmd = RoutingCommand( B[idx:idx+1+LEN( RecipientCommand )] )
    idx += 1 + LEN( RecipientCommand )
    break
    
    case surb_reply:
    if seen_surb_reply:
    /* MUST abort processing on a second SURBReplyCommand. */
    return ErrorInvalidCommand
    seen_surb_reply = true
    cmd = RoutingCommand( B[idx:idx+1+LEN( SURBReplyCommand )] )
    idx += 1 + LEN( SURBReplyCommand )
    break
    
    default:
    /* MUST abort processing on unrecognized commands. */
    return ErrorInvalidCommand
    }
    routing_commands += cmd /* Append cmd to the tail of the list. */
    }
    done:
    
  6. Apply this hop’s routing_commands (a vector of SphinxRoutingCommand) and decrypt the Sphinx packet payload.

    payload = sphinx_packet.payload
    payload = SPRP_Decrypt( keys.payload_encryption,
    keys.header_encryption_iv, payload )
    sphinx_packet.payload = payload 
    
  7. If the routing_commands vector included aNextNodeHopCommand, transform the packet for forwarding to the next mix node by applying new_routing_information.

    if next_mix_command_idx != -1:
    cmd = routing_commands[next_mix_command_idx]
    hdr.group_element = EXP( hdr.group_element, keys.blinding_factor )
    if hdr.group_element == ZEROBYTES( GROUP_ELEMENT_LENGTH ):
    /* MUST abort processing on an all-zero blinded group element. */
    return ErrorInvalidHeader
    hdr.routing_information = new_routing_information
    hdr.MAC = cmd.MAC
    sphinx_packet.header = hdr
    
Post-Sphinx_Unwrap processing

Upon the completion of the Sphinx_Unwrap operation, implementations MUST take several additional steps. As the exact behavior is mostly implementation specific, pseudo-code will not be provided for most of the post processing steps.

  1. Apply replay detection to the packet.

    The replay_tag value returned by Sphinx_Unwrap MUST be unique across all packets processed with a given private_routing_key.

    The exact specifics of how to detect replays is left up to the implementation, however any replays that are detected MUST be discarded immediately.

  2. Act on the routing commands, if any.

    The exact specifics of how implementations chose to apply routing commands is deliberately left unspecified, however in general:

    • If there is a NextNodeHopCommand, the packet should be forwarded to the next node based on the next_hop field upon completion of the post processing.

      The lack of a NextNodeHopCommand indicates that the packet is destined for the current node.

    • If there is a SURBReplyCommand, the packet should be treated as a SURBReply destined for the current node, and decrypted accordingly as described in the section called “Decrypt a Sphinx reply originating from a SURB”.

    • If the implementation supports multiple recipients on a single node, the RecipientCommand command should be used to determine the correct recipient for the packet, and the payload delivered as appropriate.

      It is possible for both a RecipientCommand and a NextNodeHopCommand to be present simultaneously in the routing commands for a given hop. The behavior when this situation occurs is implementation defined.

  3. Authenticate the packet if required.

    If the packet is destined for the current node, the integrity of the payload MUST be authenticated.

    The authentication is done as follows:

    derived_tag = sphinx_packet.payload[:PAYLOAD_TAG_LENGTH]
    expected_tag = ZEROBYTES( PAYLOAD_TAG_LENGTH )
    if !CONSTANT_TIME_CMP( derived_tag, expected_tag ):
    /* Discard the packet with no further processing. */
    return ErrorInvalidPayload
    

    Remove the authentication tag before presenting the payload to the application.

    sphinx_packet.payload = sphinx_packet.payload[PAYLOAD_TAG_LENGTH:]
    

Single-use reply block (SURB) creation

A single use reply block (SURB) is a delivery token with a short lifetime, that can be used by the recipient to reply to the initial sender.

SURBs allow for anonymous replies, when the recipient does not know the sender of the message. Usage of SURBs guarantees anonymity properties but also makes the reply messages indistinguishable from forward messages both to external adversaries as well as the mix nodes.

When a SURB is created, a matching reply block decryption token is created, which is used to decrypt the reply message that is produced and delivered via the SURB.

The Sphinx SURB wire encoding is implementation defined, but for the purposes of illustrating creation and use, the following will be used:

struct {
SphinxHeader sphinx_header;
opaque first_hop[NODE_ID_LENGTH];
opaque payload_key[SPRP_KEY_LENGTH];
opaque payload_iv[SPRP_IV_LENGTH];
} SphinxSURB;

The SURB carries an IV next to the payload key because the SPRP takes both a key and an IV.

Create a Sphinx SURB and decryption token

Structurally a SURB consists of three parts, a pre-generated Sphinx packet header, a node identifier for the first hop to use when using the SURB to reply, and cryptographic keying material by which to encrypt the reply’s payload. All elements must be securely transmitted to the recipient, perhaps as part of a forward Sphinx packet’s Payload, but the exact specifics on how to accomplish this is left up to the implementation.

When creating a SURB, the terminal routing_commands vector SHOULD include a SURBReplyCommand, containing an identifier to ensure that the payload can be decrypted with the correct set of keys (decryption token). The routing command is left optional, as it is conceivable that implementations may chose to use trial decryption, and or limit the number of outstanding SURBs to solve this problem.

Sphinx_Create_SURB( additional_data, first_hop, path[] ) ->
             sphinx_surb,
             decryption_token

Inputs:

  • additional_data – The additional data that is visible to every node along the path in the header.

  • first_hop – The node id of the first hop the recipient must use when replying via the SURB.

  • path – The vector of PathHop structures in hop order, specifying the node id, public key, and routing commands for each hop.

Outputs:

  • sphinx_surb – The resulting Sphinx SURB.

  • decryption_token – The decryption token associated with the SURB.

The Sphinx_Create_SURB operation consists of the following steps:

  1. Create the Sphinx packet header and SPRP key vector.

    sphinx_header, payload_keys =
    Sphinx_Create_Header( additional_data, path )
    
  2. Create a key and IV for the final layer of encryption.

    final_key = { key: RNG( SPRP_KEY_LENGTH ), iv: RNG( SPRP_IV_LENGTH ) }
    
  3. Build the SURB and Decryption Token.

    SphinxSURB sphinx_surb;
    sphinx_surb.sphinx_header = sphinx_header
    sphinx_surb.first_hop = first_hop
    sphinx_surb.payload_key = final_key.key
    sphinx_surb.payload_iv = final_key.iv
    
    decryption_token = final_key + payload_keys /* Prepend */
    
Decrypt a Sphinx reply originating from a SURB

A Sphinx reply packet that was generated using a SURB is externally indistinguishable from a forward Sphinx packet as it traverses the network. However, the recipient of the reply has an additional decryption step, the payload starts off encrypted with the SURB’s payload key, and accumulates layers of Sphinx packet payload decryption as it traverses the network.

Determining which decryption token to use when decrypting the SURB reply can be done via the SURBReplyCommand’s id field, if one is included at the time of the SURB’s creation.

Sphinx_Decrypt_SURB_Reply( decryption_token, payload ) -> message

Inputs:

  • decryption_token – The vector of SPRP keys and IVs allowing a client to decrypt the reply ciphertext payload. This decryption_token is generated when the SURB is created.

  • payload – The Sphinx packet ciphertext payload.

Outputs:

  • error – Indicating a unsuccessful unwrap operation if applicable.

  • message – The plaintext message.

The Sphinx_Decrypt_SURB_Reply operation consists of the following steps:

  1. Encrypt the message to reverse the decrypt operations the payload acquired as it traversed the network.

    for i = LEN( decryption_token ) - 1; i > 0; --i:
    payload = SPRP_Encrypt( decryption_token[i].key,
    decryption_token[i].iv, payload )
    
  2. Decrypt and authenticate the message ciphertext.

    message = SPRP_Decrypt( decryption_token[0].key,
    decryption_token[0].iv, payload )
    
    derived_tag = message[:PAYLOAD_TAG_LENGTH]
    expected_tag = ZEROBYTES( PAYLOAD_TAG_LENGTH )
    if !CONSTANT_TIME_CMP( derived_tag, expected_tag ):
    return ErrorInvalidPayload
    
    message = message[PAYLOAD_TAG_LENGTH:]
    

SURB replies

The process for using a SURB to reply anonymously is slightly different from the standard packet creation process, as the Sphinx packet header is already generated (as part of the SURB), and there is an additional layer of Sphinx packet payload encryption that must be performed.

Sphinx_Create_SURB_Reply( sphinx_surb, payload ) -> sphinx_packet

Inputs:

  • sphinx_surb – The SphinxSURB structure, decoded from the implementation defined wire encoding.

  • payload – The packet payload message plaintext. It MUST be exactly PAYLOAD_LENGTH - PAYLOAD_TAG_LENGTH bytes long: the caller pads a shorter message to this length.

The Sphinx_Create_SURB_Reply operation consists of the following steps:

  1. Prepend the authentication tag.

    payload = ZEROBYTES( PAYLOAD_TAG_LENGTH ) | payload
    
  2. Encrypt the payload.

    payload = SPRP_Encrypt( sphinx_surb.payload_key,
    sphinx_surb.payload_iv, payload )
    
  3. Assemble the completed Sphinx packet.

    SphinxPacket sphinx_packet
    sphinx_packet.header = sphinx_surb.sphinx_header
    sphinx_packet.payload = payload
    

The completed sphinx_packet MUST be sent to the node specified via sphinx_surb.first_hop, as the entire reply sphinx_packet’s header is pre-generated.

Anonymity considerations

Optional non-constant length Sphinx packet header padding

Depending on the mix topology, there is no hard requirement that the per-hop routing info is padded to one fixed constant length.

For example, assuming a layered topology (referred to as stratified topology in the literature) MIXTOPO10, where the layer of any given mix node is public information, as long as the following two invariants are maintained, there is no additional information available to an adversary:

  1. All packets entering any given mix node in a certain layer are uniform in length.

  2. All packets leaving any given mix node in a certain layer are uniform in length.

The only information available to an external or internal observer is the layer of any given mix node (via the packet length), which is information they are assumed to have by default in such a design.

Additional data field considerations

The Sphinx packet construct is crafted such that any given packet is bitwise unlinkable after a Sphinx_Unwrap operation, provided that the optional additional data (AD) facility is not used. This property ensures that external passive adversaries are unable to track a packet based on content as it traverses the network. As the on-the-wire AD field is static through the lifetime of a packet (that is, left unaltered by the Sphinx_Unwrap operation), implementations and applications that wish to use this facility MUST NOT transmit AD that can be used to distinctly identify individual packets.

Forward secrecy considerations

Each node acting as a mix MUST regenerate their asymmetric key pair relatively frequently. Upon key rotation the old private key MUST be securely destroyed. As each layer of a Sphinx packet is encrypted via key material derived from the output of an ephemeral/static Diffie-Hellman key exchange, without the rotation, the construct does not provide Perfect Forward Secrecy. Implementations SHOULD implement defense-in-depth mitigations, for example by using strongly forward-secure link protocols to convey Sphinx packets between nodes.

This frequent mix routing key rotation can limit SURB usage by directly reducing the lifetime of SURBs. In order to have a strong Forward Secrecy property while maintaining a higher SURB lifetime, designs such as forward secure mixes SFMIX03 could be used.

Compulsion threat considerations

Reply Blocks (SURBs), forward and reply Sphinx packets are all vulnerable to the compulsion threat, if they are captured by an adversary. The adversary can request iterative decryptions or keys from a series of honest mixes in order to perform a deanonymizing trace of the destination.

While a general solution to this class of attacks is beyond the scope of this document, applications that seek to mitigate or resist compulsion threats could implement the defenses proposed in COMPULS05 via a series of routing command extensions.

SURB usage considerations for volunteer-operated mix networks

Given a hypothetical scenario where Alice and Bob both wish to keep their location on the mix network hidden from the other, and Alice has somehow received a SURB from Bob, Alice MUST not utilize the SURB directly because in the volunteer operated mix network the first hop specified by the SURB could be operated by Bob for the purpose of deanonymizing Alice.

This problem could be solved via the incorporation of a “cross-over point” such as that described in MIXMINION, for example by having Alice delegating the transmission of a SURB Reply to a randomly selected cross-over point in the mix network, so that if the first hop in the SURB’s return path is a malicious mix, the only information gained is the identity of the cross-over point.

Security considerations

Sphinx payload encryption considerations

The payload encryption’s use of a fragile (non-malleable) SPRP is deliberate and implementations SHOULD NOT substitute it with a primitive that does not provide such a property (such as a stream cipher based PRF). In particular there is a class of correlation attacks (tagging attacks) targeting anonymity systems that involve modification to the ciphertext that are mitigated if alterations to the ciphertext result in unpredictable corruption of the plaintext (avalanche effect).

Additionally, as the PAYLOAD_TAG_LENGTH based tag-then-encrypt payload integrity authentication mechanism is predicated on the use of a non-malleable SPRP, implementations that substitute a different primitive MUST authenticate the payload using a different mechanism.

Alternatively, extending the MAC contained in the Sphinx packet header to cover the Sphinx packet payload will both defend against tagging attacks and authenticate payload integrity. However, such an extension does not work with the SURB construct presented in this specification, unless the SURB is only used to transmit payload that is known to the creator of the SURB.

References

COMPULS05

Danezis, G., Clulow, J., “Compulsion Resistant Anonymous Communications”, Proceedings of Information Hiding Workshop, June 2005, https://www.freehaven.net/anonbib/cache/ih05-danezisclulow.pdf.

MIXMINION

Danezis, G., Dingledine, R., Mathewson, N., “Mixminion: Design of a Type III Anonymous Remailer Protocol”, https://www.mixminion.net/minion-design.pdf.

MIXTOPO10

Diaz, C., Murdoch, S., Troncoso, C., “Impact of Network Topology on Anonymity and Overhead in Low-Latency Anonymity Networks”, PETS, July 2010, https://www.esat.kuleuven.be/cosic/publications/article-1230.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC5246

Dierks, T. and E. Rescorla, “The Transport Layer Security (TLS) Protocol Version 1.2”, RFC 5246, DOI 10.17487/RFC5246, August 2008, http://www.rfc-editor.org/info/rfc5246.

SFMIX03

Danezis, G., “Forward Secure Mixes”, Proceedings of 7th Nordic Workshop on Secure IT Systems, 2002, https://www.freehaven.net/anonbib/cache/Dan:SFMix03.pdf.

SPHINX09

Danezis, G., Goldberg, I., “Sphinx: A Compact and Provably Secure Mix Format”, DOI 10.1109/SP.2009.15, May 2009, https://cypherpunks.ca/~iang/pubs/Sphinx_Oakland09.pdf.

2.16 -

For the application, kpclientd and gateway arrangement, see client software and configuration. kpclientd verifies consensus documents using the directory authority protocol.

Thin client specification

David Stainton

Abstract

This document describes the design of the new Katzenpost mixnet thin client. In particular we discuss its multiplexing and privilege-separation design elements as well as the protocol used by the thin-client library.


Introduction

A Katzenpost mixnet client has several responsibilities at a minimum:

  • composing Sphinx packets

  • decrypting SURB replies

  • sending and receiving Noise protocol messages

  • keeping up to date with the latest PKI document

The thin-client library enables applications to talk with the connector daemon and in that way interact with the mix network. The library itself does not do any mixnet-related cryptography since that is already handled by the thin-client daemon. In particular, the daemon strips cryptographic signatures from the PKI document before passing data to clients using the connector library. Noise- and Sphinx-related cryptography are also handled by the daemon.

Thin-client library and daemon protocol

The thin-client daemon protocol uses a local network socket, either a Unix domain socket or TCP.

Messages

There are two protocol message types, both CBOR encoded.

  • The client sends Request messages.

  • The daemon sends Response messages.

Messages are length-prefixed CBOR blobs, that is, a blob is prefixed with a big-endian unsigned four-byte integer (uint32) that encodes the blob length.

Protocol description

The protocol has two phases.

Phase 1

Upon connecting to the daemon socket, the thin client waits for two messages.

  • First message

    • The is_status field must be set to true

    • The is_connected field must indicate whether or not the daemon has a mixnet PQ Noise protocol connection to a mixnet gateway node.

  • Second message

    • The message contains the PKI document in its payload field. This marks the end of the initial connection sequence.

    • The PKI document is stripped of cryptographic signatures as noted above.

Phase 2

  • The thin client may send Request messages to the daemon, which encapsulates the provided payload in a Sphinx packet and sends it to the gateway node.

  • The daemon may send Response messages to the client at any time during this phase. Response messages may communicate a connection status change, a new PKI document, or a message-sent or message-reply event.

2.17 -

The Namenlos profile defines the v0.0.107 link KEM, handshake, authentication payloads, and transport keys. The directory wire protocol defines directory commands and consensus retrieval over direct authority or persistent gateway sessions.

Mix network wire protocol specification

Yawning Angel

David Stainton

Abstract

This document defines the Katzenpost mix network wire protocol for use in all network communications to, from, and within the Katzenpost Mix Network.


Conventions used in this document

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in the section called “References”.

The “C” style Presentation Language as described in the section called “References” Section 4 is used to represent data structures, except for cryptographic attributes, which are specified as opaque byte vectors.

x | y denotes the concatenation of x and y.

Introduction

The Katzenpost mix network wire protocol (KMNWP) is the custom wire protocol for all network communications to, from, and within the Katzenpost mix network. This protocol provides mutual authentication along with an additional layer of cryptographic security and forward secrecy.

Key encapsulation mechanism

This protocol uses ANY key encapsulation mechanism. However, it is recommended that most users select a hybrid post-quantum KEM such as Xwing. the section called “References”

Core protocol

The protocol is based on Kyber and Trevor Perrin’s Noise protocol framework the section called “References” along with “Post Quantum Noise” paper PQNOISE. Older previous versions of our transport were based on NOISEHFS.

Our transport protocol begins with a prologue, Noise handshake, followed by a stream of Noise transport messages in a minimal framing layer, over a TCP/IP connection.

The TOML configuration selects the KEM. This protocol string gives an Xwing example:

Noise_pqXX_Xwing_ChaChaPoly_BLAKE2b

Namenlos uses the canonical KEM name Kyber768-X25519 in its protocol name. The baseline KEM profile defines its key encodings, adapter, and combiner.

The protocol string is a very condensed description of our protocol. We use the pqXX two-way Noise pattern which is described as follows:

pqXX: -> e <- ekem, s -> skem, s <- skem

The next part of the protocol string specifies the KEM, Xwing which is a hybrid KEM where the share secret outputs of both X25519 and MLKEM768 are combined.

Finally the ChaChaPoly_BLAKE2b parts of the protocol string indicate which stream cipher and hash function we are using.

Katzenpost permits larger transport messages than Noise’s 65535-byte default. Directory sessions apply the configured receive size ceiling.

Each peer has a static key pair for the configured KEM. The authentication rules determine whether a peer needs a configured key pin.

Handshake phase

All sessions start in the handshake phase, in which an anonymous authenticated handshake is conducted.

The pqXX handshake starts with a fixed prologue before the initiator’s first Noise message. Both peers also use this byte as the Noise prologue input.

The prologue is defined to be the following structure:

struct {
uint8_t protocol_version; /* 0x03 */
} Prologue;

As all Noise handshake messages are fixed sizes, no additional framing is required for the handshake.

Implementations MUST preserve the Noise handshake hash [h] for the purpose of implementing authentication (Section 2.3).

Implementations MUST reject handshake attempts by terminating the session immediately upon any Noise protocol handshake failure and when, as a responder, they receive a Prologue containing an unknown protocol_version value.

Implementations SHOULD impose reasonable timeouts for the handshake process, and SHOULD terminate sessions that are taking too long to handshake.

Handshake authentication

Mutual authentication is done via exchanging fixed sized payloads as part of the pqXX handshake consisting of the following structure:

struct {
uint8_t ad_len;
opaque additional_data[ad_len];
opaque padding[255 - ad_len];
uint32_t unix_time;
} AuthenticateMessage;

Where:

  • ad_len - The length of the optional additional data.

  • additional_data - Optional additional data, such as a username, if any.

  • unix_time - 0 for the initiator, the approximate number of seconds since 1970-01-01 00:00:00 UTC for the responder.

The responder sends AuthenticateMessage in flight 2. The initiator sends it in flight 3. The four-flight profile defines the tokens, payloads, and byte counts. The authentication payload profile defines the padding, integer encoding, and role-specific additional data.

The receiver MUST authenticate the remote static link key and additional data under the peer’s role. If authentication fails, the receiver MUST terminate the session immediately.

The responder sends its current time in whole seconds as unix_time.

Data transfer phase

Upon successfully concluding the handshake the session enters the data transfer phase, where the initiator and responder can exchange KMNWP messages.

A KMNWP message is defined to be the following structure:

enum {
no_op(0),
disconnect(1),
send_packet(2),

(255),
} Command;

struct {
Command command;
uint8_t reserved;    /* MUST be '0x00' */
uint32_t msg_length; /* bounded by the session message limit */
opaque message[msg_length];
opaque padding[];    /* length is implicit */
} Message;

Notes:

  • The padding field, if any MUST be padded with '0x00' bytes.

All outgoing Message(s) are encrypted and authenticated into a pair of Noise Transport messages, each containing one of the following structures:

struct {
uint32_t ciphertext_length;
} CiphertextHeader;

struct {
opaque message[ciphertext_length-16];
} Ciphertext;

Notes:

  • The ciphertext_length field includes the Noise protocol overhead of 16 bytes, for the Noise Transport message containing the Ciphertext.

All outgoing Message(s) are preceded by a Noise Transport Message containing a CiphertextHeader, indicating the size of the Noise Transport Message transporting the Message Ciphertext. After generating both Noise Transport Messages, the sender MUST call the Noise CipherState Rekey() operation.

To receive incoming Ciphertext messages, first the Noise Transport Message containing the CiphertextHeader is consumed off the network, authenticated and decrypted, giving the receiver the length of the Noise Transport Message containing the actual message itself. The second Noise Transport Message is consumed off the network, authenticated and decrypted, with the resulting message being returned to the caller for processing. After receiving both Noise Transport Messages, the receiver MUST call the Noise CipherState Rekey() operation.

Implementations MUST immediately terminate the session any of the DecryptWithAd() operations fails.

Implementations MUST immediately terminate the session if an unknown command is received in a Message, or if the Message is otherwise malformed in any way.

Implementations MAY impose a reasonable idle timeout, and terminate the session if it expires.

Predefined commands

The no_op command

The no_op command is a command that explicitly is a No Operation, to be used to implement functionality such as keep-alives and or application layer padding.

Implementations MUST NOT send any message payload accompanying this command, and all received command data MUST be discarded without interpretation.

The disconnect command

The disconnect command is a command that is used to signal explicit session termination. Upon receiving a disconnect command, implementations MUST interpret the command as a signal from the peer that no additional commands will be sent, and destroy the cryptographic material in the receive CipherState.

While most implementations will likely wish to terminate the session upon receiving this command, any additional behavior is explicitly left up to the implementation and application.

Implementations MUST NOT send any message payload accompanying this command, and MUST not send any further traffic after sending a disconnect command.

The send_packet command

The send_packet command is the command that is used by the initiator to transmit a Sphinx Packet over the network. The command’s message is the Sphinx packet destined for the responder.

Initiators MUST terminate the session immediately upon reception of a send_packet command.

Command padding

We use traffic padding to prevent a passive network observer from observing what command has been sent or received. The following commands are padded:

Client-to-server commands

  • GetConsensus

  • NoOp

  • Disconnect

  • SendPacket

  • RetrieveMessage

Server-to-client commands

  • MessageACK

  • Message

  • MessageEmpty

We exclude the Consensus command because its contents are a very large payload that is usually many times larger than our Sphinx packets.

The GetConsensus command is a special case because we only pad it when sending it over the mixnet. We don’t pad it when sending to directory authorities, because that would needlessly take up bandwidth without providing privacy benefits.

Anonymity considerations

Adversaries being able to determine that two parties are communicating via KMNWP is beyond the threat model of this protocol. At a minimum, it is trivial to determine that a KMNWP handshake is being performed, due to the length of each handshake message, and the fixed positions of the various public keys.

Security considerations

Each handshake MUST use a fresh ephemeral key pair. Each KEM encapsulation MUST use fresh randomness. Static link keys identify peers under the authentication rules.

Kyber was chosen as the KEM algorithm due to it’s conservative parameterization, simplicity of implementation, and high performance in software. It is hoped that the addition of a quantum resistant algorithm will provide forward secrecy even in the event that large scale quantum computers are applied to historical intercepts.

Acknowledgments

I would like to thank Trevor Perrin for providing feedback during the design of this protocol, and answering questions regarding Noise.

References

NOISE

Perrin, T., “The Noise Protocol Framework”, May 2017, https://noiseprotocol.org/noise.pdf.

NOISEHFS

Weatherley, R., “Noise Extension: Hybrid Forward Secrecy”, https://github.com/noiseprotocol/noise_hfs_spec/blob/master/output/noise_hfs.pdf.

PQNOISE

Yawning Angel, Benjamin Dowling, Andreas Hülsing, Peter Schwabe and Florian Weber, “Post Quantum Noise”, September 2023, https://eprint.iacr.org/2022/539.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC5246

Dierks, T. and E. Rescorla, “The Transport Layer Security (TLS) Protocol Version 1.2”, RFC 5246, DOI 10.17487/RFC5246, August 2008, http://www.rfc-editor.org/info/rfc5246.

RFC7748

Langley, A., Hamburg, M., and S. Turner, “Elliptic Curves for Security”, RFC 7748, January 2016, https://www.rfc-editor.org/info/rfc7748.

XWING

Manuel Barbosa, Deirdre Connolly, João Diogo Duarte, Aaron Kaiser, Peter Schwabe, Karoline Varner, Bas Westerbaan, “X-Wing: The Hybrid KEM You’ve Been Looking For”, https://eprint.iacr.org/2024/039.pdf.

Appendix: Namenlos wire profile

This profile defines the Namenlos link KEM and handshake with Katzenpost v0.0.107. Implementations MUST use these formats with that configuration. The linked primitive specifications define X25519, Kyber, BLAKE2, and ChaCha20-Poly1305. The composition rules below define their use on the wire.

Here, || means byte concatenation, empty means zero bytes, and zero[n] means n zero bytes. BE32, LE32, and LE64 encode unsigned integers in the indicated byte order. ASCII literals have no terminating zero.

H256 means unkeyed BLAKE2b with a 32-byte output. H512 means unkeyed BLAKE2b with a 64-byte output. Configure BLAKE2b-256 for 32 output bytes. Do not truncate BLAKE2b-512 to produce BLAKE2b-256. Both use the sequential mode in RFC 7693.

Key Value Explanation
Wire KEM Kyber768-X25519 This is the canonical name used in the Noise protocol name. Configuration lookup also accepts the Namenlos spelling KYBER768-X25519.
Public key 1216 bytes X25519 public key, 32 bytes, followed by Kyber768 public key, 1184 bytes.
Private key 2432 bytes X25519 scalar, 32 bytes, followed by Kyber768 secret key, 2400 bytes.
Ciphertext 1120 bytes X25519 adapter ciphertext, 32 bytes, followed by Kyber768 ciphertext, 1088 bytes.
Shared secret 32 bytes The combiner output defined below.

Keys use raw component encodings without ASN.1, text encoding, or length prefixes. X25519 uses the 32-byte little-endian u-coordinate encoding and scalar operation in RFC 7748, Section 5. The scheme definition fixes the component order.

The public PEM label is KYBER768-X25519 PUBLIC KEY. The private PEM label is KYBER768-X25519 PRIVATE KEY. A PEM payload is the base64 encoding of the corresponding raw key. There are no PEM headers or ASN.1 fields. This encoding permits import of reference key files. An implementation can use its own internal storage format.

The PEM codec wraps raw key bytes.

The Kyber component is Kyber768.CCAKEM from the round 3 specification, version 3.02, with its public-key, secret-key, and ciphertext encodings. Use Algorithms 7-9 and the Kyber768 parameters. This is the round 3 Kyber KEM, not ML-KEM. The pinned Kyber implementation identifies that primitive and its sizes.

For the X25519 component, let X_s be the recipient’s public key. Generate a fresh ephemeral scalar x_e and its public key X_e. Compute:

Z    = X25519(x_e, X_s)
ct_X = X_e
ss_X = BLAKE2Xb(output_length=32, key=Z, message=X_s || X_e)

Reject an all-zero Z. Decapsulation computes Z = X25519(x_s, ct_X) and uses the same recipient-public-key-first input. The output length supplied to BLAKE2Xb is exactly 32. Its unknown-length mode produces different bytes and MUST NOT be used here. The adapter defines the inputs. Its PRF selects the fixed-length keyed XOF.

For this invocation, BLAKE2Xb first produces a keyed 64-byte root over X_s || X_e. It then produces one unkeyed 32-byte output block over that root. Each BLAKE2 parameter block is 64 bytes and starts with all bytes zero. Set these fields:

Key Value Explanation
Root bytes 0-3 64, 32, 1, 1 Digest length, key length, fanout, and depth. The key is Z, with standard BLAKE2b key-block padding.
Root bytes 12-15 LE32(32) XOF output length.
Output byte 0 32 Output digest length.
Output bytes 4-7 LE32(64) Leaf length.
Output bytes 8-11 LE32(0) Output block number.
Output bytes 12-15 LE32(32) XOF output length.
Output byte 17 64 Inner digest length.

All unlisted fields, salt, and personalization remain zero. Set the normal final-block flag for each hash. Do not set the last-node flag. The fixed-output BLAKE2Xb implementation gives these parameter blocks.

Encapsulate independently to each component public key. Let (ct_X, ss_X) be the adapter output and (ct_K, ss_K) be the Kyber output. Both component shared secrets are 32 bytes. Define:

T = ASCII("splitprf-v1") || BE32(2)
    || BE32(32) || ct_X || BE32(1088) || ct_K

k_X = H256(ss_X)
k_K = H256(ss_K)
ss  = BLAKE2b-256(key=k_X, message=T)
      XOR BLAKE2b-256(key=k_K, message=T)
ct  = ct_X || ct_K

The two keyed hashes use BLAKE2b’s native keyed mode. They are not HMAC. XOR is bytewise across all 32 bytes.

Decapsulation splits the 1120-byte ciphertext at byte 32, decapsulates both components, and applies the same formula to the received component ciphertexts. Reject an incorrect total length or an error from either component. Kyber’s implicit-rejection behavior remains part of the Kyber primitive. The combiner definition fixes the label, length fields, prehashes, and XOR.

PQ Noise handshake

Use the symmetric operations from Noise revision 34, with the KEM token rules below. The exact protocol name is the following 45 ASCII bytes:

Noise_pqXX_Kyber768-X25519_ChaChaPoly_BLAKE2b

There are no pre-messages or pre-shared keys. Both peers have a static link KEM key pair. An anonymous fetcher generates one fresh link key pair per fetch and uses it for every authority connection of that fetch. The initiator also generates a fresh ephemeral KEM key pair for token e. Each KEM encapsulation uses fresh randomness.

Initialize h to the protocol name followed by 19 zero bytes. Copy this value to ck. Start with no cipher key and nonce zero. Then set h = H512(h || 0x03).

The single byte 0x03 is the Noise prologue and is also sent in clear before the first flight. It is not a token or payload byte. The responder MUST reject any other version byte.

The following rules define the symmetric operations. HMAC uses BLAKE2b-512. For HKDF(ck, input, count), compute:

prk = HMAC-BLAKE2b-512(key=ck, message=input)
t1  = HMAC-BLAKE2b-512(key=prk, message=0x01)
t2  = HMAC-BLAKE2b-512(key=prk, message=t1 || 0x02)
t3  = HMAC-BLAKE2b-512(key=prk, message=t2 || 0x03)

Return the first count values, each 64 bytes. No HKDF info bytes are present.

Key Value Explanation
MixHash(x) h = H512(h || x) This operation also runs when x is empty.
MixKey(x) (ck, t) = HKDF(ck, x, 2) Set the cipher key to the first 32 bytes of t, and reset the nonce to zero.
MixKeyAndHash(x) (ck, u, t) = HKDF(ck, x, 3) Run MixHash(u), set the cipher key to the first 32 bytes of t, and reset the nonce to zero.
EncryptAndHash(p) Encrypt p with associated data h, then run MixHash(ciphertext) Without a cipher key, use p unchanged as the ciphertext.
DecryptAndHash(c) Decrypt c with associated data equal to the prior h, then run MixHash(c) Without a cipher key, the plaintext is c. Reject an AEAD failure.

Encryption uses IETF ChaCha20-Poly1305, a 32-byte key, and the 12-byte nonce zero[4] || LE64(n). Its 16-byte tag follows the ciphertext. Increase n after each keyed encryption or successful keyed decryption. Do not increase it for an unkeyed operation. A normal encryption or decryption MUST fail when n = 2^64-1.

The symmetric-state implementation defines these operations. The cipher implementation fixes the AEAD and nonce bytes.

Each flight processes its tokens in order, then calls EncryptAndHash on its payload. The receiver performs the inverse operations in the same order.

Key Value Explanation
e Raw ephemeral public key, 1216 bytes Send the initiator’s ephemeral KEM public key, and run MixHash on those bytes.
ekem Raw KEM ciphertext, 1120 bytes Encapsulate to the peer’s ephemeral key. Send the ciphertext, run MixHash(ciphertext), then MixKey(shared_secret). The receiver decapsulates with its ephemeral private key.
s EncryptAndHash(static_public_key) Send the sender’s 1216-byte static link public key. The receiver decrypts it and retains it as the peer’s static key.
skem EncryptAndHash(KEM_ciphertext) Encapsulate to the peer’s static key. Encrypt and hash the ciphertext with the current cipher state, then run MixKeyAndHash(shared_secret). The receiver decrypts, decapsulates with its static private key, then runs MixKeyAndHash.

The pqXX pattern and KEM token processing define this order. In particular, skem updates both ck and h after its encrypted ciphertext.

Let P=1216, C=1120, A=260, and T=16. Each length below is an exact stream byte count. There is no handshake length prefix or padding outside the stated fields.

Key Value Explanation
Flight 1, initiator -> responder 0x03, e, empty payload. 1217 bytes. 1+P. The empty payload emits no bytes but still runs MixHash(empty).
Flight 2, responder -> initiator ekem, s, responder authentication. 2628 bytes. C + (P+T) + (A+T). After ekem, the static key and payload use nonces 0 and 1.
Flight 3, initiator -> responder skem, s, initiator authentication. 2644 bytes. (C+T) + (P+T) + (A+T). skem uses nonce 2 from flight 2. Its key update resets the nonce, so s and the payload use 0 and 1.
Flight 4, responder -> initiator skem, empty payload. 1152 bytes. (C+T) + T. skem uses nonce 2 from flight 3. Its key update resets the nonce. The empty payload uses nonce 0 and emits a 16-byte tag.

The session uses these flight lengths and payload assignments. The payload operation runs once after every flight’s tokens, including flights 1 and 4.

Authentication payload

An AuthenticateMessage is exactly 260 bytes:

u8(length(AD)) || AD || zero[255-length(AD)] || BE32(unix_time)

AD has 0 to 255 bytes. The timestamp starts at offset 256. The initiator sends timestamp zero. The responder sends its current Unix time in whole seconds, encoded as an unsigned 32-bit value.

Senders MUST set the padding to zero. The v0.0.107 receiver extracts the length, AD, and timestamp. It ignores the padding bytes. The authentication codec defines this layout.

Key Value Explanation
Authority responder 32 raw identity-hash bytes Its static Noise key is its configured link public key.
Authority or node uploading to an authority 32 raw identity-hash bytes The identity hash selects the configured peer. Authority peers also require the pinned link key. Node uploads bind the descriptor link key to this session.
Anonymous direct directory fetcher Empty AD Use one fresh link key pair per fetch. The authority grants the anonymous fetch role.
Client daemon connecting to a gateway 32 lowercase ASCII hexadecimal bytes Encode 16 fresh random bytes as two hex characters per byte. This is the gateway queue identifier. It is not a raw identity hash.

The identity signature profile defines identity hashes. The authority’s responder configuration, initiator configuration, and peer classification distinguish these roles. The client connection defines the queue identifier.

The initiator authenticates the responder after flight 2. It uses the responder’s static key and authentication payload. The responder authenticates the initiator after flight 3.

For an authority responder, the v0.0.107 client requires at least 32 AD bytes. It compares the first 32 bytes with the configured identity hash. It also compares the full static link key with its configured pin. Authority receivers accept only empty or 32-byte initiator AD and apply the role requirements above. Any failed authentication terminates the session. The authority authenticator implements these requirements.

Transport keys and framing

After flight 4’s empty payload, compute (t_I, t_R) = HKDF(ck, empty, 2). The first 32 bytes of t_I are the initiator-to-responder transport key. The first 32 bytes of t_R are the responder-to-initiator key. Each direction starts with nonce zero. Transport encryption uses empty AEAD associated data. It does not continue EncryptAndHash or update the handshake hash.

For each command, encrypt BE32(length(serialized_command)+16) as a separate 20-byte header. Then encrypt the serialized command with the next nonce. Both operations use the same direction’s cipher key. After the body, update that direction’s key to the first 32 bytes of ChaCha20-Poly1305(key, zero[4] || LE64(2^64-1), empty_AD, zero[32]). Keep the ordinary nonce counter at its value after the two frame operations. The receiver follows the same sequence.

The responder’s first transport command MUST be NoOp. The initiator MUST receive it before using the session. The session implements transport sending, rekeying, and handshake finalization.

2.18 -

For the v0.0.107 directory protocol, begin with the directory overview. Its roles and epoch definition supply the directory-specific context.

Glossary


KEM
Key encapsulation mechanism. See the wire KEM interface and KEM Sphinx.

NIKE
Non-interactive key exchange. A party combines its private key with another party’s public key to derive a shared secret. See Sphinx cryptographic primitives and directory scheme selection.

BlockSphinxPlaintext
The payload structure that is encapsulated by the Sphinx body.

classes of traffic
We distinguish the following classes of traffic:

  • SURB replies (sometimes referred to as ACKs)

  • Forwarded messages

client
Software run by a user on their local device to participate in the mixnet. A client is not considered a node in the network for purposes of analysis of the core mnixnet protocols.

directory authority system
The fixed authorities that publish a signed network directory. See the Katzenpost directory authority protocol.

entry mix, entry node
A mix node that has some additional features:

  • An entry mix is always the first hop in routes where the message originates from a client.

  • An entry mix authenticates client’s direct connections via the mixnet’s wire protocol.

  • An entry mix queues reply messages and allows clients to retrieve them later.

epoch
A configured time interval, 20 minutes by default, for which authorities publish a consensus document. See directory epochs and document retention.

family
Identifier of security domains or entities operating one or more mix nodes in the network. This is used to inform the path selection algorithm.

gateway
A mix node on the edge of the mixnet that is the first hop for messages coming from clients. The gateway authenticates client connections and queues reply messages (SURBs) for retrieval.

group
A finite set of elements and a binary operation that satisfy the properties of closure, associativity, invertability, and the presence of an identity element.

group element
An individual element of a group.

group generator
A group element capable of generating any other element of a group, via repeated applications of the generator and the group operation.

header
The packet header consisting of several components which convey the information necessary to verify packet integrity and to correctly process the packet.

KiB
Defined as 1024 8 bit octets.

layer
The layer value indicates which network topology layer a particular mix node resides in.

message
A variable-length sequence of octets sent anonymously through the network. Short messages are sent in a single packet; long messages are fragmented across multiple packets.

mix descriptor
A database record that describes a mixnet server component.

mix node
A cryptographic router that is used to compose a mixnet. Mix nodes use a cryptographic operation on messages being routed which provides bitwise unlinkability with respect to input versus output messages. Katzenpost is a decryption mixnet that uses the Sphinx cryptographic packet format.

mixnet
A mixnet, or mix network, is a network of mix servers that can be used to build various privacy-preserving protocols.

MSL
Maximum segment lifetime, currently set to 120 seconds.

nickname
A component nickname string that must be unique in the consensus document.

node
Clients are NOT considered nodes in the mix network. However, network protocols are often layered. In our design documents, we describe “mixnet hidden services” that can be operated by mixnet clients. Therefore if you are using the term “node” in some adherence to mathematical terminology, one could conceivably designate a client as a node. However, in discussion of our core mixnet protocol, it is inappropriate to refer to clients as nodes.

packet
A Sphinx packet, of fixed length for each class of traffic, carrying a message payload and metadata for routing. Packets are routed anonymously through the mixnet and cryptographically transformed at each hop.

payload
The fixed-length portion of a packet containing an encrypted message or part of a message, to be delivered anonymously.

PKI
Public key infrastructure.

SEDA
Staged Event Driven Architecture. 1. A highly parallelizable computation model. 2. A computational pipeline composed of multiple stages connected by queues utilizing active queue-management algorithms that can evict items from a queue based on dwell time or other criteria where each stage is a thread pool. 3. The only correct way to efficiently implement a software based router on general purpose computing hardware.

service node
A service node is a mix node with additional features:

  • A service node is always the last hop in routes where the message originates from a client.

  • A service node runs mixnet services which use a Sphinx SURB-based protocol.

SURB
Single use reply block. SURBs are used to achieve recipient anonymity, that is to say, SURBs function as a cryptographic delivery token that you can give to another client entity so that they can send you a message without them knowing your identity or location on the network. See SPHINXSPEC and SPHINX.

user
An agent using the Katzenpost system.

wire protocol
Refers to our PQ Noise-based protocol that currently uses TCP but in the near future will optionally use QUIC. This protocol has messages known as wire protocol commands, which are used for various mixnet functions such as sending or retrieving a message and dirauth voting. For more information, see our wire protocol specification.

2.19 -

References


AB96

Anderson, R., Biham, E., “Two Practical and Provably Secure Block Ciphers: BEAR and LION”, 1996.

AEZV5

Hoang, V., Krovetz, T., Rogaway, P., “AEZ v5: Authenticated Encryption by Enciphering”, March 2017, http://web.cs.ucdavis.edu/~rogaway/aez/aez.pdf.

BRIDGING

Danezis, G., Syverson, P., “Bridging and Fingerprinting: Epistemic Attacks on Route Selection”, Proceedings of PETS 2008, Leuven, Belgium, July 2008, https://www.freehaven.net/anonbib/cache/danezis-pet2008.pdf.

COMPULS05

Danezis, G., Clulow, J., “Compulsion Resistant Anonymous Communications”, Proceedings of Information Hiding Workshop, June 2005, https://www.freehaven.net/anonbib/cache/ih05-danezisclulow.pdf.

ED25519

https://www.rfc-editor.org/rfc/rfc8032.

FINGERPRINTING

Danezis, G., Clayton, R., “Route Finger printing in Anonymous Communications”, https://www.cl.cam.ac.uk/~rnc1/anonroute.pdf.

KATZMIXNET

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Specification”, June 2017, https://katzenpost.network/docs/specs/pdf/mixnet.pdf.

KATZMIXPKI

Angel, Y., Piotrowska, A., Stainton, D., “Katzenpost Mix Network Public Key Infrastructure Specification”, December 2017, https://katzenpost.network/docs/specs/pdf/pki.pdf.

The Directory authority specification describes the current protocol and its relation to this design.

KATZMIXWIRE

Angel, Y., “Katzenpost Mix Network Wire Protocol Specification”, June 2017, https://katzenpost.network/docs/specs/pdf/wire.pdf.

KEMCOMB

Federico Giacon, Felix Heuer, Bertram Poettering, “KEM Combiners”, 2018, https://link.springer.com/chapter/10.1007/978-3-319-76578-5_7

LOCALVIEW

Gogolewski, M., Klonowski, M., Kutylowsky, M., “Local View Attack on Anonymous Communication”, https://cs.pwr.edu.pl/kutylowski/articles/LocalView-WWW.pdf.

LOOPIX

Piotrowska, A., Hayes, J., Elahi, T., Meiser, S., Danezis, G., “The Loopix Anonymity System”USENIX, August 2017, https://arxiv.org/pdf/1703.00536.pdf.

MIRANDA

Leibowitz, H., Piotrowska, A., Danezis, G., Herzberg, A., “No right to remain silent: Isolating Malicious Mixes”, 2017, https://eprint.iacr.org/2017/1000.pdf.

MIXMINION

Danezis, G., Dingledine, R., Mathewson, N., “Mixminion: Design of a Type III Anonymous Remailer Protocol”, https://www.mixminion.net/minion-design.pdf.

MIXMINIONDIRAUTH

Danezis, G., Dingledine, R., Mathewson, N., “Type III (Mixminion) Mix Directory Specification”, December 2005, https://www.mixminion.net/dir-spec.txt.

MIXRELIABLE

Dingledine, R., Freedman, M., Hopwood, D., Molnar, D., “A Reputation System to Increase MIX-Net Reliability”, 2001, Information Hiding, 4th International Workshop, https://www.freehaven.net/anonbib/cache/mix-acc.pdf.

MIXTOPO10

Diaz, C., Murdoch, S., Troncoso, C., “Impact of Network Topology on Anonymity and Overhead in Low-Latency Anonymity Networks”, PETS, July 2010, https://www.esat.kuleuven.be/cosic/publications/article-1230.pdf.

MPRA11

Maines, L., Piva, M., Rimoldi, A., Sala, M., “On the provable security of BEAR and LION schemes”, May 2011, arXiv:1105.0259, https://arxiv.org/abs/1105.0259.

NOISE

Perrin, T., “The Noise Protocol Framework”, May 2017, https://noiseprotocol.org/noise.pdf.

NOISEHFS

Weatherley, R., “Noise Extension: Hybrid Forward Secrecy”, https://github.com/noiseprotocol/noise_hfs_spec/blob/master/output/noise_hfs.pdf.

PEERFLOW

Johnson, A., Jansen, R., Segal, A., Syverson, P., “PeerFlow: Secure Load Balancing in Tor”, July 2017, Proceedings on Privacy Enhancing Technologies, https://petsymposium.org/2017/papers/issue2/paper12-2017-2-source.pdf.

PQNOISE

Yawning Angel, Benjamin Dowling, Andreas Hülsing, Peter Schwabe and Florian Weber, “Post Quantum Noise”, September 2023, https://eprint.iacr.org/2022/539.pdf.

RFC2119

Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, http://www.rfc-editor.org/info/rfc2119.

RFC5246

Dierks, T. and E. Rescorla, “The Transport Layer Security (TLS) Protocol Version 1.2”, RFC 5246, DOI 10.17487/RFC5246, August 2008, http://www.rfc-editor.org/info/rfc5246.

RFC5322

Resnick, P., Ed., “Internet Message Format”, RFC 5322, DOI 10.17487/RFC5322, October 2008, https://www.rfc-editor.org/info/rfc5322.

RFC6234

Eastlake 3rd, D. and T. Hansen, “US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)”, RFC 6234, DOI 10.17487/RFC6234, May 2011, https://www.rfc-editor.org/info/rfc6234.

RFC7049

C. Bormann, P. Hoffman, “Concise Binary Object Representation (CBOR)”, Internet Engineering Task Force (IETF), October 2013, https://www.rfc-editor.org/info/rfc7049.

RFC7515

Jones, M., Bradley, J., Sakimura, N., “JSON Web Signature (JWS)”, May 2015, https://www.rfc-editor.org/info/rfc7515.

RFC7539

Nir, Y. and A. Langley, “ChaCha20 and Poly1305 for IETF Protocols”, May 2015, RFC 7539, DOI 10.17487/RFC7539, http://www.rfc-editor.org/info/rfc7539.

RFC7693

Saarinen, M-J., Ed., and J-P. Aumasson, “The BLAKE2 Cryptographic Hash and Message Authentication Code (MAC)”, RFC 7693, DOI 10.17487/RFC7693, November 2015, http://www.rfc-editor.org/info/rfc7693.

RFC7748

Langley, A., Hamburg, M., and S. Turner, “Elliptic Curves for Security”, RFC 7748, January 2016, https://www.rfc-editor.org/info/rfc7748.

SECNOTSEP

Miller, M., Tulloh, B., Shapiro, J., “The Structure of Authority: Why Security Is not a Separable Concer”, http://www.erights.org/talks/no-sep/secnotsep.pdf.

SEDA

Welsh, M., Culler, D., Brewer, E., “SEDA: An Architecture for Well-Conditioned, Scalable Internet Services”, 2001, ACM Symposium on Operating Systems Principles, http://www.sosp.org/2001/papers/welsh.pdf.

SFMIX03

Danezis, G., “Forward Secure Mixes”, Proceedings of 7th Nordic Workshop on Secure IT Systems, 2002, https://www.freehaven.net/anonbib/cache/Dan:SFMix03.pdf.

SP80038A

Dworkin, M., “Recommendation for Block Cipher Modes of Operation”, SP800-38A, 10.6028/NIST.SP.800, December 2001, https://doi.org/10.6028/NIST.SP.800-38A.

SPHINCS256

Bernstein, D., Hopwood, D., Hulsing, A., Lange, T., Niederhagen, R., Papachristodoulou, L., Schwabe, P., Wilcox O’Hearn, Z., “SPHINCS: practical stateless hash-based signatures”, http://sphincs.cr.yp.to/sphincs-20141001.pdf.

SPHINX09

Danezis, G., Goldberg, I., “Sphinx: A Compact and Provably Secure Mix Format”, DOI 10.1109/SP.2009.15, May 2009, https://cypherpunks.ca/~iang/pubs/Sphinx_Oakland09.pdf.

SPHINXSPEC

Angel, Y., Danezis, G., Diaz, C., Piotrowska, A., Stainton, D., “Sphinx Mix Network Cryptographic Packet Format Specification”, July 2017, https://katzenpost.network/docs/specs/pdf/sphinx.pdf.

TORDIRAUTH

“Tor directory protocol, version 3”, https://spec.torproject.org/dir-spec/index.html.

TORSRV

“Tor Shared Random Subsystem Specification”, https://spec.torproject.org/srv-spec/index.html.

XWING

Manuel Barbosa, Deirdre Connolly, João Diogo Duarte, Aaron Kaiser, Peter Schwabe, Karoline Varner, Bas Westerbaan, “X-Wing: The Hybrid KEM You’ve Been Looking For”, https://eprint.iacr.org/2024/039.pdf.

2.20 -

katzenqt1 chat over Reticulum

katzenqt1 is the group chat protocol of katzenqt, hushphone, jam, frank_chat and katzenrns. It is CBOR messages of a few types, each written as one BACAP box in the writer’s own stream. A client keeps a read capability and an index for every member and reads each member’s next box; acknowledgements inside the messages tell it where others have got to. All of that logic is in a sans-IO state machine, written once per language, and the same machine runs on the Katzenpost mixnet and on a Reticulum mesh. What differs is the transport beneath it: on the mixnet the client daemon does BACAP and carries the boxes; on a mesh the transport does BACAP itself and sends the boxes of Pigeonhole protocols over Reticulum. So a new mesh client is a transport, or a transport and a state machine that matches these:

language repository state machine
Lean katzenpost/cryptlib Cryptlib/Protocols/GroupComm/GroupChatKatzenqt1/Member/
Rust katzenpost/pigeonhole_protocols rust/src/protocols/katzenqt1/member/
Go katzenpost/pigeonhole_protocols go/protocols/katzenqt1/member/
Python katzenpost/pigeonhole_protocols py/pigeonhole_protocols/katzenqt1/member/

The transports written so far, one interface per language, which the state machine’s engine drives:

transport who does BACAP implementations
Katzenpost mixnet, through kpclientd the client daemon Rust rust/src/transport/thinclient/, Go go/transport/thinclient/, Lean GroupChatKatzenqt1/Daemon.lean in katzenpost/group_chat_client
Reticulum mesh the transport, with hpqc Python transport/reticulum.py and katzenrns/transport.py over pigeonhole_rns, Rust reticulum_rs.rs on Reticulum-rs and reticulum_py.rs over the Python one
in memory, for tests the transport Rust sim.rs, Go go/transport/sim/, Python transport/sim.py, Lean GroupChatKatzenqt1/Sim.lean

The interface itself: Rust transport/mod.rs, Go transport/transport.go, Python transport/base.py, Lean GroupChatKatzenqt1/Backend.lean.

The protocol’s rules, rosters, acknowledgements, backfill, numbering and rewrite, are the Group chat specification; vouchers are the Contact voucher specification.

This document gives versions 4 and 5 of the wire format. Version 5 is version 4 with one more message type, packed texts. Readers accept version 3 as well, whose encodings are at the end. A client has one setting, the wire version it writes, 3, 4 or 5 (default 5): it chooses the encoding of the messages and ReplyWho the client writes and the voucher form it mints, compact under 4 and 5. Answering someone else’s voucher always follows that voucher’s form. A group can mix members writing any of these versions; a reader of version 4 cannot show packed texts.

Model

  • A member is a BACAP stream that it alone writes. Its key is the first 32 bytes of its read capability.
  • A group is a set of members. Reading the group is reading every member’s stream from the position given for it.
  • Membership changes are Introductions written in members’ streams. Every box carries its writer’s membership hash.
  • A newcomer joins through a voucher that a member answers.
  • The mesh has no copy command: every box is written directly, in the order given here.

What the state machine asks of the transport

operation on the mesh
new stream a fresh write capability
write box (write capability, index, plaintext) pad, encrypt, sign, write query; ALREADY_EXISTS is a refusal
read box (read capability, index) read query: NOT_FOUND, TOMBSTONE, or the plaintext
watch box (read capability, index) after a miss, subscribe to its Box ID when the replica serves push; false otherwise
next index the BACAP derivation
epoch ⌊(now − 1496275200) / 604800⌋
box size the one the group’s members pad to
voucher mint, derive stream, induct, open below

Vouchers

voucher 32 bytes, BLAKE2b-256 of the VoucherPayload; shown and carried as standard base64
voucher stream a write capability generated from SHAKE256(voucher): Ed25519 seed 32 bytes, KDF state 32, counter 16
box 0 the VoucherPayload, at the stream’s first index
boxes 1 on the sealed VoucherReply, framed, from the next index
forms compact, minted under wire versions 4 and 5; long, the version 3 form, minted under 3
seal sealed box over the hybrid NIKE X25519 then CTIDH1024, CTIDH1024-X25519
salt 32 bytes

The newcomer:

  1. Makes a stream S and a seal keypair (sk, pk).
  2. Signs [S’s read capability, pk, display name], as CBOR, with S’s root key (Ed25519), and builds VoucherPayload [S’s read capability, pk, display name, signature]. voucher = BLAKE2b-256 of its bytes.
  3. Writes the VoucherPayload to box 0, at the smallest allowed box size that holds it, 1549 on a mesh. Gives the voucher away.
  4. Reads box 1, then each next box while the one before began with C. NOT_FOUND: wait. TOMBSTONE: withdrawn, the join failed. The boxes’ bytes after their first byte, joined, are the sealed reply: open with sk, giving VoucherReply [WhoReply, salt].
  5. Mutates S’s write capability KDF state by the salt and writes the group there from its first index. WhoReply is a ReplyWho: reads each member from the position it gives.

A member answering the voucher:

  1. Derives the voucher stream and reads box 0. NOT_FOUND: wait. TOMBSTONE: withdrawn.
  2. Checks BLAKE2b-256(payload) = voucher, and the signature under the root key in the payload’s read capability. Otherwise stops.
  3. Draws a 32 byte salt. The newcomer’s live read capability is the payload’s read capability with its KDF state mutated by the salt. Builds the ReplyWho: every member with the position the newcomer starts from, its own stream at the index its Introduction will occupy.
  4. Writes Introduction [display name, live read capability] to its own stream at that index, ahead of anything queued.
  5. Seals VoucherReply [WhoReply, salt] to pk, cuts the sealed bytes into pieces of the box size less one, and writes them from box 1 on, each behind C, the last behind F, each until a replica holds it. ALREADY_EXISTS on box 1: another member answered; stop.
  6. Reads the newcomer at the live read capability from its first index.

A member answers one voucher at a time. Box 0 is left as written; the voucher is spent once box 1 exists. A payload in the version 3 form, a CBOR map, is answered wholly in version 3: the map form of the ReplyWho, sealed with the MKEM, unframed, in box 1 alone.

ReplyWho

A CBOR array of one to five elements; trailing Nones are left out.

struct ReplyWho(
    /// One per place: `None` for a member the sender cannot name.
    Vec<Option<PleaseAdd>>,
    /// One per place, the member's roster; `None` while unknown.
    Option<Vec<Option<Vec<RosterEntry>>>>,
    Option<Vec<IntroAt>>,
    /// The sender's place.
    Option<usize>,
    /// The newcomer's place: the number of places.
    Option<usize>,
);
struct PleaseAdd(String, [u8; 136]);        // [display_name of 1 to 30 characters, read_cap]: key, then the start index
struct RosterEntry(usize, Option<usize>);   // [roster index, place]
struct IntroAt(usize, [u8; 104], usize);    // [by, index, member]

A reply is refused when a place’s name is empty or longer than 30 characters or its read capability is not 136 bytes. Without rosters, the newcomer takes the places named, the first as introducer, every roster unknown. With rosters, the reply is refused when the newcomer’s place is not the number of places, the introducer’s is not below it, there are 256 places or more, two places share a key, a roster names a place that does not exist, or the introducer’s place is None.

A pigeonhole service that admits a client answers with one place and no rosters.

Boxes

plaintext meaning
F, GroupChatMessage CBOR a message
empty tombstone: the message was deleted, step past
C, bytes a chunk of a long message, in its own stream
I, 4 byte big endian chunk count, 136 byte read capability of the chunk stream; or I and the read capability a long message: its chunks are C boxes ending in an F box

A message fits the box size less one byte. A reader that does not fetch chunks steps past an I box.

GroupChatMessage, a CBOR array of four to seven elements; trailing Nones are left out:

struct GroupChatMessage(
    u64,                 // version: 4 or 5
    [u8; 32],            // membership_hash
    u64,                 // msg_type, below
    Body,                // the type's payload; None for control
    Option<Vec<u8>>,     // acks, layout under Encoding
    Option<Vec<u8>>,     // numbers, layout under Encoding
    Option<Vec<u8>>,     // introduced_at, layout under Encoding
);
enum Body {
    Text(String),                                   // type 0
    Introduction(String, [u8; 136]),                // type 1: [display_name, read_cap]
    FileUpload(Vec<u8>, String, String),            // type 2: [payload, filetype, basename]
    Who(Value), ReplyWho(Value), Tally(Value),      // types 3, 4, 5 to 9: as the app defines
    None,                                           // types 10 and 11
    Packed(Vec<String>),                            // type 12, version 5
}
msg_type message body
0 text the text
1 introduction [display_name of 1 to 30 characters, read_cap]
2 file upload [payload, filetype, basename]
3 who the app’s value
4 reply who the app’s value
5 to 9 tally the app’s value
10 control None; only acks, numbers, introduced_at
11 ping None
12 packed texts [text, …], one or more; version 5 only

Any message may carry acks, numbers and introduced_at. A ping is content with no body: its readers play their ping sound and show that the sender pinged, instead of a line of text.

A packed box holds several texts in the order they were sent, and reads as that many messages.

A reader refuses a message of a version above its own, of a type above 12, or of type 12 in a version below 5; a reader built for version 4 therefore refuses a packed box, with the texts and acknowledgements in it. When a refused message is in the array form and its first three elements are a version, a byte string and a type, the client tells the user who sent it, its type and its version, and that the app needs updating, rather than dropping it silently.

membership_hash = SHA-256(KP:membership:v1 ‖ the members’ keys, each once, in byte order, one’s own included). The sentinel for an unknown membership is 32 zero bytes; readers also accept TODO repeated to 32 bytes. Content carries the hash as written; control messages and Introductions carry the writer’s current membership, or the sentinel.

Geometry

B is the box size of Pigeonhole protocols over Reticulum. A member’s box holds B − 1 bytes of GroupChatMessage CBOR; each box of a sealed reply holds B − 1 bytes of it. The costs below are measured on the encoders. h is a string’s CBOR header: 1, 2 or 3 bytes below 24, 256 and 65536 bytes.

field or message bytes
GroupChatMessage: array, version, membership_hash, msg_type 37
text of n bytes h + n
introduction, name of n bytes 139 + h + n
file upload, payload n, type t, name b 1 + (h + n) + (h + t) + (h + b)
control or ping body 1
acks of k members h + 1 + naming + 8k; naming ≤ k
numbers of m prefixes h + 1 + 8m
introduced_at 107
each absent field before a present one 1
ReplyWho without rosters, places with names of n 2 + Σ (139 + h + n)
ReplyWho with rosters and p − 1 introductions, names of 10 160, 429, 1272, 2797 for p = 1, 2, 5, 10
VoucherPayload, name of n bytes 367 + h + n
sealed VoucherReply WhoReply + 211 + h
seal public key, X25519 ‖ CTIDH1024 160

Version 3 cost 70 for the fixed fields, 5 + h + n for a text, 174 + h + n for an introduction, 451 + h + n for a VoucherPayload and 359 for the seal, so version 4 saves 33 bytes on every box, 35 on an introduction, 84 on a voucher and 146 on its reply. With B = 1000: a text is at most 959 bytes; a control message acknowledges up to 117 members; a sealed reply that fits box 1 alone holds a WhoReply of 786 bytes, five places without rosters or three with; a larger reply continues in box 2 and on. With B = 256, the mesh size: a text is at most 216 bytes, and a sealed reply always spans several boxes.

Reading

  • Each member’s stream from the position given: a box or a tombstone advances, NOT_FOUND waits with the backoff.
  • On a replica that serves push, a NOT_FOUND also subscribes to that box, and the stream waits for the push instead, reading again every 5 minutes in case the push was lost.
  • acks, numbers and introduced_at let a reader jump and backfill, as the state machine does.
  • Replicas keep a box for one to two weeks; older boxes are recovered only through acknowledgements.

Sending

  • A text sent while the box before it still waits to be written goes into that box, as a packed box, as long as the texts fit the box size. Only a client writing version 5 packs.
  • What a member has read is acknowledged in its next message. When it has sent nothing 30 seconds after reading something, a control message carries the acknowledgements alone.
  • A box that carries no content, such as a control message, is not acknowledged on its own, so receipts do not answer receipts.

Vectors

In katzenpost/pigeonhole_protocols: testdata/katzenqt1/groupchat_wire_vectors_v5.json and groupchat_wire_vectors_v4.json (messages, written boxes, membership hashes, replies, refused arrays) for versions 5 and 4, testdata/katzenqt1/groupchat_wire_vectors.json for version 3, and testdata/katzenqt1/acks_vectors.json. Voucher vectors are voucher/testdata/voucher_vectors_v2.json in katzenpost/hpqc, beside the version 3 file; BACAP vectors are in the same repository. katzenrns is a client of this protocol on meshes: match the above, not its storage or interface. pigeonhole_protocols main writes version 5. The compact voucher form is on the branch katzenqt1-v4 of hpqc (hpqc#154, not merged), which the Go module of pigeonhole_protocols pins; the deployed version 3 is the branch katzenqt1-v3 of hpqc, cryptlib, group_chat_client, katzenqt and katzenrns.

Encoding

Byte fields are CBOR byte strings; names are text strings; integers are unsigned.

Acks

Empty when nothing is acknowledged. Otherwise:

  • one byte, the number of members acknowledged, less one,
  • the members by roster index, ascending: a list of one byte each when no longer than the bitmap, else a bitmap, most significant bit first, as many bytes as the highest index needs,
  • one 8 byte little endian counter per member, same order: the counter of the acknowledged box.

A naming as long as the count is a list, shorter is a bitmap. Refused: a list out of order, a bitmap ending in a zero byte, a bitmap naming other than the count.

Numbers

  • one byte, the first roster index assigned,
  • one 8 byte key prefix per member numbered, consecutive indexes.

A single byte is the roster index of the member the same message’s Introduction introduces. Refused when the indexes would pass 255 or a prefix repeats.

IntroducedAt

  • one byte, the introducer’s roster index in the sender’s roster,
  • the 104 byte index of the Introduction in the introducer’s stream.

Voucher stream

  • VoucherPayload, box 0: array [read_cap 136 bytes, seal public key 160 bytes, display_name, signature 64 bytes]; the signature is Ed25519 by the read cap’s root key over the CBOR array of the first three.
  • Voucher: BLAKE2b-256 of the VoucherPayload’s bytes.
  • VoucherReply: array [WhoReply, the ReplyWho’s CBOR; salt 32 bytes]. Sealed as a sealed box to the seal public key: the sender’s ephemeral hybrid public key, 160 bytes, then XSalsa20-Poly1305 of the plaintext under a key and nonce derived from the shared secret, as hpqc’s sealedbox defines, with the NIKE named CTIDH1024-X25519.
  • Boxes 1 on: the sealed bytes in pieces of B − 1, each behind one byte, C for a piece that continues, F for the last.

Version 3

Readers accept these as well; a version 3 message is a CBOR map, a version 4 one an array, which the first byte tells apart.

GroupChatMessage: map version 3, membership_hash, msg_type, then the type’s field under its name, text, introduction (map display_name, read_cap), file_upload (map payload, filetype, basename), who, reply_who, tally, and optional acks, numbers, introduced_at. A map without msg_type has the type of the field it carries, text when none.

ReplyWho: map please_adds (array of map display_name, read_cap, or null), rosters, introductions, introducer, newcomer, the last four absent when unknown.

Vouchers: PleaseAdd is map DisplayName, MessageReadCap; SignedPleaseAdd map PleaseAdd (its CBOR), Signature (64 bytes, Ed25519 by the stream’s root key over the PleaseAdd bytes); VoucherPayload map SignedPleaseAdd (its CBOR), VoucherPubKey; all canonical CBOR. VoucherReply is map WhoReply, VoucherSalt, sealed with hpqc’s MKEM to the seal public key and written unframed to box 1 alone. A member answers a version 3 payload in this form, with the map form of the ReplyWho inside.

2.21 -

Pigeonhole protocols over Reticulum

A client on a Reticulum mesh reads and writes Pigeonhole boxes through one replica. This is what it sends and receives. Replicas, replication and bridges are in Pigeonhole replicas over Reticulum; BACAP is in the Echomix paper; a protocol on top, such as katzenqt1 chat, adds only what it writes into boxes.

Replicas

destination application name pigeonhole, aspect replica, single
announce application data 1 byte of flags, under Encoding; a bridge’s 16 byte mixnet id after it
identity the first heard for a destination; a later one for it is ignored
entry replica any announced replica with a path, the fewest hops by preference

A client uses one replica at a time. The mesh runs in open mode: every replica holds every box, and the replica forwards, syncs and finds boxes, and fetches from the mixnet through a bridge; the client does none of that. Replicas are authenticated only by Reticulum’s classical link encryption.

Requests

A query reaches a replica over a Link to its destination, in one of two modes. One Link per replica, reopened when it closes. Both modes carry the same query and reply bytes.

Request mode, every replica not announcing bit 3: the query is a Link request; a request above the MTU travels as a Resource. Up to 8 queries in flight per Link.

path query reply
write write query result code
read read query result code, and the box when found

A query whose first byte disagrees with its path is answered INVALID_PAYLOAD. subscribe and unsubscribe are under Push; the other paths are replica to replica. Reference timeouts: 20 s to establish a Link, 60 s per request; an unanswered request is asked again later, not repeated at once.

Channel mode, replicas announcing bit 1: the query goes as Channel messages on the Link, for Reticulum stacks with Links and Channel but no requests or Resources. A client uses it only with replicas that announce bit 1, and only it with those announcing bit 3. The query’s first byte picks read, write, subscribe or unsubscribe. A query or reply larger than one Channel message is cut into pieces, each a frame carrying the query’s request id; the reply comes back with the same request id. A replica drops a request whose pieces do not all arrive within 60 s. Bytes on the air for one box of 1000 bytes, client sent / received:

link MTU query request mode channel mode
500 write 1484 / 297 1468 / 428
500 read 329 / 1436 480 / 1456

Channel mode costs about 100 to 150 bytes more per query, mostly the proof every Channel packet gets. With the mesh box size a write is one packet in either mode.

Choosing a mode. The reference clients have a mode setting: request, Channel, or auto, the default. Auto asks a replica with a Link request first and, when a replica announcing bit 1 does not answer, asks again in Channel mode, and keeps per replica the mode that answered. The Rust client on Reticulum-rs speaks Channel mode alone. Replicas asking each other go Channel first, as Pigeonhole replicas over Reticulum describes.

Push

A client on a replica announcing bit 4 need not poll. After a read answers NOT_FOUND, the client subscribes to that Box ID on the same Link, in Channel mode, since pushes come only over Channel. When the replica holds the box it pushes it down the Link, and the client takes the box from the push with no further query. The client then subscribes to the stream’s next Box ID.

Pushes are best effort, so a stream waiting for a push still reads again every 5 minutes, which also renews the subscription. A subscription lasts at most an hour, and a Link waits for at most 256 Box IDs. Against a replica that does not announce push, and on the mixnet, the client polls with backoff.

Boxes

BACAP under the context string pigeonhole context.

bytes
Box ID: a blinded Ed25519 public key 32
signature: Ed25519 over the ciphertext, verifying under the Box ID 64
MessageBoxIndex: counter 8, blinding factor 32, encryption key 32, KDF state 32 104
read capability: root public key, MessageBoxIndex 136
write capability: root private key as seed then public key, MessageBoxIndex 168
ciphertext box size + 20

For the context string, the index’s blinding factor and encryption key each go through HKDF-BLAKE2b-512 with the string as salt. Box ID = root public key blinded by the derived factor. Ciphertext = AES-GCM-SIV under the derived key, nonce the first 12 bytes of the Box ID, the Box ID as associated data. Signature = root private key blinded by the derived factor, over the ciphertext. A capability’s index is its first box; each next index derives from the one before it.

The box size B is the plaintext a box carries. Two sizes are fixed: mesh, 256 bytes, the largest multiple of 16 whose write fits one Link packet at the 500 byte MTU with 16 bytes to spare in either mode, and mixnet, 1549 bytes, the Katzenpost box. A client on Reticulum writes at mesh. A box too long for that size is written at the smallest allowed size that holds it; only a voucher’s box 0 ever is, since it is never split. A reader takes a box of any allowed size: the two above, the size its transport was given (1549 by default) and any configured extra, each from 141 to 16384 bytes. It refuses any other size, and a replica answers a box of a size it does not take with INVALID_PAYLOAD.

Geometry

Every size on the mesh follows from the box size B, the plaintext a box carries.

quantity bytes
plaintext a protocol may put in a box B
padded plaintext B + 4
ciphertext B + 20
read query 33
write query B + 117
reply to a write, or a miss 1
reply with a box B + 85
tombstone write 97

With B = 256 that is a 276 byte ciphertext and a 373 byte write query; with B = 1549, 1569 and 1666. The seal scheme the protocols on top use is the hybrid NIKE CTIDH1024-X25519 and the signature scheme is Ed25519, as on the mixnet.

Writing, reading, deleting

action send outcome
write write query SUCCESS or ALREADY_EXISTS: the replica holds a box under that ID. Same bytes: SUCCESS. Different bytes: ALREADY_EXISTS, nothing changes; use the next index.
read read query SUCCESS with the box: verify, open. NOT_FOUND: not written yet; poll with backoff, reference 2 s doubling to 60 s. TOMBSTONE: deleted.
delete write query, empty ciphertext replaces the box; a box never replaces a tombstone

A client that has seen a tombstone treats that Box ID as deleted from then on; other replicas may hold the box until the tombstone reaches them.

Epochs

The mesh carries no epoch. Replica epoch = ⌊(now − 1496275200) / 604800⌋, Unix seconds. A replica keeps a box for the replica epoch it arrived in and the next, one to two weeks, and may evict the oldest boxes earlier when its disk is full.

Overhead

This section gives the bytes every operation puts on a Reticulum link at the 500 byte MTU, for the two box sizes a mesh carries, B = 256 and B = 1549.

The Pigeonhole bytes are measured: queries and replies come from the encoders of pigeonhole_rns with BACAP from hpqc, and agree with testdata/box_sizes.json in pigeonhole_protocols. The voucher sizes are measured from voucher_vectors_v2.json in hpqc. Reticulum’s encryption overhead is measured by encrypting with RNS 1.5.7’s own Token.

The packets are computed from RNS 1.5.7’s framing: the header and proof sizes are its constants, and its own ResourceAdvertisement packs the advertisements. The same computation reproduces, byte for byte, the eight figures tests/e2e_two_replicas.py measured for a 1000 byte box in the table under Requests, once a 20 byte keepalive in each direction is counted in the Channel read. Airtime is computed from these sizes with the LoRa formula below; it has not been measured on radios.

Layers

layer bytes
read query 33
write query B + 117: 373 for B = 256, 1666 for B = 1549
tombstone write 97
reply: written, not found, tombstone 1
reply with a box B + 85: 341, 1634
subscribe to n Box IDs, and its answer 3 + 32n, and 5
push 32 + the reply with the box: 373, 1666
Link request: msgpack of [time, path hash, query] the query plus 30, or 31 from 256 bytes
Link response: msgpack of [request id, reply] the reply plus 21, or 22 from 256 bytes
Channel: envelope and frame header, per piece of at most 421 bytes 10
Link encryption of n bytes: IV, padding to 16 bytes, HMAC 48 + 16 × (⌊n / 16⌋ + 1)
packet header: flags, hops, link id, context 19
proof of a Channel packet: header, packet hash, signature 115

A Link request or response larger than the Link MDU, 431 bytes, travels as a Resource: the sender encrypts it once with 4 random bytes before it and sends an advertisement (211 bytes here) and parts of up to 464 bytes, each behind a header; the receiver sends a request for the parts (131 bytes for four) and an 83 byte proof. Requests and responses that fit one packet are not proven; every Channel packet is.

The mesh write in request mode, layer by layer: the 373 byte query becomes 404 bytes of msgpack, 464 of ciphertext and a 483 byte packet; the one byte reply becomes 22, 64 and 83. In Channel mode the query becomes 383 bytes framed, 432 encrypted and a 451 byte packet; the reply becomes 11, 64 and 83, and each side proves the other’s packet with 115 bytes.

Opening a Link costs 86 bytes from the client, 118 from the replica and 83 from the client again, once per Link. An open Link sends a 20 byte keepalive each way at most every 360 seconds.

Per operation

Each cell lists the packets one side sends, in bytes. bytes is the sum of both sides. The LoRa frames column is for an RNode, which sends a packet of up to 254 bytes in one frame and a larger one in two, each frame carrying one byte of its own header, so the LoRa payload on the air is the bytes plus one per frame.

B = 256

operation mode client sends replica sends bytes packets LoRa frames
write Link request 483 99 582 1 + 1 2 + 1
write Channel 451 + 115 83 + 115 764 2 + 2 3 + 2
tombstone Link request 195 99 294 1 + 1 1 + 1
tombstone Channel 179 + 115 83 + 115 492 2 + 2 2 + 2
read, found Link request 131 435 566 1 + 1 1 + 2
read, found Channel 115 + 115 419 + 115 764 2 + 2 2 + 3
read, not found Link request 131 99 230 1 + 1 1 + 1
read, not found Channel 115 + 115 83 + 115 428 2 + 2 2 + 2
read, tombstone Link request 131 99 230 1 + 1 1 + 1
read, tombstone Channel 115 + 115 83 + 115 428 2 + 2 2 + 2
subscribe Channel 115 + 115 83 + 115 428 2 + 2 2 + 2
push Channel 115 451 566 1 + 1 1 + 2

B = 1549

operation mode client sends replica sends bytes packets LoRa frames
write Link request 211 + 483 + 483 + 483 + 387 131 + 83 + 99 2360 5 + 3 9 + 3
write Channel 499 + 499 + 499 + 483 + 115 83 + 115 + 115 + 115 + 115 2638 5 + 5 9 + 5
tombstone Link request 195 99 294 1 + 1 1 + 1
tombstone Channel 179 + 115 83 + 115 492 2 + 2 2 + 2
read, found Link request 131 + 131 + 83 211 + 483 + 483 + 483 + 339 2344 3 + 5 3 + 9
read, found Channel 115 + 115 + 115 + 115 + 115 499 + 499 + 499 + 451 + 115 2638 5 + 5 5 + 9
read, not found Link request 131 99 230 1 + 1 1 + 1
read, not found Channel 115 + 115 83 + 115 428 2 + 2 2 + 2
read, tombstone Link request 131 99 230 1 + 1 1 + 1
read, tombstone Channel 115 + 115 83 + 115 428 2 + 2 2 + 2
subscribe Channel 115 + 115 83 + 115 428 2 + 2 2 + 2
push Channel 115 + 115 + 115 + 115 499 + 499 + 499 + 483 2440 4 + 4 4 + 8

A read that finds nothing costs the same at either size. Only a found box, a write and a push grow with B. At B = 256 every query and reply fits one packet, but a packet over 254 bytes, such as a mesh write, takes two LoRa frames. A write fits one LoRa frame only for B ≤ 48 in Channel mode and B ≤ 27 in request mode.

Joining through a voucher

The voucher protocol is reads and writes of boxes, so its cost is the sum of the rows above. The newcomer writes the VoucherPayload to box 0 and reads the sealed reply from box 1 on. The inductor reads box 0, writes its Introduction to its own stream, and writes the sealed reply in pieces of B − 1 bytes, one box each. The compact VoucherPayload is 373 bytes for a five letter display name, 368 bytes plus a name shorter than 24 bytes, so it does not fit a 256 byte box. It is written at the smallest allowed size that holds it, 1549 by default, and read at that size. An Introduction with a name of 10 bytes is 188 bytes and takes one mesh box.

The sealed reply is the ReplyWho plus 213 bytes for a ReplyWho of 24 to 255 bytes, plus 214 from 256: the vectors’ 37 byte ReplyWho seals to 250. The ReplyWho grows with the group; with rosters and names of 10 bytes it is 160 bytes for a group of one member, 429 for two and 1272 for five. The table gives each side’s bytes, with the reply boxes written at B = 256; in the last three columns the newcomer’s exchange comes first, then the inductor’s.

members sealed reply boxes mode newcomer sends inductor sends replicas send packets LoRa frames
1 373 2 Link request 2309 1794 1183 + 2296 12 + 14 18 + 21
1 373 2 Channel 2555 2273 1611 + 2657 18 + 22 24 + 29
2 643 3 Link request 2440 2277 1618 + 2395 14 + 16 21 + 24
2 643 3 Channel 2785 2839 2145 + 2855 22 + 26 29 + 34
5 1486 6 Link request 2833 3726 2923 + 2692 20 + 22 30 + 33
5 1486 6 Channel 3475 4537 3747 + 3449 34 + 38 44 + 49

These assume every box is there when read. Each read that finds a box not yet written adds a miss, and a subscription adds the subscribe and the push in place of the second read. The inductor then reads the newcomer’s stream like any other member’s.

LoRa airtime

A LoRa frame of PL bytes takes, by Semtech’s formula,

T_sym      = 2^SF / BW
n_payload  = 8 + max(⌈(8 PL − 4 SF + 28 + 16 CRC − 20 IH) / (4 (SF − 2 DE))⌉ × (CR + 4), 0)
T_frame    = (n_preamble + 4.25) × T_sym + n_payload × T_sym

with RNode’s settings: CRC on (CRC = 1), explicit header (IH = 0), low data rate optimization (DE = 1) when a symbol lasts more than 16 ms, and n_preamble = max(18, ⌈24 ms / T_sym⌉). CR = 1 is coding rate 4/5. The firmware programs four symbols fewer into SX127x radios, so their frames are four symbols shorter than given here. Channel access waits are not counted.

setting symbol preamble low data rate optimization 21 B frame 116 B frame 255 B frame
SF7, 125 kHz, 4/5 1.024 ms 24 symbols off 73 ms 211 ms 416 ms
SF9, 125 kHz, 4/5 4.096 ms 18 symbols off 226 ms 656 ms 1291 ms
SF12, 125 kHz, 4/5 32.768 ms 18 symbols on 1810 ms 4923 ms 9347 ms

The 21, 116 and 255 byte frames are a keepalive, a proof and a full frame, each with RNode’s header byte.

Under the EU 868 MHz duty cycle of 1 %, each transmitter may be on the air 36 seconds an hour. The table gives, per operation, the client’s and then the replica’s airtime, and how many such operations each could send an hour on that budget alone, one hop apart. A replica answering several clients shares one budget among them, and every transport node on a longer path spends its own.

operation B mode SF7 SF9 SF12
write 256 Link request 0.80 / 0.19 s; 45 / 188 2.48 / 0.59 s; 14 / 60 17.87 / 4.27 s; 2 / 8
write 256 Channel 0.96 / 0.38 s; 37 / 95 2.99 / 1.17 s; 12 / 30 21.82 / 8.70 s; 1 / 4
read, found 256 Link request 0.24 / 0.72 s; 152 / 49 0.74 / 2.25 s; 48 / 15 5.41 / 16.40 s; 6 / 2
read, found 256 Channel 0.42 / 0.91 s; 85 / 39 1.31 / 2.85 s; 27 / 12 9.85 / 20.83 s; 3 / 1
read, not found 256 Link request 0.24 / 0.19 s; 152 / 188 0.74 / 0.59 s; 48 / 60 5.41 / 4.27 s; 6 / 8
read, not found 256 Channel 0.42 / 0.38 s; 85 / 95 1.31 / 1.17 s; 27 / 30 9.85 / 8.70 s; 3 / 4
subscribe 256 Channel 0.42 / 0.38 s; 85 / 95 1.31 / 1.17 s; 27 / 30 9.85 / 8.70 s; 3 / 4
push 256 Channel 0.21 / 0.75 s; 170 / 47 0.66 / 2.34 s; 54 / 15 4.92 / 16.89 s; 7 / 2
write 1549 Link request 3.40 / 0.59 s; 10 / 60 10.58 / 1.85 s; 3 / 19 76.42 / 13.46 s; < 1 / 2
write 1549 Channel 3.46 / 1.01 s; 10 / 35 10.76 / 3.14 s; 3 / 11 78.39 / 23.47 s; < 1 / 1
read, found 1549 Link request 0.64 / 3.33 s; 56 / 10 1.99 / 10.37 s; 18 / 3 14.61 / 74.95 s; 2 / < 1
read, found 1549 Channel 1.06 / 3.41 s; 34 / 10 3.28 / 10.62 s; 10 / 3 24.62 / 77.41 s; 1 / < 1
join, newcomer Link request 3.87 / 2.04 s; 9 / 17 12.05 / 6.36 s; 2 / 5 87.25 / 46.26 s; < 1 / < 1
join, inductor Link request 3.03 / 3.90 s; 11 / 9 9.43 / 12.16 s; 3 / 2 68.23 / 87.75 s; < 1 / < 1
join, newcomer Channel 4.30 / 2.83 s; 8 / 12 13.39 / 8.84 s; 2 / 4 98.08 / 65.13 s; < 1 / < 1
join, inductor Channel 3.94 / 4.54 s; 9 / 7 12.26 / 14.13 s; 2 / 2 90.06 / 103.51 s; < 1 / < 1

The join rows are for a group of one member, request mode on a Python replica and Channel mode on a Rust one. At SF7 a client can write a mesh box about 40 times an hour; at SF9, about 13; at SF12, once or twice. A 1549 byte box costs three to four times a mesh box to write. At SF12 that write takes over 76 seconds, more than two hours of a 1 % budget, and every join makes one.

Encoding

All integers are big endian.

Queries

A read is 33 bytes:

  • one byte, 0,
  • the 32 byte Box ID.

A read with anything after the Box ID is refused.

A write is 97 bytes and the ciphertext:

  • one byte, 1,
  • the 32 byte Box ID,
  • the 64 byte signature,
  • the ciphertext, to the end of the message. There is no length field.

A tombstone is a write with an empty ciphertext: 97 bytes.

Replies

  • one byte, the result code,
  • for SUCCESS to a read that found a box, the 64 byte signature and the ciphertext.

A reply to a write is the one byte. A reply to a read of an unwritten box, or of a tombstone, is the one byte.

The codes are the Pigeonhole replica’s: 0 SUCCESS, 1 NOT_FOUND, 2 INVALID_BOX_ID, 3 INVALID_SIGNATURE, 4 DATABASE_FAILURE, 5 INVALID_PAYLOAD, 6 STORAGE_FULL, 7 INTERNAL_ERROR, 8 INVALID_EPOCH, 9 REPLICATION_FAILED, 10 ALREADY_EXISTS, 11 TOMBSTONE.

Padding

The plaintext of a box is:

  • a 4 byte length,
  • the data,
  • zeros, to the box size plus 4 bytes.

The ciphertext is that plaintext encrypted, with a 16 byte tag: the box size plus 20 bytes.

Channel frames

Each Channel message has MSGTYPE 0x5048 and carries one frame:

  • a 2 byte request id,
  • a 1 byte piece index, from 0,
  • a 1 byte piece count, 1 to 255,
  • the piece: the next slice of the query or reply.

A frame whose count is 0 or differs from earlier pieces of its request, or whose index is not below its count, is dropped with its request. Duplicate pieces are ignored.

Piece size is computed from the Link: link MDU = ⌊(MTU − 68) / 16⌋ × 16 − 1, Channel MDU = link MDU − 6, piece = Channel MDU − 4. At MTU 500 that is 431, 425 and 421 bytes, so a write of one 1000 byte box takes three frames.

Channel messages

A stack that is not RNS must match RNS’s Channel on the wire:

  • each message is one Link packet with context CHANNEL (0x0E), its payload a 6 byte envelope, MSGTYPE, sequence number and length, each 2 bytes, then the message;
  • sequence numbers wrap at 65536; messages are delivered in order, and out-of-order ones buffered up to 48 ahead; duplicates and ones behind are dropped;
  • every Channel packet is acknowledged by the Link’s packet proof, and a receiver must prove each one, or the sender retries and then closes the Link;
  • the sender keeps at most its window of unproven packets in flight: 2 at first, one more per delivery, one less per timeout;
  • a packet is resent with the same sequence number up to 5 tries, after 1.5^(tries − 1) × max(2.5 × RTT, 0.025 s) × (packets in flight + 1.5).

Subscribe and push

Subscribe is the Channel query 6 | ttl u16 seconds | box id 32 | ..., or the Link request subscribe with the bytes after the 6. The answer is 0 | taken u16 | ttl u16: the first taken IDs are subscribed, for the granted ttl, the asked one capped at 3600, 0 asking for 3600. A malformed subscribe is answered with the one byte 5. Unsubscribe is 7 | box id 32 | ..., or the request unsubscribe, dropping those IDs, or all when none is named; the answer is the one byte 0.

A push is a run of Channel messages of MSGTYPE 0x5049, framed as Channel frames are under request ids the replica counts, carrying box id 32 | reply, the reply as for a read: 0 with the signature and ciphertext, or 11 for a tombstone.

Announce

The application data of a replica’s announce is one byte of flags: bit 0 a bridge, bit 1 serves Channel mode, bit 2 serves the replica paths in Channel mode, bit 3 serves no Link requests, bit 4 serves push. A bridge follows it with its 16 byte mixnet id.

Vectors

testdata/bridge_socket_vectors.json in pigeonhole_rns holds query and reply bytes (queries, replies), queries a replica refuses (malformed) and boxes with what a replica answers each (boxes). The frames in it, a 4 byte length before each message, are the socket between a bridge’s two halves and are not sent by a client.

2.22 -

Pigeonhole replicas over Reticulum

Abstract

Pigeonhole replicas on a Reticulum mesh give Reticulum users asynchronous group communication with post quantum confidentiality, and let them share groups with users of a Katzenpost mixnet. The mesh side spends as few bytes as it can. The mixnet side keeps its metadata privacy. Neither needs the other to work.

This document assumes the Echomix paper and the Pigeonhole specification. The client’s side is Pigeonhole protocols over Reticulum. The reference implementation is pigeonhole_rns, a Python replica on RNS and a Rust replica on Reticulum-rs.

What crosses over

A box is a Box ID, a ciphertext and a signature. The Box ID is the public key that verifies the signature, the ciphertext is readable only with the read capability, and consecutive boxes of one writer are unlinkable to anyone without it. A replica keeps a box because it verifies, not because of who brought it. Both networks carry this same object, so a box written on one can be carried to the other by anyone who can read it, and it arrives as authentic as it left.

Everything above the box is shared: BACAP, the box sizes, the group chat message format. Everything below it differs, and this document describes the mesh half.

Priorities

The mesh carries bytes over LoRa and similar links, so the design pays public key cryptography as rarely as it can, carries no padding beyond the box, and hides nothing from replicas that the mixnet hides from couriers. The mixnet makes the opposite trade in its own specification.

BACAP is already quantum annoying: without the blinding factor an adversary cannot read a box or link two of them, quantum computer or not. The one thing a quantum adversary can do is forge a write into a box whose ID it has seen. That holds on both networks. What BACAP does not cover is the traffic that carries it: which Box IDs are written and read, and when.

Open mode

A mesh runs in open mode. A replica is any node that announces a Reticulum destination under application name pigeonhole, aspect replica. There is no list to join. The replica’s Reticulum identity is its identity, and the Link a client opens to it is authenticated by it.

Queries travel on that Link as they are. Reticulum’s link encryption gives them X25519 forward secrecy and Ed25519 authentication of the replica, both classical. There is no post quantum authentication of replicas. No session layer is added, because anyone may announce a replica, and a replica sees the Box IDs and read times of the boxes it handles, as a replica does on the mixnet. What remains post quantum is what BACAP protects: contents and linkage.

Every replica holds every box. There is no placement on the mesh; sharding happens only on the Katzenpost side of a bridge, as the mixnet places boxes.

Replication

A replica that newly holds a box, written by a client, forwarded by another replica, pulled from a mixnet or fetched for a reader, forwards it to every replica it has heard except the one it came from. It retries each with backoff until that replica acknowledges with SUCCESS or ALREADY_EXISTS, and stops for one that answers INVALID_SIGNATURE, INVALID_BOX_ID or INVALID_PAYLOAD. A box it already held is not passed on again, so a forward is never forwarded twice. Forwards to different replicas run at once.

Replicas identify themselves on the Links they open to each other, so a receiver knows a forward’s sender and does not send the box back. A write from an unidentified Link is a client’s.

When a replica first hears another, and again after it found it unreachable or either restarted, the two sync. The initiator walks the Box ID space in pages of up to 128 Box IDs, each with a tombstone flag. The responder answers each page with its own page over the same range, cut short when full, and each side enqueues for the other the boxes it lacks. A tombstone is sent where the other holds the box it replaces. An unidentified initiator gets the answer but no boxes.

Reading

A client sends a read to one replica, its entry replica. The entry replica answers from its own store. Otherwise it asks every reachable replica with peek, in the box’s order, which answers from that replica’s store only, a bridge also asking its mixnet. The first box or tombstone found is returned, kept and forwarded like a write, so the next reader finds it on the mesh. If none has it and the entry replica is itself a bridge, it asks its mixnet. Otherwise the reply is NOT_FOUND, and the client asks again later or subscribes to the box.

A box’s order ranks replicas by SHA-256 of the replica’s identity hash and the Box ID, lowest first; anyone who has heard the same replicas computes the same order.

Deleting

A tombstone is a write with an empty ciphertext. It replaces the box and is forwarded and synced like one; a box never replaces a tombstone. A read of a tombstoned box answers TOMBSTONE. A reader that has seen a box’s tombstone treats the box as deleted thereafter, since another replica may hold the box until the tombstone reaches it.

Epochs and garbage collection

Boxes are kept by replica epoch, as on Katzenpost replicas. An epoch is 1200 seconds, a replica epoch is 504 epochs, one week, both counted from 2017-06-01 00:00 UTC (Unix 1496275200):

replica epoch = ⌊(now − 1496275200) / 604800⌋

A box is stamped with the replica epoch it arrived in and kept for that epoch and the next, so one to two weeks. Collection runs at start and at every replica epoch boundary. Both periods are settings; a bridge keeps the defaults, since the bridge socket carries no timing and Katzenpost’s replica epoch is a week. The group chat protocol’s acknowledgements and backfill cover readers who were away longer.

Disk limits

A replica keeps every box while there is room. Two limits bound the room: a cap on the box database and its write-ahead log (none by default), and a minimum of free space on its filesystem (500 MiB by default, as Katzenpost’s MinFreeStorageMiB). A new box that would cross either first evicts the oldest boxes, by replica epoch and then arrival, tombstones only after every box, until a sixteenth of the limit is spare. Only when nothing is left to evict is the write answered STORAGE_FULL. Evicted pages are returned to the filesystem, so the limits measure real disk use.

Box sizes

A replica takes boxes of several sizes at once, since meshes and mixnets joined through bridges need not share one. A box’s size is its plaintext size; the ciphertext is the plaintext with a 4 byte length before it, zero padded, plus a 16 byte AEAD tag.

profile plaintext ciphertext write query
mesh 256 276 373
mixnet 1549 1569 1666

mixnet is the Katzenpost box, fixed by the Sphinx geometry. mesh is the largest multiple of 16 whose write, and a replica’s forward of it, fit one Link packet at Reticulum’s 500 byte MTU in either query mode: the 431 byte Link MDU, less request mode’s 31 byte msgpack framing (more than Channel mode’s 11), less the forward’s 113 byte head, less the 20 bytes of box overhead, is 267, rounded down to 256. It is the size clients on Reticulum write.

A replica always takes mesh and mixnet and up to 8 more sizes its operator lists, none over 1549. It refuses a box of any other ciphertext size with INVALID_PAYLOAD, and a replica forwarding such a box drops it. A tombstone is always taken. An operator may instead take any size, which on a bridge leaves the check to the Katzenpost replica.

Bridges

A bridge joins a mesh to a Katzenpost mixnet so that a group can have members on both without either side doing anything. It is a mesh replica like any other, holding every box and syncing, beside a Katzenpost replica that is a member of the mixnet’s PKI. The two share a host and talk over a unix socket on the Katzenpost replica. What the bridge brings in enters under that already vetted replica’s name; this is why the crossing happens between replicas and not through a new door into the mixnet.

A bridge announces the mixnet it serves as an id: the first 16 bytes of SHA-256 of a name its operator gives, such as the mixnet’s PKI identity, the same on every bridge to that mixnet.

Out of the mesh. A bridge writes each box it holds into its mixnet, where the Katzenpost replica treats it as a replication write and dispatches it to the box’s shards. Bridges serving the same mixnet first ask each other, with pushed, whether one has written the box: the first in the box’s order among them writes, and the others wait up to three retries for it and then write themselves. A duplicate write is harmless. A bridge may instead write only the boxes clients write to it, while still pulling for reads.

Into the mesh. Nothing on the mixnet announces a write, so the mixnet cannot push. A read that misses on the mesh reaches the bridges, which ask their Katzenpost replicas; the bridge that finds the box keeps it, with its mixnet as the box’s origin, and it replicates from there. The read is the watch list: no one tells a bridge what to look for.

A box carries its origin through replication, as a forward prefixed with the mixnet id, so no bridge writes a box back into the mixnet it came from, while bridges to other mixnets do. One mesh can join several mixnets without loops. A tombstone written directly on a mixnet does not cross to the mesh, since the bridge socket returns a tombstone without its signature; one written on the mesh reaches every mixnet.

A box from the mixnet appears on the mesh only because a mesh node holding its read capability asked for it by ID, which is a group member; the consent is the membership. A mesh box written into the mixnet shows mixnet replicas nothing the mesh did not already show every mesh replica. What a bridge costs is paid by its operator: a mixnet round trip the first time a mixnet box is read on the mesh, and a replication write into the mixnet for every box the mesh writes.

A bridge carries boxes of every size it takes unchanged.

Query modes

A query reaches a replica over a Link to its destination in one of two modes. Both carry the same query and reply bytes, and one destination serves both.

  1. Request mode. Each query is a Link request to a path; one larger than the Link MDU travels as a Resource.
  2. Channel mode. Each query and reply is a run of Channel messages on the Link, for Reticulum stacks with Links and Channel but no Link requests or Resources. The message’s first byte picks the handler.
path Channel op between
read 0 client and replica
write 1 client and replica
peek 2 replicas
sync 3 replicas
forward 4 replicas
pushed 5 bridges
subscribe 6 client and replica
unsubscribe 7 client and replica

For ops 0 and 1 the op is the query’s own first byte. For the others the op byte is followed by that path’s request bytes and answered with its response bytes.

Replicas ask each other in Channel mode first, when the other announces that it serves the replica paths there (or Channel mode at all, for a write), and fall back to a Link request when it does not or the Channel query fails. A replica announcing that it serves no Link requests, such as the Rust replica, is asked only in Channel mode. The Python replica serves both modes.

A replica handles Channel queries on 2 workers per Link, with up to 16 more queued per Link and at most 32 at once across the replica. A query arriving to a full queue is dropped; the asker times out and asks again.

Push

A client can subscribe on its Link to the Box IDs it waits for, and the replica pushes each box down that Link when it newly holds it: written by a client, arriving by forward or sync, or pulled from a mixnet. A client that never subscribes polls.

A Link waits for at most 256 Box IDs. A subscription lasts the granted time, at most an hour; the client renews it by subscribing again. A Box ID already held is pushed at once. A push consumes the subscription, since a box is written once; the client then subscribes to the stream’s next Box ID. Closing the Link drops every subscription.

Pushes go only over Channel, also to a Link that subscribed with a Link request. They are best effort: a push sent as the Link closes is lost, and one is dropped when 256 wait to be sent on its Link, so a client that reconnects reads what it waits for once and subscribes again.

Group chat on the mesh

The group chat protocol depends only on reading and writing boxes. On the mixnet it writes several boxes through a temporary stream and a copy command so that a courier sees one action; the mesh has no courier to hide from, so a mesh client writes the same boxes directly. Readers on either network see identical streams, and a group whose members are on both talks through a bridge without knowing it.

Encoding

All integers are big endian.

Announce

The application data of a replica’s announce is one byte of flags:

bit set when the replica
0 is a bridge
1 serves Channel mode
2 serves the replica paths in Channel mode too
3 serves no Link requests
4 serves push

A bridge follows the byte with its 16 byte mixnet id. A bridge announcing none serves the mixnet of the empty name. The Rust replica announces bits 1, 2, 3 and 4.

Queries and replies

A read query is one byte 0 and the 32 byte Box ID. A write query is one byte 1, the 32 byte Box ID, the 64 byte signature and the ciphertext to the end of the message; a tombstone has an empty ciphertext. A reply is one result byte, a Pigeonhole replica code, and for a box found the 64 byte signature and the ciphertext. The codes and their meaning for a client are in Pigeonhole protocols over Reticulum.

Replica paths

  • peek: a read query, answered with a reply.
  • forward: the 16 byte mixnet id of the box’s origin, then a write query; answered with a reply. The origin is kept only from an identified replica.
  • sync: a 32 byte lower bound, exclusive, a 32 byte upper bound, inclusive, then up to 128 entries of a 32 byte Box ID and one byte, 1 for a tombstone, in Box ID order. The answer is the 32 byte Box ID where its page ends and up to 128 entries of the same form. A malformed page is answered with nothing.
  • pushed: a 32 byte Box ID and one byte, 1 for a tombstone; answered with one byte, 1 when this bridge has written that box or tombstone into its mixnet or pulled it from there.

Subscribe and unsubscribe

Subscribe, after the op byte in Channel mode or as the subscribe request:

ttl u16 seconds | box id 32 | box id 32 | ...

The answer is 0 | taken u16 | ttl u16. The first taken IDs are subscribed; the rest are refused because the Link already waits for 256. An ID the Link already waits for is renewed and counts as taken. The granted ttl is the asked one capped at 3600, 0 asking for 3600. A malformed subscribe is answered with the one byte 5, INVALID_PAYLOAD.

Unsubscribe, after op 7 or as the unsubscribe request, is a run of 32 byte Box IDs, dropping those from the Link, or every one when none is named. The answer is the one byte 0.

Channel frames

A Channel mode query or reply is one or more Channel messages of MSGTYPE 0x5048:

request id u16 | piece index u8 | piece count u8 | piece

A query or reply is cut into 1 to 255 pieces of at most the Channel MDU less 4 bytes, the Channel MDU being the Link MDU less Channel’s 6 byte envelope: 421 bytes on a 500 byte MTU link. A reply carries its query’s request id. A receiver drops a request whose pieces disagree on the count, or that is incomplete after 60 seconds.

A push is a run of Channel messages of MSGTYPE 0x5049, framed the same way under request ids the replica counts per Link. Its bytes are:

box id 32 | reply

the reply as for a read: 0 with the signature and ciphertext, or 11, TOMBSTONE.

Bridge socket

The two halves of a bridge exchange the same write and read queries and replies over their unix socket, each message behind a 4 byte length. The mesh replica sends writes to put boxes into the mixnet and reads to pull them out. testdata/bridge_socket_vectors.json in pigeonhole_rns, read by the tests of both implementations, pins the format and what a replica answers each box.

Pending

Not merged at the time of writing: Katzenpost replicas holding box sizes besides their geometry’s (katzenpost#1265), so that a bridged mixnet also takes the mesh size.

3 - Build Katzenpost from source

Pinned versions of the Katzenpost stack and how to build each component from source.

Build Katzenpost from source


This page is the canonical reference for the pinned versions of the Katzenpost stack, together with brief instructions for building and running each component from source. It is intended for users and mixnet node operators who wish to run the software ahead of binary packages becoming available. The pinned-versions table below is the full compatibility set across repositories and serves application developers as well; for the thin client library APIs themselves, consult the Thin Client API Reference.

Pinned versions

The following git tags are the current recommended versions for running the stack, and they are one mutually compatible set: this katzenpost with this thin_client with this katzenqt. Components in the same row of the same repository should be built from the same tag.

Component Repository Path Branch Tag
Server-side components (mix server, dirauth, courier, replica) katzenpost cmd/server, cmd/dirauth, cmd/courier, cmd/replica main v0.0.90
kpclientd (client daemon) katzenpost cmd/kpclientd main v0.0.90
Thin client libraries (Rust, Python; the Go thin client lives in the katzenpost repository at the katzenpost tag) thin_client src, katzenpost_thinclient main 0.0.23
katzenqt (Qt group chat client) katzenqt (root) main 0.0.2

The hpqc cryptography library needs no row here: it is pinned by the katzenpost repository’s go.mod and go.sum.

Prerequisites

  • Go 1.23 or newer.

  • Make, git, and a C toolchain (gcc or clang).

For users

kpclientd (the client daemon)

Client applications such as katzenqt do not, by themselves, speak to the mix network. They communicate over a local socket with the kpclientd daemon, which performs all cryptographic and network operations.

git clone https://github.com/katzenpost/katzenpost
cd katzenpost
git checkout v0.0.90
make kpclientd

The resulting cmd/kpclientd/kpclientd binary is run with a TOML configuration file:

./kpclientd -c /path/to/client.toml

A configuration file is required. For testing, the Docker test mixnet generates one automatically; for joining a public network, you would obtain the configuration from that network’s operators.

katzenqt (Qt group chat client)

A decentralised group chat client built atop Qt. It depends solely on the Katzenpost mix network and the Pigeonhole storage services; no central server is involved. The Group Chat Design spec describes some of katzenqt’s design; for the storage concept, see Understanding Pigeonhole.

Warning. katzenqt is in active development; it is not appropriate to rely on it for anonymity, security, or privacy at this stage.

sudo apt install -y git make libxcb-cursor0 libegl1
git clone https://github.com/katzenpost/katzenqt
cd katzenqt
git checkout 0.0.2
make deps
make run

Out of the box, make run builds kpclientd, installs it as a systemd user service, and connects to the namenlos public mixnet: the Makefile installs a kpclientd configuration that dials namenlos and a thin client configuration that reaches the daemon over a local socket. No configuration editing is required. If the application cannot connect or messages fail to move, first check the network’s health on the namenlos status page.

For step-by-step setup, troubleshooting, and details on persistent state, see the repository’s README at the pinned tag.

For operators

The backend components (mix server, dirauth, courier, replica) are built from the katzenpost repository’s top-level Makefile, which provides a target per component. Several of the targets, among them make server and make dirauth, produce deterministic, reproducible binaries; work is underway to make every component build reproducibly, the replica being the furthest out.

git clone https://github.com/katzenpost/katzenpost
cd katzenpost
git checkout v0.0.90
make server
make dirauth
make courier
make replica

The replica requires RocksDB; its Makefile target installs that dependency first. For deployment guidance, configuration, and operating practice, see the Admin Guide.

4 -

How to build an application protocol or a mixnet service with the pigeonhole_protocols library: plain channels, the group chat protocol, and the service framework

Pigeonhole Protocols How-to Guide

This guide is for building something new on Pigeonhole with the pigeonhole_protocols library, in Go or in Rust. It assumes you have read Understanding Pigeonhole. The Thin Client How-to Guide covers the layer below: raw boxes over the client daemon.

The code fragments here teach one task at a time and omit imports and error handling. The programs and tests they are taken from compile and run in CI, and are linked at the end of each section; when a fragment and the code disagree, the code is right.

Which shape is your protocol?

Decide this first. Pigeonhole protocols come in three shapes, and each has a different right tool.

One party writes, another reads, once. Sending a file, publishing a feed, handing over a result. You do not need a protocol library: write the data to a channel and give the other party the read capability out of band. The thin client does this directly; see how to create a channel and how to read back a multi-box payload.

Two or more parties talk for a while and both expect what they send to arrive. A bot, a bridge, a fetcher that takes requests and streams back results, a game, anything with a request and a reply. Use the group chat protocol. This is the recommendation for most protocols, and the rest of this guide explains why and how.

Anyone should be able to find you and connect. A service with a public identity. Use the service framework to be listed in the directory and reached through a voucher router, and then, once a client has reached you, carry on in a group as above.

Why the group chat protocol

The group chat protocol, katzenqt1, is what katzenqt and hushphone speak. It is a set of members who each write to a stream of their own and read everyone else’s. As a base for your own protocol it gives you, for free:

  • Reliability in both directions. Writes that must land are retried until they do; members acknowledge what they have read; messages longer than a box are split and reassembled; files ride as sealed attachments.
  • Crash safety. Every change is saved to the state directory before the network work it leads to starts. A client killed at any moment and opened again on the same directory carries on, and sends nothing twice.
  • A group of two is just a group. Your protocol starts as two parties and gains a third without redesign.
  • Humans can talk to it. A service that lives in a group is a contact in katzenqt. People can join, read, and type at your bot with the app they already have.
  • Two implementations that agree. Go and Rust run the same scenarios and the same conformance traces against katzenqt, so a Go client and a Rust service interoperate.

Your protocol is then messages inside a group: text lines for requests and replies, files for anything large. The transport, retries, persistence and membership are not your problem.

The service framework’s own two-way connection also exists, and the motd and eliza services use it directly. It is a pair of streams with send and receive, enough for a request and a reply, and it is what you have before a client has joined a group. It does not acknowledge, and a send interrupted midway can lose the next message to that box. Treat it as the lobby, and move the conversation into a group.

How to open the group chat client

A client needs a backend, a state directory and a display name. The backend is the client daemon through its thin client; for tests, an in-memory Pigeonhole (see testing without a mixnet).

Go:

backend, _ := thinclient.Dial("@katzenpost", "")   // the daemon's socket, and a log file or ""
defer backend.Close()

c, _ := client.Open(ctx, client.Config{StateDir: "state", Name: "alice", Backend: backend})
defer c.Close()

events := c.Subscribe()   // subscribe before reading state, so nothing falls between

Rust:

let backend = Arc::new(ThinClientBackend::dial("@katzenpost").await?);
let c = Client::open(Config { state_dir: "state".into(), name: "alice".into(), ..Default::default() }, backend).await?;
let mut events = c.subscribe();

Open loads whatever the state directory holds and resumes any work left under way, so the same call starts a fresh client and restarts an old one.

Working code: go/examples/chat, rust/examples/chat.rs.

How to connect two parties

One party founds the group and the other joins it with a contact voucher. The joiner mints the voucher; its code appears in the group’s view once minted; the founder invites that code. The code travels out of band: in person, over another messenger, or over a service connection (below).

Go:

// Founder
id, _ := c.Create("fetcher")

// Joiner
id, _ := c.Join("fetcher")
v, _ := c.Chat(id)        // poll or watch events until v.Code != ""
fmt.Println(v.Code)       // hand this to the founder

// Founder, given the code
c.Invite(id, code)

Rust:

let id = c.create("fetcher").await?;          // founder
let id = c.join("fetcher").await?;            // joiner; c.chat(&id).await?.code is the voucher code
c.invite(&id, &code).await?;                  // founder, given the code

The group appears as joined on the joiner’s side once the invitation is read, which on the mixnet takes a few minutes. ChatView.Joined says when.

How to run your protocol inside the group

Send requests as text and watch events for replies. Each event names a group and the lines added or changed; ask for the lines and act on the ones that are not yours.

Go:

c.Send(id, `{"fetch":"https://example.org/"}`)

for ev := range events {
    if ev.Err != nil { return ev.Err }           // the client stopped
    lines, _ := c.Lines(ev.Chat, last)           // lines after the last one handled
    for _, l := range lines {
        last = l.ID
        if l.Mine || l.Notice != nil { continue }
        handle(l.From, l.Text)                   // or l.Attachment, via c.FilePath
    }
}

Rust:

c.send(&id, r#"{"fetch":"https://example.org/"}"#).await?;

while let Some(ev) = events.recv().await {
    if let Some(e) = ev.error { return Err(e.into()); }
    for l in c.lines(&ev.chat, Some(last)).await? {
        last = l.line.id;
        if l.mine || l.line.notice.is_some() { continue; }
        handle(&l.from, &l.line.text);           // or l.line.attachment, via c.read_file
    }
}

Three habits make this robust:

  • Keep last on disk. Lines are numbered per group and the store keeps them, so after a restart you ask for the lines after the last one you handled and nothing is replayed or missed. The zulip bridge keeps this mark in a file beside its state.
  • Put large things in files. SendFile seals and chunks a file and the other side gets an attachment with a path. A text line is for what fits in one box; the client splits longer text, but a file is the honest form for a payload.
  • Choose a text encoding and stick to it. JSON or base64 CBOR in a line is fine. Members who are people will see it, so a bot that also talks to humans should answer plain text to plain text.

Working code: the zulip bridge, rust/src/services/zulip/mod.rs (to_zulip reads the group from a mark; from_zulip writes into it).

How to be a service that clients can find

A service has a NIKE keypair; its ID is the hash of the public key, 64 hex digits, and that is what you publish. On start it registers with voucher routers and advertises a descriptor naming them in the service directory. A client looks the descriptor up, mints a voucher, seals it to the service’s key and hands it to one of the routers; the service inducts it, and the two share a two-way connection. The framework does all of that; you write the handler.

Go, the service:

ph := common.NewThinPigeonhole(thinClient)
key, _ := ps.LoadServiceKey(dataDir)              // generated on first run
adv, _ := discovery.NewAll(ph, key, pollInterval) // every directory in the PKI

svc, _ := ps.NewService(ps.Config{
    Key: key, DataDir: dataDir, DisplayName: "fetcher",
    Advertiser: adv, PollInterval: pollInterval, Log: logger,
}, ph)
fmt.Println(hex.EncodeToString(svc.ID()[:]))

svc.Run(ctx, ps.HandlerFunc(func(ctx context.Context, s *ps.Session) {
    for {
        msg, err := s.Recv(ctx)
        if err != nil { return }
        s.Send(ctx, reply(msg))
    }
}))

Go, the client:

ph := common.NewThinPigeonhole(thinClient)
dir, _ := discovery.NewAll(ph, nil, pollInterval)
d, _ := dir.Lookup(ctx, serviceID)
conn, _ := ps.Dial(ctx, ph, d, "fetcher client", pollInterval)
conn.Send(ctx, request)
raw, _ := conn.Recv(ctx)

Rust, the service:

let backend = Arc::new(ThinClientBackend::dial("@katzenpost").await?);
let key = Keypair::load_or_generate(&*backend, &data_dir, "fetcher").await?;
let mut cfg = Config::new(key, data_dir.join("state"));
cfg.display_name = "fetcher".into();
let svc = Service::new(cfg, backend.clone())?;
log::info!("service id {}", svc.id());
svc.run(|session| async move {
    while let Ok(msg) = session.recv().await {
        if session.send(&reply(&msg)).await.is_err() { return; }
    }
}).await?;

Rust, the client:

let dirs = Directory::all(backend.clone(), None, poll).await?;
let d = dirs[0].lookup(service_id).await?;
let conn = services::dial(backend.clone(), &d, "fetcher client", poll).await?;
conn.send(&request).await?;
let raw = conn.recv().await?;

Messages are CBOR by convention; common.Marshal and Unmarshal in Go, services::cbor in Rust. A message must fit in one box; max_message says how large that is.

Sessions and the service’s router links are kept in the data directory and restored on restart, so a service picks up its open sessions where it left them. Session.restored() in Rust tells a handler it is resuming one, so it does not greet twice.

Working code: go/cmd/motd-service and go/cmd/motd, rust/src/bin/eliza.rs, and the end-to-end tests in go/pigeonservice/service_test.go and rust/tests/services.rs.

How to let chat users reach your service

A katzenqt user adds a contact by pasting a voucher code. A Rust service can mint such codes itself with Service::offer; each is used once, survives restarts until it is, and the session it opens arrives through accept and run like any other. Eliza keeps a few on disk for its operator to hand out:

tokio::spawn(eliza::keep_vouchers(svc.clone(), data_dir.join("vouchers"), 3));

The Go framework does not offer vouchers yet; a Go service is reached through the directory.

How to move a service connection into a group

This is the pattern to copy. The service connection is the lobby: it tells the client how to join and takes the client’s join code. From then on everything travels in the group, with the group chat protocol’s reliability and persistence, and the lobby connection is left alone.

The zulip bridge does exactly this. It is a member of one group, and its service handler is a short conversation that ends in an invitation:

pub async fn join<B: Backend>(&self, session: Session<B>) {
    let max = session.max_message().await?;
    if !session.restored() {
        send(&session, "To join: in your chat app, ask to join a group, and paste the voucher code it shows here.", max).await?;
    }
    loop {
        match recv_text(&session).await {
            Ok(Some(code)) => {
                let reply = match self.client.invite(&self.chat, code.trim()).await {
                    Ok(()) => "Inviting you; the group appears in your app once the invitation is read.",
                    Err(ClientError::NotAVoucher) => "That is not a voucher code.",
                    Err(e) => return log::warn!("{e}"),
                };
                send(&session, reply, max).await?;
            }
            Ok(None) => continue,
            Err(e) => return log::warn!("a session ended: {e}"),
        }
    }
}

self.client is an ordinary group chat client the service opened at start, in a group it founded. One service, one group, every client a member works for a bridge or a broadcast. A fetcher that must keep each client’s requests private founds a fresh group per client instead: create a group in the handler, invite the code into it, and serve that group’s lines.

Working code: rust/src/services/zulip and its README, and rust/tests/services_zulip.rs.

How to test without a mixnet

Everything above takes a transport.Backend, and two of them need no network.

In-process, for unit tests: sim.NewWorld() in Go and transport::sim in Rust are an in-memory Pigeonhole that follows the replicas’ rules: a box lives for its epoch and the next, a rewrite of the same bytes succeeds, other bytes are refused. A hook sees every read and write and can fail it, which is how the crash and flaky-network tests are written.

In a process of its own, for clients that are killed and restarted or for Go and Rust sharing one Pigeonhole: pigeonhole-sim serves the in-memory backend over a unix socket, and the remote backend dials it.

cd go && go run ./cmd/pigeonhole-sim -socket ../pigeonhole.sock
cd go && go run ./examples/chat -name alice -state alice -sim ../pigeonhole.sock
cd rust && cargo run --release --example chat -- -name bob -state bob -sim ../pigeonhole.sock

Then against the real thing: make e2e DAEMON=@katzenpost runs two clients over a running client daemon, and go/services/interop runs the services, a router and a directory against katzenpost’s localnet or a live mixnet.

Where things are

Go Rust
Group chat client go/protocols/katzenqt1/client protocols::katzenqt1::client
Service framework go/pigeonservice services
Directory and routers katzenpost pigeonservice/discovery, pigeonservice/voucher_router services::Directory, services::dial
Backends go/transport/{thinclient,sim,remote} transport::{thinclient,sim,remote}
Services shipped motd eliza, zulip-bridge

A Python implementation of the group chat client is in py/; it has no service framework yet.

5 -

Generated API reference for the Katzenpost Python thin client (katzenpost_thinclient)

Python Thin Client API

This is the API reference for the katzenpost_thinclient Python package, the Python binding of the Katzenpost thin client. The thin client is an interface to the kpclientd daemon, which performs all cryptographic and network operations; the binding itself does no cryptography.

This page is generated by website/tools/python-api-gen/ from the docstrings of the pinned katzenpost_thinclient release, using the native Python documentation tool pydoc-markdown. Do not edit it directly: changes belong in the binding docstrings (in the thin_client repository) and will be overwritten by the next generation pass.

This page documents the 0.0.23 release of the Python binding (source, PyPI). Symbols are re-exported from katzenpost_thinclient, so application code may import them directly, for example from katzenpost_thinclient import ThinClient, Config.

For the curated cross-language reference covering the Go, Rust, and Python bindings side by side, see the Thin Client API Reference. For conceptual background see Understanding Pigeonhole, and for task-oriented guidance see the Thin Client How-to Guide.


katzenpost_thinclient.core

Katzenpost Python Thin Client - Core Module

This module provides the core functionality for the Katzenpost thin client, including the ThinClient class, configuration, and helper utilities.


thin_client_error_to_string

def thin_client_error_to_string(error_code: int) -> str

Convert a thin client error code to a human-readable string.


error_code_to_exception

def error_code_to_exception(error_code: int) -> Exception

Maps error codes to exception instances for StartResendingEncryptedMessage. This matches Go’s errorCodeToSentinel function in thin/pigeonhole.go.

The daemon passes through pigeonhole replica error codes (1-9) for replica-level errors. For other errors (thin client errors like decryption failures), specific exceptions are raised.


copy_reply_to_exception

def copy_reply_to_exception(reply: "Dict[str, Any]") -> "Exception | None"

Maps a StartResendingCopyCommandReply dict to an exception (or None on success).

Unlike error_code_to_exception(), this helper has access to the reply’s diagnostic fields (replica_error_code, failed_envelope_index), which it uses to construct a CopyCommandFailedError when the courier reports THIN_CLIENT_ERROR_COPY_COMMAND_FAILED.

Arguments:

  • reply - The decoded start_resending_copy_command_reply dict.

Returns:

None if error_code is 0 (success); otherwise an Exception instance.


is_expected_outcome

def is_expected_outcome(exc: Exception) -> bool

Returns True for exceptions that represent completed operations rather than failures. These errors should not trigger retries.


Geometry

class Geometry()

Geometry describes the geometry of a Sphinx packet.

NOTE: You must not try to compose a Sphinx Geometry yourself. It must be programmatically generated by Katzenpost genconfig or gensphinx CLI utilities.

We describe all the Sphinx Geometry attributes below, however the only one you are interested in to faciliate your thin client message bounds checking is UserForwardPayloadLength, which indicates the maximum sized message that you can send to a mixnet service in a single packet.

Attributes:

  • PacketLength int - The total length of a Sphinx packet in bytes.
  • NrHops int - The number of hops; determines the header’s structure.
  • HeaderLength int - The total size of the Sphinx header in bytes.
  • RoutingInfoLength int - The length of the routing information portion of the header.
  • PerHopRoutingInfoLength int - The length of routing info for a single hop.
  • SURBLength int - The length of a Single-Use Reply Block (SURB).
  • SphinxPlaintextHeaderLength int - The length of the unencrypted plaintext header.
  • PayloadTagLength int - The length of the tag used to authenticate the payload.
  • ForwardPayloadLength int - The size of the full payload including padding and tag.
  • UserForwardPayloadLength int - The usable portion of the payload intended for the recipient.
  • NextNodeHopLength int - Derived from the expected maximum routing info block size.
  • SPRPKeyMaterialLength int - The length of the key used for SPRP (Sphinx packet payload encryption).
  • NIKEName str - Name of the NIKE scheme (if used). Mutually exclusive with KEMName.
  • KEMName str - Name of the KEM scheme (if used). Mutually exclusive with NIKEName.

PigeonholeGeometry

class PigeonholeGeometry()

PigeonholeGeometry describes the geometry of a Pigeonhole envelope.

This provides mathematically precise geometry calculations for the Pigeonhole protocol using trunnel’s fixed binary format.

It supports 3 distinct use cases:

  1. Given MaxPlaintextPayloadLength → compute all envelope sizes
  2. Given precomputed Pigeonhole Geometry → derive accommodating Sphinx Geometry
  3. Given Sphinx Geometry constraint → derive optimal Pigeonhole Geometry

Attributes:

  • max_plaintext_payload_length int - The maximum usable plaintext payload size within a Box.
  • courier_query_read_length int - The size of a CourierQuery containing a ReplicaRead.
  • courier_query_write_length int - The size of a CourierQuery containing a ReplicaWrite.
  • courier_query_reply_read_length int - The size of a CourierQueryReply containing a ReplicaReadReply.
  • courier_query_reply_write_length int - The size of a CourierQueryReply containing a ReplicaWriteReply.
  • nike_name str - The NIKE scheme name used in MKEM for encrypting to multiple storage replicas.
  • signature_scheme_name str - The signature scheme used for BACAP (always “Ed25519”).

PigeonholeGeometry.validate

def validate() -> None

Validates that the geometry has valid parameters.

Raises:

  • ValueError - If the geometry is invalid.

PigeonholeGeometry.padded_payload_length

def padded_payload_length() -> int

Returns the payload size after adding length prefix.

Returns:

  • int - The padded payload length (max_plaintext_payload_length + 4).

ConfigFile

class ConfigFile()

ConfigFile represents everything loaded from a TOML file: only the subtable-discriminated Dial transport config. The geometries are supplied by the daemon over the handshake, not configured here.

ConfigFile.load

@classmethod
def load(cls, toml_path: str) -> "ConfigFile"

Parse a kpclientd-style thin-client TOML config.

Raises ConfigError eagerly on any structural problem: unknown top-level sections (a leftover [SphinxGeometry] or [PigeonholeGeometry] is now rejected here), missing required sections, wrong types, or unknown / missing keys within the Dial subtable. The intent is that a stale or drifted config fails here at startup rather than producing a mysterious runtime failure later.


pretty_print_obj

def pretty_print_obj(obj: "Any") -> str

Pretty-print a Python object using indentation and return the formatted string.

This function uses pprintpp to format complex data structures (e.g., dictionaries, lists) in a readable, indented format.

Arguments:

  • obj Any - The object to pretty-print.

Returns:

  • str - The pretty-printed representation of the object.

ServiceDescriptor

class ServiceDescriptor()

Describes a mixnet service endpoint retrieved from the PKI document.

A ServiceDescriptor encapsulates the necessary information for communicating with a service on the mix network. The service node’s identity public key’s hash is used as the destination address along with the service’s queue ID.

Attributes:

  • recipient_queue_id bytes - The identifier of the recipient’s queue on the mixnet. (“Kaetzchen.endpoint” in the PKI)
  • mix_descriptor dict - A CBOR-decoded dictionary describing the mix node, typically includes the ‘IdentityKey’ and other metadata.

Methods:

  • to_destination() - Returns a tuple of (provider_id_hash, recipient_queue_id), where the provider ID is a 32-byte BLAKE2b hash of the IdentityKey.

ServiceDescriptor.to_destination

def to_destination() -> "Tuple[bytes,bytes]"

provider identity key hash and queue id


find_services

def find_services(capability: str,
                  doc: "Dict[str,Any]") -> "List[ServiceDescriptor]"

Search the PKI document for services supporting the specified capability.

This function iterates over all service nodes in the PKI document, deserializes each CBOR-encoded node, and looks for advertised capabilities. If a service provides the requested capability, it is returned as a ServiceDescriptor.

Arguments:

  • capability str - The name of the capability to search for (e.g., “echo”).
  • doc dict - The decoded PKI document as a Python dictionary, which must include a “ServiceNodes” key containing CBOR-encoded descriptors.

Returns:

  • List[ServiceDescriptor] - A list of matching service descriptors that advertise the capability.

Raises:

  • KeyError - If the ‘ServiceNodes’ field is missing from the PKI document.

Config

class Config()

Configuration object for the ThinClient containing connection details and event callbacks.

The Config class loads network configuration from a TOML file and provides optional callback functions that are invoked when specific events occur during client operation.

Attributes:

  • network str - Network type (’tcp’, ‘unix’, etc.)
  • address str - Network address (host:port for TCP, path for Unix sockets)
  • geometry Geometry - Sphinx packet geometry parameters
  • on_connection_status callable - Callback for connection status changes
  • on_new_pki_document callable - Callback for new PKI documents
  • on_message_sent callable - Callback for message transmission confirmations
  • on_message_reply callable - Callback for received message replies

Example:

def handle_reply(event):
# Process the received reply
payload = event['payload']

config = Config("client.toml", on_message_reply=handle_reply)
client = ThinClient(config)

Config.__init__

def __init__(filepath: str,
             on_connection_status: "Callable|None" = None,
             on_new_pki_document: "Callable|None" = None,
             on_message_sent: "Callable|None" = None,
             on_message_reply: "Callable|None" = None,
             on_daemon_disconnected: "Callable|None" = None) -> None

Initialize the Config object.

Arguments:

  • filepath str - Path to the TOML config file containing network, address, and geometry.

  • on_connection_status callable, optional - Callback invoked when the daemon’s connection status to the mixnet changes. The callback receives a single argument:

    • event (dict): Connection status event with keys:
    • ‘is_connected’ (bool): True if daemon is connected to mixnet, False otherwise
    • ’err’ (str, optional): Error message if connection failed, empty string if no error
  • Example - {'is_connected': True, 'err': ''}

  • on_new_pki_document callable, optional - Callback invoked when a new PKI document is received from the mixnet. The callback receives a single argument:

    • event (dict): PKI document event with keys:
    • ‘payload’ (bytes): CBOR-encoded PKI document data stripped of signatures
  • Example - {'payload': b'\xa5\x64Epoch\x00...'}

  • on_message_sent callable, optional - Callback invoked when a message has been successfully transmitted to the mixnet. The callback receives a single argument:

    • event (dict): Message sent event with keys:
    • ‘message_id’ (bytes): 16-byte unique identifier for the sent message
    • ‘surbid’ (bytes, optional): SURB ID if message was sent with SURB, None otherwise
    • ‘sent_at’ (str): ISO timestamp when message was sent
    • ‘reply_eta’ (float): Expected round-trip time in seconds for reply
    • ’err’ (str, optional): Error message if sending failed, empty string if successful
  • Example - {'message_id': b'\x01\x02...', 'surbid': b'\xaa\xbb...', 'sent_at': '2024-01-01T12:00:00Z', 'reply_eta': 30.5, 'err': ''}

  • on_message_reply callable, optional - Callback invoked when a reply is received for a previously sent message. The callback receives a single argument:

    • event (dict): Message reply event with keys:
    • ‘message_id’ (bytes): 16-byte identifier matching the original message
    • ‘surbid’ (bytes, optional): SURB ID if reply used SURB, None otherwise
    • ‘payload’ (bytes): Reply payload data from the service
    • ‘reply_index’ (int, optional): Index of reply used (relevant for channel reads)
    • ’error_code’ (int): Error code indicating success (0) or specific failure condition
  • Example - {'message_id': b'\x01\x02...', 'surbid': b'\xaa\xbb...', 'payload': b'echo response', 'reply_index': 0, 'error_code': 0}

Notes:

All callbacks are optional. If not provided, the corresponding events will be ignored. Callbacks should be lightweight and non-blocking as they are called from the client’s event processing loop.


ThinClient

class ThinClient()

A minimal Katzenpost Python thin client for communicating with the local Katzenpost client daemon over a UNIX or TCP socket.

The thin client is responsible for:

  • Establishing a connection to the client daemon.
  • Receiving and parsing PKI documents.
  • Sending messages to mixnet services (with or without SURBs).
  • Handling replies and events via user-defined callbacks.

All cryptographic operations are handled by the daemon, not by this client.

ThinClient.__init__

def __init__(config: Config) -> None

Initialize the thin client with the given configuration.

Arguments:

  • config Config - The configuration object containing socket details and callbacks.

Raises:

  • RuntimeError - If the network type is not recognized or config is incomplete.

ThinClient.start

async def start(loop: asyncio.AbstractEventLoop) -> None

Start the thin client: establish connection to the daemon, read initial events, and begin the background event loop.

Arguments:

  • loop asyncio.AbstractEventLoop - The running asyncio event loop.

    Exceptions: BrokenPipeError

ThinClient.is_connected

def is_connected() -> bool

Returns True if the daemon is currently connected to the mixnet.

Note the distinction: this reflects the daemon’s mixnet connectivity, not the local socket between this thin client and the daemon. The daemon may be reachable while the mixnet itself is unreachable; in that case the local socket is fine but this method returns False, and send_message / blocking_send_message will raise ThinClientOfflineError. The latest value is updated from ConnectionStatusEvents pushed by the daemon.

Returns:

  • bool - True if the daemon is connected to the mixnet, False otherwise (offline mode).

ThinClient.stop

def stop() -> None

Gracefully shut down the client and close its socket. Sends a thin_close message to the daemon so it can clean up ARQ state for this connection before disconnecting.

ThinClient.disconnect

def disconnect() -> None

Close the connection without sending thin_close. The daemon preserves all state for this client’s app ID, allowing the client to reconnect and resume with the same session token.

ThinClient.recv

async def recv(loop: asyncio.AbstractEventLoop) -> "Dict[Any,Any]"

Receive a CBOR-encoded message from the daemon.

Arguments:

  • loop asyncio.AbstractEventLoop - Event loop to use for socket reads.

Returns:

  • dict - Decoded CBOR response from the daemon.

Raises:

  • BrokenPipeError - If connection fails
  • ValueError - If message framing fails.

ThinClient.worker_loop

async def worker_loop(loop: asyncio.events.AbstractEventLoop) -> None

Background task that listens for events and dispatches them. Survives daemon disconnects by automatically reconnecting with exponential backoff. Only stopping (from stop()) causes this task to exit.

ThinClient.parse_status

def parse_status(event: "Dict[str,Any]") -> None

Parse a connection status event and update connection state.

ThinClient.pki_document

def pki_document() -> "Dict[str,Any] | None"

Return the most recent PKI consensus document the daemon has forwarded to this thin client.

The document is a CBOR map describing the current mixnet topology, the set of available services, and per-node public-key material. Useful inputs include the PKI epoch, the list of mix nodes, the list of service providers, and the replica descriptors consulted by Pigeonhole.

Returns:

Dict[str, Any] | None: The parsed CBOR PKI document, or None if the daemon has not yet forwarded one (most commonly on a freshly-connected client, before the first on_new_pki_document callback has fired).

ThinClient.pki_document_for_epoch

def pki_document_for_epoch(epoch: int) -> "Dict[str,Any]"

Return the cached PKI document for a specific epoch.

Falls back to the current document if the requested epoch is not cached. Raises if no document is available at all.

Arguments:

  • epoch int - The epoch number.

Returns:

  • dict - Parsed PKI document for the given epoch.

Raises:

  • Exception - If no PKI document is available.

ThinClient.get_pki_document_raw

async def get_pki_document_raw(epoch: int = 0) -> "Tuple[bytes,int]"

Return the cert.Certificate-wrapped signed PKI document for the requested epoch, with every directory authority signature intact.

The thin client receives the stripped PKI document by default (via the on_new_pki_document callback, also available through :py:meth:pki_document and :py:meth:pki_document_for_epoch); the daemon nils the signature map before forwarding it. Use this method when the caller wishes to verify the directory authority signatures itself: the returned payload may be deserialized and verified with the katzenpost core/pki.FromPayload routine against the authorities listed in client.toml.

Arguments:

  • epoch int - Epoch for which the signed PKI document should be returned. Pass 0 (the default) to request the document the daemon believes is current.

Returns:

Tuple[bytes, int]: (payload, epoch) where payload is the cert.Certificate-wrapped signed PKI document and epoch is the epoch of the returned document. When 0 was passed in, epoch echoes the epoch the daemon resolved to.

Raises:

  • Exception - If the daemon has no cached document for the requested epoch, or any other error code is returned.

ThinClient.get_directory_authorities

async def get_directory_authorities() -> "List[Dict[str,Any]]"

Return the directory authority descriptors the client daemon is configured with.

A thin client holds only its dial transport configuration and never sees the daemon’s voting authority peer list. This surfaces it, so a caller may, for instance, map a PKI document’s signature fingerprints (the keys of its signature map) to authority identifiers via each descriptor’s identity_key_hash.

Returns:

List[Dict[str, Any]]: one dict per directory authority, with keys identifier (str), pki_signature_scheme (str), wire_kem_scheme (str), addresses (list of str), identity_public_key_pem (str), link_public_key_pem (str), and identity_key_hash (32 raw bytes, the value by which PKI document signatures are indexed).

Raises:

  • Exception - If the daemon has no voting authority peers configured, or any other error code is returned.

ThinClient.parse_pki_doc

def parse_pki_doc(event: "Dict[str,Any]") -> None

Parse and store a new PKI document received from the daemon.

ThinClient.get_services

def get_services(capability: str) -> "List[ServiceDescriptor]"

Look up all services in the PKI that advertise a given capability.

Arguments:

  • capability str - Capability name (e.g., “echo”).

Returns:

  • list[ServiceDescriptor] - Matching services.xsy

Raises:

  • Exception - If PKI is missing or no services match.

ThinClient.get_service

def get_service(service_name: str) -> ServiceDescriptor

Select one random service matching a capability from the current PKI document.

Multiple mix nodes may advertise the same capability; this method returns an arbitrary one. To see every advertised instance, use get_services.

Arguments:

  • service_name str - The capability name (e.g. "echo", "courier").

Returns:

  • ServiceDescriptor - One of the matching services.

Raises:

  • Exception - If the PKI document is missing, or no node in the current consensus advertises service_name.

ThinClient.blocking_send_message

async def blocking_send_message(payload: bytes | str,
                                dest_node: bytes,
                                dest_queue: bytes,
                                timeout_seconds: float = 30.0) -> bytes

Send a message and block until a reply is received or timeout.

Arguments:

  • payload bytes or str - Message payload.
  • dest_node bytes - Destination node identity hash.
  • dest_queue bytes - Destination recipient queue ID.
  • timeout_seconds float - Timeout in seconds (default 30).

Returns:

  • bytes - Reply payload from the destination service.

Raises:

  • ThinClientOfflineError - If in offline mode.
  • asyncio.TimeoutError - If no reply within timeout.

ThinClient.new_message_id

@staticmethod
def new_message_id() -> bytes

Generate a new 16-byte random message ID.

Message IDs are used to correlate SendMessage requests with their corresponding MessageSentEvent and (if a SURB is present) MessageReplyEvent. Callers generally do not need to construct one by hand — blocking_send_message does it internally — but this helper is exposed for callers composing requests manually. Randomness is drawn from os.urandom.

Returns:

  • bytes - Random 16-byte identifier.

ThinClient.new_surb_id

def new_surb_id() -> bytes

Generate a new random SURB ID.

SURB IDs identify which Single Use Reply Block a given on_message_reply event corresponds to. Pass the returned bytes as the surb_id argument to send_message, then watch the callback for a matching reply. Randomness is drawn from os.urandom.

Returns:

  • bytes - Random identifier of SURB_ID_SIZE bytes.

ThinClient.new_query_id

def new_query_id() -> bytes

Generate a new 16-byte random query ID.

Query IDs correlate requests and replies within the thin client ↔ daemon CBOR protocol (distinct from mix-network SURB IDs, which identify replies within the mixnet itself). Most callers never touch query IDs directly; they are used internally by the Pigeonhole API helpers. Randomness is drawn from os.urandom.

Returns:

  • bytes - Random 16-byte identifier.

ThinClient.handle_response

async def handle_response(response: "Dict[str,Any]") -> None

Dispatch a parsed CBOR response to the appropriate handler or callback.

ThinClient.send_message_without_reply

async def send_message_without_reply(payload: bytes | str, dest_node: bytes,
                                     dest_queue: bytes) -> None

Send a fire-and-forget message with no SURB or reply handling. This method requires mixnet connectivity.

Arguments:

  • payload bytes or str - Message payload.
  • dest_node bytes - Destination node identity hash.
  • dest_queue bytes - Destination recipient queue ID.

Raises:

  • ThinClientOfflineError - If in offline mode (daemon not connected to mixnet).

ThinClient.send_message

async def send_message(surb_id: bytes, payload: bytes | str, dest_node: bytes,
                       dest_queue: bytes) -> None

Send a message using a SURB to allow the recipient to send a reply. This method requires mixnet connectivity.

Arguments:

  • surb_id bytes - SURB identifier for reply correlation.
  • payload bytes or str - Message payload.
  • dest_node bytes - Destination node identity hash.
  • dest_queue bytes - Destination recipient queue ID.

Raises:

  • ThinClientOfflineError - If in offline mode (daemon not connected to mixnet).

ThinClient.pretty_print_pki_doc

def pretty_print_pki_doc(doc: "Dict[str,Any]") -> None

Pretty-print a parsed PKI document with fully decoded CBOR nodes.

Arguments:

  • doc dict - Raw PKI document from the daemon.

katzenpost_thinclient.pigeonhole

Katzenpost Python Thin Client - New Pigeonhole API

This module provides the new capability-based Pigeonhole API methods. These methods use WriteCap/ReadCap keypairs and provide direct control over the Pigeonhole protocol.


KeypairResult

@dataclass
class KeypairResult()

Result from new_keypair containing the generated capabilities.


EncryptReadResult

@dataclass
class EncryptReadResult()

Result from encrypt_read containing the encrypted read request.


EncryptWriteResult

@dataclass
class EncryptWriteResult()

Result from encrypt_write containing the encrypted write request.


StartResendingResult

@dataclass
class StartResendingResult()

Result from start_resending_encrypted_message and its variants.

StartResendingResult.plaintext

Decrypted message for read operations, or empty bytes for writes.

StartResendingResult.courier_identity_hash

32-byte hash of the identity key of the courier that handled this message. Callers can watch PKI document updates for this courier disappearing from consensus and cancel+re-encrypt if needed.

StartResendingResult.courier_queue_id

Queue ID of the courier that handled this message.


VoucherMintResult

@dataclass
class VoucherMintResult()

Result from voucher_mint.

Hand voucher to the inductor out of band and publish voucher_payload to VoucherStream box 0. Persist voucher_secret_key to open the inductor’s reply later.


VoucherInductResult

@dataclass
class VoucherInductResult()

Result from voucher_induct.

mutated_message_read_cap is the joiner’s salt-mutated read cap: the live read cap the inductor hands the group. Write sealed_reply to VoucherStream box 1.


VoucherOpenResult

@dataclass
class VoucherOpenResult()

Result from voucher_open.

mutated_message_write_cap is the joiner’s salt-mutated write cap: the live write cap for real messages, which lands on the same box sequence as the read cap the inductor handed the group.


VoucherStreamResult

@dataclass
class VoucherStreamResult()

Result from voucher_derive_stream: the rendezvous stream caps.


new_keypair

async def new_keypair(self, seed: bytes) -> KeypairResult

Creates a new keypair for use with the Pigeonhole protocol.

This method generates a WriteCap and ReadCap from the provided seed using the BACAP (Blinding-and-Capability) protocol. The WriteCap should be stored securely for writing messages, while the ReadCap can be shared with others to allow them to read messages.

Arguments:

  • seed - 32-byte seed used to derive the keypair.

Returns:

  • KeypairResult - Contains write_cap, read_cap, and first_message_index.

Raises:

  • Exception - If the keypair creation fails.
  • ValueError - If seed is not exactly 32 bytes.

Example:

import os
seed = os.urandom(32)
result = await client.new_keypair(seed)
# Share result.read_cap with Bob so he can read messages
# Store result.write_cap for sending messages

encrypt_read

async def encrypt_read(self, read_cap: bytes,
                       message_box_index: bytes) -> EncryptReadResult

Encrypts a read operation for a given read capability.

This method prepares an encrypted read request that can be sent to the courier service to retrieve a message from a pigeonhole box. The returned ciphertext should be sent via start_resending_encrypted_message.

Arguments:

  • read_cap - Read capability that grants access to the channel.
  • message_box_index - Starting read position for the channel.

Returns:

  • EncryptReadResult - Contains message_ciphertext, envelope_descriptor, and envelope_hash.

Raises:

  • Exception - If the encryption fails.

Example:

result = await client.encrypt_read(read_cap, message_box_index)
# Send result.message_ciphertext via start_resending_encrypted_message

encrypt_write

async def encrypt_write(self, plaintext: bytes, write_cap: bytes,
                        message_box_index: bytes) -> EncryptWriteResult

Encrypts a write operation for a given write capability.

This method prepares an encrypted write request that can be sent to the courier service to store a message in a pigeonhole box. The returned ciphertext should be sent via start_resending_encrypted_message.

Plaintext Size Constraint: The plaintext must not exceed PigeonholeGeometry.max_plaintext_payload_length bytes. The daemon internally adds a 4-byte big-endian length prefix before padding and encryption, so the actual wire format is: [4-byte length][plaintext][zero padding].

If the plaintext exceeds the maximum size, the daemon will return ThinClientErrorInvalidRequest.

Arguments:

  • plaintext - The plaintext message to encrypt. Must be at most PigeonholeGeometry.max_plaintext_payload_length bytes.
  • write_cap - Write capability that grants access to the channel.
  • message_box_index - The message box index for this write operation.

Returns:

  • EncryptWriteResult - Contains message_ciphertext, envelope_descriptor, and envelope_hash.

Raises:

  • Exception - If the encryption fails (including if plaintext is too large).

Example:

plaintext = b"Hello, Bob!"
result = await client.encrypt_write(plaintext, write_cap, message_box_index)
# Send result.message_ciphertext via start_resending_encrypted_message

start_resending_encrypted_message

async def start_resending_encrypted_message(
        self,
        read_cap: "bytes|None",
        write_cap: "bytes|None",
        message_box_index: "bytes|None",
        reply_index: "int|None",
        envelope_descriptor: bytes,
        message_ciphertext: bytes,
        envelope_hash: bytes,
        *,
        no_retry_on_box_id_not_found: bool = False,
        no_idempotent_box_already_exists: bool = False
) -> StartResendingResult

Sends an encrypted read or write request to a courier through the daemon’s stop-and-wait ARQ and blocks until the operation completes, fails, or is cancelled via cancel_resending_encrypted_message. The daemon retransmits until the courier answers; see https://katzenpost.network/docs/pigeonhole_explained/#the-pigeonhole-arq for the retransmission behavior and per-operation round-trip costs.

A write completes on the courier’s ACK, a single mixnet round trip, and by default treats BoxAlreadyExists as idempotent success. A read is two-phased: after the ACK the daemon collects the payload with a fresh SURB, decrypts it, and returns the plaintext; by default a read retries BoxIDNotFound until the box is written.

The two keyword-only flags select the variant behaviors that the Go binding exposes as separate methods (StartResendingEncryptedMessageNoRetry and StartResendingEncryptedMessageReturnBoxExists).

Arguments:

  • read_cap - Read capability (can be None for write operations, required for reads).
  • write_cap - Write capability (can be None for read operations, required for writes).
  • message_box_index - Current message box index being operated on (required for reads).
  • reply_index - Index of the reply to use (typically 0 or 1).
  • envelope_descriptor - Serialized envelope descriptor for MKEM decryption.
  • message_ciphertext - MKEM-encrypted message to send (from encrypt_read or encrypt_write).
  • envelope_hash - Hash of the courier envelope.
  • no_retry_on_box_id_not_found - If True, BoxIDNotFound errors on reads trigger immediate error instead of automatic retries. By default (False), reads retry on BoxIDNotFound until the box is found or the operation is cancelled, riding out replication lag; the retries are not capped. Set to True to get an immediate BoxIDNotFound error without retries.
  • no_idempotent_box_already_exists - If True, BoxAlreadyExists errors on writes are returned as errors instead of being treated as idempotent success. By default (False), BoxAlreadyExists is treated as success (the write already happened). Set to True to detect whether a write was actually performed or if the box already existed.

Returns:

  • StartResendingResult - Contains plaintext (decrypted message for reads, empty for writes), courier_identity_hash, and courier_queue_id.

Raises:

  • BoxIDNotFoundError - If no_retry_on_box_id_not_found=True and the box does not exist.
  • BoxAlreadyExistsError - If no_idempotent_box_already_exists=True and the box already contains data.
  • Exception - If the operation fails. Check error_code for specific errors.

Example:

result = await client.start_resending_encrypted_message(
read_cap, None, message_box_index, reply_idx, env_desc, ciphertext, env_hash)
print(f"Received: {result.plaintext}")

cancel_resending_encrypted_message

async def cancel_resending_encrypted_message(self,
                                             envelope_hash: bytes) -> None

Cancels ARQ resending for an encrypted message.

The daemon stops retransmitting the operation identified by envelope_hash, the blocked start_resending_encrypted_message caller raises an error, and the operation is removed from in-flight tracking so it is not replayed after a reconnect.

Arguments:

  • envelope_hash - Hash of the courier envelope to cancel.

Raises:

  • Exception - If the cancellation fails.

Example:

await client.cancel_resending_encrypted_message(env_hash)

next_message_box_index

async def next_message_box_index(self, message_box_index: bytes) -> bytes

Returns the message box index that follows message_box_index in its BACAP stream. The computation happens in the daemon and causes no mixnet traffic.

Most callers never need this method: encrypt_read, encrypt_write, and the copy stream constructors already return the next index alongside their results.

Arguments:

  • message_box_index - Current message box index to increment (as bytes).

Returns:

  • bytes - The next message box index.

Raises:

  • Exception - If the increment operation fails.

Example:

current_index = first_message_index
next_index = await client.next_message_box_index(current_index)
# Use next_index for the next message

get_message_box_index_counter

async def get_message_box_index_counter(self, message_box_index: bytes) -> int

Return the BACAP Idx64 counter embedded in a MessageBoxIndex.

Callers that persist MessageBoxIndex blobs across sessions can use this to order or compare two indexes — e.g. to detect a duplicate ACK that would otherwise regress a write-cap’s index — without having to peek at the binary layout themselves. The layout (first 8 bytes little-endian) is a BACAP implementation detail and must not be relied on outside the daemon.

Arguments:

  • message_box_index - MessageBoxIndex blob (as bytes) whose counter should be returned.

Returns:

  • int - The BACAP Idx64 value.

Raises:

  • Exception - If the daemon rejects the request.

Example:

current_idx = await client.get_message_box_index_counter(mbi_a)
next_idx = await client.get_message_box_index_counter(mbi_b)
if next_idx <= current_idx:
print("skipping stale ACK")

start_resending_copy_command

async def start_resending_copy_command(
        self,
        write_cap: bytes,
        courier_identity_hash: "bytes|None" = None,
        courier_queue_id: "bytes|None" = None) -> None

Sends a copy command to a courier through the daemon’s stop-and-wait ARQ and blocks until the courier acknowledges completion. The copy command hands the courier the write capability of a temporary copy stream; the courier executes the stream’s envelopes to their destination boxes and tombstones the temporary stream. See https://katzenpost.network/docs/pigeonhole_explained/#copy-commands for the workflow and its all-or-nothing semantics.

If courier_identity_hash and courier_queue_id are both provided, the copy command is pinned to that specific courier; otherwise the daemon picks one.

An in-flight call may be cancelled via cancel_resending_copy_command.

Arguments:

  • write_cap - Write capability for the temporary channel containing the data.
  • courier_identity_hash - Optional identity hash of a specific courier to use.
  • courier_queue_id - Optional queue ID for the specified courier. Must be set if courier_identity_hash is set.

Raises:

  • Exception - If the operation fails.

Example:

# Send copy command to a random courier
await client.start_resending_copy_command(temp_write_cap)
# Send copy command to a specific courier
await client.start_resending_copy_command(
temp_write_cap, courier_identity_hash, courier_queue_id)

cancel_resending_copy_command

async def cancel_resending_copy_command(self, write_cap_hash: bytes) -> None

Cancels ARQ resending for a copy command.

The daemon stops retransmitting the copy command identified by write_cap_hash (the blake2b-256 hash of the serialized write capability), and the operation is removed from in-flight tracking so it is not replayed after a reconnect.

Arguments:

  • write_cap_hash - Hash of the WriteCap used in start_resending_copy_command.

Raises:

  • Exception - If the cancellation fails.

Example:

await client.cancel_resending_copy_command(write_cap_hash)

create_courier_envelopes_from_payload

async def create_courier_envelopes_from_payload(
        self, payload: bytes, dest_write_cap: bytes, dest_start_index: bytes,
        is_start: bool, is_last: bool) -> "CreateEnvelopesResult"

Packs a payload of arbitrary size (up to 10 MB) into properly sized CopyStreamElement chunks for one destination channel. Each chunk is a serialised CopyStreamElement, ready to be written to a box via encrypt_write followed by start_resending_encrypted_message; the caller marks the boundaries of the stream with the is_start and is_last flags.

This method is stateless: no daemon state is kept between calls. It causes no mixnet traffic. See https://katzenpost.network/docs/pigeonhole_explained/#copy-commands for the copy command workflow the chunks feed into.

Multiple calls can target the same destination stream by passing next_dest_index from the previous result as dest_start_index.

Arguments:

  • payload - The data to be encoded into courier envelopes (max 10MB).
  • dest_write_cap - Write capability for the destination channel.
  • dest_start_index - Starting index in the destination channel.
  • is_start - Whether this is the first call (sets IsStart flag on first element).
  • is_last - Whether this is the last call (sets IsFinal flag on last element).

Returns:

  • CreateEnvelopesResult - Contains envelopes and next_dest_index.

Raises:

  • Exception - If the envelope creation fails.

create_courier_envelopes_from_multi_payload

async def create_courier_envelopes_from_multi_payload(
        self,
        destinations: "List[Dict[str, Any]]",
        is_start: bool,
        is_last: bool,
        buffer: "bytes | None" = None) -> "CreateEnvelopesResult"

Packs payloads bound for several destination channels into a single stream of CopyStreamElement chunks. This is more space-efficient than calling create_courier_envelopes_from_payload once per destination, because it avoids padding the final box of each destination independently.

This method is stateless: the buffer argument carries any residual state across calls. Pass None for buffer on the first call and the buffer returned by the previous call thereafter; set is_last on the final call to flush the remainder.

Arguments:

  • destinations - List of destination payloads, each a dict with:
    • “payload”: bytes - The data to be written
    • “write_cap”: bytes - Write capability for destination
    • “start_index”: bytes - Starting index in destination
  • is_start - Whether this is the first call in the sequence. When True, the first CopyStreamElement will have IsStart=true.
  • is_last - Whether this is the last set of payloads in the sequence. When True, the final CopyStreamElement will have IsFinal=true.
  • buffer - Residual encoder buffer from a previous call, or None.

Returns:

  • CreateEnvelopesResult - Contains envelopes and buffer for next call.

Raises:

  • Exception - If the envelope creation fails.

Example:

destinations = [
{"payload": data1, "write_cap": cap1, "start_index": idx1},
{"payload": data2, "write_cap": cap2, "start_index": idx2},
]
result = await client.create_courier_envelopes_from_multi_payload(
destinations, is_start=True, is_last=False)
# Pass buffer to next call
result2 = await client.create_courier_envelopes_from_multi_payload(
more_destinations, is_start=False, is_last=True, buffer=result.buffer)

CreateEnvelopesResult

@dataclass
class CreateEnvelopesResult()

Result of creating courier envelopes.

CreateEnvelopesResult.envelopes

The serialized CopyStreamElements to send to the network.

CreateEnvelopesResult.buffer

The buffered data that hasn’t been output yet. Persist this for crash recovery. Only populated by create_courier_envelopes_from_multi_payload.

CreateEnvelopesResult.next_dest_index

The next destination message box index after all boxes consumed by this call. Only populated by create_courier_envelopes_from_payload.

CreateEnvelopesResult.next_dest_indices

The next destination indices for each destination, in request order. Only populated by create_courier_envelopes_from_multi_payload.


TombstoneEnvelope

@dataclass
class TombstoneEnvelope()

A single tombstone envelope ready to be sent.


TombstoneRangeResult

@dataclass
class TombstoneRangeResult()

Result of a tombstone_range operation.


tombstone_range

async def tombstone_range(self, write_cap: bytes, start: bytes,
                          max_count: int) -> TombstoneRangeResult

Prepares the encrypted envelopes needed to tombstone a consecutive range of pigeonhole boxes beginning at the supplied MessageBoxIndex. A tombstone is a signed empty payload that deletes a box’s contents; see https://katzenpost.network/docs/pigeonhole_explained/#tombstones.

This method does not itself touch the network: it returns the envelopes for the caller to dispatch one by one, typically via start_resending_encrypted_message. To tombstone a single box, pass max_count=1.

Arguments:

  • write_cap - Write capability for the boxes.
  • start - Starting MessageBoxIndex.
  • max_count - Maximum number of boxes to tombstone.

Returns:

  • TombstoneRangeResult - Contains envelopes (list of TombstoneEnvelope) and next (the next MessageBoxIndex after the last processed).

Raises:

  • ValueError - If write_cap or start is None.

Example:

result = await client.tombstone_range(write_cap, start_index, 10)
for envelope in result.envelopes:
await client.start_resending_encrypted_message(
None, write_cap, None, None,
envelope.envelope_descriptor,
envelope.message_ciphertext,
envelope.envelope_hash)

create_courier_envelopes_from_tombstone_range

async def create_courier_envelopes_from_tombstone_range(
        self,
        dest_write_cap: bytes,
        dest_start_index: bytes,
        max_count: int,
        is_start: bool,
        is_last: bool,
        buffer: "bytes | None" = None) -> "CreateEnvelopesResult"

Packs tombstones for a consecutive range of destination boxes into CopyStreamElement chunks, combining tombstone creation with the copy stream encoding of create_courier_envelopes_from_payload.

This method is stateless: the buffer argument carries any residual state across calls. Pass None for buffer on the first call and the buffer returned by the previous call thereafter; set is_last on the final call to flush the remainder.

Arguments:

  • dest_write_cap - Write capability for the destination channel.
  • dest_start_index - Starting index in the destination channel.
  • max_count - Number of tombstones to create.
  • is_start - Whether this is the first call in the sequence.
  • is_last - Whether this is the last call in the sequence.
  • buffer - Residual encoder buffer from a previous call, or None.

Returns:

  • CreateEnvelopesResult - Contains envelopes, buffer, and next_dest_index.

Raises:

  • Exception - If the operation fails.

Example:

result = await client.create_courier_envelopes_from_tombstone_range(
write_cap, start_index, 10, is_start=True, is_last=True)
for envelope in result.envelopes:
# write envelope to temp copy stream channel
pass

voucher_mint

async def voucher_mint(self, message_write_cap: bytes,
                       display_name: str) -> VoucherMintResult

Mints a Voucher from the joiner’s MessageStream write cap.

Arguments:

  • message_write_cap - The joiner’s MessageStream write capability.
  • display_name - The joiner’s chosen display name.

Returns:

  • VoucherMintResult - The Voucher, the payload to publish, the rendezvous stream caps, and the reply keypair.

Raises:

  • Exception - If minting fails.

voucher_induct

async def voucher_induct(self, voucher: bytes, voucher_payload: bytes,
                         who_reply: bytes) -> VoucherInductResult

Verifies a published VoucherPayload and seals a reply to the joiner.

Arguments:

  • voucher - The 32-byte token received out of band.
  • voucher_payload - The payload read from VoucherStream box 0.
  • who_reply - The opaque group-membership blob to seal for the joiner.

Returns:

  • VoucherInductResult - The joiner’s salt-mutated read cap, the sealed reply to write to VoucherStream box 1, and the salt.

Raises:

  • Exception - If induction fails (e.g. hash mismatch or bad signature).

voucher_open

async def voucher_open(self, voucher_secret_key: bytes, sealed_reply: bytes,
                       message_write_cap: bytes) -> VoucherOpenResult

Opens the inductor’s sealed reply with the joiner’s voucher secret key, recovers the salt, and mutates the joiner’s MessageStream write cap by it.

Arguments:

  • voucher_secret_key - The joiner’s persisted voucher secret key.
  • sealed_reply - The bytes read from VoucherStream box 1.
  • message_write_cap - The joiner’s MessageStream write cap, mutated by the recovered salt to yield the live write cap for real messages.

Returns:

  • VoucherOpenResult - The opaque WhoReply, the salt, and the salt-mutated write cap.

Raises:

  • Exception - If opening fails (e.g. wrong key).

voucher_derive_stream

async def voucher_derive_stream(self, voucher: bytes) -> VoucherStreamResult

Derives the VoucherStream caps from the Voucher, which the inductor needs to read box 0 before inducting.

Arguments:

  • voucher - The 32-byte token.

Returns:

  • VoucherStreamResult - The rendezvous stream caps.

Raises:

  • Exception - If derivation fails.

katzenpost_thinclient.transport.tcp

TCP transport for the thin-client.


TcpDialConfig

@dataclass
class TcpDialConfig()

Configures a TCP dialer.

address is in host:port form, e.g. “localhost:64331” or “[::1]:64331”. network is one of “tcp”, “tcp4”, “tcp6”; defaults to “tcp”.


katzenpost_thinclient.transport

Transport abstraction for the Python thin-client.

Each concrete transport (unix, tcp; in future ssh / pipe / pigeonhole) exposes a setup_socket() method that returns a ready-to-connect socket and the server address in the form expected by asyncio’s loop.sock_connect.

DialConfig is a discriminated-union container: exactly one of its inner variants must be populated. Zero or multiple populated variants is a configuration error.


DialConfig

@dataclass
class DialConfig()

Discriminated-union of dial transports. Exactly one subtable must be populated.

DialConfig.resolve

def resolve() -> Any

Return the single populated transport variant.

DialConfig.from_toml_dict

@classmethod
def from_toml_dict(cls, data: dict) -> "DialConfig"

Parse a TOML [Dial] subtable (dict) into a DialConfig.

Rejects unknown subtables (typos, removed variants, future names) and unknown keys inside a recognised subtable. Exactly one of [Dial.Unix] / [Dial.Tcp] must be populated.


katzenpost_thinclient.transport.unix

Unix-domain-socket transport for the thin-client.


UnixDialConfig

@dataclass
class UnixDialConfig()

Configures a unix-domain-socket dialer.


Exceptions

Error types raised by the thin client; each derives from the standard library Exception.

ConfigError

class ConfigError(Exception)

Raised when the thin-client TOML config is missing required sections, contains unknown keys, or otherwise fails structural validation.

Every caller of ConfigFile.load / Config(…) should expect this exception. It is raised eagerly at startup so that a stale or drifted config produces a loud, early failure instead of surfacing later as a mysterious runtime error during mixnet operations.

ReplicaError

class ReplicaError(Exception)

Base class for all replica errors.

BoxIDNotFoundError

class BoxIDNotFoundError(ReplicaError)

Box ID not found on the replica. Occurs when reading from a non-existent mailbox.

InvalidBoxIDError

class InvalidBoxIDError(ReplicaError)

Invalid box ID format.

InvalidSignatureError

class InvalidSignatureError(ReplicaError)

Signature verification failed.

DatabaseFailureError

class DatabaseFailureError(ReplicaError)

Replica encountered a database error.

InvalidPayloadError

class InvalidPayloadError(ReplicaError)

Payload data is invalid.

StorageFullError

class StorageFullError(ReplicaError)

Replica’s storage capacity has been exceeded.

ReplicaInternalError

class ReplicaInternalError(ReplicaError)

Internal error on the replica.

InvalidEpochError

class InvalidEpochError(ReplicaError)

Epoch is invalid or expired.

ReplicationFailedError

class ReplicationFailedError(ReplicaError)

Replication to other replicas failed.

BoxAlreadyExistsError

class BoxAlreadyExistsError(ReplicaError)

Box already contains data. Pigeonhole writes are immutable.

TombstoneError

class TombstoneError(ReplicaError)

Box contains a tombstone (intentional deletion). This is not a failure.

InvalidTombstoneSignatureError

class InvalidTombstoneSignatureError(Exception)

Tombstone signature verification failed (forgery or corruption).

MKEMDecryptionFailedError

class MKEMDecryptionFailedError(Exception)

MKEM envelope decryption failed with all replica keys.

BACAPDecryptionFailedError

class BACAPDecryptionFailedError(Exception)

BACAP payload decryption or signature verification failed.

StartResendingCancelledError

class StartResendingCancelledError(Exception)

StartResendingEncryptedMessage operation was cancelled.

CopyCommandFailedError

class CopyCommandFailedError(Exception)

StartResendingCopyCommand operation failed on the courier.

The courier aborted the Copy command because a replica rejected one of the embedded writes. Inspect the diagnostic attributes to determine the cause:

Attributes:

  • replica_error_code int - The pigeonhole replica ErrorCode that triggered the abort (e.g. REPLICA_ERROR_BOX_ALREADY_EXISTS). 0 if not reported.
  • failed_envelope_index int - 1-based sequential position in the copy stream of the envelope whose write triggered the abort. 0 if not applicable. This is NOT a BACAP message index.

PayloadTooLargeError

class PayloadTooLargeError(Exception)

A request’s payload exceeded the daemon’s configured maximum payload size.

CourierError

class CourierError(Exception)

Base class for errors raised by the courier (as opposed to a storage replica). The courier and the replicas are distinct components: a courier error means the courier itself rejected or could not dispatch the request, and must not be confused with a replica error such as a database failure.

CourierInvalidEnvelopeError

class CourierInvalidEnvelopeError(CourierError)

The courier rejected the CourierEnvelope as malformed.

CourierCacheCorruptionError

class CourierCacheCorruptionError(CourierError)

The courier detected corruption in its reply cache.

CourierPropagationError

class CourierPropagationError(CourierError)

The courier could not propagate the request to the replicas.

CourierInvalidEpochError

class CourierInvalidEpochError(CourierError)

The courier rejected the CourierEnvelope because its declared replica epoch was outside the courier’s tolerance window. This is a staleness signal from the courier, NOT a replica database failure, even though the two share value 4 in their respective source namespaces.

6 -

Run a Katzenpost Mix server in a Docker container

Prerequisites

  • Access to the namenlos git repo

Preparing the host filesystem

mkdir katzenpost-mix
cd katzenpost-mix
mkdir {conf,data}
chmod 700 data

All further actions are performed from the katzenpost-mix directory.

Building the Docker image

  • Create Dockerfile:

    FROM golang:bookworm AS builder
    
    LABEL authors="<ops@cryptonymity.net>"
    
    RUN \
        cd /go && \
        git clone https://github.com/katzenpost/katzenpost  && \
        cd katzenpost && \
        go mod tidy && \
        cd cmd/server && go build
    
    FROM debian:bookworm AS deploy
    
    COPY --from=builder /go/katzenpost/cmd/server/server /usr/bin/server
    
    EXPOSE 8181
    
    ARG uid=1000
    ARG gid=1000
    
    RUN \
        mkdir -p /home/user && \
        echo "user:x:${uid}:${gid}:User,,,:/home/user:/bin/bash" >> /etc/passwd && \
        echo "user:x:${uid}:" >> /etc/group
    
    USER user
    ENV HOME=/home/user
    
    ENTRYPOINT ["/usr/bin/server","-f","/conf/katzenpost.toml"]
    
  • Build Docker image:

docker build -t katzenpost/mix --build-arg uid=$(id -u) --build-arg gid=$(id -g) .
  • Create service.sh (modify to match your port) to manage the server:

    #!/bin/bash
    
    CMD=${1:-start}
    case ${CMD} in
        genkeys)
            MODE="-ti --rm"
            EXEC="/usr/bin/server -g"
            ;;
        start)
            MODE="-d --restart=unless-stopped"
            EXEC=""
            ;;
        stop)
            docker stop katzenpost-mix
            docker rm katzenpost-mix
            exit
            ;;
        *)
            echo "unknown command"
            exit 1
            ;;
    esac
    
    docker run ${MODE} \
        --name katzenpost-mix -h katzenpost-mix \
        -p 0.0.0.0:<port>:8181 \
        -v $(pwd)/conf:/conf \
        -v $(pwd)/data:/var/lib/katzenpost \
        katzenpost/mix ${EXEC}
    

    Always run this script while in the katzenpost-mix directory.

Creating a configuration file

  • Create a new file named <yourname>-pq-mixserver.toml in <namenlos.repo>/configs/SSOT/mixes and adjust Identifier and IP/port setting in Addresses:

    [Server]
    Identifier = "<yourname>"
    PKISignatureScheme = "Ed25519 Sphincs+"
    WireKEM = "KYBER768-X25519"
    Addresses = [ "tcp://<public-ipv4>:<port>" ]
    BindAddresses = [ "tcp://0.0.0.0:8181" ]
    DataDir = "/var/lib/katzenpost"
    IsGatewayNode = false
    IsServiceNode = false
    
    [Logging]
    Disable = false
    File = ""
    Level = "NOTICE"
    
  • Build the configuration file conf/katzenpost.toml:

    1. In the namenlos repo, change into the configs directory and run make.

    2. Copy the generated configuration file:

    cp <namelos.repo>/configs/<yourname>-pq-mixserver.toml conf/katzenpost.toml
    

Generating and extracting keys

  • Run the server to generate the keys:
./service.sh genkeys
  • Check that keys (*.pem) have been created in the data/ directory and copy the public identity key to the namenlos repo:
cp data/identity.public.pem <namelos.repo>/keys/mixserver-keys/<yourname>_mix_id_pub_key.pem
  • Update the repo:
cd <namenlos.repo>/configs
make
git commit -a
git push

Starting/stopping the server

cd katzenpost-mix
./service.sh [start|stop]

7 -

Complete API reference for the Katzenpost thin client libraries (Go, Rust, Python)

Thin Client API Reference

This is the complete API reference for the Katzenpost thin client. The thin client is an interface to the kpclientd daemon, which handles all cryptographic and network operations. The thin client communicates with the daemon over a local socket using CBOR-encoded messages.

This document is machine-generated. Do not edit this file directly, as local changes will be overwritten by the next generation pass. The canonical source files are located in website/tools/thin-client-api-gen/. Edits should be applied to binding docstrings (in the source trees) or groups.yaml / overlay/*.md (in the generator).

There are three thin-client implementations:

  • a Go reference (katzenpost/client/thin),
  • a Rust binding (thin_client/src), and
  • a Python binding (thin_client/katzenpost_thinclient).

The official API documentation for each binding is found in the following locations.

Language Official API documentation Official API release
Go pkg.go.dev git tags
Rust docs.rs crates.io
Python Python Thin Client API PyPI

This reference describes the following pinned binding versions:

Binding Repository Tag
Go reference katzenpost/client/thin v0.0.90
Rust thin_client/src 0.0.23
Python thin_client/katzenpost_thinclient 0.0.23

For pinned versions of the full stack (including kpclientd, katzenqt, and the server-side components), see Build from source.

For conceptual background on Pigeonhole, see Understanding Pigeonhole. For task-oriented usage guides, see Thin Client How-to Guide. The design and its security analysis are presented in the Echomix paper.

The reference is organized in two parts: the Pigeonhole API, the message-passing layer most applications build on, followed by the Core Thin-Client API covering configuration, connection management, events, PKI queries, and direct messaging.


Pigeonhole API

The Pigeonhole API is the message-passing layer of the thin client: applications write to and read from BACAP-encrypted storage streams held on the mixnet’s storage replicas, reached through couriers. Much of this API wraps the BACAP scheme, with the daemon performing all BACAP operations on the application’s behalf. For conceptual background, see Understanding Pigeonhole; for worked examples in all three languages, see the Thin Client How-to Guide.

Most Pigeonhole methods cause no mixnet traffic. Only StartResendingEncryptedMessage (and its two variants) and StartResendingCopyCommand put traffic on the mixnet; they are marked Sends mixnet traffic below and deliver through the daemon’s stop-and-wait ARQ, described in The Pigeonhole ARQ. The Cancel* methods are local control operations, and everything else is a local computation performed by the daemon over the local socket.

Keypairs and Capabilities

Method Purpose
NewKeypair / new_keypair Generates a new BACAP keypair from a 32-byte seed.

Preparing Reads and Writes

Method Purpose
EncryptRead / encrypt_read Creates an encrypted read request for a single Pigeonhole box.
EncryptWrite / encrypt_write Creates an encrypted write request for a single Pigeonhole box.

Sending and ARQ Transport

Method Purpose
StartResendingEncryptedMessage / start_resending_encrypted_message Sends an encrypted read or write request to a courier via the ARQ mechanism. Sends mixnet traffic.
StartResendingEncryptedMessageReturnBoxExists Same as the default variant, but returns BoxAlreadyExists as an error instead of treating it as success. Sends mixnet traffic. (Go, Rust)
StartResendingEncryptedMessageNoRetry Same as the default variant, but returns BoxIDNotFound immediately instead of retrying indefinitely. Sends mixnet traffic. (Go, Rust)
CancelResendingEncryptedMessage / cancel_resending_encrypted_message Cancels an in-flight StartResendingEncryptedMessage operation.

Tombstones

Method Purpose
TombstoneRange / tombstone_range Creates encrypted tombstone envelopes for a range of consecutive boxes.

Copy Commands

Method Purpose
CreateCourierEnvelopesFromPayload / create_courier_envelopes_from_payload Packs a single payload for one destination into copy stream elements.
CreateCourierEnvelopesFromMultiPayload / create_courier_envelopes_from_multi_payload Packs multiple payloads for different destinations into copy stream elements.
CreateCourierEnvelopesFromTombstoneRange / create_courier_envelopes_from_tombstone_range Packs tombstone envelopes for a range of consecutive destination boxes into copy stream elements.
StartResendingCopyCommand / start_resending_copy_command Sends a copy command to a courier via ARQ and blocks until the courier acknowledges completion. Sends mixnet traffic.
CancelResendingCopyCommand / cancel_resending_copy_command Cancels an in-flight copy command.

Contact Vouchers

Method Purpose
VoucherMint / voucher_mint Mints a Voucher from the joiner’s MessageStream write capability.
VoucherInduct / voucher_induct Verifies a published VoucherPayload and seals a reply to the joiner.
VoucherOpen / voucher_open Opens the inductor’s sealed reply with the joiner’s voucher secret key.
VoucherDeriveStream / voucher_derive_stream Derives the VoucherStream capabilities from the Voucher.

Pigeonhole Geometry

Method Purpose
GetPigeonholeGeometry / pigeonhole_geometry Returns the negotiated Pigeonhole geometry, so that callers can size payloads to its maximum plaintext payload length.

Auxiliary Index Helpers

Method Purpose
NextMessageBoxIndex / next_message_box_index Returns the next message box index in the sequence.
GetMessageBoxIndexCounter / get_message_box_index_counter Returns the BACAP Idx64 counter embedded in a MessageBoxIndex, the sequence number of a box within its stream.

Looking for connection management, events, PKI queries, or direct messaging? Those live in the Core Thin-Client API below, which opens with its own method index.


Keypairs and Capabilities

NewKeypair / new_keypair

NewKeypair creates a new keypair for use with the Pigeonhole protocol.

This method generates a WriteCap and ReadCap from the provided seed using the BACAP (blinding-and-capability) protocol. The WriteCap should be stored securely for writing messages, while the ReadCap can be shared with others to allow them to read messages.

func (t *ThinClient) NewKeypair(seed []byte) (writeCap *bacap.WriteCap, readCap *bacap.ReadCap, firstMessageIndex *bacap.MessageBoxIndex, err error)
pub async fn new_keypair(
    &self,
    seed: &[u8; 32],
) -> Result<KeypairResult, ThinClientError>
async def new_keypair(self, seed: bytes) -> KeypairResult:

Preparing Reads and Writes

EncryptRead / encrypt_read

EncryptRead encrypts a read operation for a given read capability.

This method prepares an encrypted read request that can be sent to the courier service to retrieve a message from a Pigeonhole box. The returned ciphertext should be sent via StartResendingEncryptedMessage.

func (t *ThinClient) EncryptRead(readCap *bacap.ReadCap, messageBoxIndex *bacap.MessageBoxIndex) (messageCiphertext []byte, envelopeDescriptor []byte, envelopeHash *[32]byte, nextMessageBoxIndex *bacap.MessageBoxIndex, err error)
pub async fn encrypt_read(
    &self,
    read_cap: &[u8],
    message_box_index: &[u8],
) -> Result<EncryptReadResult, ThinClientError>
async def encrypt_read(self, read_cap: bytes, message_box_index: bytes) -> EncryptReadResult:

EncryptWrite / encrypt_write

EncryptWrite encrypts a write operation for a given write capability.

This method prepares an encrypted write request that can be sent to the courier service to store a message in a Pigeonhole box. The returned ciphertext should be sent via StartResendingEncryptedMessage.

func (t *ThinClient) EncryptWrite(plaintext []byte, writeCap *bacap.WriteCap, messageBoxIndex *bacap.MessageBoxIndex) (messageCiphertext []byte, envelopeDescriptor []byte, envelopeHash *[32]byte, nextMessageBoxIndex *bacap.MessageBoxIndex, err error)
pub async fn encrypt_write(
    &self,
    plaintext: &[u8],
    write_cap: &[u8],
    message_box_index: &[u8],
) -> Result<EncryptWriteResult, ThinClientError>
async def encrypt_write(self, plaintext: bytes, write_cap: bytes, message_box_index: bytes) -> EncryptWriteResult:

Sending and ARQ Transport

The senders in this section deliver envelopes through the daemon’s stop-and-wait ARQ. The Pigeonhole ARQ describes the retransmission behavior and what each operation costs in mixnet round trips.

StartResendingEncryptedMessage / start_resending_encrypted_message

Sends mixnet traffic.

StartResendingEncryptedMessage sends an encrypted read or write request to a courier through the daemon’s stop-and-wait ARQ and blocks until the operation completes, fails, or is cancelled via CancelResendingEncryptedMessage. The daemon retransmits until the courier answers; see https://katzenpost.network/docs/pigeonhole_explained/#the-pigeonhole-arq for the retransmission behavior and per-operation round-trip costs.

A write completes on the courier’s ACK, a single mixnet round trip, and by default treats BoxAlreadyExists as idempotent success. A read is two-phased: after the ACK the daemon collects the payload with a fresh SURB, decrypts it, and returns the plaintext; by default a read retries BoxIDNotFound until the box is written.

Note: The Python binding exposes the two variant behaviors below as keyword-only flags on this method (no_retry_on_box_id_not_found and no_idempotent_box_already_exists) rather than as separate methods.

func (t *ThinClient) StartResendingEncryptedMessage(readCap *bacap.ReadCap, writeCap *bacap.WriteCap, messageBoxIndex []byte, replyIndex *uint8, envelopeDescriptor []byte, messageCiphertext []byte, envelopeHash *[32]byte) (*StartResendingResult, error)
pub async fn start_resending_encrypted_message(
    &self,
    read_cap: Option<&[u8]>,
    write_cap: Option<&[u8]>,
    message_box_index: Option<&[u8]>,
    reply_index: Option<u8>,
    envelope_descriptor: &[u8],
    message_ciphertext: &[u8],
    envelope_hash: &[u8; 32],
) -> Result<StartResendingResult, ThinClientError>
async def start_resending_encrypted_message(self, read_cap: 'bytes|None', write_cap: 'bytes|None', message_box_index: 'bytes|None', reply_index: 'int|None', envelope_descriptor: bytes, message_ciphertext: bytes, envelope_hash: bytes, *, no_retry_on_box_id_not_found: bool = False, no_idempotent_box_already_exists: bool = False) -> StartResendingResult:

StartResendingEncryptedMessageReturnBoxExists

Sends mixnet traffic.

Available in: Go, Rust.

StartResendingEncryptedMessageReturnBoxExists behaves exactly like StartResendingEncryptedMessage save that it returns ErrBoxAlreadyExists when the replica reports that the destination box has already been written, rather than swallowing the condition as idempotent success.

This variant costs an additional mixnet round trip: the BoxAlreadyExists code is carried by the replica’s reply rather than the courier’s ACK, so the daemon must dispatch a second SURB before it can return the answer.

An in-flight call may be cancelled via CancelResendingEncryptedMessage.

Note: In Python, pass no_idempotent_box_already_exists=True to start_resending_encrypted_message instead.

func (t *ThinClient) StartResendingEncryptedMessageReturnBoxExists(readCap *bacap.ReadCap, writeCap *bacap.WriteCap, messageBoxIndex []byte, replyIndex *uint8, envelopeDescriptor []byte, messageCiphertext []byte, envelopeHash *[32]byte) (*StartResendingResult, error)
pub async fn start_resending_encrypted_message_return_box_exists(
    &self,
    read_cap: Option<&[u8]>,
    write_cap: Option<&[u8]>,
    message_box_index: Option<&[u8]>,
    reply_index: Option<u8>,
    envelope_descriptor: &[u8],
    message_ciphertext: &[u8],
    envelope_hash: &[u8; 32],
) -> Result<StartResendingResult, ThinClientError>

StartResendingEncryptedMessageNoRetry

Sends mixnet traffic.

Available in: Go, Rust.

StartResendingEncryptedMessageNoRetry behaves exactly like StartResendingEncryptedMessage save that it disables the daemon’s automatic retry of ErrBoxIDNotFound: the caller learns at once that the box has not been written yet, rather than blocking until it appears.

An in-flight call may be cancelled via CancelResendingEncryptedMessage.

Note: In Python, pass no_retry_on_box_id_not_found=True to start_resending_encrypted_message instead.

func (t *ThinClient) StartResendingEncryptedMessageNoRetry(readCap *bacap.ReadCap, writeCap *bacap.WriteCap, messageBoxIndex []byte, replyIndex *uint8, envelopeDescriptor []byte, messageCiphertext []byte, envelopeHash *[32]byte) (*StartResendingResult, error)
pub async fn start_resending_encrypted_message_no_retry(
    &self,
    read_cap: Option<&[u8]>,
    write_cap: Option<&[u8]>,
    message_box_index: Option<&[u8]>,
    reply_index: Option<u8>,
    envelope_descriptor: &[u8],
    message_ciphertext: &[u8],
    envelope_hash: &[u8; 32],
) -> Result<StartResendingResult, ThinClientError>

CancelResendingEncryptedMessage / cancel_resending_encrypted_message

CancelResendingEncryptedMessage cancels ARQ resending for an encrypted message.

The daemon stops retransmitting the operation identified by envelopeHash, the blocked StartResendingEncryptedMessage caller returns ErrStartResendingCancelled, and the operation is removed from in-flight tracking so it is not replayed after a reconnect.

func (t *ThinClient) CancelResendingEncryptedMessage(envelopeHash *[32]byte) error
pub async fn cancel_resending_encrypted_message(
    &self,
    envelope_hash: &[u8; 32],
) -> Result<(), ThinClientError>
async def cancel_resending_encrypted_message(self, envelope_hash: bytes) -> None:

Tombstones

A tombstone is a signed empty payload that deletes a box’s contents. See Tombstones in Understanding Pigeonhole.

TombstoneRange / tombstone_range

TombstoneRange prepares the encrypted envelopes needed to tombstone a consecutive range of Pigeonhole boxes beginning at the supplied MessageBoxIndex. A tombstone is a signed empty payload that deletes a box’s contents; see https://katzenpost.network/docs/pigeonhole_explained/#tombstones.

This method does not itself touch the network: it returns the envelopes for the caller to dispatch one by one, typically via StartResendingEncryptedMessage. To tombstone a single box, pass maxCount=1.

func (c *ThinClient) TombstoneRange(
	writeCap *bacap.WriteCap,
	start *bacap.MessageBoxIndex,
	maxCount uint32,
) (result *TombstoneRangeResult, err error)
pub async fn tombstone_range(
    &self,
    write_cap: &[u8],
    start: &[u8],
    max_count: u32,
) -> TombstoneRangeResult
async def tombstone_range(self, write_cap: bytes, start: bytes, max_count: int) -> TombstoneRangeResult:

Copy Commands

A copy command atomically writes a batch of envelopes to existing streams by way of a temporary copy stream, which a courier executes and then tombstones. See Copy commands in Understanding Pigeonhole for the workflow and its use cases.

CreateCourierEnvelopesFromPayload / create_courier_envelopes_from_payload

CreateCourierEnvelopesFromPayload packs a payload of arbitrary size (up to 10 MB) into properly sized CopyStreamElement chunks for one destination channel. Each chunk is a serialized CopyStreamElement, ready to be written to a box via EncryptWrite followed by StartResendingEncryptedMessage. The caller marks the boundaries of the stream with the isStart and isLast flags.

This method is stateless: no daemon state is kept between calls. It causes no mixnet traffic. See https://katzenpost.network/docs/pigeonhole_explained/#copy-commands for the copy command workflow the chunks feed into.

func (t *ThinClient) CreateCourierEnvelopesFromPayload(payload []byte, destWriteCap *bacap.WriteCap, destStartIndex *bacap.MessageBoxIndex, isStart bool, isLast bool) (envelopes [][]byte, nextDestIndex *bacap.MessageBoxIndex, err error)
pub async fn create_courier_envelopes_from_payload(
    &self,
    payload: &[u8],
    dest_write_cap: &[u8],
    dest_start_index: &[u8],
    is_start: bool,
    is_last: bool,
) -> Result<CreateEnvelopesResult, ThinClientError>
async def create_courier_envelopes_from_payload(self, payload: bytes, dest_write_cap: bytes, dest_start_index: bytes, is_start: bool, is_last: bool) -> 'CreateEnvelopesResult':

CreateCourierEnvelopesFromMultiPayload / create_courier_envelopes_from_multi_payload

CreateCourierEnvelopesFromMultiPayload packs payloads bound for several destination channels into a single stream of CopyStreamElement chunks. This is more space-efficient than calling CreateCourierEnvelopesFromPayload once per destination, because it avoids padding the final box of each destination independently.

This method is stateless; the buffer argument carries any residual state across calls. Pass nil for buffer on the first call and the buffer returned by the previous call thereafter; set isLast on the final call to flush the remainder.

func (t *ThinClient) CreateCourierEnvelopesFromMultiPayload(destinations []DestinationPayload, isStart bool, isLast bool, buffer []byte) (*CreateEnvelopesResult, error)
pub async fn create_courier_envelopes_from_multi_payload(
    &self,
    destinations: Vec<(&[u8], &[u8], &[u8])>,
    is_start: bool,
    is_last: bool,
    buffer: Option<Vec<u8>>,
) -> Result<CreateEnvelopesResult, ThinClientError>
async def create_courier_envelopes_from_multi_payload(self, destinations: 'List[Dict[str, Any]]', is_start: bool, is_last: bool, buffer: 'bytes | None' = None) -> 'CreateEnvelopesResult':

CreateCourierEnvelopesFromTombstoneRange / create_courier_envelopes_from_tombstone_range

CreateCourierEnvelopesFromTombstoneRange creates tombstone CourierEnvelopes for a range of destination indices, encoded as copy stream elements ready to be written to a temporary copy stream channel.

This combines tombstone creation with the copy stream encoding of CreateCourierEnvelopesFromPayload.

The buffer parameter enables stateless continuation across multiple calls without wasting space in the last box. Pass nil on the first call, then pass the returned nextBuffer to the next call.

func (t *ThinClient) CreateCourierEnvelopesFromTombstoneRange(
	destWriteCap *bacap.WriteCap,
	destStartIndex *bacap.MessageBoxIndex,
	maxCount uint32,
	isStart bool,
	isLast bool,
	buffer []byte,
) (envelopes [][]byte, nextBuffer []byte, nextDestIndex *bacap.MessageBoxIndex, err error)
pub async fn create_courier_envelopes_from_tombstone_range(
    &self,
    dest_write_cap: &[u8],
    dest_start_index: &[u8],
    max_count: u32,
    is_start: bool,
    is_last: bool,
    buffer: Option<Vec<u8>>,
) -> Result<CreateEnvelopesResult, ThinClientError>
async def create_courier_envelopes_from_tombstone_range(self, dest_write_cap: bytes, dest_start_index: bytes, max_count: int, is_start: bool, is_last: bool, buffer: 'bytes | None' = None) -> 'CreateEnvelopesResult':

StartResendingCopyCommand / start_resending_copy_command

Sends mixnet traffic.

StartResendingCopyCommand sends a copy command to a courier through the daemon’s stop-and-wait ARQ and blocks until the courier acknowledges completion. The copy command hands the courier the write capability of a temporary copy stream; the courier executes the stream’s envelopes to their destination boxes and tombstones the temporary stream. See https://katzenpost.network/docs/pigeonhole_explained/#copy-commands for the workflow and its all-or-nothing semantics.

An in-flight call may be cancelled via CancelResendingCopyCommand.

func (t *ThinClient) StartResendingCopyCommand(writeCap *bacap.WriteCap) error
pub async fn start_resending_copy_command(
    &self,
    write_cap: &[u8],
    courier_identity_hash: Option<&[u8]>,
    courier_queue_id: Option<&[u8]>,
) -> Result<(), ThinClientError>
async def start_resending_copy_command(self, write_cap: bytes, courier_identity_hash: 'bytes|None' = None, courier_queue_id: 'bytes|None' = None) -> None:

CancelResendingCopyCommand / cancel_resending_copy_command

CancelResendingCopyCommand cancels ARQ resending for a copy command.

The daemon stops retransmitting the copy command identified by writeCapHash (the blake2b-256 hash of the serialized write capability), and the operation is removed from in-flight tracking so it is not replayed after a reconnect.

func (t *ThinClient) CancelResendingCopyCommand(writeCapHash *[32]byte) error
pub async fn cancel_resending_copy_command(
    &self,
    write_cap_hash: &[u8; 32],
) -> Result<(), ThinClientError>
async def cancel_resending_copy_command(self, write_cap_hash: bytes) -> None:

Contact Vouchers

VoucherMint / voucher_mint

VoucherMint mints a Voucher from the joiner’s MessageStream write cap. The returned reply carries the Voucher to hand over out of band, the payload to publish to VoucherStream box 0, the rendezvous stream caps, and the reply keypair; persist VoucherSecretKey to open the inductor’s reply later.

func (t *ThinClient) VoucherMint(messageWriteCap []byte, displayName string) (*VoucherMintReply, error)
pub async fn voucher_mint(
    &self,
    message_write_cap: &[u8],
    display_name: &str,
) -> Result<VoucherMintResult, ThinClientError>
async def voucher_mint(self, message_write_cap: bytes, display_name: str) -> VoucherMintResult:

VoucherInduct / voucher_induct

VoucherInduct verifies a published VoucherPayload and seals a reply to the joiner. The returned reply carries the joiner’s salt-mutated read cap (the live read cap to hand the group), the sealed reply to write to VoucherStream box 1, and the salt the inductor minted.

func (t *ThinClient) VoucherInduct(voucher, voucherPayload, whoReply []byte) (*VoucherInductReply, error)
pub async fn voucher_induct(
    &self,
    voucher: &[u8],
    voucher_payload: &[u8],
    who_reply: &[u8],
) -> Result<VoucherInductResult, ThinClientError>
async def voucher_induct(self, voucher: bytes, voucher_payload: bytes, who_reply: bytes) -> VoucherInductResult:

VoucherOpen / voucher_open

VoucherOpen opens the inductor’s sealed reply with the joiner’s voucher secret key, recovers the salt, and mutates the joiner’s MessageStream write cap by it. The returned reply carries the opaque WhoReply, the salt, and the salt-mutated write cap with which the joiner writes real messages.

func (t *ThinClient) VoucherOpen(voucherSecretKey, sealedReply, messageWriteCap []byte) (*VoucherOpenReply, error)
pub async fn voucher_open(
    &self,
    voucher_secret_key: &[u8],
    sealed_reply: &[u8],
    message_write_cap: &[u8],
) -> Result<VoucherOpenResult, ThinClientError>
async def voucher_open(self, voucher_secret_key: bytes, sealed_reply: bytes, message_write_cap: bytes) -> VoucherOpenResult:

VoucherDeriveStream / voucher_derive_stream

VoucherDeriveStream derives the VoucherStream caps from the Voucher, which the inductor needs to read box 0 before inducting.

func (t *ThinClient) VoucherDeriveStream(voucher []byte) (*VoucherDeriveStreamReply, error)
pub async fn voucher_derive_stream(
    &self,
    voucher: &[u8],
) -> Result<VoucherStreamResult, ThinClientError>
async def voucher_derive_stream(self, voucher: bytes) -> VoucherStreamResult:

Pigeonhole Geometry

GetPigeonholeGeometry / pigeonhole_geometry

GetPigeonholeGeometry returns the Pigeonhole geometry the daemon supplied during the connection handshake. It is nil until Dial() has completed.

Note: The Python binding has no getter method yet; it exposes the Pigeonhole geometry as the public pigeonhole_geometry attribute, cached from the daemon’s connection handshake so applications can size their payloads. A getter method is planned for the next release.

func (t *ThinClient) GetPigeonholeGeometry() *pigeonholeGeo.Geometry
pub fn pigeonhole_geometry(&self) -> PigeonholeGeometry
# Public attribute, cached from the connection handshake;
# None until the daemon connects. A getter method is planned
# for the next release.
geo = client.pigeonhole_geometry

Auxiliary Index Helpers

Most applications never need these methods: every call that consumes a message box index already returns the next index alongside its result.

NextMessageBoxIndex / next_message_box_index

NextMessageBoxIndex returns the message box index that follows messageBoxIndex in its BACAP stream. The computation happens in the daemon and causes no mixnet traffic.

Most callers never need this method: EncryptRead, EncryptWrite, and the copy stream constructors already return the next index alongside their results.

func (t *ThinClient) NextMessageBoxIndex(messageBoxIndex *bacap.MessageBoxIndex) (nextMessageBoxIndex *bacap.MessageBoxIndex, err error)
pub async fn next_message_box_index(
    &self,
    message_box_index: &[u8],
) -> Result<Vec<u8>, ThinClientError>
async def next_message_box_index(self, message_box_index: bytes) -> bytes:

GetMessageBoxIndexCounter / get_message_box_index_counter

GetMessageBoxIndexCounter returns the BACAP Idx64 counter embedded in a MessageBoxIndex. Callers can use this to order or compare two indexes without having to know bacap.MessageBoxIndex’s binary layout.

func (t *ThinClient) GetMessageBoxIndexCounter(messageBoxIndex *bacap.MessageBoxIndex) (uint64, error)
pub async fn get_message_box_index_counter(
    &self,
    message_box_index: &[u8],
) -> Result<u64, ThinClientError>
async def get_message_box_index_counter(self, message_box_index: bytes) -> int:

Core Thin-Client API

Everything below is the transport and control plumbing shared by all thin-client applications: constructing and connecting a client, consuming daemon events, querying the PKI, and sending direct (non-Pigeonhole) messages into the mixnet.

Connection Management

Method Purpose
Dial / new / start Connect to the kpclientd daemon.
Close / stop Disconnect from the daemon and shut down the thin client.
IsConnected / is_connected Returns whether the daemon is currently connected to the mixnet.
Disconnect / disconnect Disconnect from the daemon without shutting down.

Events

Method Purpose
EventSink / event_sink Returns a channel (Go) or receiver (Rust) that yields events from the daemon. (Go, Rust)
StopEventSink Stops delivering events on the given channel. (Go)

PKI and Service Discovery

Method Purpose
PKIDocument / pki_document Returns the current PKI consensus document, which contains the network topology and available services.
GetPKIDocumentRaw / get_pki_document_raw Returns the signed PKI document for a given epoch with every directory authority signature intact, so callers may verify the document themselves.
GetDirectoryAuthorities / get_directory_authorities Returns the directory authority descriptors the client daemon is configured to trust, including their identity keys and addresses.
PKIDocumentForEpoch / pki_document_for_epoch Returns the cached PKI document for a specific epoch, or an error if the daemon has not retained a document for that epoch. (Go, Python)
GetService / get_service Returns a random instance of the named service from the PKI document.
GetServices / get_services Returns all instances of a service with the given capability name. (Go, Python)

Direct Messaging

Method Purpose
SendMessage / send_message Sends a message with a SURB (Single Use Reply Block) that allows the destination service to reply. Sends mixnet traffic.
SendMessageWithoutReply / send_message_without_reply Sends a fire-and-forget message with no SURB. Sends mixnet traffic.
BlockingSendMessage / blocking_send_message Sends a message and blocks until a reply is received or the timeout expires. Sends mixnet traffic.

Sphinx Geometry

Method Purpose
GetSphinxGeometry / sphinx_geometry Returns the Sphinx geometry the daemon supplied during the connection handshake, describing the packet and payload sizes of the mixnet’s Sphinx packet format.

Utility

Method Purpose
NewMessageID / new_message_id Returns a new random message ID (16 bytes).
NewSURBID / new_surb_id Returns a new random SURB ID for correlating message replies.
NewQueryID / new_query_id Returns a new random query ID for correlating requests and replies within the thin client protocol.
GetConfig Returns the client’s configuration object, including the Sphinx and Pigeonhole geometries negotiated with the daemon. (Go)
Shutdown Cleanly shuts down the ThinClient instance and stops its background workers. (Go)
GetLogger Returns a logger instance with the given prefix, using the thin client’s configured logging backend. (Go)

Configuration and Construction

The thin client is configured via a TOML file that specifies only how to reach the local daemon. We usually name this configuration file thinclient.toml.

cfg, err := thin.LoadFile("thinclient.toml")
if err != nil {
    log.Fatal(err)
}

logging := &config.Logging{Level: "INFO"}
client := thin.NewThinClient(cfg, logging)
let config = Config::new("thinclient.toml")?;
let client = ThinClient::new(config).await?;
config = Config("thinclient.toml")
client = ThinClient(config)

The thinclient.toml file

thinclient.toml tells the thin client only where to reach the local daemon. The complete file is simply:

[Dial]
  [Dial.Tcp]
    Address = "localhost:64331"
    Network = "tcp"

[Dial] selects the daemon transport. Set exactly one of the two forms (the Network key is an optional refinement of the TCP form):

Key Type Meaning
[Dial.Unix] Address string Filesystem path of the daemon’s Unix socket.
[Dial.Tcp] Address string host:port of the daemon’s TCP listener.
[Dial.Tcp] Network string Optional: "tcp", "tcp4", or "tcp6" (default "tcp").

Concurrency

The Go ThinClient is safe for concurrent use by multiple goroutines. Because its connection state, current PKI document, and in-flight request tracking are guarded internally, the cancel-from-another-goroutine patterns shown in the how-to guide are sound. The Rust and Python bindings are async. An instance is driven from its runtime (a Tokio task or an asyncio event loop) and follows that runtime’s ordinary conventions rather than offering an independent thread-safety guarantee.


Connection Management

Dial / new / start

Dial establishes a connection to the client daemon and initializes the client.

This method performs the complete connection handshake with the client daemon with the following actions.

  1. It establishes a network connection (TCP or Unix socket).
  2. It receives an initial connection status from daemon.
  3. It receives an initial PKI document.
  4. It starts background workers for event handling.

The client supports both online and offline modes. In offline mode (when the daemon is not connected to the mixnet), channel preparation operations will work but actual message transmission will fail.

After successful connection, the client will automatically handle:

  • PKI document updates
  • connection status changes
  • event distribution to application code

Note: The Rust binding folds the connect step into its constructor, so ThinClient::new returns an already-connected handle. Go and Python construct the client first and connect afterwards via Dial() / start(), allowing the application to set up event sinks (in Go) or callbacks (in Python) before any traffic flows.

func (t *ThinClient) Dial() error
pub async fn new(config: Config) -> Result<Arc<Self>, Box<dyn std::error::Error>>
async def start(self, loop: asyncio.AbstractEventLoop) -> None:

Close / stop

Close gracefully shuts down the thin client and closes the daemon connection.

This method performs a clean shutdown with the following actions.

  1. It sends a close notification to the daemon.
  2. It closes the network connection.
  3. It stops all background workers.

After calling Close(), the ThinClient instance should not be used further. Any ongoing operations will be interrupted and may return errors.

func (t *ThinClient) Close() error
pub async fn stop(&self)
def stop(self) -> None:

IsConnected / is_connected

IsConnected returns true if the client daemon is connected to the mixnet.

This indicates whether the daemon has an active connection to the mixnet infrastructure. When false, the client is in “offline mode” where channel operations (prepare operations) will work but actual message transmission will fail.

func (t *ThinClient) IsConnected() bool
pub fn is_connected(&self) -> bool
def is_connected(self) -> bool:

Disconnect / disconnect

Disconnect closes the connection without sending ThinClose. The daemon preserves all state for this client’s app ID, allowing the client to reconnect and resume with the same session token.

func (t *ThinClient) Disconnect() error
pub async fn disconnect(&self)
def disconnect(self) -> None:

Events

The thin client emits events for connection status changes, PKI document updates, and message replies. Go uses an event channel; Rust uses a broadcast receiver; Python uses async callbacks supplied to the Config constructor.

// Get a channel that receives all events
eventCh := client.EventSink()
defer client.StopEventSink(eventCh)

for ev := range eventCh {
    switch ev.(type) {
    case *thin.ConnectionStatusEvent:
        // ...
    case *thin.NewDocumentEvent:
        // ...
    case *thin.MessageReplyEvent:
        // ...
    }
}
// Get a receiver that yields all events as CBOR BTreeMaps
let mut event_rx = client.event_sink();

tokio::spawn(async move {
    while let Some(event) = event_rx.recv().await {
        // Inspect event["type"] and dispatch
    }
});
# Pass async callback functions to the Config constructor.
# Each callback receives a dict with event-specific keys.
# All callbacks are optional; omitted events are ignored.

async def on_connection_status(event):
    print(f"Connected: {event['is_connected']}")

async def on_message_reply(event):
    print(f"Reply for SURBID {event['surbid']!r}: {event['payload']!r}")

config = Config(
    "thinclient.toml",
    on_connection_status=on_connection_status,
    on_message_reply=on_message_reply,
)
client = ThinClient(config)

Event types

  • ConnectionStatusEvent: emitted when the daemon’s connection to the mixnet changes. Fields (Go): IsConnected bool, Err error, InstanceToken [16]byte. InstanceToken uniquely identifies the daemon process and lets clients notice daemon restarts.

  • NewDocumentEvent: emitted when a new PKI consensus document is received from the directory authorities. The Go binding exposes the parsed document as Document *cpki.Document. (The lower-level NewPKIDocumentEvent carrying a raw CBOR Payload []byte is used internally between daemon and thin client. Applications should consume NewDocumentEvent.)

  • MessageSentEvent: emitted when a SendMessage request has been transmitted by the daemon. Fields (Go): MessageID *[MessageIDLength]byte, SURBID *[SURBIDLength]byte, SentAt time.Time, ReplyETA time.Duration, Err string.

  • MessageReplyEvent: emitted when a reply to a SendMessage call is received. Fields (Go): MessageID *[MessageIDLength]byte, SURBID *[SURBIDLength]byte, Payload []byte, ReplyIndex *uint8, ErrorCode uint8. ReplyIndex identifies which of the box’s two replicas answered. Each box is sharded across K=2 replicas, and the value (0 or 1) is the position within that pair of the replica whose response was used. It is chiefly of interest for Pigeonhole channel reads and may be nil when not applicable. The same value is accepted as the reply_index parameter of StartResendingEncryptedMessage, where it likewise selects the replica of the pair to address.

  • ShutdownEvent: emitted when the daemon signals that it is shutting down. Carrying no fields, it precedes the loss of the local socket and is what causes the DaemonDisconnectedEvent (see below) to report IsGraceful = true. Treat it as advance notice of the disconnect; no action is required, since the thin client reconnects and replays in-flight requests on its own.

  • DaemonDisconnectedEvent: emitted by the thin client (not the daemon) when the local socket connection to the daemon is lost. Fields (Go): IsGraceful bool, Err error. IsGraceful is true precisely when a ShutdownEvent preceded the disconnect.

EventSink / event_sink

Available in: Go, Rust.

EventSink returns a buffered channel that receives all events from the thin client.

This method creates a new event channel that will receive copies of all events generated by the thin client, including the following.

  • PKI document updates
  • message sent confirmations
  • message replies
  • channel operation results

The returned channel is buffered with capacity 1. Events are never silently dropped; the fan-out worker blocks until the subscriber accepts each event, matching the “no loss” contract that the Rust and Python thin clients uphold. Consequently an application that stops consuming from its sink will stall the entire fan-out (including events destined for other subscribers). Applications must drain promptly or call StopEventSink() to release their subscription.

Important: Always call StopEventSink() when done with the channel to prevent resource leaks and ensure proper cleanup.

Note: The event sink channel is NOT closed when the client shuts down. Consumers should also select on HaltCh() to detect shutdown, or they can check for a ShutdownEvent in the event stream.

Note: The Rust binding returns an mpsc::Receiver carrying the same event stream. The Python binding has no equivalent method: Python applications instead register async callbacks on the Config constructor and receive events through those.

func (t *ThinClient) EventSink() chan Event
pub fn event_sink(&self) -> EventSinkReceiver

StopEventSink

Available in: Go.

StopEventSink stops sending events to the specified channel and cleans up resources.

This method removes the channel from the event distribution system and should be called when the application is done processing events from a channel returned by EventSink(). Failure to call this method may result in resource leaks and continued event processing overhead.

Note: Rust subscribers are released by dropping the mpsc::Receiver, so the binding exposes no explicit teardown method. Python’s callback model owns no per-subscriber resources either, and so likewise needs no equivalent.

func (t *ThinClient) StopEventSink(ch chan Event)

PKI and Service Discovery

PKIDocument / pki_document

PKIDocument returns the thin client’s current PKI document.

The PKI document contains the current network topology, service information, and cryptographic parameters for the current epoch. This document is automatically updated when the client daemon receives new PKI information.

func (t *ThinClient) PKIDocument() *cpki.Document
pub async fn pki_document(&self) -> Result<BTreeMap<Value, Value>, ThinClientError>
def pki_document(self) -> 'Dict[str,Any] | None':

GetPKIDocumentRaw / get_pki_document_raw

GetPKIDocumentRaw returns the cert.Certificate-wrapped signed PKI document for the requested epoch, with every directory authority signature intact. Pass epoch == 0 to request the document that the daemon believes is current.

The thin client receives the stripped PKI document by default (as pushed in NewPKIDocumentEvent). Use this method when the caller needs to verify the directory authority signatures itself. The payload can be deserialized and verified with core/pki.FromPayload.

func (t *ThinClient) GetPKIDocumentRaw(epoch uint64) ([]byte, uint64, error)
pub async fn get_pki_document_raw(
    &self,
    epoch: u64,
) -> Result<(Vec<u8>, u64), ThinClientError>
async def get_pki_document_raw(self, epoch: int = 0) -> 'Tuple[bytes,int]':

GetDirectoryAuthorities / get_directory_authorities

GetDirectoryAuthorities returns the directory authority descriptors the client daemon is configured with.

A thin client holds only its dial transport configuration and never sees the daemon’s voting authority peer list. This method surfaces it, so a caller may, for instance, map a PKI document’s signature fingerprints (the keys of its Signatures map) to human-readable authority identifiers via each descriptor’s IdentityKeyHash.

func (t *ThinClient) GetDirectoryAuthorities() ([]*DirectoryAuthority, error)
pub async fn get_directory_authorities(
    &self,
) -> Result<Vec<DirectoryAuthority>, ThinClientError>
async def get_directory_authorities(self) -> 'List[Dict[str,Any]]':

PKIDocumentForEpoch / pki_document_for_epoch

Available in: Go, Python.

PKIDocumentForEpoch returns the PKI document for a specific epoch from cache.

This method provides access to PKI documents from previous epochs that are cached by the client. This is important for maintaining consistency during epoch transitions where different participants might be using PKI documents from different epochs, which can lead to different envelope hashes and communication failures.

The client automatically caches the last 5 epochs of PKI documents. If the requested epoch is not in cache, the current document is returned as a fallback.

Note: The Rust binding does not expose a per-epoch accessor; Rust callers use pki_document for the current document, or get_pki_document_raw for the signed document at a given epoch.

func (t *ThinClient) PKIDocumentForEpoch(epoch uint64) (*cpki.Document, error)
def pki_document_for_epoch(self, epoch: int) -> 'Dict[str,Any]':

GetService / get_service

GetService returns a randomly selected service matching the specified capability.

This method is a convenience wrapper around GetServices() that randomly selects one service from all available services with the given capability. This provides automatic load balancing across available service instances.

func (t *ThinClient) GetService(serviceName string) (*common.ServiceDescriptor, error)
pub async fn get_service(
    &self,
    service_name: &str,
) -> Result<ServiceDescriptor, ThinClientError>
def get_service(self, service_name: str) -> ServiceDescriptor:

GetServices / get_services

Available in: Go, Python.

GetServices returns all services matching the specified capability name.

This method searches the current PKI document for services that provide the specified capability. Services in Katzenpost are identified by their capability names (e.g., “echo”, “courier”, “keyserver”).

Note: The Rust binding exposes the same lookup as the free function find_services in helpers.rs, rather than as a method on ThinClient.

func (t *ThinClient) GetServices(capability string) ([]*common.ServiceDescriptor, error)
def get_services(self, capability: str) -> 'List[ServiceDescriptor]':

Direct Messaging

SendMessage / send_message

Sends mixnet traffic.

SendMessage sends a message with reply capability using the legacy API.

This method sends a message with a Single Use Reply Block (SURB) that allows the destination to send a reply. The method is asynchronous: it only blocks until the daemon receives the send request, not until the message is actually transmitted or a reply is received.

To receive replies, applications must monitor events from EventSink() and look for MessageReplyEvent instances with matching SURB IDs.

func (t *ThinClient) SendMessage(surbID *[sConstants.SURBIDLength]byte, payload []byte, destNode *[32]byte, destQueue []byte) error
pub async fn send_message(
    &self,
    surb_id: Vec<u8>,
    payload: &[u8],
    dest_node: Vec<u8>,
    dest_queue: Vec<u8>,
) -> Result<(), ThinClientError>
async def send_message(self, surb_id: bytes, payload: bytes | str, dest_node: bytes, dest_queue: bytes) -> None:

SendMessageWithoutReply / send_message_without_reply

Sends mixnet traffic.

SendMessageWithoutReply sends a fire-and-forget message using the legacy API.

This method sends a message without any reply capability. The message is encapsulated in a Sphinx packet and sent through the mixnet, but no response can be received. This is suitable for notifications or one-way communication.

func (t *ThinClient) SendMessageWithoutReply(payload []byte, destNode *[32]byte, destQueue []byte) error
pub async fn send_message_without_reply(
    &self,
    payload: &[u8],
    dest_node: Vec<u8>,
    dest_queue: Vec<u8>,
) -> Result<(), ThinClientError>
async def send_message_without_reply(self, payload: bytes | str, dest_node: bytes, dest_queue: bytes) -> None:

BlockingSendMessage / blocking_send_message

Sends mixnet traffic.

BlockingSendMessage sends a message and blocks until a reply is received.

This method provides a synchronous request-response pattern by automatically generating a SURB ID, sending the message, and waiting for the reply. It blocks until either a reply is received or the context times out.

This is convenient for simple request-response interactions but lacks the advanced features of the Pigeonhole channel API such as message ordering, channel persistence, and offline operation support.

func (t *ThinClient) BlockingSendMessage(ctx context.Context, payload []byte, destNode *[32]byte, destQueue []byte) ([]byte, error)
pub async fn blocking_send_message(
    &self,
    payload: &[u8],
    dest_node: Vec<u8>,
    dest_queue: Vec<u8>,
    timeout: std::time::Duration,
) -> Result<Vec<u8>, ThinClientError>
async def blocking_send_message(self, payload: bytes | str, dest_node: bytes, dest_queue: bytes, timeout_seconds: float = 30.0) -> bytes:

Sphinx Geometry

GetSphinxGeometry / sphinx_geometry

GetSphinxGeometry returns the Sphinx geometry the daemon supplied during the connection handshake. It is nil until Dial() has completed.

Note: The Python binding has no getter method yet; it exposes the Sphinx geometry as the public geometry attribute (a Geometry), cached from the daemon’s connection handshake so applications can size their payloads. A getter method is planned for the next release.

func (t *ThinClient) GetSphinxGeometry() *geo.Geometry
pub fn sphinx_geometry(&self) -> Geometry
# Public attribute, cached from the connection handshake;
# None until the daemon connects. A getter method is planned
# for the next release.
geo = client.geometry

Utility

NewMessageID / new_message_id

NewMessageID generates a new cryptographically random message identifier.

Message IDs are used to correlate requests with responses in both legacy and channel APIs. Each message should have a unique ID to prevent confusion and enable proper event correlation.

func (t *ThinClient) NewMessageID() *[MessageIDLength]byte
pub fn new_message_id() -> Vec<u8>
def new_message_id() -> bytes:

NewSURBID / new_surb_id

NewSURBID generates a new SURB.

SURB IDs are used in the legacy API to correlate reply messages with their original requests. Each SURB should have a unique ID.

func (t *ThinClient) NewSURBID() *[sConstants.SURBIDLength]byte
pub fn new_surb_id() -> Vec<u8>
def new_surb_id(self) -> bytes:

NewQueryID / new_query_id

NewQueryID generates a new cryptographically random query identifier.

Query IDs are used in the channel API to correlate channel operation requests with their responses. Each query should have a unique ID.

func (t *ThinClient) NewQueryID() *[QueryIDLength]byte
pub fn new_query_id() -> Vec<u8>
def new_query_id(self) -> bytes:

GetConfig

Available in: Go.

GetConfig returns the client’s configuration.

Note: Python callers read the configuration through the plain config attribute on ThinClient. The Rust binding exposes no configuration accessor; Rust callers read the negotiated geometries through the dedicated sphinx_geometry and pigeonhole_geometry methods.

func (t *ThinClient) GetConfig() *Config

Shutdown

Available in: Go.

Shutdown cleanly shuts down the ThinClient instance.

This method stops all background workers and closes the connection to the client daemon. It is equivalent to calling Halt() and is provided for compatibility. For proper cleanup, prefer using Close().

Note: The Rust and Python bindings expose a single teardown method, stop, documented under Close / stop above.

func (t *ThinClient) Shutdown()

GetLogger

Available in: Go.

GetLogger returns a logger instance with the specified prefix.

This allows applications to create loggers that integrate with the thin client’s logging system and maintain consistent log formatting.

Note: The Rust and Python bindings leave logging to the host application and expose no equivalent accessor.

func (t *ThinClient) GetLogger(prefix string) *logging.Logger

Data Types

The Pigeonhole methods return structured results whose fields are enumerated below. These are the Go reference structs from katzenpost/client/thin; they are authoritative. The Rust and Python bindings return the equivalent data through their own result types, with the same fields rendered in snake_case (for example WriteCap becomes write_cap, and NextMessageBoxIndex becomes next_message_box_index).

The following two fields recur throughout and are protocol plumbing rather than application data.

  • QueryID correlates a reply with the request that produced it; the bindings manage it for you.
  • ErrorCode is zero on success and otherwise names the failure. The bindings translate a non-zero code into the language-native error documented under Replica and Courier Errors; application code inspects the raised error or returned sentinel rather than this byte directly.

NewKeypair result (Rust/Python: KeypairResult)

NewKeypairReply is the reply to a NewKeypair request.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the NewKeypair request.
WriteCap *bacap.WriteCap WriteCap is the write capability that should be stored for the channel.
ReadCap *bacap.ReadCap ReadCap is the read capability that can be shared with others to allow them to read messages from this channel.
FirstMessageIndex *bacap.MessageBoxIndex FirstMessageIndex is the first message index that should be used when writing messages to the channel.
ErrorCode uint8 ErrorCode indicates the reason for a failure to create a new keypair if any. Otherwise it is set to zero for success.

EncryptWrite result (Rust/Python: EncryptWriteResult)

EncryptWriteReply is the reply to an EncryptWrite request.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the EncryptWrite request
MessageCiphertext []byte MessageCiphertext is the encrypted message ciphertext that should be sent to the courier service.
EnvelopeDescriptor []byte EnvelopeDescriptor contains the serialized EnvelopeDescriptor that contains the private key material needed to decrypt the envelope reply.
EnvelopeHash *[32]byte EnvelopeHash is the hash of the CourierEnvelope that was sent to the mixnet and is used to resume the write operation.
NextMessageBoxIndex *bacap.MessageBoxIndex NextMessageBoxIndex is the next message box index to use for subsequent write operations. This is computed by the daemon using BACAP’s NextIndex.
ErrorCode uint8 ErrorCode indicates the reason for a failure to encrypt the write if any. Otherwise it is set to zero for success.

EncryptRead result (Rust/Python: EncryptReadResult)

EncryptReadReply is the reply to an EncryptRead request.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the EncryptRead request.
MessageCiphertext []byte MessageCiphertext is the encrypted message ciphertext that should be sent to the courier service.
EnvelopeDescriptor []byte EnvelopeDescriptor contains the serialized EnvelopeDescriptor that contains the private key material needed to decrypt the envelope reply.
EnvelopeHash *[32]byte EnvelopeHash is the hash of the CourierEnvelope that was sent to the mixnet and is used to resume the read operation.
NextMessageBoxIndex *bacap.MessageBoxIndex NextMessageBoxIndex is the next message box index to use for subsequent read operations. This is computed by the daemon using BACAP’s NextIndex.
ErrorCode uint8 ErrorCode indicates the reason for a failure to encrypt the read if any. Otherwise it is set to zero for success.

StartResendingEncryptedMessage result (Rust/Python: StartResendingResult)

StartResendingEncryptedMessageReply is the reply to a StartResendingEncryptedMessage request.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the StartResendingEncryptedMessage request.
Plaintext []byte Plaintext is the plaintext message that was read from the channel.
ErrorCode uint8 ErrorCode indicates the reason for a failure to start resending the encrypted message if any. Otherwise it is set to zero for success.
CourierIdentityHash *[32]byte CourierIdentityHash is the 32-byte hash of the identity key of the courier that was selected to handle this message. Callers can watch PKI document updates for this courier disappearing from consensus and cancel+re-encrypt if it does.
CourierQueueID []byte CourierQueueID is the queue ID of the courier that was selected.

StartResendingCopyCommand result

StartResendingCopyCommandReply is the reply to a StartResendingCopyCommand request.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the StartResendingCopyCommand request.
ErrorCode uint8 ErrorCode indicates the reason for a failure to execute the copy command if any. Otherwise it is set to zero for success.
ReplicaErrorCode uint8 ReplicaErrorCode is the Pigeonhole replica ErrorCode that caused the Copy command to abort on the courier. Meaningful only when ErrorCode indicates a Copy failure and the courier identified a specific replica-side reason (e.g., ReplicaErrorBoxAlreadyExists).
FailedEnvelopeIndex uint64 FailedEnvelopeIndex is the 1-based sequential position in the copy stream of the envelope whose write triggered the abort. 0 if not applicable. Not a BACAP message index.

NextMessageBoxIndex result

NextMessageBoxIndexReply is the reply to a NextMessageBoxIndex request.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the NextMessageBoxIndex request.
NextMessageBoxIndex *bacap.MessageBoxIndex NextMessageBoxIndex is the incremented message box index.
ErrorCode uint8 ErrorCode indicates the reason for a failure to increment the index if any. Otherwise it is set to zero for success.

GetMessageBoxIndexCounter result

GetMessageBoxIndexCounterReply is the reply to a GetMessageBoxIndexCounter request.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the GetMessageBoxIndexCounter request.
Counter uint64 Counter is the BACAP Idx64 value read out of the requested MessageBoxIndex.
ErrorCode uint8 ErrorCode indicates the reason for a failure to read the counter if any. Otherwise it is set to zero for success.

GetPKIDocumentRaw result

GetPKIDocumentReply is the reply to a GetPKIDocument request. The Payload field carries the cert.Certificate-wrapped signed PKI document exactly as the daemon received it from the gateway, retaining every directory authority signature so that callers may verify it themselves.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the GetPKIDocument request.
Payload []byte Payload is the cert.Certificate-wrapped signed PKI document, or nil on failure. Use core/pki.FromPayload to deserialize and verify it against the directory authorities’ public keys.
Epoch uint64 Epoch is the epoch of the returned document. When the request asked for the current epoch this echoes the epoch the daemon believes is current.
ErrorCode uint8 ErrorCode indicates the reason for a failure to return a signed PKI document if any. Otherwise it is set to zero for success.

CreateCourierEnvelopesFromPayload result

CreateCourierEnvelopesFromPayloadReply is sent in response to a CreateCourierEnvelopesFromPayload request. It provides multiple serialized CopyStreamElements, one for each chunk of the payload.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the CreateCourierEnvelopesFromPayload request that created it.
Envelopes [][]byte Envelopes is a slice of serialized CopyStreamElements, one per chunk.
NextDestIndex *bacap.MessageBoxIndex NextDestIndex is the next destination message box index after all boxes consumed by this call. Use this as DestStartIndex in subsequent calls to continue writing to the same destination stream.
ErrorCode uint8 ErrorCode indicates the success or failure of the envelope creation. A value of ThinClientSuccess indicates successful creation.

CreateCourierEnvelopesFromMultiPayload result

CreateCourierEnvelopesFromPayloadsReply is sent in response to a CreateCourierEnvelopesFromPayloads request. It provides multiple serialized CopyStreamElements packed efficiently from multiple destination payloads.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the CreateCourierEnvelopesFromPayloads request that created it.
Envelopes [][]byte Envelopes is a slice of serialized CopyStreamElements containing all the courier envelopes from all destinations packed efficiently together.
Buffer []byte Buffer contains any data buffered by the encoder that hasn’t been output yet. This can be persisted for crash recovery and restored via SetStreamBuffer.
NextDestIndices []*bacap.MessageBoxIndex NextDestIndices contains the next destination message box index for each destination, in the same order as the destinations in the request. Use these as StartIndex in subsequent calls to continue writing to the same destination streams.
ErrorCode uint8 ErrorCode indicates the success or failure of the envelope creation. A value of ThinClientSuccess indicates successful creation.

CreateCourierEnvelopesFromTombstoneRange result

CreateCourierEnvelopesFromTombstoneRangeReply is sent in response to a CreateCourierEnvelopesFromTombstoneRange request. It provides serialized CopyStreamElements containing tombstone courier envelopes.

Field Type Description
QueryID *[QueryIDLength]byte QueryID is used for correlating this reply with the request.
Envelopes [][]byte Envelopes is a slice of serialized CopyStreamElements.
Buffer []byte Buffer is the residual encoder buffer to pass to the next call. Nil when IsLast was true in the request.
NextDestIndex *bacap.MessageBoxIndex NextDestIndex is the next destination message box index after all tombstones created by this call.
ErrorCode uint8 ErrorCode indicates the success or failure of the operation.

DestinationPayload (parameter)

DestinationPayload specifies a payload and its destination channel for multi-channel writes.

Passed into CreateCourierEnvelopesFromMultiPayload, one per destination channel.

Field Type Description
Payload []byte Payload is the data to be written to this destination.
WriteCap *bacap.WriteCap WriteCap is the write capability for the destination channel.
StartIndex *bacap.MessageBoxIndex StartIndex is the starting index in the destination channel.

Transport and Lifecycle Errors

These errors can in principle be raised by any method that performs I/O against the daemon or the mixnet.

Condition Go Rust Python
Daemon not connected to mixnet Ad-hoc error with message “cannot send message in offline mode - daemon not connected to mixnet”. (No sentinel; check IsConnected() first.) ThinClientError::OfflineMode(String) ThinClientOfflineError
Operation timed out context.DeadlineExceeded (from ctx.Err()) ThinClientError::Timeout(String) asyncio.TimeoutError
Operation canceled by caller context.Canceled (from ctx.Err()) No distinct variant; uses higher-level cancellation. asyncio.CancelledError
Local socket to kpclientd lost returned on the next I/O; thin client attempts reconnect with exponential backoff ditto (receive DaemonDisconnectedEvent on the event sink) ditto (receive DaemonDisconnectedEvent on the event sink)
CBOR (de)serialisation failure wrapped error ThinClientError::CborError(serde_cbor::Error) serde-layer exception bubbles up

The Go binding does not provide a named sentinel for offline mode. Applications that must distinguish “daemon offline” from other errors should test IsConnected() before sending, not compare error values after the fact. The Rust and Python bindings provide proper sentinels testable with matches! / isinstance.


Replica and Courier Errors

The errors below can be returned by StartResendingEncryptedMessage and its variants. They are defined in pigeonhole/errors.go.

Errors specific to reads (when readCap is set)

Error Go Rust Python
Box not found (retries exhausted) ErrBoxIDNotFound ThinClientError::BoxNotFound BoxIDNotFoundError
MKEM decryption failed ErrMKEMDecryptionFailed ThinClientError::MkemDecryptionFailed MKEMDecryptionFailedError
BACAP decryption failed ErrBACAPDecryptionFailed ThinClientError::BacapDecryptionFailed BACAPDecryptionFailedError
Tombstone (box was deleted) ErrTombstone ThinClientError::Tombstone TombstoneError

Errors specific to writes (when writeCap is set)

Error Go Rust Python
Storage full ErrStorageFull ThinClientError::StorageFull StorageFullError

Errors on both reads and writes

Error Go Rust Python
Operation canceled ErrStartResendingCancelled ThinClientError::StartResendingCancelled StartResendingCancelledError
Invalid box ID ErrInvalidBoxID ThinClientError::InvalidBoxId InvalidBoxIDError
Invalid signature ErrInvalidSignature ThinClientError::InvalidSignature InvalidSignatureError
Invalid tombstone signature ErrInvalidTombstoneSignature ThinClientError::InvalidTombstoneSignature InvalidTombstoneSignatureError
Database failure ErrDatabaseFailure ThinClientError::DatabaseFailure DatabaseFailureError
Invalid payload ErrInvalidPayload ThinClientError::InvalidPayload InvalidPayloadError
Invalid epoch ErrInvalidEpoch ThinClientError::InvalidEpoch InvalidEpochError
Replication failed ErrReplicationFailed ThinClientError::ReplicationFailed ReplicationFailedError
Replica internal error ErrReplicaInternalError ThinClientError::ReplicaInternalError ReplicaInternalError
Box already exists (writes only, when non-idempotent variant used) ErrBoxAlreadyExists ThinClientError::BoxAlreadyExists BoxAlreadyExistsError

Copy-command failure

StartResendingCopyCommand can return a diagnostic error carrying the underlying replica error code and the 1-based sequential envelope index at which processing stopped:

Binding Error
Go ErrCopyCommandFailed (see CopyCommandFailedError struct for fields)
Rust ThinClientError::CopyCommandFailed { replica_error_code, failed_envelope_index }
Python CopyCommandFailedError(replica_error_code, failed_envelope_index)

Expected Outcomes vs Real Failures

Some errors from StartResendingEncryptedMessage represent completed operations, not failures. Use IsExpectedOutcome(err) (Go), err.is_expected_outcome() (Rust), or is_expected_outcome(exc) (Python) to distinguish them:

Error Why it may be expected
BoxIDNotFound / BoxNotFound Polling for a message that hasn’t been written yet.
BoxAlreadyExists Retrying an idempotent write that already succeeded.
Tombstone Reading a box that was intentionally deleted.

These should generally not trigger retries in your application.

8 -

Task-oriented guides for using the Katzenpost thin client API

Thin Client How-to Guide

This guide shows how to accomplish specific tasks with the Katzenpost thin client. Each section is self-contained: find the task you need and follow the steps.

If you are new to Pigeonhole, read Understanding Pigeonhole first for the concepts, then return here for the recipes, and consult the Thin Client API Reference for the precise signatures.

Throughout this guide and the API the words channel and stream are used interchangeably: they denote one and the same thing.

Authoritative working examples

A word of caution before you proceed. The code fragments in this guide are illustrative: they are written to teach one task at a time, and to keep the reader’s eye on the matter at hand they omit imports, error handling, and surrounding context. They are not compiled or run by our continuous integration, and so, as the API evolves, an individual snippet may fall out of step with it.

The integration tests below carry no such caveat. They are exercised on every change by CI, so they are guaranteed to compile and to pass against the code they accompany. When a fragment in this guide and a test disagree, the test is correct. Treat these files as the canonical, runnable companion to the prose:

Language Test file Repository
Go client/pigeonhole_docker_test.go katzenpost
Python tests/test_new_pigeonhole_api.py, tests/test_new_methods.py thin_client
Rust tests/channel_api_test.rs thin_client

These links track the main branch of each repository; should you be working against a pinned release, consult the corresponding files at that tag instead.

Table of Contents

Section Description
Connect to the daemon and handle events Establish a connection and process events
Discover network services Find services in the PKI document
Verify the PKI document yourself Check directory authority signatures against your own trust store
Send a message to a mixnet service Echo ping and other non-Pigeonhole services
Create a Pigeonhole channel Generate a stream with write/read capabilities
Write a message Encrypt and send a write to a stream
Read a message Retrieve and decrypt a message from a stream
Read back a multi-box payload Concatenate consecutive boxes into one payload
Wait for a message not yet written Poll with bounded retry around BoxIDNotFound
Persist and restore channel state Survive a process restart without losing your place
Prepare operations offline Do the local crypto now, transmit when connected
A complete end-to-end example One runnable Alice-writes, Bob-reads program
Delete messages with tombstones Tombstone one or more boxes
Detect a tombstone when reading Recognise a deleted box on the read side
Send to one channel atomically Single-destination copy command
Send to multiple channels atomically Multi-destination copy command
Multi-call buffer passing Incremental copy streams with crash recovery
Tombstone a range via copy stream Atomic tombstoning through a courier
Cancel in-flight operations Cancel individual operations or stop all at once
Handle daemon disconnects Automatic reconnection and request replay

How to connect to the daemon and handle events

Connect to the kpclientd daemon and set up event handling:

cfg, err := thin.LoadFile("thinclient.toml")
if err != nil {
    log.Fatal(err)
}

logging := &config.Logging{Level: "INFO"}
client := thin.NewThinClient(cfg, logging)

err = client.Dial()
if err != nil {
    log.Fatal(err)
}
defer client.Close()

// Listen for events
eventCh := client.EventSink()
defer client.StopEventSink(eventCh)

for ev := range eventCh {
    switch v := ev.(type) {
    case *thin.ConnectionStatusEvent:
        fmt.Printf("Connected: %v\n", v.IsConnected)
    case *thin.NewDocumentEvent:
        fmt.Println("New PKI document received")
    case *thin.MessageReplyEvent:
        fmt.Printf("Reply received for SURB %x\n", v.SURBID)
    }
}
let config = Config::new("thinclient.toml")?;
let client = ThinClient::new(config).await?;

// Listen for events
let mut event_rx = client.event_sink();
tokio::spawn(async move {
    while let Some(event) = event_rx.recv().await {
        // Process events
        println!("Event: {:?}", event);
    }
});

// ... do work ...

client.stop().await;
async def on_connection_status(event):
    print(f"Connected: {event.get('is_connected')}")

async def on_new_document(event):
    print("New PKI document received")

async def on_message_reply(event):
    print(f"Reply received")

config = Config("thinclient.toml")
config.on_connection_status = on_connection_status
config.on_new_pki_document = on_new_document
config.on_message_reply = on_message_reply

client = ThinClient(config)
loop = asyncio.get_running_loop()
await client.start(loop)

# ... do work ...

client.stop()

How to discover network services via the PKI document

NOTE that this isn’t necessary for using the Pigeonhole protocol because kpclientd does courier service discovery automatically.

The PKI document lists all available mixnet services. Use GetService to get a random instance of a named service:

doc := client.PKIDocument()
if doc == nil {
    log.Fatal("No PKI document available")
}

// Get a random echo service
desc, err := client.GetService("echo")
if err != nil {
    log.Fatal(err)
}

// Use desc.MixDescriptor.IdentityKey and desc.RecipientQueueID
// as the destination for SendMessage
destNode, destQueue := desc.ToDestination()
let doc = client.pki_document().await?;

// Get a random echo service
let desc = client.get_service("echo").await?;

// Use the destination for send_message
let (dest_node, dest_queue) = desc.to_destination();
doc = client.pki_document()
if doc is None:
    raise Exception("No PKI document available")

# Get a random echo service
desc = client.get_service("echo")

# Use the destination for send_message
dest_node, dest_queue = desc.to_destination()

How to verify the PKI document yourself

In ordinary use you do not need this section. kpclientd already verifies every PKI document against the directory authorities listed in client.toml, and only after a sufficient threshold of authority signatures has passed does it push the document on to the thin client. The pki_document() method described above hands you the post-verification document, and you inherit the daemon’s guarantee without further work. The signature map is stripped before that handoff precisely because the verification has already happened; carrying the signatures through would only invite confusion about whose trust root is in force.

get_pki_document_raw is the trapdoor for special applications and integrations that want the signed document. The cases that come up in practice include:

  • An application that wishes to anchor its own root of trust, independently of kpclientd’s configuration, for instance when shipping a hardened build with the authority keys compiled in.
  • A relay that forwards the signed document to a separate consumer (for archival, audit, or out-of-band verification) which does not itself speak the thin-client protocol.
  • A diagnostic or monitoring tool that wishes to display which authorities signed which consensus, across time.

The method returns the cert.Certificate-wrapped signed document together with the epoch the daemon resolved to. Pass 0 for the requested epoch to mean “whatever the daemon currently believes is the latest”.

The examples below verify the document against the post-quantum hybrid signature scheme Falcon-padded-512-Ed25519, the recommended production scheme published by hpqc in both its Python and Go forms. The authority public keys must come from the application’s own trust store, never from the daemon: if the daemon supplied them, the verification would establish only that the daemon was internally consistent, not that the document was signed by the real authorities.

import struct
from hashlib import blake2b

import cbor2
from hpqc.sign.hybrid import FalconPadded512Ed25519


# The directory authority public keys in the wire format expected by
# hpqc's hybrid scheme: the byte concatenation
# ``falcon_padded_512_pub || ed25519_pub`` (929 bytes per authority).
# These must be obtained out of band, typically baked into the
# application or carried in a separately signed bundle. The hex
# strings below are placeholders.
AUTHORITY_PUBLIC_KEYS = [
    bytes.fromhex("ab" * 929),  # auth1
    bytes.fromhex("cd" * 929),  # auth2
    bytes.fromhex("ef" * 929),  # auth3
]
THRESHOLD = len(AUTHORITY_PUBLIC_KEYS) // 2 + 1
SCHEME_NAME = "Falcon-padded-512-Ed25519"


def _signed_message(cert: dict) -> bytes:
    """Reconstruct the byte string the authorities signed.

    A deterministic little-endian concatenation of the Certificate
    fields preceding Signatures; see katzenpost/core/cert/cert.go for
    the canonical encoding.
    """
    return b"".join([
        struct.pack("<I", cert["Version"]),
        struct.pack("<Q", cert["Expiration"]),
        cert["KeyType"].encode("utf-8"),
        cert["Certified"],
    ])


async def fetch_and_verify_pki(client, epoch: int = 0) -> bytes:
    """Fetch the signed PKI document and verify it against the trust root.

    Returns the inner Certified payload (the CBOR-encoded Document)
    once a sufficient threshold of authority signatures has verified;
    raises ValueError otherwise.
    """
    payload, returned_epoch = await client.get_pki_document_raw(epoch)
    cert = cbor2.loads(payload)

    if cert["Version"] != 0:
        raise ValueError(f"unknown certificate version: {cert['Version']}")
    if cert["KeyType"] != SCHEME_NAME:
        raise ValueError(
            f"unexpected key type {cert['KeyType']!r}, "
            f"expected {SCHEME_NAME!r}"
        )

    msg = _signed_message(cert)
    signatures = cert.get("Signatures") or {}

    verified = 0
    for pubkey in AUTHORITY_PUBLIC_KEYS:
        key_hash = blake2b(pubkey, digest_size=32).digest()
        sig = signatures.get(key_hash)
        if sig is None:
            continue
        if FalconPadded512Ed25519.verify(pubkey, msg, sig["Payload"]):
            verified += 1

    if verified < THRESHOLD:
        raise ValueError(
            f"only {verified} of {len(AUTHORITY_PUBLIC_KEYS)} authority "
            f"signatures verified for epoch {returned_epoch}; threshold "
            f"is {THRESHOLD}"
        )

    # cert["Certified"] is the CBOR-encoded Document. Decode it with
    # cbor2.loads(cert["Certified"]) if the application needs the
    # contents themselves.
    return cert["Certified"]
package main

import (
    "encoding/hex"
    "fmt"
    "log"

    "github.com/katzenpost/hpqc/sign"
    "github.com/katzenpost/hpqc/sign/hybrid"

    "github.com/katzenpost/katzenpost/client/thin"
    "github.com/katzenpost/katzenpost/core/cert"
)

// AuthorityPublicKeysHex is the application's root of trust for the
// network's directory: the wire-format hybrid public keys of each
// authority, hex-encoded. They must be obtained out of band and
// never from the daemon. Replace these placeholders with your own.
var AuthorityPublicKeysHex = []string{
    "abab...", // auth1
    "cdcd...", // auth2
    "efef...", // auth3
}

// FetchAndVerifyPKI fetches the signed PKI document for the given
// epoch (pass 0 for "current") and verifies it against the
// authority public keys above using core/cert.VerifyThreshold.
func FetchAndVerifyPKI(client *thin.ThinClient, epoch uint64) ([]byte, error) {
    scheme := hybrid.FalconPadded512Ed25519
    verifiers := make([]sign.PublicKey, 0, len(AuthorityPublicKeysHex))
    for _, hexKey := range AuthorityPublicKeysHex {
        raw, err := hex.DecodeString(hexKey)
        if err != nil {
            return nil, fmt.Errorf("decoding authority key: %w", err)
        }
        pub, err := scheme.UnmarshalBinaryPublicKey(raw)
        if err != nil {
            return nil, fmt.Errorf("parsing authority key: %w", err)
        }
        verifiers = append(verifiers, pub)
    }

    payload, returnedEpoch, err := client.GetPKIDocumentRaw(epoch)
    if err != nil {
        return nil, fmt.Errorf("fetching signed PKI doc: %w", err)
    }

    threshold := len(verifiers)/2 + 1
    certified, good, _, err := cert.VerifyThreshold(verifiers, threshold, payload)
    if err != nil {
        return nil, fmt.Errorf(
            "threshold verification failed for epoch %d: %w",
            returnedEpoch, err,
        )
    }
    log.Printf("verified %d of %d authority signatures for epoch %d",
        len(good), len(verifiers), returnedEpoch)
    return certified, nil
}

Considerations:

  • The authority public keys must come from a trust root external to the daemon. If the daemon supplied them, verification would prove only that the daemon was internally consistent.
  • The threshold above (a simple majority) matches the policy that the authorities themselves enforce when they admit a consensus. An application may apply a stricter policy, but should not relax it.
  • Should the network ever be reconfigured to use a different signature scheme, swap the hybrid for the corresponding hpqc verifier and adjust the expected KeyType (Python) or the hybrid.* selector (Go) accordingly. The KeyType field of the certificate is what the authorities signed under, and is the authoritative indicator of the scheme in force.
  • A Rust binding is not shown because hpqc does not yet publish a Rust port; a Rust application can compose the verification with the ed25519-dalek and falcon crates by the same wire layout (the public key and signature are simple concatenations of the two component halves).

How to send a message to a mixnet service

NOTE that this API call is NOT used with the Pigeonhole protocol. However it is still useful for writing other protocols and proving the echo service.

Use BlockingSendMessage for simple request-response interactions with non-Pigeonhole services (like the echo service):

desc, err := client.GetService("echo")
if err != nil {
    log.Fatal(err)
}

destNode, destQueue := desc.ToDestination()

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

reply, err := client.BlockingSendMessage(ctx, []byte("hello mixnet"), destNode, destQueue)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Reply: %s\n", reply)
let desc = client.get_service("echo").await?;
let (dest_node, dest_queue) = desc.to_destination();

let reply = client.blocking_send_message(
    b"hello mixnet",
    dest_node,
    dest_queue,
    std::time::Duration::from_secs(30),
).await?;
println!("Reply: {:?}", reply);
desc = client.get_service("echo")
dest_node, dest_queue = desc.to_destination()

reply = await client.blocking_send_message(
    b"hello mixnet", dest_node, dest_queue, timeout_seconds=30.0
)
print(f"Reply: {reply}")

How to create a Pigeonhole channel

NOTE that this does NOT produce any network traffic. It’s a local cryptographic operation only.

A Pigeonhole channel (stream) is created from a 32-byte random seed. The writer keeps the write cap; the reader receives the read cap and first index out-of-band.

seed := make([]byte, 32)
_, err := rand.Reader.Read(seed)
if err != nil {
    log.Fatal(err)
}

writeCap, readCap, firstIndex, err := client.NewKeypair(seed)
if err != nil {
    log.Fatal(err)
}

// Writer keeps: writeCap, firstIndex
// Share with reader out-of-band: readCap, firstIndex
let seed: [u8; 32] = rand::random();
let result = client.new_keypair(&seed).await?;

// Writer keeps: result.write_cap, result.first_message_index
// Share with reader out-of-band: result.read_cap, result.first_message_index
import os
seed = os.urandom(32)
result = await client.new_keypair(seed)

# Writer keeps: result.write_cap, result.first_message_index
# Share with reader out-of-band: result.read_cap, result.first_message_index

How to write a message to a Pigeonhole channel

Writing is a two-step process: encrypt the message, then send it via ARQ. A write is idempotent by default: re-sending a box that was already filled returns success rather than an error, so a retransmit after an uncertain failure is safe. When you must instead distinguish a fresh write from a repeat, for instance to implement optimistic concurrency, use the box-exists-aware variant (StartResendingEncryptedMessageReturnBoxExists in Go, start_resending_encrypted_message_return_box_exists in Rust, no_idempotent_box_already_exists=True in Python), which surfaces BoxAlreadyExists as an error at the cost of one extra mixnet round trip.

// Encrypt the message
ciphertext, envDesc, envHash, nextIndex, err := client.EncryptWrite(
    []byte("hello"), writeCap, currentIndex,
)
if err != nil {
    log.Fatal(err)
}

// Send via ARQ (blocks until acknowledged)
_, err = client.StartResendingEncryptedMessage(
    nil,       // readCap (nil for writes)
    writeCap,
    nil,       // messageBoxIndex (nil for writes)
    nil,       // replyIndex
    envDesc,
    ciphertext,
    envHash,
)
if err != nil {
    log.Fatal(err)
}

// Advance the index for the next write
currentIndex = nextIndex
// Encrypt the message
let result = client.encrypt_write(
    b"hello", &write_cap, &current_index,
).await?;

// Send via ARQ (blocks until acknowledged)
client.start_resending_encrypted_message(
    None,                           // read_cap (None for writes)
    Some(&write_cap),
    None,                           // message_box_index
    None,                           // reply_index
    &result.envelope_descriptor,
    &result.message_ciphertext,
    &result.envelope_hash,
).await?;

// Advance the index for the next write
current_index = result.next_message_box_index;
# Encrypt the message
result = await client.encrypt_write(b"hello", write_cap, current_index)

# Send via ARQ (blocks until acknowledged)
await client.start_resending_encrypted_message(
    read_cap=None,
    write_cap=write_cap,
    message_box_index=None,
    reply_index=None,
    envelope_descriptor=result.envelope_descriptor,
    message_ciphertext=result.message_ciphertext,
    envelope_hash=result.envelope_hash,
)

# Advance the index for the next write
current_index = result.next_message_box_index

How to read a message from a Pigeonhole channel

Reading is also two steps: encrypt a read request, then send it via ARQ. The reply contains the plaintext. Unlike a write, a read must be given the index of the box being read (the messageBoxIndex argument, its marshalled bytes in Go); the daemon derives the box ID and decrypts the reply from it, so a read that omits the index comes back undecrypted.

// Encrypt a read request
ciphertext, envDesc, envHash, nextIndex, err := client.EncryptRead(
    readCap, currentIndex,
)
if err != nil {
    log.Fatal(err)
}

// A read MUST supply the marshalled index of the box being read.
// The daemon needs it to derive the box ID and to decrypt the reply;
// pass nil and the reply comes back undecrypted.
idxBytes, err := currentIndex.MarshalBinary()
if err != nil {
    log.Fatal(err)
}

// Send via ARQ (blocks until the message is retrieved)
result, err := client.StartResendingEncryptedMessage(
    readCap,
    nil,       // writeCap (nil for reads)
    idxBytes,  // messageBoxIndex (required for reads)
    nil,       // replyIndex (nil uses the default)
    envDesc,
    ciphertext,
    envHash,
)
if err != nil {
    log.Fatal(err)
}

plaintext := result.Plaintext
// Advance the index for the next read
currentIndex = nextIndex
// Encrypt a read request
let read_result = client.encrypt_read(&read_cap, &current_index).await?;

// Send via ARQ (blocks until the message is retrieved)
let result = client.start_resending_encrypted_message(
    Some(&read_cap),
    None,                            // write_cap (None for reads)
    Some(&current_index),            // message_box_index (required for reads)
    None,                            // reply_index (None uses the default)
    &read_result.envelope_descriptor,
    &read_result.message_ciphertext,
    &read_result.envelope_hash,
).await?;

let plaintext = result.plaintext;
// Advance the index for the next read
current_index = read_result.next_message_box_index;
# Encrypt a read request
read_result = await client.encrypt_read(read_cap, current_index)

# Send via ARQ (blocks until the message is retrieved)
plaintext = await client.start_resending_encrypted_message(
    read_cap=read_cap,
    write_cap=None,
    message_box_index=current_index,  # required for reads
    reply_index=None,                 # None uses the default
    envelope_descriptor=read_result.envelope_descriptor,
    message_ciphertext=read_result.message_ciphertext,
    envelope_hash=read_result.envelope_hash,
)

# Advance the index for the next read
current_index = read_result.next_message_box_index

How to read back a multi-box payload

A single read retrieves one box. A payload that spanned several boxes, anything a copy command wrote, or any write larger than one box of plaintext, is read back by stepping through consecutive indices and concatenating the plaintexts in the order the writer laid them down.

The reader must know where the payload ends. The boxes themselves carry no total length, so the writer frames it. The convention the integration tests use, and the one shown here, is a fixed four-byte big-endian length prefix on the very first box; the reader accumulates boxes until it holds the prefix plus that many bytes.

// readCap and firstIndex were shared by the writer, who prefixed the
// payload with a 4-byte big-endian length.
readIndex := firstIndex
var payload []byte
var total uint32
for {
    ct, ed, eh, nextIndex, err := client.EncryptRead(readCap, readIndex)
    if err != nil {
        log.Fatal(err)
    }
    idxBytes, err := readIndex.MarshalBinary()
    if err != nil {
        log.Fatal(err)
    }
    result, err := client.StartResendingEncryptedMessage(
        readCap, nil, idxBytes, nil, ed, ct, eh)
    if err != nil {
        log.Fatal(err)
    }
    payload = append(payload, result.Plaintext...)

    // Once the 4-byte prefix is in hand, the total length is known.
    if total == 0 && len(payload) >= 4 {
        total = binary.BigEndian.Uint32(payload[:4])
    }
    if total > 0 && uint32(len(payload)) >= total+4 {
        break
    }
    readIndex = nextIndex
}
payload = payload[4:] // drop the length prefix
// read_cap and first_message_index were shared by the writer, who
// prefixed the payload with a 4-byte big-endian length.
let mut read_index = first_message_index.clone();
let mut payload: Vec<u8> = Vec::new();
let mut total: Option<u32> = None;
loop {
    let read = client.encrypt_read(&read_cap, &read_index).await?;
    let result = client.start_resending_encrypted_message(
        Some(&read_cap), None, Some(&read_index), None,
        &read.envelope_descriptor, &read.message_ciphertext,
        &read.envelope_hash).await?;
    payload.extend_from_slice(&result.plaintext);

    if total.is_none() && payload.len() >= 4 {
        total = Some(u32::from_be_bytes(payload[..4].try_into().unwrap()));
    }
    if let Some(t) = total {
        if payload.len() as u32 >= t + 4 {
            break;
        }
    }
    read_index = read.next_message_box_index;
}
let payload = &payload[4..]; // drop the length prefix
import struct

# read_cap and first_message_index were shared by the writer, who
# prefixed the payload with a 4-byte big-endian length.
read_index = first_message_index
payload = b""
total = None
while True:
    read = await client.encrypt_read(read_cap, read_index)
    result = await client.start_resending_encrypted_message(
        read_cap=read_cap, write_cap=None,
        message_box_index=read_index, reply_index=None,
        envelope_descriptor=read.envelope_descriptor,
        message_ciphertext=read.message_ciphertext,
        envelope_hash=read.envelope_hash,
    )
    payload += result.plaintext

    if total is None and len(payload) >= 4:
        total = struct.unpack(">I", payload[:4])[0]
    if total is not None and len(payload) >= total + 4:
        break
    read_index = read.next_message_box_index

payload = payload[4:]  # drop the length prefix

Each iteration of the loop costs one mixnet round trip. To write many boxes atomically in the other direction, use a copy command; see the copy command recipes below.


How to wait for a message that has not been written yet

Reads and writes are not coordinated: a reader routinely asks for an index before the writer has filled it, and replication lag can briefly hide a box that was in fact written. In both cases the daemon reports BoxIDNotFound. This is the expected answer to “anything here yet?”, not a failure. The correct pattern is a bounded poll: retry on the expected outcome, with a short delay between attempts, until the data appears or an application deadline elapses. Use IsExpectedOutcome to tell a benign “not yet” apart from a real error, so that genuine failures are not silently retried forever.

Two refinements are worth knowing. First, the ordinary read already retries through brief replication lag on its own (a default read does not return BoxIDNotFound at all: the daemon retries without bound until the box is written), so a single read often serves as a deterministic propagation gate: for a sequentially written stream, reading the last box written gates on all the earlier ones, which were written sooner and so have had at least as long to settle. This is the readiness signal to prefer over a fixed sleep. Second, when you would rather learn at once that a box is absent, for instance to peek at a peer’s next message before it has been produced, use the no-retry variant (StartResendingEncryptedMessageNoRetry in Go, start_resending_encrypted_message_no_retry in Rust, no_retry_on_box_id_not_found=True in Python), which returns BoxIDNotFound immediately instead of waiting out the retries.

deadline := time.Now().Add(2 * time.Minute)
var plaintext []byte
for {
    ciphertext, envDesc, envHash, nextIndex, err := client.EncryptRead(
        readCap, currentIndex,
    )
    if err != nil {
        log.Fatal(err)
    }

    idxBytes, err := currentIndex.MarshalBinary()
    if err != nil {
        log.Fatal(err)
    }
    result, err := client.StartResendingEncryptedMessageNoRetry(
        readCap, nil, idxBytes, nil, envDesc, ciphertext, envHash,
    )
    if err == nil {
        plaintext = result.Plaintext
        currentIndex = nextIndex
        break
    }

    // BoxIDNotFound here just means "not written yet". Anything that
    // is not an expected outcome is a real failure worth surfacing.
    if !thin.IsExpectedOutcome(err) {
        log.Fatal(err)
    }
    if time.Now().After(deadline) {
        log.Fatal("gave up waiting for the message")
    }
    time.Sleep(3 * time.Second)
}
let deadline = std::time::Instant::now()
    + std::time::Duration::from_secs(120);
let plaintext = loop {
    let read = client.encrypt_read(&read_cap, &current_index).await?;
    match client.start_resending_encrypted_message_no_retry(
        Some(&read_cap), None, Some(&current_index), None,
        &read.envelope_descriptor,
        &read.message_ciphertext,
        &read.envelope_hash,
    ).await {
        Ok(result) => {
            current_index = read.next_message_box_index;
            break result.plaintext;
        }
        Err(e) if e.is_expected_outcome() => {
            if std::time::Instant::now() > deadline {
                return Err(e);
            }
            tokio::time::sleep(
                std::time::Duration::from_secs(3)).await;
        }
        Err(e) => return Err(e),
    }
};
import asyncio, time
from katzenpost_thinclient import is_expected_outcome

deadline = time.monotonic() + 120
while True:
    read = await client.encrypt_read(read_cap, current_index)
    try:
        plaintext = await client.start_resending_encrypted_message(
            read_cap=read_cap, write_cap=None,
            message_box_index=current_index, reply_index=None,
            envelope_descriptor=read.envelope_descriptor,
            message_ciphertext=read.message_ciphertext,
            envelope_hash=read.envelope_hash,
            no_retry_on_box_id_not_found=True,
        )
        current_index = read.next_message_box_index
        break
    except Exception as exc:
        # "not written yet" is expected; anything else is a real error.
        if not is_expected_outcome(exc):
            raise
        if time.monotonic() > deadline:
            raise
        await asyncio.sleep(3)

How to persist and restore channel state

The daemon keeps no per-application channel state. The write cap, the read cap, and above all the current index belong to your application, and if you lose the index across a restart you no longer know where to append next (re-using a filled index earns BoxAlreadyExists). Persist the index every time you advance it, durably, before you treat the write as done.

In Go the capabilities and the index are typed; serialise them with MarshalBinary and restore them with the bacap constructors. In Rust and Python new_keypair already hands you the caps and index as byte strings, so persistence is simply storing and reloading those bytes.

import "github.com/katzenpost/hpqc/bacap"

// Save: marshal each artefact to bytes and write atomically to disk.
wcBytes, _ := writeCap.MarshalBinary()
rcBytes, _ := readCap.MarshalBinary()
idxBytes, _ := currentIndex.MarshalBinary()
saveState(wcBytes, rcBytes, idxBytes) // your durable, atomic write

// Restore after a restart:
writeCap, err := bacap.NewWriteCapFromBytes(wcBytes)
if err != nil {
    log.Fatal(err)
}
readCap, err := bacap.ReadCapFromBytes(rcBytes)
if err != nil {
    log.Fatal(err)
}
currentIndex, err := bacap.NewEmptyMessageBoxIndexFromBytes(idxBytes)
if err != nil {
    log.Fatal(err)
}
// new_keypair already returns Vec<u8> for each artefact.
let kp = client.new_keypair(&seed).await?;
save_state(&kp.write_cap, &kp.read_cap, &kp.first_message_index);
let mut current_index = kp.first_message_index.clone();

// ... each time you advance, persist the new index bytes ...
save_index(&current_index);

// After a restart, the stored bytes are passed straight back into
// the API; no deserialisation step is required.
let (write_cap, read_cap, current_index) = load_state();
# new_keypair already returns bytes for each artefact.
kp = await client.new_keypair(seed)
save_state(kp.write_cap, kp.read_cap, kp.first_message_index)
current_index = kp.first_message_index

# ... each time you advance, persist the new index bytes ...
save_index(current_index)

# After a restart, the stored bytes are passed straight back into
# the API; no deserialisation step is required.
write_cap, read_cap, current_index = load_state()

The writer must persist currentIndex after every successful write, the reader after every successful read. Persist the index before acknowledging the message to the rest of your application, so that a crash cannot leave you having processed a message whose index you never recorded.


How to prepare operations offline

The daemon distinguishes two kinds of work. Key generation and envelope encryption (NewKeypair, EncryptWrite, EncryptRead, TombstoneRange, and the copy-stream constructors) are local cryptography and succeed even when the daemon is not connected to the mixnet. Only StartResendingEncryptedMessage and StartResendingCopyCommand require connectivity; called offline they fail rather than block.

You can therefore prepare envelopes while offline, persist them, and transmit once connectivity returns. Test IsConnected before transmitting, or watch the connection event and flush a queue when it turns true.

// Offline: this is pure local crypto and works regardless.
ciphertext, envDesc, envHash, nextIndex, err := client.EncryptWrite(
    []byte("written while offline"), writeCap, currentIndex,
)
if err != nil {
    log.Fatal(err)
}
enqueue(envDesc, ciphertext, envHash) // persist for later

// Later, only transmit once the daemon is connected.
if client.IsConnected() {
    for _, e := range drainQueue() {
        _, err = client.StartResendingEncryptedMessage(
            nil, writeCap, nil, nil, e.desc, e.ct, e.hash)
        if err != nil {
            log.Fatal(err)
        }
    }
}
// Offline: pure local crypto, works regardless.
let w = client.encrypt_write(
    b"written while offline", &write_cap, &current_index).await?;
enqueue(&w); // persist for later

// Later, only transmit once connected.
if client.is_connected() {
    for e in drain_queue() {
        client.start_resending_encrypted_message(
            None, Some(&write_cap), None, None,
            &e.envelope_descriptor, &e.message_ciphertext,
            &e.envelope_hash).await?;
    }
}
# Offline: pure local crypto, works regardless.
w = await client.encrypt_write(
    b"written while offline", write_cap, current_index)
enqueue(w)  # persist for later

# Later, only transmit once connected.
if client.is_connected():
    for e in drain_queue():
        await client.start_resending_encrypted_message(
            read_cap=None, write_cap=write_cap,
            message_box_index=None, reply_index=None,
            envelope_descriptor=e.envelope_descriptor,
            message_ciphertext=e.message_ciphertext,
            envelope_hash=e.envelope_hash)

A complete end-to-end example

The fragments above each show one task. Here they are assembled into a single runnable program: Alice creates a stream, writes one message, and Bob reads it back. This is the smallest complete program that exercises the Pigeonhole path. As with every example in this guide it omits production concerns (durable persistence, structured logging), but it compiles into the shape of a real application; the CI-verified tests are the authority on exact, current usage.

package main

import (
    "log"

    "github.com/katzenpost/hpqc/rand"

    "github.com/katzenpost/katzenpost/client/thin"
    "github.com/katzenpost/katzenpost/core/config"
)

func main() {
    cfg, err := thin.LoadFile("thinclient.toml")
    if err != nil {
        log.Fatal(err)
    }
    client := thin.NewThinClient(cfg, &config.Logging{Level: "INFO"})
    if err := client.Dial(); err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    // Alice creates a stream.
    seed := make([]byte, 32)
    if _, err := rand.Reader.Read(seed); err != nil {
        log.Fatal(err)
    }
    writeCap, readCap, idx, err := client.NewKeypair(seed)
    if err != nil {
        log.Fatal(err)
    }

    // Alice writes one message.
    ct, ed, eh, _, err := client.EncryptWrite(
        []byte("hello from Alice"), writeCap, idx)
    if err != nil {
        log.Fatal(err)
    }
    if _, err := client.StartResendingEncryptedMessage(
        nil, writeCap, nil, nil, ed, ct, eh); err != nil {
        log.Fatal(err)
    }

    // Bob reads it back (readCap would normally be shared out-of-band).
    rct, red, reh, _, err := client.EncryptRead(readCap, idx)
    if err != nil {
        log.Fatal(err)
    }
    idxBytes, err := idx.MarshalBinary()
    if err != nil {
        log.Fatal(err)
    }
    result, err := client.StartResendingEncryptedMessage(
        readCap, nil, idxBytes, nil, red, rct, reh)
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Bob read: %s", result.Plaintext)
}
use katzenpost_thin_client::{Config, ThinClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::new("thinclient.toml")?;
    let client = ThinClient::new(config).await?;

    // Alice creates a stream.
    let seed: [u8; 32] = rand::random();
    let kp = client.new_keypair(&seed).await?;

    // Alice writes one message.
    let w = client.encrypt_write(
        b"hello from Alice", &kp.write_cap, &kp.first_message_index).await?;
    client.start_resending_encrypted_message(
        None, Some(&kp.write_cap), None, None,
        &w.envelope_descriptor, &w.message_ciphertext,
        &w.envelope_hash).await?;

    // Bob reads it back (read_cap would normally be shared out-of-band).
    let r = client.encrypt_read(&kp.read_cap, &kp.first_message_index).await?;
    let result = client.start_resending_encrypted_message(
        Some(&kp.read_cap), None, Some(&kp.first_message_index), None,
        &r.envelope_descriptor, &r.message_ciphertext,
        &r.envelope_hash).await?;
    println!("Bob read: {:?}", result.plaintext);

    client.stop().await;
    Ok(())
}
import asyncio, os
from katzenpost_thinclient import ThinClient, Config

async def main():
    config = Config("thinclient.toml")
    client = ThinClient(config)
    await client.start(asyncio.get_running_loop())

    # Alice creates a stream.
    seed = os.urandom(32)
    kp = await client.new_keypair(seed)

    # Alice writes one message.
    w = await client.encrypt_write(
        b"hello from Alice", kp.write_cap, kp.first_message_index)
    await client.start_resending_encrypted_message(
        read_cap=None, write_cap=kp.write_cap,
        message_box_index=None, reply_index=None,
        envelope_descriptor=w.envelope_descriptor,
        message_ciphertext=w.message_ciphertext,
        envelope_hash=w.envelope_hash)

    # Bob reads it back (read_cap would normally be shared out-of-band).
    r = await client.encrypt_read(kp.read_cap, kp.first_message_index)
    plaintext = await client.start_resending_encrypted_message(
        read_cap=kp.read_cap, write_cap=None,
        message_box_index=kp.first_message_index, reply_index=None,
        envelope_descriptor=r.envelope_descriptor,
        message_ciphertext=r.message_ciphertext,
        envelope_hash=r.envelope_hash)
    print("Bob read:", plaintext)

    client.stop()

asyncio.run(main())

How to delete messages with tombstones

Use TombstoneRange to create tombstone envelopes, then send each one via StartResendingEncryptedMessage. To tombstone a single box, use maxCount=1.

// Create tombstone envelopes for 5 boxes
result, err := client.TombstoneRange(writeCap, startIndex, 5)
if err != nil {
    log.Fatal(err)
}

// Send each tombstone
for _, envelope := range result.Envelopes {
    _, err = client.StartResendingEncryptedMessage(
        nil, writeCap, nil, nil,
        envelope.EnvelopeDescriptor,
        envelope.MessageCiphertext,
        envelope.EnvelopeHash,
    )
    if err != nil {
        log.Fatal(err)
    }
}
// result.Next is the index after the last tombstoned box
// Create tombstone envelopes for 5 boxes
let result = client.tombstone_range(&write_cap, &start_index, 5).await;

// Send each tombstone
for envelope in &result.envelopes {
    client.start_resending_encrypted_message(
        None,
        Some(&write_cap),
        None,
        None,
        &envelope.envelope_descriptor,
        &envelope.message_ciphertext,
        &envelope.envelope_hash,
    ).await?;
}
// result.next is the index after the last tombstoned box
# Create tombstone envelopes for 5 boxes
result = await client.tombstone_range(write_cap, start_index, 5)

# Send each tombstone
for envelope in result.envelopes:
    await client.start_resending_encrypted_message(
        read_cap=None,
        write_cap=write_cap,
        message_box_index=None,
        reply_index=None,
        envelope_descriptor=envelope.envelope_descriptor,
        message_ciphertext=envelope.message_ciphertext,
        envelope_hash=envelope.envelope_hash,
    )
# result.next is the index after the last tombstoned box

How to detect a tombstone when reading

The counterpart to deleting a box is recognising a deleted box on the read side. A reader that reaches a tombstoned box does not get silence; it gets a definite tombstone error (ErrTombstone in Go, ThinClientError::Tombstone in Rust, TombstoneError in Python). Like BoxIDNotFound, this is an expected outcome rather than a transport failure, so IsExpectedOutcome treats it as benign; catch it to learn that the box was deliberately deleted and to stop reading the stream.

idxBytes, err := currentIndex.MarshalBinary()
if err != nil {
    log.Fatal(err)
}
result, err := client.StartResendingEncryptedMessage(
    readCap, nil, idxBytes, nil, envDesc, ciphertext, envHash)
switch {
case err == nil:
    plaintext := result.Plaintext
    _ = plaintext // use the message
case errors.Is(err, thin.ErrTombstone):
    // The box was deliberately deleted. Expected, not a failure.
    log.Printf("box at this index was tombstoned")
default:
    log.Fatal(err)
}
match client.start_resending_encrypted_message(
    Some(&read_cap), None, Some(&current_index), None,
    &read.envelope_descriptor, &read.message_ciphertext,
    &read.envelope_hash,
).await {
    Ok(result) => { /* use result.plaintext */ }
    Err(ThinClientError::Tombstone) => {
        // The box was deliberately deleted. Expected, not a failure.
        println!("box at this index was tombstoned");
    }
    Err(e) => return Err(e.into()),
}
from katzenpost_thinclient import TombstoneError

try:
    result = await client.start_resending_encrypted_message(
        read_cap=read_cap, write_cap=None,
        message_box_index=current_index, reply_index=None,
        envelope_descriptor=read.envelope_descriptor,
        message_ciphertext=read.message_ciphertext,
        envelope_hash=read.envelope_hash,
    )
    plaintext = result.plaintext  # use the message
except TombstoneError:
    # The box was deliberately deleted. Expected, not a failure.
    print("box at this index was tombstoned")

How to send to one channel atomically via copy command

A copy command writes data to a destination channel atomically via a courier. The steps are:

  1. Create a temporary channel and a destination channel.
  2. Pack the payload into copy stream elements.
  3. Write each element to the temporary channel.
  4. Send a copy command referencing the temporary channel.
// Create destination channel
destSeed := make([]byte, 32)
rand.Reader.Read(destSeed)
destWriteCap, destReadCap, destFirstIndex, err := client.NewKeypair(destSeed)
if err != nil {
    log.Fatal(err)
}

// Create temporary channel
tempSeed := make([]byte, 32)
rand.Reader.Read(tempSeed)
tempWriteCap, _, tempFirstIndex, err := client.NewKeypair(tempSeed)
if err != nil {
    log.Fatal(err)
}

// Pack payload into copy stream elements
envelopes, _, err := client.CreateCourierEnvelopesFromPayload(
    payload, destWriteCap, destFirstIndex,
    true,  // isStart
    true,  // isLast
)
if err != nil {
    log.Fatal(err)
}

// Write each element to the temporary channel
tempIndex := tempFirstIndex
for _, chunk := range envelopes {
    ciphertext, envDesc, envHash, nextIdx, err := client.EncryptWrite(
        chunk, tempWriteCap, tempIndex,
    )
    if err != nil {
        log.Fatal(err)
    }
    _, err = client.StartResendingEncryptedMessage(
        nil, tempWriteCap, nil, nil, envDesc, ciphertext, envHash,
    )
    if err != nil {
        log.Fatal(err)
    }
    tempIndex = nextIdx
}

// Send the copy command (blocks until courier acknowledges)
err = client.StartResendingCopyCommand(tempWriteCap)
if err != nil {
    log.Fatal(err)
}

// Share destReadCap and destFirstIndex with the reader
// Create destination channel
let dest_seed: [u8; 32] = rand::random();
let dest = client.new_keypair(&dest_seed).await?;

// Create temporary channel
let temp_seed: [u8; 32] = rand::random();
let temp = client.new_keypair(&temp_seed).await?;

// Pack payload into copy stream elements
let envelopes_result = client.create_courier_envelopes_from_payload(
    &payload, &dest.write_cap, &dest.first_message_index,
    true,  // is_start
    true,  // is_last
).await?;

// Write each element to the temporary channel
let mut temp_index = temp.first_message_index.clone();
for chunk in &envelopes_result.envelopes {
    let write_result = client.encrypt_write(
        chunk, &temp.write_cap, &temp_index,
    ).await?;
    client.start_resending_encrypted_message(
        None, Some(&temp.write_cap), None, None,
        &write_result.envelope_descriptor,
        &write_result.message_ciphertext,
        &write_result.envelope_hash,
    ).await?;
    temp_index = write_result.next_message_box_index;
}

// Send the copy command (blocks until courier acknowledges)
client.start_resending_copy_command(&temp.write_cap, None, None).await?;

// Share dest.read_cap and dest.first_message_index with the reader
import os

# Create destination channel
dest_seed = os.urandom(32)
dest = await client.new_keypair(dest_seed)

# Create temporary channel
temp_seed = os.urandom(32)
temp = await client.new_keypair(temp_seed)

# Pack payload into copy stream elements
envelopes_result = await client.create_courier_envelopes_from_payload(
    payload, dest.write_cap, dest.first_message_index,
    is_start=True,
    is_last=True,
)

# Write each element to the temporary channel
temp_index = temp.first_message_index
for chunk in envelopes_result.envelopes:
    write_result = await client.encrypt_write(chunk, temp.write_cap, temp_index)
    await client.start_resending_encrypted_message(
        read_cap=None, write_cap=temp.write_cap,
        message_box_index=None, reply_index=None,
        envelope_descriptor=write_result.envelope_descriptor,
        message_ciphertext=write_result.message_ciphertext,
        envelope_hash=write_result.envelope_hash,
    )
    temp_index = write_result.next_message_box_index

# Send the copy command (blocks until courier acknowledges)
await client.start_resending_copy_command(temp.write_cap)

# Share dest.read_cap and dest.first_message_index with the reader

How to send to multiple channels atomically

Use CreateCourierEnvelopesFromMultiPayload to pack payloads for different destinations into a single copy stream efficiently:

// Create destination channels
dest1WriteCap, dest1ReadCap, dest1Index, _ := client.NewKeypair(seed1)
dest2WriteCap, dest2ReadCap, dest2Index, _ := client.NewKeypair(seed2)

// Create temporary channel
tempWriteCap, _, tempFirstIndex, _ := client.NewKeypair(tempSeed)

// Pack multiple payloads
destinations := []thin.DestinationPayload{
    {Payload: payload1, WriteCap: dest1WriteCap, StartIndex: dest1Index},
    {Payload: payload2, WriteCap: dest2WriteCap, StartIndex: dest2Index},
}

result, err := client.CreateCourierEnvelopesFromMultiPayload(
    destinations,
    true,  // isStart
    true,  // isLast
    nil,   // buffer (nil for first call)
)
if err != nil {
    log.Fatal(err)
}

// Write envelopes to temporary channel
tempIndex := tempFirstIndex
for _, chunk := range result.Envelopes {
    ciphertext, envDesc, envHash, nextIdx, err := client.EncryptWrite(
        chunk, tempWriteCap, tempIndex,
    )
    if err != nil {
        log.Fatal(err)
    }
    _, err = client.StartResendingEncryptedMessage(
        nil, tempWriteCap, nil, nil, envDesc, ciphertext, envHash,
    )
    if err != nil {
        log.Fatal(err)
    }
    tempIndex = nextIdx
}

// Send copy command
err = client.StartResendingCopyCommand(tempWriteCap)
// Create destination channels
let dest1 = client.new_keypair(&seed1).await?;
let dest2 = client.new_keypair(&seed2).await?;

// Create temporary channel
let temp = client.new_keypair(&temp_seed).await?;

// Pack multiple payloads
let destinations = vec![
    (&payload1[..], &dest1.write_cap[..], &dest1.first_message_index[..]),
    (&payload2[..], &dest2.write_cap[..], &dest2.first_message_index[..]),
];

let result = client.create_courier_envelopes_from_multi_payload(
    destinations,
    true,  // is_start
    true,  // is_last
    None,  // buffer (None for first call)
).await?;

// Write envelopes to temporary channel
let mut temp_index = temp.first_message_index.clone();
for chunk in &result.envelopes {
    let write_result = client.encrypt_write(
        chunk, &temp.write_cap, &temp_index,
    ).await?;
    client.start_resending_encrypted_message(
        None, Some(&temp.write_cap), None, None,
        &write_result.envelope_descriptor,
        &write_result.message_ciphertext,
        &write_result.envelope_hash,
    ).await?;
    temp_index = write_result.next_message_box_index;
}

// Send copy command
client.start_resending_copy_command(&temp.write_cap, None, None).await?;
# Create destination channels
dest1 = await client.new_keypair(seed1)
dest2 = await client.new_keypair(seed2)

# Create temporary channel
temp = await client.new_keypair(temp_seed)

# Pack multiple payloads
destinations = [
    {"payload": payload1, "write_cap": dest1.write_cap, "start_index": dest1.first_message_index},
    {"payload": payload2, "write_cap": dest2.write_cap, "start_index": dest2.first_message_index},
]

result = await client.create_courier_envelopes_from_multi_payload(
    destinations,
    is_start=True,
    is_last=True,
    buffer=None,
)

# Write envelopes to temporary channel
temp_index = temp.first_message_index
for chunk in result.envelopes:
    write_result = await client.encrypt_write(chunk, temp.write_cap, temp_index)
    await client.start_resending_encrypted_message(
        read_cap=None, write_cap=temp.write_cap,
        message_box_index=None, reply_index=None,
        envelope_descriptor=write_result.envelope_descriptor,
        message_ciphertext=write_result.message_ciphertext,
        envelope_hash=write_result.envelope_hash,
    )
    temp_index = write_result.next_message_box_index

# Send copy command
await client.start_resending_copy_command(temp.write_cap)

How to handle multi-call buffer passing for large copy streams

When building a copy stream across multiple calls (because you have more data than fits in a single call, or data arrives incrementally), pass the buffer from each result to the next call:

var buffer []byte // nil on first call

// First batch of destinations
result1, err := client.CreateCourierEnvelopesFromMultiPayload(
    batch1Destinations,
    true,   // isStart (first call)
    false,  // isLast (more calls coming)
    buffer,
)
if err != nil {
    log.Fatal(err)
}
// Write result1.Envelopes to temp channel...
buffer = result1.Buffer // save for next call

// Persist buffer to disk for crash recovery
saveState(buffer)

// Second batch (final)
result2, err := client.CreateCourierEnvelopesFromMultiPayload(
    batch2Destinations,
    false,  // isStart (not the first call)
    true,   // isLast (final call)
    buffer,
)
if err != nil {
    log.Fatal(err)
}
// Write result2.Envelopes to temp channel...

// On crash recovery, reload buffer from disk and continue
// with isStart=false
let mut buffer: Option<Vec<u8>> = None; // None on first call

// First batch
let result1 = client.create_courier_envelopes_from_multi_payload(
    batch1_destinations,
    true,   // is_start
    false,  // is_last
    buffer,
).await?;
// Write result1.envelopes to temp channel...
buffer = result1.buffer; // save for next call

// Persist buffer to disk for crash recovery
save_state(&buffer);

// Second batch (final)
let result2 = client.create_courier_envelopes_from_multi_payload(
    batch2_destinations,
    false,  // is_start
    true,   // is_last
    buffer,
).await?;
// Write result2.envelopes to temp channel...
buffer = None  # None on first call

# First batch
result1 = await client.create_courier_envelopes_from_multi_payload(
    batch1_destinations,
    is_start=True,   # first call
    is_last=False,   # more calls coming
    buffer=buffer,
)
# Write result1.envelopes to temp channel...
buffer = result1.buffer  # save for next call

# Persist buffer to disk for crash recovery
save_state(buffer)

# Second batch (final)
result2 = await client.create_courier_envelopes_from_multi_payload(
    batch2_destinations,
    is_start=False,  # not the first call
    is_last=True,    # final call
    buffer=buffer,
)
# Write result2.envelopes to temp channel...

How to tombstone a range via copy stream

Use CreateCourierEnvelopesFromTombstoneRange to atomically tombstone boxes as part of a copy command. The courier performs the tombstoning, so it either all succeeds or none of it is visible.

tempWriteCap, _, tempFirstIndex, _ := client.NewKeypair(tempSeed)

// Create tombstone copy stream elements
envelopes, nextBuffer, nextDestIndex, err := client.CreateCourierEnvelopesFromTombstoneRange(
    destWriteCap,
    destStartIndex,
    10,     // tombstone 10 boxes
    true,   // isStart
    true,   // isLast
    nil,    // buffer
)
if err != nil {
    log.Fatal(err)
}

// Write to temporary channel
tempIndex := tempFirstIndex
for _, chunk := range envelopes {
    ciphertext, envDesc, envHash, nextIdx, err := client.EncryptWrite(
        chunk, tempWriteCap, tempIndex,
    )
    if err != nil {
        log.Fatal(err)
    }
    _, err = client.StartResendingEncryptedMessage(
        nil, tempWriteCap, nil, nil, envDesc, ciphertext, envHash,
    )
    if err != nil {
        log.Fatal(err)
    }
    tempIndex = nextIdx
}

// Send copy command
err = client.StartResendingCopyCommand(tempWriteCap)
let temp = client.new_keypair(&temp_seed).await?;

// Create tombstone copy stream elements
let result = client.create_courier_envelopes_from_tombstone_range(
    &dest_write_cap,
    &dest_start_index,
    10,     // tombstone 10 boxes
    true,   // is_start
    true,   // is_last
    None,   // buffer
).await?;

// Write to temporary channel
let mut temp_index = temp.first_message_index.clone();
for chunk in &result.envelopes {
    let write_result = client.encrypt_write(
        chunk, &temp.write_cap, &temp_index,
    ).await?;
    client.start_resending_encrypted_message(
        None, Some(&temp.write_cap), None, None,
        &write_result.envelope_descriptor,
        &write_result.message_ciphertext,
        &write_result.envelope_hash,
    ).await?;
    temp_index = write_result.next_message_box_index;
}

// Send copy command
client.start_resending_copy_command(&temp.write_cap, None, None).await?;
temp = await client.new_keypair(temp_seed)

# Create tombstone copy stream elements
result = await client.create_courier_envelopes_from_tombstone_range(
    dest_write_cap,
    dest_start_index,
    10,              # tombstone 10 boxes
    is_start=True,
    is_last=True,
    buffer=None,
)

# Write to temporary channel
temp_index = temp.first_message_index
for chunk in result.envelopes:
    write_result = await client.encrypt_write(chunk, temp.write_cap, temp_index)
    await client.start_resending_encrypted_message(
        read_cap=None, write_cap=temp.write_cap,
        message_box_index=None, reply_index=None,
        envelope_descriptor=write_result.envelope_descriptor,
        message_ciphertext=write_result.message_ciphertext,
        envelope_hash=write_result.envelope_hash,
    )
    temp_index = write_result.next_message_box_index

# Send copy command
await client.start_resending_copy_command(temp.write_cap)

How to cancel in-flight operations

Both StartResendingEncryptedMessage and StartResendingCopyCommand block until completion. You can cancel them individually, or stop everything at once by closing the thin client.

To cancel a specific operation, call the corresponding cancel method from another thread/task:

// Cancel an encrypted message operation
err := client.CancelResendingEncryptedMessage(envelopeHash)

// Cancel a copy command (needs blake2b-256 hash of the write cap)
writeCapBytes, _ := tempWriteCap.MarshalBinary()
writeCapHash := blake2b.Sum256(writeCapBytes)
err = client.CancelResendingCopyCommand(&writeCapHash)
// Cancel an encrypted message operation
client.cancel_resending_encrypted_message(&envelope_hash).await?;

// Cancel a copy command
use blake2::{Blake2b, Digest};
use digest::consts::U32;
let write_cap_hash: [u8; 32] = Blake2b::<U32>::digest(&temp_write_cap).into();
client.cancel_resending_copy_command(&write_cap_hash).await?;
# Cancel an encrypted message operation
await client.cancel_resending_encrypted_message(envelope_hash)

# Cancel a copy command
from hashlib import blake2b
write_cap_hash = blake2b(temp_write_cap, digest_size=32).digest()
await client.cancel_resending_copy_command(write_cap_hash)

To stop all in-flight operations at once, call Close() (Go), stop() (Rust), or stop() (Python). This shuts down the thin client entirely – all blocked callers receive an error, and the daemon stops all ARQ retransmission loops for this client. This is useful when your application is shutting down or when you want to abandon all pending work without cancelling each operation individually.


How to handle daemon disconnects and restarts

The thin client automatically reconnects when the daemon connection is lost. It uses an instance token to detect whether it reconnected to the same daemon or a new one:

  • Same instance token: The daemon still has its state. No action needed.

  • Different instance token: The daemon is a new process. The thin client automatically replays all in-flight StartResendingEncryptedMessage and StartResendingCopyCommand operations. Callers blocked on these methods are unaware of the disconnect.

Applications do not need to manage reconnection or replay. You can observe disconnect events to log or update UI state:

eventCh := client.EventSink()
defer client.StopEventSink(eventCh)

for ev := range eventCh {
    switch v := ev.(type) {
    case *thin.DaemonDisconnectedEvent:
        if v.IsGraceful {
            fmt.Println("Daemon shut down gracefully")
        } else {
            fmt.Printf("Daemon connection lost: %v\n", v.Err)
        }
        // No action needed -- thin client reconnects automatically
        // and replays in-flight requests if the daemon instance changed.
    case *thin.ConnectionStatusEvent:
        fmt.Printf("Connected: %v\n", v.IsConnected)
        // v.InstanceToken identifies the daemon process.
        // The thin client compares this internally on reconnect.
    }
}
let config = Config::new("thinclient.toml")?;
// Set disconnect callback during config
config.on_daemon_disconnected = Some(Box::new(|graceful, err_msg| {
    if graceful {
        println!("Daemon shut down gracefully");
    } else {
        println!("Daemon connection lost: {:?}", err_msg);
    }
    // No action needed -- thin client reconnects automatically
    // and replays in-flight requests if the daemon instance changed.
}));
let client = ThinClient::new(config).await?;
async def on_daemon_disconnected(event):
    if event.get("is_graceful"):
        print("Daemon shut down gracefully")
    else:
        print(f"Daemon connection lost: {event.get('error')}")
    # No action needed -- thin client reconnects automatically
    # and replays in-flight requests if the daemon instance changed.

async def on_connection_status(event):
    print(f"Connected: {event['is_connected']}")
    # event contains 'instance_token' identifying the daemon process.
    # The thin client compares this internally on reconnect.

config = Config(
    "thinclient.toml",
    on_daemon_disconnected=on_daemon_disconnected,
    on_connection_status=on_connection_status,
)
client = ThinClient(config)

If the thin client is disconnected when you cancel an operation, the cancel just removes it from in-flight tracking – it will not be replayed on reconnect:

// Safe to call while disconnected -- removes from tracking,
// no message sent to daemon since there is no connection.
err := client.CancelResendingEncryptedMessage(envelopeHash)
err = client.CancelResendingCopyCommand(&writeCapHash)
// Safe to call while disconnected -- removes from tracking,
// no message sent to daemon since there is no connection.
client.cancel_resending_encrypted_message(&envelope_hash).await?;
client.cancel_resending_copy_command(&write_cap_hash).await?;
# Safe to call while disconnected -- removes from tracking,
# no message sent to daemon since there is no connection.
await client.cancel_resending_encrypted_message(envelope_hash)
await client.cancel_resending_copy_command(write_cap_hash)

To terminate the thin client entirely (all blocked callers receive an error, daemon disconnects never kill the thin client):

err := client.Close()
client.stop().await;
client.stop()

9 -

Threat Model

The purpose and structure of this document

This threat model document is unique in the privacy technology landscape for its detailed treatment of realistic adversary capabilities. It is not a description of a superficial, theoretical system, but rather of complex, real-life software that is being interrogated and constantly re-designed to provide the best possible security. We examine it from the point of view of both theoretical design, networking choices and practical pitfalls.

And still, it is not and will likely never be comprehensive. Various attacks and countermeasure strategies will be added to this document in the future, as it keeps evolving. However, we feel that it already provides a valuable, systematic view of the challenges faced by mixnet technology.

There exists a rich body of academic work analyzing how one might disrupt the functioning of a Mixnet or circumvent its security and privacy guarantees. We have endeavored to compile these decades research and summarized these attacks in the table on page 3. The table on page 4 focuses on networking security threats that are specific to Katzenpost protocol choices.

We then delve into the countermeasures employed by Katzenpost and discuss their efficacy. A special care is taken to discuss the details of post-quantum cryptographic primitives that we have introduced in several places of the design.

Introducing the adversary

It is no longer controversial to say that in the modern world, we face incredibly powerful surveillance adversaries. These could be state, corporate or criminal actors, vying for our information to use as means of making profit, manipulating us and others, gaining leverage, strengthening their authority, or as means of persecution. In many contexts, we have little hope for non-technical solutions due to lack of sufficiently powerful pressure in favor of privacy.

And so in a quest for technical solutions, we need equally powerful tools. In the case of communication tools, the Internet’s bread and butter, we would like to allow users to interact and exchange information with reasonable expectation of both the content and metadata of their communication, and personal information such as a user’s social graph, being protected from such adversaries. Therefore, we consider an adversary capable of the following:

  • The adversary can see the connections of the entire global internet and is capable of intricate statistical analysis of gathered data.

  • The adversary can disable parts of the network.

  • The adversary can plant or take over some devices in the network to inject malicious code and manipulate the functioning of the network or to gain access to the information available to them. The takeover could happen by technical means or by exercising force outside of the network.

  • The adversary has very large (but not infinite) computational resources, and is capable of cryptanalysis on par with frontier research.

  • The adversary has access to a quantum computer, or will have access to a quantum computer in the near future.

  • The adversary can supplement collected data with rich context of already gathered data on all users from other sources.

If we hope for our work to be relevant in the modern world, we can no longer settle for weak threat models. That is the bar we set for ourselves at Katzenpost.

Katzenpost mixnet threat model summary

Firstly, assumptions about the user:

  1. The user acts reasonably and in good faith.

  2. The user obtains an authentic copy of the Katzenpost client and the mixnet client configuration file.

Secondly, assumptions about the user’s computer:

  1. The computer operates correctly and is not compromised by malware.

Thirdly, assumptions about the mixnet:

  1. The mixnet only provides internal services and does not have any "exit nodes" or anything that resembles a proxy service or VPN.

  2. All mixnet protocols are protocols which do not force interaction.

  3. All mixnet protocols are low bandwidth and latency tolerant.

Finally, assumptions about the world:
The three core protocols of Katzenpost are configured to use modern cryptographic primitives which are valid and considered impossible to break, for example:

  • PKI Signature Scheme using Edd25519-Sphincs+

  • NIKE Sphinx using X25519

  • PQ Noise with pqXX pattern using Xwing

What the user’s Gateway can achieve keeping in mind that typically a fair sized mixnet will have more than one gateway node:

  • A Gateway node learns when a given client is online.

  • A Gateway node learns the client’s IP address.

  • A Gateway node learns how many messages the client sends and receives.

  • A Gateway node does NOT learn the sent message destinations or the received message origins.

  • A Gateway node does NOT learn if a given sent or received message is a decoy or not.

  • A Gateway node can drop or corrupt any sent or received message.

  • A Gateway node can spam a user with invalid messages.

  • A Gateway node can duplicate old messages. However duplicate outbound messages will be dropped by the first hop as per Sphinx packet deduplication cache.

What a sufficiently global, passive adversary can achieve:

  • A GPA can learn who is using the mixnet and where their Gateway nodes are located.

What a local network attacker can achieve:

  • A local network can observe when a user is using Katzenpost.

  • A local network can block Katzenpost.

What a compromise of the user’s computer can achieve:
After an endpoint device is compromised, an attacker can impersonate that user, receiving and sending messages. The attacker does NOT learn the communication correspondent network locations.

What a Service Node can achieve:
A Service Node on the mix network does not know from whence it’s service request message came. Therefore in general, absent some clever attack, the Service Nodes learn nothing about the clients that interact with them.

What a contact can achieve:

  • A contact can spam a user with messages.

  • A contact can, to some extent, prove to a third-party that a message came from a user

  • A contact can retain messages from a user, forever.

What a random person on the Internet can achieve:
A random person can attempt to DoS the mix network or a specific service on the mixnet.

A summary of theoretical security concerns in a Mixnet

Mixnet attack type Attack description Necessary adversary capabilities
Intersection, Statistical Disclosure Attacks Over time, adversary can glean statistical information that makes the probability distribution of who Alice is communicating with non-uniform. Law of Large Numbers implies the anonymity set tends to the set of clients with identical probability in the long run to the actual recipient. The adversary must typically be able to see messages entering and leaving the network. This is customarily treated as a PGA, despite only requiring a view of the network’s perimeter. The adversary must be able to distinguish messages from dummy traffic, or observe when users are active.
n − 1 Attack The adversary causes the mix to contain only messages sent by the adversary, except one. In the context of continuous time mixing such as with the Poisson mix, this means that the adversary drops or delays other messages until the mix is empty before the target message enters the mix. The adversary sees the target message exit the mix to its next destination. The adversary must compromise routers which are upstream from a target mix node so as to be able to block incoming messages, send messages, as well as be able to tell when a target message passes through them.
Epistemic Attack The fact that a client is issued only a subset of the mix nodes’ directory and encryption keys can leak information to the adversary. The adversary has knowledge of the target client’s view of the network which distinguishes them among clients. This could happen via a zero day or a design flaw such as not implementing PIR for discovery.
Denial of Service Attack The adversary is able to disrupt the functioning of the service, often by overwhelming its resources. The adversary has sufficient network and computational resources to overwhelm the network.
Sybil Attack The adversary plants a large number of malicious nodes, and is therefore able to glean partial or complete information to follow a message through the mix and disrupt the network. The adversary has sufficient resources to take over the network, and the network’s design allows for the creation of a large number of malicious nodes.
Compulsion Attack The adversary compels enough honest node operators to disclose information to follow a message through the mix network . The adversary has the necessary force to compel a sufficient number of honest actors to do the adversary’s bidding.
Timing Attack An active adversary manipulates the timing of the packets passing through compromised routers, or passive adversary exploits timing information that is leaked despite padding. The passive attack could happen via a zero day or design flaw. The efficacy of the active attack needs to be analyzed with respect to the specific design.
Cryptographic Attacks The adversary is able to forge a signature, generate a second hash preimage, decrypt ciphertext or do other damage assumed to be prevented by the use of cryptography. The adversary can break the security of one or more cryptographic primitives through a cryptographic zero day or sufficient computational resources, or exploit a flaw in their implementation.
Endpoint Security Attacks The adversary breaches the security of a user’s device via an attack not directly related to the mixnet. The adversary is able to exploit a technical flaw in the user’s device or compel the user to grant him access.
Predecessor Attack The adversary compromises at least one mix node in each routing topology layer. Eventually a client will randomly select a bad route where every mix node in the route is compromised. The adversary must have the capability to operate or compromise mix nodes, at least one in each routing topology layer. See countermeasure section for more details.

Networking security concerns in Katzenpost

Mixnet attack type Attack description Necessary adversary capabilities
Tagging Attack The adversary exploits some kind of cryptographic malleability property of the Sphinx packet format in order to violate the privacy notions of the mix network. The adversary must be able to witness the Sphinx payload decryption to determine if it was tagged or not. This means compromising a Provider for forward packets and compromising a client’s endpoint device for SURB replies.
Replay Confirmation Attack If a Sphinx packet is able to be replayed then the adversary may send the packet many times concurrently in order to observe the traffic burst in another part of the network. The mix nodes maintain Sphinx replay caches in order to prevent replays; the attack is therefore only possible if there is a replay cache malfunction.
SURB Confirmation Attack If a client sends many SURBs1 to another entity on the network, that entity may choose to send out ALL the SURBs at once in order to observe the traffic burst in another part of the network. The adversary is a global passive observer of the network and participant in the network; additionally the adversary must be in possession of multiple SURBs created by another entity on the network.
ARQ Confirmation Attack The adversary’s goal is to find a specific ARQ2 client who is currently interacting on the network by causing targeted outages of entry Providers after the target service receives a protocol message. To start, half of the entry Providers are allowed to receive messages. If the adversary observes a retransmission then it confirms the client is in the group of entry Providers that we blocked messages to. The adversary continues the binary search and finds the client’s entry Provider in log(n) time. The adversary must have access to a target mixnet service so as to distinguish a message transmission versus a retransmission. The adversary must also be able block messages from going to specific mixnet nodes, in this example, entry Providers.

Attack Countermeasures

Here we describe the attack countermeasures currently used by the Katzenpost mix network software design.

Intersection Attacks

Attack description:

Intersection attacks, also known as long term statistical disclosure attacks have two basic categories:

  1. The Adversary learns to whom Alice sends messages.

  2. The Adversary learns who sends Alice messages.

Statistical disclosure attacks work to some extent on all anonymous communication networks. The Katzenpost client and Katzen messaging protocol is designed to provide partial defense against long-term intersection attacks as well as sufficient defence against short-term timing correlation attacks.

The simplest form of this attack assumes a global passive adversary who watches Alice’s interactions with the mix network. Whenever Alice sends a message, a set of potential recipients are noted by observing which clients receive a message shortly after Alice sends her message. After many hours, days or weeks of noting these sets of potential recipients, an intersection among these sets may reveal the set of recipients Alice sends messages to.

The classical mix network literature has described intersection attacks in terms of a mix network where a passive network observer can watch individual clients receive messages. This assumption can be otherwise stated that the adversary observes all the inputs and outputs of the mix network and thus receives a high granularity of statistical information.

countermeasure

Katzenpost and the Katzen messaging protocol are designed to provide partial defense against intersection attacks. Complete defense is not practical because user behavior is often repetitive and they cannot stay connected to the mixnet forever. Attack success depends largely on the adversary’s ability to predict user behavior. If user’s behavior is overly repetitive this may lead to the success of such attacks.

Although the Katzenpost continuous time mixing strategy provides defense against short term timing correlation attacks, additional defense mechanisms are required to defend against longer term attacks:

  1. async message queueing and retrieval at the network edge

  2. traffic padded message retrieval

  3. loop decoy traffic

  4. uniform traffic patterns (all sent messages result in a SURB reply)

The Katzenpost chat protocol known as Katzen, uses an additional network route to provide another indirection to protect the network location of clients. In other words, while Katzen clients connect to the mixnet using a randomly selected entry Provider, they retrieve messages from a different Provider mix node on the network; message retrieval is done by means of a Sphinx SURB, single use reply block which is sent to the messaging queue service so that a reply containing a message payload can be sent back to the client, anonymously. All sent messages result in a SURB reply being sent back to the client.

Katzenpost clients periodically send loop decoy messages; these Sphinx packets are sent to a randomly selected Provider whose echo service sends the client’s packet payload back to the client via the attached SURB. However, loop decoy messages are only distinguishable from normal messages to the client that receives them. Passive network observers will not be able to tell the difference. These decoy loops are uniformly distributed among all of the Providers (AKA service/exit mix nodes).

Whenever clients retrieve messages from their locally connected entry Provider, they do so using a traffic padded protocol that either sends them 0 or 1 message where both outcomes are indistinguishable from the perspective of a passive network observer.

n − 1 Attacks

attack description:

An n − 1 attack is a multi stage attack where the adversary observes a target message enter the mixnet and must perform the attack in order to follow the message to the next hop. The n − 1 attack is performed repeatedly for each hop in the route in order to discover the final destination.

Although the adversary could simply compromise each mix node in the route starting with the first hop, that is the compulsion attack category and is a distinct attack category from the n − 1 attack category. The n − 1 attack is performed by the adversary compromising upstream routers so that they have the capability of watching messages enter the target mix, blocking any of those messages if they choose to, and sending messages of their own into the target mix node. By using these capabilities the adversary is able to manipulate mix nodes so that they only contain the target message and messages sent by the adversary.

For a good introduction to n − 1 attacks, please see . In the context of continuous time mixing strategies like "Stop and Go" and Poisson , the n − 1 attack is performed by the adversary blocking or delaying (although delaying obviously wouldn’t work for Stop and Go) incoming messages ahead of time so that they are reasonably certain the mix is empty before the target message enters the mix.

When the target message enters the empty mix, it is artificially delayed by the mixing strategy and then routed to the next hop. The adversary gets to observe where the message is going for it’s next hop because they are reasonably sure that the message exiting the mix, although it is bitwise unlinkable because of the cryptographic transformation, it must be the same message.

countermeasure

: Katzenpost currently does not have any countermeasures in place for n − 1 attacks. See Future Countermeasures section below.

Epistemic Attack: route fingerprinting

attack description:

A route fingerprinting attack is when the adversary is able to identify a client by the specific route being used.

countermeasure:

Katzenpost doesn’t allow clients to have a partial view of the network. The directory authority system publishes the full network view to be cached by the edge nodes, Providers, so that clients can retrieve them.

Denial of Service

attack description:

Sending many packets into the mix network can cause the mix nodes to become overwhelmed and begin dropping packets. The logical conclusion to this scenario is that there is effectively a network outage until the adversary stops sending so much traffic.

countermeasure:

Rate limiting individual clients is the current countermeasure. However this only stops the DOS attack from being conducted by a single client entity. However the adversary could still DOS the network by using many clients to send packets.

Sybil Attack

attack description:

The adversary plants a large number of malicious nodes, and is therefore able to glean partial or complete information to follow a message through the mix network.

countermeasure:

We mitigate Sybil attacks by preventing mix nodes from automatically joining the network. A prerequisite for joining the network is to have all the directory authorities add the new mix node’s connection information and public cryptographic key material to their configuration. Please see the Future Countermeasures section below for a discussion of additional directory authority features including a reputation system.

Compulsion Attack

attack description:

The adversary compels enough honest node operators to disclose information to follow a message through the mix network.

countermeasure:

Our current countermeasure for the compulsion attack is frequent mix key rotation, every 20 minutes. See Future Countermeasures section below.

Timing Attacks

attack description:

An active adversary manipulates the timing of the packets passing through compromised routers, or passive adversary exploits timing information that is leaked despite padding.

Currently, there are no known timing attacks against any Katzenpost protocols. Timing correlation attacks are already covered in the intersection attack category. And although all mix network protocols leak statistical information no matter what countermeasures are used, we posit that this leaked statistical information isn’t really the same thing as traditional timing attacks against a cryptographic system. In fact, the mix network is actively preventing timing attacks injecting latency into the system.

countermeasure:

No known timing attacks and therefore no countermeasure.

Cryptographic Attacks

attack description:

There are no known cryptographic attacks against Katzenpost core protocols (sphinx, noise, dirauth). However we explore theoretical cryptographic attacks in the Cryptographic Protocols section below.

countermeasure:

All core Katzenpost protocols make use of hybrid post quantum cryptographic constructions which in theory protect against active quantum adversaries.

Endpoint Security Attacks

attack description:

The adversary breaches the security of a user’s device via an attack not directly related to the mixnet.

countermeasure:

There are no countermeasures provided by Katzenpost for endpoint security because it’s considered an orthogonal concern.

Tagging Attack

attack description:

The Sphinx cryptographic packet format allows for a one bit tagging attack under certain circumstances. The reason for allowing the design to have this security defect is to allow for the Single Use Reply Block. The Sphinx header is MAC’ed but the packet body is not. Instead, the body is encrypted with a wide-block cipher (an SPRP). This ensures that an expected verification block in the beginning of the plaintext can be used to verify the plaintext in the final decryption. If a bit in the payload ciphertext gets flipped then the payload decryption will yield garbled results and the expected verification block will not be present. Therefore in order to make use of this to perform a tagging attack, the adversary must have access to the result of the payload decryption as well as the ability to tag the packet some number of hops earlier in the route. We call this a one bit tagging attack because it yield one bit of information: Either the verification block was destroyed or not.

In Katzenpost there are two ways to use Sphinx to send a payload. Forwards packets and SURB reply packets. Both of these Sphinx packet types are susceptible to a one bit tagging attack:

tagging attack against forward Sphinx packets:

Clients send forwards Sphinx packets to mixnet services which reply via a SURB in the payload. Let’s say an adversary "tags" a forward Sphinx packet sent by Alice. The adversary would have to compromise or collude with the service Providers on the mixnet in order to witness the forward packet payload decryption failure which indicates the tag.

tagging attack against SURB replay Sphinx packets:

If an adversary "tags" a SURB reply which a mixnet service sends to a client, then only the client will be able to witness the packet payload decryption failure. The adversary would have to compromise the client’s endpoint device to witness this event (or to compromise the key materials allowing them to compute the failed payload decryption themselves).

countermeasure:

In the context of a forward Sphinx tagging attack on Katzenpost, the adversary must compromise or collude with the destination service Provider. If that’s the case then attack allows the adversary to learn which Provider node and service the packets was destined for. Although this is valuable information in the context of the current Katzen protocol, see the Future Countermeasures section below for a discussion of how we plan to mitigate intersection attacks in the future because it also carries over to much greater defense against this forward payload tagging attack.

countermeasure:

We could encode the last hop’s Sphinx routing command, inside the Sphinx payload instead of the header. This would provide short term plausible deniability in the sense that an adversary conducting a tagging attack would be destroying the routing information so that they cannot know if the packet was a decoy or not.

Replay Confirmation Attack

attack description:

If a Sphinx packet were allowed to be replayed then the adversary may send the packet many times concurrently in order to observe the traffic burst in another section of the network.

countermeasure:

Katzenpost mix nodes maintain a relay cache which prevents Sphinx packets from being replayed. This cache doesn’t grow forever since it’s only kept until the end of the epoch which are currently only a 20 minute duration.

SURB Confirmation Attack

attack description:

If a client sends many SURBs to another entity on the network, that entity may choose to send out ALL the SURBs at once in order to observe the traffic burst in another part of the network. This works as an entry node discovery attack.

Although currently, all Katzenpost protocols only send one SURB at a time, this attack still applies if the adversary accumulates enough SURBs to form a visible traffic burst within the mix network.

countermeasure:

No countermeasure. See Future Attack Countermeasure section below for the discussion of how to countermeasure this attack.

ARQ Confirmation Attack

attack description:

See above table entry for ARQ confirmation attack description.

countermeasure:

Currently, no countermeasure.

Predecessor Attack

attack description:

A bad route is defined as a route in which every node is compromised. The goal of such an attack is to link a given client with a specific destination or service on the destination node. This attack is also known as the Predecessor Attack and is detailed in with many variations for all the different types of anonymous communication networks. In the context of the Katzenpost mixnet, the Predecessor Attack is performed by the adversary compromising at least one node in each routing topology layer. Clients using the mixnet will eventually select a bad route.

countermeasure:

Fundamentally, we have two choices, either we have clients select a new route for each message sent or they select one route and use that for some time duration. In the former, every time a message is sent, the probability of selecting a bad route is increased. Whilst in the later, if a client selects a bad route they use it many times, but the probability of selecting a bad route is reduced.

Yet another countermeasure is to design the mixnet protocols such that they use a new destination for each message using some kind of private deterministic permutation achieving a uniform distribution of message amongst the destination mixnet nodes and their message slots. We have chosen this last countermeasure for Katzenpost and it will be detailed elsewhere in our literature.

Future Countermeasures

Intersection Attacks

The new Katzen protocol is sometimes referred to as scatter queue. Two communicating parties each exchange shared secrets which they use to determine a new "mailbox" for each message. To be clear, this new protocol is an improved revision of the previous Katzen protocol where each party chooses their own "mailbox" (queue Provider + queue ID); the difference here is that instead of the two parties exchanging mailbox locations they exchange seeds which are used to deterministically generate mailbox locations for each message.

This new protocol still uses all four previously mentioned mechanisms to achieve countermeasure against intersection attacks however the new "scatter queue" design drastically reduces the amount of metadata which can be collected by the operators of the mailbox Provider mix nodes. We think this is a huge improvement to the threat model. But it would be great if we could quantify the improvement using various anonymity metrics. Firstly, Shannon entropy seems applicable here because we can make statements like "compared to the old protocol, scatter queue increases the entropy on Providers where malicious adversaries are trying to correlate communicating party sets with messages arriving at specific mailboxes"; the new protocol makes this infeasible.

Therefore we can say that the new Katzen messaging protocol mitigates or partially mitigates intersection attacks by means of five mechanisms:

  1. async message queueing and retrieval at the network edge

  2. traffic padded message retrieval

  3. loop decoy traffic

  4. uniform traffic patterns (all sent messages result in a SURB reply)

  5. scatter queue

n − 1 Attacks

Here we will attempt to describe a partial countermeasure wherein clients receive statistical information from the network which is cryptographically signed by it’s authors. Client use this data to decide if there’s an ongoing n − 1 attack, if there is they disconnect from the network and try again later.

There are two sources of information about n − 1 attacks:

  1. mix loops

  2. client loops

Mix loops vs client loops

In theory mix loops can detect n − 1 attacks in the context of a continuous time mix. Such an attack means the adversary is dropping or delaying messages before they enter the mix. Therefore the mix originating loop decoy message can function as a sort of heartbeat protocol that allow the mix to detect n − 1 attacks. Obviously this mix loop decoy message might get dropped by the network for various reasons that have nothing to do with an n − 1 attack. The red green blue heartbeat mixnet paper (by george) suggests the countermeasure of the individual mixes halting their routing of messages temporarily to thwart the n − 1 attacks. This would work but it would also probably create unnecessary outages. Instead we want a system that let’s the client software decide whether or not there is an ongoing n − 1 attack. Clients can also detect such attacks with their own end to end loop decoy messages. However we want the mixes to publish a signed certificate containing their mix loop statistics. Client will then download these mix loop statistics from the providers and they will use those statistics along with their own client loop statistics to make decisions with regards to n − 1 network status.

TODO: add detailed description of client heuristics for deciding if there’s an n-1 attack

Core Cryptographic Protocols

Katzenpost consists of three cryptographic protocols:

  1. PKI/Dirauth

  2. PQ Noise

  3. Sphinx

Katzenpost is an overlay network meaning that we aren’t trying to replace IP (internet protocol). Overlay means we build protocol layers that sit on top of existing Internet protocols. Currently Katzenpost works over TCP/IP however in the future we plan to support QUIC/IP as an optional transport that can be selected.

Katzenpost uses a PQ Noise based protocol known as the Katzenpost wire protocol, which provides point to point transport security and authorization. The wire protocol enforces the mix network’s topology whereby the clients are only allowed to connect to gateway nodes, gateway nodes are only allowed to send packets to layer 1 mixes, and layer 1 mixes are only allowed to send packets to layer 2 mixes etc.

Clients use the wire protocol to talk to gateway nodes to whom they send Sphinx packets. These Sphinx packets are encapsulated within the encrypted PQ Noise messages and are therefore never exposed to passive network observers but if they were there wouldn’t in principle be any problem with that. This redundancy in security is often referred to as "defense in depth".

Besides within the mixnet itself, the wire protocol is also used to directly communicate with the directory authorities. Gateway nodes retrieve the latest PKI document from the directory authorities and cache the document for the epoch duration so that clients can download the cached copy. This is a notably different use case because within the mixnet we should have the goal of padding all the wire protocol commands to be the same size. Whereas when gateways nodes download the consensus they are likely receiving PKI documents which are perhaps many times bigger than our Sphinx packet size.

The PKI/Directory authority protocol stands apart from the rest because it’s the root of all authority within the mix network. The PKI provides the network participants with all the connection information and key materials they need to use the other two protocols, PQ Noise and Sphinx. It does so by publishing a PKI document every epoch (currently 20 minutes). This is necessary because the mixes destroy their old mix keys and create new mix keys for each new epoch thereby reducing the window for compulsion attacks to the epoch duration.

Both the PQ Noise based wire protocol AND our Sphinx protocols are considered to be transport protocols. However the dirauth as the 3rd cryptographic protocol here refers to two aspects:

  1. The client and mixnet interactions with the dirauth system; That is, the pki document itself it signed by a majority of the dirauth nodes AND the pki document contains the mix descriptor for each mix node in the network. The document also specifies the topology. Mix nodes and clients verify these cryptographic signatures.

  2. The dirauth’s crash fault consensus cryptographic protocol for publishing new PKI documents every epoch.

Katzenpost PKI / Directory Authority

The dirauth system has voting protocol rounds where each party exchanges votes with every other party.

The public key infrastructure (PKI) protocol for Katzenpost, also known as the Directory Authority or dirauth, is a decentralized system of nodes which vote for each epoch’s consensus document. If we used a BFT protocol instead then the dirauth system would fail when 1/3 + 1 nodes failed. Therefore we can say that our crash fault tolerant system is more robust because it will fail when 1/2 + 1 nodes fail.

The Katzenpost PKI is the security root of the entire system because all clients and network nodes will depend on the PKI to sign the consensus document for each epoch. Currently epoch duration is every 20 minutes. The consensus document is essentially a view of the network, it contains all the connection information and all the public cryptographic key materials and signatures. Each mix node signs it’s descriptor and uploads it to the dirauth nodes. Each dirauth node signs the consensus. When clients or nodes download the consensus document they are able to verify the dirauth node signatures on the document.

Currently we use a hybrid signature scheme consisting of the classical Ed25519 and the post quantum stateless hash based signature scheme known as Sphincs+ with the parameters: ‘sphincs-shake-256f‘

The Katzenpost Noise Protocol Layer

Early versions of Katzenpost used the Noise cryptographic protocol framework; however we used an HFS (hybrid forward secret) variation of XX handshake that used a post quantum KEM however it could not resist active quantum adversaries since the initial keys exchanged were classical ECDH public keys. Such constructions offer protections against current classical adversaries that record ciphertext transcripts in hopes of breaking them in the future with a cryptographically relevant quantum computer.

More recently, Katzenpost was made to use PQ Noise from the paper, entitled, Post Quantum Noise . The paper shows us that we can algebraically transform existing classical Noise handshake patterns into post quantum handshake patterns by replacing all usages of ECDH with KEM. In some of these transformations there’s additional network interactions implied.

Our current, hybrid KEM uses our security preserving KEM combiner and the NIKE to KEM adapter (ad hoc hashed el gamal construction). Our Noise protocol string is:

Noise_pqXX_Kyber768X25519_ChaChaPoly_BLAKE2b

Which means that our PQ Noise protocol uses the following cryptographic primitives:

  1. Hybrid KEM: KEM Combiner + NIKE to KEM adapter + X25519 + Kyber768

  2. MAC: Blake2b

  3. AEAD: ChaChaPoly

We use the PQ Noise handshake pattern known as pqXX
which is expressed in the PQ Noise pattern language like so:

-> e
<- ekem, s
-> skem, s
<- skem

Expressed as a sequence diagram, pqXX looks like this:

pqXX sequence
  1. Client sends there ephemeral public key (e).

  2. Server sends it’s static public key (s), encrypted with the KEM ciphertext (ekem) keyed to client’s public ephemeral key.

  3. Client sends their static public key (s) encapsulated via KEM ciphertext (skem) keyed to server’s static public key.

  4. Server sends a KEM ciphertext (skem) encapsulated using the client’s static public key.

future improvement, option 1:

Remove the "retrieve message" command which client’s use to poll for new messages. Instead the client - server Noise protocol should be designed such that clients periodically receive messages from the server without requesting or polling for them. If no message is present in the message queue on the server then the server will send the client a decoy message.

future improvement, option 2:

Replace the "retrieve message" command with a "send and retrieve" command whereby every time the client sends a message they also receive a message. As per usual, perhaps some of the messages send and received are decoy messages.

Classical Sphinx and Post Quantum Sphinx

The original Sphinx paper introduces the Sphinx nested encrypted packet format using a NIKE 3. NIKE Sphinx can be a hybrid post quantum construction simply by using a hybrid NIKE. Our Sphinx implementation also can optionally use a KEM 4 instead of a NIKE, however the trade-off is that the packet’s header will take up a lot of overhead because it must store a KEM ciphertext for each hop. Katzenpost has a completely configurable Sphinx geometry which allows for any KEM or NIKE to be used.

The Sphinx cryptographic packet format also uses these additional cryptographic primitives, the current Katzenpost selection is:

  • stream cipher: CTR-AES256

  • MAC: HMAC-SHA256

  • KDF: HKDF-SHA256

  • SPRP: AEZv5

In Katzenpost the dirauths select the Sphinx geometry, each dirauth must agree with the other dirauths. They publish the hash of the Sphinx Geometry in the PKI document so that the rest of the network entities can validate their Sphinx Geometry. At the time of writing the namenlos network still uses classical Sphinx with the following geometry:


PacketLength = 3082
NrHops = 5
HeaderLength = 476
RoutingInfoLength = 410
PerHopRoutingInfoLength = 82
SURBLength = 572
SphinxPlaintextHeaderLength = 2
PayloadTagLength = 32
ForwardPayloadLength = 2574
UserForwardPayloadLength = 2000
NextNodeHopLength = 65
SPRPKeyMaterialLength = 64
NIKEName = "x25519"
KEMName = ""

In the Katzenpost implementation of Sphinx, we MAC an unencrypted two byte region at the beginning of the Sphinx packet; This additional data region is to be used to match Sphinx version numbers.

Mixnet Attack Trees

Compromise Mix Node physical Access compromise human operator social engineering threat of violence blackmail large money bribe legal action police action military action compromise software remote code execution vulnerability compromise software upgrade pipeline malware USB stick mail interdiction evil maid attack

attacker’s goal is to compromise a mix node

The above attack tree consists of all OR nodes because each of the leaves are alternative ways to achieve the sub-goal expressed by their branch which in turn, each branch, e.g. physical access, compromise human operator, compromise software are each alternatives to the overall goal of compromising the mix node.

,,,, ,,

10 -

A high-level introduction to the Pigeonhole protocol for application developers

Understanding Pigeonhole

Pigeonhole is the storage layer of the Katzenpost mix network. It lets applications communicate anonymously using encrypted, append-only streams. Even the storage servers themselves see only randomly scattered, unlinkable queries with no consistent stream access; a passive network observer sees less still: Sphinx-encrypted traffic within the mix network, and fixed-throughput PQ Noise connections between couriers and replicas (and between replicas) whose rate is independent of application activity.

   client      ┌───── via mix network ─────┐    courier        replicas
                                                                   ┌────┐
   kpclientd ──▶  Sphinx round-trip (×3 mix layers)  ──▶  service  │  1 │
                                                         node      ├────┤
                                                         (courier) │  2 │
                                                            │      ├────┤
                                                            └─────▶│ ...│
                                                                   └────┘
                                              fixed-throughput     K = 2
                                              connections;          replicas
                                              cannot read box IDs   per box
                                                                   (consistent
                                                                    hashing)

This is the document to read first. Having understood the concepts here, proceed to the how-to guide for task-oriented recipes, and consult the API reference for the precise signatures.

For the privacy properties and the adversary they are designed to withstand, see the threat model and the Echomix paper; even the storage servers learn only that scattered, unlinkable queries reach them, never which boxes belong to one stream nor who reads them. For protocol details, see the Pigeonhole specification and sections 4-5 of the paper. Note that the published threat model is an evolving work in progress and does not yet incorporate the newer designs the paper introduces.

Terminology

A short glossary of the terms used throughout this document. Each is elaborated in its own section below.

  • Box. The unit of storage. A box is a fixed-size, encrypted, signed ciphertext addressed by a pseudorandom identifier. Once written, a box’s contents are immutable except by tombstoning.
  • Stream. An ordered, append-only sequence of boxes addressed by a pair of capabilities; the analogue of a single-writer log. The terms stream and channel are used interchangeably throughout these documents and the API: they denote one and the same thing.
  • Write cap. The capability that grants the right to sign and write messages to a stream and to derive the read cap from itself.
  • Read cap. The capability that grants the right to read and verify a stream’s contents. It cannot write or tombstone.
  • Tombstone. A signed empty payload that overwrites a box’s contents; the write cap holder uses it to retire prior messages.
  • BACAP. Blinding-And-Capability scheme. The Ed25519 key-blinding construction that ties write caps, read caps, and indices to unlinkable pseudorandom box identifiers.
  • MKEM. Multi-recipient KEM. The envelope encryption scheme that delivers each request to all of a box’s replicas without revealing the box ID to the courier.
  • Sphinx. The mixnet packet format used to route every request through three layers of mix nodes before it reaches the courier.
  • SURB. Single-Use Reply Block. A pre-built Sphinx return path that allows the courier to reply to a request without learning the client’s location.
  • Courier. A service running on a Katzenpost service node. The courier mediates between clients and replicas, maintaining a fixed-throughput stream of envelopes so that traffic patterns cannot be inferred from the wire.
  • Replica. A storage server. Each box is sharded across K=2 replicas via consistent hashing; replicas mirror writes to their shard peer to maintain redundancy.
  • Katzenpost epoch. The network’s wire-protocol epoch, lasting 20 minutes by default (the duration is a deployment parameter and a given network operator may configure it otherwise). It governs the directory authority consensus, mix key rotation, and Sphinx routing. It does not govern how long a box’s contents survive, and a reader need not concern themselves with it.
  • Replica epoch. A separate, much longer epoch lasting one week, used solely by the storage replicas. Replicas rotate and garbage-collect their storage keys on this weekly schedule; it is this epoch, not the 20-minute network epoch, that determines the lifetime of stored data.

Pigeonhole Streams

All communication happens through Pigeonhole streams (also called channels). A stream is an ordered, append-only sequence of encrypted messages, known as boxes. These boxes are stored in the storage servers using a hash based sharding scheme. Boxes have a fixed-size maximum payload and are padded; the exact size is set by the pigeonhole geometry, described below.

  • Append-only and immutable. Once a message is written to a box, it cannot be overwritten by another write – the replica rejects the second write with BoxAlreadyExists. New messages are appended at the next index. The only exception is tombstones: a tombstone unconditionally replaces the box contents with an empty signed payload, regardless of whether the box previously held data.
  • Single-writer, multi-reader. One writer, any number of readers. Nothing in the protocol inherently forbids multiple writers; the constraint arises because each index addresses a box that may be written only once (tombstones aside). Two writers therefore have no agreed answer to the question of which index each should write to: were they both to target the same index it would be a race, and whoever writes first wins while the other’s write is rejected with BoxAlreadyExists. Avoiding that requires out-of-band coordination, so in practice a stream has a single writer. Two-way communication is arranged as two streams, one in each direction.
  • Durable. Each message is replicated across multiple storage nodes. Currently, set to 2 storage nodes per shard.
  • Ephemeral. Storage is keyed to the replica epoch, which lasts one week (not to be confused with the 20-minute Katzenpost network epoch). Replicas retain the current and the preceding replica epoch and garbage-collect anything older, so a box’s contents survive for roughly one to two weeks; nothing written to a box outlives that window.
  • Per-replica-epoch storage. Capabilities are cryptographic credentials independent of any epoch schedule and continue to work indefinitely, but the data at any given box location does not carry across a replica epoch transition (the weekly schedule, not the 20-minute network epoch): at the start of a new replica epoch a read at that index returns BoxIDNotFound, even though the capability that addresses it is unchanged. Workflows that need data to outlive the replica epoch in which it was written must arrange to re-emit it (the copy command, described below, is the usual instrument for doing so atomically).
  • Unlinkable. Storage servers cannot tell which messages belong to the same stream.

Box size and the pigeonhole geometry

Every box carries a fixed-size payload, and a message is padded up to that size before storage so that all boxes on the wire are indistinguishable by length. A message larger than one box’s payload must be split across several boxes; one smaller is padded.

The exact size is not a hard-coded constant but a property of the pigeonhole geometry, a deployment parameter rather than something the application chooses. It is the operators of the mix network who set the geometries: they choose the network’s Sphinx geometry, and the pigeonhole geometry is derived from, and must be consistent with, it. A Pigeonhole request travels inside a Sphinx packet, so the usable box payload is whatever the deployed Sphinx geometry allows once the envelope and protocol overheads are subtracted. A network running a larger Sphinx packet has a correspondingly larger box payload; one running a smaller Sphinx geometry has a smaller one.

The kpclientd daemon’s configuration file must carry these same correct Sphinx and pigeonhole geometries, matching the network it is to connect to; a daemon configured with the wrong geometries cannot speak to that network. The thin client itself holds no such configuration. When a thin client connects to kpclientd, the daemon sends it the geometries over the local socket during the connection handshake. An application should therefore treat the box payload size as a value obtained at runtime from the daemon, not a fixed number to hard-code. See the API reference for how each binding exposes it.

Cryptographic Capabilities

Pigeonhole is a messaging system built from couriers and storage replicas. The capabilities described here come from BACAP, the Blinding-And-Capability scheme it relies upon. (In the Echomix paper, BACAP is the subject of section 4 and Pigeonhole of section 5.)

Access to a stream is controlled by two BACAP capabilities:

  • The write cap can write messages, create tombstones, and derive the read cap. Only the write cap holder can sign and encrypt messages, and storage servers verify these signatures and store the signature and ciphertext.
  • The read cap can read, verify signatures and decrypt messages. It cannot write or tombstone.

Creating a stream produces a write cap, a read cap, and a starting index. The writer keeps the write cap. To grant someone read access, share the read cap and index with them out-of-band. That is the fundamental operation: create a stream, share the read cap.

Multiple readers can hold the same read cap independently.

A capability, once shared, cannot be revoked. There is no mechanism to withdraw a read cap from someone who holds it: anyone in possession of it can read every box the stream has produced and will produce, for as long as that data survives. If a reader must lose access, the only remedy is to abandon the stream entirely, create a fresh one, and redistribute the new read cap to the readers who remain. Plan key distribution with this permanence in mind.

A first interaction: Alice writes, Bob reads

To anchor the abstractions above, here is the smallest useful interaction: one writer (Alice) and one reader (Bob).

  1. Alice creates a stream. She generates a 32-byte random seed and calls new_keypair (Go: NewKeypair). The thin client returns a write cap, a read cap, and the first message index.
  2. Alice shares the read cap with Bob. She hands him the read cap and the first message index by any means independent of the mixnet, for instance a QR code in a face-to-face meeting, or a separate signal channel. Anyone with the read cap can decrypt the stream; anyone without it sees only pseudorandom traffic.
  3. Alice writes a message. She calls encrypt_write with her write cap, the current index, and the plaintext, then sends the resulting envelope via start_resending_encrypted_message. The daemon dispatches the envelope through three mix layers, the courier receives it, and the courier writes the box to both of its replicas. Once the call returns Alice advances her local index.
  4. Bob reads the message. He calls encrypt_read with his copy of the read cap and his current index, dispatches the envelope, and waits for the daemon to return the decrypted plaintext.
  5. Alice writes again. She repeats step 3 with the next index. Bob reads in step 4 at his own pace, advancing his own index. The two indices are independent: Alice never blocks on Bob, and Bob can fall behind without losing messages until the replica-epoch garbage collection window (roughly one to two weeks) expires.

A two-way conversation is therefore two streams, one in each direction, because every stream has exactly one writer. The how-to guide shows the equivalent code in Go, Rust, and Python.

Division of labor

Your application talks to a local daemon (kpclientd) through a thin client library. The daemon handles all cryptography (BACAP encryption and decryption, MKEM envelope encryption and decryption, signature creation and verification, payload padding and unpadding), Sphinx packet construction, courier selection, and automatic retransmission (ARQ). Your application creates streams, tracks indexes, and persists state for crash recovery.

Most API calls are local crypto operations with no network traffic. Only StartResendingEncryptedMessage and StartResendingCopyCommand touch the network.

The Pigeonhole ARQ

The two sending methods deliver their envelopes through a stop-and-wait ARQ (Automatic Repeat reQuest) inside the daemon: one outstanding query per operation, retransmitted until it is answered or cancelled. All sends and retransmissions leave on the client’s Poisson traffic schedule, so retries are indistinguishable from any other client traffic.

How many mixnet round trips an operation costs depends on what it is:

  • A write costs one round trip. The courier’s ACK confirms it has taken custody of the envelope and will dispatch it to both of the box’s replicas; the operation completes on that ACK. If the box already exists, the write completes as an idempotent success by default; the ReturnBoxExists variant instead spends a second round trip to fetch the replica’s answer and reports BoxAlreadyExists as an error.

  • A read costs two phases: the courier first ACKs the query, then the daemon sends a fresh SURB to collect the payload once the courier has fetched it from a replica. The daemon decrypts the reply and hands the application plaintext. If the box has not been written yet, the replica answers BoxIDNotFound; by default the daemon keeps retrying on its Poisson schedule until the box appears, while the NoRetry variant reports the condition immediately (see Consistency and timing).

  • A copy command costs one ARQ exchange: the courier ACKs after it has executed the whole copy stream.

The daemon picks a courier when the operation starts and pins every retransmission and follow-up phase to it, because the courier holds per-envelope state for the exchange. An in-flight operation can be cancelled by envelope hash (CancelResendingEncryptedMessage) or by write-cap hash for copy commands (CancelResendingCopyCommand), which unblocks the waiting caller.

Consistency and timing

Pigeonhole offers no read-after-write ordering guarantee across participants, and an application that assumes one will misbehave.

  • Reading ahead of the writer. A reader who reads an index the writer has not yet written to receives BoxIDNotFound. This is not an error but the expected answer to “has anything been written here yet?”: it simply means “not yet.” The reader should wait and ask again rather than abandon the stream. The thin client exposes IsExpectedOutcome precisely so that an application can tell this benign outcome apart from a genuine failure; the how-to guide gives the polling pattern.

  • Replication lag. Each box is written to both of its K=2 replicas, but the two are not updated in the same instant. A read dispatched in the brief interval after a write reaches one replica but before its peer has caught up may transiently return BoxIDNotFound even though the write has in fact succeeded. The remedy is the same: retry. A handful of retries spaced over a few seconds is normally ample.

  • Read-delay randomisation. The courier maintains a fixed-throughput connection to the replicas, decoupled from the rate at which clients submit requests. A read therefore returns after a delay that bears no exploitable relation to when the data was written or requested. This randomised latency is a deliberate privacy property, not a defect: do not design protocols that depend on a read completing within a tight deadline.

The practical consequence is that every read should be written as a poll with bounded retry, treating BoxIDNotFound as “try again shortly” until either the data appears or an application-level timeout elapses.

Copy commands

Copy commands exist for when you need to atomically write more than one box to one or more streams that already exist and are already known to other entities. The writer creates a temporary stream, packs all the destination writes into it, then sends a single copy command to a courier. The courier reads the temporary stream, executes all the writes to their destination streams, then overwrites the temporary stream with tombstones. Either all the destination writes succeed or none of them are visible to readers.

Use cases: sending to a group, backfilling messages for an offline reader, atomically tombstoning old messages while writing new ones.

Tombstones

A tombstone is a Pigeonhole box which is signed with an empty ciphertext. Unlike normal writes, which are rejected if the box already exists, a tombstone unconditionally replaces the box contents. Only the write cap holder can create tombstones. Tombstones can be sent directly or bundled into a copy command for atomic deletion.

Protocol Composition

Many different protocols can be composed using these Pigeonhole streams. For example, in our Group Chat Design each group participant creates their own channel to write to. Each of the participants shares their own channel’s ReadCap with the other group members. Therefore each group member monitors and reads from all the other channels in the group. Each of them can simply write to their own channel in order to write a message to the group.

Fundamentally, protocols are composed by creating channels and sharing the read caps to those channels. When writing to a channel the entity doing the writing must keep track of the current index into the channel. This is the reason why channels are single writer, multi reader; because without coordination, multiple writers would be racing to write first before any of the others write to a specific index.

11 - Writing READMEs

A checklist for writing the README of any Katzenpost repository.

A README is the doorway into a repository for one named audience: a user who wants a client running, an operator, an application developer, or a contributor. Write it for that reader. Use this checklist for every Katzenpost repository.

Checklist

  1. Who is this for? Name the primary audience, and at most one secondary audience, before writing.
  2. One sentence. Say what this repository is and what it is for, in that audience’s words.
  3. Is it for you? Say what it does and does not do, and when to use something else.
  4. Fastest path to success. Installation, then the smallest working example, with commands that actually run.
  5. Map. List what is in the repository (crates, modules, binaries), with one line and a link each.
  6. Link out, don’t dump. Specifications, design notes and long how-tos live in docs/ or on this website; the README stays short.
  7. Status and compatibility. Versions, wire versions, what it interoperates with, and which test vectors prove it.
  8. Testing, contributing, licence. Briefly.
  9. Checked. Every command and claim is verified against the code; the README describes only this repository; no bragging. Changelog-style “new in” sections belong in a changelog or the release notes.

Where the rest goes

Diátaxis divides documentation into four kinds: tutorials, which teach by doing; how-to guides, which solve a stated task; reference, which describes the machinery; and explanation, which gives the reasons behind it. A README is none of these at length. It gives the reader one quick start and then links to each kind where it lives, in the repository’s docs/ or on this website.

Sources