diff options
author | Marco Munizaga <marco.munizaga@grooveshark.com> | 2013-08-11 14:09:06 -0400 |
---|---|---|
committer | Marco Munizaga <marco.munizaga@ufl.edu> | 2013-10-26 19:19:56 -0400 |
commit | 6995f0cbda14b98fedaf573ae27a45f792f65aa7 (patch) | |
tree | 42c53edccc8f782579675e3c0c8851ef7e8cec53 /test/ccm_arraybuffer_test.js | |
parent | a8ac27a8279d1ac1dabfd81958e8ff51d7ad8327 (diff) | |
download | sjcl-6995f0cbda14b98fedaf573ae27a45f792f65aa7.zip sjcl-6995f0cbda14b98fedaf573ae27a45f792f65aa7.tar.gz sjcl-6995f0cbda14b98fedaf573ae27a45f792f65aa7.tar.bz2 |
Added array buffer tests
Diffstat (limited to 'test/ccm_arraybuffer_test.js')
-rw-r--r-- | test/ccm_arraybuffer_test.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/ccm_arraybuffer_test.js b/test/ccm_arraybuffer_test.js new file mode 100644 index 0000000..4069d71 --- /dev/null +++ b/test/ccm_arraybuffer_test.js @@ -0,0 +1,47 @@ +//Run using phantomjs, since rhino doesn't support array buffers, and node has an issue with create dataviews with a bytelength of 0 +sjcl = require("../sjcl.js") + +sjcl = sjcl || {} +sjcl.test = {} +sjcl.test.vector = {} +require("./ccm_vectors.js") + +//This ccm implementation is only defined for IV Lengths of 8 bytes +var applicable_tests = sjcl.test.vector.ccm.filter(function(test){ + return test.iv.length === 16 +}) + +applicable_tests.map(function(tv, index){ + var len = 32 * tv.key.length, + h = sjcl.codec.hex + aes = new sjcl.cipher.aes(h.toBits(tv.key)), + iv = h.toBits(tv.iv), + ad = h.toBits(tv.adata), + pt = h.toBits(tv.pt), + ct = h.toBits(tv.ct + tv.tag), + tlen = tv.tag.length * 4, + pass_e = false, + pass_d = false; + + pass_e = sjcl.bitArray.equal( + sjcl.arrayBuffer.ccm.compat_encrypt(aes, pt, iv, ad, tlen), ct + ) + + console.log("Running: ",len+"-ccm-encrypt #", index, "Pass?:", pass_e) + + pass_d = sjcl.bitArray.equal( + sjcl.arrayBuffer.ccm.compat_decrypt(aes, ct, iv, ad, tlen), pt + ) + + console.log("Running: ",len+"-ccm-decrypt #", index, "Pass?:", pass_d) + + if (!(pass_e && pass_d)){ + throw("Failed at: "+i) + } + + return pass_e && pass_d; + +}) + +phantom.exit() + |