diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-05-31 13:42:58 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-05-31 13:42:58 +0000 |
| commit | 5a243ca784b423d6c39f02521029e7151e76908a (patch) | |
| tree | c52498d34dae03252fb5c2ca710755d15ccadd9a /include | |
| parent | a6efbbf4d8ff7f6f492caa04dd41cac9bc4a5f56 (diff) | |
libc: Reintroduce getentropy.
This was introduced two years ago when the getrandom/getentropy API
question was still open, and removed because the discussion was
ongoing. Now getentropy is more widely adopted and soon to be in
POSIX. So reintroduce the symbol into libc since we'll be keeping it
anyway. Discussion of details of the semantics, as interpreted by
NetBSD, is ongoing, but the symbol needs to get in before the
netbsd-10 branch. The draft POSIX text is
(https://www.opengroup.org/austin/docs/austin_1110.pdf):
SYNOPSIS
#include <unistd.h>
int getentropy(void *buffer, size_t length);
DESCRIPTION
The getentropy() function shall write length bytes of data
starting at the location pointed to by buffer. The output
shall be unpredictable high quality random data, generated by
a cryptographically secure pseudo-random number
generator. The maximum permitted value for the length
argument is given by the {GETENTROPY_MAX} symbolic constant
defined in <limits.h>.
RETURN VALUES
Upon successful completion, getentropy() shall return 0;
otherwise, -1 shall be retunred and errno set to indicate the
error.
ERRORS
The getentropy() function shall fail if:
[EINVAL] The value of length is greater than
{GETENTROPY_MAX}.
The getentropy() function may fail if:
[ENOSYS] The system does not provide the necessary
source of entropy.
RATIONALE
The getentropy() function is not a cancellation point.
Minor changes from the previous introduction of getentropy into libc:
- Return EINVAL, not EIO, on buflen > 256.
- Define GETENTROPY_MAX in limits.h.
The declaration of getentropy in unistd.h and definition of
GETENTROPY_MAX in limits.h are currently conditional on
_NETBSD_SOURCE. When the next revision of POSIX is finalized, we can
expose them also under _POSIX_C_SOURCE > 20yymmL as usual -- and this
can be done as a pullup without breaking existing compiled programs.
Diffstat (limited to 'include')
| -rw-r--r-- | include/limits.h | 6 | ||||
| -rw-r--r-- | include/unistd.h | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/include/limits.h b/include/limits.h index 12c25c73b24..98591592ad3 100644 --- a/include/limits.h +++ b/include/limits.h @@ -1,4 +1,4 @@ -/* $NetBSD: limits.h,v 1.42 2019/09/15 23:52:59 christos Exp $ */ +/* $NetBSD: limits.h,v 1.43 2022/05/31 13:42:59 riastradh Exp $ */ /* * Copyright (c) 1988, 1993 @@ -144,6 +144,10 @@ #define MB_LEN_MAX 32 /* Allow ISO/IEC 2022 */ +#ifdef _NETBSD_SOURCE +#define GETENTROPY_MAX 256 +#endif + #include <machine/limits.h> #ifdef __CHAR_UNSIGNED__ diff --git a/include/unistd.h b/include/unistd.h index ea941acb76a..a4be358a994 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -1,4 +1,4 @@ -/* $NetBSD: unistd.h,v 1.162 2021/10/15 22:32:28 andvar Exp $ */ +/* $NetBSD: unistd.h,v 1.163 2022/05/31 13:42:59 riastradh Exp $ */ /*- * Copyright (c) 1998, 1999, 2008 The NetBSD Foundation, Inc. @@ -338,6 +338,7 @@ int fchroot(int); int fdiscard(int, off_t, off_t); int fsync_range(int, int, off_t, off_t); int getdomainname(char *, size_t); +int getentropy(void *, size_t); int getgrouplist(const char *, gid_t, gid_t *, int *); int getgroupmembership(const char *, gid_t, gid_t *, int, int *); mode_t getmode(const void *, mode_t); |
