1*e71b7053SJung-uk Kim=pod 2*e71b7053SJung-uk Kim 3*e71b7053SJung-uk Kim=head1 NAME 4*e71b7053SJung-uk Kim 5*e71b7053SJung-uk KimEVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption 6*e71b7053SJung-uk Kim 7*e71b7053SJung-uk Kim=head1 SYNOPSIS 8*e71b7053SJung-uk Kim 9*e71b7053SJung-uk Kim #include <openssl/evp.h> 10*e71b7053SJung-uk Kim 11*e71b7053SJung-uk Kim int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, 12*e71b7053SJung-uk Kim unsigned char **ek, int *ekl, unsigned char *iv, 13*e71b7053SJung-uk Kim EVP_PKEY **pubk, int npubk); 14*e71b7053SJung-uk Kim int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 15*e71b7053SJung-uk Kim int *outl, unsigned char *in, int inl); 16*e71b7053SJung-uk Kim int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 17*e71b7053SJung-uk Kim 18*e71b7053SJung-uk Kim=head1 DESCRIPTION 19*e71b7053SJung-uk Kim 20*e71b7053SJung-uk KimThe EVP envelope routines are a high level interface to envelope 21*e71b7053SJung-uk Kimencryption. They generate a random key and IV (if required) then 22*e71b7053SJung-uk Kim"envelope" it by using public key encryption. Data can then be 23*e71b7053SJung-uk Kimencrypted using this key. 24*e71b7053SJung-uk Kim 25*e71b7053SJung-uk KimEVP_SealInit() initializes a cipher context B<ctx> for encryption 26*e71b7053SJung-uk Kimwith cipher B<type> using a random secret key and IV. B<type> is normally 27*e71b7053SJung-uk Kimsupplied by a function such as EVP_aes_256_cbc(). The secret key is encrypted 28*e71b7053SJung-uk Kimusing one or more public keys, this allows the same encrypted data to be 29*e71b7053SJung-uk Kimdecrypted using any of the corresponding private keys. B<ek> is an array of 30*e71b7053SJung-uk Kimbuffers where the public key encrypted secret key will be written, each buffer 31*e71b7053SJung-uk Kimmust contain enough room for the corresponding encrypted key: that is 32*e71b7053SJung-uk KimB<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual 33*e71b7053SJung-uk Kimsize of each encrypted secret key is written to the array B<ekl>. B<pubk> is 34*e71b7053SJung-uk Kiman array of B<npubk> public keys. 35*e71b7053SJung-uk Kim 36*e71b7053SJung-uk KimThe B<iv> parameter is a buffer where the generated IV is written to. It must 37*e71b7053SJung-uk Kimcontain enough room for the corresponding cipher's IV, as determined by (for 38*e71b7053SJung-uk Kimexample) EVP_CIPHER_iv_length(type). 39*e71b7053SJung-uk Kim 40*e71b7053SJung-uk KimIf the cipher does not require an IV then the B<iv> parameter is ignored 41*e71b7053SJung-uk Kimand can be B<NULL>. 42*e71b7053SJung-uk Kim 43*e71b7053SJung-uk KimEVP_SealUpdate() and EVP_SealFinal() have exactly the same properties 44*e71b7053SJung-uk Kimas the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as 45*e71b7053SJung-uk Kimdocumented on the L<EVP_EncryptInit(3)> manual 46*e71b7053SJung-uk Kimpage. 47*e71b7053SJung-uk Kim 48*e71b7053SJung-uk Kim=head1 RETURN VALUES 49*e71b7053SJung-uk Kim 50*e71b7053SJung-uk KimEVP_SealInit() returns 0 on error or B<npubk> if successful. 51*e71b7053SJung-uk Kim 52*e71b7053SJung-uk KimEVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for 53*e71b7053SJung-uk Kimfailure. 54*e71b7053SJung-uk Kim 55*e71b7053SJung-uk Kim=head1 NOTES 56*e71b7053SJung-uk Kim 57*e71b7053SJung-uk KimBecause a random secret key is generated the random number generator 58*e71b7053SJung-uk Kimmust be seeded before calling EVP_SealInit(). 59*e71b7053SJung-uk Kim 60*e71b7053SJung-uk KimThe public key must be RSA because it is the only OpenSSL public key 61*e71b7053SJung-uk Kimalgorithm that supports key transport. 62*e71b7053SJung-uk Kim 63*e71b7053SJung-uk KimEnvelope encryption is the usual method of using public key encryption 64*e71b7053SJung-uk Kimon large amounts of data, this is because public key encryption is slow 65*e71b7053SJung-uk Kimbut symmetric encryption is fast. So symmetric encryption is used for 66*e71b7053SJung-uk Kimbulk encryption and the small random symmetric key used is transferred 67*e71b7053SJung-uk Kimusing public key encryption. 68*e71b7053SJung-uk Kim 69*e71b7053SJung-uk KimIt is possible to call EVP_SealInit() twice in the same way as 70*e71b7053SJung-uk KimEVP_EncryptInit(). The first call should have B<npubk> set to 0 71*e71b7053SJung-uk Kimand (after setting any cipher parameters) it should be called again 72*e71b7053SJung-uk Kimwith B<type> set to NULL. 73*e71b7053SJung-uk Kim 74*e71b7053SJung-uk Kim=head1 SEE ALSO 75*e71b7053SJung-uk Kim 76*e71b7053SJung-uk KimL<evp(7)>, L<RAND_bytes(3)>, 77*e71b7053SJung-uk KimL<EVP_EncryptInit(3)>, 78*e71b7053SJung-uk KimL<EVP_OpenInit(3)> 79*e71b7053SJung-uk Kim 80*e71b7053SJung-uk Kim=head1 COPYRIGHT 81*e71b7053SJung-uk Kim 82*e71b7053SJung-uk KimCopyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. 83*e71b7053SJung-uk Kim 84*e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 85*e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 86*e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 87*e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 88*e71b7053SJung-uk Kim 89*e71b7053SJung-uk Kim=cut 90