Go · Noise Keys

Noise Keys

import "github.com/unum-cloud/ucall" 1.0.0-rc.1 · b7577426

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ucall/go/noise-keys.md' | claude -p "How would this fit my code?"

Interfaces and calls can run over the Noise protocol instead of plain TCP, authenticating both sides by 32-byte Curve25519 static keys.

serverPrivateKey, serverPublicKey, err := ucall.GenerateNoiseKeypair()
if err != nil {
	return err
}
clientPrivateKey, _, err := ucall.GenerateNoiseKeypair()
if err != nil {
	return err
}
clientPublicKey, err := ucall.DeriveNoisePublicKey(clientPrivateKey)
if err != nil {
	return err
}

sealed := ucall.NewInterface("0.0.0.0:8546")
sealed.Security, sealed.NoisePrivateKey = ucall.SecurityNoiseXX, &serverPrivateKey
sealed.PeerAuthorizer = func(key ucall.NoiseKey) bool { return key == clientPublicKey }
server, err := ucall.NewServer([]ucall.Interface{sealed}, nil)
if err != nil {
	return err
}

client, err := ucall.NewClient(&ucall.ClientOptions{
	Connections:     1,
	NoisePrivateKey: &clientPrivateKey,
	PeerAuthorizer:  func(key ucall.NoiseKey) bool { return key == serverPublicKey },
})

GenerateNoiseKeypair draws from the operating system’s entropy and fails with StatusIO when it is refused. DeriveNoisePublicKey recovers the public half of a stored private key, which peers compare in their authorizers. Under Noise XX both sides learn each other’s key during the handshake, so both need an authorizer; Noise IK has the client name the server’s key in advance through ClientCallOptions.NoisePeerKey. Noise KK has both sides know each other in advance: the interface admits the one key Interface.NoisePeerKey names, and the call presents ClientCallOptions.NoisePrivateKey or the client’s own key. Both sides may also hold a 32-byte NoisePreSharedKey, and must match their KeyExchange, whose zero value is the post-quantum KeyExchangeX25519MLKEM768. An http+noise:// URL implies Noise XX, and a handler reads the client’s authenticated key through Request.Peer.

API

Types

PeerAuthorizerPeerAuthorizer decides whether a peer presenting an authenticated static key may proceed.
server.go:640 ↗
type PeerAuthorizer func(key NoiseKey) bool

It runs on the polling goroutine completing the handshake and must not panic.

SecuritySecurity is the transport an interface or a call runs over.
server.go:560 ↗
type Security int32

Values

SecurityNoneSecurityNone is plain TCP.
SecurityNoiseXXSecurityNoiseXX authenticates both sides during the handshake.
SecurityNoiseIKSecurityNoiseIK has the client know the server's key in advance.
SecurityNoiseKKSecurityNoiseKK has both sides know each other's key in advance.
EnumKeyExchangeKeyExchange is the key exchange of a Noise handshake, which both sides must match.2
types.go:575 ↗
type KeyExchange int32

Values

KeyExchangeX25519MLKEM768KeyExchangeX25519MLKEM768 runs X25519 and ML-KEM-768 together: recorded traffic stays private unless both break.
KeyExchangeX25519KeyExchangeX25519 runs X25519 alone, for standard Noise peers: recorded traffic falls to a quantum computer.
KeyExchangeFromNameKeyExchangeFromName reads a key exchange back from its stable name.
types.go:592 ↗
func KeyExchangeFromName(name string) (KeyExchange, error)
String
types.go:587 ↗
func (exchange KeyExchange) String() string
TypeNoiseKeyNoiseKey is a 32-byte Curve25519 key.1
types.go:605 ↗
type NoiseKey [32]byte
DeriveNoisePublicKeyDeriveNoisePublicKey recovers the public half of a stored private key, which peers compare in their authorizers.
types.go:624 ↗
func DeriveNoisePublicKey(privateKey NoiseKey) (NoiseKey, error)

Functions

GenerateNoiseKeypairGenerateNoiseKeypair draws a fresh private key and its public key from the operating system's entropy.
ucall.go:609 ↗
func GenerateNoiseKeypair() (NoiseKey, NoiseKey, error)