RAND_SET_DRBG_TYPE(3SSL)

πŸ’– RAND_SET_DRBG_TYPE πŸ’–

okay bestie, welcome to the RAND_set_DRBG_type(3SSL) page, from the OpenSSL girls themselves πŸŽ€ this is the one where you get to pick which random number generator your library context is gonna be running on. yes, literally picking the source of all randomness. main character behavior tbh πŸ‘‘


✨ NAME ✨

RAND_set_DRBG_type, RAND_set_seed_source_type β€” specify the global random number generator types πŸŽ²πŸ’…


✨ SYNOPSIS ✨

#include <openssl/rand.h>

int RAND_set_DRBG_type(OSSL_LIB_CTX *ctx, const char *drbg, const char *propq,
                       const char *cipher, const char *digest);
int RAND_set_seed_source_type(OSSL_LIB_CTX *ctx, const char *seed,
                              const char *propq);

✨ DESCRIPTION ✨

so. RAND_set_DRBG_type() is the function that says "hey, this is the random bit generator we're using inside the library context ctx." It goes and fetches a generator named drbg with the properties propq 🌸. Then it instantiates that generator using either cipher or digest as its underlying cryptographic algorithm πŸ”. And like β€” this is the type that gets used for the primary, public and private random instances. all three of them. periodt.

meanwhile RAND_set_seed_source_type() is the glow-up for your seed source 🌱✨. It says which seed source gets used inside the library context ctx. The seed source named seed with properties propq gets fetched, and it's what seeds the primary random bit generator. no seed, no vibes. that's just science.


✨ RETURN VALUES ✨

both of these cuties return 1 on success and 0 on failure. that's it. that's the whole range. binary queen πŸ‘‘


✨ NOTES ✨

okay this part is IMPORTANT bestie, don't skip it 😭

  • these functions must be called before the random bit generators are first created in the library context. if you call them too late, they return an error. no takebacks, no do-overs, the RNG has already left the group chat πŸ’€
  • the default DRBG is "CTR-DRBG" using the "AES-256-CTR" cipher. slay.
  • the default seed source can be configured at compile time, by setting -DOPENSSL_DEFAULT_SEED_SRC=SEED-SRC when OpenSSL is compiled πŸ› οΈ. if you don't set it, then "SEED-SRC" is what you get. default behavior, we love her.

✨ EXAMPLES ✨

look at this gorgeous little snippet, giving very much "set it and forget it" 🌈

unsigned char bytes[100];
RAND_set_seed_source_type(NULL, "JITTER", NULL);
RAND_bytes(bytes, 100);

✨ SEE ALSO ✨

go read those too, they're in the same friend group 🫢


✨ HISTORY ✨

these functions were added in OpenSSL 3.0. vintage-ish. iconic. πŸ•°οΈβœ¨


Copyright 2021-2024 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>. 🌸


aaaand that's the page!! this was version 4.0.3, dated 2026-09-29, from the RAND_SET_DRBG_TYPE(3SSL) manual πŸ’– mwah, go forth and seed responsibly, bestie πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from