EVP_SEALINIT(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’Œ EVP_SealInit β€” the envelope encryption era πŸ’Œ

okay so this is the OpenSSL manual page for EVP_SealInit, EVP_SealUpdate, and EVP_SealFinal β€” aka EVP envelope encryption. bestie, this is the whole "wrap a tiny key in a big key so you can encrypt everything" pipeline and honestly? it's giving main character energy. 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);

no cap, copy these exactly, the compiler is not forgiving 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

the EVP envelope routines are a high-level interface to envelope encryption. they generate a random key and IV (if required) and then "envelope" that key by using public key encryption. after that, data can be encrypted using this key. it's lowkey genius. πŸ’–

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(). the secret key gets encrypted using one or more public keys β€” which is so iconic because it means the same encrypted data can be decrypted using any of the corresponding private keys. slay. ✨

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 is written to the array ekl. and pubk is an array of npubk public keys. πŸ—οΈ

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 does not require an IV then the iv parameter is ignored and can be NULL. no IV, no problem. πŸ™ˆ

EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as documented on the EVP_EncryptInit(3) manual page. literally identical energy. πŸ’«


πŸ”₯ RETURN VALUES πŸ”₯

  • EVP_SealInit() returns 0 on error or npubk if successful.
  • EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for failure.

so like... zero is bad for the first one but good-ish news is always 1 for the other two. iykyk πŸ’€


πŸ‘‘ NOTES πŸ‘‘

okay bestie, important stuff, pay attention:

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. 😭 that's not a vibe but it's the truth.

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

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. big brain behavior, honestly. 🧚

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, we love a process. πŸŽ€


🌈 SEE ALSO 🌈

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

go read these, they're all connected, it's a whole ecosystem πŸ’œ


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.6, dated 2026-04-07, manual page EVP_SEALINIT(3ossl) β€” go forth and envelope-encrypt responsibly, mwah πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from