Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Dec 2009 15:45:15 +0300
From:      Paul Graphov <graphov@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   yarrow random generator
Message-ID:  <5a5b03660912240445x7df1498dt42e29d93105efebc@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hello guys,

I've looked at FreeBSD 8.0 cryptographically secure pseudorandom
numbers generator and have a question. It looks like a bug but I'am
not sure.

In file sys/dev/randomdev.c, function random_read:

        if (!random_systat.seeded)
                error = (*random_systat.block)(flag);

It blocks until PRNG is seeded. For software random generator implementation
block method looks as follows, sys/dev/randomdev_soft.c:

random_yarrow_block(int flag)
{
        int error = 0;

        mtx_lock(&random_reseed_mtx);

        /* Blocking logic */
        while (random_systat.seeded && !error) {
                if (flag & O_NONBLOCK)
                        error = EWOULDBLOCK;
                else {
                        printf("Entropy device is blocking.\n");
                        error = msleep(&random_systat,
                            &random_reseed_mtx,
                            PUSER | PCATCH, "block", 0);
                }
        }
        mtx_unlock(&random_reseed_mtx);

        return error;
}

It seems that random_systat.seeded in "while" condition should be negated.
Or it will never block actually, or block erroneously until next reseed
(under very rare
conditions)

Am I right?

Thanks.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5a5b03660912240445x7df1498dt42e29d93105efebc>