ThreadLocalRandom clinit troubles

Martin Buchholz martinrb at google.com
Tue Jun 24 16:01:53 UTC 2014


On Tue, Jun 24, 2014 at 7:03 AM, Peter Levart <peter.levart at gmail.com>
wrote:

>
> I would rather use SecureRandom.generateSeed() instance method instead of
> SecureRandom.nextBytes(). Why? Because every SecureRandom instance has to
> initialize it's seed 1st before getBytes() can provide the next random
> bytes from the PRNG. Since we only need the 1st 8 bytes from the
> SecureRandom instance to initialize TLR's seeder, we might as well directly
> call the SecureRandom.generateSeed() method.
>

If I strace this program on Linux using strace -ff -q java SecureRandoms:

public class SecureRandoms {
    public static void main(String[] args) throws Throwable {
        byte[] bytes = new byte[8];
        new java.security.SecureRandom().nextBytes(bytes);
    }
}

I see a read from /dev/urandom, but not from /dev/random, so I conclude
your intuitive understanding of how the seeding works must be wrong.  It
makes sense that NativePRNG doesn't need to do any special seeding of its
own, since it reuses the operating system's.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/security-dev/attachments/20140624/404668bd/attachment.htm>


More information about the security-dev mailing list