EVP_SEALINIT(3ossl)

πŸ’Œ EVP_SEALINIT(3ossl) β€” the OpenSSL envelope encryption girlies

okay bestie, welcome to EVP_SealInit, EVP_SealUpdate, and EVP_SealFinal β€” aka EVP envelope encryption, straight out of the OpenSSL manual. this is the ✨high-level✨ interface and she is iconic. let's get into it πŸŽ€


🌸 NAME 🌸

EVP_SealInit, EVP_SealUpdate, EVP_SealFinal β€” EVP envelope encryption. that's the whole vibe. πŸ’–


✨ 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);

🫢 DESCRIPTION 🫢

so the EVP envelope routines are a high-level interface to envelope encryption. what they do is: generate a random key and IV (if the cipher needs one), then "envelope" that key by using public key encryption. after that you can encrypt your actual data with that key. it's giving wrapped present energy 🎁

πŸ’… 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 like EVP_aes_256_cbc(). the secret key then gets encrypted using one or more public keys, which is the slay part β€” it means the same encrypted data can be decrypted using any of the corresponding private keys. multi-key access, we love to see it. πŸ‘‘

  • 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. don't skimp on the buffer bestie, she needs space. 🫢
  • the actual size of each encrypted secret key is written to the array ekl.
  • pubk is an array of npubk public keys.

the iv parameter is a buffer where the generated IV gets 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 does not require an IV, then the iv parameter is ignored and can be NULL. no IV, no problem. ✨

🌈 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. so if you already know those, you already know these. iykyk. πŸ’œ


πŸ“ RETURN VALUES πŸ“

  • EVP_SealInit() returns 0 on error, or npubk if successful. so like, a nonzero return is your green flag. βœ…
  • EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for failure.

🧚 NOTES 🧚

because a random secret key is generated, the random number generator must be seeded when EVP_SealInit() is called. and listen β€” if the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to external circumstances (see RAND(7)), the operation will fail. that's just how it is. 😭

the public key must be RSA, because it is the only OpenSSL public key algorithm that supports key transport. no RSA, no envelope. periodt. πŸ’…

envelope encryption is the usual method of using public key encryption on large amounts of data, and here's why: public key encryption is slow but symmetric encryption is fast. so symmetric encryption handles the bulk encryption, and the small random symmetric key gets transferred using public key encryption. best of both worlds, honestly. 🌸

and a lil trick: 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 then (after setting any cipher parameters) it should be called again with type set to NULL. two calls, one glow-up. ✨


πŸ’– SEE ALSO πŸ’–

evp(7), RAND_bytes(3), EVP_EncryptInit(3), EVP_OpenInit(3), RAND(7)


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 whole page bestie!! πŸ¦‹ this one's from OpenSSL 3.5.9, dated 2026-09-29 β€” so like, go forth and seal your envelopes, you absolute main character. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from