summaryrefslogtreecommitdiff
path: root/lib/libcrypto/arc4random
AgeCommit message (Collapse)Author
2017-04-29Switch Linux getrandom() usage to non-blocking mode, continuing toBob Beck
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@
2016-09-02add iOS support for getentropyBrent Cook
from jacob berkman
2016-08-07Update the link for the getentropy(2) manual to man.openbsd.org/Theo Buehler
ok deraadt@
2016-06-30Tighten behavior of _rs_allocate failure for portable arc4random ↵Brent Cook
implementations. In the event of a failure in _rs_allocate for rsx, we still have a reference to freed memory for rs on return. Not a huge deal since we subsequently abort in _rs_init, but it looks strange on its own. ok deraadt@
2016-06-30Tighten behavior of _rs_allocate on Windows.Brent Cook
For Windows, we are simply using calloc, which has two annoyances: the memory has more permissions than needed by default, and it comes from the process heap, which looks like a memory leak since this memory is rightfully never freed. This switches _rs_alloc on Windows to use VirtualAlloc, which restricts the memory to READ|WRITE and keeps the memory out of the process heap. ok deraadt@
2016-04-19fix typo in comment; ok beckT.J. Townsend
2016-01-04Calling clone(2) with CLONE_NEWPID yields multiple processes with pid=1.Brent Cook
Work around this particular case by reseeding whenever pid=1, but as guenther@ notes, directly calling clone(2), and then forking to match another pid, provides other ways to bypass new process detection on Linux. Hopefully at some point Linux implements something like MAP_INHERIT_ZERO, and does not invent a corresponding mechanism to subvert it. Noted by Sebastian Krahmer and the opmsg team. See http://stealth.openwall.net/crypto/randup.c for a test program. ok beck@
2015-09-11unify files furtherTheo de Raadt
2015-08-25unify versions, so they are easier to diff.Theo de Raadt
2015-08-25KNFTheo de Raadt
2015-06-13Remove unneeded sys/sysctl.h on linux.Brent Cook
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.
2015-04-27Not all Linux libc's include linux/sysctl.h in sys/sysctl.h.Brent Cook
Include it if we have the sysctl syscall.
2015-04-27Support AIX versions without WPAR support.Brent Cook
From Michael Felt.
2015-03-30add initial AIX getentropy/arc4random files. Thanks to Michael Felt.Brent Cook
2015-03-22sys/sysctl.h includes linux/sysctl.h, remove the extra unchecked includeBrent Cook
2015-01-19Add arc4random/getentropy shims for NetBSD.Brent Cook
The latest NetBSD (6.1.5) arc4random does not appear to reseed the CRNG state after a fork, so provide an override until the fork-safe version in CVS appears in a release. These are the same as the FreeBSD shims. ok deraadt@
2015-01-15back in september I did the large abstraction refactoring to allow theseTheo de Raadt
other systems to fit into the same mold, so add copyright
2015-01-07mix in more virtual memory and process informationBrent Cook
2015-01-06add initial HP-UX getentropy/arc4random support.Brent Cook
patch from Kinichiro Inoguchi, tested on HP-UX 11.31 ok deraadt@
2014-11-11correct the failure case for getentropy on win32Brent Cook
CryptAcquireContext and CryptGenRandom returns zero (FALSE) if fails. From: Dongsheng Song <dongsheng.song@gmail.com>
2014-11-03Add hooks to override native arc4random_buf on FreeBSD.Brent Cook
The FreeBSD-native arc4random_buf implementation falls back to weak sources of entropy if the sysctl fails. Remove these dangerous fallbacks by overriding locally. Unfortunately, pthread_atfork() is also broken on FreeBSD (at least 9 and 10) if a program does not link to -lthr. Callbacks registered with pthread_atfork() simply fail silently. So, it is not always possible to detect a PID wraparound. I wish we could do better. This improves arc4random_buf's safety compared to the native FreeBSD implementation. Tested on FreeBSD 9 and 10.
2014-10-11include header needed by older linux kernelsBrent Cook
not all versions of <linux/random.h> include <linux/types.h> by default
2014-08-28preserve errno value on success.Brent Cook
If getrandom returns a temporary failure, make sure errno is not polluted when it succeeds. Thanks to deraadt@ for pointing it out.
2014-08-16only build the getrandom path if SYS_getrandom is defined.Brent Cook
like the sysctl path
2014-08-16getrandom(2) support for getentropy_linuxBrent Cook
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@
2014-08-13munmap correct object in (extremely unlikely, and effectively terminal)Theo de Raadt
case of failing to map the 2nd object. found by Paul Maurers
2014-07-22better match proposed syscall apiBrent Cook
2014-07-21protect sysctl path with SYS__sysctl instead; from enh@google, ok bcookTheo de Raadt
2014-07-21Use explicit_bzero() instead of memset() on buffers going out of scope.Philip Guenther
Also, zero the SHA256 context. suggested by "eric" in a comment on an opensslrampage.org post ok miod@ deraadt@
2014-07-21cast from void * before math; enh@googleTheo de Raadt
2014-07-20Move more OS-specific functionality to arc4random.h headers.Brent Cook
Move <sys/mman.h> and raise(SIGKILL) calls to OS-specific headers. On OpenBSD, move thread_private.h as well to arc4random.h. On Windows, use TerminateProcess on getentropy failure. ok deraadt@
2014-07-20initial win32 ARC4_LOCK/UNLOCK implementation.Brent Cook
It may make sense to later replace this with a Critical Section later. ok guenther@
2014-07-20Demonstrate how new linux getrandom() will be called, at least untilTheo de Raadt
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.
2014-07-19remove disabled main hook; we use phdr now; ok bcookTheo de Raadt
2014-07-19tab loveTheo de Raadt
2014-07-19Move _ARC4_ATFORK handlers from thread_private.h in portable.Brent Cook
2014-07-19move _ARC4_LOCK/UNLOCK primitives from thread_private into OS-specific modulesBrent Cook
2014-07-19fixup typosBrent Cook
2014-07-19Change _rs_allocate so it can combine the two regions (rs and rsx)Theo de Raadt
into one if a system has an awesome getentropy(). In that case it is valid to totally throw away the rsx state in the child. If the getentropy() is not very good and has a lazy reseed operation, this combining is a bad idea, and the reseed should probably continue to use the "something old, something new" mix. _rs_allocate() can accomodate either method, but not on the fly. ok matthew
2014-07-18Cleanup portable arc4random fork detection code:Matthew Dempsky
1. Use "len" parameter instead of sizeof(*rs). 2. Simplify the atfork handler to be strictly async signal safe by simply writing to a global volatile sig_atomic_t object, and then checking for this in _rs_forkdetect(). (Idea from discussions with Szabolcs Nagy and Rich Felker.) 3. Use memset(rs, 0, sizeof(*rs)) to match OpenBSD's MAP_INHERIT_ZERO fork semantics to avoid any skew in behavior across platforms. ok deraadt
2014-07-18Seperate arc4random's os-dependent parts into static inline functions,Theo de Raadt
making it much easier for libressl -portable to fill in the gaps. ok bcook beck
2014-07-16Only call getauxval(3) if HAVE_GETAUXVAL is defined. Fixes build on olderMark Kettenis
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@
2014-07-13Use dl_iterate_phdr() to iterate over the segments and throw the addressesTheo de Raadt
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
2014-07-13Provide a link to the canonical API specification.Theo de Raadt
ok beck
2014-07-13Take away the use of the address of main as a source of entropy. CausesBob Beck
distractions to people testing and seeing link errors in some setups. This will come back in another form ok deraadt@
2014-07-12getentropy on Windows. It compiles but has not been thoroughly tested yet.Wouter Wijngaards
OK: beck@
2014-07-12Remove signed/unsigned warning, statement before declaration andWouter Wijngaards
add a function to use function pointers that does not take sizeof(fptr). OK beck@
2014-07-12guard inclusion of sys/sysctl.h so we can detect at compile time andBob Beck
keep linux distros happy that don't have it. ok bcook@
2014-07-12remove gratuitous differences, ok beckTheo de Raadt
2014-07-12remove gratuitous differences, ok beck bcookTheo de Raadt