xref: /freebsd/crypto/openssl/doc/man3/EVP_PKEY_verify.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5*b077aed3SPierre ProncheryEVP_PKEY_verify_init, EVP_PKEY_verify_init_ex, EVP_PKEY_verify
6*b077aed3SPierre Pronchery- signature verification using a public key algorithm
7e71b7053SJung-uk Kim
8e71b7053SJung-uk Kim=head1 SYNOPSIS
9e71b7053SJung-uk Kim
10e71b7053SJung-uk Kim #include <openssl/evp.h>
11e71b7053SJung-uk Kim
12e71b7053SJung-uk Kim int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
13*b077aed3SPierre Pronchery int EVP_PKEY_verify_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
14e71b7053SJung-uk Kim int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
15e71b7053SJung-uk Kim                     const unsigned char *sig, size_t siglen,
16e71b7053SJung-uk Kim                     const unsigned char *tbs, size_t tbslen);
17e71b7053SJung-uk Kim
18e71b7053SJung-uk Kim=head1 DESCRIPTION
19e71b7053SJung-uk Kim
20*b077aed3SPierre ProncheryEVP_PKEY_verify_init() initializes a public key algorithm context I<ctx> for
21*b077aed3SPierre Proncherysigning using the algorithm given when the context was created
22*b077aed3SPierre Proncheryusing L<EVP_PKEY_CTX_new(3)> or variants thereof.  The algorithm is used to
23*b077aed3SPierre Proncheryfetch a B<EVP_SIGNATURE> method implicitly, see L<provider(7)/Implicit fetch>
24*b077aed3SPierre Proncheryfor more information about implicit fetches.
25*b077aed3SPierre Pronchery
26*b077aed3SPierre ProncheryEVP_PKEY_verify_init_ex() is the same as EVP_PKEY_verify_init() but additionally
27*b077aed3SPierre Proncherysets the passed parameters I<params> on the context before returning.
28e71b7053SJung-uk Kim
29e71b7053SJung-uk KimThe EVP_PKEY_verify() function performs a public key verification operation
30*b077aed3SPierre Proncheryusing I<ctx>. The signature is specified using the I<sig> and
31*b077aed3SPierre ProncheryI<siglen> parameters. The verified data (i.e. the data believed originally
32*b077aed3SPierre Proncherysigned) is specified using the I<tbs> and I<tbslen> parameters.
33e71b7053SJung-uk Kim
34e71b7053SJung-uk Kim=head1 NOTES
35e71b7053SJung-uk Kim
36e71b7053SJung-uk KimAfter the call to EVP_PKEY_verify_init() algorithm specific control
37e71b7053SJung-uk Kimoperations can be performed to set any appropriate parameters for the
38e71b7053SJung-uk Kimoperation.
39e71b7053SJung-uk Kim
40e71b7053SJung-uk KimThe function EVP_PKEY_verify() can be called more than once on the same
41e71b7053SJung-uk Kimcontext if several operations are performed using the same parameters.
42e71b7053SJung-uk Kim
43e71b7053SJung-uk Kim=head1 RETURN VALUES
44e71b7053SJung-uk Kim
45e71b7053SJung-uk KimEVP_PKEY_verify_init() and EVP_PKEY_verify() return 1 if the verification was
46e71b7053SJung-uk Kimsuccessful and 0 if it failed. Unlike other functions the return value 0 from
47e71b7053SJung-uk KimEVP_PKEY_verify() only indicates that the signature did not verify
48e71b7053SJung-uk Kimsuccessfully (that is tbs did not match the original data or the signature was
49e71b7053SJung-uk Kimof invalid form) it is not an indication of a more serious error.
50e71b7053SJung-uk Kim
51e71b7053SJung-uk KimA negative value indicates an error other that signature verification failure.
52e71b7053SJung-uk KimIn particular a return value of -2 indicates the operation is not supported by
53e71b7053SJung-uk Kimthe public key algorithm.
54e71b7053SJung-uk Kim
55da327cd2SJung-uk Kim=head1 EXAMPLES
56e71b7053SJung-uk Kim
57e71b7053SJung-uk KimVerify signature using PKCS#1 and SHA256 digest:
58e71b7053SJung-uk Kim
59e71b7053SJung-uk Kim #include <openssl/evp.h>
60e71b7053SJung-uk Kim #include <openssl/rsa.h>
61e71b7053SJung-uk Kim
62e71b7053SJung-uk Kim EVP_PKEY_CTX *ctx;
63e71b7053SJung-uk Kim unsigned char *md, *sig;
64e71b7053SJung-uk Kim size_t mdlen, siglen;
65e71b7053SJung-uk Kim EVP_PKEY *verify_key;
66e71b7053SJung-uk Kim
67e71b7053SJung-uk Kim /*
68e71b7053SJung-uk Kim  * NB: assumes verify_key, sig, siglen md and mdlen are already set up
69e71b7053SJung-uk Kim  * and that verify_key is an RSA public key
70e71b7053SJung-uk Kim  */
71e71b7053SJung-uk Kim ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */);
72e71b7053SJung-uk Kim if (!ctx)
73e71b7053SJung-uk Kim     /* Error occurred */
74e71b7053SJung-uk Kim if (EVP_PKEY_verify_init(ctx) <= 0)
75e71b7053SJung-uk Kim     /* Error */
76e71b7053SJung-uk Kim if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
77e71b7053SJung-uk Kim     /* Error */
78e71b7053SJung-uk Kim if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
79e71b7053SJung-uk Kim     /* Error */
80e71b7053SJung-uk Kim
81e71b7053SJung-uk Kim /* Perform operation */
82e71b7053SJung-uk Kim ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);
83e71b7053SJung-uk Kim
84e71b7053SJung-uk Kim /*
85e71b7053SJung-uk Kim  * ret == 1 indicates success, 0 verify failure and < 0 for some
86e71b7053SJung-uk Kim  * other error.
87e71b7053SJung-uk Kim  */
88e71b7053SJung-uk Kim
89e71b7053SJung-uk Kim=head1 SEE ALSO
90e71b7053SJung-uk Kim
91e71b7053SJung-uk KimL<EVP_PKEY_CTX_new(3)>,
92e71b7053SJung-uk KimL<EVP_PKEY_encrypt(3)>,
93e71b7053SJung-uk KimL<EVP_PKEY_decrypt(3)>,
94e71b7053SJung-uk KimL<EVP_PKEY_sign(3)>,
95e71b7053SJung-uk KimL<EVP_PKEY_verify_recover(3)>,
96e71b7053SJung-uk KimL<EVP_PKEY_derive(3)>
97e71b7053SJung-uk Kim
98e71b7053SJung-uk Kim=head1 HISTORY
99e71b7053SJung-uk Kim
100*b077aed3SPierre ProncheryThe EVP_PKEY_verify_init() and EVP_PKEY_verify() functions were added in
101*b077aed3SPierre ProncheryOpenSSL 1.0.0.
102*b077aed3SPierre Pronchery
103*b077aed3SPierre ProncheryThe EVP_PKEY_verify_init_ex() function was added in OpenSSL 3.0.
104e71b7053SJung-uk Kim
105e71b7053SJung-uk Kim=head1 COPYRIGHT
106e71b7053SJung-uk Kim
107*b077aed3SPierre ProncheryCopyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
108e71b7053SJung-uk Kim
109*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
110e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
111e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
112e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
113e71b7053SJung-uk Kim
114e71b7053SJung-uk Kim=cut
115