From aeea6a838e995040a6978fcdcee85c8f740cdd17 Mon Sep 17 00:00:00 2001 From: Barry Jaspan Date: Mon, 5 May 1997 21:12:33 +0000 Subject: [PATCH] * setkey-test.c, configure.in: add rules to test for correct random()-equivlant function git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10085 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kadm5/unit-test/ChangeLog | 5 +++++ src/lib/kadm5/unit-test/configure.in | 1 + src/lib/kadm5/unit-test/setkey-test.c | 20 ++++++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib/kadm5/unit-test/ChangeLog b/src/lib/kadm5/unit-test/ChangeLog index 4401065c9..23c750015 100644 --- a/src/lib/kadm5/unit-test/ChangeLog +++ b/src/lib/kadm5/unit-test/ChangeLog @@ -1,3 +1,8 @@ +Mon May 5 17:11:44 1997 Barry Jaspan + + * setkey-test.c, configure.in: add rules to test for correct + random()-equivlant function + Mon Mar 31 17:39:52 1997 Barry Jaspan * Makefile.in, setkey-test.c: add support for setkey diff --git a/src/lib/kadm5/unit-test/configure.in b/src/lib/kadm5/unit-test/configure.in index fb32f917e..d49a2bba7 100644 --- a/src/lib/kadm5/unit-test/configure.in +++ b/src/lib/kadm5/unit-test/configure.in @@ -4,6 +4,7 @@ AC_CANONICAL_HOST dnl The following are tests for the presence of programs required for testing AC_CHECK_PROG(RUNTEST,runtest,runtest) AC_CHECK_PROG(PERL,perl,perl) +AC_CHECK_FUNCS(srand48 srand srandom) AC_KRB5_TCL if test "$PERL" = perl -a "$RUNTEST" = runtest -a "$TCL_LIBS" != ""; then DO_TEST=ok diff --git a/src/lib/kadm5/unit-test/setkey-test.c b/src/lib/kadm5/unit-test/setkey-test.c index e329fce25..fed4e0e74 100644 --- a/src/lib/kadm5/unit-test/setkey-test.c +++ b/src/lib/kadm5/unit-test/setkey-test.c @@ -2,6 +2,22 @@ #include #include +#if HAVE_SRAND48 +#define RAND() lrand48() +#define SRAND(a) srand48(a) +#define RAND_TYPE long +#elif HAVE_SRAND +#define RAND() rand() +#define SRAND(a) srand(a) +#define RAND_TYPE int +#elif HAVE_SRANDOM +#define RAND() random() +#define SRAND(a) srandom(a) +#define RAND_TYPE long +#else /* no random */ +need a random number generator +#endif /* no random */ + krb5_keyblock test1[] = { 0, ENCTYPE_DES_CBC_CRC, 0, 0, -1, @@ -107,7 +123,7 @@ main(int argc, char **argv) } /* these pw's don't need to be secure, just different every time */ - srandom(getpid() ^ time(0)); + SRAND((RAND_TYPE)time((void *) NULL)); pwdata.data = pw; pwdata.length = sizeof(pw); @@ -127,7 +143,7 @@ main(int argc, char **argv) for (encnum = 0; testp[encnum].magic != -1; encnum++) { for (i = 0; i < sizeof(pw); i++) - pw[i] = (random() % 26) + '0'; /* XXX */ + pw[i] = (RAND() % 26) + '0'; /* XXX */ krb5_use_enctype(context, &eblock, testp[encnum].enctype); if (ret = krb5_string_to_key(context, &eblock, &testp[encnum], -- 2.26.2