From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261528AbVAGTZw (ORCPT ); Fri, 7 Jan 2005 14:25:52 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261541AbVAGTXl (ORCPT ); Fri, 7 Jan 2005 14:23:41 -0500 Received: from [195.23.16.24] ([195.23.16.24]:21645 "EHLO bipbip.comserver-pie.com") by vger.kernel.org with ESMTP id S261535AbVAGTR7 (ORCPT ); Fri, 7 Jan 2005 14:17:59 -0500 Message-ID: <41DEE00E.8030901@grupopie.com> Date: Fri, 07 Jan 2005 19:16:30 +0000 From: Paulo Marques Organization: Grupo PIE User-Agent: Mozilla Thunderbird 0.7.1 (X11/20040626) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ron Peterson Cc: linux-kernel@vger.kernel.org Subject: Re: /dev/random vs. /dev/urandom References: <20050107190536.GA14205@mtholyoke.edu> In-Reply-To: <20050107190536.GA14205@mtholyoke.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Ron Peterson wrote: > When I compile and run the code below, the string of octal characters > generated by reading /dev/random contains long strings of zeroes. I was > under the impression that /dev/random is "more random" than > /dev/urandom, and will block when it runs out of entropy until it > gathers more. It's only when RAND_LEN is on the largish side that these > strings of zeroes appear. > >[...] > read( fd, dat, RAND_LEN ); > for( i = 0; i < RAND_LEN; i++ ) { > dat[i] = (dat[i] & 0x07) + '0'; This is wrong. You must check the return value of read to know how many bytes have you actually gathered, instead of assuming RAND_LEN... -- Paulo Marques - www.grupopie.com "A journey of a thousand miles begins with a single step." Lao-tzu, The Way of Lao-tzu