> From: Lutz Jaenicke [mailto:[EMAIL PROTECTED]]
> Sent: Friday, April 27, 2001 6:58 PM
> On Fri, Apr 27, 2001 at 11:33:25AM -0700, Crosland, Jerel (Contract)
wrote:
> > I'd like to use the Ocotillo
> > PRNG with OpenSSL, but it is failing when I do the "make test" in the
> > "randtest" module. Ocotillo creates a named pipe at /dev/urandom but if
> > OpenSSL is treating it like a character device it may not work
correctly.
> As far as I have seen from the open() man-page, using a named pipe for
> this purpose is not very robust (it will fail for non-blocking behaviour:
> you cannot open a pipe for writing without a reading process, HP-UX 10.20)
> and I am not sure how this setup should work with several processes
> trying to read entropy at the same time.
For arrangements of this sort - a named pipe with a single long-running
producer (the daemon) and multiple consumers opening and reading from the
pipe unpredictably - the standard method is to have the producer open the
pipe with O_RDWR (ie. for both reading and writing).[1]
Though the producer never actually reads from the pipe, there is always at
least one process (the producer itself) that has it open for reading. That
lets the open succeed and also prevents the producer from receiving SIGPIPE
or EPIPE (depending on the disposition of SIGPIPE) if all the consumers
close while it's writing.
Several processes trying to read from the pipe at the same time should work
fine for this application. The reads will be interleaved unpredictably
(from the users' points of view), but that won't hurt anything. If that
biases the data stream from the generator, then it's broken anyway.
That said, I can't think of anything to particularly recommend named pipes
over Unix-domain sockets for this application, except the create-and-open
race condition with SVR4 streams-based implementations of Unix-domain
sockets (which I noted in a message to openssl-users on 5 February). Of
course that condition is easily handled with a loop in the producer when the
socket is being created.
[1] Stevens _UNP_ 2nd ed. vol. 2 says to open the pipe twice with two
separate open calls, once with O_RDONLY and once with O_WRONLY, on the
grounds that since pipes are half-duplex they should only be opened in one
direction on any given descriptor. I don't know if this actually makes a
difference on any platform; it doesn't appear to on Solaris 2.6. The Unix
Programming FAQ from comp.unix.programmer documents using O_RDWR with no
special cautions.
Michael Wojcik [EMAIL PROTECTED]
MERANT
Department of English, Miami University
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]