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.6  christos EVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate,
      6  1.1.1.6  christos EVP_SignFinal_ex, EVP_SignFinal
      7  1.1.1.4  christos - EVP signing functions
      8      1.1  christos 
      9      1.1  christos =head1 SYNOPSIS
     10      1.1  christos 
     11      1.1  christos  #include <openssl/evp.h>
     12      1.1  christos 
     13      1.1  christos  int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
     14      1.1  christos  int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
     15  1.1.1.6  christos  int EVP_SignFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
     16  1.1.1.6  christos                       EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *propq);
     17  1.1.1.6  christos  int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sig, unsigned int *s,
     18  1.1.1.6  christos                    EVP_PKEY *pkey);
     19      1.1  christos 
     20      1.1  christos  void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
     21      1.1  christos 
     22      1.1  christos =head1 DESCRIPTION
     23      1.1  christos 
     24  1.1.1.5  christos The EVP signature routines are a high-level interface to digital
     25      1.1  christos signatures.
     26      1.1  christos 
     27  1.1.1.4  christos EVP_SignInit_ex() sets up signing context I<ctx> to use digest
     28  1.1.1.4  christos I<type> from B<ENGINE> I<impl>. I<ctx> must be created with
     29      1.1  christos EVP_MD_CTX_new() before calling this function.
     30      1.1  christos 
     31  1.1.1.4  christos EVP_SignUpdate() hashes I<cnt> bytes of data at I<d> into the
     32  1.1.1.4  christos signature context I<ctx>. This function can be called several times on the
     33  1.1.1.4  christos same I<ctx> to include additional data.
     34  1.1.1.4  christos 
     35  1.1.1.6  christos EVP_SignFinal_ex() signs the data in I<ctx> using the private key
     36  1.1.1.6  christos I<pkey> and places the signature in I<sig>. The library context I<libctx> and
     37  1.1.1.6  christos property query I<propq> are used when creating a context to use with the key
     38  1.1.1.6  christos I<pkey>. I<sig> must be at least C<EVP_PKEY_get_size(pkey)> bytes in size.
     39  1.1.1.6  christos I<s> is an OUT parameter, and not used as an IN parameter.
     40      1.1  christos The number of bytes of data written (i.e. the length of the signature)
     41  1.1.1.6  christos will be written to the integer at I<s>, at most C<EVP_PKEY_get_size(pkey)>
     42  1.1.1.6  christos bytes will be written.
     43  1.1.1.6  christos 
     44  1.1.1.6  christos EVP_SignFinal() is similar to EVP_SignFinal_ex() but uses default
     45  1.1.1.6  christos values of NULL for the library context I<libctx> and the property query I<propq>.
     46      1.1  christos 
     47  1.1.1.4  christos EVP_SignInit() initializes a signing context I<ctx> to use the default
     48  1.1.1.4  christos implementation of digest I<type>.
     49      1.1  christos 
     50      1.1  christos =head1 RETURN VALUES
     51      1.1  christos 
     52  1.1.1.6  christos EVP_SignInit_ex(), EVP_SignUpdate(), EVP_SignFinal_ex() and
     53  1.1.1.6  christos EVP_SignFinal() return 1 for success and 0 for failure.
     54      1.1  christos 
     55      1.1  christos The error codes can be obtained by L<ERR_get_error(3)>.
     56      1.1  christos 
     57      1.1  christos =head1 NOTES
     58      1.1  christos 
     59      1.1  christos The B<EVP> interface to digital signatures should almost always be used in
     60  1.1.1.5  christos preference to the low-level interfaces. This is because the code then becomes
     61      1.1  christos transparent to the algorithm used and much more flexible.
     62      1.1  christos 
     63  1.1.1.6  christos When signing with some private key types the random number generator must
     64  1.1.1.6  christos be seeded. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails
     65  1.1.1.6  christos due to external circumstances (see L<RAND(7)>), the operation will fail.
     66      1.1  christos 
     67      1.1  christos The call to EVP_SignFinal() internally finalizes a copy of the digest context.
     68      1.1  christos This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
     69      1.1  christos later to digest and sign additional data.
     70      1.1  christos 
     71      1.1  christos Since only a copy of the digest context is ever finalized the context must
     72      1.1  christos be cleaned up after use by calling EVP_MD_CTX_free() or a memory leak
     73      1.1  christos will occur.
     74      1.1  christos 
     75      1.1  christos =head1 BUGS
     76      1.1  christos 
     77      1.1  christos Older versions of this documentation wrongly stated that calls to
     78      1.1  christos EVP_SignUpdate() could not be made after calling EVP_SignFinal().
     79      1.1  christos 
     80      1.1  christos Since the private key is passed in the call to EVP_SignFinal() any error
     81      1.1  christos relating to the private key (for example an unsuitable key and digest
     82      1.1  christos combination) will not be indicated until after potentially large amounts of
     83      1.1  christos data have been passed through EVP_SignUpdate().
     84      1.1  christos 
     85      1.1  christos It is not possible to change the signing parameters using these function.
     86      1.1  christos 
     87  1.1.1.6  christos The previous two bugs are fixed in the newer EVP_DigestSign*() functions.
     88      1.1  christos 
     89      1.1  christos =head1 SEE ALSO
     90      1.1  christos 
     91  1.1.1.6  christos L<EVP_PKEY_get_size(3)>, L<EVP_PKEY_get_bits(3)>,
     92  1.1.1.6  christos L<EVP_PKEY_get_security_bits(3)>,
     93      1.1  christos L<EVP_VerifyInit(3)>,
     94      1.1  christos L<EVP_DigestInit(3)>,
     95      1.1  christos L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
     96      1.1  christos L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
     97  1.1.1.6  christos L<SHA1(3)>, L<openssl-dgst(1)>
     98  1.1.1.6  christos 
     99  1.1.1.6  christos =head1 HISTORY
    100  1.1.1.6  christos 
    101  1.1.1.6  christos The function EVP_SignFinal_ex() was added in OpenSSL 3.0.
    102      1.1  christos 
    103      1.1  christos =head1 COPYRIGHT
    104      1.1  christos 
    105  1.1.1.6  christos Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
    106      1.1  christos 
    107  1.1.1.6  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    108      1.1  christos this file except in compliance with the License.  You can obtain a copy
    109      1.1  christos in the file LICENSE in the source distribution or at
    110      1.1  christos L<https://www.openssl.org/source/license.html>.
    111      1.1  christos 
    112      1.1  christos =cut
    113