-/* $OpenBSD: unistd.h,v 1.109 2024/05/18 05:20:22 guenther Exp $ */
+/* $OpenBSD: unistd.h,v 1.110 2024/08/02 01:53:21 guenther Exp $ */
/* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */
/*-
int unlinkat(int, const char *, int);
#endif
+#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE
+int getentropy(void *, size_t);
+#endif
+
#if __BSD_VISIBLE
int dup3(int, int, int);
int pipe2(int [2], int);
void setusershell(void);
int strtofflags(char **, u_int32_t *, u_int32_t *);
int swapctl(int cmd, const void *arg, int misc);
-int getentropy(void *, size_t);
int pledge(const char *, const char *);
int unveil(const char *, const char *);
pid_t __tfork_thread(const struct __tfork *, size_t, void (*)(void *),
-.\" $OpenBSD: getentropy.2,v 1.10 2022/02/06 00:29:02 jsg Exp $
+.\" $OpenBSD: getentropy.2,v 1.11 2024/08/02 01:53:21 guenther Exp $
.\"
.\" Copyright (c) 2014 Theo de Raadt
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: February 6 2022 $
+.Dd $Mdocdate: August 2 2024 $
.Dt GETENTROPY 2
.Os
.Sh NAME
as input for process-context pseudorandom generators like
.Xr arc4random 3 .
.Pp
-The maximum buffer size permitted is 256 bytes.
+The maximum buffer size permitted is
+.Dv GETENTROPY_MAX
+(256) bytes.
.Pp
.Fn getentropy
is not intended for regular code; use the
.Fa buf
parameter points to an
invalid address.
-.It Bq Er EIO
-Too many bytes requested, or some other fatal error occurred.
+.It Bq Er EINVAL
+Too many bytes requested.
.El
.Sh SEE ALSO
.Xr arc4random 3
+.Sh STANDARDS
+The
+.Fn getentropy
+function conforms to
+.St -p1003.1-2024 .
.Sh HISTORY
The
.Fn getentropy
-/* $OpenBSD: rnd.c,v 1.228 2024/06/14 10:17:05 claudio Exp $ */
+/* $OpenBSD: rnd.c,v 1.229 2024/08/02 01:53:21 guenther Exp $ */
/*
* Copyright (c) 2011,2020 Theo de Raadt.
#include <sys/msgbuf.h>
#include <sys/mount.h>
#include <sys/syscallargs.h>
+#include <sys/syslimits.h>
#include <crypto/sha2.h>
syscallarg(void *) buf;
syscallarg(size_t) nbyte;
} */ *uap = v;
- char buf[256];
+ char buf[GETENTROPY_MAX];
int error;
if (SCARG(uap, nbyte) > sizeof(buf))
- return (EIO);
+ return (EINVAL);
arc4random_buf(buf, SCARG(uap, nbyte));
if ((error = copyout(buf, SCARG(uap, buf), SCARG(uap, nbyte))) != 0)
return (error);
-/* $OpenBSD: syslimits.h,v 1.15 2022/02/22 16:58:08 deraadt Exp $ */
+/* $OpenBSD: syslimits.h,v 1.16 2024/08/02 01:53:21 guenther Exp $ */
/* $NetBSD: syslimits.h,v 1.12 1995/10/05 05:26:19 thorpej Exp $ */
/*
#define HOST_NAME_MAX 255 /* max hostname length w/o NUL */
#endif
+#if __POSIX_VISIBLE >= 202405
+#define GETENTROPY_MAX 256 /* max bytes from getentropy(2) */
+#endif
+
#define _MAXCOMLEN 24 /* includes NUL */