'Get EVP_PKEY from EVP_PKEY_CTX

I have a function that takes as parameter an EVP_PKEY_CTX*. I cannot modify the function signature in any way. Is there any way to get the EVP_PKEY object from the EVP_PKEY_CTX ?

My code would look something like this :

void foo(EVP_PKEY_CTX *ctx) {
    EVP_PKEY *pkey;
    pkey = ctx->pkey // This does not work but it is essentially what I want to do
    // Do operations with pkey
    bar(pkey);
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source