EVP_SEALINIT(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’Œ EVP_SEALINIT(3ossl) β€” like, the OpenSSL manual page, but make it make sense

okay bestie, sit down, grab a strawberry πŸ“ β€” this is the OpenSSL 3ossl page for the EVP envelope encryption girlies, and it's genuinely iconic once you get it, i promise.

✨ NAME ✨

EVP_SealInit, EVP_SealUpdate, EVP_SealFinal β€” EVP envelope encryption. yes, that's the whole name section, she's short and she knows it πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

#include <openssl/evp.h>

int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
                 unsigned char **ek, int *ekl, unsigned char *iv,
                 EVP_PKEY **pubk, int npubk);
int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
                   int *outl, unsigned char *in, int inl);
int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);

like, that's a lot of parameters, but we're gonna walk through each one, no panic 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

So the EVP envelope routines are basically a high-level interface to envelope encryption. What do they do? They generate a random key and IV (if required) and then "envelope" it β€” like wrapping a lil gift 🎁 β€” by using public key encryption. After that, you can encrypt your actual data with that key. slay.

πŸ’– EVP_SealInit()

EVP_SealInit() initializes a cipher context ctx for encryption with cipher type using a random secret key and IV.

type is normally supplied by a function such as EVP_aes_256_cbc().

Here's the actually cool part: the secret key gets encrypted using one or more public keys. that means the same encrypted data can be decrypted using any of the corresponding private keys. main character flexibility, honestly πŸ‘‘

  • 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, ek[i] must have room for EVP_PKEY_get_size(pubk[i]) bytes.
  • The actual size of each encrypted secret key gets written to the array ekl.
  • pubk is an array of npubk public keys.

🌸 the iv situation

The 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_get_iv_length(type).

If the cipher doesn't require an IV then the iv parameter is ignored and can be NULL. so don't stress about it if your cipher's not that kind of cipher πŸ’€

🧚 EVP_SealUpdate() and EVP_SealFinal()

These two have exactly the same properties as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as documented on the EVP_EncryptInit(3) manual page. same energy, different name, iykyk.


⭐ RETURN VALUES ⭐

  • EVP_SealInit() returns 0 on error, or npubk if successful. (yes, the success value is literally the number of public keys, she's quirky like that πŸ™ˆ)
  • EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for failure.

πŸ”₯ NOTES πŸ”₯

okay this is the part where you actually pay attention, bestie:

  • Because a random secret key is generated, the random number generator must be seeded when EVP_SealInit() is called. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to external circumstances (see RAND(7)), the operation will fail. no cap, this one matters 😭
  • The public key must be RSA, because it is the only OpenSSL public key algorithm that supports key transport. that's the whole reason, no shade to the others, they just don't do that πŸ’…
  • Envelope encryption is the usual method of using public key encryption on large amounts of data. why? 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. it's giving teamwork, it's giving division of labour, we love to see it.
  • It is possible to call EVP_SealInit() twice in the same way as EVP_EncryptInit(). The first call should have npubk set to 0 and (after setting any cipher parameters) it should be called again with type set to NULL. two-step init, iconic behaviour ✨

🌈 SEE ALSO 🌈

evp(7), RAND_bytes(3), EVP_EncryptInit(3), EVP_OpenInit(3), RAND(7) β€” go read them, they're all friends of this page 🫢


Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the page, bestie πŸ’œ this was OpenSSL 3.5.0, dated 2026-09-25, and yes the footer says EVP_SEALINIT(3ossl) β€” go forth and envelope-encrypt responsibly, mwah πŸŽ€

πŸ“¦ where this page comes from