1=pod 2 3=head1 NAME 4 5EVP_PKEY_verify_recover_init, EVP_PKEY_verify_recover_init_ex, 6EVP_PKEY_verify_recover_init_ex2, EVP_PKEY_verify_recover 7- recover signature using a public key algorithm 8 9=head1 SYNOPSIS 10 11 #include <openssl/evp.h> 12 13 int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); 14 int EVP_PKEY_verify_recover_init_ex(EVP_PKEY_CTX *ctx, 15 const OSSL_PARAM params[]); 16 int EVP_PKEY_verify_recover_init_ex2(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *algo, 17 const OSSL_PARAM params[]); 18 int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, 19 unsigned char *rout, size_t *routlen, 20 const unsigned char *sig, size_t siglen); 21 22=head1 DESCRIPTION 23 24EVP_PKEY_verify_recover_init() initializes a public key algorithm context 25I<ctx> for signing using the algorithm given when the context was created 26using L<EVP_PKEY_CTX_new(3)> or variants thereof. The algorithm is used to 27fetch a B<EVP_SIGNATURE> method implicitly, see L<provider(7)/Implicit fetch> 28for more information about implicit fetches. 29 30EVP_PKEY_verify_recover_init_ex() is the same as 31EVP_PKEY_verify_recover_init() but additionally sets the passed parameters 32I<params> on the context before returning. 33 34EVP_PKEY_verify_recover_init_ex2() is the same as EVP_PKEY_verify_recover_init_ex(), 35but works with an explicitly fetched B<EVP_SIGNATURE> I<algo>. 36A context I<ctx> without a pre-loaded key cannot be used with this function. 37Depending on what algorithm was fetched, certain details revolving around the 38treatment of the input to EVP_PKEY_verify() may be pre-determined, and in that 39case, those details may normally not be changed. 40See L</NOTES> below for a deeper explanation. 41 42The EVP_PKEY_verify_recover() function recovers signed data 43using I<ctx>. The signature is specified using the I<sig> and 44I<siglen> parameters. If I<rout> is NULL then the maximum size of the output 45buffer is written to the I<routlen> parameter. If I<rout> is not NULL then 46before the call the I<routlen> parameter should contain the length of the 47I<rout> buffer, if the call is successful recovered data is written to 48I<rout> and the amount of data written to I<routlen>. 49 50=head1 NOTES 51 52Normally an application is only interested in whether a signature verification 53operation is successful in those cases the EVP_verify() function should be 54used. 55 56Sometimes however it is useful to obtain the data originally signed using a 57signing operation. Only certain public key algorithms can recover a signature 58in this way (for example RSA in PKCS padding mode). 59 60After the call to EVP_PKEY_verify_recover_init() algorithm specific control 61operations can be performed to set any appropriate parameters for the 62operation. 63 64After the call to EVP_PKEY_verify_recover_init_ex2(), algorithm specific control 65operations may not be needed if the chosen algorithm implies that those controls 66pre-set (and immutable). 67 68The function EVP_PKEY_verify_recover() can be called more than once on the same 69context if several operations are performed using the same parameters. 70 71=head1 RETURN VALUES 72 73EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover() return 1 for success 74and 0 or a negative value for failure. In particular a return value of -2 75indicates the operation is not supported by the public key algorithm. 76 77=head1 EXAMPLES 78 79Recover digest originally signed using PKCS#1 and SHA256 digest: 80 81 #include <openssl/evp.h> 82 #include <openssl/rsa.h> 83 84 EVP_PKEY_CTX *ctx; 85 unsigned char *rout, *sig; 86 size_t routlen, siglen; 87 EVP_PKEY *verify_key; 88 89 /* 90 * NB: assumes verify_key, sig and siglen are already set up 91 * and that verify_key is an RSA public key 92 */ 93 ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */); 94 if (!ctx) 95 /* Error occurred */ 96 if (EVP_PKEY_verify_recover_init(ctx) <= 0) 97 /* Error */ 98 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) 99 /* Error */ 100 if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) 101 /* Error */ 102 103 /* Determine buffer length */ 104 if (EVP_PKEY_verify_recover(ctx, NULL, &routlen, sig, siglen) <= 0) 105 /* Error */ 106 107 rout = OPENSSL_malloc(routlen); 108 109 if (!rout) 110 /* malloc failure */ 111 112 if (EVP_PKEY_verify_recover(ctx, rout, &routlen, sig, siglen) <= 0) 113 /* Error */ 114 115 /* Recovered data is routlen bytes written to buffer rout */ 116 117=head1 SEE ALSO 118 119L<EVP_PKEY_CTX_new(3)>, 120L<EVP_PKEY_encrypt(3)>, 121L<EVP_PKEY_decrypt(3)>, 122L<EVP_PKEY_sign(3)>, 123L<EVP_PKEY_verify(3)>, 124L<EVP_PKEY_derive(3)> 125 126=head1 HISTORY 127 128The EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover() 129functions were added in OpenSSL 1.0.0. 130 131The EVP_PKEY_verify_recover_init_ex() function was added in OpenSSL 3.0. 132 133=head1 COPYRIGHT 134 135Copyright 2013-2024 The OpenSSL Project Authors. All Rights Reserved. 136 137Licensed under the Apache License 2.0 (the "License"). You may not use 138this file except in compliance with the License. You can obtain a copy 139in the file LICENSE in the source distribution or at 140L<https://www.openssl.org/source/license.html>. 141 142=cut 143