EVP_SignInit.pod 4.1 KB
Newer Older
1 2 3 4
=pod

=head1 NAME

5 6
EVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate,
EVP_SignFinal_with_libctx, EVP_SignFinal
7
- EVP signing functions
8 9 10 11 12

=head1 SYNOPSIS

 #include <openssl/evp.h>

D
Dr. Stephen Henson 已提交
13 14
 int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
 int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
15 16 17 18 19
 int EVP_SignFinal_with_libctx(EVP_MD_CTX *ctx, unsigned char *md,
                               unsigned int *s, EVP_PKEY *pkey,
                               OPENSSL_CTX *libctx, const char *propq);
 int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sig, unsigned int *s,
                   EVP_PKEY *pkey);
20

D
Dr. Stephen Henson 已提交
21 22
 void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);

23 24
=head1 DESCRIPTION

G
Gustaf Neumann 已提交
25
The EVP signature routines are a high-level interface to digital
26 27
signatures.

28 29
EVP_SignInit_ex() sets up signing context I<ctx> to use digest
I<type> from B<ENGINE> I<impl>. I<ctx> must be created with
R
Richard Levitte 已提交
30
EVP_MD_CTX_new() before calling this function.
31

32 33 34
EVP_SignUpdate() hashes I<cnt> bytes of data at I<d> into the
signature context I<ctx>. This function can be called several times on the
same I<ctx> to include additional data.
35

36 37 38 39 40
EVP_SignFinal_with_libctx() signs the data in I<ctx> using the private key
I<pkey> and places the signature in I<sig>. The library context I<libctx> and
property query I<propq> are used when creating a context to use with the key
I<pkey>. I<sig> must be at least C<EVP_PKEY_size(pkey)> bytes in size. I<s> is
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.
D
Dr. Stephen Henson 已提交
44

45 46 47
EVP_SignFinal() is similar to EVP_SignFinal_with_libctx() but uses default
values of NULL for the library context I<libctx> and the property query I<propq>.

48 49
EVP_SignInit() initializes a signing context I<ctx> to use the default
implementation of digest I<type>.
50 51 52

=head1 RETURN VALUES

53 54
EVP_SignInit_ex(), EVP_SignUpdate(), EVP_SignFinal_with_libctx() and
EVP_SignFinal() return 1 for success and 0 for failure.
55

R
Rich Salz 已提交
56
The error codes can be obtained by L<ERR_get_error(3)>.
57 58 59 60

=head1 NOTES

The B<EVP> interface to digital signatures should almost always be used in
G
Gustaf Neumann 已提交
61
preference to the low-level interfaces. This is because the code then becomes
62 63
transparent to the algorithm used and much more flexible.

64 65 66 67
When signing with DSA private keys the random number generator must be seeded.
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
external circumstances (see L<RAND(7)>), the operation will fail.
This requirement does not hold for RSA signatures.
68

D
Dr. Stephen Henson 已提交
69 70 71 72 73
The call to EVP_SignFinal() internally finalizes a copy of the digest context.
This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
later to digest and sign additional data.

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
D
Dr. Stephen Henson 已提交
75 76
will occur.

77 78
=head1 BUGS

R
Rich Salz 已提交
79
Older versions of this documentation wrongly stated that calls to
D
Dr. Stephen Henson 已提交
80
EVP_SignUpdate() could not be made after calling EVP_SignFinal().
81

82 83 84 85 86 87 88 89 90
Since the private key is passed in the call to EVP_SignFinal() any error
relating to the private key (for example an unsuitable key and digest
combination) will not be indicated until after potentially large amounts of
data have been passed through EVP_SignUpdate().

It is not possible to change the signing parameters using these function.

The previous two bugs are fixed in the newer EVP_SignDigest*() function.

91 92
=head1 SEE ALSO

93
L<EVP_PKEY_size(3)>, L<EVP_PKEY_bits(3)>, L<EVP_PKEY_security_bits(3)>,
R
Rich Salz 已提交
94
L<EVP_VerifyInit(3)>,
95
L<EVP_DigestInit(3)>,
96 97
L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
98
L<SHA1(3)>, L<openssl-dgst(1)>
99

100 101 102 103
=head1 HISTORY

The function EVP_SignFinal_with_libctx() was added in OpenSSL 3.0.

R
Rich Salz 已提交
104 105
=head1 COPYRIGHT

M
Matt Caswell 已提交
106
Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
R
Rich Salz 已提交
107

108
Licensed under the Apache License 2.0 (the "License").  You may not use
R
Rich Salz 已提交
109 110 111 112 113
this file except in compliance with the License.  You can obtain a copy
in the file LICENSE in the source distribution or at
L<https://www.openssl.org/source/license.html>.

=cut