Home | History | Annotate | Line # | Download | only in man3
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 EVP_DigestVerifyInit_ex, EVP_DigestVerifyInit, EVP_DigestVerifyUpdate,
      6 EVP_DigestVerifyFinal, EVP_DigestVerify - EVP signature verification functions
      7 
      8 =head1 SYNOPSIS
      9 
     10  #include <openssl/evp.h>
     11 
     12  int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
     13                              const char *mdname, OSSL_LIB_CTX *libctx,
     14                              const char *props, EVP_PKEY *pkey,
     15                              const OSSL_PARAM params[]);
     16  int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
     17                           const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
     18  int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
     19  int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
     20                            size_t siglen);
     21  int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
     22                       size_t siglen, const unsigned char *tbs, size_t tbslen);
     23 
     24 =head1 DESCRIPTION
     25 
     26 The EVP signature routines are a high-level interface to digital signatures.
     27 Input data is digested first before the signature verification takes place.
     28 
     29 EVP_DigestVerifyInit_ex() sets up verification context B<ctx> to use a
     30 digest with the name B<mdname> and public key B<pkey>. The name of the digest to
     31 be used is passed to the provider of the signature algorithm in use. How that
     32 provider interprets the digest name is provider specific. The provider may
     33 implement that digest directly itself or it may (optionally) choose to fetch it
     34 (which could result in a digest from a different provider being selected). If
     35 the provider supports fetching the digest then it may use the B<props> argument
     36 for the properties to be used during the fetch. Finally, the passed parameters
     37 I<params>, if not NULL, are set on the context before returning.
     38 
     39 The I<pkey> algorithm is used to fetch a B<EVP_SIGNATURE> method implicitly, to
     40 be used for the actual signing. See L<provider(7)/Implicit fetch> for
     41 more information about implicit fetches.
     42 
     43 The OpenSSL default and legacy providers support fetching digests and can fetch
     44 those digests from any available provider. The OpenSSL FIPS provider also
     45 supports fetching digests but will only fetch digests that are themselves
     46 implemented inside the FIPS provider.
     47 
     48 B<ctx> must be created with EVP_MD_CTX_new() before calling this function. If
     49 B<pctx> is not NULL, the EVP_PKEY_CTX of the verification operation will be
     50 written to B<*pctx>: this can be used to set alternative verification options.
     51 Note that any existing value in B<*pctx> is overwritten. The EVP_PKEY_CTX value
     52 returned must not be freed directly by the application if B<ctx> is not assigned
     53 an EVP_PKEY_CTX value before being passed to EVP_DigestVerifyInit_ex()
     54 (which means the EVP_PKEY_CTX is created inside
     55 EVP_DigestVerifyInit_ex() and it will be freed automatically when the
     56 EVP_MD_CTX is freed). If the EVP_PKEY_CTX to be used is created by
     57 EVP_DigestVerifyInit_ex then it will use the B<OSSL_LIB_CTX> specified
     58 in I<libctx> and the property query string specified in I<props>.
     59 
     60 No B<EVP_PKEY_CTX> will be created by EVP_DigestVerifyInit_ex() if the
     61 passed B<ctx> has already been assigned one via L<EVP_MD_CTX_set_pkey_ctx(3)>.
     62 See also L<SM2(7)>.
     63 
     64 Not all digests can be used for all key types. The following combinations apply.
     65 
     66 =over 4
     67 
     68 =item DSA
     69 
     70 Supports SHA1, SHA224, SHA256, SHA384 and SHA512
     71 
     72 =item ECDSA
     73 
     74 Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
     75 
     76 =item RSA with no padding
     77 
     78 Supports no digests (the digest B<type> must be NULL)
     79 
     80 =item RSA with X931 padding
     81 
     82 Supports SHA1, SHA256, SHA384 and SHA512
     83 
     84 =item All other RSA padding types
     85 
     86 Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2,
     87 SHA3-224, SHA3-256, SHA3-384, SHA3-512
     88 
     89 =item Ed25519 and Ed448
     90 
     91 Support no digests (the digest B<type> must be NULL)
     92 
     93 =item HMAC
     94 
     95 Supports any digest
     96 
     97 =item CMAC, Poly1305 and Siphash
     98 
     99 Will ignore any digest provided.
    100 
    101 =back
    102 
    103 If RSA-PSS is used and restrictions apply then the digest must match.
    104 
    105 EVP_DigestVerifyInit() works in the same way as
    106 EVP_DigestVerifyInit_ex() except that the B<mdname> parameter will be
    107 inferred from the supplied digest B<type>, and B<props> will be NULL. Where
    108 supplied the ENGINE B<e> will be used for the signature verification and digest
    109 algorithm implementations. B<e> may be NULL.
    110 
    111 EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
    112 verification context B<ctx>. This function can be called several times on the
    113 same B<ctx> to include additional data.
    114 
    115 EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in
    116 B<sig> of length B<siglen>.
    117 
    118 EVP_DigestVerify() verifies B<tbslen> bytes at B<tbs> against the signature
    119 in B<sig> of length B<siglen>.
    120 
    121 =head1 RETURN VALUES
    122 
    123 EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0
    124 for failure.
    125 
    126 EVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other
    127 value indicates failure.  A return value of zero indicates that the signature
    128 did not verify successfully (that is, B<tbs> did not match the original data or
    129 the signature had an invalid form), while other values indicate a more serious
    130 error (and sometimes also indicate an invalid signature form).
    131 
    132 The error codes can be obtained from L<ERR_get_error(3)>.
    133 
    134 =head1 NOTES
    135 
    136 The B<EVP> interface to digital signatures should almost always be used in
    137 preference to the low-level interfaces. This is because the code then becomes
    138 transparent to the algorithm used and much more flexible.
    139 
    140 EVP_DigestVerify() is a one shot operation which verifies a single block of
    141 data in one function. For algorithms that support streaming it is equivalent
    142 to calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). For
    143 algorithms which do not support streaming (e.g. PureEdDSA) it is the only way
    144 to verify data.
    145 
    146 In previous versions of OpenSSL there was a link between message digest types
    147 and public key algorithms. This meant that "clone" digests such as EVP_dss1()
    148 needed to be used to sign using SHA1 and DSA. This is no longer necessary and
    149 the use of clone digest is now discouraged.
    150 
    151 For some key types and parameters the random number generator must be seeded.
    152 If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
    153 external circumstances (see L<RAND(7)>), the operation will fail.
    154 
    155 The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest
    156 context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can
    157 be called later to digest and verify additional data.
    158 
    159 EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex() functions can be called
    160 multiple times on a context and the parameters set by previous calls should be
    161 preserved if the I<pkey> parameter is NULL. The call then just resets the state
    162 of the I<ctx>.
    163 
    164 Ignoring failure returns of EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex()
    165 functions can lead to subsequent undefined behavior when calling
    166 EVP_DigestVerifyUpdate(), EVP_DigestVerifyFinal(), or EVP_DigestVerify().
    167 
    168 =head1 SEE ALSO
    169 
    170 L<EVP_DigestSignInit(3)>,
    171 L<EVP_DigestInit(3)>,
    172 L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
    173 L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
    174 L<SHA1(3)>, L<openssl-dgst(1)>,
    175 L<RAND(7)>
    176 
    177 =head1 HISTORY
    178 
    179 EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal()
    180 were added in OpenSSL 1.0.0.
    181 
    182 EVP_DigestVerifyInit_ex() was added in OpenSSL 3.0.
    183 
    184 EVP_DigestVerifyUpdate() was converted from a macro to a function in OpenSSL
    185 3.0.
    186 
    187 =head1 COPYRIGHT
    188 
    189 Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved.
    190 
    191 Licensed under the Apache License 2.0 (the "License").  You may not use
    192 this file except in compliance with the License.  You can obtain a copy
    193 in the file LICENSE in the source distribution or at
    194 L<https://www.openssl.org/source/license.html>.
    195 
    196 =cut
    197