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() β€” returns 1 on success and 0 on failure. classic.
  • RAND_get_rand_method() and RAND_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 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