PKCS12_PBE_KEYIVGEN(3ossl)

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

πŸ’– PKCS12_PBE_KEYIVGEN(3ossl) β€” the OpenSSL girlies' guide to PKCS#12 password-based encryption πŸ’–

okay so bestie, welcome to the 3ossl manual page, and listen β€” this one's about PKCS#12 password based encryption, which is genuinely iconic: you got a password, you got a key, you got a cipher, and we're making it all happen. ✨


🌸 NAME 🌸

PKCS12_PBE_keyivgen, PKCS12_PBE_keyivgen_ex, PKCS12_pbe_crypt, PKCS12_pbe_crypt_ex β€” PKCS#12 Password based encryption πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <openssl/evp.h>

int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
                        ASN1_TYPE *param, const EVP_CIPHER *cipher,
                        const EVP_MD *md_type, int en_de);
int PKCS12_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
                           ASN1_TYPE *param, const EVP_CIPHER *cipher,
                           const EVP_MD *md_type, int en_de,
                           OSSL_LIB_CTX *libctx, const char *propq);
unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
                                const char *pass, int passlen,
                                const unsigned char *in, int inlen,
                                unsigned char **data, int *datalen,
                                int en_de);
unsigned char *PKCS12_pbe_crypt_ex(const X509_ALGOR *algor,
                                   const char *pass, int passlen,
                                   const unsigned char *in, int inlen,
                                   unsigned char **data, int *datalen,
                                   int en_de, OSSL_LIB_CTX *libctx,
                                   const char *propq);

like, copy these exactly, do not freehand them, i'm begging πŸ™ˆ


πŸ’… DESCRIPTION πŸ’…

so PKCS12_PBE_keyivgen() and PKCS12_PBE_keyivgen_ex() take a password pass of length passlen, parameters param, and a message digest function md_type, and they do a key derivation according to PKCS#12. the resulting key then initialises the cipher context ctx with a cipher cipher β€” for encryption when en_de=1, or for decryption when en_de=0. literally that's the whole glow-up ✨

PKCS12_PBE_keyivgen_ex() also lets the application specify a library context libctx and property query propq so it can pick the appropriate algorithm implementations. fancy, we love options πŸ’…

PKCS12_pbe_crypt() and PKCS12_pbe_crypt_ex() will encrypt or decrypt a buffer based on the algorithm in algor and the password pass of length passlen. the input comes from in of length inlen, and the output goes into a malloc'd buffer returned in *data of length datalen. the operation is determined by en_de β€” encryption (en_de=1) or decryption (en_de=0). no cap, it's giving "one function, two moods" πŸ¦‹

PKCS12_pbe_crypt_ex() lets the application specify a library context libctx and property query propq to select appropriate algorithm implementations. same energy, extra knobs.

pass is the password used in the derivation, of length passlen. pass is an optional parameter and can be NULL. if passlen is -1, then the function will calculate the length of pass using strlen(). iykyk, that's the convenience clause πŸŽ€

salt is the salt used in the derivation, of length saltlen. if the salt is NULL, then saltlen must be 0. the function will not attempt to calculate the length of the salt, because it is not assumed to be NULL terminated. so like, don't assume, bestie, it's not that kind of string 😭

iter is the iteration count and its value should be greater than or equal to 1. RFC 2898 suggests an iteration count of at least 1000. any iter less than 1 is treated as a single iteration. periodt. πŸ‘‘

*d*igest is the message digest function used in the derivation.

functions ending in _ex() take optional parameters libctx and propq, which are used to select appropriate algorithm implementations. the _ex girlies are the main characters here fr fr πŸ’œ


✨ NOTES ✨

the functions are typically used in PKCS#12 to encrypt objects. that's their whole thing, that's their moment 🌈

these functions make no assumption regarding the given password. it will simply be treated as a byte sequence. no vibes check, no encoding drama, just bytes πŸ’€


πŸ“ RETURN VALUES πŸ“

PKCS12_PBE_keyivgen() and PKCS12_PBE_keyivgen_ex() return 1 on success or 0 on error.

PKCS12_pbe_crypt() and PKCS12_pbe_crypt_ex() return a buffer containing the output, or NULL if an error occurred. so like, always check for NULL, bestie, don't just rawdog the pointer πŸ™ˆ


🧚 CONFORMING TO 🧚

IETF RFC 7292 (<https://tools.ietf.org/html/rfc7292>) β€” the sacred text, go read it if you want the deep lore πŸ“œ


πŸ”₯ SEE ALSO πŸ”₯

all of these are your friends, please actually read them 🫢


⭐ HISTORY ⭐

PKCS12_PBE_keyivgen_ex() and PKCS12_pbe_crypt_ex() were added in OpenSSL 3.0. the _ex era began, and honestly? we're obsessed πŸ’–


Copyright 2014-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>.


okay that's the whole page, you ate it up πŸ’… this was OpenSSL 3.5.6, dated 2026-04-07, and it's the PKCS12_PBE_KEYIVGEN(3ossl) manual β€” go forth and derive those keys, bestie, you got this πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from