From d60cd4596a461efc29856c01ba37bb130851c0f0 Mon Sep 17 00:00:00 2001 From: Zaran Date: Tue, 20 Sep 2011 01:51:33 +0200 Subject: Update sjcl --- webclient/lib/sjcl.js | 94 ++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 42 deletions(-) (limited to 'webclient/lib/sjcl.js') diff --git a/webclient/lib/sjcl.js b/webclient/lib/sjcl.js index bb7262a..24d3e3b 100644 --- a/webclient/lib/sjcl.js +++ b/webclient/lib/sjcl.js @@ -19,6 +19,9 @@ var sjcl = { /** @namespace Hash functions. Right now only SHA256 is implemented. */ hash: {}, + + /** @namespace Key exchange functions. Right now only SRP is implemented. */ + keyexchange: {}, /** @namespace Block cipher modes of operation. */ mode: {}, @@ -55,6 +58,12 @@ var sjcl = { bug: function(message) { this.toString = function() { return "BUG: "+this.message; }; this.message = message; + }, + + /** @class Something isn't ready. */ + notReady: function(message) { + this.toString = function() { return "NOT READY: "+this.message; }; + this.message = message; } } }; @@ -310,6 +319,27 @@ 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<>>bits) >>> 26); if (bits < 6) { @@ -534,9 +565,10 @@ sjcl.codec.base64 = { }, /** Convert from a base64 string to a bitArray */ - toBits: function(str) { + toBits: function(str, _url) { str = str.replace(/\s|=/g,''); var out = [], i, bits=0, c = sjcl.codec.base64._chars, ta=0, x; + if (_url) c = c.substr(0,62) + '-_'; for (i=0; i>> 24); - tmp <<= 8; - } - return out; - }, - /** Convert from an array of bytes to a bitArray. */ - toBits: function (bytes) { - var out = [], i, tmp=0; - for (i=0; i