]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/EVP_PKEY_verify.pod
Expand the XTS documentation
[thirdparty/openssl.git] / doc / man3 / EVP_PKEY_verify.pod
CommitLineData
6535bd42
DSH
1=pod
2
3=head1 NAME
4
0e521004 5EVP_PKEY_verify_init, EVP_PKEY_verify
11031468 6- signature verification using a public key algorithm
6535bd42
DSH
7
8=head1 SYNOPSIS
9
10 #include <openssl/evp.h>
11
12 int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
13 int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
e9b77246
BB
14 const unsigned char *sig, size_t siglen,
15 const unsigned char *tbs, size_t tbslen);
6535bd42
DSH
16
17=head1 DESCRIPTION
18
0e521004
RL
19EVP_PKEY_verify_init() initializes a public key algorithm context I<ctx> for
20signing using the algorithm given when the context was created
21using L<EVP_PKEY_CTX_new(3)> or variants thereof. The algorithm is used to
22fetch a B<EVP_SIGNATURE> method implicitly, see L<provider(7)/Implicit fetch>
23for more information about implict fetches.
6535bd42
DSH
24
25The EVP_PKEY_verify() function performs a public key verification operation
0e521004
RL
26using I<ctx>. The signature is specified using the I<sig> and
27I<siglen> parameters. The verified data (i.e. the data believed originally
28signed) is specified using the I<tbs> and I<tbslen> parameters.
6535bd42
DSH
29
30=head1 NOTES
31
32After the call to EVP_PKEY_verify_init() algorithm specific control
33operations can be performed to set any appropriate parameters for the
34operation.
35
36The function EVP_PKEY_verify() can be called more than once on the same
37context if several operations are performed using the same parameters.
38
39=head1 RETURN VALUES
40
29cf84c6
DSH
41EVP_PKEY_verify_init() and EVP_PKEY_verify() return 1 if the verification was
42successful and 0 if it failed. Unlike other functions the return value 0 from
a970b14f 43EVP_PKEY_verify() only indicates that the signature did not verify
29cf84c6
DSH
44successfully (that is tbs did not match the original data or the signature was
45of invalid form) it is not an indication of a more serious error.
6535bd42
DSH
46
47A negative value indicates an error other that signature verification failure.
48In particular a return value of -2 indicates the operation is not supported by
49the public key algorithm.
50
cda77422 51=head1 EXAMPLES
6535bd42
DSH
52
53Verify signature using PKCS#1 and SHA256 digest:
54
43636910
DSH
55 #include <openssl/evp.h>
56 #include <openssl/rsa.h>
57
58 EVP_PKEY_CTX *ctx;
59 unsigned char *md, *sig;
1bc74519 60 size_t mdlen, siglen;
43636910 61 EVP_PKEY *verify_key;
e9b77246 62
2947af32
BB
63 /*
64 * NB: assumes verify_key, sig, siglen md and mdlen are already set up
43636910
DSH
65 * and that verify_key is an RSA public key
66 */
9db6673e 67 ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */);
43636910 68 if (!ctx)
2947af32 69 /* Error occurred */
43636910 70 if (EVP_PKEY_verify_init(ctx) <= 0)
2947af32 71 /* Error */
43636910 72 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
2947af32 73 /* Error */
43636910 74 if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
2947af32 75 /* Error */
43636910
DSH
76
77 /* Perform operation */
6f413ef4 78 ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);
43636910 79
2947af32
BB
80 /*
81 * ret == 1 indicates success, 0 verify failure and < 0 for some
43636910
DSH
82 * other error.
83 */
6535bd42
DSH
84
85=head1 SEE ALSO
86
9b86974e
RS
87L<EVP_PKEY_CTX_new(3)>,
88L<EVP_PKEY_encrypt(3)>,
89L<EVP_PKEY_decrypt(3)>,
90L<EVP_PKEY_sign(3)>,
91L<EVP_PKEY_verify_recover(3)>,
1bc74519 92L<EVP_PKEY_derive(3)>
6535bd42
DSH
93
94=head1 HISTORY
95
fadb57e5 96These functions were added in OpenSSL 1.0.0.
6535bd42 97
e2f92610
RS
98=head1 COPYRIGHT
99
48e5119a 100Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
e2f92610 101
4746f25a 102Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
103this file except in compliance with the License. You can obtain a copy
104in the file LICENSE in the source distribution or at
105L<https://www.openssl.org/source/license.html>.
106
107=cut