xref: /freebsd/crypto/openssl/doc/man3/EVP_SealInit.pod (revision c6989859ae9388eeb46a24fe88f9b8d07101c710)
1=pod
2
3=head1 NAME
4
5EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
12                  unsigned char **ek, int *ekl, unsigned char *iv,
13                  EVP_PKEY **pubk, int npubk);
14 int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
15                    int *outl, unsigned char *in, int inl);
16 int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
17
18=head1 DESCRIPTION
19
20The EVP envelope routines are a high level interface to envelope
21encryption. They generate a random key and IV (if required) then
22"envelope" it by using public key encryption. Data can then be
23encrypted using this key.
24
25EVP_SealInit() initializes a cipher context B<ctx> for encryption
26with cipher B<type> using a random secret key and IV. B<type> is normally
27supplied by a function such as EVP_aes_256_cbc(). The secret key is encrypted
28using one or more public keys, this allows the same encrypted data to be
29decrypted using any of the corresponding private keys. B<ek> is an array of
30buffers where the public key encrypted secret key will be written, each buffer
31must contain enough room for the corresponding encrypted key: that is
32B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual
33size of each encrypted secret key is written to the array B<ekl>. B<pubk> is
34an array of B<npubk> public keys.
35
36The B<iv> parameter is a buffer where the generated IV is written to. It must
37contain enough room for the corresponding cipher's IV, as determined by (for
38example) EVP_CIPHER_iv_length(type).
39
40If the cipher does not require an IV then the B<iv> parameter is ignored
41and can be B<NULL>.
42
43EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties
44as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as
45documented on the L<EVP_EncryptInit(3)> manual
46page.
47
48=head1 RETURN VALUES
49
50EVP_SealInit() returns 0 on error or B<npubk> if successful.
51
52EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for
53failure.
54
55=head1 NOTES
56
57Because a random secret key is generated the random number generator
58must be seeded when EVP_SealInit() is called.
59If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
60external circumstances (see L<RAND(7)>), the operation will fail.
61
62The public key must be RSA because it is the only OpenSSL public key
63algorithm that supports key transport.
64
65Envelope encryption is the usual method of using public key encryption
66on large amounts of data, this is because public key encryption is slow
67but symmetric encryption is fast. So symmetric encryption is used for
68bulk encryption and the small random symmetric key used is transferred
69using public key encryption.
70
71It is possible to call EVP_SealInit() twice in the same way as
72EVP_EncryptInit(). The first call should have B<npubk> set to 0
73and (after setting any cipher parameters) it should be called again
74with B<type> set to NULL.
75
76=head1 SEE ALSO
77
78L<evp(7)>, L<RAND_bytes(3)>,
79L<EVP_EncryptInit(3)>,
80L<EVP_OpenInit(3)>,
81L<RAND(7)>
82
83=head1 COPYRIGHT
84
85Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
86
87Licensed under the OpenSSL license (the "License").  You may not use
88this file except in compliance with the License.  You can obtain a copy
89in the file LICENSE in the source distribution or at
90L<https://www.openssl.org/source/license.html>.
91
92=cut
93