kripken/emscripten — pull request #2773 by NWilson (2014-09-08 18:14:36+00:00)
Title: Add an emscripten crypto API

This gives C code a convenient way to access the crypto functions in node.js or a web browser. In this commit, we add support for fetching random numbers, and making SHA hashes.

Soon-to-be-added functions: a high-level RSA wrapper, and AES functions.

These are useful things for emscripten to accept upstream, because they abstract away differences between node.js and WebCrypto, plus it's tedious boilerplate that application porters shouldn't have to write.

Advantages of using WebCrypto rather than native JavaScript or C implementations via emscripten:
1. Smaller download size
2. The browser's own crypto library gets auto-updated, a bundled library doesn't
3. The browser's implementation is much less susceptible to timing attacks (the JavaScript JIT is not a secure environment for implementing crypto algorithms)
4. It's a well-known audited implementation. Native JavaScript libraries are not considered mature yet, nor is emscripten well-suited to compiling crypto code (can't use fast assembler, or constant-time implementation tricks).