# Encrypted transport

> Pearl nodes speak only BIP-324: an ElligatorSwift key exchange, HKDF keys salted with pearl_v2_shared_secret and the magic, ChaCha20-Poly1305 packets.

Source: https://pearlcodex.com/technical/networking/encrypted-transport/ · Last updated: 2026-10-20 · Checked against Pearl's source code at v1.5.5

When two Pearl nodes talk, nobody in between can read what they say. Every connection is encrypted with [BIP-324](https://pearlcodex.com/glossary/#bip-324), a standard written for Bitcoin, and Pearl made it the only option. There’s no plaintext mode to fall back to and no setting to turn encryption off.

The idea is the same one that protects web pages: the two sides agree on a secret key without ever sending it, then encrypt everything with it. What’s special about BIP-324 is that even the very first bytes look random, so a watcher can’t tell the conversation is Pearl at all.

## Try it

Encryption keys here are derived with hash functions. Type a message and watch a hash change completely when one character changes: that’s the property that keeps derived keys unguessable.

_Interactive: Hash playground. Try it on the page: <https://pearlcodex.com/technical/networking/encrypted-transport/>_

## How does the handshake work?

In four steps, all from BIP-324, with Pearl’s salt in step 3:

1. **Swap disguised public keys**

   Each node makes a fresh key pair on secp256k1, Bitcoin’s curve, and sends its public key as 64 bytes encoded with [ElligatorSwift](https://pearlcodex.com/glossary/#elligatorswift). Unlike a normal public key, those 64 bytes are indistinguishable from random noise. Each side may add up to 4,095 bytes of random garbage after its key, so even the length of the opening says nothing.

2. **Compute a shared secret**

   Each node combines its own private key with the other’s public key (elliptic-curve Diffie-Hellman). Both get the same secret; nobody watching can.

3. **Expand it into keys**

   [HKDF](https://pearlcodex.com/glossary/#hkdf) with SHA-256 turns the secret into separate keys for each direction, plus a session ID and the “garbage terminators” that mark where the garbage ends. Pearl’s salt for this step is `pearl_v2_shared_secret` followed by the network’s magic bytes.

4. **Confirm and talk**

   Each side sends its garbage terminator and an encrypted version packet. From then on, every message, starting with the ordinary `version` and `verack`, travels encrypted.

## What is Pearl’s salt?

For mainnet, 26 bytes: the ASCII text `pearl_v2_shared_secret`, then the magic `0x50524C4D` written little-endian.

**BIP-324 HKDF salt, mainnet · 26 bytes**

```
706561726c5f76325f7368617265645f736563726574 4d4c5250
```

| Field                    | Bytes        | Value                  |
| ------------------------ | ------------ | ---------------------- |
| "pearl_v2_shared_secret" | 22, offset 0 | 22 bytes of ASCII text |
| Magic, little-endian     | 4, offset 22 | 0x50524C4D, "PRLM"     |

_Bitcoin's salt is bitcoin_v2_shared_secret followed by its own magic, f9 be b4 d9._

That small change does two jobs. A Pearl node and a Bitcoin node derive different keys and can’t talk by accident. And because the magic is in the salt, Pearl’s own networks are kept apart the same way: a testnet node’s salt ends `31 4c 52 50`, so its keys never match a mainnet node’s. More on that is on [magic bytes and ports](https://pearlcodex.com/technical/networking/magic-bytes-and-ports/).

## What does an encrypted message look like?

From the outside, a stream of random bytes. Inside, each message is a packet:

| Field       | Size   | Description                                                                                                      |
| ----------- | ------ | ---------------------------------------------------------------------------------------------------------------- |
| Length      | 3      | How long the contents are, encrypted with its own ChaCha20 key so even message sizes aren’t sent in the clear.   |
| Header byte | 1      | A flag byte, encrypted with the contents (it can mark a packet as decoy, to be ignored).                         |
| Contents    | varies | The message: a one-byte message ID (or 00 and a 12-byte name) and its payload, encrypted with ChaCha20-Poly1305. |
| Tag         | 16     | Poly1305 authentication tag. Any tampering makes it fail and the connection drop.                                |

Both ciphers roll their keys forward every 224 messages, so a key stolen later can’t decrypt older traffic in that session. The message IDs and payloads inside are described on [messages](https://pearlcodex.com/technical/networking/messages/).

## Why does Pearl insist on it?

Pearl’s code doesn’t give a reason; it simply has no other path. Both incoming and outgoing connections start with the BIP-324 handshake, every message is read and written in the encrypted form, and every node advertises the `NODE_P2P_V2` service bit by default.

The effects are easy to see, though:

- **No magic bytes on the wire.** Nothing in the stream says “Pearl”. The magic only appears in the salt and in block files on disk.
- **Privacy from passive watchers.** An internet provider can’t read which transactions or blocks your node relays.
- **Tamper-evidence.** Any byte changed in transit breaks the authentication tag.
- **One protocol.** No downgrade to plaintext for an attacker to force.

> **Warning: What it doesn't hide**
>
> An eavesdropper still sees IP addresses, when packets flow and roughly how big they are. A Pearl block, with its \~60 KB certificate, is a fairly distinctive burst. And BIP-324 is _unauthenticated_ encryption: it doesn’t prove who is on the other end, so an active attacker in the middle of the connection could still pose as each side to the other. The session ID exists so two operators can compare it out of band if they need that assurance.

**Make a guess:** Pearl’s encryption keys depend on the network magic. If a future Pearl testnet3 picks magic 0x50524C33, can its nodes accidentally join mainnet?

**Answer:** No. Their salt would end 33 4c 52 50, so their keys would never match mainnet’s.

The key exchange itself would work, but each side would derive different keys from its own salt. Neither would find the garbage terminator it expects or be able to decrypt the other’s first packet, so the connection would drop before any block or transaction was exchanged.

> **Pearl vs Bitcoin**
>
> Pearl’s transport is BIP-324 as Bitcoin specifies it: ElligatorSwift keys, HKDF-SHA256, ChaCha20-Poly1305 packets, short message IDs, garbage and decoys. Two things differ. The salt is `pearl_v2_shared_secret` plus Pearl’s magic instead of `bitcoin_v2_shared_secret` plus Bitcoin’s. And Bitcoin Core falls back to the old unencrypted v1 protocol when a peer doesn’t support BIP-324; Pearl has no v1 at all.

**Code: deriving the keys**

From [`transport.go`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/v2transport/transport.go#L186-L275):

`node/v2transport/transport.go`

```go
salt := []byte("pearl_v2_shared_secret")
var magic [4]byte
binary.LittleEndian.PutUint32(magic[:], uint32(net))
salt = append(salt, magic[:]...)

prk := hkdf.Extract(sha256.New, ecdhSecret, salt)

sessionReader := hkdf.Expand(sha256.New, prk, []byte("session_id"))
// … then "initiator_L", "initiator_P", "responder_L", "responder_P"
// and "garbage_terminators", each its own HKDF-Expand.
```

Inbound connections answer the handshake and outbound ones start it, in [`peer.go`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/peer/peer.go#L2231-L2296); in both cases the v2 handshake runs before the `version` message.

## In short

- Every Pearl peer connection is encrypted with BIP-324, the same scheme Bitcoin Core offers. Pearl has no unencrypted fallback.
- The two nodes swap 64-byte public keys encoded with ElligatorSwift so they look like random bytes, derive a shared secret, and expand it into keys with HKDF-SHA256.
- Pearl’s HKDF salt is the text pearl_v2_shared_secret followed by the network’s magic bytes, so mainnet and testnet nodes can’t decrypt each other.
- Each message then travels as a ChaCha20-encrypted 3-byte length, ChaCha20-Poly1305-encrypted contents and a 16-byte authentication tag; keys roll over every 224 messages.
- An eavesdropper sees IP addresses, timing and sizes, but no magic bytes, no message names and no contents. Like all of BIP-324, it doesn’t by itself stop an active man in the middle.

## Read the code

- [Inbound and outbound connections both run the v2 handshake](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/peer/peer.go#L2231-L2296) `node/peer/peer.go:2231-2296`
- [Messages are only read in v2 form](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/peer/peer.go#L1090-L1093) `node/peer/peer.go:1090-1093`
- [HKDF with salt pearl_v2_shared_secret ‖ magic](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/v2transport/transport.go#L186-L275) `node/v2transport/transport.go:186-275`
- [Garbage up to 4,095 bytes, 3-byte length, 16-byte tag](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/v2transport/transport.go#L38-L61) `node/v2transport/transport.go:38-61`
- [Rekey every 224 messages](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/v2transport/chacha.go#L13-L15) `node/v2transport/chacha.go:13-15`

## Sources

### Pearl source

- [Pearl source code at v1.5.5](https://github.com/pearl-research-labs/pearl/tree/v1.5.5)

### Bitcoin standards

- [BIP-324: Version 2 P2P Encrypted Transport Protocol](https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki)

### Other

- [RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF)](https://www.rfc-editor.org/rfc/rfc5869)
- [RFC 8439: ChaCha20 and Poly1305](https://www.rfc-editor.org/rfc/rfc8439)
