2 ** Copyright 1998 - 2006 Double Precision, Inc.
3 ** See COPYING for distribution information.
20 #include <sys/types.h>
26 #include "random128.h"
28 static const char rcsid
[]="$Id: random128.c,v 1.6 2006/05/28 15:29:52 mrsam Exp $";
30 const char *random128()
32 static char randombuf
[sizeof(MD5_DIGEST
)*2+1];
36 int fd
=open(RANDOM
, O_RDONLY
);
37 char buf2
[sizeof(MD5_DIGEST
)];
42 if (read(fd
, buf2
, sizeof(buf2
)) == sizeof(buf2
))
44 for (i
=0; i
<sizeof(buf2
); i
++)
45 sprintf(randombuf
+i
*2,
47 (int)(unsigned char)buf2
[i
]);
56 /* /dev/urandom not available or broken? Create some noise */
62 struct MD5_CONTEXT context
;
72 if (pipe(pipefd
)) return (0);
73 while ((p
=fork()) == -1)
85 while ((p
=fork()) == -1)
91 execl(W
, W
, (char *)0);
99 execl(PS
, PS
, PS_OPTIONS
, (char *)0);
104 md5_context_init(&context
);
105 md5_context_hashstream(&context
, &t
, sizeof(t
));
106 md5_context_hashstream(&context
, &p
, sizeof(p
));
107 l
=sizeof(t
)+sizeof(p
);
109 while ((n
=read(pipefd
[0], buf
, sizeof(buf
))) > 0)
111 md5_context_hashstream(&context
, buf
, n
);
114 md5_context_endstream(&context
, l
);
115 md5_context_digest(&context
, digest
);
117 while ((p2
=wait(&s
)) >= 0 && p
!= p2
)
120 for (n
=0; n
<sizeof(digest
); n
++)
121 sprintf(randombuf
+n
*2,
122 "%02X", (int)(unsigned char)digest
[n
]);