1EVP_PKEY_VERIFY(3) OpenSSL EVP_PKEY_VERIFY(3)
2
3
4
6 EVP_PKEY_verify_init, EVP_PKEY_verify - signature verification using a
7 public key algorithm
8
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,
14 const unsigned char *sig, size_t siglen,
15 const unsigned char *tbs, size_t tbslen);
16
18 The EVP_PKEY_verify_init() function initializes a public key algorithm
19 context using key pkey for a signature verification operation.
20
21 The EVP_PKEY_verify() function performs a public key verification
22 operation using ctx. The signature is specified using the sig and
23 siglen parameters. The verified data (i.e. the data believed originally
24 signed) is specified using the tbs and tbslen parameters.
25
27 After the call to EVP_PKEY_verify_init() algorithm specific control
28 operations can be performed to set any appropriate parameters for the
29 operation.
30
31 The function EVP_PKEY_verify() can be called more than once on the same
32 context if several operations are performed using the same parameters.
33
35 EVP_PKEY_verify_init() and EVP_PKEY_verify() return 1 if the
36 verification was successful and 0 if it failed. Unlike other functions
37 the return value 0 from EVP_PKEY_verify() only indicates that the
38 signature did not verify successfully (that is tbs did not match the
39 original data or the signature was of invalid form) it is not an
40 indication of a more serious error.
41
42 A negative value indicates an error other that signature verification
43 failure. In particular a return value of -2 indicates the operation is
44 not supported by the public key algorithm.
45
47 Verify signature using PKCS#1 and SHA256 digest:
48
49 #include <openssl/evp.h>
50 #include <openssl/rsa.h>
51
52 EVP_PKEY_CTX *ctx;
53 unsigned char *md, *sig;
54 size_t mdlen, siglen;
55 EVP_PKEY *verify_key;
56
57 /*
58 * NB: assumes verify_key, sig, siglen md and mdlen are already set up
59 * and that verify_key is an RSA public key
60 */
61 ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */);
62 if (!ctx)
63 /* Error occurred */
64 if (EVP_PKEY_verify_init(ctx) <= 0)
65 /* Error */
66 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
67 /* Error */
68 if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
69 /* Error */
70
71 /* Perform operation */
72 ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);
73
74 /*
75 * ret == 1 indicates success, 0 verify failure and < 0 for some
76 * other error.
77 */
78
80 EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3),
81 EVP_PKEY_sign(3), EVP_PKEY_verify_recover(3), EVP_PKEY_derive(3)
82
84 These functions were added in OpenSSL 1.0.0.
85
87 Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
88
89 Licensed under the OpenSSL license (the "License"). You may not use
90 this file except in compliance with the License. You can obtain a copy
91 in the file LICENSE in the source distribution or at
92 <https://www.openssl.org/source/license.html>.
93
94
95
961.1.1q 2023-02-06 EVP_PKEY_VERIFY(3)