summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@uclibc-ng.org>2018-01-30 04:01:56 +0000
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2018-01-31 18:44:51 +0000
commitf20179d6931df17c9310fd911dd4a348141ba72c (patch)
treef360310ea410b6466e2303a5efaad8fb7d0d2cb9
parent25ae0a3f30c9651dd22507a66f7ddea009973154 (diff)
remove arc4random (rc4 based)
OpenBSD arc4random is using chacha20 cipher algorithm for a long time. This copy is still based on deprecated rc4 cipher algorithm. We could either update the arc4random.c or drop it. Drop it. Users should better use libbsd when using arc4random interface. Musl/glibc does not have arc4random either.
-rw-r--r--extra/Configs/Config.in22
-rw-r--r--include/stdlib.h7
-rw-r--r--libc/stdlib/Makefile.in1
-rw-r--r--libc/stdlib/arc4random.c216
4 files changed, 0 insertions, 246 deletions
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index bf2defbae..deb165a8e 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -2012,28 +2012,6 @@ config UCLIBC_BUILD_PIE
assembler functions must be written as position independent
code (PIC).
-config UCLIBC_HAS_ARC4RANDOM
- bool "Include the arc4random() function"
- help
- Answer Y to support the OpenBSD-like arc4random() function. This
- function picks a random number between 0 and N, and will always return
- something even if the random driver is dead. If urandom fails then
- gettimeofday(2) will be used as the random seed. This function is
- designed to be more dependable than invoking /dev/urandom directly.
- OpenSSL and OpenNTPD currently support this function.
-
- Most people will answer N.
-
-config ARC4RANDOM_USES_NODEV
- bool "Do not use /dev/urandom with arc4random()"
- depends on UCLIBC_HAS_ARC4RANDOM
- help
- Answer Y to use gettimeofday(2) and getpid(2) exclusively for
- arc4random(). This is not a bad idea for a diskless system, but
- it uses a lot of syscalls to stir each array element.
-
- Most people will answer N.
-
config HAVE_NO_SSP
bool
diff --git a/include/stdlib.h b/include/stdlib.h
index 89477967e..6a253cc3f 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -987,13 +987,6 @@ extern int getloadavg (double __loadavg[], int __nelem)
__THROW __nonnull ((1));
#endif
-#ifdef __UCLIBC_HAS_ARC4RANDOM__
-# include <sys/types.h>
-extern u_int32_t arc4random(void);
-extern void arc4random_stir(void);
-extern void arc4random_addrandom(unsigned char *, int);
-#endif
-
#ifdef _LIBC
extern int __drand48_iterate (unsigned short int xsubi[3], struct drand48_data *buffer) attribute_hidden;
diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in
index 7b6eda34e..386890ce7 100644
--- a/libc/stdlib/Makefile.in
+++ b/libc/stdlib/Makefile.in
@@ -21,7 +21,6 @@ CSRC-y := \
CSRC-$(UCLIBC_SUSV2_LEGACY) += valloc.c
CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_memalign.c
CSRC-$(UCLIBC_HAS_PTY) += grantpt.c unlockpt.c ptsname.c
-CSRC-$(UCLIBC_HAS_ARC4RANDOM) += arc4random.c
CSRC-y += mkstemp64.c mkostemp64.c mkstemps64.c mkostemps64.c
CSRC-$(UCLIBC_HAS_FLOATS) += drand48.c drand48_r.c erand48.c erand48_r.c
CSRC-$(if $(findstring yy,$(UCLIBC_HAS_FLOATS)$(UCLIBC_SUSV3_LEGACY)),y) += \
diff --git a/libc/stdlib/arc4random.c b/libc/stdlib/arc4random.c
deleted file mode 100644
index 03b2234ae..000000000
--- a/libc/stdlib/arc4random.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (c) 1996, David Mazieres <dm@uun.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-/*
- * Arc4 random number generator for OpenBSD.
- *
- * This code is derived from section 17.1 of Applied Cryptography,
- * second edition, which describes a stream cipher allegedly
- * compatible with RSA Labs "RC4" cipher (the actual description of
- * which is a trade secret). The same algorithm is used as a stream
- * cipher called "arcfour" in Tatu Ylonen's ssh package.
- *
- * Here the stream cipher has been modified always to include entropy
- * when initializing the state. That makes it impossible to
- * regenerate the same random sequence twice, so this can't be used
- * for encryption, but will generate good random numbers.
- *
- * RC4 is a registered trademark of RSA Laboratories.
- */
-
-/* $OpenBSD: arc4random.c,v 1.16 2007/02/12 19:58:47 otto Exp $ */
-
-#include <features.h>
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/time.h>
-
-struct arc4_stream {
- u_int8_t i;
- u_int8_t j;
- u_int8_t s[256];
-};
-
-static smallint rs_initialized;
-static struct arc4_stream rs;
-static pid_t arc4_stir_pid;
-static int arc4_count;
-
-static __inline__ void
-arc4_init(struct arc4_stream *as)
-{
- int n;
-
- for (n = 0; n < 256; n++)
- as->s[n] = n;
- as->i = 0;
- as->j = 0;
-}
-
-static __inline__ u_int8_t
-arc4_getbyte(struct arc4_stream *as)
-{
- u_int8_t si, sj;
-
- as->i = (as->i + 1);
- si = as->s[as->i];
- as->j = (as->j + si);
- sj = as->s[as->j];
- as->s[as->i] = sj;
- as->s[as->j] = si;
- return (as->s[(si + sj) & 0xff]);
-}
-
-static __inline__ void
-arc4_addrandom(struct arc4_stream *as, u_char *dat, int datlen)
-{
- int n;
- u_int8_t si;
-
- as->i--;
- for (n = 0; n < 256; n++) {
- as->i = (as->i + 1);
- si = as->s[as->i];
- as->j = (as->j + si + dat[n % datlen]);
- as->s[as->i] = as->s[as->j];
- as->s[as->j] = si;
- }
- as->j = as->i;
-}
-
-static void
-arc4_stir(struct arc4_stream *as)
-{
- int n;
- u_char rnd[128];
- struct timeval tv;
-
-#ifndef __ARC4RANDOM_USES_NODEV__
- int fd;
-
- fd = open("/dev/urandom", O_RDONLY);
- if (fd != -1) {
- read(fd, rnd, sizeof(rnd));
- close(fd);
- }
- /* Did the pseudo-random device fail? Use gettimeofday(). */
- else
-#endif
- if (gettimeofday(&tv, NULL) != (-1)) {
-
- /* Initialize the first element so it's hopefully not '0',
- * to help out the next loop. Tossing in some prime numbers
- * probably can't hurt. */
- rnd[0] = (tv.tv_sec % 10000) * 3 + tv.tv_usec * 7 + \
- (getpid() % 1000) * 13;
-
- for (n = 1; n < 127 ; n++) {
-
- /* Take advantage of the stack space. Only initialize
- * elements equal to '0'. This will make the rnd[]
- * array much less vulnerable to timing attacks. Here
- * we'll stir getpid() into the value of the previous
- * element. Approximately 1 in 128 elements will still
- * become '0'. */
-
- if (rnd[n] == 0) {
- rnd[n] = ((rnd[n - 1] + n) ^ \
- ((getpid() % 1000) * 17));
- }
- }
- }
- else {
- /* gettimeofday() failed? Do the same thing as above, but only
- * with getpid(). */
-
- rnd[0] = (getpid() % 1000) * 19;
- for (n = 1; n < 127 ; n++) {
- if (rnd[n] == 0) {
- rnd[n] = ((rnd[n - 1] + n) ^ \
- ((getpid() % 1000) * 23));
- }
- }
- }
-
- arc4_stir_pid = getpid();
- arc4_addrandom(as, rnd, sizeof(rnd));
-
- /*
- * Discard early keystream, as per recommendations.
- * Network Operations Division Cryptographic requirements
- * published on wikileaks on march 2017
- */
- for (n = 0; n < 3072; n++)
- (void)arc4_getbyte(as);
- arc4_count = 1600000;
-}
-
-#if 0
-static void __arc4random_stir(void);
-/*
- * __arc4_getbyte() is a libc private function intended for use
- * with malloc.
- */
-u_int8_t
-__arc4_getbyte(void)
-{
- if (--arc4_count == 0 || !rs_initialized)
- __arc4random_stir();
- return arc4_getbyte(&rs);
-}
-#endif
-
-static __inline__ u_int32_t
-arc4_getword(struct arc4_stream *as)
-{
- u_int32_t val;
- val = arc4_getbyte(as) << 24;
- val |= arc4_getbyte(as) << 16;
- val |= arc4_getbyte(as) << 8;
- val |= arc4_getbyte(as);
- return val;
-}
-
-static void
-__arc4random_stir(void)
-{
- if (!rs_initialized) {
- arc4_init(&rs);
- rs_initialized = 1;
- }
- arc4_stir(&rs);
-}
-strong_alias(__arc4random_stir,arc4random_stir)
-
-void
-arc4random_addrandom(u_char *dat, int datlen)
-{
- if (!rs_initialized)
- __arc4random_stir();
- arc4_addrandom(&rs, dat, datlen);
-}
-
-u_int32_t
-arc4random(void)
-{
- arc4_count -= 4;
- if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != getpid())
- __arc4random_stir();
- return arc4_getword(&rs);
-}