getentropy(3)

getentropy3

Get entropy

Usage

#include <unistd.h>

int

getentropy(void *buf, size_t buflen);

Library

Standard C Library (libc, -lc)

Overview

getentropy() fills a buffer with high-quality random data.

The maximum buflen permitted is 256 bytes.

If it does not produce an error, getentropy() always provides the requested number of bytes of random data.

Similar to reading from /dev/urandom just after boot, getentropy() may block until the system has collected enough entropy to seed the CSPRNG.

Implementation notes

The getentropy() function is implemented using getrandom(2).

Return values

The getentropy() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Errors

getentropy() will succeed unless:

[EFAULT]

The buf parameter points to an invalid address.

[EINVAL]

Too many bytes requested.

Releases

20 releases since FreeBSD 12.0-RELEASE; the text changed 7 times.

  1. 12.0
  2. 12.1
  3. 12.2
  4. 12.3
  5. 12.4
  6. 13.0–13.2
  7. 13.3–14.2
  8. 14.3–16.0

Standards

getentropy() conforms to IEEE Std 1003.1-2024 (“POSIX.1”).

History

The getentropy() function appeared in OpenBSD 5.6. The FreeBSD libc compatibility shim first appeared in FreeBSD 12.0.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.