xref: /openbsd/lib/libcrypto/man/EVP_SealInit.3 (revision 510d2225)
1.\"	$OpenBSD: EVP_SealInit.3,v 1.9 2023/11/16 20:27:43 schwarze Exp $
2.\"	OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5.\" Copyright (c) 2000, 2002, 2003, 2005, 2015 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: November 16 2023 $
53.Dt EVP_SEALINIT 3
54.Os
55.Sh NAME
56.Nm EVP_SealInit ,
57.Nm EVP_SealUpdate ,
58.Nm EVP_SealFinal
59.Nd EVP envelope encryption
60.Sh SYNOPSIS
61.In openssl/evp.h
62.Ft int
63.Fo EVP_SealInit
64.Fa "EVP_CIPHER_CTX *ctx"
65.Fa "const EVP_CIPHER *type"
66.Fa "unsigned char **ek"
67.Fa "int *ekl"
68.Fa "unsigned char *iv"
69.Fa "EVP_PKEY **pubk"
70.Fa "int npubk"
71.Fc
72.Ft int
73.Fo EVP_SealUpdate
74.Fa "EVP_CIPHER_CTX *ctx"
75.Fa "unsigned char *out"
76.Fa "int *outl"
77.Fa "unsigned char *in"
78.Fa "int inl"
79.Fc
80.Ft int
81.Fo EVP_SealFinal
82.Fa "EVP_CIPHER_CTX *ctx"
83.Fa "unsigned char *out"
84.Fa "int *outl"
85.Fc
86.Sh DESCRIPTION
87The EVP envelope routines are a high level interface to envelope
88encryption.
89They generate a random key and IV (if required) then "envelope" it by
90using public key encryption.
91Data can then be encrypted using this key.
92.Pp
93.Fn EVP_SealInit
94initializes a cipher context
95.Fa ctx
96for encryption with cipher
97.Fa type
98using a random secret key and IV.
99.Fa type
100is normally supplied by a function such as
101.Xr EVP_aes_256_cbc 3 ;
102see
103.Xr EVP_EncryptInit 3
104for details.
105The secret key is encrypted using one or more public keys.
106This allows the same encrypted data to be decrypted using any of
107the corresponding private keys.
108.Fa ek
109is an array of buffers where the public key encrypted secret key will be
110written.
111Each buffer must contain enough room for the corresponding encrypted
112key: that is
113.Fa ek[i]
114must have room for
115.Fn EVP_PKEY_size pubk[i]
116bytes.
117The actual size of each encrypted secret key is written to the array
118.Fa ekl .
119.Fa pubk
120is an array of
121.Fa npubk
122public keys.
123.Pp
124The
125.Fa iv
126parameter is a buffer where the generated IV is written to.
127It must contain enough room for the corresponding cipher's IV, as
128determined by (for example)
129.Fn EVP_CIPHER_iv_length type .
130.Pp
131If the cipher does not require an IV then the
132.Fa iv
133parameter is ignored and can be
134.Dv NULL .
135.Pp
136.Fn EVP_SealUpdate
137and
138.Fn EVP_SealFinal
139have exactly the same properties as the
140.Xr EVP_EncryptUpdate 3
141and
142.Xr EVP_EncryptFinal 3
143routines.
144.Pp
145The public key must be RSA because it is the only OpenSSL public key
146algorithm that supports key transport.
147.Pp
148Envelope encryption is the usual method of using public key encryption
149on large amounts of data.
150This is because public key encryption is slow but symmetric encryption
151is fast.
152So symmetric encryption is used for bulk encryption and the small random
153symmetric key used is transferred using public key encryption.
154.Pp
155It is possible to call
156.Fn EVP_SealInit
157twice in the same way as
158.Xr EVP_EncryptInit 3 .
159The first call should have
160.Fa npubk
161set to 0 and (after setting any cipher parameters) it should be called
162again with
163.Fa type
164set to NULL.
165.Pp
166.Fn EVP_SealUpdate
167is implemented as a macro.
168.Sh RETURN VALUES
169.Fn EVP_SealInit
170returns 0 on error or
171.Fa npubk
172if successful.
173.Pp
174.Fn EVP_SealUpdate
175and
176.Fn EVP_SealFinal
177return 1 for success and 0 for failure.
178.Sh SEE ALSO
179.Xr evp 3 ,
180.Xr EVP_EncryptInit 3 ,
181.Xr EVP_OpenInit 3
182.Sh HISTORY
183.Fn EVP_SealInit ,
184.Fn EVP_SealUpdate ,
185and
186.Fn EVP_SealFinal
187first appeared in SSLeay 0.5.1 and have been available since
188.Ox 2.4 .
189.Pp
190.Fn EVP_SealFinal
191did not return a value before OpenSSL 0.9.7.
192