ECDH_COMPUTE_KEY(3)
๐ ECDH_COMPUTE_KEY โ ok so hear me out, elliptic curve diffie-hellman
bestie. come sit. this is a Library Functions Manual page (that's the manual name, iykyk) and it's genuinely one of the cuter ones โ it's literally about two people agreeing on a secret without ever saying it out loud. main character energy fr. ๐
โจ NAME โจ
ECDH_compute_key, ECDH_size โ Elliptic Curve Diffie-Hellman key exchange ๐
๐ธ SYNOPSIS ๐ธ
#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);
Like, look at that second one. One line. So unbothered. ๐
๐ฆ DESCRIPTION ๐ฆ
๐ ECDH_compute_key()
okay so picture this: ECDH_compute_key() does the whole Elliptic Curve Diffie-Hellman key agreement dance. ๐
It takes the private key that's chillin' inside ecdh and combines it with the other party's public_key. Then it grabs the x component of the affine coordinates (yes, x specifically, not y, don't ask, it's a whole thing) and optionally runs the key derivation function KDF on top of it.
Then it drops the resulting symmetric key into the buffer out, which is outlen bytes long. ๐ฅ
โ ๏ธ tiny lil heads up: ifKDFisNULL, thenoutlenmust be at leastECDH_size(ecdh). no cap, it'll be a whole problem otherwise. ๐ญ
๐ฉต ECDH_size()
This one's the lowkey MVP. It returns the number of bytes you need to store an affine coordinate of a point on the elliptic curve that ecdh is using.
And how's that calculated? It's one eighth of the degree of the finite field underlying that elliptic curve, rounded up to the next integer. ๐งฎโจ math girlies rise.
๐ฅ RETURN VALUES ๐ฅ
ECDH_compute_key()โ returns the length of the computed key in bytes ๐ซ โฆor-1if something goes wrong (๐ it happens to the best of us).ECDH_size()โ returns the number of bytes needed to store an affine coordinate. periodt.
๐ SEE ALSO ๐
the whole friend group, slay:
๐ HISTORY ๐
ECDH_compute_key()first appeared in OpenSSL 0.9.8 and has been available since OpenBSD 4.5. a true veteran, we stan. ๐ซถECDH_size()first appeared in OpenBSD 6.1. the younger sibling that still ate. ๐
ok that's the page!! this one's from Debian, dated August 29, 2023, and it's ECDH_COMPUTE_KEY(3) if you need to find it again. go forth and agree on keys with your bestie, responsibly. ๐๐ง๐
๐ฆ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 ยท OpenSSL
- Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms