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

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

<h1>EVP_SealInit(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_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/evp.h&gt;
</PRE>
<PRE> int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
                  unsigned char **ek, int *ekl, unsigned char *iv,
                  EVP_PKEY **pubk, int npubk);
 int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
         int *outl, unsigned char *in, int inl);
 int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
         int *outl);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
The EVP envelope routines are a high level interface to envelope
encryption. They generate a random key and IV (if required) then
``envelope'' it by using public key encryption. Data can then be encrypted
using this key.

</P>
<P>
<CODE>EVP_SealInit()</CODE> initializes a cipher context <STRONG>ctx</STRONG> for encryption with cipher <STRONG>type</STRONG> using a random secret key and IV. <STRONG>type</STRONG> is normally supplied by a function such as <CODE>EVP_des_cbc().</CODE> The
secret key is encrypted using one or more public keys, this allows the same
encrypted data to be decrypted using any of the corresponding private keys. <STRONG>ek</STRONG> is an array of buffers where the public key encrypted secret key will be
written, each buffer must contain enough room for the corresponding
encrypted key: that is
<STRONG>ek[i]</STRONG> must have room for <STRONG>EVP_PKEY_size(pubk[i])</STRONG> bytes. The actual size of each encrypted secret key is written to the array <STRONG>ekl</STRONG>. <STRONG>pubk</STRONG> is an array of <STRONG>npubk</STRONG> public keys.

</P>
<P>
The <STRONG>iv</STRONG> parameter is a buffer where the generated IV is written to. It must contain
enough room for the corresponding cipher's IV, as determined by (for
example) <CODE>EVP_CIPHER_iv_length(type).</CODE>

</P>
<P>
If the cipher does not require an IV then the <STRONG>iv</STRONG> parameter is ignored and can be <STRONG>NULL</STRONG>.

</P>
<P>
<CODE>EVP_SealUpdate()</CODE> and <CODE>EVP_SealFinal()</CODE> have exactly
the same properties as the <CODE>EVP_EncryptUpdate()</CODE> and
<CODE>EVP_EncryptFinal()</CODE> routines, as documented on the <A HREF="../crypto/EVP_EncryptInit.html#">EVP_EncryptInit(3)</A> manual page. 

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>EVP_SealInit()</CODE> returns 0 on error or <STRONG>npubk</STRONG> if successful.

</P>
<P>
<CODE>EVP_SealUpdate()</CODE> and <CODE>EVP_SealFinal()</CODE> return 1 for
success and 0 for failure.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
Because a random secret key is generated the random number generator must
be seeded before calling <CODE>EVP_SealInit().</CODE>

</P>
<P>
The public key must be RSA because it is the only OpenSSL public key
algorithm that supports key transport.

</P>
<P>
Envelope encryption is the usual method of using public key encryption on
large amounts of data, this is because public key encryption is slow but
symmetric encryption is fast. So symmetric encryption is used for bulk
encryption and the small random symmetric key used is transferred using
public key encryption.

</P>
<P>
It is possible to call <CODE>EVP_SealInit()</CODE> twice in the same way as
<CODE>EVP_EncryptInit().</CODE> The first call should have <STRONG>npubk</STRONG> set to 0 and (after setting any cipher parameters) it should be called
again with <STRONG>type</STRONG> set to NULL.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/evp.html#">evp(3)</A>, <A HREF="../crypto/rand.html#">rand(3)</A>,
<A HREF="../crypto/EVP_EncryptInit.html#">EVP_EncryptInit(3)</A>,
<A HREF="../crypto/EVP_OpenInit.html#">EVP_OpenInit(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>EVP_SealFinal()</CODE> did not return a value before OpenSSL 0.9.7.

</P>
:}


