EVP_PKEY_CTX_SET_SCRYPT_N(3SSL)

πŸ’– EVP_PKEY_CTX_set1_scrypt_salt, EVP_PKEY_CTX_set_scrypt_N, EVP_PKEY_CTX_set_scrypt_r, EVP_PKEY_CTX_set_scrypt_p, EVP_PKEY_CTX_set_scrypt_maxmem_bytes β€” the scrypt KDF glow-up ✨

okay bestie so this is straight out of the OpenSSL 3SSL manual, and it's literally the EVP_PKEY scrypt KDF support functions. yes that's a mouthful, we're gonna get through it together 🫢


🌸 SYNOPSIS 🌸

#include <openssl/kdf.h>

int EVP_PKEY_CTX_set1_scrypt_salt(EVP_PKEY_CTX *pctx, unsigned char *salt,
                                  int saltlen);

int EVP_PKEY_CTX_set_scrypt_N(EVP_PKEY_CTX *pctx, uint64_t N);

int EVP_PKEY_CTX_set_scrypt_r(EVP_PKEY_CTX *pctx, uint64_t r);

int EVP_PKEY_CTX_set_scrypt_p(EVP_PKEY_CTX *pctx, uint64_t p);

int EVP_PKEY_CTX_set_scrypt_maxmem_bytes(EVP_PKEY_CTX *pctx,
                                         uint64_t maxmem);

like look at her, five little functions, all int-returning, all taking an EVP_PKEY_CTX *pctx first. iconic. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so these functions are the setup crew πŸŽ€ they set up all the data you need to actually use the scrypt KDF. and if you want the full scrypt lore, go read EVP_KDF-SCRYPT(7). iykyk.

  • EVP_PKEY_CTX_set1_scrypt_salt() β€” sets the salt value, and the salt is saltlen bytes long. that's it, that's the whole job. bestie just drops the salt in. πŸ§‚βœ¨
  • EVP_PKEY_CTX_set_scrypt_N(), EVP_PKEY_CTX_set_scrypt_r() and EVP_PKEY_CTX_set_scrypt_p() β€” these three configure the work factors N, r and p. yes they're the main characters of the difficulty dial, respect them. πŸ‘‘
  • EVP_PKEY_CTX_set_scrypt_maxmem_bytes() β€” sets how much RAM key derivation is allowed to use maximally, and it's given in bytes. and here's the part where u need to pay attention fr fr β€” if the RAM gets exceeded because the load factors are chosen too high, the key derivation will fail. no cap. so don't be greedy with those work factors or she just gives up 😭

✨ STRING CTRLS ✨

plot twist: scrypt also supports string based control operations</> through EVP_PKEY_CTX_ctrl_str(3). love that for her 🌈

and similarly (yes we're doing "similarly"), the salt can be specified either:

  • using the type parameter "salt", or
  • in hex encoding, by using the "hexsalt" parameter.

the work factors N, r and p, plus maxmem_bytes, can each be set by using the parameters "N", "r", "p" and "maxmem_bytes", respectively. respectively!! she's so organized πŸŽ€


πŸ’œ NOTES πŸ’œ

  • real talk: there's a newer generic API for KDFs, EVP_KDF(3), and it is preferred over the EVP_PKEY method. so like… if you're starting fresh, that one's the vibe.
  • the scrypt KDF also uses EVP_PKEY_CTX_set1_pbe_pass() as well as the value from the string controls "pass" and "hexpass". see EVP_PKEY_CTX_set1_pbe_pass(3) for the tea. πŸ“

⭐ RETURN VALUES ⭐

all of these functions return 1 for success, and 0 or a negative value for failure. simple as. πŸ’–

and in particular β€” drumroll pls β€” a return value of -2 indicates the operation is not supported by the public key algorithm. so if u see that -2, it's not you, it's the algorithm 🫢


πŸ‘‘ SEE ALSO πŸ‘‘


🌈 HISTORY 🌈

all of the functions described here were converted from macros to functions in OpenSSL 3.0. glow-up arc complete, we love a redemption story ✨


Copyright 2017-2020 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 so that's the whole page bestie 🫢 go forth and derive your keys, but keep an eye on that maxmem_bytes or she WILL fail on you πŸ’€

and that's a wrap on EVP_PKEY_CTX_SET_SCRYPT_N(3SSL) β€” this was OpenSSL 4.0.3, dated 2026-09-29. mwah, periodt πŸ’…πŸŒΈ

πŸ“¦ where this page comes from