]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
libntp/random.c now always provides ntp_[s]random(). Use them instead of RANDOM...
authorHarlan Stenn <stenn@ntp.org>
Wed, 3 Aug 2005 00:19:27 +0000 (20:19 -0400)
committerHarlan Stenn <stenn@ntp.org>
Wed, 3 Aug 2005 00:19:27 +0000 (20:19 -0400)
bk: 42f00d8fmVWhZW34W-3DASbeRxo5EA

17 files changed:
configure.ac
include/l_stdlib.h
include/ntp.h
include/ntp_machine.h
include/ntpd.h
libntp/Makefile.am
libntp/random.c
libntp/ranny.c [deleted file]
ntpd/ntp_config.c
ntpd/ntp_crypto.c
ntpd/ntp_monitor.c
ntpd/ntp_peer.c
ntpd/ntp_proto.c
ntpd/ntpd.c
ntpd/ntpsim.c
util/Makefile.am
util/ntp-keygen.c

index 31a460a76300e6dd517e6aa95b9feec576a58ba4..251f7069b3126bac0ca921e005db40c52e1c2428 100644 (file)
@@ -984,7 +984,7 @@ case "$host" in
  *) AC_CHECK_FUNCS(mlockall)
     ;;
 esac
-AC_CHECK_FUNCS(mrand48 srand48 nice nlist)
+AC_CHECK_FUNCS(nice nlist)
 case "$host" in
  *-*-solaris2.6)
     # Broken...
@@ -993,10 +993,6 @@ case "$host" in
     ;;
 esac
 AC_CHECK_FUNCS(plock pututline pututxline readlink recvmsg rtprio)
-case "$ac_cv_func_mrand48" in
- yes) ;;
- *) AC_REPLACE_FUNCS(random) ;;
-esac
 case "$host" in
  *-*-aix[[45]]*)
     # Just a stub in AIX 4.  Idiots.
@@ -1186,10 +1182,8 @@ case "$host" in
     AC_DEFINE(DECL_ADJTIME_0, 1, [Declaration style])
     AC_DEFINE(DECL_INET_NTOA_0, 1, [Declaration style])
     AC_DEFINE(DECL_MKTEMP_0, 1, [Declaration style])
-    AC_DEFINE(DECL_MRAND48_0, 1, [Declaration style])
     AC_DEFINE(DECL_SELECT_0, 1, [Declaration style])
     AC_DEFINE(DECL_SETITIMER_0, 1, [Declaration style])
-    AC_DEFINE(DECL_SRAND48_0, 1, [Declaration style])
     AC_DEFINE(DECL_SYSLOG_0, 1, [Declaration style])
     AC_DEFINE(DECL_TIMEOFDAY_0, 1, [Declaration style])
     ;;
@@ -1236,13 +1230,11 @@ case "$host" in
     AC_DEFINE(DECL_MEMMOVE_0, 1, [Declaration style])
     AC_DEFINE(DECL_MKTEMP_0, 1, [Declaration style])
     AC_DEFINE(DECL_MKSTEMP_0, 1, [Declaration style])
-    AC_DEFINE(DECL_MRAND48_0, 1, [Declaration style])
     AC_DEFINE(DECL_RENAME_0, 1, [Declaration style])
     AC_DEFINE(DECL_SELECT_0, 1, [Declaration style])
     AC_DEFINE(DECL_SETITIMER_0, 1, [Declaration style])
     AC_DEFINE(DECL_SETPRIORITY_0, 1, [Declaration style])
     AC_DEFINE(DECL_SIGVEC_0, 1, [Declaration style])
-    AC_DEFINE(DECL_SRAND48_0, 1, [Declaration style])
     case "`basename $ac_cv_prog_CC`" in
      acc*) ;;
      *) AC_DEFINE(DECL_STDIO_0, 1, [Declaration style])
@@ -1263,13 +1255,11 @@ case "$host" in
     AC_DEFINE(DECL_IOCTL_0, 1, [Declaration style])
     AC_DEFINE(DECL_IPC_0, 1, [Declaration style])
     AC_DEFINE(DECL_MKTEMP_0, 1, [Declaration style])
-    AC_DEFINE(DECL_MRAND48_0, 1, [Declaration style])
     AC_DEFINE(DECL_NLIST_0, 1, [Declaration style])
     AC_DEFINE(DECL_PLOCK_0, 1, [Declaration style])
     AC_DEFINE(DECL_SELECT_0, 1, [Declaration style])
     AC_DEFINE(DECL_SETITIMER_0, 1, [Declaration style])
     AC_DEFINE(DECL_SETPRIORITY_0, 1, [Declaration style])
-    AC_DEFINE(DECL_SRAND48_0, 1, [Declaration style])
     AC_DEFINE(DECL_STIME_0, 1, [Declaration style])
     AC_DEFINE(DECL_SYSLOG_0, 1, [Declaration style])
     AC_DEFINE(DECL_TIMEOFDAY_0, 1, [Declaration style])
index 3f242b7994a0681cca4d87a486eaabf65669bab4..58bbeedc212380acfc413f2900ae9dbabdad81c4 100644 (file)
@@ -104,10 +104,6 @@ extern     int     mkstemp         P((char *));
 extern char   *mktemp          P((char *));    
 #endif
 
-#ifdef DECL_MRAND48_0
-extern long    mrand48         P((void));
-#endif
-
 #ifdef DECL_NLIST_0
 struct nlist;
 extern int     nlist           P((const char *, struct nlist *));
@@ -156,10 +152,6 @@ extern     int     snprintf        P((char *, size_t, const char *, ...));
 extern int     vsnprintf       P((char *, size_t, const char *, va_list));
 #endif
 
-#ifdef DECL_SRAND48_0
-extern void    srand48         P((long));
-#endif
-
 #ifdef DECL_STDIO_0
 #if defined(FILE) || defined(BUFSIZ)
 extern int     _flsbuf         P((int, FILE *));
@@ -276,10 +268,7 @@ extern     int     fork            P((void));
 extern int     getdtablesize   P((void));
 extern int     qsort           (void *, int , int,
                                   int P((*compar)(void *, void *)));
-extern long    random          P((void));
-extern long    mrand48         P((void));
 extern int     setpgrp         P((int, int));
-extern void    srandom         P((unsigned int));
 extern void    bcopy           P((const char *, char *, int));
 #endif
 
@@ -481,8 +470,6 @@ extern      int     execve          P((char *, char **,char **));
 extern int     fork            P((void));
 extern int     getdtablesize   P((void));
 extern int     ran             P((void));
-extern int     rand            P((void));
-extern void    srand           P((unsigned int));
 #ifdef _TIME_H_
 extern int     gettimeofday    P((struct timeval *, struct timezone *));
 extern int     settimeofday    P((struct timeval *, struct timezone *));
index 136742bfa42fa41ce618f36365ddf1b3f70bf5cf..528726f5df6072108e88d41737b1a6fae67ef99f 100644 (file)
@@ -697,15 +697,7 @@ struct pkt {
  * How we randomize polls.  The poll interval is a power of two. We chose
  * a random interval which is this value plus-minus one second.
  */
-#if defined(HAVE_MRAND48)
-# define RANDOM                (mrand48())
-# define SRANDOM(x)    (srand48(x))
-#else
-# define RANDOM                (random())
-# define SRANDOM(x)    (srandom(x))
-#endif
-
-#define RANDPOLL(x)    ((1 << (x)) - 1 + (RANDOM & 0x3))
+#define RANDPOLL(x)    ((1 << (x)) - 1 + (ntp_random() & 0x3))
 
 /*
  * min, min3 and max.  Makes it easier to transliterate the spec without
index 850606cb243b0a61c41b573fb1e0089e65c8e598..0883230621bd649f75e32680fb02813c0f23848f 100644 (file)
@@ -353,8 +353,6 @@ extern void alarm P((int seconds));
 #define getclock       clock_gettime
 #define fcntl          ioctl
 #define _getch         getchar
-#define random                 rand
-#define srandom                srand
 
 /* define this away for vxWorks */
 #define openlog(x,y)
index 995f8a57d7da6849859079aec982eb43eb21d170..af29f62a6f1d156fddd0fce9ca6f4d1f9942e1bc 100644 (file)
@@ -20,6 +20,9 @@ void  worker_thread   (void *);
 #define sleep(x) Sleep((DWORD) x * 1000 /* milliseconds */ );
 #endif /* SYS_WINNT */
 
+extern void    ntp_srandom     P((unsigned long));
+extern int     ntp_random      P((void));
+
 /* ntp_config.c */
 extern void    getconfig       P((int, char **));
 
index 544dca4e2cb6a8bf5ff664bdace9973f2c3dab87..e2ddb76071e0949e569de6d42d0b9cda4a028e33 100644 (file)
@@ -11,7 +11,7 @@ libntp_a_SRCS = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
        lib_strbuf.c machines.c md5c.c memmove.c mfptoa.c \
        mfptoms.c mktime.c modetoa.c mstolfp.c msutotsf.c msyslog.c netof.c \
        ntp_rfc2553.c numtoa.c numtohost.c octtoint.c prettydate.c \
-       recvbuff.c refnumtoa.c snprintf.c socktoa.c socktohost.c \
+       random.c recvbuff.c refnumtoa.c snprintf.c socktoa.c socktohost.c \
        statestr.c strdup.c strerror.c strstr.c \
        syssignal.c tsftomsu.c tstotv.c tvtoa.c tvtots.c \
        uglydate.c uinttoa.c utvtoa.c ymd2yd.c \
@@ -25,7 +25,7 @@ libntp_a_SRCS = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
        $(srcdir)/../libisc/netscope.c
 libntp_a_SOURCES = systime.c $(libntp_a_SRCS)
 libntpsim_a_SOURCES = systime_s.c $(libntp_a_SRCS)
-EXTRA_libntp_a_SOURCES = adjtimex.c random.c
+EXTRA_libntp_a_SOURCES = adjtimex.c
 INCLUDES = -I$(top_srcdir)/include -I../include
 ETAGS_ARGS = Makefile.am
 
index c8d7b702043f1bc095198743b160bffcf2c831ac..e59fc854ab136f3f98addbad0856fd4d0fd0e314 100644 (file)
@@ -218,7 +218,7 @@ static long rand_sep = SEP_3;
 static long *end_ptr = &randtbl[DEG_3 + 1];
 
 static inline long good_rand P((long));
-long random P((void));
+long ntp_random P((void));
 
 static inline long
 good_rand (
@@ -265,7 +265,7 @@ good_rand (
  * for default usage relies on values produced by this routine.
  */
 void
-srandom(
+ntp_srandom(
        unsigned long x
        )
 {
@@ -280,7 +280,7 @@ srandom(
                fptr = &state[rand_sep];
                rptr = &state[0];
                for (i = 0; i < 10 * rand_deg; i++)
-                       (void)random();
+                       (void)ntp_random();
        }
 }
 
@@ -296,13 +296,13 @@ srandom(
  * a fixed seed.
  */
 void
-srandomdev( void )
+ntp_srandomdev( void )
 {
        struct timeval tv;
        unsigned long junk;     /* Purposely used uninitialized */
 
        gettimeofday(&tv, NULL);
-       srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk);
+       ntp_srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk);
        return;
 }
 
@@ -330,7 +330,7 @@ srandomdev( void )
  * complain about mis-alignment, but you should disregard these messages.
  */
 char *
-initstate(
+ntp_initstate(
        unsigned long seed,             /* seed for R.N.G. */
        char *arg_state,                /* pointer to state array */
        long n                          /* # bytes of state info */
@@ -371,7 +371,7 @@ initstate(
        }
        state = (long *) (long_arg_state + 1); /* first location */
        end_ptr = &state[rand_deg];     /* must set end_ptr before srandom */
-       srandom(seed);
+       ntp_srandom(seed);
        if (rand_type == TYPE_0)
                long_arg_state[0] = rand_type;
        else
@@ -399,7 +399,7 @@ initstate(
  * complain about mis-alignment, but you should disregard these messages.
  */
 char *
-setstate(
+ntp_setstate(
        char *arg_state                 /* pointer to state array */
        )
 {
@@ -453,7 +453,7 @@ setstate(
  * Returns a 31-bit random number.
  */
 long
-random( void )
+ntp_random( void )
 {
        register long i;
        register long *f, *r;
diff --git a/libntp/ranny.c b/libntp/ranny.c
deleted file mode 100644 (file)
index d6c4cc9..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Random number generator is:
- *
- *     Copyright 1988 by Rayan S. Zachariassen, all rights reserved.
- *     This will be free software, but only when it is finished.
- *
- * Used in ntp by permission of the author.  If copyright is
- * annoying to you, read no further.  Instead, look up the reference,
- * write me an equivalent to this and send it back to me.
- */
-
-/*
- * Random number generator; see Knuth Vol 2. 2nd ed. p.27 (section 3.2.2)
- */
-#include "ntp_stdlib.h"
-
-/*
- * 55 random numbers, not all even.  Note we don't initialize ran_y
- * directly since I have had thoughts of putting this in an EPROM
- */
-static time_t ran_y[55];
-
-static time_t init_ran_y[55] = {
-       1860909544, 231033423, 437666411, 1349655137, 2014584962,
-       504613712, 656256107, 1246027206, 573713775, 643466871,
-       540235388, 1630565153, 443649364, 729302839, 1933991552,
-       944681982, 949111118, 406212522, 1065063137, 1712954727,
-       73280612, 787623973, 1874130997, 801658492, 73395958,
-       739165367, 596047144, 490055249, 1131094323, 662727104,
-       483614097, 844520219, 893760527, 921280508, 46691708,
-       760861842, 1425894220, 702947816, 2006889048, 1999607995,
-       1346414687, 399640789, 1482689501, 1790064052, 1128943628,
-       1269197405, 587262386, 2078054746, 1675409928, 1652325524,
-       1643525825, 1748690540, 292465849, 1370173174, 402865384
-};
-
-static int ran_j;
-static int ran_k;
-
-
-/*
- * ranp2 - return a random integer in the range 0 .. (1 << m) - 1
- */
-u_long
-ranp2(
-       int m
-       )
-{
-       time_t r;
-
-       ran_y[ran_k] += ran_y[ran_j];   /* overflow does a mod */
-       r = ran_y[ran_k];
-       if (ran_k-- == 0)
-           ran_k = 54;
-       if (ran_j-- == 0)
-           ran_j = 54;
-       return (u_long)(r & ((1 << m ) - 1));
-}
-
-/*
- * init_random - do initialization of random number routine
- */
-void
-init_random(void)
-{
-       register int i;
-       register time_t now;
-
-       ran_j = 23;
-       ran_k = 54;
-
-       /*
-        * Randomize the seed array some more.  The time of day
-        * should be initialized by now.
-        */
-       now = time((time_t *)0) | 01;
-
-       for (i = 0; i < 55; ++i)
-           ran_y[i] = now * init_ran_y[i];     /* overflow does a mod */
-}
index c69adf6e375b8796ff4598c0a97605d347d7b11f..3d8227ee539c5ed35d23fb40b0b5614c34a05209 100644 (file)
@@ -1819,7 +1819,7 @@ getconfig(
 
                for (i = 0; i < 8; i++)
                        for (j = 1; j < 100; ++j) {
-                               rankey[i] = (char) (RANDOM & 0xff);
+                               rankey[i] = (char) (ntp_random() & 0xff);
                                if (rankey[i] != 0) break;
                        }
                rankey[8] = 0;
index b26def27ba89807bc3981826248971425a8e8307..124887f6f7d96e831a7513853aaaa36dd635971e 100644 (file)
@@ -274,7 +274,7 @@ make_keylist(
         * NTP_MAXKEY.
         */
        while (1) {
-               keyid = (u_long)RANDOM & 0xffffffff;
+               keyid = (u_long)ntp_random();   /* 31 bits from ntp_random() */
                if (keyid <= NTP_MAXKEY)
                        continue;
 
index b033dcd0054e42319021c340513ff566eb8a67be..f998dcaba310245e1e91d752360dff4547287445 100644 (file)
@@ -239,7 +239,8 @@ ntp_monitor(
                 * Preempt from the MRU list if old enough.
                 */
                md = mon_mru_list.mru_prev;
-               if (((u_long)RANDOM & 0xffffffff) / FRAC >
+               /* We get 31 bits from ntp_random() */
+               if (((u_long)ntp_random()) / FRAC >
                    (double)(current_time - md->lasttime) / mon_age)
                        return;
 
index a35b9b5665aa4eeb9d0a790097b8ac29b51bea1e..d6fd55d28226e96ce1a1d098749829dcd3449809 100644 (file)
@@ -144,7 +144,7 @@ init_peer(void)
        /*
         * Initialize our first association ID
         */
-       while ((current_association_ID = RANDOM & 0xffff) == 0);
+       while ((current_association_ID = ntp_random() & 0xffff) == 0);
 }
 
 
index 9899941490454b36176c547b6b1394baa94b71fd..39c721b9d9df85854d700613f1655a8ace3d4496 100644 (file)
@@ -1524,7 +1524,7 @@ peer_clear(
        if (initializing)
                peer->nextdate = current_time + peer_associations;
        else
-               peer->nextdate = current_time + (RANDOM & ((1 <<
+               peer->nextdate = current_time + (ntp_random() & ((1 <<
                    NTP_MINPOLL) - 1));
 #ifdef DEBUG
        if (debug)
index 8d782dcebfc880b4cf40708194e00d24a15b1167..ac92df92b2a46b737cf77ea887a395550d270838 100644 (file)
@@ -464,7 +464,7 @@ ntpdmain(
         * Initialize random generator and public key pair
         */
        get_systime(&now);
-       SRANDOM((int)(now.l_i * now.l_uf));
+       ntp_srandom((int)(now.l_i * now.l_uf));
 
 #ifdef HAVE_DNSREGISTRATION
        msyslog(LOG_INFO, "Attemping to register mDNS\n");
index b92084fdf0bb1b8f5c469b4ed046b1b381399402..73bdb6739b56d568b10ca3f63fd7bc95416adb31 100644 (file)
@@ -80,7 +80,7 @@ ntpsim(
         * Watch out here, we want the real time, not the silly stuff.
         */
        gettimeofday(&seed, NULL);
-       srand48(seed.tv_usec);
+       ntp_srandom(seed.tv_usec);
 
        /*
         * Push a beep and timer interrupt on the queue
index 364d7cf86c5f812e5acecb17f460b4aef42e3195..ae4202f8d49593678ff96ac8a5fa6b61bd20528e 100644 (file)
@@ -9,7 +9,7 @@ EXTRA_PROGRAMS= audio-pcm byteorder hist jitter kern longsize \
 INCLUDES=      -I$(top_srcdir)/include
 # LDADD might need RESLIB and ADJLIB
 LDADD=         ../libntp/libntp.a
-ntp_keygen_LDADD=      @LCRYPTO@
+ntp_keygen_LDADD=      @LCRYPTO@ ../libntp/libntp.a
 #EXTRA_DIST=   README TAGS
 EXTRA_DIST=
 ETAGS_ARGS=    Makefile.am
index 2cd763ec030467edcb30b68e57d5d97cbd8bcc1e..b76de1d3de6bf8b84027b4c342430d0244242ab9 100644 (file)
@@ -794,11 +794,11 @@ gen_md5(
 
        fprintf(stderr, "Generating MD5 keys...\n");
        str = fheader("MD5key", hostname);
-       srandom(epoch);
+       ntp_srandom(epoch);
        for (i = 1; i <= MD5KEYS; i++) {
                for (j = 0; j < 16; j++) {
                        while (1) {
-                               temp = random() & 0xff;
+                               temp = ntp_random() & 0xff;
                                if (temp == '#')
                                        continue;
                                if (temp > 0x20 && temp < 0x7f)