gnutls\_hpke\_encap(3) gnutls gnutls\_hpke\_encap(3)

# [NAME](#NAME)

gnutls\_hpke\_encap - API function

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;gnutls/hpke.h&gt;**

**int gnutls\_hpke\_encap(gnutls\_hpke\_context\_t ctx, const gnutls\_datum\_t * info, gnutls\_datum\_t * enc, const gnutls\_pubkey\_t receiver\_pubkey, const gnutls\_privkey\_t sender\_privkey, const gnutls\_datum\_t * psk, const gnutls\_datum\_t * psk\_id);**

# [ARGUMENTS](#ARGUMENTS)

[gnutls\_hpke\_context\_t ctx](#gnutls_hpke_context_t)

The HPKE context to use for encapsulation.

[const gnutls\_datum\_t * info](#const)

The application-specific information to be included in the key schedule (optional).

[gnutls\_datum\_t * enc](#gnutls_datum_t)

A pointer to a gnutls\_datum\_t structure where the encapsulated key will be stored.

[const gnutls\_pubkey\_t receiver\_pubkey](#const~2)

The receiver's public key to use for encapsulation.

[const gnutls\_privkey\_t sender\_privkey](#const~3)

The sender's private key needed for AuthEncap operation (optional).

[const gnutls\_datum\_t * psk](#const~4)

The pre-shared key (optional).

[const gnutls\_datum\_t * psk\_id](#const~5)

The pre-shared key identifier (optional).

# [DESCRIPTION](#DESCRIPTION)

This function performs the encapsulation operation of HPKE. It generates an encapsulated key ( *enc* ) that can be sent to the receiver, who can then use it to derive the shared secret.

The function checks that the context is properly initialized and that the provided parameters are valid. It also checks that the context is in the correct role (**GNUTLS\_HPKE\_ROLE\_SENDER**) for encapsulation.

This function must be used once per HPKE context and before any calls to **gnutls\_hpke\_seal()**.

The function will allocate memory for *enc* , and the caller is responsible for freeing this memory using **gnutls\_free()** when it is no longer needed.

*receiver\_pubkey* must be a valid public key that is compatible with the KEM algorithm specified in the HPKE context.

For **GNUTLS\_HPKE\_MODE\_AUTH** or **GNUTLS\_HPKE\_MODE\_AUTH\_PSK**,  
*sender\_privkey* must be a valid private key that can be used for authentication. For **GNUTLS\_HPKE\_MODE\_PSK** or **GNUTLS\_HPKE\_MODE\_AUTH\_PSK**, a pre-shared key ( *psk* ) and its identifier ( *psk\_id* ) must be supplied.

# [RETURNS](#RETURNS)

0 on success, or a negative error code on failure

# [SINCE](#SINCE)

3.8.13

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;bugs@gnutls.org&gt;.  
Home page: https://www.gnutls.org

# [COPYRIGHT](#COPYRIGHT)

Copyright © 2001-2023 Free Software Foundation, Inc., and others.  
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved.

# [SEE ALSO](#SEE_ALSO)

The full documentation for **gnutls** is maintained as a Texinfo manual. If the /usr/share/doc/gnutls/ directory does not contain the HTML form visit

[https://www.gnutls.org/manual/](https://www.gnutls.org/manual/)

3.8.13 gnutls

---

Document: gnutls_hpke_encap(3) from gnutls 3.8.13-r1 (Chainguard OS)
Source: https://gitlab.com/gnutls/gnutls
