summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/arc4random.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* In the incredibly unbelievable circumstance where _rs_init() fails toderaadt2019-03-241-2/+2
| | | | | | | | | allocate pages, don't call abort() because of corefile data leakage concerns, but simply _exit(). The reasoning is _rs_init() will only fail if someone finds a way to apply specific pressure against this failure point, for the purpose of leaking information into a core which they can read. We don't need a corefile in this instance to debug that. So take this "lever" away from whoever in the future wants to do that.
* Wrap <stdlib.h> so that calls go direct and the symbols not in theguenther2015-09-131-1/+3
| | | | | | C standard are all weak. Apply __{BEGIN,END}_HIDDEN_DECLS to gdtoa{,imp}.h, hiding the arch-specific __strtorx, __ULtox_D2A, __strtorQ, __ULtoQ_D2A symbols.
* Add support for building arc4random with MSVC.bcook2015-09-101-7/+8
| | | | | | | By default, MSVC's stdlib.h defines min(), so we need to spell out something less common to avoid picking it up. ok deraadt@ beck@ miod@
* Move to the <limits.h> universe.deraadt2015-01-161-2/+1
| | | | review by millert, binary checking process with doug, concept with guenther
* back in september I did the large abstraction refactoring to allow thesederaadt2015-01-151-1/+2
| | | | other systems to fit into the same mold, so add copyright
* missing newlinederaadt2014-07-211-1/+2
|
* Move more OS-specific functionality to arc4random.h headers.bcook2014-07-201-5/+2
| | | | | | | | 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@
* Change _rs_allocate so it can combine the two regions (rs and rsx)deraadt2014-07-191-14/+8
| | | | | | | | | | 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
* Seperate arc4random's os-dependent parts into static inline functions,deraadt2014-07-181-36/+11
| | | | | making it much easier for libressl -portable to fill in the gaps. ok bcook beck
* "Race-free because we're running single-threaded in a newderaadt2014-07-171-1/+5
| | | | | address space, and once allocated rs is never deallocated." document the forkhandler to save reviewers time, with matthew
* #ifdef wrap the _rs_forkhandlerderaadt2014-07-161-1/+3
|
* added handler for an atfork hook from kettenis@bcook2014-07-161-1/+10
| | | | ok deraadt@ beck@ kettenis@
* While we thought this would make portable life easier it actuallybeck2014-07-131-3/+1
| | | | | makes it much harder. ok bcook@ kettenis@
* Wrap "thread_private.h" with #ifdef __OpenBSD__ so that other systemsderaadt2014-07-121-1/+3
| | | | | | can copy this file (plus chacha_private.h) directly and reuse it trivially. Well, as long as they have a getentropy() as well.. ok beck
* Split arc4random_uniform into it's own file, to assist other projectsderaadt2014-07-121-37/+1
| | | | | | now using this as upstream code. The particular problem is systems that contain older arc4random derivations lacking arc4random_uniform(). ok tedu miod
* changes to improve portabilitybcook2014-07-091-10/+11
| | | | ok beck@ deraadt@ jsing@ guenther@
* re-init and init code paths are now more shared, so the getpid()-basedderaadt2014-06-271-2/+3
| | | | portable code path must handle that; with brent cook
* Add back an #ifndef MAP_INHERIT_ZERO chunk to support the old getpid()deraadt2014-06-261-1/+13
| | | | | mechanism, to aid in portability to other systems as requested. ok matthew
* document why we explicit_bzeroderaadt2014-06-251-2/+2
|
* arc4random: hard fail with raise(SIGKILL) if getentropy() returns -1matthew2014-06-201-3/+4
| | | | | | | Allow other non-zero return values in case we change our mind to return an ssize_t byte count instead of simple success/fail. ok deraadt, djm
* Move rs_chacha and rs_buf into the same memory page and don't mark itmatthew2014-06-191-22/+31
| | | | | | | | | MAP_INHERIT_ZERO anymore. This restores arc4random's previous behavior where fork children would mix in some randomness from the parent process. New behavior noticed by deraadt ok deraadt, tedu
* Use MAP_INHERIT_ZERO in arc4random(3)matthew2014-06-171-37/+44
| | | | | | | | Now instead of calling getpid() each time a user invokes arc4random(), we're able to rely on the kernel zero'ing out the RNG state if the process forks. ok deraadt, djm
* For now... assume success of getentropy() just like we assumed successderaadt2014-06-131-3/+3
| | | | of sysctl(). Mark it with XXX while we consider.
* use getgentropy() call. If it fails, things are pretty bad --deraadt2014-06-131-8/+3
| | | | | call abort(). this direction discussed at length with miod beck tedu matthew etc
* Delete the extraneous "return" statement at the end of a void function.jca2014-05-311-2/+1
| | | | From Fritjof Bornebusch.
* missing NULL checks to see if init is needed. found hard way by deraadt.tedu2014-05-061-3/+3
|
* clear a stack buffer with explicit_bzerotedu2014-05-061-2/+2
|
* move chacha context and buffer out of bss and allow mmap to place themtedu2014-05-061-6/+16
| | | | wherever it decides it would like them. first step. ok deraadt dlg djm
* delete useless test codederaadt2014-05-041-23/+1
|
* Remove arc4random_stir() and arc4random_addrandom(), which none shouldderaadt2013-10-211-26/+1
| | | | | | be using directly. Well, a few rare people cloned it upstream and it will take a bit of time for them to learn. ok various
* replace rc4 with ChaCha20; inspired by Nick Mathewson's work on libottery;markus2013-10-011-98/+106
| | | | feedback and ok djm@
* spacingderaadt2013-06-111-3/+2
|
* Change arc4random_uniform() to calculate ``2**32 % upper_bound'' asmatthew2012-06-241-12/+3
| | | | | | | | | | ``-upper_bound % upper_bound''. Simplifies the code and makes it the same on both ILP32 and LP64 architectures, and also slightly faster on LP64 architectures by using a 32-bit remainder instead of a 64-bit remainder. Pointed out by Jorden Verwer on tech@ ok deraadt; no objections from djm or otto
* remove comment that hasn't been true for quite a while now;otto2010-12-221-6/+1
| | | | ok deraadt@ djm@
* No point in refreshing the pid from inside arc4_stir() when thatguenther2009-12-151-6/+15
| | | | | | | | | doesn't test it, so factor out the two places that test it into a routine and do the refreshing there. With this, arch4random_buf() doesn't trigger superfluous calls to getpid() when filling large buffers. ok deraadt@, "looks nicer indeed" otto@
* zap __arc4_getbyte(), it was only used by the old malloc; ok millert@otto2008-10-031-14/+1
| | | | kurt@
* fix math screwup that reintroduced a bias for upper_bounds in rangedjm2008-06-041-2/+2
| | | | | | | (2^30,2^31). Nothing in the tree yet requests random numbers bounded by this range. report jakob!deraadt; ok deraadt@
* diff from djm@ committed at his request:otto2008-03-161-1/+63
| | | | | | | | | | | | | | introduce two new APIs for requesting strong random numbers: arc4random_buf() - fill an arbitrary memory range with random numbers arc4random_uniform() - return a uniformly distributed random number below a specified upper bound, avoiding the bias that comes from a naive "arc4random() % upper_bound" construction. these mirror similarly-named functions in the kernel; lots of discussion deraadt@ mcbride@
* - make arc4random*() functions thread safe. Use a custom spinlock functionkurt2008-01-011-41/+56
| | | | | | | | | | | instead of the generic pthread macros since free(3) uses __arc4_getbyte() when freeing small sized allocations and the generic pthread macros call malloc(3). - eliminate passing pointers to a static variable with global scope (rs) for additional code clarity and reduction. - shlib minor bumps for libc and libpthread due to new functions. From andreas@ with some bits from me. okay tedu@ marc@ w/some spot checking from millert@
* provide an libc internal interface to get random bytes, to be used by mallocotto2007-02-121-3/+12
| | | | to get random data without calling getpid(), ok millert@ deraadt@
* Use sysctl(KERN_ARND) to get n bytes, instead of just 4 at a timeotto2005-11-301-9/+2
| | | | | | | and remove fallback code. If somebody is dumb enough to make the sysctl fail using systrace, he deserves what he gets. Saves 7 syscalls on process startup. looks good miod@ ok deraadt@ tedu@
* Change email address for author, at his request.kjell2005-06-061-2/+2
|
* Change license to standard OpenBSD boilerplate, with permissionkjell2005-06-061-6/+15
| | | | from original author (David Mazieres)
* use the new fat random sysctl to get initial state. (fallback to looping).tedu2005-06-041-12/+14
| | | | stir after eating 400000 words. ok + input deraadt
* kill spaceshshoexer2004-11-021-3/+3
| | | | ok djm@
* Discard first 256 bytes of keystream, as per recommendation indjm2003-11-261-1/+10
| | | | | "Weaknesses in the Key Scheduling Algorithm of RC4", Fluhrer, Mantin and Shamir. ok itojun@
* just use sysctl for stirring. thread safe and can't fail.tedu2003-08-161-23/+10
| | | | ok deraadt and co.
* ansification; checked by pvalderaadt2003-06-111-18/+9
|
* re-stir if pid changes; markus & mederaadt2003-02-141-3/+5
|
* License clarification from David Mazieres, ok deraadt@pvalchev2001-06-051-3/+2
|