travist/jsencrypt — pull request #6 by ctso (2013-08-20 21:59:24+00:00)
Title: Use better methods for generating entropy

The jsbn libraries are a bit old, last modified in 2009 to be exact. Crypto in the browser has come a long way since then, and I generally feel that the way it generates entropy could be greatly improved.

Using time to generate random values is well, not random. Math.random() is not as good as using crypto.getRandomValues, and while the RNG included in jsbn does attempt to use crypto.random, that API seems to be very old and not supported on modern browsers.

Up to you if you would like to accept this, as you state that the jsbn files have been copied over exactly. Not sure what your stance is on modifying them. This pull request does a few things:

- Prefers crypto.getRandomValues
- Falls back to collecting entropy via mouse movement.
- When the PRNG (Arcfour) is initiated, if there is not enough entropy from getRandomValues or mouse movement, it falls back to Math.random.

I am currently using these changes in a live system (http://www.cyanogenmod.org/blog/cyanogenmod-account) that has a lot of "tinfoil hat" users, and would love to see them upstream :)