EVP_PKEY_CTX_GET0_PKEY(3ossl)

πŸ’– EVP_PKEY_CTX_GET0_PKEY πŸ’–

okay bestie, welcome to the OpenSSL manual, section 3ossl β€” yes this is a real man page and yes it's about two tiny getter functions that are lowkey the backbone of your whole key-derivation setup. let's get into it πŸ¦‹


✨ NAME ✨

EVP_PKEY_CTX_get0_pkey, EVP_PKEY_CTX_get0_peerkey β€” functions for accessing the EVP_PKEY associated with an EVP_PKEY_CTX

like. that's the whole job. they get the key. iconic behaviour honestly πŸ‘‘


✨ SYNOPSIS ✨

#include <openssl/evp.h>

EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx);
EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx);

look at them. two little functions. so much power. πŸ’…


✨ DESCRIPTION ✨

EVP_PKEY_CTX_get0_pkey() 🌸

this one is used to access the EVP_PKEY associated with the given EVP_PKEY_CTX ctx. and like, which EVP_PKEY is it? it's the one you used to create the EVP_PKEY_CTX in the first place β€” either through EVP_PKEY_CTX_new(3) or through EVP_PKEY_CTX_new_from_pkey(3). so it's giving "hey remember that key you walked in with? here it is again." main character energy fr fr ✨

EVP_PKEY_CTX_get0_peerkey() 🫢

and this one is for the peer EVP_PKEY associated with the given EVP_PKEY_CTX ctx. the peer key you get back is the one that was set using either EVP_PKEY_derive_set_peer(3) or EVP_PKEY_derive_set_peer_ex(3). so it's the other party's key β€” your plus-one, your duet partner, the one you're deriving a shared secret with πŸŽ€


✨ RETURN VALUES ✨

  • EVP_PKEY_CTX_get0_pkey() returns the EVP_PKEY associated with the EVP_PKEY_CTX, or NULL if it is not set. 😭
  • EVP_PKEY_CTX_get0_peerkey() returns the peer EVP_PKEY associated with the EVP_PKEY_CTX, or NULL if it is not set. 😭
🚨 bestie listen up, this is the important part: the returned EVP_PKEY objects are owned by the EVP_PKEY_CTX, and therefore should not explicitly be freed by the caller. do not EVP_PKEY_free() them. do not pass go. the ctx is the parent, you are just visiting. πŸ™ˆ

and one more thing, no cap: these functions do not affect the EVP_PKEY reference count. they merely act as getter functions, and should be treated as such. no refcount bump, no ownership transfer, just a lil peek. get0 in the name is literally telling you that β€” zero refs added, zero drama πŸ’€


✨ SEE ALSO ✨

go read those next, iykyk πŸ“š


Copyright 2022-2023 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!! πŸŽ€ this was OpenSSL 3.5.9, dated 2026-09-29, from the EVP_PKEY_CTX_GET0_PKEY(3ossl) manual β€” now go forth and get those keys (without freeing them, please, i'm begging 😭). mwah πŸ’–βœ¨

πŸ“¦ where this page comes from