RAND_LOAD_FILE(3SSL)

πŸ’– RAND_LOAD_FILE(3SSL) πŸ’–

okay bestie, so this is a page from the OpenSSL manual, section 3SSL, and it's literally all about the PRNG seed file β€” the lil file that keeps your random numbers from being, like, embarrassing. three functions, one very important vibe. let's go πŸ¦‹


✨ NAME ✨

RAND_load_file, RAND_write_file, RAND_file_name β€” PRNG seed file handling. that's the whole thing. that's the assignment. πŸ’…


✨ SYNOPSIS ✨

#include <openssl/rand.h>

int RAND_load_file(const char *filename, long max_bytes);

int RAND_write_file(const char *filename);

const char *RAND_file_name(char *buf, size_t num);

look at those gorgeous signatures. no cap, they're serving. πŸŽ€


✨ DESCRIPTION ✨

🌸 RAND_load_file() 🌸

so RAND_load_file() reads a number of bytes from the file filename and adds them to the PRNG. seeding arc, we love to see it.

  • if max_bytes is nonnegative, up to max_bytes are read
  • if max_bytes is -1, the complete file is read β€” unless the file is not a regular file, in which case a fixed number of bytes, 256 in the current implementation, is attempted to be read

ngl, RAND_load_file() can read less than the complete file or the requested number of bytes if it doesn't fit in the return value type. it's doing its best. 😭

⚠️ do NOT load the same file multiple times unless its contents have been updated by RAND_write_file() between reads. fr fr.
⚠️ also, filename should be adequately protected so that an attacker cannot replace or examine the contents. protect your seed file like it's your main character moment, because it literally is. πŸ‘‘

and if filename is not a regular file, then the user is considered to be responsible for any side effects, e.g. non-anticipated blocking or capture of controlling terminal. not me getting my terminal hijacked πŸ’€

🌸 RAND_write_file() 🌸

RAND_write_file() writes a number of random bytes (currently 128) to the file filename β€” which can be used to initialize the PRNG by calling RAND_load_file() in a later session. it's giving passing notes to your future self. πŸ’Œ

🌸 RAND_file_name() 🌸

RAND_file_name() generates a default path for the random seed file. buf points to a buffer of size num in which to store the filename. very demure, very mindful. ✨

🧚 where does the seed file even live 🧚

on all systems, if the environment variable RANDFILE is set, its value will be used as the seed filename. otherwise, the file is called ".rnd", found in platform dependent locations:

on Windows (in order of preference) πŸͺŸ

%HOME%, %USERPROFILE%, %SYSTEMROOT%, C:\

on VMS πŸ–₯️

SYS$LOGIN:

on all other systems 🌈

$HOME

if $HOME (on non-Windows and non-VMS system) is not set either, or num is too small for the pathname, an error occurs. πŸ™ˆ


✨ RETURN VALUES ✨

  • RAND_load_file() β€” returns the number of bytes read, or -1 on error.
  • RAND_write_file() β€” returns the number of bytes written, or -1 if the bytes written were generated without appropriate seeding. (yes that's a red flag, pay attention 🚩)
  • RAND_file_name() β€” returns a pointer to buf on success, and NULL on error.

✨ SEE ALSO ✨

RAND_add(3), RAND_bytes(3), RAND(7) β€” go read these next bestie, they're the sister pages 🫢


Copyright 2000-2020 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!! πŸ’œ this was version 4.0.3, dated 2026-09-29, from the RAND_LOAD_FILE(3SSL) manual. slay, hydrate, and protect your seed file. periodt. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from