David R. Conrad (drc@adni.net)
Thu, 11 Feb 1999 10:00:09 -0500 (EST)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, 10 Feb 1999, Bill Frantz wrote:
> At 2:31 PM -0700 2/10/99, David R. Conrad wrote:
> >[My problem with this is that the source of entropy is particularly
> > bad... --Perry]
>
> Perry - I thought that /dev/random was fairly good on the systems that
> support it. However, collapsing all the entropy down to a 16 or 32 bit int
> seems a bit bogus.
Good point. Here's a revised version which solves that problem, but there
is still the issue of a slight bias due to the %. (I didn't want to waste
bits from /dev/random, so I used unsigned char -- any thoughts on whether
the bias is worth worrying about? I gather it would be much less if I
used a wider type for seed[].)
-=-=- randpwd.c -=-=-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
int main(int argc, char **argv) {
struct timeval tv;
char chars[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789,.;'/-=";
int i, len = strlen(chars);
unsigned char seed[8];
FILE *fp;
fp = fopen("/dev/random", "r");
if (fp) {
if (fread(seed, 1, 8, fp) != 8) {
fputs("Error reading from /dev/random\n", stderr);
return EXIT_FAILURE;
}
fclose(fp);
} else {
#ifdef PARANOID
fputs("Error reading from /dev/random\n", stderr);
return EXIT_FAILURE;
#endif
/* use seriously inferior seed material */
gettimeofday(&tv, NULL);
srand(tv.tv_sec ^ tv.tv_usec ^ getpid());
for (i = 0; i < 8; i++) seed[i] = rand();
}
if (argc > 1) for (i = 0; i < 5; i++) printf("%d", seed[i]%6+1);
else for (i = 0; i < 8; i++) printf("%c", chars[seed[i]%len]);
fputs("\n", stdout);
return 0;
}
-=-=- randpwd.c -=-=-
Compile with -DPARANOID unless you don't have /dev/random.
David R. Conrad <drc@adni.net> PGP keys (0x1993E1AE and 0xA0B83D31):
DSS Fingerprint20 = 9942 E27C 3966 9FB8 5058 73A4 83CE 62EF 1993 E1AE
RSA Fingerprint16 = 1D F2 F3 90 DA CA 35 5D 91 E4 09 45 95 C8 20 F1
Note: Due to frequent spam abuse, I accept no email from *.da.uu.net.
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv
iQA/AwUBNsLwhoPOYu8Zk+GuEQKUMwCg4CohLpiItcsf64mjxXjLhu/oR5UAoPFk
QB7eJFJLYRB/lyx8gXsJ9y3R
=VUWg
-----END PGP SIGNATURE-----
The following archive was created by hippie-mail 7.98617-22 on Sat Apr 10 1999 - 01:18:27