[Git][NTPsec/ntpsec][master] Nuke libisc/random

Hal Murray gitlab at mg.gitlab.com
Sat Dec 19 01:40:57 UTC 2015


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
feca8fab by Hal Murray at 2015-12-18T17:40:13Z
Nuke libisc/random

- - - - -


3 changed files:

- − libisc/include/isc/random.h
- − libisc/random.c
- libisc/wscript


Changes:

=====================================
libisc/include/isc/random.h deleted
=====================================
--- a/libisc/include/isc/random.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2004-2007, 2009  Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2001  Internet Software Consortium.
- * Copyright 2015 by the NTPsec project contributors
- * SPDX-License-Identifier: ISC
- */
-
-#ifndef GUARD_ISC_RANDOM_H
-#define GUARD_ISC_RANDOM_H 1
-
-#include <isc/lang.h>
-#include <isc/types.h>
-
-/*! \file isc/random.h
- * \brief Implements a random state pool which will let the caller return a
- * series of possibly non-reproducible random values.
- *
- * Note that the
- * strength of these numbers is not all that high, and should not be
- * used in cryptography functions.  It is useful for jittering values
- * a bit here and there, such as timeouts, etc.
- */
-
-ISC_LANG_BEGINDECLS
-
-void
-isc_random_seed(uint32_t seed);
-/*%<
- * Set the initial seed of the random state.
- */
-
-void
-isc_random_get(uint32_t *val);
-/*%<
- * Get a random value.
- *
- * Requires:
- *	val != NULL.
- */
-
-uint32_t
-isc_random_jitter(uint32_t max, uint32_t jitter);
-/*%<
- * Get a random value between (max - jitter) and (max).
- * This is useful for jittering timer values.
- */
-
-ISC_LANG_ENDDECLS
-
-#endif /* GUARD_ISC_RANDOM_H */


=====================================
libisc/random.c deleted
=====================================
--- a/libisc/random.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2003  Internet Software Consortium.
- * Copyright 2015 by the NTPsec project contributors
- * SPDX-License-Identifier: ISC
- */
-
-/*! \file */
-
-#include <config.h>
-
-#include <stdlib.h>
-#include <time.h>		/* Required for time(). */
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <isc/once.h>
-#include <isc/random.h>
-#include <isc/util.h>
-
-static isc_once_t once = ISC_ONCE_INIT;
-
-static void
-initialize_rand(void)
-{
-#ifndef HAVE_ARC4RANDOM
-	unsigned int pid = getpid();
-
-	/*
-	 * The low bits of pid generally change faster.
-	 * Xor them with the high bits of time which change slowly.
-	 */
-	pid = ((pid << 16) & 0xffff0000) | ((pid >> 16) & 0xffff);
-
-	srand(time(NULL) ^ pid);
-#endif
-}
-
-static void
-initialize(void)
-{
-	RUNTIME_CHECK(isc_once_do(&once, initialize_rand) == ISC_R_SUCCESS);
-}
-
-void
-isc_random_seed(uint32_t seed)
-{
-	initialize();
-
-#ifndef HAVE_ARC4RANDOM
-	srand(seed);
-#else
-	arc4random_addrandom((u_char *) &seed, sizeof(uint32_t));
-#endif
-}
-
-void
-isc_random_get(uint32_t *val)
-{
-	REQUIRE(val != NULL);
-
-	initialize();
-
-#ifndef HAVE_ARC4RANDOM
-	/*
-	 * rand()'s lower bits are not random.
-	 * rand()'s upper bit is zero.
-	 */
-#if RAND_MAX >= 0xfffff
-	/* We have at least 20 bits.  Use lower 16 excluding lower most 4 */
-	*val = ((rand() >> 4) & 0xffff) | ((rand() << 12) & 0xffff0000);
-#elif RAND_MAX >= 0x7fff
-	/* We have at least 15 bits.  Use lower 10/11 excluding lower most 4 */
-	*val = ((rand() >> 4) & 0x000007ff) | ((rand() << 7) & 0x003ff800) |
-		((rand() << 18) & 0xffc00000);
-#else
-#error RAND_MAX is too small
-#endif
-#else
-	*val = arc4random();
-#endif
-}
-
-uint32_t
-isc_random_jitter(uint32_t max, uint32_t jitter) {
-	uint32_t rnd;
-
-	REQUIRE(jitter < max || (jitter == 0 && max == 0));
-
-	if (jitter == 0)
-		return (max);
-
-	isc_random_get(&rnd);
-	return (max - rnd % jitter);
-}


=====================================
libisc/wscript
=====================================
--- a/libisc/wscript
+++ b/libisc/wscript
@@ -9,7 +9,6 @@ def build(ctx):
 		"log.c",
 		"md5.c",
 		"netaddr.c",
-		"random.c",
 		"result.c",
 		"sha1.c",
 		"unix/errno2result.c",



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/feca8fab203c5a5a291839f07625ae0de885b49a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151219/2d76a417/attachment.html>


More information about the vc mailing list