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