
USTP-Secure — Updated!
Secure (with AEAD) version of USTP, called USTP-Secure (ustps://)
USTP
USTP means UDP Speedy Transmission Protocol.
USTP keeps the same authenticated transport model, but the project name is now simply USTP again.
By default, USTP uses AEAD for DATA.
It also supports an optional negotiated cleartext + HMAC mode for DATA, where payload bytes are visible on the wire but tampering is detected and rejected.
USTP now supports an optional congestion controller called USTP Congestion. It is still UDP-first, but it can optionally slow down and ramp back up when the path starts showing congestion signals.
Status: Beta
USTP is no longer just a proof of concept. It is currently in the Beta phase.
USTP can be used for many kinds of applications and transports.
This repository, however, is focused specifically on streaming over USTP.
News
02/08/2026:USTP-Secureis now back toUSTP.USTP-Securewas an old project name and no longer a good fit for the project.- The shorter
USTPname is now preferred again. - The full name is now
UDP Speedy Transmission Protocol, withoutSecurein the title.
2026-07-18: USTP/2 Beta was removed from the current tree.- Real-world behavior was less stable than USTP/1.1 under loss.
- The current stable transport path is USTP/1.1 only.
- The transport handshake now uses plaintext ASCII records.
Build note
- Built with
CodexusingGPT-5.4 (Low). - Verified without freezing at
--loss 33. - Test path:
Brazil -> Canadawith about140msRTT.
Security model
- Transport remains UDP (no TCP tunnel)
- AEAD ciphers:
chacha20=CHACHA20_POLY1305aes-256-gcm=AES_256_GCMaes-128-gcm=AES_128_GCM
- Default AEAD cipher:
chacha20 - Default
DATAprotection mode is AEAD. - Optional
DATAprotection mode is cleartext + per-packet HMAC. - In cleartext mode, payload bytes are not encrypted, but modifications are detected and invalid packets are discarded.
- Transport control packets (
HELLO,ACK,RETRANSMIT_REQUEST,CLOSE) stay plaintext on purpose. - Control packets are serialized as ASCII transport records.
ACKandNACK/RETRANSMIT_REQUESTremain plaintext, but are authenticated with a per-session HMAC tag.- This prevents off-path forged ACK/NACK control packets from forcing ACK attacks or retransmission DoS after the secure session is established.
DATApackets use a binary frame format namedUPACK(UPAKon the wire).- No static PSK is used.
- Each client performs an X25519 key exchange when it joins.
- Each client gets a separate AEAD session key.
- Servers support multiple clients.
- The server validates the client with a challenge round-trip on the source
IP:port. - If
--cipheris set on the server, the server uses that exact cipher. - If
--cipheris omitted or set toauto, the server uses the cipher requested by the client. - Clients reject unexpected cipher negotiation.
DATAprotection mode is negotiated separately from cipher choice:- server:
--cleartext auto|on|off - client:
--cleartext on|off - server default:
auto - client default:
off
- server:
- With server
auto, the server follows the client request. - With server
on, the server forces cleartext + HMAC. - With server
off, the server forces AEAD. - TOFU (Trust On First Use) is enabled on the client to detect unexpected server key changes after the first connection.
- The server keeps a persistent X25519 host key in
~/.ustps_host_keyby default so TOFU remains stable across reconnects and restarts. - A normal server restart does not change the host key.
- Use
--regen-keyon the server only when you intentionally want to rotate that host key.
Packet magic values
ACK:,NACK:,HELLO:, andCLOSE:are the plaintext control record prefixes.USS1meansUDP Speedy Secure, version 1.USC1meansUDP Speedy Clear, version 1.UPAKis the binaryUPACKDATA frame marker.- In USTP, plaintext control is human-readable ASCII such as
ACK: 10,NACK: 42,HELLO: ..., andCLOSE:. - In USTP,
UPAKidentifies binary DATA packets after decryption. - In USTP,
USS1is the outer secure AEAD envelope format. - In USTP,
USC1is the outer cleartext+HMACDATAenvelope format. - So, on the wire you normally see:
USS1...for AEAD-protectedDATAUSC1...for cleartext+HMACDATA- readable control lines for transport control
Transport model
- USTP can run with optional
USTP Congestion, negotiated during the handshake. - Packets carry both a transport
seqand an application-facingstream_pos. seqis used for ACK, loss detection, retransmission, andRTTsampling.stream_postells the application where the payload belongs in the logical byte stream.- In the current implementation,
seqis a 32-bit counter that starts at1for each fresh session. - In the current implementation,
stream_posis a 64-bit byte counter that starts at0for each fresh logical stream. - The receiver accepts packets immediately instead of blocking delivery behind one missing packet.
Handshake and session model
- The client starts with a plaintext transport
HELLOcarrying its X25519 public key, requested cipher, requested congestion-control mode (onoroff), and requestedDATAprotection mode (cleartext on|off). - The server does not send media immediately. It first sends a plaintext challenge containing:
- a random retry token
- a generated Base64
session_id - the selected cipher
- the negotiated congestion-control mode
- the negotiated
DATAprotection mode - the server public key
- The client must answer with that exact same token and session metadata.
- Only after that token round-trip succeeds does the server create the session and begin sending
DATA. - After validation, the session is bound to the source
IP:portthat completed the challenge. session_idis still used as a session label, but it is not accepted from a differentIP:port.
Retry Token
- USTP uses a plaintext retry-token step before any encrypted media session is accepted.
- Flow:
- client sends
HELLO - server replies with
USTPS-CHALLENGE1carryingtoken,session_id, selected cipher, negotiated congestion-control mode, negotiatedDATAprotection mode, and server public key - client echoes that token back in
USTPS-CHALLENGE-REPLY1 - only then does the server create the session and send
USTPS-SESSION1
- client sends
- Purpose:
- prove that the sender at that source
IP:portcan actually receive packets there - avoid sending encrypted media immediately to an unvalidated source address
- bind the final session creation to the endpoint that completed the round-trip
- prove that the sender at that source
- The retry token is not the session key.
- It is only a reachability proof and handshake gate before the real USTP session is created.
- It is also not used as a nonce, not used as an ACK/NACK MAC key by itself, and not reused as packet payload state.
Historical protocol identifiers
- The project name is now
USTP, but several on-wire ASCII identifiers still use the historicalUSTPS-*prefix. - This is intentional for backward compatibility with existing implementations, captures, logs, and older deployments.
- In the current implementation, the following control identifiers remain on the wire:
USTPS-KEX1USTPS-CHALLENGE1USTPS-CHALLENGE-REPLY1USTPS-SESSION1USTPS-RESUME1USTPS-RTT1
- The project/documentation name changed back to
USTP, but those historical wire identifiers were not renamed in the protocol bytes.