RAND_EGD(3ossl)

✨ RAND_EGD β€” the "hey bestie can I borrow some randomness" page πŸ’–

okay so this is from the OpenSSL manual, section 3ossl, and it's literally all about asking a little daemon for some chaos. randomness. entropy. the good stuff. πŸŽ€


🌸 NAME 🌸

RAND_egd, RAND_egd_bytes, RAND_query_egd_bytes β€” query an entropy gathering daemon, bestie. it's giving "borrow some randomness from the neighbor". πŸ¦‹


✨ SYNOPSIS ✨

#include <openssl/rand.h>

int RAND_egd_bytes(const char *path, int num);
int RAND_egd(const char *path);

int RAND_query_egd_bytes(const char *path, unsigned char *buf, int num);

look at those signatures. so clean. so iconic. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so picture this: you're on some older platform and there's no good source of randomness lying around β€” like, no "/dev/urandom" to be found. tragic. 😭 but no worries, because you can still query an Entropy Gathering Daemon (EGD for short, slay) over a local socket, grab some randomness, and use it to seed the OpenSSL RNG. the protocol it speaks is defined by the EGDs hanging out at <http://egd.sourceforge.net/> or <http://prngd.sourceforge.net>. iykyk.

RAND_egd_bytes() asks an EGD at the socket path for num bytes of randomness, then takes whatever data comes back and hands it over to RAND_add(). RAND_egd() is literally the same thing but with num set to 255. same vibe, different number. 🫢

RAND_query_egd_bytes() also asks an EGD at path for num bytes of randomness, BUT β€” and this is important bestie β€” num must be less than 256. no exceptions, that's the rule. πŸ“ if buf is NULL, it behaves exactly like RAND_egd_bytes(). if buf is not NULL, then the data gets copied straight into that buffer and RAND_add() is not called. so it's just the fetch, no seeding. πŸ’…

also, fun fact: OpenSSL can be configured at build time to try to use the EGD for seeding automatically. so it might just... do it. on its own. main character energy fr fr. πŸ‘‘


πŸ”₯ RETURN VALUES πŸ”₯

RAND_egd() and RAND_egd_bytes() return the number of bytes read from the daemon when things go right, or -1 if the connection failed β€” OR if the daemon didn't return enough data to fully seed the PRNG. so like, partial success is still a fail here. πŸ’€

RAND_query_egd_bytes() returns the number of bytes read from the daemon on success, or -1 if the connection failed. simple. iconic. periodt.


🌈 SEE ALSO 🌈

go read those too, they're all part of the same friend group. 🧚


Copyright 2000-2018 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 whole page is from OpenSSL version 3.5.9, dated 2026-09-29. take care of her, she's doing her best. πŸ’– mwah, bye bestie! πŸŽ€βœ¨
πŸ“¦ where this page comes from