RAND_SET_DRBG_TYPE(3ossl)

✨ RAND_SET_DRBG_TYPE(3ossl) ✨

okay bestie, welcome to the OpenSSL manual page for RAND_set_DRBG_type and RAND_set_seed_source_type πŸ’– like yes we're picking which random number generator the library uses, and no it is NOT as scary as it sounds, i promise. grab a strawberry πŸ“ and let's go.


🌸 NAME 🌸

RAND_set_DRBG_type, RAND_set_seed_source_type β€” specify the global random number generator types

lowkey the whole vibe of this page: you're telling OpenSSL which RNG to roll with, globally, before anything else gets a chance to make one. main character energy, but for randomness. ✨


πŸŽ€ 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);

look at those signatures. iconic. don't change a single character of them. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So. RAND_set_DRBG_type() specifies the random bit generator that will be used within the library context ctx. The way it works: a generator of name drbg with properties propq gets fetched, and then it gets instantiated with either cipher or digest as its underlying cryptographic algorithm. Not both, bestie β€” either. πŸ™ˆ

And this? This sets the type used for the primary, public and private random instances. All three. At once. Slay. πŸ‘‘

Then there's RAND_set_seed_source_type(), which specifies the seed source that will be used within the library context ctx. The seed source of name seed with properties propq gets fetched and used to seed the primary random bit generator. it's giving "feed the main RNG" and honestly? crucial. 🌱


⭐ RETURN VALUES ⭐

These functions return 1 on success and 0 on failure. that's it, that's the whole thing. binary. like your opinion of anyone who ships code without seeding properly. 😭


πŸ”₯ NOTES πŸ”₯

okay this part is important, do NOT skip it, no cap:

  • These functions must be called before the random bit generators are first created in the library context. If you call them too late, they will return an error. too late = you already lost, bestie πŸ’€
  • The default DRBG is "CTR-DRBG" using the "AES-256-CTR" cipher. that's the standard-issue vibe.
  • The default seed source can be configured when OpenSSL is compiled by setting -DOPENSSL_DEFAULT_SEED_SRC=SEED-SRC. If that isn't set, then "SEED-SRC" is used.

🌈 EXAMPLES 🌈

here's a whole little moment of code, verbatim, as the universe intended:

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

see how it sets the seed source before calling RAND_bytes()? that's the whole point, that's the order, that's the law. 🫢


πŸ’œ SEE ALSO πŸ’œ

go read those next, bestie, they're the extended universe 🧚


πŸ‘‘ HISTORY πŸ‘‘

These functions were added in OpenSSL 3.0. so they're not ancient, they're just established. a modern classic. ✨


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


okay that's the page!! πŸ’– this was OpenSSL version 3.5.9, dated 2026-09-29, and the page is RAND_SET_DRBG_TYPE(3ossl) β€” go forth and seed responsibly, bestie, mwah πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from