You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by "MATHIHALLI,MADHUSUDAN (HP-Cupertino,ex1)" <ma...@hp.com> on 2002/02/20 23:48:05 UTC

[PATCH] APR_HAS_RANDOM

HPUX does not have /dev/random, hence I was trying to use the rand()
function.. I was wondering if there was any specific reason not to use it
this way.. If there's no objection, can somebody pl. commit this patch.

Thanks
-Madhu

diff -ru PA/httpd-2.0.32/srclib/apr/configure.in
TEST/httpd-2.0.32/srclib/apr/configure.in
--- PA/httpd-2.0.32/srclib/apr/configure.in     Wed Feb 20 14:23:33 2002
+++ TEST/httpd-2.0.32/srclib/apr/configure.in   Wed Feb 20 11:12:49 2002
@@ -1309,6 +1309,10 @@
             AC_MSG_RESULT([Using OS/2 builtin random])
             rand="1"
             ;;
+        *hp-hpux11*)
+            AC_MSG_RESULT([Using HP-UX builtin random])
+            rand="1"
+            ;;
         *)
             AC_ARG_WITH(egd,
               [  --with-egd=<path>       use egd-compatible socket],

--- PA/httpd-2.0.32/srclib/apr/misc/unix/rand.c Wed Feb 20 14:23:35 2002
+++ TEST/httpd-2.0.32/srclib/apr/misc/unix/rand.c       Wed Feb 20 14:43:22
2002
@@ -104,6 +104,18 @@
     for (idx=0; idx<length; idx++)
        buf[idx] = randbyte();

+#elif defined(HPUX11)
+    unsigned int idx;
+    static int was_init = 0;
+
+    if ( !was_init ) {
+       was_init = 1;
+       srand(apr_time_now());
+    }
+
+    for (idx=0; idx<length; idx++)
+       buf[idx] = rand() % sizeof(char);
+
 #elif defined(HAVE_EGD)
     /* use EGD-compatible socket daemon (such as EGD or PRNGd).
      * message format:

Re: [PATCH] APR_HAS_RANDOM

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Wed, Feb 20, 2002 at 02:48:05PM -0800, MATHIHALLI,MADHUSUDAN (HP-Cupertino,ex1) wrote:
> HPUX does not have /dev/random, hence I was trying to use the rand()
> function.. I was wondering if there was any specific reason not to use it
> this way.. If there's no objection, can somebody pl. commit this patch.

Typically, rand() doesn't provide enough entropy.  From the
looks of this, I'm doubtful that this will be random enough
(esp. considering you are seeding it with the time value).

You should try --with-egd and use either EGD or prngd.  -- justin