RAND_SET_RAND_METHOD(3ossl)
β¨ RAND_SET_RAND_METHOD β¨
okay bestie, welcome to RAND_SET_RAND_METHOD(3ossl) β yes that's the page name, it's a whole mouthful, i know π«Ά we're in the OpenSSL manual and we're talking about selecting the RAND method. buckle up, it's giving legacy era energy π
πΈ NAME πΈ
RAND_set_rand_method, RAND_get_rand_method, RAND_OpenSSL β select RAND method. that's the whole vibe, three little functions that pick who's in charge of your randomness π
π SYNOPSIS π
#include <openssl/rand.h>
okay so heads up bestie, these functions have been deprecated since OpenSSL 3.0 π and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value β check openssl_user_macros(7) for the deets.
RAND_METHOD *RAND_OpenSSL(void);
int RAND_set_rand_method(const RAND_METHOD *meth);
const RAND_METHOD *RAND_get_rand_method(void);
π DESCRIPTION π
so like, every single function on this page? deprecated. all of them. not me having to say that first thing π applications should be using RAND_set_DRBG_type(3), EVP_RAND(3) and EVP_RAND(7) instead. periodt.
a RAND_METHOD is basically the lil' spec that says which functions OpenSSL uses for random number generation β¨
RAND_OpenSSL() hands you back the default RAND_METHOD implementation by OpenSSL. and the slay here? this implementation makes sure the PRNG state is unique for each thread π§ iconic behavior honestly.
but WAIT β if an ENGINE is loaded that provides the RAND API, that one gets used instead of whatever RAND_OpenSSL() returned. lowkey messy. also this is deprecated in OpenSSL 3.0 π
RAND_set_rand_method() makes meth the method for PRNG use. and if an ENGINE was providing the method before? it gets released first, no hard feelings π
RAND_get_rand_method() just returns a pointer to the current RAND_METHOD. that's it, that's the function π
π¦ THE RAND_METHOD STRUCTURE π¦
here's the whole struct, verbatim, no cap:
typedef struct rand_meth_st {
int (*seed)(const void *buf, int num);
int (*bytes)(unsigned char *buf, int num);
void (*cleanup)(void);
int (*add)(const void *buf, int num, double entropy);
int (*pseudorand)(unsigned char *buf, int num);
int (*status)(void);
} RAND_METHOD;
so the fields point to functions that get used by, in order: RAND_seed(), RAND_bytes(), internal RAND cleanup, RAND_add(), RAND_pseudo_rand() and RAND_status(). and every single one of those pointers can be NULL if that function isn't implemented. yes, NULL, it's fine, it's allowed π
π RETURN VALUES π
RAND_set_rand_method()β returns1on success and0on failure. classic.RAND_get_rand_method()andRAND_OpenSSL()β return pointers to the respective methods π«Ά
β SEE ALSO β
EVP_RAND(3), RAND_set_DRBG_type(3), RAND_bytes(3), ENGINE_by_id(3), EVP_RAND(7), RAND(7)
π HISTORY π
all of these functions were deprecated in OpenSSL 3.0. yeah. all of them. we been knew π
π COPYRIGHT π
Copyright 2000-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>.
and that's the whole page bestie, we ate and left no crumbs π this was OpenSSL 3.5.9, dated 2026-09-29, filed under RAND_SET_RAND_METHOD(3ossl) β go forth and random responsibly, mwah πβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms