| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | =pod | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 NAME | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 SYNOPSIS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  #include <openssl/evp.h> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-30 01:50:08 +08:00
										 |  |  |  int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | 
					
						
							|  |  |  |                   unsigned char **ek, int *ekl, unsigned char *iv, | 
					
						
							|  |  |  |                   EVP_PKEY **pubk, int npubk); | 
					
						
							| 
									
										
										
										
											2000-06-11 23:43:17 +08:00
										 |  |  |  int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | 
					
						
							| 
									
										
										
										
											2017-01-21 02:58:49 +08:00
										 |  |  |                     int *outl, unsigned char *in, int inl); | 
					
						
							|  |  |  |  int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 DESCRIPTION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The EVP envelope routines are a high level interface to envelope | 
					
						
							| 
									
										
										
										
											2003-01-26 21:38:56 +08:00
										 |  |  | encryption. They generate a random key and IV (if required) then | 
					
						
							|  |  |  | "envelope" it by using public key encryption. Data can then be | 
					
						
							|  |  |  | encrypted using this key. | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-20 11:24:36 +08:00
										 |  |  | EVP_SealInit() initializes a cipher context B<ctx> for encryption | 
					
						
							| 
									
										
										
										
											2003-01-26 21:38:56 +08:00
										 |  |  | with cipher B<type> using a random secret key and IV. B<type> is normally | 
					
						
							| 
									
										
										
										
											2015-07-31 23:52:57 +08:00
										 |  |  | supplied by a function such as EVP_aes_256_cbc(). The secret key is encrypted | 
					
						
							| 
									
										
										
										
											2003-01-26 21:38:56 +08:00
										 |  |  | using one or more public keys, this allows the same encrypted data to be | 
					
						
							|  |  |  | decrypted using any of the corresponding private keys. B<ek> is an array of | 
					
						
							|  |  |  | buffers where the public key encrypted secret key will be written, each buffer | 
					
						
							|  |  |  | must contain enough room for the corresponding encrypted key: that is | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual | 
					
						
							|  |  |  | size of each encrypted secret key is written to the array B<ekl>. B<pubk> is | 
					
						
							|  |  |  | an array of B<npubk> public keys. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-26 21:38:56 +08:00
										 |  |  | The B<iv> parameter is a buffer where the generated IV is written to. It must | 
					
						
							|  |  |  | contain enough room for the corresponding cipher's IV, as determined by (for | 
					
						
							|  |  |  | example) EVP_CIPHER_iv_length(type). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If the cipher does not require an IV then the B<iv> parameter is ignored | 
					
						
							|  |  |  | and can be B<NULL>. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties | 
					
						
							| 
									
										
										
										
											2016-05-20 20:11:46 +08:00
										 |  |  | as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as | 
					
						
							| 
									
										
										
										
											2015-08-18 03:21:33 +08:00
										 |  |  | documented on the L<EVP_EncryptInit(3)> manual | 
					
						
							| 
									
										
										
										
											2016-05-20 20:11:46 +08:00
										 |  |  | page. | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 RETURN VALUES | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-11 23:43:17 +08:00
										 |  |  | EVP_SealInit() returns 0 on error or B<npubk> if successful. | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-11 20:27:58 +08:00
										 |  |  | EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for | 
					
						
							|  |  |  | failure. | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 NOTES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Because a random secret key is generated the random number generator | 
					
						
							| 
									
										
										
										
											2019-06-27 16:12:08 +08:00
										 |  |  | must be seeded when EVP_SealInit() is called. | 
					
						
							|  |  |  | If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to | 
					
						
							|  |  |  | external circumstances (see L<RAND(7)>), the operation will fail. | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | The public key must be RSA because it is the only OpenSSL public key | 
					
						
							|  |  |  | algorithm that supports key transport. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Envelope encryption is the usual method of using public key encryption | 
					
						
							|  |  |  | on large amounts of data, this is because public key encryption is slow | 
					
						
							|  |  |  | but symmetric encryption is fast. So symmetric encryption is used for | 
					
						
							|  |  |  | bulk encryption and the small random symmetric key used is transferred | 
					
						
							|  |  |  | using public key encryption. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-11 20:18:15 +08:00
										 |  |  | It is possible to call EVP_SealInit() twice in the same way as | 
					
						
							|  |  |  | EVP_EncryptInit(). The first call should have B<npubk> set to 0 | 
					
						
							| 
									
										
										
										
											2000-09-20 11:24:36 +08:00
										 |  |  | and (after setting any cipher parameters) it should be called again | 
					
						
							| 
									
										
										
										
											2000-06-11 20:18:15 +08:00
										 |  |  | with B<type> set to NULL. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | =head1 SEE ALSO | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-11 16:33:09 +08:00
										 |  |  | L<evp(7)>, L<RAND_bytes(3)>, | 
					
						
							| 
									
										
										
										
											2015-08-18 03:21:33 +08:00
										 |  |  | L<EVP_EncryptInit(3)>, | 
					
						
							| 
									
										
										
										
											2019-06-27 16:12:08 +08:00
										 |  |  | L<EVP_OpenInit(3)>, | 
					
						
							|  |  |  | L<RAND(7)> | 
					
						
							| 
									
										
										
										
											2000-03-08 09:48:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-18 23:44:05 +08:00
										 |  |  | =head1 COPYRIGHT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-06 21:04:44 +08:00
										 |  |  | Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 23:44:05 +08:00
										 |  |  | this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  | in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  | L<https://www.openssl.org/source/license.html>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =cut |