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,256in 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-1on error.RAND_write_file()β returns the number of bytes written, or-1if 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, andNULLon error.
β¨ SEE ALSO β¨
RAND_add(3), RAND_bytes(3), RAND(7) β go read these next bestie, they're the sister pages π«Ά
β¨ COPYRIGHT β¨
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
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms