1*89729f59Sschwarze.\" $OpenBSD: EVP_SealInit.3,v 1.9 2023/11/16 20:27:43 schwarze Exp $ 25c1aabeeSschwarze.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100 38974101aSjmc.\" 45c1aabeeSschwarze.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 55c1aabeeSschwarze.\" Copyright (c) 2000, 2002, 2003, 2005, 2015 The OpenSSL Project. 65c1aabeeSschwarze.\" All rights reserved. 75c1aabeeSschwarze.\" 85c1aabeeSschwarze.\" Redistribution and use in source and binary forms, with or without 95c1aabeeSschwarze.\" modification, are permitted provided that the following conditions 105c1aabeeSschwarze.\" are met: 115c1aabeeSschwarze.\" 125c1aabeeSschwarze.\" 1. Redistributions of source code must retain the above copyright 135c1aabeeSschwarze.\" notice, this list of conditions and the following disclaimer. 145c1aabeeSschwarze.\" 155c1aabeeSschwarze.\" 2. Redistributions in binary form must reproduce the above copyright 165c1aabeeSschwarze.\" notice, this list of conditions and the following disclaimer in 175c1aabeeSschwarze.\" the documentation and/or other materials provided with the 185c1aabeeSschwarze.\" distribution. 195c1aabeeSschwarze.\" 205c1aabeeSschwarze.\" 3. All advertising materials mentioning features or use of this 215c1aabeeSschwarze.\" software must display the following acknowledgment: 225c1aabeeSschwarze.\" "This product includes software developed by the OpenSSL Project 235c1aabeeSschwarze.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 245c1aabeeSschwarze.\" 255c1aabeeSschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 265c1aabeeSschwarze.\" endorse or promote products derived from this software without 275c1aabeeSschwarze.\" prior written permission. For written permission, please contact 285c1aabeeSschwarze.\" openssl-core@openssl.org. 295c1aabeeSschwarze.\" 305c1aabeeSschwarze.\" 5. Products derived from this software may not be called "OpenSSL" 315c1aabeeSschwarze.\" nor may "OpenSSL" appear in their names without prior written 325c1aabeeSschwarze.\" permission of the OpenSSL Project. 335c1aabeeSschwarze.\" 345c1aabeeSschwarze.\" 6. Redistributions of any form whatsoever must retain the following 355c1aabeeSschwarze.\" acknowledgment: 365c1aabeeSschwarze.\" "This product includes software developed by the OpenSSL Project 375c1aabeeSschwarze.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 385c1aabeeSschwarze.\" 395c1aabeeSschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 405c1aabeeSschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 415c1aabeeSschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 425c1aabeeSschwarze.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 435c1aabeeSschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 445c1aabeeSschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 455c1aabeeSschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 465c1aabeeSschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 475c1aabeeSschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 485c1aabeeSschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 495c1aabeeSschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 505c1aabeeSschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE. 515c1aabeeSschwarze.\" 52*89729f59Sschwarze.Dd $Mdocdate: November 16 2023 $ 53d5c51cd3Sschwarze.Dt EVP_SEALINIT 3 54d5c51cd3Sschwarze.Os 55d5c51cd3Sschwarze.Sh NAME 56d5c51cd3Sschwarze.Nm EVP_SealInit , 57d5c51cd3Sschwarze.Nm EVP_SealUpdate , 58d5c51cd3Sschwarze.Nm EVP_SealFinal 59d5c51cd3Sschwarze.Nd EVP envelope encryption 60d5c51cd3Sschwarze.Sh SYNOPSIS 61d5c51cd3Sschwarze.In openssl/evp.h 62d5c51cd3Sschwarze.Ft int 63d5c51cd3Sschwarze.Fo EVP_SealInit 64d5c51cd3Sschwarze.Fa "EVP_CIPHER_CTX *ctx" 65d5c51cd3Sschwarze.Fa "const EVP_CIPHER *type" 66d5c51cd3Sschwarze.Fa "unsigned char **ek" 67d5c51cd3Sschwarze.Fa "int *ekl" 68d5c51cd3Sschwarze.Fa "unsigned char *iv" 69d5c51cd3Sschwarze.Fa "EVP_PKEY **pubk" 70d5c51cd3Sschwarze.Fa "int npubk" 71d5c51cd3Sschwarze.Fc 72d5c51cd3Sschwarze.Ft int 73d5c51cd3Sschwarze.Fo EVP_SealUpdate 74d5c51cd3Sschwarze.Fa "EVP_CIPHER_CTX *ctx" 75d5c51cd3Sschwarze.Fa "unsigned char *out" 76d5c51cd3Sschwarze.Fa "int *outl" 77d5c51cd3Sschwarze.Fa "unsigned char *in" 78d5c51cd3Sschwarze.Fa "int inl" 79d5c51cd3Sschwarze.Fc 80d5c51cd3Sschwarze.Ft int 81d5c51cd3Sschwarze.Fo EVP_SealFinal 82d5c51cd3Sschwarze.Fa "EVP_CIPHER_CTX *ctx" 83d5c51cd3Sschwarze.Fa "unsigned char *out" 84d5c51cd3Sschwarze.Fa "int *outl" 85d5c51cd3Sschwarze.Fc 86d5c51cd3Sschwarze.Sh DESCRIPTION 87d5c51cd3SschwarzeThe EVP envelope routines are a high level interface to envelope 88d5c51cd3Sschwarzeencryption. 89d5c51cd3SschwarzeThey generate a random key and IV (if required) then "envelope" it by 90d5c51cd3Sschwarzeusing public key encryption. 91d5c51cd3SschwarzeData can then be encrypted using this key. 92d5c51cd3Sschwarze.Pp 93d5c51cd3Sschwarze.Fn EVP_SealInit 94d5c51cd3Sschwarzeinitializes a cipher context 95d5c51cd3Sschwarze.Fa ctx 96d5c51cd3Sschwarzefor encryption with cipher 97d5c51cd3Sschwarze.Fa type 98d5c51cd3Sschwarzeusing a random secret key and IV. 99d5c51cd3Sschwarze.Fa type 100d5c51cd3Sschwarzeis normally supplied by a function such as 1015c1aabeeSschwarze.Xr EVP_aes_256_cbc 3 ; 102d5c51cd3Sschwarzesee 103d5c51cd3Sschwarze.Xr EVP_EncryptInit 3 104d5c51cd3Sschwarzefor details. 105d5c51cd3SschwarzeThe secret key is encrypted using one or more public keys. 106d5c51cd3SschwarzeThis allows the same encrypted data to be decrypted using any of 107d5c51cd3Sschwarzethe corresponding private keys. 108d5c51cd3Sschwarze.Fa ek 109d5c51cd3Sschwarzeis an array of buffers where the public key encrypted secret key will be 110d5c51cd3Sschwarzewritten. 111d5c51cd3SschwarzeEach buffer must contain enough room for the corresponding encrypted 112d5c51cd3Sschwarzekey: that is 113d5c51cd3Sschwarze.Fa ek[i] 114d5c51cd3Sschwarzemust have room for 115d5c51cd3Sschwarze.Fn EVP_PKEY_size pubk[i] 116d5c51cd3Sschwarzebytes. 117d5c51cd3SschwarzeThe actual size of each encrypted secret key is written to the array 118d5c51cd3Sschwarze.Fa ekl . 119d5c51cd3Sschwarze.Fa pubk 120d5c51cd3Sschwarzeis an array of 121d5c51cd3Sschwarze.Fa npubk 122d5c51cd3Sschwarzepublic keys. 123d5c51cd3Sschwarze.Pp 124d5c51cd3SschwarzeThe 125d5c51cd3Sschwarze.Fa iv 126d5c51cd3Sschwarzeparameter is a buffer where the generated IV is written to. 127d5c51cd3SschwarzeIt must contain enough room for the corresponding cipher's IV, as 128d5c51cd3Sschwarzedetermined by (for example) 129d5c51cd3Sschwarze.Fn EVP_CIPHER_iv_length type . 130d5c51cd3Sschwarze.Pp 131d5c51cd3SschwarzeIf the cipher does not require an IV then the 132d5c51cd3Sschwarze.Fa iv 133d5c51cd3Sschwarzeparameter is ignored and can be 134d5c51cd3Sschwarze.Dv NULL . 135d5c51cd3Sschwarze.Pp 136d5c51cd3Sschwarze.Fn EVP_SealUpdate 137d5c51cd3Sschwarzeand 138d5c51cd3Sschwarze.Fn EVP_SealFinal 139d5c51cd3Sschwarzehave exactly the same properties as the 140d5c51cd3Sschwarze.Xr EVP_EncryptUpdate 3 141d5c51cd3Sschwarzeand 142d5c51cd3Sschwarze.Xr EVP_EncryptFinal 3 143d5c51cd3Sschwarzeroutines. 144d5c51cd3Sschwarze.Pp 145d5c51cd3SschwarzeThe public key must be RSA because it is the only OpenSSL public key 146d5c51cd3Sschwarzealgorithm that supports key transport. 147d5c51cd3Sschwarze.Pp 148d5c51cd3SschwarzeEnvelope encryption is the usual method of using public key encryption 149d5c51cd3Sschwarzeon large amounts of data. 150d5c51cd3SschwarzeThis is because public key encryption is slow but symmetric encryption 151d5c51cd3Sschwarzeis fast. 152d5c51cd3SschwarzeSo symmetric encryption is used for bulk encryption and the small random 153d5c51cd3Sschwarzesymmetric key used is transferred using public key encryption. 154d5c51cd3Sschwarze.Pp 155d5c51cd3SschwarzeIt is possible to call 156d5c51cd3Sschwarze.Fn EVP_SealInit 157d5c51cd3Sschwarzetwice in the same way as 158d5c51cd3Sschwarze.Xr EVP_EncryptInit 3 . 159d5c51cd3SschwarzeThe first call should have 160d5c51cd3Sschwarze.Fa npubk 161d5c51cd3Sschwarzeset to 0 and (after setting any cipher parameters) it should be called 162d5c51cd3Sschwarzeagain with 163d5c51cd3Sschwarze.Fa type 164d5c51cd3Sschwarzeset to NULL. 165*89729f59Sschwarze.Pp 166*89729f59Sschwarze.Fn EVP_SealUpdate 167*89729f59Sschwarzeis implemented as a macro. 168d5c51cd3Sschwarze.Sh RETURN VALUES 169d5c51cd3Sschwarze.Fn EVP_SealInit 170d5c51cd3Sschwarzereturns 0 on error or 171d5c51cd3Sschwarze.Fa npubk 172d5c51cd3Sschwarzeif successful. 173d5c51cd3Sschwarze.Pp 174d5c51cd3Sschwarze.Fn EVP_SealUpdate 175d5c51cd3Sschwarzeand 176d5c51cd3Sschwarze.Fn EVP_SealFinal 177d5c51cd3Sschwarzereturn 1 for success and 0 for failure. 178d5c51cd3Sschwarze.Sh SEE ALSO 179d5c51cd3Sschwarze.Xr evp 3 , 180d5c51cd3Sschwarze.Xr EVP_EncryptInit 3 , 18164af7bbfSschwarze.Xr EVP_OpenInit 3 182d5c51cd3Sschwarze.Sh HISTORY 18352c2d5e5Sschwarze.Fn EVP_SealInit , 18452c2d5e5Sschwarze.Fn EVP_SealUpdate , 18552c2d5e5Sschwarzeand 18652c2d5e5Sschwarze.Fn EVP_SealFinal 18710e00d17Sschwarzefirst appeared in SSLeay 0.5.1 and have been available since 18852c2d5e5Sschwarze.Ox 2.4 . 18952c2d5e5Sschwarze.Pp 190d5c51cd3Sschwarze.Fn EVP_SealFinal 191d5c51cd3Sschwarzedid not return a value before OpenSSL 0.9.7. 192