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