1EVP_PKEY_VERIFY_RECOVER(3ossl) OpenSSL EVP_PKEY_VERIFY_RECOVER(3ossl)
2
3
4
6 EVP_PKEY_verify_recover_init, EVP_PKEY_verify_recover_init_ex,
7 EVP_PKEY_verify_recover - recover signature using a public key
8 algorithm
9
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(EVP_PKEY_CTX *ctx,
17 unsigned char *rout, size_t *routlen,
18 const unsigned char *sig, size_t siglen);
19
21 EVP_PKEY_verify_recover_init() initializes a public key algorithm
22 context ctx for signing using the algorithm given when the context was
23 created using EVP_PKEY_CTX_new(3) or variants thereof. The algorithm
24 is used to fetch a EVP_SIGNATURE method implicitly, see "Implicit
25 fetch" in provider(7) for more information about implicit fetches.
26
27 EVP_PKEY_verify_recover_init_ex() is the same as
28 EVP_PKEY_verify_recover_init() but additionally sets the passed
29 parameters params on the context before returning.
30
31 The EVP_PKEY_verify_recover() function recovers signed data using ctx.
32 The signature is specified using the sig and siglen parameters. If rout
33 is NULL then the maximum size of the output buffer is written to the
34 routlen parameter. If rout is not NULL then before the call the routlen
35 parameter should contain the length of the rout buffer, if the call is
36 successful recovered data is written to rout and the amount of data
37 written to routlen.
38
40 Normally an application is only interested in whether a signature
41 verification operation is successful in those cases the EVP_verify()
42 function should be used.
43
44 Sometimes however it is useful to obtain the data originally signed
45 using a signing operation. Only certain public key algorithms can
46 recover a signature in this way (for example RSA in PKCS padding mode).
47
48 After the call to EVP_PKEY_verify_recover_init() algorithm specific
49 control operations can be performed to set any appropriate parameters
50 for the operation.
51
52 The function EVP_PKEY_verify_recover() can be called more than once on
53 the same context if several operations are performed using the same
54 parameters.
55
57 EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover() return 1
58 for success and 0 or a negative value for failure. In particular a
59 return value of -2 indicates the operation is not supported by the
60 public key algorithm.
61
63 Recover digest originally signed using PKCS#1 and SHA256 digest:
64
65 #include <openssl/evp.h>
66 #include <openssl/rsa.h>
67
68 EVP_PKEY_CTX *ctx;
69 unsigned char *rout, *sig;
70 size_t routlen, siglen;
71 EVP_PKEY *verify_key;
72
73 /*
74 * NB: assumes verify_key, sig and siglen are already set up
75 * and that verify_key is an RSA public key
76 */
77 ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */);
78 if (!ctx)
79 /* Error occurred */
80 if (EVP_PKEY_verify_recover_init(ctx) <= 0)
81 /* Error */
82 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
83 /* Error */
84 if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
85 /* Error */
86
87 /* Determine buffer length */
88 if (EVP_PKEY_verify_recover(ctx, NULL, &routlen, sig, siglen) <= 0)
89 /* Error */
90
91 rout = OPENSSL_malloc(routlen);
92
93 if (!rout)
94 /* malloc failure */
95
96 if (EVP_PKEY_verify_recover(ctx, rout, &routlen, sig, siglen) <= 0)
97 /* Error */
98
99 /* Recovered data is routlen bytes written to buffer rout */
100
102 EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3),
103 EVP_PKEY_sign(3), EVP_PKEY_verify(3), EVP_PKEY_derive(3)
104
106 The EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover()
107 functions were added in OpenSSL 1.0.0.
108
109 The EVP_PKEY_verify_recover_init_ex() function was added in OpenSSL
110 3.0.
111
113 Copyright 2013-2021 The OpenSSL Project Authors. All Rights Reserved.
114
115 Licensed under the Apache License 2.0 (the "License"). You may not use
116 this file except in compliance with the License. You can obtain a copy
117 in the file LICENSE in the source distribution or at
118 <https://www.openssl.org/source/license.html>.
119
120
121
1223.0.5 2022-07-05 EVP_PKEY_VERIFY_RECOVER(3ossl)