---
name: "libressl-ECDH_compute_key"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-ECDH_compute_key"
---

# libressl-ECDH\_compute\_key(3)

Elliptic Curve Diffie-Hellman key exchange

## NAME

**ECDH\_compute\_key**, **ECDH\_size** – Elliptic Curve Diffie-Hellman key exchange

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/ec.h\>**

*int*\

**ECDH\_compute\_key**(*void \*out*, *size\_t outlen*, *const EC\_POINT \*public\_key*, *EC\_KEY \*ecdh*, *void \*(\*KDF)(const void \*in, size\_t inlen, void \*out, size\_t \*outlen)*);

*int*\

**ECDH\_size**(*const EC\_KEY \*ecdh*);

## DESCRIPTION

**ECDH\_compute\_key**() performs Elliptic Curve Diffie-Hellman key agreement. It combines the private key contained in *ecdh* with the other party's *public\_key*, takes the *x* component of the affine coordinates, and optionally applies the key derivation function *KDF*. It stores the resulting symmetric key in the buffer *out*, which is *outlen* bytes long. If *KDF* is NULL, *outlen* must be at least **ECDH\_size**(*ecdh*).

**ECDH\_size**() returns the number of bytes needed to store an affine coordinate of a point on the elliptic curve used by *ecdh*, which is one eighth of the degree of the finite field underlying that elliptic curve, rounded up to the next integer number.

## RETURN VALUES

**ECDH\_compute\_key**() returns the length of the computed key in bytes or -1 if an error occurs.

**ECDH\_size**() returns the number of bytes needed to store an affine coordinate.

## SEE ALSO

DH\_generate\_key(3), DH\_size(3), EC\_GROUP\_new\_by\_curve\_name(3), EC\_KEY\_new(3), EC\_POINT\_new(3), X25519(3)

## HISTORY

**ECDH\_compute\_key**() first appeared in OpenSSL 0.9.8 and has been available since OpenBSD 4.5.

**ECDH\_size**() first appeared in OpenBSD 6.1.
