bcook
ea887211a6
Backport getentropy changes from deraadt@ on MAIN
Saw a mention somewhere a while back that the gotdata() function in
here could creates non-uniformity since very short fetches of 0 would
be excluded. blocks of 0 are just as random as any other data, including
blocks of 4 4 4.. This is a misguided attempt to identify errors from the
entropy churn/gather code doesn't make sense, errors don't happen.
ok bcook
5 years ago
bcook
becf8cef00
ensure SYS_getrandom and GRND_NONBLOCK are both defined before using getrandom(2)
Based on discussion here https://github.com/libressl-portable/openbsd/pull/82
Suggested fix from jsing@
6 years ago
beck
0e208737fa
Switch Linux getrandom() usage to non-blocking mode, continuing to
use fallback mechanims if unsuccessful.
The design of Linux getrandom is broken. It has an
uninitialized phase coupled with blocking behaviour, which
is unacceptable from within a library at boot time without
possible recovery.
ok deraadt@ jsing@
7 years ago
tb
646f43cf69
Update the link for the getentropy(2) manual to man.openbsd.org/
ok deraadt@
8 years ago
tj
41e193dea0
fix typo in comment; ok beck
8 years ago
deraadt
31a603a934
unify files further
9 years ago
deraadt
8e631f698c
unify versions, so they are easier to diff.
9 years ago
bcook
fd9b2358f2
Remove unneeded sys/sysctl.h on linux.
This only provides the sysctl wrapper in glibc, which we do not use and is not available in other libc implementations for Linux. Thanks to ncopa from github.
9 years ago
bcook
94be377a56
Not all Linux libc's include linux/sysctl.h in sys/sysctl.h.
Include it if we have the sysctl syscall.
9 years ago
bcook
65192b885a
sys/sysctl.h includes linux/sysctl.h, remove the extra unchecked include
9 years ago
bcook
d926e49a0b
include header needed by older linux kernels
not all versions of <linux/random.h> include <linux/types.h> by default
10 years ago
bcook
7131c8971a
preserve errno value on success.
If getrandom returns a temporary failure, make sure errno is not polluted when
it succeeds. Thanks to deraadt@ for pointing it out.
10 years ago
bcook
5fc23a1e55
only build the getrandom path if SYS_getrandom is defined.
like the sysctl path
10 years ago
bcook
e285ea02b5
getrandom(2) support for getentropy_linux
This enables support for the new getrandom(2) syscall in Linux 3.17.
If the call exists and fails, return a failure in getentropy(2) emulation as
well. This adds a EINTR check in case the urandom pool is not initialized.
Tested on Fedora Rawhide with 3.17rc0 and Ubuntu 14.04
ok deraadt@
10 years ago
bcook
aca9f895fe
better match proposed syscall api
10 years ago
deraadt
ef5581e5fc
protect sysctl path with SYS__sysctl instead; from enh@google, ok bcook
10 years ago
guenther
6fd1ff93b6
Use explicit_bzero() instead of memset() on buffers going out of scope.
Also, zero the SHA256 context.
suggested by "eric" in a comment on an opensslrampage.org post
ok miod@ deraadt@
10 years ago
deraadt
de41d1af59
cast from void * before math; enh@google
10 years ago
deraadt
d107050d39
Demonstrate how new linux getrandom() will be called, at least until
it shows up in libraries. Even the system call is probably not finalized.
Bit dissapointed it has turned out to be a descriptor-less read() with
EINVAL and EINTR error conditions, but we can work with it.
10 years ago
deraadt
403b6a2c61
remove disabled main hook; we use phdr now; ok bcook
10 years ago
deraadt
2d56bb72a9
tab love
10 years ago
kettenis
2c152452b6
Only call getauxval(3) if HAVE_GETAUXVAL is defined. Fixes build on older
Linux (such as Ubuntu 12.04LTS) that don't have it yet. Seems the AT_XXX
defines are pulled in by <link.h> now.
ok beck@
10 years ago
deraadt
1efcd9909f
Use dl_iterate_phdr() to iterate over the segments and throw the addresses
into the hash; hoping the system has some ASLR or PIE. This replaces and
substantially improves upon &main which proved problematic with some picky
linkers.
Work with kettenis, testing by beck
10 years ago
deraadt
757bd836f8
Provide a link to the canonical API specification.
ok beck
10 years ago
beck
7f965a2eac
Take away the use of the address of main as a source of entropy. Causes
distractions to people testing and seeing link errors in some setups.
This will come back in another form
ok deraadt@
10 years ago
wouter
ca0c9eb852
Remove signed/unsigned warning, statement before declaration and
add a function to use function pointers that does not take sizeof(fptr).
OK beck@
10 years ago
beck
279cc5b646
guard inclusion of sys/sysctl.h so we can detect at compile time and
keep linux distros happy that don't have it.
ok bcook@
10 years ago
deraadt
96303f230c
remove gratuitous differences, ok beck bcook
10 years ago
beck
b7e16f9d19
fix oops, accidental delete.. darn copying of files between machines
10 years ago
beck
8de43bf12f
j should be an int, like repeat
10 years ago
beck
287fe24a2f
unbreak last commit - but same intent, make re-seed less expensive
10 years ago
deraadt
bc5b290d46
repeat calls to getentrypy() with the same pid likely indicate reseeds.
Since we assume the PRNG above is doing "something old, something new"
folding, shortcut and do fewer repeats through the timing loop.
ok beck
10 years ago
deraadt
0dedf80951
fix HD() misuse; from brent cook
10 years ago
beck
344e312a56
AT_BASE returns us the *address* of the start of ld.so, so
use the address, not what it points to (which is always the same)
ok deraadt@
10 years ago
beck
aed4dc98fb
get the page of data at AT_SYSINFO_EHDR
ok deraadt@
10 years ago
beck
802d41544e
comment fixes from theo
10 years ago
beck
eaa7e91438
Possibly obtain a little bit of entropy from addresses returned
by getauxval if we have it.
ok deraadt@
10 years ago
beck
839b9ab79f
O_NOFOLLOW would be very nice to have here if the version of linux
we are running supports it.
from enh@google.com
10 years ago
beck
dca54ba442
unbreak build of getentropy_sysctl - we need linux/sysctl.h, and
RANDOM_UUID is an enum member.
10 years ago
beck
13d2b96f86
unbreak - main needs to be extern in here somewhere.
10 years ago
deraadt
40d09112d0
repair indentation for an inner loop; shorten some macros and variable
names to shorten line lengths
ok beck
10 years ago
deraadt
7eb671100b
hash in correct pointer
10 years ago
beck
ac370875b0
KNF
10 years ago
deraadt
8f4e03ef5a
indent
10 years ago
otto
1878cbb6e4
rearrange so that the main function with the important comments is at the top
ok deraadt@ beck@
10 years ago
beck
a1d1946997
Work in progress on how to deal with the inherit unreliability of
/dev/urandom. Does well in the fallback case. Get it in tree so
it can be worked on.
ok otto@ deraadt@
10 years ago