xref: /freebsd/crypto/openssl/doc/man3/EVP_SignInit.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5*b077aed3SPierre ProncheryEVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate,
6*b077aed3SPierre ProncheryEVP_SignFinal_ex, EVP_SignFinal
717f01e99SJung-uk Kim- EVP signing functions
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim=head1 SYNOPSIS
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim #include <openssl/evp.h>
12e71b7053SJung-uk Kim
13e71b7053SJung-uk Kim int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
14e71b7053SJung-uk Kim int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
15*b077aed3SPierre Pronchery int EVP_SignFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
16*b077aed3SPierre Pronchery                      EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *propq);
17*b077aed3SPierre Pronchery int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sig, unsigned int *s,
18*b077aed3SPierre Pronchery                   EVP_PKEY *pkey);
19e71b7053SJung-uk Kim
20e71b7053SJung-uk Kim void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
21e71b7053SJung-uk Kim
22e71b7053SJung-uk Kim=head1 DESCRIPTION
23e71b7053SJung-uk Kim
2458f35182SJung-uk KimThe EVP signature routines are a high-level interface to digital
25e71b7053SJung-uk Kimsignatures.
26e71b7053SJung-uk Kim
2717f01e99SJung-uk KimEVP_SignInit_ex() sets up signing context I<ctx> to use digest
2817f01e99SJung-uk KimI<type> from B<ENGINE> I<impl>. I<ctx> must be created with
29e71b7053SJung-uk KimEVP_MD_CTX_new() before calling this function.
30e71b7053SJung-uk Kim
3117f01e99SJung-uk KimEVP_SignUpdate() hashes I<cnt> bytes of data at I<d> into the
3217f01e99SJung-uk Kimsignature context I<ctx>. This function can be called several times on the
3317f01e99SJung-uk Kimsame I<ctx> to include additional data.
34e71b7053SJung-uk Kim
35*b077aed3SPierre ProncheryEVP_SignFinal_ex() signs the data in I<ctx> using the private key
36*b077aed3SPierre ProncheryI<pkey> and places the signature in I<sig>. The library context I<libctx> and
37*b077aed3SPierre Proncheryproperty query I<propq> are used when creating a context to use with the key
38*b077aed3SPierre ProncheryI<pkey>. I<sig> must be at least C<EVP_PKEY_get_size(pkey)> bytes in size.
39*b077aed3SPierre ProncheryI<s> is an OUT parameter, and not used as an IN parameter.
40e71b7053SJung-uk KimThe number of bytes of data written (i.e. the length of the signature)
41*b077aed3SPierre Proncherywill be written to the integer at I<s>, at most C<EVP_PKEY_get_size(pkey)>
42*b077aed3SPierre Proncherybytes will be written.
43*b077aed3SPierre Pronchery
44*b077aed3SPierre ProncheryEVP_SignFinal() is similar to EVP_SignFinal_ex() but uses default
45*b077aed3SPierre Proncheryvalues of NULL for the library context I<libctx> and the property query I<propq>.
46e71b7053SJung-uk Kim
4717f01e99SJung-uk KimEVP_SignInit() initializes a signing context I<ctx> to use the default
4817f01e99SJung-uk Kimimplementation of digest I<type>.
49e71b7053SJung-uk Kim
50e71b7053SJung-uk Kim=head1 RETURN VALUES
51e71b7053SJung-uk Kim
52*b077aed3SPierre ProncheryEVP_SignInit_ex(), EVP_SignUpdate(), EVP_SignFinal_ex() and
53*b077aed3SPierre ProncheryEVP_SignFinal() return 1 for success and 0 for failure.
54e71b7053SJung-uk Kim
55e71b7053SJung-uk KimThe error codes can be obtained by L<ERR_get_error(3)>.
56e71b7053SJung-uk Kim
57e71b7053SJung-uk Kim=head1 NOTES
58e71b7053SJung-uk Kim
59e71b7053SJung-uk KimThe B<EVP> interface to digital signatures should almost always be used in
6058f35182SJung-uk Kimpreference to the low-level interfaces. This is because the code then becomes
61e71b7053SJung-uk Kimtransparent to the algorithm used and much more flexible.
62e71b7053SJung-uk Kim
63*b077aed3SPierre ProncheryWhen signing with some private key types the random number generator must
64*b077aed3SPierre Proncherybe seeded. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails
65*b077aed3SPierre Proncherydue to external circumstances (see L<RAND(7)>), the operation will fail.
66e71b7053SJung-uk Kim
67e71b7053SJung-uk KimThe call to EVP_SignFinal() internally finalizes a copy of the digest context.
68e71b7053SJung-uk KimThis means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
69e71b7053SJung-uk Kimlater to digest and sign additional data.
70e71b7053SJung-uk Kim
71e71b7053SJung-uk KimSince only a copy of the digest context is ever finalized the context must
72e71b7053SJung-uk Kimbe cleaned up after use by calling EVP_MD_CTX_free() or a memory leak
73e71b7053SJung-uk Kimwill occur.
74e71b7053SJung-uk Kim
75e71b7053SJung-uk Kim=head1 BUGS
76e71b7053SJung-uk Kim
77e71b7053SJung-uk KimOlder versions of this documentation wrongly stated that calls to
78e71b7053SJung-uk KimEVP_SignUpdate() could not be made after calling EVP_SignFinal().
79e71b7053SJung-uk Kim
80e71b7053SJung-uk KimSince the private key is passed in the call to EVP_SignFinal() any error
81e71b7053SJung-uk Kimrelating to the private key (for example an unsuitable key and digest
82e71b7053SJung-uk Kimcombination) will not be indicated until after potentially large amounts of
83e71b7053SJung-uk Kimdata have been passed through EVP_SignUpdate().
84e71b7053SJung-uk Kim
85e71b7053SJung-uk KimIt is not possible to change the signing parameters using these function.
86e71b7053SJung-uk Kim
87*b077aed3SPierre ProncheryThe previous two bugs are fixed in the newer EVP_DigestSign*() functions.
88e71b7053SJung-uk Kim
89e71b7053SJung-uk Kim=head1 SEE ALSO
90e71b7053SJung-uk Kim
91*b077aed3SPierre ProncheryL<EVP_PKEY_get_size(3)>, L<EVP_PKEY_get_bits(3)>,
92*b077aed3SPierre ProncheryL<EVP_PKEY_get_security_bits(3)>,
93e71b7053SJung-uk KimL<EVP_VerifyInit(3)>,
94e71b7053SJung-uk KimL<EVP_DigestInit(3)>,
95e71b7053SJung-uk KimL<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
96e71b7053SJung-uk KimL<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
97*b077aed3SPierre ProncheryL<SHA1(3)>, L<openssl-dgst(1)>
98*b077aed3SPierre Pronchery
99*b077aed3SPierre Pronchery=head1 HISTORY
100*b077aed3SPierre Pronchery
101*b077aed3SPierre ProncheryThe function EVP_SignFinal_ex() was added in OpenSSL 3.0.
102e71b7053SJung-uk Kim
103e71b7053SJung-uk Kim=head1 COPYRIGHT
104e71b7053SJung-uk Kim
105*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
106e71b7053SJung-uk Kim
107*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
108e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
109e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
110e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
111e71b7053SJung-uk Kim
112e71b7053SJung-uk Kim=cut
113