RAND_SET_RAND_METHOD(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’œ NAME πŸ’œ

RAND_set_rand_method, RAND_get_rand_method, RAND_OpenSSL β€” okay bestie, this is the select RAND method situation, and it's a whole thing (it's a 3ossl page, from the OpenSSL fam 🫢)


✨ SYNOPSIS ✨

First things first, the include, no cap:

#include <openssl/rand.h>

So here's the tea 😭 β€” the following functions have been deprecated since OpenSSL 3.0, and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value. Peep openssl_user_macros(7) for that:

RAND_METHOD *RAND_OpenSSL(void);

int RAND_set_rand_method(const RAND_METHOD *meth);

const RAND_METHOD *RAND_get_rand_method(void);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so real talk: all of the functions described on this page are deprecated πŸ’€. Applications should instead use RAND_set_DRBG_type(3), EVP_RAND(3) and EVP_RAND(7). Noted, moving on.

A RAND_METHOD specifies the functions that OpenSSL uses for random number generation. It's literally the blueprint of "how do we make randomness" πŸ‘‘

RAND_OpenSSL() returns the default RAND_METHOD implementation by OpenSSL. And the way this implementation slays is that it ensures the PRNG state is unique for each thread ✨ (per-thread vibes, no sharing, we love to see it).

But 🌸 β€” if an ENGINE is loaded that provides the RAND API, then it will be used instead of the method returned by RAND_OpenSSL(). And that whole behavior is deprecated in OpenSSL 3.0, so, yeah, it's giving legacy πŸ™ˆ.

RAND_set_rand_method() makes meth the method for PRNG use. And if an ENGINE was providing the method, it will be released first (politely shown the door πŸ’…).

RAND_get_rand_method() returns a pointer to the current RAND_METHOD. Simple as that, bestie.


πŸŽ€ THE RAND_METHOD STRUCTURE πŸŽ€

Here's what the struct looks like, character for character, because I would never mess with your code:

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 are used by, in order:

  1. RAND_seed()
  2. RAND_bytes()
  3. internal RAND cleanup
  4. RAND_add()
  5. RAND_pseudo_rand()
  6. RAND_status()

And each pointer may be NULL if the function is not implemented β€” so like, no pressure, not every slot has to be filled 🫢


🌈 RETURN VALUES 🌈

  • RAND_set_rand_method() β€” returns 1 on success and 0 on failure. That's it, that's the whole mood.
  • RAND_get_rand_method() and RAND_OpenSSL() β€” return pointers to the respective methods.

🌸 SEE ALSO 🌸

Go read these, iykyk:


⭐ HISTORY ⭐

All of these functions were deprecated in OpenSSL 3.0. Every single one. Periodt πŸ’…


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


πŸ’– ngl this page was 3.5.0 energy, dated 2026-09-25, and it is literally RAND_SET_RAND_METHOD(3ossl) β€” drink water, use EVP_RAND(3) instead, mwah πŸ§šβ€β™€οΈβœ¨
πŸ“¦ where this page comes from