xref: /freebsd/crypto/openssl/doc/man3/EVP_SignInit.pod (revision 17f01e9963948a18f55eb97173123702c5dae671)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5*17f01e99SJung-uk KimEVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate, EVP_SignFinal
6*17f01e99SJung-uk Kim- EVP signing functions
7e71b7053SJung-uk Kim
8e71b7053SJung-uk Kim=head1 SYNOPSIS
9e71b7053SJung-uk Kim
10e71b7053SJung-uk Kim #include <openssl/evp.h>
11e71b7053SJung-uk Kim
12e71b7053SJung-uk Kim int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
13e71b7053SJung-uk Kim int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
14e71b7053SJung-uk Kim int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sig, unsigned int *s, EVP_PKEY *pkey);
15e71b7053SJung-uk Kim
16e71b7053SJung-uk Kim void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
17e71b7053SJung-uk Kim
18e71b7053SJung-uk Kim=head1 DESCRIPTION
19e71b7053SJung-uk Kim
20e71b7053SJung-uk KimThe EVP signature routines are a high level interface to digital
21e71b7053SJung-uk Kimsignatures.
22e71b7053SJung-uk Kim
23*17f01e99SJung-uk KimEVP_SignInit_ex() sets up signing context I<ctx> to use digest
24*17f01e99SJung-uk KimI<type> from B<ENGINE> I<impl>. I<ctx> must be created with
25e71b7053SJung-uk KimEVP_MD_CTX_new() before calling this function.
26e71b7053SJung-uk Kim
27*17f01e99SJung-uk KimEVP_SignUpdate() hashes I<cnt> bytes of data at I<d> into the
28*17f01e99SJung-uk Kimsignature context I<ctx>. This function can be called several times on the
29*17f01e99SJung-uk Kimsame I<ctx> to include additional data.
30e71b7053SJung-uk Kim
31*17f01e99SJung-uk KimEVP_SignFinal() signs the data in I<ctx> using the private key I<pkey> and
32*17f01e99SJung-uk Kimplaces the signature in I<sig>. I<sig> must be at least C<EVP_PKEY_size(pkey)>
33*17f01e99SJung-uk Kimbytes in size. I<s> is an OUT parameter, and not used as an IN parameter.
34e71b7053SJung-uk KimThe number of bytes of data written (i.e. the length of the signature)
35*17f01e99SJung-uk Kimwill be written to the integer at I<s>, at most C<EVP_PKEY_size(pkey)> bytes
36e71b7053SJung-uk Kimwill be written.
37e71b7053SJung-uk Kim
38*17f01e99SJung-uk KimEVP_SignInit() initializes a signing context I<ctx> to use the default
39*17f01e99SJung-uk Kimimplementation of digest I<type>.
40e71b7053SJung-uk Kim
41e71b7053SJung-uk Kim=head1 RETURN VALUES
42e71b7053SJung-uk Kim
43e71b7053SJung-uk KimEVP_SignInit_ex(), EVP_SignUpdate() and EVP_SignFinal() return 1
44e71b7053SJung-uk Kimfor success and 0 for failure.
45e71b7053SJung-uk Kim
46e71b7053SJung-uk KimThe error codes can be obtained by L<ERR_get_error(3)>.
47e71b7053SJung-uk Kim
48e71b7053SJung-uk Kim=head1 NOTES
49e71b7053SJung-uk Kim
50e71b7053SJung-uk KimThe B<EVP> interface to digital signatures should almost always be used in
51e71b7053SJung-uk Kimpreference to the low level interfaces. This is because the code then becomes
52e71b7053SJung-uk Kimtransparent to the algorithm used and much more flexible.
53e71b7053SJung-uk Kim
54da327cd2SJung-uk KimWhen signing with DSA private keys the random number generator must be seeded.
55da327cd2SJung-uk KimIf the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
56da327cd2SJung-uk Kimexternal circumstances (see L<RAND(7)>), the operation will fail.
57da327cd2SJung-uk KimThis requirement does not hold for RSA signatures.
58e71b7053SJung-uk Kim
59e71b7053SJung-uk KimThe call to EVP_SignFinal() internally finalizes a copy of the digest context.
60e71b7053SJung-uk KimThis means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
61e71b7053SJung-uk Kimlater to digest and sign additional data.
62e71b7053SJung-uk Kim
63e71b7053SJung-uk KimSince only a copy of the digest context is ever finalized the context must
64e71b7053SJung-uk Kimbe cleaned up after use by calling EVP_MD_CTX_free() or a memory leak
65e71b7053SJung-uk Kimwill occur.
66e71b7053SJung-uk Kim
67e71b7053SJung-uk Kim=head1 BUGS
68e71b7053SJung-uk Kim
69e71b7053SJung-uk KimOlder versions of this documentation wrongly stated that calls to
70e71b7053SJung-uk KimEVP_SignUpdate() could not be made after calling EVP_SignFinal().
71e71b7053SJung-uk Kim
72e71b7053SJung-uk KimSince the private key is passed in the call to EVP_SignFinal() any error
73e71b7053SJung-uk Kimrelating to the private key (for example an unsuitable key and digest
74e71b7053SJung-uk Kimcombination) will not be indicated until after potentially large amounts of
75e71b7053SJung-uk Kimdata have been passed through EVP_SignUpdate().
76e71b7053SJung-uk Kim
77e71b7053SJung-uk KimIt is not possible to change the signing parameters using these function.
78e71b7053SJung-uk Kim
79e71b7053SJung-uk KimThe previous two bugs are fixed in the newer EVP_SignDigest*() function.
80e71b7053SJung-uk Kim
81e71b7053SJung-uk Kim=head1 SEE ALSO
82e71b7053SJung-uk Kim
83*17f01e99SJung-uk KimL<EVP_PKEY_size(3)>, L<EVP_PKEY_bits(3)>, L<EVP_PKEY_security_bits(3)>,
84e71b7053SJung-uk KimL<EVP_VerifyInit(3)>,
85e71b7053SJung-uk KimL<EVP_DigestInit(3)>,
86e71b7053SJung-uk KimL<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
87e71b7053SJung-uk KimL<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
88e71b7053SJung-uk KimL<SHA1(3)>, L<dgst(1)>
89e71b7053SJung-uk Kim
90e71b7053SJung-uk Kim=head1 COPYRIGHT
91e71b7053SJung-uk Kim
92*17f01e99SJung-uk KimCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
93e71b7053SJung-uk Kim
94e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
95e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
96e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
97e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
98e71b7053SJung-uk Kim
99e71b7053SJung-uk Kim=cut
100