Commit Graph

6 Commits

Author SHA1 Message Date
Jon Beniston 7283d2513c stdlib/arc4random.c: Fix reseed count for 16-bit targets. 2018-09-06 13:26:25 +02:00
Thomas Preud'homme fa55c610fa Only define static locks in multithreaded mode
Newlib build system defines __SINGLE_THREAD__ to allow concurrency code
to be only compiled when newlib is configured for multithread. One such
example are locks which become useless in single thread mode. Although
most static locks are indeed guarded by !defined(__SINGLE_THREAD__),
some are not.

This commit adds these missing guards to __dd_hash_mutex,
__atexit_recursive_mutex, __at_quick_exit_mutex and __arc4random_mutex.
It also makes sure locking macros in lock.h are noop in single thread
mode.
2017-02-13 17:04:17 -05:00
Sebastian Huber 08537d88f6 Move arc4random Cygwin only code to Cygwin
Keep the Newlib arc4random.c identical to the OpenBSD upstream version.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>.
2016-03-21 11:12:19 +01:00
Corinna Vinschen 8e2b2adb3d Only export arc4random_stir and arc4random_addrandom on Cygwin
Export to maintain backward compatibility, but don't let
	them do anything useful.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-03-18 21:12:12 +01:00
Corinna Vinschen 5ccdcf0219 Add arc4random_stir and arc4random_addrandom for OpenBSD compatibility
* libc/stdlib/arc4random.c (arc4random_stir): New function.
        (arc4random_addrandom): Ditto.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-03-18 14:39:58 +01:00
Sebastian Huber f74cf1350e Add arc4random() etc. from OpenBSD 5.8
According to the OpenBSD man page, "A Replacement Call for Random".  It
offers high quality random numbers derived from input data obtained by
the OpenBSD specific getentropy() system call which is declared in
<unistd.h> and must be implemented for each Newlib port externally.  The
arc4random() functions are used for example in LibreSSL and OpenSSH.

Cygwin provides currently its own implementation of the arc4random
family.  Maybe it makes sense to use this getentropy() implementation:

http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libcrypto/crypto/getentropy_win.c?rev=1.4&content-type=text/x-cvsweb-markup

	* libc/include/stdlib.h (arc4random): Declare if __BSD_VISIBLE.
	(arc4random_buf): Likewise.
	(arc4random_uniform): Likewise.
	* libc/include/sys/unistd.h (getentropy): Likewise.
	* libc/include/machine/_arc4random.h: New file.
	* libc/stdlib/arc4random.c: Likewise.
	* libc/stdlib/arc4random.h: Likewise.
	* libc/stdlib/arc4random_uniform.c: Likewise.
	* libc/stdlib/chacha_private.h: Likewise.
	* libc/sys/rtems/include/machine/_arc4random.h: Likewise.
	* libc/stdlib/Makefile.am (EXTENDED_SOURCES): Add arc4random.c
	and arc4random_uniform.c.
	* libc/stdlib/Makefile.in: Regenerate.
2016-03-18 12:33:41 +01:00