News for hackers. Stuff that matters.
Re:How to safely generate a random number by weavejester on Tuesday February 25, 2014 @08:42PM (#7302175)
The NativePRNG algorithm for SecureRandom XORs /dev/urandom with a SHA1PRNG seeded from /dev/urandom, so as long as the XOR is correct, it should be no less secure than reading from /dev/urandom directly.
Re:How to safely generate a random number by tptacek on Tuesday February 25, 2014 @08:50PM (#7302212)
I would definitely avoid Java's SecureRandom. It means too many different things depending on what platform you're on. Meanwhile, XORing SHA1PRNG against /dev/urandom seems cryptographically nonsensical.
Re:How to safely generate a random number by TheLoneWolfling on Tuesday February 25, 2014 @09:10PM (#7302309)
> XORing SHA1PRNG against /dev/urandom seems cryptographically nonsensical.

Untrue! Assuming that the two (/dev/urandom and SHA1PRNG) are not correlated, the resulting output will be at least as secure as the most secure of the two. This means that (for example) if SHA1PRNG is found to be breakable, SecureRandom will still be at least as secure as /dev/urandom, and vice versa.

Re:How to safely generate a random number by tptacek on Tuesday February 25, 2014 @09:27PM (#7302395)
This is a rabbit hole I don't want to go down and so I will concede the point about NativePRNG, while sticking to my guns on "avoid the Java SecureRandom interface".
Re:How to safely generate a random number by weavejester on Tuesday February 25, 2014 @09:18PM (#7302344)
If you want a cross-platform secure random source, you can't rely on /dev/urandom existing, so I'm not sure what alternative you're suggesting here.
Re:How to safely generate a random number by tptacek on Tuesday February 25, 2014 @09:29PM (#7302411)
You can't on the one hand say that OpenJDK Unix SecureRandom uses urandom so it's OK while on the other hand saying that SecureRandom is preferable because it works on platforms without urandom. That's the problem with SecureRandom: it's hard to know exactly what it's doing, as the Android team discovered last year.

(On Windows, I'd use CryptGenRandom, although it inspires even less confidence than Linux /dev/random).

Re:How to safely generate a random number by weavejester on Tuesday February 25, 2014 @09:51PM (#7302523)
I don't see any contradiction. SecureRandom uses urandom where it's available, and the next best alternative where it's not. Again, I'd like to know what your suggested solution is. The way I see it, you can either:

1) Don't write cross-platform code

2) Use the language implementation

3) Write your own cross-platform code

Assuming (1) isn't an option, it comes down to using SecureRandom or writing your own version of SecureRandom, which strikes me as plain crazy.

Re:How to safely generate a random number by tptacek on Tuesday February 25, 2014 @09:53PM (#7302534)
If SecureRandom was simply "pull bytes from urandom" on Linux and "pull bytes from CryptGenRandom" on Windows, I wouldn't care enough to argue. But it's not. It's not even "pull bytes from urandom" on Linux; depending on the specific details of your platform, it can be dramatically different than that.

I'm absolutely not recommending that people write their own version of SecureRandom; I'm advising the opposite. Avoid userspace CSPRNGs. Use the system CSPRNG.

Re:How to safely generate a random number by weavejester on Wednesday February 26, 2014 @04:45AM (#7303907)
So I should write my own cross-platform interface to the system PRNG? Doesn't that strike you as more prone to error than relying on SecureRandom, which at least has the advantage of having many eyes on it.
Re:How to safely generate a random number by tptacek on Wednesday February 26, 2014 @11:41AM (#7305946)
NO. Relying on SecureRandom is riskier than writing the 5-10 lines of code it takes to read from urandom. Prefer urandom to SecureRandom.

Look what "many eyes" did for the Harmony PRNG.

Re:How to safely generate a random number by weavejester on Wednesday February 26, 2014 @05:15PM (#7308461)
And urandom is not cross-platform, so if I were going to write a cross-platform library, how would you suggest doing it? By writing an interface to urandom, then an interface to CryptGenRandom (doesn't that require an FFI?), and then manually going through all of the platforms Java can potentially execute on until I can be sure I've covered all my bases?

I'm pretty sure that's going to be more than 5-10 lines of code.

Re:How to safely generate a random number by marshray on Tuesday February 25, 2014 @09:37PM (#7302454)
If you're ever in Redmond, stop by and we'll go inspire some confidence with the folks maintaining it.
Re:How to safely generate a random number by tptacek on Tuesday February 25, 2014 @09:40PM (#7302468)
Two immediate questions: forward secrecy and CryptGenRandom's state relative to other WinAPI processes. As in, I'm very clear how the Unix security model protects /dev/random, and less clear about Windows. Some of my C.G.R. thoughts are probably dated. But it's the system CSPRNG, and I think, just use the system CSPRNG.
Re:How to safely generate a random number by marshray on Tuesday February 25, 2014 @09:59PM (#7302567)
You have my email right? If you'd like to send me some specific questions and concerns I can try to put them to people who know.
Re:How to safely generate a random number by pbsd on Wednesday February 26, 2014 @11:20AM (#7305809)
The forward security issues have been fixed for a long time (since Vista I believe): they now use SP800-90A's CTR_DRBG. But the generator continues to be unprotected in user mode, seeded from kernel.