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