X25519(7ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’œ X25519 β€” the OpenSSL manual page, but make it make sense

okay so bestie, this is X25519(7ossl) from the OpenSSL docs β€” yes that's the manual name, it's giving "crypto but make it cute" ✨

🌸 NAME 🌸

X25519, X448 β€” EVP_PKEY X25519 and X448 support. that's it, that's the whole name section, slay πŸ’…

✨ DESCRIPTION ✨

so the X25519 and X448 EVP_PKEY implementation supports key generation and key derivation using X25519 and X448. it comes with associated private and public key formats that are compatible with RFC 8410 β€” yes, RFC 8410, remember that number, it's iconic πŸŽ€

no additional parameters can be set during key generation. like, zero, none, that door is closed, don't even try πŸ™ˆ

and bestie listen β€” the peer public key must be set using EVP_PKEY_derive_set_peer() when you're performing key derivation. must. not optional. it's giving "you literally cannot skip this step" πŸ’€


πŸ¦‹ NOTES πŸ¦‹

want a context for the X25519 algorithm? you get one by calling:

EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL);

and for the X448 algorithm, you call this instead:

EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X448, NULL);

see what they did there? one word changed. main character energy πŸ‘‘

okay so for the keys themselves:

  • 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 any similar function). completely new keys can also be generated β€” see the example below, it's right there 🫢
  • and here's the cute part: setting a private key also sets the associated public key. two for one, we love efficiency ✨
  • 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 a similar function).

🌈 EXAMPLES 🌈

this example generates an X25519 private key and writes it to standard output in PEM format. copy it exactly, don't freestyle:

#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 the key derivation example in EVP_PKEY_derive(3)? yeah, that one can be used with X25519 and X448 too. reuse, recycle, iconic πŸ’š


πŸŽ€ SEE ALSO πŸŽ€

go read these, i'm serious, they're the supporting cast and they ate:


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>.


and that's the whole page bestie, no cap 🧚 this was OpenSSL 3.5.6, dated 2026-04-07, and the page is X25519(7ossl) β€” go forth and derive those keys, you're gonna slay πŸ’–πŸ’…

πŸ“¦ where this page comes from