From: Theodore Tso Date: Mon, 24 Oct 1994 19:29:47 +0000 (+0000) Subject: Use the srand48/lrand48 functions if available X-Git-Tag: krb5-1.0-beta5~1077 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ba2f3ef7071991efd7fd85afa8ea8e15eaacb843;p=krb5.git Use the srand48/lrand48 functions if available git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4563 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/os/ChangeLog b/src/lib/crypto/os/ChangeLog index 7a407c1d0..7a3bb2a89 100644 --- a/src/lib/crypto/os/ChangeLog +++ b/src/lib/crypto/os/ChangeLog @@ -1,3 +1,9 @@ +Mon Oct 24 14:58:14 1994 (tytso@rsx-11) + + * configure.in: + * rnd_confoun.c (krb5_random_confounder): Use the srand48/lrand48 + functions if available. + Fri Oct 14 00:21:05 1994 Theodore Y. Ts'o (tytso@dcl) * Makefile.in: Remove symlinked files on make clean. diff --git a/src/lib/crypto/os/configure.in b/src/lib/crypto/os/configure.in index eeb989d0f..dc3860edc 100644 --- a/src/lib/crypto/os/configure.in +++ b/src/lib/crypto/os/configure.in @@ -6,4 +6,5 @@ SubdirLibraryRule([${OBJS}]) KRB_INCLUDE AC_LN_S AC_REPLACE_FUNCS(memmove) +AC_HAVE_FUNCS(srand48 srand srandom getpid) AC_OUTPUT(Makefile,[EXTRA_RULES]) diff --git a/src/lib/crypto/os/rnd_confoun.c b/src/lib/crypto/os/rnd_confoun.c index a086d5400..e4557ebb5 100644 --- a/src/lib/crypto/os/rnd_confoun.c +++ b/src/lib/crypto/os/rnd_confoun.c @@ -36,6 +36,28 @@ #include #endif +#ifdef HAVE_SRAND48 +#define SRAND srand48 +#define RAND lrand48 +#define RAND_TYPE long +#endif + +#if !defined(RAND_TYPE) && defined(HAVE_SRAND) +#define SRAND srand +#define RAND rand +#define RAND_TYPE int +#endif + +#if !defined(RAND_TYPE) && defined(HAVE_SRANDOM) +#define SRAND srandom +#define RAND random +#define RAND_TYPE long +#endif + +#if !defined(RAND_TYPE) +You need a random number generator! +#endif + /* * Generate a random confounder */ @@ -45,37 +67,25 @@ int size; krb5_pointer fillin; { static int seeded = 0; - register krb5_octet *real_fill; + register krb5_octet *real_fill; + RAND_TYPE rval; -#ifdef __STDC__ - /* Use the srand/rand calls, see X3.159-1989, section 4.10.2 */ if (!seeded) { /* time() defined in 4.12.2.4, but returns a time_t, which is an "arithmetic type" (4.12.1) */ - srand((unsigned int) time(0)); - seeded = 1; - } -#else - /* assume Berkeley srandom...after all, this is libos! */ - if (!seeded) { - srandom(time(0)); + rval = time(0); + SRAND(rval); +#ifdef HAVE_GETPID + rval = RAND(); + rval ^= getpid(); + SRAND(rval); +#endif seeded = 1; } -#endif + real_fill = (krb5_octet *)fillin; while (size > 0) { - -#ifdef __STDC__ - int rval; - rval = rand(); - /* RAND_MAX is at least 32767, so we assume we can use the lower 16 bits - of the value of rand(). */ -#else - long rval; - rval = random(); - /* BSD random number generator generates "in the range from - 0 to (2**31)-1" (random(3)). So we can use the bottom 16 bits. */ -#endif + rval = RAND(); *real_fill = rval & 0xff; real_fill++; size--;