]>
Commit | Line | Data |
---|---|---|
64cee65e DSH |
1 | =pod |
2 | ||
3 | =head1 NAME | |
4 | ||
e54e1235 | 5 | EVP_PKEY_verify_recover_init, EVP_PKEY_verify_recover - recover signature using a public key algorithm |
64cee65e DSH |
6 | |
7 | =head1 SYNOPSIS | |
8 | ||
9 | #include <openssl/evp.h> | |
10 | ||
e54e1235 BL |
11 | int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); |
12 | int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, | |
e9b77246 BB |
13 | unsigned char *rout, size_t *routlen, |
14 | const unsigned char *sig, size_t siglen); | |
64cee65e DSH |
15 | |
16 | =head1 DESCRIPTION | |
17 | ||
e54e1235 | 18 | The EVP_PKEY_verify_recover_init() function initializes a public key algorithm |
64cee65e DSH |
19 | context using key B<pkey> for a verify recover operation. |
20 | ||
e54e1235 | 21 | The EVP_PKEY_verify_recover() function recovers signed data |
64cee65e DSH |
22 | using B<ctx>. The signature is specified using the B<sig> and |
23 | B<siglen> parameters. If B<rout> is B<NULL> then the maximum size of the output | |
24 | buffer is written to the B<routlen> parameter. If B<rout> is not B<NULL> then | |
25 | before the call the B<routlen> parameter should contain the length of the | |
26 | B<rout> buffer, if the call is successful recovered data is written to | |
27 | B<rout> and the amount of data written to B<routlen>. | |
28 | ||
29 | =head1 NOTES | |
30 | ||
31 | Normally an application is only interested in whether a signature verification | |
1bc74519 | 32 | operation is successful in those cases the EVP_verify() function should be |
64cee65e DSH |
33 | used. |
34 | ||
35 | Sometimes however it is useful to obtain the data originally signed using a | |
36 | signing operation. Only certain public key algorithms can recover a signature | |
37 | in this way (for example RSA in PKCS padding mode). | |
38 | ||
e54e1235 | 39 | After the call to EVP_PKEY_verify_recover_init() algorithm specific control |
64cee65e DSH |
40 | operations can be performed to set any appropriate parameters for the |
41 | operation. | |
42 | ||
e54e1235 | 43 | The function EVP_PKEY_verify_recover() can be called more than once on the same |
64cee65e DSH |
44 | context if several operations are performed using the same parameters. |
45 | ||
46 | =head1 RETURN VALUES | |
47 | ||
e54e1235 | 48 | EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover() return 1 for success |
64cee65e DSH |
49 | and 0 or a negative value for failure. In particular a return value of -2 |
50 | indicates the operation is not supported by the public key algorithm. | |
51 | ||
52 | =head1 EXAMPLE | |
53 | ||
54 | Recover digest originally signed using PKCS#1 and SHA256 digest: | |
55 | ||
43636910 DSH |
56 | #include <openssl/evp.h> |
57 | #include <openssl/rsa.h> | |
58 | ||
59 | EVP_PKEY_CTX *ctx; | |
60 | unsigned char *rout, *sig; | |
1bc74519 | 61 | size_t routlen, siglen; |
43636910 | 62 | EVP_PKEY *verify_key; |
e9b77246 | 63 | |
2947af32 BB |
64 | /* |
65 | * NB: assumes verify_key, sig and siglen are already set up | |
43636910 DSH |
66 | * and that verify_key is an RSA public key |
67 | */ | |
9db6673e | 68 | ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */); |
43636910 | 69 | if (!ctx) |
2947af32 | 70 | /* Error occurred */ |
e54e1235 | 71 | if (EVP_PKEY_verify_recover_init(ctx) <= 0) |
2947af32 | 72 | /* Error */ |
43636910 | 73 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) |
2947af32 | 74 | /* Error */ |
43636910 | 75 | if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) |
2947af32 | 76 | /* Error */ |
43636910 DSH |
77 | |
78 | /* Determine buffer length */ | |
e54e1235 | 79 | if (EVP_PKEY_verify_recover(ctx, NULL, &routlen, sig, siglen) <= 0) |
2947af32 | 80 | /* Error */ |
43636910 DSH |
81 | |
82 | rout = OPENSSL_malloc(routlen); | |
83 | ||
84 | if (!rout) | |
2947af32 | 85 | /* malloc failure */ |
1bc74519 | 86 | |
e54e1235 | 87 | if (EVP_PKEY_verify_recover(ctx, rout, &routlen, sig, siglen) <= 0) |
2947af32 | 88 | /* Error */ |
43636910 DSH |
89 | |
90 | /* Recovered data is routlen bytes written to buffer rout */ | |
64cee65e DSH |
91 | |
92 | =head1 SEE ALSO | |
93 | ||
9b86974e RS |
94 | L<EVP_PKEY_CTX_new(3)>, |
95 | L<EVP_PKEY_encrypt(3)>, | |
96 | L<EVP_PKEY_decrypt(3)>, | |
97 | L<EVP_PKEY_sign(3)>, | |
98 | L<EVP_PKEY_verify(3)>, | |
1bc74519 | 99 | L<EVP_PKEY_derive(3)> |
64cee65e DSH |
100 | |
101 | =head1 HISTORY | |
102 | ||
fb552ac6 | 103 | These functions were first added to OpenSSL 1.0.0. |
64cee65e | 104 | |
e2f92610 RS |
105 | =head1 COPYRIGHT |
106 | ||
48e5119a | 107 | Copyright 2013-2018 The OpenSSL Project Authors. All Rights Reserved. |
e2f92610 RS |
108 | |
109 | Licensed under the OpenSSL license (the "License"). You may not use | |
110 | this file except in compliance with the License. You can obtain a copy | |
111 | in the file LICENSE in the source distribution or at | |
112 | L<https://www.openssl.org/source/license.html>. | |
113 | ||
114 | =cut |