From: Mike Mestnik <cheako@mikemestnik.net>
To: linux-kernel@vger.kernel.org
Subject: drivers/char/random.c: Open ended int size, makes assumption always 4 bytes.
Date: Wed, 09 Nov 2011 22:49:14 -0600 [thread overview]
Message-ID: <4EBB57CA.6060202@mikemestnik.net> (raw)
Given that 64bit systems are farilly common it stands to reason that
calculations that need to use 32bit int/float(s) are appropriately type
cast. I understand that while 64bit systems have pointers that are
64bit and that the size of int may well be 32bit, it's important that
type casts and shifts such as these take sizeof(int) into account...
Even if sizeof(int) can be assured to always be 4.
In this case I believe it would be best to use more specific typecasts
to get accurate calculations.
Note the sifts here are 4bits, not 4bytes. Still I think there is room
for problems here if these functions are passed int(s) with bits above
32set.
http://j.mp/uj0JZC
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=drivers/char/random.c;h=63e19ba56bbea5a12ee784f023bd13a758eaf611;hb=HEAD#l683
On another note, I can't discover what "uint code" should be. It seams
like a good place to avoid hitting the repeat squelch. For my project I
may have two 6 sided dice and there is a good chance they would hit the
same total for adjacent iterations, dropping this result seams like
something to avoid if the goal is to pool randomness. At the same time
I'd wonder if I should shift/xor to undo the effects of this function or
if this is merely the first step in massaging the data into random
output. One wonders what I should do.
My first thought would be to do something like:
void putc_randomness(unsigned char code)
{
static unsigned char last_value;
value^=1;
add_input_randomness(32768, code ^ (code >> 4) ^ value, value);
}
reply other threads:[~2011-11-10 4:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4EBB57CA.6060202@mikemestnik.net \
--to=cheako@mikemestnik.net \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®