diff options
author | Nils Kenneweg <nk@ovt.me> | 2014-09-28 12:49:36 +0200 |
---|---|---|
committer | Nils Kenneweg <nk@ovt.me> | 2014-09-28 12:49:36 +0200 |
commit | 1a633153c43fbac8c2f78fd8c50f6e2d8f161388 (patch) | |
tree | e7298cf72c10c1461757b49c59d63d124188afed /test/ccm_arraybuffer_test.js | |
parent | 6aeda8e79b284548be57c988d2ff214b3dd3a65c (diff) | |
download | sjcl-1a633153c43fbac8c2f78fd8c50f6e2d8f161388.zip sjcl-1a633153c43fbac8c2f78fd8c50f6e2d8f161388.tar.gz sjcl-1a633153c43fbac8c2f78fd8c50f6e2d8f161388.tar.bz2 |
use sjcl test suite.
Diffstat (limited to 'test/ccm_arraybuffer_test.js')
-rw-r--r-- | test/ccm_arraybuffer_test.js | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/test/ccm_arraybuffer_test.js b/test/ccm_arraybuffer_test.js index 9f628d6..65a288e 100644 --- a/test/ccm_arraybuffer_test.js +++ b/test/ccm_arraybuffer_test.js @@ -1,39 +1,31 @@ -//Run using phantomjs, since rhino doesn't support array buffers, and node has an issue with create dataviews with a bytelength of 0 -console.log("Running CCM using ArrayBuffer tests"); -var start_time = +(new Date()); - -//This ccm implementation is only defined for IV Lengths of 8 bytes -var applicable_tests = sjcl.test.vector.ccm; - -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 - ); - - pass_d = sjcl.bitArray.equal( - sjcl.arrayBuffer.ccm.compat_decrypt(aes, ct, iv, ad, tlen), pt - ); - - if (!(pass_e && pass_d)){ - console.log("Failed at : ",len+"-ccm #", index, "Pass?:", pass_d); - phantom.exit(1); +new sjcl.test.TestCase("CCM arrayBuffer tests", function (cb) { + if (!sjcl.cipher.aes || !sjcl.mode.ccm || !sjcl.arrayBuffer) { + this.unimplemented(); + cb && cb(); + return; } - return pass_e && pass_d; - + var i, kat = sjcl.test.vector.ccm, tv, iv, ct, aes, len, tlen, thiz=this, w=sjcl.bitArray, pt, h=sjcl.codec.hex, ad; + browserUtil.cpsIterate(function (j, cbb) { + for (i=100*j; i<kat.length && i<100*(j+1); i++) { + tv = kat[i]; + len = 32 * tv.key.length; + aes = new sjcl.cipher.aes(h.toBits(tv.key)); + + // Convert from strings + 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; + + thiz.require(w.equal(sjcl.arrayBuffer.ccm.compat_encrypt(aes, pt, iv, ad, tlen), ct), "aes-"+len+"-ccm-encrypt #"+i); + try { + thiz.require(w.equal(sjcl.arrayBuffer.ccm.compat_decrypt(aes, ct, iv, ad, tlen), pt), "aes-"+len+"-ccm-decrypt #"+i); + } catch (e) { + thiz.fail("aes-ccm-decrypt #"+i+" (exn "+e+")"); + } + } + cbb(); + }, 0, kat.length / 100, true, cb); }); - -var total_time = parseInt(+(new Date())-start_time); -console.log(" + passed all",applicable_tests.length,"tests. ("+ total_time, "ms)"); - |