
#use wml::openssl-macros area=docs page=EVP_DigestSignInit

<title>Documents, EVP_DigestSignInit(3)</title>

<h1>EVP_DigestSignInit(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
EVP_DigestSignInit, EVP_DigestSignUpdate, EVP_DigestSignFinal - EVP signing
functions

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/evp.h&gt;
</PRE>
<PRE> int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
                        const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
 int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
 int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
The EVP signature routines are a high level interface to digital
signatures.

</P>
<P>
<CODE>EVP_DigestSignInit()</CODE> sets up signing context <STRONG>ctx</STRONG> to use digest <STRONG>type</STRONG> from ENGINE <STRONG>impl</STRONG> and private key <STRONG>pkey</STRONG>. <STRONG>ctx</STRONG> must be initialized with <CODE>EVP_MD_CTX_init()</CODE> before calling this
function. If <STRONG>pctx</STRONG> is not NULL the EVP_PKEY_CTX of the signing operation will be written to <STRONG>*pctx</STRONG>: this can be used to set alternative signing options.

</P>
<P>
<CODE>EVP_DigestSignUpdate()</CODE> hashes <STRONG>cnt</STRONG> bytes of data at <STRONG>d</STRONG> into the signature context <STRONG>ctx</STRONG>. This function can be called several times on the same <STRONG>ctx</STRONG> to include additional data. This function is currently implemented usig a
macro.

</P>
<P>
<CODE>EVP_DigestSignFinal()</CODE> signs the data in <STRONG>ctx</STRONG> places the signature in <STRONG>sig</STRONG>. If <STRONG>sig</STRONG> is <STRONG>NULL</STRONG> then the maximum size of the output buffer is written to the <STRONG>siglen</STRONG> parameter. If <STRONG>sig</STRONG> is not <STRONG>NULL</STRONG> then before the call the
<STRONG>siglen</STRONG> parameter should contain the length of the <STRONG>sig</STRONG> buffer, if the call is successful the signature is written to <STRONG>sig</STRONG> and the amount of data written to <STRONG>siglen</STRONG>.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>EVP_DigestSignInit()</CODE> <CODE>EVP_DigestSignUpdate()</CODE> and
<CODE>EVP_DigestSignaFinal()</CODE> return 1 for success and 0 or a
negative value for failure. In particular a return value of -2 indicates
the operation is not supported by the public key algorithm.

</P>
<P>
The error codes can be obtained from <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
The <STRONG>EVP</STRONG> interface to digital signatures should almost always be used in preference
to the low level interfaces. This is because the code then becomes
transparent to the algorithm used and much more flexible.

</P>
<P>
In previous versions of OpenSSL there was a link between message digest
types and public key algorithms. This meant that ``clone'' digests such as
<CODE>EVP_dss1()</CODE> needed to be used to sign using SHA1 and DSA. This
is no longer necessary and the use of clone digest is now discouraged.

</P>
<P>
For some key types and parameters the random number generator must be
seeded or the operation will fail. 

</P>
<P>
The call to <CODE>EVP_DigestSignFinal()</CODE> internally finalizes a copy
of the digest context. This means that calls to
<CODE>EVP_DigestSignUpdate()</CODE> and <CODE>EVP_DigestSignFinal()</CODE>
can be called later to digest and sign additional data.

</P>
<P>
Since only a copy of the digest context is ever finalized the context must
be cleaned up after use by calling <CODE>EVP_MD_CTX_cleanup()</CODE> or a
memory leak will occur.

</P>
<P>
The use of <CODE>EVP_PKEY_size()</CODE> with these functions is discouraged
because some signature operations may have a signature length which depends
on the parameters set. As a result <CODE>EVP_PKEY_size()</CODE> would have
to return a value which indicates the maximum possible signature for any
set of parameters.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/EVP_DigestVerifyInit.html#">EVP_DigestVerifyInit(3)</A>,
<A HREF="../crypto/EVP_DigestInit.html#">EVP_DigestInit(3)</A>, <A HREF="../crypto/err.html#">err(3)</A>,
<A HREF="../crypto/evp.html#">evp(3)</A>, <A HREF="../crypto/hmac.html#">hmac(3)</A>, <A HREF="../crypto/md5.html#">md2(3)</A>,
<A HREF="../crypto/md5.html#">md5(3)</A>, <A HREF="../crypto/mdc2.html#">mdc2(3)</A>, <A HREF="../crypto/ripemd.html#">ripemd(3)</A>,
<A HREF="../crypto/sha.html#">sha(3)</A>, <A HREF="../apps/dgst.html#">dgst(1)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>EVP_DigestSignInit(),</CODE> <CODE>EVP_DigestSignUpdate()</CODE> and
<CODE>EVP_DigestSignFinal()</CODE> were first added to OpenSSL 1.0.0.

</P>
:}

