PKCS5_PBKDF2_HMAC(3ossl)

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

πŸ’– NAME πŸ’–

okay so welcome to the PKCS5_PBKDF2_HMAC page from the OpenSSL 3ossl manual, bestie πŸ’… the main characters are PKCS5_PBKDF2_HMAC and PKCS5_PBKDF2_HMAC_SHA1 β€” password based derivation routines with salt and iteration count. no cap, this is the password-to-key pipeline.

✨ SYNOPSIS ✨

        #include <openssl/evp.h>

        int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
                              const unsigned char *salt, int saltlen, int iter,
                              const EVP_MD *digest,
                              int keylen, unsigned char *out);

        int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
                                   const unsigned char *salt, int saltlen, int iter,
                                   int keylen, unsigned char *out);

🌸 DESCRIPTION 🌸

PKCS5_PBKDF2_HMAC() derives a key from a password using a salt and iteration count as specified in RFC 2898. it's giving "turn a password into key material, but make it deliberately slow" ✨

  • pass β€” the password used in the derivation, with length passlen. it's optional and can be NULL. if passlen is -1, then the function will calculate the length of pass using strlen().
  • salt β€” the salt used in the derivation, with 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. periodt.
  • iter β€” 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 value less than 1 is invalid; such values will result in failure and raise the PROV_R_INVALID_ITERATION_COUNT error. that's the vibe check failing, bestie πŸ’€
  • digest β€” the message digest function used in the derivation. PKCS5_PBKDF2_HMAC_SHA1() calls PKCS5_PBKDF2_HMAC() with EVP_sha1().
  • out β€” the derived key will be written to out. the size of the out buffer is specified via keylen. so yes, you gotta give it room to slay 🫢

πŸ¦‹ NOTES πŸ¦‹

a typical application of this function is to derive keying material for an encryption algorithm from a password in the pass, a salt in salt, and an iteration count. iconic behavior, honestly.

increasing the iter parameter slows down the algorithm, which makes it harder for an attacker to perform a brute force attack using a large number of candidate passwords. lowkey the whole point: make brute force expensive, bestie πŸ”₯

these functions make no assumption regarding the given password. it will simply be treated as a byte sequence. no judgment, no trimming, no "are you sure?" β€” just bytes πŸ’œ

πŸŽ€ RETURN VALUES πŸŽ€

PKCS5_PBKDF2_HMAC() and PBKCS5_PBKDF2_HMAC_SHA1() return 1 on success or 0 on error. and yes, that line literally says PBKCS5_PBKDF2_HMAC_SHA1() β€” character check, iykyk πŸ’€

πŸ’… SEE ALSO πŸ’…

legal bestie moment, exact as printed:

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

signed off from the OpenSSL 3.5.0 manual, dated 2026-09-25 β€” go derive responsibly and stay salty, bestie πŸ§šπŸ’œ

πŸ“¦ where this page comes from