bitwiseshiftleft/sjcl — pull request #89 by MarcoPolo (2013-08-11 19:22:18+00:00)
Title: Fast ArrayBuffer Implementation of CCM + ArrayBuffer Codec

I really like sjcl, and I've been using it to encrypt Gigabytes in javascript. However the existing ccm implementation is too slow. So I decided to implement ccm using arraybuffers to speed things up.

# Benchmarks:
(https://gist.github.com/MarcoPolo/6180338):
Original Implementation encrypting 1MB: 767 ms
Array Buffer implementation encrypting 1MB: 137 ms
The results get more impressive for bigger data

# Implementation:
All new code is under sjcl.arrayBuffer.ccm

One caveat:
It's only valid for an IV of 8 bytes

# Compatibility
I've defined sjcl.arrayBuffer.ccm.compat_encrypt and compat_decrypt
These functions look and act just like the sjcl.mode.ccm.encrypt decrypt
They aren't as fast as the sjcl.arrayBuffer.ccm.encrypt decrypt but still faster than the original

They simply convert the bitarrays to arraybuffers before calling sjcl.arrayBuffer.ccm.encrypt decrypt

# Test
Rhino doesn't support Array Buffers, so I wrote a new testfile using phantomjs
I ran all the tests from ccm_vectros that had an IV length of 8 bytes (500 some tests)
I added the test to the make test

# Codec
SJCL now has a codec for converting between ArrayBuffers and bitArrays!

# Final words
SJCL is great, but we need to take advantage of the better/faster ways to bit manipulate in JS. I think this is a great start.

Let me know if there is anything you want me to do