ECDH_COMPUTE_KEY(3)

๐Ÿ“ฆ version 4.1.0, in opensuse-leap 16.0

๐Ÿ’… 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: if KDF is NULL, then outlen must be at least ECDH_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 -1 if 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