1.\" $OpenBSD: getentropy.2,v 1.11 2024/08/02 01:53:21 guenther Exp $ 2.\" 3.\" Copyright (c) 2014 Theo de Raadt 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: August 2 2024 $ 18.Dt GETENTROPY 2 19.Os 20.Sh NAME 21.Nm getentropy 22.Nd get entropy 23.Sh SYNOPSIS 24.In unistd.h 25.Ft int 26.Fn getentropy "void *buf" "size_t buflen" 27.Sh DESCRIPTION 28.Fn getentropy 29fills a buffer with high-quality entropy, which can be used 30as input for process-context pseudorandom generators like 31.Xr arc4random 3 . 32.Pp 33The maximum buffer size permitted is 34.Dv GETENTROPY_MAX 35(256) bytes. 36.Pp 37.Fn getentropy 38is not intended for regular code; use the 39.Xr arc4random 3 40family of functions instead. 41.Pp 42The high-quality entropy data is provided by the 43.Xr random 4 44subsystem. 45.Sh RETURN VALUES 46.Rv -std 47.Sh ERRORS 48.Fn getentropy 49will succeed unless: 50.Bl -tag -width Er 51.It Bq Er EFAULT 52The 53.Fa buf 54parameter points to an 55invalid address. 56.It Bq Er EINVAL 57Too many bytes requested. 58.El 59.Sh SEE ALSO 60.Xr arc4random 3 61.Sh STANDARDS 62The 63.Fn getentropy 64function conforms to 65.St -p1003.1-2024 . 66.Sh HISTORY 67The 68.Fn getentropy 69function appeared in 70.Ox 5.6 . 71