New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make_random_password(): avoid modulo bias, and do not deplete system entropy #9
make_random_password(): avoid modulo bias, and do not deplete system entropy #9
Conversation
in_channel has a 64k buffer, so one make_random_password () call removes a lot of the system's entropy (for example /proc/sys/kernel/random/entropy_avail goes from ~3000 to 128)
Char.code (input_char chan) mod nr_chars has modulo bias because the original interval is not a multiple of the destination interval, i.e. 256 mod nr_chars != 0. One way to fix this is to keep generating random numbers until they fall outside the interval where modulo bias occurs, that is accept only c=[256 % nr_chars, 256). That interval maps back to [0, nr_chars), and has a length of (256 - 256 % nr_chars), which is a multiple of nr_chars.
|
On Thu, Nov 14, 2013 at 01:48:17AM -0800, edwintorok wrote:
I'm posting this patch to the list for review. Please follow Rich. Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones in_channel has a 64k buffer, so one make_random_password () call removes a lot of the system's entropy (for example /proc/sys/kernel/random/entropy_avail goes from ~3000 to 128)builder/builder.ml | 14 +++++++++++--- diff --git a/builder/builder.ml b/builder/builder.ml
let make_random_password () =
From 4cd1763 Mon Sep 17 00:00:00 2001 Char.code (input_char chan) mod nr_chars has modulo bias because One way to fix this is to keep generating random numbers until they fall outside (256 - 256 % nr_chars), which is a multiple of nr_chars.builder/builder.ml | 10 +++++++++- diff --git a/builder/builder.ml b/builder/builder.ml
let make_random_password () =
1.8.4 |
|
Thanks, I'll close this issue. |
Following the link to builder.ml from your blogpost I noticed the make_random_password () function, and I have some suggestions, well nitpicks really. See the 2 commits from this pull request.
See here for more details: http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx
And see arc4random_uniform's implementation: http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/crypt/arc4random.c?rev=1.26;content-type=text%2Fplain