From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 24 13:14:39 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 54410106566B for ; Thu, 24 Dec 2009 13:14:39 +0000 (UTC) (envelope-from graphov@gmail.com) Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.25]) by mx1.freebsd.org (Postfix) with ESMTP id E0D5F8FC17 for ; Thu, 24 Dec 2009 13:14:38 +0000 (UTC) Received: by ey-out-2122.google.com with SMTP id 4so2057753eyf.9 for ; Thu, 24 Dec 2009 05:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=3/a2mlHoehJOVfSKXxZNXhEt2OdY+310thfXxELdmB8=; b=i9nFvBjaMszNPjOezmGoUgr+lnA4J7P+evfLDWn2/JrQO53QkTjekpqy43XrOXgur0 flVJk96LPgand/4AlCE18dSys+p/2nMlIa0viWg58zUcx4402XTiTKQ3IjFsHtNVqVF9 Lziv94FCcDQIaD3tA+wD+39Kirbw5UU9tTYKw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=kYEUpYs3XBhfW24mAjmcX1mK/mYkqRYUARvrWw9TMFDi12uUUYmuwJJm4m5gCpw7ka aiU9faulfpWJPyTLDQBrmhvgELsHwz5qdto37dA4ccBrqwVwERlPSDvFT33ikqlHAA6Y uKReEt3XrlTlUOtCqkdex7TgrFalivg5KKGlw= MIME-Version: 1.0 Received: by 10.213.109.156 with SMTP id j28mr6070739ebp.79.1261658715924; Thu, 24 Dec 2009 04:45:15 -0800 (PST) Date: Thu, 24 Dec 2009 15:45:15 +0300 Message-ID: <5a5b03660912240445x7df1498dt42e29d93105efebc@mail.gmail.com> From: Paul Graphov To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: yarrow random generator X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 13:14:39 -0000 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.