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