From 86fe235744b3aab4246e1278327aef9125eb37f0 Mon Sep 17 00:00:00 2001 From: Quinn Slack Date: Wed, 20 Apr 2011 22:29:14 -0700 Subject: [PATCH] undo ecc --- core/bitArray.js | 23 +-- core/cbc.js | 115 ----------- core/convenience.js | 15 +- core/ocb2.js | 5 +- core/sjcl.js | 2 +- test/cbc_test.js | 33 --- test/cbc_vectors.js | 413 -------------------------------------- test/ecdh_test.js | 18 -- test/ecdsa_test.js | 29 --- test/run_tests_browser.js | 2 - 10 files changed, 11 insertions(+), 644 deletions(-) delete mode 100644 core/cbc.js delete mode 100644 test/cbc_test.js delete mode 100644 test/cbc_vectors.js delete mode 100644 test/ecdh_test.js delete mode 100644 test/ecdsa_test.js diff --git a/core/bitArray.js b/core/bitArray.js index a6d06171..40e4acd0 100644 --- a/core/bitArray.js +++ b/core/bitArray.js @@ -31,7 +31,7 @@ sjcl.bitArray = { /** * Array slices in units of bits. - * @param {bitArray} a The array to slice. + * @param {bitArray a} The array to slice. * @param {Number} bstart The offset to the start of the slice, in bits. * @param {Number} bend The offset to the end of the slice, in bits. If this is undefined, * slice until the end of the array. @@ -42,27 +42,6 @@ sjcl.bitArray = { return (bend === undefined) ? a : sjcl.bitArray.clamp(a, bend-bstart); }, - /** - * Extract a number packed into a bit array. - * @param {bitArray} a The array to slice. - * @param {Number} bstart The offset to the start of the slice, in bits. - * @param {Number} length The length of the number to extract. - * @return {Number} The requested slice. - */ - extract: function(a, bstart, blength) { - // FIXME: this Math.floor is not necessary at all, but for some reason - // seems to suppress a bug in the Chromium JIT. - var x, sh = Math.floor((-bstart-blength) & 31); - if ((bstart + blength - 1 ^ bstart) & -32) { - // it crosses a boundary - x = (a[bstart/32|0] << (32 - sh)) ^ (a[bstart/32+1|0] >>> sh); - } else { - // within a single word - x = a[bstart/32|0] >>> sh; - } - return x & ((1<> 3) & 15)) * 0x1010101; - - /* Pad and encrypt. */ - iv = prp.encrypt(xor(iv,w.concat(plaintext,[bl,bl,bl,bl]).slice(i,i+4))); - output.splice(i,0,iv[0],iv[1],iv[2],iv[3]); - return output; - }, - - /** Decrypt in CBC mode. - * @param {Object} prp The block cipher. It must have a block size of 16 bytes. - * @param {bitArray} ciphertext The ciphertext data. - * @param {bitArray} iv The initialization value. - * @param {bitArray} [adata=[]] The authenticated data. It must be empty. - * @return The decrypted data, an array of bytes. - * @throws {sjcl.exception.invalid} if the IV isn't exactly 128 bits, or if any adata is specified. - * @throws {sjcl.exception.corrupt} if if the message is corrupt. - */ - decrypt: function(prp, ciphertext, iv, adata) { - if (adata && adata.length) { - throw new sjcl.exception.invalid("cbc can't authenticate data"); - } - if (sjcl.bitArray.bitLength(iv) !== 128) { - throw new sjcl.exception.invalid("cbc iv must be 128 bits"); - } - if ((sjcl.bitArray.bitLength(ciphertext) & 127) || !ciphertext.length) { - throw new sjcl.exception.corrupt("cbc ciphertext must be a positive multiple of the block size"); - } - var i, - w = sjcl.bitArray, - xor = w._xor4, - bi, bo, - output = []; - - adata = adata || []; - - for (i=0; i 16) { - throw new sjcl.exception.corrupt("pkcs#5 padding corrupt"); - } - bo = bi * 0x1010101; - if (!w.equal(w.bitSlice([bo,bo,bo,bo], 0, bi*8), - w.bitSlice(output, output.length*32 - bi*8, output.length*32))) { - throw new sjcl.exception.corrupt("pkcs#5 padding corrupt"); - } - - return w.bitSlice(output, 0, output.length*32 - bi*8); - } - }; -}; diff --git a/core/convenience.js b/core/convenience.js index d97f9dfb..2a7a3f25 100644 --- a/core/convenience.js +++ b/core/convenience.js @@ -58,8 +58,7 @@ /* do the encryption */ p.ct = sjcl.mode[p.mode].encrypt(prp, plaintext, p.iv, p.adata, p.tag); - //return j.encode(j._subtract(p, j.defaults)); - return j.encode(p); + return j.encode(j._subtract(p, j.defaults)); }, /** Simple decryption function. @@ -123,7 +122,7 @@ if (!i.match(/^[a-z0-9]+$/i)) { throw new sjcl.exception.invalid("json encode: invalid property name"); } - out += comma + '"' + i + '":'; + out += comma + i + ':'; comma = ','; switch (typeof obj[i]) { @@ -161,13 +160,13 @@ } var a = str.replace(/^\{|\}$/g, '').split(/,/), out={}, i, m; for (i=0; i