From: linux-os <linux-os@chaos.analogic.com>
To: Andries Brouwer <aebr@win.tue.nl>
Cc: Ron Peterson <rpeterso@mtholyoke.edu>, linux-kernel@vger.kernel.org
Subject: Re: /dev/random vs. /dev/urandom
Date: Fri, 7 Jan 2005 17:39:46 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.61.0501071729330.22391@chaos.analogic.com> (raw)
In-Reply-To: <20050107213943.GA6052@pclin040.win.tue.nl>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed, Size: 2245 bytes --]
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 <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#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> exi\b^[[Kit
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.
next prev parent reply other threads:[~2005-01-07 22:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-07 19:05 /dev/random vs. /dev/urandom Ron Peterson
2005-01-07 19:16 ` Paulo Marques
2005-01-07 19:24 ` Chris Friesen
2005-01-07 19:26 ` Florian Weimer
2005-01-07 19:27 ` linux-os
2005-01-07 19:40 ` Robert Love
2005-01-07 20:50 ` Ron Peterson
2005-01-07 21:39 ` Andries Brouwer
2005-01-07 22:39 ` linux-os [this message]
2005-01-07 17:55 ` Michal Schmidt
2005-01-07 23:29 ` Andries Brouwer
2005-01-08 17:34 ` Patrick J. LoPresti
2005-01-10 12:41 ` linux-os
2005-01-10 13:03 ` Paulo Marques
2005-01-10 14:39 ` Felipe Alfaro Solana
2005-01-10 15:13 ` Patrick J. LoPresti
2005-01-10 19:24 ` David Schwartz
2005-01-11 14:38 ` Andrea Arcangeli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.61.0501071729330.22391@chaos.analogic.com \
--to=linux-os@chaos.analogic.com \
--cc=aebr@win.tue.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
--cc=rpeterso@mtholyoke.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).