1.\" $OpenBSD: getentropy.2,v 1.6 2014/07/18 18:20:17 deraadt 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: July 18 2014 $ 18.Dt GETENTROPY 2 19.Os 20.Sh NAME 21.Nm getentropy 22.Nd get entropy 23.Sh SYNOPSIS 24.Fd #include <unistd.h> 25.Ft int 26.Fn getentropy "void *buf" "size_t buflen" 27.Sh DESCRIPTION 28.Nm 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 256 bytes. 34If 35.Va buflen 36exceeds this, an error of 37.Er EIO 38will be indicated. 39.Pp 40.Nm 41is not intended for regular code; please use the 42.Xr arc4random 3 43family of functions instead. 44.Sh RETURN VALUES 45Upon successful completion, a value of 0 is returned. 46Otherwise, a value of \-1 is returned and 47.Va errno 48is set to indicate the error. 49.Sh ERRORS 50.Fn getentropy 51will succeed unless: 52.Bl -tag -width Er 53.It Bq Er EFAULT 54The 55.Fa buf 56parameter points to an 57invalid address. 58.It Bq Er EIO 59Too many bytes requested, or some other fatal error occurred. 60.El 61.Sh SEE ALSO 62.Xr arc4random 3 63.Sh HISTORY 64The 65.Nm 66function appeared in 67.Ox 5.6 . 68