.\" $NetBSD: getentropy.3,v 1.4 2022/05/31 13:42:59 riastradh 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 May 1, 2020 .Dt GETENTROPY 3 .Os .Sh NAME .Nm getentropy .Nd fill a buffer with high quality random data .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn getentropy "void *buf" "size_t buflen" .In limits.h .Li #define GETENTROPY_MAX 256 .Sh DESCRIPTION .Pp The .Fn getentropy function fills a buffer with high quality random data, suitable for seeding cryptographically secure psuedorandom number generators. .Pp .Fn getentropy is only intended for seeding random number generators and is not intended for use by regular code which simply needs secure random data. For this purpose, please use .Xr arc4random 3 . .Pp The maximum value for .Li buflen is 256 bytes. .Sh IMPLEMENTATION NOTES .Fn getentropy reads from the .Xr sysctl 7 variable .Li kern.arandom . .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. .Sh SEE ALSO .Xr arc4random 3 , .Xr rnd 4 .Sh STANDARDS The .Fn getentropy function is non-standard. 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 .Nx 10 .