xref: /onnv-gate/usr/src/common/openssl/doc/crypto/EVP_SignInit.pod (revision 2175:b0b2f052a486)
1*2175Sjp161948=pod
2*2175Sjp161948
3*2175Sjp161948=head1 NAME
4*2175Sjp161948
5*2175Sjp161948EVP_SignInit, EVP_SignUpdate, EVP_SignFinal - EVP signing functions
6*2175Sjp161948
7*2175Sjp161948=head1 SYNOPSIS
8*2175Sjp161948
9*2175Sjp161948 #include <openssl/evp.h>
10*2175Sjp161948
11*2175Sjp161948 int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
12*2175Sjp161948 int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13*2175Sjp161948 int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey);
14*2175Sjp161948
15*2175Sjp161948 void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
16*2175Sjp161948
17*2175Sjp161948 int EVP_PKEY_size(EVP_PKEY *pkey);
18*2175Sjp161948
19*2175Sjp161948=head1 DESCRIPTION
20*2175Sjp161948
21*2175Sjp161948The EVP signature routines are a high level interface to digital
22*2175Sjp161948signatures.
23*2175Sjp161948
24*2175Sjp161948EVP_SignInit_ex() sets up signing context B<ctx> to use digest
25*2175Sjp161948B<type> from ENGINE B<impl>. B<ctx> must be initialized with
26*2175Sjp161948EVP_MD_CTX_init() before calling this function.
27*2175Sjp161948
28*2175Sjp161948EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the
29*2175Sjp161948signature context B<ctx>. This function can be called several times on the
30*2175Sjp161948same B<ctx> to include additional data.
31*2175Sjp161948
32*2175Sjp161948EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey> and
33*2175Sjp161948places the signature in B<sig>. The number of bytes of data written (i.e. the
34*2175Sjp161948length of the signature) will be written to the integer at B<s>, at most
35*2175Sjp161948EVP_PKEY_size(pkey) bytes will be written.
36*2175Sjp161948
37*2175Sjp161948EVP_SignInit() initializes a signing context B<ctx> to use the default
38*2175Sjp161948implementation of digest B<type>.
39*2175Sjp161948
40*2175Sjp161948EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual
41*2175Sjp161948signature returned by EVP_SignFinal() may be smaller.
42*2175Sjp161948
43*2175Sjp161948=head1 RETURN VALUES
44*2175Sjp161948
45*2175Sjp161948EVP_SignInit_ex(), EVP_SignUpdate() and EVP_SignFinal() return 1
46*2175Sjp161948for success and 0 for failure.
47*2175Sjp161948
48*2175Sjp161948EVP_PKEY_size() returns the maximum size of a signature in bytes.
49*2175Sjp161948
50*2175Sjp161948The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
51*2175Sjp161948
52*2175Sjp161948=head1 NOTES
53*2175Sjp161948
54*2175Sjp161948The B<EVP> interface to digital signatures should almost always be used in
55*2175Sjp161948preference to the low level interfaces. This is because the code then becomes
56*2175Sjp161948transparent to the algorithm used and much more flexible.
57*2175Sjp161948
58*2175Sjp161948Due to the link between message digests and public key algorithms the correct
59*2175Sjp161948digest algorithm must be used with the correct public key type. A list of
60*2175Sjp161948algorithms and associated public key algorithms appears in
61*2175Sjp161948L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
62*2175Sjp161948
63*2175Sjp161948When signing with DSA private keys the random number generator must be seeded
64*2175Sjp161948or the operation will fail. The random number generator does not need to be
65*2175Sjp161948seeded for RSA signatures.
66*2175Sjp161948
67*2175Sjp161948The call to EVP_SignFinal() internally finalizes a copy of the digest context.
68*2175Sjp161948This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
69*2175Sjp161948later to digest and sign additional data.
70*2175Sjp161948
71*2175Sjp161948Since only a copy of the digest context is ever finalized the context must
72*2175Sjp161948be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
73*2175Sjp161948will occur.
74*2175Sjp161948
75*2175Sjp161948=head1 BUGS
76*2175Sjp161948
77*2175Sjp161948Older versions of this documentation wrongly stated that calls to
78*2175Sjp161948EVP_SignUpdate() could not be made after calling EVP_SignFinal().
79*2175Sjp161948
80*2175Sjp161948=head1 SEE ALSO
81*2175Sjp161948
82*2175Sjp161948L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
83*2175Sjp161948L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
84*2175Sjp161948L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
85*2175Sjp161948L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
86*2175Sjp161948L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
87*2175Sjp161948
88*2175Sjp161948=head1 HISTORY
89*2175Sjp161948
90*2175Sjp161948EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are
91*2175Sjp161948available in all versions of SSLeay and OpenSSL.
92*2175Sjp161948
93*2175Sjp161948EVP_SignInit_ex() was added in OpenSSL 0.9.7.
94*2175Sjp161948
95*2175Sjp161948=cut
96