This message generated a parse failure. Raw output follows here. Please use 'back' to navigate. From devnull@lkml.org Sat Apr 27 04:28:00 2024 Delivery-date: Fri, 07 Jan 2005 23:52:21 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261677AbVAGWom (ORCPT ); Fri, 7 Jan 2005 17:44:42 -0500 Received: from alog0359.analogic.com ([208.224.222.135]:15488 "EHLO chaos.analogic.com") by vger.kernel.org with ESMTP id S261665AbVAGWkI (ORCPT ); Fri, 7 Jan 2005 17:40:08 -0500 Received: from chaos.analogic.com (localhost.localdomain [127.0.0.1]) by chaos.analogic.com (8.12.11/8.12.11) with ESMTP id j07Mdlml022488; Fri, 7 Jan 2005 17:39:47 -0500 Received: (from linux-os@localhost) by chaos.analogic.com (8.12.11/8.12.11/Submit) id j07MdkTW022487; Fri, 7 Jan 2005 17:39:46 -0500 Date: Fri, 7 Jan 2005 17:39:46 -0500 (EST) From: linux-os Reply-To: linux-os@analogic.com To: Andries Brouwer Cc: Ron Peterson , linux-kernel@vger.kernel.org Subject: Re: /dev/random vs. /dev/urandom In-Reply-To: <20050107213943.GA6052@pclin040.win.tue.nl> Message-Id: References: <20050107190536.GA14205@mtholyoke.edu> <20050107213943.GA6052@pclin040.win.tue.nl> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 7 Jan 2005, Andries Brouwer wrote: > On Fri, Jan 07, 2005 at 02:05:36PM -0500, 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. > > But it is your program that invents the zeros, they are not returned > by /dev/random. The bug in your program is failing to check the > return value of read(). > - Also, the following shows that the AND operation will destroy the randomness of the data. In this case I AND with 1, which should produce as many '1's as '0's, ... and clearly does not. Script started on Fri 07 Jan 2005 05:36:43 PM EST LINUX> cat >xxx.c #include #include #include #include #include #define LEN 0x20 void doit(unsigned char *buf) { size_t i, odds, evens; int fd, ret; odds = evens = 0; printf("Trying %s\n", buf); if((fd = open(buf, O_RDONLY)) < 0) exit(EXIT_FAILURE); if((ret = read(fd, buf, LEN)) > 0) { for(i=0; i< ret; i++) { if(buf[i] & 1) odds++; else evens++; printf("%02x", buf[i] & 1); } printf("\n odds = %u evens = %u\n", odds, evens); } (void)close(fd); } int main() { char buf[0x100]; strcpy(buf, "/dev/random"); doit(buf); strcpy(buf, "/dev/urandom"); doit(buf); return 0; } LINUX> gcc -Wall -O2 -o xxx xxx.c LINUX> ./xxx Trying /dev/random 0100000101010000010001000101000000000000000101000100010000000101 odds = 14 evens = 18 Trying /dev/urandom 0001010001000100000101000100010001000000000000000000010000000000 odds = 10 evens = 22 LINUX> ./xxx Trying /dev/random 0100000100010101000101010101010101000100010000010001010000000101 odds = 20 evens = 12 Trying /dev/urandom 0100000100000101010001000101010001010001000000010101010100010000 odds = 18 evens = 14 LINUX> exiit Script done on Fri 07 Jan 2005 05:37:37 PM EST Cheers, Dick Johnson Penguin : Linux version 2.6.10 on an i686 machine (5537.79 BogoMips). Notice : All mail here is now cached for review by Dictator Bush. 98.36% of all statistics are fiction. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/