diff --git a/package.json b/package.json
index 8b0b1c20e..133f71bb8 100644
--- a/package.json
+++ b/package.json
@@ -64,7 +64,6 @@
"gulp-terser": "^1.4.0",
"gulp-util": "3.0.8",
"node-fs": "0.1.7",
- "openpgp": "2.6.2",
"rimraf": "3.0.2"
},
"dependencies": {
diff --git a/tasks/js.js b/tasks/js.js
index f35d222cb..bff007bbc 100644
--- a/tasks/js.js
+++ b/tasks/js.js
@@ -37,14 +37,14 @@ const jsServiceWorker = () => {
// OpenPGP
const jsOpenPGP = () => {
return gulp
- .src('node_modules/openpgp/dist/openpgp.min.js')
+ .src('vendors/openpgp-2.6.2/dist/openpgp.min.js')
.pipe(gulp.dest(config.paths.staticMinJS));
};
// OpenPGP Worker
const jsOpenPGPWorker = () => {
return gulp
- .src('node_modules/openpgp/dist/openpgp.worker.min.js')
+ .src('vendors/openpgp-2.6.2/dist/openpgp.worker.min.js')
.pipe(gulp.dest(config.paths.staticMinJS));
};
diff --git a/vendors/openpgp-2.6.2/LICENSE b/vendors/openpgp-2.6.2/LICENSE
new file mode 100644
index 000000000..65c5ca88a
--- /dev/null
+++ b/vendors/openpgp-2.6.2/LICENSE
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ * Heap buffer layout by offset:
+ *
+ * 0x0000 encryption key schedule
+ * 0x0400 decryption key schedule
+ * 0x0800 sbox
+ * 0x0c00 inv sbox
+ * 0x1000 encryption tables
+ * 0x2000 decryption tables
+ * 0x3000 reserved (future GCM multiplication lookup table)
+ * 0x4000 data
+ *
+ * Don't touch anything before 0x400
.
+ *
window
)
+ * @param {Object} foreign - ignored
+ * @param {ArrayBuffer} buffer - heap buffer to link with
+ */
+ var wrapper = function ( stdlib, foreign, buffer ) {
+ // Init AES stuff for the first time
+ if ( !aes_init_done ) aes_init();
+
+ // Fill up AES tables
+ var heap = new Uint32Array(buffer);
+ heap.set( aes_sbox, 0x0800>>2 );
+ heap.set( aes_sinv, 0x0c00>>2 );
+ for ( var i = 0; i < 4; i++ ) {
+ heap.set( aes_enc[i], ( 0x1000 + 0x400 * i )>>2 );
+ heap.set( aes_dec[i], ( 0x2000 + 0x400 * i )>>2 );
+ }
+
+ /**
+ * Calculate AES key schedules.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} ks - key size, 4/6/8 (for 128/192/256-bit key correspondingly)
+ * @param {int} k0..k7 - key vector components
+ */
+ function set_key ( ks, k0, k1, k2, k3, k4, k5, k6, k7 ) {
+ var ekeys = heap.subarray( 0x000, 60 ),
+ dkeys = heap.subarray( 0x100, 0x100+60 );
+
+ // Encryption key schedule
+ ekeys.set( [ k0, k1, k2, k3, k4, k5, k6, k7 ] );
+ for ( var i = ks, rcon = 1; i < 4*ks+28; i++ ) {
+ var k = ekeys[i-1];
+ if ( ( i % ks === 0 ) || ( ks === 8 && i % ks === 4 ) ) {
+ k = aes_sbox[k>>>24]<<24 ^ aes_sbox[k>>>16&255]<<16 ^ aes_sbox[k>>>8&255]<<8 ^ aes_sbox[k&255];
+ }
+ if ( i % ks === 0 ) {
+ k = (k << 8) ^ (k >>> 24) ^ (rcon << 24);
+ rcon = (rcon << 1) ^ ( (rcon & 0x80) ? 0x1b : 0 );
+ }
+ ekeys[i] = ekeys[i-ks] ^ k;
+ }
+
+ // Decryption key schedule
+ for ( var j = 0; j < i; j += 4 ) {
+ for ( var jj = 0; jj < 4; jj++ ) {
+ var k = ekeys[i-(4+j)+(4-jj)%4];
+ if ( j < 4 || j >= i-4 ) {
+ dkeys[j+jj] = k;
+ } else {
+ dkeys[j+jj] = aes_dec[0][aes_sbox[k>>>24]]
+ ^ aes_dec[1][aes_sbox[k>>>16&255]]
+ ^ aes_dec[2][aes_sbox[k>>>8&255]]
+ ^ aes_dec[3][aes_sbox[k&255]];
+ }
+ }
+ }
+
+ // Set rounds number
+ asm.set_rounds( ks + 5 );
+ }
+
+ var asm = function ( stdlib, foreign, buffer ) {
+ "use asm";
+
+ var S0 = 0, S1 = 0, S2 = 0, S3 = 0,
+ I0 = 0, I1 = 0, I2 = 0, I3 = 0,
+ N0 = 0, N1 = 0, N2 = 0, N3 = 0,
+ M0 = 0, M1 = 0, M2 = 0, M3 = 0,
+ H0 = 0, H1 = 0, H2 = 0, H3 = 0,
+ R = 0;
+
+ var HEAP = new stdlib.Uint32Array(buffer),
+ DATA = new stdlib.Uint8Array(buffer);
+
+ /**
+ * AES core
+ * @param {int} k - precomputed key schedule offset
+ * @param {int} s - precomputed sbox table offset
+ * @param {int} t - precomputed round table offset
+ * @param {int} r - number of inner rounds to perform
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _core ( k, s, t, r, x0, x1, x2, x3 ) {
+ k = k|0;
+ s = s|0;
+ t = t|0;
+ r = r|0;
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ var t1 = 0, t2 = 0, t3 = 0,
+ y0 = 0, y1 = 0, y2 = 0, y3 = 0,
+ i = 0;
+
+ t1 = t|0x400, t2 = t|0x800, t3 = t|0xc00;
+
+ // round 0
+ x0 = x0 ^ HEAP[(k|0)>>2],
+ x1 = x1 ^ HEAP[(k|4)>>2],
+ x2 = x2 ^ HEAP[(k|8)>>2],
+ x3 = x3 ^ HEAP[(k|12)>>2];
+
+ // round 1..r
+ for ( i = 16; (i|0) <= (r<<4); i = (i+16)|0 ) {
+ y0 = HEAP[(t|x0>>22&1020)>>2] ^ HEAP[(t1|x1>>14&1020)>>2] ^ HEAP[(t2|x2>>6&1020)>>2] ^ HEAP[(t3|x3<<2&1020)>>2] ^ HEAP[(k|i|0)>>2],
+ y1 = HEAP[(t|x1>>22&1020)>>2] ^ HEAP[(t1|x2>>14&1020)>>2] ^ HEAP[(t2|x3>>6&1020)>>2] ^ HEAP[(t3|x0<<2&1020)>>2] ^ HEAP[(k|i|4)>>2],
+ y2 = HEAP[(t|x2>>22&1020)>>2] ^ HEAP[(t1|x3>>14&1020)>>2] ^ HEAP[(t2|x0>>6&1020)>>2] ^ HEAP[(t3|x1<<2&1020)>>2] ^ HEAP[(k|i|8)>>2],
+ y3 = HEAP[(t|x3>>22&1020)>>2] ^ HEAP[(t1|x0>>14&1020)>>2] ^ HEAP[(t2|x1>>6&1020)>>2] ^ HEAP[(t3|x2<<2&1020)>>2] ^ HEAP[(k|i|12)>>2];
+ x0 = y0, x1 = y1, x2 = y2, x3 = y3;
+ }
+
+ // final round
+ S0 = HEAP[(s|x0>>22&1020)>>2]<<24 ^ HEAP[(s|x1>>14&1020)>>2]<<16 ^ HEAP[(s|x2>>6&1020)>>2]<<8 ^ HEAP[(s|x3<<2&1020)>>2] ^ HEAP[(k|i|0)>>2],
+ S1 = HEAP[(s|x1>>22&1020)>>2]<<24 ^ HEAP[(s|x2>>14&1020)>>2]<<16 ^ HEAP[(s|x3>>6&1020)>>2]<<8 ^ HEAP[(s|x0<<2&1020)>>2] ^ HEAP[(k|i|4)>>2],
+ S2 = HEAP[(s|x2>>22&1020)>>2]<<24 ^ HEAP[(s|x3>>14&1020)>>2]<<16 ^ HEAP[(s|x0>>6&1020)>>2]<<8 ^ HEAP[(s|x1<<2&1020)>>2] ^ HEAP[(k|i|8)>>2],
+ S3 = HEAP[(s|x3>>22&1020)>>2]<<24 ^ HEAP[(s|x0>>14&1020)>>2]<<16 ^ HEAP[(s|x1>>6&1020)>>2]<<8 ^ HEAP[(s|x2<<2&1020)>>2] ^ HEAP[(k|i|12)>>2];
+ }
+
+ /**
+ * ECB mode encryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _ecb_enc ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ _core(
+ 0x0000, 0x0800, 0x1000,
+ R,
+ x0,
+ x1,
+ x2,
+ x3
+ );
+ }
+
+ /**
+ * ECB mode decryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _ecb_dec ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ var t = 0;
+
+ _core(
+ 0x0400, 0x0c00, 0x2000,
+ R,
+ x0,
+ x3,
+ x2,
+ x1
+ );
+
+ t = S1, S1 = S3, S3 = t;
+ }
+
+
+ /**
+ * CBC mode encryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _cbc_enc ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ _core(
+ 0x0000, 0x0800, 0x1000,
+ R,
+ I0 ^ x0,
+ I1 ^ x1,
+ I2 ^ x2,
+ I3 ^ x3
+ );
+
+ I0 = S0,
+ I1 = S1,
+ I2 = S2,
+ I3 = S3;
+ }
+
+ /**
+ * CBC mode decryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _cbc_dec ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ var t = 0;
+
+ _core(
+ 0x0400, 0x0c00, 0x2000,
+ R,
+ x0,
+ x3,
+ x2,
+ x1
+ );
+
+ t = S1, S1 = S3, S3 = t;
+
+ S0 = S0 ^ I0,
+ S1 = S1 ^ I1,
+ S2 = S2 ^ I2,
+ S3 = S3 ^ I3;
+
+ I0 = x0,
+ I1 = x1,
+ I2 = x2,
+ I3 = x3;
+ }
+
+ /**
+ * CFB mode encryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _cfb_enc ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ _core(
+ 0x0000, 0x0800, 0x1000,
+ R,
+ I0,
+ I1,
+ I2,
+ I3
+ );
+
+ I0 = S0 = S0 ^ x0,
+ I1 = S1 = S1 ^ x1,
+ I2 = S2 = S2 ^ x2,
+ I3 = S3 = S3 ^ x3;
+ }
+
+
+ /**
+ * CFB mode decryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _cfb_dec ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ _core(
+ 0x0000, 0x0800, 0x1000,
+ R,
+ I0,
+ I1,
+ I2,
+ I3
+ );
+
+ S0 = S0 ^ x0,
+ S1 = S1 ^ x1,
+ S2 = S2 ^ x2,
+ S3 = S3 ^ x3;
+
+ I0 = x0,
+ I1 = x1,
+ I2 = x2,
+ I3 = x3;
+ }
+
+ /**
+ * OFB mode encryption / decryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _ofb ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ _core(
+ 0x0000, 0x0800, 0x1000,
+ R,
+ I0,
+ I1,
+ I2,
+ I3
+ );
+
+ I0 = S0,
+ I1 = S1,
+ I2 = S2,
+ I3 = S3;
+
+ S0 = S0 ^ x0,
+ S1 = S1 ^ x1,
+ S2 = S2 ^ x2,
+ S3 = S3 ^ x3;
+ }
+
+ /**
+ * CTR mode encryption / decryption
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _ctr ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ _core(
+ 0x0000, 0x0800, 0x1000,
+ R,
+ N0,
+ N1,
+ N2,
+ N3
+ );
+
+ N3 = ( ~M3 & N3 ) | M3 & ( N3 + 1 ),
+ N2 = ( ~M2 & N2 ) | M2 & ( N2 + ( (N3|0) == 0 ) ),
+ N1 = ( ~M1 & N1 ) | M1 & ( N1 + ( (N2|0) == 0 ) ),
+ N0 = ( ~M0 & N0 ) | M0 & ( N0 + ( (N1|0) == 0 ) );
+
+ S0 = S0 ^ x0,
+ S1 = S1 ^ x1,
+ S2 = S2 ^ x2,
+ S3 = S3 ^ x3;
+ }
+
+ /**
+ * GCM mode MAC calculation
+ * @param {int} x0..x3 - 128-bit input block vector
+ */
+ function _gcm_mac ( x0, x1, x2, x3 ) {
+ x0 = x0|0;
+ x1 = x1|0;
+ x2 = x2|0;
+ x3 = x3|0;
+
+ var y0 = 0, y1 = 0, y2 = 0, y3 = 0,
+ z0 = 0, z1 = 0, z2 = 0, z3 = 0,
+ i = 0, c = 0;
+
+ x0 = x0 ^ I0,
+ x1 = x1 ^ I1,
+ x2 = x2 ^ I2,
+ x3 = x3 ^ I3;
+
+ y0 = H0|0,
+ y1 = H1|0,
+ y2 = H2|0,
+ y3 = H3|0;
+
+ for ( ; (i|0) < 128; i = (i + 1)|0 ) {
+ if ( y0 >>> 31 ) {
+ z0 = z0 ^ x0,
+ z1 = z1 ^ x1,
+ z2 = z2 ^ x2,
+ z3 = z3 ^ x3;
+ }
+
+ y0 = (y0 << 1) | (y1 >>> 31),
+ y1 = (y1 << 1) | (y2 >>> 31),
+ y2 = (y2 << 1) | (y3 >>> 31),
+ y3 = (y3 << 1);
+
+ c = x3 & 1;
+
+ x3 = (x3 >>> 1) | (x2 << 31),
+ x2 = (x2 >>> 1) | (x1 << 31),
+ x1 = (x1 >>> 1) | (x0 << 31),
+ x0 = (x0 >>> 1);
+
+ if ( c ) x0 = x0 ^ 0xe1000000;
+ }
+
+ I0 = z0,
+ I1 = z1,
+ I2 = z2,
+ I3 = z3;
+ }
+
+ /**
+ * Set the internal rounds number.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} r - number if inner AES rounds
+ */
+ function set_rounds ( r ) {
+ r = r|0;
+ R = r;
+ }
+
+ /**
+ * Populate the internal state of the module.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} s0...s3 - state vector
+ */
+ function set_state ( s0, s1, s2, s3 ) {
+ s0 = s0|0;
+ s1 = s1|0;
+ s2 = s2|0;
+ s3 = s3|0;
+
+ S0 = s0,
+ S1 = s1,
+ S2 = s2,
+ S3 = s3;
+ }
+
+ /**
+ * Populate the internal iv of the module.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} i0...i3 - iv vector
+ */
+ function set_iv ( i0, i1, i2, i3 ) {
+ i0 = i0|0;
+ i1 = i1|0;
+ i2 = i2|0;
+ i3 = i3|0;
+
+ I0 = i0,
+ I1 = i1,
+ I2 = i2,
+ I3 = i3;
+ }
+
+ /**
+ * Set nonce for CTR-family modes.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} n0..n3 - nonce vector
+ */
+ function set_nonce ( n0, n1, n2, n3 ) {
+ n0 = n0|0;
+ n1 = n1|0;
+ n2 = n2|0;
+ n3 = n3|0;
+
+ N0 = n0,
+ N1 = n1,
+ N2 = n2,
+ N3 = n3;
+ }
+
+ /**
+ * Set counter mask for CTR-family modes.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} m0...m3 - counter mask vector
+ */
+ function set_mask ( m0, m1, m2, m3 ) {
+ m0 = m0|0;
+ m1 = m1|0;
+ m2 = m2|0;
+ m3 = m3|0;
+
+ M0 = m0,
+ M1 = m1,
+ M2 = m2,
+ M3 = m3;
+ }
+
+ /**
+ * Set counter for CTR-family modes.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} c0...c3 - counter vector
+ */
+ function set_counter ( c0, c1, c2, c3 ) {
+ c0 = c0|0;
+ c1 = c1|0;
+ c2 = c2|0;
+ c3 = c3|0;
+
+ N3 = ( ~M3 & N3 ) | M3 & c3,
+ N2 = ( ~M2 & N2 ) | M2 & c2,
+ N1 = ( ~M1 & N1 ) | M1 & c1,
+ N0 = ( ~M0 & N0 ) | M0 & c0;
+ }
+
+ /**
+ * Store the internal state vector into the heap.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} pos - offset where to put the data
+ * @return {int} The number of bytes have been written into the heap, always 16.
+ */
+ function get_state ( pos ) {
+ pos = pos|0;
+
+ if ( pos & 15 ) return -1;
+
+ DATA[pos|0] = S0>>>24,
+ DATA[pos|1] = S0>>>16&255,
+ DATA[pos|2] = S0>>>8&255,
+ DATA[pos|3] = S0&255,
+ DATA[pos|4] = S1>>>24,
+ DATA[pos|5] = S1>>>16&255,
+ DATA[pos|6] = S1>>>8&255,
+ DATA[pos|7] = S1&255,
+ DATA[pos|8] = S2>>>24,
+ DATA[pos|9] = S2>>>16&255,
+ DATA[pos|10] = S2>>>8&255,
+ DATA[pos|11] = S2&255,
+ DATA[pos|12] = S3>>>24,
+ DATA[pos|13] = S3>>>16&255,
+ DATA[pos|14] = S3>>>8&255,
+ DATA[pos|15] = S3&255;
+
+ return 16;
+ }
+
+ /**
+ * Store the internal iv vector into the heap.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} pos - offset where to put the data
+ * @return {int} The number of bytes have been written into the heap, always 16.
+ */
+ function get_iv ( pos ) {
+ pos = pos|0;
+
+ if ( pos & 15 ) return -1;
+
+ DATA[pos|0] = I0>>>24,
+ DATA[pos|1] = I0>>>16&255,
+ DATA[pos|2] = I0>>>8&255,
+ DATA[pos|3] = I0&255,
+ DATA[pos|4] = I1>>>24,
+ DATA[pos|5] = I1>>>16&255,
+ DATA[pos|6] = I1>>>8&255,
+ DATA[pos|7] = I1&255,
+ DATA[pos|8] = I2>>>24,
+ DATA[pos|9] = I2>>>16&255,
+ DATA[pos|10] = I2>>>8&255,
+ DATA[pos|11] = I2&255,
+ DATA[pos|12] = I3>>>24,
+ DATA[pos|13] = I3>>>16&255,
+ DATA[pos|14] = I3>>>8&255,
+ DATA[pos|15] = I3&255;
+
+ return 16;
+ }
+
+ /**
+ * GCM initialization.
+ * @instance
+ * @memberof AES_asm
+ */
+ function gcm_init ( ) {
+ _ecb_enc( 0, 0, 0, 0 );
+ H0 = S0,
+ H1 = S1,
+ H2 = S2,
+ H3 = S3;
+ }
+
+ /**
+ * Perform ciphering operation on the supplied data.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} mode - block cipher mode (see {@link AES_asm} mode constants)
+ * @param {int} pos - offset of the data being processed
+ * @param {int} len - length of the data being processed
+ * @return {int} Actual amount of data have been processed.
+ */
+ function cipher ( mode, pos, len ) {
+ mode = mode|0;
+ pos = pos|0;
+ len = len|0;
+
+ var ret = 0;
+
+ if ( pos & 15 ) return -1;
+
+ while ( (len|0) >= 16 ) {
+ _cipher_modes[mode&7](
+ DATA[pos|0]<<24 | DATA[pos|1]<<16 | DATA[pos|2]<<8 | DATA[pos|3],
+ DATA[pos|4]<<24 | DATA[pos|5]<<16 | DATA[pos|6]<<8 | DATA[pos|7],
+ DATA[pos|8]<<24 | DATA[pos|9]<<16 | DATA[pos|10]<<8 | DATA[pos|11],
+ DATA[pos|12]<<24 | DATA[pos|13]<<16 | DATA[pos|14]<<8 | DATA[pos|15]
+ );
+
+ DATA[pos|0] = S0>>>24,
+ DATA[pos|1] = S0>>>16&255,
+ DATA[pos|2] = S0>>>8&255,
+ DATA[pos|3] = S0&255,
+ DATA[pos|4] = S1>>>24,
+ DATA[pos|5] = S1>>>16&255,
+ DATA[pos|6] = S1>>>8&255,
+ DATA[pos|7] = S1&255,
+ DATA[pos|8] = S2>>>24,
+ DATA[pos|9] = S2>>>16&255,
+ DATA[pos|10] = S2>>>8&255,
+ DATA[pos|11] = S2&255,
+ DATA[pos|12] = S3>>>24,
+ DATA[pos|13] = S3>>>16&255,
+ DATA[pos|14] = S3>>>8&255,
+ DATA[pos|15] = S3&255;
+
+ ret = (ret + 16)|0,
+ pos = (pos + 16)|0,
+ len = (len - 16)|0;
+ }
+
+ return ret|0;
+ }
+
+ /**
+ * Calculates MAC of the supplied data.
+ * @instance
+ * @memberof AES_asm
+ * @param {int} mode - block cipher mode (see {@link AES_asm} mode constants)
+ * @param {int} pos - offset of the data being processed
+ * @param {int} len - length of the data being processed
+ * @return {int} Actual amount of data have been processed.
+ */
+ function mac ( mode, pos, len ) {
+ mode = mode|0;
+ pos = pos|0;
+ len = len|0;
+
+ var ret = 0;
+
+ if ( pos & 15 ) return -1;
+
+ while ( (len|0) >= 16 ) {
+ _mac_modes[mode&1](
+ DATA[pos|0]<<24 | DATA[pos|1]<<16 | DATA[pos|2]<<8 | DATA[pos|3],
+ DATA[pos|4]<<24 | DATA[pos|5]<<16 | DATA[pos|6]<<8 | DATA[pos|7],
+ DATA[pos|8]<<24 | DATA[pos|9]<<16 | DATA[pos|10]<<8 | DATA[pos|11],
+ DATA[pos|12]<<24 | DATA[pos|13]<<16 | DATA[pos|14]<<8 | DATA[pos|15]
+ );
+
+ ret = (ret + 16)|0,
+ pos = (pos + 16)|0,
+ len = (len - 16)|0;
+ }
+
+ return ret|0;
+ }
+
+ /**
+ * AES cipher modes table (virual methods)
+ */
+ var _cipher_modes = [ _ecb_enc, _ecb_dec, _cbc_enc, _cbc_dec, _cfb_enc, _cfb_dec, _ofb, _ctr ];
+
+ /**
+ * AES MAC modes table (virual methods)
+ */
+ var _mac_modes = [ _cbc_enc, _gcm_mac ];
+
+ /**
+ * Asm.js module exports
+ */
+ return {
+ set_rounds: set_rounds,
+ set_state: set_state,
+ set_iv: set_iv,
+ set_nonce: set_nonce,
+ set_mask: set_mask,
+ set_counter:set_counter,
+ get_state: get_state,
+ get_iv: get_iv,
+ gcm_init: gcm_init,
+ cipher: cipher,
+ mac: mac
+ };
+ }( stdlib, foreign, buffer );
+
+ asm.set_key = set_key;
+
+ return asm;
+ };
+
+ /**
+ * AES enciphering mode constants
+ * @enum {int}
+ * @const
+ */
+ wrapper.ENC = {
+ ECB: 0,
+ CBC: 2,
+ CFB: 4,
+ OFB: 6,
+ CTR: 7
+ },
+
+ /**
+ * AES deciphering mode constants
+ * @enum {int}
+ * @const
+ */
+ wrapper.DEC = {
+ ECB: 1,
+ CBC: 3,
+ CFB: 5,
+ OFB: 6,
+ CTR: 7
+ },
+
+ /**
+ * AES MAC mode constants
+ * @enum {int}
+ * @const
+ */
+ wrapper.MAC = {
+ CBC: 0,
+ GCM: 1
+ };
+
+ /**
+ * Heap data offset
+ * @type {int}
+ * @const
+ */
+ wrapper.HEAP_DATA = 0x4000;
+
+ return wrapper;
+}();
+
+function AES ( options ) {
+ options = options || {};
+
+ this.heap = _heap_init( Uint8Array, options ).subarray( AES_asm.HEAP_DATA );
+ this.asm = options.asm || AES_asm( global, null, this.heap.buffer );
+ this.mode = null;
+ this.key = null;
+
+ this.reset( options );
+}
+
+function AES_set_key ( key ) {
+ if ( key !== undefined ) {
+ if ( is_buffer(key) || is_bytes(key) ) {
+ key = new Uint8Array(key);
+ }
+ else if ( is_string(key) ) {
+ key = string_to_bytes(key);
+ }
+ else {
+ throw new TypeError("unexpected key type");
+ }
+
+ var keylen = key.length;
+ if ( keylen !== 16 && keylen !== 24 && keylen !== 32 )
+ throw new IllegalArgumentError("illegal key size");
+
+ var keyview = new DataView( key.buffer, key.byteOffset, key.byteLength );
+ this.asm.set_key(
+ keylen >> 2,
+ keyview.getUint32(0),
+ keyview.getUint32(4),
+ keyview.getUint32(8),
+ keyview.getUint32(12),
+ keylen > 16 ? keyview.getUint32(16) : 0,
+ keylen > 16 ? keyview.getUint32(20) : 0,
+ keylen > 24 ? keyview.getUint32(24) : 0,
+ keylen > 24 ? keyview.getUint32(28) : 0
+ );
+
+ this.key = key;
+ }
+ else if ( !this.key ) {
+ throw new Error("key is required");
+ }
+}
+
+function AES_set_iv ( iv ) {
+ if ( iv !== undefined ) {
+ if ( is_buffer(iv) || is_bytes(iv) ) {
+ iv = new Uint8Array(iv);
+ }
+ else if ( is_string(iv) ) {
+ iv = string_to_bytes(iv);
+ }
+ else {
+ throw new TypeError("unexpected iv type");
+ }
+
+ if ( iv.length !== 16 )
+ throw new IllegalArgumentError("illegal iv size");
+
+ var ivview = new DataView( iv.buffer, iv.byteOffset, iv.byteLength );
+
+ this.iv = iv;
+ this.asm.set_iv( ivview.getUint32(0), ivview.getUint32(4), ivview.getUint32(8), ivview.getUint32(12) );
+ }
+ else {
+ this.iv = null;
+ this.asm.set_iv( 0, 0, 0, 0 );
+ }
+}
+
+function AES_set_padding ( padding ) {
+ if ( padding !== undefined ) {
+ this.padding = !!padding;
+ }
+ else {
+ this.padding = true;
+ }
+}
+
+function AES_reset ( options ) {
+ options = options || {};
+
+ this.result = null;
+ this.pos = 0;
+ this.len = 0;
+
+ AES_set_key.call( this, options.key );
+ if ( this.hasOwnProperty('iv') ) AES_set_iv.call( this, options.iv );
+ if ( this.hasOwnProperty('padding') ) AES_set_padding.call( this, options.padding );
+
+ return this;
+}
+
+function AES_Encrypt_process ( data ) {
+ if ( is_string(data) )
+ data = string_to_bytes(data);
+
+ if ( is_buffer(data) )
+ data = new Uint8Array(data);
+
+ if ( !is_bytes(data) )
+ throw new TypeError("data isn't of expected type");
+
+ var asm = this.asm,
+ heap = this.heap,
+ amode = AES_asm.ENC[this.mode],
+ hpos = AES_asm.HEAP_DATA,
+ pos = this.pos,
+ len = this.len,
+ dpos = 0,
+ dlen = data.length || 0,
+ rpos = 0,
+ rlen = (len + dlen) & -16,
+ wlen = 0;
+
+ var result = new Uint8Array(rlen);
+
+ while ( dlen > 0 ) {
+ wlen = _heap_write( heap, pos+len, data, dpos, dlen );
+ len += wlen;
+ dpos += wlen;
+ dlen -= wlen;
+
+ wlen = asm.cipher( amode, hpos + pos, len );
+
+ if ( wlen ) result.set( heap.subarray( pos, pos + wlen ), rpos );
+ rpos += wlen;
+
+ if ( wlen < len ) {
+ pos += wlen;
+ len -= wlen;
+ } else {
+ pos = 0;
+ len = 0;
+ }
+ }
+
+ this.result = result;
+ this.pos = pos;
+ this.len = len;
+
+ return this;
+}
+
+function AES_Encrypt_finish ( data ) {
+ var presult = null,
+ prlen = 0;
+
+ if ( data !== undefined ) {
+ presult = AES_Encrypt_process.call( this, data ).result;
+ prlen = presult.length;
+ }
+
+ var asm = this.asm,
+ heap = this.heap,
+ amode = AES_asm.ENC[this.mode],
+ hpos = AES_asm.HEAP_DATA,
+ pos = this.pos,
+ len = this.len,
+ plen = 16 - len % 16,
+ rlen = len;
+
+ if ( this.hasOwnProperty('padding') ) {
+ if ( this.padding ) {
+ for ( var p = 0; p < plen; ++p ) heap[ pos + len + p ] = plen;
+ len += plen;
+ rlen = len;
+ }
+ else if ( len % 16 ) {
+ throw new IllegalArgumentError("data length must be a multiple of the block size");
+ }
+ }
+ else {
+ len += plen;
+ }
+
+ var result = new Uint8Array( prlen + rlen );
+
+ if ( prlen ) result.set( presult );
+
+ if ( len ) asm.cipher( amode, hpos + pos, len );
+
+ if ( rlen ) result.set( heap.subarray( pos, pos + rlen ), prlen );
+
+ this.result = result;
+ this.pos = 0;
+ this.len = 0;
+
+ return this;
+}
+
+function AES_Decrypt_process ( data ) {
+ if ( is_string(data) )
+ data = string_to_bytes(data);
+
+ if ( is_buffer(data) )
+ data = new Uint8Array(data);
+
+ if ( !is_bytes(data) )
+ throw new TypeError("data isn't of expected type");
+
+ var asm = this.asm,
+ heap = this.heap,
+ amode = AES_asm.DEC[this.mode],
+ hpos = AES_asm.HEAP_DATA,
+ pos = this.pos,
+ len = this.len,
+ dpos = 0,
+ dlen = data.length || 0,
+ rpos = 0,
+ rlen = (len + dlen) & -16,
+ plen = 0,
+ wlen = 0;
+
+ if ( this.hasOwnProperty('padding') && this.padding ) {
+ plen = len + dlen - rlen || 16;
+ rlen -= plen;
+ }
+
+ var result = new Uint8Array(rlen);
+
+ while ( dlen > 0 ) {
+ wlen = _heap_write( heap, pos+len, data, dpos, dlen );
+ len += wlen;
+ dpos += wlen;
+ dlen -= wlen;
+
+ wlen = asm.cipher( amode, hpos + pos, len - ( !dlen ? plen : 0 ) );
+
+ if ( wlen ) result.set( heap.subarray( pos, pos + wlen ), rpos );
+ rpos += wlen;
+
+ if ( wlen < len ) {
+ pos += wlen;
+ len -= wlen;
+ } else {
+ pos = 0;
+ len = 0;
+ }
+ }
+
+ this.result = result;
+ this.pos = pos;
+ this.len = len;
+
+ return this;
+}
+
+function AES_Decrypt_finish ( data ) {
+ var presult = null,
+ prlen = 0;
+
+ if ( data !== undefined ) {
+ presult = AES_Decrypt_process.call( this, data ).result;
+ prlen = presult.length;
+ }
+
+ var asm = this.asm,
+ heap = this.heap,
+ amode = AES_asm.DEC[this.mode],
+ hpos = AES_asm.HEAP_DATA,
+ pos = this.pos,
+ len = this.len,
+ rlen = len;
+
+ if ( len > 0 ) {
+ if ( len % 16 ) {
+ if ( this.hasOwnProperty('padding') ) {
+ throw new IllegalArgumentError("data length must be a multiple of the block size");
+ } else {
+ len += 16 - len % 16;
+ }
+ }
+
+ asm.cipher( amode, hpos + pos, len );
+
+ if ( this.hasOwnProperty('padding') && this.padding ) {
+ var pad = heap[ pos + rlen - 1 ];
+ if ( pad < 1 || pad > 16 || pad > rlen )
+ throw new SecurityError("bad padding");
+
+ var pcheck = 0;
+ for ( var i = pad; i > 1; i-- ) pcheck |= pad ^ heap[ pos + rlen - i ];
+ if ( pcheck )
+ throw new SecurityError("bad padding");
+
+ rlen -= pad;
+ }
+ }
+
+ var result = new Uint8Array( prlen + rlen );
+
+ if ( prlen > 0 ) {
+ result.set( presult );
+ }
+
+ if ( rlen > 0 ) {
+ result.set( heap.subarray( pos, pos + rlen ), prlen );
+ }
+
+ this.result = result;
+ this.pos = 0;
+ this.len = 0;
+
+ return this;
+}
+
+/**
+ * Cipher Feedback Mode (CFB)
+ */
+
+function AES_CFB ( options ) {
+ this.iv = null;
+
+ AES.call( this, options );
+
+ this.mode = 'CFB';
+}
+
+var AES_CFB_prototype = AES_CFB.prototype;
+AES_CFB_prototype.BLOCK_SIZE = 16;
+AES_CFB_prototype.reset = AES_reset;
+AES_CFB_prototype.encrypt = AES_Encrypt_finish;
+AES_CFB_prototype.decrypt = AES_Decrypt_finish;
+
+function AES_CFB_Encrypt ( options ) {
+ AES_CFB.call( this, options );
+}
+
+var AES_CFB_Encrypt_prototype = AES_CFB_Encrypt.prototype;
+AES_CFB_Encrypt_prototype.BLOCK_SIZE = 16;
+AES_CFB_Encrypt_prototype.reset = AES_reset;
+AES_CFB_Encrypt_prototype.process = AES_Encrypt_process;
+AES_CFB_Encrypt_prototype.finish = AES_Encrypt_finish;
+
+function AES_CFB_Decrypt ( options ) {
+ AES_CFB.call( this, options );
+}
+
+var AES_CFB_Decrypt_prototype = AES_CFB_Decrypt.prototype;
+AES_CFB_Decrypt_prototype.BLOCK_SIZE = 16;
+AES_CFB_Decrypt_prototype.reset = AES_reset;
+AES_CFB_Decrypt_prototype.process = AES_Decrypt_process;
+AES_CFB_Decrypt_prototype.finish = AES_Decrypt_finish;
+
+/**
+ * Counter Mode (CTR)
+ */
+
+function AES_CTR ( options ) {
+ this.nonce = null,
+ this.counter = 0,
+ this.counterSize = 0;
+
+ AES.call( this, options );
+
+ this.mode = 'CTR';
+}
+
+function AES_CTR_Crypt ( options ) {
+ AES_CTR.call( this, options );
+}
+
+function AES_CTR_set_options ( nonce, counter, size ) {
+ if ( size !== undefined ) {
+ if ( size < 8 || size > 48 )
+ throw new IllegalArgumentError("illegal counter size");
+
+ this.counterSize = size;
+
+ var mask = Math.pow( 2, size ) - 1;
+ this.asm.set_mask( 0, 0, (mask / 0x100000000)|0, mask|0 );
+ }
+ else {
+ this.counterSize = size = 48;
+ this.asm.set_mask( 0, 0, 0xffff, 0xffffffff );
+ }
+
+ if ( nonce !== undefined ) {
+ if ( is_buffer(nonce) || is_bytes(nonce) ) {
+ nonce = new Uint8Array(nonce);
+ }
+ else if ( is_string(nonce) ) {
+ nonce = string_to_bytes(nonce);
+ }
+ else {
+ throw new TypeError("unexpected nonce type");
+ }
+
+ var len = nonce.length;
+ if ( !len || len > 16 )
+ throw new IllegalArgumentError("illegal nonce size");
+
+ this.nonce = nonce;
+
+ var view = new DataView( new ArrayBuffer(16) );
+ new Uint8Array(view.buffer).set(nonce);
+
+ this.asm.set_nonce( view.getUint32(0), view.getUint32(4), view.getUint32(8), view.getUint32(12) );
+ }
+ else {
+ throw new Error("nonce is required");
+ }
+
+ if ( counter !== undefined ) {
+ if ( !is_number(counter) )
+ throw new TypeError("unexpected counter type");
+
+ if ( counter < 0 || counter >= Math.pow( 2, size ) )
+ throw new IllegalArgumentError("illegal counter value");
+
+ this.counter = counter;
+
+ this.asm.set_counter( 0, 0, (counter / 0x100000000)|0, counter|0 );
+ }
+ else {
+ this.counter = counter = 0;
+ }
+}
+
+function AES_CTR_reset ( options ) {
+ options = options || {};
+
+ AES_reset.call( this, options );
+
+ AES_CTR_set_options.call( this, options.nonce, options.counter, options.counterSize );
+
+ return this;
+}
+
+var AES_CTR_prototype = AES_CTR.prototype;
+AES_CTR_prototype.BLOCK_SIZE = 16;
+AES_CTR_prototype.reset = AES_CTR_reset;
+AES_CTR_prototype.encrypt = AES_Encrypt_finish;
+AES_CTR_prototype.decrypt = AES_Encrypt_finish;
+
+var AES_CTR_Crypt_prototype = AES_CTR_Crypt.prototype;
+AES_CTR_Crypt_prototype.BLOCK_SIZE = 16;
+AES_CTR_Crypt_prototype.reset = AES_CTR_reset;
+AES_CTR_Crypt_prototype.process = AES_Encrypt_process;
+AES_CTR_Crypt_prototype.finish = AES_Encrypt_finish;
+
+/**
+ * Galois/Counter mode
+ */
+
+var _AES_GCM_data_maxLength = 68719476704; // 2^36 - 2^5
+
+function _gcm_mac_process ( data ) {
+ var heap = this.heap,
+ asm = this.asm,
+ dpos = 0,
+ dlen = data.length || 0,
+ wlen = 0;
+
+ while ( dlen > 0 ) {
+ wlen = _heap_write( heap, 0, data, dpos, dlen );
+ dpos += wlen;
+ dlen -= wlen;
+
+ while ( wlen & 15 ) heap[ wlen++ ] = 0;
+
+ asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, wlen );
+ }
+}
+
+function AES_GCM ( options ) {
+ this.nonce = null;
+ this.adata = null;
+ this.iv = null;
+ this.counter = 1;
+ this.tagSize = 16;
+
+ AES.call( this, options );
+
+ this.mode = 'GCM';
+}
+
+function AES_GCM_Encrypt ( options ) {
+ AES_GCM.call( this, options );
+}
+
+function AES_GCM_Decrypt ( options ) {
+ AES_GCM.call( this, options );
+}
+
+function AES_GCM_reset ( options ) {
+ options = options || {};
+
+ AES_reset.call( this, options );
+
+ var asm = this.asm,
+ heap = this.heap;
+
+ asm.gcm_init();
+
+ var tagSize = options.tagSize;
+ if ( tagSize !== undefined ) {
+ if ( !is_number(tagSize) )
+ throw new TypeError("tagSize must be a number");
+
+ if ( tagSize < 4 || tagSize > 16 )
+ throw new IllegalArgumentError("illegal tagSize value");
+
+ this.tagSize = tagSize;
+ }
+ else {
+ this.tagSize = 16;
+ }
+
+ var nonce = options.nonce;
+ if ( nonce !== undefined ) {
+ if ( is_bytes(nonce) || is_buffer(nonce) ) {
+ nonce = new Uint8Array(nonce);
+ }
+ else if ( is_string(nonce) ) {
+ nonce = string_to_bytes(nonce);
+ }
+ else {
+ throw new TypeError("unexpected nonce type");
+ }
+
+ this.nonce = nonce;
+
+ var noncelen = nonce.length || 0,
+ noncebuf = new Uint8Array(16);
+ if ( noncelen !== 12 ) {
+ _gcm_mac_process.call( this, nonce );
+
+ heap[0] = heap[1] = heap[2] = heap[3] = heap[4] = heap[5] = heap[6] = heap[7] = heap[8] = heap[9] = heap[10] = 0,
+ heap[11] = noncelen>>>29,
+ heap[12] = noncelen>>>21&255,
+ heap[13] = noncelen>>>13&255,
+ heap[14] = noncelen>>>5&255,
+ heap[15] = noncelen<<3&255;
+ asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, 16 );
+
+ asm.get_iv( AES_asm.HEAP_DATA );
+ asm.set_iv();
+
+ noncebuf.set( heap.subarray( 0, 16 ) );
+ }
+ else {
+ noncebuf.set(nonce);
+ noncebuf[15] = 1;
+ }
+
+ var nonceview = new DataView( noncebuf.buffer );
+ this.gamma0 = nonceview.getUint32(12);
+
+ asm.set_nonce( nonceview.getUint32(0), nonceview.getUint32(4), nonceview.getUint32(8), 0 );
+ asm.set_mask( 0, 0, 0, 0xffffffff );
+ }
+ else {
+ throw new Error("nonce is required");
+ }
+
+ var adata = options.adata;
+ if ( adata !== undefined && adata !== null ) {
+ if ( is_bytes(adata) || is_buffer(adata) ) {
+ adata = new Uint8Array(adata);
+ }
+ else if ( is_string(adata) ) {
+ adata = string_to_bytes(adata);
+ }
+ else {
+ throw new TypeError("unexpected adata type");
+ }
+
+ if ( adata.length > _AES_GCM_data_maxLength )
+ throw new IllegalArgumentError("illegal adata length");
+
+ if ( adata.length ) {
+ this.adata = adata;
+ _gcm_mac_process.call( this, adata );
+ }
+ else {
+ this.adata = null;
+ }
+ }
+ else {
+ this.adata = null;
+ }
+
+ var counter = options.counter;
+ if ( counter !== undefined ) {
+ if ( !is_number(counter) )
+ throw new TypeError("counter must be a number");
+
+ if ( counter < 1 || counter > 0xffffffff )
+ throw new RangeError("counter must be a positive 32-bit integer");
+
+ this.counter = counter;
+ asm.set_counter( 0, 0, 0, this.gamma0+counter|0 );
+ }
+ else {
+ this.counter = 1;
+ asm.set_counter( 0, 0, 0, this.gamma0+1|0 );
+ }
+
+ var iv = options.iv;
+ if ( iv !== undefined ) {
+ if ( !is_number(counter) )
+ throw new TypeError("counter must be a number");
+
+ this.iv = iv;
+
+ AES_set_iv.call( this, iv );
+ }
+
+ return this;
+}
+
+function AES_GCM_Encrypt_process ( data ) {
+ if ( is_string(data) )
+ data = string_to_bytes(data);
+
+ if ( is_buffer(data) )
+ data = new Uint8Array(data);
+
+ if ( !is_bytes(data) )
+ throw new TypeError("data isn't of expected type");
+
+ var dpos = 0,
+ dlen = data.length || 0,
+ asm = this.asm,
+ heap = this.heap,
+ counter = this.counter,
+ pos = this.pos,
+ len = this.len,
+ rpos = 0,
+ rlen = ( len + dlen ) & -16,
+ wlen = 0;
+
+ if ( ((counter-1)<<4) + len + dlen > _AES_GCM_data_maxLength )
+ throw new RangeError("counter overflow");
+
+ var result = new Uint8Array(rlen);
+
+ while ( dlen > 0 ) {
+ wlen = _heap_write( heap, pos+len, data, dpos, dlen );
+ len += wlen;
+ dpos += wlen;
+ dlen -= wlen;
+
+ wlen = asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA + pos, len );
+ wlen = asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, wlen );
+
+ if ( wlen ) result.set( heap.subarray( pos, pos + wlen ), rpos );
+ counter += (wlen>>>4);
+ rpos += wlen;
+
+ if ( wlen < len ) {
+ pos += wlen;
+ len -= wlen;
+ } else {
+ pos = 0;
+ len = 0;
+ }
+ }
+
+ this.result = result;
+ this.counter = counter;
+ this.pos = pos;
+ this.len = len;
+
+ return this;
+}
+
+function AES_GCM_Encrypt_finish () {
+ var asm = this.asm,
+ heap = this.heap,
+ counter = this.counter,
+ tagSize = this.tagSize,
+ adata = this.adata,
+ pos = this.pos,
+ len = this.len;
+
+ var result = new Uint8Array( len + tagSize );
+
+ asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA + pos, (len + 15) & -16 );
+ if ( len ) result.set( heap.subarray( pos, pos + len ) );
+
+ for ( var i = len; i & 15; i++ ) heap[ pos + i ] = 0;
+ asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, i );
+
+ var alen = ( adata !== null ) ? adata.length : 0,
+ clen = ( (counter-1) << 4) + len;
+ heap[0] = heap[1] = heap[2] = 0,
+ heap[3] = alen>>>29,
+ heap[4] = alen>>>21,
+ heap[5] = alen>>>13&255,
+ heap[6] = alen>>>5&255,
+ heap[7] = alen<<3&255,
+ heap[8] = heap[9] = heap[10] = 0,
+ heap[11] = clen>>>29,
+ heap[12] = clen>>>21&255,
+ heap[13] = clen>>>13&255,
+ heap[14] = clen>>>5&255,
+ heap[15] = clen<<3&255;
+ asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, 16 );
+ asm.get_iv( AES_asm.HEAP_DATA );
+
+ asm.set_counter( 0, 0, 0, this.gamma0 );
+ asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA, 16 );
+ result.set( heap.subarray( 0, tagSize ), len );
+
+ this.result = result;
+ this.counter = 1;
+ this.pos = 0;
+ this.len = 0;
+
+ return this;
+}
+
+function AES_GCM_encrypt ( data ) {
+ var result1 = AES_GCM_Encrypt_process.call( this, data ).result,
+ result2 = AES_GCM_Encrypt_finish.call(this).result;
+
+ var result = new Uint8Array( result1.length + result2.length );
+ if ( result1.length ) result.set( result1 );
+ if ( result2.length ) result.set( result2, result1.length );
+ this.result = result;
+
+ return this;
+}
+
+function AES_GCM_Decrypt_process ( data ) {
+ if ( is_string(data) )
+ data = string_to_bytes(data);
+
+ if ( is_buffer(data) )
+ data = new Uint8Array(data);
+
+ if ( !is_bytes(data) )
+ throw new TypeError("data isn't of expected type");
+
+ var dpos = 0,
+ dlen = data.length || 0,
+ asm = this.asm,
+ heap = this.heap,
+ counter = this.counter,
+ tagSize = this.tagSize,
+ pos = this.pos,
+ len = this.len,
+ rpos = 0,
+ rlen = len + dlen > tagSize ? ( len + dlen - tagSize ) & -16 : 0,
+ tlen = len + dlen - rlen,
+ wlen = 0;
+
+ if ( ((counter-1)<<4) + len + dlen > _AES_GCM_data_maxLength )
+ throw new RangeError("counter overflow");
+
+ var result = new Uint8Array(rlen);
+
+ while ( dlen > tlen ) {
+ wlen = _heap_write( heap, pos+len, data, dpos, dlen-tlen );
+ len += wlen;
+ dpos += wlen;
+ dlen -= wlen;
+
+ wlen = asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, wlen );
+ wlen = asm.cipher( AES_asm.DEC.CTR, AES_asm.HEAP_DATA + pos, wlen );
+
+ if ( wlen ) result.set( heap.subarray( pos, pos+wlen ), rpos );
+ counter += (wlen>>>4);
+ rpos += wlen;
+
+ pos = 0;
+ len = 0;
+ }
+
+ if ( dlen > 0 ) {
+ len += _heap_write( heap, 0, data, dpos, dlen );
+ }
+
+ this.result = result;
+ this.counter = counter;
+ this.pos = pos;
+ this.len = len;
+
+ return this;
+}
+
+function AES_GCM_Decrypt_finish () {
+ var asm = this.asm,
+ heap = this.heap,
+ tagSize = this.tagSize,
+ adata = this.adata,
+ counter = this.counter,
+ pos = this.pos,
+ len = this.len,
+ rlen = len - tagSize,
+ wlen = 0;
+
+ if ( len < tagSize )
+ throw new IllegalStateError("authentication tag not found");
+
+ var result = new Uint8Array(rlen),
+ atag = new Uint8Array( heap.subarray( pos+rlen, pos+len ) );
+
+ for ( var i = rlen; i & 15; i++ ) heap[ pos + i ] = 0;
+
+ wlen = asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, i );
+ wlen = asm.cipher( AES_asm.DEC.CTR, AES_asm.HEAP_DATA + pos, i );
+ if ( rlen ) result.set( heap.subarray( pos, pos+rlen ) );
+
+ var alen = ( adata !== null ) ? adata.length : 0,
+ clen = ( (counter-1) << 4) + len - tagSize;
+ heap[0] = heap[1] = heap[2] = 0,
+ heap[3] = alen>>>29,
+ heap[4] = alen>>>21,
+ heap[5] = alen>>>13&255,
+ heap[6] = alen>>>5&255,
+ heap[7] = alen<<3&255,
+ heap[8] = heap[9] = heap[10] = 0,
+ heap[11] = clen>>>29,
+ heap[12] = clen>>>21&255,
+ heap[13] = clen>>>13&255,
+ heap[14] = clen>>>5&255,
+ heap[15] = clen<<3&255;
+ asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, 16 );
+ asm.get_iv( AES_asm.HEAP_DATA );
+
+ asm.set_counter( 0, 0, 0, this.gamma0 );
+ asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA, 16 );
+
+ var acheck = 0;
+ for ( var i = 0; i < tagSize; ++i ) acheck |= atag[i] ^ heap[i];
+ if ( acheck )
+ throw new SecurityError("data integrity check failed");
+
+ this.result = result;
+ this.counter = 1;
+ this.pos = 0;
+ this.len = 0;
+
+ return this;
+}
+
+function AES_GCM_decrypt ( data ) {
+ var result1 = AES_GCM_Decrypt_process.call( this, data ).result,
+ result2 = AES_GCM_Decrypt_finish.call( this ).result;
+
+ var result = new Uint8Array( result1.length + result2.length );
+ if ( result1.length ) result.set( result1 );
+ if ( result2.length ) result.set( result2, result1.length );
+ this.result = result;
+
+ return this;
+}
+
+var AES_GCM_prototype = AES_GCM.prototype;
+AES_GCM_prototype.BLOCK_SIZE = 16;
+AES_GCM_prototype.reset = AES_GCM_reset;
+AES_GCM_prototype.encrypt = AES_GCM_encrypt;
+AES_GCM_prototype.decrypt = AES_GCM_decrypt;
+
+var AES_GCM_Encrypt_prototype = AES_GCM_Encrypt.prototype;
+AES_GCM_Encrypt_prototype.BLOCK_SIZE = 16;
+AES_GCM_Encrypt_prototype.reset = AES_GCM_reset;
+AES_GCM_Encrypt_prototype.process = AES_GCM_Encrypt_process;
+AES_GCM_Encrypt_prototype.finish = AES_GCM_Encrypt_finish;
+
+var AES_GCM_Decrypt_prototype = AES_GCM_Decrypt.prototype;
+AES_GCM_Decrypt_prototype.BLOCK_SIZE = 16;
+AES_GCM_Decrypt_prototype.reset = AES_GCM_reset;
+AES_GCM_Decrypt_prototype.process = AES_GCM_Decrypt_process;
+AES_GCM_Decrypt_prototype.finish = AES_GCM_Decrypt_finish;
+
+// shared asm.js module and heap
+var _AES_heap_instance = new Uint8Array(0x100000),
+ _AES_asm_instance = AES_asm( global, null, _AES_heap_instance.buffer );
+
+/**
+ * AES-CFB exports
+ */
+
+function AES_CFB_encrypt_bytes ( data, key, iv ) {
+ if ( data === undefined ) throw new SyntaxError("data required");
+ if ( key === undefined ) throw new SyntaxError("key required");
+ return new AES_CFB( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, iv: iv } ).encrypt(data).result;
+}
+
+function AES_CFB_decrypt_bytes ( data, key, iv ) {
+ if ( data === undefined ) throw new SyntaxError("data required");
+ if ( key === undefined ) throw new SyntaxError("key required");
+ return new AES_CFB( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, iv: iv } ).decrypt(data).result;
+}
+
+exports.AES_CFB = AES_CFB;
+exports.AES_CFB.encrypt = AES_CFB_encrypt_bytes;
+exports.AES_CFB.decrypt = AES_CFB_decrypt_bytes;
+
+exports.AES_CFB.Encrypt = AES_CFB_Encrypt;
+exports.AES_CFB.Decrypt = AES_CFB_Decrypt;
+
+/**
+ * AES-GCM exports
+ */
+
+function AES_GCM_encrypt_bytes ( data, key, nonce, adata, tagSize ) {
+ if ( data === undefined ) throw new SyntaxError("data required");
+ if ( key === undefined ) throw new SyntaxError("key required");
+ if ( nonce === undefined ) throw new SyntaxError("nonce required");
+ return new AES_GCM( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, nonce: nonce, adata: adata, tagSize: tagSize } ).encrypt(data).result;
+}
+
+function AES_GCM_decrypt_bytes ( data, key, nonce, adata, tagSize ) {
+ if ( data === undefined ) throw new SyntaxError("data required");
+ if ( key === undefined ) throw new SyntaxError("key required");
+ if ( nonce === undefined ) throw new SyntaxError("nonce required");
+ return new AES_GCM( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, nonce: nonce, adata: adata, tagSize: tagSize } ).decrypt(data).result;
+}
+
+exports.AES_GCM = AES_GCM;
+exports.AES_GCM.encrypt = AES_GCM_encrypt_bytes;
+exports.AES_GCM.decrypt = AES_GCM_decrypt_bytes;
+
+exports.AES_GCM.Encrypt = AES_GCM_Encrypt;
+exports.AES_GCM.Decrypt = AES_GCM_Decrypt;
+
+function hash_reset () {
+ this.result = null;
+ this.pos = 0;
+ this.len = 0;
+
+ this.asm.reset();
+
+ return this;
+}
+
+function hash_process ( data ) {
+ if ( this.result !== null )
+ throw new IllegalStateError("state must be reset before processing new data");
+
+ if ( is_string(data) )
+ data = string_to_bytes(data);
+
+ if ( is_buffer(data) )
+ data = new Uint8Array(data);
+
+ if ( !is_bytes(data) )
+ throw new TypeError("data isn't of expected type");
+
+ var asm = this.asm,
+ heap = this.heap,
+ hpos = this.pos,
+ hlen = this.len,
+ dpos = 0,
+ dlen = data.length,
+ wlen = 0;
+
+ while ( dlen > 0 ) {
+ wlen = _heap_write( heap, hpos+hlen, data, dpos, dlen );
+ hlen += wlen;
+ dpos += wlen;
+ dlen -= wlen;
+
+ wlen = asm.process( hpos, hlen );
+
+ hpos += wlen;
+ hlen -= wlen;
+
+ if ( !hlen ) hpos = 0;
+ }
+
+ this.pos = hpos;
+ this.len = hlen;
+
+ return this;
+}
+
+function hash_finish () {
+ if ( this.result !== null )
+ throw new IllegalStateError("state must be reset before processing new data");
+
+ this.asm.finish( this.pos, this.len, 0 );
+
+ this.result = new Uint8Array(this.HASH_SIZE);
+ this.result.set( this.heap.subarray( 0, this.HASH_SIZE ) );
+
+ this.pos = 0;
+ this.len = 0;
+
+ return this;
+}
+
+function sha256_asm ( stdlib, foreign, buffer ) {
+ "use asm";
+
+ // SHA256 state
+ var H0 = 0, H1 = 0, H2 = 0, H3 = 0, H4 = 0, H5 = 0, H6 = 0, H7 = 0,
+ TOTAL0 = 0, TOTAL1 = 0;
+
+ // HMAC state
+ var I0 = 0, I1 = 0, I2 = 0, I3 = 0, I4 = 0, I5 = 0, I6 = 0, I7 = 0,
+ O0 = 0, O1 = 0, O2 = 0, O3 = 0, O4 = 0, O5 = 0, O6 = 0, O7 = 0;
+
+ // I/O buffer
+ var HEAP = new stdlib.Uint8Array(buffer);
+
+ function _core ( w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15 ) {
+ w0 = w0|0;
+ w1 = w1|0;
+ w2 = w2|0;
+ w3 = w3|0;
+ w4 = w4|0;
+ w5 = w5|0;
+ w6 = w6|0;
+ w7 = w7|0;
+ w8 = w8|0;
+ w9 = w9|0;
+ w10 = w10|0;
+ w11 = w11|0;
+ w12 = w12|0;
+ w13 = w13|0;
+ w14 = w14|0;
+ w15 = w15|0;
+
+ var a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0,
+ t = 0;
+
+ a = H0;
+ b = H1;
+ c = H2;
+ d = H3;
+ e = H4;
+ f = H5;
+ g = H6;
+ h = H7;
+
+ // 0
+ t = ( w0 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x428a2f98 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 1
+ t = ( w1 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x71374491 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 2
+ t = ( w2 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xb5c0fbcf )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 3
+ t = ( w3 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xe9b5dba5 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 4
+ t = ( w4 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x3956c25b )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 5
+ t = ( w5 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x59f111f1 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 6
+ t = ( w6 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x923f82a4 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 7
+ t = ( w7 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xab1c5ed5 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 8
+ t = ( w8 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd807aa98 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 9
+ t = ( w9 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x12835b01 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 10
+ t = ( w10 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x243185be )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 11
+ t = ( w11 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x550c7dc3 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 12
+ t = ( w12 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x72be5d74 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 13
+ t = ( w13 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x80deb1fe )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 14
+ t = ( w14 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x9bdc06a7 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 15
+ t = ( w15 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc19bf174 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 16
+ w0 = t = ( ( w1>>>7 ^ w1>>>18 ^ w1>>>3 ^ w1<<25 ^ w1<<14 ) + ( w14>>>17 ^ w14>>>19 ^ w14>>>10 ^ w14<<15 ^ w14<<13 ) + w0 + w9 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xe49b69c1 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 17
+ w1 = t = ( ( w2>>>7 ^ w2>>>18 ^ w2>>>3 ^ w2<<25 ^ w2<<14 ) + ( w15>>>17 ^ w15>>>19 ^ w15>>>10 ^ w15<<15 ^ w15<<13 ) + w1 + w10 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xefbe4786 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 18
+ w2 = t = ( ( w3>>>7 ^ w3>>>18 ^ w3>>>3 ^ w3<<25 ^ w3<<14 ) + ( w0>>>17 ^ w0>>>19 ^ w0>>>10 ^ w0<<15 ^ w0<<13 ) + w2 + w11 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x0fc19dc6 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 19
+ w3 = t = ( ( w4>>>7 ^ w4>>>18 ^ w4>>>3 ^ w4<<25 ^ w4<<14 ) + ( w1>>>17 ^ w1>>>19 ^ w1>>>10 ^ w1<<15 ^ w1<<13 ) + w3 + w12 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x240ca1cc )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 20
+ w4 = t = ( ( w5>>>7 ^ w5>>>18 ^ w5>>>3 ^ w5<<25 ^ w5<<14 ) + ( w2>>>17 ^ w2>>>19 ^ w2>>>10 ^ w2<<15 ^ w2<<13 ) + w4 + w13 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x2de92c6f )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 21
+ w5 = t = ( ( w6>>>7 ^ w6>>>18 ^ w6>>>3 ^ w6<<25 ^ w6<<14 ) + ( w3>>>17 ^ w3>>>19 ^ w3>>>10 ^ w3<<15 ^ w3<<13 ) + w5 + w14 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x4a7484aa )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 22
+ w6 = t = ( ( w7>>>7 ^ w7>>>18 ^ w7>>>3 ^ w7<<25 ^ w7<<14 ) + ( w4>>>17 ^ w4>>>19 ^ w4>>>10 ^ w4<<15 ^ w4<<13 ) + w6 + w15 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x5cb0a9dc )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 23
+ w7 = t = ( ( w8>>>7 ^ w8>>>18 ^ w8>>>3 ^ w8<<25 ^ w8<<14 ) + ( w5>>>17 ^ w5>>>19 ^ w5>>>10 ^ w5<<15 ^ w5<<13 ) + w7 + w0 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x76f988da )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 24
+ w8 = t = ( ( w9>>>7 ^ w9>>>18 ^ w9>>>3 ^ w9<<25 ^ w9<<14 ) + ( w6>>>17 ^ w6>>>19 ^ w6>>>10 ^ w6<<15 ^ w6<<13 ) + w8 + w1 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x983e5152 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 25
+ w9 = t = ( ( w10>>>7 ^ w10>>>18 ^ w10>>>3 ^ w10<<25 ^ w10<<14 ) + ( w7>>>17 ^ w7>>>19 ^ w7>>>10 ^ w7<<15 ^ w7<<13 ) + w9 + w2 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa831c66d )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 26
+ w10 = t = ( ( w11>>>7 ^ w11>>>18 ^ w11>>>3 ^ w11<<25 ^ w11<<14 ) + ( w8>>>17 ^ w8>>>19 ^ w8>>>10 ^ w8<<15 ^ w8<<13 ) + w10 + w3 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xb00327c8 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 27
+ w11 = t = ( ( w12>>>7 ^ w12>>>18 ^ w12>>>3 ^ w12<<25 ^ w12<<14 ) + ( w9>>>17 ^ w9>>>19 ^ w9>>>10 ^ w9<<15 ^ w9<<13 ) + w11 + w4 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xbf597fc7 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 28
+ w12 = t = ( ( w13>>>7 ^ w13>>>18 ^ w13>>>3 ^ w13<<25 ^ w13<<14 ) + ( w10>>>17 ^ w10>>>19 ^ w10>>>10 ^ w10<<15 ^ w10<<13 ) + w12 + w5 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc6e00bf3 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 29
+ w13 = t = ( ( w14>>>7 ^ w14>>>18 ^ w14>>>3 ^ w14<<25 ^ w14<<14 ) + ( w11>>>17 ^ w11>>>19 ^ w11>>>10 ^ w11<<15 ^ w11<<13 ) + w13 + w6 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd5a79147 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 30
+ w14 = t = ( ( w15>>>7 ^ w15>>>18 ^ w15>>>3 ^ w15<<25 ^ w15<<14 ) + ( w12>>>17 ^ w12>>>19 ^ w12>>>10 ^ w12<<15 ^ w12<<13 ) + w14 + w7 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x06ca6351 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 31
+ w15 = t = ( ( w0>>>7 ^ w0>>>18 ^ w0>>>3 ^ w0<<25 ^ w0<<14 ) + ( w13>>>17 ^ w13>>>19 ^ w13>>>10 ^ w13<<15 ^ w13<<13 ) + w15 + w8 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x14292967 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 32
+ w0 = t = ( ( w1>>>7 ^ w1>>>18 ^ w1>>>3 ^ w1<<25 ^ w1<<14 ) + ( w14>>>17 ^ w14>>>19 ^ w14>>>10 ^ w14<<15 ^ w14<<13 ) + w0 + w9 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x27b70a85 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 33
+ w1 = t = ( ( w2>>>7 ^ w2>>>18 ^ w2>>>3 ^ w2<<25 ^ w2<<14 ) + ( w15>>>17 ^ w15>>>19 ^ w15>>>10 ^ w15<<15 ^ w15<<13 ) + w1 + w10 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x2e1b2138 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 34
+ w2 = t = ( ( w3>>>7 ^ w3>>>18 ^ w3>>>3 ^ w3<<25 ^ w3<<14 ) + ( w0>>>17 ^ w0>>>19 ^ w0>>>10 ^ w0<<15 ^ w0<<13 ) + w2 + w11 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x4d2c6dfc )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 35
+ w3 = t = ( ( w4>>>7 ^ w4>>>18 ^ w4>>>3 ^ w4<<25 ^ w4<<14 ) + ( w1>>>17 ^ w1>>>19 ^ w1>>>10 ^ w1<<15 ^ w1<<13 ) + w3 + w12 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x53380d13 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 36
+ w4 = t = ( ( w5>>>7 ^ w5>>>18 ^ w5>>>3 ^ w5<<25 ^ w5<<14 ) + ( w2>>>17 ^ w2>>>19 ^ w2>>>10 ^ w2<<15 ^ w2<<13 ) + w4 + w13 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x650a7354 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 37
+ w5 = t = ( ( w6>>>7 ^ w6>>>18 ^ w6>>>3 ^ w6<<25 ^ w6<<14 ) + ( w3>>>17 ^ w3>>>19 ^ w3>>>10 ^ w3<<15 ^ w3<<13 ) + w5 + w14 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x766a0abb )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 38
+ w6 = t = ( ( w7>>>7 ^ w7>>>18 ^ w7>>>3 ^ w7<<25 ^ w7<<14 ) + ( w4>>>17 ^ w4>>>19 ^ w4>>>10 ^ w4<<15 ^ w4<<13 ) + w6 + w15 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x81c2c92e )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 39
+ w7 = t = ( ( w8>>>7 ^ w8>>>18 ^ w8>>>3 ^ w8<<25 ^ w8<<14 ) + ( w5>>>17 ^ w5>>>19 ^ w5>>>10 ^ w5<<15 ^ w5<<13 ) + w7 + w0 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x92722c85 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 40
+ w8 = t = ( ( w9>>>7 ^ w9>>>18 ^ w9>>>3 ^ w9<<25 ^ w9<<14 ) + ( w6>>>17 ^ w6>>>19 ^ w6>>>10 ^ w6<<15 ^ w6<<13 ) + w8 + w1 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa2bfe8a1 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 41
+ w9 = t = ( ( w10>>>7 ^ w10>>>18 ^ w10>>>3 ^ w10<<25 ^ w10<<14 ) + ( w7>>>17 ^ w7>>>19 ^ w7>>>10 ^ w7<<15 ^ w7<<13 ) + w9 + w2 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa81a664b )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 42
+ w10 = t = ( ( w11>>>7 ^ w11>>>18 ^ w11>>>3 ^ w11<<25 ^ w11<<14 ) + ( w8>>>17 ^ w8>>>19 ^ w8>>>10 ^ w8<<15 ^ w8<<13 ) + w10 + w3 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc24b8b70 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 43
+ w11 = t = ( ( w12>>>7 ^ w12>>>18 ^ w12>>>3 ^ w12<<25 ^ w12<<14 ) + ( w9>>>17 ^ w9>>>19 ^ w9>>>10 ^ w9<<15 ^ w9<<13 ) + w11 + w4 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc76c51a3 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 44
+ w12 = t = ( ( w13>>>7 ^ w13>>>18 ^ w13>>>3 ^ w13<<25 ^ w13<<14 ) + ( w10>>>17 ^ w10>>>19 ^ w10>>>10 ^ w10<<15 ^ w10<<13 ) + w12 + w5 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd192e819 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 45
+ w13 = t = ( ( w14>>>7 ^ w14>>>18 ^ w14>>>3 ^ w14<<25 ^ w14<<14 ) + ( w11>>>17 ^ w11>>>19 ^ w11>>>10 ^ w11<<15 ^ w11<<13 ) + w13 + w6 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd6990624 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 46
+ w14 = t = ( ( w15>>>7 ^ w15>>>18 ^ w15>>>3 ^ w15<<25 ^ w15<<14 ) + ( w12>>>17 ^ w12>>>19 ^ w12>>>10 ^ w12<<15 ^ w12<<13 ) + w14 + w7 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xf40e3585 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 47
+ w15 = t = ( ( w0>>>7 ^ w0>>>18 ^ w0>>>3 ^ w0<<25 ^ w0<<14 ) + ( w13>>>17 ^ w13>>>19 ^ w13>>>10 ^ w13<<15 ^ w13<<13 ) + w15 + w8 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x106aa070 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 48
+ w0 = t = ( ( w1>>>7 ^ w1>>>18 ^ w1>>>3 ^ w1<<25 ^ w1<<14 ) + ( w14>>>17 ^ w14>>>19 ^ w14>>>10 ^ w14<<15 ^ w14<<13 ) + w0 + w9 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x19a4c116 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 49
+ w1 = t = ( ( w2>>>7 ^ w2>>>18 ^ w2>>>3 ^ w2<<25 ^ w2<<14 ) + ( w15>>>17 ^ w15>>>19 ^ w15>>>10 ^ w15<<15 ^ w15<<13 ) + w1 + w10 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x1e376c08 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 50
+ w2 = t = ( ( w3>>>7 ^ w3>>>18 ^ w3>>>3 ^ w3<<25 ^ w3<<14 ) + ( w0>>>17 ^ w0>>>19 ^ w0>>>10 ^ w0<<15 ^ w0<<13 ) + w2 + w11 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x2748774c )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 51
+ w3 = t = ( ( w4>>>7 ^ w4>>>18 ^ w4>>>3 ^ w4<<25 ^ w4<<14 ) + ( w1>>>17 ^ w1>>>19 ^ w1>>>10 ^ w1<<15 ^ w1<<13 ) + w3 + w12 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x34b0bcb5 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 52
+ w4 = t = ( ( w5>>>7 ^ w5>>>18 ^ w5>>>3 ^ w5<<25 ^ w5<<14 ) + ( w2>>>17 ^ w2>>>19 ^ w2>>>10 ^ w2<<15 ^ w2<<13 ) + w4 + w13 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x391c0cb3 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 53
+ w5 = t = ( ( w6>>>7 ^ w6>>>18 ^ w6>>>3 ^ w6<<25 ^ w6<<14 ) + ( w3>>>17 ^ w3>>>19 ^ w3>>>10 ^ w3<<15 ^ w3<<13 ) + w5 + w14 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x4ed8aa4a )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 54
+ w6 = t = ( ( w7>>>7 ^ w7>>>18 ^ w7>>>3 ^ w7<<25 ^ w7<<14 ) + ( w4>>>17 ^ w4>>>19 ^ w4>>>10 ^ w4<<15 ^ w4<<13 ) + w6 + w15 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x5b9cca4f )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 55
+ w7 = t = ( ( w8>>>7 ^ w8>>>18 ^ w8>>>3 ^ w8<<25 ^ w8<<14 ) + ( w5>>>17 ^ w5>>>19 ^ w5>>>10 ^ w5<<15 ^ w5<<13 ) + w7 + w0 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x682e6ff3 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 56
+ w8 = t = ( ( w9>>>7 ^ w9>>>18 ^ w9>>>3 ^ w9<<25 ^ w9<<14 ) + ( w6>>>17 ^ w6>>>19 ^ w6>>>10 ^ w6<<15 ^ w6<<13 ) + w8 + w1 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x748f82ee )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 57
+ w9 = t = ( ( w10>>>7 ^ w10>>>18 ^ w10>>>3 ^ w10<<25 ^ w10<<14 ) + ( w7>>>17 ^ w7>>>19 ^ w7>>>10 ^ w7<<15 ^ w7<<13 ) + w9 + w2 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x78a5636f )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 58
+ w10 = t = ( ( w11>>>7 ^ w11>>>18 ^ w11>>>3 ^ w11<<25 ^ w11<<14 ) + ( w8>>>17 ^ w8>>>19 ^ w8>>>10 ^ w8<<15 ^ w8<<13 ) + w10 + w3 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x84c87814 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 59
+ w11 = t = ( ( w12>>>7 ^ w12>>>18 ^ w12>>>3 ^ w12<<25 ^ w12<<14 ) + ( w9>>>17 ^ w9>>>19 ^ w9>>>10 ^ w9<<15 ^ w9<<13 ) + w11 + w4 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x8cc70208 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 60
+ w12 = t = ( ( w13>>>7 ^ w13>>>18 ^ w13>>>3 ^ w13<<25 ^ w13<<14 ) + ( w10>>>17 ^ w10>>>19 ^ w10>>>10 ^ w10<<15 ^ w10<<13 ) + w12 + w5 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x90befffa )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 61
+ w13 = t = ( ( w14>>>7 ^ w14>>>18 ^ w14>>>3 ^ w14<<25 ^ w14<<14 ) + ( w11>>>17 ^ w11>>>19 ^ w11>>>10 ^ w11<<15 ^ w11<<13 ) + w13 + w6 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa4506ceb )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 62
+ w14 = t = ( ( w15>>>7 ^ w15>>>18 ^ w15>>>3 ^ w15<<25 ^ w15<<14 ) + ( w12>>>17 ^ w12>>>19 ^ w12>>>10 ^ w12<<15 ^ w12<<13 ) + w14 + w7 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xbef9a3f7 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ // 63
+ w15 = t = ( ( w0>>>7 ^ w0>>>18 ^ w0>>>3 ^ w0<<25 ^ w0<<14 ) + ( w13>>>17 ^ w13>>>19 ^ w13>>>10 ^ w13<<15 ^ w13<<13 ) + w15 + w8 )|0;
+ t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc67178f2 )|0;
+ h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a;
+ a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0;
+
+ H0 = ( H0 + a )|0;
+ H1 = ( H1 + b )|0;
+ H2 = ( H2 + c )|0;
+ H3 = ( H3 + d )|0;
+ H4 = ( H4 + e )|0;
+ H5 = ( H5 + f )|0;
+ H6 = ( H6 + g )|0;
+ H7 = ( H7 + h )|0;
+ }
+
+ function _core_heap ( offset ) {
+ offset = offset|0;
+
+ _core(
+ HEAP[offset|0]<<24 | HEAP[offset|1]<<16 | HEAP[offset|2]<<8 | HEAP[offset|3],
+ HEAP[offset|4]<<24 | HEAP[offset|5]<<16 | HEAP[offset|6]<<8 | HEAP[offset|7],
+ HEAP[offset|8]<<24 | HEAP[offset|9]<<16 | HEAP[offset|10]<<8 | HEAP[offset|11],
+ HEAP[offset|12]<<24 | HEAP[offset|13]<<16 | HEAP[offset|14]<<8 | HEAP[offset|15],
+ HEAP[offset|16]<<24 | HEAP[offset|17]<<16 | HEAP[offset|18]<<8 | HEAP[offset|19],
+ HEAP[offset|20]<<24 | HEAP[offset|21]<<16 | HEAP[offset|22]<<8 | HEAP[offset|23],
+ HEAP[offset|24]<<24 | HEAP[offset|25]<<16 | HEAP[offset|26]<<8 | HEAP[offset|27],
+ HEAP[offset|28]<<24 | HEAP[offset|29]<<16 | HEAP[offset|30]<<8 | HEAP[offset|31],
+ HEAP[offset|32]<<24 | HEAP[offset|33]<<16 | HEAP[offset|34]<<8 | HEAP[offset|35],
+ HEAP[offset|36]<<24 | HEAP[offset|37]<<16 | HEAP[offset|38]<<8 | HEAP[offset|39],
+ HEAP[offset|40]<<24 | HEAP[offset|41]<<16 | HEAP[offset|42]<<8 | HEAP[offset|43],
+ HEAP[offset|44]<<24 | HEAP[offset|45]<<16 | HEAP[offset|46]<<8 | HEAP[offset|47],
+ HEAP[offset|48]<<24 | HEAP[offset|49]<<16 | HEAP[offset|50]<<8 | HEAP[offset|51],
+ HEAP[offset|52]<<24 | HEAP[offset|53]<<16 | HEAP[offset|54]<<8 | HEAP[offset|55],
+ HEAP[offset|56]<<24 | HEAP[offset|57]<<16 | HEAP[offset|58]<<8 | HEAP[offset|59],
+ HEAP[offset|60]<<24 | HEAP[offset|61]<<16 | HEAP[offset|62]<<8 | HEAP[offset|63]
+ );
+ }
+
+ // offset — multiple of 32
+ function _state_to_heap ( output ) {
+ output = output|0;
+
+ HEAP[output|0] = H0>>>24;
+ HEAP[output|1] = H0>>>16&255;
+ HEAP[output|2] = H0>>>8&255;
+ HEAP[output|3] = H0&255;
+ HEAP[output|4] = H1>>>24;
+ HEAP[output|5] = H1>>>16&255;
+ HEAP[output|6] = H1>>>8&255;
+ HEAP[output|7] = H1&255;
+ HEAP[output|8] = H2>>>24;
+ HEAP[output|9] = H2>>>16&255;
+ HEAP[output|10] = H2>>>8&255;
+ HEAP[output|11] = H2&255;
+ HEAP[output|12] = H3>>>24;
+ HEAP[output|13] = H3>>>16&255;
+ HEAP[output|14] = H3>>>8&255;
+ HEAP[output|15] = H3&255;
+ HEAP[output|16] = H4>>>24;
+ HEAP[output|17] = H4>>>16&255;
+ HEAP[output|18] = H4>>>8&255;
+ HEAP[output|19] = H4&255;
+ HEAP[output|20] = H5>>>24;
+ HEAP[output|21] = H5>>>16&255;
+ HEAP[output|22] = H5>>>8&255;
+ HEAP[output|23] = H5&255;
+ HEAP[output|24] = H6>>>24;
+ HEAP[output|25] = H6>>>16&255;
+ HEAP[output|26] = H6>>>8&255;
+ HEAP[output|27] = H6&255;
+ HEAP[output|28] = H7>>>24;
+ HEAP[output|29] = H7>>>16&255;
+ HEAP[output|30] = H7>>>8&255;
+ HEAP[output|31] = H7&255;
+ }
+
+ function reset () {
+ H0 = 0x6a09e667;
+ H1 = 0xbb67ae85;
+ H2 = 0x3c6ef372;
+ H3 = 0xa54ff53a;
+ H4 = 0x510e527f;
+ H5 = 0x9b05688c;
+ H6 = 0x1f83d9ab;
+ H7 = 0x5be0cd19;
+ TOTAL0 = TOTAL1 = 0;
+ }
+
+ function init ( h0, h1, h2, h3, h4, h5, h6, h7, total0, total1 ) {
+ h0 = h0|0;
+ h1 = h1|0;
+ h2 = h2|0;
+ h3 = h3|0;
+ h4 = h4|0;
+ h5 = h5|0;
+ h6 = h6|0;
+ h7 = h7|0;
+ total0 = total0|0;
+ total1 = total1|0;
+
+ H0 = h0;
+ H1 = h1;
+ H2 = h2;
+ H3 = h3;
+ H4 = h4;
+ H5 = h5;
+ H6 = h6;
+ H7 = h7;
+ TOTAL0 = total0;
+ TOTAL1 = total1;
+ }
+
+ // offset — multiple of 64
+ function process ( offset, length ) {
+ offset = offset|0;
+ length = length|0;
+
+ var hashed = 0;
+
+ if ( offset & 63 )
+ return -1;
+
+ while ( (length|0) >= 64 ) {
+ _core_heap(offset);
+
+ offset = ( offset + 64 )|0;
+ length = ( length - 64 )|0;
+
+ hashed = ( hashed + 64 )|0;
+ }
+
+ TOTAL0 = ( TOTAL0 + hashed )|0;
+ if ( TOTAL0>>>0 < hashed>>>0 ) TOTAL1 = ( TOTAL1 + 1 )|0;
+
+ return hashed|0;
+ }
+
+ // offset — multiple of 64
+ // output — multiple of 32
+ function finish ( offset, length, output ) {
+ offset = offset|0;
+ length = length|0;
+ output = output|0;
+
+ var hashed = 0,
+ i = 0;
+
+ if ( offset & 63 )
+ return -1;
+
+ if ( ~output )
+ if ( output & 31 )
+ return -1;
+
+ if ( (length|0) >= 64 ) {
+ hashed = process( offset, length )|0;
+ if ( (hashed|0) == -1 )
+ return -1;
+
+ offset = ( offset + hashed )|0;
+ length = ( length - hashed )|0;
+ }
+
+ hashed = ( hashed + length )|0;
+ TOTAL0 = ( TOTAL0 + length )|0;
+ if ( TOTAL0>>>0 < length>>>0 ) TOTAL1 = ( TOTAL1 + 1 )|0;
+
+ HEAP[offset|length] = 0x80;
+
+ if ( (length|0) >= 56 ) {
+ for ( i = (length+1)|0; (i|0) < 64; i = (i+1)|0 )
+ HEAP[offset|i] = 0x00;
+
+ _core_heap(offset);
+
+ length = 0;
+
+ HEAP[offset|0] = 0;
+ }
+
+ for ( i = (length+1)|0; (i|0) < 59; i = (i+1)|0 )
+ HEAP[offset|i] = 0;
+
+ HEAP[offset|56] = TOTAL1>>>21&255;
+ HEAP[offset|57] = TOTAL1>>>13&255;
+ HEAP[offset|58] = TOTAL1>>>5&255;
+ HEAP[offset|59] = TOTAL1<<3&255 | TOTAL0>>>29;
+ HEAP[offset|60] = TOTAL0>>>21&255;
+ HEAP[offset|61] = TOTAL0>>>13&255;
+ HEAP[offset|62] = TOTAL0>>>5&255;
+ HEAP[offset|63] = TOTAL0<<3&255;
+ _core_heap(offset);
+
+ if ( ~output )
+ _state_to_heap(output);
+
+ return hashed|0;
+ }
+
+ function hmac_reset () {
+ H0 = I0;
+ H1 = I1;
+ H2 = I2;
+ H3 = I3;
+ H4 = I4;
+ H5 = I5;
+ H6 = I6;
+ H7 = I7;
+ TOTAL0 = 64;
+ TOTAL1 = 0;
+ }
+
+ function _hmac_opad () {
+ H0 = O0;
+ H1 = O1;
+ H2 = O2;
+ H3 = O3;
+ H4 = O4;
+ H5 = O5;
+ H6 = O6;
+ H7 = O7;
+ TOTAL0 = 64;
+ TOTAL1 = 0;
+ }
+
+ function hmac_init ( p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15 ) {
+ p0 = p0|0;
+ p1 = p1|0;
+ p2 = p2|0;
+ p3 = p3|0;
+ p4 = p4|0;
+ p5 = p5|0;
+ p6 = p6|0;
+ p7 = p7|0;
+ p8 = p8|0;
+ p9 = p9|0;
+ p10 = p10|0;
+ p11 = p11|0;
+ p12 = p12|0;
+ p13 = p13|0;
+ p14 = p14|0;
+ p15 = p15|0;
+
+ // opad
+ reset();
+ _core(
+ p0 ^ 0x5c5c5c5c,
+ p1 ^ 0x5c5c5c5c,
+ p2 ^ 0x5c5c5c5c,
+ p3 ^ 0x5c5c5c5c,
+ p4 ^ 0x5c5c5c5c,
+ p5 ^ 0x5c5c5c5c,
+ p6 ^ 0x5c5c5c5c,
+ p7 ^ 0x5c5c5c5c,
+ p8 ^ 0x5c5c5c5c,
+ p9 ^ 0x5c5c5c5c,
+ p10 ^ 0x5c5c5c5c,
+ p11 ^ 0x5c5c5c5c,
+ p12 ^ 0x5c5c5c5c,
+ p13 ^ 0x5c5c5c5c,
+ p14 ^ 0x5c5c5c5c,
+ p15 ^ 0x5c5c5c5c
+ );
+ O0 = H0;
+ O1 = H1;
+ O2 = H2;
+ O3 = H3;
+ O4 = H4;
+ O5 = H5;
+ O6 = H6;
+ O7 = H7;
+
+ // ipad
+ reset();
+ _core(
+ p0 ^ 0x36363636,
+ p1 ^ 0x36363636,
+ p2 ^ 0x36363636,
+ p3 ^ 0x36363636,
+ p4 ^ 0x36363636,
+ p5 ^ 0x36363636,
+ p6 ^ 0x36363636,
+ p7 ^ 0x36363636,
+ p8 ^ 0x36363636,
+ p9 ^ 0x36363636,
+ p10 ^ 0x36363636,
+ p11 ^ 0x36363636,
+ p12 ^ 0x36363636,
+ p13 ^ 0x36363636,
+ p14 ^ 0x36363636,
+ p15 ^ 0x36363636
+ );
+ I0 = H0;
+ I1 = H1;
+ I2 = H2;
+ I3 = H3;
+ I4 = H4;
+ I5 = H5;
+ I6 = H6;
+ I7 = H7;
+
+ TOTAL0 = 64;
+ TOTAL1 = 0;
+ }
+
+ // offset — multiple of 64
+ // output — multiple of 32
+ function hmac_finish ( offset, length, output ) {
+ offset = offset|0;
+ length = length|0;
+ output = output|0;
+
+ var t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
+ hashed = 0;
+
+ if ( offset & 63 )
+ return -1;
+
+ if ( ~output )
+ if ( output & 31 )
+ return -1;
+
+ hashed = finish( offset, length, -1 )|0;
+ t0 = H0, t1 = H1, t2 = H2, t3 = H3, t4 = H4, t5 = H5, t6 = H6, t7 = H7;
+
+ _hmac_opad();
+ _core( t0, t1, t2, t3, t4, t5, t6, t7, 0x80000000, 0, 0, 0, 0, 0, 0, 768 );
+
+ if ( ~output )
+ _state_to_heap(output);
+
+ return hashed|0;
+ }
+
+ // salt is assumed to be already processed
+ // offset — multiple of 64
+ // output — multiple of 32
+ function pbkdf2_generate_block ( offset, length, block, count, output ) {
+ offset = offset|0;
+ length = length|0;
+ block = block|0;
+ count = count|0;
+ output = output|0;
+
+ var h0 = 0, h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0, h7 = 0,
+ t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0;
+
+ if ( offset & 63 )
+ return -1;
+
+ if ( ~output )
+ if ( output & 31 )
+ return -1;
+
+ // pad block number into heap
+ // FIXME probable OOB write
+ HEAP[(offset+length)|0] = block>>>24;
+ HEAP[(offset+length+1)|0] = block>>>16&255;
+ HEAP[(offset+length+2)|0] = block>>>8&255;
+ HEAP[(offset+length+3)|0] = block&255;
+
+ // finish first iteration
+ hmac_finish( offset, (length+4)|0, -1 )|0;
+ h0 = t0 = H0, h1 = t1 = H1, h2 = t2 = H2, h3 = t3 = H3, h4 = t4 = H4, h5 = t5 = H5, h6 = t6 = H6, h7 = t7 = H7;
+ count = (count-1)|0;
+
+ // perform the rest iterations
+ while ( (count|0) > 0 ) {
+ hmac_reset();
+ _core( t0, t1, t2, t3, t4, t5, t6, t7, 0x80000000, 0, 0, 0, 0, 0, 0, 768 );
+ t0 = H0, t1 = H1, t2 = H2, t3 = H3, t4 = H4, t5 = H5, t6 = H6, t7 = H7;
+
+ _hmac_opad();
+ _core( t0, t1, t2, t3, t4, t5, t6, t7, 0x80000000, 0, 0, 0, 0, 0, 0, 768 );
+ t0 = H0, t1 = H1, t2 = H2, t3 = H3, t4 = H4, t5 = H5, t6 = H6, t7 = H7;
+
+ h0 = h0 ^ H0;
+ h1 = h1 ^ H1;
+ h2 = h2 ^ H2;
+ h3 = h3 ^ H3;
+ h4 = h4 ^ H4;
+ h5 = h5 ^ H5;
+ h6 = h6 ^ H6;
+ h7 = h7 ^ H7;
+
+ count = (count-1)|0;
+ }
+
+ H0 = h0;
+ H1 = h1;
+ H2 = h2;
+ H3 = h3;
+ H4 = h4;
+ H5 = h5;
+ H6 = h6;
+ H7 = h7;
+
+ if ( ~output )
+ _state_to_heap(output);
+
+ return 0;
+ }
+
+ return {
+ // SHA256
+ reset: reset,
+ init: init,
+ process: process,
+ finish: finish,
+
+ // HMAC-SHA256
+ hmac_reset: hmac_reset,
+ hmac_init: hmac_init,
+ hmac_finish: hmac_finish,
+
+ // PBKDF2-HMAC-SHA256
+ pbkdf2_generate_block: pbkdf2_generate_block
+ }
+}
+
+var _sha256_block_size = 64,
+ _sha256_hash_size = 32;
+
+function sha256_constructor ( options ) {
+ options = options || {};
+
+ this.heap = _heap_init( Uint8Array, options );
+ this.asm = options.asm || sha256_asm( global, null, this.heap.buffer );
+
+ this.BLOCK_SIZE = _sha256_block_size;
+ this.HASH_SIZE = _sha256_hash_size;
+
+ this.reset();
+}
+
+sha256_constructor.BLOCK_SIZE = _sha256_block_size;
+sha256_constructor.HASH_SIZE = _sha256_hash_size;
+var sha256_prototype = sha256_constructor.prototype;
+sha256_prototype.reset = hash_reset;
+sha256_prototype.process = hash_process;
+sha256_prototype.finish = hash_finish;
+
+var sha256_instance = null;
+
+function get_sha256_instance () {
+ if ( sha256_instance === null ) sha256_instance = new sha256_constructor( { heapSize: 0x100000 } );
+ return sha256_instance;
+}
+
+/**
+ * SHA256 exports
+ */
+
+function sha256_bytes ( data ) {
+ if ( data === undefined ) throw new SyntaxError("data required");
+ return get_sha256_instance().reset().process(data).finish().result;
+}
+
+function sha256_hex ( data ) {
+ var result = sha256_bytes(data);
+ return bytes_to_hex(result);
+}
+
+function sha256_base64 ( data ) {
+ var result = sha256_bytes(data);
+ return bytes_to_base64(result);
+}
+
+sha256_constructor.bytes = sha256_bytes;
+sha256_constructor.hex = sha256_hex;
+sha256_constructor.base64 = sha256_base64;
+
+exports.SHA256 = sha256_constructor;
+
+
+'function'==typeof define&&define.amd?define([],function(){return exports}):'object'==typeof module&&module.exports?module.exports=exports:global.asmCrypto=exports;
+
+return exports;
+})( {}, function(){return this}() );
+},{}],2:[function(_dereq_,module,exports){
+(function (process,global){
+/*!
+ * @overview es6-promise - a tiny implementation of Promises/A+.
+ * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
+ * @license Licensed under MIT license
+ * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
+ * @version 4.1.1
+ */
+
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+ typeof define === 'function' && define.amd ? define(factory) :
+ (global.ES6Promise = factory());
+}(this, (function () { 'use strict';
+
+function objectOrFunction(x) {
+ var type = typeof x;
+ return x !== null && (type === 'object' || type === 'function');
+}
+
+function isFunction(x) {
+ return typeof x === 'function';
+}
+
+var _isArray = undefined;
+if (Array.isArray) {
+ _isArray = Array.isArray;
+} else {
+ _isArray = function (x) {
+ return Object.prototype.toString.call(x) === '[object Array]';
+ };
+}
+
+var isArray = _isArray;
+
+var len = 0;
+var vertxNext = undefined;
+var customSchedulerFn = undefined;
+
+var asap = function asap(callback, arg) {
+ queue[len] = callback;
+ queue[len + 1] = arg;
+ len += 2;
+ if (len === 2) {
+ // If len is 2, that means that we need to schedule an async flush.
+ // If additional callbacks are queued before the queue is flushed, they
+ // will be processed by this flush that we are scheduling.
+ if (customSchedulerFn) {
+ customSchedulerFn(flush);
+ } else {
+ scheduleFlush();
+ }
+ }
+};
+
+function setScheduler(scheduleFn) {
+ customSchedulerFn = scheduleFn;
+}
+
+function setAsap(asapFn) {
+ asap = asapFn;
+}
+
+var browserWindow = typeof window !== 'undefined' ? window : undefined;
+var browserGlobal = browserWindow || {};
+var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
+var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
+
+// test for web worker but not in IE10
+var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
+
+// node
+function useNextTick() {
+ // node version 0.10.x displays a deprecation warning when nextTick is used recursively
+ // see https://github.com/cujojs/when/issues/410 for details
+ return function () {
+ return process.nextTick(flush);
+ };
+}
+
+// vertx
+function useVertxTimer() {
+ if (typeof vertxNext !== 'undefined') {
+ return function () {
+ vertxNext(flush);
+ };
+ }
+
+ return useSetTimeout();
+}
+
+function useMutationObserver() {
+ var iterations = 0;
+ var observer = new BrowserMutationObserver(flush);
+ var node = document.createTextNode('');
+ observer.observe(node, { characterData: true });
+
+ return function () {
+ node.data = iterations = ++iterations % 2;
+ };
+}
+
+// web worker
+function useMessageChannel() {
+ var channel = new MessageChannel();
+ channel.port1.onmessage = flush;
+ return function () {
+ return channel.port2.postMessage(0);
+ };
+}
+
+function useSetTimeout() {
+ // Store setTimeout reference so es6-promise will be unaffected by
+ // other code modifying setTimeout (like sinon.useFakeTimers())
+ var globalSetTimeout = setTimeout;
+ return function () {
+ return globalSetTimeout(flush, 1);
+ };
+}
+
+var queue = new Array(1000);
+function flush() {
+ for (var i = 0; i < len; i += 2) {
+ var callback = queue[i];
+ var arg = queue[i + 1];
+
+ callback(arg);
+
+ queue[i] = undefined;
+ queue[i + 1] = undefined;
+ }
+
+ len = 0;
+}
+
+function attemptVertx() {
+ try {
+ var r = _dereq_;
+ var vertx = r('vertx');
+ vertxNext = vertx.runOnLoop || vertx.runOnContext;
+ return useVertxTimer();
+ } catch (e) {
+ return useSetTimeout();
+ }
+}
+
+var scheduleFlush = undefined;
+// Decide what async method to use to triggering processing of queued callbacks:
+if (isNode) {
+ scheduleFlush = useNextTick();
+} else if (BrowserMutationObserver) {
+ scheduleFlush = useMutationObserver();
+} else if (isWorker) {
+ scheduleFlush = useMessageChannel();
+} else if (browserWindow === undefined && typeof _dereq_ === 'function') {
+ scheduleFlush = attemptVertx();
+} else {
+ scheduleFlush = useSetTimeout();
+}
+
+function then(onFulfillment, onRejection) {
+ var _arguments = arguments;
+
+ var parent = this;
+
+ var child = new this.constructor(noop);
+
+ if (child[PROMISE_ID] === undefined) {
+ makePromise(child);
+ }
+
+ var _state = parent._state;
+
+ if (_state) {
+ (function () {
+ var callback = _arguments[_state - 1];
+ asap(function () {
+ return invokeCallback(_state, child, callback, parent._result);
+ });
+ })();
+ } else {
+ subscribe(parent, child, onFulfillment, onRejection);
+ }
+
+ return child;
+}
+
+/**
+ `Promise.resolve` returns a promise that will become resolved with the
+ passed `value`. It is shorthand for the following:
+
+ ```javascript
+ let promise = new Promise(function(resolve, reject){
+ resolve(1);
+ });
+
+ promise.then(function(value){
+ // value === 1
+ });
+ ```
+
+ Instead of writing the above, your code now simply becomes the following:
+
+ ```javascript
+ let promise = Promise.resolve(1);
+
+ promise.then(function(value){
+ // value === 1
+ });
+ ```
+
+ @method resolve
+ @static
+ @param {Any} value value that the returned promise will be resolved with
+ Useful for tooling.
+ @return {Promise} a promise that will become fulfilled with the given
+ `value`
+*/
+function resolve$1(object) {
+ /*jshint validthis:true */
+ var Constructor = this;
+
+ if (object && typeof object === 'object' && object.constructor === Constructor) {
+ return object;
+ }
+
+ var promise = new Constructor(noop);
+ resolve(promise, object);
+ return promise;
+}
+
+var PROMISE_ID = Math.random().toString(36).substring(16);
+
+function noop() {}
+
+var PENDING = void 0;
+var FULFILLED = 1;
+var REJECTED = 2;
+
+var GET_THEN_ERROR = new ErrorObject();
+
+function selfFulfillment() {
+ return new TypeError("You cannot resolve a promise with itself");
+}
+
+function cannotReturnOwn() {
+ return new TypeError('A promises callback cannot return that same promise.');
+}
+
+function getThen(promise) {
+ try {
+ return promise.then;
+ } catch (error) {
+ GET_THEN_ERROR.error = error;
+ return GET_THEN_ERROR;
+ }
+}
+
+function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
+ try {
+ then$$1.call(value, fulfillmentHandler, rejectionHandler);
+ } catch (e) {
+ return e;
+ }
+}
+
+function handleForeignThenable(promise, thenable, then$$1) {
+ asap(function (promise) {
+ var sealed = false;
+ var error = tryThen(then$$1, thenable, function (value) {
+ if (sealed) {
+ return;
+ }
+ sealed = true;
+ if (thenable !== value) {
+ resolve(promise, value);
+ } else {
+ fulfill(promise, value);
+ }
+ }, function (reason) {
+ if (sealed) {
+ return;
+ }
+ sealed = true;
+
+ reject(promise, reason);
+ }, 'Settle: ' + (promise._label || ' unknown promise'));
+
+ if (!sealed && error) {
+ sealed = true;
+ reject(promise, error);
+ }
+ }, promise);
+}
+
+function handleOwnThenable(promise, thenable) {
+ if (thenable._state === FULFILLED) {
+ fulfill(promise, thenable._result);
+ } else if (thenable._state === REJECTED) {
+ reject(promise, thenable._result);
+ } else {
+ subscribe(thenable, undefined, function (value) {
+ return resolve(promise, value);
+ }, function (reason) {
+ return reject(promise, reason);
+ });
+ }
+}
+
+function handleMaybeThenable(promise, maybeThenable, then$$1) {
+ if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
+ handleOwnThenable(promise, maybeThenable);
+ } else {
+ if (then$$1 === GET_THEN_ERROR) {
+ reject(promise, GET_THEN_ERROR.error);
+ GET_THEN_ERROR.error = null;
+ } else if (then$$1 === undefined) {
+ fulfill(promise, maybeThenable);
+ } else if (isFunction(then$$1)) {
+ handleForeignThenable(promise, maybeThenable, then$$1);
+ } else {
+ fulfill(promise, maybeThenable);
+ }
+ }
+}
+
+function resolve(promise, value) {
+ if (promise === value) {
+ reject(promise, selfFulfillment());
+ } else if (objectOrFunction(value)) {
+ handleMaybeThenable(promise, value, getThen(value));
+ } else {
+ fulfill(promise, value);
+ }
+}
+
+function publishRejection(promise) {
+ if (promise._onerror) {
+ promise._onerror(promise._result);
+ }
+
+ publish(promise);
+}
+
+function fulfill(promise, value) {
+ if (promise._state !== PENDING) {
+ return;
+ }
+
+ promise._result = value;
+ promise._state = FULFILLED;
+
+ if (promise._subscribers.length !== 0) {
+ asap(publish, promise);
+ }
+}
+
+function reject(promise, reason) {
+ if (promise._state !== PENDING) {
+ return;
+ }
+ promise._state = REJECTED;
+ promise._result = reason;
+
+ asap(publishRejection, promise);
+}
+
+function subscribe(parent, child, onFulfillment, onRejection) {
+ var _subscribers = parent._subscribers;
+ var length = _subscribers.length;
+
+ parent._onerror = null;
+
+ _subscribers[length] = child;
+ _subscribers[length + FULFILLED] = onFulfillment;
+ _subscribers[length + REJECTED] = onRejection;
+
+ if (length === 0 && parent._state) {
+ asap(publish, parent);
+ }
+}
+
+function publish(promise) {
+ var subscribers = promise._subscribers;
+ var settled = promise._state;
+
+ if (subscribers.length === 0) {
+ return;
+ }
+
+ var child = undefined,
+ callback = undefined,
+ detail = promise._result;
+
+ for (var i = 0; i < subscribers.length; i += 3) {
+ child = subscribers[i];
+ callback = subscribers[i + settled];
+
+ if (child) {
+ invokeCallback(settled, child, callback, detail);
+ } else {
+ callback(detail);
+ }
+ }
+
+ promise._subscribers.length = 0;
+}
+
+function ErrorObject() {
+ this.error = null;
+}
+
+var TRY_CATCH_ERROR = new ErrorObject();
+
+function tryCatch(callback, detail) {
+ try {
+ return callback(detail);
+ } catch (e) {
+ TRY_CATCH_ERROR.error = e;
+ return TRY_CATCH_ERROR;
+ }
+}
+
+function invokeCallback(settled, promise, callback, detail) {
+ var hasCallback = isFunction(callback),
+ value = undefined,
+ error = undefined,
+ succeeded = undefined,
+ failed = undefined;
+
+ if (hasCallback) {
+ value = tryCatch(callback, detail);
+
+ if (value === TRY_CATCH_ERROR) {
+ failed = true;
+ error = value.error;
+ value.error = null;
+ } else {
+ succeeded = true;
+ }
+
+ if (promise === value) {
+ reject(promise, cannotReturnOwn());
+ return;
+ }
+ } else {
+ value = detail;
+ succeeded = true;
+ }
+
+ if (promise._state !== PENDING) {
+ // noop
+ } else if (hasCallback && succeeded) {
+ resolve(promise, value);
+ } else if (failed) {
+ reject(promise, error);
+ } else if (settled === FULFILLED) {
+ fulfill(promise, value);
+ } else if (settled === REJECTED) {
+ reject(promise, value);
+ }
+}
+
+function initializePromise(promise, resolver) {
+ try {
+ resolver(function resolvePromise(value) {
+ resolve(promise, value);
+ }, function rejectPromise(reason) {
+ reject(promise, reason);
+ });
+ } catch (e) {
+ reject(promise, e);
+ }
+}
+
+var id = 0;
+function nextId() {
+ return id++;
+}
+
+function makePromise(promise) {
+ promise[PROMISE_ID] = id++;
+ promise._state = undefined;
+ promise._result = undefined;
+ promise._subscribers = [];
+}
+
+function Enumerator$1(Constructor, input) {
+ this._instanceConstructor = Constructor;
+ this.promise = new Constructor(noop);
+
+ if (!this.promise[PROMISE_ID]) {
+ makePromise(this.promise);
+ }
+
+ if (isArray(input)) {
+ this.length = input.length;
+ this._remaining = input.length;
+
+ this._result = new Array(this.length);
+
+ if (this.length === 0) {
+ fulfill(this.promise, this._result);
+ } else {
+ this.length = this.length || 0;
+ this._enumerate(input);
+ if (this._remaining === 0) {
+ fulfill(this.promise, this._result);
+ }
+ }
+ } else {
+ reject(this.promise, validationError());
+ }
+}
+
+function validationError() {
+ return new Error('Array Methods must be provided an Array');
+}
+
+Enumerator$1.prototype._enumerate = function (input) {
+ for (var i = 0; this._state === PENDING && i < input.length; i++) {
+ this._eachEntry(input[i], i);
+ }
+};
+
+Enumerator$1.prototype._eachEntry = function (entry, i) {
+ var c = this._instanceConstructor;
+ var resolve$$1 = c.resolve;
+
+ if (resolve$$1 === resolve$1) {
+ var _then = getThen(entry);
+
+ if (_then === then && entry._state !== PENDING) {
+ this._settledAt(entry._state, i, entry._result);
+ } else if (typeof _then !== 'function') {
+ this._remaining--;
+ this._result[i] = entry;
+ } else if (c === Promise$2) {
+ var promise = new c(noop);
+ handleMaybeThenable(promise, entry, _then);
+ this._willSettleAt(promise, i);
+ } else {
+ this._willSettleAt(new c(function (resolve$$1) {
+ return resolve$$1(entry);
+ }), i);
+ }
+ } else {
+ this._willSettleAt(resolve$$1(entry), i);
+ }
+};
+
+Enumerator$1.prototype._settledAt = function (state, i, value) {
+ var promise = this.promise;
+
+ if (promise._state === PENDING) {
+ this._remaining--;
+
+ if (state === REJECTED) {
+ reject(promise, value);
+ } else {
+ this._result[i] = value;
+ }
+ }
+
+ if (this._remaining === 0) {
+ fulfill(promise, this._result);
+ }
+};
+
+Enumerator$1.prototype._willSettleAt = function (promise, i) {
+ var enumerator = this;
+
+ subscribe(promise, undefined, function (value) {
+ return enumerator._settledAt(FULFILLED, i, value);
+ }, function (reason) {
+ return enumerator._settledAt(REJECTED, i, reason);
+ });
+};
+
+/**
+ `Promise.all` accepts an array of promises, and returns a new promise which
+ is fulfilled with an array of fulfillment values for the passed promises, or
+ rejected with the reason of the first passed promise to be rejected. It casts all
+ elements of the passed iterable to promises as it runs this algorithm.
+
+ Example:
+
+ ```javascript
+ let promise1 = resolve(1);
+ let promise2 = resolve(2);
+ let promise3 = resolve(3);
+ let promises = [ promise1, promise2, promise3 ];
+
+ Promise.all(promises).then(function(array){
+ // The array here would be [ 1, 2, 3 ];
+ });
+ ```
+
+ If any of the `promises` given to `all` are rejected, the first promise
+ that is rejected will be given as an argument to the returned promises's
+ rejection handler. For example:
+
+ Example:
+
+ ```javascript
+ let promise1 = resolve(1);
+ let promise2 = reject(new Error("2"));
+ let promise3 = reject(new Error("3"));
+ let promises = [ promise1, promise2, promise3 ];
+
+ Promise.all(promises).then(function(array){
+ // Code here never runs because there are rejected promises!
+ }, function(error) {
+ // error.message === "2"
+ });
+ ```
+
+ @method all
+ @static
+ @param {Array} entries array of promises
+ @param {String} label optional string for labeling the promise.
+ Useful for tooling.
+ @return {Promise} promise that is fulfilled when all `promises` have been
+ fulfilled, or rejected if any of them become rejected.
+ @static
+*/
+function all$1(entries) {
+ return new Enumerator$1(this, entries).promise;
+}
+
+/**
+ `Promise.race` returns a new promise which is settled in the same way as the
+ first passed promise to settle.
+
+ Example:
+
+ ```javascript
+ let promise1 = new Promise(function(resolve, reject){
+ setTimeout(function(){
+ resolve('promise 1');
+ }, 200);
+ });
+
+ let promise2 = new Promise(function(resolve, reject){
+ setTimeout(function(){
+ resolve('promise 2');
+ }, 100);
+ });
+
+ Promise.race([promise1, promise2]).then(function(result){
+ // result === 'promise 2' because it was resolved before promise1
+ // was resolved.
+ });
+ ```
+
+ `Promise.race` is deterministic in that only the state of the first
+ settled promise matters. For example, even if other promises given to the
+ `promises` array argument are resolved, but the first settled promise has
+ become rejected before the other promises became fulfilled, the returned
+ promise will become rejected:
+
+ ```javascript
+ let promise1 = new Promise(function(resolve, reject){
+ setTimeout(function(){
+ resolve('promise 1');
+ }, 200);
+ });
+
+ let promise2 = new Promise(function(resolve, reject){
+ setTimeout(function(){
+ reject(new Error('promise 2'));
+ }, 100);
+ });
+
+ Promise.race([promise1, promise2]).then(function(result){
+ // Code here never runs
+ }, function(reason){
+ // reason.message === 'promise 2' because promise 2 became rejected before
+ // promise 1 became fulfilled
+ });
+ ```
+
+ An example real-world use case is implementing timeouts:
+
+ ```javascript
+ Promise.race([ajax('foo.json'), timeout(5000)])
+ ```
+
+ @method race
+ @static
+ @param {Array} promises array of promises to observe
+ Useful for tooling.
+ @return {Promise} a promise which settles in the same way as the first passed
+ promise to settle.
+*/
+function race$1(entries) {
+ /*jshint validthis:true */
+ var Constructor = this;
+
+ if (!isArray(entries)) {
+ return new Constructor(function (_, reject) {
+ return reject(new TypeError('You must pass an array to race.'));
+ });
+ } else {
+ return new Constructor(function (resolve, reject) {
+ var length = entries.length;
+ for (var i = 0; i < length; i++) {
+ Constructor.resolve(entries[i]).then(resolve, reject);
+ }
+ });
+ }
+}
+
+/**
+ `Promise.reject` returns a promise rejected with the passed `reason`.
+ It is shorthand for the following:
+
+ ```javascript
+ let promise = new Promise(function(resolve, reject){
+ reject(new Error('WHOOPS'));
+ });
+
+ promise.then(function(value){
+ // Code here doesn't run because the promise is rejected!
+ }, function(reason){
+ // reason.message === 'WHOOPS'
+ });
+ ```
+
+ Instead of writing the above, your code now simply becomes the following:
+
+ ```javascript
+ let promise = Promise.reject(new Error('WHOOPS'));
+
+ promise.then(function(value){
+ // Code here doesn't run because the promise is rejected!
+ }, function(reason){
+ // reason.message === 'WHOOPS'
+ });
+ ```
+
+ @method reject
+ @static
+ @param {Any} reason value that the returned promise will be rejected with.
+ Useful for tooling.
+ @return {Promise} a promise rejected with the given `reason`.
+*/
+function reject$1(reason) {
+ /*jshint validthis:true */
+ var Constructor = this;
+ var promise = new Constructor(noop);
+ reject(promise, reason);
+ return promise;
+}
+
+function needsResolver() {
+ throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
+}
+
+function needsNew() {
+ throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
+}
+
+/**
+ Promise objects represent the eventual result of an asynchronous operation. The
+ primary way of interacting with a promise is through its `then` method, which
+ registers callbacks to receive either a promise's eventual value or the reason
+ why the promise cannot be fulfilled.
+
+ Terminology
+ -----------
+
+ - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
+ - `thenable` is an object or function that defines a `then` method.
+ - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
+ - `exception` is a value that is thrown using the throw statement.
+ - `reason` is a value that indicates why a promise was rejected.
+ - `settled` the final resting state of a promise, fulfilled or rejected.
+
+ A promise can be in one of three states: pending, fulfilled, or rejected.
+
+ Promises that are fulfilled have a fulfillment value and are in the fulfilled
+ state. Promises that are rejected have a rejection reason and are in the
+ rejected state. A fulfillment value is never a thenable.
+
+ Promises can also be said to *resolve* a value. If this value is also a
+ promise, then the original promise's settled state will match the value's
+ settled state. So a promise that *resolves* a promise that rejects will
+ itself reject, and a promise that *resolves* a promise that fulfills will
+ itself fulfill.
+
+
+ Basic Usage:
+ ------------
+
+ ```js
+ let promise = new Promise(function(resolve, reject) {
+ // on success
+ resolve(value);
+
+ // on failure
+ reject(reason);
+ });
+
+ promise.then(function(value) {
+ // on fulfillment
+ }, function(reason) {
+ // on rejection
+ });
+ ```
+
+ Advanced Usage:
+ ---------------
+
+ Promises shine when abstracting away asynchronous interactions such as
+ `XMLHttpRequest`s.
+
+ ```js
+ function getJSON(url) {
+ return new Promise(function(resolve, reject){
+ let xhr = new XMLHttpRequest();
+
+ xhr.open('GET', url);
+ xhr.onreadystatechange = handler;
+ xhr.responseType = 'json';
+ xhr.setRequestHeader('Accept', 'application/json');
+ xhr.send();
+
+ function handler() {
+ if (this.readyState === this.DONE) {
+ if (this.status === 200) {
+ resolve(this.response);
+ } else {
+ reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
+ }
+ }
+ };
+ });
+ }
+
+ getJSON('/posts.json').then(function(json) {
+ // on fulfillment
+ }, function(reason) {
+ // on rejection
+ });
+ ```
+
+ Unlike callbacks, promises are great composable primitives.
+
+ ```js
+ Promise.all([
+ getJSON('/posts'),
+ getJSON('/comments')
+ ]).then(function(values){
+ values[0] // => postsJSON
+ values[1] // => commentsJSON
+
+ return values;
+ });
+ ```
+
+ @class Promise
+ @param {function} resolver
+ Useful for tooling.
+ @constructor
+*/
+function Promise$2(resolver) {
+ this[PROMISE_ID] = nextId();
+ this._result = this._state = undefined;
+ this._subscribers = [];
+
+ if (noop !== resolver) {
+ typeof resolver !== 'function' && needsResolver();
+ this instanceof Promise$2 ? initializePromise(this, resolver) : needsNew();
+ }
+}
+
+Promise$2.all = all$1;
+Promise$2.race = race$1;
+Promise$2.resolve = resolve$1;
+Promise$2.reject = reject$1;
+Promise$2._setScheduler = setScheduler;
+Promise$2._setAsap = setAsap;
+Promise$2._asap = asap;
+
+Promise$2.prototype = {
+ constructor: Promise$2,
+
+ /**
+ The primary way of interacting with a promise is through its `then` method,
+ which registers callbacks to receive either a promise's eventual value or the
+ reason why the promise cannot be fulfilled.
+
+ ```js
+ findUser().then(function(user){
+ // user is available
+ }, function(reason){
+ // user is unavailable, and you are given the reason why
+ });
+ ```
+
+ Chaining
+ --------
+
+ The return value of `then` is itself a promise. This second, 'downstream'
+ promise is resolved with the return value of the first promise's fulfillment
+ or rejection handler, or rejected if the handler throws an exception.
+
+ ```js
+ findUser().then(function (user) {
+ return user.name;
+ }, function (reason) {
+ return 'default name';
+ }).then(function (userName) {
+ // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
+ // will be `'default name'`
+ });
+
+ findUser().then(function (user) {
+ throw new Error('Found user, but still unhappy');
+ }, function (reason) {
+ throw new Error('`findUser` rejected and we're unhappy');
+ }).then(function (value) {
+ // never reached
+ }, function (reason) {
+ // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
+ // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
+ });
+ ```
+ If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
+
+ ```js
+ findUser().then(function (user) {
+ throw new PedagogicalException('Upstream error');
+ }).then(function (value) {
+ // never reached
+ }).then(function (value) {
+ // never reached
+ }, function (reason) {
+ // The `PedgagocialException` is propagated all the way down to here
+ });
+ ```
+
+ Assimilation
+ ------------
+
+ Sometimes the value you want to propagate to a downstream promise can only be
+ retrieved asynchronously. This can be achieved by returning a promise in the
+ fulfillment or rejection handler. The downstream promise will then be pending
+ until the returned promise is settled. This is called *assimilation*.
+
+ ```js
+ findUser().then(function (user) {
+ return findCommentsByAuthor(user);
+ }).then(function (comments) {
+ // The user's comments are now available
+ });
+ ```
+
+ If the assimliated promise rejects, then the downstream promise will also reject.
+
+ ```js
+ findUser().then(function (user) {
+ return findCommentsByAuthor(user);
+ }).then(function (comments) {
+ // If `findCommentsByAuthor` fulfills, we'll have the value here
+ }, function (reason) {
+ // If `findCommentsByAuthor` rejects, we'll have the reason here
+ });
+ ```
+
+ Simple Example
+ --------------
+
+ Synchronous Example
+
+ ```javascript
+ let result;
+
+ try {
+ result = findResult();
+ // success
+ } catch(reason) {
+ // failure
+ }
+ ```
+
+ Errback Example
+
+ ```js
+ findResult(function(result, err){
+ if (err) {
+ // failure
+ } else {
+ // success
+ }
+ });
+ ```
+
+ Promise Example;
+
+ ```javascript
+ findResult().then(function(result){
+ // success
+ }, function(reason){
+ // failure
+ });
+ ```
+
+ Advanced Example
+ --------------
+
+ Synchronous Example
+
+ ```javascript
+ let author, books;
+
+ try {
+ author = findAuthor();
+ books = findBooksByAuthor(author);
+ // success
+ } catch(reason) {
+ // failure
+ }
+ ```
+
+ Errback Example
+
+ ```js
+
+ function foundBooks(books) {
+
+ }
+
+ function failure(reason) {
+
+ }
+
+ findAuthor(function(author, err){
+ if (err) {
+ failure(err);
+ // failure
+ } else {
+ try {
+ findBoooksByAuthor(author, function(books, err) {
+ if (err) {
+ failure(err);
+ } else {
+ try {
+ foundBooks(books);
+ } catch(reason) {
+ failure(reason);
+ }
+ }
+ });
+ } catch(error) {
+ failure(err);
+ }
+ // success
+ }
+ });
+ ```
+
+ Promise Example;
+
+ ```javascript
+ findAuthor().
+ then(findBooksByAuthor).
+ then(function(books){
+ // found books
+ }).catch(function(reason){
+ // something went wrong
+ });
+ ```
+
+ @method then
+ @param {Function} onFulfilled
+ @param {Function} onRejected
+ Useful for tooling.
+ @return {Promise}
+ */
+ then: then,
+
+ /**
+ `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
+ as the catch block of a try/catch statement.
+
+ ```js
+ function findAuthor(){
+ throw new Error('couldn't find that author');
+ }
+
+ // synchronous
+ try {
+ findAuthor();
+ } catch(reason) {
+ // something went wrong
+ }
+
+ // async with promises
+ findAuthor().catch(function(reason){
+ // something went wrong
+ });
+ ```
+
+ @method catch
+ @param {Function} onRejection
+ Useful for tooling.
+ @return {Promise}
+ */
+ 'catch': function _catch(onRejection) {
+ return this.then(null, onRejection);
+ }
+};
+
+/*global self*/
+function polyfill$1() {
+ var local = undefined;
+
+ if (typeof global !== 'undefined') {
+ local = global;
+ } else if (typeof self !== 'undefined') {
+ local = self;
+ } else {
+ try {
+ local = Function('return this')();
+ } catch (e) {
+ throw new Error('polyfill failed because global object is unavailable in this environment');
+ }
+ }
+
+ var P = local.Promise;
+
+ if (P) {
+ var promiseToString = null;
+ try {
+ promiseToString = Object.prototype.toString.call(P.resolve());
+ } catch (e) {
+ // silently ignored
+ }
+
+ if (promiseToString === '[object Promise]' && !P.cast) {
+ return;
+ }
+ }
+
+ local.Promise = Promise$2;
+}
+
+// Strange compat..
+Promise$2.polyfill = polyfill$1;
+Promise$2.Promise = Promise$2;
+
+return Promise$2;
+
+})));
+
+
+
+}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"_process":3}],3:[function(_dereq_,module,exports){
+// shim for using process in browser
+var process = module.exports = {};
+
+// cached from whatever global is present so that test runners that stub it
+// don't break things. But we need to wrap it in a try catch in case it is
+// wrapped in strict mode code which doesn't define any globals. It's inside a
+// function because try/catches deoptimize in certain engines.
+
+var cachedSetTimeout;
+var cachedClearTimeout;
+
+function defaultSetTimout() {
+ throw new Error('setTimeout has not been defined');
+}
+function defaultClearTimeout () {
+ throw new Error('clearTimeout has not been defined');
+}
+(function () {
+ try {
+ if (typeof setTimeout === 'function') {
+ cachedSetTimeout = setTimeout;
+ } else {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ } catch (e) {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ try {
+ if (typeof clearTimeout === 'function') {
+ cachedClearTimeout = clearTimeout;
+ } else {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+ } catch (e) {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+} ())
+function runTimeout(fun) {
+ if (cachedSetTimeout === setTimeout) {
+ //normal enviroments in sane situations
+ return setTimeout(fun, 0);
+ }
+ // if setTimeout wasn't available but was latter defined
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
+ cachedSetTimeout = setTimeout;
+ return setTimeout(fun, 0);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedSetTimeout(fun, 0);
+ } catch(e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedSetTimeout.call(null, fun, 0);
+ } catch(e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
+ return cachedSetTimeout.call(this, fun, 0);
+ }
+ }
+
+
+}
+function runClearTimeout(marker) {
+ if (cachedClearTimeout === clearTimeout) {
+ //normal enviroments in sane situations
+ return clearTimeout(marker);
+ }
+ // if clearTimeout wasn't available but was latter defined
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
+ cachedClearTimeout = clearTimeout;
+ return clearTimeout(marker);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedClearTimeout(marker);
+ } catch (e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedClearTimeout.call(null, marker);
+ } catch (e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
+ return cachedClearTimeout.call(this, marker);
+ }
+ }
+
+
+
+}
+var queue = [];
+var draining = false;
+var currentQueue;
+var queueIndex = -1;
+
+function cleanUpNextTick() {
+ if (!draining || !currentQueue) {
+ return;
+ }
+ draining = false;
+ if (currentQueue.length) {
+ queue = currentQueue.concat(queue);
+ } else {
+ queueIndex = -1;
+ }
+ if (queue.length) {
+ drainQueue();
+ }
+}
+
+function drainQueue() {
+ if (draining) {
+ return;
+ }
+ var timeout = runTimeout(cleanUpNextTick);
+ draining = true;
+
+ var len = queue.length;
+ while(len) {
+ currentQueue = queue;
+ queue = [];
+ while (++queueIndex < len) {
+ if (currentQueue) {
+ currentQueue[queueIndex].run();
+ }
+ }
+ queueIndex = -1;
+ len = queue.length;
+ }
+ currentQueue = null;
+ draining = false;
+ runClearTimeout(timeout);
+}
+
+process.nextTick = function (fun) {
+ var args = new Array(arguments.length - 1);
+ if (arguments.length > 1) {
+ for (var i = 1; i < arguments.length; i++) {
+ args[i - 1] = arguments[i];
+ }
+ }
+ queue.push(new Item(fun, args));
+ if (queue.length === 1 && !draining) {
+ runTimeout(drainQueue);
+ }
+};
+
+// v8 likes predictible objects
+function Item(fun, array) {
+ this.fun = fun;
+ this.array = array;
+}
+Item.prototype.run = function () {
+ this.fun.apply(null, this.array);
+};
+process.title = 'browser';
+process.browser = true;
+process.env = {};
+process.argv = [];
+process.version = ''; // empty string to avoid regexp issues
+process.versions = {};
+
+function noop() {}
+
+process.on = noop;
+process.addListener = noop;
+process.once = noop;
+process.off = noop;
+process.removeListener = noop;
+process.removeAllListeners = noop;
+process.emit = noop;
+process.prependListener = noop;
+process.prependOnceListener = noop;
+
+process.listeners = function (name) { return [] }
+
+process.binding = function (name) {
+ throw new Error('process.binding is not supported');
+};
+
+process.cwd = function () { return '/' };
+process.chdir = function (dir) {
+ throw new Error('process.chdir is not supported');
+};
+process.umask = function() { return 0; };
+
+},{}],4:[function(_dereq_,module,exports){
+(function (global){
+(function () {
+ function Rusha(chunkSize) {
+ 'use strict';
+ var util = {
+ getDataType: function (data) {
+ if (typeof data === 'string') {
+ return 'string';
+ }
+ if (data instanceof Array) {
+ return 'array';
+ }
+ if (typeof global !== 'undefined' && global.Buffer && global.Buffer.isBuffer(data)) {
+ return 'buffer';
+ }
+ if (data instanceof ArrayBuffer) {
+ return 'arraybuffer';
+ }
+ if (data.buffer instanceof ArrayBuffer) {
+ return 'view';
+ }
+ if (data instanceof Blob) {
+ return 'blob';
+ }
+ throw new Error('Unsupported data type.');
+ }
+ };
+ var // Private object structure.
+ self$2 = { fill: 0 };
+ var // Calculate the length of buffer that the sha1 routine uses
+ // including the padding.
+ padlen = function (len) {
+ for (len += 9; len % 64 > 0; len += 1);
+ return len;
+ };
+ var padZeroes = function (bin, len) {
+ var h8 = new Uint8Array(bin.buffer);
+ var om = len % 4, align = len - om;
+ switch (om) {
+ case 0:
+ h8[align + 3] = 0;
+ case 1:
+ h8[align + 2] = 0;
+ case 2:
+ h8[align + 1] = 0;
+ case 3:
+ h8[align + 0] = 0;
+ }
+ for (var i$2 = (len >> 2) + 1; i$2 < bin.length; i$2++)
+ bin[i$2] = 0;
+ };
+ var padData = function (bin, chunkLen, msgLen) {
+ bin[chunkLen >> 2] |= 128 << 24 - (chunkLen % 4 << 3);
+ // To support msgLen >= 2 GiB, use a float division when computing the
+ // high 32-bits of the big-endian message length in bits.
+ bin[((chunkLen >> 2) + 2 & ~15) + 14] = msgLen / (1 << 29) | 0;
+ bin[((chunkLen >> 2) + 2 & ~15) + 15] = msgLen << 3;
+ };
+ var // Convert a binary string and write it to the heap.
+ // A binary string is expected to only contain char codes < 256.
+ convStr = function (H8, H32, start, len, off) {
+ var str = this, i$2, om = off % 4, lm = (len + om) % 4, j = len - lm;
+ switch (om) {
+ case 0:
+ H8[off] = str.charCodeAt(start + 3);
+ case 1:
+ H8[off + 1 - (om << 1) | 0] = str.charCodeAt(start + 2);
+ case 2:
+ H8[off + 2 - (om << 1) | 0] = str.charCodeAt(start + 1);
+ case 3:
+ H8[off + 3 - (om << 1) | 0] = str.charCodeAt(start);
+ }
+ if (len < lm + om) {
+ return;
+ }
+ for (i$2 = 4 - om; i$2 < j; i$2 = i$2 + 4 | 0) {
+ H32[off + i$2 >> 2] = str.charCodeAt(start + i$2) << 24 | str.charCodeAt(start + i$2 + 1) << 16 | str.charCodeAt(start + i$2 + 2) << 8 | str.charCodeAt(start + i$2 + 3);
+ }
+ switch (lm) {
+ case 3:
+ H8[off + j + 1 | 0] = str.charCodeAt(start + j + 2);
+ case 2:
+ H8[off + j + 2 | 0] = str.charCodeAt(start + j + 1);
+ case 1:
+ H8[off + j + 3 | 0] = str.charCodeAt(start + j);
+ }
+ };
+ var // Convert a buffer or array and write it to the heap.
+ // The buffer or array is expected to only contain elements < 256.
+ convBuf = function (H8, H32, start, len, off) {
+ var buf = this, i$2, om = off % 4, lm = (len + om) % 4, j = len - lm;
+ switch (om) {
+ case 0:
+ H8[off] = buf[start + 3];
+ case 1:
+ H8[off + 1 - (om << 1) | 0] = buf[start + 2];
+ case 2:
+ H8[off + 2 - (om << 1) | 0] = buf[start + 1];
+ case 3:
+ H8[off + 3 - (om << 1) | 0] = buf[start];
+ }
+ if (len < lm + om) {
+ return;
+ }
+ for (i$2 = 4 - om; i$2 < j; i$2 = i$2 + 4 | 0) {
+ H32[off + i$2 >> 2 | 0] = buf[start + i$2] << 24 | buf[start + i$2 + 1] << 16 | buf[start + i$2 + 2] << 8 | buf[start + i$2 + 3];
+ }
+ switch (lm) {
+ case 3:
+ H8[off + j + 1 | 0] = buf[start + j + 2];
+ case 2:
+ H8[off + j + 2 | 0] = buf[start + j + 1];
+ case 1:
+ H8[off + j + 3 | 0] = buf[start + j];
+ }
+ };
+ var convBlob = function (H8, H32, start, len, off) {
+ var blob = this, i$2, om = off % 4, lm = (len + om) % 4, j = len - lm;
+ var buf = new Uint8Array(reader.readAsArrayBuffer(blob.slice(start, start + len)));
+ switch (om) {
+ case 0:
+ H8[off] = buf[3];
+ case 1:
+ H8[off + 1 - (om << 1) | 0] = buf[2];
+ case 2:
+ H8[off + 2 - (om << 1) | 0] = buf[1];
+ case 3:
+ H8[off + 3 - (om << 1) | 0] = buf[0];
+ }
+ if (len < lm + om) {
+ return;
+ }
+ for (i$2 = 4 - om; i$2 < j; i$2 = i$2 + 4 | 0) {
+ H32[off + i$2 >> 2 | 0] = buf[i$2] << 24 | buf[i$2 + 1] << 16 | buf[i$2 + 2] << 8 | buf[i$2 + 3];
+ }
+ switch (lm) {
+ case 3:
+ H8[off + j + 1 | 0] = buf[j + 2];
+ case 2:
+ H8[off + j + 2 | 0] = buf[j + 1];
+ case 1:
+ H8[off + j + 3 | 0] = buf[j];
+ }
+ };
+ var convFn = function (data) {
+ switch (util.getDataType(data)) {
+ case 'string':
+ return convStr.bind(data);
+ case 'array':
+ return convBuf.bind(data);
+ case 'buffer':
+ return convBuf.bind(data);
+ case 'arraybuffer':
+ return convBuf.bind(new Uint8Array(data));
+ case 'view':
+ return convBuf.bind(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
+ case 'blob':
+ return convBlob.bind(data);
+ }
+ };
+ var slice = function (data, offset) {
+ switch (util.getDataType(data)) {
+ case 'string':
+ return data.slice(offset);
+ case 'array':
+ return data.slice(offset);
+ case 'buffer':
+ return data.slice(offset);
+ case 'arraybuffer':
+ return data.slice(offset);
+ case 'view':
+ return data.buffer.slice(offset);
+ }
+ };
+ var // Precompute 00 - ff strings
+ precomputedHex = new Array(256);
+ for (var i = 0; i < 256; i++) {
+ precomputedHex[i] = (i < 16 ? '0' : '') + i.toString(16);
+ }
+ var // Convert an ArrayBuffer into its hexadecimal string representation.
+ hex = function (arrayBuffer) {
+ var binarray = new Uint8Array(arrayBuffer);
+ var res = new Array(arrayBuffer.byteLength);
+ for (var i$2 = 0; i$2 < res.length; i$2++) {
+ res[i$2] = precomputedHex[binarray[i$2]];
+ }
+ return res.join('');
+ };
+ var ceilHeapSize = function (v) {
+ // The asm.js spec says:
+ // The heap object's byteLength must be either
+ // 2^n for n in [12, 24) or 2^24 * n for n ≥ 1.
+ // Also, byteLengths smaller than 2^16 are deprecated.
+ var p;
+ if (// If v is smaller than 2^16, the smallest possible solution
+ // is 2^16.
+ v <= 65536)
+ return 65536;
+ if (// If v < 2^24, we round up to 2^n,
+ // otherwise we round up to 2^24 * n.
+ v < 16777216) {
+ for (p = 1; p < v; p = p << 1);
+ } else {
+ for (p = 16777216; p < v; p += 16777216);
+ }
+ return p;
+ };
+ var // Initialize the internal data structures to a new capacity.
+ init = function (size) {
+ if (size % 64 > 0) {
+ throw new Error('Chunk size must be a multiple of 128 bit');
+ }
+ self$2.offset = 0;
+ self$2.maxChunkLen = size;
+ self$2.padMaxChunkLen = padlen(size);
+ // The size of the heap is the sum of:
+ // 1. The padded input message size
+ // 2. The extended space the algorithm needs (320 byte)
+ // 3. The 160 bit state the algoritm uses
+ self$2.heap = new ArrayBuffer(ceilHeapSize(self$2.padMaxChunkLen + 320 + 20));
+ self$2.h32 = new Int32Array(self$2.heap);
+ self$2.h8 = new Int8Array(self$2.heap);
+ self$2.core = new Rusha._core({
+ Int32Array: Int32Array,
+ DataView: DataView
+ }, {}, self$2.heap);
+ self$2.buffer = null;
+ };
+ // Iinitializethe datastructures according
+ // to a chunk siyze.
+ init(chunkSize || 64 * 1024);
+ var initState = function (heap, padMsgLen) {
+ self$2.offset = 0;
+ var io = new Int32Array(heap, padMsgLen + 320, 5);
+ io[0] = 1732584193;
+ io[1] = -271733879;
+ io[2] = -1732584194;
+ io[3] = 271733878;
+ io[4] = -1009589776;
+ };
+ var padChunk = function (chunkLen, msgLen) {
+ var padChunkLen = padlen(chunkLen);
+ var view = new Int32Array(self$2.heap, 0, padChunkLen >> 2);
+ padZeroes(view, chunkLen);
+ padData(view, chunkLen, msgLen);
+ return padChunkLen;
+ };
+ var // Write data to the heap.
+ write = function (data, chunkOffset, chunkLen, off) {
+ convFn(data)(self$2.h8, self$2.h32, chunkOffset, chunkLen, off || 0);
+ };
+ var // Initialize and call the RushaCore,
+ // assuming an input buffer of length len * 4.
+ coreCall = function (data, chunkOffset, chunkLen, msgLen, finalize) {
+ var padChunkLen = chunkLen;
+ write(data, chunkOffset, chunkLen);
+ if (finalize) {
+ padChunkLen = padChunk(chunkLen, msgLen);
+ }
+ self$2.core.hash(padChunkLen, self$2.padMaxChunkLen);
+ };
+ var getRawDigest = function (heap, padMaxChunkLen) {
+ var io = new Int32Array(heap, padMaxChunkLen + 320, 5);
+ var out = new Int32Array(5);
+ var arr = new DataView(out.buffer);
+ arr.setInt32(0, io[0], false);
+ arr.setInt32(4, io[1], false);
+ arr.setInt32(8, io[2], false);
+ arr.setInt32(12, io[3], false);
+ arr.setInt32(16, io[4], false);
+ return out;
+ };
+ var // Calculate the hash digest as an array of 5 32bit integers.
+ rawDigest = this.rawDigest = function (str) {
+ var msgLen = str.byteLength || str.length || str.size || 0;
+ initState(self$2.heap, self$2.padMaxChunkLen);
+ var chunkOffset = 0, chunkLen = self$2.maxChunkLen;
+ for (chunkOffset = 0; msgLen > chunkOffset + chunkLen; chunkOffset += chunkLen) {
+ coreCall(str, chunkOffset, chunkLen, msgLen, false);
+ }
+ coreCall(str, chunkOffset, msgLen - chunkOffset, msgLen, true);
+ return getRawDigest(self$2.heap, self$2.padMaxChunkLen);
+ };
+ // The digest and digestFrom* interface returns the hash digest
+ // as a hex string.
+ this.digest = this.digestFromString = this.digestFromBuffer = this.digestFromArrayBuffer = function (str) {
+ return hex(rawDigest(str).buffer);
+ };
+ this.resetState = function () {
+ initState(self$2.heap, self$2.padMaxChunkLen);
+ return this;
+ };
+ this.append = function (chunk) {
+ var chunkOffset = 0;
+ var chunkLen = chunk.byteLength || chunk.length || chunk.size || 0;
+ var turnOffset = self$2.offset % self$2.maxChunkLen;
+ var inputLen;
+ self$2.offset += chunkLen;
+ while (chunkOffset < chunkLen) {
+ inputLen = Math.min(chunkLen - chunkOffset, self$2.maxChunkLen - turnOffset);
+ write(chunk, chunkOffset, inputLen, turnOffset);
+ turnOffset += inputLen;
+ chunkOffset += inputLen;
+ if (turnOffset === self$2.maxChunkLen) {
+ self$2.core.hash(self$2.maxChunkLen, self$2.padMaxChunkLen);
+ turnOffset = 0;
+ }
+ }
+ return this;
+ };
+ this.getState = function () {
+ var turnOffset = self$2.offset % self$2.maxChunkLen;
+ var heap;
+ if (!turnOffset) {
+ var io = new Int32Array(self$2.heap, self$2.padMaxChunkLen + 320, 5);
+ heap = io.buffer.slice(io.byteOffset, io.byteOffset + io.byteLength);
+ } else {
+ heap = self$2.heap.slice(0);
+ }
+ return {
+ offset: self$2.offset,
+ heap: heap
+ };
+ };
+ this.setState = function (state) {
+ self$2.offset = state.offset;
+ if (state.heap.byteLength === 20) {
+ var io = new Int32Array(self$2.heap, self$2.padMaxChunkLen + 320, 5);
+ io.set(new Int32Array(state.heap));
+ } else {
+ self$2.h32.set(new Int32Array(state.heap));
+ }
+ return this;
+ };
+ var rawEnd = this.rawEnd = function () {
+ var msgLen = self$2.offset;
+ var chunkLen = msgLen % self$2.maxChunkLen;
+ var padChunkLen = padChunk(chunkLen, msgLen);
+ self$2.core.hash(padChunkLen, self$2.padMaxChunkLen);
+ var result = getRawDigest(self$2.heap, self$2.padMaxChunkLen);
+ initState(self$2.heap, self$2.padMaxChunkLen);
+ return result;
+ };
+ this.end = function () {
+ return hex(rawEnd().buffer);
+ };
+ }
+ ;
+ // The low-level RushCore module provides the heart of Rusha,
+ // a high-speed sha1 implementation working on an Int32Array heap.
+ // At first glance, the implementation seems complicated, however
+ // with the SHA1 spec at hand, it is obvious this almost a textbook
+ // implementation that has a few functions hand-inlined and a few loops
+ // hand-unrolled.
+ Rusha._core = function RushaCore(stdlib, foreign, heap) {
+ 'use asm';
+ var H = new stdlib.Int32Array(heap);
+ function hash(k, x) {
+ // k in bytes
+ k = k | 0;
+ x = x | 0;
+ var i = 0, j = 0, y0 = 0, z0 = 0, y1 = 0, z1 = 0, y2 = 0, z2 = 0, y3 = 0, z3 = 0, y4 = 0, z4 = 0, t0 = 0, t1 = 0;
+ y0 = H[x + 320 >> 2] | 0;
+ y1 = H[x + 324 >> 2] | 0;
+ y2 = H[x + 328 >> 2] | 0;
+ y3 = H[x + 332 >> 2] | 0;
+ y4 = H[x + 336 >> 2] | 0;
+ for (i = 0; (i | 0) < (k | 0); i = i + 64 | 0) {
+ z0 = y0;
+ z1 = y1;
+ z2 = y2;
+ z3 = y3;
+ z4 = y4;
+ for (j = 0; (j | 0) < 64; j = j + 4 | 0) {
+ t1 = H[i + j >> 2] | 0;
+ t0 = ((y0 << 5 | y0 >>> 27) + (y1 & y2 | ~y1 & y3) | 0) + ((t1 + y4 | 0) + 1518500249 | 0) | 0;
+ y4 = y3;
+ y3 = y2;
+ y2 = y1 << 30 | y1 >>> 2;
+ y1 = y0;
+ y0 = t0;
+ H[k + j >> 2] = t1;
+ }
+ for (j = k + 64 | 0; (j | 0) < (k + 80 | 0); j = j + 4 | 0) {
+ t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
+ t0 = ((y0 << 5 | y0 >>> 27) + (y1 & y2 | ~y1 & y3) | 0) + ((t1 + y4 | 0) + 1518500249 | 0) | 0;
+ y4 = y3;
+ y3 = y2;
+ y2 = y1 << 30 | y1 >>> 2;
+ y1 = y0;
+ y0 = t0;
+ H[j >> 2] = t1;
+ }
+ for (j = k + 80 | 0; (j | 0) < (k + 160 | 0); j = j + 4 | 0) {
+ t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
+ t0 = ((y0 << 5 | y0 >>> 27) + (y1 ^ y2 ^ y3) | 0) + ((t1 + y4 | 0) + 1859775393 | 0) | 0;
+ y4 = y3;
+ y3 = y2;
+ y2 = y1 << 30 | y1 >>> 2;
+ y1 = y0;
+ y0 = t0;
+ H[j >> 2] = t1;
+ }
+ for (j = k + 160 | 0; (j | 0) < (k + 240 | 0); j = j + 4 | 0) {
+ t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
+ t0 = ((y0 << 5 | y0 >>> 27) + (y1 & y2 | y1 & y3 | y2 & y3) | 0) + ((t1 + y4 | 0) - 1894007588 | 0) | 0;
+ y4 = y3;
+ y3 = y2;
+ y2 = y1 << 30 | y1 >>> 2;
+ y1 = y0;
+ y0 = t0;
+ H[j >> 2] = t1;
+ }
+ for (j = k + 240 | 0; (j | 0) < (k + 320 | 0); j = j + 4 | 0) {
+ t1 = (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) << 1 | (H[j - 12 >> 2] ^ H[j - 32 >> 2] ^ H[j - 56 >> 2] ^ H[j - 64 >> 2]) >>> 31;
+ t0 = ((y0 << 5 | y0 >>> 27) + (y1 ^ y2 ^ y3) | 0) + ((t1 + y4 | 0) - 899497514 | 0) | 0;
+ y4 = y3;
+ y3 = y2;
+ y2 = y1 << 30 | y1 >>> 2;
+ y1 = y0;
+ y0 = t0;
+ H[j >> 2] = t1;
+ }
+ y0 = y0 + z0 | 0;
+ y1 = y1 + z1 | 0;
+ y2 = y2 + z2 | 0;
+ y3 = y3 + z3 | 0;
+ y4 = y4 + z4 | 0;
+ }
+ H[x + 320 >> 2] = y0;
+ H[x + 324 >> 2] = y1;
+ H[x + 328 >> 2] = y2;
+ H[x + 332 >> 2] = y3;
+ H[x + 336 >> 2] = y4;
+ }
+ return { hash: hash };
+ };
+ if (// If we'e running in Node.JS, export a module.
+ typeof module !== 'undefined') {
+ module.exports = Rusha;
+ } else if (// If we're running in a DOM context, export
+ // the Rusha object to toplevel.
+ typeof window !== 'undefined') {
+ window.Rusha = Rusha;
+ }
+ if (// If we're running in a webworker, accept
+ // messages containing a jobid and a buffer
+ // or blob object, and return the hash result.
+ typeof FileReaderSync !== 'undefined') {
+ var reader = new FileReaderSync();
+ var hashData = function hash(hasher, data, cb) {
+ try {
+ return cb(null, hasher.digest(data));
+ } catch (e) {
+ return cb(e);
+ }
+ };
+ var hashFile = function hashArrayBuffer(hasher, readTotal, blockSize, file, cb) {
+ var reader$2 = new self.FileReader();
+ reader$2.onloadend = function onloadend() {
+ var buffer = reader$2.result;
+ readTotal += reader$2.result.byteLength;
+ try {
+ hasher.append(buffer);
+ } catch (e) {
+ cb(e);
+ return;
+ }
+ if (readTotal < file.size) {
+ hashFile(hasher, readTotal, blockSize, file, cb);
+ } else {
+ cb(null, hasher.end());
+ }
+ };
+ reader$2.readAsArrayBuffer(file.slice(readTotal, readTotal + blockSize));
+ };
+ self.onmessage = function onMessage(event) {
+ var data = event.data.data, file = event.data.file, id = event.data.id;
+ if (typeof id === 'undefined')
+ return;
+ if (!file && !data)
+ return;
+ var blockSize = event.data.blockSize || 4 * 1024 * 1024;
+ var hasher = new Rusha(blockSize);
+ hasher.resetState();
+ var done = function done$2(err, hash) {
+ if (!err) {
+ self.postMessage({
+ id: id,
+ hash: hash
+ });
+ } else {
+ self.postMessage({
+ id: id,
+ error: err.name
+ });
+ }
+ };
+ if (data)
+ hashData(hasher, data, done);
+ if (file)
+ hashFile(hasher, 0, blockSize, file, done);
+ };
+ }
+}());
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{}],5:[function(_dereq_,module,exports){
+// GPG4Browsers - An OpenPGP implementation in javascript
+// Copyright (C) 2011 Recurity Labs GmbH
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 3.0 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+/**
+ * @requires config
+ * @requires encoding/armor
+ * @requires enums
+ * @requires packet
+ * @module cleartext
+ */
+
+'use strict';
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.CleartextMessage = CleartextMessage;
+exports.readArmored = readArmored;
+
+var _config = _dereq_('./config');
+
+var _config2 = _interopRequireDefault(_config);
+
+var _packet = _dereq_('./packet');
+
+var _packet2 = _interopRequireDefault(_packet);
+
+var _enums = _dereq_('./enums.js');
+
+var _enums2 = _interopRequireDefault(_enums);
+
+var _armor = _dereq_('./encoding/armor.js');
+
+var _armor2 = _interopRequireDefault(_armor);
+
+var _signature = _dereq_('./signature.js');
+
+var sigModule = _interopRequireWildcard(_signature);
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * @class
+ * @classdesc Class that represents an OpenPGP cleartext signed message.
+ * See {@link http://tools.ietf.org/html/rfc4880#section-7}
+ * @param {String} text The cleartext of the signed message
+ * @param {module:signature} signature The detached signature or an empty signature if message not yet signed
+ */
+
+function CleartextMessage(text, signature) {
+ if (!(this instanceof CleartextMessage)) {
+ return new CleartextMessage(text, signature);
+ }
+ // normalize EOL to canonical form =a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
+a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:throw"invalid length: "+a;}}var d=[],c,f;for(c=3;258>=c;c++)f=e(c),d[c]=f[2]<<24|
+f[1]<<16|f[0];return d}(),Ga=C?new Uint32Array(Fa):Fa;
+function na(e,d){function c(a,c){var b=a.g,d=[],f=0,e;e=Ga[a.length];d[f++]=e&65535;d[f++]=e>>16&255;d[f++]=e>>24;var g;switch(u){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b-
+65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>=
+b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:throw"invalid distance";}e=g;d[f++]=e[0];d[f++]=e[1];d[f++]=e[2];var k,m;k=0;for(m=d.length;k=U?8:255>=U?9:279>=U?7:8;var ba=u(P),V=new (t?Uint8Array:Array)(30),W,ea;W=0;for(ea=V.length;Wf&&(b=e,f=g);if(258===g)break}return new ua(f,a-b)}
+function ra(d,a){var c=d.length,e=new ja(572),b=new (G?Uint8Array:Array)(c),f,g,h,k,p;if(!G)for(k=0;k
+ * Canonicalyzing the document by converting line endings. */
+ text: 1,
+ /** 0x02: Standalone signature.
+ * This signature is a signature of only its own subpacket contents.
+ * It is calculated identically to a signature over a zero-lengh
+ * binary document. Note that it doesn't make sense to have a V3
+ * standalone signature. */
+ standalone: 2,
+ /** 0x10: Generic certification of a User ID and Public-Key packet.
+ * The issuer of this certification does not make any particular
+ * assertion as to how well the certifier has checked that the owner
+ * of the key is in fact the person described by the User ID. */
+ cert_generic: 16,
+ /** 0x11: Persona certification of a User ID and Public-Key packet.
+ * The issuer of this certification has not done any verification of
+ * the claim that the owner of this key is the User ID specified. */
+ cert_persona: 17,
+ /** 0x12: Casual certification of a User ID and Public-Key packet.
+ * The issuer of this certification has done some casual
+ * verification of the claim of identity. */
+ cert_casual: 18,
+ /** 0x13: Positive certification of a User ID and Public-Key packet.
+ * The issuer of this certification has done substantial
+ * verification of the claim of identity.
+ *
+ * Most OpenPGP implementations make their "key signatures" as 0x10
+ * certifications. Some implementations can issue 0x11-0x13
+ * certifications, but few differentiate between the types. */
+ cert_positive: 19,
+ /** 0x30: Certification revocation signature
+ * This signature revokes an earlier User ID certification signature
+ * (signature class 0x10 through 0x13) or direct-key signature
+ * (0x1F). It should be issued by the same key that issued the
+ * revoked signature or an authorized revocation key. The signature
+ * is computed over the same data as the certificate that it
+ * revokes, and should have a later creation date than that
+ * certificate. */
+ cert_revocation: 48,
+ /** 0x18: Subkey Binding Signature
+ * This signature is a statement by the top-level signing key that
+ * indicates that it owns the subkey. This signature is calculated
+ * directly on the primary key and subkey, and not on any User ID or
+ * other packets. A signature that binds a signing subkey MUST have
+ * an Embedded Signature subpacket in this binding signature that
+ * contains a 0x19 signature made by the signing subkey on the
+ * primary key and subkey. */
+ subkey_binding: 24,
+ /** 0x19: Primary Key Binding Signature
+ * This signature is a statement by a signing subkey, indicating
+ * that it is owned by the primary key and subkey. This signature
+ * is calculated the same way as a 0x18 signature: directly on the
+ * primary key and subkey, and not on any User ID or other packets.
+ *
+ * When a signature is made over a key, the hash data starts with the
+ * octet 0x99, followed by a two-octet length of the key, and then body
+ * of the key packet. (Note that this is an old-style packet header for
+ * a key packet with two-octet length.) A subkey binding signature
+ * (type 0x18) or primary key binding signature (type 0x19) then hashes
+ * the subkey using the same format as the main key (also using 0x99 as
+ * the first octet). */
+ key_binding: 25,
+ /** 0x1F: Signature directly on a key
+ * This signature is calculated directly on a key. It binds the
+ * information in the Signature subpackets to the key, and is
+ * appropriate to be used for subpackets that provide information
+ * about the key, such as the Revocation Key subpacket. It is also
+ * appropriate for statements that non-self certifiers want to make
+ * about the key itself, rather than the binding between a key and a
+ * name. */
+ key: 31,
+ /** 0x20: Key revocation signature
+ * The signature is calculated directly on the key being revoked. A
+ * revoked key is not to be used. Only revocation signatures by the
+ * key being revoked, or by an authorized revocation key, should be
+ * considered valid revocation signatures.a */
+ key_revocation: 32,
+ /** 0x28: Subkey revocation signature
+ * The signature is calculated directly on the subkey being revoked.
+ * A revoked subkey is not to be used. Only revocation signatures
+ * by the top-level signature key that is bound to this subkey, or
+ * by an authorized revocation key, should be considered valid
+ * revocation signatures.
+ *
+ * Key revocation signatures (types 0x20 and 0x28)
+ * hash only the key being revoked. */
+ subkey_revocation: 40,
+ /** 0x40: Timestamp signature.
+ * This signature is only meaningful for the timestamp contained in
+ * it. */
+ timestamp: 64,
+ /** 0x50: Third-Party Confirmation signature.
+ * This signature is a signature over some other OpenPGP Signature
+ * packet(s). It is analogous to a notary seal on the signed data.
+ * A third-party signature SHOULD include Signature Target
+ * subpacket(s) to give easy identification. Note that we really do
+ * mean SHOULD. There are plausible uses for this (such as a blind
+ * party that only sees the signature, not the key or source
+ * document) that cannot include a target subpacket. */
+ third_party: 80
+ },
+
+ /** Signature subpacket type
+ * @enum {Integer}
+ * @readonly
+ */
+ signatureSubpacket: {
+ signature_creation_time: 2,
+ signature_expiration_time: 3,
+ exportable_certification: 4,
+ trust_signature: 5,
+ regular_expression: 6,
+ revocable: 7,
+ key_expiration_time: 9,
+ placeholder_backwards_compatibility: 10,
+ preferred_symmetric_algorithms: 11,
+ revocation_key: 12,
+ issuer: 16,
+ notation_data: 20,
+ preferred_hash_algorithms: 21,
+ preferred_compression_algorithms: 22,
+ key_server_preferences: 23,
+ preferred_key_server: 24,
+ primary_user_id: 25,
+ policy_uri: 26,
+ key_flags: 27,
+ signers_user_id: 28,
+ reason_for_revocation: 29,
+ features: 30,
+ signature_target: 31,
+ embedded_signature: 32
+ },
+
+ /** Key flags
+ * @enum {Integer}
+ * @readonly
+ */
+ keyFlags: {
+ /** 0x01 - This key may be used to certify other keys. */
+ certify_keys: 1,
+ /** 0x02 - This key may be used to sign data. */
+ sign_data: 2,
+ /** 0x04 - This key may be used to encrypt communications. */
+ encrypt_communication: 4,
+ /** 0x08 - This key may be used to encrypt storage. */
+ encrypt_storage: 8,
+ /** 0x10 - The private component of this key may have been split
+ * by a secret-sharing mechanism. */
+ split_private_key: 16,
+ /** 0x20 - This key may be used for authentication. */
+ authentication: 32,
+ /** 0x80 - The private component of this key may be in the
+ * possession of more than one person. */
+ shared_private_key: 128
+ },
+
+ /** Key status
+ * @enum {Integer}
+ * @readonly
+ */
+ keyStatus: {
+ invalid: 0,
+ expired: 1,
+ revoked: 2,
+ valid: 3,
+ no_self_cert: 4
+ },
+
+ /** Armor type
+ * @enum {Integer}
+ * @readonly
+ */
+ armor: {
+ multipart_section: 0,
+ multipart_last: 1,
+ signed: 2,
+ message: 3,
+ public_key: 4,
+ private_key: 5,
+ signature: 6
+ },
+
+ /** Asserts validity and converts from string/integer to integer. */
+ write: function write(type, e) {
+ if (typeof e === 'number') {
+ e = this.read(type, e);
+ }
+
+ if (type[e] !== undefined) {
+ return type[e];
+ } else {
+ throw new Error('Invalid enum value.');
+ }
+ },
+
+ /** Converts from an integer to string. */
+ read: function read(type, e) {
+ for (var i in type) {
+ if (type[i] === parseInt(e)) {
+ return i;
+ }
+ }
+
+ throw new Error('Invalid enum value.');
+ }
+
+};
+
+},{}],36:[function(_dereq_,module,exports){
+// OpenPGP.js - An OpenPGP implementation in javascript
+// Copyright (C) 2015 Tankred Hase
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 3.0 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+/**
+ * @fileoverview This class implements a client for the OpenPGP HTTP Keyserver Protocol (HKP)
+ * in order to lookup and upload keys on standard public key servers.
+ */
+
+'use strict';
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = HKP;
+
+var _config = _dereq_('./config');
+
+var _config2 = _interopRequireDefault(_config);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * Initialize the HKP client and configure it with the key server url and fetch function.
+ * @constructor
+ * @param {String} keyServerBaseUrl (optional) The HKP key server base url including
+ * the protocol to use e.g. https://pgp.mit.edu
+ */
+function HKP(keyServerBaseUrl) {
+ this._baseUrl = keyServerBaseUrl ? keyServerBaseUrl : _config2.default.keyserver;
+ this._fetch = typeof window !== 'undefined' ? window.fetch : _dereq_('node-fetch');
+}
+
+/**
+ * Search for a public key on the key server either by key ID or part of the user ID.
+ * @param {String} options.keyID The long public key ID.
+ * @param {String} options.query This can be any part of the key user ID such as name
+ * or email address.
+ * @return {Promise