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 not verify successfully (that is tbs did not match
39 the 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 /* NB: assumes verify_key, sig, siglen md and mdlen are already set up
57 * and that verify_key is an RSA public key
58 */
59 ctx = EVP_PKEY_CTX_new(verify_key);
60 if (!ctx)
61 /* Error occurred */
62 if (EVP_PKEY_verify_init(ctx) <= 0)
63 /* Error */
64 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
65 /* Error */
66 if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
67 /* Error */
68
69 /* Perform operation */
70 ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);
71
72 /* ret == 1 indicates success, 0 verify failure and < 0 for some
73 * other error.
74 */
75
77 EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3),
78 EVP_PKEY_sign(3), EVP_PKEY_verify_recover(3), EVP_PKEY_derive(3)
79
81 These functions were first added to OpenSSL 1.0.0.
82
83
84
851.0.2o 2020-01-28 EVP_PKEY_verify(3)