OpenBSD manual page server

Manual Page Search Parameters
GETENTROPY(2) System Calls Manual GETENTROPY(2)

getentropyget entropy

#include <unistd.h>

getentropy(void *buf, size_t buflen);

() fills a buffer with high-quality entropy, which can be used as input for process-context pseudorandom generators like arc4random(3).

The maximum buffer size permitted is 256 bytes.

() is not intended for regular code; use the arc4random(3) family of functions instead.

The high-quality entropy data is provided by the random(4) subsystem.

Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

getentropy() will succeed unless:

The buf parameter points to an invalid address.
Too many bytes requested, or some other fatal error occurred.


The getentropy() function appeared in OpenBSD 5.6.

February 6, 2022 OpenBSD-current