From 0903359bc1a221e3d6d1b6832509e098ad7a3525 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Tue, 23 Oct 1990 14:39:30 +0000 Subject: [PATCH] change to a lengt/contents fill-in rather than a return value git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1311 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/crypto/os/rnd_confoun.c | 48 +++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/lib/crypto/os/rnd_confoun.c b/src/lib/crypto/os/rnd_confoun.c index 35a8b83e4..aca997395 100644 --- a/src/lib/crypto/os/rnd_confoun.c +++ b/src/lib/crypto/os/rnd_confoun.c @@ -22,19 +22,51 @@ static char rcsid_rnd_counfoun_c[] = /* * Generate a random confounder */ -krb5_confounder -krb5_random_confounder PROTOTYPE((void)) +krb5_error_code +krb5_random_confounder(size, fillin) +int size; +krb5_pointer fillin; { static int seeded = 0; - long retval; + register krb5_octet *real_fill; - /* XXX this needs an alternative for an X3J11 C environment, - to use srand() and rand() */ +#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) */ + srandom((unsigned int) time(0)); + seeded = 1; + } +#else + /* assume Berkeley srandom...after all, this is libos! */ if (!seeded) { srandom(time(0)); seeded = 1; } - /* this only gives us 31 random buts, but so what ? */ - retval = random(); - return (krb5_confounder) retval; +#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 + *real_fill = rval & 0xff; + real_fill++; + size--; + if (size) { + *real_fill = (rval >> 8) & 0xff; + real_fill++; + size--; + } + } + return 0; } -- 2.26.2