---
name: "nng_tls_config_psk"
section: "3tls"
platform: "linux"
package: "libnng-dev"
version: "1.10.1-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/nng_tls_config_psk"
---

# nng\_tls\_config\_psk(3tls)

configure pre-shared keys (PSK) for TLS

## NAME

nng\_tls\_config\_psk - configure pre-shared keys (PSK) for TLS

## SYNOPSIS

```
#include <nng/nng.h>
#include <nng/supplemental/tls/tls.h>
int nng_tls_config_psk(nng_tls_config *cfg, const char *identity,
    const uint8_t *key, size_t key_len);
```

## DESCRIPTION

The `nng_tls_config_psk()` function configures a pre-shared secret to use for TLS connections.

Client mode configurations can call this just once, to set their own *identity* and a single *key* of *key\_len* bytes in size.

Server mode configurations can call this multiple times, and servers will look up the appropriate key to use when a client connects.

The *identity* may be thought of at some level as a public value like a user name, and the *key* of course is the confidential material used to establish keys. Both parties my have the same values for *identity*, *key*, and *key\_len*.

Implementations may impose limits on whether this functionality is supported, as well as limitations on the length of keys or identities, but generally key lengths of up to 32 bytes as well as identities of up to 64 bytes will be supported wherever PSK configurations are present.

Note that while some implementations may allow arbitrary byte patterns in the identity, this implementation does not support embedded zero bytes, and assumes that the values are printable (for logging).

## RETURN VALUES

This function returns 0 on success, and non-zero otherwise.

## ERRORS

`NNG_ENOMEM`

Insufficient memory is available.

`NNG_EBUSY`

The configuration *cfg* is already in use, and cannot be modified.

`NNG_EINVAL`

Invalid parameters were supplied.

## SEE ALSO

[nng\_strerror(3)](/nng_strerror/3.md), [nng\_tls\_config\_alloc(3tls)](/nng_tls_config_alloc/3tls.md), [nng(7)](/nng/7.md)
