X25519(7ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’œ X25519 β€” the glow-up era (OpenSSL, section 7ossl)

okay bestie, gather round, because this one is actually iconic. We're talking X25519 and X448 β€” the two cool kids of the EVP_PKEY world β€” living their best life inside OpenSSL. πŸ¦‹


✨ NAME ✨

X25519, X448 β€” the EVP_PKEY X25519 and X448 support. That's the whole vibe. No cap.


🌸 DESCRIPTION 🌸

So the X25519 and X448 EVP_PKEY implementation is out here doing key generation and key derivation using X25519 and X448, and honestly? Slay. πŸ’…

It comes with associated private and public key formats that are compatible with RFC 8410 β€” yes, the actual RFC, we're being so valid and standards-compliant today.

🫢 tiny little caveat, bestie: no additional parameters can be set during key generation. Like, at all. Zero. The parameter menu is empty. Periodt.

And when you're doing key derivation, the peer public key must be set using EVP_PKEY_derive_set_peer(). You can't just show up without it β€” that's not how this works. 😭


πŸŽ€ NOTES πŸŽ€

Wanna get yourself a context for the X25519 algorithm? Say less. Just call:

EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL);

And for the X448 algorithm, the exact same energy, just swap the name:

EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X448, NULL);

Now β€” setting your keys. This is the part where it gets good. πŸ’–

  • Private keys: X25519 or X448 private keys can be set directly using EVP_PKEY_new_raw_private_key(3), or loaded from a PKCS#8 private key file using PEM_read_bio_PrivateKey(3) (or a similar function β€” iykyk).
  • Brand-new keys can also be generated from scratch (peep the example below πŸ‘€). And here's the little magic trick: setting a private key also sets the associated public key. Not me getting a two-for-one. πŸ”₯
  • Public keys: X25519 or X448 public keys can be set directly using EVP_PKEY_new_raw_public_key(3), or loaded from a SubjectPublicKeyInfo structure in a PEM file using PEM_read_bio_PUBKEY(3) (or similar function).

🌈 EXAMPLES 🌈

okay so this example generates an X25519 private key and writes it to standard output in PEM format. It's giving main character energy and it works:

#include <openssl/evp.h>
#include <openssl/pem.h>
...
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL);
EVP_PKEY_keygen_init(pctx);
EVP_PKEY_keygen(pctx, &pkey);
EVP_PKEY_CTX_free(pctx);
PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL);

And for key derivation? The key derivation example over in EVP_PKEY_derive(3) can be used with X25519 and X448. Go off, honestly. πŸ‘‘


⭐ SEE ALSO ⭐


Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


πŸ’€ fr fr, read the license before you ship it. That's the vibe check nobody wants to fail.

k bye bestie, go forth and derive those keys πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

β€” this page is X25519(7ossl) from the OpenSSL fam, version 3.5.0, dated 2026-09-25. mwah πŸ’‹

πŸ“¦ where this page comes from