Rename OSSL_SERIALIZER / OSSL_DESERIALIZER to OSSL_ENCODE / OSSL_DECODE
[openssl.git] / doc / man3 / EVP_SignInit.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate,
6 EVP_SignFinal_with_libctx, EVP_SignFinal
7 - EVP signing functions
8
9 =head1 SYNOPSIS
10
11  #include <openssl/evp.h>
12
13  int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
14  int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
15  int EVP_SignFinal_with_libctx(EVP_MD_CTX *ctx, unsigned char *md,
16                                unsigned int *s, EVP_PKEY *pkey,
17                                OPENSSL_CTX *libctx, const char *propq);
18  int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sig, unsigned int *s,
19                    EVP_PKEY *pkey);
20
21  void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
22
23 =head1 DESCRIPTION
24
25 The EVP signature routines are a high-level interface to digital
26 signatures.
27
28 EVP_SignInit_ex() sets up signing context I<ctx> to use digest
29 I<type> from B<ENGINE> I<impl>. I<ctx> must be created with
30 EVP_MD_CTX_new() before calling this function.
31
32 EVP_SignUpdate() hashes I<cnt> bytes of data at I<d> into the
33 signature context I<ctx>. This function can be called several times on the
34 same I<ctx> to include additional data.
35
36 EVP_SignFinal_with_libctx() signs the data in I<ctx> using the private key
37 I<pkey> and places the signature in I<sig>. The library context I<libctx> and
38 property query I<propq> are used when creating a context to use with the key
39 I<pkey>. I<sig> must be at least C<EVP_PKEY_size(pkey)> bytes in size. I<s> is
40 an OUT parameter, and not used as an IN parameter.
41 The number of bytes of data written (i.e. the length of the signature)
42 will be written to the integer at I<s>, at most C<EVP_PKEY_size(pkey)> bytes
43 will be written.
44
45 EVP_SignFinal() is similar to EVP_SignFinal_with_libctx() but uses default
46 values of NULL for the library context I<libctx> and the property query I<propq>.
47
48 EVP_SignInit() initializes a signing context I<ctx> to use the default
49 implementation of digest I<type>.
50
51 =head1 RETURN VALUES
52
53 EVP_SignInit_ex(), EVP_SignUpdate(), EVP_SignFinal_with_libctx() and
54 EVP_SignFinal() return 1 for success and 0 for failure.
55
56 The error codes can be obtained by L<ERR_get_error(3)>.
57
58 =head1 NOTES
59
60 The B<EVP> interface to digital signatures should almost always be used in
61 preference to the low-level interfaces. This is because the code then becomes
62 transparent to the algorithm used and much more flexible.
63
64 When signing with DSA private keys the random number generator must be seeded.
65 If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
66 external circumstances (see L<RAND(7)>), the operation will fail.
67 This requirement does not hold for RSA signatures.
68
69 The call to EVP_SignFinal() internally finalizes a copy of the digest context.
70 This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
71 later to digest and sign additional data.
72
73 Since only a copy of the digest context is ever finalized the context must
74 be cleaned up after use by calling EVP_MD_CTX_free() or a memory leak
75 will occur.
76
77 =head1 BUGS
78
79 Older versions of this documentation wrongly stated that calls to
80 EVP_SignUpdate() could not be made after calling EVP_SignFinal().
81
82 Since the private key is passed in the call to EVP_SignFinal() any error
83 relating to the private key (for example an unsuitable key and digest
84 combination) will not be indicated until after potentially large amounts of
85 data have been passed through EVP_SignUpdate().
86
87 It is not possible to change the signing parameters using these function.
88
89 The previous two bugs are fixed in the newer EVP_SignDigest*() function.
90
91 =head1 SEE ALSO
92
93 L<EVP_PKEY_size(3)>, L<EVP_PKEY_bits(3)>, L<EVP_PKEY_security_bits(3)>,
94 L<EVP_VerifyInit(3)>,
95 L<EVP_DigestInit(3)>,
96 L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
97 L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
98 L<SHA1(3)>, L<openssl-dgst(1)>
99
100 =head1 HISTORY
101
102 The function EVP_SignFinal_with_libctx() was added in OpenSSL 3.0.
103
104 =head1 COPYRIGHT
105
106 Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
107
108 Licensed under the Apache License 2.0 (the "License").  You may not use
109 this file except in compliance with the License.  You can obtain a copy
110 in the file LICENSE in the source distribution or at
111 L<https://www.openssl.org/source/license.html>.
112
113 =cut