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