EVP_SealInit.pod 3.4 KB

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