EVP_PKEY_VERIFY_RECOVER(3ossl)
π EVP_PKEY_VERIFY_RECOVER(3ossl) π
okay so bestie, welcome to the OpenSSL 3ossl manual page for EVP_PKEY_verify_recover_init, EVP_PKEY_verify_recover_init_ex, EVP_PKEY_verify_recover_init_ex2 and EVP_PKEY_verify_recover β the whole squad that recovers a signature using a public key algorithm. yes, recovers. like getting the original message back out of a signature. it's giving un-baking a cake. π
β¨ SYNOPSIS β¨
#include <openssl/evp.h>
int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx);
int EVP_PKEY_verify_recover_init_ex(EVP_PKEY_CTX *ctx,
const OSSL_PARAM params[]);
int EVP_PKEY_verify_recover_init_ex2(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *algo,
const OSSL_PARAM params[]);
int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
unsigned char *rout, size_t *routlen,
const unsigned char *sig, size_t siglen);
πΈ DESCRIPTION πΈ
EVP_PKEY_verify_recover_init()β this one initializes a public key algorithm contextctxfor signing, using the algorithm that was given when the context was created withEVP_PKEY_CTX_new(3)or variants thereof. the algorithm gets used to fetch anEVP_SIGNATUREmethod implicitly, so go read "Implicit fetch" inprovider(7)if you want the whole lore on implicit fetches. iykyk π₯EVP_PKEY_verify_recover_init_ex()β literally the same asEVP_PKEY_verify_recover_init()except it also sets the passed parametersparamson the context before it returns. cute little bonus. β¨EVP_PKEY_verify_recover_init_ex2()β same asEVP_PKEY_verify_recover_init_ex(), but it works with an explicitly fetchedEVP_SIGNATUREalgo. important vibe check: a contextctxwithout a pre-loaded key cannot be used with this function. and depending on what algorithm was fetched, certain details revolving around the treatment of the input toEVP_PKEY_verify()may be pre-determined, and in that case those details may normally not be changed. see "NOTES" below for the deeper explanation. πEVP_PKEY_verify_recover()β the main character π . it recovers signed data usingctx. the signature is specified using thesigandsiglenparameters. ifroutisNULLthen the maximum size of the output buffer gets written to theroutlenparameter. ifroutis notNULLthen before the call theroutlenparameter should contain the length of theroutbuffer, and if the call is successful the recovered data is written toroutand the amount of data written goes toroutlen. two-step queen behavior, we love to see it.
π¦ NOTES π¦
ngl, normally an application is only interested in whether a signature verification operation is successful β in those cases you should just use the EVP_verify() function. simple. done. periodt.
sometimes though it's genuinely useful to obtain the data that was originally signed using a signing operation. but bestie, listen: only certain public key algorithms can recover a signature in this way (for example RSA in PKCS padding mode). so don't come at every algorithm expecting miracles. π
after the call to EVP_PKEY_verify_recover_init() you can perform algorithm specific control operations to set any appropriate parameters for the operation. β¨
after the call to EVP_PKEY_verify_recover_init_ex2(), algorithm specific control operations may not be needed if the chosen algorithm implies that those controls are pre-set (and immutable). iykyk.
and the fun part: EVP_PKEY_verify_recover() can be called more than once on the same context if several operations are performed using the same parameters. reuse the vibe, save the allocation. π«Ά
β RETURN VALUES β
EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover() return 1 for success and 0 or a negative value for failure.
π¨ in particular, a return value of-2indicates the operation is not supported by the public key algorithm. so if you see-2, it's not you, it's the algorithm. π
π EXAMPLES π
Recover digest originally signed using PKCS#1 and SHA256 digest:
#include <openssl/evp.h>
#include <openssl/rsa.h>
EVP_PKEY_CTX *ctx;
unsigned char *rout, *sig;
size_t routlen, siglen;
EVP_PKEY *verify_key;
/*
* NB: assumes verify_key, sig and siglen are already set up
* and that verify_key is an RSA public key
*/
ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */);
if (!ctx)
/* Error occurred */
if (EVP_PKEY_verify_recover_init(ctx) <= 0)
/* Error */
if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
/* Error */
if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
/* Error */
/* Determine buffer length */
if (EVP_PKEY_verify_recover(ctx, NULL, &routlen, sig, siglen) <= 0)
/* Error */
rout = OPENSSL_malloc(routlen);
if (!rout)
/* malloc failure */
if (EVP_PKEY_verify_recover(ctx, rout, &routlen, sig, siglen) <= 0)
/* Error */
/* Recovered data is routlen bytes written to buffer rout */
see how we call it once with NULL to get the length, then malloc, then call it again? that's the two-pass slay. π₯
π SEE ALSO π
EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3), EVP_PKEY_sign(3), EVP_PKEY_verify(3), EVP_PKEY_derive(3)
π HISTORY π
EVP_PKEY_verify_recover_init()andEVP_PKEY_verify_recover()were added in OpenSSL 1.0.0. vintage icons fr fr.EVP_PKEY_verify_recover_init_ex()was added in OpenSSL 3.0.
π COPYRIGHT π
Copyright 2013-2024 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 π«Ά β from the OpenSSL crew, version 3.5.0, dated 2026-09-25. go recover some signatures responsibly, mwah π
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms