1.\" $OpenBSD: EVP_SignInit.3,v 1.21 2024/12/06 12:51:13 schwarze Exp $ 2.\" full merge up to: OpenSSL 6328d367 Jul 4 21:58:30 2020 +0200 3.\" 4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" Copyright (c) 2000-2002, 2005, 2006, 2014-2016 The OpenSSL Project. 6.\" All rights reserved. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in 17.\" the documentation and/or other materials provided with the 18.\" distribution. 19.\" 20.\" 3. All advertising materials mentioning features or use of this 21.\" software must display the following acknowledgment: 22.\" "This product includes software developed by the OpenSSL Project 23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24.\" 25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26.\" endorse or promote products derived from this software without 27.\" prior written permission. For written permission, please contact 28.\" openssl-core@openssl.org. 29.\" 30.\" 5. Products derived from this software may not be called "OpenSSL" 31.\" nor may "OpenSSL" appear in their names without prior written 32.\" permission of the OpenSSL Project. 33.\" 34.\" 6. Redistributions of any form whatsoever must retain the following 35.\" acknowledgment: 36.\" "This product includes software developed by the OpenSSL Project 37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38.\" 39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 51.\" 52.Dd $Mdocdate: December 6 2024 $ 53.Dt EVP_SIGNINIT 3 54.Os 55.Sh NAME 56.Nm EVP_SignInit_ex , 57.Nm EVP_SignUpdate , 58.Nm EVP_SignFinal , 59.Nm EVP_SignInit 60.Nd EVP signing functions 61.Sh SYNOPSIS 62.In openssl/evp.h 63.Ft int 64.Fo EVP_SignInit_ex 65.Fa "EVP_MD_CTX *ctx" 66.Fa "const EVP_MD *type" 67.Fa "ENGINE *engine" 68.Fc 69.Ft int 70.Fo EVP_SignUpdate 71.Fa "EVP_MD_CTX *ctx" 72.Fa "const void *d" 73.Fa "unsigned int cnt" 74.Fc 75.Ft int 76.Fo EVP_SignFinal 77.Fa "EVP_MD_CTX *ctx" 78.Fa "unsigned char *sig" 79.Fa "unsigned int *s" 80.Fa "EVP_PKEY *pkey" 81.Fc 82.Ft void 83.Fo EVP_SignInit 84.Fa "EVP_MD_CTX *ctx" 85.Fa "const EVP_MD *type" 86.Fc 87.Sh DESCRIPTION 88The EVP signature routines are a high-level interface to digital 89signatures. 90.Pp 91.Fn EVP_SignInit_ex 92sets up the signing context 93.Fa ctx 94to use the digest 95.Fa type . 96Before calling this function, obtain 97.Fa ctx 98from 99.Xr EVP_MD_CTX_new 3 100or call 101.Xr EVP_MD_CTX_reset 3 102on it. 103The 104.Fa engine 105argument is always ignored and passing 106.Dv NULL 107is recommended. 108.Pp 109.Fn EVP_SignUpdate 110hashes 111.Fa cnt 112bytes of data at 113.Fa d 114into the signature context 115.Fa ctx . 116This function can be called several times on the same 117.Fa ctx 118to include additional data. 119.Pp 120.Fn EVP_SignFinal 121signs the data in 122.Fa ctx 123using the private key 124.Fa pkey 125and places the signature in 126.Fa sig . 127.Fa sig 128must be at least 129.Xr EVP_PKEY_size 3 130bytes in size. 131.Fa s 132is an OUT parameter, and not used as an IN parameter. 133The number of bytes of data written (i.e.\& 134the length of the signature) will be written to the integer at 135.Fa s . 136At most 137.Xr EVP_PKEY_size 3 138bytes will be written. 139.Pp 140.Fn EVP_SignInit 141initializes a signing context 142.Fa ctx 143to use the default implementation of digest 144.Fa type . 145.Pp 146The EVP interface to digital signatures should almost always be 147used in preference to the low-level interfaces. 148This is because the code then becomes transparent to the algorithm used 149and much more flexible. 150.Pp 151The call to 152.Fn EVP_SignFinal 153internally finalizes a copy of the digest context. 154This means that calls to 155.Fn EVP_SignUpdate 156and 157.Fn EVP_SignFinal 158can be called later to digest and sign additional data. 159.Pp 160Since only a copy of the digest context is ever finalized, the context 161must be cleaned up after use by calling 162.Xr EVP_MD_CTX_free 3 163or a memory leak will occur. 164.Pp 165.Fn EVP_SignInit_ex , 166.Fn EVP_SignUpdate , 167and 168.Fn EVP_SignInit 169are implemented as macros. 170.Sh RETURN VALUES 171.Fn EVP_SignInit_ex , 172.Fn EVP_SignUpdate , 173and 174.Fn EVP_SignFinal 175return 1 for success and 0 for failure. 176.Pp 177The error codes can be obtained by 178.Xr ERR_get_error 3 . 179.Sh SEE ALSO 180.Xr evp 3 , 181.Xr EVP_DigestInit 3 , 182.Xr EVP_PKEY_size 3 , 183.Xr EVP_VerifyInit 3 184.Sh HISTORY 185.Fn EVP_SignInit , 186.Fn EVP_SignUpdate , 187and 188.Fn EVP_SignFinal 189first appeared in SSLeay 0.5.1 and have been available since 190.Ox 2.4 . 191.Pp 192.Fn EVP_SignInit_ex 193first appeared in OpenSSL 0.9.7 and has been available since 194.Ox 3.2 . 195.Sh BUGS 196Older versions of this documentation wrongly stated that calls to 197.Fn EVP_SignUpdate 198could not be made after calling 199.Fn EVP_SignFinal . 200.Pp 201Since the private key is passed in the call to 202.Fn EVP_SignFinal , 203any error relating to the private key (for example an unsuitable key and 204digest combination) will not be indicated until after potentially large 205amounts of data have been passed through 206.Fn EVP_SignUpdate . 207.Pp 208It is not possible to change the signing parameters using these 209function. 210.Pp 211The previous two bugs are fixed in the newer EVP_DigestSign* function. 212