2 ** Copyright 1998 - 2006 Double Precision, Inc.
3 ** See COPYING for distribution information.
20 #include <sys/types.h>
26 #include "random128.h"
29 const char *random128()
31 static char randombuf
[sizeof(MD5_DIGEST
)*2+1];
35 int fd
=open(RANDOM
, O_RDONLY
);
36 char buf2
[sizeof(MD5_DIGEST
)];
41 if (read(fd
, buf2
, sizeof(buf2
)) == sizeof(buf2
))
43 for (i
=0; i
<sizeof(buf2
); i
++)
44 sprintf(randombuf
+i
*2,
46 (int)(unsigned char)buf2
[i
]);
55 /* /dev/urandom not available or broken? Create some noise */
61 struct MD5_CONTEXT context
;
71 if (pipe(pipefd
)) return (0);
72 while ((p
=fork()) == -1)
84 while ((p
=fork()) == -1)
90 execl(W
, W
, (char *)0);
98 execl(PS
, PS
, PS_OPTIONS
, (char *)0);
103 md5_context_init(&context
);
104 md5_context_hashstream(&context
, &t
, sizeof(t
));
105 md5_context_hashstream(&context
, &p
, sizeof(p
));
106 l
=sizeof(t
)+sizeof(p
);
108 while ((n
=read(pipefd
[0], buf
, sizeof(buf
))) > 0)
110 md5_context_hashstream(&context
, buf
, n
);
113 md5_context_endstream(&context
, l
);
114 md5_context_digest(&context
, digest
);
116 while ((p2
=wait(&s
)) >= 0 && p
!= p2
)
119 for (n
=0; n
<sizeof(digest
); n
++)
120 sprintf(randombuf
+n
*2,
121 "%02X", (int)(unsigned char)digest
[n
]);