Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

I'm writing some software that requires the use of a CSPRNG with javascript for use in the browser and I'm wondering what libraries are available. Crypto-js doesn't seem to have a CSPRNG I can directly call (unless I missed it?). I've looked through the Stanford crypto js library, but I'm uncertain how much analysis this code has gotten. http://bitwiseshiftleft.github.io/sjcl/doc/symbols/sjcl.random.html

They appear to be implementing Schneier's Fortuna: http://sourceforge.net/projects/fortunaprng/

I've also seen https://www.clipperz.com/open_source/javascript_crypto_library/.

My question is there a well vetted crypto js library that has a well designed CSPRNG that generates values independently of some browser support? Or with a standard all modern browsers implement? And where is the entropy source? I'm used to crypto with languages like java and C++, not this fragmented world.

share|improve this question

put on hold as off-topic by owlstead, DrLecter, otus, poncho, Gilles 2 days ago

  • This question does not appear to be about cryptography within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Similar to crypto.stackexchange.com/questions/9256/… –  archie Nov 2 '13 at 1:07
1  
Not so much in my opinion, I'm asking a broader question than a particular implementation. I'm also concerned about javascript entropy sources. –  Charles Hoskinson Nov 2 '13 at 1:39
1  
Thanks e-sushi for the edits –  Charles Hoskinson Nov 2 '13 at 7:10
4  
This question appears to be off-topic because it is about implementations for a specific runtime. –  owlstead Jul 25 at 14:26
    
Your question is not clear: you say you want a CSPRNG, and then you talk about an entropy source. Do you need a CSRNG (unpredictable, i.e. at least seeded with a sufficient entropy source), or a CSPRNG (i.e. deterministic, but predictable only by knowing the secret seed)? –  Gilles 2 days ago

1 Answer 1

I would try to avoid doing any cryptography using javascript… but that's just my personal opinion.

Anyway, if you really want to walk the Javascript path, you could skip the libraries and take a look at the window.crypto.getRandomValues() function, as long as you can live with the fact that it's an experimental API and not yet supported in all browsers… it should work on current versions of Firefox and Chrome though.

And for Opera, there's Math.Random() which has been implemented as a CSRNG. But you should be aware that Math.Random will only be a CSRNG in Opera (only in Opera, not any other browser!!!), and that the function will only return 53 bits of entropy on each call.

Besides that, I don't know of any further CSRNGs being available in Javascript, or in Javascript libraries.

EDIT

Some stuff that might help you find solutions to your quest:

share|improve this answer
    
""Am I really dealing with a random number generator, or with something provided by an attacker?"" You resolve this attack via https and can even have the server sign the code. "First up: I would try to avoid doing any cryptography using javascript… " As much as we'd like to return to the C days, JS is king now and will be for some time. I have to work with the cards I've been dealt. –  Charles Hoskinson Nov 2 '13 at 6:01
    
@e-sushi: "Am I really dealing with a random number generator, or with something provided by an attacker?" - what's your line of reasoning for doubting this assertion? Say for example, a sound javascript implementation of CTR_DRBG as defined in SP800-90A, delivered via TLS, using decent quality entropy (or even something like the service offered here). Given the NSA's recent indiscretions (amongst others), I think JS crypto is something worth considering. –  hunter Nov 2 '13 at 6:04
    
@CharlesHoskinson Well, as I noted, there's window.crypto.getRandomValues() and Opera's Math.Random(). With some browser detection code you can do a lot. Problem will be to get IE into the crypto bucket. –  e-sushi Nov 2 '13 at 6:05
1  
@CharlesHoskinson - C'mon - I'm a fan of JS, really, but 'King'? In my opinion, a language that can't handle 64-bit integers natively in crypto is going to struggle. I also think that weakly-typed languages like JS are asking for trouble. –  hunter Nov 2 '13 at 6:11
    
@e-sushi - the whole chicken/egg problem with javascript is real - but still, the world could be forgiven for having trust-issues with TLS/the-internet/NSA. This question is strongly related to this one. It's a contentious issue - I err very much on the side of experimentation and creativity - not qualities that usually lend themselves well to crypto. –  hunter Nov 2 '13 at 6:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.