.\" $NetBSD: getentropy.3,v 1.4.2.1 2023/08/11 14:35:24 martin Exp $ $ .\" .\" Copyright (c) 2020 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Nia Alarie. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd February 28, 2023 .Dt GETENTROPY 3 .Os .Sh NAME .Nm getentropy .Nd generate uniform random seeds from system entropy for cryptography .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn getentropy "void *buf" "size_t buflen" .In limits.h .Pp .Li #define GETENTROPY_MAX 256 .Sh DESCRIPTION .Pp The .Nm function fills .Fa buf with exactly .Fa buflen independent uniform random bytes derived from the system's entropy pool. .Pp The output of .Nm is meant to be unpredictable to an adversary and fit for use in cryptography. See .Sx CAVEATS below. .Pp .Nm is meant for seeding random number generators, not for direct use by applications; most applications should use .Xr arc4random 3 . .Pp .Fa buflen must be at most 256. .Sh RETURN VALUES .Rv -std getentropy .Sh ERRORS .Fn getentropy will succeed unless: .Bl -tag -width Er .It Bq Er EFAULT The .Fa buf argument points to an invalid memory address. .It Bq Er EINVAL More than 256 bytes were requested. .El .Sh CAVEATS Security can only be guaranteed relative to whatever unpredictable physical processes or secret seed material are available to the system; see .Xr entropy 7 . .Pp On systems which have no hardware random number generator and which have not had secret seed material loaded, .Nx makes a reasonable effort to incorporate samples from various physical processes available to it that might be unpredictable from random jitter in timing. .Pp However, the .Nm interface alone can make no security guarantees without a physical system configuration that includes random number generation hardware or secret seed material from such hardware on another machine. .Sh SEE ALSO .Xr arc4random 3 , .Xr rnd 4 , .Xr entropy 7 .Sh STANDARDS The .Fn getentropy function is nonstandard. However, it is likely to be included in the next revision of POSIX. .Sh HISTORY The .Fn getentropy function first appeared in .Ox 5.6 , then in .Fx 12.0 , and in .Nx 10.0 .