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