C++ · Noise Keys

Noise Keys

#include <ucall/types.hpp> 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/cpp/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.

auto [server_keys, server_keys_status] = uc::noise_key_generate();
auto [client_keys, client_keys_status] = uc::noise_key_generate();

auto admit_client = [&client_keys](ucall_noise_key_t const& key) noexcept {
    return uc::noise_keys_equal(key, client_keys.public_key);
};
uc::interface_t const interfaces[] {{.address = "0.0.0.0:8546",
                                     .security = ucall_security_noise_xx_k,
                                     .noise_private_key = &server_keys.private_key,
                                     .peer_authorizer = admit_client}};
auto [server, server_status] = uc::server_t::make(interfaces);

auto admit_server = [&server_keys](ucall_noise_key_t const& key) noexcept {
    return uc::noise_keys_equal(key, server_keys.public_key);
};
auto [client, client_status] = uc::client_t::make(
    {.max_concurrent_connections = 1, .noise_private_key = &client_keys.private_key, .peer_authorizer = admit_server});

noise_key_generate draws from the operating system’s entropy and fails with status_code_t::io_k when it is refused. noise_key_derive 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 client_call_options_t::noise_peer_key. Noise KK has both sides know each other in advance: the interface admits the one key interface_t::noise_peer_key names, and the call presents its own key or the client’s. Both sides may also hold a 32-byte noise_pre_shared_key, and must match their key_exchange, which defaults to the post-quantum ucall_key_exchange_x25519_mlkem768_k. An http+noise:// URL implies Noise XX, and a handler reads the client’s authenticated key through request_t::peer.

API

Types

noise_keypair_tA static Curve25519 keypair, the private half kept secret.
types.hpp:368 ↗
struct noise_keypair_t

Fields

private_keyucall_noise_key_tThe secret scalar a server interface or a client presents.
public_keyucall_noise_key_tThe public key peers see during the handshake and compare in their authorizers.
peer_authorizer_tA peer authorizer the caller keeps for the server's or the client's lifetime; empty admits nobody under Noise XX, which needs one.
types.hpp:425 ↗
class peer_authorizer_t

Functions

noise_key_generateDraws a fresh keypair from the operating system's entropy.
types.hpp:378 ↗
expected<noise_keypair_t> noise_key_generate() noexcept;
noise_key_deriveDerives the public half of a stored private_key, answering both halves.
types.hpp:390 ↗
expected<noise_keypair_t> noise_key_derive(
    ucall_noise_key_t const & private_key) noexcept;
noise_keys_equalWhether two keys hold the same bytes, as an authorizer compares a peer with the one expected.
types.hpp:403 ↗
bool noise_keys_equal(
    ucall_noise_key_t const & first,
    ucall_noise_key_t const & second) noexcept;