diff --git a/bower.json b/bower.json index 91360e6b..986b5054 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "openpgp", - "version": "1.5.7", + "version": "2.0.0", "license": "LGPL-3.0+", "homepage": "http://openpgpjs.org/", "authors": [ diff --git a/dist/openpgp.js b/dist/openpgp.js index c1b1600d..5bce2c09 100644 --- a/dist/openpgp.js +++ b/dist/openpgp.js @@ -1,10 +1,2402 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.openpgp = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= len ) throw new Error( "Malformed string, low surrogate expected at position " + i ); + c = ( (c ^ 0xd800) << 10 ) | 0x10000 | ( str.charCodeAt(i) ^ 0xdc00 ); + } + else if ( !utf8 && c >>> 8 ) { + throw new Error("Wide characters are not allowed."); + } + + if ( !utf8 || c <= 0x7f ) { + bytes[j++] = c; + } + else if ( c <= 0x7ff ) { + bytes[j++] = 0xc0 | (c >> 6); + bytes[j++] = 0x80 | (c & 0x3f); + } + else if ( c <= 0xffff ) { + bytes[j++] = 0xe0 | (c >> 12); + bytes[j++] = 0x80 | (c >> 6 & 0x3f); + bytes[j++] = 0x80 | (c & 0x3f); + } + else { + bytes[j++] = 0xf0 | (c >> 18); + bytes[j++] = 0x80 | (c >> 12 & 0x3f); + bytes[j++] = 0x80 | (c >> 6 & 0x3f); + bytes[j++] = 0x80 | (c & 0x3f); + } + } + + return bytes.subarray(0, j); +} + +function hex_to_bytes ( str ) { + var len = str.length; + if ( len & 1 ) { + str = '0'+str; + len++; + } + var bytes = new Uint8Array(len>>1); + for ( var i = 0; i < len; i += 2 ) { + bytes[i>>1] = parseInt( str.substr( i, 2), 16 ); + } + return bytes; +} + +function base64_to_bytes ( str ) { + return string_to_bytes( atob( str ) ); +} + +function bytes_to_string ( bytes, utf8 ) { + utf8 = !!utf8; + + var len = bytes.length, + chars = new Array(len); + + for ( var i = 0, j = 0; i < len; i++ ) { + var b = bytes[i]; + if ( !utf8 || b < 128 ) { + chars[j++] = b; + } + else if ( b >= 192 && b < 224 && i+1 < len ) { + chars[j++] = ( (b & 0x1f) << 6 ) | (bytes[++i] & 0x3f); + } + else if ( b >= 224 && b < 240 && i+2 < len ) { + chars[j++] = ( (b & 0xf) << 12 ) | ( (bytes[++i] & 0x3f) << 6 ) | (bytes[++i] & 0x3f); + } + else if ( b >= 240 && b < 248 && i+3 < len ) { + var c = ( (b & 7) << 18 ) | ( (bytes[++i] & 0x3f) << 12 ) | ( (bytes[++i] & 0x3f) << 6 ) | (bytes[++i] & 0x3f); + if ( c <= 0xffff ) { + chars[j++] = c; + } + else { + c ^= 0x10000; + chars[j++] = 0xd800 | (c >> 10); + chars[j++] = 0xdc00 | (c & 0x3ff); + } + } + else { + throw new Error("Malformed UTF8 character at byte offset " + i); + } + } + + var str = '', + bs = 16384; + for ( var i = 0; i < j; i += bs ) { + str += String.fromCharCode.apply( String, chars.slice( i, i+bs <= j ? i+bs : j ) ); + } + + return str; +} + +function bytes_to_hex ( arr ) { + var str = ''; + for ( var i = 0; i < arr.length; i++ ) { + var h = ( arr[i] & 0xff ).toString(16); + if ( h.length < 2 ) str += '0'; + str += h; + } + return str; +} + +function bytes_to_base64 ( arr ) { + return btoa( bytes_to_string(arr) ); +} + +function pow2_ceil ( a ) { + a -= 1; + a |= a >>> 1; + a |= a >>> 2; + a |= a >>> 4; + a |= a >>> 8; + a |= a >>> 16; + a += 1; + return a; +} + +function is_number ( a ) { + return ( typeof a === 'number' ); +} + +function is_string ( a ) { + return ( typeof a === 'string' ); +} + +function is_buffer ( a ) { + return ( a instanceof ArrayBuffer ); +} + +function is_bytes ( a ) { + return ( a instanceof Uint8Array ); +} + +function is_typed_array ( a ) { + return ( a instanceof Int8Array ) || ( a instanceof Uint8Array ) + || ( a instanceof Int16Array ) || ( a instanceof Uint16Array ) + || ( a instanceof Int32Array ) || ( a instanceof Uint32Array ) + || ( a instanceof Float32Array ) + || ( a instanceof Float64Array ); +} + +function _heap_init ( constructor, options ) { + var heap = options.heap, + size = heap ? heap.byteLength : options.heapSize || 65536; + + if ( size & 0xfff || size <= 0 ) + throw new Error("heap size must be a positive integer and a multiple of 4096"); + + heap = heap || new constructor( new ArrayBuffer(size) ); + + return heap; +} + +function _heap_write ( heap, hpos, data, dpos, dlen ) { + var hlen = heap.length - hpos, + wlen = ( hlen < dlen ) ? hlen : dlen; + + heap.set( data.subarray( dpos, dpos+wlen ), hpos ); + + return wlen; +} + +/** + * Error definitions + */ + +global.IllegalStateError = IllegalStateError; +global.IllegalArgumentError = IllegalArgumentError; +global.SecurityError = SecurityError; + +/** + * @file {@link http://asmjs.org Asm.js} implementation of the {@link https://en.wikipedia.org/wiki/Advanced_Encryption_Standard Advanced Encryption Standard}. + * @author Artem S Vybornov + * @license MIT + */ +var AES_asm = function () { + "use strict"; + + /** + * Galois Field stuff init flag + */ + var ginit_done = false; + + /** + * Galois Field exponentiation and logarithm tables for 3 (the generator) + */ + var gexp3, glog3; + + /** + * Init Galois Field tables + */ + function ginit () { + gexp3 = [], + glog3 = []; + + var a = 1, c, d; + for ( c = 0; c < 255; c++ ) { + gexp3[c] = a; + + // Multiply by three + d = a & 0x80, a <<= 1, a &= 255; + if ( d === 0x80 ) a ^= 0x1b; + a ^= gexp3[c]; + + // Set the log table value + glog3[gexp3[c]] = c; + } + gexp3[255] = gexp3[0]; + glog3[0] = 0; + + ginit_done = true; + } + + /** + * Galois Field multiplication + * @param {int} a + * @param {int} b + * @return {int} + */ + function gmul ( a, b ) { + var c = gexp3[ ( glog3[a] + glog3[b] ) % 255 ]; + if ( a === 0 || b === 0 ) c = 0; + return c; + } + + /** + * Galois Field reciprocal + * @param {int} a + * @return {int} + */ + function ginv ( a ) { + var i = gexp3[ 255 - glog3[a] ]; + if ( a === 0 ) i = 0; + return i; + } + + /** + * AES stuff init flag + */ + var aes_init_done = false; + + /** + * Encryption, Decryption, S-Box and KeyTransform tables + */ + var aes_sbox, aes_sinv, aes_enc, aes_dec; + + /** + * Init AES tables + */ + function aes_init () { + if ( !ginit_done ) ginit(); + + // Calculates AES S-Box value + function _s ( a ) { + var c, s, x; + s = x = ginv(a); + for ( c = 0; c < 4; c++ ) { + s = ( (s << 1) | (s >>> 7) ) & 255; + x ^= s; + } + x ^= 99; + return x; + } + + // Tables + aes_sbox = [], + aes_sinv = [], + aes_enc = [ [], [], [], [] ], + aes_dec = [ [], [], [], [] ]; + + for ( var i = 0; i < 256; i++ ) { + var s = _s(i); + + // S-Box and its inverse + aes_sbox[i] = s; + aes_sinv[s] = i; + + // Ecryption and Decryption tables + aes_enc[0][i] = ( gmul( 2, s ) << 24 ) | ( s << 16 ) | ( s << 8 ) | gmul( 3, s ); + aes_dec[0][s] = ( gmul( 14, i ) << 24 ) | ( gmul( 9, i ) << 16 ) | ( gmul( 13, i ) << 8 ) | gmul( 11, i ); + // Rotate tables + for ( var t = 1; t < 4; t++ ) { + aes_enc[t][i] = ( aes_enc[t-1][i] >>> 8 ) | ( aes_enc[t-1][i] << 24 ); + aes_dec[t][s] = ( aes_dec[t-1][s] >>> 8 ) | ( aes_dec[t-1][s] << 24 ); + } + } + } + + /** + * Asm.js module constructor. + * + *

+ * 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. + *

+ * + * @alias AES_asm + * @class + * @param {GlobalScope} stdlib - global scope object (e.g. 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; + +// 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; + +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(require,module,exports){ "use strict"; var Promise = require("./promise/promise").Promise; var polyfill = require("./promise/polyfill").polyfill; exports.Promise = Promise; exports.polyfill = polyfill; -},{"./promise/polyfill":5,"./promise/promise":6}],2:[function(require,module,exports){ +},{"./promise/polyfill":6,"./promise/promise":7}],3:[function(require,module,exports){ "use strict"; /* global toString */ @@ -98,7 +2490,7 @@ function all(promises) { } exports.all = all; -},{"./utils":10}],3:[function(require,module,exports){ +},{"./utils":11}],4:[function(require,module,exports){ (function (process,global){ "use strict"; var browserGlobal = (typeof window !== 'undefined') ? window : {}; @@ -162,7 +2554,7 @@ function asap(callback, arg) { exports.asap = asap; }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"_process":11}],4:[function(require,module,exports){ +},{"_process":12}],5:[function(require,module,exports){ "use strict"; var config = { instrument: false @@ -178,7 +2570,7 @@ function configure(name, value) { exports.config = config; exports.configure = configure; -},{}],5:[function(require,module,exports){ +},{}],6:[function(require,module,exports){ (function (global){ "use strict"; /*global self*/ @@ -219,7 +2611,7 @@ function polyfill() { exports.polyfill = polyfill; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./promise":6,"./utils":10}],6:[function(require,module,exports){ +},{"./promise":7,"./utils":11}],7:[function(require,module,exports){ "use strict"; var config = require("./config").config; var configure = require("./config").configure; @@ -431,7 +2823,7 @@ function publishRejection(promise) { } exports.Promise = Promise; -},{"./all":2,"./asap":3,"./config":4,"./race":7,"./reject":8,"./resolve":9,"./utils":10}],7:[function(require,module,exports){ +},{"./all":3,"./asap":4,"./config":5,"./race":8,"./reject":9,"./resolve":10,"./utils":11}],8:[function(require,module,exports){ "use strict"; /* global toString */ var isArray = require("./utils").isArray; @@ -521,7 +2913,7 @@ function race(promises) { } exports.race = race; -},{"./utils":10}],8:[function(require,module,exports){ +},{"./utils":11}],9:[function(require,module,exports){ "use strict"; /** `RSVP.reject` returns a promise that will become rejected with the passed @@ -569,7 +2961,7 @@ function reject(reason) { } exports.reject = reject; -},{}],9:[function(require,module,exports){ +},{}],10:[function(require,module,exports){ "use strict"; function resolve(value) { /*jshint validthis:true */ @@ -585,7 +2977,7 @@ function resolve(value) { } exports.resolve = resolve; -},{}],10:[function(require,module,exports){ +},{}],11:[function(require,module,exports){ "use strict"; function objectOrFunction(x) { return isFunction(x) || (typeof x === "object" && x !== null); @@ -608,7 +3000,7 @@ exports.objectOrFunction = objectOrFunction; exports.isFunction = isFunction; exports.isArray = isArray; exports.now = now; -},{}],11:[function(require,module,exports){ +},{}],12:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -701,7 +3093,423 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],12:[function(require,module,exports){ +},{}],13:[function(require,module,exports){ +(function (global){ +/* + * Rusha, a JavaScript implementation of the Secure Hash Algorithm, SHA-1, + * as defined in FIPS PUB 180-1, tuned for high performance with large inputs. + * (http://github.com/srijs/rusha) + * + * Inspired by Paul Johnstons implementation (http://pajhome.org.uk/crypt/md5). + * + * Copyright (c) 2013 Sam Rijs (http://awesam.de). + * Released under the terms of the MIT license as follows: + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +(function () { + 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.'); + } + }; + // The Rusha object is a wrapper around the low-level RushaCore. + // It provides means of converting different inputs to the + // format accepted by RushaCore as well as other utility methods. + function Rusha(chunkSize) { + 'use strict'; + // Private object structure. + var self$2 = { fill: 0 }; + // Calculate the length of buffer that the sha1 routine uses + // including the padding. + var padlen = function (len) { + for (len += 9; len % 64 > 0; len += 1); + return len; + }; + var padZeroes = function (bin, len) { + for (var i = len >> 2; i < bin.length; i++) + bin[i] = 0; + }; + var padData = function (bin, chunkLen, msgLen) { + bin[chunkLen >> 2] |= 128 << 24 - (chunkLen % 4 << 3); + bin[((chunkLen >> 2) + 2 & ~15) + 14] = msgLen >> 29; + bin[((chunkLen >> 2) + 2 & ~15) + 15] = msgLen << 3; + }; + // Convert a binary string and write it to the heap. + // A binary string is expected to only contain char codes < 256. + var convStr = function (H8, H32, start, len, off) { + var str = this, i, om = off % 4, lm = len % 4, j = len - lm; + if (j > 0) { + switch (om) { + case 0: + H8[off + 3 | 0] = str.charCodeAt(start); + case 1: + H8[off + 2 | 0] = str.charCodeAt(start + 1); + case 2: + H8[off + 1 | 0] = str.charCodeAt(start + 2); + case 3: + H8[off | 0] = str.charCodeAt(start + 3); + } + } + for (i = om; i < j; i = i + 4 | 0) { + H32[off + i >> 2] = str.charCodeAt(start + i) << 24 | str.charCodeAt(start + i + 1) << 16 | str.charCodeAt(start + i + 2) << 8 | str.charCodeAt(start + i + 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); + } + }; + // Convert a buffer or array and write it to the heap. + // The buffer or array is expected to only contain elements < 256. + var convBuf = function (H8, H32, start, len, off) { + var buf = this, i, om = off % 4, lm = len % 4, j = len - lm; + if (j > 0) { + switch (om) { + case 0: + H8[off + 3 | 0] = buf[start]; + case 1: + H8[off + 2 | 0] = buf[start + 1]; + case 2: + H8[off + 1 | 0] = buf[start + 2]; + case 3: + H8[off | 0] = buf[start + 3]; + } + } + for (i = 4 - om; i < j; i = i += 4 | 0) { + H32[off + i >> 2] = buf[start + i] << 24 | buf[start + i + 1] << 16 | buf[start + i + 2] << 8 | buf[start + i + 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, om = off % 4, lm = len % 4, j = len - lm; + var buf = new Uint8Array(reader.readAsArrayBuffer(blob.slice(start, start + len))); + if (j > 0) { + switch (om) { + case 0: + H8[off + 3 | 0] = buf[0]; + case 1: + H8[off + 2 | 0] = buf[1]; + case 2: + H8[off + 1 | 0] = buf[2]; + case 3: + H8[off | 0] = buf[3]; + } + } + for (i = 4 - om; i < j; i = i += 4 | 0) { + H32[off + i >> 2] = buf[i] << 24 | buf[i + 1] << 16 | buf[i + 2] << 8 | buf[i + 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); + } + }; + // Convert an ArrayBuffer into its hexadecimal string representation. + var hex = function (arrayBuffer) { + var i, x, hex_tab = '0123456789abcdef', res = [], binarray = new Uint8Array(arrayBuffer); + for (i = 0; i < binarray.length; i++) { + x = binarray[i]; + res[i] = hex_tab.charAt(x >> 4 & 15) + hex_tab.charAt(x >> 0 & 15); + } + 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 v is smaller than 2^16, the smallest possible solution + // is 2^16. + if (v <= 65536) + return 65536; + // If v < 2^24, we round up to 2^n, + // otherwise we round up to 2^24 * n. + if (v < 16777216) { + for (p = 1; p < v; p = p << 1); + } else { + for (p = 16777216; p < v; p += 16777216); + } + return p; + }; + // Initialize the internal data structures to a new capacity. + var init = function (size) { + if (size % 64 > 0) { + throw new Error('Chunk size must be a multiple of 128 bit'); + } + 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) { + 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; + }; + // Write data to the heap. + var write = function (data, chunkOffset, chunkLen) { + convFn(data)(self$2.h8, self$2.h32, chunkOffset, chunkLen, 0); + }; + // Initialize and call the RushaCore, + // assuming an input buffer of length len * 4. + var coreCall = function (data, chunkOffset, chunkLen, msgLen, finalize) { + var padChunkLen = chunkLen; + if (finalize) { + padChunkLen = padChunk(chunkLen, msgLen); + } + write(data, chunkOffset, chunkLen); + 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; + }; + // Calculate the hash digest as an array of 5 32bit integers. + var 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, last; + 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); + }; + } + ; + // 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 we'e running in Node.JS, export a module. + if (typeof module !== 'undefined') { + module.exports = Rusha; + } else if (typeof window !== 'undefined') { + window.Rusha = Rusha; + } + // If we're running in a webworker, accept + // messages containing a jobid and a buffer + // or blob object, and return the hash result. + if (typeof FileReaderSync !== 'undefined') { + var reader = new FileReaderSync(), hasher = new Rusha(4 * 1024 * 1024); + self.onmessage = function onMessage(event) { + var hash, data = event.data.data; + try { + hash = hasher.digest(data); + self.postMessage({ + id: event.data.id, + hash: hash + }); + } catch (e) { + self.postMessage({ + id: event.data.id, + error: e.name + }); + } + }; + } +}()); +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],14:[function(require,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -729,10 +3537,29 @@ process.umask = function() { return 0; }; 'use strict'; -var config = require('./config'), - packet = require('./packet'), - enums = require('./enums.js'), - armor = require('./encoding/armor.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.CleartextMessage = CleartextMessage; +exports.readArmored = readArmored; + +var _config = require('./config'); + +var _config2 = _interopRequireDefault(_config); + +var _packet = require('./packet'); + +var _packet2 = _interopRequireDefault(_packet); + +var _enums = require('./enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _armor = require('./encoding/armor.js'); + +var _armor2 = _interopRequireDefault(_armor); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @class @@ -748,18 +3575,18 @@ function CleartextMessage(text, packetlist) { return new CleartextMessage(text, packetlist); } // normalize EOL to canonical form - this.text = text.replace(/\r/g, '').replace(/[\t ]+\n/g, "\n").replace(/\n/g,"\r\n"); - this.packets = packetlist || new packet.List(); + this.text = text.replace(/\r/g, '').replace(/[\t ]+\n/g, "\n").replace(/\n/g, "\r\n"); + this.packets = packetlist || new _packet2.default.List(); } /** * Returns the key IDs of the keys that signed the cleartext message * @return {Array} array of keyid objects */ -CleartextMessage.prototype.getSigningKeyIds = function() { +CleartextMessage.prototype.getSigningKeyIds = function () { var keyIds = []; - var signatureList = this.packets.filterByTag(enums.packet.signature); - signatureList.forEach(function(packet) { + var signatureList = this.packets.filterByTag(_enums2.default.packet.signature); + signatureList.forEach(function (packet) { keyIds.push(packet.issuerKeyId); }); return keyIds; @@ -769,20 +3596,22 @@ CleartextMessage.prototype.getSigningKeyIds = function() { * Sign the cleartext message * @param {Array} privateKeys private keys with decrypted secret key data for signing */ -CleartextMessage.prototype.sign = function(privateKeys) { - var packetlist = new packet.List(); - var literalDataPacket = new packet.Literal(); +CleartextMessage.prototype.sign = function (privateKeys) { + var packetlist = new _packet2.default.List(); + var literalDataPacket = new _packet2.default.Literal(); literalDataPacket.setText(this.text); for (var i = 0; i < privateKeys.length; i++) { if (privateKeys[i].isPublic()) { throw new Error('Need private key for signing'); } - var signaturePacket = new packet.Signature(); - signaturePacket.signatureType = enums.signature.text; - signaturePacket.hashAlgorithm = config.prefer_hash_algorithm; + var signaturePacket = new _packet2.default.Signature(); + signaturePacket.signatureType = _enums2.default.signature.text; + signaturePacket.hashAlgorithm = _config2.default.prefer_hash_algorithm; var signingKeyPacket = privateKeys[i].getSigningKeyPacket(); signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm; - if (!signingKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.'); + if (!signingKeyPacket.isDecrypted) { + throw new Error('Private key is not decrypted.'); + } signaturePacket.sign(signingKeyPacket, literalDataPacket); packetlist.push(signaturePacket); } @@ -794,10 +3623,10 @@ CleartextMessage.prototype.sign = function(privateKeys) { * @param {Array} keys array of keys to verify signatures * @return {Array<{keyid: module:type/keyid, valid: Boolean}>} list of signer's keyid and validity of signature */ -CleartextMessage.prototype.verify = function(keys) { +CleartextMessage.prototype.verify = function (keys) { var result = []; - var signatureList = this.packets.filterByTag(enums.packet.signature); - var literalDataPacket = new packet.Literal(); + var signatureList = this.packets.filterByTag(_enums2.default.packet.signature); + var literalDataPacket = new _packet2.default.Literal(); // we assume that cleartext signature is generated based on UTF8 cleartext literalDataPacket.setText(this.text); for (var i = 0; i < signatureList.length; i++) { @@ -826,25 +3655,24 @@ CleartextMessage.prototype.verify = function(keys) { * Get cleartext * @return {String} cleartext of message */ -CleartextMessage.prototype.getText = function() { +CleartextMessage.prototype.getText = function () { // normalize end of line to \n - return this.text.replace(/\r\n/g,"\n"); + return this.text.replace(/\r\n/g, "\n"); }; /** * Returns ASCII armored text of cleartext signed message * @return {String} ASCII armor */ -CleartextMessage.prototype.armor = function() { +CleartextMessage.prototype.armor = function () { var body = { - hash: enums.read(enums.hash, config.prefer_hash_algorithm).toUpperCase(), + hash: _enums2.default.read(_enums2.default.hash, _config2.default.prefer_hash_algorithm).toUpperCase(), text: this.text, data: this.packets.write() }; - return armor.encode(enums.armor.signed, body); + return _armor2.default.encode(_enums2.default.armor.signed, body); }; - /** * reads an OpenPGP cleartext signed message and returns a CleartextMessage object * @param {String} armoredText text to be parsed @@ -852,11 +3680,11 @@ CleartextMessage.prototype.armor = function() { * @static */ function readArmored(armoredText) { - var input = armor.decode(armoredText); - if (input.type !== enums.armor.signed) { + var input = _armor2.default.decode(armoredText); + if (input.type !== _enums2.default.armor.signed) { throw new Error('No cleartext signed message.'); } - var packetlist = new packet.List(); + var packetlist = new _packet2.default.List(); packetlist.read(input.data); verifyHeaders(input.headers, packetlist); var newMessage = new CleartextMessage(input.text, packetlist); @@ -870,12 +3698,12 @@ function readArmored(armoredText) { * @param {module:packet/packetlist} packetlist The packetlist with signature packets */ function verifyHeaders(headers, packetlist) { - var checkHashAlgos = function(hashAlgos) { + var checkHashAlgos = function checkHashAlgos(hashAlgos) { + function check(algo) { + return packetlist[i].hashAlgorithm === algo; + } for (var i = 0; i < packetlist.length; i++) { - if (packetlist[i].tag === enums.packet.signature && - !hashAlgos.some(function(algo) { - return packetlist[i].hashAlgorithm === algo; - })) { + if (packetlist[i].tag === _enums2.default.packet.signature && !hashAlgos.some(check)) { return false; } } @@ -883,15 +3711,15 @@ function verifyHeaders(headers, packetlist) { }; var oneHeader = null; var hashAlgos = []; - for (var i = 0; i < headers.length; i++) { - oneHeader = headers[i].match(/Hash: (.+)/); // get header value + headers.forEach(function (header) { + oneHeader = header.match(/Hash: (.+)/); // get header value if (oneHeader) { - oneHeader = oneHeader[1].replace(/\s/g, ''); // remove whitespace + oneHeader = oneHeader[1].replace(/\s/g, ''); // remove whitespace oneHeader = oneHeader.split(','); - oneHeader = oneHeader.map(function(hash) { + oneHeader = oneHeader.map(function (hash) { hash = hash.toLowerCase(); try { - return enums.write(enums.hash, hash); + return _enums2.default.write(_enums2.default.hash, hash); } catch (e) { throw new Error('Unknown hash algorithm in armor header: ' + hash); } @@ -900,18 +3728,15 @@ function verifyHeaders(headers, packetlist) { } else { throw new Error('Only "Hash" header allowed in cleartext signed message'); } - } - if (!hashAlgos.length && !checkHashAlgos([enums.hash.md5])) { + }); + if (!hashAlgos.length && !checkHashAlgos([_enums2.default.hash.md5])) { throw new Error('If no "Hash" header in cleartext signed message, then only MD5 signatures allowed'); } else if (!checkHashAlgos(hashAlgos)) { throw new Error('Hash algorithm mismatch in armor header and signature'); } } -exports.CleartextMessage = CleartextMessage; -exports.readArmored = readArmored; - -},{"./config":17,"./encoding/armor.js":41,"./enums.js":43,"./packet":55}],13:[function(require,module,exports){ +},{"./config":19,"./encoding/armor.js":41,"./enums.js":43,"./packet":55}],15:[function(require,module,exports){ /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var n=void 0,u=!0,aa=this;function ba(e,d){var c=e.split("."),f=aa;!(c[0]in f)&&f.execScript&&f.execScript("var "+c[0]);for(var a;c.length&&(a=c.shift());)!c.length&&d!==n?f[a]=d:f=f[a]?f[a]:f[a]={}};var C="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function K(e,d){this.index="number"===typeof d?d:0;this.d=0;this.buffer=e instanceof(C?Uint8Array:Array)?e:new (C?Uint8Array:Array)(32768);if(2*this.buffer.length<=this.index)throw Error("invalid index");this.buffer.length<=this.index&&ca(this)}function ca(e){var d=e.buffer,c,f=d.length,a=new (C?Uint8Array:Array)(f<<1);if(C)a.set(d);else for(c=0;c>>8&255]<<16|L[e>>>16&255]<<8|L[e>>>24&255])>>32-d:L[e]>>8-d);if(8>d+b)k=k<>d-m-1&1,8===++b&&(b=0,f[a++]=L[k],k=0,a===f.length&&(f=ca(this)));f[a]=k;this.buffer=f;this.d=b;this.index=a};K.prototype.finish=function(){var e=this.buffer,d=this.index,c;0M;++M){for(var R=M,S=R,ha=7,R=R>>>1;R;R>>>=1)S<<=1,S|=R&1,--ha;ga[M]=(S<>>0}var L=ga;function ja(e){this.buffer=new (C?Uint16Array:Array)(2*e);this.length=0}ja.prototype.getParent=function(e){return 2*((e-2)/4|0)};ja.prototype.push=function(e,d){var c,f,a=this.buffer,b;c=this.length;a[this.length++]=d;for(a[this.length++]=e;0a[f])b=a[c],a[c]=a[f],a[f]=b,b=a[c+1],a[c+1]=a[f+1],a[f+1]=b,c=f;else break;return this.length}; @@ -936,7 +3761,7 @@ function Ja(e,d,c){function f(a){var b=g[a][p[a]];b===d?(f(a+1),f(a+1)):--k[b];+ 1][q]=e[q],g[c-1][q]=q;for(l=0;le[l]?(m[h][q]=t,g[h][q]=d,w+=2):(m[h][q]=e[l],g[h][q]=l,++l);p[h]=0;1===b[h]&&f(h)}return k} function pa(e){var d=new (C?Uint16Array:Array)(e.length),c=[],f=[],a=0,b,k,m,g;b=0;for(k=e.length;b>>=1}return d};ba("Zlib.RawDeflate",ka);ba("Zlib.RawDeflate.prototype.compress",ka.prototype.h);var Ka={NONE:0,FIXED:1,DYNAMIC:ma},V,La,$,Ma;if(Object.keys)V=Object.keys(Ka);else for(La in V=[],$=0,Ka)V[$++]=La;$=0;for(Ma=V.length;$a&&(a=b[n]),b[n]>=1;J=g<<16|n;for(s=m;s>>=1;switch(b){case 0:var e=this.input,a=this.d,c=this.b,d=this.a,f=e.length,g=void 0,h=void 0,k=c.length,m=void 0;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=e[a++]|e[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=e[a++]|e[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>e.length)throw Error("input buffer is broken");switch(this.i){case w:for(;d+ @@ -952,7 +3777,7 @@ u.prototype.v=function(b){var e,a=this.input.length/this.d+1|0,c,d,f,g=this.inpu u.prototype.m=function(){var b=0,e=this.b,a=this.g,c,d=new (q?Uint8Array:Array)(this.k+(this.a-32768)),f,g,h,k;if(0===a.length)return q?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);f=0;for(g=a.length;fe&&(this.b.length=e),b=this.b);return this.buffer=b};p("Zlib.RawInflate",u);p("Zlib.RawInflate.prototype.decompress",u.prototype.u);var T={ADAPTIVE:v,BLOCK:w},U,V,W,X;if(Object.keys)U=Object.keys(T);else for(V in U=[],W=0,T)U[W++]=V;W=0;for(X=U.length;W>>8&255]<<16|N[d>>>16&255]<<8|N[d>>>24&255])>>32-a:N[d]>>8-a);if(8>a+f)g=g<>a-h-1&1,8===++f&&(f=0,e[b++]=N[g],g=0,b===e.length&&(e=this.f()));e[b]=g;this.buffer=e;this.i=f;this.index=b};H.prototype.finish=function(){var d=this.buffer,a=this.index,c;0O;++O){for(var P=O,Q=P,ga=7,P=P>>>1;P;P>>>=1)Q<<=1,Q|=P&1,--ga;fa[O]=(Q<>>0}var N=fa;function ha(d){this.buffer=new (F?Uint16Array:Array)(2*d);this.length=0}ha.prototype.getParent=function(d){return 2*((d-2)/4|0)};ha.prototype.push=function(d,a){var c,e,b=this.buffer,f;c=this.length;b[this.length++]=a;for(b[this.length++]=d;0b[e])f=b[c],b[c]=b[e],b[e]=f,f=b[c+1],b[c+1]=b[e+1],b[e+1]=f,c=e;else break;return this.length}; @@ -993,7 +3818,7 @@ kb.prototype.p=function(){var d=this.input,a,c;a=this.B.p();this.c=this.B.c;this mb.prototype.j=function(){var d,a,c,e,b,f,g,h=0;g=this.a;d=lb;switch(d){case lb:a=Math.LOG2E*Math.log(32768)-8;break;default:l(Error("invalid compression method"))}c=a<<4|d;g[h++]=c;switch(d){case lb:switch(this.h){case $.NONE:b=0;break;case $.r:b=1;break;case $.k:b=2;break;default:l(Error("unsupported compression type"))}break;default:l(Error("invalid compression method"))}e=b<<6|0;g[h++]=e|31-(256*c+e)%31;f=jb(this.input);this.A.b=h;g=this.A.j();h=g.length;F&&(g=new Uint8Array(g.buffer),g.length<= h+4&&(this.a=new Uint8Array(g.length+4),this.a.set(g),g=this.a),g=g.subarray(0,h+4));g[h++]=f>>24&255;g[h++]=f>>16&255;g[h++]=f>>8&255;g[h++]=f&255;return g};function nb(d,a){var c,e,b,f;if(Object.keys)c=Object.keys(a);else for(e in c=[],b=0,a)c[b++]=e;b=0;for(f=c.length;b block_size * pos) { - var encblock = cipherfn.encrypt(util.str2bin(blockc)); - blocki = plaintext.substring((pos * block_size), (pos * block_size) + block_size); - for (var i = 0; i < blocki.length; i++) { - tempBlock += String.fromCharCode(blocki.charCodeAt(i) ^ encblock[i]); + var cyphertext = new Uint8Array(plaintext.length); + var i, + j = 0; + + if (iv === null) { + for (i = 0; i < block_size; i++) { + blockc[i] = 0; + } + } else { + for (i = 0; i < block_size; i++) { + blockc[i] = iv[i]; + } + } + while (plaintext.length > block_size * pos) { + var encblock = cipherfn.encrypt(blockc); + blocki = plaintext.subarray(pos * block_size, pos * block_size + block_size); + for (i = 0; i < blocki.length; i++) { + blockc[i] = blocki[i] ^ encblock[i]; + cyphertext[j++] = blockc[i]; } - blockc = tempBlock; - tempBlock = ''; - cyphertext += blockc; pos++; } return cyphertext; }, - normalDecrypt: function(cipherfn, key, ciphertext, iv) { - cipherfn = new cipher[cipherfn](key); + normalDecrypt: function normalDecrypt(cipherfn, key, ciphertext, iv) { + cipherfn = new _cipher2.default[cipherfn](key); var block_size = cipherfn.blockSize; - var blockp = ''; + var blockp; var pos = 0; - var plaintext = ''; + var plaintext = new Uint8Array(ciphertext.length); var offset = 0; - var i; - if (iv === null) + var i, + j = 0; + + if (iv === null) { + blockp = new Uint8Array(block_size); for (i = 0; i < block_size; i++) { - blockp += String.fromCharCode(0); + blockp[i] = 0; } - else - blockp = iv.substring(0, block_size); - while (ciphertext.length > (block_size * pos)) { - var decblock = cipherfn.encrypt(util.str2bin(blockp)); - blockp = ciphertext.substring((pos * (block_size)) + offset, (pos * (block_size)) + (block_size) + offset); + } else { + blockp = iv.subarray(0, block_size); + } + while (ciphertext.length > block_size * pos) { + var decblock = cipherfn.encrypt(blockp); + blockp = ciphertext.subarray(pos * block_size + offset, pos * block_size + block_size + offset); for (i = 0; i < blockp.length; i++) { - plaintext += String.fromCharCode(blockp.charCodeAt(i) ^ decblock[i]); + plaintext[j++] = blockp[i] ^ decblock[i]; } pos++; } @@ -1349,344 +4228,62 @@ module.exports = { } }; -},{"../util.js":76,"./cipher":23}],19:[function(require,module,exports){ +},{"./cipher":25}],21:[function(require,module,exports){ /* Rijndael (AES) Encryption * Copyright 2005 Herbert Hanewinkel, www.haneWIN.de * version 1.1, check www.haneWIN.de for the latest version - * This software is provided as-is, without express or implied warranty. + * This software is provided as-is, without express or implied warranty. * Permission to use, copy, modify, distribute or sell this software, with or * without fee, for any purpose and by any individual or organization, is hereby - * granted, provided that the above copyright notice and this paragraph appear + * granted, provided that the above copyright notice and this paragraph appear * in all copies. Distribution as a part of an application or binary must * include the above copyright notice in the documentation and/or other * materials provided with the application or distribution. */ /** - * @requires util * @module crypto/cipher/aes */ 'use strict'; -var util = require('../../util.js'); - // The round constants used in subkey expansion -var Rcon = new Uint8Array([ - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, - 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, - 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 -]); + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var Rcon = new Uint8Array([0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91]); // Precomputed lookup table for the SBox -var S = new Uint8Array([ - 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, - 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, - 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, - 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, - 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, - 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, - 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69, - 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245, - 188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68, - 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42, - 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, - 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, - 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, - 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62, - 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225, - 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, - 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, - 22 -]); +var S = new Uint8Array([99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22]); -var T1 = new Uint32Array([ - 0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, - 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591, - 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56, - 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec, - 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa, - 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb, - 0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, - 0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b, - 0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c, - 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83, - 0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9, - 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a, - 0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d, - 0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f, - 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df, - 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea, - 0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34, - 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b, - 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d, - 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413, - 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1, - 0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6, - 0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972, - 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85, - 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed, - 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511, - 0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe, - 0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b, - 0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05, - 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1, - 0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, - 0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf, - 0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3, - 0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e, - 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a, - 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6, - 0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3, - 0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b, - 0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428, - 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad, - 0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14, - 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8, - 0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4, - 0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2, - 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda, - 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949, - 0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf, - 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810, - 0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c, - 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697, - 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e, - 0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f, - 0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc, - 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c, - 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969, - 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27, - 0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122, - 0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433, - 0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9, - 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5, - 0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, - 0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0, - 0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e, - 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c -]); +var T1 = new Uint32Array([0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591, 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56, 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec, 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa, 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb, 0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, 0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b, 0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c, 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83, 0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9, 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a, 0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d, 0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f, 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df, 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea, 0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34, 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b, 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d, 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413, 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1, 0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6, 0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972, 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85, 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed, 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511, 0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe, 0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b, 0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05, 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1, 0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, 0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf, 0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3, 0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e, 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a, 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6, 0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3, 0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b, 0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428, 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad, 0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14, 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8, 0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4, 0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2, 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda, 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949, 0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf, 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810, 0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c, 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697, 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e, 0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f, 0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc, 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c, 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969, 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27, 0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122, 0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433, 0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9, 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5, 0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, 0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0, 0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e, 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c]); -var T2 = new Uint32Array([ - 0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d, - 0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154, - 0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d, - 0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a, - 0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87, - 0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b, - 0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea, - 0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b, - 0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a, - 0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f, - 0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908, - 0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f, - 0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e, - 0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5, - 0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d, - 0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f, - 0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e, - 0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb, - 0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce, - 0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397, - 0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c, - 0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed, - 0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b, - 0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a, - 0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16, - 0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194, - 0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81, - 0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3, - 0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a, - 0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104, - 0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263, - 0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d, - 0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f, - 0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39, - 0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47, - 0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695, - 0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f, - 0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83, - 0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c, - 0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76, - 0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e, - 0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4, - 0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6, - 0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b, - 0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7, - 0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0, - 0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25, - 0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018, - 0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72, - 0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751, - 0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21, - 0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85, - 0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa, - 0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12, - 0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0, - 0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9, - 0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233, - 0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7, - 0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920, - 0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a, - 0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17, - 0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8, - 0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11, - 0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a -]); +var T2 = new Uint32Array([0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d, 0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154, 0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d, 0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a, 0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87, 0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b, 0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea, 0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b, 0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a, 0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f, 0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908, 0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f, 0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e, 0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5, 0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d, 0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f, 0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e, 0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb, 0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce, 0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397, 0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c, 0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed, 0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b, 0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a, 0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16, 0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194, 0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81, 0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3, 0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a, 0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104, 0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263, 0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d, 0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f, 0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39, 0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47, 0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695, 0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f, 0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83, 0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c, 0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76, 0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e, 0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4, 0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6, 0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b, 0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7, 0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0, 0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25, 0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018, 0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72, 0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751, 0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21, 0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85, 0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa, 0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12, 0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0, 0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9, 0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233, 0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7, 0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920, 0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a, 0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17, 0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8, 0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11, 0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a]); -var T3 = new Uint32Array([ - 0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b, - 0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5, - 0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b, - 0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76, - 0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d, - 0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0, - 0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf, - 0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0, - 0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26, - 0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc, - 0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1, - 0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15, - 0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3, - 0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a, - 0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2, - 0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75, - 0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a, - 0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0, - 0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3, - 0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784, - 0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced, - 0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b, - 0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39, - 0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf, - 0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb, - 0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485, - 0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f, - 0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8, - 0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f, - 0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5, - 0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321, - 0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2, - 0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec, - 0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917, - 0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d, - 0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573, - 0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc, - 0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388, - 0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14, - 0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db, - 0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a, - 0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c, - 0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662, - 0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79, - 0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d, - 0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9, - 0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea, - 0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808, - 0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e, - 0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6, - 0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f, - 0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a, - 0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66, - 0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e, - 0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9, - 0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e, - 0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311, - 0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794, - 0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9, - 0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf, - 0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d, - 0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868, - 0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f, - 0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16 -]); +var T3 = new Uint32Array([0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b, 0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5, 0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b, 0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76, 0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d, 0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0, 0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf, 0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0, 0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26, 0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc, 0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1, 0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15, 0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3, 0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a, 0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2, 0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75, 0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a, 0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0, 0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3, 0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784, 0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced, 0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b, 0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39, 0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf, 0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb, 0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485, 0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f, 0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8, 0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f, 0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5, 0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321, 0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2, 0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec, 0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917, 0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d, 0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573, 0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc, 0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388, 0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14, 0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db, 0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a, 0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c, 0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662, 0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79, 0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d, 0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9, 0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea, 0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808, 0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e, 0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6, 0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f, 0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a, 0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66, 0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e, 0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9, 0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e, 0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311, 0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794, 0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9, 0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf, 0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d, 0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868, 0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f, 0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16]); -var T4 = new Uint32Array([ - 0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b, - 0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5, - 0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b, - 0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676, - 0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d, - 0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0, - 0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf, - 0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0, - 0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626, - 0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc, - 0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1, - 0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515, - 0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3, - 0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a, - 0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2, - 0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575, - 0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a, - 0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0, - 0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3, - 0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484, - 0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded, - 0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b, - 0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939, - 0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf, - 0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb, - 0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585, - 0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f, - 0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8, - 0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f, - 0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5, - 0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121, - 0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2, - 0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec, - 0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717, - 0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d, - 0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373, - 0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc, - 0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888, - 0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414, - 0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb, - 0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a, - 0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c, - 0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262, - 0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979, - 0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d, - 0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9, - 0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea, - 0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808, - 0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e, - 0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6, - 0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f, - 0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a, - 0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666, - 0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e, - 0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9, - 0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e, - 0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111, - 0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494, - 0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9, - 0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf, - 0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d, - 0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868, - 0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f, - 0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616 -]); +var T4 = new Uint32Array([0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b, 0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5, 0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b, 0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676, 0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d, 0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0, 0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf, 0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0, 0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626, 0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc, 0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1, 0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515, 0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3, 0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a, 0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2, 0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575, 0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a, 0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0, 0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3, 0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484, 0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded, 0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b, 0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939, 0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf, 0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb, 0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585, 0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f, 0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8, 0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f, 0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5, 0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121, 0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2, 0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec, 0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717, 0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d, 0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373, 0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc, 0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888, 0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414, 0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb, 0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a, 0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c, 0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262, 0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979, 0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d, 0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9, 0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea, 0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808, 0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e, 0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6, 0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f, 0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a, 0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666, 0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e, 0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9, 0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e, 0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111, 0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494, 0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9, 0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf, 0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d, 0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868, 0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f, 0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616]); function B0(x) { - return (x & 255); + return x & 255; } function B1(x) { - return ((x >> 8) & 255); + return x >> 8 & 255; } function B2(x) { - return ((x >> 16) & 255); + return x >> 16 & 255; } function B3(x) { - return ((x >> 24) & 255); + return x >> 24 & 255; } function F1(x0, x1, x2, x3) { - return B1(T1[x0 & 255]) | (B1(T1[(x1 >> 8) & 255]) << 8) | (B1(T1[(x2 >> 16) & 255]) << 16) | (B1(T1[x3 >>> 24]) << 24); + return B1(T1[x0 & 255]) | B1(T1[x1 >> 8 & 255]) << 8 | B1(T1[x2 >> 16 & 255]) << 16 | B1(T1[x3 >>> 24]) << 24; } function packBytes(octets) { @@ -1694,10 +4291,12 @@ function packBytes(octets) { var len = octets.length; var b = new Array(len / 4); - if (!octets || len % 4) return; + if (!octets || len % 4) { + return; + } for (i = 0, j = 0; j < len; j += 4) { - b[i++] = octets[j] | (octets[j + 1] << 8) | (octets[j + 2] << 16) | (octets[j + 3] << 24); + b[i++] = octets[j] | octets[j + 1] << 8 | octets[j + 2] << 16 | octets[j + 3] << 24; } return b; @@ -1706,7 +4305,7 @@ function packBytes(octets) { function unpackBytes(packed) { var j; var i = 0, - l = packed.length; + l = packed.length; var r = new Array(l * 4); for (j = 0; j < l; j++) { @@ -1732,13 +4331,13 @@ function keyExpansion(key) { var tk = new Array(maxkc); var rconpointer = 0; - if (keylen == 16) { + if (keylen === 16) { rounds = 10; kc = 4; - } else if (keylen == 24) { + } else if (keylen === 24) { rounds = 12; kc = 6; - } else if (keylen == 32) { + } else if (keylen === 32) { rounds = 14; kc = 8; } else { @@ -1750,7 +4349,7 @@ function keyExpansion(key) { } for (i = 0, j = 0; j < keylen; j++, i += 4) { - k[j] = key.charCodeAt(i) | (key.charCodeAt(i + 1) << 8) | (key.charCodeAt(i + 2) << 16) | (key.charCodeAt(i + 3) << 24); + k[j] = key[i] | key[i + 1] << 8 | key[i + 2] << 16 | key[i + 3] << 24; } for (j = kc - 1; j >= 0; j--) { @@ -1759,11 +4358,11 @@ function keyExpansion(key) { r = 0; t = 0; - for (j = 0; (j < kc) && (r < rounds + 1);) { - for (; (j < kc) && (t < 4); j++, t++) { + for (j = 0; j < kc && r < rounds + 1;) { + for (; j < kc && t < 4; j++, t++) { keySched[r][t] = tk[j]; } - if (t == 4) { + if (t === 4) { r++; t = 0; } @@ -1772,10 +4371,10 @@ function keyExpansion(key) { while (r < rounds + 1) { var temp = tk[kc - 1]; - tk[0] ^= S[B1(temp)] | (S[B2(temp)] << 8) | (S[B3(temp)] << 16) | (S[B0(temp)] << 24); + tk[0] ^= S[B1(temp)] | S[B2(temp)] << 8 | S[B3(temp)] << 16 | S[B0(temp)] << 24; tk[0] ^= Rcon[rconpointer++]; - if (kc != 8) { + if (kc !== 8) { for (j = 1; j < kc; j++) { tk[j] ^= tk[j - 1]; } @@ -1785,18 +4384,18 @@ function keyExpansion(key) { } temp = tk[kc / 2 - 1]; - tk[kc / 2] ^= S[B0(temp)] | (S[B1(temp)] << 8) | (S[B2(temp)] << 16) | (S[B3(temp)] << 24); + tk[kc / 2] ^= S[B0(temp)] | S[B1(temp)] << 8 | S[B2(temp)] << 16 | S[B3(temp)] << 24; for (j = kc / 2 + 1; j < kc; j++) { tk[j] ^= tk[j - 1]; } } - for (j = 0; (j < kc) && (r < rounds + 1);) { - for (; (j < kc) && (t < 4); j++, t++) { + for (j = 0; j < kc && r < rounds + 1;) { + for (; j < kc && t < 4; j++, t++) { keySched[r][t] = tk[j]; } - if (t == 4) { + if (t === 4) { r++; t = 0; } @@ -1821,10 +4420,10 @@ function AESencrypt(block, ctx, t) { t[2] = b[2] ^ ctx.rk[r][2]; t[3] = b[3] ^ ctx.rk[r][3]; - b[0] = T1[t[0] & 255] ^ T2[(t[1] >> 8) & 255] ^ T3[(t[2] >> 16) & 255] ^ T4[t[3] >>> 24]; - b[1] = T1[t[1] & 255] ^ T2[(t[2] >> 8) & 255] ^ T3[(t[3] >> 16) & 255] ^ T4[t[0] >>> 24]; - b[2] = T1[t[2] & 255] ^ T2[(t[3] >> 8) & 255] ^ T3[(t[0] >> 16) & 255] ^ T4[t[1] >>> 24]; - b[3] = T1[t[3] & 255] ^ T2[(t[0] >> 8) & 255] ^ T3[(t[1] >> 16) & 255] ^ T4[t[2] >>> 24]; + b[0] = T1[t[0] & 255] ^ T2[t[1] >> 8 & 255] ^ T3[t[2] >> 16 & 255] ^ T4[t[3] >>> 24]; + b[1] = T1[t[1] & 255] ^ T2[t[2] >> 8 & 255] ^ T3[t[3] >> 16 & 255] ^ T4[t[0] >>> 24]; + b[2] = T1[t[2] & 255] ^ T2[t[3] >> 8 & 255] ^ T3[t[0] >> 16 & 255] ^ T4[t[1] >>> 24]; + b[3] = T1[t[3] & 255] ^ T2[t[0] >> 8 & 255] ^ T3[t[1] >> 16 & 255] ^ T4[t[2] >>> 24]; } // last round is special @@ -1845,11 +4444,11 @@ function AESencrypt(block, ctx, t) { function makeClass(length) { - var c = function(key) { + var c = function c(key) { this.key = keyExpansion(key); this._temp = new Uint32Array(this.blockSize / 4); - this.encrypt = function(block) { + this.encrypt = function (block) { return AESencrypt(block, this.key, this._temp); }; }; @@ -1860,17 +4459,15 @@ function makeClass(length) { return c; } -module.exports = {}; +exports.default = { + 128: makeClass(128), + 192: makeClass(192), + 256: makeClass(256) +}; -var types = [128, 192, 256]; - -for (var i in types) { - module.exports[types[i]] = makeClass(types[i]); -} - -},{"../../util.js":76}],20:[function(require,module,exports){ -/* Modified by Recurity Labs GmbH - * +},{}],22:[function(require,module,exports){ +/* Modified by Recurity Labs GmbH + * * Originally written by nklein software (nklein.com) */ @@ -1878,13 +4475,20 @@ for (var i in types) { * @module crypto/cipher/blowfish */ -/* +'use strict'; + +/* * Javascript implementation based on Bruce Schneier's reference implementation. * * * The constructor doesn't do much of anything. It's just here * so we can start defining properties and methods and such. */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = BF; function Blowfish() {} /* @@ -1896,197 +4500,12 @@ Blowfish.prototype.BLOCKSIZE = 8; /* * These are the default SBOXES. */ -Blowfish.prototype.SBOXES = [ - [ - 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, - 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, - 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, - 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, - 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, - 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, - 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, - 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, - 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, - 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, - 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1, - 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, - 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, - 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, - 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176, - 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, - 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, - 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, - 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b, - 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, - 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, - 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, - 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a, - 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, - 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, - 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, - 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8, - 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, - 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, - 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, - 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0, - 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, - 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, - 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, - 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705, - 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, - 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, - 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, - 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9, - 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, - 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, - 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, - 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a - ], - [ - 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, - 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, - 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, - 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, - 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, - 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, - 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d, - 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, - 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, - 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, - 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908, - 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, - 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, - 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, - 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908, - 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, - 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, - 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, - 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa, - 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, - 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, - 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, - 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5, - 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, - 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, - 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, - 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca, - 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, - 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, - 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, - 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054, - 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, - 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, - 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, - 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646, - 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, - 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, - 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, - 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e, - 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, - 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, - 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, - 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 - ], - [ - 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, - 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, - 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, - 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, - 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, - 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, - 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec, - 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, - 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, - 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, - 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58, - 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, - 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, - 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, - 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60, - 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, - 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, - 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, - 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74, - 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, - 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, - 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, - 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979, - 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, - 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, - 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, - 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086, - 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, - 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, - 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, - 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84, - 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, - 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, - 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, - 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe, - 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, - 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, - 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, - 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188, - 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, - 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, - 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, - 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 - ], - [ - 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, - 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, - 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, - 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, - 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, - 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, - 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1, - 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, - 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, - 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, - 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6, - 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, - 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, - 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, - 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5, - 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, - 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, - 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, - 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd, - 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, - 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, - 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, - 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc, - 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, - 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, - 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, - 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a, - 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, - 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, - 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, - 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b, - 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, - 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, - 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, - 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623, - 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, - 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, - 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, - 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3, - 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, - 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, - 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, - 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 - ] -]; +Blowfish.prototype.SBOXES = [[0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a], [0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7], [0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0], [0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6]]; //* //* This is the default PARRAY //* -Blowfish.prototype.PARRAY = [ - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, - 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b -]; +Blowfish.prototype.PARRAY = [0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b]; //* //* This is the number of rounds the cipher will go @@ -2100,7 +4519,7 @@ Blowfish.prototype.NN = 16; //* equal to ( bb & 0x00FFFFFFFF ) even when they //* agree bit-for-bit for the first 32 bits. //* -Blowfish.prototype._clean = function(xx) { +Blowfish.prototype._clean = function (xx) { if (xx < 0) { var yy = xx & 0x7FFFFFFF; xx = yy + 0x80000000; @@ -2111,7 +4530,7 @@ Blowfish.prototype._clean = function(xx) { //* //* This is the mixing function that uses the sboxes //* -Blowfish.prototype._F = function(xx) { +Blowfish.prototype._F = function (xx) { var aa; var bb; var cc; @@ -2137,7 +4556,7 @@ Blowfish.prototype._F = function(xx) { //* This method takes an array with two values, left and right //* and does NN rounds of Blowfish on them. //* -Blowfish.prototype._encrypt_block = function(vals) { +Blowfish.prototype._encrypt_block = function (vals) { var dataL = vals[0]; var dataR = vals[1]; @@ -2168,21 +4587,21 @@ Blowfish.prototype._encrypt_block = function(vals) { //* instead. That will involve more looping, but it won't require //* the F() method to deconstruct the vector. //* -Blowfish.prototype.encrypt_block = function(vector) { +Blowfish.prototype.encrypt_block = function (vector) { var ii; var vals = [0, 0]; var off = this.BLOCKSIZE / 2; for (ii = 0; ii < this.BLOCKSIZE / 2; ++ii) { - vals[0] = (vals[0] << 8) | (vector[ii + 0] & 0x00FF); - vals[1] = (vals[1] << 8) | (vector[ii + off] & 0x00FF); + vals[0] = vals[0] << 8 | vector[ii + 0] & 0x00FF; + vals[1] = vals[1] << 8 | vector[ii + off] & 0x00FF; } this._encrypt_block(vals); var ret = []; for (ii = 0; ii < this.BLOCKSIZE / 2; ++ii) { - ret[ii + 0] = (vals[0] >>> (24 - 8 * (ii)) & 0x00FF); - ret[ii + off] = (vals[1] >>> (24 - 8 * (ii)) & 0x00FF); + ret[ii + 0] = vals[0] >>> 24 - 8 * ii & 0x00FF; + ret[ii + off] = vals[1] >>> 24 - 8 * ii & 0x00FF; // vals[ 0 ] = ( vals[ 0 ] >>> 8 ); // vals[ 1 ] = ( vals[ 1 ] >>> 8 ); } @@ -2194,7 +4613,7 @@ Blowfish.prototype.encrypt_block = function(vector) { //* This method takes an array with two values, left and right //* and undoes NN rounds of Blowfish on them. //* -Blowfish.prototype._decrypt_block = function(vals) { +Blowfish.prototype._decrypt_block = function (vals) { var dataL = vals[0]; var dataR = vals[1]; @@ -2220,7 +4639,7 @@ Blowfish.prototype._decrypt_block = function(vals) { //* This method takes a key array and initializes the //* sboxes and parray for this encryption. //* -Blowfish.prototype.init = function(key) { +Blowfish.prototype.init = function (key) { var ii; var jj = 0; @@ -2229,7 +4648,7 @@ Blowfish.prototype.init = function(key) { var data = 0x00000000; var kk; for (kk = 0; kk < 4; ++kk) { - data = (data << 8) | (key[jj] & 0x00FF); + data = data << 8 | key[jj] & 0x00FF; if (++jj >= key.length) { jj = 0; } @@ -2262,31 +4681,20 @@ Blowfish.prototype.init = function(key) { } }; -var util = require('../../util.js'); - // added by Recurity Labs -function BFencrypt(block, key) { - var bf = new Blowfish(); - bf.init(util.str2bin(key)); - return bf.encrypt_block(block); -} - function BF(key) { this.bf = new Blowfish(); - this.bf.init(util.str2bin(key)); + this.bf.init(key); - this.encrypt = function(block) { + this.encrypt = function (block) { return this.bf.encrypt_block(block); }; } +BF.keySize = BF.prototype.keySize = 16; +BF.blockSize = BF.prototype.blockSize = 16; - -module.exports = BF; -module.exports.keySize = BF.prototype.keySize = 16; -module.exports.blockSize = BF.prototype.blockSize = 16; - -},{"../../util.js":76}],21:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -2300,24 +4708,27 @@ module.exports.blockSize = BF.prototype.blockSize = 16; // cast5.js is a Javascript implementation of CAST-128, as defined in RFC 2144. // CAST-128 is a common OpenPGP cipher. - // CAST5 constructor /** @module crypto/cipher/cast5 */ +'use strict'; - -function openpgp_symenc_cast5() { +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Cast5; +function OpenpgpSymencCast5() { this.BlockSize = 8; this.KeySize = 16; - this.setKey = function(key) { + this.setKey = function (key) { this.masking = new Array(16); this.rotate = new Array(16); this.reset(); - if (key.length == this.KeySize) { + if (key.length === this.KeySize) { this.keySchedule(key); } else { throw new Error('CAST-128: keys must be 16 bytes'); @@ -2325,18 +4736,18 @@ function openpgp_symenc_cast5() { return true; }; - this.reset = function() { + this.reset = function () { for (var i = 0; i < 16; i++) { this.masking[i] = 0; this.rotate[i] = 0; } }; - this.getBlockSize = function() { - return BlockSize; + this.getBlockSize = function () { + return this.BlockSize; }; - this.encrypt = function(src) { + this.encrypt = function (src) { var dst = new Array(src.length); for (var i = 0; i < src.length; i += 8) { @@ -2396,20 +4807,20 @@ function openpgp_symenc_cast5() { r = l ^ f1(r, this.masking[15], this.rotate[15]); l = t; - dst[i] = (r >>> 24) & 255; - dst[i + 1] = (r >>> 16) & 255; - dst[i + 2] = (r >>> 8) & 255; + dst[i] = r >>> 24 & 255; + dst[i + 1] = r >>> 16 & 255; + dst[i + 2] = r >>> 8 & 255; dst[i + 3] = r & 255; - dst[i + 4] = (l >>> 24) & 255; - dst[i + 5] = (l >>> 16) & 255; - dst[i + 6] = (l >>> 8) & 255; + dst[i + 4] = l >>> 24 & 255; + dst[i + 5] = l >>> 16 & 255; + dst[i + 6] = l >>> 8 & 255; dst[i + 7] = l & 255; } return dst; }; - this.decrypt = function(src) { + this.decrypt = function (src) { var dst = new Array(src.length); for (var i = 0; i < src.length; i += 8) { @@ -2469,13 +4880,13 @@ function openpgp_symenc_cast5() { r = l ^ f1(r, this.masking[0], this.rotate[0]); l = t; - dst[i] = (r >>> 24) & 255; - dst[i + 1] = (r >>> 16) & 255; - dst[i + 2] = (r >>> 8) & 255; + dst[i] = r >>> 24 & 255; + dst[i + 1] = r >>> 16 & 255; + dst[i + 2] = r >>> 8 & 255; dst[i + 3] = r & 255; - dst[i + 4] = (l >>> 24) & 255; - dst[i + 5] = (l >> 16) & 255; - dst[i + 6] = (l >> 8) & 255; + dst[i + 4] = l >>> 24 & 255; + dst[i + 5] = l >> 16 & 255; + dst[i + 6] = l >> 8 & 255; dst[i + 7] = l & 255; } @@ -2501,7 +4912,6 @@ function openpgp_symenc_cast5() { scheduleA[2][2] = new Array(6, 3, 16 + 7, 16 + 6, 16 + 5, 16 + 4, 9); scheduleA[2][3] = new Array(7, 1, 16 + 0xa, 16 + 9, 16 + 0xb, 16 + 8, 0xb); - scheduleA[3] = new Array(4); scheduleA[3][0] = new Array(0, 6, 16 + 5, 16 + 7, 16 + 4, 16 + 6, 16 + 0); scheduleA[3][1] = new Array(1, 4, 0, 2, 1, 3, 16 + 2); @@ -2522,14 +4932,12 @@ function openpgp_symenc_cast5() { scheduleB[1][2] = new Array(7, 6, 8, 9, 3); scheduleB[1][3] = new Array(5, 4, 0xa, 0xb, 7); - scheduleB[2] = new Array(4); scheduleB[2][0] = new Array(16 + 3, 16 + 2, 16 + 0xc, 16 + 0xd, 16 + 9); scheduleB[2][1] = new Array(16 + 1, 16 + 0, 16 + 0xe, 16 + 0xf, 16 + 0xc); scheduleB[2][2] = new Array(16 + 7, 16 + 6, 16 + 8, 16 + 9, 16 + 2); scheduleB[2][3] = new Array(16 + 5, 16 + 4, 16 + 0xa, 16 + 0xb, 16 + 6); - scheduleB[3] = new Array(4); scheduleB[3][0] = new Array(8, 9, 7, 6, 3); scheduleB[3][1] = new Array(0xa, 0xb, 5, 4, 7); @@ -2537,7 +4945,7 @@ function openpgp_symenc_cast5() { scheduleB[3][3] = new Array(0xe, 0xf, 1, 0, 0xd); // changed 'in' to 'inn' (in javascript 'in' is a reserved word) - this.keySchedule = function(inn) { + this.keySchedule = function (inn) { var t = new Array(8); var k = new Array(32); @@ -2558,22 +4966,22 @@ function openpgp_symenc_cast5() { var a = scheduleA[round][j]; w = t[a[1]]; - w ^= sBox[4][(t[a[2] >>> 2] >>> (24 - 8 * (a[2] & 3))) & 0xff]; - w ^= sBox[5][(t[a[3] >>> 2] >>> (24 - 8 * (a[3] & 3))) & 0xff]; - w ^= sBox[6][(t[a[4] >>> 2] >>> (24 - 8 * (a[4] & 3))) & 0xff]; - w ^= sBox[7][(t[a[5] >>> 2] >>> (24 - 8 * (a[5] & 3))) & 0xff]; - w ^= sBox[x[j]][(t[a[6] >>> 2] >>> (24 - 8 * (a[6] & 3))) & 0xff]; + w ^= sBox[4][t[a[2] >>> 2] >>> 24 - 8 * (a[2] & 3) & 0xff]; + w ^= sBox[5][t[a[3] >>> 2] >>> 24 - 8 * (a[3] & 3) & 0xff]; + w ^= sBox[6][t[a[4] >>> 2] >>> 24 - 8 * (a[4] & 3) & 0xff]; + w ^= sBox[7][t[a[5] >>> 2] >>> 24 - 8 * (a[5] & 3) & 0xff]; + w ^= sBox[x[j]][t[a[6] >>> 2] >>> 24 - 8 * (a[6] & 3) & 0xff]; t[a[0]] = w; } for (j = 0; j < 4; j++) { var b = scheduleB[round][j]; - w = sBox[4][(t[b[0] >>> 2] >>> (24 - 8 * (b[0] & 3))) & 0xff]; + w = sBox[4][t[b[0] >>> 2] >>> 24 - 8 * (b[0] & 3) & 0xff]; - w ^= sBox[5][(t[b[1] >>> 2] >>> (24 - 8 * (b[1] & 3))) & 0xff]; - w ^= sBox[6][(t[b[2] >>> 2] >>> (24 - 8 * (b[2] & 3))) & 0xff]; - w ^= sBox[7][(t[b[3] >>> 2] >>> (24 - 8 * (b[3] & 3))) & 0xff]; - w ^= sBox[4 + j][(t[b[4] >>> 2] >>> (24 - 8 * (b[4] & 3))) & 0xff]; + w ^= sBox[5][t[b[1] >>> 2] >>> 24 - 8 * (b[1] & 3) & 0xff]; + w ^= sBox[6][t[b[2] >>> 2] >>> 24 - 8 * (b[2] & 3) & 0xff]; + w ^= sBox[7][t[b[3] >>> 2] >>> 24 - 8 * (b[3] & 3) & 0xff]; + w ^= sBox[4 + j][t[b[4] >>> 2] >>> 24 - 8 * (b[4] & 3) & 0xff]; k[ki] = w; ki++; } @@ -2590,312 +4998,53 @@ function openpgp_symenc_cast5() { function f1(d, m, r) { var t = m + d; - var I = (t << r) | (t >>> (32 - r)); - return ((sBox[0][I >>> 24] ^ sBox[1][(I >>> 16) & 255]) - sBox[2][(I >>> 8) & 255]) + sBox[3][I & 255]; + var I = t << r | t >>> 32 - r; + return (sBox[0][I >>> 24] ^ sBox[1][I >>> 16 & 255]) - sBox[2][I >>> 8 & 255] + sBox[3][I & 255]; } function f2(d, m, r) { var t = m ^ d; - var I = (t << r) | (t >>> (32 - r)); - return ((sBox[0][I >>> 24] - sBox[1][(I >>> 16) & 255]) + sBox[2][(I >>> 8) & 255]) ^ sBox[3][I & 255]; + var I = t << r | t >>> 32 - r; + return sBox[0][I >>> 24] - sBox[1][I >>> 16 & 255] + sBox[2][I >>> 8 & 255] ^ sBox[3][I & 255]; } function f3(d, m, r) { var t = m - d; - var I = (t << r) | (t >>> (32 - r)); - return ((sBox[0][I >>> 24] + sBox[1][(I >>> 16) & 255]) ^ sBox[2][(I >>> 8) & 255]) - sBox[3][I & 255]; + var I = t << r | t >>> 32 - r; + return (sBox[0][I >>> 24] + sBox[1][I >>> 16 & 255] ^ sBox[2][I >>> 8 & 255]) - sBox[3][I & 255]; } var sBox = new Array(8); - sBox[0] = new Array( - 0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3, 0x6003e540, 0xcf9fc949, - 0xbfd4af27, 0x88bbbdb5, 0xe2034090, 0x98d09675, 0x6e63a0e0, 0x15c361d2, 0xc2e7661d, 0x22d4ff8e, - 0x28683b6f, 0xc07fd059, 0xff2379c8, 0x775f50e2, 0x43c340d3, 0xdf2f8656, 0x887ca41a, 0xa2d2bd2d, - 0xa1c9e0d6, 0x346c4819, 0x61b76d87, 0x22540f2f, 0x2abe32e1, 0xaa54166b, 0x22568e3a, 0xa2d341d0, - 0x66db40c8, 0xa784392f, 0x004dff2f, 0x2db9d2de, 0x97943fac, 0x4a97c1d8, 0x527644b7, 0xb5f437a7, - 0xb82cbaef, 0xd751d159, 0x6ff7f0ed, 0x5a097a1f, 0x827b68d0, 0x90ecf52e, 0x22b0c054, 0xbc8e5935, - 0x4b6d2f7f, 0x50bb64a2, 0xd2664910, 0xbee5812d, 0xb7332290, 0xe93b159f, 0xb48ee411, 0x4bff345d, - 0xfd45c240, 0xad31973f, 0xc4f6d02e, 0x55fc8165, 0xd5b1caad, 0xa1ac2dae, 0xa2d4b76d, 0xc19b0c50, - 0x882240f2, 0x0c6e4f38, 0xa4e4bfd7, 0x4f5ba272, 0x564c1d2f, 0xc59c5319, 0xb949e354, 0xb04669fe, - 0xb1b6ab8a, 0xc71358dd, 0x6385c545, 0x110f935d, 0x57538ad5, 0x6a390493, 0xe63d37e0, 0x2a54f6b3, - 0x3a787d5f, 0x6276a0b5, 0x19a6fcdf, 0x7a42206a, 0x29f9d4d5, 0xf61b1891, 0xbb72275e, 0xaa508167, - 0x38901091, 0xc6b505eb, 0x84c7cb8c, 0x2ad75a0f, 0x874a1427, 0xa2d1936b, 0x2ad286af, 0xaa56d291, - 0xd7894360, 0x425c750d, 0x93b39e26, 0x187184c9, 0x6c00b32d, 0x73e2bb14, 0xa0bebc3c, 0x54623779, - 0x64459eab, 0x3f328b82, 0x7718cf82, 0x59a2cea6, 0x04ee002e, 0x89fe78e6, 0x3fab0950, 0x325ff6c2, - 0x81383f05, 0x6963c5c8, 0x76cb5ad6, 0xd49974c9, 0xca180dcf, 0x380782d5, 0xc7fa5cf6, 0x8ac31511, - 0x35e79e13, 0x47da91d0, 0xf40f9086, 0xa7e2419e, 0x31366241, 0x051ef495, 0xaa573b04, 0x4a805d8d, - 0x548300d0, 0x00322a3c, 0xbf64cddf, 0xba57a68e, 0x75c6372b, 0x50afd341, 0xa7c13275, 0x915a0bf5, - 0x6b54bfab, 0x2b0b1426, 0xab4cc9d7, 0x449ccd82, 0xf7fbf265, 0xab85c5f3, 0x1b55db94, 0xaad4e324, - 0xcfa4bd3f, 0x2deaa3e2, 0x9e204d02, 0xc8bd25ac, 0xeadf55b3, 0xd5bd9e98, 0xe31231b2, 0x2ad5ad6c, - 0x954329de, 0xadbe4528, 0xd8710f69, 0xaa51c90f, 0xaa786bf6, 0x22513f1e, 0xaa51a79b, 0x2ad344cc, - 0x7b5a41f0, 0xd37cfbad, 0x1b069505, 0x41ece491, 0xb4c332e6, 0x032268d4, 0xc9600acc, 0xce387e6d, - 0xbf6bb16c, 0x6a70fb78, 0x0d03d9c9, 0xd4df39de, 0xe01063da, 0x4736f464, 0x5ad328d8, 0xb347cc96, - 0x75bb0fc3, 0x98511bfb, 0x4ffbcc35, 0xb58bcf6a, 0xe11f0abc, 0xbfc5fe4a, 0xa70aec10, 0xac39570a, - 0x3f04442f, 0x6188b153, 0xe0397a2e, 0x5727cb79, 0x9ceb418f, 0x1cacd68d, 0x2ad37c96, 0x0175cb9d, - 0xc69dff09, 0xc75b65f0, 0xd9db40d8, 0xec0e7779, 0x4744ead4, 0xb11c3274, 0xdd24cb9e, 0x7e1c54bd, - 0xf01144f9, 0xd2240eb1, 0x9675b3fd, 0xa3ac3755, 0xd47c27af, 0x51c85f4d, 0x56907596, 0xa5bb15e6, - 0x580304f0, 0xca042cf1, 0x011a37ea, 0x8dbfaadb, 0x35ba3e4a, 0x3526ffa0, 0xc37b4d09, 0xbc306ed9, - 0x98a52666, 0x5648f725, 0xff5e569d, 0x0ced63d0, 0x7c63b2cf, 0x700b45e1, 0xd5ea50f1, 0x85a92872, - 0xaf1fbda7, 0xd4234870, 0xa7870bf3, 0x2d3b4d79, 0x42e04198, 0x0cd0ede7, 0x26470db8, 0xf881814c, - 0x474d6ad7, 0x7c0c5e5c, 0xd1231959, 0x381b7298, 0xf5d2f4db, 0xab838653, 0x6e2f1e23, 0x83719c9e, - 0xbd91e046, 0x9a56456e, 0xdc39200c, 0x20c8c571, 0x962bda1c, 0xe1e696ff, 0xb141ab08, 0x7cca89b9, - 0x1a69e783, 0x02cc4843, 0xa2f7c579, 0x429ef47d, 0x427b169c, 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf); + sBox[0] = new Array(0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3, 0x6003e540, 0xcf9fc949, 0xbfd4af27, 0x88bbbdb5, 0xe2034090, 0x98d09675, 0x6e63a0e0, 0x15c361d2, 0xc2e7661d, 0x22d4ff8e, 0x28683b6f, 0xc07fd059, 0xff2379c8, 0x775f50e2, 0x43c340d3, 0xdf2f8656, 0x887ca41a, 0xa2d2bd2d, 0xa1c9e0d6, 0x346c4819, 0x61b76d87, 0x22540f2f, 0x2abe32e1, 0xaa54166b, 0x22568e3a, 0xa2d341d0, 0x66db40c8, 0xa784392f, 0x004dff2f, 0x2db9d2de, 0x97943fac, 0x4a97c1d8, 0x527644b7, 0xb5f437a7, 0xb82cbaef, 0xd751d159, 0x6ff7f0ed, 0x5a097a1f, 0x827b68d0, 0x90ecf52e, 0x22b0c054, 0xbc8e5935, 0x4b6d2f7f, 0x50bb64a2, 0xd2664910, 0xbee5812d, 0xb7332290, 0xe93b159f, 0xb48ee411, 0x4bff345d, 0xfd45c240, 0xad31973f, 0xc4f6d02e, 0x55fc8165, 0xd5b1caad, 0xa1ac2dae, 0xa2d4b76d, 0xc19b0c50, 0x882240f2, 0x0c6e4f38, 0xa4e4bfd7, 0x4f5ba272, 0x564c1d2f, 0xc59c5319, 0xb949e354, 0xb04669fe, 0xb1b6ab8a, 0xc71358dd, 0x6385c545, 0x110f935d, 0x57538ad5, 0x6a390493, 0xe63d37e0, 0x2a54f6b3, 0x3a787d5f, 0x6276a0b5, 0x19a6fcdf, 0x7a42206a, 0x29f9d4d5, 0xf61b1891, 0xbb72275e, 0xaa508167, 0x38901091, 0xc6b505eb, 0x84c7cb8c, 0x2ad75a0f, 0x874a1427, 0xa2d1936b, 0x2ad286af, 0xaa56d291, 0xd7894360, 0x425c750d, 0x93b39e26, 0x187184c9, 0x6c00b32d, 0x73e2bb14, 0xa0bebc3c, 0x54623779, 0x64459eab, 0x3f328b82, 0x7718cf82, 0x59a2cea6, 0x04ee002e, 0x89fe78e6, 0x3fab0950, 0x325ff6c2, 0x81383f05, 0x6963c5c8, 0x76cb5ad6, 0xd49974c9, 0xca180dcf, 0x380782d5, 0xc7fa5cf6, 0x8ac31511, 0x35e79e13, 0x47da91d0, 0xf40f9086, 0xa7e2419e, 0x31366241, 0x051ef495, 0xaa573b04, 0x4a805d8d, 0x548300d0, 0x00322a3c, 0xbf64cddf, 0xba57a68e, 0x75c6372b, 0x50afd341, 0xa7c13275, 0x915a0bf5, 0x6b54bfab, 0x2b0b1426, 0xab4cc9d7, 0x449ccd82, 0xf7fbf265, 0xab85c5f3, 0x1b55db94, 0xaad4e324, 0xcfa4bd3f, 0x2deaa3e2, 0x9e204d02, 0xc8bd25ac, 0xeadf55b3, 0xd5bd9e98, 0xe31231b2, 0x2ad5ad6c, 0x954329de, 0xadbe4528, 0xd8710f69, 0xaa51c90f, 0xaa786bf6, 0x22513f1e, 0xaa51a79b, 0x2ad344cc, 0x7b5a41f0, 0xd37cfbad, 0x1b069505, 0x41ece491, 0xb4c332e6, 0x032268d4, 0xc9600acc, 0xce387e6d, 0xbf6bb16c, 0x6a70fb78, 0x0d03d9c9, 0xd4df39de, 0xe01063da, 0x4736f464, 0x5ad328d8, 0xb347cc96, 0x75bb0fc3, 0x98511bfb, 0x4ffbcc35, 0xb58bcf6a, 0xe11f0abc, 0xbfc5fe4a, 0xa70aec10, 0xac39570a, 0x3f04442f, 0x6188b153, 0xe0397a2e, 0x5727cb79, 0x9ceb418f, 0x1cacd68d, 0x2ad37c96, 0x0175cb9d, 0xc69dff09, 0xc75b65f0, 0xd9db40d8, 0xec0e7779, 0x4744ead4, 0xb11c3274, 0xdd24cb9e, 0x7e1c54bd, 0xf01144f9, 0xd2240eb1, 0x9675b3fd, 0xa3ac3755, 0xd47c27af, 0x51c85f4d, 0x56907596, 0xa5bb15e6, 0x580304f0, 0xca042cf1, 0x011a37ea, 0x8dbfaadb, 0x35ba3e4a, 0x3526ffa0, 0xc37b4d09, 0xbc306ed9, 0x98a52666, 0x5648f725, 0xff5e569d, 0x0ced63d0, 0x7c63b2cf, 0x700b45e1, 0xd5ea50f1, 0x85a92872, 0xaf1fbda7, 0xd4234870, 0xa7870bf3, 0x2d3b4d79, 0x42e04198, 0x0cd0ede7, 0x26470db8, 0xf881814c, 0x474d6ad7, 0x7c0c5e5c, 0xd1231959, 0x381b7298, 0xf5d2f4db, 0xab838653, 0x6e2f1e23, 0x83719c9e, 0xbd91e046, 0x9a56456e, 0xdc39200c, 0x20c8c571, 0x962bda1c, 0xe1e696ff, 0xb141ab08, 0x7cca89b9, 0x1a69e783, 0x02cc4843, 0xa2f7c579, 0x429ef47d, 0x427b169c, 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf); - sBox[1] = new Array( - 0x1f201094, 0xef0ba75b, 0x69e3cf7e, 0x393f4380, 0xfe61cf7a, 0xeec5207a, 0x55889c94, 0x72fc0651, - 0xada7ef79, 0x4e1d7235, 0xd55a63ce, 0xde0436ba, 0x99c430ef, 0x5f0c0794, 0x18dcdb7d, 0xa1d6eff3, - 0xa0b52f7b, 0x59e83605, 0xee15b094, 0xe9ffd909, 0xdc440086, 0xef944459, 0xba83ccb3, 0xe0c3cdfb, - 0xd1da4181, 0x3b092ab1, 0xf997f1c1, 0xa5e6cf7b, 0x01420ddb, 0xe4e7ef5b, 0x25a1ff41, 0xe180f806, - 0x1fc41080, 0x179bee7a, 0xd37ac6a9, 0xfe5830a4, 0x98de8b7f, 0x77e83f4e, 0x79929269, 0x24fa9f7b, - 0xe113c85b, 0xacc40083, 0xd7503525, 0xf7ea615f, 0x62143154, 0x0d554b63, 0x5d681121, 0xc866c359, - 0x3d63cf73, 0xcee234c0, 0xd4d87e87, 0x5c672b21, 0x071f6181, 0x39f7627f, 0x361e3084, 0xe4eb573b, - 0x602f64a4, 0xd63acd9c, 0x1bbc4635, 0x9e81032d, 0x2701f50c, 0x99847ab4, 0xa0e3df79, 0xba6cf38c, - 0x10843094, 0x2537a95e, 0xf46f6ffe, 0xa1ff3b1f, 0x208cfb6a, 0x8f458c74, 0xd9e0a227, 0x4ec73a34, - 0xfc884f69, 0x3e4de8df, 0xef0e0088, 0x3559648d, 0x8a45388c, 0x1d804366, 0x721d9bfd, 0xa58684bb, - 0xe8256333, 0x844e8212, 0x128d8098, 0xfed33fb4, 0xce280ae1, 0x27e19ba5, 0xd5a6c252, 0xe49754bd, - 0xc5d655dd, 0xeb667064, 0x77840b4d, 0xa1b6a801, 0x84db26a9, 0xe0b56714, 0x21f043b7, 0xe5d05860, - 0x54f03084, 0x066ff472, 0xa31aa153, 0xdadc4755, 0xb5625dbf, 0x68561be6, 0x83ca6b94, 0x2d6ed23b, - 0xeccf01db, 0xa6d3d0ba, 0xb6803d5c, 0xaf77a709, 0x33b4a34c, 0x397bc8d6, 0x5ee22b95, 0x5f0e5304, - 0x81ed6f61, 0x20e74364, 0xb45e1378, 0xde18639b, 0x881ca122, 0xb96726d1, 0x8049a7e8, 0x22b7da7b, - 0x5e552d25, 0x5272d237, 0x79d2951c, 0xc60d894c, 0x488cb402, 0x1ba4fe5b, 0xa4b09f6b, 0x1ca815cf, - 0xa20c3005, 0x8871df63, 0xb9de2fcb, 0x0cc6c9e9, 0x0beeff53, 0xe3214517, 0xb4542835, 0x9f63293c, - 0xee41e729, 0x6e1d2d7c, 0x50045286, 0x1e6685f3, 0xf33401c6, 0x30a22c95, 0x31a70850, 0x60930f13, - 0x73f98417, 0xa1269859, 0xec645c44, 0x52c877a9, 0xcdff33a6, 0xa02b1741, 0x7cbad9a2, 0x2180036f, - 0x50d99c08, 0xcb3f4861, 0xc26bd765, 0x64a3f6ab, 0x80342676, 0x25a75e7b, 0xe4e6d1fc, 0x20c710e6, - 0xcdf0b680, 0x17844d3b, 0x31eef84d, 0x7e0824e4, 0x2ccb49eb, 0x846a3bae, 0x8ff77888, 0xee5d60f6, - 0x7af75673, 0x2fdd5cdb, 0xa11631c1, 0x30f66f43, 0xb3faec54, 0x157fd7fa, 0xef8579cc, 0xd152de58, - 0xdb2ffd5e, 0x8f32ce19, 0x306af97a, 0x02f03ef8, 0x99319ad5, 0xc242fa0f, 0xa7e3ebb0, 0xc68e4906, - 0xb8da230c, 0x80823028, 0xdcdef3c8, 0xd35fb171, 0x088a1bc8, 0xbec0c560, 0x61a3c9e8, 0xbca8f54d, - 0xc72feffa, 0x22822e99, 0x82c570b4, 0xd8d94e89, 0x8b1c34bc, 0x301e16e6, 0x273be979, 0xb0ffeaa6, - 0x61d9b8c6, 0x00b24869, 0xb7ffce3f, 0x08dc283b, 0x43daf65a, 0xf7e19798, 0x7619b72f, 0x8f1c9ba4, - 0xdc8637a0, 0x16a7d3b1, 0x9fc393b7, 0xa7136eeb, 0xc6bcc63e, 0x1a513742, 0xef6828bc, 0x520365d6, - 0x2d6a77ab, 0x3527ed4b, 0x821fd216, 0x095c6e2e, 0xdb92f2fb, 0x5eea29cb, 0x145892f5, 0x91584f7f, - 0x5483697b, 0x2667a8cc, 0x85196048, 0x8c4bacea, 0x833860d4, 0x0d23e0f9, 0x6c387e8a, 0x0ae6d249, - 0xb284600c, 0xd835731d, 0xdcb1c647, 0xac4c56ea, 0x3ebd81b3, 0x230eabb0, 0x6438bc87, 0xf0b5b1fa, - 0x8f5ea2b3, 0xfc184642, 0x0a036b7a, 0x4fb089bd, 0x649da589, 0xa345415e, 0x5c038323, 0x3e5d3bb9, - 0x43d79572, 0x7e6dd07c, 0x06dfdf1e, 0x6c6cc4ef, 0x7160a539, 0x73bfbe70, 0x83877605, 0x4523ecf1); + sBox[1] = new Array(0x1f201094, 0xef0ba75b, 0x69e3cf7e, 0x393f4380, 0xfe61cf7a, 0xeec5207a, 0x55889c94, 0x72fc0651, 0xada7ef79, 0x4e1d7235, 0xd55a63ce, 0xde0436ba, 0x99c430ef, 0x5f0c0794, 0x18dcdb7d, 0xa1d6eff3, 0xa0b52f7b, 0x59e83605, 0xee15b094, 0xe9ffd909, 0xdc440086, 0xef944459, 0xba83ccb3, 0xe0c3cdfb, 0xd1da4181, 0x3b092ab1, 0xf997f1c1, 0xa5e6cf7b, 0x01420ddb, 0xe4e7ef5b, 0x25a1ff41, 0xe180f806, 0x1fc41080, 0x179bee7a, 0xd37ac6a9, 0xfe5830a4, 0x98de8b7f, 0x77e83f4e, 0x79929269, 0x24fa9f7b, 0xe113c85b, 0xacc40083, 0xd7503525, 0xf7ea615f, 0x62143154, 0x0d554b63, 0x5d681121, 0xc866c359, 0x3d63cf73, 0xcee234c0, 0xd4d87e87, 0x5c672b21, 0x071f6181, 0x39f7627f, 0x361e3084, 0xe4eb573b, 0x602f64a4, 0xd63acd9c, 0x1bbc4635, 0x9e81032d, 0x2701f50c, 0x99847ab4, 0xa0e3df79, 0xba6cf38c, 0x10843094, 0x2537a95e, 0xf46f6ffe, 0xa1ff3b1f, 0x208cfb6a, 0x8f458c74, 0xd9e0a227, 0x4ec73a34, 0xfc884f69, 0x3e4de8df, 0xef0e0088, 0x3559648d, 0x8a45388c, 0x1d804366, 0x721d9bfd, 0xa58684bb, 0xe8256333, 0x844e8212, 0x128d8098, 0xfed33fb4, 0xce280ae1, 0x27e19ba5, 0xd5a6c252, 0xe49754bd, 0xc5d655dd, 0xeb667064, 0x77840b4d, 0xa1b6a801, 0x84db26a9, 0xe0b56714, 0x21f043b7, 0xe5d05860, 0x54f03084, 0x066ff472, 0xa31aa153, 0xdadc4755, 0xb5625dbf, 0x68561be6, 0x83ca6b94, 0x2d6ed23b, 0xeccf01db, 0xa6d3d0ba, 0xb6803d5c, 0xaf77a709, 0x33b4a34c, 0x397bc8d6, 0x5ee22b95, 0x5f0e5304, 0x81ed6f61, 0x20e74364, 0xb45e1378, 0xde18639b, 0x881ca122, 0xb96726d1, 0x8049a7e8, 0x22b7da7b, 0x5e552d25, 0x5272d237, 0x79d2951c, 0xc60d894c, 0x488cb402, 0x1ba4fe5b, 0xa4b09f6b, 0x1ca815cf, 0xa20c3005, 0x8871df63, 0xb9de2fcb, 0x0cc6c9e9, 0x0beeff53, 0xe3214517, 0xb4542835, 0x9f63293c, 0xee41e729, 0x6e1d2d7c, 0x50045286, 0x1e6685f3, 0xf33401c6, 0x30a22c95, 0x31a70850, 0x60930f13, 0x73f98417, 0xa1269859, 0xec645c44, 0x52c877a9, 0xcdff33a6, 0xa02b1741, 0x7cbad9a2, 0x2180036f, 0x50d99c08, 0xcb3f4861, 0xc26bd765, 0x64a3f6ab, 0x80342676, 0x25a75e7b, 0xe4e6d1fc, 0x20c710e6, 0xcdf0b680, 0x17844d3b, 0x31eef84d, 0x7e0824e4, 0x2ccb49eb, 0x846a3bae, 0x8ff77888, 0xee5d60f6, 0x7af75673, 0x2fdd5cdb, 0xa11631c1, 0x30f66f43, 0xb3faec54, 0x157fd7fa, 0xef8579cc, 0xd152de58, 0xdb2ffd5e, 0x8f32ce19, 0x306af97a, 0x02f03ef8, 0x99319ad5, 0xc242fa0f, 0xa7e3ebb0, 0xc68e4906, 0xb8da230c, 0x80823028, 0xdcdef3c8, 0xd35fb171, 0x088a1bc8, 0xbec0c560, 0x61a3c9e8, 0xbca8f54d, 0xc72feffa, 0x22822e99, 0x82c570b4, 0xd8d94e89, 0x8b1c34bc, 0x301e16e6, 0x273be979, 0xb0ffeaa6, 0x61d9b8c6, 0x00b24869, 0xb7ffce3f, 0x08dc283b, 0x43daf65a, 0xf7e19798, 0x7619b72f, 0x8f1c9ba4, 0xdc8637a0, 0x16a7d3b1, 0x9fc393b7, 0xa7136eeb, 0xc6bcc63e, 0x1a513742, 0xef6828bc, 0x520365d6, 0x2d6a77ab, 0x3527ed4b, 0x821fd216, 0x095c6e2e, 0xdb92f2fb, 0x5eea29cb, 0x145892f5, 0x91584f7f, 0x5483697b, 0x2667a8cc, 0x85196048, 0x8c4bacea, 0x833860d4, 0x0d23e0f9, 0x6c387e8a, 0x0ae6d249, 0xb284600c, 0xd835731d, 0xdcb1c647, 0xac4c56ea, 0x3ebd81b3, 0x230eabb0, 0x6438bc87, 0xf0b5b1fa, 0x8f5ea2b3, 0xfc184642, 0x0a036b7a, 0x4fb089bd, 0x649da589, 0xa345415e, 0x5c038323, 0x3e5d3bb9, 0x43d79572, 0x7e6dd07c, 0x06dfdf1e, 0x6c6cc4ef, 0x7160a539, 0x73bfbe70, 0x83877605, 0x4523ecf1); - sBox[2] = new Array( - 0x8defc240, 0x25fa5d9f, 0xeb903dbf, 0xe810c907, 0x47607fff, 0x369fe44b, 0x8c1fc644, 0xaececa90, - 0xbeb1f9bf, 0xeefbcaea, 0xe8cf1950, 0x51df07ae, 0x920e8806, 0xf0ad0548, 0xe13c8d83, 0x927010d5, - 0x11107d9f, 0x07647db9, 0xb2e3e4d4, 0x3d4f285e, 0xb9afa820, 0xfade82e0, 0xa067268b, 0x8272792e, - 0x553fb2c0, 0x489ae22b, 0xd4ef9794, 0x125e3fbc, 0x21fffcee, 0x825b1bfd, 0x9255c5ed, 0x1257a240, - 0x4e1a8302, 0xbae07fff, 0x528246e7, 0x8e57140e, 0x3373f7bf, 0x8c9f8188, 0xa6fc4ee8, 0xc982b5a5, - 0xa8c01db7, 0x579fc264, 0x67094f31, 0xf2bd3f5f, 0x40fff7c1, 0x1fb78dfc, 0x8e6bd2c1, 0x437be59b, - 0x99b03dbf, 0xb5dbc64b, 0x638dc0e6, 0x55819d99, 0xa197c81c, 0x4a012d6e, 0xc5884a28, 0xccc36f71, - 0xb843c213, 0x6c0743f1, 0x8309893c, 0x0feddd5f, 0x2f7fe850, 0xd7c07f7e, 0x02507fbf, 0x5afb9a04, - 0xa747d2d0, 0x1651192e, 0xaf70bf3e, 0x58c31380, 0x5f98302e, 0x727cc3c4, 0x0a0fb402, 0x0f7fef82, - 0x8c96fdad, 0x5d2c2aae, 0x8ee99a49, 0x50da88b8, 0x8427f4a0, 0x1eac5790, 0x796fb449, 0x8252dc15, - 0xefbd7d9b, 0xa672597d, 0xada840d8, 0x45f54504, 0xfa5d7403, 0xe83ec305, 0x4f91751a, 0x925669c2, - 0x23efe941, 0xa903f12e, 0x60270df2, 0x0276e4b6, 0x94fd6574, 0x927985b2, 0x8276dbcb, 0x02778176, - 0xf8af918d, 0x4e48f79e, 0x8f616ddf, 0xe29d840e, 0x842f7d83, 0x340ce5c8, 0x96bbb682, 0x93b4b148, - 0xef303cab, 0x984faf28, 0x779faf9b, 0x92dc560d, 0x224d1e20, 0x8437aa88, 0x7d29dc96, 0x2756d3dc, - 0x8b907cee, 0xb51fd240, 0xe7c07ce3, 0xe566b4a1, 0xc3e9615e, 0x3cf8209d, 0x6094d1e3, 0xcd9ca341, - 0x5c76460e, 0x00ea983b, 0xd4d67881, 0xfd47572c, 0xf76cedd9, 0xbda8229c, 0x127dadaa, 0x438a074e, - 0x1f97c090, 0x081bdb8a, 0x93a07ebe, 0xb938ca15, 0x97b03cff, 0x3dc2c0f8, 0x8d1ab2ec, 0x64380e51, - 0x68cc7bfb, 0xd90f2788, 0x12490181, 0x5de5ffd4, 0xdd7ef86a, 0x76a2e214, 0xb9a40368, 0x925d958f, - 0x4b39fffa, 0xba39aee9, 0xa4ffd30b, 0xfaf7933b, 0x6d498623, 0x193cbcfa, 0x27627545, 0x825cf47a, - 0x61bd8ba0, 0xd11e42d1, 0xcead04f4, 0x127ea392, 0x10428db7, 0x8272a972, 0x9270c4a8, 0x127de50b, - 0x285ba1c8, 0x3c62f44f, 0x35c0eaa5, 0xe805d231, 0x428929fb, 0xb4fcdf82, 0x4fb66a53, 0x0e7dc15b, - 0x1f081fab, 0x108618ae, 0xfcfd086d, 0xf9ff2889, 0x694bcc11, 0x236a5cae, 0x12deca4d, 0x2c3f8cc5, - 0xd2d02dfe, 0xf8ef5896, 0xe4cf52da, 0x95155b67, 0x494a488c, 0xb9b6a80c, 0x5c8f82bc, 0x89d36b45, - 0x3a609437, 0xec00c9a9, 0x44715253, 0x0a874b49, 0xd773bc40, 0x7c34671c, 0x02717ef6, 0x4feb5536, - 0xa2d02fff, 0xd2bf60c4, 0xd43f03c0, 0x50b4ef6d, 0x07478cd1, 0x006e1888, 0xa2e53f55, 0xb9e6d4bc, - 0xa2048016, 0x97573833, 0xd7207d67, 0xde0f8f3d, 0x72f87b33, 0xabcc4f33, 0x7688c55d, 0x7b00a6b0, - 0x947b0001, 0x570075d2, 0xf9bb88f8, 0x8942019e, 0x4264a5ff, 0x856302e0, 0x72dbd92b, 0xee971b69, - 0x6ea22fde, 0x5f08ae2b, 0xaf7a616d, 0xe5c98767, 0xcf1febd2, 0x61efc8c2, 0xf1ac2571, 0xcc8239c2, - 0x67214cb8, 0xb1e583d1, 0xb7dc3e62, 0x7f10bdce, 0xf90a5c38, 0x0ff0443d, 0x606e6dc6, 0x60543a49, - 0x5727c148, 0x2be98a1d, 0x8ab41738, 0x20e1be24, 0xaf96da0f, 0x68458425, 0x99833be5, 0x600d457d, - 0x282f9350, 0x8334b362, 0xd91d1120, 0x2b6d8da0, 0x642b1e31, 0x9c305a00, 0x52bce688, 0x1b03588a, - 0xf7baefd5, 0x4142ed9c, 0xa4315c11, 0x83323ec5, 0xdfef4636, 0xa133c501, 0xe9d3531c, 0xee353783); + sBox[2] = new Array(0x8defc240, 0x25fa5d9f, 0xeb903dbf, 0xe810c907, 0x47607fff, 0x369fe44b, 0x8c1fc644, 0xaececa90, 0xbeb1f9bf, 0xeefbcaea, 0xe8cf1950, 0x51df07ae, 0x920e8806, 0xf0ad0548, 0xe13c8d83, 0x927010d5, 0x11107d9f, 0x07647db9, 0xb2e3e4d4, 0x3d4f285e, 0xb9afa820, 0xfade82e0, 0xa067268b, 0x8272792e, 0x553fb2c0, 0x489ae22b, 0xd4ef9794, 0x125e3fbc, 0x21fffcee, 0x825b1bfd, 0x9255c5ed, 0x1257a240, 0x4e1a8302, 0xbae07fff, 0x528246e7, 0x8e57140e, 0x3373f7bf, 0x8c9f8188, 0xa6fc4ee8, 0xc982b5a5, 0xa8c01db7, 0x579fc264, 0x67094f31, 0xf2bd3f5f, 0x40fff7c1, 0x1fb78dfc, 0x8e6bd2c1, 0x437be59b, 0x99b03dbf, 0xb5dbc64b, 0x638dc0e6, 0x55819d99, 0xa197c81c, 0x4a012d6e, 0xc5884a28, 0xccc36f71, 0xb843c213, 0x6c0743f1, 0x8309893c, 0x0feddd5f, 0x2f7fe850, 0xd7c07f7e, 0x02507fbf, 0x5afb9a04, 0xa747d2d0, 0x1651192e, 0xaf70bf3e, 0x58c31380, 0x5f98302e, 0x727cc3c4, 0x0a0fb402, 0x0f7fef82, 0x8c96fdad, 0x5d2c2aae, 0x8ee99a49, 0x50da88b8, 0x8427f4a0, 0x1eac5790, 0x796fb449, 0x8252dc15, 0xefbd7d9b, 0xa672597d, 0xada840d8, 0x45f54504, 0xfa5d7403, 0xe83ec305, 0x4f91751a, 0x925669c2, 0x23efe941, 0xa903f12e, 0x60270df2, 0x0276e4b6, 0x94fd6574, 0x927985b2, 0x8276dbcb, 0x02778176, 0xf8af918d, 0x4e48f79e, 0x8f616ddf, 0xe29d840e, 0x842f7d83, 0x340ce5c8, 0x96bbb682, 0x93b4b148, 0xef303cab, 0x984faf28, 0x779faf9b, 0x92dc560d, 0x224d1e20, 0x8437aa88, 0x7d29dc96, 0x2756d3dc, 0x8b907cee, 0xb51fd240, 0xe7c07ce3, 0xe566b4a1, 0xc3e9615e, 0x3cf8209d, 0x6094d1e3, 0xcd9ca341, 0x5c76460e, 0x00ea983b, 0xd4d67881, 0xfd47572c, 0xf76cedd9, 0xbda8229c, 0x127dadaa, 0x438a074e, 0x1f97c090, 0x081bdb8a, 0x93a07ebe, 0xb938ca15, 0x97b03cff, 0x3dc2c0f8, 0x8d1ab2ec, 0x64380e51, 0x68cc7bfb, 0xd90f2788, 0x12490181, 0x5de5ffd4, 0xdd7ef86a, 0x76a2e214, 0xb9a40368, 0x925d958f, 0x4b39fffa, 0xba39aee9, 0xa4ffd30b, 0xfaf7933b, 0x6d498623, 0x193cbcfa, 0x27627545, 0x825cf47a, 0x61bd8ba0, 0xd11e42d1, 0xcead04f4, 0x127ea392, 0x10428db7, 0x8272a972, 0x9270c4a8, 0x127de50b, 0x285ba1c8, 0x3c62f44f, 0x35c0eaa5, 0xe805d231, 0x428929fb, 0xb4fcdf82, 0x4fb66a53, 0x0e7dc15b, 0x1f081fab, 0x108618ae, 0xfcfd086d, 0xf9ff2889, 0x694bcc11, 0x236a5cae, 0x12deca4d, 0x2c3f8cc5, 0xd2d02dfe, 0xf8ef5896, 0xe4cf52da, 0x95155b67, 0x494a488c, 0xb9b6a80c, 0x5c8f82bc, 0x89d36b45, 0x3a609437, 0xec00c9a9, 0x44715253, 0x0a874b49, 0xd773bc40, 0x7c34671c, 0x02717ef6, 0x4feb5536, 0xa2d02fff, 0xd2bf60c4, 0xd43f03c0, 0x50b4ef6d, 0x07478cd1, 0x006e1888, 0xa2e53f55, 0xb9e6d4bc, 0xa2048016, 0x97573833, 0xd7207d67, 0xde0f8f3d, 0x72f87b33, 0xabcc4f33, 0x7688c55d, 0x7b00a6b0, 0x947b0001, 0x570075d2, 0xf9bb88f8, 0x8942019e, 0x4264a5ff, 0x856302e0, 0x72dbd92b, 0xee971b69, 0x6ea22fde, 0x5f08ae2b, 0xaf7a616d, 0xe5c98767, 0xcf1febd2, 0x61efc8c2, 0xf1ac2571, 0xcc8239c2, 0x67214cb8, 0xb1e583d1, 0xb7dc3e62, 0x7f10bdce, 0xf90a5c38, 0x0ff0443d, 0x606e6dc6, 0x60543a49, 0x5727c148, 0x2be98a1d, 0x8ab41738, 0x20e1be24, 0xaf96da0f, 0x68458425, 0x99833be5, 0x600d457d, 0x282f9350, 0x8334b362, 0xd91d1120, 0x2b6d8da0, 0x642b1e31, 0x9c305a00, 0x52bce688, 0x1b03588a, 0xf7baefd5, 0x4142ed9c, 0xa4315c11, 0x83323ec5, 0xdfef4636, 0xa133c501, 0xe9d3531c, 0xee353783); - sBox[3] = new Array( - 0x9db30420, 0x1fb6e9de, 0xa7be7bef, 0xd273a298, 0x4a4f7bdb, 0x64ad8c57, 0x85510443, 0xfa020ed1, - 0x7e287aff, 0xe60fb663, 0x095f35a1, 0x79ebf120, 0xfd059d43, 0x6497b7b1, 0xf3641f63, 0x241e4adf, - 0x28147f5f, 0x4fa2b8cd, 0xc9430040, 0x0cc32220, 0xfdd30b30, 0xc0a5374f, 0x1d2d00d9, 0x24147b15, - 0xee4d111a, 0x0fca5167, 0x71ff904c, 0x2d195ffe, 0x1a05645f, 0x0c13fefe, 0x081b08ca, 0x05170121, - 0x80530100, 0xe83e5efe, 0xac9af4f8, 0x7fe72701, 0xd2b8ee5f, 0x06df4261, 0xbb9e9b8a, 0x7293ea25, - 0xce84ffdf, 0xf5718801, 0x3dd64b04, 0xa26f263b, 0x7ed48400, 0x547eebe6, 0x446d4ca0, 0x6cf3d6f5, - 0x2649abdf, 0xaea0c7f5, 0x36338cc1, 0x503f7e93, 0xd3772061, 0x11b638e1, 0x72500e03, 0xf80eb2bb, - 0xabe0502e, 0xec8d77de, 0x57971e81, 0xe14f6746, 0xc9335400, 0x6920318f, 0x081dbb99, 0xffc304a5, - 0x4d351805, 0x7f3d5ce3, 0xa6c866c6, 0x5d5bcca9, 0xdaec6fea, 0x9f926f91, 0x9f46222f, 0x3991467d, - 0xa5bf6d8e, 0x1143c44f, 0x43958302, 0xd0214eeb, 0x022083b8, 0x3fb6180c, 0x18f8931e, 0x281658e6, - 0x26486e3e, 0x8bd78a70, 0x7477e4c1, 0xb506e07c, 0xf32d0a25, 0x79098b02, 0xe4eabb81, 0x28123b23, - 0x69dead38, 0x1574ca16, 0xdf871b62, 0x211c40b7, 0xa51a9ef9, 0x0014377b, 0x041e8ac8, 0x09114003, - 0xbd59e4d2, 0xe3d156d5, 0x4fe876d5, 0x2f91a340, 0x557be8de, 0x00eae4a7, 0x0ce5c2ec, 0x4db4bba6, - 0xe756bdff, 0xdd3369ac, 0xec17b035, 0x06572327, 0x99afc8b0, 0x56c8c391, 0x6b65811c, 0x5e146119, - 0x6e85cb75, 0xbe07c002, 0xc2325577, 0x893ff4ec, 0x5bbfc92d, 0xd0ec3b25, 0xb7801ab7, 0x8d6d3b24, - 0x20c763ef, 0xc366a5fc, 0x9c382880, 0x0ace3205, 0xaac9548a, 0xeca1d7c7, 0x041afa32, 0x1d16625a, - 0x6701902c, 0x9b757a54, 0x31d477f7, 0x9126b031, 0x36cc6fdb, 0xc70b8b46, 0xd9e66a48, 0x56e55a79, - 0x026a4ceb, 0x52437eff, 0x2f8f76b4, 0x0df980a5, 0x8674cde3, 0xedda04eb, 0x17a9be04, 0x2c18f4df, - 0xb7747f9d, 0xab2af7b4, 0xefc34d20, 0x2e096b7c, 0x1741a254, 0xe5b6a035, 0x213d42f6, 0x2c1c7c26, - 0x61c2f50f, 0x6552daf9, 0xd2c231f8, 0x25130f69, 0xd8167fa2, 0x0418f2c8, 0x001a96a6, 0x0d1526ab, - 0x63315c21, 0x5e0a72ec, 0x49bafefd, 0x187908d9, 0x8d0dbd86, 0x311170a7, 0x3e9b640c, 0xcc3e10d7, - 0xd5cad3b6, 0x0caec388, 0xf73001e1, 0x6c728aff, 0x71eae2a1, 0x1f9af36e, 0xcfcbd12f, 0xc1de8417, - 0xac07be6b, 0xcb44a1d8, 0x8b9b0f56, 0x013988c3, 0xb1c52fca, 0xb4be31cd, 0xd8782806, 0x12a3a4e2, - 0x6f7de532, 0x58fd7eb6, 0xd01ee900, 0x24adffc2, 0xf4990fc5, 0x9711aac5, 0x001d7b95, 0x82e5e7d2, - 0x109873f6, 0x00613096, 0xc32d9521, 0xada121ff, 0x29908415, 0x7fbb977f, 0xaf9eb3db, 0x29c9ed2a, - 0x5ce2a465, 0xa730f32c, 0xd0aa3fe8, 0x8a5cc091, 0xd49e2ce7, 0x0ce454a9, 0xd60acd86, 0x015f1919, - 0x77079103, 0xdea03af6, 0x78a8565e, 0xdee356df, 0x21f05cbe, 0x8b75e387, 0xb3c50651, 0xb8a5c3ef, - 0xd8eeb6d2, 0xe523be77, 0xc2154529, 0x2f69efdf, 0xafe67afb, 0xf470c4b2, 0xf3e0eb5b, 0xd6cc9876, - 0x39e4460c, 0x1fda8538, 0x1987832f, 0xca007367, 0xa99144f8, 0x296b299e, 0x492fc295, 0x9266beab, - 0xb5676e69, 0x9bd3ddda, 0xdf7e052f, 0xdb25701c, 0x1b5e51ee, 0xf65324e6, 0x6afce36c, 0x0316cc04, - 0x8644213e, 0xb7dc59d0, 0x7965291f, 0xccd6fd43, 0x41823979, 0x932bcdf6, 0xb657c34d, 0x4edfd282, - 0x7ae5290c, 0x3cb9536b, 0x851e20fe, 0x9833557e, 0x13ecf0b0, 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2); + sBox[3] = new Array(0x9db30420, 0x1fb6e9de, 0xa7be7bef, 0xd273a298, 0x4a4f7bdb, 0x64ad8c57, 0x85510443, 0xfa020ed1, 0x7e287aff, 0xe60fb663, 0x095f35a1, 0x79ebf120, 0xfd059d43, 0x6497b7b1, 0xf3641f63, 0x241e4adf, 0x28147f5f, 0x4fa2b8cd, 0xc9430040, 0x0cc32220, 0xfdd30b30, 0xc0a5374f, 0x1d2d00d9, 0x24147b15, 0xee4d111a, 0x0fca5167, 0x71ff904c, 0x2d195ffe, 0x1a05645f, 0x0c13fefe, 0x081b08ca, 0x05170121, 0x80530100, 0xe83e5efe, 0xac9af4f8, 0x7fe72701, 0xd2b8ee5f, 0x06df4261, 0xbb9e9b8a, 0x7293ea25, 0xce84ffdf, 0xf5718801, 0x3dd64b04, 0xa26f263b, 0x7ed48400, 0x547eebe6, 0x446d4ca0, 0x6cf3d6f5, 0x2649abdf, 0xaea0c7f5, 0x36338cc1, 0x503f7e93, 0xd3772061, 0x11b638e1, 0x72500e03, 0xf80eb2bb, 0xabe0502e, 0xec8d77de, 0x57971e81, 0xe14f6746, 0xc9335400, 0x6920318f, 0x081dbb99, 0xffc304a5, 0x4d351805, 0x7f3d5ce3, 0xa6c866c6, 0x5d5bcca9, 0xdaec6fea, 0x9f926f91, 0x9f46222f, 0x3991467d, 0xa5bf6d8e, 0x1143c44f, 0x43958302, 0xd0214eeb, 0x022083b8, 0x3fb6180c, 0x18f8931e, 0x281658e6, 0x26486e3e, 0x8bd78a70, 0x7477e4c1, 0xb506e07c, 0xf32d0a25, 0x79098b02, 0xe4eabb81, 0x28123b23, 0x69dead38, 0x1574ca16, 0xdf871b62, 0x211c40b7, 0xa51a9ef9, 0x0014377b, 0x041e8ac8, 0x09114003, 0xbd59e4d2, 0xe3d156d5, 0x4fe876d5, 0x2f91a340, 0x557be8de, 0x00eae4a7, 0x0ce5c2ec, 0x4db4bba6, 0xe756bdff, 0xdd3369ac, 0xec17b035, 0x06572327, 0x99afc8b0, 0x56c8c391, 0x6b65811c, 0x5e146119, 0x6e85cb75, 0xbe07c002, 0xc2325577, 0x893ff4ec, 0x5bbfc92d, 0xd0ec3b25, 0xb7801ab7, 0x8d6d3b24, 0x20c763ef, 0xc366a5fc, 0x9c382880, 0x0ace3205, 0xaac9548a, 0xeca1d7c7, 0x041afa32, 0x1d16625a, 0x6701902c, 0x9b757a54, 0x31d477f7, 0x9126b031, 0x36cc6fdb, 0xc70b8b46, 0xd9e66a48, 0x56e55a79, 0x026a4ceb, 0x52437eff, 0x2f8f76b4, 0x0df980a5, 0x8674cde3, 0xedda04eb, 0x17a9be04, 0x2c18f4df, 0xb7747f9d, 0xab2af7b4, 0xefc34d20, 0x2e096b7c, 0x1741a254, 0xe5b6a035, 0x213d42f6, 0x2c1c7c26, 0x61c2f50f, 0x6552daf9, 0xd2c231f8, 0x25130f69, 0xd8167fa2, 0x0418f2c8, 0x001a96a6, 0x0d1526ab, 0x63315c21, 0x5e0a72ec, 0x49bafefd, 0x187908d9, 0x8d0dbd86, 0x311170a7, 0x3e9b640c, 0xcc3e10d7, 0xd5cad3b6, 0x0caec388, 0xf73001e1, 0x6c728aff, 0x71eae2a1, 0x1f9af36e, 0xcfcbd12f, 0xc1de8417, 0xac07be6b, 0xcb44a1d8, 0x8b9b0f56, 0x013988c3, 0xb1c52fca, 0xb4be31cd, 0xd8782806, 0x12a3a4e2, 0x6f7de532, 0x58fd7eb6, 0xd01ee900, 0x24adffc2, 0xf4990fc5, 0x9711aac5, 0x001d7b95, 0x82e5e7d2, 0x109873f6, 0x00613096, 0xc32d9521, 0xada121ff, 0x29908415, 0x7fbb977f, 0xaf9eb3db, 0x29c9ed2a, 0x5ce2a465, 0xa730f32c, 0xd0aa3fe8, 0x8a5cc091, 0xd49e2ce7, 0x0ce454a9, 0xd60acd86, 0x015f1919, 0x77079103, 0xdea03af6, 0x78a8565e, 0xdee356df, 0x21f05cbe, 0x8b75e387, 0xb3c50651, 0xb8a5c3ef, 0xd8eeb6d2, 0xe523be77, 0xc2154529, 0x2f69efdf, 0xafe67afb, 0xf470c4b2, 0xf3e0eb5b, 0xd6cc9876, 0x39e4460c, 0x1fda8538, 0x1987832f, 0xca007367, 0xa99144f8, 0x296b299e, 0x492fc295, 0x9266beab, 0xb5676e69, 0x9bd3ddda, 0xdf7e052f, 0xdb25701c, 0x1b5e51ee, 0xf65324e6, 0x6afce36c, 0x0316cc04, 0x8644213e, 0xb7dc59d0, 0x7965291f, 0xccd6fd43, 0x41823979, 0x932bcdf6, 0xb657c34d, 0x4edfd282, 0x7ae5290c, 0x3cb9536b, 0x851e20fe, 0x9833557e, 0x13ecf0b0, 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2); - sBox[4] = new Array( - 0x7ec90c04, 0x2c6e74b9, 0x9b0e66df, 0xa6337911, 0xb86a7fff, 0x1dd358f5, 0x44dd9d44, 0x1731167f, - 0x08fbf1fa, 0xe7f511cc, 0xd2051b00, 0x735aba00, 0x2ab722d8, 0x386381cb, 0xacf6243a, 0x69befd7a, - 0xe6a2e77f, 0xf0c720cd, 0xc4494816, 0xccf5c180, 0x38851640, 0x15b0a848, 0xe68b18cb, 0x4caadeff, - 0x5f480a01, 0x0412b2aa, 0x259814fc, 0x41d0efe2, 0x4e40b48d, 0x248eb6fb, 0x8dba1cfe, 0x41a99b02, - 0x1a550a04, 0xba8f65cb, 0x7251f4e7, 0x95a51725, 0xc106ecd7, 0x97a5980a, 0xc539b9aa, 0x4d79fe6a, - 0xf2f3f763, 0x68af8040, 0xed0c9e56, 0x11b4958b, 0xe1eb5a88, 0x8709e6b0, 0xd7e07156, 0x4e29fea7, - 0x6366e52d, 0x02d1c000, 0xc4ac8e05, 0x9377f571, 0x0c05372a, 0x578535f2, 0x2261be02, 0xd642a0c9, - 0xdf13a280, 0x74b55bd2, 0x682199c0, 0xd421e5ec, 0x53fb3ce8, 0xc8adedb3, 0x28a87fc9, 0x3d959981, - 0x5c1ff900, 0xfe38d399, 0x0c4eff0b, 0x062407ea, 0xaa2f4fb1, 0x4fb96976, 0x90c79505, 0xb0a8a774, - 0xef55a1ff, 0xe59ca2c2, 0xa6b62d27, 0xe66a4263, 0xdf65001f, 0x0ec50966, 0xdfdd55bc, 0x29de0655, - 0x911e739a, 0x17af8975, 0x32c7911c, 0x89f89468, 0x0d01e980, 0x524755f4, 0x03b63cc9, 0x0cc844b2, - 0xbcf3f0aa, 0x87ac36e9, 0xe53a7426, 0x01b3d82b, 0x1a9e7449, 0x64ee2d7e, 0xcddbb1da, 0x01c94910, - 0xb868bf80, 0x0d26f3fd, 0x9342ede7, 0x04a5c284, 0x636737b6, 0x50f5b616, 0xf24766e3, 0x8eca36c1, - 0x136e05db, 0xfef18391, 0xfb887a37, 0xd6e7f7d4, 0xc7fb7dc9, 0x3063fcdf, 0xb6f589de, 0xec2941da, - 0x26e46695, 0xb7566419, 0xf654efc5, 0xd08d58b7, 0x48925401, 0xc1bacb7f, 0xe5ff550f, 0xb6083049, - 0x5bb5d0e8, 0x87d72e5a, 0xab6a6ee1, 0x223a66ce, 0xc62bf3cd, 0x9e0885f9, 0x68cb3e47, 0x086c010f, - 0xa21de820, 0xd18b69de, 0xf3f65777, 0xfa02c3f6, 0x407edac3, 0xcbb3d550, 0x1793084d, 0xb0d70eba, - 0x0ab378d5, 0xd951fb0c, 0xded7da56, 0x4124bbe4, 0x94ca0b56, 0x0f5755d1, 0xe0e1e56e, 0x6184b5be, - 0x580a249f, 0x94f74bc0, 0xe327888e, 0x9f7b5561, 0xc3dc0280, 0x05687715, 0x646c6bd7, 0x44904db3, - 0x66b4f0a3, 0xc0f1648a, 0x697ed5af, 0x49e92ff6, 0x309e374f, 0x2cb6356a, 0x85808573, 0x4991f840, - 0x76f0ae02, 0x083be84d, 0x28421c9a, 0x44489406, 0x736e4cb8, 0xc1092910, 0x8bc95fc6, 0x7d869cf4, - 0x134f616f, 0x2e77118d, 0xb31b2be1, 0xaa90b472, 0x3ca5d717, 0x7d161bba, 0x9cad9010, 0xaf462ba2, - 0x9fe459d2, 0x45d34559, 0xd9f2da13, 0xdbc65487, 0xf3e4f94e, 0x176d486f, 0x097c13ea, 0x631da5c7, - 0x445f7382, 0x175683f4, 0xcdc66a97, 0x70be0288, 0xb3cdcf72, 0x6e5dd2f3, 0x20936079, 0x459b80a5, - 0xbe60e2db, 0xa9c23101, 0xeba5315c, 0x224e42f2, 0x1c5c1572, 0xf6721b2c, 0x1ad2fff3, 0x8c25404e, - 0x324ed72f, 0x4067b7fd, 0x0523138e, 0x5ca3bc78, 0xdc0fd66e, 0x75922283, 0x784d6b17, 0x58ebb16e, - 0x44094f85, 0x3f481d87, 0xfcfeae7b, 0x77b5ff76, 0x8c2302bf, 0xaaf47556, 0x5f46b02a, 0x2b092801, - 0x3d38f5f7, 0x0ca81f36, 0x52af4a8a, 0x66d5e7c0, 0xdf3b0874, 0x95055110, 0x1b5ad7a8, 0xf61ed5ad, - 0x6cf6e479, 0x20758184, 0xd0cefa65, 0x88f7be58, 0x4a046826, 0x0ff6f8f3, 0xa09c7f70, 0x5346aba0, - 0x5ce96c28, 0xe176eda3, 0x6bac307f, 0x376829d2, 0x85360fa9, 0x17e3fe2a, 0x24b79767, 0xf5a96b20, - 0xd6cd2595, 0x68ff1ebf, 0x7555442c, 0xf19f06be, 0xf9e0659a, 0xeeb9491d, 0x34010718, 0xbb30cab8, - 0xe822fe15, 0x88570983, 0x750e6249, 0xda627e55, 0x5e76ffa8, 0xb1534546, 0x6d47de08, 0xefe9e7d4); + sBox[4] = new Array(0x7ec90c04, 0x2c6e74b9, 0x9b0e66df, 0xa6337911, 0xb86a7fff, 0x1dd358f5, 0x44dd9d44, 0x1731167f, 0x08fbf1fa, 0xe7f511cc, 0xd2051b00, 0x735aba00, 0x2ab722d8, 0x386381cb, 0xacf6243a, 0x69befd7a, 0xe6a2e77f, 0xf0c720cd, 0xc4494816, 0xccf5c180, 0x38851640, 0x15b0a848, 0xe68b18cb, 0x4caadeff, 0x5f480a01, 0x0412b2aa, 0x259814fc, 0x41d0efe2, 0x4e40b48d, 0x248eb6fb, 0x8dba1cfe, 0x41a99b02, 0x1a550a04, 0xba8f65cb, 0x7251f4e7, 0x95a51725, 0xc106ecd7, 0x97a5980a, 0xc539b9aa, 0x4d79fe6a, 0xf2f3f763, 0x68af8040, 0xed0c9e56, 0x11b4958b, 0xe1eb5a88, 0x8709e6b0, 0xd7e07156, 0x4e29fea7, 0x6366e52d, 0x02d1c000, 0xc4ac8e05, 0x9377f571, 0x0c05372a, 0x578535f2, 0x2261be02, 0xd642a0c9, 0xdf13a280, 0x74b55bd2, 0x682199c0, 0xd421e5ec, 0x53fb3ce8, 0xc8adedb3, 0x28a87fc9, 0x3d959981, 0x5c1ff900, 0xfe38d399, 0x0c4eff0b, 0x062407ea, 0xaa2f4fb1, 0x4fb96976, 0x90c79505, 0xb0a8a774, 0xef55a1ff, 0xe59ca2c2, 0xa6b62d27, 0xe66a4263, 0xdf65001f, 0x0ec50966, 0xdfdd55bc, 0x29de0655, 0x911e739a, 0x17af8975, 0x32c7911c, 0x89f89468, 0x0d01e980, 0x524755f4, 0x03b63cc9, 0x0cc844b2, 0xbcf3f0aa, 0x87ac36e9, 0xe53a7426, 0x01b3d82b, 0x1a9e7449, 0x64ee2d7e, 0xcddbb1da, 0x01c94910, 0xb868bf80, 0x0d26f3fd, 0x9342ede7, 0x04a5c284, 0x636737b6, 0x50f5b616, 0xf24766e3, 0x8eca36c1, 0x136e05db, 0xfef18391, 0xfb887a37, 0xd6e7f7d4, 0xc7fb7dc9, 0x3063fcdf, 0xb6f589de, 0xec2941da, 0x26e46695, 0xb7566419, 0xf654efc5, 0xd08d58b7, 0x48925401, 0xc1bacb7f, 0xe5ff550f, 0xb6083049, 0x5bb5d0e8, 0x87d72e5a, 0xab6a6ee1, 0x223a66ce, 0xc62bf3cd, 0x9e0885f9, 0x68cb3e47, 0x086c010f, 0xa21de820, 0xd18b69de, 0xf3f65777, 0xfa02c3f6, 0x407edac3, 0xcbb3d550, 0x1793084d, 0xb0d70eba, 0x0ab378d5, 0xd951fb0c, 0xded7da56, 0x4124bbe4, 0x94ca0b56, 0x0f5755d1, 0xe0e1e56e, 0x6184b5be, 0x580a249f, 0x94f74bc0, 0xe327888e, 0x9f7b5561, 0xc3dc0280, 0x05687715, 0x646c6bd7, 0x44904db3, 0x66b4f0a3, 0xc0f1648a, 0x697ed5af, 0x49e92ff6, 0x309e374f, 0x2cb6356a, 0x85808573, 0x4991f840, 0x76f0ae02, 0x083be84d, 0x28421c9a, 0x44489406, 0x736e4cb8, 0xc1092910, 0x8bc95fc6, 0x7d869cf4, 0x134f616f, 0x2e77118d, 0xb31b2be1, 0xaa90b472, 0x3ca5d717, 0x7d161bba, 0x9cad9010, 0xaf462ba2, 0x9fe459d2, 0x45d34559, 0xd9f2da13, 0xdbc65487, 0xf3e4f94e, 0x176d486f, 0x097c13ea, 0x631da5c7, 0x445f7382, 0x175683f4, 0xcdc66a97, 0x70be0288, 0xb3cdcf72, 0x6e5dd2f3, 0x20936079, 0x459b80a5, 0xbe60e2db, 0xa9c23101, 0xeba5315c, 0x224e42f2, 0x1c5c1572, 0xf6721b2c, 0x1ad2fff3, 0x8c25404e, 0x324ed72f, 0x4067b7fd, 0x0523138e, 0x5ca3bc78, 0xdc0fd66e, 0x75922283, 0x784d6b17, 0x58ebb16e, 0x44094f85, 0x3f481d87, 0xfcfeae7b, 0x77b5ff76, 0x8c2302bf, 0xaaf47556, 0x5f46b02a, 0x2b092801, 0x3d38f5f7, 0x0ca81f36, 0x52af4a8a, 0x66d5e7c0, 0xdf3b0874, 0x95055110, 0x1b5ad7a8, 0xf61ed5ad, 0x6cf6e479, 0x20758184, 0xd0cefa65, 0x88f7be58, 0x4a046826, 0x0ff6f8f3, 0xa09c7f70, 0x5346aba0, 0x5ce96c28, 0xe176eda3, 0x6bac307f, 0x376829d2, 0x85360fa9, 0x17e3fe2a, 0x24b79767, 0xf5a96b20, 0xd6cd2595, 0x68ff1ebf, 0x7555442c, 0xf19f06be, 0xf9e0659a, 0xeeb9491d, 0x34010718, 0xbb30cab8, 0xe822fe15, 0x88570983, 0x750e6249, 0xda627e55, 0x5e76ffa8, 0xb1534546, 0x6d47de08, 0xefe9e7d4); - sBox[5] = new Array( - 0xf6fa8f9d, 0x2cac6ce1, 0x4ca34867, 0xe2337f7c, 0x95db08e7, 0x016843b4, 0xeced5cbc, 0x325553ac, - 0xbf9f0960, 0xdfa1e2ed, 0x83f0579d, 0x63ed86b9, 0x1ab6a6b8, 0xde5ebe39, 0xf38ff732, 0x8989b138, - 0x33f14961, 0xc01937bd, 0xf506c6da, 0xe4625e7e, 0xa308ea99, 0x4e23e33c, 0x79cbd7cc, 0x48a14367, - 0xa3149619, 0xfec94bd5, 0xa114174a, 0xeaa01866, 0xa084db2d, 0x09a8486f, 0xa888614a, 0x2900af98, - 0x01665991, 0xe1992863, 0xc8f30c60, 0x2e78ef3c, 0xd0d51932, 0xcf0fec14, 0xf7ca07d2, 0xd0a82072, - 0xfd41197e, 0x9305a6b0, 0xe86be3da, 0x74bed3cd, 0x372da53c, 0x4c7f4448, 0xdab5d440, 0x6dba0ec3, - 0x083919a7, 0x9fbaeed9, 0x49dbcfb0, 0x4e670c53, 0x5c3d9c01, 0x64bdb941, 0x2c0e636a, 0xba7dd9cd, - 0xea6f7388, 0xe70bc762, 0x35f29adb, 0x5c4cdd8d, 0xf0d48d8c, 0xb88153e2, 0x08a19866, 0x1ae2eac8, - 0x284caf89, 0xaa928223, 0x9334be53, 0x3b3a21bf, 0x16434be3, 0x9aea3906, 0xefe8c36e, 0xf890cdd9, - 0x80226dae, 0xc340a4a3, 0xdf7e9c09, 0xa694a807, 0x5b7c5ecc, 0x221db3a6, 0x9a69a02f, 0x68818a54, - 0xceb2296f, 0x53c0843a, 0xfe893655, 0x25bfe68a, 0xb4628abc, 0xcf222ebf, 0x25ac6f48, 0xa9a99387, - 0x53bddb65, 0xe76ffbe7, 0xe967fd78, 0x0ba93563, 0x8e342bc1, 0xe8a11be9, 0x4980740d, 0xc8087dfc, - 0x8de4bf99, 0xa11101a0, 0x7fd37975, 0xda5a26c0, 0xe81f994f, 0x9528cd89, 0xfd339fed, 0xb87834bf, - 0x5f04456d, 0x22258698, 0xc9c4c83b, 0x2dc156be, 0x4f628daa, 0x57f55ec5, 0xe2220abe, 0xd2916ebf, - 0x4ec75b95, 0x24f2c3c0, 0x42d15d99, 0xcd0d7fa0, 0x7b6e27ff, 0xa8dc8af0, 0x7345c106, 0xf41e232f, - 0x35162386, 0xe6ea8926, 0x3333b094, 0x157ec6f2, 0x372b74af, 0x692573e4, 0xe9a9d848, 0xf3160289, - 0x3a62ef1d, 0xa787e238, 0xf3a5f676, 0x74364853, 0x20951063, 0x4576698d, 0xb6fad407, 0x592af950, - 0x36f73523, 0x4cfb6e87, 0x7da4cec0, 0x6c152daa, 0xcb0396a8, 0xc50dfe5d, 0xfcd707ab, 0x0921c42f, - 0x89dff0bb, 0x5fe2be78, 0x448f4f33, 0x754613c9, 0x2b05d08d, 0x48b9d585, 0xdc049441, 0xc8098f9b, - 0x7dede786, 0xc39a3373, 0x42410005, 0x6a091751, 0x0ef3c8a6, 0x890072d6, 0x28207682, 0xa9a9f7be, - 0xbf32679d, 0xd45b5b75, 0xb353fd00, 0xcbb0e358, 0x830f220a, 0x1f8fb214, 0xd372cf08, 0xcc3c4a13, - 0x8cf63166, 0x061c87be, 0x88c98f88, 0x6062e397, 0x47cf8e7a, 0xb6c85283, 0x3cc2acfb, 0x3fc06976, - 0x4e8f0252, 0x64d8314d, 0xda3870e3, 0x1e665459, 0xc10908f0, 0x513021a5, 0x6c5b68b7, 0x822f8aa0, - 0x3007cd3e, 0x74719eef, 0xdc872681, 0x073340d4, 0x7e432fd9, 0x0c5ec241, 0x8809286c, 0xf592d891, - 0x08a930f6, 0x957ef305, 0xb7fbffbd, 0xc266e96f, 0x6fe4ac98, 0xb173ecc0, 0xbc60b42a, 0x953498da, - 0xfba1ae12, 0x2d4bd736, 0x0f25faab, 0xa4f3fceb, 0xe2969123, 0x257f0c3d, 0x9348af49, 0x361400bc, - 0xe8816f4a, 0x3814f200, 0xa3f94043, 0x9c7a54c2, 0xbc704f57, 0xda41e7f9, 0xc25ad33a, 0x54f4a084, - 0xb17f5505, 0x59357cbe, 0xedbd15c8, 0x7f97c5ab, 0xba5ac7b5, 0xb6f6deaf, 0x3a479c3a, 0x5302da25, - 0x653d7e6a, 0x54268d49, 0x51a477ea, 0x5017d55b, 0xd7d25d88, 0x44136c76, 0x0404a8c8, 0xb8e5a121, - 0xb81a928a, 0x60ed5869, 0x97c55b96, 0xeaec991b, 0x29935913, 0x01fdb7f1, 0x088e8dfa, 0x9ab6f6f5, - 0x3b4cbf9f, 0x4a5de3ab, 0xe6051d35, 0xa0e1d855, 0xd36b4cf1, 0xf544edeb, 0xb0e93524, 0xbebb8fbd, - 0xa2d762cf, 0x49c92f54, 0x38b5f331, 0x7128a454, 0x48392905, 0xa65b1db8, 0x851c97bd, 0xd675cf2f); + sBox[5] = new Array(0xf6fa8f9d, 0x2cac6ce1, 0x4ca34867, 0xe2337f7c, 0x95db08e7, 0x016843b4, 0xeced5cbc, 0x325553ac, 0xbf9f0960, 0xdfa1e2ed, 0x83f0579d, 0x63ed86b9, 0x1ab6a6b8, 0xde5ebe39, 0xf38ff732, 0x8989b138, 0x33f14961, 0xc01937bd, 0xf506c6da, 0xe4625e7e, 0xa308ea99, 0x4e23e33c, 0x79cbd7cc, 0x48a14367, 0xa3149619, 0xfec94bd5, 0xa114174a, 0xeaa01866, 0xa084db2d, 0x09a8486f, 0xa888614a, 0x2900af98, 0x01665991, 0xe1992863, 0xc8f30c60, 0x2e78ef3c, 0xd0d51932, 0xcf0fec14, 0xf7ca07d2, 0xd0a82072, 0xfd41197e, 0x9305a6b0, 0xe86be3da, 0x74bed3cd, 0x372da53c, 0x4c7f4448, 0xdab5d440, 0x6dba0ec3, 0x083919a7, 0x9fbaeed9, 0x49dbcfb0, 0x4e670c53, 0x5c3d9c01, 0x64bdb941, 0x2c0e636a, 0xba7dd9cd, 0xea6f7388, 0xe70bc762, 0x35f29adb, 0x5c4cdd8d, 0xf0d48d8c, 0xb88153e2, 0x08a19866, 0x1ae2eac8, 0x284caf89, 0xaa928223, 0x9334be53, 0x3b3a21bf, 0x16434be3, 0x9aea3906, 0xefe8c36e, 0xf890cdd9, 0x80226dae, 0xc340a4a3, 0xdf7e9c09, 0xa694a807, 0x5b7c5ecc, 0x221db3a6, 0x9a69a02f, 0x68818a54, 0xceb2296f, 0x53c0843a, 0xfe893655, 0x25bfe68a, 0xb4628abc, 0xcf222ebf, 0x25ac6f48, 0xa9a99387, 0x53bddb65, 0xe76ffbe7, 0xe967fd78, 0x0ba93563, 0x8e342bc1, 0xe8a11be9, 0x4980740d, 0xc8087dfc, 0x8de4bf99, 0xa11101a0, 0x7fd37975, 0xda5a26c0, 0xe81f994f, 0x9528cd89, 0xfd339fed, 0xb87834bf, 0x5f04456d, 0x22258698, 0xc9c4c83b, 0x2dc156be, 0x4f628daa, 0x57f55ec5, 0xe2220abe, 0xd2916ebf, 0x4ec75b95, 0x24f2c3c0, 0x42d15d99, 0xcd0d7fa0, 0x7b6e27ff, 0xa8dc8af0, 0x7345c106, 0xf41e232f, 0x35162386, 0xe6ea8926, 0x3333b094, 0x157ec6f2, 0x372b74af, 0x692573e4, 0xe9a9d848, 0xf3160289, 0x3a62ef1d, 0xa787e238, 0xf3a5f676, 0x74364853, 0x20951063, 0x4576698d, 0xb6fad407, 0x592af950, 0x36f73523, 0x4cfb6e87, 0x7da4cec0, 0x6c152daa, 0xcb0396a8, 0xc50dfe5d, 0xfcd707ab, 0x0921c42f, 0x89dff0bb, 0x5fe2be78, 0x448f4f33, 0x754613c9, 0x2b05d08d, 0x48b9d585, 0xdc049441, 0xc8098f9b, 0x7dede786, 0xc39a3373, 0x42410005, 0x6a091751, 0x0ef3c8a6, 0x890072d6, 0x28207682, 0xa9a9f7be, 0xbf32679d, 0xd45b5b75, 0xb353fd00, 0xcbb0e358, 0x830f220a, 0x1f8fb214, 0xd372cf08, 0xcc3c4a13, 0x8cf63166, 0x061c87be, 0x88c98f88, 0x6062e397, 0x47cf8e7a, 0xb6c85283, 0x3cc2acfb, 0x3fc06976, 0x4e8f0252, 0x64d8314d, 0xda3870e3, 0x1e665459, 0xc10908f0, 0x513021a5, 0x6c5b68b7, 0x822f8aa0, 0x3007cd3e, 0x74719eef, 0xdc872681, 0x073340d4, 0x7e432fd9, 0x0c5ec241, 0x8809286c, 0xf592d891, 0x08a930f6, 0x957ef305, 0xb7fbffbd, 0xc266e96f, 0x6fe4ac98, 0xb173ecc0, 0xbc60b42a, 0x953498da, 0xfba1ae12, 0x2d4bd736, 0x0f25faab, 0xa4f3fceb, 0xe2969123, 0x257f0c3d, 0x9348af49, 0x361400bc, 0xe8816f4a, 0x3814f200, 0xa3f94043, 0x9c7a54c2, 0xbc704f57, 0xda41e7f9, 0xc25ad33a, 0x54f4a084, 0xb17f5505, 0x59357cbe, 0xedbd15c8, 0x7f97c5ab, 0xba5ac7b5, 0xb6f6deaf, 0x3a479c3a, 0x5302da25, 0x653d7e6a, 0x54268d49, 0x51a477ea, 0x5017d55b, 0xd7d25d88, 0x44136c76, 0x0404a8c8, 0xb8e5a121, 0xb81a928a, 0x60ed5869, 0x97c55b96, 0xeaec991b, 0x29935913, 0x01fdb7f1, 0x088e8dfa, 0x9ab6f6f5, 0x3b4cbf9f, 0x4a5de3ab, 0xe6051d35, 0xa0e1d855, 0xd36b4cf1, 0xf544edeb, 0xb0e93524, 0xbebb8fbd, 0xa2d762cf, 0x49c92f54, 0x38b5f331, 0x7128a454, 0x48392905, 0xa65b1db8, 0x851c97bd, 0xd675cf2f); - sBox[6] = new Array( - 0x85e04019, 0x332bf567, 0x662dbfff, 0xcfc65693, 0x2a8d7f6f, 0xab9bc912, 0xde6008a1, 0x2028da1f, - 0x0227bce7, 0x4d642916, 0x18fac300, 0x50f18b82, 0x2cb2cb11, 0xb232e75c, 0x4b3695f2, 0xb28707de, - 0xa05fbcf6, 0xcd4181e9, 0xe150210c, 0xe24ef1bd, 0xb168c381, 0xfde4e789, 0x5c79b0d8, 0x1e8bfd43, - 0x4d495001, 0x38be4341, 0x913cee1d, 0x92a79c3f, 0x089766be, 0xbaeeadf4, 0x1286becf, 0xb6eacb19, - 0x2660c200, 0x7565bde4, 0x64241f7a, 0x8248dca9, 0xc3b3ad66, 0x28136086, 0x0bd8dfa8, 0x356d1cf2, - 0x107789be, 0xb3b2e9ce, 0x0502aa8f, 0x0bc0351e, 0x166bf52a, 0xeb12ff82, 0xe3486911, 0xd34d7516, - 0x4e7b3aff, 0x5f43671b, 0x9cf6e037, 0x4981ac83, 0x334266ce, 0x8c9341b7, 0xd0d854c0, 0xcb3a6c88, - 0x47bc2829, 0x4725ba37, 0xa66ad22b, 0x7ad61f1e, 0x0c5cbafa, 0x4437f107, 0xb6e79962, 0x42d2d816, - 0x0a961288, 0xe1a5c06e, 0x13749e67, 0x72fc081a, 0xb1d139f7, 0xf9583745, 0xcf19df58, 0xbec3f756, - 0xc06eba30, 0x07211b24, 0x45c28829, 0xc95e317f, 0xbc8ec511, 0x38bc46e9, 0xc6e6fa14, 0xbae8584a, - 0xad4ebc46, 0x468f508b, 0x7829435f, 0xf124183b, 0x821dba9f, 0xaff60ff4, 0xea2c4e6d, 0x16e39264, - 0x92544a8b, 0x009b4fc3, 0xaba68ced, 0x9ac96f78, 0x06a5b79a, 0xb2856e6e, 0x1aec3ca9, 0xbe838688, - 0x0e0804e9, 0x55f1be56, 0xe7e5363b, 0xb3a1f25d, 0xf7debb85, 0x61fe033c, 0x16746233, 0x3c034c28, - 0xda6d0c74, 0x79aac56c, 0x3ce4e1ad, 0x51f0c802, 0x98f8f35a, 0x1626a49f, 0xeed82b29, 0x1d382fe3, - 0x0c4fb99a, 0xbb325778, 0x3ec6d97b, 0x6e77a6a9, 0xcb658b5c, 0xd45230c7, 0x2bd1408b, 0x60c03eb7, - 0xb9068d78, 0xa33754f4, 0xf430c87d, 0xc8a71302, 0xb96d8c32, 0xebd4e7be, 0xbe8b9d2d, 0x7979fb06, - 0xe7225308, 0x8b75cf77, 0x11ef8da4, 0xe083c858, 0x8d6b786f, 0x5a6317a6, 0xfa5cf7a0, 0x5dda0033, - 0xf28ebfb0, 0xf5b9c310, 0xa0eac280, 0x08b9767a, 0xa3d9d2b0, 0x79d34217, 0x021a718d, 0x9ac6336a, - 0x2711fd60, 0x438050e3, 0x069908a8, 0x3d7fedc4, 0x826d2bef, 0x4eeb8476, 0x488dcf25, 0x36c9d566, - 0x28e74e41, 0xc2610aca, 0x3d49a9cf, 0xbae3b9df, 0xb65f8de6, 0x92aeaf64, 0x3ac7d5e6, 0x9ea80509, - 0xf22b017d, 0xa4173f70, 0xdd1e16c3, 0x15e0d7f9, 0x50b1b887, 0x2b9f4fd5, 0x625aba82, 0x6a017962, - 0x2ec01b9c, 0x15488aa9, 0xd716e740, 0x40055a2c, 0x93d29a22, 0xe32dbf9a, 0x058745b9, 0x3453dc1e, - 0xd699296e, 0x496cff6f, 0x1c9f4986, 0xdfe2ed07, 0xb87242d1, 0x19de7eae, 0x053e561a, 0x15ad6f8c, - 0x66626c1c, 0x7154c24c, 0xea082b2a, 0x93eb2939, 0x17dcb0f0, 0x58d4f2ae, 0x9ea294fb, 0x52cf564c, - 0x9883fe66, 0x2ec40581, 0x763953c3, 0x01d6692e, 0xd3a0c108, 0xa1e7160e, 0xe4f2dfa6, 0x693ed285, - 0x74904698, 0x4c2b0edd, 0x4f757656, 0x5d393378, 0xa132234f, 0x3d321c5d, 0xc3f5e194, 0x4b269301, - 0xc79f022f, 0x3c997e7e, 0x5e4f9504, 0x3ffafbbd, 0x76f7ad0e, 0x296693f4, 0x3d1fce6f, 0xc61e45be, - 0xd3b5ab34, 0xf72bf9b7, 0x1b0434c0, 0x4e72b567, 0x5592a33d, 0xb5229301, 0xcfd2a87f, 0x60aeb767, - 0x1814386b, 0x30bcc33d, 0x38a0c07d, 0xfd1606f2, 0xc363519b, 0x589dd390, 0x5479f8e6, 0x1cb8d647, - 0x97fd61a9, 0xea7759f4, 0x2d57539d, 0x569a58cf, 0xe84e63ad, 0x462e1b78, 0x6580f87e, 0xf3817914, - 0x91da55f4, 0x40a230f3, 0xd1988f35, 0xb6e318d2, 0x3ffa50bc, 0x3d40f021, 0xc3c0bdae, 0x4958c24c, - 0x518f36b2, 0x84b1d370, 0x0fedce83, 0x878ddada, 0xf2a279c7, 0x94e01be8, 0x90716f4b, 0x954b8aa3); - - sBox[7] = new Array( - 0xe216300d, 0xbbddfffc, 0xa7ebdabd, 0x35648095, 0x7789f8b7, 0xe6c1121b, 0x0e241600, 0x052ce8b5, - 0x11a9cfb0, 0xe5952f11, 0xece7990a, 0x9386d174, 0x2a42931c, 0x76e38111, 0xb12def3a, 0x37ddddfc, - 0xde9adeb1, 0x0a0cc32c, 0xbe197029, 0x84a00940, 0xbb243a0f, 0xb4d137cf, 0xb44e79f0, 0x049eedfd, - 0x0b15a15d, 0x480d3168, 0x8bbbde5a, 0x669ded42, 0xc7ece831, 0x3f8f95e7, 0x72df191b, 0x7580330d, - 0x94074251, 0x5c7dcdfa, 0xabbe6d63, 0xaa402164, 0xb301d40a, 0x02e7d1ca, 0x53571dae, 0x7a3182a2, - 0x12a8ddec, 0xfdaa335d, 0x176f43e8, 0x71fb46d4, 0x38129022, 0xce949ad4, 0xb84769ad, 0x965bd862, - 0x82f3d055, 0x66fb9767, 0x15b80b4e, 0x1d5b47a0, 0x4cfde06f, 0xc28ec4b8, 0x57e8726e, 0x647a78fc, - 0x99865d44, 0x608bd593, 0x6c200e03, 0x39dc5ff6, 0x5d0b00a3, 0xae63aff2, 0x7e8bd632, 0x70108c0c, - 0xbbd35049, 0x2998df04, 0x980cf42a, 0x9b6df491, 0x9e7edd53, 0x06918548, 0x58cb7e07, 0x3b74ef2e, - 0x522fffb1, 0xd24708cc, 0x1c7e27cd, 0xa4eb215b, 0x3cf1d2e2, 0x19b47a38, 0x424f7618, 0x35856039, - 0x9d17dee7, 0x27eb35e6, 0xc9aff67b, 0x36baf5b8, 0x09c467cd, 0xc18910b1, 0xe11dbf7b, 0x06cd1af8, - 0x7170c608, 0x2d5e3354, 0xd4de495a, 0x64c6d006, 0xbcc0c62c, 0x3dd00db3, 0x708f8f34, 0x77d51b42, - 0x264f620f, 0x24b8d2bf, 0x15c1b79e, 0x46a52564, 0xf8d7e54e, 0x3e378160, 0x7895cda5, 0x859c15a5, - 0xe6459788, 0xc37bc75f, 0xdb07ba0c, 0x0676a3ab, 0x7f229b1e, 0x31842e7b, 0x24259fd7, 0xf8bef472, - 0x835ffcb8, 0x6df4c1f2, 0x96f5b195, 0xfd0af0fc, 0xb0fe134c, 0xe2506d3d, 0x4f9b12ea, 0xf215f225, - 0xa223736f, 0x9fb4c428, 0x25d04979, 0x34c713f8, 0xc4618187, 0xea7a6e98, 0x7cd16efc, 0x1436876c, - 0xf1544107, 0xbedeee14, 0x56e9af27, 0xa04aa441, 0x3cf7c899, 0x92ecbae6, 0xdd67016d, 0x151682eb, - 0xa842eedf, 0xfdba60b4, 0xf1907b75, 0x20e3030f, 0x24d8c29e, 0xe139673b, 0xefa63fb8, 0x71873054, - 0xb6f2cf3b, 0x9f326442, 0xcb15a4cc, 0xb01a4504, 0xf1e47d8d, 0x844a1be5, 0xbae7dfdc, 0x42cbda70, - 0xcd7dae0a, 0x57e85b7a, 0xd53f5af6, 0x20cf4d8c, 0xcea4d428, 0x79d130a4, 0x3486ebfb, 0x33d3cddc, - 0x77853b53, 0x37effcb5, 0xc5068778, 0xe580b3e6, 0x4e68b8f4, 0xc5c8b37e, 0x0d809ea2, 0x398feb7c, - 0x132a4f94, 0x43b7950e, 0x2fee7d1c, 0x223613bd, 0xdd06caa2, 0x37df932b, 0xc4248289, 0xacf3ebc3, - 0x5715f6b7, 0xef3478dd, 0xf267616f, 0xc148cbe4, 0x9052815e, 0x5e410fab, 0xb48a2465, 0x2eda7fa4, - 0xe87b40e4, 0xe98ea084, 0x5889e9e1, 0xefd390fc, 0xdd07d35b, 0xdb485694, 0x38d7e5b2, 0x57720101, - 0x730edebc, 0x5b643113, 0x94917e4f, 0x503c2fba, 0x646f1282, 0x7523d24a, 0xe0779695, 0xf9c17a8f, - 0x7a5b2121, 0xd187b896, 0x29263a4d, 0xba510cdf, 0x81f47c9f, 0xad1163ed, 0xea7b5965, 0x1a00726e, - 0x11403092, 0x00da6d77, 0x4a0cdd61, 0xad1f4603, 0x605bdfb0, 0x9eedc364, 0x22ebe6a8, 0xcee7d28a, - 0xa0e736a0, 0x5564a6b9, 0x10853209, 0xc7eb8f37, 0x2de705ca, 0x8951570f, 0xdf09822b, 0xbd691a6c, - 0xaa12e4f2, 0x87451c0f, 0xe0f6a27a, 0x3ada4819, 0x4cf1764f, 0x0d771c2b, 0x67cdb156, 0x350d8384, - 0x5938fa0f, 0x42399ef3, 0x36997b07, 0x0e84093d, 0x4aa93e61, 0x8360d87b, 0x1fa98b0c, 0x1149382c, - 0xe97625a5, 0x0614d1b7, 0x0e25244b, 0x0c768347, 0x589e8d82, 0x0d2059d1, 0xa466bb1e, 0xf8da0a82, - 0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e); + sBox[6] = new Array(0x85e04019, 0x332bf567, 0x662dbfff, 0xcfc65693, 0x2a8d7f6f, 0xab9bc912, 0xde6008a1, 0x2028da1f, 0x0227bce7, 0x4d642916, 0x18fac300, 0x50f18b82, 0x2cb2cb11, 0xb232e75c, 0x4b3695f2, 0xb28707de, 0xa05fbcf6, 0xcd4181e9, 0xe150210c, 0xe24ef1bd, 0xb168c381, 0xfde4e789, 0x5c79b0d8, 0x1e8bfd43, 0x4d495001, 0x38be4341, 0x913cee1d, 0x92a79c3f, 0x089766be, 0xbaeeadf4, 0x1286becf, 0xb6eacb19, 0x2660c200, 0x7565bde4, 0x64241f7a, 0x8248dca9, 0xc3b3ad66, 0x28136086, 0x0bd8dfa8, 0x356d1cf2, 0x107789be, 0xb3b2e9ce, 0x0502aa8f, 0x0bc0351e, 0x166bf52a, 0xeb12ff82, 0xe3486911, 0xd34d7516, 0x4e7b3aff, 0x5f43671b, 0x9cf6e037, 0x4981ac83, 0x334266ce, 0x8c9341b7, 0xd0d854c0, 0xcb3a6c88, 0x47bc2829, 0x4725ba37, 0xa66ad22b, 0x7ad61f1e, 0x0c5cbafa, 0x4437f107, 0xb6e79962, 0x42d2d816, 0x0a961288, 0xe1a5c06e, 0x13749e67, 0x72fc081a, 0xb1d139f7, 0xf9583745, 0xcf19df58, 0xbec3f756, 0xc06eba30, 0x07211b24, 0x45c28829, 0xc95e317f, 0xbc8ec511, 0x38bc46e9, 0xc6e6fa14, 0xbae8584a, 0xad4ebc46, 0x468f508b, 0x7829435f, 0xf124183b, 0x821dba9f, 0xaff60ff4, 0xea2c4e6d, 0x16e39264, 0x92544a8b, 0x009b4fc3, 0xaba68ced, 0x9ac96f78, 0x06a5b79a, 0xb2856e6e, 0x1aec3ca9, 0xbe838688, 0x0e0804e9, 0x55f1be56, 0xe7e5363b, 0xb3a1f25d, 0xf7debb85, 0x61fe033c, 0x16746233, 0x3c034c28, 0xda6d0c74, 0x79aac56c, 0x3ce4e1ad, 0x51f0c802, 0x98f8f35a, 0x1626a49f, 0xeed82b29, 0x1d382fe3, 0x0c4fb99a, 0xbb325778, 0x3ec6d97b, 0x6e77a6a9, 0xcb658b5c, 0xd45230c7, 0x2bd1408b, 0x60c03eb7, 0xb9068d78, 0xa33754f4, 0xf430c87d, 0xc8a71302, 0xb96d8c32, 0xebd4e7be, 0xbe8b9d2d, 0x7979fb06, 0xe7225308, 0x8b75cf77, 0x11ef8da4, 0xe083c858, 0x8d6b786f, 0x5a6317a6, 0xfa5cf7a0, 0x5dda0033, 0xf28ebfb0, 0xf5b9c310, 0xa0eac280, 0x08b9767a, 0xa3d9d2b0, 0x79d34217, 0x021a718d, 0x9ac6336a, 0x2711fd60, 0x438050e3, 0x069908a8, 0x3d7fedc4, 0x826d2bef, 0x4eeb8476, 0x488dcf25, 0x36c9d566, 0x28e74e41, 0xc2610aca, 0x3d49a9cf, 0xbae3b9df, 0xb65f8de6, 0x92aeaf64, 0x3ac7d5e6, 0x9ea80509, 0xf22b017d, 0xa4173f70, 0xdd1e16c3, 0x15e0d7f9, 0x50b1b887, 0x2b9f4fd5, 0x625aba82, 0x6a017962, 0x2ec01b9c, 0x15488aa9, 0xd716e740, 0x40055a2c, 0x93d29a22, 0xe32dbf9a, 0x058745b9, 0x3453dc1e, 0xd699296e, 0x496cff6f, 0x1c9f4986, 0xdfe2ed07, 0xb87242d1, 0x19de7eae, 0x053e561a, 0x15ad6f8c, 0x66626c1c, 0x7154c24c, 0xea082b2a, 0x93eb2939, 0x17dcb0f0, 0x58d4f2ae, 0x9ea294fb, 0x52cf564c, 0x9883fe66, 0x2ec40581, 0x763953c3, 0x01d6692e, 0xd3a0c108, 0xa1e7160e, 0xe4f2dfa6, 0x693ed285, 0x74904698, 0x4c2b0edd, 0x4f757656, 0x5d393378, 0xa132234f, 0x3d321c5d, 0xc3f5e194, 0x4b269301, 0xc79f022f, 0x3c997e7e, 0x5e4f9504, 0x3ffafbbd, 0x76f7ad0e, 0x296693f4, 0x3d1fce6f, 0xc61e45be, 0xd3b5ab34, 0xf72bf9b7, 0x1b0434c0, 0x4e72b567, 0x5592a33d, 0xb5229301, 0xcfd2a87f, 0x60aeb767, 0x1814386b, 0x30bcc33d, 0x38a0c07d, 0xfd1606f2, 0xc363519b, 0x589dd390, 0x5479f8e6, 0x1cb8d647, 0x97fd61a9, 0xea7759f4, 0x2d57539d, 0x569a58cf, 0xe84e63ad, 0x462e1b78, 0x6580f87e, 0xf3817914, 0x91da55f4, 0x40a230f3, 0xd1988f35, 0xb6e318d2, 0x3ffa50bc, 0x3d40f021, 0xc3c0bdae, 0x4958c24c, 0x518f36b2, 0x84b1d370, 0x0fedce83, 0x878ddada, 0xf2a279c7, 0x94e01be8, 0x90716f4b, 0x954b8aa3); + sBox[7] = new Array(0xe216300d, 0xbbddfffc, 0xa7ebdabd, 0x35648095, 0x7789f8b7, 0xe6c1121b, 0x0e241600, 0x052ce8b5, 0x11a9cfb0, 0xe5952f11, 0xece7990a, 0x9386d174, 0x2a42931c, 0x76e38111, 0xb12def3a, 0x37ddddfc, 0xde9adeb1, 0x0a0cc32c, 0xbe197029, 0x84a00940, 0xbb243a0f, 0xb4d137cf, 0xb44e79f0, 0x049eedfd, 0x0b15a15d, 0x480d3168, 0x8bbbde5a, 0x669ded42, 0xc7ece831, 0x3f8f95e7, 0x72df191b, 0x7580330d, 0x94074251, 0x5c7dcdfa, 0xabbe6d63, 0xaa402164, 0xb301d40a, 0x02e7d1ca, 0x53571dae, 0x7a3182a2, 0x12a8ddec, 0xfdaa335d, 0x176f43e8, 0x71fb46d4, 0x38129022, 0xce949ad4, 0xb84769ad, 0x965bd862, 0x82f3d055, 0x66fb9767, 0x15b80b4e, 0x1d5b47a0, 0x4cfde06f, 0xc28ec4b8, 0x57e8726e, 0x647a78fc, 0x99865d44, 0x608bd593, 0x6c200e03, 0x39dc5ff6, 0x5d0b00a3, 0xae63aff2, 0x7e8bd632, 0x70108c0c, 0xbbd35049, 0x2998df04, 0x980cf42a, 0x9b6df491, 0x9e7edd53, 0x06918548, 0x58cb7e07, 0x3b74ef2e, 0x522fffb1, 0xd24708cc, 0x1c7e27cd, 0xa4eb215b, 0x3cf1d2e2, 0x19b47a38, 0x424f7618, 0x35856039, 0x9d17dee7, 0x27eb35e6, 0xc9aff67b, 0x36baf5b8, 0x09c467cd, 0xc18910b1, 0xe11dbf7b, 0x06cd1af8, 0x7170c608, 0x2d5e3354, 0xd4de495a, 0x64c6d006, 0xbcc0c62c, 0x3dd00db3, 0x708f8f34, 0x77d51b42, 0x264f620f, 0x24b8d2bf, 0x15c1b79e, 0x46a52564, 0xf8d7e54e, 0x3e378160, 0x7895cda5, 0x859c15a5, 0xe6459788, 0xc37bc75f, 0xdb07ba0c, 0x0676a3ab, 0x7f229b1e, 0x31842e7b, 0x24259fd7, 0xf8bef472, 0x835ffcb8, 0x6df4c1f2, 0x96f5b195, 0xfd0af0fc, 0xb0fe134c, 0xe2506d3d, 0x4f9b12ea, 0xf215f225, 0xa223736f, 0x9fb4c428, 0x25d04979, 0x34c713f8, 0xc4618187, 0xea7a6e98, 0x7cd16efc, 0x1436876c, 0xf1544107, 0xbedeee14, 0x56e9af27, 0xa04aa441, 0x3cf7c899, 0x92ecbae6, 0xdd67016d, 0x151682eb, 0xa842eedf, 0xfdba60b4, 0xf1907b75, 0x20e3030f, 0x24d8c29e, 0xe139673b, 0xefa63fb8, 0x71873054, 0xb6f2cf3b, 0x9f326442, 0xcb15a4cc, 0xb01a4504, 0xf1e47d8d, 0x844a1be5, 0xbae7dfdc, 0x42cbda70, 0xcd7dae0a, 0x57e85b7a, 0xd53f5af6, 0x20cf4d8c, 0xcea4d428, 0x79d130a4, 0x3486ebfb, 0x33d3cddc, 0x77853b53, 0x37effcb5, 0xc5068778, 0xe580b3e6, 0x4e68b8f4, 0xc5c8b37e, 0x0d809ea2, 0x398feb7c, 0x132a4f94, 0x43b7950e, 0x2fee7d1c, 0x223613bd, 0xdd06caa2, 0x37df932b, 0xc4248289, 0xacf3ebc3, 0x5715f6b7, 0xef3478dd, 0xf267616f, 0xc148cbe4, 0x9052815e, 0x5e410fab, 0xb48a2465, 0x2eda7fa4, 0xe87b40e4, 0xe98ea084, 0x5889e9e1, 0xefd390fc, 0xdd07d35b, 0xdb485694, 0x38d7e5b2, 0x57720101, 0x730edebc, 0x5b643113, 0x94917e4f, 0x503c2fba, 0x646f1282, 0x7523d24a, 0xe0779695, 0xf9c17a8f, 0x7a5b2121, 0xd187b896, 0x29263a4d, 0xba510cdf, 0x81f47c9f, 0xad1163ed, 0xea7b5965, 0x1a00726e, 0x11403092, 0x00da6d77, 0x4a0cdd61, 0xad1f4603, 0x605bdfb0, 0x9eedc364, 0x22ebe6a8, 0xcee7d28a, 0xa0e736a0, 0x5564a6b9, 0x10853209, 0xc7eb8f37, 0x2de705ca, 0x8951570f, 0xdf09822b, 0xbd691a6c, 0xaa12e4f2, 0x87451c0f, 0xe0f6a27a, 0x3ada4819, 0x4cf1764f, 0x0d771c2b, 0x67cdb156, 0x350d8384, 0x5938fa0f, 0x42399ef3, 0x36997b07, 0x0e84093d, 0x4aa93e61, 0x8360d87b, 0x1fa98b0c, 0x1149382c, 0xe97625a5, 0x0614d1b7, 0x0e25244b, 0x0c768347, 0x589e8d82, 0x0d2059d1, 0xa466bb1e, 0xf8da0a82, 0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e); } -var util = require('../../util.js'); -function cast5(key) { - this.cast5 = new openpgp_symenc_cast5(); - this.cast5.setKey(util.str2bin(key)); +function Cast5(key) { + this.cast5 = new OpenpgpSymencCast5(); + this.cast5.setKey(key); - this.encrypt = function(block) { + this.encrypt = function (block) { return this.cast5.encrypt(block); }; } -module.exports = cast5; -module.exports.blockSize = cast5.prototype.blockSize = 8; -module.exports.keySize = cast5.prototype.keySize = 16; +Cast5.blockSize = Cast5.prototype.blockSize = 8; +Cast5.keySize = Cast5.prototype.keySize = 16; -},{"../../util.js":76}],22:[function(require,module,exports){ +},{}],24:[function(require,module,exports){ //Paul Tero, July 2001 //http://www.tero.co.uk/des/ // @@ -2925,68 +5074,37 @@ module.exports.keySize = cast5.prototype.keySize = 16; 'use strict'; +Object.defineProperty(exports, "__esModule", { + value: true +}); function des(keys, message, encrypt, mode, iv, padding) { //declaring this locally speeds things up a bit - var spfunction1 = new Array(0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404, 0x4, 0x10000, 0x400, 0x1010400, - 0x1010404, 0x400, 0x1000404, 0x1010004, 0x1000000, 0x4, 0x404, 0x1000400, 0x1000400, 0x10400, 0x10400, 0x1010000, - 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004, 0x10004, 0, 0x404, 0x10404, 0x1000000, 0x10000, 0x1010404, 0x4, - 0x1010000, 0x1010400, 0x1000000, 0x1000000, 0x400, 0x1010004, 0x10000, 0x10400, 0x1000004, 0x400, 0x4, 0x1000404, - 0x10404, 0x1010404, 0x10004, 0x1010000, 0x1000404, 0x1000004, 0x404, 0x10404, 0x1010400, 0x404, 0x1000400, - 0x1000400, 0, 0x10004, 0x10400, 0, 0x1010004); - var spfunction2 = new Array(-0x7fef7fe0, -0x7fff8000, 0x8000, 0x108020, 0x100000, 0x20, -0x7fefffe0, -0x7fff7fe0, - - 0x7fffffe0, -0x7fef7fe0, -0x7fef8000, -0x80000000, -0x7fff8000, 0x100000, 0x20, -0x7fefffe0, 0x108000, 0x100020, - - 0x7fff7fe0, 0, -0x80000000, 0x8000, 0x108020, -0x7ff00000, 0x100020, -0x7fffffe0, 0, 0x108000, 0x8020, -0x7fef8000, - - 0x7ff00000, 0x8020, 0, 0x108020, -0x7fefffe0, 0x100000, -0x7fff7fe0, -0x7ff00000, -0x7fef8000, 0x8000, -0x7ff00000, - - 0x7fff8000, 0x20, -0x7fef7fe0, 0x108020, 0x20, 0x8000, -0x80000000, 0x8020, -0x7fef8000, 0x100000, -0x7fffffe0, - 0x100020, -0x7fff7fe0, -0x7fffffe0, 0x100020, 0x108000, 0, -0x7fff8000, 0x8020, -0x80000000, -0x7fefffe0, - - 0x7fef7fe0, 0x108000); - var spfunction3 = new Array(0x208, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200, 0x20008, 0x8000008, - 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 0x208, 0x8000000, 0x8, 0x8020200, 0x200, 0x20200, 0x8020000, - 0x8020008, 0x20208, 0x8000208, 0x20200, 0x20000, 0x8000208, 0x8, 0x8020208, 0x200, 0x8000000, 0x8020200, 0x8000000, - 0x20008, 0x208, 0x20000, 0x8020200, 0x8000200, 0, 0x200, 0x20008, 0x8020208, 0x8000200, 0x8000008, 0x200, 0, - 0x8020008, 0x8000208, 0x20000, 0x8000000, 0x8020208, 0x8, 0x20208, 0x20200, 0x8000008, 0x8020000, 0x8000208, 0x208, - 0x8020000, 0x20208, 0x8, 0x8020008, 0x20200); - var spfunction4 = new Array(0x802001, 0x2081, 0x2081, 0x80, 0x802080, 0x800081, 0x800001, 0x2001, 0, 0x802000, - 0x802000, 0x802081, 0x81, 0, 0x800080, 0x800001, 0x1, 0x2000, 0x800000, 0x802001, 0x80, 0x800000, 0x2001, 0x2080, - 0x800081, 0x1, 0x2080, 0x800080, 0x2000, 0x802080, 0x802081, 0x81, 0x800080, 0x800001, 0x802000, 0x802081, 0x81, 0, - 0, 0x802000, 0x2080, 0x800080, 0x800081, 0x1, 0x802001, 0x2081, 0x2081, 0x80, 0x802081, 0x81, 0x1, 0x2000, 0x800001, - 0x2001, 0x802080, 0x800081, 0x2001, 0x2080, 0x800000, 0x802001, 0x80, 0x800000, 0x2000, 0x802080); - var spfunction5 = new Array(0x100, 0x2080100, 0x2080000, 0x42000100, 0x80000, 0x100, 0x40000000, 0x2080000, - 0x40080100, 0x80000, 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100, 0x40000000, 0x2000000, 0x40080000, - 0x40080000, 0, 0x40000100, 0x42080100, 0x42080100, 0x2000100, 0x42080000, 0x40000100, 0, 0x42000000, 0x2080100, - 0x2000000, 0x42000000, 0x80100, 0x80000, 0x42000100, 0x100, 0x2000000, 0x40000000, 0x2080000, 0x42000100, - 0x40080100, 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 0x100, 0x2000000, 0x42080000, 0x42080100, - 0x80100, 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000, 0x42000000, 0x80100, 0x2000100, 0x40000100, 0x80000, 0, - 0x40080000, 0x2080100, 0x40000100); - var spfunction6 = new Array(0x20000010, 0x20400000, 0x4000, 0x20404010, 0x20400000, 0x10, 0x20404010, 0x400000, - 0x20004000, 0x404010, 0x400000, 0x20000010, 0x400010, 0x20004000, 0x20000000, 0x4010, 0, 0x400010, 0x20004010, - 0x4000, 0x404000, 0x20004010, 0x10, 0x20400010, 0x20400010, 0, 0x404010, 0x20404000, 0x4010, 0x404000, 0x20404000, - 0x20000000, 0x20004000, 0x10, 0x20400010, 0x404000, 0x20404010, 0x400000, 0x4010, 0x20000010, 0x400000, 0x20004000, - 0x20000000, 0x4010, 0x20000010, 0x20404010, 0x404000, 0x20400000, 0x404010, 0x20404000, 0, 0x20400010, 0x10, 0x4000, - 0x20400000, 0x404010, 0x4000, 0x400010, 0x20004010, 0, 0x20404000, 0x20000000, 0x400010, 0x20004010); - var spfunction7 = new Array(0x200000, 0x4200002, 0x4000802, 0, 0x800, 0x4000802, 0x200802, 0x4200800, 0x4200802, - 0x200000, 0, 0x4000002, 0x2, 0x4000000, 0x4200002, 0x802, 0x4000800, 0x200802, 0x200002, 0x4000800, 0x4000002, - 0x4200000, 0x4200800, 0x200002, 0x4200000, 0x800, 0x802, 0x4200802, 0x200800, 0x2, 0x4000000, 0x200800, 0x4000000, - 0x200800, 0x200000, 0x4000802, 0x4000802, 0x4200002, 0x4200002, 0x2, 0x200002, 0x4000000, 0x4000800, 0x200000, - 0x4200800, 0x802, 0x200802, 0x4200800, 0x802, 0x4000002, 0x4200802, 0x4200000, 0x200800, 0, 0x2, 0x4200802, 0, - 0x200802, 0x4200000, 0x800, 0x4000002, 0x4000800, 0x800, 0x200002); - var spfunction8 = new Array(0x10001040, 0x1000, 0x40000, 0x10041040, 0x10000000, 0x10001040, 0x40, 0x10000000, - 0x40040, 0x10040000, 0x10041040, 0x41000, 0x10041000, 0x41040, 0x1000, 0x40, 0x10040000, 0x10000040, 0x10001000, - 0x1040, 0x41000, 0x40040, 0x10040040, 0x10041000, 0x1040, 0, 0, 0x10040040, 0x10000040, 0x10001000, 0x41040, - 0x40000, 0x41040, 0x40000, 0x10041000, 0x1000, 0x40, 0x10040040, 0x1000, 0x41040, 0x10001000, 0x40, 0x10000040, - 0x10040000, 0x10040040, 0x10000000, 0x40000, 0x10001040, 0, 0x10041040, 0x40040, 0x10000040, 0x10040000, 0x10001000, - 0x10001040, 0, 0x10041040, 0x41000, 0x41000, 0x1040, 0x1040, 0x40040, 0x10000000, 0x10041000); + var spfunction1 = new Array(0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404, 0x4, 0x10000, 0x400, 0x1010400, 0x1010404, 0x400, 0x1000404, 0x1010004, 0x1000000, 0x4, 0x404, 0x1000400, 0x1000400, 0x10400, 0x10400, 0x1010000, 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004, 0x10004, 0, 0x404, 0x10404, 0x1000000, 0x10000, 0x1010404, 0x4, 0x1010000, 0x1010400, 0x1000000, 0x1000000, 0x400, 0x1010004, 0x10000, 0x10400, 0x1000004, 0x400, 0x4, 0x1000404, 0x10404, 0x1010404, 0x10004, 0x1010000, 0x1000404, 0x1000004, 0x404, 0x10404, 0x1010400, 0x404, 0x1000400, 0x1000400, 0, 0x10004, 0x10400, 0, 0x1010004); + var spfunction2 = new Array(-0x7fef7fe0, -0x7fff8000, 0x8000, 0x108020, 0x100000, 0x20, -0x7fefffe0, -0x7fff7fe0, -0x7fffffe0, -0x7fef7fe0, -0x7fef8000, -0x80000000, -0x7fff8000, 0x100000, 0x20, -0x7fefffe0, 0x108000, 0x100020, -0x7fff7fe0, 0, -0x80000000, 0x8000, 0x108020, -0x7ff00000, 0x100020, -0x7fffffe0, 0, 0x108000, 0x8020, -0x7fef8000, -0x7ff00000, 0x8020, 0, 0x108020, -0x7fefffe0, 0x100000, -0x7fff7fe0, -0x7ff00000, -0x7fef8000, 0x8000, -0x7ff00000, -0x7fff8000, 0x20, -0x7fef7fe0, 0x108020, 0x20, 0x8000, -0x80000000, 0x8020, -0x7fef8000, 0x100000, -0x7fffffe0, 0x100020, -0x7fff7fe0, -0x7fffffe0, 0x100020, 0x108000, 0, -0x7fff8000, 0x8020, -0x80000000, -0x7fefffe0, -0x7fef7fe0, 0x108000); + var spfunction3 = new Array(0x208, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200, 0x20008, 0x8000008, 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 0x208, 0x8000000, 0x8, 0x8020200, 0x200, 0x20200, 0x8020000, 0x8020008, 0x20208, 0x8000208, 0x20200, 0x20000, 0x8000208, 0x8, 0x8020208, 0x200, 0x8000000, 0x8020200, 0x8000000, 0x20008, 0x208, 0x20000, 0x8020200, 0x8000200, 0, 0x200, 0x20008, 0x8020208, 0x8000200, 0x8000008, 0x200, 0, 0x8020008, 0x8000208, 0x20000, 0x8000000, 0x8020208, 0x8, 0x20208, 0x20200, 0x8000008, 0x8020000, 0x8000208, 0x208, 0x8020000, 0x20208, 0x8, 0x8020008, 0x20200); + var spfunction4 = new Array(0x802001, 0x2081, 0x2081, 0x80, 0x802080, 0x800081, 0x800001, 0x2001, 0, 0x802000, 0x802000, 0x802081, 0x81, 0, 0x800080, 0x800001, 0x1, 0x2000, 0x800000, 0x802001, 0x80, 0x800000, 0x2001, 0x2080, 0x800081, 0x1, 0x2080, 0x800080, 0x2000, 0x802080, 0x802081, 0x81, 0x800080, 0x800001, 0x802000, 0x802081, 0x81, 0, 0, 0x802000, 0x2080, 0x800080, 0x800081, 0x1, 0x802001, 0x2081, 0x2081, 0x80, 0x802081, 0x81, 0x1, 0x2000, 0x800001, 0x2001, 0x802080, 0x800081, 0x2001, 0x2080, 0x800000, 0x802001, 0x80, 0x800000, 0x2000, 0x802080); + var spfunction5 = new Array(0x100, 0x2080100, 0x2080000, 0x42000100, 0x80000, 0x100, 0x40000000, 0x2080000, 0x40080100, 0x80000, 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100, 0x40000000, 0x2000000, 0x40080000, 0x40080000, 0, 0x40000100, 0x42080100, 0x42080100, 0x2000100, 0x42080000, 0x40000100, 0, 0x42000000, 0x2080100, 0x2000000, 0x42000000, 0x80100, 0x80000, 0x42000100, 0x100, 0x2000000, 0x40000000, 0x2080000, 0x42000100, 0x40080100, 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 0x100, 0x2000000, 0x42080000, 0x42080100, 0x80100, 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000, 0x42000000, 0x80100, 0x2000100, 0x40000100, 0x80000, 0, 0x40080000, 0x2080100, 0x40000100); + var spfunction6 = new Array(0x20000010, 0x20400000, 0x4000, 0x20404010, 0x20400000, 0x10, 0x20404010, 0x400000, 0x20004000, 0x404010, 0x400000, 0x20000010, 0x400010, 0x20004000, 0x20000000, 0x4010, 0, 0x400010, 0x20004010, 0x4000, 0x404000, 0x20004010, 0x10, 0x20400010, 0x20400010, 0, 0x404010, 0x20404000, 0x4010, 0x404000, 0x20404000, 0x20000000, 0x20004000, 0x10, 0x20400010, 0x404000, 0x20404010, 0x400000, 0x4010, 0x20000010, 0x400000, 0x20004000, 0x20000000, 0x4010, 0x20000010, 0x20404010, 0x404000, 0x20400000, 0x404010, 0x20404000, 0, 0x20400010, 0x10, 0x4000, 0x20400000, 0x404010, 0x4000, 0x400010, 0x20004010, 0, 0x20404000, 0x20000000, 0x400010, 0x20004010); + var spfunction7 = new Array(0x200000, 0x4200002, 0x4000802, 0, 0x800, 0x4000802, 0x200802, 0x4200800, 0x4200802, 0x200000, 0, 0x4000002, 0x2, 0x4000000, 0x4200002, 0x802, 0x4000800, 0x200802, 0x200002, 0x4000800, 0x4000002, 0x4200000, 0x4200800, 0x200002, 0x4200000, 0x800, 0x802, 0x4200802, 0x200800, 0x2, 0x4000000, 0x200800, 0x4000000, 0x200800, 0x200000, 0x4000802, 0x4000802, 0x4200002, 0x4200002, 0x2, 0x200002, 0x4000000, 0x4000800, 0x200000, 0x4200800, 0x802, 0x200802, 0x4200800, 0x802, 0x4000002, 0x4200802, 0x4200000, 0x200800, 0, 0x2, 0x4200802, 0, 0x200802, 0x4200000, 0x800, 0x4000002, 0x4000800, 0x800, 0x200002); + var spfunction8 = new Array(0x10001040, 0x1000, 0x40000, 0x10041040, 0x10000000, 0x10001040, 0x40, 0x10000000, 0x40040, 0x10040000, 0x10041040, 0x41000, 0x10041000, 0x41040, 0x1000, 0x40, 0x10040000, 0x10000040, 0x10001000, 0x1040, 0x41000, 0x40040, 0x10040040, 0x10041000, 0x1040, 0, 0, 0x10040040, 0x10000040, 0x10001000, 0x41040, 0x40000, 0x41040, 0x40000, 0x10041000, 0x1000, 0x40, 0x10040040, 0x1000, 0x41040, 0x10001000, 0x40, 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x40000, 0x10001040, 0, 0x10041040, 0x40040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0, 0x10041040, 0x41000, 0x41000, 0x1040, 0x1040, 0x40040, 0x10000000, 0x10041000); //create the 16 or 48 subkeys we will need var m = 0, - i, j, temp, temp2, right1, right2, left, right, looping; + i, + j, + temp, + right1, + right2, + left, + right, + looping; var cbcleft, cbcleft2, cbcright, cbcright2; var endloop, loopinc; var len = message.length; - var chunk = 0; + //set up the loops for single and triple des - var iterations = keys.length == 32 ? 3 : 9; //single or triple des - if (iterations == 3) { + var iterations = keys.length === 32 ? 3 : 9; //single or triple des + if (iterations === 3) { looping = encrypt ? new Array(0, 32, 2) : new Array(30, -2, -2); } else { looping = encrypt ? new Array(0, 32, 2, 62, 30, -2, 64, 96, 2) : new Array(94, 62, -2, 32, 64, 2, 30, -2, -2); @@ -3000,24 +5118,23 @@ function des(keys, message, encrypt, mode, iv, padding) { } //store the result here - var result = ""; - var tempresult = ""; + var result = new Uint8Array(len); + var k = 0; - if (mode == 1) { //CBC mode - cbcleft = (iv.charCodeAt(m++) << 24) | (iv.charCodeAt(m++) << 16) | (iv.charCodeAt(m++) << 8) | iv.charCodeAt(m++); - cbcright = (iv.charCodeAt(m++) << 24) | (iv.charCodeAt(m++) << 16) | (iv.charCodeAt(m++) << 8) | iv.charCodeAt(m++); + if (mode === 1) { + //CBC mode + cbcleft = iv[m++] << 24 | iv[m++] << 16 | iv[m++] << 8 | iv[m++]; + cbcright = iv[m++] << 24 | iv[m++] << 16 | iv[m++] << 8 | iv[m++]; m = 0; } //loop through each 64 bit chunk of the message while (m < len) { - left = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) | (message.charCodeAt(m++) << 8) | message - .charCodeAt(m++); - right = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) | (message.charCodeAt(m++) << 8) | - message.charCodeAt(m++); + left = message[m++] << 24 | message[m++] << 16 | message[m++] << 8 | message[m++]; + right = message[m++] << 24 | message[m++] << 16 | message[m++] << 8 | message[m++]; //for Cipher Block Chaining mode, xor the message with the previous result - if (mode == 1) { + if (mode === 1) { if (encrypt) { left ^= cbcleft; right ^= cbcright; @@ -3030,39 +5147,38 @@ function des(keys, message, encrypt, mode, iv, padding) { } //first each 64 but chunk of the message must be permuted according to IP - temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; + temp = (left >>> 4 ^ right) & 0x0f0f0f0f; right ^= temp; - left ^= (temp << 4); - temp = ((left >>> 16) ^ right) & 0x0000ffff; + left ^= temp << 4; + temp = (left >>> 16 ^ right) & 0x0000ffff; right ^= temp; - left ^= (temp << 16); - temp = ((right >>> 2) ^ left) & 0x33333333; + left ^= temp << 16; + temp = (right >>> 2 ^ left) & 0x33333333; left ^= temp; - right ^= (temp << 2); - temp = ((right >>> 8) ^ left) & 0x00ff00ff; + right ^= temp << 2; + temp = (right >>> 8 ^ left) & 0x00ff00ff; left ^= temp; - right ^= (temp << 8); - temp = ((left >>> 1) ^ right) & 0x55555555; + right ^= temp << 8; + temp = (left >>> 1 ^ right) & 0x55555555; right ^= temp; - left ^= (temp << 1); + left ^= temp << 1; - left = ((left << 1) | (left >>> 31)); - right = ((right << 1) | (right >>> 31)); + left = left << 1 | left >>> 31; + right = right << 1 | right >>> 31; //do this either 1 or 3 times for each chunk of the message for (j = 0; j < iterations; j += 3) { endloop = looping[j + 1]; loopinc = looping[j + 2]; //now go through and perform the encryption or decryption - for (i = looping[j]; i != endloop; i += loopinc) { //for efficiency + for (i = looping[j]; i !== endloop; i += loopinc) { + //for efficiency right1 = right ^ keys[i]; - right2 = ((right >>> 4) | (right << 28)) ^ keys[i + 1]; + right2 = (right >>> 4 | right << 28) ^ keys[i + 1]; //the result is attained by passing these bytes through the S selection functions temp = left; left = right; - right = temp ^ (spfunction2[(right1 >>> 24) & 0x3f] | spfunction4[(right1 >>> 16) & 0x3f] | spfunction6[(right1 >>> - 8) & 0x3f] | spfunction8[right1 & 0x3f] | spfunction1[(right2 >>> 24) & 0x3f] | spfunction3[(right2 >>> 16) & - 0x3f] | spfunction5[(right2 >>> 8) & 0x3f] | spfunction7[right2 & 0x3f]); + right = temp ^ (spfunction2[right1 >>> 24 & 0x3f] | spfunction4[right1 >>> 16 & 0x3f] | spfunction6[right1 >>> 8 & 0x3f] | spfunction8[right1 & 0x3f] | spfunction1[right2 >>> 24 & 0x3f] | spfunction3[right2 >>> 16 & 0x3f] | spfunction5[right2 >>> 8 & 0x3f] | spfunction7[right2 & 0x3f]); } temp = left; left = right; @@ -3070,28 +5186,28 @@ function des(keys, message, encrypt, mode, iv, padding) { } //for either 1 or 3 iterations //move then each one bit to the right - left = ((left >>> 1) | (left << 31)); - right = ((right >>> 1) | (right << 31)); + left = left >>> 1 | left << 31; + right = right >>> 1 | right << 31; //now perform IP-1, which is IP in the opposite direction - temp = ((left >>> 1) ^ right) & 0x55555555; + temp = (left >>> 1 ^ right) & 0x55555555; right ^= temp; - left ^= (temp << 1); - temp = ((right >>> 8) ^ left) & 0x00ff00ff; + left ^= temp << 1; + temp = (right >>> 8 ^ left) & 0x00ff00ff; left ^= temp; - right ^= (temp << 8); - temp = ((right >>> 2) ^ left) & 0x33333333; + right ^= temp << 8; + temp = (right >>> 2 ^ left) & 0x33333333; left ^= temp; - right ^= (temp << 2); - temp = ((left >>> 16) ^ right) & 0x0000ffff; + right ^= temp << 2; + temp = (left >>> 16 ^ right) & 0x0000ffff; right ^= temp; - left ^= (temp << 16); - temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; + left ^= temp << 16; + temp = (left >>> 4 ^ right) & 0x0f0f0f0f; right ^= temp; - left ^= (temp << 4); + left ^= temp << 4; //for Cipher Block Chaining mode, xor the message with the previous result - if (mode == 1) { + if (mode === 1) { if (encrypt) { cbcleft = left; cbcright = right; @@ -3100,20 +5216,17 @@ function des(keys, message, encrypt, mode, iv, padding) { right ^= cbcright2; } } - tempresult += String.fromCharCode((left >>> 24), ((left >>> 16) & 0xff), ((left >>> 8) & 0xff), (left & 0xff), ( - right >>> 24), ((right >>> 16) & 0xff), ((right >>> 8) & 0xff), (right & 0xff)); - chunk += 8; - if (chunk == 512) { - result += tempresult; - tempresult = ""; - chunk = 0; - } + result[k++] = left >>> 24; + result[k++] = left >>> 16 & 0xff; + result[k++] = left >>> 8 & 0xff; + result[k++] = left & 0xff; + result[k++] = right >>> 24; + result[k++] = right >>> 16 & 0xff; + result[k++] = right >>> 8 & 0xff; + result[k++] = right & 0xff; } //for every 8 characters, or 64 bits in the message - //return the result as an array - result += tempresult; - //only remove padding if decrypting - note that you need to use the same padding option for both encrypt and decrypt if (!encrypt) { result = des_removePadding(result, padding); @@ -3122,40 +5235,25 @@ function des(keys, message, encrypt, mode, iv, padding) { return result; } //end of des - - //des_createKeys //this takes as input a 64 bit key (even though only 56 bits are used) //as an array of 2 integers, and returns 16 48 bit keys function des_createKeys(key) { //declaring this locally speeds things up a bit - var pc2bytes0 = new Array(0, 0x4, 0x20000000, 0x20000004, 0x10000, 0x10004, 0x20010000, 0x20010004, 0x200, 0x204, - 0x20000200, 0x20000204, 0x10200, 0x10204, 0x20010200, 0x20010204); - var pc2bytes1 = new Array(0, 0x1, 0x100000, 0x100001, 0x4000000, 0x4000001, 0x4100000, 0x4100001, 0x100, 0x101, 0x100100, - 0x100101, 0x4000100, 0x4000101, 0x4100100, 0x4100101); - var pc2bytes2 = new Array(0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808, 0, 0x8, 0x800, 0x808, - 0x1000000, 0x1000008, 0x1000800, 0x1000808); - var pc2bytes3 = new Array(0, 0x200000, 0x8000000, 0x8200000, 0x2000, 0x202000, 0x8002000, 0x8202000, 0x20000, 0x220000, - 0x8020000, 0x8220000, 0x22000, 0x222000, 0x8022000, 0x8222000); - var pc2bytes4 = new Array(0, 0x40000, 0x10, 0x40010, 0, 0x40000, 0x10, 0x40010, 0x1000, 0x41000, 0x1010, 0x41010, 0x1000, - 0x41000, 0x1010, 0x41010); - var pc2bytes5 = new Array(0, 0x400, 0x20, 0x420, 0, 0x400, 0x20, 0x420, 0x2000000, 0x2000400, 0x2000020, 0x2000420, - 0x2000000, 0x2000400, 0x2000020, 0x2000420); - var pc2bytes6 = new Array(0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002, 0, 0x10000000, - 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002); - var pc2bytes7 = new Array(0, 0x10000, 0x800, 0x10800, 0x20000000, 0x20010000, 0x20000800, 0x20010800, 0x20000, 0x30000, - 0x20800, 0x30800, 0x20020000, 0x20030000, 0x20020800, 0x20030800); - var pc2bytes8 = new Array(0, 0x40000, 0, 0x40000, 0x2, 0x40002, 0x2, 0x40002, 0x2000000, 0x2040000, 0x2000000, 0x2040000, - 0x2000002, 0x2040002, 0x2000002, 0x2040002); - var pc2bytes9 = new Array(0, 0x10000000, 0x8, 0x10000008, 0, 0x10000000, 0x8, 0x10000008, 0x400, 0x10000400, 0x408, - 0x10000408, 0x400, 0x10000400, 0x408, 0x10000408); - var pc2bytes10 = new Array(0, 0x20, 0, 0x20, 0x100000, 0x100020, 0x100000, 0x100020, 0x2000, 0x2020, 0x2000, 0x2020, - 0x102000, 0x102020, 0x102000, 0x102020); - var pc2bytes11 = new Array(0, 0x1000000, 0x200, 0x1000200, 0x200000, 0x1200000, 0x200200, 0x1200200, 0x4000000, 0x5000000, - 0x4000200, 0x5000200, 0x4200000, 0x5200000, 0x4200200, 0x5200200); - var pc2bytes12 = new Array(0, 0x1000, 0x8000000, 0x8001000, 0x80000, 0x81000, 0x8080000, 0x8081000, 0x10, 0x1010, - 0x8000010, 0x8001010, 0x80010, 0x81010, 0x8080010, 0x8081010); + var pc2bytes0 = new Array(0, 0x4, 0x20000000, 0x20000004, 0x10000, 0x10004, 0x20010000, 0x20010004, 0x200, 0x204, 0x20000200, 0x20000204, 0x10200, 0x10204, 0x20010200, 0x20010204); + var pc2bytes1 = new Array(0, 0x1, 0x100000, 0x100001, 0x4000000, 0x4000001, 0x4100000, 0x4100001, 0x100, 0x101, 0x100100, 0x100101, 0x4000100, 0x4000101, 0x4100100, 0x4100101); + var pc2bytes2 = new Array(0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808, 0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808); + var pc2bytes3 = new Array(0, 0x200000, 0x8000000, 0x8200000, 0x2000, 0x202000, 0x8002000, 0x8202000, 0x20000, 0x220000, 0x8020000, 0x8220000, 0x22000, 0x222000, 0x8022000, 0x8222000); + var pc2bytes4 = new Array(0, 0x40000, 0x10, 0x40010, 0, 0x40000, 0x10, 0x40010, 0x1000, 0x41000, 0x1010, 0x41010, 0x1000, 0x41000, 0x1010, 0x41010); + var pc2bytes5 = new Array(0, 0x400, 0x20, 0x420, 0, 0x400, 0x20, 0x420, 0x2000000, 0x2000400, 0x2000020, 0x2000420, 0x2000000, 0x2000400, 0x2000020, 0x2000420); + var pc2bytes6 = new Array(0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002, 0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002); + var pc2bytes7 = new Array(0, 0x10000, 0x800, 0x10800, 0x20000000, 0x20010000, 0x20000800, 0x20010800, 0x20000, 0x30000, 0x20800, 0x30800, 0x20020000, 0x20030000, 0x20020800, 0x20030800); + var pc2bytes8 = new Array(0, 0x40000, 0, 0x40000, 0x2, 0x40002, 0x2, 0x40002, 0x2000000, 0x2040000, 0x2000000, 0x2040000, 0x2000002, 0x2040002, 0x2000002, 0x2040002); + var pc2bytes9 = new Array(0, 0x10000000, 0x8, 0x10000008, 0, 0x10000000, 0x8, 0x10000008, 0x400, 0x10000400, 0x408, 0x10000408, 0x400, 0x10000400, 0x408, 0x10000408); + var pc2bytes10 = new Array(0, 0x20, 0, 0x20, 0x100000, 0x100020, 0x100000, 0x100020, 0x2000, 0x2020, 0x2000, 0x2020, 0x102000, 0x102020, 0x102000, 0x102020); + var pc2bytes11 = new Array(0, 0x1000000, 0x200, 0x1000200, 0x200000, 0x1200000, 0x200200, 0x1200200, 0x4000000, 0x5000000, 0x4000200, 0x5000200, 0x4200000, 0x5200000, 0x4200200, 0x5200200); + var pc2bytes12 = new Array(0, 0x1000, 0x8000000, 0x8001000, 0x80000, 0x81000, 0x8080000, 0x8081000, 0x10, 0x1010, 0x8000010, 0x8001010, 0x80010, 0x81010, 0x8080010, 0x8081010); var pc2bytes13 = new Array(0, 0x4, 0x100, 0x104, 0, 0x4, 0x100, 0x104, 0x1, 0x5, 0x101, 0x105, 0x1, 0x5, 0x101, 0x105); //how many iterations (1 for des, 3 for triple des) @@ -3165,51 +5263,54 @@ function des_createKeys(key) { //now define the left shifts which need to be done var shifts = new Array(0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0); //other variables - var lefttemp, righttemp, m = 0, - n = 0, - temp; + var lefttemp, + righttemp, + m = 0, + n = 0, + temp; - for (var j = 0; j < iterations; j++) { //either 1 or 3 iterations - var left = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++); - var right = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++); + for (var j = 0; j < iterations; j++) { + //either 1 or 3 iterations + var left = key[m++] << 24 | key[m++] << 16 | key[m++] << 8 | key[m++]; + var right = key[m++] << 24 | key[m++] << 16 | key[m++] << 8 | key[m++]; - temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; + temp = (left >>> 4 ^ right) & 0x0f0f0f0f; right ^= temp; - left ^= (temp << 4); - temp = ((right >>> -16) ^ left) & 0x0000ffff; + left ^= temp << 4; + temp = (right >>> -16 ^ left) & 0x0000ffff; left ^= temp; - right ^= (temp << -16); - temp = ((left >>> 2) ^ right) & 0x33333333; + right ^= temp << -16; + temp = (left >>> 2 ^ right) & 0x33333333; right ^= temp; - left ^= (temp << 2); - temp = ((right >>> -16) ^ left) & 0x0000ffff; + left ^= temp << 2; + temp = (right >>> -16 ^ left) & 0x0000ffff; left ^= temp; - right ^= (temp << -16); - temp = ((left >>> 1) ^ right) & 0x55555555; + right ^= temp << -16; + temp = (left >>> 1 ^ right) & 0x55555555; right ^= temp; - left ^= (temp << 1); - temp = ((right >>> 8) ^ left) & 0x00ff00ff; + left ^= temp << 1; + temp = (right >>> 8 ^ left) & 0x00ff00ff; left ^= temp; - right ^= (temp << 8); - temp = ((left >>> 1) ^ right) & 0x55555555; + right ^= temp << 8; + temp = (left >>> 1 ^ right) & 0x55555555; right ^= temp; - left ^= (temp << 1); + left ^= temp << 1; //the right side needs to be shifted and to get the last four bits of the left side - temp = (left << 8) | ((right >>> 20) & 0x000000f0); + temp = left << 8 | right >>> 20 & 0x000000f0; //left needs to be put upside down - left = (right << 24) | ((right << 8) & 0xff0000) | ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0); + left = right << 24 | right << 8 & 0xff0000 | right >>> 8 & 0xff00 | right >>> 24 & 0xf0; right = temp; //now go through and perform these shifts on the left and right keys for (var i = 0; i < shifts.length; i++) { //shift the keys either one or two bits to the left if (shifts[i]) { - left = (left << 2) | (left >>> 26); - right = (right << 2) | (right >>> 26); + left = left << 2 | left >>> 26; + right = right << 2 | right >>> 26; } else { - left = (left << 1) | (left >>> 27); - right = (right << 1) | (right >>> 27); + left = left << 1 | left >>> 27; + right = right << 1 | right >>> 27; } left &= -0xf; right &= -0xf; @@ -3218,65 +5319,85 @@ function des_createKeys(key) { //this conversion will look like PC-2 except only the last 6 bits of each byte are used //rather than 48 consecutive bits and the order of lines will be according to //how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7 - lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf] | pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[( - left >>> 16) & 0xf] | pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf] | pc2bytes6[(left >>> 4) & - 0xf]; - righttemp = pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf] | pc2bytes9[(right >>> 20) & 0xf] | - pc2bytes10[(right >>> 16) & 0xf] | pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf] | - pc2bytes13[(right >>> 4) & 0xf]; - temp = ((righttemp >>> 16) ^ lefttemp) & 0x0000ffff; + lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[left >>> 24 & 0xf] | pc2bytes2[left >>> 20 & 0xf] | pc2bytes3[left >>> 16 & 0xf] | pc2bytes4[left >>> 12 & 0xf] | pc2bytes5[left >>> 8 & 0xf] | pc2bytes6[left >>> 4 & 0xf]; + righttemp = pc2bytes7[right >>> 28] | pc2bytes8[right >>> 24 & 0xf] | pc2bytes9[right >>> 20 & 0xf] | pc2bytes10[right >>> 16 & 0xf] | pc2bytes11[right >>> 12 & 0xf] | pc2bytes12[right >>> 8 & 0xf] | pc2bytes13[right >>> 4 & 0xf]; + temp = (righttemp >>> 16 ^ lefttemp) & 0x0000ffff; keys[n++] = lefttemp ^ temp; - keys[n++] = righttemp ^ (temp << 16); + keys[n++] = righttemp ^ temp << 16; } } //for each iterations //return the keys we've created return keys; } //end of des_createKeys - function des_addPadding(message, padding) { - var padLength = 8 - (message.length % 8); - if ((padding == 2) && (padLength < 8)) { //pad the message with spaces - message += " ".substr(0, padLength); - } else if (padding == 1) { //PKCS7 padding - message += String.fromCharCode(padLength, padLength, padLength, padLength, padLength, padLength, padLength, - padLength).substr(0, padLength); - } else if (!padding && (padLength < 8)) { //pad the message out with null bytes - message += "\0\0\0\0\0\0\0\0".substr(0, padLength); + var padLength = 8 - message.length % 8; + + var pad; + if (padding === 2 && padLength < 8) { + //pad the message with spaces + pad = " ".charCodeAt(0); + } else if (padding === 1) { + //PKCS7 padding + pad = padLength; + } else if (!padding && padLength < 8) { + //pad the message out with null bytes + pad = 0; + } else if (padLength === 8) { + return message; + } else { + throw new Error('des: invalid padding'); } - return message; + + var paddedMessage = new Uint8Array(message.length + padLength); + for (var i = 0; i < message.length; i++) { + paddedMessage[i] = message[i]; + } + for (var j = 0; j < padLength; j++) { + paddedMessage[message.length + j] = pad; + } + + return paddedMessage; } function des_removePadding(message, padding) { - if (padding == 2) { // space padded - message = message.replace(/ *$/g, ""); - } else if (padding == 1) { // PKCS7 - var padCount = message.charCodeAt(message.length - 1); - message = message.substr(0, message.length - padCount); - } else if (!padding) { // null padding - message = message.replace(/\0*$/g, ""); + var padLength = null; + var pad; + if (padding === 2) { + // space padded + pad = " ".charCodeAt(0); + } else if (padding === 1) { + // PKCS7 + padLength = message[message.length - 1]; + } else if (!padding) { + // null padding + pad = 0; + } else { + throw new Error('des: invalid padding'); } - return message; + + if (!padLength) { + padLength = 1; + while (message[message.length - padLength] === pad) { + padLength++; + } + padLength--; + } + + return message.subarray(0, message.length - padLength); } - -var util = require('../../util.js'); - // added by Recurity Labs function Des(key) { this.key = []; for (var i = 0; i < 3; i++) { - this.key.push(key.substr(i * 8, 8)); + this.key.push(new Uint8Array(key.subarray(i * 8, i * 8 + 8))); } - this.encrypt = function(block) { - return util.str2bin(des(des_createKeys(this.key[2]), - des(des_createKeys(this.key[1]), - des(des_createKeys(this.key[0]), - util.bin2str(block), true, 0, null, null), - false, 0, null, null), true, 0, null, null)); + this.encrypt = function (block) { + return des(des_createKeys(this.key[2]), des(des_createKeys(this.key[1]), des(des_createKeys(this.key[0]), block, true, 0, null, null), false, 0, null, null), true, 0, null, null); }; } @@ -3289,25 +5410,25 @@ Des.blockSize = Des.prototype.blockSize = 8; function OriginalDes(key) { this.key = key; - this.encrypt = function(block, padding) { + this.encrypt = function (block, padding) { var keys = des_createKeys(this.key); - return util.str2bin(des(keys, util.bin2str(block), true, 0, null, padding)); + return des(keys, block, true, 0, null, padding); }; - this.decrypt = function(block, padding) { + this.decrypt = function (block, padding) { var keys = des_createKeys(this.key); - return util.str2bin(des(keys, util.bin2str(block), false, 0, null, padding)); + return des(keys, block, false, 0, null, padding); }; } -module.exports = { +exports.default = { /** @static */ des: Des, /** @static */ originalDes: OriginalDes }; -},{"../../util.js":76}],23:[function(require,module,exports){ +},{}],25:[function(require,module,exports){ /** * @requires crypto/cipher/aes * @requires crypto/cipher/blowfish @@ -3316,34 +5437,64 @@ module.exports = { * @module crypto/cipher */ -var desModule = require('./des.js'); +'use strict'; -module.exports = { +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _aes = require('./aes.js'); + +var _aes2 = _interopRequireDefault(_aes); + +var _des = require('./des.js'); + +var _des2 = _interopRequireDefault(_des); + +var _cast = require('./cast5.js'); + +var _cast2 = _interopRequireDefault(_cast); + +var _twofish = require('./twofish.js'); + +var _twofish2 = _interopRequireDefault(_twofish); + +var _blowfish = require('./blowfish.js'); + +var _blowfish2 = _interopRequireDefault(_blowfish); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = { + /** @see module:crypto/cipher/aes */ + aes128: _aes2.default[128], + aes192: _aes2.default[192], + aes256: _aes2.default[256], /** @see module:crypto/cipher/des.originalDes */ - des: desModule.originalDes, + des: _des2.default.originalDes, /** @see module:crypto/cipher/des.des */ - tripledes: desModule.des, + tripledes: _des2.default.des, /** @see module:crypto/cipher/cast5 */ - cast5: require('./cast5.js'), + cast5: _cast2.default, /** @see module:crypto/cipher/twofish */ - twofish: require('./twofish.js'), + twofish: _twofish2.default, /** @see module:crypto/cipher/blowfish */ - blowfish: require('./blowfish.js'), + blowfish: _blowfish2.default, /** Not implemented */ - idea: function() { + idea: function idea() { throw new Error('IDEA symmetric-key algorithm not implemented'); } }; -var aes = require('./aes.js'); +},{"./aes.js":21,"./blowfish.js":22,"./cast5.js":23,"./des.js":24,"./twofish.js":26}],26:[function(require,module,exports){ +"use strict"; -for (var i in aes) { - module.exports['aes' + i] = aes[i]; -} - -},{"./aes.js":19,"./blowfish.js":20,"./cast5.js":21,"./des.js":22,"./twofish.js":24}],24:[function(require,module,exports){ -/* Modified by Recurity Labs GmbH - * +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = TF; +/* Modified by Recurity Labs GmbH + * * Cipher.js * A block-cipher algorithm implementation on JavaScript * See Cipher.readme.txt for further information. @@ -3354,10 +5505,10 @@ for (var i in aes) { * ACKNOWLEDGMENT * * The main subroutines are written by Michiel van Everdingen. - * + * * Michiel van Everdingen * http://home.versatel.nl/MAvanEverdingen/index.html - * + * * All rights for these routines are reserved to Michiel van Everdingen. * */ @@ -3366,8 +5517,6 @@ for (var i in aes) { * @module crypto/cipher/twofish */ - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Math //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3375,7 +5524,7 @@ for (var i in aes) { var MAXINT = 0xFFFFFFFF; function rotw(w, n) { - return (w << n | w >>> (32 - n)) & MAXINT; + return (w << n | w >>> 32 - n) & MAXINT; } function getW(a, i) { @@ -3383,15 +5532,11 @@ function getW(a, i) { } function setW(a, i, w) { - a.splice(i, 4, w & 0xFF, (w >>> 8) & 0xFF, (w >>> 16) & 0xFF, (w >>> 24) & 0xFF); -} - -function setWInv(a, i, w) { - a.splice(i, 4, (w >>> 24) & 0xFF, (w >>> 16) & 0xFF, (w >>> 8) & 0xFF, w & 0xFF); + a.splice(i, 4, w & 0xFF, w >>> 8 & 0xFF, w >>> 16 & 0xFF, w >>> 24 & 0xFF); } function getB(x, n) { - return (x >>> (n * 8)) & 0xFF; + return x >>> n * 8 & 0xFF; } // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3411,70 +5556,50 @@ function createTwofish() { algorithmName = "twofish"; var tfsKey = []; - var tfsM = [ - [], - [], - [], - [] - ]; + var tfsM = [[], [], [], []]; function tfsInit(key) { keyBytes = key; - var i, a, b, c, d, meKey = [], - moKey = [], - inKey = []; + var i, + a, + b, + c, + d, + meKey = [], + moKey = [], + inKey = []; var kLen; var sKey = []; var f01, f5b, fef; - var q0 = [ - [8, 1, 7, 13, 6, 15, 3, 2, 0, 11, 5, 9, 14, 12, 10, 4], - [2, 8, 11, 13, 15, 7, 6, 14, 3, 1, 9, 4, 0, 10, 12, 5] - ]; - var q1 = [ - [14, 12, 11, 8, 1, 2, 3, 5, 15, 4, 10, 6, 7, 0, 9, 13], - [1, 14, 2, 11, 4, 12, 3, 7, 6, 13, 10, 5, 15, 9, 0, 8] - ]; - var q2 = [ - [11, 10, 5, 14, 6, 13, 9, 0, 12, 8, 15, 3, 2, 4, 7, 1], - [4, 12, 7, 5, 1, 6, 9, 10, 0, 14, 13, 8, 2, 11, 3, 15] - ]; - var q3 = [ - [13, 7, 15, 4, 1, 2, 6, 14, 9, 11, 3, 0, 8, 5, 12, 10], - [11, 9, 5, 1, 12, 3, 13, 14, 6, 4, 7, 15, 2, 0, 8, 10] - ]; + var q0 = [[8, 1, 7, 13, 6, 15, 3, 2, 0, 11, 5, 9, 14, 12, 10, 4], [2, 8, 11, 13, 15, 7, 6, 14, 3, 1, 9, 4, 0, 10, 12, 5]]; + var q1 = [[14, 12, 11, 8, 1, 2, 3, 5, 15, 4, 10, 6, 7, 0, 9, 13], [1, 14, 2, 11, 4, 12, 3, 7, 6, 13, 10, 5, 15, 9, 0, 8]]; + var q2 = [[11, 10, 5, 14, 6, 13, 9, 0, 12, 8, 15, 3, 2, 4, 7, 1], [4, 12, 7, 5, 1, 6, 9, 10, 0, 14, 13, 8, 2, 11, 3, 15]]; + var q3 = [[13, 7, 15, 4, 1, 2, 6, 14, 9, 11, 3, 0, 8, 5, 12, 10], [11, 9, 5, 1, 12, 3, 13, 14, 6, 4, 7, 15, 2, 0, 8, 10]]; var ror4 = [0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15]; var ashx = [0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 5, 14, 7]; - var q = [ - [], - [] - ]; - var m = [ - [], - [], - [], - [] - ]; + var q = [[], []]; + var m = [[], [], [], []]; function ffm5b(x) { - return x ^ (x >> 2) ^ [0, 90, 180, 238][x & 3]; + return x ^ x >> 2 ^ [0, 90, 180, 238][x & 3]; } function ffmEf(x) { - return x ^ (x >> 1) ^ (x >> 2) ^ [0, 238, 180, 90][x & 3]; + return x ^ x >> 1 ^ x >> 2 ^ [0, 238, 180, 90][x & 3]; } function mdsRem(p, q) { var i, t, u; for (i = 0; i < 8; i++) { t = q >>> 24; - q = ((q << 8) & MAXINT) | p >>> 24; - p = (p << 8) & MAXINT; + q = q << 8 & MAXINT | p >>> 24; + p = p << 8 & MAXINT; u = t << 1; if (t & 128) { u ^= 333; } - q ^= t ^ (u << 16); + q ^= t ^ u << 16; u ^= t >>> 1; if (t & 1) { u ^= 166; @@ -3495,9 +5620,9 @@ function createTwofish() { function hFun(x, key) { var a = getB(x, 0), - b = getB(x, 1), - c = getB(x, 2), - d = getB(x, 3); + b = getB(x, 1), + c = getB(x, 2), + d = getB(x, 3); switch (kLen) { case 4: a = q[1][a] ^ getB(key[3], 0); @@ -3520,8 +5645,9 @@ function createTwofish() { keyBytes = keyBytes.slice(0, 32); i = keyBytes.length; - while (i != 16 && i != 24 && i != 32) + while (i !== 16 && i !== 24 && i !== 32) { keyBytes[i++] = 0; + } for (i = 0; i < keyBytes.length; i += 4) { inKey[i >> 2] = getW(keyBytes, i); @@ -3556,7 +5682,7 @@ function createTwofish() { b = a + 0x1010101; a = hFun(a, meKey); b = rotw(hFun(b, moKey), 8); - tfsKey[i] = (a + b) & MAXINT; + tfsKey[i] = a + b & MAXINT; tfsKey[i + 1] = rotw(a + 2 * b, 9); } for (i = 0; i < 256; i++) { @@ -3592,43 +5718,34 @@ function createTwofish() { function tfsFrnd(r, blk) { var a = tfsG0(blk[0]); var b = tfsG1(blk[1]); - blk[2] = rotw(blk[2] ^ (a + b + tfsKey[4 * r + 8]) & MAXINT, 31); - blk[3] = rotw(blk[3], 1) ^ (a + 2 * b + tfsKey[4 * r + 9]) & MAXINT; + blk[2] = rotw(blk[2] ^ a + b + tfsKey[4 * r + 8] & MAXINT, 31); + blk[3] = rotw(blk[3], 1) ^ a + 2 * b + tfsKey[4 * r + 9] & MAXINT; a = tfsG0(blk[2]); b = tfsG1(blk[3]); - blk[0] = rotw(blk[0] ^ (a + b + tfsKey[4 * r + 10]) & MAXINT, 31); - blk[1] = rotw(blk[1], 1) ^ (a + 2 * b + tfsKey[4 * r + 11]) & MAXINT; + blk[0] = rotw(blk[0] ^ a + b + tfsKey[4 * r + 10] & MAXINT, 31); + blk[1] = rotw(blk[1], 1) ^ a + 2 * b + tfsKey[4 * r + 11] & MAXINT; } function tfsIrnd(i, blk) { var a = tfsG0(blk[0]); var b = tfsG1(blk[1]); - blk[2] = rotw(blk[2], 1) ^ (a + b + tfsKey[4 * i + 10]) & MAXINT; - blk[3] = rotw(blk[3] ^ (a + 2 * b + tfsKey[4 * i + 11]) & MAXINT, 31); + blk[2] = rotw(blk[2], 1) ^ a + b + tfsKey[4 * i + 10] & MAXINT; + blk[3] = rotw(blk[3] ^ a + 2 * b + tfsKey[4 * i + 11] & MAXINT, 31); a = tfsG0(blk[2]); b = tfsG1(blk[3]); - blk[0] = rotw(blk[0], 1) ^ (a + b + tfsKey[4 * i + 8]) & MAXINT; - blk[1] = rotw(blk[1] ^ (a + 2 * b + tfsKey[4 * i + 9]) & MAXINT, 31); + blk[0] = rotw(blk[0], 1) ^ a + b + tfsKey[4 * i + 8] & MAXINT; + blk[1] = rotw(blk[1] ^ a + 2 * b + tfsKey[4 * i + 9] & MAXINT, 31); } function tfsClose() { tfsKey = []; - tfsM = [ - [], - [], - [], - [] - ]; + tfsM = [[], [], [], []]; } function tfsEncrypt(data, offset) { dataBytes = data; dataOffset = offset; - var blk = [getW(dataBytes, dataOffset) ^ tfsKey[0], - getW(dataBytes, dataOffset + 4) ^ tfsKey[1], - getW(dataBytes, dataOffset + 8) ^ tfsKey[2], - getW(dataBytes, dataOffset + 12) ^ tfsKey[3] - ]; + var blk = [getW(dataBytes, dataOffset) ^ tfsKey[0], getW(dataBytes, dataOffset + 4) ^ tfsKey[1], getW(dataBytes, dataOffset + 8) ^ tfsKey[2], getW(dataBytes, dataOffset + 12) ^ tfsKey[3]]; for (var j = 0; j < 8; j++) { tfsFrnd(j, blk); } @@ -3643,11 +5760,7 @@ function createTwofish() { function tfsDecrypt(data, offset) { dataBytes = data; dataOffset = offset; - var blk = [getW(dataBytes, dataOffset) ^ tfsKey[4], - getW(dataBytes, dataOffset + 4) ^ tfsKey[5], - getW(dataBytes, dataOffset + 8) ^ tfsKey[6], - getW(dataBytes, dataOffset + 12) ^ tfsKey[7] - ]; + var blk = [getW(dataBytes, dataOffset) ^ tfsKey[4], getW(dataBytes, dataOffset + 4) ^ tfsKey[5], getW(dataBytes, dataOffset + 8) ^ tfsKey[6], getW(dataBytes, dataOffset + 12) ^ tfsKey[7]]; for (var j = 7; j >= 0; j--) { tfsIrnd(j, blk); } @@ -3676,24 +5789,13 @@ function createTwofish() { }; } -var util = require('../../util.js'); - // added by Recurity Labs -function TFencrypt(block, key) { - var block_copy = toArray(block); - var tf = createTwofish(); - tf.open(util.str2bin(key), 0); - var result = tf.encrypt(block_copy, 0); - tf.close(); - return result; -} - function TF(key) { this.tf = createTwofish(); - this.tf.open(util.str2bin(key), 0); + this.tf.open(toArray(key), 0); - this.encrypt = function(block) { + this.encrypt = function (block) { return this.tf.encrypt(toArray(block), 0); }; } @@ -3707,12 +5809,10 @@ function toArray(typedArray) { return result; } +TF.keySize = TF.prototype.keySize = 32; +TF.blockSize = TF.prototype.blockSize = 16; -module.exports = TF; -module.exports.keySize = TF.prototype.keySize = 32; -module.exports.blockSize = TF.prototype.blockSize = 16; - -},{"../../util.js":76}],25:[function(require,module,exports){ +},{}],27:[function(require,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -3740,12 +5840,31 @@ module.exports.blockSize = TF.prototype.blockSize = 16; * @module crypto/crypto */ -var random = require('./random.js'), - cipher = require('./cipher'), - publicKey = require('./public_key'), - type_mpi = require('../type/mpi.js'); +'use strict'; -module.exports = { +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _random = require('./random.js'); + +var _random2 = _interopRequireDefault(_random); + +var _cipher = require('./cipher'); + +var _cipher2 = _interopRequireDefault(_cipher); + +var _public_key = require('./public_key'); + +var _public_key2 = _interopRequireDefault(_public_key); + +var _mpi = require('../type/mpi.js'); + +var _mpi2 = _interopRequireDefault(_mpi); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = { /** * Encrypts data using the specified public key multiprecision integers * and the specified algorithm. @@ -3755,20 +5874,20 @@ module.exports = { * @return {Array} if RSA an module:type/mpi; * if elgamal encryption an array of two module:type/mpi is returned; otherwise null */ - publicKeyEncrypt: function(algo, publicMPIs, data) { - var result = (function() { + publicKeyEncrypt: function publicKeyEncrypt(algo, publicMPIs, data) { + var result = function () { var m; switch (algo) { case 'rsa_encrypt': case 'rsa_encrypt_sign': - var rsa = new publicKey.rsa(); + var rsa = new _public_key2.default.rsa(); var n = publicMPIs[0].toBigInteger(); var e = publicMPIs[1].toBigInteger(); m = data.toBigInteger(); return [rsa.encrypt(m, e, n)]; case 'elgamal': - var elgamal = new publicKey.elgamal(); + var elgamal = new _public_key2.default.elgamal(); var p = publicMPIs[0].toBigInteger(); var g = publicMPIs[1].toBigInteger(); var y = publicMPIs[2].toBigInteger(); @@ -3778,10 +5897,10 @@ module.exports = { default: return []; } - })(); + }(); - return result.map(function(bn) { - var mpi = new type_mpi(); + return result.map(function (bn) { + var mpi = new _mpi2.default(); mpi.fromBigInteger(bn); return mpi; }); @@ -3799,14 +5918,14 @@ module.exports = { * @return {module:type/mpi} returns a big integer containing the decrypted data; otherwise null */ - publicKeyDecrypt: function(algo, keyIntegers, dataIntegers) { + publicKeyDecrypt: function publicKeyDecrypt(algo, keyIntegers, dataIntegers) { var p; - var bn = (function() { + var bn = function () { switch (algo) { case 'rsa_encrypt_sign': case 'rsa_encrypt': - var rsa = new publicKey.rsa(); + var rsa = new _public_key2.default.rsa(); // 0 and 1 are the public key. var n = keyIntegers[0].toBigInteger(); var e = keyIntegers[1].toBigInteger(); @@ -3818,7 +5937,7 @@ module.exports = { var m = dataIntegers[0].toBigInteger(); return rsa.decrypt(m, n, e, d, p, q, u); case 'elgamal': - var elgamal = new publicKey.elgamal(); + var elgamal = new _public_key2.default.elgamal(); var x = keyIntegers[3].toBigInteger(); var c1 = dataIntegers[0].toBigInteger(); var c2 = dataIntegers[1].toBigInteger(); @@ -3827,9 +5946,9 @@ module.exports = { default: return null; } - })(); + }(); - var result = new type_mpi(); + var result = new _mpi2.default(); result.fromBigInteger(bn); return result; }, @@ -3838,7 +5957,7 @@ module.exports = { * @param {String} algo The public key algorithm * @return {Integer} The number of integers. */ - getPrivateMpiCount: function(algo) { + getPrivateMpiCount: function getPrivateMpiCount(algo) { switch (algo) { case 'rsa_encrypt': case 'rsa_encrypt_sign': @@ -3862,7 +5981,7 @@ module.exports = { } }, - getPublicMpiCount: function(algo) { + getPublicMpiCount: function getPublicMpiCount(algo) { // - A series of multiprecision integers comprising the key material: // Algorithm-Specific Fields for RSA public keys: // - a multiprecision integer (MPI) of RSA public modulus n; @@ -3873,18 +5992,18 @@ module.exports = { case 'rsa_sign': return 2; - // Algorithm-Specific Fields for Elgamal public keys: - // - MPI of Elgamal prime p; - // - MPI of Elgamal group generator g; - // - MPI of Elgamal public key value y (= g**x mod p where x is secret). + // Algorithm-Specific Fields for Elgamal public keys: + // - MPI of Elgamal prime p; + // - MPI of Elgamal group generator g; + // - MPI of Elgamal public key value y (= g**x mod p where x is secret). case 'elgamal': return 3; - // Algorithm-Specific Fields for DSA public keys: - // - MPI of DSA prime p; - // - MPI of DSA group order q (q is a prime divisor of p-1); - // - MPI of DSA group generator g; - // - MPI of DSA public-key value y (= g**x mod p where x is secret). + // Algorithm-Specific Fields for DSA public keys: + // - MPI of DSA prime p; + // - MPI of DSA group order q (q is a prime divisor of p-1); + // - MPI of DSA group generator g; + // - MPI of DSA public-key value y (= g**x mod p where x is secret). case 'dsa': return 4; @@ -3893,14 +6012,14 @@ module.exports = { } }, - generateMpi: function(algo, bits) { + generateMpi: function generateMpi(algo, bits) { switch (algo) { case 'rsa_encrypt': case 'rsa_encrypt_sign': case 'rsa_sign': //remember "publicKey" refers to the crypto/public_key dir - var rsa = new publicKey.rsa(); - return rsa.generate(bits, "10001").then(function(keyObject) { + var rsa = new _public_key2.default.rsa(); + return rsa.generate(bits, "10001").then(function (keyObject) { var output = []; output.push(keyObject.n); output.push(keyObject.ee); @@ -3915,1195 +6034,140 @@ module.exports = { } function mapResult(result) { - return result.map(function(bn) { - var mpi = new type_mpi(); + return result.map(function (bn) { + var mpi = new _mpi2.default(); mpi.fromBigInteger(bn); return mpi; }); } }, - /** * generate random byte prefix as string for the specified algorithm * @param {module:enums.symmetric} algo Algorithm to use (see {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2}) - * @return {String} Random bytes with length equal to the block + * @return {Uint8Array} Random bytes with length equal to the block * size of the cipher */ - getPrefixRandom: function(algo) { - return random.getRandomBytes(cipher[algo].blockSize); + getPrefixRandom: function getPrefixRandom(algo) { + return _random2.default.getRandomBytes(_cipher2.default[algo].blockSize); }, /** * Generating a session key for the specified symmetric algorithm * @param {module:enums.symmetric} algo Algorithm to use (see {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2}) - * @return {String} Random bytes as a string to be used as a key + * @return {Uint8Array} Random bytes as a string to be used as a key */ - generateSessionKey: function(algo) { - return random.getRandomBytes(cipher[algo].keySize); + generateSessionKey: function generateSessionKey(algo) { + return _random2.default.getRandomBytes(_cipher2.default[algo].keySize); } }; -},{"../type/mpi.js":74,"./cipher":23,"./public_key":36,"./random.js":39}],26:[function(require,module,exports){ -/** - * Secure Hash Algorithm with 256-bit digest (SHA-256) implementation. - * - * See FIPS 180-2 for details. - * - * This implementation is currently limited to message lengths (in bytes) that - * are up to 32-bits in size. - * - * @author Dave Longley - * - * Copyright (c) 2010-2012 Digital Bazaar, Inc. - */ - -var sha256 = module.exports = {}; -var util = require('./forge_util.js'); - -// sha-256 padding bytes not initialized yet -var _padding = null; -var _initialized = false; - -// table of constants -var _k = null; - -/** - * Initializes the constant tables. - */ -var _init = function() { - // create padding - _padding = String.fromCharCode(128); - _padding += util.fillString(String.fromCharCode(0x00), 64); - - // create K table for SHA-256 - _k = [ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 - ]; - - // now initialized - _initialized = true; -}; - -/** - * Updates a SHA-256 state with the given byte buffer. - * - * @param s the SHA-256 state to update. - * @param w the array to use to store words. - * @param bytes the byte buffer to update with. - */ -var _update = function(s, w, bytes) { - // consume 512 bit (64 byte) chunks - var t1, t2, s0, s1, ch, maj, i, a, b, c, d, e, f, g, h; - var len = bytes.length(); - while (len >= 64) { - // the w array will be populated with sixteen 32-bit big-endian words - // and then extended into 64 32-bit words according to SHA-256 - for (i = 0; i < 16; ++i) { - w[i] = bytes.getInt32(); - } - for (; i < 64; ++i) { - // XOR word 2 words ago rot right 17, rot right 19, shft right 10 - t1 = w[i - 2]; - t1 = - ((t1 >>> 17) | (t1 << 15)) ^ - ((t1 >>> 19) | (t1 << 13)) ^ - (t1 >>> 10); - // XOR word 15 words ago rot right 7, rot right 18, shft right 3 - t2 = w[i - 15]; - t2 = - ((t2 >>> 7) | (t2 << 25)) ^ - ((t2 >>> 18) | (t2 << 14)) ^ - (t2 >>> 3); - // sum(t1, word 7 ago, t2, word 16 ago) modulo 2^32 - w[i] = (t1 + w[i - 7] + t2 + w[i - 16]) & 0xFFFFFFFF; - } - - // initialize hash value for this chunk - a = s.h0; - b = s.h1; - c = s.h2; - d = s.h3; - e = s.h4; - f = s.h5; - g = s.h6; - h = s.h7; - - // round function - for (i = 0; i < 64; ++i) { - // Sum1(e) - s1 = - ((e >>> 6) | (e << 26)) ^ - ((e >>> 11) | (e << 21)) ^ - ((e >>> 25) | (e << 7)); - // Ch(e, f, g) (optimized the same way as SHA-1) - ch = g ^ (e & (f ^ g)); - // Sum0(a) - s0 = - ((a >>> 2) | (a << 30)) ^ - ((a >>> 13) | (a << 19)) ^ - ((a >>> 22) | (a << 10)); - // Maj(a, b, c) (optimized the same way as SHA-1) - maj = (a & b) | (c & (a ^ b)); - - // main algorithm - t1 = h + s1 + ch + _k[i] + w[i]; - t2 = s0 + maj; - h = g; - g = f; - f = e; - e = (d + t1) & 0xFFFFFFFF; - d = c; - c = b; - b = a; - a = (t1 + t2) & 0xFFFFFFFF; - } - - // update hash state - s.h0 = (s.h0 + a) & 0xFFFFFFFF; - s.h1 = (s.h1 + b) & 0xFFFFFFFF; - s.h2 = (s.h2 + c) & 0xFFFFFFFF; - s.h3 = (s.h3 + d) & 0xFFFFFFFF; - s.h4 = (s.h4 + e) & 0xFFFFFFFF; - s.h5 = (s.h5 + f) & 0xFFFFFFFF; - s.h6 = (s.h6 + g) & 0xFFFFFFFF; - s.h7 = (s.h7 + h) & 0xFFFFFFFF; - len -= 64; - } -}; - -/** - * Creates a SHA-256 message digest object. - * - * @return a message digest object. - */ -sha256.create = function() { - // do initialization as necessary - if (!_initialized) { - _init(); - } - - // SHA-256 state contains eight 32-bit integers - var _state = null; - - // input buffer - var _input = util.createBuffer(); - - // used for word storage - var _w = new Array(64); - - // message digest object - var md = { - algorithm: 'sha256', - blockLength: 64, - digestLength: 32, - // length of message so far (does not including padding) - messageLength: 0 - }; - - /** - * Starts the digest. - * - * @return this digest object. - */ - md.start = function() { - md.messageLength = 0; - _input = util.createBuffer(); - _state = { - h0: 0x6A09E667, - h1: 0xBB67AE85, - h2: 0x3C6EF372, - h3: 0xA54FF53A, - h4: 0x510E527F, - h5: 0x9B05688C, - h6: 0x1F83D9AB, - h7: 0x5BE0CD19 - }; - return md; - }; - // start digest automatically for first time - md.start(); - - /** - * Updates the digest with the given message input. The given input can - * treated as raw input (no encoding will be applied) or an encoding of - * 'utf8' maybe given to encode the input using UTF-8. - * - * @param msg the message input to update with. - * @param encoding the encoding to use (default: 'raw', other: 'utf8'). - * - * @return this digest object. - */ - md.update = function(msg, encoding) { - if (encoding === 'utf8') { - msg = util.encodeUtf8(msg); - } - - // update message length - md.messageLength += msg.length; - - // add bytes to input buffer - _input.putBytes(msg); - - // process bytes - _update(_state, _w, _input); - - // compact input buffer every 2K or if empty - if (_input.read > 2048 || _input.length() === 0) { - _input.compact(); - } - - return md; - }; - - /** - * Produces the digest. - * - * @return a byte buffer containing the digest value. - */ - md.digest = function() { - /* Note: Here we copy the remaining bytes in the input buffer and - add the appropriate SHA-256 padding. Then we do the final update - on a copy of the state so that if the user wants to get - intermediate digests they can do so. */ - - /* Determine the number of bytes that must be added to the message - to ensure its length is congruent to 448 mod 512. In other words, - a 64-bit integer that gives the length of the message will be - appended to the message and whatever the length of the message is - plus 64 bits must be a multiple of 512. So the length of the - message must be congruent to 448 mod 512 because 512 - 64 = 448. - - In order to fill up the message length it must be filled with - padding that begins with 1 bit followed by all 0 bits. Padding - must *always* be present, so if the message length is already - congruent to 448 mod 512, then 512 padding bits must be added. */ - - // 512 bits == 64 bytes, 448 bits == 56 bytes, 64 bits = 8 bytes - // _padding starts with 1 byte with first bit is set in it which - // is byte value 128, then there may be up to 63 other pad bytes - var len = md.messageLength; - var padBytes = util.createBuffer(); - padBytes.putBytes(_input.bytes()); - padBytes.putBytes(_padding.substr(0, 64 - ((len + 8) % 64))); - - /* Now append length of the message. The length is appended in bits - as a 64-bit number in big-endian order. Since we store the length - in bytes, we must multiply it by 8 (or left shift by 3). So here - store the high 3 bits in the low end of the first 32-bits of the - 64-bit number and the lower 5 bits in the high end of the second - 32-bits. */ - padBytes.putInt32((len >>> 29) & 0xFF); - padBytes.putInt32((len << 3) & 0xFFFFFFFF); - var s2 = { - h0: _state.h0, - h1: _state.h1, - h2: _state.h2, - h3: _state.h3, - h4: _state.h4, - h5: _state.h5, - h6: _state.h6, - h7: _state.h7 - }; - _update(s2, _w, padBytes); - var rval = util.createBuffer(); - rval.putInt32(s2.h0); - rval.putInt32(s2.h1); - rval.putInt32(s2.h2); - rval.putInt32(s2.h3); - rval.putInt32(s2.h4); - rval.putInt32(s2.h5); - rval.putInt32(s2.h6); - rval.putInt32(s2.h7); - return rval; - }; - - return md; -}; -},{"./forge_util.js":27}],27:[function(require,module,exports){ -/** - * Utility functions for web applications. - * - * @author Dave Longley - * - * Copyright (c) 2010-2012 Digital Bazaar, Inc. - */ - -/* Utilities API */ -var util = module.exports = {}; - -// define isArray -util.isArray = Array.isArray || function(x) { - return Object.prototype.toString.call(x) === '[object Array]'; -}; - -// define isArrayBuffer -util.isArrayBuffer = function(x) { - return typeof ArrayBuffer !== 'undefined' && x instanceof ArrayBuffer; -}; - -// define isArrayBufferView -var _arrayBufferViews = []; -if(typeof Int8Array !== 'undefined') { - _arrayBufferViews.push(Int8Array); -} -if(typeof Uint8Array !== 'undefined') { - _arrayBufferViews.push(Uint8Array); -} -if(typeof Uint8ClampedArray !== 'undefined') { - _arrayBufferViews.push(Uint8ClampedArray); -} -if(typeof Int16Array !== 'undefined') { - _arrayBufferViews.push(Int16Array); -} -if(typeof Uint16Array !== 'undefined') { - _arrayBufferViews.push(Uint16Array); -} -if(typeof Int32Array !== 'undefined') { - _arrayBufferViews.push(Int32Array); -} -if(typeof Uint32Array !== 'undefined') { - _arrayBufferViews.push(Uint32Array); -} -if(typeof Float32Array !== 'undefined') { - _arrayBufferViews.push(Float32Array); -} -if(typeof Float64Array !== 'undefined') { - _arrayBufferViews.push(Float64Array); -} -util.isArrayBufferView = function(x) { - for(var i = 0; i < _arrayBufferViews.length; ++i) { - if(x instanceof _arrayBufferViews[i]) { - return true; - } - } - return false; -}; - -/** - * Constructor for a byte buffer. - * - * @param [b] the bytes to wrap (either encoded as string, one byte per - * character, or as an ArrayBuffer or Typed Array). - */ -util.ByteBuffer = function(b) { - // the data in this buffer - this.data = ''; - // the pointer for reading from this buffer - this.read = 0; - - if(typeof b === 'string') { - this.data = b; - } - else if(util.isArrayBuffer(b) || util.isArrayBufferView(b)) { - // convert native buffer to forge buffer - // FIXME: support native buffers internally instead - var arr = new Uint8Array(b); - try { - this.data = String.fromCharCode.apply(null, arr); - } - catch(e) { - for(var i = 0; i < arr.length; ++i) { - this.putByte(arr[i]); - } - } - } -}; - -/** - * Gets the number of bytes in this buffer. - * - * @return the number of bytes in this buffer. - */ -util.ByteBuffer.prototype.length = function() { - return this.data.length - this.read; -}; - -/** - * Gets whether or not this buffer is empty. - * - * @return true if this buffer is empty, false if not. - */ -util.ByteBuffer.prototype.isEmpty = function() { - return this.length() <= 0; -}; - -/** - * Puts a byte in this buffer. - * - * @param b the byte to put. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putByte = function(b) { - this.data += String.fromCharCode(b); - return this; -}; - -/** - * Puts a byte in this buffer N times. - * - * @param b the byte to put. - * @param n the number of bytes of value b to put. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.fillWithByte = function(b, n) { - b = String.fromCharCode(b); - var d = this.data; - while(n > 0) { - if(n & 1) { - d += b; - } - n >>>= 1; - if(n > 0) { - b += b; - } - } - this.data = d; - return this; -}; - -/** - * Puts bytes in this buffer. - * - * @param bytes the bytes (as a UTF-8 encoded string) to put. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putBytes = function(bytes) { - this.data += bytes; - return this; -}; - -/** - * Puts a UTF-16 encoded string into this buffer. - * - * @param str the string to put. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putString = function(str) { - this.data += util.encodeUtf8(str); - return this; -}; - -/** - * Puts a 16-bit integer in this buffer in big-endian order. - * - * @param i the 16-bit integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putInt16 = function(i) { - this.data += - String.fromCharCode(i >> 8 & 0xFF) + - String.fromCharCode(i & 0xFF); - return this; -}; - -/** - * Puts a 24-bit integer in this buffer in big-endian order. - * - * @param i the 24-bit integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putInt24 = function(i) { - this.data += - String.fromCharCode(i >> 16 & 0xFF) + - String.fromCharCode(i >> 8 & 0xFF) + - String.fromCharCode(i & 0xFF); - return this; -}; - -/** - * Puts a 32-bit integer in this buffer in big-endian order. - * - * @param i the 32-bit integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putInt32 = function(i) { - this.data += - String.fromCharCode(i >> 24 & 0xFF) + - String.fromCharCode(i >> 16 & 0xFF) + - String.fromCharCode(i >> 8 & 0xFF) + - String.fromCharCode(i & 0xFF); - return this; -}; - -/** - * Puts a 16-bit integer in this buffer in little-endian order. - * - * @param i the 16-bit integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putInt16Le = function(i) { - this.data += - String.fromCharCode(i & 0xFF) + - String.fromCharCode(i >> 8 & 0xFF); - return this; -}; - -/** - * Puts a 24-bit integer in this buffer in little-endian order. - * - * @param i the 24-bit integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putInt24Le = function(i) { - this.data += - String.fromCharCode(i & 0xFF) + - String.fromCharCode(i >> 8 & 0xFF) + - String.fromCharCode(i >> 16 & 0xFF); - return this; -}; - -/** - * Puts a 32-bit integer in this buffer in little-endian order. - * - * @param i the 32-bit integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putInt32Le = function(i) { - this.data += - String.fromCharCode(i & 0xFF) + - String.fromCharCode(i >> 8 & 0xFF) + - String.fromCharCode(i >> 16 & 0xFF) + - String.fromCharCode(i >> 24 & 0xFF); - return this; -}; - -/** - * Puts an n-bit integer in this buffer in big-endian order. - * - * @param i the n-bit integer. - * @param n the number of bits in the integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putInt = function(i, n) { - do { - n -= 8; - this.data += String.fromCharCode((i >> n) & 0xFF); - } - while(n > 0); - return this; -}; - -/** - * Puts a signed n-bit integer in this buffer in big-endian order. Two's - * complement representation is used. - * - * @param i the n-bit integer. - * @param n the number of bits in the integer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putSignedInt = function(i, n) { - if(i < 0) { - i += 2 << (n - 1); - } - return this.putInt(i, n); -}; - -/** - * Puts the given buffer into this buffer. - * - * @param buffer the buffer to put into this one. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.putBuffer = function(buffer) { - this.data += buffer.getBytes(); - return this; -}; - -/** - * Gets a byte from this buffer and advances the read pointer by 1. - * - * @return the byte. - */ -util.ByteBuffer.prototype.getByte = function() { - return this.data.charCodeAt(this.read++); -}; - -/** - * Gets a uint16 from this buffer in big-endian order and advances the read - * pointer by 2. - * - * @return the uint16. - */ -util.ByteBuffer.prototype.getInt16 = function() { - var rval = ( - this.data.charCodeAt(this.read) << 8 ^ - this.data.charCodeAt(this.read + 1)); - this.read += 2; - return rval; -}; - -/** - * Gets a uint24 from this buffer in big-endian order and advances the read - * pointer by 3. - * - * @return the uint24. - */ -util.ByteBuffer.prototype.getInt24 = function() { - var rval = ( - this.data.charCodeAt(this.read) << 16 ^ - this.data.charCodeAt(this.read + 1) << 8 ^ - this.data.charCodeAt(this.read + 2)); - this.read += 3; - return rval; -}; - -/** - * Gets a uint32 from this buffer in big-endian order and advances the read - * pointer by 4. - * - * @return the word. - */ -util.ByteBuffer.prototype.getInt32 = function() { - var rval = ( - this.data.charCodeAt(this.read) << 24 ^ - this.data.charCodeAt(this.read + 1) << 16 ^ - this.data.charCodeAt(this.read + 2) << 8 ^ - this.data.charCodeAt(this.read + 3)); - this.read += 4; - return rval; -}; - -/** - * Gets a uint16 from this buffer in little-endian order and advances the read - * pointer by 2. - * - * @return the uint16. - */ -util.ByteBuffer.prototype.getInt16Le = function() { - var rval = ( - this.data.charCodeAt(this.read) ^ - this.data.charCodeAt(this.read + 1) << 8); - this.read += 2; - return rval; -}; - -/** - * Gets a uint24 from this buffer in little-endian order and advances the read - * pointer by 3. - * - * @return the uint24. - */ -util.ByteBuffer.prototype.getInt24Le = function() { - var rval = ( - this.data.charCodeAt(this.read) ^ - this.data.charCodeAt(this.read + 1) << 8 ^ - this.data.charCodeAt(this.read + 2) << 16); - this.read += 3; - return rval; -}; - -/** - * Gets a uint32 from this buffer in little-endian order and advances the read - * pointer by 4. - * - * @return the word. - */ -util.ByteBuffer.prototype.getInt32Le = function() { - var rval = ( - this.data.charCodeAt(this.read) ^ - this.data.charCodeAt(this.read + 1) << 8 ^ - this.data.charCodeAt(this.read + 2) << 16 ^ - this.data.charCodeAt(this.read + 3) << 24); - this.read += 4; - return rval; -}; - -/** - * Gets an n-bit integer from this buffer in big-endian order and advances the - * read pointer by n/8. - * - * @param n the number of bits in the integer. - * - * @return the integer. - */ -util.ByteBuffer.prototype.getInt = function(n) { - var rval = 0; - do { - rval = (rval << 8) + this.data.charCodeAt(this.read++); - n -= 8; - } - while(n > 0); - return rval; -}; - -/** - * Gets a signed n-bit integer from this buffer in big-endian order, using - * two's complement, and advances the read pointer by n/8. - * - * @param n the number of bits in the integer. - * - * @return the integer. - */ -util.ByteBuffer.prototype.getSignedInt = function(n) { - var x = this.getInt(n); - var max = 2 << (n - 2); - if(x >= max) { - x -= max << 1; - } - return x; -}; - -/** - * Reads bytes out into a UTF-8 string and clears them from the buffer. - * - * @param count the number of bytes to read, undefined or null for all. - * - * @return a UTF-8 string of bytes. - */ -util.ByteBuffer.prototype.getBytes = function(count) { - var rval; - if(count) { - // read count bytes - count = Math.min(this.length(), count); - rval = this.data.slice(this.read, this.read + count); - this.read += count; - } - else if(count === 0) { - rval = ''; - } - else { - // read all bytes, optimize to only copy when needed - rval = (this.read === 0) ? this.data : this.data.slice(this.read); - this.clear(); - } - return rval; -}; - -/** - * Gets a UTF-8 encoded string of the bytes from this buffer without modifying - * the read pointer. - * - * @param count the number of bytes to get, omit to get all. - * - * @return a string full of UTF-8 encoded characters. - */ -util.ByteBuffer.prototype.bytes = function(count) { - return (typeof(count) === 'undefined' ? - this.data.slice(this.read) : - this.data.slice(this.read, this.read + count)); -}; - -/** - * Gets a byte at the given index without modifying the read pointer. - * - * @param i the byte index. - * - * @return the byte. - */ -util.ByteBuffer.prototype.at = function(i) { - return this.data.charCodeAt(this.read + i); -}; - -/** - * Puts a byte at the given index without modifying the read pointer. - * - * @param i the byte index. - * @param b the byte to put. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.setAt = function(i, b) { - this.data = this.data.substr(0, this.read + i) + - String.fromCharCode(b) + - this.data.substr(this.read + i + 1); - return this; -}; - -/** - * Gets the last byte without modifying the read pointer. - * - * @return the last byte. - */ -util.ByteBuffer.prototype.last = function() { - return this.data.charCodeAt(this.data.length - 1); -}; - -/** - * Creates a copy of this buffer. - * - * @return the copy. - */ -util.ByteBuffer.prototype.copy = function() { - var c = util.createBuffer(this.data); - c.read = this.read; - return c; -}; - -/** - * Compacts this buffer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.compact = function() { - if(this.read > 0) { - this.data = this.data.slice(this.read); - this.read = 0; - } - return this; -}; - -/** - * Clears this buffer. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.clear = function() { - this.data = ''; - this.read = 0; - return this; -}; - -/** - * Shortens this buffer by triming bytes off of the end of this buffer. - * - * @param count the number of bytes to trim off. - * - * @return this buffer. - */ -util.ByteBuffer.prototype.truncate = function(count) { - var len = Math.max(0, this.length() - count); - this.data = this.data.substr(this.read, len); - this.read = 0; - return this; -}; - -/** - * Converts this buffer to a hexadecimal string. - * - * @return a hexadecimal string. - */ -util.ByteBuffer.prototype.toHex = function() { - var rval = ''; - for(var i = this.read; i < this.data.length; ++i) { - var b = this.data.charCodeAt(i); - if(b < 16) { - rval += '0'; - } - rval += b.toString(16); - } - return rval; -}; - -/** - * Converts this buffer to a UTF-16 string (standard JavaScript string). - * - * @return a UTF-16 string. - */ -util.ByteBuffer.prototype.toString = function() { - return util.decodeUtf8(this.bytes()); -}; - -/** - * Creates a buffer that stores bytes. A value may be given to put into the - * buffer that is either a string of bytes or a UTF-16 string that will - * be encoded using UTF-8 (to do the latter, specify 'utf8' as the encoding). - * - * @param [input] the bytes to wrap (as a string) or a UTF-16 string to encode - * as UTF-8. - * @param [encoding] (default: 'raw', other: 'utf8'). - */ -util.createBuffer = function(input, encoding) { - encoding = encoding || 'raw'; - if(input !== undefined && encoding === 'utf8') { - input = util.encodeUtf8(input); - } - return new util.ByteBuffer(input); -}; - -/** - * Fills a string with a particular value. If you want the string to be a byte - * string, pass in String.fromCharCode(theByte). - * - * @param c the character to fill the string with, use String.fromCharCode - * to fill the string with a byte value. - * @param n the number of characters of value c to fill with. - * - * @return the filled string. - */ -util.fillString = function(c, n) { - var s = ''; - while(n > 0) { - if(n & 1) { - s += c; - } - n >>>= 1; - if(n > 0) { - c += c; - } - } - return s; -}; - -/** - * Performs a per byte XOR between two byte strings and returns the result as a - * string of bytes. - * - * @param s1 first string of bytes. - * @param s2 second string of bytes. - * @param n the number of bytes to XOR. - * - * @return the XOR'd result. - */ -util.xorBytes = function(s1, s2, n) { - var s3 = ''; - var b = ''; - var t = ''; - var i = 0; - var c = 0; - for(; n > 0; --n, ++i) { - b = s1.charCodeAt(i) ^ s2.charCodeAt(i); - if(c >= 10) { - s3 += t; - t = ''; - c = 0; - } - t += String.fromCharCode(b); - ++c; - } - s3 += t; - return s3; -}; - -/** - * Converts a hex string into a UTF-8 string of bytes. - * - * @param hex the hexadecimal string to convert. - * - * @return the string of bytes. - */ -util.hexToBytes = function(hex) { - var rval = ''; - var i = 0; - if(hex.length & 1 == 1) { - // odd number of characters, convert first character alone - i = 1; - rval += String.fromCharCode(parseInt(hex[0], 16)); - } - // convert 2 characters (1 byte) at a time - for(; i < hex.length; i += 2) { - rval += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); - } - return rval; -}; - -/** - * Converts a UTF-8 byte string into a string of hexadecimal characters. - * - * @param bytes the byte string to convert. - * - * @return the string of hexadecimal characters. - */ -util.bytesToHex = function(bytes) { - return util.createBuffer(bytes).toHex(); -}; - -/** - * Converts an 32-bit integer to 4-big-endian byte string. - * - * @param i the integer. - * - * @return the byte string. - */ -util.int32ToBytes = function(i) { - return ( - String.fromCharCode(i >> 24 & 0xFF) + - String.fromCharCode(i >> 16 & 0xFF) + - String.fromCharCode(i >> 8 & 0xFF) + - String.fromCharCode(i & 0xFF)); -}; - -// base64 characters, reverse mapping -var _base64 = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; -var _base64Idx = [ -/*43 -43 = 0*/ -/*'+', 1, 2, 3,'/' */ - 62, -1, -1, -1, 63, - -/*'0','1','2','3','4','5','6','7','8','9' */ - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - -/*15, 16, 17,'=', 19, 20, 21 */ - -1, -1, -1, 64, -1, -1, -1, - -/*65 - 43 = 22*/ -/*'A','B','C','D','E','F','G','H','I','J','K','L','M', */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - -/*'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' */ - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - -/*91 - 43 = 48 */ -/*48, 49, 50, 51, 52, 53 */ - -1, -1, -1, -1, -1, -1, - -/*97 - 43 = 54*/ -/*'a','b','c','d','e','f','g','h','i','j','k','l','m' */ - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, - -/*'n','o','p','q','r','s','t','u','v','w','x','y','z' */ - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 -]; - -/** - * Base64 encodes a UTF-8 string of bytes. - * - * @param input the UTF-8 string of bytes to encode. - * @param maxline the maximum number of encoded bytes per line to use, - * defaults to none. - * - * @return the base64-encoded output. - */ -util.encode64 = function(input, maxline) { - var line = ''; - var output = ''; - var chr1, chr2, chr3; - var i = 0; - while(i < input.length) { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - - // encode 4 character group - line += _base64.charAt(chr1 >> 2); - line += _base64.charAt(((chr1 & 3) << 4) | (chr2 >> 4)); - if(isNaN(chr2)) { - line += '=='; - } - else { - line += _base64.charAt(((chr2 & 15) << 2) | (chr3 >> 6)); - line += isNaN(chr3) ? '=' : _base64.charAt(chr3 & 63); - } - - if(maxline && line.length > maxline) { - output += line.substr(0, maxline) + '\r\n'; - line = line.substr(maxline); - } - } - output += line; - - return output; -}; - -/** - * Base64 decodes a string into a UTF-8 string of bytes. - * - * @param input the base64-encoded input. - * - * @return the raw bytes. - */ -util.decode64 = function(input) { - // remove all non-base64 characters - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ''); - - var output = ''; - var enc1, enc2, enc3, enc4; - var i = 0; - - while(i < input.length) { - enc1 = _base64Idx[input.charCodeAt(i++) - 43]; - enc2 = _base64Idx[input.charCodeAt(i++) - 43]; - enc3 = _base64Idx[input.charCodeAt(i++) - 43]; - enc4 = _base64Idx[input.charCodeAt(i++) - 43]; - - output += String.fromCharCode((enc1 << 2) | (enc2 >> 4)); - if(enc3 !== 64) { - // decoded at least 2 bytes - output += String.fromCharCode(((enc2 & 15) << 4) | (enc3 >> 2)); - if(enc4 !== 64) { - // decoded 3 bytes - output += String.fromCharCode(((enc3 & 3) << 6) | enc4); - } - } - } - - return output; -}; - -/** - * UTF-8 encodes the given UTF-16 encoded string (a standard JavaScript - * string). Non-ASCII characters will be encoded as multiple bytes according - * to UTF-8. - * - * @param str the string to encode. - * - * @return the UTF-8 encoded string. - */ -util.encodeUtf8 = function(str) { - return unescape(encodeURIComponent(str)); -}; - -/** - * Decodes a UTF-8 encoded string into a UTF-16 string. - * - * @param str the string to encode. - * - * @return the UTF-16 encoded string (standard JavaScript string). - */ -util.decodeUtf8 = function(str) { - return decodeURIComponent(escape(str)); -}; - -},{}],28:[function(require,module,exports){ +},{"../type/mpi.js":74,"./cipher":25,"./public_key":36,"./random.js":39}],28:[function(require,module,exports){ /** * @requires crypto/hash/sha + * @requires crypto/hash/md5 + * @requires crypto/hash/ripe-md + * @requires util * @module crypto/hash */ -var sha = require('./sha.js'), - forge_sha256 = require('./forge_sha256.js'); -module.exports = { - /** @see module:crypto/hash/md5 */ - md5: require('./md5.js'), - /** @see module:crypto/hash/sha.sha1 */ - sha1: sha.sha1, - /** @see module:crypto/hash/sha.sha224 */ - sha224: sha.sha224, - /** @see module:crypto/hash/sha.sha256 */ - sha256: sha.sha256, - /** @see module:crypto/hash/sha.sha384 */ - sha384: sha.sha384, - /** @see module:crypto/hash/sha.sha512 */ - sha512: sha.sha512, - /** @see module:crypto/hash/ripe-md */ - ripemd: require('./ripe-md.js'), +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _sha = require('./sha.js'); + +var _sha2 = _interopRequireDefault(_sha); + +var _asmcryptoLite = require('asmcrypto-lite'); + +var _asmcryptoLite2 = _interopRequireDefault(_asmcryptoLite); + +var _rusha = require('rusha'); + +var _rusha2 = _interopRequireDefault(_rusha); + +var _md = require('./md5.js'); + +var _md2 = _interopRequireDefault(_md); + +var _ripeMd = require('./ripe-md.js'); + +var _ripeMd2 = _interopRequireDefault(_ripeMd); + +var _util = require('../../util.js'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var rusha = new _rusha2.default(), + nodeCrypto = _util2.default.getNodeCrypto(), + Buffer = _util2.default.getNodeBuffer(); + +function node_hash(type) { + return function (data) { + var shasum = nodeCrypto.createHash(type); + shasum.update(new Buffer(data)); + return new Uint8Array(shasum.digest()); + }; +} + +var hash_fns; +if (nodeCrypto) { + // Use Node native crypto for all hash functions + + hash_fns = { + md5: node_hash('md5'), + sha1: node_hash('sha1'), + sha224: node_hash('sha224'), + sha256: node_hash('sha256'), + sha384: node_hash('sha384'), + sha512: node_hash('sha512'), + ripemd: node_hash('ripemd160') + }; +} else { + // Use JS fallbacks + + hash_fns = { + /** @see module:crypto/hash/md5 */ + md5: _md2.default, + /** @see module:rusha */ + sha1: function sha1(data) { + return _util2.default.str2Uint8Array(_util2.default.hex2bin(rusha.digest(data))); + }, + /** @see module:crypto/hash/sha.sha224 */ + sha224: _sha2.default.sha224, + /** @see module:asmcrypto */ + sha256: _asmcryptoLite2.default.SHA256.bytes, + /** @see module:crypto/hash/sha.sha384 */ + sha384: _sha2.default.sha384, + /** @see module:crypto/hash/sha.sha512 */ + sha512: _sha2.default.sha512, + /** @see module:crypto/hash/ripe-md */ + ripemd: _ripeMd2.default + }; +} + +exports.default = { + + md5: hash_fns.md5, + sha1: hash_fns.sha1, + sha224: hash_fns.sha224, + sha256: hash_fns.sha256, + sha384: hash_fns.sha384, + sha512: hash_fns.sha512, + ripemd: hash_fns.ripemd, /** * Create a hash on the specified data using the specified algorithm * @param {module:enums.hash} algo Hash algorithm type (see {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4}) - * @param {String} data Data to be hashed - * @return {String} hash value + * @param {Uint8Array} data Data to be hashed + * @return {Uint8Array} hash value */ - digest: function(algo, data) { + digest: function digest(algo, data) { switch (algo) { case 1: // - MD5 [HAC] @@ -5116,9 +6180,7 @@ module.exports = { return this.ripemd(data); case 8: // - SHA256 [FIPS180] - var sha256 = forge_sha256.create(); - sha256.update(data); - return sha256.digest().getBytes(); + return this.sha256(data); case 9: // - SHA384 [FIPS180] return this.sha384(data); @@ -5138,13 +6200,13 @@ module.exports = { * @param {module:enums.hash} algo Hash algorithm type (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4}) * @return {Integer} Size in bytes of the resulting hash */ - getHashByteLength: function(algo) { + getHashByteLength: function getHashByteLength(algo) { switch (algo) { case 1: // - MD5 [HAC] return 16; case 2: - // - SHA-1 [FIPS180] + // - SHA-1 [FIPS180] case 3: // - RIPE-MD/160 [HAC] return 20; @@ -5166,7 +6228,7 @@ module.exports = { } }; -},{"./forge_sha256.js":26,"./md5.js":29,"./ripe-md.js":30,"./sha.js":31}],29:[function(require,module,exports){ +},{"../../util.js":76,"./md5.js":29,"./ripe-md.js":30,"./sha.js":31,"asmcrypto-lite":1,"rusha":13}],29:[function(require,module,exports){ /** * A fast MD5 JavaScript implementation * Copyright (c) 2012 Joseph Myers @@ -5186,23 +6248,29 @@ module.exports = { * @module crypto/hash/md5 */ -var util = require('../../util.js'); +'use strict'; -/** - * MD5 hash - * @param {String} entree string to hash - */ -module.exports = function (entree) { - var hex = md5(entree); - var bin = util.hex2bin(hex); +Object.defineProperty(exports, "__esModule", { + value: true +}); + +exports.default = function (entree) { + var hex = md5(_util2.default.Uint8Array2str(entree)); + var bin = _util2.default.str2Uint8Array(_util2.default.hex2bin(hex)); return bin; }; +var _util = require('../../util.js'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function md5cycle(x, k) { var a = x[0], - b = x[1], - c = x[2], - d = x[3]; + b = x[1], + c = x[2], + d = x[3]; a = ff(a, b, c, d, k[0], 7, -680876936); d = ff(d, a, b, c, k[1], 12, -389564586); @@ -5276,20 +6344,25 @@ function md5cycle(x, k) { x[1] = add32(b, x[1]); x[2] = add32(c, x[2]); x[3] = add32(d, x[3]); - } +/** + * MD5 hash + * @param {String} entree string to hash + */ + + function cmn(q, a, b, x, s, t) { a = add32(add32(a, q), add32(x, t)); - return add32((a << s) | (a >>> (32 - s)), b); + return add32(a << s | a >>> 32 - s, b); } function ff(a, b, c, d, x, s, t) { - return cmn((b & c) | ((~b) & d), a, b, x, s, t); + return cmn(b & c | ~b & d, a, b, x, s, t); } function gg(a, b, c, d, x, s, t) { - return cmn((b & d) | (c & (~d)), a, b, x, s, t); + return cmn(b & d | c & ~d, a, b, x, s, t); } function hh(a, b, c, d, x, s, t) { @@ -5297,24 +6370,27 @@ function hh(a, b, c, d, x, s, t) { } function ii(a, b, c, d, x, s, t) { - return cmn(c ^ (b | (~d)), a, b, x, s, t); + return cmn(c ^ (b | ~d), a, b, x, s, t); } function md51(s) { var n = s.length, - state = [1732584193, -271733879, -1732584194, 271733878], - i; + state = [1732584193, -271733879, -1732584194, 271733878], + i; for (i = 64; i <= s.length; i += 64) { md5cycle(state, md5blk(s.substring(i - 64, i))); } s = s.substring(i - 64); var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - for (i = 0; i < s.length; i++) - tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3); - tail[i >> 2] |= 0x80 << ((i % 4) << 3); + for (i = 0; i < s.length; i++) { + tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3); + } + tail[i >> 2] |= 0x80 << (i % 4 << 3); if (i > 55) { md5cycle(state, tail); - for (i = 0; i < 16; i++) tail[i] = 0; + for (i = 0; i < 16; i++) { + tail[i] = 0; + } } tail[14] = n * 8; md5cycle(state, tail); @@ -5336,12 +6412,12 @@ function md51(s) { * providing access to strings as preformed UTF-8 * 8-bit unsigned value arrays. */ -function md5blk(s) { /* I figured global was faster. */ +function md5blk(s) { + /* I figured global was faster. */ var md5blks = [], - i; /* Andy King said do it this way. */ + i; /* Andy King said do it this way. */ for (i = 0; i < 64; i += 4) { - md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << - 24); + md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24); } return md5blks; } @@ -5350,15 +6426,17 @@ var hex_chr = '0123456789abcdef'.split(''); function rhex(n) { var s = '', - j = 0; - for (; j < 4; j++) - s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F]; + j = 0; + for (; j < 4; j++) { + s += hex_chr[n >> j * 8 + 4 & 0x0F] + hex_chr[n >> j * 8 & 0x0F]; + } return s; } function hex(x) { - for (var i = 0; i < x.length; i++) + for (var i = 0; i < x.length; i++) { x[i] = rhex(x[i]); + } return x.join(''); } @@ -5373,49 +6451,57 @@ need the idiotic second function, generated by an if clause. */ function add32(a, b) { - return (a + b) & 0xFFFFFFFF; -} - -if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') { - function add32(x, y) { - var lsw = (x & 0xFFFF) + (y & 0xFFFF), - msw = (x >> 16) + (y >> 16) + (lsw >> 16); - return (msw << 16) | (lsw & 0xFFFF); - } + return a + b & 0xFFFFFFFF; } },{"../../util.js":76}],30:[function(require,module,exports){ -/* - * CryptoMX Tools - * Copyright (C) 2004 - 2006 Derek Buitenhuis - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = RMDstring; + +var _util = require("../../util.js"); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var RMDsize = 160; /* + * CryptoMX Tools + * Copyright (C) 2004 - 2006 Derek Buitenhuis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ /* Modified by Recurity Labs GmbH */ +/* Modified by ProtonTech AG + */ + /** + * @requires util * @module crypto/hash/ripe-md */ -var RMDsize = 160; var X = []; function ROL(x, n) { - return new Number((x << n) | (x >>> (32 - n))); + return new Number(x << n | x >>> 32 - n); } function F(x, y, z) { @@ -5423,7 +6509,7 @@ function F(x, y, z) { } function G(x, y, z) { - return new Number((x & y) | (~x & z)); + return new Number(x & y | ~x & z); } function H(x, y, z) { @@ -5431,7 +6517,7 @@ function H(x, y, z) { } function I(x, y, z) { - return new Number((x & z) | (y & ~z)); + return new Number(x & z | y & ~z); } function J(x, y, z) { @@ -5505,31 +6591,9 @@ function MDinit(MDbuf) { MDbuf[4] = 0xc3d2e1f0; } -var ROLs = [ - [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8], - [7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12], - [11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5], - [11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12], - [9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6], - [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6], - [9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11], - [9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5], - [15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8], - [8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11] -]; +var ROLs = [[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8], [7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12], [11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5], [11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12], [9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6], [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6], [9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11], [9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5], [15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8], [8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]]; -var indexes = [ - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - [7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8], - [3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12], - [1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2], - [4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13], - [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12], - [6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2], - [15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13], - [8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14], - [12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11] -]; +var indexes = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8], [3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12], [1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2], [4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13], [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12], [6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2], [15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13], [8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14], [12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]]; function compress(MDbuf, X) { var blockA = []; @@ -5547,15 +6611,7 @@ function compress(MDbuf, X) { var step = 0; for (j = 0; j < 5; j++) { for (i = 0; i < 16; i++) { - retBlock = mixOneRound( - blockA[(step + 0) % 5], - blockA[(step + 1) % 5], - blockA[(step + 2) % 5], - blockA[(step + 3) % 5], - blockA[(step + 4) % 5], - X[indexes[j][i]], - ROLs[j][i], - j); + retBlock = mixOneRound(blockA[(step + 0) % 5], blockA[(step + 1) % 5], blockA[(step + 2) % 5], blockA[(step + 3) % 5], blockA[(step + 4) % 5], X[indexes[j][i]], ROLs[j][i], j); blockA[(step + 0) % 5] = retBlock[0]; blockA[(step + 1) % 5] = retBlock[1]; @@ -5570,15 +6626,7 @@ function compress(MDbuf, X) { step = 0; for (j = 5; j < 10; j++) { for (i = 0; i < 16; i++) { - retBlock = mixOneRound( - blockB[(step + 0) % 5], - blockB[(step + 1) % 5], - blockB[(step + 2) % 5], - blockB[(step + 3) % 5], - blockB[(step + 4) % 5], - X[indexes[j][i]], - ROLs[j][i], - j); + retBlock = mixOneRound(blockB[(step + 0) % 5], blockB[(step + 1) % 5], blockB[(step + 2) % 5], blockB[(step + 3) % 5], blockB[(step + 4) % 5], X[indexes[j][i]], ROLs[j][i], j); blockB[(step + 0) % 5] = retBlock[0]; blockB[(step + 1) % 5] = retBlock[1]; @@ -5610,10 +6658,10 @@ function MDfinish(MDbuf, strptr, lswlen, mswlen) { var j = 0; for (var i = 0; i < (lswlen & 63); i++) { - X[i >>> 2] ^= (strptr.charCodeAt(j++) & 255) << (8 * (i & 3)); + X[i >>> 2] ^= (strptr.charCodeAt(j++) & 255) << 8 * (i & 3); } - X[(lswlen >>> 2) & 15] ^= 1 << (8 * (lswlen & 3) + 7); + X[lswlen >>> 2 & 15] ^= 1 << 8 * (lswlen & 3) + 7; if ((lswlen & 63) > 55) { compress(MDbuf, X); @@ -5622,7 +6670,7 @@ function MDfinish(MDbuf, strptr, lswlen, mswlen) { } X[14] = lswlen << 3; - X[15] = (lswlen >>> 29) | (mswlen << 3); + X[15] = lswlen >>> 29 | mswlen << 3; compress(MDbuf, X); } @@ -5631,7 +6679,7 @@ function BYTES_TO_DWORD(fourChars) { var tmp = (fourChars.charCodeAt(3) & 255) << 24; tmp |= (fourChars.charCodeAt(2) & 255) << 16; tmp |= (fourChars.charCodeAt(1) & 255) << 8; - tmp |= (fourChars.charCodeAt(0) & 255); + tmp |= fourChars.charCodeAt(0) & 255; return tmp; } @@ -5648,7 +6696,8 @@ function RMD(message) { var X = new Array(16); zeroX(X); - var i, j = 0; + var i, + j = 0; for (nbytes = length; nbytes > 63; nbytes -= 64) { for (i = 0; i < 16; i++) { X[i] = BYTES_TO_DWORD(message.substr(j, 4)); @@ -5661,1152 +6710,1356 @@ function RMD(message) { for (i = 0; i < RMDsize / 8; i += 4) { hashcode[i] = MDbuf[i >>> 2] & 255; - hashcode[i + 1] = (MDbuf[i >>> 2] >>> 8) & 255; - hashcode[i + 2] = (MDbuf[i >>> 2] >>> 16) & 255; - hashcode[i + 3] = (MDbuf[i >>> 2] >>> 24) & 255; + hashcode[i + 1] = MDbuf[i >>> 2] >>> 8 & 255; + hashcode[i + 2] = MDbuf[i >>> 2] >>> 16 & 255; + hashcode[i + 3] = MDbuf[i >>> 2] >>> 24 & 255; } return hashcode; } - function RMDstring(message) { - var hashcode = RMD(message); + var hashcode = RMD(_util2.default.Uint8Array2str(message)); var retString = ""; for (var i = 0; i < RMDsize / 8; i++) { retString += String.fromCharCode(hashcode[i]); } - return retString; + return _util2.default.str2Uint8Array(retString); } -module.exports = RMDstring; - -},{}],31:[function(require,module,exports){ -/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS - * PUB 180-2 as well as the corresponding HMAC implementation as defined in - * FIPS PUB 198a +},{"../../util.js":76}],31:[function(require,module,exports){ +/** + * @preserve A JavaScript implementation of the SHA family of hashes, as + * defined in FIPS PUB 180-2 as well as the corresponding HMAC implementation + * as defined in FIPS PUB 198a * - * Version 1.3 Copyright Brian Turek 2008-2010 + * Copyright Brian Turek 2008-2015 * Distributed under the BSD License - * See http://jssha.sourceforge.net/ for more information + * See http://caligatio.github.com/jsSHA/ for more information * - * Several functions taken from Paul Johnson - */ - -/* Modified by Recurity Labs GmbH - * - * This code has been slightly modified direct string output: - * - bin2bstr has been added - * - following wrappers of this library have been added: - * - str_sha1 - * - str_sha256 - * - str_sha224 - * - str_sha384 - * - str_sha512 + * Several functions taken from Paul Johnston */ /** - * @module crypto/hash/sha + * SUPPORTED_ALGS is the stub for a compile flag that will cause pruning of + * functions that are not needed when a limited number of SHA families are + * selected + * + * @define {number} ORed value of SHA variants to be supported + * 1 = SHA-1, 2 = SHA-224/SHA-256, 4 = SHA-384/SHA-512 */ -var jsSHA = (function() { +"use strict"; - /* - * Configurable variables. Defaults typically work +Object.defineProperty(exports, "__esModule", { + value: true +}); +var SUPPORTED_ALGS = 4 | 2 | 1; + +/** + * Int_64 is a object for 2 32-bit numbers emulating a 64-bit number + * + * @private + * @constructor + * @this {Int_64} + * @param {number} msint_32 The most significant 32-bits of a 64-bit number + * @param {number} lsint_32 The least significant 32-bits of a 64-bit number + */ +function Int_64(msint_32, lsint_32) { + this.highOrder = msint_32; + this.lowOrder = lsint_32; +} + +/** + * Convert a string to an array of big-endian words + * + * @private + * @param {string} str String to be converted to binary representation + * @param {string} utfType The Unicode type, UTF8 or UTF16BE, UTF16LE, to + * use to encode the source string + * @return {{value : Array., binLen : number}} Hash list where + * "value" contains the output number array and "binLen" is the binary + * length of "value" + */ +function str2binb(str, utfType) { + var bin = [], + codePnt, + binArr = [], + byteCnt = 0, + i, + j, + offset; + + if ("UTF8" === utfType) { + for (i = 0; i < str.length; i += 1) { + codePnt = str.charCodeAt(i); + binArr = []; + + if (0x80 > codePnt) { + binArr.push(codePnt); + } else if (0x800 > codePnt) { + binArr.push(0xC0 | codePnt >>> 6); + binArr.push(0x80 | codePnt & 0x3F); + } else if (0xd800 > codePnt || 0xe000 <= codePnt) { + binArr.push(0xe0 | codePnt >>> 12, 0x80 | codePnt >>> 6 & 0x3f, 0x80 | codePnt & 0x3f); + } else { + i += 1; + codePnt = 0x10000 + ((codePnt & 0x3ff) << 10 | str.charCodeAt(i) & 0x3ff); + binArr.push(0xf0 | codePnt >>> 18, 0x80 | codePnt >>> 12 & 0x3f, 0x80 | codePnt >>> 6 & 0x3f, 0x80 | codePnt & 0x3f); + } + + for (j = 0; j < binArr.length; j += 1) { + offset = byteCnt >>> 2; + while (bin.length <= offset) { + bin.push(0); + } + bin[offset] |= binArr[j] << 24 - 8 * (byteCnt % 4); + byteCnt += 1; + } + } + } else if ("UTF16BE" === utfType || "UTF16LE" === utfType) { + for (i = 0; i < str.length; i += 1) { + codePnt = str.charCodeAt(i); + /* Internally strings are UTF-16BE so only change if UTF-16LE */ + if ("UTF16LE" === utfType) { + j = codePnt & 0xFF; + codePnt = j << 8 | codePnt >> 8; + } + + offset = byteCnt >>> 2; + while (bin.length <= offset) { + bin.push(0); + } + bin[offset] |= codePnt << 16 - 8 * (byteCnt % 4); + byteCnt += 2; + } + } + return { "value": bin, "binLen": byteCnt * 8 }; +} + +/** + * Convert a hex string to an array of big-endian words + * + * @private + * @param {string} str String to be converted to binary representation + * @return {{value : Array., binLen : number}} Hash list where + * "value" contains the output number array and "binLen" is the binary + * length of "value" + */ +function hex2binb(str) { + var bin = [], + length = str.length, + i, + num, + offset; + + if (0 !== length % 2) { + throw "String of HEX type must be in byte increments"; + } + + for (i = 0; i < length; i += 2) { + num = parseInt(str.substr(i, 2), 16); + if (!isNaN(num)) { + offset = i >>> 3; + while (bin.length <= offset) { + bin.push(0); + } + bin[i >>> 3] |= num << 24 - 4 * (i % 8); + } else { + throw "String of HEX type contains invalid characters"; + } + } + + return { "value": bin, "binLen": length * 4 }; +} + +/** + * Convert a string of raw bytes to an array of big-endian words + * + * @private + * @param {string} str String of raw bytes to be converted to binary representation + * @return {{value : Array., binLen : number}} Hash list where + * "value" contains the output number array and "binLen" is the binary + * length of "value" + */ +function bytes2binb(str) { + var bin = [], + codePnt, + i, + offset; + + for (i = 0; i < str.length; i += 1) { + codePnt = str.charCodeAt(i); + + offset = i >>> 2; + if (bin.length <= offset) { + bin.push(0); + } + bin[offset] |= codePnt << 24 - 8 * (i % 4); + } + + return { "value": bin, "binLen": str.length * 8 }; +} + +/** + * Convert a Uint8Array of raw bytes to an array of big-endian 32-bit words + * + * @private + * @param {Uint8Array} str String of raw bytes to be converted to binary representation + * @return {{value : Array., binLen : number}} Hash list where + * "value" contains the output array and "binLen" is the binary + * length of "value" + */ +function typed2binb(array) { + + var bin = [], + octet, + i, + offset; + + for (i = 0; i < array.length; i += 1) { + octet = array[i]; + + offset = i >>> 2; + if (bin.length <= offset) { + bin.push(0); + } + bin[offset] |= octet << 24 - 8 * (i % 4); + } + + return { "value": bin, "binLen": array.length * 8 }; +} + +/** + * Convert a base-64 string to an array of big-endian words + * + * @private + * @param {string} str String to be converted to binary representation + * @return {{value : Array., binLen : number}} Hash list where + * "value" contains the output number array and "binLen" is the binary + * length of "value" + */ +function b642binb(str) { + var retVal = [], + byteCnt = 0, + index, + i, + j, + tmpInt, + strPart, + firstEqual, + offset, + b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + if (-1 === str.search(/^[a-zA-Z0-9=+\/]+$/)) { + throw "Invalid character in base-64 string"; + } + firstEqual = str.indexOf('='); + str = str.replace(/\=/g, ''); + if (-1 !== firstEqual && firstEqual < str.length) { + throw "Invalid '=' found in base-64 string"; + } + + for (i = 0; i < str.length; i += 4) { + strPart = str.substr(i, 4); + tmpInt = 0; + + for (j = 0; j < strPart.length; j += 1) { + index = b64Tab.indexOf(strPart[j]); + tmpInt |= index << 18 - 6 * j; + } + + for (j = 0; j < strPart.length - 1; j += 1) { + offset = byteCnt >>> 2; + while (retVal.length <= offset) { + retVal.push(0); + } + retVal[offset] |= (tmpInt >>> 16 - j * 8 & 0xFF) << 24 - 8 * (byteCnt % 4); + byteCnt += 1; + } + } + + return { "value": retVal, "binLen": byteCnt * 8 }; +} + +/** + * Convert an array of big-endian words to a hex string. + * + * @private + * @param {Array.} binarray Array of integers to be converted to + * hexidecimal representation + * @param {{outputUpper : boolean, b64Pad : string}} formatOpts Hash list + * containing validated output formatting options + * @return {string} Hexidecimal representation of the parameter in string + * form + */ +function binb2hex(binarray, formatOpts) { + var hex_tab = "0123456789abcdef", + str = "", + length = binarray.length * 4, + i, + srcByte; + + for (i = 0; i < length; i += 1) { + /* The below is more than a byte but it gets taken care of later */ + srcByte = binarray[i >>> 2] >>> (3 - i % 4) * 8; + str += hex_tab.charAt(srcByte >>> 4 & 0xF) + hex_tab.charAt(srcByte & 0xF); + } + + return formatOpts["outputUpper"] ? str.toUpperCase() : str; +} + +/** + * Convert an array of big-endian words to a base-64 string + * + * @private + * @param {Array.} binarray Array of integers to be converted to + * base-64 representation + * @param {{outputUpper : boolean, b64Pad : string}} formatOpts Hash list + * containing validated output formatting options + * @return {string} Base-64 encoded representation of the parameter in + * string form + */ +function binb2b64(binarray, formatOpts) { + var str = "", + length = binarray.length * 4, + i, + j, + triplet, + offset, + int1, + int2, + b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + for (i = 0; i < length; i += 3) { + offset = i + 1 >>> 2; + int1 = binarray.length <= offset ? 0 : binarray[offset]; + offset = i + 2 >>> 2; + int2 = binarray.length <= offset ? 0 : binarray[offset]; + triplet = (binarray[i >>> 2] >>> 8 * (3 - i % 4) & 0xFF) << 16 | (int1 >>> 8 * (3 - (i + 1) % 4) & 0xFF) << 8 | int2 >>> 8 * (3 - (i + 2) % 4) & 0xFF; + for (j = 0; j < 4; j += 1) { + if (i * 8 + j * 6 <= binarray.length * 32) { + str += b64Tab.charAt(triplet >>> 6 * (3 - j) & 0x3F); + } else { + str += formatOpts["b64Pad"]; + } + } + } + return str; +} + +/** + * Convert an array of big-endian words to raw bytes string + * + * @private + * @param {Array.} binarray Array of integers to be converted to + * a raw bytes string representation + * @param {!Object} formatOpts Unused Hash list + * @return {string} Raw bytes representation of the parameter in string + * form + */ +function binb2bytes(binarray, formatOpts) { + var str = "", + length = binarray.length * 4, + i, + srcByte; + + for (i = 0; i < length; i += 1) { + srcByte = binarray[i >>> 2] >>> (3 - i % 4) * 8 & 0xFF; + str += String.fromCharCode(srcByte); + } + + return str; +} + +/** + * Convert an array of big-endian words to raw bytes Uint8Array + * + * @private + * @param {Array.} binarray Array of integers to be converted to + * a raw bytes string representation + * @param {!Object} formatOpts Unused Hash list + * @return {Uint8Array} Raw bytes representation of the parameter + */ +function binb2typed(binarray, formatOpts) { + var length = binarray.length * 4; + var arr = new Uint8Array(length), + i; + + for (i = 0; i < length; i += 1) { + arr[i] = binarray[i >>> 2] >>> (3 - i % 4) * 8 & 0xFF; + } + + return arr; +} + +/** + * Validate hash list containing output formatting options, ensuring + * presence of every option or adding the default value + * + * @private + * @param {{outputUpper : boolean, b64Pad : string}|undefined} outputOpts + * Hash list of output formatting options + * @return {{outputUpper : boolean, b64Pad : string}} Validated hash list + * containing output formatting options + */ +function getOutputOpts(outputOpts) { + var retVal = { "outputUpper": false, "b64Pad": "=" }; + + try { + if (outputOpts.hasOwnProperty("outputUpper")) { + retVal["outputUpper"] = outputOpts["outputUpper"]; + } + + if (outputOpts.hasOwnProperty("b64Pad")) { + retVal["b64Pad"] = outputOpts["b64Pad"]; + } + } catch (ignore) {} + + if ("boolean" !== typeof retVal["outputUpper"]) { + throw "Invalid outputUpper formatting option"; + } + + if ("string" !== typeof retVal["b64Pad"]) { + throw "Invalid b64Pad formatting option"; + } + + return retVal; +} + +/** + * The 32-bit implementation of circular rotate left + * + * @private + * @param {number} x The 32-bit integer argument + * @param {number} n The number of bits to shift + * @return {number} The x shifted circularly by n bits + */ +function rotl_32(x, n) { + return x << n | x >>> 32 - n; +} + +/** + * The 32-bit implementation of circular rotate right + * + * @private + * @param {number} x The 32-bit integer argument + * @param {number} n The number of bits to shift + * @return {number} The x shifted circularly by n bits + */ +function rotr_32(x, n) { + return x >>> n | x << 32 - n; +} + +/** + * The 64-bit implementation of circular rotate right + * + * @private + * @param {Int_64} x The 64-bit integer argument + * @param {number} n The number of bits to shift + * @return {Int_64} The x shifted circularly by n bits + */ +function rotr_64(x, n) { + var retVal = null, + tmp = new Int_64(x.highOrder, x.lowOrder); + + if (32 >= n) { + retVal = new Int_64(tmp.highOrder >>> n | tmp.lowOrder << 32 - n & 0xFFFFFFFF, tmp.lowOrder >>> n | tmp.highOrder << 32 - n & 0xFFFFFFFF); + } else { + retVal = new Int_64(tmp.lowOrder >>> n - 32 | tmp.highOrder << 64 - n & 0xFFFFFFFF, tmp.highOrder >>> n - 32 | tmp.lowOrder << 64 - n & 0xFFFFFFFF); + } + + return retVal; +} + +/** + * The 32-bit implementation of shift right + * + * @private + * @param {number} x The 32-bit integer argument + * @param {number} n The number of bits to shift + * @return {number} The x shifted by n bits + */ +function shr_32(x, n) { + return x >>> n; +} + +/** + * The 64-bit implementation of shift right + * + * @private + * @param {Int_64} x The 64-bit integer argument + * @param {number} n The number of bits to shift + * @return {Int_64} The x shifted by n bits + */ +function shr_64(x, n) { + var retVal = null; + + if (32 >= n) { + retVal = new Int_64(x.highOrder >>> n, x.lowOrder >>> n | x.highOrder << 32 - n & 0xFFFFFFFF); + } else { + retVal = new Int_64(0, x.highOrder >>> n - 32); + } + + return retVal; +} + +/** + * The 32-bit implementation of the NIST specified Parity function + * + * @private + * @param {number} x The first 32-bit integer argument + * @param {number} y The second 32-bit integer argument + * @param {number} z The third 32-bit integer argument + * @return {number} The NIST specified output of the function + */ +function parity_32(x, y, z) { + return x ^ y ^ z; +} + +/** + * The 32-bit implementation of the NIST specified Ch function + * + * @private + * @param {number} x The first 32-bit integer argument + * @param {number} y The second 32-bit integer argument + * @param {number} z The third 32-bit integer argument + * @return {number} The NIST specified output of the function + */ +function ch_32(x, y, z) { + return x & y ^ ~x & z; +} + +/** + * The 64-bit implementation of the NIST specified Ch function + * + * @private + * @param {Int_64} x The first 64-bit integer argument + * @param {Int_64} y The second 64-bit integer argument + * @param {Int_64} z The third 64-bit integer argument + * @return {Int_64} The NIST specified output of the function + */ +function ch_64(x, y, z) { + return new Int_64(x.highOrder & y.highOrder ^ ~x.highOrder & z.highOrder, x.lowOrder & y.lowOrder ^ ~x.lowOrder & z.lowOrder); +} + +/** + * The 32-bit implementation of the NIST specified Maj function + * + * @private + * @param {number} x The first 32-bit integer argument + * @param {number} y The second 32-bit integer argument + * @param {number} z The third 32-bit integer argument + * @return {number} The NIST specified output of the function + */ +function maj_32(x, y, z) { + return x & y ^ x & z ^ y & z; +} + +/** + * The 64-bit implementation of the NIST specified Maj function + * + * @private + * @param {Int_64} x The first 64-bit integer argument + * @param {Int_64} y The second 64-bit integer argument + * @param {Int_64} z The third 64-bit integer argument + * @return {Int_64} The NIST specified output of the function + */ +function maj_64(x, y, z) { + return new Int_64(x.highOrder & y.highOrder ^ x.highOrder & z.highOrder ^ y.highOrder & z.highOrder, x.lowOrder & y.lowOrder ^ x.lowOrder & z.lowOrder ^ y.lowOrder & z.lowOrder); +} + +/** + * The 32-bit implementation of the NIST specified Sigma0 function + * + * @private + * @param {number} x The 32-bit integer argument + * @return {number} The NIST specified output of the function + */ +function sigma0_32(x) { + return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22); +} + +/** + * The 64-bit implementation of the NIST specified Sigma0 function + * + * @private + * @param {Int_64} x The 64-bit integer argument + * @return {Int_64} The NIST specified output of the function + */ +function sigma0_64(x) { + var rotr28 = rotr_64(x, 28), + rotr34 = rotr_64(x, 34), + rotr39 = rotr_64(x, 39); + + return new Int_64(rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder, rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder); +} + +/** + * The 32-bit implementation of the NIST specified Sigma1 function + * + * @private + * @param {number} x The 32-bit integer argument + * @return {number} The NIST specified output of the function + */ +function sigma1_32(x) { + return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25); +} + +/** + * The 64-bit implementation of the NIST specified Sigma1 function + * + * @private + * @param {Int_64} x The 64-bit integer argument + * @return {Int_64} The NIST specified output of the function + */ +function sigma1_64(x) { + var rotr14 = rotr_64(x, 14), + rotr18 = rotr_64(x, 18), + rotr41 = rotr_64(x, 41); + + return new Int_64(rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder, rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder); +} + +/** + * The 32-bit implementation of the NIST specified Gamma0 function + * + * @private + * @param {number} x The 32-bit integer argument + * @return {number} The NIST specified output of the function + */ +function gamma0_32(x) { + return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3); +} + +/** + * The 64-bit implementation of the NIST specified Gamma0 function + * + * @private + * @param {Int_64} x The 64-bit integer argument + * @return {Int_64} The NIST specified output of the function + */ +function gamma0_64(x) { + var rotr1 = rotr_64(x, 1), + rotr8 = rotr_64(x, 8), + shr7 = shr_64(x, 7); + + return new Int_64(rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder, rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder); +} + +/** + * The 32-bit implementation of the NIST specified Gamma1 function + * + * @private + * @param {number} x The 32-bit integer argument + * @return {number} The NIST specified output of the function + */ +function gamma1_32(x) { + return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10); +} + +/** + * The 64-bit implementation of the NIST specified Gamma1 function + * + * @private + * @param {Int_64} x The 64-bit integer argument + * @return {Int_64} The NIST specified output of the function + */ +function gamma1_64(x) { + var rotr19 = rotr_64(x, 19), + rotr61 = rotr_64(x, 61), + shr6 = shr_64(x, 6); + + return new Int_64(rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder, rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder); +} + +/** + * Add two 32-bit integers, wrapping at 2^32. This uses 16-bit operations + * internally to work around bugs in some JS interpreters. + * + * @private + * @param {number} a The first 32-bit integer argument to be added + * @param {number} b The second 32-bit integer argument to be added + * @return {number} The sum of a + b + */ +function safeAdd_32_2(a, b) { + var lsw = (a & 0xFFFF) + (b & 0xFFFF), + msw = (a >>> 16) + (b >>> 16) + (lsw >>> 16); + + return (msw & 0xFFFF) << 16 | lsw & 0xFFFF; +} + +/** + * Add four 32-bit integers, wrapping at 2^32. This uses 16-bit operations + * internally to work around bugs in some JS interpreters. + * + * @private + * @param {number} a The first 32-bit integer argument to be added + * @param {number} b The second 32-bit integer argument to be added + * @param {number} c The third 32-bit integer argument to be added + * @param {number} d The fourth 32-bit integer argument to be added + * @return {number} The sum of a + b + c + d + */ +function safeAdd_32_4(a, b, c, d) { + var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF), + msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (lsw >>> 16); + + return (msw & 0xFFFF) << 16 | lsw & 0xFFFF; +} + +/** + * Add five 32-bit integers, wrapping at 2^32. This uses 16-bit operations + * internally to work around bugs in some JS interpreters. + * + * @private + * @param {number} a The first 32-bit integer argument to be added + * @param {number} b The second 32-bit integer argument to be added + * @param {number} c The third 32-bit integer argument to be added + * @param {number} d The fourth 32-bit integer argument to be added + * @param {number} e The fifth 32-bit integer argument to be added + * @return {number} The sum of a + b + c + d + e + */ +function safeAdd_32_5(a, b, c, d, e) { + var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF) + (e & 0xFFFF), + msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (e >>> 16) + (lsw >>> 16); + + return (msw & 0xFFFF) << 16 | lsw & 0xFFFF; +} + +/** + * Add two 64-bit integers, wrapping at 2^64. This uses 16-bit operations + * internally to work around bugs in some JS interpreters. + * + * @private + * @param {Int_64} x The first 64-bit integer argument to be added + * @param {Int_64} y The second 64-bit integer argument to be added + * @return {Int_64} The sum of x + y + */ +function safeAdd_64_2(x, y) { + var lsw, msw, lowOrder, highOrder; + + lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF); + msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16); + lowOrder = (msw & 0xFFFF) << 16 | lsw & 0xFFFF; + + lsw = (x.highOrder & 0xFFFF) + (y.highOrder & 0xFFFF) + (msw >>> 16); + msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16); + highOrder = (msw & 0xFFFF) << 16 | lsw & 0xFFFF; + + return new Int_64(highOrder, lowOrder); +} + +/** + * Add four 64-bit integers, wrapping at 2^64. This uses 16-bit operations + * internally to work around bugs in some JS interpreters. + * + * @private + * @param {Int_64} a The first 64-bit integer argument to be added + * @param {Int_64} b The second 64-bit integer argument to be added + * @param {Int_64} c The third 64-bit integer argument to be added + * @param {Int_64} d The fouth 64-bit integer argument to be added + * @return {Int_64} The sum of a + b + c + d + */ +function safeAdd_64_4(a, b, c, d) { + var lsw, msw, lowOrder, highOrder; + + lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) + (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF); + msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (lsw >>> 16); + lowOrder = (msw & 0xFFFF) << 16 | lsw & 0xFFFF; + + lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) + (c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + (msw >>> 16); + msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + (c.highOrder >>> 16) + (d.highOrder >>> 16) + (lsw >>> 16); + highOrder = (msw & 0xFFFF) << 16 | lsw & 0xFFFF; + + return new Int_64(highOrder, lowOrder); +} + +/** + * Add five 64-bit integers, wrapping at 2^64. This uses 16-bit operations + * internally to work around bugs in some JS interpreters. + * + * @private + * @param {Int_64} a The first 64-bit integer argument to be added + * @param {Int_64} b The second 64-bit integer argument to be added + * @param {Int_64} c The third 64-bit integer argument to be added + * @param {Int_64} d The fouth 64-bit integer argument to be added + * @param {Int_64} e The fouth 64-bit integer argument to be added + * @return {Int_64} The sum of a + b + c + d + e + */ +function safeAdd_64_5(a, b, c, d, e) { + var lsw, msw, lowOrder, highOrder; + + lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) + (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF) + (e.lowOrder & 0xFFFF); + msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (e.lowOrder >>> 16) + (lsw >>> 16); + lowOrder = (msw & 0xFFFF) << 16 | lsw & 0xFFFF; + + lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) + (c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + (e.highOrder & 0xFFFF) + (msw >>> 16); + msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + (c.highOrder >>> 16) + (d.highOrder >>> 16) + (e.highOrder >>> 16) + (lsw >>> 16); + highOrder = (msw & 0xFFFF) << 16 | lsw & 0xFFFF; + + return new Int_64(highOrder, lowOrder); +} + +/** + * Calculates the SHA-1 hash of the string set at instantiation + * + * @private + * @param {Array.} message The binary array representation of the + * string to hash + * @param {number} messageLen The number of bits in the message + * @return {Array.} The array of integers representing the SHA-1 + * hash of message + */ +function coreSHA1(message, messageLen) { + var W = [], + a, + b, + c, + d, + e, + T, + ch = ch_32, + parity = parity_32, + maj = maj_32, + rotl = rotl_32, + safeAdd_2 = safeAdd_32_2, + i, + t, + safeAdd_5 = safeAdd_32_5, + appendedMessageLength, + offset, + H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]; + + offset = (messageLen + 65 >>> 9 << 4) + 15; + while (message.length <= offset) { + message.push(0); + } + /* Append '1' at the end of the binary string */ + message[messageLen >>> 5] |= 0x80 << 24 - messageLen % 32; + /* Append length of binary string in the position such that the new + length is a multiple of 512. Logic does not work for even multiples + of 512 but there can never be even multiples of 512 */ + message[offset] = messageLen; + + appendedMessageLength = message.length; + + for (i = 0; i < appendedMessageLength; i += 16) { + a = H[0]; + b = H[1]; + c = H[2]; + d = H[3]; + e = H[4]; + + for (t = 0; t < 80; t += 1) { + if (t < 16) { + W[t] = message[t + i]; + } else { + W[t] = rotl(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); + } + + if (t < 20) { + T = safeAdd_5(rotl(a, 5), ch(b, c, d), e, 0x5a827999, W[t]); + } else if (t < 40) { + T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, 0x6ed9eba1, W[t]); + } else if (t < 60) { + T = safeAdd_5(rotl(a, 5), maj(b, c, d), e, 0x8f1bbcdc, W[t]); + } else { + T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, 0xca62c1d6, W[t]); + } + + e = d; + d = c; + c = rotl(b, 30); + b = a; + a = T; + } + + H[0] = safeAdd_2(a, H[0]); + H[1] = safeAdd_2(b, H[1]); + H[2] = safeAdd_2(c, H[2]); + H[3] = safeAdd_2(d, H[3]); + H[4] = safeAdd_2(e, H[4]); + } + + return H; +} + +/** + * Calculates the desired SHA-2 hash of the string set at instantiation + * + * @private + * @param {Array.} message The binary array representation of the + * string to hash + * @param {number} messageLen The number of bits in message + * @param {string} variant The desired SHA-2 variant + * @return {Array.} The array of integers representing the SHA-2 + * hash of message + */ +function coreSHA2(message, messageLen, variant) { + var a, + b, + c, + d, + e, + f, + g, + h, + T1, + T2, + H, + numRounds, + lengthPosition, + i, + t, + binaryStringInc, + binaryStringMult, + safeAdd_2, + safeAdd_4, + safeAdd_5, + gamma0, + gamma1, + sigma0, + sigma1, + ch, + maj, + Int, + W = [], + int1, + int2, + offset, + appendedMessageLength, + retVal, + K = [0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2], + H_trunc = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4], + H_full = [0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19]; + + /* Set up the various function handles and variable for the specific + * variant */ + if ((variant === "SHA-224" || variant === "SHA-256") && 2 & SUPPORTED_ALGS) { + /* 32-bit variant */ + numRounds = 64; + lengthPosition = (messageLen + 65 >>> 9 << 4) + 15; + binaryStringInc = 16; + binaryStringMult = 1; + Int = Number; + safeAdd_2 = safeAdd_32_2; + safeAdd_4 = safeAdd_32_4; + safeAdd_5 = safeAdd_32_5; + gamma0 = gamma0_32; + gamma1 = gamma1_32; + sigma0 = sigma0_32; + sigma1 = sigma1_32; + maj = maj_32; + ch = ch_32; + + if ("SHA-224" === variant) { + H = H_trunc; + } else /* "SHA-256" === variant */ + { + H = H_full; + } + } else if ((variant === "SHA-384" || variant === "SHA-512") && 4 & SUPPORTED_ALGS) { + /* 64-bit variant */ + numRounds = 80; + lengthPosition = (messageLen + 128 >>> 10 << 5) + 31; + binaryStringInc = 32; + binaryStringMult = 2; + Int = Int_64; + safeAdd_2 = safeAdd_64_2; + safeAdd_4 = safeAdd_64_4; + safeAdd_5 = safeAdd_64_5; + gamma0 = gamma0_64; + gamma1 = gamma1_64; + sigma0 = sigma0_64; + sigma1 = sigma1_64; + maj = maj_64; + ch = ch_64; + + K = [new Int(K[0], 0xd728ae22), new Int(K[1], 0x23ef65cd), new Int(K[2], 0xec4d3b2f), new Int(K[3], 0x8189dbbc), new Int(K[4], 0xf348b538), new Int(K[5], 0xb605d019), new Int(K[6], 0xaf194f9b), new Int(K[7], 0xda6d8118), new Int(K[8], 0xa3030242), new Int(K[9], 0x45706fbe), new Int(K[10], 0x4ee4b28c), new Int(K[11], 0xd5ffb4e2), new Int(K[12], 0xf27b896f), new Int(K[13], 0x3b1696b1), new Int(K[14], 0x25c71235), new Int(K[15], 0xcf692694), new Int(K[16], 0x9ef14ad2), new Int(K[17], 0x384f25e3), new Int(K[18], 0x8b8cd5b5), new Int(K[19], 0x77ac9c65), new Int(K[20], 0x592b0275), new Int(K[21], 0x6ea6e483), new Int(K[22], 0xbd41fbd4), new Int(K[23], 0x831153b5), new Int(K[24], 0xee66dfab), new Int(K[25], 0x2db43210), new Int(K[26], 0x98fb213f), new Int(K[27], 0xbeef0ee4), new Int(K[28], 0x3da88fc2), new Int(K[29], 0x930aa725), new Int(K[30], 0xe003826f), new Int(K[31], 0x0a0e6e70), new Int(K[32], 0x46d22ffc), new Int(K[33], 0x5c26c926), new Int(K[34], 0x5ac42aed), new Int(K[35], 0x9d95b3df), new Int(K[36], 0x8baf63de), new Int(K[37], 0x3c77b2a8), new Int(K[38], 0x47edaee6), new Int(K[39], 0x1482353b), new Int(K[40], 0x4cf10364), new Int(K[41], 0xbc423001), new Int(K[42], 0xd0f89791), new Int(K[43], 0x0654be30), new Int(K[44], 0xd6ef5218), new Int(K[45], 0x5565a910), new Int(K[46], 0x5771202a), new Int(K[47], 0x32bbd1b8), new Int(K[48], 0xb8d2d0c8), new Int(K[49], 0x5141ab53), new Int(K[50], 0xdf8eeb99), new Int(K[51], 0xe19b48a8), new Int(K[52], 0xc5c95a63), new Int(K[53], 0xe3418acb), new Int(K[54], 0x7763e373), new Int(K[55], 0xd6b2b8a3), new Int(K[56], 0x5defb2fc), new Int(K[57], 0x43172f60), new Int(K[58], 0xa1f0ab72), new Int(K[59], 0x1a6439ec), new Int(K[60], 0x23631e28), new Int(K[61], 0xde82bde9), new Int(K[62], 0xb2c67915), new Int(K[63], 0xe372532b), new Int(0xca273ece, 0xea26619c), new Int(0xd186b8c7, 0x21c0c207), new Int(0xeada7dd6, 0xcde0eb1e), new Int(0xf57d4f7f, 0xee6ed178), new Int(0x06f067aa, 0x72176fba), new Int(0x0a637dc5, 0xa2c898a6), new Int(0x113f9804, 0xbef90dae), new Int(0x1b710b35, 0x131c471b), new Int(0x28db77f5, 0x23047d84), new Int(0x32caab7b, 0x40c72493), new Int(0x3c9ebe0a, 0x15c9bebc), new Int(0x431d67c4, 0x9c100d4c), new Int(0x4cc5d4be, 0xcb3e42b6), new Int(0x597f299c, 0xfc657e2a), new Int(0x5fcb6fab, 0x3ad6faec), new Int(0x6c44198c, 0x4a475817)]; + + if ("SHA-384" === variant) { + H = [new Int(0xcbbb9d5d, H_trunc[0]), new Int(0x0629a292a, H_trunc[1]), new Int(0x9159015a, H_trunc[2]), new Int(0x0152fecd8, H_trunc[3]), new Int(0x67332667, H_trunc[4]), new Int(0x98eb44a87, H_trunc[5]), new Int(0xdb0c2e0d, H_trunc[6]), new Int(0x047b5481d, H_trunc[7])]; + } else /* "SHA-512" === variant */ + { + H = [new Int(H_full[0], 0xf3bcc908), new Int(H_full[1], 0x84caa73b), new Int(H_full[2], 0xfe94f82b), new Int(H_full[3], 0x5f1d36f1), new Int(H_full[4], 0xade682d1), new Int(H_full[5], 0x2b3e6c1f), new Int(H_full[6], 0xfb41bd6b), new Int(H_full[7], 0x137e2179)]; + } + } else { + throw "Unexpected error in SHA-2 implementation"; + } + + while (message.length <= lengthPosition) { + message.push(0); + } + /* Append '1' at the end of the binary string */ + message[messageLen >>> 5] |= 0x80 << 24 - messageLen % 32; + /* Append length of binary string in the position such that the new + * length is correct */ + message[lengthPosition] = messageLen; + + appendedMessageLength = message.length; + + for (i = 0; i < appendedMessageLength; i += binaryStringInc) { + a = H[0]; + b = H[1]; + c = H[2]; + d = H[3]; + e = H[4]; + f = H[5]; + g = H[6]; + h = H[7]; + + for (t = 0; t < numRounds; t += 1) { + if (t < 16) { + offset = t * binaryStringMult + i; + int1 = message.length <= offset ? 0 : message[offset]; + int2 = message.length <= offset + 1 ? 0 : message[offset + 1]; + /* Bit of a hack - for 32-bit, the second term is ignored */ + W[t] = new Int(int1, int2); + } else { + W[t] = safeAdd_4(gamma1(W[t - 2]), W[t - 7], gamma0(W[t - 15]), W[t - 16]); + } + + T1 = safeAdd_5(h, sigma1(e), ch(e, f, g), K[t], W[t]); + T2 = safeAdd_2(sigma0(a), maj(a, b, c)); + h = g; + g = f; + f = e; + e = safeAdd_2(d, T1); + d = c; + c = b; + b = a; + a = safeAdd_2(T1, T2); + } + + H[0] = safeAdd_2(a, H[0]); + H[1] = safeAdd_2(b, H[1]); + H[2] = safeAdd_2(c, H[2]); + H[3] = safeAdd_2(d, H[3]); + H[4] = safeAdd_2(e, H[4]); + H[5] = safeAdd_2(f, H[5]); + H[6] = safeAdd_2(g, H[6]); + H[7] = safeAdd_2(h, H[7]); + } + + if ("SHA-224" === variant && 2 & SUPPORTED_ALGS) { + retVal = [H[0], H[1], H[2], H[3], H[4], H[5], H[6]]; + } else if ("SHA-256" === variant && 2 & SUPPORTED_ALGS) { + retVal = H; + } else if ("SHA-384" === variant && 4 & SUPPORTED_ALGS) { + retVal = [H[0].highOrder, H[0].lowOrder, H[1].highOrder, H[1].lowOrder, H[2].highOrder, H[2].lowOrder, H[3].highOrder, H[3].lowOrder, H[4].highOrder, H[4].lowOrder, H[5].highOrder, H[5].lowOrder]; + } else if ("SHA-512" === variant && 4 & SUPPORTED_ALGS) { + retVal = [H[0].highOrder, H[0].lowOrder, H[1].highOrder, H[1].lowOrder, H[2].highOrder, H[2].lowOrder, H[3].highOrder, H[3].lowOrder, H[4].highOrder, H[4].lowOrder, H[5].highOrder, H[5].lowOrder, H[6].highOrder, H[6].lowOrder, H[7].highOrder, H[7].lowOrder]; + } else /* This should never be reached */ + { + throw "Unexpected error in SHA-2 implementation"; + } + + return retVal; +} + +/** + * jsSHA is the workhorse of the library. Instantiate it with the string to + * be hashed as the parameter + * + * @constructor + * @this {jsSHA} + * @param {string} srcString The string to be hashed + * @param {string} inputFormat The format of srcString, HEX, ASCII, TEXT, + * B64, or BYTES + * @param {string=} encoding The text encoding to use to encode the source + * string + */ +var jsSHA = function jsSHA(srcString, inputFormat, encoding) { + var strBinLen = 0, + strToHash = [0], + utfType = '', + srcConvertRet = null; + + utfType = encoding || "UTF8"; + + if (!("UTF8" === utfType || "UTF16BE" === utfType || "UTF16LE" === utfType)) { + throw "encoding must be UTF8, UTF16BE, or UTF16LE"; + } + + /* Convert the input string into the correct type */ + if ("HEX" === inputFormat) { + if (0 !== srcString.length % 2) { + throw "srcString of HEX type must be in byte increments"; + } + srcConvertRet = hex2binb(srcString); + strBinLen = srcConvertRet["binLen"]; + strToHash = srcConvertRet["value"]; + } else if ("TEXT" === inputFormat || "ASCII" === inputFormat) { + srcConvertRet = str2binb(srcString, utfType); + strBinLen = srcConvertRet["binLen"]; + strToHash = srcConvertRet["value"]; + } else if ("B64" === inputFormat) { + srcConvertRet = b642binb(srcString); + strBinLen = srcConvertRet["binLen"]; + strToHash = srcConvertRet["value"]; + } else if ("BYTES" === inputFormat) { + srcConvertRet = bytes2binb(srcString); + strBinLen = srcConvertRet["binLen"]; + strToHash = srcConvertRet["value"]; + } else if ("TYPED" === inputFormat) { + srcConvertRet = typed2binb(srcString); + strBinLen = srcConvertRet["binLen"]; + strToHash = srcConvertRet["value"]; + } else { + throw "inputFormat must be HEX, TEXT, ASCII, B64, BYTES, or TYPED"; + } + + /** + * Returns the desired SHA hash of the string specified at instantiation + * using the specified parameters + * + * @expose + * @param {string} variant The desired SHA variant (SHA-1, SHA-224, + * SHA-256, SHA-384, or SHA-512) + * @param {string} format The desired output formatting (B64, HEX, or BYTES) + * @param {number=} numRounds The number of rounds of hashing to be + * executed + * @param {{outputUpper : boolean, b64Pad : string}=} outputFormatOpts + * Hash list of output formatting options + * @return {string} The string representation of the hash in the format + * specified */ - /* Number of Bits Per character (8 for ASCII, 16 for Unicode) */ - var charSize = 8, - /* base-64 pad character. "=" for strict RFC compliance */ - b64pad = "", - /* hex output format. 0 - lowercase; 1 - uppercase */ - hexCase = 0, - - /* - * Int_64 is a object for 2 32-bit numbers emulating a 64-bit number - * - * @constructor - * @param {Number} msint_32 The most significant 32-bits of a 64-bit number - * @param {Number} lsint_32 The least significant 32-bits of a 64-bit number - */ - Int_64 = function(msint_32, lsint_32) { - this.highOrder = msint_32; - this.lowOrder = lsint_32; - }, - - /* - * Convert a string to an array of big-endian words - * If charSize is ASCII, characters >255 have their hi-byte silently - * ignored. - * - * @param {String} str String to be converted to binary representation - * @return Integer array representation of the parameter - */ - str2binb = function(str) { - var bin = [], - mask = (1 << charSize) - 1, - length = str.length * charSize, + this.getHash = function (variant, format, numRounds, outputFormatOpts) { + var formatFunc = null, + message = strToHash.slice(), + messageBinLen = strBinLen, i; - for (i = 0; i < length; i += charSize) { - bin[i >> 5] |= (str.charCodeAt(i / charSize) & mask) << - (32 - charSize - (i % 32)); + /* Need to do argument patching since both numRounds and + outputFormatOpts are optional */ + if (3 === arguments.length) { + if ("number" !== typeof numRounds) { + outputFormatOpts = numRounds; + numRounds = 1; } - - return bin; - }, - - /* - * Convert a hex string to an array of big-endian words - * - * @param {String} str String to be converted to binary representation - * @return Integer array representation of the parameter - */ - hex2binb = function(str) { - var bin = [], - length = str.length, - i, num; - - for (i = 0; i < length; i += 2) { - num = parseInt(str.substr(i, 2), 16); - if (!isNaN(num)) { - bin[i >> 3] |= num << (24 - (4 * (i % 8))); - } else { - throw new Error("INVALID HEX STRING"); - } - } - - return bin; - }, - - /* - * Convert an array of big-endian words to a hex string. - * - * @private - * @param {Array} binarray Array of integers to be converted to hexidecimal - * representation - * @return Hexidecimal representation of the parameter in String form - */ - binb2hex = function(binarray) { - var hex_tab = (hexCase) ? "0123456789ABCDEF" : "0123456789abcdef", - str = "", - length = binarray.length * 4, - i, srcByte; - - for (i = 0; i < length; i += 1) { - srcByte = binarray[i >> 2] >> ((3 - (i % 4)) * 8); - str += hex_tab.charAt((srcByte >> 4) & 0xF) + - hex_tab.charAt(srcByte & 0xF); - } - - return str; - }, - - /* - * Convert an array of big-endian words to a base-64 string - * - * @private - * @param {Array} binarray Array of integers to be converted to base-64 - * representation - * @return Base-64 encoded representation of the parameter in String form - */ - binb2b64 = function(binarray) { - var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + - "0123456789+/", - str = "", - length = binarray.length * 4, - i, j, - triplet; - - for (i = 0; i < length; i += 3) { - triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | - (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | - ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF); - for (j = 0; j < 4; j += 1) { - if (i * 8 + j * 6 <= binarray.length * 32) { - str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F); - } else { - str += b64pad; - } - } - } - return str; - }, - - /* - * Convert an array of big-endian words to a string - */ - binb2str = function(bin) { - var str = ""; - var mask = (1 << 8) - 1; - for (var i = 0; i < bin.length * 32; i += 8) - str += String.fromCharCode((bin[i >> 5] >>> (24 - i % 32)) & mask); - return str; - }, - /* - * The 32-bit implementation of circular rotate left - * - * @private - * @param {Number} x The 32-bit integer argument - * @param {Number} n The number of bits to shift - * @return The x shifted circularly by n bits - */ - rotl_32 = function(x, n) { - return (x << n) | (x >>> (32 - n)); - }, - - /* - * The 32-bit implementation of circular rotate right - * - * @private - * @param {Number} x The 32-bit integer argument - * @param {Number} n The number of bits to shift - * @return The x shifted circularly by n bits - */ - rotr_32 = function(x, n) { - return (x >>> n) | (x << (32 - n)); - }, - - /* - * The 64-bit implementation of circular rotate right - * - * @private - * @param {Int_64} x The 64-bit integer argument - * @param {Number} n The number of bits to shift - * @return The x shifted circularly by n bits - */ - rotr_64 = function(x, n) { - if (n <= 32) { - return new Int_64( - (x.highOrder >>> n) | (x.lowOrder << (32 - n)), (x.lowOrder >>> n) | (x.highOrder << (32 - n))); - } else { - return new Int_64( - (x.lowOrder >>> n) | (x.highOrder << (32 - n)), (x.highOrder >>> n) | (x.lowOrder << (32 - n))); - } - }, - - /* - * The 32-bit implementation of shift right - * - * @private - * @param {Number} x The 32-bit integer argument - * @param {Number} n The number of bits to shift - * @return The x shifted by n bits - */ - shr_32 = function(x, n) { - return x >>> n; - }, - - /* - * The 64-bit implementation of shift right - * - * @private - * @param {Int_64} x The 64-bit integer argument - * @param {Number} n The number of bits to shift - * @return The x shifted by n bits - */ - shr_64 = function(x, n) { - if (n <= 32) { - return new Int_64( - x.highOrder >>> n, - x.lowOrder >>> n | (x.highOrder << (32 - n))); - } else { - return new Int_64( - 0, - x.highOrder << (32 - n)); - } - }, - - /* - * The 32-bit implementation of the NIST specified Parity function - * - * @private - * @param {Number} x The first 32-bit integer argument - * @param {Number} y The second 32-bit integer argument - * @param {Number} z The third 32-bit integer argument - * @return The NIST specified output of the function - */ - parity_32 = function(x, y, z) { - return x ^ y ^ z; - }, - - /* - * The 32-bit implementation of the NIST specified Ch function - * - * @private - * @param {Number} x The first 32-bit integer argument - * @param {Number} y The second 32-bit integer argument - * @param {Number} z The third 32-bit integer argument - * @return The NIST specified output of the function - */ - ch_32 = function(x, y, z) { - return (x & y) ^ (~x & z); - }, - - /* - * The 64-bit implementation of the NIST specified Ch function - * - * @private - * @param {Int_64} x The first 64-bit integer argument - * @param {Int_64} y The second 64-bit integer argument - * @param {Int_64} z The third 64-bit integer argument - * @return The NIST specified output of the function - */ - ch_64 = function(x, y, z) { - return new Int_64( - (x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder), (x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)); - }, - - /* - * The 32-bit implementation of the NIST specified Maj function - * - * @private - * @param {Number} x The first 32-bit integer argument - * @param {Number} y The second 32-bit integer argument - * @param {Number} z The third 32-bit integer argument - * @return The NIST specified output of the function - */ - maj_32 = function(x, y, z) { - return (x & y) ^ (x & z) ^ (y & z); - }, - - /* - * The 64-bit implementation of the NIST specified Maj function - * - * @private - * @param {Int_64} x The first 64-bit integer argument - * @param {Int_64} y The second 64-bit integer argument - * @param {Int_64} z The third 64-bit integer argument - * @return The NIST specified output of the function - */ - maj_64 = function(x, y, z) { - return new Int_64( - (x.highOrder & y.highOrder) ^ - (x.highOrder & z.highOrder) ^ - (y.highOrder & z.highOrder), (x.lowOrder & y.lowOrder) ^ - (x.lowOrder & z.lowOrder) ^ - (y.lowOrder & z.lowOrder)); - }, - - /* - * The 32-bit implementation of the NIST specified Sigma0 function - * - * @private - * @param {Number} x The 32-bit integer argument - * @return The NIST specified output of the function - */ - sigma0_32 = function(x) { - return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22); - }, - - /* - * The 64-bit implementation of the NIST specified Sigma0 function - * - * @private - * @param {Int_64} x The 64-bit integer argument - * @return The NIST specified output of the function - */ - sigma0_64 = function(x) { - var rotr28 = rotr_64(x, 28), - rotr34 = rotr_64(x, 34), - rotr39 = rotr_64(x, 39); - - return new Int_64( - rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder, - rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder); - }, - - /* - * The 32-bit implementation of the NIST specified Sigma1 function - * - * @private - * @param {Number} x The 32-bit integer argument - * @return The NIST specified output of the function - */ - sigma1_32 = function(x) { - return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25); - }, - - /* - * The 64-bit implementation of the NIST specified Sigma1 function - * - * @private - * @param {Int_64} x The 64-bit integer argument - * @return The NIST specified output of the function - */ - sigma1_64 = function(x) { - var rotr14 = rotr_64(x, 14), - rotr18 = rotr_64(x, 18), - rotr41 = rotr_64(x, 41); - - return new Int_64( - rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder, - rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder); - }, - - /* - * The 32-bit implementation of the NIST specified Gamma0 function - * - * @private - * @param {Number} x The 32-bit integer argument - * @return The NIST specified output of the function - */ - gamma0_32 = function(x) { - return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3); - }, - - /* - * The 64-bit implementation of the NIST specified Gamma0 function - * - * @private - * @param {Int_64} x The 64-bit integer argument - * @return The NIST specified output of the function - */ - gamma0_64 = function(x) { - var rotr1 = rotr_64(x, 1), - rotr8 = rotr_64(x, 8), - shr7 = shr_64(x, 7); - - return new Int_64( - rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder, - rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder); - }, - - /* - * The 32-bit implementation of the NIST specified Gamma1 function - * - * @private - * @param {Number} x The 32-bit integer argument - * @return The NIST specified output of the function - */ - gamma1_32 = function(x) { - return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10); - }, - - /* - * The 64-bit implementation of the NIST specified Gamma1 function - * - * @private - * @param {Int_64} x The 64-bit integer argument - * @return The NIST specified output of the function - */ - gamma1_64 = function(x) { - var rotr19 = rotr_64(x, 19), - rotr61 = rotr_64(x, 61), - shr6 = shr_64(x, 6); - - return new Int_64( - rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder, - rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder); - }, - - /* - * Add two 32-bit integers, wrapping at 2^32. This uses 16-bit operations - * internally to work around bugs in some JS interpreters. - * - * @private - * @param {Number} x The first 32-bit integer argument to be added - * @param {Number} y The second 32-bit integer argument to be added - * @return The sum of x + y - */ - safeAdd_32_2 = function(x, y) { - var lsw = (x & 0xFFFF) + (y & 0xFFFF), - msw = (x >>> 16) + (y >>> 16) + (lsw >>> 16); - - return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - }, - - /* - * Add four 32-bit integers, wrapping at 2^32. This uses 16-bit operations - * internally to work around bugs in some JS interpreters. - * - * @private - * @param {Number} a The first 32-bit integer argument to be added - * @param {Number} b The second 32-bit integer argument to be added - * @param {Number} c The third 32-bit integer argument to be added - * @param {Number} d The fourth 32-bit integer argument to be added - * @return The sum of a + b + c + d - */ - safeAdd_32_4 = function(a, b, c, d) { - var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF), - msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + - (lsw >>> 16); - - return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - }, - - /* - * Add five 32-bit integers, wrapping at 2^32. This uses 16-bit operations - * internally to work around bugs in some JS interpreters. - * - * @private - * @param {Number} a The first 32-bit integer argument to be added - * @param {Number} b The second 32-bit integer argument to be added - * @param {Number} c The third 32-bit integer argument to be added - * @param {Number} d The fourth 32-bit integer argument to be added - * @param {Number} e The fifth 32-bit integer argument to be added - * @return The sum of a + b + c + d + e - */ - safeAdd_32_5 = function(a, b, c, d, e) { - var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF) + - (e & 0xFFFF), - msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + - (e >>> 16) + (lsw >>> 16); - - return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - }, - - /* - * Add two 64-bit integers, wrapping at 2^64. This uses 16-bit operations - * internally to work around bugs in some JS interpreters. - * - * @private - * @param {Int_64} x The first 64-bit integer argument to be added - * @param {Int_64} y The second 64-bit integer argument to be added - * @return The sum of x + y - */ - safeAdd_64_2 = function(x, y) { - var lsw, msw, lowOrder, highOrder; - - lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF); - msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16); - lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - - lsw = (x.highOrder & 0xFFFF) + (y.highOrder & 0xFFFF) + (msw >>> 16); - msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16); - highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - - return new Int_64(highOrder, lowOrder); - }, - - /* - * Add four 64-bit integers, wrapping at 2^64. This uses 16-bit operations - * internally to work around bugs in some JS interpreters. - * - * @private - * @param {Int_64} a The first 64-bit integer argument to be added - * @param {Int_64} b The second 64-bit integer argument to be added - * @param {Int_64} c The third 64-bit integer argument to be added - * @param {Int_64} d The fouth 64-bit integer argument to be added - * @return The sum of a + b + c + d - */ - safeAdd_64_4 = function(a, b, c, d) { - var lsw, msw, lowOrder, highOrder; - - lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) + - (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF); - msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + - (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (lsw >>> 16); - lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - - lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) + - (c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + (msw >>> 16); - msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + - (c.highOrder >>> 16) + (d.highOrder >>> 16) + (lsw >>> 16); - highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - - return new Int_64(highOrder, lowOrder); - }, - - /* - * Add five 64-bit integers, wrapping at 2^64. This uses 16-bit operations - * internally to work around bugs in some JS interpreters. - * - * @private - * @param {Int_64} a The first 64-bit integer argument to be added - * @param {Int_64} b The second 64-bit integer argument to be added - * @param {Int_64} c The third 64-bit integer argument to be added - * @param {Int_64} d The fouth 64-bit integer argument to be added - * @param {Int_64} e The fouth 64-bit integer argument to be added - * @return The sum of a + b + c + d + e - */ - safeAdd_64_5 = function(a, b, c, d, e) { - var lsw, msw, lowOrder, highOrder; - - lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) + - (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF) + - (e.lowOrder & 0xFFFF); - msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + - (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (e.lowOrder >>> 16) + - (lsw >>> 16); - lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - - lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) + - (c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + - (e.highOrder & 0xFFFF) + (msw >>> 16); - msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + - (c.highOrder >>> 16) + (d.highOrder >>> 16) + - (e.highOrder >>> 16) + (lsw >>> 16); - highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF); - - return new Int_64(highOrder, lowOrder); - }, - - /* - * Calculates the SHA-1 hash of the string set at instantiation - * - * @private - * @param {Array} message The binary array representation of the string to - * hash - * @param {Number} messageLen The number of bits in the message - * @return The array of integers representing the SHA-1 hash of message - */ - coreSHA1 = function(message, messageLen) { - var W = [], - a, b, c, d, e, T, ch = ch_32, - parity = parity_32, - maj = maj_32, - rotl = rotl_32, - safeAdd_2 = safeAdd_32_2, - i, t, - safeAdd_5 = safeAdd_32_5, - appendedMessageLength, - H = [ - 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 - ], - K = [ - 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, - 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, - 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, - 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, - 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, - 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, - 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, - 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, - 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, - 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, - 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, - 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, - 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, - 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, - 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, - 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, - 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, - 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, - 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, - 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6 - ]; - - /* Append '1' at the end of the binary string */ - message[messageLen >> 5] |= 0x80 << (24 - (messageLen % 32)); - /* Append length of binary string in the position such that the new - length is a multiple of 512. Logic does not work for even multiples - of 512 but there can never be even multiples of 512 */ - message[(((messageLen + 65) >> 9) << 4) + 15] = messageLen; - - appendedMessageLength = message.length; - - for (i = 0; i < appendedMessageLength; i += 16) { - a = H[0]; - b = H[1]; - c = H[2]; - d = H[3]; - e = H[4]; - - for (t = 0; t < 80; t += 1) { - if (t < 16) { - W[t] = message[t + i]; - } else { - W[t] = rotl(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); - } - - if (t < 20) { - T = safeAdd_5(rotl(a, 5), ch(b, c, d), e, K[t], W[t]); - } else if (t < 40) { - T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, K[t], W[t]); - } else if (t < 60) { - T = safeAdd_5(rotl(a, 5), maj(b, c, d), e, K[t], W[t]); - } else { - T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, K[t], W[t]); - } - - e = d; - d = c; - c = rotl(b, 30); - b = a; - a = T; - } - - H[0] = safeAdd_2(a, H[0]); - H[1] = safeAdd_2(b, H[1]); - H[2] = safeAdd_2(c, H[2]); - H[3] = safeAdd_2(d, H[3]); - H[4] = safeAdd_2(e, H[4]); - } - - return H; - }, - - /* - * Calculates the desired SHA-2 hash of the string set at instantiation - * - * @private - * @param {Array} The binary array representation of the string to hash - * @param {Number} The number of bits in message - * @param {String} variant The desired SHA-2 variant - * @return The array of integers representing the SHA-2 hash of message - */ - coreSHA2 = function(message, messageLen, variant) { - var a, b, c, d, e, f, g, h, T1, T2, H, numRounds, lengthPosition, i, t, - binaryStringInc, binaryStringMult, safeAdd_2, safeAdd_4, safeAdd_5, - gamma0, gamma1, sigma0, sigma1, ch, maj, Int, K, W = [], - appendedMessageLength; - - /* Set up the various function handles and variable for the specific - * variant */ - if (variant === "SHA-224" || variant === "SHA-256") { - /* 32-bit variant */ - numRounds = 64; - lengthPosition = (((messageLen + 65) >> 9) << 4) + 15; - binaryStringInc = 16; - binaryStringMult = 1; - Int = Number; - safeAdd_2 = safeAdd_32_2; - safeAdd_4 = safeAdd_32_4; - safeAdd_5 = safeAdd_32_5; - gamma0 = gamma0_32; - gamma1 = gamma1_32; - sigma0 = sigma0_32; - sigma1 = sigma1_32; - maj = maj_32; - ch = ch_32; - K = [ - 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, - 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, - 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, - 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, - 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, - 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, - 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, - 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, - 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, - 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, - 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, - 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, - 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, - 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, - 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, - 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 - ]; - - if (variant === "SHA-224") { - H = [ - 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, - 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 - ]; - } else { - H = [ - 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, - 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 - ]; - } - } else if (variant === "SHA-384" || variant === "SHA-512") { - /* 64-bit variant */ - numRounds = 80; - lengthPosition = (((messageLen + 128) >> 10) << 5) + 31; - binaryStringInc = 32; - binaryStringMult = 2; - Int = Int_64; - safeAdd_2 = safeAdd_64_2; - safeAdd_4 = safeAdd_64_4; - safeAdd_5 = safeAdd_64_5; - gamma0 = gamma0_64; - gamma1 = gamma1_64; - sigma0 = sigma0_64; - sigma1 = sigma1_64; - maj = maj_64; - ch = ch_64; - - K = [ - new Int(0x428a2f98, 0xd728ae22), new Int(0x71374491, 0x23ef65cd), - new Int(0xb5c0fbcf, 0xec4d3b2f), new Int(0xe9b5dba5, 0x8189dbbc), - new Int(0x3956c25b, 0xf348b538), new Int(0x59f111f1, 0xb605d019), - new Int(0x923f82a4, 0xaf194f9b), new Int(0xab1c5ed5, 0xda6d8118), - new Int(0xd807aa98, 0xa3030242), new Int(0x12835b01, 0x45706fbe), - new Int(0x243185be, 0x4ee4b28c), new Int(0x550c7dc3, 0xd5ffb4e2), - new Int(0x72be5d74, 0xf27b896f), new Int(0x80deb1fe, 0x3b1696b1), - new Int(0x9bdc06a7, 0x25c71235), new Int(0xc19bf174, 0xcf692694), - new Int(0xe49b69c1, 0x9ef14ad2), new Int(0xefbe4786, 0x384f25e3), - new Int(0x0fc19dc6, 0x8b8cd5b5), new Int(0x240ca1cc, 0x77ac9c65), - new Int(0x2de92c6f, 0x592b0275), new Int(0x4a7484aa, 0x6ea6e483), - new Int(0x5cb0a9dc, 0xbd41fbd4), new Int(0x76f988da, 0x831153b5), - new Int(0x983e5152, 0xee66dfab), new Int(0xa831c66d, 0x2db43210), - new Int(0xb00327c8, 0x98fb213f), new Int(0xbf597fc7, 0xbeef0ee4), - new Int(0xc6e00bf3, 0x3da88fc2), new Int(0xd5a79147, 0x930aa725), - new Int(0x06ca6351, 0xe003826f), new Int(0x14292967, 0x0a0e6e70), - new Int(0x27b70a85, 0x46d22ffc), new Int(0x2e1b2138, 0x5c26c926), - new Int(0x4d2c6dfc, 0x5ac42aed), new Int(0x53380d13, 0x9d95b3df), - new Int(0x650a7354, 0x8baf63de), new Int(0x766a0abb, 0x3c77b2a8), - new Int(0x81c2c92e, 0x47edaee6), new Int(0x92722c85, 0x1482353b), - new Int(0xa2bfe8a1, 0x4cf10364), new Int(0xa81a664b, 0xbc423001), - new Int(0xc24b8b70, 0xd0f89791), new Int(0xc76c51a3, 0x0654be30), - new Int(0xd192e819, 0xd6ef5218), new Int(0xd6990624, 0x5565a910), - new Int(0xf40e3585, 0x5771202a), new Int(0x106aa070, 0x32bbd1b8), - new Int(0x19a4c116, 0xb8d2d0c8), new Int(0x1e376c08, 0x5141ab53), - new Int(0x2748774c, 0xdf8eeb99), new Int(0x34b0bcb5, 0xe19b48a8), - new Int(0x391c0cb3, 0xc5c95a63), new Int(0x4ed8aa4a, 0xe3418acb), - new Int(0x5b9cca4f, 0x7763e373), new Int(0x682e6ff3, 0xd6b2b8a3), - new Int(0x748f82ee, 0x5defb2fc), new Int(0x78a5636f, 0x43172f60), - new Int(0x84c87814, 0xa1f0ab72), new Int(0x8cc70208, 0x1a6439ec), - new Int(0x90befffa, 0x23631e28), new Int(0xa4506ceb, 0xde82bde9), - new Int(0xbef9a3f7, 0xb2c67915), new Int(0xc67178f2, 0xe372532b), - new Int(0xca273ece, 0xea26619c), new Int(0xd186b8c7, 0x21c0c207), - new Int(0xeada7dd6, 0xcde0eb1e), new Int(0xf57d4f7f, 0xee6ed178), - new Int(0x06f067aa, 0x72176fba), new Int(0x0a637dc5, 0xa2c898a6), - new Int(0x113f9804, 0xbef90dae), new Int(0x1b710b35, 0x131c471b), - new Int(0x28db77f5, 0x23047d84), new Int(0x32caab7b, 0x40c72493), - new Int(0x3c9ebe0a, 0x15c9bebc), new Int(0x431d67c4, 0x9c100d4c), - new Int(0x4cc5d4be, 0xcb3e42b6), new Int(0x597f299c, 0xfc657e2a), - new Int(0x5fcb6fab, 0x3ad6faec), new Int(0x6c44198c, 0x4a475817) - ]; - - if (variant === "SHA-384") { - H = [ - new Int(0xcbbb9d5d, 0xc1059ed8), new Int(0x0629a292a, 0x367cd507), - new Int(0x9159015a, 0x3070dd17), new Int(0x0152fecd8, 0xf70e5939), - new Int(0x67332667, 0xffc00b31), new Int(0x98eb44a87, 0x68581511), - new Int(0xdb0c2e0d, 0x64f98fa7), new Int(0x047b5481d, 0xbefa4fa4) - ]; - } else { - H = [ - new Int(0x6a09e667, 0xf3bcc908), new Int(0xbb67ae85, 0x84caa73b), - new Int(0x3c6ef372, 0xfe94f82b), new Int(0xa54ff53a, 0x5f1d36f1), - new Int(0x510e527f, 0xade682d1), new Int(0x9b05688c, 0x2b3e6c1f), - new Int(0x1f83d9ab, 0xfb41bd6b), new Int(0x5be0cd19, 0x137e2179) - ]; - } - } - - /* Append '1' at the end of the binary string */ - message[messageLen >> 5] |= 0x80 << (24 - messageLen % 32); - /* Append length of binary string in the position such that the new - * length is correct */ - message[lengthPosition] = messageLen; - - appendedMessageLength = message.length; - - for (i = 0; i < appendedMessageLength; i += binaryStringInc) { - a = H[0]; - b = H[1]; - c = H[2]; - d = H[3]; - e = H[4]; - f = H[5]; - g = H[6]; - h = H[7]; - - for (t = 0; t < numRounds; t += 1) { - if (t < 16) { - /* Bit of a hack - for 32-bit, the second term is ignored */ - W[t] = new Int(message[t * binaryStringMult + i], - message[t * binaryStringMult + i + 1]); - } else { - W[t] = safeAdd_4( - gamma1(W[t - 2]), W[t - 7], - gamma0(W[t - 15]), W[t - 16]); - } - - T1 = safeAdd_5(h, sigma1(e), ch(e, f, g), K[t], W[t]); - T2 = safeAdd_2(sigma0(a), maj(a, b, c)); - h = g; - g = f; - f = e; - e = safeAdd_2(d, T1); - d = c; - c = b; - b = a; - a = safeAdd_2(T1, T2); - } - - H[0] = safeAdd_2(a, H[0]); - H[1] = safeAdd_2(b, H[1]); - H[2] = safeAdd_2(c, H[2]); - H[3] = safeAdd_2(d, H[3]); - H[4] = safeAdd_2(e, H[4]); - H[5] = safeAdd_2(f, H[5]); - H[6] = safeAdd_2(g, H[6]); - H[7] = safeAdd_2(h, H[7]); - } - - switch (variant) { - case "SHA-224": - return [ - H[0], H[1], H[2], H[3], - H[4], H[5], H[6]]; - case "SHA-256": - return H; - case "SHA-384": - return [ - H[0].highOrder, H[0].lowOrder, - H[1].highOrder, H[1].lowOrder, - H[2].highOrder, H[2].lowOrder, - H[3].highOrder, H[3].lowOrder, - H[4].highOrder, H[4].lowOrder, - H[5].highOrder, H[5].lowOrder]; - case "SHA-512": - return [ - H[0].highOrder, H[0].lowOrder, - H[1].highOrder, H[1].lowOrder, - H[2].highOrder, H[2].lowOrder, - H[3].highOrder, H[3].lowOrder, - H[4].highOrder, H[4].lowOrder, - H[5].highOrder, H[5].lowOrder, - H[6].highOrder, H[6].lowOrder, - H[7].highOrder, H[7].lowOrder]; - default: - /* This should never be reached */ - throw new Error('Unknown SHA variant'); - } - }, - - /* - * jsSHA is the workhorse of the library. Instantiate it with the string to - * be hashed as the parameter - * - * @constructor - * @param {String} srcString The string to be hashed - * @param {String} inputFormat The format of srcString, ASCII or HEX - */ - jsSHA = function(srcString, inputFormat) { - - this.sha1 = null; - this.sha224 = null; - this.sha256 = null; - this.sha384 = null; - this.sha512 = null; - - this.strBinLen = null; - this.strToHash = null; - - /* Convert the input string into the correct type */ - if ("HEX" === inputFormat) { - if (0 !== (srcString.length % 2)) { - throw new Error("TEXT MUST BE IN BYTE INCREMENTS"); - } - this.strBinLen = srcString.length * 4; - this.strToHash = hex2binb(srcString); - } else if (("ASCII" === inputFormat) || - ('undefined' === typeof(inputFormat))) { - this.strBinLen = srcString.length * charSize; - this.strToHash = str2binb(srcString); - } else { - throw new Error("UNKNOWN TEXT INPUT TYPE"); - } - }; - - jsSHA.prototype = { - /* - * Returns the desired SHA hash of the string specified at instantiation - * using the specified parameters - * - * @param {String} variant The desired SHA variant (SHA-1, SHA-224, - * SHA-256, SHA-384, or SHA-512) - * @param {String} format The desired output formatting (B64 or HEX) - * @return The string representation of the hash in the format specified - */ - getHash: function(variant, format) { - var formatFunc = null, - message = this.strToHash.slice(); - - switch (format) { - case "HEX": - formatFunc = binb2hex; - break; - case "B64": - formatFunc = binb2b64; - break; - case "ASCII": - formatFunc = binb2str; - break; - default: - throw new Error("FORMAT NOT RECOGNIZED"); - } - - switch (variant) { - case "SHA-1": - if (null === this.sha1) { - this.sha1 = coreSHA1(message, this.strBinLen); - } - return formatFunc(this.sha1); - case "SHA-224": - if (null === this.sha224) { - this.sha224 = coreSHA2(message, this.strBinLen, variant); - } - return formatFunc(this.sha224); - case "SHA-256": - if (null === this.sha256) { - this.sha256 = coreSHA2(message, this.strBinLen, variant); - } - return formatFunc(this.sha256); - case "SHA-384": - if (null === this.sha384) { - this.sha384 = coreSHA2(message, this.strBinLen, variant); - } - return formatFunc(this.sha384); - case "SHA-512": - if (null === this.sha512) { - this.sha512 = coreSHA2(message, this.strBinLen, variant); - } - return formatFunc(this.sha512); - default: - throw new Error("HASH NOT RECOGNIZED"); - } - }, - - /* - * Returns the desired HMAC of the string specified at instantiation - * using the key and variant param. - * - * @param {String} key The key used to calculate the HMAC - * @param {String} inputFormat The format of key, ASCII or HEX - * @param {String} variant The desired SHA variant (SHA-1, SHA-224, - * SHA-256, SHA-384, or SHA-512) - * @param {String} outputFormat The desired output formatting - * (B64 or HEX) - * @return The string representation of the hash in the format specified - */ - getHMAC: function(key, inputFormat, variant, outputFormat) { - var formatFunc, keyToUse, blockByteSize, blockBitSize, i, - retVal, lastArrayIndex, keyBinLen, hashBitSize, - keyWithIPad = [], - keyWithOPad = []; - - /* Validate the output format selection */ - switch (outputFormat) { - case "HEX": - formatFunc = binb2hex; - break; - case "B64": - formatFunc = binb2b64; - break; - case "ASCII": - formatFunc = binb2str; - break; - default: - throw new Error("FORMAT NOT RECOGNIZED"); - } - - /* Validate the hash variant selection and set needed variables */ - switch (variant) { - case "SHA-1": - blockByteSize = 64; - hashBitSize = 160; - break; - case "SHA-224": - blockByteSize = 64; - hashBitSize = 224; - break; - case "SHA-256": - blockByteSize = 64; - hashBitSize = 256; - break; - case "SHA-384": - blockByteSize = 128; - hashBitSize = 384; - break; - case "SHA-512": - blockByteSize = 128; - hashBitSize = 512; - break; - default: - throw new Error("HASH NOT RECOGNIZED"); - } - - /* Validate input format selection */ - if ("HEX" === inputFormat) { - /* Nibbles must come in pairs */ - if (0 !== (key.length % 2)) { - throw new Error("KEY MUST BE IN BYTE INCREMENTS"); - } - keyToUse = hex2binb(key); - keyBinLen = key.length * 4; - } else if ("ASCII" === inputFormat) { - keyToUse = str2binb(key); - keyBinLen = key.length * charSize; - } else { - throw new Error("UNKNOWN KEY INPUT TYPE"); - } - - /* These are used multiple times, calculate and store them */ - blockBitSize = blockByteSize * 8; - lastArrayIndex = (blockByteSize / 4) - 1; - - /* Figure out what to do with the key based on its size relative to - * the hash's block size */ - if (blockByteSize < (keyBinLen / 8)) { - if ("SHA-1" === variant) { - keyToUse = coreSHA1(keyToUse, keyBinLen); - } else { - keyToUse = coreSHA2(keyToUse, keyBinLen, variant); - } - /* For all variants, the block size is bigger than the output - * size so there will never be a useful byte at the end of the - * string */ - keyToUse[lastArrayIndex] &= 0xFFFFFF00; - } else if (blockByteSize > (keyBinLen / 8)) { - /* If the blockByteSize is greater than the key length, there - * will always be at LEAST one "useless" byte at the end of the - * string */ - keyToUse[lastArrayIndex] &= 0xFFFFFF00; - } - - /* Create ipad and opad */ - for (i = 0; i <= lastArrayIndex; i += 1) { - keyWithIPad[i] = keyToUse[i] ^ 0x36363636; - keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C; - } - - /* Calculate the HMAC */ - if ("SHA-1" === variant) { - retVal = coreSHA1( - keyWithIPad.concat(this.strToHash), - blockBitSize + this.strBinLen); - retVal = coreSHA1( - keyWithOPad.concat(retVal), - blockBitSize + hashBitSize); - } else { - retVal = coreSHA2( - keyWithIPad.concat(this.strToHash), - blockBitSize + this.strBinLen, variant); - retVal = coreSHA2( - keyWithOPad.concat(retVal), - blockBitSize + hashBitSize, variant); - } - - return (formatFunc(retVal)); + } else if (2 === arguments.length) { + numRounds = 1; } + + /* Validate the numRounds argument */ + if (numRounds !== parseInt(numRounds, 10) || 1 > numRounds) { + throw "numRounds must a integer >= 1"; + } + + /* Validate the output format selection */ + switch (format) { + case "HEX": + formatFunc = binb2hex; + break; + case "B64": + formatFunc = binb2b64; + break; + case "BYTES": + formatFunc = binb2bytes; + break; + case "TYPED": + formatFunc = binb2typed; + break; + default: + throw "format must be HEX, B64, or BYTES"; + } + + if ("SHA-1" === variant && 1 & SUPPORTED_ALGS) { + for (i = 0; i < numRounds; i += 1) { + message = coreSHA1(message, messageBinLen); + messageBinLen = 160; + } + } else if ("SHA-224" === variant && 2 & SUPPORTED_ALGS) { + for (i = 0; i < numRounds; i += 1) { + message = coreSHA2(message, messageBinLen, variant); + messageBinLen = 224; + } + } else if ("SHA-256" === variant && 2 & SUPPORTED_ALGS) { + for (i = 0; i < numRounds; i += 1) { + message = coreSHA2(message, messageBinLen, variant); + messageBinLen = 256; + } + } else if ("SHA-384" === variant && 4 & SUPPORTED_ALGS) { + for (i = 0; i < numRounds; i += 1) { + message = coreSHA2(message, messageBinLen, variant); + messageBinLen = 384; + } + } else if ("SHA-512" === variant && 4 & SUPPORTED_ALGS) { + for (i = 0; i < numRounds; i += 1) { + message = coreSHA2(message, messageBinLen, variant); + messageBinLen = 512; + } + } else { + throw "Chosen SHA variant is not supported"; + } + + return formatFunc(message, getOutputOpts(outputFormatOpts)); }; - return jsSHA; -}()); + /** + * Returns the desired HMAC of the string specified at instantiation + * using the key and variant parameter + * + * @expose + * @param {string} key The key used to calculate the HMAC + * @param {string} inputFormat The format of key, HEX, TEXT, ASCII, + * B64, or BYTES + * @param {string} variant The desired SHA variant (SHA-1, SHA-224, + * SHA-256, SHA-384, or SHA-512) + * @param {string} outputFormat The desired output formatting + * (B64, HEX, or BYTES) + * @param {{outputUpper : boolean, b64Pad : string}=} outputFormatOpts + * associative array of output formatting options + * @return {string} The string representation of the hash in the format + * specified + */ + this.getHMAC = function (key, inputFormat, variant, outputFormat, outputFormatOpts) { + var formatFunc, + keyToUse, + blockByteSize, + blockBitSize, + i, + retVal, + lastArrayIndex, + keyBinLen, + hashBitSize, + keyWithIPad = [], + keyWithOPad = [], + keyConvertRet = null; -module.exports = { + /* Validate the output format selection */ + switch (outputFormat) { + case "HEX": + formatFunc = binb2hex; + break; + case "B64": + formatFunc = binb2b64; + break; + case "BYTES": + formatFunc = binb2bytes; + break; + default: + throw "outputFormat must be HEX, B64, or BYTES"; + } + + /* Validate the hash variant selection and set needed variables */ + if ("SHA-1" === variant && 1 & SUPPORTED_ALGS) { + blockByteSize = 64; + hashBitSize = 160; + } else if ("SHA-224" === variant && 2 & SUPPORTED_ALGS) { + blockByteSize = 64; + hashBitSize = 224; + } else if ("SHA-256" === variant && 2 & SUPPORTED_ALGS) { + blockByteSize = 64; + hashBitSize = 256; + } else if ("SHA-384" === variant && 4 & SUPPORTED_ALGS) { + blockByteSize = 128; + hashBitSize = 384; + } else if ("SHA-512" === variant && 4 & SUPPORTED_ALGS) { + blockByteSize = 128; + hashBitSize = 512; + } else { + throw "Chosen SHA variant is not supported"; + } + + /* Validate input format selection */ + if ("HEX" === inputFormat) { + keyConvertRet = hex2binb(key); + keyBinLen = keyConvertRet["binLen"]; + keyToUse = keyConvertRet["value"]; + } else if ("TEXT" === inputFormat || "ASCII" === inputFormat) { + keyConvertRet = str2binb(key, utfType); + keyBinLen = keyConvertRet["binLen"]; + keyToUse = keyConvertRet["value"]; + } else if ("B64" === inputFormat) { + keyConvertRet = b642binb(key); + keyBinLen = keyConvertRet["binLen"]; + keyToUse = keyConvertRet["value"]; + } else if ("BYTES" === inputFormat) { + keyConvertRet = bytes2binb(key); + keyBinLen = keyConvertRet["binLen"]; + keyToUse = keyConvertRet["value"]; + } else { + throw "inputFormat must be HEX, TEXT, ASCII, B64, or BYTES"; + } + + /* These are used multiple times, calculate and store them */ + blockBitSize = blockByteSize * 8; + lastArrayIndex = blockByteSize / 4 - 1; + + /* Figure out what to do with the key based on its size relative to + * the hash's block size */ + if (blockByteSize < keyBinLen / 8) { + if ("SHA-1" === variant && 1 & SUPPORTED_ALGS) { + keyToUse = coreSHA1(keyToUse, keyBinLen); + } else if (6 & SUPPORTED_ALGS) { + keyToUse = coreSHA2(keyToUse, keyBinLen, variant); + } else { + throw "Unexpected error in HMAC implementation"; + } + /* For all variants, the block size is bigger than the output + * size so there will never be a useful byte at the end of the + * string */ + while (keyToUse.length <= lastArrayIndex) { + keyToUse.push(0); + } + keyToUse[lastArrayIndex] &= 0xFFFFFF00; + } else if (blockByteSize > keyBinLen / 8) { + /* If the blockByteSize is greater than the key length, there + * will always be at LEAST one "useless" byte at the end of the + * string */ + while (keyToUse.length <= lastArrayIndex) { + keyToUse.push(0); + } + keyToUse[lastArrayIndex] &= 0xFFFFFF00; + } + + /* Create ipad and opad */ + for (i = 0; i <= lastArrayIndex; i += 1) { + keyWithIPad[i] = keyToUse[i] ^ 0x36363636; + keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C; + } + + /* Calculate the HMAC */ + if ("SHA-1" === variant && 1 & SUPPORTED_ALGS) { + retVal = coreSHA1(keyWithOPad.concat(coreSHA1(keyWithIPad.concat(strToHash), blockBitSize + strBinLen)), blockBitSize + hashBitSize); + } else if (6 & SUPPORTED_ALGS) { + retVal = coreSHA2(keyWithOPad.concat(coreSHA2(keyWithIPad.concat(strToHash), blockBitSize + strBinLen, variant)), blockBitSize + hashBitSize, variant); + } else { + throw "Unexpected error in HMAC implementation"; + } + + return formatFunc(retVal, getOutputOpts(outputFormatOpts)); + }; +}; + +exports.default = { /** SHA1 hash */ - sha1: function(str) { - var shaObj = new jsSHA(str, "ASCII"); - return shaObj.getHash("SHA-1", "ASCII"); + sha1: function sha1(str) { + var shaObj = new jsSHA(str, "TYPED", "UTF8"); + return shaObj.getHash("SHA-1", "TYPED"); }, /** SHA224 hash */ - sha224: function(str) { - var shaObj = new jsSHA(str, "ASCII"); - return shaObj.getHash("SHA-224", "ASCII"); + sha224: function sha224(str) { + var shaObj = new jsSHA(str, "TYPED", "UTF8"); + return shaObj.getHash("SHA-224", "TYPED"); }, /** SHA256 hash */ - sha256: function(str) { - var shaObj = new jsSHA(str, "ASCII"); - return shaObj.getHash("SHA-256", "ASCII"); + sha256: function sha256(str) { + var shaObj = new jsSHA(str, "TYPED", "UTF8"); + return shaObj.getHash("SHA-256", "TYPED"); }, /** SHA384 hash */ - sha384: function(str) { - var shaObj = new jsSHA(str, "ASCII"); - return shaObj.getHash("SHA-384", "ASCII"); - + sha384: function sha384(str) { + var shaObj = new jsSHA(str, "TYPED", "UTF8"); + return shaObj.getHash("SHA-384", "TYPED"); }, /** SHA512 hash */ - sha512: function(str) { - var shaObj = new jsSHA(str, "ASCII"); - return shaObj.getHash("SHA-512", "ASCII"); + sha512: function sha512(str) { + var shaObj = new jsSHA(str, "TYPED", "UTF8"); + return shaObj.getHash("SHA-512", "TYPED"); } }; @@ -6815,42 +8068,84 @@ module.exports = { * @see module:crypto/crypto * @module crypto */ -module.exports = { + +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _cipher = require('./cipher'); + +var _cipher2 = _interopRequireDefault(_cipher); + +var _hash = require('./hash'); + +var _hash2 = _interopRequireDefault(_hash); + +var _cfb = require('./cfb'); + +var _cfb2 = _interopRequireDefault(_cfb); + +var _public_key = require('./public_key'); + +var _public_key2 = _interopRequireDefault(_public_key); + +var _signature = require('./signature'); + +var _signature2 = _interopRequireDefault(_signature); + +var _random = require('./random'); + +var _random2 = _interopRequireDefault(_random); + +var _pkcs = require('./pkcs1'); + +var _pkcs2 = _interopRequireDefault(_pkcs); + +var _crypto = require('./crypto.js'); + +var _crypto2 = _interopRequireDefault(_crypto); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var mod = { /** @see module:crypto/cipher */ - cipher: require('./cipher'), + cipher: _cipher2.default, /** @see module:crypto/hash */ - hash: require('./hash'), + hash: _hash2.default, /** @see module:crypto/cfb */ - cfb: require('./cfb.js'), + cfb: _cfb2.default, /** @see module:crypto/public_key */ - publicKey: require('./public_key'), + publicKey: _public_key2.default, /** @see module:crypto/signature */ - signature: require('./signature.js'), + signature: _signature2.default, /** @see module:crypto/random */ - random: require('./random.js'), + random: _random2.default, /** @see module:crypto/pkcs1 */ - pkcs1: require('./pkcs1.js') + pkcs1: _pkcs2.default }; -var crypto = require('./crypto.js'); +for (var i in _crypto2.default) { + mod[i] = _crypto2.default[i]; +} -for (var i in crypto) - module.exports[i] = crypto[i]; +exports.default = mod; -},{"./cfb.js":18,"./cipher":23,"./crypto.js":25,"./hash":28,"./pkcs1.js":33,"./public_key":36,"./random.js":39,"./signature.js":40}],33:[function(require,module,exports){ +},{"./cfb":20,"./cipher":25,"./crypto.js":27,"./hash":28,"./pkcs1":33,"./public_key":36,"./random":39,"./signature":40}],33:[function(require,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 @@ -6865,33 +8160,41 @@ for (var i in crypto) * @module crypto/pkcs1 */ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _random = require('./random.js'); + +var _random2 = _interopRequireDefault(_random); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _jsbn = require('./public_key/jsbn.js'); + +var _jsbn2 = _interopRequireDefault(_jsbn); + +var _hash = require('./hash'); + +var _hash2 = _interopRequireDefault(_hash); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /** * ASN1 object identifiers for hashes (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.2}) */ var hash_headers = []; -hash_headers[1] = [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, - 0x10 -]; +hash_headers[1] = [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10]; hash_headers[2] = [0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14]; hash_headers[3] = [0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14]; -hash_headers[8] = [0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, - 0x04, 0x20 -]; -hash_headers[9] = [0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, - 0x04, 0x30 -]; -hash_headers[10] = [0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, - 0x00, 0x04, 0x40 -]; -hash_headers[11] = [0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, - 0x00, 0x04, 0x1C -]; - -var crypto = require('./crypto.js'), - random = require('./random.js'), - util = require('../util.js'), - BigInteger = require('./public_key/jsbn.js'), - hash = require('./hash'); +hash_headers[8] = [0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20]; +hash_headers[9] = [0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30]; +hash_headers[10] = [0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40]; +hash_headers[11] = [0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1C]; /** * Create padding with secure random data @@ -6903,7 +8206,7 @@ function getPkcs1Padding(length) { var result = ''; var randomByte; while (result.length < length) { - randomByte = random.getSecureRandomOctet(); + randomByte = _random2.default.getSecureRandomOctet(); if (randomByte !== 0) { result += String.fromCharCode(randomByte); } @@ -6911,8 +8214,7 @@ function getPkcs1Padding(length) { return result; } - -module.exports = { +exports.default = { eme: { /** * create a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.1|RFC 4880 13.1.1}) @@ -6920,7 +8222,7 @@ module.exports = { * @param {Integer} k the length in octets of the key modulus * @return {String} EME-PKCS1 padded message */ - encode: function(M, k) { + encode: function encode(M, k) { var mLen = M.length; // length checking if (mLen > k - 11) { @@ -6931,11 +8233,7 @@ module.exports = { var PS = getPkcs1Padding(k - mLen - 3); // Concatenate PS, the message M, and other padding to form an // encoded message EM of length k octets as EM = 0x00 || 0x02 || PS || 0x00 || M. - var EM = String.fromCharCode(0) + - String.fromCharCode(2) + - PS + - String.fromCharCode(0) + - M; + var EM = String.fromCharCode(0) + String.fromCharCode(2) + PS + String.fromCharCode(0) + M; return EM; }, /** @@ -6943,7 +8241,7 @@ module.exports = { * @param {String} EM encoded message, an octet string * @return {String} message, an octet string */ - decode: function(EM) { + decode: function decode(EM) { // leading zeros truncated by jsbn if (EM.charCodeAt(0) !== 0) { EM = String.fromCharCode(0) + EM; @@ -6972,11 +8270,11 @@ module.exports = { * @param {Integer} emLen intended length in octets of the encoded message * @returns {String} encoded message */ - encode: function(algo, M, emLen) { + encode: function encode(algo, M, emLen) { var i; // Apply the hash function to the message M to produce a hash value H - var H = hash.digest(algo, M); - if (H.length !== hash.getHashByteLength(algo)) { + var H = _util2.default.Uint8Array2str(_hash2.default.digest(algo, _util2.default.str2Uint8Array(M))); + if (H.length !== _hash2.default.getHashByteLength(algo)) { throw new Error('Invalid hash length'); } // produce an ASN.1 DER value for the hash function used. @@ -6995,35 +8293,31 @@ module.exports = { // an octet string PS consisting of emLen - tLen - 3 octets with hexadecimal value 0xFF // The length of PS will be at least 8 octets var PS = ''; - for (i = 0; i < (emLen - tLen - 3); i++) { + for (i = 0; i < emLen - tLen - 3; i++) { PS += String.fromCharCode(0xff); } // Concatenate PS, the hash prefix T, and other padding to form the // encoded message EM as EM = 0x00 || 0x01 || PS || 0x00 || T. - var EM = String.fromCharCode(0x00) + - String.fromCharCode(0x01) + - PS + - String.fromCharCode(0x00) + - T; - return new BigInteger(util.hexstrdump(EM), 16); + var EM = String.fromCharCode(0x00) + String.fromCharCode(0x01) + PS + String.fromCharCode(0x00) + T; + return new _jsbn2.default(_util2.default.hexstrdump(EM), 16); } } }; -},{"../util.js":76,"./crypto.js":25,"./hash":28,"./public_key/jsbn.js":37,"./random.js":39}],34:[function(require,module,exports){ +},{"../util.js":76,"./hash":28,"./public_key/jsbn.js":37,"./random.js":39}],34:[function(require,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 @@ -7038,11 +8332,34 @@ module.exports = { * @module crypto/public_key/dsa */ -var BigInteger = require('./jsbn.js'), - random = require('../random.js'), - hashModule = require('../hash'), - util = require('../../util.js'), - config = require('../../config'); +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = DSA; + +var _jsbn = require('./jsbn.js'); + +var _jsbn2 = _interopRequireDefault(_jsbn); + +var _random = require('../random.js'); + +var _random2 = _interopRequireDefault(_random); + +var _hash = require('../hash'); + +var _hash2 = _interopRequireDefault(_hash); + +var _util = require('../../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _config = require('../../config'); + +var _config2 = _interopRequireDefault(_config); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function DSA() { // s1 = ((g**s) mod p) mod q @@ -7053,19 +8370,19 @@ function DSA() { // of leftmost bits equal to the number of bits of q. This (possibly // truncated) hash function result is treated as a number and used // directly in the DSA signature algorithm. - var hashed_data = util.getLeftNBits(hashModule.digest(hashalgo, m), q.bitLength()); - var hash = new BigInteger(util.hexstrdump(hashed_data), 16); + var hashed_data = _util2.default.getLeftNBits(_util2.default.Uint8Array2str(_hash2.default.digest(hashalgo, _util2.default.str2Uint8Array(m))), q.bitLength()); + var hash = new _jsbn2.default(_util2.default.hexstrdump(hashed_data), 16); // FIPS-186-4, section 4.6: // The values of r and s shall be checked to determine if r = 0 or s = 0. // If either r = 0 or s = 0, a new value of k shall be generated, and the - // signature shall be recalculated. It is extremely unlikely that r = 0 + // signature shall be recalculated. It is extremely unlikely that r = 0 // or s = 0 if signatures are generated properly. var k, s1, s2; while (true) { - k = random.getRandomBigIntegerInRange(BigInteger.ONE, q.subtract(BigInteger.ONE)); - s1 = (g.modPow(k, p)).mod(q); - s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q); - if (s1 != 0 && s2 != 0) { + k = _random2.default.getRandomBigIntegerInRange(_jsbn2.default.ONE, q.subtract(_jsbn2.default.ONE)); + s1 = g.modPow(k, p).mod(q); + s2 = k.modInverse(q).multiply(hash.add(x.multiply(s1))).mod(q); + if (s1 !== 0 && s2 !== 0) { break; } } @@ -7076,7 +8393,7 @@ function DSA() { } function select_hash_algorithm(q) { - var usersetting = config.prefer_hash_algorithm; + var usersetting = _config2.default.prefer_hash_algorithm; /* * 1024-bit key, 160-bit q, SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512 hash * 2048-bit key, 224-bit q, SHA-224, SHA-256, SHA-384, or SHA-512 hash @@ -7086,45 +8403,39 @@ function DSA() { switch (Math.round(q.bitLength() / 8)) { case 20: // 1024 bit - if (usersetting != 2 && - usersetting > 11 && - usersetting != 10 && - usersetting < 8) + if (usersetting !== 2 && usersetting > 11 && usersetting !== 10 && usersetting < 8) { return 2; // prefer sha1 + } return usersetting; case 28: // 2048 bit - if (usersetting > 11 && - usersetting < 8) + if (usersetting > 11 && usersetting < 8) { return 11; + } return usersetting; case 32: // 4096 bit // prefer sha224 - if (usersetting > 10 && - usersetting < 8) + if (usersetting > 10 && usersetting < 8) { return 8; // prefer sha256 + } return usersetting; default: - util.print_debug("DSA select hash algorithm: returning null for an unknown length of q"); + _util2.default.print_debug("DSA select hash algorithm: returning null for an unknown length of q"); return null; - } } this.select_hash_algorithm = select_hash_algorithm; function verify(hashalgo, s1, s2, m, p, q, g, y) { - var hashed_data = util.getLeftNBits(hashModule.digest(hashalgo, m), q.bitLength()); - var hash = new BigInteger(util.hexstrdump(hashed_data), 16); - if (BigInteger.ZERO.compareTo(s1) >= 0 || - s1.compareTo(q) >= 0 || - BigInteger.ZERO.compareTo(s2) >= 0 || - s2.compareTo(q) >= 0) { - util.print_debug("invalid DSA Signature"); + var hashed_data = _util2.default.getLeftNBits(_util2.default.Uint8Array2str(_hash2.default.digest(hashalgo, _util2.default.str2Uint8Array(m))), q.bitLength()); + var hash = new _jsbn2.default(_util2.default.hexstrdump(hashed_data), 16); + if (_jsbn2.default.ZERO.compareTo(s1) >= 0 || s1.compareTo(q) >= 0 || _jsbn2.default.ZERO.compareTo(s2) >= 0 || s2.compareTo(q) >= 0) { + _util2.default.print_debug("invalid DSA Signature"); return null; } var w = s2.modInverse(q); - if (BigInteger.ZERO.compareTo(w) == 0) { - util.print_debug("invalid DSA Signature"); + if (_jsbn2.default.ZERO.compareTo(w) === 0) { + _util2.default.print_debug("invalid DSA Signature"); return null; } var u1 = hash.multiply(w).mod(q); @@ -7132,86 +8443,24 @@ function DSA() { return g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q); } - /* - * unused code. This can be used as a start to write a key generator - * function. - - function generateKey(bitcount) { - var qi = new BigInteger(bitcount, primeCenterie); - var pi = generateP(q, 512); - var gi = generateG(p, q, bitcount); - var xi; - do { - xi = new BigInteger(q.bitCount(), rand); - } while (x.compareTo(BigInteger.ZERO) != 1 && x.compareTo(q) != -1); - var yi = g.modPow(x, p); - return {x: xi, q: qi, p: pi, g: gi, y: yi}; - } - - function generateP(q, bitlength, randomfn) { - if (bitlength % 64 != 0) { - return false; - } - var pTemp; - var pTemp2; - do { - pTemp = randomfn(bitcount, true); - pTemp2 = pTemp.subtract(BigInteger.ONE); - pTemp = pTemp.subtract(pTemp2.remainder(q)); - } while (!pTemp.isProbablePrime(primeCenterie) || pTemp.bitLength() != l); - return pTemp; - } - - function generateG(p, q, bitlength, randomfn) { - var aux = p.subtract(BigInteger.ONE); - var pow = aux.divide(q); - var gTemp; - do { - gTemp = randomfn(bitlength); - } while (gTemp.compareTo(aux) != -1 && gTemp.compareTo(BigInteger.ONE) != 1); - return gTemp.modPow(pow, p); - } - - function generateK(q, bitlength, randomfn) { - var tempK; - do { - tempK = randomfn(bitlength, false); - } while (tempK.compareTo(q) != -1 && tempK.compareTo(BigInteger.ZERO) != 1); - return tempK; - } - - function generateR(q,p) { - k = generateK(q); - var r = g.modPow(k, p).mod(q); - return r; - } - - function generateS(hashfn,k,r,m,q,x) { - var hash = hashfn(m); - s = (k.modInverse(q).multiply(hash.add(x.multiply(r)))).mod(q); - return s; - } */ this.sign = sign; this.verify = verify; - // this.generate = generateKey; } -module.exports = DSA; - -},{"../../config":17,"../../util.js":76,"../hash":28,"../random.js":39,"./jsbn.js":37}],35:[function(require,module,exports){ +},{"../../config":19,"../../util.js":76,"../hash":28,"../random.js":39,"./jsbn.js":37}],35:[function(require,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 @@ -7225,17 +8474,34 @@ module.exports = DSA; * @module crypto/public_key/elgamal */ -var BigInteger = require('./jsbn.js'), - random = require('../random.js'), - util = require('../../util.js'); +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Elgamal; + +var _jsbn = require('./jsbn.js'); + +var _jsbn2 = _interopRequireDefault(_jsbn); + +var _random = require('../random.js'); + +var _random2 = _interopRequireDefault(_random); + +var _util = require('../../util.js'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function Elgamal() { function encrypt(m, g, p, y) { // choose k in {2,...,p-2} - var pMinus2 = p.subtract(BigInteger.TWO); - var k = random.getRandomBigIntegerInRange(BigInteger.ONE, pMinus2); - k = k.mod(pMinus2).add(BigInteger.ONE); + var pMinus2 = p.subtract(_jsbn2.default.TWO); + var k = _random2.default.getRandomBigIntegerInRange(_jsbn2.default.ONE, pMinus2); + k = k.mod(pMinus2).add(_jsbn2.default.ONE); var c = []; c[0] = g.modPow(k, p); c[1] = y.modPow(k, p).multiply(m).mod(p); @@ -7243,11 +8509,8 @@ function Elgamal() { } function decrypt(c1, c2, p, x) { - util.print_debug("Elgamal Decrypt:\nc1:" + util.hexstrdump(c1.toMPI()) + "\n" + - "c2:" + util.hexstrdump(c2.toMPI()) + "\n" + - "p:" + util.hexstrdump(p.toMPI()) + "\n" + - "x:" + util.hexstrdump(x.toMPI())); - return (c1.modPow(x, p).modInverse(p)).multiply(c2).mod(p); + _util2.default.print_debug("Elgamal Decrypt:\nc1:" + _util2.default.hexstrdump(c1.toMPI()) + "\n" + "c2:" + _util2.default.hexstrdump(c2.toMPI()) + "\n" + "p:" + _util2.default.hexstrdump(p.toMPI()) + "\n" + "x:" + _util2.default.hexstrdump(x.toMPI())); + return c1.modPow(x, p).modInverse(p).multiply(c2).mod(p); //var c = c1.pow(x).modInverse(p); // c0^-a mod p //return c.multiply(c2).mod(p); } @@ -7257,8 +8520,6 @@ function Elgamal() { this.decrypt = decrypt; } -module.exports = Elgamal; - },{"../../util.js":76,"../random.js":39,"./jsbn.js":37}],36:[function(require,module,exports){ /** * @requires crypto/public_key/dsa @@ -7266,22 +8527,63 @@ module.exports = Elgamal; * @requires crypto/public_key/rsa * @module crypto/public_key */ -module.exports = { - /** @see module:crypto/public_key/rsa */ - rsa: require('./rsa.js'), - /** @see module:crypto/public_key/elgamal */ - elgamal: require('./elgamal.js'), - /** @see module:crypto/public_key/dsa */ - dsa: require('./dsa.js') + +'use strict'; + +/** @see module:crypto/public_key/rsa */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _rsa = require('./rsa.js'); + +var _rsa2 = _interopRequireDefault(_rsa); + +var _elgamal = require('./elgamal.js'); + +var _elgamal2 = _interopRequireDefault(_elgamal); + +var _dsa = require('./dsa.js'); + +var _dsa2 = _interopRequireDefault(_dsa); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/** @see module:crypto/public_key/elgamal */ +exports.default = { + rsa: _rsa2.default, + elgamal: _elgamal2.default, + dsa: _dsa2.default }; +/** @see module:crypto/public_key/dsa */ },{"./dsa.js":34,"./elgamal.js":35,"./rsa.js":38}],37:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = BigInteger; + +var _util = require("../../util.js"); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +// Basic JavaScript BN library - subset useful for RSA encryption. + +// Bits per digit +var dbits; + +// JavaScript engine analysis /* - * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) + * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) * All Rights Reserved. * - * Modified by Recurity Labs GmbH - * + * Modified by Recurity Labs GmbH + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -7293,9 +8595,9 @@ module.exports = { * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER @@ -7309,30 +8611,18 @@ module.exports = { * and disclaimer. */ - /** * @requires util * @module crypto/public_key/jsbn */ -var util = require('../../util.js'); - -// Basic JavaScript BN library - subset useful for RSA encryption. - -// Bits per digit -var dbits; - -// JavaScript engine analysis var canary = 0xdeadbeefcafe; -var j_lm = ((canary & 0xffffff) == 0xefcafe); +var j_lm = (canary & 0xffffff) == 0xefcafe; // (public) Constructor function BigInteger(a, b, c) { - if (a != null) - if ("number" == typeof a) this.fromNumber(a, b, c); - else if (b == null && "string" != typeof a) this.fromString(a, 256); - else this.fromString(a, b); + if (a != null) if ("number" == typeof a) this.fromNumber(a, b, c);else if (b == null && "string" != typeof a) this.fromString(a, 256);else this.fromString(a, b); } // return new, unset BigInteger @@ -7364,7 +8654,7 @@ function am1(i, x, w, j, c, n) { function am2(i, x, w, j, c, n) { var xl = x & 0x7fff, - xh = x >> 15; + xh = x >> 15; while (--n >= 0) { var l = this[i] & 0x7fff; var h = this[i++] >> 15; @@ -7380,7 +8670,7 @@ function am2(i, x, w, j, c, n) { function am3(i, x, w, j, c, n) { var xl = x & 0x3fff, - xh = x >> 14; + xh = x >> 14; while (--n >= 0) { var l = this[i] & 0x3fff; var h = this[i++] >> 14; @@ -7391,7 +8681,7 @@ function am3(i, x, w, j, c, n) { } return c; } -/*if(j_lm && (navigator != undefined && +/*if(j_lm && (navigator != undefined && navigator.appName == "Microsoft Internet Explorer")) { BigInteger.prototype.am = am2; dbits = 30; @@ -7406,8 +8696,8 @@ else { // Mozilla/Netscape seems to prefer am3 }*/ BigInteger.prototype.DB = dbits; -BigInteger.prototype.DM = ((1 << dbits) - 1); -BigInteger.prototype.DV = (1 << dbits); +BigInteger.prototype.DM = (1 << dbits) - 1; +BigInteger.prototype.DV = 1 << dbits; var BI_FP = 52; BigInteger.prototype.FV = Math.pow(2, BI_FP); @@ -7419,26 +8709,29 @@ var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"; var BI_RC = new Array(); var rr, vv; rr = "0".charCodeAt(0); -for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv; -rr = "a".charCodeAt(0); -for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; -rr = "A".charCodeAt(0); -for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; - -function int2char(n) { +for (vv = 0; vv <= 9; ++vv) { + BI_RC[rr++] = vv; +}rr = "a".charCodeAt(0); +for (vv = 10; vv < 36; ++vv) { + BI_RC[rr++] = vv; +}rr = "A".charCodeAt(0); +for (vv = 10; vv < 36; ++vv) { + BI_RC[rr++] = vv; +}function int2char(n) { return BI_RM.charAt(n); } function intAt(s, i) { var c = BI_RC[s.charCodeAt(i)]; - return (c == null) ? -1 : c; + return c == null ? -1 : c; } // (protected) copy this to r function bnpCopyTo(r) { - for (var i = this.t - 1; i >= 0; --i) r[i] = this[i]; - r.t = this.t; + for (var i = this.t - 1; i >= 0; --i) { + r[i] = this[i]; + }r.t = this.t; r.s = this.s; } @@ -7446,10 +8739,8 @@ function bnpCopyTo(r) { function bnpFromInt(x) { this.t = 1; - this.s = (x < 0) ? -1 : 0; - if (x > 0) this[0] = x; - else if (x < -1) this[0] = x + this.DV; - else this.t = 0; + this.s = x < 0 ? -1 : 0; + if (x > 0) this[0] = x;else if (x < -1) this[0] = x + this.DV;else this.t = 0; } // return bigint initialized to value @@ -7464,41 +8755,33 @@ function nbv(i) { function bnpFromString(s, b) { var k; - if (b == 16) k = 4; - else if (b == 8) k = 3; - else if (b == 256) k = 8; // byte array - else if (b == 2) k = 1; - else if (b == 32) k = 5; - else if (b == 4) k = 2; - else { - this.fromRadix(s, b); - return; - } + if (b == 16) k = 4;else if (b == 8) k = 3;else if (b == 256) k = 8; // byte array + else if (b == 2) k = 1;else if (b == 32) k = 5;else if (b == 4) k = 2;else { + this.fromRadix(s, b); + return; + } this.t = 0; this.s = 0; var i = s.length, - mi = false, - sh = 0; + mi = false, + sh = 0; while (--i >= 0) { - var x = (k == 8) ? s[i] & 0xff : intAt(s, i); + var x = k == 8 ? s[i] & 0xff : intAt(s, i); if (x < 0) { if (s.charAt(i) == "-") mi = true; continue; } mi = false; - if (sh == 0) - this[this.t++] = x; - else if (sh + k > this.DB) { - this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh; - this[this.t++] = (x >> (this.DB - sh)); - } else - this[this.t - 1] |= x << sh; + if (sh == 0) this[this.t++] = x;else if (sh + k > this.DB) { + this[this.t - 1] |= (x & (1 << this.DB - sh) - 1) << sh; + this[this.t++] = x >> this.DB - sh; + } else this[this.t - 1] |= x << sh; sh += k; if (sh >= this.DB) sh -= this.DB; } if (k == 8 && (s[0] & 0x80) != 0) { this.s = -1; - if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh; + if (sh > 0) this[this.t - 1] |= (1 << this.DB - sh) - 1 << sh; } this.clamp(); if (mi) BigInteger.ZERO.subTo(this, this); @@ -7508,7 +8791,9 @@ function bnpFromString(s, b) { function bnpClamp() { var c = this.s & this.DM; - while (this.t > 0 && this[this.t - 1] == c)--this.t; + while (this.t > 0 && this[this.t - 1] == c) { + --this.t; + } } // (public) return string representation in given radix @@ -7516,17 +8801,13 @@ function bnpClamp() { function bnToString(b) { if (this.s < 0) return "-" + this.negate().toString(b); var k; - if (b == 16) k = 4; - else if (b == 8) k = 3; - else if (b == 2) k = 1; - else if (b == 32) k = 5; - else if (b == 4) k = 2; - else return this.toRadix(b); + if (b == 16) k = 4;else if (b == 8) k = 3;else if (b == 2) k = 1;else if (b == 32) k = 5;else if (b == 4) k = 2;else return this.toRadix(b); var km = (1 << k) - 1, - d, m = false, - r = "", - i = this.t; - var p = this.DB - (i * this.DB) % k; + d, + m = false, + r = "", + i = this.t; + var p = this.DB - i * this.DB % k; if (i-- > 0) { if (p < this.DB && (d = this[i] >> p) > 0) { m = true; @@ -7534,10 +8815,10 @@ function bnToString(b) { } while (i >= 0) { if (p < k) { - d = (this[i] & ((1 << p) - 1)) << (k - p); + d = (this[i] & (1 << p) - 1) << k - p; d |= this[--i] >> (p += this.DB - k); } else { - d = (this[i] >> (p -= k)) & km; + d = this[i] >> (p -= k) & km; if (p <= 0) { p += this.DB; --i; @@ -7561,7 +8842,7 @@ function bnNegate() { // (public) |this| function bnAbs() { - return (this.s < 0) ? this.negate() : this; + return this.s < 0 ? this.negate() : this; } // (public) return + if this > a, - if this < a, 0 if equal @@ -7571,16 +8852,17 @@ function bnCompareTo(a) { if (r != 0) return r; var i = this.t; r = i - a.t; - if (r != 0) return (this.s < 0) ? -r : r; - while (--i >= 0) if ((r = this[i] - a[i]) != 0) return r; - return 0; + if (r != 0) return this.s < 0 ? -r : r; + while (--i >= 0) { + if ((r = this[i] - a[i]) != 0) return r; + }return 0; } // returns bit length of the integer x function nbits(x) { var r = 1, - t; + t; if ((t = x >>> 16) != 0) { x = t; r += 16; @@ -7608,24 +8890,27 @@ function nbits(x) { function bnBitLength() { if (this.t <= 0) return 0; - return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM)); + return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM); } // (protected) r = this << n*DB function bnpDLShiftTo(n, r) { var i; - for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i]; - for (i = n - 1; i >= 0; --i) r[i] = 0; - r.t = this.t + n; + for (i = this.t - 1; i >= 0; --i) { + r[i + n] = this[i]; + }for (i = n - 1; i >= 0; --i) { + r[i] = 0; + }r.t = this.t + n; r.s = this.s; } // (protected) r = this >> n*DB function bnpDRShiftTo(n, r) { - for (var i = n; i < this.t; ++i) r[i - n] = this[i]; - r.t = Math.max(this.t - n, 0); + for (var i = n; i < this.t; ++i) { + r[i - n] = this[i]; + }r.t = Math.max(this.t - n, 0); r.s = this.s; } @@ -7636,14 +8921,15 @@ function bnpLShiftTo(n, r) { var cbs = this.DB - bs; var bm = (1 << cbs) - 1; var ds = Math.floor(n / this.DB), - c = (this.s << bs) & this.DM, - i; + c = this.s << bs & this.DM, + i; for (i = this.t - 1; i >= 0; --i) { - r[i + ds + 1] = (this[i] >> cbs) | c; + r[i + ds + 1] = this[i] >> cbs | c; c = (this[i] & bm) << bs; } - for (i = ds - 1; i >= 0; --i) r[i] = 0; - r[ds] = c; + for (i = ds - 1; i >= 0; --i) { + r[i] = 0; + }r[ds] = c; r.t = this.t + ds + 1; r.s = this.s; r.clamp(); @@ -7675,8 +8961,8 @@ function bnpRShiftTo(n, r) { function bnpSubTo(a, r) { var i = 0, - c = 0, - m = Math.min(a.t, this.t); + c = 0, + m = Math.min(a.t, this.t); while (i < m) { c += this[i] - a[i]; r[i++] = c & this.DM; @@ -7699,9 +8985,8 @@ function bnpSubTo(a, r) { } c -= a.s; } - r.s = (c < 0) ? -1 : 0; - if (c < -1) r[i++] = this.DV + c; - else if (c > 0) r[i++] = c; + r.s = c < 0 ? -1 : 0; + if (c < -1) r[i++] = this.DV + c;else if (c > 0) r[i++] = c; r.t = i; r.clamp(); } @@ -7711,12 +8996,14 @@ function bnpSubTo(a, r) { function bnpMultiplyTo(a, r) { var x = this.abs(), - y = a.abs(); + y = a.abs(); var i = x.t; r.t = i + y.t; - while (--i >= 0) r[i] = 0; - for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t); - r.s = 0; + while (--i >= 0) { + r[i] = 0; + }for (i = 0; i < y.t; ++i) { + r[i + x.t] = x.am(0, y[i], r, i, 0, x.t); + }r.s = 0; r.clamp(); if (this.s != a.s) BigInteger.ZERO.subTo(r, r); } @@ -7726,8 +9013,9 @@ function bnpMultiplyTo(a, r) { function bnpSquareTo(r) { var x = this.abs(); var i = r.t = 2 * x.t; - while (--i >= 0) r[i] = 0; - for (i = 0; i < x.t - 1; ++i) { + while (--i >= 0) { + r[i] = 0; + }for (i = 0; i < x.t - 1; ++i) { var c = x.am(i, x[i], r, 2 * i, 0, 1); if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) { r[i + x.t] -= x.DV; @@ -7753,8 +9041,8 @@ function bnpDivRemTo(m, q, r) { } if (r == null) r = nbi(); var y = nbi(), - ts = this.s, - ms = m.s; + ts = this.s, + ms = m.s; var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus if (nsh > 0) { pm.lShiftTo(nsh, y); @@ -7766,13 +9054,13 @@ function bnpDivRemTo(m, q, r) { var ys = y.t; var y0 = y[ys - 1]; if (y0 == 0) return; - var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0); + var yt = y0 * (1 << this.F1) + (ys > 1 ? y[ys - 2] >> this.F2 : 0); var d1 = this.FV / yt, - d2 = (1 << this.F1) / yt, - e = 1 << this.F2; + d2 = (1 << this.F1) / yt, + e = 1 << this.F2; var i = r.t, - j = i - ys, - t = (q == null) ? nbi() : q; + j = i - ys, + t = q == null ? nbi() : q; y.dlShiftTo(j, t); if (r.compareTo(t) >= 0) { r[r.t++] = 1; @@ -7780,14 +9068,18 @@ function bnpDivRemTo(m, q, r) { } BigInteger.ONE.dlShiftTo(ys, t); t.subTo(y, y); // "negative" y so we can replace sub with am later - while (y.t < ys) y[y.t++] = 0; - while (--j >= 0) { + while (y.t < ys) { + y[y.t++] = 0; + }while (--j >= 0) { // Estimate quotient digit - var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2); - if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out + var qd = r[--i] == y0 ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2); + if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { + // Try it out y.dlShiftTo(j, t); r.subTo(t, r); - while (r[i] < --qd) r.subTo(t, r); + while (r[i] < --qd) { + r.subTo(t, r); + } } } if (q != null) { @@ -7816,8 +9108,7 @@ function Classic(m) { } function cConvert(x) { - if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); - else return x; + if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);else return x; } function cRevert(x) { @@ -7860,14 +9151,14 @@ function bnpInvDigit() { var x = this[0]; if ((x & 1) == 0) return 0; var y = x & 3; // y == 1/x mod 2^2 - y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4 - y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8 - y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16 + y = y * (2 - (x & 0xf) * y) & 0xf; // y == 1/x mod 2^4 + y = y * (2 - (x & 0xff) * y) & 0xff; // y == 1/x mod 2^8 + y = y * (2 - ((x & 0xffff) * y & 0xffff)) & 0xffff; // y == 1/x mod 2^16 // last step - calculate inverse mod DV directly; // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints - y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits + y = y * (2 - x * y % this.DV) % this.DV; // y == 1/x mod 2^dbits // we really want the negative inverse, and -DV < y < DV - return (y > 0) ? this.DV - y : -y; + return y > 0 ? this.DV - y : -y; } // Montgomery reduction @@ -7877,7 +9168,7 @@ function Montgomery(m) { this.mp = m.invDigit(); this.mpl = this.mp & 0x7fff; this.mph = this.mp >> 15; - this.um = (1 << (m.DB - 15)) - 1; + this.um = (1 << m.DB - 15) - 1; this.mt2 = 2 * m.t; } @@ -7903,12 +9194,13 @@ function montRevert(x) { // x = x/R mod m (HAC 14.32) function montReduce(x) { - while (x.t <= this.mt2) // pad x so am has enough room later + while (x.t <= this.mt2) { + // pad x so am has enough room later x[x.t++] = 0; - for (var i = 0; i < this.m.t; ++i) { + }for (var i = 0; i < this.m.t; ++i) { // faster way of calculating u0 = x[i]*mp mod DV var j = x[i] & 0x7fff; - var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM; + var u0 = j * this.mpl + ((j * this.mph + (x[i] >> 15) * this.mpl & this.um) << 15) & x.DM; // use am to combine the multiply-shift-add into one call j = i + this.m.t; x[j] += this.m.am(0, u0, x, i, 0, this.m.t); @@ -7946,7 +9238,7 @@ Montgomery.prototype.sqrTo = montSqrTo; // (protected) true iff this is even function bnpIsEven() { - return ((this.t > 0) ? (this[0] & 1) : this.s) == 0; + return (this.t > 0 ? this[0] & 1 : this.s) == 0; } // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) @@ -7954,14 +9246,13 @@ function bnpIsEven() { function bnpExp(e, z) { if (e > 0xffffffff || e < 1) return BigInteger.ONE; var r = nbi(), - r2 = nbi(), - g = z.convert(this), - i = nbits(e) - 1; + r2 = nbi(), + g = z.convert(this), + i = nbits(e) - 1; g.copyTo(r); while (--i >= 0) { z.sqrTo(r, r2); - if ((e & (1 << i)) > 0) z.mulTo(r2, g, r); - else { + if ((e & 1 << i) > 0) z.mulTo(r2, g, r);else { var t = r; r = r2; r2 = t; @@ -7974,8 +9265,7 @@ function bnpExp(e, z) { function bnModPowInt(e, m) { var z; - if (e < 256 || m.isEven()) z = new Classic(m); - else z = new Montgomery(m); + if (e < 256 || m.isEven()) z = new Classic(m);else z = new Montgomery(m); return this.exp(e, z); } @@ -8010,28 +9300,8 @@ BigInteger.ZERO = nbv(0); BigInteger.ONE = nbv(1); BigInteger.TWO = nbv(2); -module.exports = BigInteger; - - - - - - - - - - - - - - - - - - - /* - * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) + * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) * All Rights Reserved. * * Modified by Recurity Labs GmbH @@ -8047,9 +9317,9 @@ module.exports = BigInteger; * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER @@ -8063,7 +9333,6 @@ module.exports = BigInteger; * and disclaimer. */ - // Extended JavaScript BN functions, required for RSA private ops. // Version 1.1: new BigInteger("0", 10) returns "proper" zero @@ -8080,24 +9349,22 @@ function bnClone() { function bnIntValue() { if (this.s < 0) { - if (this.t == 1) return this[0] - this.DV; - else if (this.t == 0) return -1; - } else if (this.t == 1) return this[0]; - else if (this.t == 0) return 0; + if (this.t == 1) return this[0] - this.DV;else if (this.t == 0) return -1; + } else if (this.t == 1) return this[0];else if (this.t == 0) return 0; // assumes 16 < DB < 32 - return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0]; + return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0]; } // (public) return value as byte function bnByteValue() { - return (this.t == 0) ? this.s : (this[0] << 24) >> 24; + return this.t == 0 ? this.s : this[0] << 24 >> 24; } // (public) return value as short (assumes DB>=16) function bnShortValue() { - return (this.t == 0) ? this.s : (this[0] << 16) >> 16; + return this.t == 0 ? this.s : this[0] << 16 >> 16; } // (protected) return x s.t. r^x < DV @@ -8109,9 +9376,7 @@ function bnpChunkSize(r) { // (public) 0 if this == 0, 1 if this > 0 function bnSigNum() { - if (this.s < 0) return -1; - else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0; - else return 1; + if (this.s < 0) return -1;else if (this.t <= 0 || this.t == 1 && this[0] <= 0) return 0;else return 1; } // (protected) convert to radix string @@ -8122,9 +9387,9 @@ function bnpToRadix(b) { var cs = this.chunkSize(b); var a = Math.pow(b, cs); var d = nbv(a), - y = nbi(), - z = nbi(), - r = ""; + y = nbi(), + z = nbi(), + r = ""; this.divRemTo(d, y, z); while (y.signum() > 0) { r = (a + z.intValue()).toString(b).substr(1) + r; @@ -8140,9 +9405,9 @@ function bnpFromRadix(s, b) { if (b == null) b = 10; var cs = this.chunkSize(b); var d = Math.pow(b, cs), - mi = false, - j = 0, - w = 0; + mi = false, + j = 0, + w = 0; for (var i = 0; i < s.length; ++i) { var x = intAt(s, i); if (x < 0) { @@ -8169,8 +9434,7 @@ function bnpFromRadix(s, b) { function bnpFromNumber(a, b, c) { if ("number" == typeof b) { // new BigInteger(int,int,RNG) - if (a < 2) this.fromInt(1); - else { + if (a < 2) this.fromInt(1);else { this.fromNumber(a, c); if (!this.testBit(a - 1)) // force MSB set this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this); @@ -8183,11 +9447,10 @@ function bnpFromNumber(a, b, c) { } else { // new BigInteger(int,RNG) var x = new Array(), - t = a & 7; + t = a & 7; x.length = (a >> 3) + 1; b.nextBytes(x); - if (t > 0) x[0] &= ((1 << t) - 1); - else x[0] = 0; + if (t > 0) x[0] &= (1 << t) - 1;else x[0] = 0; this.fromString(x, 256); } } @@ -8196,19 +9459,19 @@ function bnpFromNumber(a, b, c) { function bnToByteArray() { var i = this.t, - r = new Array(); + r = new Array(); r[0] = this.s; - var p = this.DB - (i * this.DB) % 8, - d, k = 0; + var p = this.DB - i * this.DB % 8, + d, + k = 0; if (i-- > 0) { - if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) - r[k++] = d | (this.s << (this.DB - p)); + if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) r[k++] = d | this.s << this.DB - p; while (i >= 0) { if (p < 8) { - d = (this[i] & ((1 << p) - 1)) << (8 - p); + d = (this[i] & (1 << p) - 1) << 8 - p; d |= this[--i] >> (p += this.DB - 8); } else { - d = (this[i] >> (p -= 8)) & 0xff; + d = this[i] >> (p -= 8) & 0xff; if (p <= 0) { p += this.DB; --i; @@ -8223,30 +9486,35 @@ function bnToByteArray() { } function bnEquals(a) { - return (this.compareTo(a) == 0); + return this.compareTo(a) == 0; } function bnMin(a) { - return (this.compareTo(a) < 0) ? this : a; + return this.compareTo(a) < 0 ? this : a; } function bnMax(a) { - return (this.compareTo(a) > 0) ? this : a; + return this.compareTo(a) > 0 ? this : a; } // (protected) r = this op a (bitwise) function bnpBitwiseTo(a, op, r) { - var i, f, m = Math.min(a.t, this.t); - for (i = 0; i < m; ++i) r[i] = op(this[i], a[i]); - if (a.t < this.t) { + var i, + f, + m = Math.min(a.t, this.t); + for (i = 0; i < m; ++i) { + r[i] = op(this[i], a[i]); + }if (a.t < this.t) { f = a.s & this.DM; - for (i = m; i < this.t; ++i) r[i] = op(this[i], f); - r.t = this.t; + for (i = m; i < this.t; ++i) { + r[i] = op(this[i], f); + }r.t = this.t; } else { f = this.s & this.DM; - for (i = m; i < a.t; ++i) r[i] = op(f, a[i]); - r.t = a.t; + for (i = m; i < a.t; ++i) { + r[i] = op(f, a[i]); + }r.t = a.t; } r.s = op(this.s, a.s); r.clamp(); @@ -8304,8 +9572,9 @@ function bnAndNot(a) { function bnNot() { var r = nbi(); - for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i]; - r.t = this.t; + for (var i = 0; i < this.t; ++i) { + r[i] = this.DM & ~this[i]; + }r.t = this.t; r.s = ~this.s; return r; } @@ -8314,8 +9583,7 @@ function bnNot() { function bnShiftLeft(n) { var r = nbi(); - if (n < 0) this.rShiftTo(-n, r); - else this.lShiftTo(n, r); + if (n < 0) this.rShiftTo(-n, r);else this.lShiftTo(n, r); return r; } @@ -8323,8 +9591,7 @@ function bnShiftLeft(n) { function bnShiftRight(n) { var r = nbi(); - if (n < 0) this.lShiftTo(-n, r); - else this.rShiftTo(n, r); + if (n < 0) this.lShiftTo(-n, r);else this.rShiftTo(n, r); return r; } @@ -8349,16 +9616,16 @@ function lbit(x) { x >>= 2; r += 2; } - if ((x & 1) == 0)++r; + if ((x & 1) == 0) ++r; return r; } // (public) returns index of lowest 1-bit (or -1 if none) function bnGetLowestSetBit() { - for (var i = 0; i < this.t; ++i) + for (var i = 0; i < this.t; ++i) { if (this[i] != 0) return i * this.DB + lbit(this[i]); - if (this.s < 0) return this.t * this.DB; + }if (this.s < 0) return this.t * this.DB; return -1; } @@ -8377,17 +9644,18 @@ function cbit(x) { function bnBitCount() { var r = 0, - x = this.s & this.DM; - for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x); - return r; + x = this.s & this.DM; + for (var i = 0; i < this.t; ++i) { + r += cbit(this[i] ^ x); + }return r; } // (public) true iff nth bit is set function bnTestBit(n) { var j = Math.floor(n / this.DB); - if (j >= this.t) return (this.s != 0); - return ((this[j] & (1 << (n % this.DB))) != 0); + if (j >= this.t) return this.s != 0; + return (this[j] & 1 << n % this.DB) != 0; } // (protected) this op (1< 0) r[i++] = c; - else if (c < -1) r[i++] = this.DV + c; + r.s = c < 0 ? -1 : 0; + if (c > 0) r[i++] = c;else if (c < -1) r[i++] = this.DV + c; r.t = i; r.clamp(); } @@ -8503,7 +9770,7 @@ function bnRemainder(a) { function bnDivideAndRemainder(a) { var q = nbi(), - r = nbi(); + r = nbi(); this.divRemTo(a, q, r); return new Array(q, r); } @@ -8520,8 +9787,9 @@ function bnpDMultiply(n) { function bnpDAddOffset(n, w) { if (n == 0) return; - while (this.t <= w) this[this.t++] = 0; - this[w] += n; + while (this.t <= w) { + this[this.t++] = 0; + }this[w] += n; while (this[w] >= this.DV) { this[w] -= this.DV; if (++w >= this.t) this[this.t++] = 0; @@ -8563,11 +9831,14 @@ function bnpMultiplyLowerTo(a, n, r) { var i = Math.min(this.t + a.t, n); r.s = 0; // assumes a,this >= 0 r.t = i; - while (i > 0) r[--i] = 0; - var j; - for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t); - for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i); - r.clamp(); + while (i > 0) { + r[--i] = 0; + }var j; + for (j = r.t - this.t; i < j; ++i) { + r[i + this.t] = this.am(0, a[i], r, i, 0, this.t); + }for (j = Math.min(a.t, n); i < j; ++i) { + this.am(0, a[i], r, i, 0, n - i); + }r.clamp(); } // (protected) r = "this * a" without lower n words, n > 0 @@ -8577,10 +9848,11 @@ function bnpMultiplyUpperTo(a, n, r) { --n; var i = r.t = this.t + a.t - n; r.s = 0; // assumes a,this >= 0 - while (--i >= 0) r[i] = 0; - for (i = Math.max(n - this.t, 0); i < a.t; ++i) + while (--i >= 0) { + r[i] = 0; + }for (i = Math.max(n - this.t, 0); i < a.t; ++i) { r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n); - r.clamp(); + }r.clamp(); r.drShiftTo(1, r); } @@ -8596,9 +9868,7 @@ function Barrett(m) { } function barrettConvert(x) { - if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m); - else if (x.compareTo(this.m) < 0) return x; - else { + if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m);else if (x.compareTo(this.m) < 0) return x;else { var r = nbi(); x.copyTo(r); this.reduce(r); @@ -8620,9 +9890,12 @@ function barrettReduce(x) { } this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3); this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); - while (x.compareTo(this.r2) < 0) x.dAddOffset(1, this.m.t + 1); - x.subTo(this.r2, x); - while (x.compareTo(this.m) >= 0) x.subTo(this.m, x); + while (x.compareTo(this.r2) < 0) { + x.dAddOffset(1, this.m.t + 1); + }x.subTo(this.r2, x); + while (x.compareTo(this.m) >= 0) { + x.subTo(this.m, x); + } } // r = x^2 mod m; x != r @@ -8649,26 +9922,17 @@ Barrett.prototype.sqrTo = barrettSqrTo; function bnModPow(e, m) { var i = e.bitLength(), - k, r = nbv(1), - z; - if (i <= 0) return r; - else if (i < 18) k = 1; - else if (i < 48) k = 3; - else if (i < 144) k = 4; - else if (i < 768) k = 5; - else k = 6; - if (i < 8) - z = new Classic(m); - else if (m.isEven()) - z = new Barrett(m); - else - z = new Montgomery(m); + k, + r = nbv(1), + z; + if (i <= 0) return r;else if (i < 18) k = 1;else if (i < 48) k = 3;else if (i < 144) k = 4;else if (i < 768) k = 5;else k = 6; + if (i < 8) z = new Classic(m);else if (m.isEven()) z = new Barrett(m);else z = new Montgomery(m); // precomputation var g = new Array(), - n = 3, - k1 = k - 1, - km = (1 << k) - 1; + n = 3, + k1 = k - 1, + km = (1 << k) - 1; g[1] = z.convert(this); if (k > 1) { var g2 = nbi(); @@ -8681,15 +9945,15 @@ function bnModPow(e, m) { } var j = e.t - 1, - w, is1 = true, - r2 = nbi(), - t; + w, + is1 = true, + r2 = nbi(), + t; i = nbits(e[j]) - 1; while (j >= 0) { - if (i >= k1) w = (e[j] >> (i - k1)) & km; - else { - w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i); - if (j > 0) w |= e[j - 1] >> (this.DB + i - k1); + if (i >= k1) w = e[j] >> i - k1 & km;else { + w = (e[j] & (1 << i + 1) - 1) << k1 - i; + if (j > 0) w |= e[j - 1] >> this.DB + i - k1; } n = k; @@ -8701,7 +9965,8 @@ function bnModPow(e, m) { i += this.DB; --j; } - if (is1) { // ret == 1, don't bother squaring or multiplying it + if (is1) { + // ret == 1, don't bother squaring or multiplying it g[w].copyTo(r); is1 = false; } else { @@ -8710,8 +9975,7 @@ function bnModPow(e, m) { z.sqrTo(r2, r); n -= 2; } - if (n > 0) z.sqrTo(r, r2); - else { + if (n > 0) z.sqrTo(r, r2);else { t = r; r = r2; r2 = t; @@ -8719,7 +9983,7 @@ function bnModPow(e, m) { z.mulTo(r2, g[w], r); } - while (j >= 0 && (e[j] & (1 << i)) == 0) { + while (j >= 0 && (e[j] & 1 << i) == 0) { z.sqrTo(r, r2); t = r; r = r2; @@ -8736,15 +10000,15 @@ function bnModPow(e, m) { // (public) gcd(this,a) (HAC 14.54) function bnGCD(a) { - var x = (this.s < 0) ? this.negate() : this.clone(); - var y = (a.s < 0) ? a.negate() : a.clone(); + var x = this.s < 0 ? this.negate() : this.clone(); + var y = a.s < 0 ? a.negate() : a.clone(); if (x.compareTo(y) < 0) { var t = x; x = y; y = t; } var i = x.getLowestSetBit(), - g = y.getLowestSetBit(); + g = y.getLowestSetBit(); if (g < 0) return x; if (i < g) g = i; if (g > 0) { @@ -8771,24 +10035,23 @@ function bnGCD(a) { function bnpModInt(n) { if (n <= 0) return 0; var d = this.DV % n, - r = (this.s < 0) ? n - 1 : 0; - if (this.t > 0) - if (d == 0) r = this[0] % n; - else for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n; - return r; + r = this.s < 0 ? n - 1 : 0; + if (this.t > 0) if (d == 0) r = this[0] % n;else for (var i = this.t - 1; i >= 0; --i) { + r = (d * r + this[i]) % n; + }return r; } // (public) 1/this % m (HAC 14.61) function bnModInverse(m) { var ac = m.isEven(); - if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; + if (this.isEven() && ac || m.signum() == 0) return BigInteger.ZERO; var u = m.clone(), - v = this.clone(); + v = this.clone(); var a = nbv(1), - b = nbv(0), - c = nbv(0), - d = nbv(1); + b = nbv(0), + c = nbv(0), + d = nbv(1); while (u.signum() != 0) { while (u.isEven()) { u.rShiftTo(1, u); @@ -8824,40 +10087,34 @@ function bnModInverse(m) { } if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; if (d.compareTo(m) >= 0) return d.subtract(m); - if (d.signum() < 0) d.addTo(m, d); - else return d; - if (d.signum() < 0) return d.add(m); - else return d; + if (d.signum() < 0) d.addTo(m, d);else return d; + if (d.signum() < 0) return d.add(m);else return d; } -var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, - 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, - 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, - 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, - 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, - 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, - 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, - 977, 983, 991, 997 -]; +var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]; var lplim = (1 << 26) / lowprimes[lowprimes.length - 1]; // (public) test primality with certainty >= 1-.5^t function bnIsProbablePrime(t) { - var i, x = this.abs(); + var i, + x = this.abs(); if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) { - for (i = 0; i < lowprimes.length; ++i) + for (i = 0; i < lowprimes.length; ++i) { if (x[0] == lowprimes[i]) return true; - return false; + }return false; } if (x.isEven()) return false; i = 1; while (i < lowprimes.length) { var m = lowprimes[i], - j = i + 1; - while (j < lowprimes.length && m < lplim) m *= lowprimes[j++]; - m = x.modInt(m); - while (i < j) if (m % lowprimes[i++] == 0) return false; + j = i + 1; + while (j < lowprimes.length && m < lplim) { + m *= lowprimes[j++]; + }m = x.modInt(m); + while (i < j) { + if (m % lowprimes[i++] == 0) return false; + } } return x.millerRabin(t); } @@ -8866,7 +10123,7 @@ function bnIsProbablePrime(t) { function nbits(x) { var n = 1, - t; + t; if ((t = x >>> 16) != 0) { x = t; n += 16; @@ -8896,7 +10153,7 @@ function bnToMPI() { var result = ""; result += String.fromCharCode((size & 0xFF00) >> 8); result += String.fromCharCode(size & 0xFF); - result += util.bin2str(ba); + result += _util2.default.bin2str(ba); return result; } /* END of addition */ @@ -8907,10 +10164,11 @@ function bnpMillerRabin(t) { var k = n1.getLowestSetBit(); if (k <= 0) return false; var r = n1.shiftRight(k); - t = (t + 1) >> 1; + t = t + 1 >> 1; if (t > lowprimes.length) t = lowprimes.length; var a = nbi(); - var j, bases = []; + var j, + bases = []; for (var i = 0; i < t; ++i) { //Pick bases at random, instead of starting at 2 for (;;) { @@ -8932,8 +10190,6 @@ function bnpMillerRabin(t) { return true; } -var BigInteger = require('./jsbn.js'); - // protected BigInteger.prototype.chunkSize = bnpChunkSize; BigInteger.prototype.toRadix = bnpToRadix; @@ -8988,7 +10244,7 @@ BigInteger.prototype.toMPI = bnToMPI; // JSBN-specific extension BigInteger.prototype.square = bnSquare; -},{"../../util.js":76,"./jsbn.js":37}],38:[function(require,module,exports){ +},{"../../util.js":76}],38:[function(require,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -9015,28 +10271,48 @@ BigInteger.prototype.square = bnSquare; * @module crypto/public_key/rsa */ -var BigInteger = require('./jsbn.js'), - util = require('../../util.js'), - random = require('../random.js'), - config = require('../../config'); +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = RSA; + +var _jsbn = require('./jsbn.js'); + +var _jsbn2 = _interopRequireDefault(_jsbn); + +var _util = require('../../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _random = require('../random.js'); + +var _random2 = _interopRequireDefault(_random); + +var _config = require('../../config'); + +var _config2 = _interopRequireDefault(_config); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function SecureRandom() { function nextBytes(byteArray) { for (var n = 0; n < byteArray.length; n++) { - byteArray[n] = random.getSecureRandomOctet(); + byteArray[n] = _random2.default.getSecureRandomOctet(); } } this.nextBytes = nextBytes; } -var blinder = BigInteger.ZERO; -var unblinder = BigInteger.ZERO; +var blinder = _jsbn2.default.ZERO; +var unblinder = _jsbn2.default.ZERO; function blind(m, n, e) { if (unblinder.bitLength() === n.bitLength()) { unblinder = unblinder.square().mod(n); } else { - unblinder = random.getRandomBigIntegerInRange(BigInteger.TWO, n); + unblinder = _random2.default.getRandomBigIntegerInRange(_jsbn2.default.TWO, n); } blinder = unblinder.modInverse(n).modPow(e, n); return m.multiply(blinder).mod(n); @@ -9066,12 +10342,12 @@ function RSA() { * @return {BigInteger} The decrypted value of the message */ function decrypt(m, n, e, d, p, q, u) { - if (config.rsa_blinding) { + if (_config2.default.rsa_blinding) { m = blind(m, n, e); } - var xp = m.mod(p).modPow(d.mod(p.subtract(BigInteger.ONE)), p); - var xq = m.mod(q).modPow(d.mod(q.subtract(BigInteger.ONE)), q); - util.print_debug("rsa.js decrypt\nxpn:" + util.hexstrdump(xp.toMPI()) + "\nxqn:" + util.hexstrdump(xq.toMPI())); + var xp = m.mod(p).modPow(d.mod(p.subtract(_jsbn2.default.ONE)), p); + var xq = m.mod(q).modPow(d.mod(q.subtract(_jsbn2.default.ONE)), q); + _util2.default.print_debug("rsa.js decrypt\nxpn:" + _util2.default.hexstrdump(xp.toMPI()) + "\nxqn:" + _util2.default.hexstrdump(xq.toMPI())); var t = xq.subtract(xp); if (t[0] === 0) { @@ -9082,7 +10358,7 @@ function RSA() { t = t.multiply(u).mod(q); } t = t.multiply(p).add(xp); - if (config.rsa_blinding) { + if (_config2.default.rsa_blinding) { t = unblind(t, n); } return t; @@ -9110,7 +10386,7 @@ function RSA() { // "empty" RSA key constructor - function keyObject() { + function KeyObject() { this.n = null; this.e = 0; this.ee = null; @@ -9125,7 +10401,7 @@ function RSA() { // Generate a new random private key B bits long, using public expt E function generate(B, E) { - var webCrypto = util.getWebCrypto(); + var webCrypto = _util2.default.getWebCrypto(); // // Native RSA keygen using Web Crypto @@ -9145,8 +10421,7 @@ function RSA() { publicExponent: Euint8.subarray(0, 3) // take three bytes (max 65537) }; keys = webCrypto.generateKey(keyGenOpt, true, ['encrypt', 'decrypt']); - } - else { + } else { // current standard spec keyGenOpt = { name: 'RSASSA-PKCS1-v1_5', @@ -9156,14 +10431,15 @@ function RSA() { name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify' } }; - + keys = webCrypto.generateKey(keyGenOpt, true, ['sign', 'verify']); - if (!(typeof keys.then === 'function')) { // IE11 KeyOperation - keys = convertKeyOperation(keys, 'Error generating RSA key pair.'); + if (typeof keys.then !== 'function') { + // IE11 KeyOperation + keys = _util2.default.promisifyIE11Op(keys, 'Error generating RSA key pair.'); } } - return keys.then(exportKey).then(function(key) { + return keys.then(exportKey).then(function (key) { if (key instanceof ArrayBuffer) { // parse raw ArrayBuffer bytes to jwk/json (WebKit/Safari/IE11 quirk) return decodeKey(JSON.parse(String.fromCharCode.apply(null, new Uint8Array(key)))); @@ -9176,17 +10452,18 @@ function RSA() { // export the generated keys as JsonWebKey (JWK) // https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33 var key = webCrypto.exportKey('jwk', keypair.privateKey); - if (!(typeof key.then === 'function')) { // IE11 KeyOperation - key = convertKeyOperation(key, 'Error exporting RSA key pair.'); + if (typeof key.then !== 'function') { + // IE11 KeyOperation + key = _util2.default.promisifyIE11Op(key, 'Error exporting RSA key pair.'); } return key; } function decodeKey(jwk) { // map JWK parameters to local BigInteger type system - var key = new keyObject(); + var key = new KeyObject(); key.n = toBigInteger(jwk.n); - key.ee = new BigInteger(E, 16); + key.ee = new _jsbn2.default(E, 16); key.d = toBigInteger(jwk.d); key.p = toBigInteger(jwk.p); key.q = toBigInteger(jwk.q); @@ -9194,55 +10471,46 @@ function RSA() { function toBigInteger(base64url) { var base64 = base64url.replace(/\-/g, '+').replace(/_/g, '/'); - var hex = util.hexstrdump(atob(base64)); - return new BigInteger(hex, 16); + var hex = _util2.default.hexstrdump(atob(base64)); + return new _jsbn2.default(hex, 16); } return key; } - function convertKeyOperation(keyop, errmsg) { - return new Promise(function(resolve, reject) { - keyop.onerror = function (err) { - reject(new Error(errmsg)); - }; - keyop.oncomplete = function (e) { - resolve(e.target.result); - }; - }); - } - // // JS code // - return new Promise(function(resolve) { - var key = new keyObject(); + return new Promise(function (resolve) { + var key = new KeyObject(); var rng = new SecureRandom(); var qs = B >> 1; key.e = parseInt(E, 16); - key.ee = new BigInteger(E, 16); + key.ee = new _jsbn2.default(E, 16); for (;;) { for (;;) { - key.p = new BigInteger(B - qs, 1, rng); - if (key.p.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) === 0 && key.p.isProbablePrime(10)) + key.p = new _jsbn2.default(B - qs, 1, rng); + if (key.p.subtract(_jsbn2.default.ONE).gcd(key.ee).compareTo(_jsbn2.default.ONE) === 0 && key.p.isProbablePrime(10)) { break; + } } for (;;) { - key.q = new BigInteger(qs, 1, rng); - if (key.q.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) === 0 && key.q.isProbablePrime(10)) + key.q = new _jsbn2.default(qs, 1, rng); + if (key.q.subtract(_jsbn2.default.ONE).gcd(key.ee).compareTo(_jsbn2.default.ONE) === 0 && key.q.isProbablePrime(10)) { break; + } } if (key.p.compareTo(key.q) <= 0) { var t = key.p; key.p = key.q; key.q = t; } - var p1 = key.p.subtract(BigInteger.ONE); - var q1 = key.q.subtract(BigInteger.ONE); + var p1 = key.p.subtract(_jsbn2.default.ONE); + var q1 = key.q.subtract(_jsbn2.default.ONE); var phi = p1.multiply(q1); - if (phi.gcd(key.ee).compareTo(BigInteger.ONE) === 0) { + if (phi.gcd(key.ee).compareTo(_jsbn2.default.ONE) === 0) { key.n = key.p.multiply(key.q); key.d = key.ee.modInverse(phi); key.dmp1 = key.d.mod(p1); @@ -9261,53 +10529,65 @@ function RSA() { this.verify = verify; this.sign = sign; this.generate = generate; - this.keyObject = keyObject; + this.keyObject = KeyObject; } -module.exports = RSA; - -},{"../../config":17,"../../util.js":76,"../random.js":39,"./jsbn.js":37}],39:[function(require,module,exports){ +},{"../../config":19,"../../util.js":76,"../random.js":39,"./jsbn.js":37}],39:[function(require,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 +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // The GPG4Browsers crypto interface /** * @requires type/mpi + * @requires util * @module crypto/random */ -var type_mpi = require('../type/mpi.js'); -var nodeCrypto = null; +'use strict'; -if (typeof window === 'undefined') { - nodeCrypto = require('crypto'); -} +Object.defineProperty(exports, "__esModule", { + value: true +}); -module.exports = { +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + +var _mpi = require('../type/mpi.js'); + +var _mpi2 = _interopRequireDefault(_mpi); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var nodeCrypto = _util2.default.detectNode() && require('crypto'); + +exports.default = { /** - * Retrieve secure random byte string of the specified length + * Retrieve secure random byte array of the specified length * @param {Integer} length Length in bytes to generate - * @return {String} Random byte string + * @return {Uint8Array} Random byte array */ - getRandomBytes: function(length) { - var result = ''; + getRandomBytes: function getRandomBytes(length) { + var result = new Uint8Array(length); for (var i = 0; i < length; i++) { - result += String.fromCharCode(this.getSecureRandomOctet()); + result[i] = this.getSecureRandomOctet(); } return result; }, @@ -9318,22 +10598,22 @@ module.exports = { * @param {Integer} to Max of the random number (max 32bit) * @return {Integer} A secure random number */ - getSecureRandom: function(from, to) { + getSecureRandom: function getSecureRandom(from, to) { var randUint = this.getSecureRandomUint(); - var bits = ((to - from)).toString(2).length; - while ((randUint & (Math.pow(2, bits) - 1)) > (to - from)) { + var bits = (to - from).toString(2).length; + while ((randUint & Math.pow(2, bits) - 1) > to - from) { randUint = this.getSecureRandomUint(); } - return from + (Math.abs(randUint & (Math.pow(2, bits) - 1))); + return from + Math.abs(randUint & Math.pow(2, bits) - 1); }, - getSecureRandomOctet: function() { + getSecureRandomOctet: function getSecureRandomOctet() { var buf = new Uint8Array(1); this.getRandomValues(buf); return buf[0]; }, - getSecureRandomUint: function() { + getSecureRandomUint: function getSecureRandomUint() { var buf = new Uint8Array(4); var dv = new DataView(buf.buffer); this.getRandomValues(buf); @@ -9344,13 +10624,13 @@ module.exports = { * Helper routine which calls platform specific crypto random generator * @param {Uint8Array} buf */ - getRandomValues: function(buf) { + getRandomValues: function getRandomValues(buf) { if (!(buf instanceof Uint8Array)) { throw new Error('Invalid type: buf not an Uint8Array'); } if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) { window.crypto.getRandomValues(buf); - } else if (typeof window !== 'undefined' && typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') { + } else if (typeof window !== 'undefined' && _typeof(window.msCrypto) === 'object' && typeof window.msCrypto.getRandomValues === 'function') { window.msCrypto.getRandomValues(buf); } else if (nodeCrypto) { var bytes = nodeCrypto.randomBytes(buf.length); @@ -9367,26 +10647,23 @@ module.exports = { * @param {Integer} bits Bit length of the MPI to create * @return {BigInteger} Resulting big integer */ - getRandomBigInteger: function(bits) { + getRandomBigInteger: function getRandomBigInteger(bits) { if (bits < 1) { throw new Error('Illegal parameter value: bits < 1'); } var numBytes = Math.floor((bits + 7) / 8); - var randomBits = this.getRandomBytes(numBytes); + var randomBits = _util2.default.Uint8Array2str(this.getRandomBytes(numBytes)); if (bits % 8 > 0) { - randomBits = String.fromCharCode( - (Math.pow(2, bits % 8) - 1) & - randomBits.charCodeAt(0)) + - randomBits.substring(1); + randomBits = String.fromCharCode(Math.pow(2, bits % 8) - 1 & randomBits.charCodeAt(0)) + randomBits.substring(1); } - var mpi = new type_mpi(); + var mpi = new _mpi2.default(); mpi.fromBytes(randomBits); return mpi.toBigInteger(); }, - getRandomBigIntegerInRange: function(min, max) { + getRandomBigIntegerInRange: function getRandomBigIntegerInRange(min, max) { if (max.compareTo(min) <= 0) { throw new Error('Illegal parameter value: max <= min'); } @@ -9406,6 +10683,7 @@ module.exports = { /** * Buffer for secure random numbers */ + function RandomBuffer() { this.buffer = null; this.size = null; @@ -9415,7 +10693,7 @@ function RandomBuffer() { * Initialize buffer * @param {Integer} size size of buffer */ -RandomBuffer.prototype.init = function(size) { +RandomBuffer.prototype.init = function (size) { this.buffer = new Uint8Array(size); this.size = 0; }; @@ -9424,7 +10702,7 @@ RandomBuffer.prototype.init = function(size) { * Concat array of secure random numbers to buffer * @param {Uint8Array} buf */ -RandomBuffer.prototype.set = function(buf) { +RandomBuffer.prototype.set = function (buf) { if (!this.buffer) { throw new Error('RandomBuffer is not initialized'); } @@ -9444,7 +10722,7 @@ RandomBuffer.prototype.set = function(buf) { * Take numbers out of buffer and copy to array * @param {Uint8Array} buf the destination array */ -RandomBuffer.prototype.get = function(buf) { +RandomBuffer.prototype.get = function (buf) { if (!this.buffer) { throw new Error('RandomBuffer is not initialized'); } @@ -9461,57 +10739,77 @@ RandomBuffer.prototype.get = function(buf) { } }; -},{"../type/mpi.js":74,"crypto":"crypto"}],40:[function(require,module,exports){ +},{"../type/mpi.js":74,"../util.js":76,"crypto":"crypto"}],40:[function(require,module,exports){ /** + * @requires util * @requires crypto/hash * @requires crypto/pkcs1 * @requires crypto/public_key * @module crypto/signature */ -var publicKey = require('./public_key'), - pkcs1 = require('./pkcs1.js'), - hashModule = require('./hash'); +'use strict'; -module.exports = { +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _util = require('../util'); + +var _util2 = _interopRequireDefault(_util); + +var _public_key = require('./public_key'); + +var _public_key2 = _interopRequireDefault(_public_key); + +var _pkcs = require('./pkcs1.js'); + +var _pkcs2 = _interopRequireDefault(_pkcs); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = { /** - * + * * @param {module:enums.publicKey} algo public Key algorithm * @param {module:enums.hash} hash_algo Hash algorithm * @param {Array} msg_MPIs Signature multiprecision integers - * @param {Array} publickey_MPIs Public key multiprecision integers - * @param {String} data Data on where the signature was computed on. + * @param {Array} publickey_MPIs Public key multiprecision integers + * @param {Uint8Array} data Data on where the signature was computed on. * @return {Boolean} true if signature (sig_data was equal to data over hash) */ - verify: function(algo, hash_algo, msg_MPIs, publickey_MPIs, data) { + verify: function verify(algo, hash_algo, msg_MPIs, publickey_MPIs, data) { + var m; + + data = _util2.default.Uint8Array2str(data); switch (algo) { case 1: - // RSA (Encrypt or Sign) [HAC] + // RSA (Encrypt or Sign) [HAC] case 2: - // RSA Encrypt-Only [HAC] + // RSA Encrypt-Only [HAC] case 3: // RSA Sign-Only [HAC] - var rsa = new publicKey.rsa(); + var rsa = new _public_key2.default.rsa(); var n = publickey_MPIs[0].toBigInteger(); var k = publickey_MPIs[0].byteLength(); var e = publickey_MPIs[1].toBigInteger(); - var m = msg_MPIs[0].toBigInteger(); + m = msg_MPIs[0].toBigInteger(); var EM = rsa.verify(m, e, n); - var EM2 = pkcs1.emsa.encode(hash_algo, data, k); + var EM2 = _pkcs2.default.emsa.encode(hash_algo, data, k); return EM.compareTo(EM2) === 0; case 16: // Elgamal (Encrypt-Only) [ELGAMAL] [HAC] throw new Error("signing with Elgamal is not defined in the OpenPGP standard."); case 17: // DSA (Digital Signature Algorithm) [FIPS186] [HAC] - var dsa = new publicKey.dsa(); + var dsa = new _public_key2.default.dsa(); var s1 = msg_MPIs[0].toBigInteger(); var s2 = msg_MPIs[1].toBigInteger(); var p = publickey_MPIs[0].toBigInteger(); var q = publickey_MPIs[1].toBigInteger(); var g = publickey_MPIs[2].toBigInteger(); var y = publickey_MPIs[3].toBigInteger(); - var m = data; + m = data; var dopublic = dsa.verify(hash_algo, s1, s2, m, p, q, g, y); return dopublic.compareTo(s1) === 0; default: @@ -9523,45 +10821,44 @@ module.exports = { * Create a signature on data using the specified algorithm * @param {module:enums.hash} hash_algo hash Algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4}) * @param {module:enums.publicKey} algo Asymmetric cipher algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1}) - * @param {Array} publicMPIs Public key multiprecision integers - * of the private key - * @param {Array} secretMPIs Private key multiprecision + * @param {Array} publicMPIs Public key multiprecision integers + * of the private key + * @param {Array} secretMPIs Private key multiprecision * integers which is used to sign the data - * @param {String} data Data to be signed + * @param {Uint8Array} data Data to be signed * @return {Array} */ - sign: function(hash_algo, algo, keyIntegers, data) { + sign: function sign(hash_algo, algo, keyIntegers, data) { + + data = _util2.default.Uint8Array2str(data); var m; switch (algo) { case 1: - // RSA (Encrypt or Sign) [HAC] + // RSA (Encrypt or Sign) [HAC] case 2: - // RSA Encrypt-Only [HAC] + // RSA Encrypt-Only [HAC] case 3: // RSA Sign-Only [HAC] - var rsa = new publicKey.rsa(); + var rsa = new _public_key2.default.rsa(); var d = keyIntegers[2].toBigInteger(); var n = keyIntegers[0].toBigInteger(); - m = pkcs1.emsa.encode(hash_algo, - data, keyIntegers[0].byteLength()); - - return rsa.sign(m, d, n).toMPI(); + m = _pkcs2.default.emsa.encode(hash_algo, data, keyIntegers[0].byteLength()); + return _util2.default.str2Uint8Array(rsa.sign(m, d, n).toMPI()); case 17: // DSA (Digital Signature Algorithm) [FIPS186] [HAC] - var dsa = new publicKey.dsa(); + var dsa = new _public_key2.default.dsa(); var p = keyIntegers[0].toBigInteger(); var q = keyIntegers[1].toBigInteger(); var g = keyIntegers[2].toBigInteger(); - var y = keyIntegers[3].toBigInteger(); var x = keyIntegers[4].toBigInteger(); m = data; var result = dsa.sign(hash_algo, m, g, p, q, x); - return result[0].toString() + result[1].toString(); + return _util2.default.str2Uint8Array(result[0].toString() + result[1].toString()); case 16: // Elgamal (Encrypt-Only) [ELGAMAL] [HAC] throw new Error('Signing with Elgamal is not defined in the OpenPGP standard.'); @@ -9571,7 +10868,7 @@ module.exports = { } }; -},{"./hash":28,"./pkcs1.js":33,"./public_key":36}],41:[function(require,module,exports){ +},{"../util":76,"./pkcs1.js":33,"./public_key":36}],41:[function(require,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -9596,9 +10893,25 @@ module.exports = { * @module encoding/armor */ -var base64 = require('./base64.js'), - enums = require('../enums.js'), - config = require('../config'); +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _base = require('./base64.js'); + +var _base2 = _interopRequireDefault(_base); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _config = require('../config'); + +var _config2 = _interopRequireDefault(_config); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Finds out which Ascii Armoring type is used. Throws error if unknown type. @@ -9624,41 +10937,37 @@ function getType(text) { // Used for multi-part messages, where the armor is split amongst Y // parts, and this is the Xth part out of Y. if (/MESSAGE, PART \d+\/\d+/.test(header[1])) { - return enums.armor.multipart_section; + return _enums2.default.armor.multipart_section; } else - // BEGIN PGP MESSAGE, PART X - // Used for multi-part messages, where this is the Xth part of an - // unspecified number of parts. Requires the MESSAGE-ID Armor - // Header to be used. - if (/MESSAGE, PART \d+/.test(header[1])) { - return enums.armor.multipart_last; - - } else - // BEGIN PGP SIGNATURE - // Used for detached signatures, OpenPGP/MIME signatures, and - // cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE - // for detached signatures. - if (/SIGNED MESSAGE/.test(header[1])) { - return enums.armor.signed; - - } else - // BEGIN PGP MESSAGE - // Used for signed, encrypted, or compressed files. - if (/MESSAGE/.test(header[1])) { - return enums.armor.message; - - } else - // BEGIN PGP PUBLIC KEY BLOCK - // Used for armoring public keys. - if (/PUBLIC KEY BLOCK/.test(header[1])) { - return enums.armor.public_key; - - } else - // BEGIN PGP PRIVATE KEY BLOCK - // Used for armoring private keys. - if (/PRIVATE KEY BLOCK/.test(header[1])) { - return enums.armor.private_key; - } + // BEGIN PGP MESSAGE, PART X + // Used for multi-part messages, where this is the Xth part of an + // unspecified number of parts. Requires the MESSAGE-ID Armor + // Header to be used. + if (/MESSAGE, PART \d+/.test(header[1])) { + return _enums2.default.armor.multipart_last; + } else + // BEGIN PGP SIGNATURE + // Used for detached signatures, OpenPGP/MIME signatures, and + // cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE + // for detached signatures. + if (/SIGNED MESSAGE/.test(header[1])) { + return _enums2.default.armor.signed; + } else + // BEGIN PGP MESSAGE + // Used for signed, encrypted, or compressed files. + if (/MESSAGE/.test(header[1])) { + return _enums2.default.armor.message; + } else + // BEGIN PGP PUBLIC KEY BLOCK + // Used for armoring public keys. + if (/PUBLIC KEY BLOCK/.test(header[1])) { + return _enums2.default.armor.public_key; + } else + // BEGIN PGP PRIVATE KEY BLOCK + // Used for armoring private keys. + if (/PRIVATE KEY BLOCK/.test(header[1])) { + return _enums2.default.armor.private_key; + } } /** @@ -9670,18 +10979,16 @@ function getType(text) { */ function addheader() { var result = ""; - if (config.show_version) { - result += "Version: " + config.versionstring + '\r\n'; + if (_config2.default.show_version) { + result += "Version: " + _config2.default.versionstring + '\r\n'; } - if (config.show_comment) { - result += "Comment: " + config.commentstring + '\r\n'; + if (_config2.default.show_comment) { + result += "Comment: " + _config2.default.commentstring + '\r\n'; } result += '\r\n'; return result; } - - /** * Calculates a checksum over the given data and returns it base64 encoded * @param {String} data Data to create a CRC-24 checksum for @@ -9689,10 +10996,8 @@ function addheader() { */ function getCheckSum(data) { var c = createcrc24(data); - var str = "" + String.fromCharCode(c >> 16) + - String.fromCharCode((c >> 8) & 0xFF) + - String.fromCharCode(c & 0xFF); - return base64.encode(str); + var bytes = new Uint8Array([c >> 16, c >> 8 & 0xFF, c & 0xFF]); + return _base2.default.encode(bytes); } /** @@ -9705,74 +11010,41 @@ function getCheckSum(data) { function verifyCheckSum(data, checksum) { var c = getCheckSum(data); var d = checksum; - return c[0] == d[0] && c[1] == d[1] && c[2] == d[2] && c[3] == d[3]; + return c[0] === d[0] && c[1] === d[1] && c[2] === d[2] && c[3] === d[3]; } /** * Internal function to calculate a CRC-24 checksum over a given string (data) * @param {String} data Data to create a CRC-24 checksum for * @return {Integer} The CRC-24 checksum as number */ -var crc_table = [ - 0x00000000, 0x00864cfb, 0x018ad50d, 0x010c99f6, 0x0393e6e1, 0x0315aa1a, 0x021933ec, 0x029f7f17, 0x07a18139, - 0x0727cdc2, 0x062b5434, 0x06ad18cf, 0x043267d8, 0x04b42b23, 0x05b8b2d5, 0x053efe2e, 0x0fc54e89, 0x0f430272, - 0x0e4f9b84, 0x0ec9d77f, 0x0c56a868, 0x0cd0e493, 0x0ddc7d65, 0x0d5a319e, 0x0864cfb0, 0x08e2834b, 0x09ee1abd, - 0x09685646, 0x0bf72951, 0x0b7165aa, 0x0a7dfc5c, 0x0afbb0a7, 0x1f0cd1e9, 0x1f8a9d12, 0x1e8604e4, 0x1e00481f, - 0x1c9f3708, 0x1c197bf3, 0x1d15e205, 0x1d93aefe, 0x18ad50d0, 0x182b1c2b, 0x192785dd, 0x19a1c926, 0x1b3eb631, - 0x1bb8faca, 0x1ab4633c, 0x1a322fc7, 0x10c99f60, 0x104fd39b, 0x11434a6d, 0x11c50696, 0x135a7981, 0x13dc357a, - 0x12d0ac8c, 0x1256e077, 0x17681e59, 0x17ee52a2, 0x16e2cb54, 0x166487af, 0x14fbf8b8, 0x147db443, 0x15712db5, - 0x15f7614e, 0x3e19a3d2, 0x3e9fef29, 0x3f9376df, 0x3f153a24, 0x3d8a4533, 0x3d0c09c8, 0x3c00903e, 0x3c86dcc5, - 0x39b822eb, 0x393e6e10, 0x3832f7e6, 0x38b4bb1d, 0x3a2bc40a, 0x3aad88f1, 0x3ba11107, 0x3b275dfc, 0x31dced5b, - 0x315aa1a0, - 0x30563856, 0x30d074ad, 0x324f0bba, 0x32c94741, 0x33c5deb7, 0x3343924c, 0x367d6c62, 0x36fb2099, 0x37f7b96f, - 0x3771f594, 0x35ee8a83, 0x3568c678, 0x34645f8e, 0x34e21375, 0x2115723b, 0x21933ec0, 0x209fa736, 0x2019ebcd, - 0x228694da, 0x2200d821, 0x230c41d7, 0x238a0d2c, 0x26b4f302, 0x2632bff9, 0x273e260f, 0x27b86af4, 0x252715e3, - 0x25a15918, 0x24adc0ee, 0x242b8c15, 0x2ed03cb2, 0x2e567049, 0x2f5ae9bf, 0x2fdca544, 0x2d43da53, 0x2dc596a8, - 0x2cc90f5e, 0x2c4f43a5, 0x2971bd8b, 0x29f7f170, 0x28fb6886, 0x287d247d, 0x2ae25b6a, 0x2a641791, 0x2b688e67, - 0x2beec29c, 0x7c3347a4, 0x7cb50b5f, 0x7db992a9, 0x7d3fde52, 0x7fa0a145, 0x7f26edbe, 0x7e2a7448, 0x7eac38b3, - 0x7b92c69d, 0x7b148a66, 0x7a181390, 0x7a9e5f6b, 0x7801207c, 0x78876c87, 0x798bf571, 0x790db98a, 0x73f6092d, - 0x737045d6, 0x727cdc20, 0x72fa90db, 0x7065efcc, 0x70e3a337, 0x71ef3ac1, 0x7169763a, 0x74578814, 0x74d1c4ef, - 0x75dd5d19, 0x755b11e2, 0x77c46ef5, 0x7742220e, 0x764ebbf8, 0x76c8f703, 0x633f964d, 0x63b9dab6, 0x62b54340, - 0x62330fbb, - 0x60ac70ac, 0x602a3c57, 0x6126a5a1, 0x61a0e95a, 0x649e1774, 0x64185b8f, 0x6514c279, 0x65928e82, 0x670df195, - 0x678bbd6e, 0x66872498, 0x66016863, 0x6cfad8c4, 0x6c7c943f, 0x6d700dc9, 0x6df64132, 0x6f693e25, 0x6fef72de, - 0x6ee3eb28, 0x6e65a7d3, 0x6b5b59fd, 0x6bdd1506, 0x6ad18cf0, 0x6a57c00b, 0x68c8bf1c, 0x684ef3e7, 0x69426a11, - 0x69c426ea, 0x422ae476, 0x42aca88d, 0x43a0317b, 0x43267d80, 0x41b90297, 0x413f4e6c, 0x4033d79a, 0x40b59b61, - 0x458b654f, 0x450d29b4, 0x4401b042, 0x4487fcb9, 0x461883ae, 0x469ecf55, 0x479256a3, 0x47141a58, 0x4defaaff, - 0x4d69e604, 0x4c657ff2, 0x4ce33309, 0x4e7c4c1e, 0x4efa00e5, 0x4ff69913, 0x4f70d5e8, 0x4a4e2bc6, 0x4ac8673d, - 0x4bc4fecb, 0x4b42b230, 0x49ddcd27, 0x495b81dc, 0x4857182a, 0x48d154d1, 0x5d26359f, 0x5da07964, 0x5cace092, - 0x5c2aac69, 0x5eb5d37e, 0x5e339f85, 0x5f3f0673, 0x5fb94a88, 0x5a87b4a6, 0x5a01f85d, 0x5b0d61ab, 0x5b8b2d50, - 0x59145247, 0x59921ebc, 0x589e874a, 0x5818cbb1, 0x52e37b16, 0x526537ed, 0x5369ae1b, 0x53efe2e0, 0x51709df7, - 0x51f6d10c, - 0x50fa48fa, 0x507c0401, 0x5542fa2f, 0x55c4b6d4, 0x54c82f22, 0x544e63d9, 0x56d11cce, 0x56575035, 0x575bc9c3, - 0x57dd8538 -]; +var crc_table = [0x00000000, 0x00864cfb, 0x018ad50d, 0x010c99f6, 0x0393e6e1, 0x0315aa1a, 0x021933ec, 0x029f7f17, 0x07a18139, 0x0727cdc2, 0x062b5434, 0x06ad18cf, 0x043267d8, 0x04b42b23, 0x05b8b2d5, 0x053efe2e, 0x0fc54e89, 0x0f430272, 0x0e4f9b84, 0x0ec9d77f, 0x0c56a868, 0x0cd0e493, 0x0ddc7d65, 0x0d5a319e, 0x0864cfb0, 0x08e2834b, 0x09ee1abd, 0x09685646, 0x0bf72951, 0x0b7165aa, 0x0a7dfc5c, 0x0afbb0a7, 0x1f0cd1e9, 0x1f8a9d12, 0x1e8604e4, 0x1e00481f, 0x1c9f3708, 0x1c197bf3, 0x1d15e205, 0x1d93aefe, 0x18ad50d0, 0x182b1c2b, 0x192785dd, 0x19a1c926, 0x1b3eb631, 0x1bb8faca, 0x1ab4633c, 0x1a322fc7, 0x10c99f60, 0x104fd39b, 0x11434a6d, 0x11c50696, 0x135a7981, 0x13dc357a, 0x12d0ac8c, 0x1256e077, 0x17681e59, 0x17ee52a2, 0x16e2cb54, 0x166487af, 0x14fbf8b8, 0x147db443, 0x15712db5, 0x15f7614e, 0x3e19a3d2, 0x3e9fef29, 0x3f9376df, 0x3f153a24, 0x3d8a4533, 0x3d0c09c8, 0x3c00903e, 0x3c86dcc5, 0x39b822eb, 0x393e6e10, 0x3832f7e6, 0x38b4bb1d, 0x3a2bc40a, 0x3aad88f1, 0x3ba11107, 0x3b275dfc, 0x31dced5b, 0x315aa1a0, 0x30563856, 0x30d074ad, 0x324f0bba, 0x32c94741, 0x33c5deb7, 0x3343924c, 0x367d6c62, 0x36fb2099, 0x37f7b96f, 0x3771f594, 0x35ee8a83, 0x3568c678, 0x34645f8e, 0x34e21375, 0x2115723b, 0x21933ec0, 0x209fa736, 0x2019ebcd, 0x228694da, 0x2200d821, 0x230c41d7, 0x238a0d2c, 0x26b4f302, 0x2632bff9, 0x273e260f, 0x27b86af4, 0x252715e3, 0x25a15918, 0x24adc0ee, 0x242b8c15, 0x2ed03cb2, 0x2e567049, 0x2f5ae9bf, 0x2fdca544, 0x2d43da53, 0x2dc596a8, 0x2cc90f5e, 0x2c4f43a5, 0x2971bd8b, 0x29f7f170, 0x28fb6886, 0x287d247d, 0x2ae25b6a, 0x2a641791, 0x2b688e67, 0x2beec29c, 0x7c3347a4, 0x7cb50b5f, 0x7db992a9, 0x7d3fde52, 0x7fa0a145, 0x7f26edbe, 0x7e2a7448, 0x7eac38b3, 0x7b92c69d, 0x7b148a66, 0x7a181390, 0x7a9e5f6b, 0x7801207c, 0x78876c87, 0x798bf571, 0x790db98a, 0x73f6092d, 0x737045d6, 0x727cdc20, 0x72fa90db, 0x7065efcc, 0x70e3a337, 0x71ef3ac1, 0x7169763a, 0x74578814, 0x74d1c4ef, 0x75dd5d19, 0x755b11e2, 0x77c46ef5, 0x7742220e, 0x764ebbf8, 0x76c8f703, 0x633f964d, 0x63b9dab6, 0x62b54340, 0x62330fbb, 0x60ac70ac, 0x602a3c57, 0x6126a5a1, 0x61a0e95a, 0x649e1774, 0x64185b8f, 0x6514c279, 0x65928e82, 0x670df195, 0x678bbd6e, 0x66872498, 0x66016863, 0x6cfad8c4, 0x6c7c943f, 0x6d700dc9, 0x6df64132, 0x6f693e25, 0x6fef72de, 0x6ee3eb28, 0x6e65a7d3, 0x6b5b59fd, 0x6bdd1506, 0x6ad18cf0, 0x6a57c00b, 0x68c8bf1c, 0x684ef3e7, 0x69426a11, 0x69c426ea, 0x422ae476, 0x42aca88d, 0x43a0317b, 0x43267d80, 0x41b90297, 0x413f4e6c, 0x4033d79a, 0x40b59b61, 0x458b654f, 0x450d29b4, 0x4401b042, 0x4487fcb9, 0x461883ae, 0x469ecf55, 0x479256a3, 0x47141a58, 0x4defaaff, 0x4d69e604, 0x4c657ff2, 0x4ce33309, 0x4e7c4c1e, 0x4efa00e5, 0x4ff69913, 0x4f70d5e8, 0x4a4e2bc6, 0x4ac8673d, 0x4bc4fecb, 0x4b42b230, 0x49ddcd27, 0x495b81dc, 0x4857182a, 0x48d154d1, 0x5d26359f, 0x5da07964, 0x5cace092, 0x5c2aac69, 0x5eb5d37e, 0x5e339f85, 0x5f3f0673, 0x5fb94a88, 0x5a87b4a6, 0x5a01f85d, 0x5b0d61ab, 0x5b8b2d50, 0x59145247, 0x59921ebc, 0x589e874a, 0x5818cbb1, 0x52e37b16, 0x526537ed, 0x5369ae1b, 0x53efe2e0, 0x51709df7, 0x51f6d10c, 0x50fa48fa, 0x507c0401, 0x5542fa2f, 0x55c4b6d4, 0x54c82f22, 0x544e63d9, 0x56d11cce, 0x56575035, 0x575bc9c3, 0x57dd8538]; function createcrc24(input) { var crc = 0xB704CE; var index = 0; - while ((input.length - index) > 16) { - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 1)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 2)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 3)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 4)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 5)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 6)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 7)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 8)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 9)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 10)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 11)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 12)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 13)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 14)) & 0xff]; - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index + 15)) & 0xff]; + while (input.length - index > 16) { + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 1]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 2]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 3]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 4]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 5]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 6]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 7]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 8]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 9]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 10]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 11]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 12]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 13]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 14]) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index + 15]) & 0xff]; index += 16; } for (var j = index; j < input.length; j++) { - crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index++)) & 0xff]; + crc = crc << 8 ^ crc_table[(crc >> 16 ^ input[index++]) & 0xff]; } return crc & 0xffffff; } @@ -9867,16 +11139,16 @@ function dearmor(text) { var result, checksum, msg; - if (text.search(reSplit) != splittext[0].length) { + if (text.search(reSplit) !== splittext[0].length) { indexBase = 0; } - if (type != 2) { + if (type !== 2) { msg = splitHeaders(splittext[indexBase]); var msg_sum = splitChecksum(msg.body); result = { - data: base64.decode(msg_sum.body), + data: _base2.default.decode(msg_sum.body), headers: msg.headers, type: type }; @@ -9891,7 +11163,7 @@ function dearmor(text) { result = { text: msg.body.replace(/\n$/, '').replace(/\n/g, "\r\n"), - data: base64.decode(sig_sum.body), + data: _base2.default.decode(sig_sum.body), headers: msg.headers, type: type }; @@ -9902,10 +11174,7 @@ function dearmor(text) { checksum = checksum.substr(0, 4); if (!verifyCheckSum(result.data, checksum)) { - throw new Error("Ascii armor integrity check on message failed: '" + - checksum + - "' should be '" + - getCheckSum(result.data) + "'"); + throw new Error("Ascii armor integrity check on message failed: '" + checksum + "' should be '" + getCheckSum(result.data) + "'"); } verifyHeaders(result.headers); @@ -9913,7 +11182,6 @@ function dearmor(text) { return result; } - /** * Armor an OpenPGP binary packet block * @param {Integer} messagetype type of the message @@ -9926,48 +11194,48 @@ function dearmor(text) { function armor(messagetype, body, partindex, parttotal) { var result = []; switch (messagetype) { - case enums.armor.multipart_section: + case _enums2.default.armor.multipart_section: result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n"); result.push(addheader()); - result.push(base64.encode(body)); + result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n"); break; - case enums.armor.multipart_last: + case _enums2.default.armor.multipart_last: result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n"); result.push(addheader()); - result.push(base64.encode(body)); + result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP MESSAGE, PART " + partindex + "-----\r\n"); break; - case enums.armor.signed: + case _enums2.default.armor.signed: result.push("\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\n"); result.push("Hash: " + body.hash + "\r\n\r\n"); result.push(body.text.replace(/\n-/g, "\n- -")); result.push("\r\n-----BEGIN PGP SIGNATURE-----\r\n"); result.push(addheader()); - result.push(base64.encode(body.data)); + result.push(_base2.default.encode(body.data)); result.push("\r\n=" + getCheckSum(body.data) + "\r\n"); result.push("-----END PGP SIGNATURE-----\r\n"); break; - case enums.armor.message: + case _enums2.default.armor.message: result.push("-----BEGIN PGP MESSAGE-----\r\n"); result.push(addheader()); - result.push(base64.encode(body)); + result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP MESSAGE-----\r\n"); break; - case enums.armor.public_key: + case _enums2.default.armor.public_key: result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n"); result.push(addheader()); - result.push(base64.encode(body)); + result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n"); break; - case enums.armor.private_key: + case _enums2.default.armor.private_key: result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n"); result.push(addheader()); - result.push(base64.encode(body)); + result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP PRIVATE KEY BLOCK-----\r\n"); break; @@ -9976,20 +11244,20 @@ function armor(messagetype, body, partindex, parttotal) { return result.join(''); } -module.exports = { +exports.default = { encode: armor, decode: dearmor }; -},{"../config":17,"../enums.js":43,"./base64.js":42}],42:[function(require,module,exports){ +},{"../config":19,"../enums.js":43,"./base64.js":42}],42:[function(require,module,exports){ /* OpenPGP radix-64/base64 string encoding/decoding * Copyright 2005 Herbert Hanewinkel, www.haneWIN.de * version 1.0, check www.haneWIN.de for the latest version * - * This software is provided as-is, without express or implied warranty. + * This software is provided as-is, without express or implied warranty. * Permission to use, copy, modify, distribute or sell this software, with or * without fee, for any purpose and by any individual or organization, is hereby - * granted, provided that the above copyright notice and this paragraph appear + * granted, provided that the above copyright notice and this paragraph appear * in all copies. Distribution as a part of an application or binary must * include the above copyright notice in the documentation and/or other materials * provided with the application or distribution. @@ -9999,11 +11267,16 @@ module.exports = { * @module encoding/base64 */ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); var b64s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; /** - * Convert binary string to radix-64 - * @param {String} t binary string to convert + * Convert binary array to radix-64 + * @param {Uint8Array} t Uint8Array to convert * @returns {string} radix-64 version of input string * @static */ @@ -10016,52 +11289,56 @@ function s2r(t, o) { var tl = t.length; for (n = 0; n < tl; n++) { - c = t.charCodeAt(n); + c = t[n]; if (s === 0) { - r.push(b64s.charAt((c >> 2) & 63)); + r.push(b64s.charAt(c >> 2 & 63)); a = (c & 3) << 4; - } else if (s == 1) { - r.push(b64s.charAt((a | (c >> 4) & 15))); + } else if (s === 1) { + r.push(b64s.charAt(a | c >> 4 & 15)); a = (c & 15) << 2; - } else if (s == 2) { - r.push(b64s.charAt(a | ((c >> 6) & 3))); + } else if (s === 2) { + r.push(b64s.charAt(a | c >> 6 & 3)); l += 1; - if ((l % 60) === 0) + if (l % 60 === 0) { r.push("\n"); + } r.push(b64s.charAt(c & 63)); } l += 1; - if ((l % 60) === 0) + if (l % 60 === 0) { r.push("\n"); + } s += 1; - if (s == 3) + if (s === 3) { s = 0; + } } if (s > 0) { r.push(b64s.charAt(a)); l += 1; - if ((l % 60) === 0) + if (l % 60 === 0) { r.push("\n"); + } r.push('='); l += 1; } - if (s == 1) { - if ((l % 60) === 0) + if (s === 1) { + if (l % 60 === 0) { r.push("\n"); + } r.push('='); } - if (o) - { + if (o) { return; } return r.join(''); } /** - * Convert radix-64 to binary string + * Convert radix-64 to binary array * @param {String} t radix-64 string to convert - * @returns {string} binary version of input string + * @returns {Uint8Array} binary array version of input string * @static */ function r2s(t) { @@ -10075,16 +11352,17 @@ function r2s(t) { for (n = 0; n < tl; n++) { c = b64s.indexOf(t.charAt(n)); if (c >= 0) { - if (s) - r.push(String.fromCharCode(a | (c >> (6 - s)) & 255)); - s = (s + 2) & 7; - a = (c << s) & 255; + if (s) { + r.push(a | c >> 6 - s & 255); + } + s = s + 2 & 7; + a = c << s & 255; } } - return r.join(''); + return new Uint8Array(r); } -module.exports = { +exports.default = { encode: s2r, decode: r2s }; @@ -10096,7 +11374,10 @@ module.exports = { * @module enums */ -module.exports = { +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = { /** A string to key specifier type * @enum {Integer} @@ -10202,7 +11483,6 @@ module.exports = { utf8: 'u'.charCodeAt() }, - /** One pass signature packet type * @enum {Integer} * @readonly @@ -10371,10 +11651,10 @@ module.exports = { * @readonly */ keyStatus: { - invalid: 0, - expired: 1, - revoked: 2, - valid: 3, + invalid: 0, + expired: 1, + revoked: 2, + valid: 3, no_self_cert: 4 }, @@ -10392,22 +11672,29 @@ module.exports = { }, /** Asserts validity and converts from string/integer to integer. */ - write: function(type, e) { - if (typeof e == 'number') { + 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.'); + } else { + throw new Error('Invalid enum value.'); + } }, + /** Converts from an integer to string. */ - read: function(type, e) { - for (var i in type) - if (type[i] == e) return i; + read: function read(type, e) { + for (var i in type) { + if (type[i] === parseInt(e)) { + return i; + } + } throw new Error('Invalid enum value.'); } + }; },{}],44:[function(require,module,exports){ @@ -10428,16 +11715,23 @@ module.exports = { // 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'; -/** - * This class implements a client for the OpenPGP HTTP Keyserver Protocol (HKP) - * in order to lookup and upload keys on standard public key servers. - * @module hkp/hkp - */ -module.exports = HKP; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = HKP; -var config = require('../config'); +var _config = require('./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. @@ -10446,7 +11740,7 @@ var config = require('../config'); * the protocol to use e.g. https://pgp.mit.edu */ function HKP(keyServerBaseUrl) { - this._baseUrl = keyServerBaseUrl ? keyServerBaseUrl : config.keyserver; + this._baseUrl = keyServerBaseUrl ? keyServerBaseUrl : _config2.default.keyserver; this._fetch = typeof window !== 'undefined' ? window.fetch : require('node-fetch'); } @@ -10457,9 +11751,9 @@ function HKP(keyServerBaseUrl) { * or email address. * @return {Promise} The ascii armored public key. */ -HKP.prototype.lookup = function(options) { +HKP.prototype.lookup = function (options) { var uri = this._baseUrl + '/pks/lookup?op=get&options=mr&search=', - fetch = this._fetch; + fetch = this._fetch; if (options.keyId) { uri += '0x' + encodeURIComponent(options.keyId); @@ -10469,12 +11763,11 @@ HKP.prototype.lookup = function(options) { throw new Error('You must provide a query parameter!'); } - return fetch(uri).then(function(response) { + return fetch(uri).then(function (response) { if (response.status === 200) { return response.text(); } - - }).then(function(publicKeyArmored) { + }).then(function (publicKeyArmored) { if (!publicKeyArmored || publicKeyArmored.indexOf('-----END PGP PUBLIC KEY BLOCK-----') < 0) { return; } @@ -10487,9 +11780,9 @@ HKP.prototype.lookup = function(options) { * @param {String} publicKeyArmored An ascii armored public key to be uploaded. * @return {Promise} */ -HKP.prototype.upload = function(publicKeyArmored) { +HKP.prototype.upload = function (publicKeyArmored) { var uri = this._baseUrl + '/pks/add', - fetch = this._fetch; + fetch = this._fetch; return fetch(uri, { method: 'post', @@ -10499,94 +11792,203 @@ HKP.prototype.upload = function(publicKeyArmored) { body: 'keytext=' + encodeURIComponent(publicKeyArmored) }); }; -},{"../config":17,"node-fetch":"node-fetch"}],45:[function(require,module,exports){ -/** - * @see module:hkp/hkp - * @module hkp - */ -module.exports = require('./hkp.js'); -},{"./hkp.js":44}],46:[function(require,module,exports){ +},{"./config":19,"node-fetch":"node-fetch"}],45:[function(require,module,exports){ 'use strict'; -module.exports = require('./openpgp.js'); +/** + * Export high level api as default. + * Usage: + * + * import openpgp from 'openpgp.js' + * openpgp.encryptMessage(keys, text) + */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.HKP = exports.AsyncProxy = exports.Keyring = exports.crypto = exports.config = exports.enums = exports.armor = exports.Keyid = exports.S2K = exports.MPI = exports.packet = exports.util = exports.cleartext = exports.message = exports.key = undefined; + +var _openpgp = require('./openpgp'); + +var _loop = function _loop(_key3) { + if (_key3 === "default") return 'continue'; + Object.defineProperty(exports, _key3, { + enumerable: true, + get: function get() { + return _openpgp[_key3]; + } + }); +}; + +for (var _key3 in _openpgp) { + var _ret = _loop(_key3); + + if (_ret === 'continue') continue; +} + +var _util = require('./util'); + +Object.defineProperty(exports, 'util', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_util).default; + } +}); + +var _packet = require('./packet'); + +Object.defineProperty(exports, 'packet', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_packet).default; + } +}); + +var _mpi = require('./type/mpi'); + +Object.defineProperty(exports, 'MPI', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_mpi).default; + } +}); + +var _s2k = require('./type/s2k'); + +Object.defineProperty(exports, 'S2K', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_s2k).default; + } +}); + +var _keyid = require('./type/keyid'); + +Object.defineProperty(exports, 'Keyid', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_keyid).default; + } +}); + +var _armor = require('./encoding/armor'); + +Object.defineProperty(exports, 'armor', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_armor).default; + } +}); + +var _enums = require('./enums'); + +Object.defineProperty(exports, 'enums', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_enums).default; + } +}); + +var _config = require('./config/config'); + +Object.defineProperty(exports, 'config', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_config).default; + } +}); + +var _crypto = require('./crypto'); + +Object.defineProperty(exports, 'crypto', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_crypto).default; + } +}); + +var _keyring = require('./keyring'); + +Object.defineProperty(exports, 'Keyring', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_keyring).default; + } +}); + +var _async_proxy = require('./worker/async_proxy'); + +Object.defineProperty(exports, 'AsyncProxy', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_async_proxy).default; + } +}); + +var _hkp = require('./hkp'); + +Object.defineProperty(exports, 'HKP', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_hkp).default; + } +}); + +var openpgp = _interopRequireWildcard(_openpgp); + +var _key2 = require('./key'); + +var keyMod = _interopRequireWildcard(_key2); + +var _message = require('./message'); + +var messageMod = _interopRequireWildcard(_message); + +var _cleartext = require('./cleartext'); + +var cleartextMod = _interopRequireWildcard(_cleartext); + +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 }; } + +exports.default = openpgp; + +/** + * Export each high level api function seperately. + * Usage: + * + * import { encryptMessage } from 'openpgp.js' + * encryptMessage(keys, text) + */ + + /** * @see module:key * @name module:openpgp.key */ -module.exports.key = require('./key.js'); + +var key = exports.key = keyMod; + /** * @see module:message * @name module:openpgp.message */ -module.exports.message = require('./message.js'); +var message = exports.message = messageMod; + /** * @see module:cleartext * @name module:openpgp.cleartext */ -module.exports.cleartext = require('./cleartext.js'); +var cleartext = exports.cleartext = cleartextMod; + /** * @see module:util * @name module:openpgp.util */ -module.exports.util = require('./util.js'); -/** - * @see module:packet - * @name module:openpgp.packet - */ -module.exports.packet = require('./packet'); -/** - * @see module:type/mpi - * @name module:openpgp.MPI - */ -module.exports.MPI = require('./type/mpi.js'); -/** - * @see module:type/s2k - * @name module:openpgp.S2K - */ -module.exports.S2K = require('./type/s2k.js'); -/** - * @see module:type/keyid - * @name module:openpgp.Keyid - */ -module.exports.Keyid = require('./type/keyid.js'); -/** - * @see module:encoding/armor - * @name module:openpgp.armor - */ -module.exports.armor = require('./encoding/armor.js'); -/** - * @see module:enums - * @name module:openpgp.enums - */ -module.exports.enums = require('./enums.js'); -/** - * @see module:config/config - * @name module:openpgp.config - */ -module.exports.config = require('./config/config.js'); -/** - * @see module:crypto - * @name module:openpgp.crypto - */ -module.exports.crypto = require('./crypto'); -/** - * @see module:keyring - * @name module:openpgp.Keyring - */ -module.exports.Keyring = require('./keyring'); -/** - * @see module:worker/async_proxy - * @name module:openpgp.AsyncProxy - */ -module.exports.AsyncProxy = require('./worker/async_proxy.js'); -/** - * @see module:hkp - * @name module:openpgp.HKP - */ -module.exports.HKP = require('./hkp'); -},{"./cleartext.js":12,"./config/config.js":16,"./crypto":32,"./encoding/armor.js":41,"./enums.js":43,"./hkp":45,"./key.js":47,"./keyring":48,"./message.js":51,"./openpgp.js":52,"./packet":55,"./type/keyid.js":73,"./type/mpi.js":74,"./type/s2k.js":75,"./util.js":76,"./worker/async_proxy.js":77}],47:[function(require,module,exports){ +},{"./cleartext":14,"./config/config":18,"./crypto":32,"./encoding/armor":41,"./enums":43,"./hkp":44,"./key":46,"./keyring":47,"./message":50,"./openpgp":51,"./packet":55,"./type/keyid":73,"./type/mpi":74,"./type/s2k":75,"./util":76,"./worker/async_proxy":77}],46:[function(require,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -10614,11 +12016,35 @@ module.exports.HKP = require('./hkp'); 'use strict'; -var packet = require('./packet'), - enums = require('./enums.js'), - armor = require('./encoding/armor.js'), - config = require('./config'), - util = require('./util'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Key = Key; +exports.readArmored = readArmored; +exports.generate = generate; +exports.getPreferredSymAlgo = getPreferredSymAlgo; + +var _packet = require('./packet'); + +var _packet2 = _interopRequireDefault(_packet); + +var _enums = require('./enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _armor = require('./encoding/armor.js'); + +var _armor2 = _interopRequireDefault(_armor); + +var _config = require('./config'); + +var _config2 = _interopRequireDefault(_config); + +var _util = require('./util'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @class @@ -10647,72 +12073,86 @@ function Key(packetlist) { * Transforms packetlist to structured key data * @param {module:packet/packetlist} packetlist The packets that form a key */ -Key.prototype.packetlist2structure = function(packetlist) { +Key.prototype.packetlist2structure = function (packetlist) { var user, primaryKeyId, subKey; for (var i = 0; i < packetlist.length; i++) { switch (packetlist[i].tag) { - case enums.packet.publicKey: - case enums.packet.secretKey: + case _enums2.default.packet.publicKey: + case _enums2.default.packet.secretKey: this.primaryKey = packetlist[i]; primaryKeyId = this.primaryKey.getKeyId(); break; - case enums.packet.userid: - case enums.packet.userAttribute: + case _enums2.default.packet.userid: + case _enums2.default.packet.userAttribute: user = new User(packetlist[i]); - if (!this.users) this.users = []; + if (!this.users) { + this.users = []; + } this.users.push(user); break; - case enums.packet.publicSubkey: - case enums.packet.secretSubkey: + case _enums2.default.packet.publicSubkey: + case _enums2.default.packet.secretSubkey: user = null; - if (!this.subKeys) this.subKeys = []; + if (!this.subKeys) { + this.subKeys = []; + } subKey = new SubKey(packetlist[i]); this.subKeys.push(subKey); break; - case enums.packet.signature: + case _enums2.default.packet.signature: switch (packetlist[i].signatureType) { - case enums.signature.cert_generic: - case enums.signature.cert_persona: - case enums.signature.cert_casual: - case enums.signature.cert_positive: + case _enums2.default.signature.cert_generic: + case _enums2.default.signature.cert_persona: + case _enums2.default.signature.cert_casual: + case _enums2.default.signature.cert_positive: if (!user) { - util.print_debug('Dropping certification signatures without preceding user packet'); + _util2.default.print_debug('Dropping certification signatures without preceding user packet'); continue; } if (packetlist[i].issuerKeyId.equals(primaryKeyId)) { - if (!user.selfCertifications) user.selfCertifications = []; + if (!user.selfCertifications) { + user.selfCertifications = []; + } user.selfCertifications.push(packetlist[i]); } else { - if (!user.otherCertifications) user.otherCertifications = []; + if (!user.otherCertifications) { + user.otherCertifications = []; + } user.otherCertifications.push(packetlist[i]); } break; - case enums.signature.cert_revocation: + case _enums2.default.signature.cert_revocation: if (user) { - if (!user.revocationCertifications) user.revocationCertifications = []; + if (!user.revocationCertifications) { + user.revocationCertifications = []; + } user.revocationCertifications.push(packetlist[i]); } else { - if (!this.directSignatures) this.directSignatures = []; + if (!this.directSignatures) { + this.directSignatures = []; + } this.directSignatures.push(packetlist[i]); } break; - case enums.signature.key: - if (!this.directSignatures) this.directSignatures = []; + case _enums2.default.signature.key: + if (!this.directSignatures) { + this.directSignatures = []; + } this.directSignatures.push(packetlist[i]); break; - case enums.signature.subkey_binding: + case _enums2.default.signature.subkey_binding: if (!subKey) { - util.print_debug('Dropping subkey binding signature without preceding subkey packet'); + _util2.default.print_debug('Dropping subkey binding signature without preceding subkey packet'); continue; } subKey.bindingSignature = packetlist[i]; break; - case enums.signature.key_revocation: + case _enums2.default.signature.key_revocation: this.revocationSignature = packetlist[i]; break; - case enums.signature.subkey_revocation: + case _enums2.default.signature.subkey_revocation: if (!subKey) { - util.print_debug('Dropping subkey revocation signature without preceding subkey packet'); + _util2.default.print_debug('Dropping subkey revocation signature without preceding subkey packet'); continue; } subKey.revocationSignature = packetlist[i]; @@ -10727,8 +12167,8 @@ Key.prototype.packetlist2structure = function(packetlist) { * Transforms structured key data to packetlist * @return {module:packet/packetlist} The packets that form a key */ -Key.prototype.toPacketlist = function() { - var packetlist = new packet.List(); +Key.prototype.toPacketlist = function () { + var packetlist = new _packet2.default.List(); packetlist.push(this.primaryKey); packetlist.push(this.revocationSignature); packetlist.concat(this.directSignatures); @@ -10748,7 +12188,7 @@ Key.prototype.toPacketlist = function() { * Returns all the private and public subkey packets * @returns {Array<(module:packet/public_subkey|module:packet/secret_subkey)>} */ -Key.prototype.getSubkeyPackets = function() { +Key.prototype.getSubkeyPackets = function () { var subKeys = []; if (this.subKeys) { for (var i = 0; i < this.subKeys.length; i++) { @@ -10762,7 +12202,7 @@ Key.prototype.getSubkeyPackets = function() { * Returns all the private and public key and subkey packets * @returns {Array<(module:packet/public_subkey|module:packet/secret_subkey|module:packet/secret_key|module:packet/public_key)>} */ -Key.prototype.getAllKeyPackets = function() { +Key.prototype.getAllKeyPackets = function () { return [this.primaryKey].concat(this.getSubkeyPackets()); }; @@ -10770,7 +12210,7 @@ Key.prototype.getAllKeyPackets = function() { * Returns key IDs of all key packets * @returns {Array} */ -Key.prototype.getKeyIds = function() { +Key.prototype.getKeyIds = function () { var keyIds = []; var keys = this.getAllKeyPackets(); for (var i = 0; i < keys.length; i++) { @@ -10785,7 +12225,7 @@ Key.prototype.getKeyIds = function() { * @return {(module:packet/public_subkey|module:packet/public_key| * module:packet/secret_subkey|module:packet/secret_key|null)} */ -Key.prototype.getKeyPacket = function(keyIds) { +Key.prototype.getKeyPacket = function (keyIds) { var keys = this.getAllKeyPackets(); for (var i = 0; i < keys.length; i++) { var keyId = keys[i].getKeyId(); @@ -10802,11 +12242,11 @@ Key.prototype.getKeyPacket = function(keyIds) { * Returns userids * @return {Array} array of userids */ -Key.prototype.getUserIds = function() { +Key.prototype.getUserIds = function () { var userids = []; for (var i = 0; i < this.users.length; i++) { if (this.users[i].userId) { - userids.push(this.users[i].userId.write()); + userids.push(_util2.default.Uint8Array2str(this.users[i].userId.write())); } } return userids; @@ -10816,37 +12256,37 @@ Key.prototype.getUserIds = function() { * Returns true if this is a public key * @return {Boolean} */ -Key.prototype.isPublic = function() { - return this.primaryKey.tag == enums.packet.publicKey; +Key.prototype.isPublic = function () { + return this.primaryKey.tag === _enums2.default.packet.publicKey; }; /** * Returns true if this is a private key * @return {Boolean} */ -Key.prototype.isPrivate = function() { - return this.primaryKey.tag == enums.packet.secretKey; +Key.prototype.isPrivate = function () { + return this.primaryKey.tag === _enums2.default.packet.secretKey; }; /** * Returns key as public key (shallow copy) * @return {module:key~Key} new public Key */ -Key.prototype.toPublic = function() { - var packetlist = new packet.List(); +Key.prototype.toPublic = function () { + var packetlist = new _packet2.default.List(); var keyPackets = this.toPacketlist(); var bytes; for (var i = 0; i < keyPackets.length; i++) { switch (keyPackets[i].tag) { - case enums.packet.secretKey: + case _enums2.default.packet.secretKey: bytes = keyPackets[i].writePublicKey(); - var pubKeyPacket = new packet.PublicKey(); + var pubKeyPacket = new _packet2.default.PublicKey(); pubKeyPacket.read(bytes); packetlist.push(pubKeyPacket); break; - case enums.packet.secretSubkey: + case _enums2.default.packet.secretSubkey: bytes = keyPackets[i].writePublicKey(); - var pubSubkeyPacket = new packet.PublicSubkey(); + var pubSubkeyPacket = new _packet2.default.PublicSubkey(); pubSubkeyPacket.read(bytes); packetlist.push(pubSubkeyPacket); break; @@ -10861,9 +12301,9 @@ Key.prototype.toPublic = function() { * Returns ASCII armored text of key * @return {String} ASCII armor */ -Key.prototype.armor = function() { - var type = this.isPublic() ? enums.armor.public_key : enums.armor.private_key; - return armor.encode(type, this.toPacketlist().write()); +Key.prototype.armor = function () { + var type = this.isPublic() ? _enums2.default.armor.public_key : _enums2.default.armor.private_key; + return _armor2.default.encode(type, this.toPacketlist().write()); }; /** @@ -10871,17 +12311,14 @@ Key.prototype.armor = function() { * @param {module:type/keyid} keyId, optional * @return {(module:packet/secret_subkey|module:packet/secret_key|null)} key packet or null if no signing key has been found */ -Key.prototype.getSigningKeyPacket = function(keyId) { +Key.prototype.getSigningKeyPacket = function (keyId) { var primaryUser = this.getPrimaryUser(); - if (primaryUser && - isValidSigningKeyPacket(this.primaryKey, primaryUser.selfCertificate) && - (!keyId || this.primaryKey.getKeyId().equals(keyId))) { + if (primaryUser && isValidSigningKeyPacket(this.primaryKey, primaryUser.selfCertificate) && (!keyId || this.primaryKey.getKeyId().equals(keyId))) { return this.primaryKey; } if (this.subKeys) { for (var i = 0; i < this.subKeys.length; i++) { - if (this.subKeys[i].isValidSigningKey(this.primaryKey) && - (!keyId || this.subKeys[i].subKey.getKeyId().equals(keyId))) { + if (this.subKeys[i].isValidSigningKey(this.primaryKey) && (!keyId || this.subKeys[i].subKey.getKeyId().equals(keyId))) { return this.subKeys[i].subKey; } } @@ -10893,35 +12330,27 @@ Key.prototype.getSigningKeyPacket = function(keyId) { * Returns preferred signature hash algorithm of this key * @return {String} */ -Key.prototype.getPreferredHashAlgorithm = function() { +Key.prototype.getPreferredHashAlgorithm = function () { var primaryUser = this.getPrimaryUser(); if (primaryUser && primaryUser.selfCertificate.preferredHashAlgorithms) { return primaryUser.selfCertificate.preferredHashAlgorithms[0]; } - return config.prefer_hash_algorithm; + return _config2.default.prefer_hash_algorithm; }; function isValidEncryptionKeyPacket(keyPacket, signature) { - return keyPacket.algorithm !== enums.read(enums.publicKey, enums.publicKey.dsa) && - keyPacket.algorithm !== enums.read(enums.publicKey, enums.publicKey.rsa_sign) && - (!signature.keyFlags || - (signature.keyFlags[0] & enums.keyFlags.encrypt_communication) !== 0 || - (signature.keyFlags[0] & enums.keyFlags.encrypt_storage) !== 0); + return keyPacket.algorithm !== _enums2.default.read(_enums2.default.publicKey, _enums2.default.publicKey.dsa) && keyPacket.algorithm !== _enums2.default.read(_enums2.default.publicKey, _enums2.default.publicKey.rsa_sign) && (!signature.keyFlags || (signature.keyFlags[0] & _enums2.default.keyFlags.encrypt_communication) !== 0 || (signature.keyFlags[0] & _enums2.default.keyFlags.encrypt_storage) !== 0); } function isValidSigningKeyPacket(keyPacket, signature) { - return (keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.dsa) || - keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.rsa_sign) || - keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.rsa_encrypt_sign)) && - (!signature.keyFlags || - (signature.keyFlags[0] & enums.keyFlags.sign_data) !== 0); + return (keyPacket.algorithm === _enums2.default.read(_enums2.default.publicKey, _enums2.default.publicKey.dsa) || keyPacket.algorithm === _enums2.default.read(_enums2.default.publicKey, _enums2.default.publicKey.rsa_sign) || keyPacket.algorithm === _enums2.default.read(_enums2.default.publicKey, _enums2.default.publicKey.rsa_encrypt_sign)) && (!signature.keyFlags || (signature.keyFlags[0] & _enums2.default.keyFlags.sign_data) !== 0); } /** * Returns the first valid encryption key packet for this key * @returns {(module:packet/public_subkey|module:packet/secret_subkey|module:packet/secret_key|module:packet/public_key|null)} key packet or null if no encryption key has been found */ -Key.prototype.getEncryptionKeyPacket = function() { +Key.prototype.getEncryptionKeyPacket = function () { // V4: by convention subkeys are prefered for encryption service // V3: keys MUST NOT have subkeys if (this.subKeys) { @@ -10933,8 +12362,7 @@ Key.prototype.getEncryptionKeyPacket = function() { } // if no valid subkey for encryption, evaluate primary key var primaryUser = this.getPrimaryUser(); - if (primaryUser && - isValidEncryptionKeyPacket(this.primaryKey, primaryUser.selfCertificate)) { + if (primaryUser && isValidEncryptionKeyPacket(this.primaryKey, primaryUser.selfCertificate)) { return this.primaryKey; } return null; @@ -10945,12 +12373,14 @@ Key.prototype.getEncryptionKeyPacket = function() { * @param {String} passphrase * @return {Boolean} true if all key and subkey packets decrypted successfully */ -Key.prototype.decrypt = function(passphrase) { +Key.prototype.decrypt = function (passphrase) { if (this.isPrivate()) { var keys = this.getAllKeyPackets(); for (var i = 0; i < keys.length; i++) { var success = keys[i].decrypt(passphrase); - if (!success) return false; + if (!success) { + return false; + } } } else { throw new Error("Nothing to decrypt in a public key"); @@ -10964,7 +12394,7 @@ Key.prototype.decrypt = function(passphrase) { * @param {String} passphrase * @return {Boolean} true if all key packets decrypted successfully */ -Key.prototype.decryptKeyPacket = function(keyIds, passphrase) { +Key.prototype.decryptKeyPacket = function (keyIds, passphrase) { if (this.isPrivate()) { var keys = this.getAllKeyPackets(); for (var i = 0; i < keys.length; i++) { @@ -10972,7 +12402,9 @@ Key.prototype.decryptKeyPacket = function(keyIds, passphrase) { for (var j = 0; j < keyIds.length; j++) { if (keyId.equals(keyIds[j])) { var success = keys[i].decrypt(passphrase); - if (!success) return false; + if (!success) { + return false; + } } } } @@ -10987,17 +12419,14 @@ Key.prototype.decryptKeyPacket = function(keyIds, passphrase) { * and valid self signature * @return {module:enums.keyStatus} The status of the primary key */ -Key.prototype.verifyPrimaryKey = function() { +Key.prototype.verifyPrimaryKey = function () { // check revocation signature - if (this.revocationSignature && !this.revocationSignature.isExpired() && - (this.revocationSignature.verified || - this.revocationSignature.verify(this.primaryKey, {key: this.primaryKey}))) { - return enums.keyStatus.revoked; + if (this.revocationSignature && !this.revocationSignature.isExpired() && (this.revocationSignature.verified || this.revocationSignature.verify(this.primaryKey, { key: this.primaryKey }))) { + return _enums2.default.keyStatus.revoked; } // check V3 expiration time - if (this.primaryKey.version == 3 && this.primaryKey.expirationTimeV3 !== 0 && - Date.now() > (this.primaryKey.created.getTime() + this.primaryKey.expirationTimeV3*24*3600*1000)) { - return enums.keyStatus.expired; + if (this.primaryKey.version === 3 && this.primaryKey.expirationTimeV3 !== 0 && Date.now() > this.primaryKey.created.getTime() + this.primaryKey.expirationTimeV3 * 24 * 3600 * 1000) { + return _enums2.default.keyStatus.expired; } // check for at least one self signature. Self signature of user ID not mandatory // See {@link http://tools.ietf.org/html/rfc4880#section-11.1} @@ -11008,30 +12437,29 @@ Key.prototype.verifyPrimaryKey = function() { } } if (!selfSigned) { - return enums.keyStatus.no_self_cert; + return _enums2.default.keyStatus.no_self_cert; } // check for valid self signature var primaryUser = this.getPrimaryUser(); if (!primaryUser) { - return enums.keyStatus.invalid; + return _enums2.default.keyStatus.invalid; } // check V4 expiration time - if (this.primaryKey.version == 4 && primaryUser.selfCertificate.keyNeverExpires === false && - Date.now() > (this.primaryKey.created.getTime() + primaryUser.selfCertificate.keyExpirationTime*1000)) { - return enums.keyStatus.expired; + if (this.primaryKey.version === 4 && primaryUser.selfCertificate.keyNeverExpires === false && Date.now() > this.primaryKey.created.getTime() + primaryUser.selfCertificate.keyExpirationTime * 1000) { + return _enums2.default.keyStatus.expired; } - return enums.keyStatus.valid; + return _enums2.default.keyStatus.valid; }; /** * Returns the expiration time of the primary key or null if key does not expire * @return {Date|null} */ -Key.prototype.getExpirationTime = function() { - if (this.primaryKey.version == 3) { +Key.prototype.getExpirationTime = function () { + if (this.primaryKey.version === 3) { return getExpirationTime(this.primaryKey); } - if (this.primaryKey.version == 4) { + if (this.primaryKey.version === 4) { var primaryUser = this.getPrimaryUser(); if (!primaryUser) { return null; @@ -11040,15 +12468,14 @@ Key.prototype.getExpirationTime = function() { } }; - function getExpirationTime(keyPacket, selfCertificate) { // check V3 expiration time - if (keyPacket.version == 3 && keyPacket.expirationTimeV3 !== 0) { - return new Date(keyPacket.created.getTime() + keyPacket.expirationTimeV3*24*3600*1000); + if (keyPacket.version === 3 && keyPacket.expirationTimeV3 !== 0) { + return new Date(keyPacket.created.getTime() + keyPacket.expirationTimeV3 * 24 * 3600 * 1000); } // check V4 expiration time - if (keyPacket.version == 4 && selfCertificate.keyNeverExpires === false) { - return new Date(keyPacket.created.getTime() + selfCertificate.keyExpirationTime*1000); + if (keyPacket.version === 4 && selfCertificate.keyNeverExpires === false) { + return new Date(keyPacket.created.getTime() + selfCertificate.keyExpirationTime * 1000); } return null; } @@ -11059,18 +12486,18 @@ function getExpirationTime(keyPacket, selfCertificate) { * - if no primary user is found returns the user with the latest self signature * @return {{user: Array, selfCertificate: Array}|null} The primary user and the self signature */ -Key.prototype.getPrimaryUser = function() { +Key.prototype.getPrimaryUser = function () { var primUser = []; for (var i = 0; i < this.users.length; i++) { if (!this.users[i].userId || !this.users[i].selfCertifications) { continue; } for (var j = 0; j < this.users[i].selfCertifications.length; j++) { - primUser.push({user: this.users[i], selfCertificate: this.users[i].selfCertifications[j]}); + primUser.push({ user: this.users[i], selfCertificate: this.users[i].selfCertifications[j] }); } } // sort by primary user flag and signature creation time - primUser = primUser.sort(function(a, b) { + primUser = primUser.sort(function (a, b) { if (a.selfCertificate.isPrimaryUserID > b.selfCertificate.isPrimaryUserID) { return -1; } else if (a.selfCertificate.isPrimaryUserID < b.selfCertificate.isPrimaryUserID) { @@ -11084,9 +12511,9 @@ Key.prototype.getPrimaryUser = function() { } }); // return first valid - for (var i = 0; i < primUser.length; i++) { - if (primUser[i].user.isValidSelfCertificate(this.primaryKey, primUser[i].selfCertificate)) { - return primUser[i]; + for (var k = 0; k < primUser.length; k++) { + if (primUser[k].user.isValidSelfCertificate(this.primaryKey, primUser[k].selfCertificate)) { + return primUser[k]; } } return null; @@ -11100,9 +12527,9 @@ Key.prototype.getPrimaryUser = function() { * the destination key is tranformed to a private key. * @param {module:key~Key} key source key to merge */ -Key.prototype.update = function(key) { +Key.prototype.update = function (key) { var that = this; - if (key.verifyPrimaryKey() === enums.keyStatus.invalid) { + if (key.verifyPrimaryKey() === _enums2.default.keyStatus.invalid) { return; } if (this.primaryKey.getFingerprint() !== key.primaryKey.getFingerprint()) { @@ -11110,31 +12537,27 @@ Key.prototype.update = function(key) { } if (this.isPublic() && key.isPrivate()) { // check for equal subkey packets - var equal = ((this.subKeys && this.subKeys.length) === (key.subKeys && key.subKeys.length)) && - (!this.subKeys || this.subKeys.every(function(destSubKey) { - return key.subKeys.some(function(srcSubKey) { - return destSubKey.subKey.getFingerprint() === srcSubKey.subKey.getFingerprint(); - }); - })); + var equal = (this.subKeys && this.subKeys.length) === (key.subKeys && key.subKeys.length) && (!this.subKeys || this.subKeys.every(function (destSubKey) { + return key.subKeys.some(function (srcSubKey) { + return destSubKey.subKey.getFingerprint() === srcSubKey.subKey.getFingerprint(); + }); + })); if (!equal) { throw new Error('Cannot update public key with private key if subkey mismatch'); } this.primaryKey = key.primaryKey; } // revocation signature - if (!this.revocationSignature && key.revocationSignature && !key.revocationSignature.isExpired() && - (key.revocationSignature.verified || - key.revocationSignature.verify(key.primaryKey, {key: key.primaryKey}))) { + if (!this.revocationSignature && key.revocationSignature && !key.revocationSignature.isExpired() && (key.revocationSignature.verified || key.revocationSignature.verify(key.primaryKey, { key: key.primaryKey }))) { this.revocationSignature = key.revocationSignature; } // direct signatures mergeSignatures(key, this, 'directSignatures'); // users - key.users.forEach(function(srcUser) { + key.users.forEach(function (srcUser) { var found = false; for (var i = 0; i < that.users.length; i++) { - if (srcUser.userId && (srcUser.userId.userid === that.users[i].userId.userid) || - srcUser.userAttribute && (srcUser.userAttribute.equals(that.users[i].userAttribute))) { + if (srcUser.userId && srcUser.userId.userid === that.users[i].userId.userid || srcUser.userAttribute && srcUser.userAttribute.equals(that.users[i].userAttribute)) { that.users[i].update(srcUser, that.primaryKey); found = true; break; @@ -11146,7 +12569,7 @@ Key.prototype.update = function(key) { }); // subkeys if (key.subKeys) { - key.subKeys.forEach(function(srcSubKey) { + key.subKeys.forEach(function (srcSubKey) { var found = false; for (var i = 0; i < that.subKeys.length; i++) { if (srcSubKey.subKey.getFingerprint() === that.subKeys[i].subKey.getFingerprint()) { @@ -11176,11 +12599,10 @@ function mergeSignatures(source, dest, attr, checkFn) { if (!dest[attr]) { dest[attr] = source; } else { - source.forEach(function(sourceSig) { - if (!sourceSig.isExpired() && (!checkFn || checkFn(sourceSig)) && - !dest[attr].some(function(destSig) { - return destSig.signature === sourceSig.signature; - })) { + source.forEach(function (sourceSig) { + if (!sourceSig.isExpired() && (!checkFn || checkFn(sourceSig)) && !dest[attr].some(function (destSig) { + return _util2.default.equalsUint8Array(destSig.signature, sourceSig.signature); + })) { dest[attr].push(sourceSig); } }); @@ -11189,9 +12611,7 @@ function mergeSignatures(source, dest, attr, checkFn) { } // TODO -Key.prototype.revoke = function() { - -}; +Key.prototype.revoke = function () {}; /** * @class @@ -11201,8 +12621,8 @@ function User(userPacket) { if (!(this instanceof User)) { return new User(userPacket); } - this.userId = userPacket.tag == enums.packet.userid ? userPacket : null; - this.userAttribute = userPacket.tag == enums.packet.userAttribute ? userPacket : null; + this.userId = userPacket.tag === _enums2.default.packet.userid ? userPacket : null; + this.userAttribute = userPacket.tag === _enums2.default.packet.userAttribute ? userPacket : null; this.selfCertifications = null; this.otherCertifications = null; this.revocationCertifications = null; @@ -11212,8 +12632,8 @@ function User(userPacket) { * Transforms structured user data to packetlist * @return {module:packet/packetlist} */ -User.prototype.toPacketlist = function() { - var packetlist = new packet.List(); +User.prototype.toPacketlist = function () { + var packetlist = new _packet2.default.List(); packetlist.push(this.userId || this.userAttribute); packetlist.concat(this.revocationCertifications); packetlist.concat(this.selfCertifications); @@ -11227,15 +12647,12 @@ User.prototype.toPacketlist = function() { * @param {module:packet/secret_key|module:packet/public_key} primaryKey The primary key packet * @return {Boolean} True if the certificate is revoked */ -User.prototype.isRevoked = function(certificate, primaryKey) { +User.prototype.isRevoked = function (certificate, primaryKey) { if (this.revocationCertifications) { var that = this; - return this.revocationCertifications.some(function(revCert) { - return revCert.issuerKeyId.equals(certificate.issuerKeyId) && - !revCert.isExpired() && - (revCert.verified || - revCert.verify(primaryKey, {userid: that.userId || that.userAttribute, key: primaryKey})); - }); + return this.revocationCertifications.some(function (revCert) { + return revCert.issuerKeyId.equals(certificate.issuerKeyId) && !revCert.isExpired() && (revCert.verified || revCert.verify(primaryKey, { userid: that.userId || that.userAttribute, key: primaryKey })); + }); } else { return false; } @@ -11246,15 +12663,15 @@ User.prototype.isRevoked = function(certificate, primaryKey) { * @param {module:packet/secret_key|module:packet/public_key} primaryKey The primary key packet * @return {module:packet/signature} The self signature */ -User.prototype.getValidSelfCertificate = function(primaryKey) { +User.prototype.getValidSelfCertificate = function (primaryKey) { if (!this.selfCertifications) { return null; } // most recent first - var validCert = this.selfCertifications.sort(function(a, b) { + var validCert = this.selfCertifications.sort(function (a, b) { a = a.created; b = b.created; - return a>b ? -1 : a b ? -1 : a < b ? 1 : 0; }); for (var i = 0; i < validCert.length; i++) { if (this.isValidSelfCertificate(primaryKey, validCert[i])) { @@ -11270,13 +12687,11 @@ User.prototype.getValidSelfCertificate = function(primaryKey) { * @param {module:packet/signature} selfCertificate A self certificate of this user * @return {Boolean} */ -User.prototype.isValidSelfCertificate = function(primaryKey, selfCertificate) { +User.prototype.isValidSelfCertificate = function (primaryKey, selfCertificate) { if (this.isRevoked(selfCertificate, primaryKey)) { return false; } - if (!selfCertificate.isExpired() && - (selfCertificate.verified || - selfCertificate.verify(primaryKey, {userid: this.userId || this.userAttribute, key: primaryKey}))) { + if (!selfCertificate.isExpired() && (selfCertificate.verified || selfCertificate.verify(primaryKey, { userid: this.userId || this.userAttribute, key: primaryKey }))) { return true; } return false; @@ -11288,26 +12703,25 @@ User.prototype.isValidSelfCertificate = function(primaryKey, selfCertificate) { * @param {module:packet/secret_key|module:packet/public_key} primaryKey The primary key packet * @return {module:enums.keyStatus} status of user */ -User.prototype.verify = function(primaryKey) { +User.prototype.verify = function (primaryKey) { if (!this.selfCertifications) { - return enums.keyStatus.no_self_cert; + return _enums2.default.keyStatus.no_self_cert; } var status; for (var i = 0; i < this.selfCertifications.length; i++) { if (this.isRevoked(this.selfCertifications[i], primaryKey)) { - status = enums.keyStatus.revoked; + status = _enums2.default.keyStatus.revoked; continue; } - if (!(this.selfCertifications[i].verified || - this.selfCertifications[i].verify(primaryKey, {userid: this.userId || this.userAttribute, key: primaryKey}))) { - status = enums.keyStatus.invalid; + if (!(this.selfCertifications[i].verified || this.selfCertifications[i].verify(primaryKey, { userid: this.userId || this.userAttribute, key: primaryKey }))) { + status = _enums2.default.keyStatus.invalid; continue; } if (this.selfCertifications[i].isExpired()) { - status = enums.keyStatus.expired; + status = _enums2.default.keyStatus.expired; continue; } - status = enums.keyStatus.valid; + status = _enums2.default.keyStatus.valid; break; } return status; @@ -11318,12 +12732,11 @@ User.prototype.verify = function(primaryKey) { * @param {module:key~User} user source user to merge * @param {module:packet/signature} primaryKey primary key used for validation */ -User.prototype.update = function(user, primaryKey) { +User.prototype.update = function (user, primaryKey) { var that = this; // self signatures - mergeSignatures(user, this, 'selfCertifications', function(srcSelfSig) { - return srcSelfSig.verified || - srcSelfSig.verify(primaryKey, {userid: that.userId || that.userAttribute, key: primaryKey}); + mergeSignatures(user, this, 'selfCertifications', function (srcSelfSig) { + return srcSelfSig.verified || srcSelfSig.verify(primaryKey, { userid: that.userId || that.userAttribute, key: primaryKey }); }); // other signatures mergeSignatures(user, this, 'otherCertifications'); @@ -11348,8 +12761,8 @@ function SubKey(subKeyPacket) { * Transforms structured subkey data to packetlist * @return {module:packet/packetlist} */ -SubKey.prototype.toPacketlist = function() { - var packetlist = new packet.List(); +SubKey.prototype.toPacketlist = function () { + var packetlist = new _packet2.default.List(); packetlist.push(this.subKey); packetlist.push(this.revocationSignature); packetlist.push(this.bindingSignature); @@ -11361,9 +12774,8 @@ SubKey.prototype.toPacketlist = function() { * @param {module:packet/secret_key|module:packet/public_key} primaryKey The primary key packet * @return {Boolean} */ -SubKey.prototype.isValidEncryptionKey = function(primaryKey) { - return this.verify(primaryKey) == enums.keyStatus.valid && - isValidEncryptionKeyPacket(this.subKey, this.bindingSignature); +SubKey.prototype.isValidEncryptionKey = function (primaryKey) { + return this.verify(primaryKey) === _enums2.default.keyStatus.valid && isValidEncryptionKeyPacket(this.subKey, this.bindingSignature); }; /** @@ -11371,9 +12783,8 @@ SubKey.prototype.isValidEncryptionKey = function(primaryKey) { * @param {module:packet/secret_key|module:packet/public_key} primaryKey The primary key packet * @return {Boolean} */ -SubKey.prototype.isValidSigningKey = function(primaryKey) { - return this.verify(primaryKey) == enums.keyStatus.valid && - isValidSigningKeyPacket(this.subKey, this.bindingSignature); +SubKey.prototype.isValidSigningKey = function (primaryKey) { + return this.verify(primaryKey) === _enums2.default.keyStatus.valid && isValidSigningKeyPacket(this.subKey, this.bindingSignature); }; /** @@ -11381,43 +12792,37 @@ SubKey.prototype.isValidSigningKey = function(primaryKey) { * and valid binding signature * @return {module:enums.keyStatus} The status of the subkey */ -SubKey.prototype.verify = function(primaryKey) { +SubKey.prototype.verify = function (primaryKey) { // check subkey revocation signature - if (this.revocationSignature && !this.revocationSignature.isExpired() && - (this.revocationSignature.verified || - this.revocationSignature.verify(primaryKey, {key:primaryKey, bind: this.subKey}))) { - return enums.keyStatus.revoked; + if (this.revocationSignature && !this.revocationSignature.isExpired() && (this.revocationSignature.verified || this.revocationSignature.verify(primaryKey, { key: primaryKey, bind: this.subKey }))) { + return _enums2.default.keyStatus.revoked; } // check V3 expiration time - if (this.subKey.version == 3 && this.subKey.expirationTimeV3 !== 0 && - Date.now() > (this.subKey.created.getTime() + this.subKey.expirationTimeV3*24*3600*1000)) { - return enums.keyStatus.expired; + if (this.subKey.version === 3 && this.subKey.expirationTimeV3 !== 0 && Date.now() > this.subKey.created.getTime() + this.subKey.expirationTimeV3 * 24 * 3600 * 1000) { + return _enums2.default.keyStatus.expired; } // check subkey binding signature if (!this.bindingSignature) { - return enums.keyStatus.invalid; + return _enums2.default.keyStatus.invalid; } if (this.bindingSignature.isExpired()) { - return enums.keyStatus.expired; + return _enums2.default.keyStatus.expired; } - if (!(this.bindingSignature.verified || - this.bindingSignature.verify(primaryKey, {key: primaryKey, bind: this.subKey}))) { - return enums.keyStatus.invalid; + if (!(this.bindingSignature.verified || this.bindingSignature.verify(primaryKey, { key: primaryKey, bind: this.subKey }))) { + return _enums2.default.keyStatus.invalid; } // check V4 expiration time - if (this.subKey.version == 4 && - this.bindingSignature.keyNeverExpires === false && - Date.now() > (this.subKey.created.getTime() + this.bindingSignature.keyExpirationTime*1000)) { - return enums.keyStatus.expired; + if (this.subKey.version === 4 && this.bindingSignature.keyNeverExpires === false && Date.now() > this.subKey.created.getTime() + this.bindingSignature.keyExpirationTime * 1000) { + return _enums2.default.keyStatus.expired; } - return enums.keyStatus.valid; + return _enums2.default.keyStatus.valid; }; /** * Returns the expiration time of the subkey or null if key does not expire * @return {Date|null} */ -SubKey.prototype.getExpirationTime = function() { +SubKey.prototype.getExpirationTime = function () { return getExpirationTime(this.subKey, this.bindingSignature); }; @@ -11426,28 +12831,23 @@ SubKey.prototype.getExpirationTime = function() { * @param {module:key~SubKey} subKey source subkey to merge * @param {module:packet/signature} primaryKey primary key used for validation */ -SubKey.prototype.update = function(subKey, primaryKey) { - if (subKey.verify(primaryKey) === enums.keyStatus.invalid) { +SubKey.prototype.update = function (subKey, primaryKey) { + if (subKey.verify(primaryKey) === _enums2.default.keyStatus.invalid) { return; } if (this.subKey.getFingerprint() !== subKey.subKey.getFingerprint()) { throw new Error('SubKey update method: fingerprints of subkeys not equal'); } // key packet - if (this.subKey.tag === enums.packet.publicSubkey && - subKey.subKey.tag === enums.packet.secretSubkey) { + if (this.subKey.tag === _enums2.default.packet.publicSubkey && subKey.subKey.tag === _enums2.default.packet.secretSubkey) { this.subKey = subKey.subKey; } // binding signature - if (!this.bindingSignature && subKey.bindingSignature && - (subKey.bindingSignature.verified || - subKey.bindingSignature.verify(primaryKey, {key: primaryKey, bind: this.subKey}))) { + if (!this.bindingSignature && subKey.bindingSignature && (subKey.bindingSignature.verified || subKey.bindingSignature.verify(primaryKey, { key: primaryKey, bind: this.subKey }))) { this.bindingSignature = subKey.bindingSignature; } // revocation signature - if (!this.revocationSignature && subKey.revocationSignature && !subKey.revocationSignature.isExpired() && - (subKey.revocationSignature.verified || - subKey.revocationSignature.verify(primaryKey, {key: primaryKey, bind: this.subKey}))) { + if (!this.revocationSignature && subKey.revocationSignature && !subKey.revocationSignature.isExpired() && (subKey.revocationSignature.verified || subKey.revocationSignature.verify(primaryKey, { key: primaryKey, bind: this.subKey }))) { this.revocationSignature = subKey.revocationSignature; } }; @@ -11462,13 +12862,13 @@ function readArmored(armoredText) { var result = {}; result.keys = []; try { - var input = armor.decode(armoredText); - if (!(input.type == enums.armor.public_key || input.type == enums.armor.private_key)) { + var input = _armor2.default.decode(armoredText); + if (!(input.type === _enums2.default.armor.public_key || input.type === _enums2.default.armor.private_key)) { throw new Error('Armored text not of type key'); } - var packetlist = new packet.List(); + var packetlist = new _packet2.default.List(); packetlist.read(input.data); - var keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey); + var keyIndex = packetlist.indexOfTag(_enums2.default.packet.publicKey, _enums2.default.packet.secretKey); if (keyIndex.length === 0) { throw new Error('No key packet found in armored text'); } @@ -11495,7 +12895,7 @@ function readArmored(armoredText) { * @param {module:enums.publicKey} [options.keyType=module:enums.publicKey.rsa_encrypt_sign] to indicate what type of key to make. * RSA is 1. See {@link http://tools.ietf.org/html/rfc4880#section-9.1} * @param {Integer} options.numBits number of bits for the key creation. - * @param {String|Array} options.userId assumes already in form of "User Name " + * @param {String|Array} options.userIds assumes already in form of "User Name " If array is used, the first userId is set as primary user Id * @param {String} options.passphrase The passphrase used to encrypt the resulting private key * @param {Boolean} [options.unlocked=false] The secret part of the generated key is unlocked @@ -11505,17 +12905,17 @@ function readArmored(armoredText) { function generate(options) { var packetlist, secretKeyPacket, userIdPacket, dataToSign, signaturePacket, secretSubkeyPacket, subkeySignaturePacket; - options.keyType = options.keyType || enums.publicKey.rsa_encrypt_sign; + options.keyType = options.keyType || _enums2.default.publicKey.rsa_encrypt_sign; // RSA Encrypt-Only and RSA Sign-Only are deprecated and SHOULD NOT be generated - if (options.keyType !== enums.publicKey.rsa_encrypt_sign) { + if (options.keyType !== _enums2.default.publicKey.rsa_encrypt_sign) { throw new Error('Only RSA Encrypt or Sign supported'); } // Key without passphrase is unlocked by definition if (!options.passphrase) { options.unlocked = true; } - if (String.prototype.isPrototypeOf(options.userId) || typeof options.userId === 'string') { - options.userId = [options.userId]; + if (String.prototype.isPrototypeOf(options.userIds) || typeof options.userIds === 'string') { + options.userIds = [options.userIds]; } // generate @@ -11524,14 +12924,14 @@ function generate(options) { return Promise.all([genSecretKey, genSecretSubkey]).then(wrapKeyObject); function generateSecretKey() { - secretKeyPacket = new packet.SecretKey(); - secretKeyPacket.algorithm = enums.read(enums.publicKey, options.keyType); + secretKeyPacket = new _packet2.default.SecretKey(); + secretKeyPacket.algorithm = _enums2.default.read(_enums2.default.publicKey, options.keyType); return secretKeyPacket.generate(options.numBits); } function generateSecretSubkey() { - secretSubkeyPacket = new packet.SecretSubkey(); - secretSubkeyPacket.algorithm = enums.read(enums.publicKey, options.keyType); + secretSubkeyPacket = new _packet2.default.SecretSubkey(); + secretSubkeyPacket.algorithm = _enums2.default.read(_enums2.default.publicKey, options.keyType); return secretSubkeyPacket.generate(options.numBits); } @@ -11542,40 +12942,40 @@ function generate(options) { secretSubkeyPacket.encrypt(options.passphrase); } - packetlist = new packet.List(); + packetlist = new _packet2.default.List(); packetlist.push(secretKeyPacket); - options.userId.forEach(function(userId, index) { + options.userIds.forEach(function (userId, index) { - userIdPacket = new packet.Userid(); - userIdPacket.read(userId); + userIdPacket = new _packet2.default.Userid(); + userIdPacket.read(_util2.default.str2Uint8Array(userId)); dataToSign = {}; dataToSign.userid = userIdPacket; dataToSign.key = secretKeyPacket; - signaturePacket = new packet.Signature(); - signaturePacket.signatureType = enums.signature.cert_generic; + signaturePacket = new _packet2.default.Signature(); + signaturePacket.signatureType = _enums2.default.signature.cert_generic; signaturePacket.publicKeyAlgorithm = options.keyType; - signaturePacket.hashAlgorithm = config.prefer_hash_algorithm; - signaturePacket.keyFlags = [enums.keyFlags.certify_keys | enums.keyFlags.sign_data]; + signaturePacket.hashAlgorithm = _config2.default.prefer_hash_algorithm; + signaturePacket.keyFlags = [_enums2.default.keyFlags.certify_keys | _enums2.default.keyFlags.sign_data]; signaturePacket.preferredSymmetricAlgorithms = []; - signaturePacket.preferredSymmetricAlgorithms.push(enums.symmetric.aes256); - signaturePacket.preferredSymmetricAlgorithms.push(enums.symmetric.aes192); - signaturePacket.preferredSymmetricAlgorithms.push(enums.symmetric.aes128); - signaturePacket.preferredSymmetricAlgorithms.push(enums.symmetric.cast5); - signaturePacket.preferredSymmetricAlgorithms.push(enums.symmetric.tripledes); + signaturePacket.preferredSymmetricAlgorithms.push(_enums2.default.symmetric.aes256); + signaturePacket.preferredSymmetricAlgorithms.push(_enums2.default.symmetric.aes192); + signaturePacket.preferredSymmetricAlgorithms.push(_enums2.default.symmetric.aes128); + signaturePacket.preferredSymmetricAlgorithms.push(_enums2.default.symmetric.cast5); + signaturePacket.preferredSymmetricAlgorithms.push(_enums2.default.symmetric.tripledes); signaturePacket.preferredHashAlgorithms = []; - signaturePacket.preferredHashAlgorithms.push(enums.hash.sha256); - signaturePacket.preferredHashAlgorithms.push(enums.hash.sha1); - signaturePacket.preferredHashAlgorithms.push(enums.hash.sha512); + signaturePacket.preferredHashAlgorithms.push(_enums2.default.hash.sha256); + signaturePacket.preferredHashAlgorithms.push(_enums2.default.hash.sha1); + signaturePacket.preferredHashAlgorithms.push(_enums2.default.hash.sha512); signaturePacket.preferredCompressionAlgorithms = []; - signaturePacket.preferredCompressionAlgorithms.push(enums.compression.zlib); - signaturePacket.preferredCompressionAlgorithms.push(enums.compression.zip); + signaturePacket.preferredCompressionAlgorithms.push(_enums2.default.compression.zlib); + signaturePacket.preferredCompressionAlgorithms.push(_enums2.default.compression.zip); if (index === 0) { signaturePacket.isPrimaryUserID = true; } - if (config.integrity_protect) { + if (_config2.default.integrity_protect) { signaturePacket.features = []; signaturePacket.features.push(1); // Modification Detection } @@ -11583,17 +12983,16 @@ function generate(options) { packetlist.push(userIdPacket); packetlist.push(signaturePacket); - }); dataToSign = {}; dataToSign.key = secretKeyPacket; dataToSign.bind = secretSubkeyPacket; - subkeySignaturePacket = new packet.Signature(); - subkeySignaturePacket.signatureType = enums.signature.subkey_binding; + subkeySignaturePacket = new _packet2.default.Signature(); + subkeySignaturePacket.signatureType = _enums2.default.signature.subkey_binding; subkeySignaturePacket.publicKeyAlgorithm = options.keyType; - subkeySignaturePacket.hashAlgorithm = config.prefer_hash_algorithm; - subkeySignaturePacket.keyFlags = [enums.keyFlags.encrypt_communication | enums.keyFlags.encrypt_storage]; + subkeySignaturePacket.hashAlgorithm = _config2.default.prefer_hash_algorithm; + subkeySignaturePacket.keyFlags = [_enums2.default.keyFlags.encrypt_communication | _enums2.default.keyFlags.encrypt_storage]; subkeySignaturePacket.sign(secretKeyPacket, dataToSign); packetlist.push(secretSubkeyPacket); @@ -11615,25 +13014,24 @@ function generate(options) { */ function getPreferredSymAlgo(keys) { var prioMap = {}; - for (var i = 0; i < keys.length; i++) { - var primaryUser = keys[i].getPrimaryUser(); + keys.forEach(function (key) { + var primaryUser = key.getPrimaryUser(); if (!primaryUser || !primaryUser.selfCertificate.preferredSymmetricAlgorithms) { - return config.encryption_cipher; + return _config2.default.encryption_cipher; } - primaryUser.selfCertificate.preferredSymmetricAlgorithms.forEach(function(algo, index) { - var entry = prioMap[algo] || (prioMap[algo] = {prio: 0, count: 0, algo: algo}); + primaryUser.selfCertificate.preferredSymmetricAlgorithms.forEach(function (algo, index) { + var entry = prioMap[algo] || (prioMap[algo] = { prio: 0, count: 0, algo: algo }); entry.prio += 64 >> index; entry.count++; }); - } - var prefAlgo = {prio: 0, algo: config.encryption_cipher}; + }); + var prefAlgo = { prio: 0, algo: _config2.default.encryption_cipher }; for (var algo in prioMap) { try { - if (algo !== enums.symmetric.plaintext && - algo !== enums.symmetric.idea && // not implemented - enums.read(enums.symmetric, algo) && // known algorithm - prioMap[algo].count === keys.length && // available for all keys - prioMap[algo].prio > prefAlgo.prio) { + if (algo !== _enums2.default.symmetric.plaintext && algo !== _enums2.default.symmetric.idea && // not implemented + _enums2.default.read(_enums2.default.symmetric, algo) && // known algorithm + prioMap[algo].count === keys.length && // available for all keys + prioMap[algo].prio > prefAlgo.prio) { prefAlgo = prioMap[algo]; } } catch (e) {} @@ -11641,33 +13039,46 @@ function getPreferredSymAlgo(keys) { return prefAlgo.algo; } -exports.Key = Key; -exports.readArmored = readArmored; -exports.generate = generate; -exports.getPreferredSymAlgo = getPreferredSymAlgo; +},{"./config":19,"./encoding/armor.js":41,"./enums.js":43,"./packet":55,"./util":76}],47:[function(require,module,exports){ +'use strict'; -},{"./config":17,"./encoding/armor.js":41,"./enums.js":43,"./packet":55,"./util":76}],48:[function(require,module,exports){ /** * @see module:keyring/keyring * @module keyring */ -module.exports = require('./keyring.js'); -module.exports.localstore = require('./localstore.js'); -},{"./keyring.js":49,"./localstore.js":50}],49:[function(require,module,exports){ +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _keyring = require('./keyring.js'); + +var _keyring2 = _interopRequireDefault(_keyring); + +var _localstore = require('./localstore.js'); + +var _localstore2 = _interopRequireDefault(_localstore); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +_keyring2.default.localstore = _localstore2.default; + +exports.default = _keyring2.default; + +},{"./keyring.js":48,"./localstore.js":49}],48:[function(require,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 @@ -11680,20 +13091,33 @@ module.exports.localstore = require('./localstore.js'); * @module keyring/keyring */ -var enums = require('../enums.js'), - keyModule = require('../key.js'), - util = require('../util.js'); +'use strict'; -module.exports = Keyring; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Keyring; - /** +var _key = require('../key.js'); + +var keyModule = _interopRequireWildcard(_key); + +var _localstore = require('./localstore.js'); + +var _localstore2 = _interopRequireDefault(_localstore); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +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; } } + +/** * Initialization routine for the keyring. This method reads the * keyring from HTML5 local storage and initializes this instance. * @constructor * @param {class} [storeHandler] class implementing load() and store() methods */ function Keyring(storeHandler) { - this.storeHandler = storeHandler || new (require('./localstore.js'))(); + this.storeHandler = storeHandler || new _localstore2.default(); this.publicKeys = new KeyArray(this.storeHandler.loadPublic()); this.privateKeys = new KeyArray(this.storeHandler.loadPrivate()); } @@ -11709,7 +13133,7 @@ Keyring.prototype.store = function () { /** * Clear the keyring - erase all the keys */ -Keyring.prototype.clear = function() { +Keyring.prototype.clear = function () { this.publicKeys.keys = []; this.privateKeys.keys = []; }; @@ -11762,7 +13186,7 @@ function KeyArray(keys) { * @param {String} email email address to search for * @return {Array} The public keys associated with provided email address. */ -KeyArray.prototype.getForAddress = function(email) { +KeyArray.prototype.getForAddress = function (email) { var results = []; for (var i = 0; i < this.keys.length; i++) { if (emailCheck(email, this.keys[i])) { @@ -11841,7 +13265,7 @@ KeyArray.prototype.getForId = function (keyId, deep) { KeyArray.prototype.importKey = function (armored) { var imported = keyModule.readArmored(armored); var that = this; - imported.keys.forEach(function(key) { + imported.keys.forEach(function (key) { // check if key already in key array var keyidHex = key.primaryKey.getKeyId().toHex(); var keyFound = that.getForId(keyidHex); @@ -11878,20 +13302,20 @@ KeyArray.prototype.removeForId = function (keyId) { return null; }; -},{"../enums.js":43,"../key.js":47,"../util.js":76,"./localstore.js":50}],50:[function(require,module,exports){ +},{"../key.js":46,"./localstore.js":49}],49:[function(require,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 @@ -11902,20 +13326,38 @@ KeyArray.prototype.removeForId = function (keyId) { * @module keyring/localstore * @param {String} prefix prefix for itemnames in localstore */ -module.exports = LocalStore; -var config = require('../config'), - keyModule = require('../key.js'), - util = require('../util.js'); +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = LocalStore; + +var _config = require('../config'); + +var _config2 = _interopRequireDefault(_config); + +var _key = require('../key.js'); + +var keyModule = _interopRequireWildcard(_key); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +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 }; } function LocalStore(prefix) { prefix = prefix || 'openpgp-'; this.publicKeysItem = prefix + this.publicKeysItem; this.privateKeysItem = prefix + this.privateKeysItem; - if (typeof window != 'undefined' && window.localStorage) { + if (typeof window !== 'undefined' && window.localStorage) { this.storage = window.localStorage; } else { - this.storage = new (require('node-localstorage').LocalStorage)(config.node_store); + this.storage = new (require('node-localstorage').LocalStorage)(_config2.default.node_store); } } @@ -11951,7 +13393,7 @@ function loadKeys(storage, itemname) { if (!key.err) { keys.push(key.keys[0]); } else { - util.print_debug("Error reading armored key from keyring index: " + i); + _util2.default.print_debug("Error reading armored key from keyring index: " + i); } } } @@ -11988,7 +13430,7 @@ function storeKeys(storage, itemname, keys) { } } -},{"../config":17,"../key.js":47,"../util.js":76,"node-localstorage":"node-localstorage"}],51:[function(require,module,exports){ +},{"../config":19,"../key.js":46,"../util.js":76,"node-localstorage":"node-localstorage"}],50:[function(require,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -12017,12 +13459,48 @@ function storeKeys(storage, itemname, keys) { 'use strict'; -var packet = require('./packet'), - enums = require('./enums.js'), - armor = require('./encoding/armor.js'), - config = require('./config'), - crypto = require('./crypto'), - keyModule = require('./key.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Message = Message; +exports.encryptSessionKey = encryptSessionKey; +exports.readArmored = readArmored; +exports.read = read; +exports.readSignedContent = readSignedContent; +exports.fromText = fromText; +exports.fromBinary = fromBinary; + +var _util = require('./util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _packet = require('./packet'); + +var _packet2 = _interopRequireDefault(_packet); + +var _enums = require('./enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _armor = require('./encoding/armor.js'); + +var _armor2 = _interopRequireDefault(_armor); + +var _config = require('./config'); + +var _config2 = _interopRequireDefault(_config); + +var _crypto = require('./crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +var _key = require('./key.js'); + +var keyModule = _interopRequireWildcard(_key); + +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 @@ -12036,17 +13514,17 @@ function Message(packetlist) { if (!(this instanceof Message)) { return new Message(packetlist); } - this.packets = packetlist || new packet.List(); + this.packets = packetlist || new _packet2.default.List(); } /** * Returns the key IDs of the keys to which the session key is encrypted * @return {Array} array of keyid objects */ -Message.prototype.getEncryptionKeyIds = function() { +Message.prototype.getEncryptionKeyIds = function () { var keyIds = []; - var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey); - pkESKeyPacketlist.forEach(function(packet) { + var pkESKeyPacketlist = this.packets.filterByTag(_enums2.default.packet.publicKeyEncryptedSessionKey); + pkESKeyPacketlist.forEach(function (packet) { keyIds.push(packet.publicKeyId); }); return keyIds; @@ -12056,18 +13534,18 @@ Message.prototype.getEncryptionKeyIds = function() { * Returns the key IDs of the keys that signed the message * @return {Array} array of keyid objects */ -Message.prototype.getSigningKeyIds = function() { +Message.prototype.getSigningKeyIds = function () { var keyIds = []; var msg = this.unwrapCompressed(); // search for one pass signatures - var onePassSigList = msg.packets.filterByTag(enums.packet.onePassSignature); - onePassSigList.forEach(function(packet) { + var onePassSigList = msg.packets.filterByTag(_enums2.default.packet.onePassSignature); + onePassSigList.forEach(function (packet) { keyIds.push(packet.signingKeyId); }); // if nothing found look for signature packets if (!keyIds.length) { - var signatureList = msg.packets.filterByTag(enums.packet.signature); - signatureList.forEach(function(packet) { + var signatureList = msg.packets.filterByTag(_enums2.default.packet.signature); + signatureList.forEach(function (packet) { keyIds.push(packet.issuerKeyId); }); } @@ -12075,55 +13553,109 @@ Message.prototype.getSigningKeyIds = function() { }; /** - * Decrypt the message - * @param {module:key~Key} privateKey private key with decrypted secret data - * @return {Array} new message with decrypted content + * Decrypt the message. Either a private key, a session key, or a password must be specified. + * @param {Key} privateKey (optional) private key with decrypted secret data + * @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String } + * @param {String} password (optional) password used to decrypt + * @return {Message} new message with decrypted content */ -Message.prototype.decrypt = function(privateKey) { - var encryptionKeyIds = this.getEncryptionKeyIds(); - if (!encryptionKeyIds.length) { - // nothing to decrypt return unmodified message - return this; +Message.prototype.decrypt = function (privateKey, sessionKey, password) { + var keyObj = sessionKey || this.decryptSessionKey(privateKey, password); + if (!keyObj || !_util2.default.isUint8Array(keyObj.data) || !_util2.default.isString(keyObj.algorithm)) { + throw new Error('Invalid session key for decryption.'); } - var privateKeyPacket = privateKey.getKeyPacket(encryptionKeyIds); - if (!privateKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.'); - var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey); - var pkESKeyPacket; - for (var i = 0; i < pkESKeyPacketlist.length; i++) { - if (pkESKeyPacketlist[i].publicKeyId.equals(privateKeyPacket.getKeyId())) { - pkESKeyPacket = pkESKeyPacketlist[i]; - pkESKeyPacket.decrypt(privateKeyPacket); - break; - } + var symEncryptedPacketlist = this.packets.filterByTag(_enums2.default.packet.symmetricallyEncrypted, _enums2.default.packet.symEncryptedIntegrityProtected); + if (symEncryptedPacketlist.length !== 0) { + var symEncryptedPacket = symEncryptedPacketlist[0]; + symEncryptedPacket.decrypt(keyObj.algorithm, keyObj.data); + var resultMsg = new Message(symEncryptedPacket.packets); + // remove packets after decryption + symEncryptedPacket.packets = new _packet2.default.List(); + return resultMsg; } - if (pkESKeyPacket) { - var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetricallyEncrypted, enums.packet.symEncryptedIntegrityProtected); - if (symEncryptedPacketlist.length !== 0) { - var symEncryptedPacket = symEncryptedPacketlist[0]; - symEncryptedPacket.decrypt(pkESKeyPacket.sessionKeyAlgorithm, pkESKeyPacket.sessionKey); - var resultMsg = new Message(symEncryptedPacket.packets); - // remove packets after decryption - symEncryptedPacket.packets = new packet.List(); - return resultMsg; +}; + +/** + * Decrypt an encrypted session key either with a private key or a password. + * @param {Key} privateKey (optional) private key with decrypted secret data + * @param {String} password (optional) password used to decrypt + * @return {Object} object with sessionKey, algorithm in the form: + * { data:Uint8Array, algorithm:String } + */ +Message.prototype.decryptSessionKey = function (privateKey, password) { + var keyPacket; + + if (password) { + var symEncryptedSessionKeyPacketlist = this.packets.filterByTag(_enums2.default.packet.symEncryptedSessionKey); + var symLength = symEncryptedSessionKeyPacketlist.length; + for (var i = 0; i < symLength; i++) { + keyPacket = symEncryptedSessionKeyPacketlist[i]; + try { + keyPacket.decrypt(password); + break; + } catch (err) { + if (i === symLength - 1) { + throw err; + } + } } + if (!keyPacket) { + throw new Error('No symmetrically encrypted session key packet found.'); + } + } else if (privateKey) { + var encryptionKeyIds = this.getEncryptionKeyIds(); + if (!encryptionKeyIds.length) { + // nothing to decrypt + return; + } + var privateKeyPacket = privateKey.getKeyPacket(encryptionKeyIds); + if (!privateKeyPacket.isDecrypted) { + throw new Error('Private key is not decrypted.'); + } + var pkESKeyPacketlist = this.packets.filterByTag(_enums2.default.packet.publicKeyEncryptedSessionKey); + for (var j = 0; j < pkESKeyPacketlist.length; j++) { + if (pkESKeyPacketlist[j].publicKeyId.equals(privateKeyPacket.getKeyId())) { + keyPacket = pkESKeyPacketlist[j]; + keyPacket.decrypt(privateKeyPacket); + break; + } + } + } else { + throw new Error('No key or password specified.'); + } + + if (keyPacket) { + return { + data: keyPacket.sessionKey, + algorithm: keyPacket.sessionKeyAlgorithm + }; } }; /** * Get literal data that is the body of the message - * @return {(String|null)} literal body of the message as string + * @return {(Uint8Array|null)} literal body of the message as Uint8Array */ -Message.prototype.getLiteralData = function() { - var literal = this.packets.findPacket(enums.packet.literal); +Message.prototype.getLiteralData = function () { + var literal = this.packets.findPacket(_enums2.default.packet.literal); return literal && literal.data || null; }; +/** + * Get filename from literal data packet + * @return {(String|null)} filename of literal data packet as string + */ +Message.prototype.getFilename = function () { + var literal = this.packets.findPacket(_enums2.default.packet.literal); + return literal && literal.getFilename() || null; +}; + /** * Get literal data as text * @return {(String|null)} literal body of the message interpreted as text */ -Message.prototype.getText = function() { - var literal = this.packets.findPacket(enums.packet.literal); +Message.prototype.getText = function () { + var literal = this.packets.findPacket(_enums2.default.packet.literal); if (literal) { return literal.getText(); } else { @@ -12132,120 +13664,108 @@ Message.prototype.getText = function() { }; /** - * Encrypt the message - * @param {Array} keys array of keys, used to encrypt the message - * @return {Array} new message with encrypted content + * Encrypt the message either with public keys, passwords, or both at once. + * @param {Array} keys (optional) public key(s) for message encryption + * @param {Array} passwords (optional) password(s) for message encryption + * @return {Message} new message with encrypted content */ -Message.prototype.encrypt = function(keys) { - var packetlist = new packet.List(); - var symAlgo = keyModule.getPreferredSymAlgo(keys); - var sessionKey = crypto.generateSessionKey(enums.read(enums.symmetric, symAlgo)); - keys.forEach(function(key) { - var encryptionKeyPacket = key.getEncryptionKeyPacket(); - if (encryptionKeyPacket) { - var pkESKeyPacket = new packet.PublicKeyEncryptedSessionKey(); - pkESKeyPacket.publicKeyId = encryptionKeyPacket.getKeyId(); - pkESKeyPacket.publicKeyAlgorithm = encryptionKeyPacket.algorithm; - pkESKeyPacket.sessionKey = sessionKey; - pkESKeyPacket.sessionKeyAlgorithm = enums.read(enums.symmetric, symAlgo); - pkESKeyPacket.encrypt(encryptionKeyPacket); - packetlist.push(pkESKeyPacket); - } else { - throw new Error('Could not find valid key packet for encryption in key ' + key.primaryKey.getKeyId().toHex()); - } - }); - var symEncryptedPacket; - if (config.integrity_protect) { - symEncryptedPacket = new packet.SymEncryptedIntegrityProtected(); +Message.prototype.encrypt = function (keys, passwords) { + var symAlgo; + if (keys) { + symAlgo = keyModule.getPreferredSymAlgo(keys); + } else if (passwords) { + symAlgo = _config2.default.encryption_cipher; } else { - symEncryptedPacket = new packet.SymmetricallyEncrypted(); + throw new Error('No keys or passwords'); + } + + var sessionKey = _crypto2.default.generateSessionKey(_enums2.default.read(_enums2.default.symmetric, symAlgo)); + var msg = encryptSessionKey(sessionKey, _enums2.default.read(_enums2.default.symmetric, symAlgo), keys, passwords); + var packetlist = msg.packets; + + var symEncryptedPacket; + if (_config2.default.integrity_protect) { + symEncryptedPacket = new _packet2.default.SymEncryptedIntegrityProtected(); + } else { + symEncryptedPacket = new _packet2.default.SymmetricallyEncrypted(); } symEncryptedPacket.packets = this.packets; - symEncryptedPacket.encrypt(enums.read(enums.symmetric, symAlgo), sessionKey); + symEncryptedPacket.encrypt(_enums2.default.read(_enums2.default.symmetric, symAlgo), sessionKey); packetlist.push(symEncryptedPacket); // remove packets after encryption - symEncryptedPacket.packets = new packet.List(); - return new Message(packetlist); + symEncryptedPacket.packets = new _packet2.default.List(); + + return msg; }; /** - * Encrypt the message symmetrically using a passphrase. - * https://tools.ietf.org/html/rfc4880#section-3.7.2.2 - * @param {String} passphrase - * @return {Array} new message with encrypted content + * Encrypt a session key either with public keys, passwords, or both at once. + * @param {Uint8Array} sessionKey session key for encryption + * @param {String} symAlgo session key algorithm + * @param {Array} publicKeys (optional) public key(s) for message encryption + * @param {Array} passwords (optional) for message encryption + * @return {Message} new message with encrypted content */ -Message.prototype.symEncrypt = function(passphrase) { - if (!passphrase) { - throw new Error('The passphrase cannot be empty!'); +function encryptSessionKey(sessionKey, symAlgo, publicKeys, passwords) { + var packetlist = new _packet2.default.List(); + + if (publicKeys) { + publicKeys.forEach(function (key) { + var encryptionKeyPacket = key.getEncryptionKeyPacket(); + if (encryptionKeyPacket) { + var pkESKeyPacket = new _packet2.default.PublicKeyEncryptedSessionKey(); + pkESKeyPacket.publicKeyId = encryptionKeyPacket.getKeyId(); + pkESKeyPacket.publicKeyAlgorithm = encryptionKeyPacket.algorithm; + pkESKeyPacket.sessionKey = sessionKey; + pkESKeyPacket.sessionKeyAlgorithm = symAlgo; + pkESKeyPacket.encrypt(encryptionKeyPacket); + delete pkESKeyPacket.sessionKey; // delete plaintext session key after encryption + packetlist.push(pkESKeyPacket); + } else { + throw new Error('Could not find valid key packet for encryption in key ' + key.primaryKey.getKeyId().toHex()); + } + }); } - var algo = enums.read(enums.symmetric, config.encryption_cipher); - var packetlist = new packet.List(); + if (passwords) { + passwords.forEach(function (password) { + var symEncryptedSessionKeyPacket = new _packet2.default.SymEncryptedSessionKey(); + symEncryptedSessionKeyPacket.sessionKey = sessionKey; + symEncryptedSessionKeyPacket.sessionKeyAlgorithm = symAlgo; + symEncryptedSessionKeyPacket.encrypt(password); + delete symEncryptedSessionKeyPacket.sessionKey; // delete plaintext session key after encryption + packetlist.push(symEncryptedSessionKeyPacket); + }); + } - // create a Symmetric-key Encrypted Session Key (ESK) - var symESKPacket = new packet.SymEncryptedSessionKey(); - symESKPacket.sessionKeyAlgorithm = algo; - symESKPacket.decrypt(passphrase); // generate the session key - packetlist.push(symESKPacket); - - // create integrity protected packet - var symEncryptedPacket = new packet.SymEncryptedIntegrityProtected(); - symEncryptedPacket.packets = this.packets; - symEncryptedPacket.encrypt(algo, symESKPacket.sessionKey); - packetlist.push(symEncryptedPacket); - - // remove packets after encryption - symEncryptedPacket.packets = new packet.List(); return new Message(packetlist); -}; - -/** - * Decrypt the message symmetrically using a passphrase. - * https://tools.ietf.org/html/rfc4880#section-3.7.2.2 - * @param {String} passphrase - * @return {Array} new message with decrypted content - */ -Message.prototype.symDecrypt = function(passphrase) { - var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symEncryptedSessionKey, enums.packet.symEncryptedIntegrityProtected); - - // decrypt Symmetric-key Encrypted Session Key (ESK) - var symESKPacket = symEncryptedPacketlist[0]; - symESKPacket.decrypt(passphrase); - - // decrypt integrity protected packet - var symEncryptedPacket = symEncryptedPacketlist[1]; - symEncryptedPacket.decrypt(symESKPacket.sessionKeyAlgorithm, symESKPacket.sessionKey); - - var resultMsg = new Message(symEncryptedPacket.packets); - // remove packets after decryption - symEncryptedPacket.packets = new packet.List(); - return resultMsg; -}; +} /** * Sign the message (the literal data packet of the message) * @param {Array} privateKey private keys with decrypted secret key data for signing * @return {module:message~Message} new message with signed content */ -Message.prototype.sign = function(privateKeys) { +Message.prototype.sign = function (privateKeys) { - var packetlist = new packet.List(); + var packetlist = new _packet2.default.List(); - var literalDataPacket = this.packets.findPacket(enums.packet.literal); - if (!literalDataPacket) throw new Error('No literal data packet to sign.'); + var literalDataPacket = this.packets.findPacket(_enums2.default.packet.literal); + if (!literalDataPacket) { + throw new Error('No literal data packet to sign.'); + } - var literalFormat = enums.write(enums.literal, literalDataPacket.format); - var signatureType = literalFormat == enums.literal.binary ? - enums.signature.binary : enums.signature.text; + var literalFormat = _enums2.default.write(_enums2.default.literal, literalDataPacket.format); + var signatureType = literalFormat === _enums2.default.literal.binary ? _enums2.default.signature.binary : _enums2.default.signature.text; var i, signingKeyPacket; for (i = 0; i < privateKeys.length; i++) { if (privateKeys[i].isPublic()) { throw new Error('Need private key for signing'); } - var onePassSig = new packet.OnePassSignature(); + var onePassSig = new _packet2.default.OnePassSignature(); onePassSig.type = signatureType; //TODO get preferred hashg algo from key signature - onePassSig.hashAlgorithm = config.prefer_hash_algorithm; + onePassSig.hashAlgorithm = _config2.default.prefer_hash_algorithm; signingKeyPacket = privateKeys[i].getSigningKeyPacket(); if (!signingKeyPacket) { throw new Error('Could not find valid key packet for signing in key ' + privateKeys[i].primaryKey.getKeyId().toHex()); @@ -12258,11 +13778,13 @@ Message.prototype.sign = function(privateKeys) { packetlist.push(literalDataPacket); for (i = privateKeys.length - 1; i >= 0; i--) { - var signaturePacket = new packet.Signature(); + var signaturePacket = new _packet2.default.Signature(); signaturePacket.signatureType = signatureType; - signaturePacket.hashAlgorithm = config.prefer_hash_algorithm; + signaturePacket.hashAlgorithm = _config2.default.prefer_hash_algorithm; signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm; - if (!signingKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.'); + if (!signingKeyPacket.isDecrypted) { + throw new Error('Private key is not decrypted.'); + } signaturePacket.sign(signingKeyPacket, literalDataPacket); packetlist.push(signaturePacket); } @@ -12275,12 +13797,14 @@ Message.prototype.sign = function(privateKeys) { * @param {Array} keys array of keys to verify signatures * @return {Array<({keyid: module:type/keyid, valid: Boolean})>} list of signer's keyid and validity of signature */ -Message.prototype.verify = function(keys) { +Message.prototype.verify = function (keys) { var result = []; var msg = this.unwrapCompressed(); - var literalDataList = msg.packets.filterByTag(enums.packet.literal); - if (literalDataList.length !== 1) throw new Error('Can only verify message with one literal data packet.'); - var signatureList = msg.packets.filterByTag(enums.packet.signature); + var literalDataList = msg.packets.filterByTag(_enums2.default.packet.literal); + if (literalDataList.length !== 1) { + throw new Error('Can only verify message with one literal data packet.'); + } + var signatureList = msg.packets.filterByTag(_enums2.default.packet.signature); for (var i = 0; i < signatureList.length; i++) { var keyPacket = null; for (var j = 0; j < keys.length; j++) { @@ -12307,8 +13831,8 @@ Message.prototype.verify = function(keys) { * Unwrap compressed message * @return {module:message~Message} message Content of compressed message */ -Message.prototype.unwrapCompressed = function() { - var compressed = this.packets.filterByTag(enums.packet.compressed); +Message.prototype.unwrapCompressed = function () { + var compressed = this.packets.filterByTag(_enums2.default.packet.compressed); if (compressed.length) { return new Message(compressed[0].packets); } else { @@ -12320,8 +13844,8 @@ Message.prototype.unwrapCompressed = function() { * Returns ASCII armored text of message * @return {String} ASCII armor */ -Message.prototype.armor = function() { - return armor.encode(enums.armor.message, this.packets.write()); +Message.prototype.armor = function () { + return _armor2.default.encode(_enums2.default.armor.message, this.packets.write()); }; /** @@ -12333,8 +13857,18 @@ Message.prototype.armor = function() { function readArmored(armoredText) { //TODO how do we want to handle bad text? Exception throwing //TODO don't accept non-message armored texts - var input = armor.decode(armoredText).data; - var packetlist = new packet.List(); + var input = _armor2.default.decode(armoredText).data; + return read(input); +} + +/** + * reads an OpenPGP message as byte array and returns a message object + * @param {Uint8Array} input binary message + * @return {Message} new message object + * @static + */ +function read(input) { + var packetlist = new _packet2.default.List(); packetlist.read(input); return new Message(packetlist); } @@ -12342,14 +13876,14 @@ function readArmored(armoredText) { /** * Create a message object from signed content and a detached armored signature. * @param {String} content An 8 bit ascii string containing e.g. a MIME subtree with text nodes or attachments - * @param {String} detachedSignature The detached ascii armored PGP signarure + * @param {String} detachedSignature The detached ascii armored PGP signature */ function readSignedContent(content, detachedSignature) { - var literalDataPacket = new packet.Literal(); - literalDataPacket.setBytes(content, enums.read(enums.literal, enums.literal.binary)); - var packetlist = new packet.List(); + var literalDataPacket = new _packet2.default.Literal(); + literalDataPacket.setBytes(_util2.default.str2Uint8Array(content), _enums2.default.read(_enums2.default.literal, _enums2.default.literal.binary)); + var packetlist = new _packet2.default.List(); packetlist.push(literalDataPacket); - var input = armor.decode(detachedSignature).data; + var input = _armor2.default.decode(detachedSignature).data; packetlist.read(input); return new Message(packetlist); } @@ -12357,45 +13891,50 @@ function readSignedContent(content, detachedSignature) { /** * creates new message object from text * @param {String} text + * @param {String} filename (optional) * @return {module:message~Message} new message object * @static */ -function fromText(text) { - var literalDataPacket = new packet.Literal(); +function fromText(text, filename) { + var literalDataPacket = new _packet2.default.Literal(); // text will be converted to UTF8 literalDataPacket.setText(text); - var literalDataPacketlist = new packet.List(); + if (filename !== undefined) { + literalDataPacket.setFilename(filename); + } + var literalDataPacketlist = new _packet2.default.List(); literalDataPacketlist.push(literalDataPacket); return new Message(literalDataPacketlist); } /** * creates new message object from binary data - * @param {String} bytes - * @param {String} filename + * @param {Uint8Array} bytes + * @param {String} filename (optional) * @return {module:message~Message} new message object * @static */ function fromBinary(bytes, filename) { - var literalDataPacket = new packet.Literal(); + if (!_util2.default.isUint8Array(bytes)) { + throw new Error('Data must be in the form of a Uint8Array'); + } + + var literalDataPacket = new _packet2.default.Literal(); if (filename) { literalDataPacket.setFilename(filename); } - literalDataPacket.setBytes(bytes, enums.read(enums.literal, enums.literal.binary)); - var literalDataPacketlist = new packet.List(); + literalDataPacket.setBytes(bytes, _enums2.default.read(_enums2.default.literal, _enums2.default.literal.binary)); + if (filename !== undefined) { + literalDataPacket.setFilename(filename); + } + var literalDataPacketlist = new _packet2.default.List(); literalDataPacketlist.push(literalDataPacket); return new Message(literalDataPacketlist); } -exports.Message = Message; -exports.readArmored = readArmored; -exports.readSignedContent = readSignedContent; -exports.fromText = fromText; -exports.fromBinary = fromBinary; - -},{"./config":17,"./crypto":32,"./encoding/armor.js":41,"./enums.js":43,"./key.js":47,"./packet":55}],52:[function(require,module,exports){ -// GPG4Browsers - An OpenPGP implementation in javascript -// Copyright (C) 2011 Recurity Labs GmbH +},{"./config":19,"./crypto":32,"./encoding/armor.js":41,"./enums.js":43,"./key.js":46,"./packet":55,"./util.js":76}],51:[function(require,module,exports){ +// OpenPGP.js - An OpenPGP implementation in javascript +// Copyright (C) 2016 Tankred Hase // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12411,51 +13950,95 @@ exports.fromBinary = fromBinary; // 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 message + * @requires cleartext + * @requires key + * @requires config + * @requires util + * @module openpgp + */ + /** * @fileoverview The openpgp base module should provide all of the functionality * to consume the openpgp.js library. All additional classes are documented * for extending and developing on top of the base library. */ -/** - * @requires cleartext - * @requires config - * @requires encoding/armor - * @requires enums - * @requires message - * @requires packet - * @module openpgp - */ - 'use strict'; -var armor = require('./encoding/armor.js'), - enums = require('./enums.js'), - message = require('./message.js'), - cleartext = require('./cleartext.js'), - key = require('./key.js'), - util = require('./util'), - AsyncProxy = require('./worker/async_proxy.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.initWorker = initWorker; +exports.getWorker = getWorker; +exports.destroyWorker = destroyWorker; +exports.generateKey = generateKey; +exports.decryptKey = decryptKey; +exports.encrypt = encrypt; +exports.decrypt = decrypt; +exports.sign = sign; +exports.verify = verify; +exports.encryptSessionKey = encryptSessionKey; +exports.decryptSessionKey = decryptSessionKey; -require('es6-promise').polyfill(); // load ES6 Promises polyfill +var _message = require('./message.js'); -var asyncProxy = null; // instance of the asyncproxy +var messageLib = _interopRequireWildcard(_message); + +var _cleartext = require('./cleartext.js'); + +var cleartext = _interopRequireWildcard(_cleartext); + +var _key = require('./key.js'); + +var key = _interopRequireWildcard(_key); + +var _config = require('./config/config.js'); + +var _config2 = _interopRequireDefault(_config); + +var _util = require('./util'); + +var _util2 = _interopRequireDefault(_util); + +var _async_proxy = require('./worker/async_proxy.js'); + +var _async_proxy2 = _interopRequireDefault(_async_proxy); + +var _es6Promise = require('es6-promise'); + +var _es6Promise2 = _interopRequireDefault(_es6Promise); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +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; } } + +_es6Promise2.default.polyfill(); // load ES6 Promises polyfill + +////////////////////////// +// // +// Web Worker setup // +// // +////////////////////////// + +var asyncProxy = undefined; // instance of the asyncproxy /** * Set the path for the web worker script and create an instance of the async proxy - * @param {String} path relative path to the worker scripts, default: 'openpgp.worker.js' - * @param {Object} [options.worker=Object] alternative to path parameter: - * web worker initialized with 'openpgp.worker.js' - * @return {Boolean} true if worker created successfully + * @param {String} path relative path to the worker scripts, default: 'openpgp.worker.js' + * @param {Object} worker alternative to path parameter: web worker initialized with 'openpgp.worker.js' */ -function initWorker(path, options) { - if (options && options.worker || typeof window !== 'undefined' && window.Worker) { - options = options || {}; - options.config = this.config; - asyncProxy = new AsyncProxy(path, options); +function initWorker() { + var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + var _ref$path = _ref.path; + var path = _ref$path === undefined ? 'openpgp.worker.js' : _ref$path; + var worker = _ref.worker; + + if (worker || typeof window !== 'undefined' && window.Worker) { + asyncProxy = new _async_proxy2.default({ path: path, worker: worker, config: _config2.default }); return true; - } else { - return false; } } @@ -12468,318 +14051,674 @@ function getWorker() { } /** - * Encrypts message text with keys - * @param {(Array|module:key~Key)} keys array of keys or single key, used to encrypt the message - * @param {String} text message as native JavaScript string - * @return {Promise} encrypted ASCII armored message - * @static + * Cleanup the current instance of the web worker. */ -function encryptMessage(keys, text) { - if (!keys.length) { - keys = [keys]; - } - - if (asyncProxy) { - return asyncProxy.encryptMessage(keys, text); - } - - return execute(function() { - var msg, armored; - msg = message.fromText(text); - msg = msg.encrypt(keys); - armored = armor.encode(enums.armor.message, msg.packets.write()); - return armored; - - }, 'Error encrypting message!'); +function destroyWorker() { + asyncProxy = undefined; } -/** - * Signs message text and encrypts it - * @param {(Array|module:key~Key)} publicKeys array of keys or single key, used to encrypt the message - * @param {module:key~Key} privateKey private key with decrypted secret key data for signing - * @param {String} text message as native JavaScript string - * @return {Promise} encrypted ASCII armored message - * @static - */ -function signAndEncryptMessage(publicKeys, privateKey, text) { - if (!publicKeys.length) { - publicKeys = [publicKeys]; - } - - if (asyncProxy) { - return asyncProxy.signAndEncryptMessage(publicKeys, privateKey, text); - } - - return execute(function() { - var msg, armored; - msg = message.fromText(text); - msg = msg.sign([privateKey]); - msg = msg.encrypt(publicKeys); - armored = armor.encode(enums.armor.message, msg.packets.write()); - return armored; - - }, 'Error signing and encrypting message!'); -} +////////////////////// +// // +// Key handling // +// // +////////////////////// /** - * Decrypts message - * @param {module:key~Key} privateKey private key with decrypted secret key data - * @param {module:message~Message} msg the message object with the encrypted data - * @return {Promise<(String|null)>} decrypted message as as native JavaScript string - * or null if no literal data found + * Generates a new OpenPGP key pair. Currently only supports RSA keys. Primary and subkey will be of same type. + * @param {Array} userIds array of user IDs e.g. [{ name:'Phil Zimmermann', email:'phil@openpgp.org' }] + * @param {String} passphrase (optional) The passphrase used to encrypt the resulting private key + * @param {Number} numBits (optional) number of bits for the key creation. (should be 2048 or 4096) + * @param {Boolean} unlocked (optional) If the returned secret part of the generated key is unlocked + * @return {Promise} The generated key object in the form: + * { key:Key, privateKeyArmored:String, publicKeyArmored:String } * @static */ -function decryptMessage(privateKey, msg) { - if (asyncProxy) { - return asyncProxy.decryptMessage(privateKey, msg); +function generateKey() { + var _ref2 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + var _ref2$userIds = _ref2.userIds; + var userIds = _ref2$userIds === undefined ? [] : _ref2$userIds; + var passphrase = _ref2.passphrase; + var _ref2$numBits = _ref2.numBits; + var numBits = _ref2$numBits === undefined ? 2048 : _ref2$numBits; + var _ref2$unlocked = _ref2.unlocked; + var unlocked = _ref2$unlocked === undefined ? false : _ref2$unlocked; + + var options = formatUserIds({ userIds: userIds, passphrase: passphrase, numBits: numBits, unlocked: unlocked }); + + if (!_util2.default.getWebCrypto() && asyncProxy) { + // use web worker if web crypto apis are not supported + return asyncProxy.delegate('generateKey', options); } - return execute(function() { - msg = msg.decrypt(privateKey); - return msg.getText(); + return key.generate(options).then(function (newKey) { + return { - }, 'Error decrypting message!'); -} + key: newKey, + privateKeyArmored: newKey.armor(), + publicKeyArmored: newKey.toPublic().armor() -/** - * Decrypts message and verifies signatures - * @param {module:key~Key} privateKey private key with decrypted secret key data - * @param {(Array|module:key~Key)} publicKeys array of keys or single key, to verify signatures - * @param {module:message~Message} msg the message object with signed and encrypted data - * @return {Promise<{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}>} - * decrypted message as as native JavaScript string - * with verified signatures or null if no literal data found - * @static - */ -function decryptAndVerifyMessage(privateKey, publicKeys, msg) { - if (!publicKeys.length) { - publicKeys = [publicKeys]; - } + }; + }).catch(function (err) { - if (asyncProxy) { - return asyncProxy.decryptAndVerifyMessage(privateKey, publicKeys, msg); - } - - return execute(function() { - var result = {}; - msg = msg.decrypt(privateKey); - result.text = msg.getText(); - if (result.text) { - result.signatures = msg.verify(publicKeys); - return result; + // js fallback already tried + if (_config2.default.debug) { + console.error(err); } - return null; - - }, 'Error decrypting and verifying message!'); + if (!_util2.default.getWebCrypto()) { + throw new Error('Error generating keypair using js fallback'); + } + // fall back to js keygen in a worker + if (_config2.default.debug) { + console.log('Error generating keypair using native WebCrypto... falling back back to js'); + } + return asyncProxy.delegate('generateKey', options); + }).catch(onError.bind(null, 'Error generating keypair')); } /** - * Signs a cleartext message - * @param {(Array|module:key~Key)} privateKeys array of keys or single key with decrypted secret key data to sign cleartext - * @param {String} text cleartext - * @return {Promise} ASCII armored message - * @static + * Unlock a private key with your passphrase. + * @param {Key} privateKey the private key that is to be decrypted + * @param {String} passphrase the user's passphrase chosen during key generation + * @return {Key} the unlocked private key */ -function signClearMessage(privateKeys, text) { - if (!privateKeys.length) { - privateKeys = [privateKeys]; - } +function decryptKey(_ref3) { + var privateKey = _ref3.privateKey; + var passphrase = _ref3.passphrase; if (asyncProxy) { - return asyncProxy.signClearMessage(privateKeys, text); + // use web worker if available + return asyncProxy.delegate('decryptKey', { privateKey: privateKey, passphrase: passphrase }); } - return execute(function() { - var cleartextMessage = new cleartext.CleartextMessage(text); - cleartextMessage.sign(privateKeys); - return cleartextMessage.armor(); + return execute(function () { - }, 'Error signing cleartext message!'); + if (!privateKey.decrypt(passphrase)) { + throw new Error('Invalid passphrase'); + } + return { + key: privateKey + }; + }, 'Error decrypting private key'); +} + +/////////////////////////////////////////// +// // +// Message encryption and decryption // +// // +/////////////////////////////////////////// + +/** + * Encrypts message text/data with public keys, passwords or both at once. At least either public keys or passwords + * must be specified. If private keys are specified, those will be used to sign the message. + * @param {String|Uint8Array} data text/data to be encrypted as JavaScript binary string or Uint8Array + * @param {Key|Array} publicKeys (optional) array of keys or single key, used to encrypt the message + * @param {Key|Array} privateKeys (optional) private keys for signing. If omitted message will not be signed + * @param {String|Array} passwords (optional) array of passwords or a single password to encrypt the message + * @param {String} filename (optional) a filename for the literal data packet + * @param {Boolean} armor (optional) if the return value should be ascii armored or the message object + * @return {Promise} encrypted ASCII armored message, or the full Message object if 'armor' is false + * @static + */ +function encrypt(_ref4) { + var data = _ref4.data; + var publicKeys = _ref4.publicKeys; + var privateKeys = _ref4.privateKeys; + var passwords = _ref4.passwords; + var filename = _ref4.filename; + var _ref4$armor = _ref4.armor; + var armor = _ref4$armor === undefined ? true : _ref4$armor; + + checkData(data);publicKeys = toArray(publicKeys);privateKeys = toArray(privateKeys);passwords = toArray(passwords); + + if (asyncProxy) { + // use web worker if available + return asyncProxy.delegate('encrypt', { data: data, publicKeys: publicKeys, privateKeys: privateKeys, passwords: passwords, filename: filename, armor: armor }); + } + + return execute(function () { + + var message = createMessage(data, filename); + if (privateKeys) { + // sign the message only if private keys are specified + message = message.sign(privateKeys); + } + message = message.encrypt(publicKeys, passwords); + + if (armor) { + return { + data: message.armor() + }; + } + return { + message: message + }; + }, 'Error encrypting message'); +} + +/** + * Decrypts a message with the user's private key, a session key or a password. Either a private key, + * a session key or a password must be specified. + * @param {Message} message the message object with the encrypted data + * @param {Key} privateKey (optional) private key with decrypted secret key data or session key + * @param {Key|Array} publicKeys (optional) array of public keys or single key, to verify signatures + * @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String } + * @param {String} password (optional) single password to decrypt the message + * @param {String} format (optional) return data format either as 'utf8' or 'binary' + * @return {Promise} decrypted and verified message in the form: + * { data:Uint8Array|String, filename:String, signatures:[{ keyid:String, valid:Boolean }] } + * @static + */ +function decrypt(_ref5) { + var message = _ref5.message; + var privateKey = _ref5.privateKey; + var publicKeys = _ref5.publicKeys; + var sessionKey = _ref5.sessionKey; + var password = _ref5.password; + var _ref5$format = _ref5.format; + var format = _ref5$format === undefined ? 'utf8' : _ref5$format; + + checkMessage(message);publicKeys = toArray(publicKeys); + + if (asyncProxy) { + // use web worker if available + return asyncProxy.delegate('decrypt', { message: message, privateKey: privateKey, publicKeys: publicKeys, sessionKey: sessionKey, password: password, format: format }); + } + + return execute(function () { + + message = message.decrypt(privateKey, sessionKey, password); + var result = parseMessage(message, format); + if (publicKeys && result.data) { + // verify only if publicKeys are specified + result.signatures = message.verify(publicKeys); + } + return result; + }, 'Error decrypting message'); +} + +////////////////////////////////////////// +// // +// Message signing and verification // +// // +////////////////////////////////////////// + +/** + * Signs a cleartext message. + * @param {String} data cleartext input to be signed + * @param {Key|Array} privateKeys array of keys or single key with decrypted secret key data to sign cleartext + * @param {Boolean} armor (optional) if the return value should be ascii armored or the message object + * @return {Promise} ASCII armored message or the message of type CleartextMessage + * @static + */ +function sign(_ref6) { + var data = _ref6.data; + var privateKeys = _ref6.privateKeys; + var _ref6$armor = _ref6.armor; + var armor = _ref6$armor === undefined ? true : _ref6$armor; + + checkString(data); + privateKeys = toArray(privateKeys); + + if (asyncProxy) { + // use web worker if available + return asyncProxy.delegate('sign', { data: data, privateKeys: privateKeys, armor: armor }); + } + + return execute(function () { + + var cleartextMessage = new cleartext.CleartextMessage(data); + cleartextMessage.sign(privateKeys); + + if (armor) { + return { + data: cleartextMessage.armor() + }; + } + return { + message: cleartextMessage + }; + }, 'Error signing cleartext message'); } /** * Verifies signatures of cleartext signed message - * @param {(Array|module:key~Key)} publicKeys array of keys or single key, to verify signatures - * @param {module:cleartext~CleartextMessage} msg cleartext message object with signatures - * @return {Promise<{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}>} - * cleartext with status of verified signatures + * @param {Key|Array} publicKeys array of publicKeys or single key, to verify signatures + * @param {CleartextMessage} message cleartext message object with signatures + * @return {Promise} cleartext with status of verified signatures in the form of: + * { data:String, signatures: [{ keyid:String, valid:Boolean }] } * @static */ -function verifyClearSignedMessage(publicKeys, msg) { - if (!publicKeys.length) { - publicKeys = [publicKeys]; - } +function verify(_ref7) { + var message = _ref7.message; + var publicKeys = _ref7.publicKeys; + + checkCleartextMessage(message); + publicKeys = toArray(publicKeys); if (asyncProxy) { - return asyncProxy.verifyClearSignedMessage(publicKeys, msg); + // use web worker if available + return asyncProxy.delegate('verify', { message: message, publicKeys: publicKeys }); } - return execute(function() { - var result = {}; - if (!(msg instanceof cleartext.CleartextMessage)) { - throw new Error('Parameter [message] needs to be of type CleartextMessage.'); - } - result.text = msg.getText(); - result.signatures = msg.verify(publicKeys); - return result; + return execute(function () { + return { - }, 'Error verifying cleartext signed message!'); + data: message.getText(), + signatures: message.verify(publicKeys) + + }; + }, 'Error verifying cleartext signed message'); } +/////////////////////////////////////////////// +// // +// Session key encryption and decryption // +// // +/////////////////////////////////////////////// + /** - * Generates a new OpenPGP key pair. Currently only supports RSA keys. - * Primary and subkey will be of same type. - * @param {module:enums.publicKey} [options.keyType=module:enums.publicKey.rsa_encrypt_sign] to indicate what type of key to make. - * RSA is 1. See {@link http://tools.ietf.org/html/rfc4880#section-9.1} - * @param {Integer} options.numBits number of bits for the key creation. (should be 1024+, generally) - * @param {String} options.userId assumes already in form of "User Name " - * @param {String} options.passphrase The passphrase used to encrypt the resulting private key - * @param {Boolean} [options.unlocked=false] The secret part of the generated key is unlocked - * @return {Promise} {key: module:key~Key, privateKeyArmored: String, publicKeyArmored: String} + * Encrypt a symmetric session key with public keys, passwords, or both at once. At least either public keys + * or passwords must be specified. + * @param {Uint8Array} data the session key to be encrypted e.g. 16 random bytes (for aes128) + * @param {String} algorithm algorithm of the symmetric session key e.g. 'aes128' or 'aes256' + * @param {Key|Array} publicKeys (optional) array of public keys or single key, used to encrypt the key + * @param {String|Array} passwords (optional) passwords for the message + * @return {Promise} the encrypted session key packets contained in a message object * @static */ -function generateKeyPair(options) { - // use web worker if web crypto apis are not supported - if (!util.getWebCrypto() && asyncProxy) { - return asyncProxy.generateKeyPair(options); +function encryptSessionKey(_ref8) { + var data = _ref8.data; + var algorithm = _ref8.algorithm; + var publicKeys = _ref8.publicKeys; + var passwords = _ref8.passwords; + + checkbinary(data);checkString(algorithm, 'algorithm');publicKeys = toArray(publicKeys);passwords = toArray(passwords); + + if (asyncProxy) { + // use web worker if available + return asyncProxy.delegate('encryptSessionKey', { data: data, algorithm: algorithm, publicKeys: publicKeys, passwords: passwords }); } - return key.generate(options).then(function(newKey) { - var result = {}; - result.key = newKey; - result.privateKeyArmored = newKey.armor(); - result.publicKeyArmored = newKey.toPublic().armor(); - return result; + return execute(function () { + return { - }).catch(function(err) { - console.error(err); + message: messageLib.encryptSessionKey(data, algorithm, publicKeys, passwords) - if (!util.getWebCrypto()) { - // js fallback already tried - throw new Error('Error generating keypair using js fallback!'); - } - - // fall back to js keygen in a worker - console.log('Error generating keypair using native WebCrypto... falling back back to js!'); - return asyncProxy.generateKeyPair(options); - - }).catch(onError.bind(null, 'Error generating keypair!')); + }; + }, 'Error encrypting session key'); } -// -// helper functions -// +/** + * Decrypt a symmetric session key with a private key or password. Either a private key or + * a password must be specified. + * @param {Message} message a message object containing the encrypted session key packets + * @param {Key} privateKey (optional) private key with decrypted secret key data + * @param {String} password (optional) a single password to decrypt the session key + * @return {Promise} decrypted session key and algorithm in object form: + * { data:Uint8Array, algorithm:String } + * or 'undefined' if no key packets found + * @static + */ +function decryptSessionKey(_ref9) { + var message = _ref9.message; + var privateKey = _ref9.privateKey; + var password = _ref9.password; + + checkMessage(message); + + if (asyncProxy) { + // use web worker if available + return asyncProxy.delegate('decryptSessionKey', { message: message, privateKey: privateKey, password: password }); + } + + return execute(function () { + return message.decryptSessionKey(privateKey, password); + }, 'Error decrypting session key'); +} + +////////////////////////// +// // +// Helper functions // +// // +////////////////////////// /** - * Command pattern that wraps synchronous code into a promise + * Input validation + */ +function checkString(data, name) { + if (!_util2.default.isString(data)) { + throw new Error('Parameter [' + (name || 'data') + '] must be of type String'); + } +} +function checkbinary(data, name) { + if (!_util2.default.isUint8Array(data)) { + throw new Error('Parameter [' + (name || 'data') + '] must be of type Uint8Array'); + } +} +function checkData(data, name) { + if (!_util2.default.isUint8Array(data) && !_util2.default.isString(data)) { + throw new Error('Parameter [' + (name || 'data') + '] must be of type String or Uint8Array'); + } +} +function checkMessage(message) { + if (!messageLib.Message.prototype.isPrototypeOf(message)) { + throw new Error('Parameter [message] needs to be of type Message'); + } +} +function checkCleartextMessage(message) { + if (!cleartext.CleartextMessage.prototype.isPrototypeOf(message)) { + throw new Error('Parameter [message] needs to be of type CleartextMessage'); + } +} + +/** + * Format user ids for internal use. + */ +function formatUserIds(options) { + if (!options.userIds) { + return options; + } + options.userIds = toArray(options.userIds); // normalize to array + options.userIds = options.userIds.map(function (id) { + if (_util2.default.isString(id) && !_util2.default.isUserId(id)) { + throw new Error('Invalid user id format'); + } + if (_util2.default.isUserId(id)) { + return id; // user id is already in correct format... no conversion necessary + } + // name and email address can be empty but must be of the correct type + id.name = id.name || ''; + id.email = id.email || ''; + if (!_util2.default.isString(id.name) || id.email && !_util2.default.isEmailAddress(id.email)) { + throw new Error('Invalid user id format'); + } + return id.name + ' <' + id.email + '>'; + }); + return options; +} + +/** + * Normalize parameter to an array if it is not undefined. + * @param {Object} param the parameter to be normalized + * @return {Array|undefined} the resulting array or undefined + */ +function toArray(param) { + if (param && !_util2.default.isArray(param)) { + param = [param]; + } + return param; +} + +/** + * Creates a message obejct either from a Uint8Array or a string. + * @param {String|Uint8Array} data the payload for the message + * @param {String} filename the literal data packet's filename + * @return {Message} a message object + */ +function createMessage(data, filename) { + var msg = undefined; + if (_util2.default.isUint8Array(data)) { + msg = messageLib.fromBinary(data, filename); + } else if (_util2.default.isString(data)) { + msg = messageLib.fromText(data, filename); + } else { + throw new Error('Data must be of type String or Uint8Array'); + } + return msg; +} + +/** + * Parse the message given a certain format. + * @param {Message} message the message object to be parse + * @param {String} format the output format e.g. 'utf8' or 'binary' + * @return {Object} the parse data in the respective format + */ +function parseMessage(message, format) { + if (format === 'binary') { + return { + data: message.getLiteralData(), + filename: message.getFilename() + }; + } else if (format === 'utf8') { + return { + data: message.getText(), + filename: message.getFilename() + }; + } else { + throw new Error('Invalid format'); + } +} + +/** + * Command pattern that wraps synchronous code into a promise. * @param {function} cmd The synchronous function with a return value - * to be wrapped in a promise - * @param {String} errMsg A human readable error Message + * to be wrapped in a promise + * @param {String} message A human readable error Message * @return {Promise} The promise wrapped around cmd */ -function execute(cmd, errMsg) { +function execute(cmd, message) { // wrap the sync cmd in a promise - var promise = new Promise(function(resolve) { - var result = cmd(); - resolve(result); + var promise = new Promise(function (resolve) { + return resolve(cmd()); }); - // handler error globally - return promise.catch(onError.bind(null, errMsg)); + return promise.catch(onError.bind(null, message)); } /** - * Global error handler that logs the stack trace and - * rethrows a high lvl error message - * @param {String} message A human readable high level error Message - * @param {Error} error The internal error that caused the failure + * Global error handler that logs the stack trace and rethrows a high lvl error message. + * @param {String} message A human readable high level error Message + * @param {Error} error The internal error that caused the failure */ function onError(message, error) { // log the stack trace - console.error(error.stack); + if (_config2.default.debug) { + console.error(error.stack); + } // rethrow new high level error for api users - throw new Error(message); + throw new Error(message + ': ' + error.message); } -exports.initWorker = initWorker; -exports.getWorker = getWorker; -exports.encryptMessage = encryptMessage; -exports.signAndEncryptMessage = signAndEncryptMessage; -exports.decryptMessage = decryptMessage; -exports.decryptAndVerifyMessage = decryptAndVerifyMessage; -exports.signClearMessage = signClearMessage; -exports.verifyClearSignedMessage = verifyClearSignedMessage; -exports.generateKeyPair = generateKeyPair; -},{"./cleartext.js":12,"./encoding/armor.js":41,"./enums.js":43,"./key.js":47,"./message.js":51,"./util":76,"./worker/async_proxy.js":77,"es6-promise":1}],53:[function(require,module,exports){ +},{"./cleartext.js":14,"./config/config.js":18,"./key.js":46,"./message.js":50,"./util":76,"./worker/async_proxy.js":77,"es6-promise":2}],52:[function(require,module,exports){ /** * @requires enums * @module packet */ -var enums = require('../enums.js'); -// This is pretty ugly, but browserify needs to have the requires explicitly written. +'use strict'; -module.exports = { - /** @see module:packet/compressed */ - Compressed: require('./compressed.js'), - /** @see module:packet/sym_encrypted_integrity_protected */ - SymEncryptedIntegrityProtected: require('./sym_encrypted_integrity_protected.js'), - /** @see module:packet/public_key_encrypted_session_key */ - PublicKeyEncryptedSessionKey: require('./public_key_encrypted_session_key.js'), - /** @see module:packet/sym_encrypted_session_key */ - SymEncryptedSessionKey: require('./sym_encrypted_session_key.js'), - /** @see module:packet/literal */ - Literal: require('./literal.js'), - /** @see module:packet/public_key */ - PublicKey: require('./public_key.js'), - /** @see module:packet/symmetrically_encrypted */ - SymmetricallyEncrypted: require('./symmetrically_encrypted.js'), - /** @see module:packet/marker */ - Marker: require('./marker.js'), - /** @see module:packet/public_subkey */ - PublicSubkey: require('./public_subkey.js'), - /** @see module:packet/user_attribute */ - UserAttribute: require('./user_attribute.js'), - /** @see module:packet/one_pass_signature */ - OnePassSignature: require('./one_pass_signature.js'), - /** @see module:packet/secret_key */ - SecretKey: require('./secret_key.js'), - /** @see module:packet/userid */ - Userid: require('./userid.js'), - /** @see module:packet/secret_subkey */ - SecretSubkey: require('./secret_subkey.js'), - /** @see module:packet/signature */ - Signature: require('./signature.js'), - /** @see module:packet/trust */ - Trust: require('./trust.js'), - /** - * Allocate a new packet - * @param {String} tag property name from {@link module:enums.packet} - * @returns {Object} new packet object with type based on tag - */ - newPacketFromTag: function (tag) { - return new this[packetClassFromTagName(tag)](); - }, - /** - * Allocate a new packet from structured packet clone - * See {@link http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#safe-passing-of-structured-data} - * @param {Object} packetClone packet clone - * @returns {Object} new packet object with data from packet clone - */ - fromStructuredClone: function(packetClone) { - var tagName = enums.read(enums.packet, packetClone.tag); - var packet = this.newPacketFromTag(tagName); - for (var attr in packetClone) { - if (packetClone.hasOwnProperty(attr)) { - packet[attr] = packetClone[attr]; - } - } - if (packet.postCloneTypeFix) { - packet.postCloneTypeFix(); - } - return packet; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Trust = exports.Signature = exports.SecretSubkey = exports.Userid = exports.SecretKey = exports.OnePassSignature = exports.UserAttribute = exports.PublicSubkey = exports.Marker = exports.SymmetricallyEncrypted = exports.PublicKey = exports.Literal = exports.SymEncryptedSessionKey = exports.PublicKeyEncryptedSessionKey = exports.SymEncryptedIntegrityProtected = exports.Compressed = undefined; + +var _compressed = require('./compressed.js'); + +Object.defineProperty(exports, 'Compressed', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_compressed).default; } -}; +}); + +var _sym_encrypted_integrity_protected = require('./sym_encrypted_integrity_protected.js'); + +Object.defineProperty(exports, 'SymEncryptedIntegrityProtected', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_sym_encrypted_integrity_protected).default; + } +}); + +var _public_key_encrypted_session_key = require('./public_key_encrypted_session_key.js'); + +Object.defineProperty(exports, 'PublicKeyEncryptedSessionKey', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_public_key_encrypted_session_key).default; + } +}); + +var _sym_encrypted_session_key = require('./sym_encrypted_session_key.js'); + +Object.defineProperty(exports, 'SymEncryptedSessionKey', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_sym_encrypted_session_key).default; + } +}); + +var _literal = require('./literal.js'); + +Object.defineProperty(exports, 'Literal', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_literal).default; + } +}); + +var _public_key = require('./public_key.js'); + +Object.defineProperty(exports, 'PublicKey', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_public_key).default; + } +}); + +var _symmetrically_encrypted = require('./symmetrically_encrypted.js'); + +Object.defineProperty(exports, 'SymmetricallyEncrypted', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_symmetrically_encrypted).default; + } +}); + +var _marker = require('./marker.js'); + +Object.defineProperty(exports, 'Marker', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_marker).default; + } +}); + +var _public_subkey = require('./public_subkey.js'); + +Object.defineProperty(exports, 'PublicSubkey', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_public_subkey).default; + } +}); + +var _user_attribute = require('./user_attribute.js'); + +Object.defineProperty(exports, 'UserAttribute', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_user_attribute).default; + } +}); + +var _one_pass_signature = require('./one_pass_signature.js'); + +Object.defineProperty(exports, 'OnePassSignature', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_one_pass_signature).default; + } +}); + +var _secret_key = require('./secret_key.js'); + +Object.defineProperty(exports, 'SecretKey', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_secret_key).default; + } +}); + +var _userid = require('./userid.js'); + +Object.defineProperty(exports, 'Userid', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_userid).default; + } +}); + +var _secret_subkey = require('./secret_subkey.js'); + +Object.defineProperty(exports, 'SecretSubkey', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_secret_subkey).default; + } +}); + +var _signature = require('./signature.js'); + +Object.defineProperty(exports, 'Signature', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_signature).default; + } +}); + +var _trust = require('./trust.js'); + +Object.defineProperty(exports, 'Trust', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_trust).default; + } +}); +exports.newPacketFromTag = newPacketFromTag; +exports.fromStructuredClone = fromStructuredClone; + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _all_packets = require('./all_packets.js'); + +var packets = _interopRequireWildcard(_all_packets); + +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 }; } + +/** + * Allocate a new packet + * @param {String} tag property name from {@link module:enums.packet} + * @returns {Object} new packet object with type based on tag + */ +function newPacketFromTag(tag) { + return new packets[packetClassFromTagName(tag)](); +} + +/** + * Allocate a new packet from structured packet clone + * See {@link http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#safe-passing-of-structured-data} + * @param {Object} packetClone packet clone + * @returns {Object} new packet object with data from packet clone + */ +function fromStructuredClone(packetClone) { + var tagName = _enums2.default.read(_enums2.default.packet, packetClone.tag); + var packet = newPacketFromTag(tagName); + for (var attr in packetClone) { + if (packetClone.hasOwnProperty(attr)) { + packet[attr] = packetClone[attr]; + } + } + if (packet.postCloneTypeFix) { + packet.postCloneTypeFix(); + } + return packet; +} /** * Convert tag name to class name @@ -12790,20 +14729,164 @@ function packetClassFromTagName(tag) { return tag.substr(0, 1).toUpperCase() + tag.substr(1); } -},{"../enums.js":43,"./compressed.js":54,"./literal.js":56,"./marker.js":57,"./one_pass_signature.js":58,"./public_key.js":61,"./public_key_encrypted_session_key.js":62,"./public_subkey.js":63,"./secret_key.js":64,"./secret_subkey.js":65,"./signature.js":66,"./sym_encrypted_integrity_protected.js":67,"./sym_encrypted_session_key.js":68,"./symmetrically_encrypted.js":69,"./trust.js":70,"./user_attribute.js":71,"./userid.js":72}],54:[function(require,module,exports){ -// GPG4Browsers - An OpenPGP implementation in javascript -// Copyright (C) 2011 Recurity Labs GmbH -// +},{"../enums.js":43,"./all_packets.js":52,"./compressed.js":54,"./literal.js":56,"./marker.js":57,"./one_pass_signature.js":58,"./public_key.js":61,"./public_key_encrypted_session_key.js":62,"./public_subkey.js":63,"./secret_key.js":64,"./secret_subkey.js":65,"./signature.js":66,"./sym_encrypted_integrity_protected.js":67,"./sym_encrypted_session_key.js":68,"./symmetrically_encrypted.js":69,"./trust.js":70,"./user_attribute.js":71,"./userid.js":72}],53:[function(require,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 module implements packet list cloning required to + * pass certain object types beteen the web worker and main thread using + * the structured cloning algorithm. + */ + +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.clonePackets = clonePackets; +exports.parseClonedPackets = parseClonedPackets; + +var _key = require('../key.js'); + +var key = _interopRequireWildcard(_key); + +var _message = require('../message.js'); + +var message = _interopRequireWildcard(_message); + +var _cleartext = require('../cleartext.js'); + +var cleartext = _interopRequireWildcard(_cleartext); + +var _packetlist = require('./packetlist.js'); + +var _packetlist2 = _interopRequireDefault(_packetlist); + +var _keyid = require('../type/keyid.js'); + +var _keyid2 = _interopRequireDefault(_keyid); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +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; } } + +////////////////////////////// +// // +// Packetlist --> Clone // +// // +////////////////////////////// + +/** + * Create a packetlist from the correspoding object types. + * @param {Object} options the object passed to and from the web worker + * @return {Object} a mutated version of the options optject + */ +function clonePackets(options) { + if (options.publicKeys) { + options.publicKeys = options.publicKeys.map(function (key) { + return key.toPacketlist(); + }); + } + if (options.privateKeys) { + options.privateKeys = options.privateKeys.map(function (key) { + return key.toPacketlist(); + }); + } + if (options.privateKey) { + options.privateKey = options.privateKey.toPacketlist(); + } + if (options.key) { + options.key = options.key.toPacketlist(); + } + return options; +} + +////////////////////////////// +// // +// Clone --> Packetlist // +// // +////////////////////////////// + +/** + * Creates an object with the correct prototype from a corresponding packetlist. + * @param {Object} options the object passed to and from the web worker + * @param {String} method the public api function name to be delegated to the worker + * @return {Object} a mutated version of the options optject + */ +function parseClonedPackets(options, method) { + if (options.publicKeys) { + options.publicKeys = options.publicKeys.map(packetlistCloneToKey); + } + if (options.privateKeys) { + options.privateKeys = options.privateKeys.map(packetlistCloneToKey); + } + if (options.privateKey) { + options.privateKey = packetlistCloneToKey(options.privateKey); + } + if (options.key) { + options.key = packetlistCloneToKey(options.key); + } + if (options.message && (method === 'sign' || method === 'verify')) { + // sign and verify support only CleartextMessage + options.message = packetlistCloneToCleartextMessage(options.message); + } else if (options.message) { + options.message = packetlistCloneToMessage(options.message); + } + if (options.signatures) { + options.signatures = options.signatures.map(packetlistCloneToSignature); + } + return options; +} + +function packetlistCloneToKey(clone) { + var packetlist = _packetlist2.default.fromStructuredClone(clone); + return new key.Key(packetlist); +} + +function packetlistCloneToMessage(clone) { + var packetlist = _packetlist2.default.fromStructuredClone(clone.packets); + return new message.Message(packetlist); +} + +function packetlistCloneToCleartextMessage(clone) { + var packetlist = _packetlist2.default.fromStructuredClone(clone.packets); + return new cleartext.CleartextMessage(clone.text, packetlist); +} + +function packetlistCloneToSignature(clone) { + clone.keyid = _keyid2.default.fromClone(clone.keyid); + return clone; +} + +},{"../cleartext.js":14,"../key.js":46,"../message.js":50,"../type/keyid.js":73,"./packetlist.js":60}],54:[function(require,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 @@ -12822,13 +14905,34 @@ function packetClassFromTagName(tag) { * @module packet/compressed */ -module.exports = Compressed; +'use strict'; -var enums = require('../enums.js'), - util = require('../util.js'), - Zlib = require('../compression/zlib.min.js'), - RawInflate = require('../compression/rawinflate.min.js'), - RawDeflate = require('../compression/rawdeflate.min.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Compressed; + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _zlibMin = require('../compression/zlib.min.js'); + +var _zlibMin2 = _interopRequireDefault(_zlibMin); + +var _rawinflateMin = require('../compression/rawinflate.min.js'); + +var _rawinflateMin2 = _interopRequireDefault(_rawinflateMin); + +var _rawdeflateMin = require('../compression/rawdeflate.min.js'); + +var _rawdeflateMin2 = _interopRequireDefault(_rawdeflateMin); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor @@ -12838,7 +14942,7 @@ function Compressed() { * Packet type * @type {module:enums.packet} */ - this.tag = enums.packet.compressed; + this.tag = _enums2.default.packet.compressed; /** * List of packets * @type {module:packet/packetlist} @@ -12863,34 +14967,32 @@ function Compressed() { */ Compressed.prototype.read = function (bytes) { // One octet that gives the algorithm used to compress the packet. - this.algorithm = enums.read(enums.compression, bytes.charCodeAt(0)); + this.algorithm = _enums2.default.read(_enums2.default.compression, bytes[0]); // Compressed data, which makes up the remainder of the packet. - this.compressed = bytes.substr(1); + this.compressed = bytes.subarray(1, bytes.length); this.decompress(); }; - - /** * Return the compressed packet. * @return {String} binary compressed packet */ Compressed.prototype.write = function () { - if (this.compressed === null) + if (this.compressed === null) { this.compress(); + } - return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed; + return _util2.default.concatUint8Array(new Uint8Array([_enums2.default.write(_enums2.default.compression, this.algorithm)]), this.compressed); }; - /** * Decompression method for decompressing the compressed data * read by read_packet */ Compressed.prototype.decompress = function () { - var decompressed; + var decompressed, inflate; switch (this.algorithm) { case 'uncompressed': @@ -12898,13 +15000,13 @@ Compressed.prototype.decompress = function () { break; case 'zip': - var inflate = new RawInflate.Zlib.RawInflate(util.str2Uint8Array(this.compressed)); - decompressed = util.Uint8Array2str(inflate.decompress()); + inflate = new _rawinflateMin2.default.Zlib.RawInflate(this.compressed); + decompressed = inflate.decompress(); break; case 'zlib': - var inflate = new Zlib.Zlib.Inflate(util.str2Uint8Array(this.compressed)); - decompressed = util.Uint8Array2str(inflate.decompress()); + inflate = new _zlibMin2.default.Zlib.Inflate(this.compressed); + decompressed = inflate.decompress(); break; case 'bzip2': @@ -12934,14 +15036,14 @@ Compressed.prototype.compress = function () { case 'zip': // - ZIP [RFC1951] - deflate = new RawDeflate.Zlib.RawDeflate(util.str2Uint8Array(uncompressed)); - this.compressed = util.Uint8Array2str(deflate.compress()); + deflate = new _rawdeflateMin2.default.Zlib.RawDeflate(uncompressed); + this.compressed = deflate.compress(); break; case 'zlib': // - ZLIB [RFC1950] - deflate = new Zlib.Zlib.Deflate(util.str2Uint8Array(uncompressed)); - this.compressed = util.Uint8Array2str(deflate.compress()); + deflate = new _zlibMin2.default.Zlib.Deflate(uncompressed); + this.compressed = deflate.compress(); break; case 'bzip2': @@ -12954,36 +15056,56 @@ Compressed.prototype.compress = function () { } }; -},{"../compression/rawdeflate.min.js":13,"../compression/rawinflate.min.js":14,"../compression/zlib.min.js":15,"../enums.js":43,"../util.js":76}],55:[function(require,module,exports){ -var enums = require('../enums.js'); +},{"../compression/rawdeflate.min.js":15,"../compression/rawinflate.min.js":16,"../compression/zlib.min.js":17,"../enums.js":43,"../util.js":76}],55:[function(require,module,exports){ +'use strict'; -module.exports = { - /** - * @name module:packet.List - * @see module:packet/packetlist - */ - List: require('./packetlist.js') +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _all_packets = require('./all_packets.js'); + +var packets = _interopRequireWildcard(_all_packets); + +var _clone = require('./clone.js'); + +var clone = _interopRequireWildcard(_clone); + +var _packetlist = require('./packetlist.js'); + +var _packetlist2 = _interopRequireDefault(_packetlist); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +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; } } + +var mod = { + /** @see module:packet/packetlist */ + List: _packetlist2.default, + /** @see module:packet/clone */ + clone: clone }; -var packets = require('./all_packets.js'); +for (var i in packets) { + mod[i] = packets[i]; +} -for (var i in packets) - module.exports[i] = packets[i]; +exports.default = mod; -},{"../enums.js":43,"./all_packets.js":53,"./packetlist.js":60}],56:[function(require,module,exports){ +},{"./all_packets.js":52,"./clone.js":53,"./packetlist.js":60}],56:[function(require,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 @@ -12998,19 +15120,31 @@ for (var i in packets) * @module packet/literal */ -module.exports = Literal; +'use strict'; -var util = require('../util.js'), - enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Literal; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function Literal() { - this.tag = enums.packet.literal; + this.tag = _enums2.default.packet.literal; this.format = 'utf8'; // default format for literal data packets - this.data = ''; // literal data representation as native JavaScript string or bytes this.date = new Date(); + this.data = new Uint8Array(0); // literal data representation this.filename = 'msg.txt'; } @@ -13023,7 +15157,7 @@ Literal.prototype.setText = function (text) { // normalize EOL to \r\n text = text.replace(/\r/g, '').replace(/\n/g, '\r\n'); // encode UTF8 - this.data = this.format == 'utf8' ? util.encode_utf8(text) : text; + this.data = this.format === 'utf8' ? _util2.default.str2Uint8Array(_util2.default.encode_utf8(text)) : _util2.default.str2Uint8Array(text); }; /** @@ -13033,14 +15167,14 @@ Literal.prototype.setText = function (text) { */ Literal.prototype.getText = function () { // decode UTF8 - var text = util.decode_utf8(this.data); + var text = _util2.default.decode_utf8(_util2.default.Uint8Array2str(this.data)); // normalize EOL to \n return text.replace(/\r\n/g, '\n'); }; /** * Set the packet data to value represented by the provided string of bytes. - * @param {String} bytes The string of bytes + * @param {Uint8Array} bytes The string of bytes * @param {utf8|binary|text} format The format of the string of bytes */ Literal.prototype.setBytes = function (bytes, format) { @@ -13048,16 +15182,14 @@ Literal.prototype.setBytes = function (bytes, format) { this.data = bytes; }; - /** * Get the byte sequence representing the literal packet data - * @returns {String} A sequence of bytes + * @returns {Uint8Array} A sequence of bytes */ Literal.prototype.getBytes = function () { return this.data; }; - /** * Sets the filename of the literal packet data * @param {String} filename Any native javascript string @@ -13066,38 +15198,30 @@ Literal.prototype.setFilename = function (filename) { this.filename = filename; }; - /** * Get the filename of the literal packet data - * @returns {String} filename + * @returns {String} filename */ -Literal.prototype.getFilename = function() { +Literal.prototype.getFilename = function () { return this.filename; }; - /** * Parsing function for a literal data packet (tag 11). * - * @param {String} input Payload of a tag 11 packet - * @param {Integer} position - * Position to start reading from the input string - * @param {Integer} len - * Length of the packet or the remaining length of - * input at position + * @param {Uint8Array} input Payload of a tag 11 packet * @return {module:packet/literal} object representation */ Literal.prototype.read = function (bytes) { // - A one-octet field that describes how the data is formatted. + var format = _enums2.default.read(_enums2.default.literal, bytes[0]); - var format = enums.read(enums.literal, bytes.charCodeAt(0)); + var filename_len = bytes[1]; + this.filename = _util2.default.decode_utf8(_util2.default.Uint8Array2str(bytes.subarray(2, 2 + filename_len))); - var filename_len = bytes.charCodeAt(1); - this.filename = util.decode_utf8(bytes.substr(2, filename_len)); + this.date = _util2.default.readDate(bytes.subarray(2 + filename_len, 2 + filename_len + 4)); - this.date = util.readDate(bytes.substr(2 + filename_len, 4)); - - var data = bytes.substring(6 + filename_len); + var data = bytes.subarray(6 + filename_len, bytes.length); this.setBytes(data, format); }; @@ -13105,42 +15229,37 @@ Literal.prototype.read = function (bytes) { /** * Creates a string representation of the packet * - * @param {String} data The data to be inserted as body - * @return {String} string-representation of the packet + * @return {Uint8Array} Uint8Array representation of the packet */ Literal.prototype.write = function () { - var filename = util.encode_utf8(this.filename); + var filename = _util2.default.str2Uint8Array(_util2.default.encode_utf8(this.filename)); + var filename_length = new Uint8Array([filename.length]); + var format = new Uint8Array([_enums2.default.write(_enums2.default.literal, this.format)]); + var date = _util2.default.writeDate(this.date); var data = this.getBytes(); - var result = ''; - result += String.fromCharCode(enums.write(enums.literal, this.format)); - result += String.fromCharCode(filename.length); - result += filename; - result += util.writeDate(this.date); - result += data; - return result; + return _util2.default.concatUint8Array([format, filename_length, filename, date, data]); }; },{"../enums.js":43,"../util.js":76}],57:[function(require,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 - /** * Implementation of the strange "Marker packet" (Tag 10)
*
@@ -13154,15 +15273,24 @@ Literal.prototype.write = function () { * @module packet/marker */ -module.exports = Marker; +'use strict'; -var enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Marker; + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function Marker() { - this.tag = enums.packet.marker; + this.tag = _enums2.default.packet.marker; } /** @@ -13177,10 +15305,12 @@ function Marker() { * @return {module:packet/marker} Object representation */ Marker.prototype.read = function (bytes) { - if (bytes.charCodeAt(0) == 0x50 && // P - bytes.charCodeAt(1) == 0x47 && // G - bytes.charCodeAt(2) == 0x50) // P + if (bytes[0] === 0x50 && // P + bytes[1] === 0x47 && // G + bytes[2] === 0x50) { + // P return true; + } // marker packet does not contain "PGP" return false; }; @@ -13188,17 +15318,17 @@ Marker.prototype.read = function (bytes) { },{"../enums.js":43}],58:[function(require,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 @@ -13211,21 +15341,38 @@ Marker.prototype.read = function (bytes) { * hashes needed to verify the signature. It allows the Signature * packet to be placed at the end of the message, so that the signer * can compute the entire signed message in one pass. +* @requires util * @requires enums * @requires type/keyid * @module packet/one_pass_signature */ -module.exports = OnePassSignature; +'use strict'; -var enums = require('../enums.js'), - type_keyid = require('../type/keyid.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = OnePassSignature; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _keyid = require('../type/keyid.js'); + +var _keyid2 = _interopRequireDefault(_keyid); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function OnePassSignature() { - this.tag = enums.packet.onePassSignature; // The packet type + this.tag = _enums2.default.packet.onePassSignature; // The packet type this.version = null; // A one-octet version number. The current version is 3. this.type = null; // A one-octet signature type. Signature types are described in {@link http://tools.ietf.org/html/rfc4880#section-5.2.1|RFC4880 Section 5.2.1}. this.hashAlgorithm = null; // A one-octet number describing the hash algorithm used. (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC4880 9.4}) @@ -13236,75 +15383,71 @@ function OnePassSignature() { /** * parsing function for a one-pass signature packet (tag 4). - * @param {String} bytes payload of a tag 4 packet + * @param {Uint8Array} bytes payload of a tag 4 packet * @return {module:packet/one_pass_signature} object representation */ OnePassSignature.prototype.read = function (bytes) { var mypos = 0; // A one-octet version number. The current version is 3. - this.version = bytes.charCodeAt(mypos++); + this.version = bytes[mypos++]; // A one-octet signature type. Signature types are described in // Section 5.2.1. - this.type = enums.read(enums.signature, bytes.charCodeAt(mypos++)); + this.type = _enums2.default.read(_enums2.default.signature, bytes[mypos++]); // A one-octet number describing the hash algorithm used. - this.hashAlgorithm = enums.read(enums.hash, bytes.charCodeAt(mypos++)); + this.hashAlgorithm = _enums2.default.read(_enums2.default.hash, bytes[mypos++]); // A one-octet number describing the public-key algorithm used. - this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(mypos++)); + this.publicKeyAlgorithm = _enums2.default.read(_enums2.default.publicKey, bytes[mypos++]); // An eight-octet number holding the Key ID of the signing key. - this.signingKeyId = new type_keyid(); - this.signingKeyId.read(bytes.substr(mypos)); + this.signingKeyId = new _keyid2.default(); + this.signingKeyId.read(bytes.subarray(mypos, mypos + 8)); mypos += 8; // A one-octet number holding a flag showing whether the signature // is nested. A zero value indicates that the next packet is // another One-Pass Signature packet that describes another // signature to be applied to the same message data. - this.flags = bytes.charCodeAt(mypos++); + this.flags = bytes[mypos++]; return this; }; /** * creates a string representation of a one-pass signature packet - * @return {String} a string representation of a one-pass signature packet + * @return {Uint8Array} a Uint8Array representation of a one-pass signature packet */ OnePassSignature.prototype.write = function () { - var result = ""; - result += String.fromCharCode(3); - result += String.fromCharCode(enums.write(enums.signature, this.type)); - result += String.fromCharCode(enums.write(enums.hash, this.hashAlgorithm)); - result += String.fromCharCode(enums.write(enums.publicKey, this.publicKeyAlgorithm)); - result += this.signingKeyId.write(); - result += String.fromCharCode(this.flags); + var start = new Uint8Array([3, _enums2.default.write(_enums2.default.signature, this.type), _enums2.default.write(_enums2.default.hash, this.hashAlgorithm), _enums2.default.write(_enums2.default.publicKey, this.publicKeyAlgorithm)]); - return result; + var end = new Uint8Array([this.flags]); + + return _util2.default.concatUint8Array([start, this.signingKeyId.write(), end]); }; /** * Fix custom types after cloning */ -OnePassSignature.prototype.postCloneTypeFix = function() { - this.signingKeyId = type_keyid.fromClone(this.signingKeyId); +OnePassSignature.prototype.postCloneTypeFix = function () { + this.signingKeyId = _keyid2.default.fromClone(this.signingKeyId); }; -},{"../enums.js":43,"../type/keyid.js":73}],59:[function(require,module,exports){ +},{"../enums.js":43,"../type/keyid.js":73,"../util.js":76}],59:[function(require,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 @@ -13315,24 +15458,32 @@ OnePassSignature.prototype.postCloneTypeFix = function() { * @module packet/packet */ -var enums = require('../enums.js'), - util = require('../util.js'); +'use strict'; -module.exports = { - readSimpleLength: function(bytes) { +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = { + readSimpleLength: function readSimpleLength(bytes) { var len = 0, - offset, - type = bytes.charCodeAt(0); - + offset, + type = bytes[0]; if (type < 192) { - len = bytes.charCodeAt(0); + len = bytes[0]; offset = 1; } else if (type < 255) { - len = ((bytes.charCodeAt(0) - 192) << 8) + (bytes.charCodeAt(1)) + 192; + len = (bytes[0] - 192 << 8) + bytes[1] + 192; offset = 2; - } else if (type == 255) { - len = util.readNumber(bytes.substr(1, 4)); + } else if (type === 255) { + len = _util2.default.readNumber(bytes.subarray(1, 1 + 4)); offset = 5; } @@ -13345,80 +15496,69 @@ module.exports = { /** * Encodes a given integer of length to the openpgp length specifier to a * string - * + * * @param {Integer} length The length to encode - * @return {String} String with openpgp length representation + * @return {Uint8Array} String with openpgp length representation */ - writeSimpleLength: function(length) { - var result = ""; + writeSimpleLength: function writeSimpleLength(length) { + if (length < 192) { - result += String.fromCharCode(length); + return new Uint8Array([length]); } else if (length > 191 && length < 8384) { /* * let a = (total data packet length) - 192 let bc = two octet * representation of a let d = b + 192 */ - result += String.fromCharCode(((length - 192) >> 8) + 192); - result += String.fromCharCode((length - 192) & 0xFF); + return new Uint8Array([(length - 192 >> 8) + 192, length - 192 & 0xFF]); } else { - result += String.fromCharCode(255); - result += util.writeNumber(length, 4); + return _util2.default.concatUint8Array([new Uint8Array([255]), _util2.default.writeNumber(length, 4)]); } - return result; }, /** * Writes a packet header version 4 with the given tag_type and length to a * string - * + * * @param {Integer} tag_type Tag type * @param {Integer} length Length of the payload * @return {String} String of the header */ - writeHeader: function(tag_type, length) { + writeHeader: function writeHeader(tag_type, length) { /* we're only generating v4 packet headers here */ - var result = ""; - result += String.fromCharCode(0xC0 | tag_type); - result += this.writeSimpleLength(length); - return result; + return _util2.default.concatUint8Array([new Uint8Array([0xC0 | tag_type]), this.writeSimpleLength(length)]); }, /** * Writes a packet header Version 3 with the given tag_type and length to a * string - * + * * @param {Integer} tag_type Tag type * @param {Integer} length Length of the payload * @return {String} String of the header */ - writeOldHeader: function(tag_type, length) { - var result = ""; + writeOldHeader: function writeOldHeader(tag_type, length) { + if (length < 256) { - result += String.fromCharCode(0x80 | (tag_type << 2)); - result += String.fromCharCode(length); + return new Uint8Array([0x80 | tag_type << 2, length]); } else if (length < 65536) { - result += String.fromCharCode(0x80 | (tag_type << 2) | 1); - result += util.writeNumber(length, 2); + return _util2.default.concatUint8Array([0x80 | tag_type << 2 | 1, _util2.default.writeNumber(length, 2)]); } else { - result += String.fromCharCode(0x80 | (tag_type << 2) | 2); - result += util.writeNumber(length, 4); + return _util2.default.concatUint8Array([0x80 | tag_type << 2 | 2, _util2.default.writeNumber(length, 4)]); } - return result; }, /** * Generic static Packet Parser function - * + * * @param {String} input Input stream as string * @param {integer} position Position to start parsing * @param {integer} len Length of the input from position on * @return {Object} Returns a parsed module:packet/packet */ - read: function(input, position, len) { + read: function read(input, position, len) { // some sanity checks - if (input === null || input.length <= position || input.substring(position).length < 2 || (input.charCodeAt(position) & - 0x80) === 0) { - throw new Error("Error during parsing. This message / key is probably not containing a valid OpenPGP format."); + if (input === null || input.length <= position || input.subarray(position, input.length).length < 2 || (input[position] & 0x80) === 0) { + throw new Error("Error during parsing. This message / key probably does not conform to a valid OpenPGP format."); } var mypos = position; var tag = -1; @@ -13426,19 +15566,19 @@ module.exports = { var packet_length; format = 0; // 0 = old format; 1 = new format - if ((input.charCodeAt(mypos) & 0x40) !== 0) { + if ((input[mypos] & 0x40) !== 0) { format = 1; } var packet_length_type; if (format) { // new format header - tag = input.charCodeAt(mypos) & 0x3F; // bit 5-0 + tag = input[mypos] & 0x3F; // bit 5-0 } else { - // old format header - tag = (input.charCodeAt(mypos) & 0x3F) >> 2; // bit 5-2 - packet_length_type = input.charCodeAt(mypos) & 0x03; // bit 1-0 - } + // old format header + tag = (input[mypos] & 0x3F) >> 2; // bit 5-2 + packet_length_type = input[mypos] & 0x03; // bit 1-0 + } // header octet parsing done mypos++; @@ -13454,98 +15594,96 @@ module.exports = { case 0: // The packet has a one-octet length. The header is 2 octets // long. - packet_length = input.charCodeAt(mypos++); + packet_length = input[mypos++]; break; case 1: // The packet has a two-octet length. The header is 3 octets // long. - packet_length = (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++); + packet_length = input[mypos++] << 8 | input[mypos++]; break; case 2: // The packet has a four-octet length. The header is 5 // octets long. - packet_length = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << - 8) | input.charCodeAt(mypos++); + packet_length = input[mypos++] << 24 | input[mypos++] << 16 | input[mypos++] << 8 | input[mypos++]; break; default: // 3 - The packet is of indeterminate length. The header is 1 // octet long, and the implementation must determine how long // the packet is. If the packet is in a file, this means that - // the packet extends until the end of the file. In general, - // an implementation SHOULD NOT use indeterminate-length - // packets except where the end of the data will be clear - // from the context, and even then it is better to use a - // definite length, or a new format header. The new format + // the packet extends until the end of the file. In general, + // an implementation SHOULD NOT use indeterminate-length + // packets except where the end of the data will be clear + // from the context, and even then it is better to use a + // definite length, or a new format header. The new format // headers described below have a mechanism for precisely // encoding data of indeterminate length. packet_length = len; break; } - } else // 4.2.2. New Format Packet Lengths - { + { - // 4.2.2.1. One-Octet Lengths - if (input.charCodeAt(mypos) < 192) { - packet_length = input.charCodeAt(mypos++); - util.print_debug("1 byte length:" + packet_length); - // 4.2.2.2. Two-Octet Lengths - } else if (input.charCodeAt(mypos) >= 192 && input.charCodeAt(mypos) < 224) { - packet_length = ((input.charCodeAt(mypos++) - 192) << 8) + (input.charCodeAt(mypos++)) + 192; - util.print_debug("2 byte length:" + packet_length); - // 4.2.2.4. Partial Body Lengths - } else if (input.charCodeAt(mypos) > 223 && input.charCodeAt(mypos) < 255) { - packet_length = 1 << (input.charCodeAt(mypos++) & 0x1F); - util.print_debug("4 byte length:" + packet_length); - // EEEK, we're reading the full data here... - var mypos2 = mypos + packet_length; - bodydata = input.substring(mypos, mypos + packet_length); - var tmplen; - while (true) { - if (input.charCodeAt(mypos2) < 192) { - tmplen = input.charCodeAt(mypos2++); - packet_length += tmplen; - bodydata += input.substring(mypos2, mypos2 + tmplen); - mypos2 += tmplen; - break; - } else if (input.charCodeAt(mypos2) >= 192 && input.charCodeAt(mypos2) < 224) { - tmplen = ((input.charCodeAt(mypos2++) - 192) << 8) + (input.charCodeAt(mypos2++)) + 192; - packet_length += tmplen; - bodydata += input.substring(mypos2, mypos2 + tmplen); - mypos2 += tmplen; - break; - } else if (input.charCodeAt(mypos2) > 223 && input.charCodeAt(mypos2) < 255) { - tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F); - packet_length += tmplen; - bodydata += input.substring(mypos2, mypos2 + tmplen); - mypos2 += tmplen; - } else { - mypos2++; - tmplen = (input.charCodeAt(mypos2++) << 24) | (input.charCodeAt(mypos2++) << 16) | (input - .charCodeAt(mypos2++) << 8) | input.charCodeAt(mypos2++); - bodydata += input.substring(mypos2, mypos2 + tmplen); - packet_length += tmplen; - mypos2 += tmplen; - break; - } - } - real_packet_length = mypos2 - mypos; - // 4.2.2.3. Five-Octet Lengths - } else { - mypos++; - packet_length = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) << - 8) | input.charCodeAt(mypos++); + // 4.2.2.1. One-Octet Lengths + if (input[mypos] < 192) { + packet_length = input[mypos++]; + _util2.default.print_debug("1 byte length:" + packet_length); + // 4.2.2.2. Two-Octet Lengths + } else if (input[mypos] >= 192 && input[mypos] < 224) { + packet_length = (input[mypos++] - 192 << 8) + input[mypos++] + 192; + _util2.default.print_debug("2 byte length:" + packet_length); + // 4.2.2.4. Partial Body Lengths + } else if (input[mypos] > 223 && input[mypos] < 255) { + packet_length = 1 << (input[mypos++] & 0x1F); + _util2.default.print_debug("4 byte length:" + packet_length); + // EEEK, we're reading the full data here... + var mypos2 = mypos + packet_length; + bodydata = [input.subarray(mypos, mypos + packet_length)]; + var tmplen; + while (true) { + if (input[mypos2] < 192) { + tmplen = input[mypos2++]; + packet_length += tmplen; + bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); + mypos2 += tmplen; + break; + } else if (input[mypos2] >= 192 && input[mypos2] < 224) { + tmplen = (input[mypos2++] - 192 << 8) + input[mypos2++] + 192; + packet_length += tmplen; + bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); + mypos2 += tmplen; + break; + } else if (input[mypos2] > 223 && input[mypos2] < 255) { + tmplen = 1 << (input[mypos2++] & 0x1F); + packet_length += tmplen; + bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); + mypos2 += tmplen; + } else { + mypos2++; + tmplen = input[mypos2++] << 24 | input[mypos2++] << 16 | input[mypos2++] << 8 | input[mypos2++]; + bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); + packet_length += tmplen; + mypos2 += tmplen; + break; + } + } + real_packet_length = mypos2 - mypos; + // 4.2.2.3. Five-Octet Lengths + } else { + mypos++; + packet_length = input[mypos++] << 24 | input[mypos++] << 16 | input[mypos++] << 8 | input[mypos++]; + } } - } // if there was'nt a partial body length: use the specified // packet_length - if (real_packet_length == -1) { + if (real_packet_length === -1) { real_packet_length = packet_length; } if (bodydata === null) { - bodydata = input.substring(mypos, mypos + real_packet_length); + bodydata = input.subarray(mypos, mypos + real_packet_length); + } else if (bodydata instanceof Array) { + bodydata = _util2.default.concatUint8Array(bodydata); } return { @@ -13556,22 +15694,44 @@ module.exports = { } }; -},{"../enums.js":43,"../util.js":76}],60:[function(require,module,exports){ +},{"../util.js":76}],60:[function(require,module,exports){ /** * This class represents a list of openpgp packets. * Take care when iterating over it - the packets themselves * are stored as numerical indices. + * @requires util * @requires enums * @requires packet * @requires packet/packet * @module packet/packetlist */ -module.exports = Packetlist; +'use strict'; -var packetParser = require('./packet.js'), - packets = require('./all_packets.js'), - enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Packetlist; + +var _util = require('../util'); + +var _util2 = _interopRequireDefault(_util); + +var _packet = require('./packet.js'); + +var _packet2 = _interopRequireDefault(_packet); + +var _all_packets = require('./all_packets.js'); + +var packets = _interopRequireWildcard(_all_packets); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +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 }; } /** * @constructor @@ -13584,16 +15744,16 @@ function Packetlist() { } /** * Reads a stream of binary data and interprents it as a list of packets. - * @param {String} A binary string of bytes. + * @param {Uint8Array} A Uint8Array of bytes. */ Packetlist.prototype.read = function (bytes) { var i = 0; while (i < bytes.length) { - var parsed = packetParser.read(bytes, i, bytes.length - i); + var parsed = _packet2.default.read(bytes, i, bytes.length - i); i = parsed.offset; - var tag = enums.read(enums.packet, parsed.tag); + var tag = _enums2.default.read(_enums2.default.packet, parsed.tag); var packet = packets.newPacketFromTag(tag); this.push(packet); @@ -13605,18 +15765,18 @@ Packetlist.prototype.read = function (bytes) { /** * Creates a binary representation of openpgp objects contained within the * class instance. - * @returns {String} A binary string of bytes containing valid openpgp packets. + * @returns {Uint8Array} A Uint8Array containing valid openpgp packets. */ Packetlist.prototype.write = function () { - var bytes = ''; + var arr = []; for (var i = 0; i < this.length; i++) { var packetbytes = this[i].write(); - bytes += packetParser.writeHeader(this[i].tag, packetbytes.length); - bytes += packetbytes; + arr.push(_packet2.default.writeHeader(this[i].tag, packetbytes.length)); + arr.push(packetbytes); } - return bytes; + return _util2.default.concatUint8Array(arr); }; /** @@ -13624,7 +15784,9 @@ Packetlist.prototype.write = function () { * writing to packetlist[i] directly will result in an error. */ Packetlist.prototype.push = function (packet) { - if (!packet) return; + if (!packet) { + return; + } packet.packets = packet.packets || new Packetlist(); @@ -13656,8 +15818,11 @@ Packetlist.prototype.filterByTag = function () { var filtered = new Packetlist(); var that = this; + function handle(packetType) { + return that[i].tag === packetType; + } for (var i = 0; i < this.length; i++) { - if (args.some(function(packetType) {return that[i].tag == packetType;})) { + if (args.some(handle)) { filtered.push(this[i]); } } @@ -13688,7 +15853,9 @@ Packetlist.prototype.findPacket = function (type) { for (var i = 0; i < this.length; i++) { if (this[i].packets.length) { found = this[i].packets.findPacket(type); - if (found) return found; + if (found) { + return found; + } } } } @@ -13702,8 +15869,12 @@ Packetlist.prototype.indexOfTag = function () { var args = Array.prototype.slice.call(arguments); var tagIndex = []; var that = this; + + function handle(packetType) { + return that[i].tag === packetType; + } for (var i = 0; i < this.length; i++) { - if (args.some(function(packetType) {return that[i].tag == packetType;})) { + if (args.some(handle)) { tagIndex.push(i); } } @@ -13741,7 +15912,7 @@ Packetlist.prototype.concat = function (packetlist) { * @param {Object} packetClone packetlist clone * @returns {Object} new packetlist object with data from packetlist clone */ -module.exports.fromStructuredClone = function(packetlistClone) { +Packetlist.fromStructuredClone = function (packetlistClone) { var packetlist = new Packetlist(); for (var i = 0; i < packetlistClone.length; i++) { packetlist.push(packets.fromStructuredClone(packetlistClone[i])); @@ -13753,20 +15924,21 @@ module.exports.fromStructuredClone = function(packetlistClone) { } return packetlist; }; -},{"../enums.js":43,"./all_packets.js":53,"./packet.js":59}],61:[function(require,module,exports){ + +},{"../enums.js":43,"../util":76,"./all_packets.js":52,"./packet.js":59}],61:[function(require,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 @@ -13786,19 +15958,40 @@ module.exports.fromStructuredClone = function(packetlistClone) { * @module packet/public_key */ -module.exports = PublicKey; +'use strict'; -var util = require('../util.js'), - type_mpi = require('../type/mpi.js'), - type_keyid = require('../type/keyid.js'), - enums = require('../enums.js'), - crypto = require('../crypto'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = PublicKey; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _mpi = require('../type/mpi.js'); + +var _mpi2 = _interopRequireDefault(_mpi); + +var _keyid = require('../type/keyid.js'); + +var _keyid2 = _interopRequireDefault(_keyid); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function PublicKey() { - this.tag = enums.packet.publicKey; + this.tag = _enums2.default.packet.publicKey; this.version = 4; /** Key creation date. * @type {Date} */ @@ -13826,40 +16019,40 @@ function PublicKey() { /** * Internal Parser for public keys as specified in {@link http://tools.ietf.org/html/rfc4880#section-5.5.2|RFC 4880 section 5.5.2 Public-Key Packet Formats} * called by read_tag<num> - * @param {String} input Input string to read the packet from + * @param {Uint8Array} bytes Input array to read the packet from * @return {Object} This object with attributes set by the parser */ PublicKey.prototype.read = function (bytes) { var pos = 0; // A one-octet version number (3 or 4). - this.version = bytes.charCodeAt(pos++); + this.version = bytes[pos++]; - if (this.version == 3 || this.version == 4) { + if (this.version === 3 || this.version === 4) { // - A four-octet number denoting the time that the key was created. - this.created = util.readDate(bytes.substr(pos, 4)); + this.created = _util2.default.readDate(bytes.subarray(pos, pos + 4)); pos += 4; - if (this.version == 3) { + if (this.version === 3) { // - A two-octet number denoting the time in days that this key is // valid. If this number is zero, then it does not expire. - this.expirationTimeV3 = util.readNumber(bytes.substr(pos, 2)); + this.expirationTimeV3 = _util2.default.readNumber(bytes.subarray(pos, pos + 2)); pos += 2; } // - A one-octet number denoting the public-key algorithm of this key. - this.algorithm = enums.read(enums.publicKey, bytes.charCodeAt(pos++)); + this.algorithm = _enums2.default.read(_enums2.default.publicKey, bytes[pos++]); - var mpicount = crypto.getPublicMpiCount(this.algorithm); + var mpicount = _crypto2.default.getPublicMpiCount(this.algorithm); this.mpi = []; - var bmpi = bytes.substr(pos); + var bmpi = bytes.subarray(pos, bytes.length); var p = 0; for (var i = 0; i < mpicount && p < bmpi.length; i++) { - this.mpi[i] = new type_mpi(); + this.mpi[i] = new _mpi2.default(); - p += this.mpi[i].read(bmpi.substr(p)); + p += this.mpi[i].read(bmpi.subarray(p, bmpi.length)); if (p > bmpi.length) { throw new Error('Error reading MPI @:' + p); @@ -13881,25 +16074,26 @@ PublicKey.prototype.readPublicKey = PublicKey.prototype.read; /** * Same as write_private_key, but has less information because of * public key. - * @return {Object} {body: [string]OpenPGP packet body contents, - * header: [string] OpenPGP packet header, string: [string] header+body} + * @return {Uint8Array} OpenPGP packet body contents, */ PublicKey.prototype.write = function () { - // Version - var result = String.fromCharCode(this.version); - result += util.writeDate(this.created); - if (this.version == 3) { - result += util.writeNumber(this.expirationTimeV3, 2); - } - result += String.fromCharCode(enums.write(enums.publicKey, this.algorithm)); - var mpicount = crypto.getPublicMpiCount(this.algorithm); + var arr = []; + // Version + arr.push(new Uint8Array([this.version])); + arr.push(_util2.default.writeDate(this.created)); + if (this.version === 3) { + arr.push(_util2.default.writeNumber(this.expirationTimeV3, 2)); + } + arr.push(new Uint8Array([_enums2.default.write(_enums2.default.publicKey, this.algorithm)])); + + var mpicount = _crypto2.default.getPublicMpiCount(this.algorithm); for (var i = 0; i < mpicount; i++) { - result += this.mpi[i].write(); + arr.push(this.mpi[i].write()); } - return result; + return _util2.default.concatUint8Array(arr); }; /** @@ -13914,9 +16108,7 @@ PublicKey.prototype.writePublicKey = PublicKey.prototype.write; PublicKey.prototype.writeOld = function () { var bytes = this.writePublicKey(); - return String.fromCharCode(0x99) + - util.writeNumber(bytes.length, 2) + - bytes; + return _util2.default.concatUint8Array([new Uint8Array([0x99]), _util2.default.writeNumber(bytes.length, 2), bytes]); }; /** @@ -13927,11 +16119,12 @@ PublicKey.prototype.getKeyId = function () { if (this.keyid) { return this.keyid; } - this.keyid = new type_keyid(); - if (this.version == 4) { - this.keyid.read(util.hex2bin(this.getFingerprint()).substr(12, 8)); - } else if (this.version == 3) { - this.keyid.read(this.mpi[0].write().substr(-8)); + this.keyid = new _keyid2.default(); + if (this.version === 4) { + this.keyid.read(_util2.default.str2Uint8Array(_util2.default.hex2bin(this.getFingerprint()).substr(12, 8))); + } else if (this.version === 3) { + var arr = this.mpi[0].write(); + this.keyid.read(arr.subarray(arr.length - 8, arr.length)); } return this.keyid; }; @@ -13945,17 +16138,17 @@ PublicKey.prototype.getFingerprint = function () { return this.fingerprint; } var toHash = ''; - if (this.version == 4) { + if (this.version === 4) { toHash = this.writeOld(); - this.fingerprint = crypto.hash.sha1(toHash); - } else if (this.version == 3) { - var mpicount = crypto.getPublicMpiCount(this.algorithm); + this.fingerprint = _util2.default.Uint8Array2str(_crypto2.default.hash.sha1(toHash)); + } else if (this.version === 3) { + var mpicount = _crypto2.default.getPublicMpiCount(this.algorithm); for (var i = 0; i < mpicount; i++) { toHash += this.mpi[i].toBytes(); } - this.fingerprint = crypto.hash.md5(toHash); + this.fingerprint = _util2.default.Uint8Array2str(_crypto2.default.hash.md5(_util2.default.str2Uint8Array(toHash))); } - this.fingerprint = util.hexstrdump(this.fingerprint); + this.fingerprint = _util2.default.hexstrdump(this.fingerprint); return this.fingerprint; }; @@ -13970,29 +16163,29 @@ PublicKey.prototype.getBitSize = function () { /** * Fix custom types after cloning */ -PublicKey.prototype.postCloneTypeFix = function() { +PublicKey.prototype.postCloneTypeFix = function () { for (var i = 0; i < this.mpi.length; i++) { - this.mpi[i] = type_mpi.fromClone(this.mpi[i]); + this.mpi[i] = _mpi2.default.fromClone(this.mpi[i]); } if (this.keyid) { - this.keyid = type_keyid.fromClone(this.keyid); + this.keyid = _keyid2.default.fromClone(this.keyid); } }; },{"../crypto":32,"../enums.js":43,"../type/keyid.js":73,"../type/mpi.js":74,"../util.js":76}],62:[function(require,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 @@ -14019,22 +16212,43 @@ PublicKey.prototype.postCloneTypeFix = function() { * @module packet/public_key_encrypted_session_key */ -module.exports = PublicKeyEncryptedSessionKey; +'use strict'; -var type_keyid = require('../type/keyid.js'), - util = require('../util.js'), - type_mpi = require('../type/mpi.js'), - enums = require('../enums.js'), - crypto = require('../crypto'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = PublicKeyEncryptedSessionKey; + +var _keyid = require('../type/keyid.js'); + +var _keyid2 = _interopRequireDefault(_keyid); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _mpi = require('../type/mpi.js'); + +var _mpi2 = _interopRequireDefault(_mpi); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function PublicKeyEncryptedSessionKey() { - this.tag = enums.packet.publicKeyEncryptedSessionKey; + this.tag = _enums2.default.packet.publicKeyEncryptedSessionKey; this.version = 3; - this.publicKeyId = new type_keyid(); + this.publicKeyId = new _keyid2.default(); this.publicKeyAlgorithm = 'rsa_encrypt'; this.sessionKey = null; @@ -14047,7 +16261,7 @@ function PublicKeyEncryptedSessionKey() { /** * Parsing function for a publickey encrypted session key packet (tag 1). * - * @param {String} input Payload of a tag 1 packet + * @param {Uint8Array} input Payload of a tag 1 packet * @param {Integer} position Position to start reading from the input string * @param {Integer} len Length of the packet or the remaining length of * input at position @@ -14055,13 +16269,13 @@ function PublicKeyEncryptedSessionKey() { */ PublicKeyEncryptedSessionKey.prototype.read = function (bytes) { - this.version = bytes.charCodeAt(0); - this.publicKeyId.read(bytes.substr(1)); - this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(9)); + this.version = bytes[0]; + this.publicKeyId.read(bytes.subarray(1, bytes.length)); + this.publicKeyAlgorithm = _enums2.default.read(_enums2.default.publicKey, bytes[9]); var i = 10; - var integerCount = (function(algo) { + var integerCount = function (algo) { switch (algo) { case 'rsa_encrypt': case 'rsa_encrypt_sign': @@ -14073,13 +16287,13 @@ PublicKeyEncryptedSessionKey.prototype.read = function (bytes) { default: throw new Error("Invalid algorithm."); } - })(this.publicKeyAlgorithm); + }(this.publicKeyAlgorithm); this.encrypted = []; for (var j = 0; j < integerCount; j++) { - var mpi = new type_mpi(); - i += mpi.read(bytes.substr(i)); + var mpi = new _mpi2.default(); + i += mpi.read(bytes.subarray(i, bytes.length)); this.encrypted.push(mpi); } }; @@ -14087,52 +16301,30 @@ PublicKeyEncryptedSessionKey.prototype.read = function (bytes) { /** * Create a string representation of a tag 1 packet * - * @param {String} publicKeyId - * The public key id corresponding to publicMPIs key as string - * @param {Array} publicMPIs - * Multiprecision integer objects describing the public key - * @param {module:enums.publicKey} pubalgo - * The corresponding public key algorithm // See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC4880 9.1} - * @param {module:enums.symmetric} symmalgo - * The symmetric cipher algorithm used to encrypt the data - * within an encrypteddatapacket or encryptedintegrity- - * protecteddatapacket - * following this packet //See {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC4880 9.2} - * @param {String} sessionkey - * A string of randombytes representing the session key - * @return {String} The string representation + * @return {Uint8Array} The Uint8Array representation */ PublicKeyEncryptedSessionKey.prototype.write = function () { - var result = String.fromCharCode(this.version); - result += this.publicKeyId.write(); - result += String.fromCharCode( - enums.write(enums.publicKey, this.publicKeyAlgorithm)); + var arr = [new Uint8Array([this.version]), this.publicKeyId.write(), new Uint8Array([_enums2.default.write(_enums2.default.publicKey, this.publicKeyAlgorithm)])]; for (var i = 0; i < this.encrypted.length; i++) { - result += this.encrypted[i].write(); + arr.push(this.encrypted[i].write()); } - return result; + return _util2.default.concatUint8Array(arr); }; PublicKeyEncryptedSessionKey.prototype.encrypt = function (key) { - var data = String.fromCharCode( - enums.write(enums.symmetric, this.sessionKeyAlgorithm)); + var data = String.fromCharCode(_enums2.default.write(_enums2.default.symmetric, this.sessionKeyAlgorithm)); - data += this.sessionKey; - var checksum = util.calc_checksum(this.sessionKey); - data += util.writeNumber(checksum, 2); + data += _util2.default.Uint8Array2str(this.sessionKey); + var checksum = _util2.default.calc_checksum(this.sessionKey); + data += _util2.default.Uint8Array2str(_util2.default.writeNumber(checksum, 2)); - var mpi = new type_mpi(); - mpi.fromBytes(crypto.pkcs1.eme.encode( - data, - key.mpi[0].byteLength())); + var mpi = new _mpi2.default(); + mpi.fromBytes(_crypto2.default.pkcs1.eme.encode(data, key.mpi[0].byteLength())); - this.encrypted = crypto.publicKeyEncrypt( - this.publicKeyAlgorithm, - key.mpi, - mpi); + this.encrypted = _crypto2.default.publicKeyEncrypt(this.publicKeyAlgorithm, key.mpi, mpi); }; /** @@ -14144,50 +16336,46 @@ PublicKeyEncryptedSessionKey.prototype.encrypt = function (key) { * @return {String} The unencrypted session key */ PublicKeyEncryptedSessionKey.prototype.decrypt = function (key) { - var result = crypto.publicKeyDecrypt( - this.publicKeyAlgorithm, - key.mpi, - this.encrypted).toBytes(); + var result = _crypto2.default.publicKeyDecrypt(this.publicKeyAlgorithm, key.mpi, this.encrypted).toBytes(); - var checksum = util.readNumber(result.substr(result.length - 2)); + var checksum = _util2.default.readNumber(_util2.default.str2Uint8Array(result.substr(result.length - 2))); - var decoded = crypto.pkcs1.eme.decode(result); + var decoded = _crypto2.default.pkcs1.eme.decode(result); - key = decoded.substring(1, decoded.length - 2); + key = _util2.default.str2Uint8Array(decoded.substring(1, decoded.length - 2)); - if (checksum != util.calc_checksum(key)) { + if (checksum !== _util2.default.calc_checksum(key)) { throw new Error('Checksum mismatch'); } else { this.sessionKey = key; - this.sessionKeyAlgorithm = - enums.read(enums.symmetric, decoded.charCodeAt(0)); + this.sessionKeyAlgorithm = _enums2.default.read(_enums2.default.symmetric, decoded.charCodeAt(0)); } }; /** * Fix custom types after cloning */ -PublicKeyEncryptedSessionKey.prototype.postCloneTypeFix = function() { - this.publicKeyId = type_keyid.fromClone(this.publicKeyId); +PublicKeyEncryptedSessionKey.prototype.postCloneTypeFix = function () { + this.publicKeyId = _keyid2.default.fromClone(this.publicKeyId); for (var i = 0; i < this.encrypted.length; i++) { - this.encrypted[i] = type_mpi.fromClone(this.encrypted[i]); + this.encrypted[i] = _mpi2.default.fromClone(this.encrypted[i]); } }; },{"../crypto":32,"../enums.js":43,"../type/keyid.js":73,"../type/mpi.js":74,"../util.js":76}],63:[function(require,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 @@ -14198,21 +16386,33 @@ PublicKeyEncryptedSessionKey.prototype.postCloneTypeFix = function() { * @module packet/public_subkey */ -module.exports = PublicSubkey; +'use strict'; -var publicKey = require('./public_key.js'), - enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = PublicSubkey; + +var _public_key = require('./public_key.js'); + +var _public_key2 = _interopRequireDefault(_public_key); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor * @extends module:packet/public_key */ function PublicSubkey() { - publicKey.call(this); - this.tag = enums.packet.publicSubkey; + _public_key2.default.call(this); + this.tag = _enums2.default.packet.publicSubkey; } -PublicSubkey.prototype = new publicKey(); +PublicSubkey.prototype = new _public_key2.default(); PublicSubkey.prototype.constructor = PublicSubkey; },{"../enums.js":43,"./public_key.js":61}],64:[function(require,module,exports){ @@ -14249,89 +16449,116 @@ PublicSubkey.prototype.constructor = PublicSubkey; * @module packet/secret_key */ -module.exports = SecretKey; +'use strict'; -var publicKey = require('./public_key.js'), - enums = require('../enums.js'), - util = require('../util.js'), - crypto = require('../crypto'), - type_mpi = require('../type/mpi.js'), - type_s2k = require('../type/s2k.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = SecretKey; + +var _public_key = require('./public_key.js'); + +var _public_key2 = _interopRequireDefault(_public_key); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +var _mpi = require('../type/mpi.js'); + +var _mpi2 = _interopRequireDefault(_mpi); + +var _s2k = require('../type/s2k.js'); + +var _s2k2 = _interopRequireDefault(_s2k); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor * @extends module:packet/public_key */ function SecretKey() { - publicKey.call(this); - this.tag = enums.packet.secretKey; + _public_key2.default.call(this); + this.tag = _enums2.default.packet.secretKey; // encrypted secret-key data this.encrypted = null; // indicator if secret-key data is available in decrypted form this.isDecrypted = false; } -SecretKey.prototype = new publicKey(); +SecretKey.prototype = new _public_key2.default(); SecretKey.prototype.constructor = SecretKey; function get_hash_len(hash) { - if (hash == 'sha1') + if (hash === 'sha1') { return 20; - else + } else { return 2; + } } function get_hash_fn(hash) { - if (hash == 'sha1') - return crypto.hash.sha1; - else - return function(c) { - return util.writeNumber(util.calc_checksum(c), 2); - }; + if (hash === 'sha1') { + return _crypto2.default.hash.sha1; + } else { + return function (c) { + return _util2.default.writeNumber(_util2.default.calc_checksum(c), 2); + }; + } } // Helper function function parse_cleartext_mpi(hash_algorithm, cleartext, algorithm) { var hashlen = get_hash_len(hash_algorithm), - hashfn = get_hash_fn(hash_algorithm); + hashfn = get_hash_fn(hash_algorithm); - var hashtext = cleartext.substr(cleartext.length - hashlen); - cleartext = cleartext.substr(0, cleartext.length - hashlen); + var hashtext = _util2.default.Uint8Array2str(cleartext.subarray(cleartext.length - hashlen, cleartext.length)); + cleartext = cleartext.subarray(0, cleartext.length - hashlen); - var hash = hashfn(cleartext); + var hash = _util2.default.Uint8Array2str(hashfn(cleartext)); - if (hash != hashtext) + if (hash !== hashtext) { return new Error("Hash mismatch."); + } - var mpis = crypto.getPrivateMpiCount(algorithm); + var mpis = _crypto2.default.getPrivateMpiCount(algorithm); var j = 0; var mpi = []; for (var i = 0; i < mpis && j < cleartext.length; i++) { - mpi[i] = new type_mpi(); - j += mpi[i].read(cleartext.substr(j)); + mpi[i] = new _mpi2.default(); + j += mpi[i].read(cleartext.subarray(j, cleartext.length)); } return mpi; } function write_cleartext_mpi(hash_algorithm, algorithm, mpi) { - var bytes = ''; - var discard = crypto.getPublicMpiCount(algorithm); + var arr = []; + var discard = _crypto2.default.getPublicMpiCount(algorithm); for (var i = discard; i < mpi.length; i++) { - bytes += mpi[i].write(); + arr.push(mpi[i].write()); } + var bytes = _util2.default.concatUint8Array(arr); - bytes += get_hash_fn(hash_algorithm)(bytes); + var hash = get_hash_fn(hash_algorithm)(bytes); - return bytes; + return _util2.default.concatUint8Array([bytes, hash]); } - // 5.5.3. Secret-Key Packet Formats /** @@ -14342,53 +16569,47 @@ SecretKey.prototype.read = function (bytes) { // - A Public-Key or Public-Subkey packet, as described above. var len = this.readPublicKey(bytes); - bytes = bytes.substr(len); - + bytes = bytes.subarray(len, bytes.length); // - One octet indicating string-to-key usage conventions. Zero // indicates that the secret-key data is not encrypted. 255 or 254 // indicates that a string-to-key specifier is being given. Any // other value is a symmetric-key encryption algorithm identifier. - var isEncrypted = bytes.charCodeAt(0); + var isEncrypted = bytes[0]; if (isEncrypted) { this.encrypted = bytes; } else { - // - Plain or encrypted multiprecision integers comprising the secret // key data. These algorithm-specific fields are as described // below. - var parsedMPI = parse_cleartext_mpi('mod', bytes.substr(1), this.algorithm); - if (parsedMPI instanceof Error) + var parsedMPI = parse_cleartext_mpi('mod', bytes.subarray(1, bytes.length), this.algorithm); + if (parsedMPI instanceof Error) { throw parsedMPI; + } this.mpi = this.mpi.concat(parsedMPI); this.isDecrypted = true; } - }; /** Creates an OpenPGP key packet for the given key. * @return {String} A string of bytes containing the secret key OpenPGP packet */ SecretKey.prototype.write = function () { - var bytes = this.writePublicKey(); + var arr = [this.writePublicKey()]; if (!this.encrypted) { - bytes += String.fromCharCode(0); - - bytes += write_cleartext_mpi('mod', this.algorithm, this.mpi); + arr.push(new Uint8Array([0])); + arr.push(write_cleartext_mpi('mod', this.algorithm, this.mpi)); } else { - bytes += this.encrypted; + arr.push(this.encrypted); } - return bytes; + return _util2.default.concatUint8Array(arr); }; - - - /** Encrypt the payload. By default, we use aes256 and iterated, salted string - * to key specifier. If the key is in a decrypted state (isDecrypted == true) + * to key specifier. If the key is in a decrypted state (isDecrypted === true) * and the passphrase is empty or undefined, the key will be set as not encrypted. * This can be used to remove passphrase protection after calling decrypt(). * @param {String} passphrase @@ -14401,25 +16622,23 @@ SecretKey.prototype.encrypt = function (passphrase) { throw new Error('The key must be decrypted before removing passphrase protection.'); } - var s2k = new type_s2k(), - symmetric = 'aes256', - cleartext = write_cleartext_mpi('sha1', this.algorithm, this.mpi), - key = produceEncryptionKey(s2k, passphrase, symmetric), - blockLen = crypto.cipher[symmetric].blockSize, - iv = crypto.random.getRandomBytes(blockLen); + var s2k = new _s2k2.default(), + symmetric = 'aes256', + cleartext = write_cleartext_mpi('sha1', this.algorithm, this.mpi), + key = produceEncryptionKey(s2k, passphrase, symmetric), + blockLen = _crypto2.default.cipher[symmetric].blockSize, + iv = _crypto2.default.random.getRandomBytes(blockLen); - this.encrypted = ''; - this.encrypted += String.fromCharCode(254); - this.encrypted += String.fromCharCode(enums.write(enums.symmetric, symmetric)); - this.encrypted += s2k.write(); - this.encrypted += iv; + var arr = [new Uint8Array([254, _enums2.default.write(_enums2.default.symmetric, symmetric)])]; + arr.push(s2k.write()); + arr.push(iv); + arr.push(_crypto2.default.cfb.normalEncrypt(symmetric, key, cleartext, iv)); - this.encrypted += crypto.cfb.normalEncrypt(symmetric, key, cleartext, iv); + this.encrypted = _util2.default.concatUint8Array(arr); }; function produceEncryptionKey(s2k, passphrase, algorithm) { - return s2k.produce_key(passphrase, - crypto.cipher[algorithm].keySize); + return s2k.produce_key(passphrase, _crypto2.default.cipher[algorithm].keySize); } /** @@ -14433,51 +16652,48 @@ function produceEncryptionKey(s2k, passphrase, algorithm) { * decrypted; false if not */ SecretKey.prototype.decrypt = function (passphrase) { - if (this.isDecrypted) + if (this.isDecrypted) { return true; + } var i = 0, - symmetric, - key; + symmetric, + key; - var s2k_usage = this.encrypted.charCodeAt(i++); + var s2k_usage = this.encrypted[i++]; // - [Optional] If string-to-key usage octet was 255 or 254, a one- // octet symmetric encryption algorithm. - if (s2k_usage == 255 || s2k_usage == 254) { - symmetric = this.encrypted.charCodeAt(i++); - symmetric = enums.read(enums.symmetric, symmetric); + if (s2k_usage === 255 || s2k_usage === 254) { + symmetric = this.encrypted[i++]; + symmetric = _enums2.default.read(_enums2.default.symmetric, symmetric); // - [Optional] If string-to-key usage octet was 255 or 254, a // string-to-key specifier. The length of the string-to-key // specifier is implied by its type, as described above. - var s2k = new type_s2k(); - i += s2k.read(this.encrypted.substr(i)); + var s2k = new _s2k2.default(); + i += s2k.read(this.encrypted.subarray(i, this.encrypted.length)); key = produceEncryptionKey(s2k, passphrase, symmetric); } else { symmetric = s2k_usage; - symmetric = enums.read(enums.symmetric, symmetric); - key = crypto.hash.md5(passphrase); + symmetric = _enums2.default.read(_enums2.default.symmetric, symmetric); + key = _crypto2.default.hash.md5(passphrase); } - // - [Optional] If secret data is encrypted (string-to-key usage octet // not zero), an Initial Vector (IV) of the same length as the // cipher's block size. - var iv = this.encrypted.substr(i, - crypto.cipher[symmetric].blockSize); + var iv = this.encrypted.subarray(i, i + _crypto2.default.cipher[symmetric].blockSize); i += iv.length; var cleartext, - ciphertext = this.encrypted.substr(i); + ciphertext = this.encrypted.subarray(i, this.encrypted.length); - cleartext = crypto.cfb.normalDecrypt(symmetric, key, ciphertext, iv); + cleartext = _crypto2.default.cfb.normalDecrypt(symmetric, key, ciphertext, iv); - var hash = s2k_usage == 254 ? - 'sha1' : - 'mod'; + var hash = s2k_usage === 254 ? 'sha1' : 'mod'; var parsedMPI = parse_cleartext_mpi(hash, cleartext, this.algorithm); if (parsedMPI instanceof Error) { @@ -14491,7 +16707,7 @@ SecretKey.prototype.decrypt = function (passphrase) { SecretKey.prototype.generate = function (bits) { var self = this; - return crypto.generateMpi(self.algorithm, bits).then(function(mpi) { + return _crypto2.default.generateMpi(self.algorithm, bits).then(function (mpi) { self.mpi = mpi; self.isDecrypted = true; }); @@ -14504,24 +16720,24 @@ SecretKey.prototype.clearPrivateMPIs = function () { if (!this.encrypted) { throw new Error('If secret key is not encrypted, clearing private MPIs is irreversible.'); } - this.mpi = this.mpi.slice(0, crypto.getPublicMpiCount(this.algorithm)); + this.mpi = this.mpi.slice(0, _crypto2.default.getPublicMpiCount(this.algorithm)); this.isDecrypted = false; }; },{"../crypto":32,"../enums.js":43,"../type/mpi.js":74,"../type/s2k.js":75,"../util.js":76,"./public_key.js":61}],65:[function(require,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 @@ -14532,37 +16748,85 @@ SecretKey.prototype.clearPrivateMPIs = function () { * @module packet/secret_subkey */ -module.exports = SecretSubkey; +'use strict'; -var secretKey = require('./secret_key.js'), - enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = SecretSubkey; + +var _secret_key = require('./secret_key.js'); + +var _secret_key2 = _interopRequireDefault(_secret_key); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor * @extends module:packet/secret_key */ function SecretSubkey() { - secretKey.call(this); - this.tag = enums.packet.secretSubkey; + _secret_key2.default.call(this); + this.tag = _enums2.default.packet.secretSubkey; } -SecretSubkey.prototype = new secretKey(); +SecretSubkey.prototype = new _secret_key2.default(); SecretSubkey.prototype.constructor = SecretSubkey; },{"../enums.js":43,"./secret_key.js":64}],66:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Signature; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _packet = require('./packet.js'); + +var _packet2 = _interopRequireDefault(_packet); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +var _mpi = require('../type/mpi.js'); + +var _mpi2 = _interopRequireDefault(_mpi); + +var _keyid = require('../type/keyid.js'); + +var _keyid2 = _interopRequireDefault(_keyid); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/** + * @constructor + */ // 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 @@ -14583,20 +16847,8 @@ SecretSubkey.prototype.constructor = SecretSubkey; * @module packet/signature */ -module.exports = Signature; - -var util = require('../util.js'), - packet = require('./packet.js'), - enums = require('../enums.js'), - crypto = require('../crypto'), - type_mpi = require('../type/mpi.js'), - type_keyid = require('../type/keyid.js'); - -/** - * @constructor - */ function Signature() { - this.tag = enums.packet.signature; + this.tag = _enums2.default.packet.signature; this.version = 4; this.signatureType = null; this.hashAlgorithm = null; @@ -14620,7 +16872,7 @@ function Signature() { this.revocationKeyClass = null; this.revocationKeyAlgorithm = null; this.revocationKeyFingerprint = null; - this.issuerKeyId = new type_keyid(); + this.issuerKeyId = new _keyid2.default(); this.notation = null; this.preferredHashAlgorithms = null; this.preferredCompressionAlgorithms = null; @@ -14650,67 +16902,65 @@ function Signature() { */ Signature.prototype.read = function (bytes) { var i = 0; - - this.version = bytes.charCodeAt(i++); + this.version = bytes[i++]; // switch on version (3 and 4) switch (this.version) { case 3: // One-octet length of following hashed material. MUST be 5. - if (bytes.charCodeAt(i++) != 5) - util.print_debug("packet/signature.js\n" + - 'invalid One-octet length of following hashed material.' + - 'MUST be 5. @:' + (i - 1)); + if (bytes[i++] !== 5) { + _util2.default.print_debug("packet/signature.js\n" + 'invalid One-octet length of following hashed material.' + 'MUST be 5. @:' + (i - 1)); + } var sigpos = i; // One-octet signature type. - this.signatureType = bytes.charCodeAt(i++); + this.signatureType = bytes[i++]; // Four-octet creation time. - this.created = util.readDate(bytes.substr(i, 4)); + this.created = _util2.default.readDate(bytes.subarray(i, i + 4)); i += 4; // storing data appended to data which gets verified - this.signatureData = bytes.substring(sigpos, i); + this.signatureData = bytes.subarray(sigpos, i); // Eight-octet Key ID of signer. - this.issuerKeyId.read(bytes.substring(i, i + 8)); + this.issuerKeyId.read(bytes.subarray(i, i + 8)); i += 8; // One-octet public-key algorithm. - this.publicKeyAlgorithm = bytes.charCodeAt(i++); + this.publicKeyAlgorithm = bytes[i++]; // One-octet hash algorithm. - this.hashAlgorithm = bytes.charCodeAt(i++); + this.hashAlgorithm = bytes[i++]; break; case 4: - this.signatureType = bytes.charCodeAt(i++); - this.publicKeyAlgorithm = bytes.charCodeAt(i++); - this.hashAlgorithm = bytes.charCodeAt(i++); + this.signatureType = bytes[i++]; + this.publicKeyAlgorithm = bytes[i++]; + this.hashAlgorithm = bytes[i++]; - function subpackets(bytes) { + var subpackets = function subpackets(bytes) { // Two-octet scalar octet count for following subpacket data. - var subpacket_length = util.readNumber( - bytes.substr(0, 2)); + var subpacket_length = _util2.default.readNumber(bytes.subarray(0, 2)); var i = 2; // subpacket data set (zero or more subpackets) - var subpacked_read = 0; while (i < 2 + subpacket_length) { - var len = packet.readSimpleLength(bytes.substr(i)); + var len = _packet2.default.readSimpleLength(bytes.subarray(i, bytes.length)); i += len.offset; - this.read_sub_packet(bytes.substr(i, len.len)); + this.read_sub_packet(bytes.subarray(i, i + len.len)); i += len.len; } return i; - } + }; // hashed subpackets - i += subpackets.call(this, bytes.substr(i), true); + + + i += subpackets.call(this, bytes.subarray(i, bytes.length), true); // A V4 signature hashes the packet body // starting from its first field, the version number, through the end @@ -14718,12 +16968,12 @@ Signature.prototype.read = function (bytes) { // signature version, the signature type, the public-key algorithm, the // hash algorithm, the hashed subpacket length, and the hashed // subpacket body. - this.signatureData = bytes.substr(0, i); + this.signatureData = bytes.subarray(0, i); var sigDataLength = i; // unhashed subpackets - i += subpackets.call(this, bytes.substr(i), false); - this.unhashedSubpackets = bytes.substr(sigDataLength, i - sigDataLength); + i += subpackets.call(this, bytes.subarray(i, bytes.length), false); + this.unhashedSubpackets = bytes.subarray(sigDataLength, i); break; default: @@ -14731,30 +16981,29 @@ Signature.prototype.read = function (bytes) { } // Two-octet field holding left 16 bits of signed hash value. - this.signedHashValue = bytes.substr(i, 2); + this.signedHashValue = bytes.subarray(i, i + 2); i += 2; - this.signature = bytes.substr(i); + this.signature = bytes.subarray(i, bytes.length); }; Signature.prototype.write = function () { - var result = ''; + var arr = []; switch (this.version) { case 3: - result += String.fromCharCode(3); // version - result += String.fromCharCode(5); // One-octet length of following hashed material. MUST be 5 - result += this.signatureData; - result += this.issuerKeyId.write(); - result += String.fromCharCode(this.publicKeyAlgorithm); - result += String.fromCharCode(this.hashAlgorithm); + arr.push(new Uint8Array([3, 5])); // version, One-octet length of following hashed material. MUST be 5 + arr.push(this.signatureData); + arr.push(this.issuerKeyId.write()); + arr.push(new Uint8Array([this.publicKeyAlgorithm, this.hashAlgorithm])); break; case 4: - result += this.signatureData; - result += this.unhashedSubpackets ? this.unhashedSubpackets : util.writeNumber(0, 2); + arr.push(this.signatureData); + arr.push(this.unhashedSubpackets ? this.unhashedSubpackets : _util2.default.writeNumber(0, 2)); break; } - result += this.signedHashValue + this.signature; - return result; + arr.push(this.signedHashValue); + arr.push(this.signature); + return _util2.default.concatUint8Array(arr); }; /** @@ -14763,33 +17012,28 @@ Signature.prototype.write = function () { * @param {Object} data Contains packets to be signed. */ Signature.prototype.sign = function (key, data) { - var signatureType = enums.write(enums.signature, this.signatureType), - publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm), - hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm); + var signatureType = _enums2.default.write(_enums2.default.signature, this.signatureType), + publicKeyAlgorithm = _enums2.default.write(_enums2.default.publicKey, this.publicKeyAlgorithm), + hashAlgorithm = _enums2.default.write(_enums2.default.hash, this.hashAlgorithm); - var result = String.fromCharCode(4); - result += String.fromCharCode(signatureType); - result += String.fromCharCode(publicKeyAlgorithm); - result += String.fromCharCode(hashAlgorithm); + var arr = [new Uint8Array([4, signatureType, publicKeyAlgorithm, hashAlgorithm])]; this.issuerKeyId = key.getKeyId(); // Add hashed subpackets - result += this.write_all_sub_packets(); + arr.push(this.write_all_sub_packets()); - this.signatureData = result; + this.signatureData = _util2.default.concatUint8Array(arr); var trailer = this.calculateTrailer(); - var toHash = this.toSign(signatureType, data) + - this.signatureData + trailer; + var toHash = _util2.default.concatUint8Array([this.toSign(signatureType, data), this.signatureData, trailer]); - var hash = crypto.hash.digest(hashAlgorithm, toHash); + var hash = _crypto2.default.hash.digest(hashAlgorithm, toHash); - this.signedHashValue = hash.substr(0, 2); + this.signedHashValue = hash.subarray(0, 2); - this.signature = crypto.signature.sign(hashAlgorithm, - publicKeyAlgorithm, key.mpi, toHash); + this.signature = _crypto2.default.signature.sign(hashAlgorithm, publicKeyAlgorithm, key.mpi, toHash); }; /** @@ -14797,109 +17041,109 @@ Signature.prototype.sign = function (key, data) { * @return {String} a string-representation of a all subpacket data */ Signature.prototype.write_all_sub_packets = function () { - var sub = enums.signatureSubpacket; - var result = ''; - var bytes = ''; + var sub = _enums2.default.signatureSubpacket; + var arr = []; + var bytes; if (this.created !== null) { - result += write_sub_packet(sub.signature_creation_time, util.writeDate(this.created)); + arr.push(write_sub_packet(sub.signature_creation_time, _util2.default.writeDate(this.created))); } if (this.signatureExpirationTime !== null) { - result += write_sub_packet(sub.signature_expiration_time, util.writeNumber(this.signatureExpirationTime, 4)); + arr.push(write_sub_packet(sub.signature_expiration_time, _util2.default.writeNumber(this.signatureExpirationTime, 4))); } if (this.exportable !== null) { - result += write_sub_packet(sub.exportable_certification, String.fromCharCode(this.exportable ? 1 : 0)); + arr.push(write_sub_packet(sub.exportable_certification, new Uint8Array([this.exportable ? 1 : 0]))); } if (this.trustLevel !== null) { - bytes = String.fromCharCode(this.trustLevel) + String.fromCharCode(this.trustAmount); - result += write_sub_packet(sub.trust_signature, bytes); + bytes = new Uint8Array([this.trustLevel, this.trustAmount]); + arr.push(write_sub_packet(sub.trust_signature, bytes)); } if (this.regularExpression !== null) { - result += write_sub_packet(sub.regular_expression, this.regularExpression); + arr.push(write_sub_packet(sub.regular_expression, this.regularExpression)); } if (this.revocable !== null) { - result += write_sub_packet(sub.revocable, String.fromCharCode(this.revocable ? 1 : 0)); + arr.push(write_sub_packet(sub.revocable, new Uint8Array([this.revocable ? 1 : 0]))); } if (this.keyExpirationTime !== null) { - result += write_sub_packet(sub.key_expiration_time, util.writeNumber(this.keyExpirationTime, 4)); + arr.push(write_sub_packet(sub.key_expiration_time, _util2.default.writeNumber(this.keyExpirationTime, 4))); } if (this.preferredSymmetricAlgorithms !== null) { - bytes = util.bin2str(this.preferredSymmetricAlgorithms); - result += write_sub_packet(sub.preferred_symmetric_algorithms, bytes); + bytes = _util2.default.str2Uint8Array(_util2.default.bin2str(this.preferredSymmetricAlgorithms)); + arr.push(write_sub_packet(sub.preferred_symmetric_algorithms, bytes)); } if (this.revocationKeyClass !== null) { - bytes = String.fromCharCode(this.revocationKeyClass); - bytes += String.fromCharCode(this.revocationKeyAlgorithm); - bytes += this.revocationKeyFingerprint; - result += write_sub_packet(sub.revocation_key, bytes); + + bytes = new Uint8Array([this.revocationKeyClass, this.revocationKeyAlgorithm]); + bytes = _util2.default.concatUint8Array([bytes, this.revocationKeyFingerprint]); + arr.push(write_sub_packet(sub.revocation_key, bytes)); } if (!this.issuerKeyId.isNull()) { - result += write_sub_packet(sub.issuer, this.issuerKeyId.write()); + arr.push(write_sub_packet(sub.issuer, this.issuerKeyId.write())); } if (this.notation !== null) { for (var name in this.notation) { if (this.notation.hasOwnProperty(name)) { var value = this.notation[name]; - bytes = String.fromCharCode(0x80); - bytes += String.fromCharCode(0); - bytes += String.fromCharCode(0); - bytes += String.fromCharCode(0); + bytes = [new Uint8Array([0x80, 0, 0, 0])]; // 2 octets of name length - bytes += util.writeNumber(name.length, 2); + bytes.push(_util2.default.writeNumber(name.length, 2)); // 2 octets of value length - bytes += util.writeNumber(value.length, 2); - bytes += name + value; - result += write_sub_packet(sub.notation_data, bytes); + bytes.push(_util2.default.writeNumber(value.length, 2)); + bytes.push(_util2.default.str2Uint8Array(name + value)); + bytes = _util2.default.concatUint8Array(bytes); + arr.push(write_sub_packet(sub.notation_data, bytes)); } } } if (this.preferredHashAlgorithms !== null) { - bytes = util.bin2str(this.preferredHashAlgorithms); - result += write_sub_packet(sub.preferred_hash_algorithms, bytes); + bytes = _util2.default.str2Uint8Array(_util2.default.bin2str(this.preferredHashAlgorithms)); + arr.push(write_sub_packet(sub.preferred_hash_algorithms, bytes)); } if (this.preferredCompressionAlgorithms !== null) { - bytes = util.bin2str(this.preferredCompressionAlgorithms); - result += write_sub_packet(sub.preferred_compression_algorithms, bytes); + bytes = _util2.default.str2Uint8Array(_util2.default.bin2str(this.preferredCompressionAlgorithms)); + arr.push(write_sub_packet(sub.preferred_compression_algorithms, bytes)); } if (this.keyServerPreferences !== null) { - bytes = util.bin2str(this.keyServerPreferences); - result += write_sub_packet(sub.key_server_preferences, bytes); + bytes = _util2.default.str2Uint8Array(_util2.default.bin2str(this.keyServerPreferences)); + arr.push(write_sub_packet(sub.key_server_preferences, bytes)); } if (this.preferredKeyServer !== null) { - result += write_sub_packet(sub.preferred_key_server, this.preferredKeyServer); + arr.push(write_sub_packet(sub.preferred_key_server, _util2.default.str2Uint8Array(this.preferredKeyServer))); } if (this.isPrimaryUserID !== null) { - result += write_sub_packet(sub.primary_user_id, String.fromCharCode(this.isPrimaryUserID ? 1 : 0)); + arr.push(write_sub_packet(sub.primary_user_id, new Uint8Array([this.isPrimaryUserID ? 1 : 0]))); } if (this.policyURI !== null) { - result += write_sub_packet(sub.policy_uri, this.policyURI); + arr.push(write_sub_packet(sub.policy_uri, _util2.default.str2Uint8Array(this.policyURI))); } if (this.keyFlags !== null) { - bytes = util.bin2str(this.keyFlags); - result += write_sub_packet(sub.key_flags, bytes); + bytes = _util2.default.str2Uint8Array(_util2.default.bin2str(this.keyFlags)); + arr.push(write_sub_packet(sub.key_flags, bytes)); } if (this.signersUserId !== null) { - result += write_sub_packet(sub.signers_user_id, this.signersUserId); + arr.push(write_sub_packet(sub.signers_user_id, _util2.default.str2Uint8Array(this.signersUserId))); } if (this.reasonForRevocationFlag !== null) { - bytes = String.fromCharCode(this.reasonForRevocationFlag); - bytes += this.reasonForRevocationString; - result += write_sub_packet(sub.reason_for_revocation, bytes); + bytes = _util2.default.str2Uint8Array(String.fromCharCode(this.reasonForRevocationFlag) + this.reasonForRevocationString); + arr.push(write_sub_packet(sub.reason_for_revocation, bytes)); } if (this.features !== null) { - bytes = util.bin2str(this.features); - result += write_sub_packet(sub.features, bytes); + bytes = _util2.default.str2Uint8Array(_util2.default.bin2str(this.features)); + arr.push(write_sub_packet(sub.features, bytes)); } if (this.signatureTargetPublicKeyAlgorithm !== null) { - bytes = String.fromCharCode(this.signatureTargetPublicKeyAlgorithm); - bytes += String.fromCharCode(this.signatureTargetHashAlgorithm); - bytes += this.signatureTargetHash; - result += write_sub_packet(sub.signature_target, bytes); + bytes = [new Uint8Array([this.signatureTargetPublicKeyAlgorithm, this.signatureTargetHashAlgorithm])]; + bytes.push(_util2.default.str2Uint8Array(this.signatureTargetHash)); + bytes = _util2.default.concatUint8Array(bytes); + arr.push(write_sub_packet(sub.signature_target, bytes)); } if (this.embeddedSignature !== null) { - result += write_sub_packet(sub.embedded_signature, this.embeddedSignature.write()); + arr.push(write_sub_packet(sub.embedded_signature, this.embeddedSignature.write())); } - result = util.writeNumber(result.length, 2) + result; - return result; + + var result = _util2.default.concatUint8Array(arr); + var length = _util2.default.writeNumber(result.length, 2); + + return _util2.default.concatUint8Array([length, result]); }; /** @@ -14910,11 +17154,11 @@ Signature.prototype.write_all_sub_packets = function () { * @return {String} a string-representation of a sub signature packet (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.3.1|RFC 4880 5.2.3.1}) */ function write_sub_packet(type, data) { - var result = ""; - result += packet.writeSimpleLength(data.length + 1); - result += String.fromCharCode(type); - result += data; - return result; + var arr = []; + arr.push(_packet2.default.writeSimpleLength(data.length + 1)); + arr.push(new Uint8Array([type])); + arr.push(data); + return _util2.default.concatUint8Array(arr); } // V4 signature sub packets @@ -14926,23 +17170,23 @@ Signature.prototype.read_sub_packet = function (bytes) { this[prop] = []; for (var i = 0; i < bytes.length; i++) { - this[prop].push(bytes.charCodeAt(i)); + this[prop].push(bytes[i]); } } // The leftwost bit denotes a "critical" packet, but we ignore it. - var type = bytes.charCodeAt(mypos++) & 0x7F; + var type = bytes[mypos++] & 0x7F; var seconds; // subpacket type switch (type) { case 2: // Signature Creation Time - this.created = util.readDate(bytes.substr(mypos)); + this.created = _util2.default.readDate(bytes.subarray(mypos, bytes.length)); break; case 3: // Signature Expiration Time in seconds - seconds = util.readNumber(bytes.substr(mypos)); + seconds = _util2.default.readNumber(bytes.subarray(mypos, bytes.length)); this.signatureNeverExpires = seconds === 0; this.signatureExpirationTime = seconds; @@ -14950,24 +17194,24 @@ Signature.prototype.read_sub_packet = function (bytes) { break; case 4: // Exportable Certification - this.exportable = bytes.charCodeAt(mypos++) == 1; + this.exportable = bytes[mypos++] === 1; break; case 5: // Trust Signature - this.trustLevel = bytes.charCodeAt(mypos++); - this.trustAmount = bytes.charCodeAt(mypos++); + this.trustLevel = bytes[mypos++]; + this.trustAmount = bytes[mypos++]; break; case 6: // Regular Expression - this.regularExpression = bytes.substr(mypos); + this.regularExpression = bytes[mypos]; break; case 7: // Revocable - this.revocable = bytes.charCodeAt(mypos++) == 1; + this.revocable = bytes[mypos++] === 1; break; case 9: // Key Expiration Time in seconds - seconds = util.readNumber(bytes.substr(mypos)); + seconds = _util2.default.readNumber(bytes.subarray(mypos, bytes.length)); this.keyExpirationTime = seconds; this.keyNeverExpires = seconds === 0; @@ -14975,59 +17219,59 @@ Signature.prototype.read_sub_packet = function (bytes) { break; case 11: // Preferred Symmetric Algorithms - read_array.call(this, 'preferredSymmetricAlgorithms', bytes.substr(mypos)); + read_array.call(this, 'preferredSymmetricAlgorithms', bytes.subarray(mypos, bytes.length)); break; case 12: // Revocation Key // (1 octet of class, 1 octet of public-key algorithm ID, 20 // octets of // fingerprint) - this.revocationKeyClass = bytes.charCodeAt(mypos++); - this.revocationKeyAlgorithm = bytes.charCodeAt(mypos++); - this.revocationKeyFingerprint = bytes.substr(mypos, 20); + this.revocationKeyClass = bytes[mypos++]; + this.revocationKeyAlgorithm = bytes[mypos++]; + this.revocationKeyFingerprint = bytes.subarray(mypos, 20); break; case 16: // Issuer - this.issuerKeyId.read(bytes.substr(mypos)); + this.issuerKeyId.read(bytes.subarray(mypos, bytes.length)); break; case 20: // Notation Data // We don't know how to handle anything but a text flagged data. - if (bytes.charCodeAt(mypos) == 0x80) { + if (bytes[mypos] === 0x80) { // We extract key/value tuple from the byte stream. mypos += 4; - var m = util.readNumber(bytes.substr(mypos, 2)); + var m = _util2.default.readNumber(bytes.subarray(mypos, mypos + 2)); mypos += 2; - var n = util.readNumber(bytes.substr(mypos, 2)); + var n = _util2.default.readNumber(bytes.subarray(mypos, mypos + 2)); mypos += 2; - var name = bytes.substr(mypos, m), - value = bytes.substr(mypos + m, n); + var name = _util2.default.Uint8Array2str(bytes.subarray(mypos, mypos + m)), + value = _util2.default.Uint8Array2str(bytes.subarray(mypos + m, mypos + m + n)); this.notation = this.notation || {}; this.notation[name] = value; } else { - util.print_debug("Unsupported notation flag "+bytes.charCodeAt(mypos)); - } + _util2.default.print_debug("Unsupported notation flag " + bytes[mypos]); + } break; case 21: // Preferred Hash Algorithms - read_array.call(this, 'preferredHashAlgorithms', bytes.substr(mypos)); + read_array.call(this, 'preferredHashAlgorithms', bytes.subarray(mypos, bytes.length)); break; case 22: // Preferred Compression Algorithms - read_array.call(this, 'preferredCompressionAlgorithms', bytes.substr(mypos)); + read_array.call(this, 'preferredCompressionAlgorithms', bytes.subarray(mypos, bytes.length)); break; case 23: // Key Server Preferences - read_array.call(this, 'keyServerPreferencess', bytes.substr(mypos)); + read_array.call(this, 'keyServerPreferencess', bytes.subarray(mypos, bytes.length)); break; case 24: // Preferred Key Server - this.preferredKeyServer = bytes.substr(mypos); + this.preferredKeyServer = _util2.default.Uint8Array2str(bytes.subarray(mypos, bytes.length)); break; case 25: // Primary User ID @@ -15035,48 +17279,48 @@ Signature.prototype.read_sub_packet = function (bytes) { break; case 26: // Policy URI - this.policyURI = bytes.substr(mypos); + this.policyURI = _util2.default.Uint8Array2str(bytes.subarray(mypos, bytes.length)); break; case 27: // Key Flags - read_array.call(this, 'keyFlags', bytes.substr(mypos)); + read_array.call(this, 'keyFlags', bytes.subarray(mypos, bytes.length)); break; case 28: // Signer's User ID - this.signersUserId += bytes.substr(mypos); + this.signersUserId += _util2.default.Uint8Array2str(bytes.subarray(mypos, bytes.length)); break; case 29: // Reason for Revocation - this.reasonForRevocationFlag = bytes.charCodeAt(mypos++); - this.reasonForRevocationString = bytes.substr(mypos); + this.reasonForRevocationFlag = bytes[mypos++]; + this.reasonForRevocationString = _util2.default.Uint8Array2str(bytes.subarray(mypos, bytes.length)); break; case 30: // Features - read_array.call(this, 'features', bytes.substr(mypos)); + read_array.call(this, 'features', bytes.subarray(mypos, bytes.length)); break; case 31: // Signature Target // (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash) - this.signatureTargetPublicKeyAlgorithm = bytes.charCodeAt(mypos++); - this.signatureTargetHashAlgorithm = bytes.charCodeAt(mypos++); + this.signatureTargetPublicKeyAlgorithm = bytes[mypos++]; + this.signatureTargetHashAlgorithm = bytes[mypos++]; - var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm); + var len = _crypto2.default.getHashByteLength(this.signatureTargetHashAlgorithm); - this.signatureTargetHash = bytes.substr(mypos, len); + this.signatureTargetHash = _util2.default.Uint8Array2str(bytes.subarray(mypos, mypos + len)); break; case 32: // Embedded Signature this.embeddedSignature = new Signature(); - this.embeddedSignature.read(bytes.substr(mypos)); + this.embeddedSignature.read(bytes.subarray(mypos, bytes.length)); break; default: - util.print_debug("Unknown signature subpacket type " + type + " @:" + mypos); + _util2.default.print_debug("Unknown signature subpacket type " + type + " @:" + mypos); } }; // Produces data to produce signature on Signature.prototype.toSign = function (type, data) { - var t = enums.signature; + var t = _enums2.default.signature; switch (type) { case t.binary: @@ -15084,7 +17328,7 @@ Signature.prototype.toSign = function (type, data) { return data.getBytes(); case t.standalone: - return ''; + return new Uint8Array(0); case t.cert_generic: case t.cert_persona: @@ -15099,39 +17343,36 @@ Signature.prototype.toSign = function (type, data) { } else if (data.userattribute !== undefined) { tag = 0xD1; packet = data.userattribute; - } else throw new Error('Either a userid or userattribute packet needs to be ' + - 'supplied for certification.'); + } else { + throw new Error('Either a userid or userattribute packet needs to be ' + 'supplied for certification.'); + } var bytes = packet.write(); - if (this.version == 4) { - return this.toSign(t.key, data) + - String.fromCharCode(tag) + - util.writeNumber(bytes.length, 4) + - bytes; - } else if (this.version == 3) { - return this.toSign(t.key, data) + - bytes; + if (this.version === 4) { + return _util2.default.concatUint8Array([this.toSign(t.key, data), new Uint8Array([tag]), _util2.default.writeNumber(bytes.length, 4), bytes]); + } else if (this.version === 3) { + return _util2.default.concatUint8Array([this.toSign(t.key, data), bytes]); } break; case t.subkey_binding: case t.subkey_revocation: case t.key_binding: - return this.toSign(t.key, data) + this.toSign(t.key, { + return _util2.default.concatUint8Array([this.toSign(t.key, data), this.toSign(t.key, { key: data.bind - }); + })]); case t.key: - if (data.key === undefined) + if (data.key === undefined) { throw new Error('Key packet is required for this signature.'); - + } return data.key.writeOld(); case t.key_revocation: return this.toSign(t.key, data); case t.timestamp: - return ''; + return new Uint8Array(0); case t.third_party: throw new Error('Not implemented'); default: @@ -15139,19 +17380,16 @@ Signature.prototype.toSign = function (type, data) { } }; - Signature.prototype.calculateTrailer = function () { // calculating the trailer - var trailer = ''; // V3 signatures don't have a trailer - if (this.version == 3) return trailer; - trailer += String.fromCharCode(4); // Version - trailer += String.fromCharCode(0xFF); - trailer += util.writeNumber(this.signatureData.length, 4); - return trailer; + if (this.version === 3) { + return new Uint8Array(0); + } + var first = new Uint8Array([4, 0xFF]); //Version, ? + return _util2.default.concatUint8Array([first, _util2.default.writeNumber(this.signatureData.length, 4)]); }; - /** * verifys the signature packet. Note: not signature types are implemented * @param {String|Object} data data which on the signature applies @@ -15160,35 +17398,34 @@ Signature.prototype.calculateTrailer = function () { * @return {boolean} True if message is verified, else false. */ Signature.prototype.verify = function (key, data) { - var signatureType = enums.write(enums.signature, this.signatureType), - publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm), - hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm); + var signatureType = _enums2.default.write(_enums2.default.signature, this.signatureType), + publicKeyAlgorithm = _enums2.default.write(_enums2.default.publicKey, this.publicKeyAlgorithm), + hashAlgorithm = _enums2.default.write(_enums2.default.hash, this.hashAlgorithm); var bytes = this.toSign(signatureType, data), - trailer = this.calculateTrailer(); - + trailer = this.calculateTrailer(); var mpicount = 0; // Algorithm-Specific Fields for RSA signatures: // - multiprecision number (MPI) of RSA signature value m**d mod n. - if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4) + if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4) { mpicount = 1; + } // Algorithm-Specific Fields for DSA signatures: // - MPI of DSA value r. // - MPI of DSA value s. - else if (publicKeyAlgorithm == 17) - mpicount = 2; + else if (publicKeyAlgorithm === 17) { + mpicount = 2; + } var mpi = [], - i = 0; + i = 0; for (var j = 0; j < mpicount; j++) { - mpi[j] = new type_mpi(); - i += mpi[j].read(this.signature.substr(i)); + mpi[j] = new _mpi2.default(); + i += mpi[j].read(this.signature.subarray(i, this.signature.length)); } - this.verified = crypto.signature.verify(publicKeyAlgorithm, - hashAlgorithm, mpi, key.mpi, - bytes + this.signatureData + trailer); + this.verified = _crypto2.default.signature.verify(publicKeyAlgorithm, hashAlgorithm, mpi, key.mpi, _util2.default.concatUint8Array([bytes, this.signatureData, trailer])); return this.verified; }; @@ -15199,7 +17436,7 @@ Signature.prototype.verify = function (key, data) { */ Signature.prototype.isExpired = function () { if (!this.signatureNeverExpires) { - return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000); + return Date.now() > this.created.getTime() + this.signatureExpirationTime * 1000; } return false; }; @@ -15207,24 +17444,24 @@ Signature.prototype.isExpired = function () { /** * Fix custom types after cloning */ -Signature.prototype.postCloneTypeFix = function() { - this.issuerKeyId = type_keyid.fromClone(this.issuerKeyId); +Signature.prototype.postCloneTypeFix = function () { + this.issuerKeyId = _keyid2.default.fromClone(this.issuerKeyId); }; },{"../crypto":32,"../enums.js":43,"../type/keyid.js":73,"../type/mpi.js":74,"../util.js":76,"./packet.js":59}],67:[function(require,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 @@ -15242,20 +17479,43 @@ Signature.prototype.postCloneTypeFix = function() { * @requires crypto * @requires util * @requires enums + * @requires config * @module packet/sym_encrypted_integrity_protected */ -module.exports = SymEncryptedIntegrityProtected; +'use strict'; -var util = require('../util.js'), - crypto = require('../crypto'), - enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = SymEncryptedIntegrityProtected; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _asmcryptoLite = require('asmcrypto-lite'); + +var _asmcryptoLite2 = _interopRequireDefault(_asmcryptoLite); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var nodeCrypto = _util2.default.getNodeCrypto(); +var Buffer = _util2.default.getNodeBuffer(); /** * @constructor */ function SymEncryptedIntegrityProtected() { - this.tag = enums.packet.symEncryptedIntegrityProtected; + this.tag = _enums2.default.packet.symEncryptedIntegrityProtected; /** The encrypted payload. */ this.encrypted = null; // string /** @@ -15270,48 +17530,52 @@ function SymEncryptedIntegrityProtected() { SymEncryptedIntegrityProtected.prototype.read = function (bytes) { // - A one-octet version number. The only currently defined value is 1. - var version = bytes.charCodeAt(0); + var version = bytes[0]; - if (version != 1) { + if (version !== 1) { throw new Error('Invalid packet version.'); } // - Encrypted data, the output of the selected symmetric-key cipher // operating in Cipher Feedback mode with shift amount equal to the // block size of the cipher (CFB-n where n is the block size). - this.encrypted = bytes.substr(1); + this.encrypted = bytes.subarray(1, bytes.length); }; SymEncryptedIntegrityProtected.prototype.write = function () { - // 1 = Version - return String.fromCharCode(1) + this.encrypted; + return _util2.default.concatUint8Array([new Uint8Array([1]), this.encrypted]); }; SymEncryptedIntegrityProtected.prototype.encrypt = function (sessionKeyAlgorithm, key) { var bytes = this.packets.write(); - var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm); - var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length - - 1); - - var tohash = bytes; - + var prefixrandom = _crypto2.default.getPrefixRandom(sessionKeyAlgorithm); + var repeat = new Uint8Array([prefixrandom[prefixrandom.length - 2], prefixrandom[prefixrandom.length - 1]]); + var prefix = _util2.default.concatUint8Array([prefixrandom, repeat]); // Modification detection code packet. - tohash += String.fromCharCode(0xD3); - tohash += String.fromCharCode(0x14); + var mdc = new Uint8Array([0xD3, 0x14]); + // This could probably be cleaned up to use less memory + var tohash = _util2.default.concatUint8Array([bytes, mdc]); + var hash = _crypto2.default.hash.sha1(_util2.default.concatUint8Array([prefix, tohash])); + tohash = _util2.default.concatUint8Array([tohash, hash]); - tohash += crypto.hash.sha1(prefix + tohash); + if (sessionKeyAlgorithm.substr(0, 3) === 'aes') { + // AES optimizations. Native code for node, asmCrypto for browser. + var blockSize = _crypto2.default.cipher[sessionKeyAlgorithm].blockSize; - - this.encrypted = crypto.cfb.encrypt(prefixrandom, - sessionKeyAlgorithm, tohash, key, false); - - if (prefix.length + tohash.length != this.encrypted.length) - { - this.encrypted = this.encrypted.substring(0, prefix.length + tohash.length); + if (nodeCrypto) { + // Node crypto library. Only loaded if config.useNative === true + var cipherObj = new nodeCrypto.createCipheriv('aes-' + sessionKeyAlgorithm.substr(3, 3) + '-cfb', new Buffer(key), new Buffer(new Uint8Array(blockSize))); + this.encrypted = new Uint8Array(cipherObj.update(new Buffer(_util2.default.concatUint8Array([prefix, tohash])))); + } else { + // asm.js fallback + this.encrypted = _asmcryptoLite2.default.AES_CFB.encrypt(_util2.default.concatUint8Array([prefix, tohash]), key); + } + } else { + this.encrypted = _crypto2.default.cfb.encrypt(prefixrandom, sessionKeyAlgorithm, tohash, key, false).subarray(0, prefix.length + tohash.length); } }; @@ -15321,45 +17585,58 @@ SymEncryptedIntegrityProtected.prototype.encrypt = function (sessionKeyAlgorithm * * @param {module:enums.symmetric} sessionKeyAlgorithm * The selected symmetric encryption algorithm to be used - * @param {String} key The key of cipher blocksize length to be used + * @param {Uint8Array} key The key of cipher blocksize length to be used * @return {String} The decrypted data of this packet */ SymEncryptedIntegrityProtected.prototype.decrypt = function (sessionKeyAlgorithm, key) { - var decrypted = crypto.cfb.decrypt( - sessionKeyAlgorithm, key, this.encrypted, false); + var decrypted; - var mdc = decrypted.slice(decrypted.length - 20, decrypted.length).join(''); + if (sessionKeyAlgorithm.substr(0, 3) === 'aes') { + // AES optimizations. Native code for node, asmCrypto for browser. + var blockSize = _crypto2.default.cipher[sessionKeyAlgorithm].blockSize; - decrypted.splice(decrypted.length - 20); + if (nodeCrypto) { + // Node crypto library. Only loaded if config.useNative === true + var decipherObj = new nodeCrypto.createDecipheriv('aes-' + sessionKeyAlgorithm.substr(3, 3) + '-cfb', new Buffer(key), new Buffer(new Uint8Array(blockSize))); + decrypted = new Uint8Array(decipherObj.update(new Buffer(this.encrypted))); + } else { + // asm.js fallback + decrypted = _asmcryptoLite2.default.AES_CFB.decrypt(this.encrypted, key); + } + + // Remove random prefix + decrypted = decrypted.subarray(blockSize + 2, decrypted.length); + } else { + decrypted = _crypto2.default.cfb.decrypt(sessionKeyAlgorithm, key, this.encrypted, false); + } // there must be a modification detection code packet as the // last packet and everything gets hashed except the hash itself - this.hash = crypto.hash.sha1( - crypto.cfb.mdc(sessionKeyAlgorithm, key, this.encrypted) + decrypted.join('')); + this.hash = _util2.default.Uint8Array2str(_crypto2.default.hash.sha1(_util2.default.concatUint8Array([_crypto2.default.cfb.mdc(sessionKeyAlgorithm, key, this.encrypted), decrypted.subarray(0, decrypted.length - 20)]))); + var mdc = _util2.default.Uint8Array2str(decrypted.subarray(decrypted.length - 20, decrypted.length)); - if (this.hash != mdc) { + if (this.hash !== mdc) { throw new Error('Modification detected.'); } else { - decrypted.splice(decrypted.length - 2); - this.packets.read(decrypted.join('')); + this.packets.read(decrypted.subarray(0, decrypted.length - 22)); } }; -},{"../crypto":32,"../enums.js":43,"../util.js":76}],68:[function(require,module,exports){ +},{"../crypto":32,"../enums.js":43,"../util.js":76,"asmcrypto-lite":1}],68:[function(require,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 @@ -15378,72 +17655,91 @@ SymEncryptedIntegrityProtected.prototype.decrypt = function (sessionKeyAlgorithm * The recipient of the message finds a session key that is encrypted to their * public key, decrypts the session key, and then uses the session key to * decrypt the message. + * @requires util * @requires crypto * @requires enums * @requires type/s2k * @module packet/sym_encrypted_session_key */ -var type_s2k = require('../type/s2k.js'), - enums = require('../enums.js'), - crypto = require('../crypto'); +'use strict'; -module.exports = SymEncryptedSessionKey; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = SymEncryptedSessionKey; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _s2k = require('../type/s2k.js'); + +var _s2k2 = _interopRequireDefault(_s2k); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function SymEncryptedSessionKey() { - this.tag = enums.packet.symEncryptedSessionKey; + this.tag = _enums2.default.packet.symEncryptedSessionKey; this.version = 4; + this.sessionKey = null; this.sessionKeyEncryptionAlgorithm = null; this.sessionKeyAlgorithm = 'aes256'; this.encrypted = null; - this.s2k = new type_s2k(); + this.s2k = new _s2k2.default(); } /** * Parsing function for a symmetric encrypted session key packet (tag 3). * - * @param {String} input Payload of a tag 1 packet + * @param {Uint8Array} input Payload of a tag 1 packet * @param {Integer} position Position to start reading from the input string * @param {Integer} len * Length of the packet or the remaining length of * input at position * @return {module:packet/sym_encrypted_session_key} Object representation */ -SymEncryptedSessionKey.prototype.read = function(bytes) { +SymEncryptedSessionKey.prototype.read = function (bytes) { // A one-octet version number. The only currently defined version is 4. - this.version = bytes.charCodeAt(0); + this.version = bytes[0]; // A one-octet number describing the symmetric algorithm used. - var algo = enums.read(enums.symmetric, bytes.charCodeAt(1)); + var algo = _enums2.default.read(_enums2.default.symmetric, bytes[1]); // A string-to-key (S2K) specifier, length as defined above. - var s2klength = this.s2k.read(bytes.substr(2)); + var s2klength = this.s2k.read(bytes.subarray(2, bytes.length)); // Optionally, the encrypted session key itself, which is decrypted // with the string-to-key object. var done = s2klength + 2; if (done < bytes.length) { - this.encrypted = bytes.substr(done); + this.encrypted = bytes.subarray(done, bytes.length); this.sessionKeyEncryptionAlgorithm = algo; - } else + } else { this.sessionKeyAlgorithm = algo; + } }; -SymEncryptedSessionKey.prototype.write = function() { - var algo = this.encrypted === null ? - this.sessionKeyAlgorithm : - this.sessionKeyEncryptionAlgorithm; +SymEncryptedSessionKey.prototype.write = function () { + var algo = this.encrypted === null ? this.sessionKeyAlgorithm : this.sessionKeyEncryptionAlgorithm; - var bytes = String.fromCharCode(this.version) + - String.fromCharCode(enums.write(enums.symmetric, algo)) + - this.s2k.write(); + var bytes = _util2.default.concatUint8Array([new Uint8Array([this.version, _enums2.default.write(_enums2.default.symmetric, algo)]), this.s2k.write()]); - if (this.encrypted !== null) - bytes += this.encrypted; + if (this.encrypted !== null) { + bytes = _util2.default.concatUint8Array([bytes, this.encrypted]); + } return bytes; }; @@ -15451,68 +17747,65 @@ SymEncryptedSessionKey.prototype.write = function() { * Decrypts the session key (only for public key encrypted session key * packets (tag 1) * - * @return {String} The unencrypted session key + * @return {Uint8Array} The unencrypted session key */ -SymEncryptedSessionKey.prototype.decrypt = function(passphrase) { - var algo = this.sessionKeyEncryptionAlgorithm !== null ? - this.sessionKeyEncryptionAlgorithm : - this.sessionKeyAlgorithm; +SymEncryptedSessionKey.prototype.decrypt = function (passphrase) { + var algo = this.sessionKeyEncryptionAlgorithm !== null ? this.sessionKeyEncryptionAlgorithm : this.sessionKeyAlgorithm; - - var length = crypto.cipher[algo].keySize; + var length = _crypto2.default.cipher[algo].keySize; var key = this.s2k.produce_key(passphrase, length); if (this.encrypted === null) { this.sessionKey = key; - } else { - var decrypted = crypto.cfb.decrypt( - this.sessionKeyEncryptionAlgorithm, key, this.encrypted, true); - decrypted = decrypted.join(''); + var decrypted = _crypto2.default.cfb.normalDecrypt(algo, key, this.encrypted, null); - this.sessionKeyAlgorithm = enums.read(enums.symmetric, - decrypted[0].keyCodeAt()); + this.sessionKeyAlgorithm = _enums2.default.read(_enums2.default.symmetric, decrypted[0]); - this.sessionKey = decrypted.substr(1); + this.sessionKey = decrypted.subarray(1, decrypted.length); } }; -SymEncryptedSessionKey.prototype.encrypt = function(passphrase) { - var length = crypto.getKeyLength(this.sessionKeyEncryptionAlgorithm); +SymEncryptedSessionKey.prototype.encrypt = function (passphrase) { + var algo = this.sessionKeyEncryptionAlgorithm !== null ? this.sessionKeyEncryptionAlgorithm : this.sessionKeyAlgorithm; + + this.sessionKeyEncryptionAlgorithm = algo; + + var length = _crypto2.default.cipher[algo].keySize; var key = this.s2k.produce_key(passphrase, length); - var private_key = String.fromCharCode( - enums.write(enums.symmetric, this.sessionKeyAlgorithm)) + + var algo_enum = new Uint8Array([_enums2.default.write(_enums2.default.symmetric, this.sessionKeyAlgorithm)]); - crypto.getRandomBytes( - crypto.getKeyLength(this.sessionKeyAlgorithm)); + var private_key; + if (this.sessionKey === null) { + this.sessionKey = _crypto2.default.getRandomBytes(_crypto2.default.cipher[this.sessionKeyAlgorithm].keySize); + } + private_key = _util2.default.concatUint8Array([algo_enum, this.sessionKey]); - this.encrypted = crypto.cfb.encrypt( - crypto.getPrefixRandom(this.sessionKeyEncryptionAlgorithm), - this.sessionKeyEncryptionAlgorithm, key, private_key, true); + this.encrypted = _crypto2.default.cfb.normalEncrypt(algo, key, private_key, null); }; /** * Fix custom types after cloning */ -SymEncryptedSessionKey.prototype.postCloneTypeFix = function() { - this.s2k = type_s2k.fromClone(this.s2k); +SymEncryptedSessionKey.prototype.postCloneTypeFix = function () { + this.s2k = _s2k2.default.fromClone(this.s2k); }; -},{"../crypto":32,"../enums.js":43,"../type/s2k.js":75}],69:[function(require,module,exports){ +},{"../crypto":32,"../enums.js":43,"../type/s2k.js":75,"../util.js":76}],69:[function(require,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 @@ -15530,22 +17823,37 @@ SymEncryptedSessionKey.prototype.postCloneTypeFix = function() { * @module packet/symmetrically_encrypted */ -module.exports = SymmetricallyEncrypted; +'use strict'; -var crypto = require('../crypto'), - enums = require('../enums.js'), - config = require('../config'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = SymmetricallyEncrypted; + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _config = require('../config'); + +var _config2 = _interopRequireDefault(_config); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function SymmetricallyEncrypted() { - this.tag = enums.packet.symmetricallyEncrypted; + this.tag = _enums2.default.packet.symmetricallyEncrypted; this.encrypted = null; - /** Decrypted packets contained within. + /** Decrypted packets contained within. * @type {module:packet/packetlist} */ - this.packets = null; - this.ignore_mdc_error = config.ignore_mdc_error; + this.packets = null; + this.ignore_mdc_error = _config2.default.ignore_mdc_error; } SymmetricallyEncrypted.prototype.read = function (bytes) { @@ -15566,39 +17874,44 @@ SymmetricallyEncrypted.prototype.write = function () { * algorithm */ SymmetricallyEncrypted.prototype.decrypt = function (sessionKeyAlgorithm, key) { - var decrypted = crypto.cfb.decrypt(sessionKeyAlgorithm, key, this.encrypted, true); + var decrypted = _crypto2.default.cfb.decrypt(sessionKeyAlgorithm, key, this.encrypted, true); // for modern cipher (blocklength != 64 bit, except for Twofish) MDC is required - if (!this.ignore_mdc_error && - (sessionKeyAlgorithm === 'aes128' || - sessionKeyAlgorithm === 'aes192' || - sessionKeyAlgorithm === 'aes256')) { - throw new Error('Decryption failed due to missing MDC in combination with modern cipher.') + if (!this.ignore_mdc_error && (sessionKeyAlgorithm === 'aes128' || sessionKeyAlgorithm === 'aes192' || sessionKeyAlgorithm === 'aes256')) { + throw new Error('Decryption failed due to missing MDC in combination with modern cipher.'); } - this.packets.read(decrypted.join('')); + this.packets.read(decrypted); }; SymmetricallyEncrypted.prototype.encrypt = function (algo, key) { var data = this.packets.write(); - this.encrypted = crypto.cfb.encrypt( - crypto.getPrefixRandom(algo), algo, data, key, true); + this.encrypted = _crypto2.default.cfb.encrypt(_crypto2.default.getPrefixRandom(algo), algo, data, key, true); }; -},{"../config":17,"../crypto":32,"../enums.js":43}],70:[function(require,module,exports){ +},{"../config":19,"../crypto":32,"../enums.js":43}],70:[function(require,module,exports){ /** * @requires enums * @module packet/trust */ -module.exports = Trust; +'use strict'; -var enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Trust; + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function Trust() { - this.tag = enums.packet.trust; + this.tag = _enums2.default.packet.trust; } /** @@ -15606,24 +17919,22 @@ function Trust() { * Currently empty as we ignore trust packets * @param {String} byptes payload of a tag 12 packet */ -Trust.prototype.read = function (bytes) { - -}; +Trust.prototype.read = function () {}; },{"../enums.js":43}],71:[function(require,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 @@ -15649,46 +17960,61 @@ Trust.prototype.read = function (bytes) { * @module packet/user_attribute */ -var util = require('../util.js'), - packet = require('./packet.js'), - enums = require('../enums.js'); +'use strict'; -module.exports = UserAttribute; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = UserAttribute; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _packet = require('./packet.js'); + +var _packet2 = _interopRequireDefault(_packet); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function UserAttribute() { - this.tag = enums.packet.userAttribute; + this.tag = _enums2.default.packet.userAttribute; this.attributes = []; } /** * parsing function for a user attribute packet (tag 17). - * @param {String} input payload of a tag 17 packet + * @param {Uint8Array} input payload of a tag 17 packet */ -UserAttribute.prototype.read = function(bytes) { +UserAttribute.prototype.read = function (bytes) { var i = 0; while (i < bytes.length) { - var len = packet.readSimpleLength(bytes.substr(i)); + var len = _packet2.default.readSimpleLength(bytes.subarray(i, bytes.length)); i += len.offset; - this.attributes.push(bytes.substr(i, len.len)); + this.attributes.push(_util2.default.Uint8Array2str(bytes.subarray(i, i + len.len))); i += len.len; } }; /** - * Creates a string representation of the user attribute packet - * @return {String} string representation + * Creates a binary representation of the user attribute packet + * @return {Uint8Array} string representation */ -UserAttribute.prototype.write = function() { - var result = ''; +UserAttribute.prototype.write = function () { + var arr = []; for (var i = 0; i < this.attributes.length; i++) { - result += packet.writeSimpleLength(this.attributes[i].length); - result += this.attributes[i]; + arr.push(_packet2.default.writeSimpleLength(this.attributes[i].length)); + arr.push(_util2.default.str2Uint8Array(this.attributes[i])); } - return result; + return _util2.default.concatUint8Array(arr); }; /** @@ -15696,11 +18022,11 @@ UserAttribute.prototype.write = function() { * @param {module:user_attribute~UserAttribute} usrAttr * @return {Boolean} true if equal */ -UserAttribute.prototype.equals = function(usrAttr) { +UserAttribute.prototype.equals = function (usrAttr) { if (!usrAttr || !(usrAttr instanceof UserAttribute)) { return false; } - return this.attributes.every(function(attr, index) { + return this.attributes.every(function (attr, index) { return attr === usrAttr.attributes[index]; }); }; @@ -15708,17 +18034,17 @@ UserAttribute.prototype.equals = function(usrAttr) { },{"../enums.js":43,"../util.js":76,"./packet.js":59}],72:[function(require,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 @@ -15736,53 +18062,65 @@ UserAttribute.prototype.equals = function(usrAttr) { * @module packet/userid */ -module.exports = Userid; +'use strict'; -var util = require('../util.js'), - enums = require('../enums.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Userid; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function Userid() { - this.tag = enums.packet.userid; + this.tag = _enums2.default.packet.userid; /** A string containing the user id. Usually in the form * John Doe - * @type {String} + * @type {String} */ this.userid = ''; } /** * Parsing function for a user id packet (tag 13). - * @param {String} input payload of a tag 13 packet + * @param {Uint8Array} input payload of a tag 13 packet */ Userid.prototype.read = function (bytes) { - this.userid = util.decode_utf8(bytes); + this.userid = _util2.default.decode_utf8(_util2.default.Uint8Array2str(bytes)); }; /** - * Creates a string representation of the user id packet - * @return {String} string representation + * Creates a binary representation of the user id packet + * @return {Uint8Array} binary representation */ Userid.prototype.write = function () { - return util.encode_utf8(this.userid); + return _util2.default.str2Uint8Array(_util2.default.encode_utf8(this.userid)); }; },{"../enums.js":43,"../util.js":76}],73:[function(require,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 @@ -15798,15 +18136,23 @@ Userid.prototype.write = function () { * @module type/keyid */ -module.exports = Keyid; +'use strict'; -var util = require('../util.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = Keyid; + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor */ function Keyid() { - this.bytes = ''; } @@ -15814,63 +18160,63 @@ function Keyid() { * Parsing method for a key id * @param {String} input Input to read the key id from */ -Keyid.prototype.read = function(bytes) { - this.bytes = bytes.substr(0, 8); +Keyid.prototype.read = function (bytes) { + this.bytes = _util2.default.Uint8Array2str(bytes.subarray(0, 8)); }; -Keyid.prototype.write = function() { - return this.bytes; +Keyid.prototype.write = function () { + return _util2.default.str2Uint8Array(this.bytes); }; -Keyid.prototype.toHex = function() { - return util.hexstrdump(this.bytes); +Keyid.prototype.toHex = function () { + return _util2.default.hexstrdump(this.bytes); }; -Keyid.prototype.equals = function(keyid) { - return this.bytes == keyid.bytes; +Keyid.prototype.equals = function (keyid) { + return this.bytes === keyid.bytes; }; -Keyid.prototype.isNull = function() { +Keyid.prototype.isNull = function () { return this.bytes === ''; }; -module.exports.mapToHex = function (keyId) { +Keyid.mapToHex = function (keyId) { return keyId.toHex(); }; -module.exports.fromClone = function (clone) { +Keyid.fromClone = function (clone) { var keyid = new Keyid(); keyid.bytes = clone.bytes; return keyid; }; -module.exports.fromId = function (hex) { +Keyid.fromId = function (hex) { var keyid = new Keyid(); - keyid.read(util.hex2bin(hex)); + keyid.read(_util2.default.hex2bin(hex)); return keyid; }; },{"../util.js":76}],74:[function(require,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 // Hint: We hold our MPIs as an array of octets in big endian format preceeding a two // octet scalar: MPI: [a,b,c,d,e,f] -// - MPI size: (a << 8) | b +// - MPI size: (a << 8) | b // - MPI = c | d << 8 | e << ((MPI.length -2)*8) | f ((MPI.length -2)*8) /** @@ -15887,10 +18233,22 @@ module.exports.fromId = function (hex) { * @module type/mpi */ -module.exports = MPI; +'use strict'; -var BigInteger = require('../crypto/public_key/jsbn.js'), - util = require('../util.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = MPI; + +var _jsbn = require('../crypto/public_key/jsbn.js'); + +var _jsbn2 = _interopRequireDefault(_jsbn); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor @@ -15906,7 +18264,12 @@ function MPI() { * @return {Integer} Length of data read */ MPI.prototype.read = function (bytes) { - var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1); + + if (typeof bytes === 'string' || String.prototype.isPrototypeOf(bytes)) { + bytes = _util2.default.str2Uint8Array(bytes); + } + + var bits = bytes[0] << 8 | bytes[1]; // Additional rules: // @@ -15920,18 +18283,19 @@ MPI.prototype.read = function (bytes) { // specified above is not applicable in JavaScript var bytelen = Math.ceil(bits / 8); - var raw = bytes.substr(2, bytelen); + var raw = _util2.default.Uint8Array2str(bytes.subarray(2, 2 + bytelen)); this.fromBytes(raw); return 2 + bytelen; }; MPI.prototype.fromBytes = function (bytes) { - this.data = new BigInteger(util.hexstrdump(bytes), 16); + this.data = new _jsbn2.default(_util2.default.hexstrdump(bytes), 16); }; MPI.prototype.toBytes = function () { - return this.write().substr(2); + var bytes = _util2.default.Uint8Array2str(this.write()); + return bytes.substr(2); }; MPI.prototype.byteLength = function () { @@ -15939,11 +18303,11 @@ MPI.prototype.byteLength = function () { }; /** - * Converts the mpi object to a string as specified in {@link http://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2} - * @return {String} mpi Byte representation + * Converts the mpi object to a bytes as specified in {@link http://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2} + * @return {Uint8Aray} mpi Byte representation */ MPI.prototype.write = function () { - return this.data.toMPI(); + return _util2.default.str2Uint8Array(this.data.toMPI()); }; MPI.prototype.toBigInteger = function () { @@ -15954,9 +18318,9 @@ MPI.prototype.fromBigInteger = function (bn) { this.data = bn.clone(); }; -module.exports.fromClone = function (clone) { - clone.data.copyTo = BigInteger.prototype.copyTo; - var bn = new BigInteger(); +MPI.fromClone = function (clone) { + clone.data.copyTo = _jsbn2.default.prototype.copyTo; + var bn = new _jsbn2.default(); clone.data.copyTo(bn); var mpi = new MPI(); mpi.data = bn; @@ -15966,17 +18330,17 @@ module.exports.fromClone = function (clone) { },{"../crypto/public_key/jsbn.js":37,"../util.js":76}],75:[function(require,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 @@ -15995,11 +18359,26 @@ module.exports.fromClone = function (clone) { * @module type/s2k */ -module.exports = S2K; +'use strict'; -var enums = require('../enums.js'), - util = require('../util.js'), - crypto = require('../crypto'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = S2K; + +var _enums = require('../enums.js'); + +var _enums2 = _interopRequireDefault(_enums); + +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @constructor @@ -16013,14 +18392,14 @@ function S2K() { /** Eight bytes of salt in a binary string. * @type {String} */ - this.salt = crypto.random.getRandomBytes(8); + this.salt = _crypto2.default.random.getRandomBytes(8); } S2K.prototype.get_count = function () { // Exponent bias, defined in RFC4880 var expbias = 6; - return (16 + (this.c & 15)) << ((this.c >> 4) + expbias); + return 16 + (this.c & 15) << (this.c >> 4) + expbias; }; /** @@ -16030,36 +18409,36 @@ S2K.prototype.get_count = function () { */ S2K.prototype.read = function (bytes) { var i = 0; - this.type = enums.read(enums.s2k, bytes.charCodeAt(i++)); - this.algorithm = enums.read(enums.hash, bytes.charCodeAt(i++)); + this.type = _enums2.default.read(_enums2.default.s2k, bytes[i++]); + this.algorithm = _enums2.default.read(_enums2.default.hash, bytes[i++]); switch (this.type) { case 'simple': break; case 'salted': - this.salt = bytes.substr(i, 8); + this.salt = bytes.subarray(i, i + 8); i += 8; break; case 'iterated': - this.salt = bytes.substr(i, 8); + this.salt = bytes.subarray(i, i + 8); i += 8; // Octet 10: count, a one-octet, coded value - this.c = bytes.charCodeAt(i++); + this.c = bytes[i++]; break; case 'gnu': - if (bytes.substr(i, 3) == "GNU") { + if (_util2.default.Uint8Array2str(bytes.subarray(i, 3)) === "GNU") { i += 3; // GNU - var gnuExtType = 1000 + bytes.charCodeAt(i++); - if (gnuExtType == 1001) { + var gnuExtType = 1000 + bytes[i++]; + if (gnuExtType === 1001) { this.type = gnuExtType; // GnuPG extension mode 1001 -- don't write secret key at all } else { - throw new Error("Unknown s2k gnu protection mode."); - } + throw new Error("Unknown s2k gnu protection mode."); + } } else { throw new Error("Unknown s2k type."); } @@ -16072,24 +18451,23 @@ S2K.prototype.read = function (bytes) { return i; }; - /** - * writes an s2k hash based on the inputs. - * @return {String} Produced key of hashAlgorithm hash length + * Serializes s2k information + * @return {Uint8Array} binary representation of s2k */ S2K.prototype.write = function () { - var bytes = String.fromCharCode(enums.write(enums.s2k, this.type)); - bytes += String.fromCharCode(enums.write(enums.hash, this.algorithm)); + + var arr = [new Uint8Array([_enums2.default.write(_enums2.default.s2k, this.type), _enums2.default.write(_enums2.default.hash, this.algorithm)])]; switch (this.type) { case 'simple': break; case 'salted': - bytes += this.salt; + arr.push(this.salt); break; case 'iterated': - bytes += this.salt; - bytes += String.fromCharCode(this.c); + arr.push(this.salt); + arr.push(new Uint8Array([this.c])); break; case 'gnu': throw new Error("GNU s2k type not supported."); @@ -16097,44 +18475,45 @@ S2K.prototype.write = function () { throw new Error("Unknown s2k type."); } - return bytes; + return _util2.default.concatUint8Array(arr); }; /** * Produces a key using the specified passphrase and the defined * hashAlgorithm * @param {String} passphrase Passphrase containing user input - * @return {String} Produced key with a length corresponding to + * @return {Uint8Array} Produced key with a length corresponding to * hashAlgorithm hash length */ S2K.prototype.produce_key = function (passphrase, numBytes) { - passphrase = util.encode_utf8(passphrase); + passphrase = _util2.default.str2Uint8Array(_util2.default.encode_utf8(passphrase)); function round(prefix, s2k) { - var algorithm = enums.write(enums.hash, s2k.algorithm); + var algorithm = _enums2.default.write(_enums2.default.hash, s2k.algorithm); switch (s2k.type) { case 'simple': - return crypto.hash.digest(algorithm, prefix + passphrase); + return _crypto2.default.hash.digest(algorithm, _util2.default.concatUint8Array([prefix, passphrase])); case 'salted': - return crypto.hash.digest(algorithm, - prefix + s2k.salt + passphrase); + return _crypto2.default.hash.digest(algorithm, _util2.default.concatUint8Array([prefix, s2k.salt, passphrase])); case 'iterated': var isp = [], - count = s2k.get_count(), - data = s2k.salt + passphrase; + count = s2k.get_count(), + data = _util2.default.concatUint8Array([s2k.salt, passphrase]); - while (isp.length * data.length < count) + while (isp.length * data.length < count) { isp.push(data); + } - isp = isp.join(''); + isp = _util2.default.concatUint8Array(isp); - if (isp.length > count) - isp = isp.substr(0, count); + if (isp.length > count) { + isp = isp.subarray(0, count); + } - return crypto.hash.digest(algorithm, prefix + isp); + return _crypto2.default.hash.digest(algorithm, _util2.default.concatUint8Array([prefix, isp])); case 'gnu': throw new Error("GNU s2k type not supported."); @@ -16144,23 +18523,31 @@ S2K.prototype.produce_key = function (passphrase, numBytes) { } } - var result = '', - prefix = ''; + var arr = [], + rlength = 0, + prefix = new Uint8Array(numBytes); - while (result.length <= numBytes) { - result += round(prefix, this); - prefix += String.fromCharCode(0); + for (var i = 0; i < numBytes; i++) { + prefix[i] = 0; + } + i = 0; + + while (rlength <= numBytes) { + var result = round(prefix.subarray(0, i), this); + arr.push(result); + rlength += result.length; + i++; } - return result.substr(0, numBytes); + return _util2.default.concatUint8Array(arr).subarray(0, numBytes); }; -module.exports.fromClone = function (clone) { +S2K.fromClone = function (clone) { var s2k = new S2K(); - this.algorithm = clone.algorithm; - this.type = clone.type; - this.c = clone.c; - this.salt = clone.salt; + s2k.algorithm = clone.algorithm; + s2k.type = clone.type; + s2k.c = clone.c; + s2k.salt = clone.salt; return s2k; }; @@ -16190,37 +18577,104 @@ module.exports.fromClone = function (clone) { 'use strict'; -var config = require('./config'); +Object.defineProperty(exports, "__esModule", { + value: true +}); -module.exports = { - readNumber: function (bytes) { +var _config = require('./config'); + +var _config2 = _interopRequireDefault(_config); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = { + + isString: function isString(data) { + return typeof data === 'string' || String.prototype.isPrototypeOf(data); + }, + + isArray: function isArray(data) { + return Array.prototype.isPrototypeOf(data); + }, + + isUint8Array: function isUint8Array(data) { + return Uint8Array.prototype.isPrototypeOf(data); + }, + + isEmailAddress: function isEmailAddress(data) { + if (!this.isString(data)) { + return false; + } + var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(data); + }, + + isUserId: function isUserId(data) { + if (!this.isString(data)) { + return false; + } + return (/ $/.test(data) + ); + }, + + /** + * Get transferable objects to pass buffers with zero copy (similar to "pass by reference" in C++) + * See: https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage + * @param {Object} obj the options object to be passed to the web worker + * @return {Array} an array of binary data to be passed + */ + getTransferables: function getTransferables(obj) { + if (_config2.default.zeroCopy && Object.prototype.isPrototypeOf(obj)) { + var transferables = []; + this.collectBuffers(obj, transferables); + return transferables.length ? transferables : undefined; + } + }, + + collectBuffers: function collectBuffers(obj, collection) { + if (!obj) { + return; + } + if (this.isUint8Array(obj) && collection.indexOf(obj.buffer) === -1) { + collection.push(obj.buffer); + return; + } + if (Object.prototype.isPrototypeOf(obj)) { + for (var key in obj) { + // recursively search all children + this.collectBuffers(obj[key], collection); + } + } + }, + + readNumber: function readNumber(bytes) { var n = 0; for (var i = 0; i < bytes.length; i++) { n <<= 8; - n += bytes.charCodeAt(i); + n += bytes[i]; } return n; }, - writeNumber: function (n, bytes) { - var b = ''; + writeNumber: function writeNumber(n, bytes) { + var b = new Uint8Array(bytes); for (var i = 0; i < bytes; i++) { - b += String.fromCharCode((n >> (8 * (bytes - i - 1))) & 0xFF); + b[i] = n >> 8 * (bytes - i - 1) & 0xFF; } return b; }, - readDate: function (bytes) { + readDate: function readDate(bytes) { var n = this.readNumber(bytes); var d = new Date(); d.setTime(n * 1000); return d; }, - writeDate: function (time) { + writeDate: function writeDate(time) { var numeric = Math.round(time.getTime() / 1000); return this.writeNumber(numeric, 4); @@ -16228,7 +18682,7 @@ module.exports = { emailRegEx: /^[+a-zA-Z0-9_.-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,6}$/, - hexdump: function (str) { + hexdump: function hexdump(str) { var r = []; var e = str.length; var c = 0; @@ -16236,11 +18690,14 @@ module.exports = { var i = 0; while (c < e) { h = str.charCodeAt(c++).toString(16); - while (h.length < 2) h = "0" + h; + while (h.length < 2) { + h = "0" + h; + } r.push(" " + h); i++; - if (i % 32 === 0) + if (i % 32 === 0) { r.push("\n "); + } } return r.join(''); }, @@ -16250,16 +18707,19 @@ module.exports = { * @param {String} str String to convert * @return {String} String containing the hexadecimal values */ - hexstrdump: function (str) { - if (str === null) + hexstrdump: function hexstrdump(str) { + if (str === null) { return ""; + } var r = []; var e = str.length; var c = 0; var h; while (c < e) { h = str.charCodeAt(c++).toString(16); - while (h.length < 2) h = "0" + h; + while (h.length < 2) { + h = "0" + h; + } r.push("" + h); } return r.join(''); @@ -16270,10 +18730,11 @@ module.exports = { * @param {String} str Hex string to convert * @return {String} String containing the binary values */ - hex2bin: function (hex) { + hex2bin: function hex2bin(hex) { var str = ''; - for (var i = 0; i < hex.length; i += 2) + for (var i = 0; i < hex.length; i += 2) { str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + } return str; }, @@ -16282,26 +18743,27 @@ module.exports = { * @param {String} str Array of bytes to convert * @return {String} Hexadecimal representation of the array */ - hexidump: function (str) { + hexidump: function hexidump(str) { var r = []; var e = str.length; var c = 0; var h; while (c < e) { h = str[c++].toString(16); - while (h.length < 2) h = "0" + h; + while (h.length < 2) { + h = "0" + h; + } r.push("" + h); } return r.join(''); }, - /** * Convert a native javascript string to a string of utf8 bytes * @param {String} str The string to convert * @return {String} A valid squence of utf8 bytes */ - encode_utf8: function (str) { + encode_utf8: function encode_utf8(str) { return unescape(encodeURIComponent(str)); }, @@ -16310,7 +18772,7 @@ module.exports = { * @param {String} utf8 A valid squence of utf8 bytes * @return {String} A native javascript string */ - decode_utf8: function (utf8) { + decode_utf8: function decode_utf8(utf8) { if (typeof utf8 !== 'string') { throw new Error('Parameter "utf8" is not of type string'); } @@ -16326,7 +18788,7 @@ module.exports = { * @param {Array} bin An array of (binary) integers to convert * @return {String} The string representation of the array */ - bin2str: function (bin) { + bin2str: function bin2str(bin) { var result = []; for (var i = 0; i < bin.length; i++) { result[i] = String.fromCharCode(bin[i]); @@ -16339,7 +18801,7 @@ module.exports = { * @param {String} str String to convert * @return {Array} An array of (binary) integers */ - str2bin: function (str) { + str2bin: function str2bin(str) { var result = []; for (var i = 0; i < str.length; i++) { result[i] = str.charCodeAt(i); @@ -16347,13 +18809,16 @@ module.exports = { return result; }, - /** * Convert a string to a Uint8Array * @param {String} str String to convert * @return {Uint8Array} The array of (binary) integers */ - str2Uint8Array: function (str) { + str2Uint8Array: function str2Uint8Array(str) { + if (typeof str !== 'string' && !String.prototype.isPrototypeOf(str)) { + throw new Error('str2Uint8Array: Data must be in the form of a string'); + } + var result = new Uint8Array(str.length); for (var i = 0; i < str.length; i++) { result[i] = str.charCodeAt(i); @@ -16368,7 +18833,11 @@ module.exports = { * @param {Uint8Array} bin An array of (binary) integers to convert * @return {String} String representation of the array */ - Uint8Array2str: function (bin) { + Uint8Array2str: function Uint8Array2str(bin) { + if (!Uint8Array.prototype.isPrototypeOf(bin)) { + throw new Error('Uint8Array2str: Data must be in the form of a Uint8Array'); + } + var result = []; for (var i = 0; i < bin.length; i++) { result[i] = String.fromCharCode(bin[i]); @@ -16377,21 +18846,87 @@ module.exports = { }, /** - * Calculates a 16bit sum of a string by adding each character + * Concat Uint8arrays + * @function module:util.concatUint8Array + * @param {Array} Array of Uint8Arrays to concatenate + * @return {Uint8array} Concatenated array + */ + concatUint8Array: function concatUint8Array(arrays) { + var totalLength = 0; + arrays.forEach(function (element) { + if (!Uint8Array.prototype.isPrototypeOf(element)) { + throw new Error('concatUint8Array: Data must be in the form of a Uint8Array'); + } + + totalLength += element.length; + }); + + var result = new Uint8Array(totalLength); + var pos = 0; + arrays.forEach(function (element) { + result.set(element, pos); + pos += element.length; + }); + + return result; + }, + + /** + * Deep copy Uint8Array + * @function module:util.copyUint8Array + * @param {Uint8Array} Array to copy + * @return {Uint8Array} new Uint8Array + */ + copyUint8Array: function copyUint8Array(array) { + if (!Uint8Array.prototype.isPrototypeOf(array)) { + throw new Error('Data must be in the form of a Uint8Array'); + } + + var copy = new Uint8Array(array.length); + copy.set(array); + return copy; + }, + + /** + * Check Uint8Array equality + * @function module:util.equalsUint8Array + * @param {Uint8Array} first array + * @param {Uint8Array} second array + * @return {Boolean} equality + */ + equalsUint8Array: function equalsUint8Array(array1, array2) { + if (!Uint8Array.prototype.isPrototypeOf(array1) || !Uint8Array.prototype.isPrototypeOf(array2)) { + throw new Error('Data must be in the form of a Uint8Array'); + } + + if (array1.length !== array2.length) { + return false; + } + + for (var i = 0; i < array1.length; i++) { + if (array1[i] !== array2[i]) { + return false; + } + } + return true; + }, + + /** + * Calculates a 16bit sum of a Uint8Array by adding each character * codes modulus 65535 - * @param {String} text String to create a sum of + * @param {Uint8Array} Uint8Array to create a sum of * @return {Integer} An integer containing the sum of all character * codes % 65535 */ - calc_checksum: function (text) { + calc_checksum: function calc_checksum(text) { var checksum = { s: 0, - add: function (sadd) { + add: function add(sadd) { this.s = (this.s + sadd) % 65536; } }; for (var i = 0; i < text.length; i++) { - checksum.add(text.charCodeAt(i)); + checksum.add(text[i]); } return checksum.s; }, @@ -16402,8 +18937,8 @@ module.exports = { * @link module:config/config.debug is set to true. * @param {String} str String of the debug message */ - print_debug: function (str) { - if (config.debug) { + print_debug: function print_debug(str) { + if (_config2.default.debug) { console.log(str); } }, @@ -16415,17 +18950,18 @@ module.exports = { * Different than print_debug because will call hexstrdump iff necessary. * @param {String} str String of the debug message */ - print_debug_hexstr_dump: function (str, strToHex) { - if (config.debug) { + print_debug_hexstr_dump: function print_debug_hexstr_dump(str, strToHex) { + if (_config2.default.debug) { str = str + this.hexstrdump(strToHex); console.log(str); } }, - getLeftNBits: function (string, bitcount) { + getLeftNBits: function getLeftNBits(string, bitcount) { var rest = bitcount % 8; - if (rest === 0) + if (rest === 0) { return string.substring(0, bitcount / 8); + } var bytes = (bitcount - rest) / 8 + 1; var result = string.substring(0, bytes); return this.shiftRight(result, 8 - rest); // +String.fromCharCode(string.charCodeAt(bytes -1) << (8-rest) & 0xFF); @@ -16438,25 +18974,26 @@ module.exports = { * than 9) * @return {String} Resulting string. */ - shiftRight: function (value, bitcount) { - var temp = util.str2bin(value); + shiftRight: function shiftRight(value, bitcount) { + var temp = this.str2bin(value); if (bitcount % 8 !== 0) { for (var i = temp.length - 1; i >= 0; i--) { temp[i] >>= bitcount % 8; - if (i > 0) - temp[i] |= (temp[i - 1] << (8 - (bitcount % 8))) & 0xFF; + if (i > 0) { + temp[i] |= temp[i - 1] << 8 - bitcount % 8 & 0xFF; + } } } else { return value; } - return util.bin2str(temp); + return this.bin2str(temp); }, /** * Return the algorithm type as string * @return {String} String representing the message type */ - get_hashAlgorithmString: function (algo) { + get_hashAlgorithmString: function get_hashAlgorithmString(algo) { switch (algo) { case 1: return "MD5"; @@ -16478,12 +19015,11 @@ module.exports = { /** * Get native Web Cryptography api. The default configuration is to use - * the api when available. But it can also be deactivated with config.useWebCrypto - * @return {Object} The SubtleCrypto api or 'undefined' + * the api when available. But it can also be deactivated with config.useNative + * @return {Object} The SubtleCrypto api or 'undefined' */ - getWebCrypto: function() { - if (config.useWebCrypto === false) { - // make web crypto optional + getWebCrypto: function getWebCrypto() { + if (!_config2.default.useNative) { return; } @@ -16495,10 +19031,78 @@ module.exports = { return window.msCrypto.subtle; } } + }, + + /** + * Wraps a generic synchronous function in an ES6 Promise. + * @param {Function} fn The function to be wrapped + * @return {Function} The function wrapped in a Promise + */ + promisify: function promisify(fn) { + return function () { + var args = arguments; + return new Promise(function (resolve) { + var result = fn.apply(null, args); + resolve(result); + }); + }; + }, + + /** + * Converts an IE11 web crypro api result to a promise. + * This is required since IE11 implements an old version of the + * Web Crypto specification that does not use promises. + * @param {Object} cryptoOp The return value of an IE11 web cryptro api call + * @param {String} errmsg An error message for a specific operation + * @return {Promise} The resulting Promise + */ + promisifyIE11Op: function promisifyIE11Op(cryptoOp, errmsg) { + return new Promise(function (resolve, reject) { + cryptoOp.onerror = function () { + reject(new Error(errmsg)); + }; + cryptoOp.oncomplete = function (e) { + resolve(e.target.result); + }; + }); + }, + + /** + * Detect Node.js runtime. + */ + detectNode: function detectNode() { + return typeof window === 'undefined'; + }, + + /** + * Get native Node.js crypto api. The default configuration is to use + * the api when available. But it can also be deactivated with config.useNative + * @return {Object} The crypto module or 'undefined' + */ + getNodeCrypto: function getNodeCrypto() { + if (!this.detectNode() || !_config2.default.useNative) { + return; + } + + return require('crypto'); + }, + + /** + * Get native Node.js Buffer constructor. This should be used since + * Buffer is not available under browserify. + * @return {Function} The Buffer constructor or 'undefined' + */ + getNodeBuffer: function getNodeBuffer() { + if (!this.detectNode()) { + return; + } + + return require('buffer').Buffer; } + }; -},{"./config":17}],77:[function(require,module,exports){ +},{"./config":19,"buffer":"buffer","crypto":"crypto"}],77:[function(require,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -16516,73 +19120,64 @@ module.exports = { // 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 crypto - * @requires enums - * @requires packet - * @requires type_keyid - * @requires key - * @module async_proxy - */ - 'use strict'; -var crypto = require('../crypto'), - packet = require('../packet'), - key = require('../key.js'), - type_keyid = require('../type/keyid.js'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = AsyncProxy; -var INITIAL_RANDOM_SEED = 50000, // random bytes seeded to worker - RANDOM_SEED_REQUEST = 20000; // random bytes seeded after worker request +var _util = require('../util.js'); + +var _util2 = _interopRequireDefault(_util); + +var _crypto = require('../crypto'); + +var _crypto2 = _interopRequireDefault(_crypto); + +var _packet = require('../packet'); + +var _packet2 = _interopRequireDefault(_packet); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var INITIAL_RANDOM_SEED = 50000, + // random bytes seeded to worker +RANDOM_SEED_REQUEST = 20000; // random bytes seeded after worker request /** * Initializes a new proxy and loads the web worker * @constructor - * @param {String} path The path to the worker or 'openpgp.worker.js' by default - * @param {Object} [options.config=Object] config The worker configuration - * @param {Object} [options.worker=Object] alternative to path parameter: - * web worker initialized with 'openpgp.worker.js' + * @param {String} path The path to the worker or 'openpgp.worker.js' by default + * @param {Object} config config The worker configuration + * @param {Object} worker alternative to path parameter: web worker initialized with 'openpgp.worker.js' + * @return {Promise} */ -function AsyncProxy(path, options) { - if (options && options.worker) { - this.worker = options.worker; - } else { - this.worker = new Worker(path || 'openpgp.worker.js'); - } +function AsyncProxy() { + var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + var _ref$path = _ref.path; + var path = _ref$path === undefined ? 'openpgp.worker.js' : _ref$path; + var worker = _ref.worker; + var config = _ref.config; + + this.worker = worker || new Worker(path); this.worker.onmessage = this.onMessage.bind(this); - this.worker.onerror = function(e) { + this.worker.onerror = function (e) { throw new Error('Unhandled error in openpgp worker: ' + e.message + ' (' + e.filename + ':' + e.lineno + ')'); }; this.seedRandom(INITIAL_RANDOM_SEED); // FIFO this.tasks = []; - if (options && options.config) { - this.worker.postMessage({event: 'configure', config: options.config}); + if (config) { + this.worker.postMessage({ event: 'configure', config: config }); } } -/** - * Command pattern that wraps synchronous code into a promise - * @param {Object} self The current this - * @param {function} cmd The synchronous function with a return value - * to be wrapped in a promise - * @return {Promise} The promise wrapped around cmd - */ -AsyncProxy.prototype.execute = function(cmd) { - var self = this; - - var promise = new Promise(function(resolve, reject) { - cmd(); - self.tasks.push({ resolve:resolve, reject:reject }); - }); - - return promise; -}; - /** * Message handling */ -AsyncProxy.prototype.onMessage = function(event) { +AsyncProxy.prototype.onMessage = function (event) { var msg = event.data; switch (msg.event) { case 'method-return': @@ -16606,9 +19201,9 @@ AsyncProxy.prototype.onMessage = function(event) { * Send message to worker with random data * @param {Integer} size Number of bytes to send */ -AsyncProxy.prototype.seedRandom = function(size) { +AsyncProxy.prototype.seedRandom = function (size) { var buf = this.getRandomBuffer(size); - this.worker.postMessage({event: 'seed-random', buf: buf}); + this.worker.postMessage({ event: 'seed-random', buf: buf }, _util2.default.getTransferables.call(_util2.default, buf)); }; /** @@ -16616,262 +19211,41 @@ AsyncProxy.prototype.seedRandom = function(size) { * @param {Integer} size Length of buffer * @return {Uint8Array} */ -AsyncProxy.prototype.getRandomBuffer = function(size) { - if (!size) return null; +AsyncProxy.prototype.getRandomBuffer = function (size) { + if (!size) { + return null; + } var buf = new Uint8Array(size); - crypto.random.getRandomValues(buf); + _crypto2.default.random.getRandomValues(buf); return buf; }; /** * Terminates the worker */ -AsyncProxy.prototype.terminate = function() { +AsyncProxy.prototype.terminate = function () { this.worker.terminate(); }; /** - * Encrypts message text with keys - * @param {(Array|module:key~Key)} keys array of keys or single key, used to encrypt the message - * @param {String} text message as native JavaScript string + * Generic proxy function that handles all commands from the public api. + * @param {String} method the public api function to be delegated to the worker thread + * @param {Object} options the api function's options + * @return {Promise} see the corresponding public api functions for their return types */ -AsyncProxy.prototype.encryptMessage = function(keys, text) { - var self = this; +AsyncProxy.prototype.delegate = function (method, options) { + var _this = this; - return self.execute(function() { - if (!keys.length) { - keys = [keys]; - } - keys = keys.map(function(key) { - return key.toPacketlist(); - }); - self.worker.postMessage({ - event: 'encrypt-message', - keys: keys, - text: text - }); + return new Promise(function (_resolve, reject) { + // clone packets (for web worker structured cloning algorithm) + _this.worker.postMessage({ event: method, options: _packet2.default.clone.clonePackets(options) }, _util2.default.getTransferables.call(_util2.default, options)); + + // remember to handle parsing cloned packets from worker + _this.tasks.push({ resolve: function resolve(data) { + return _resolve(_packet2.default.clone.parseClonedPackets(data, method)); + }, reject: reject }); }); }; -/** - * Signs message text and encrypts it - * @param {(Array|module:key~Key)} publicKeys array of keys or single key, used to encrypt the message - * @param {module:key~Key} privateKey private key with decrypted secret key data for signing - * @param {String} text message as native JavaScript string - */ -AsyncProxy.prototype.signAndEncryptMessage = function(publicKeys, privateKey, text) { - var self = this; - - return self.execute(function() { - if (!publicKeys.length) { - publicKeys = [publicKeys]; - } - publicKeys = publicKeys.map(function(key) { - return key.toPacketlist(); - }); - privateKey = privateKey.toPacketlist(); - self.worker.postMessage({ - event: 'sign-and-encrypt-message', - publicKeys: publicKeys, - privateKey: privateKey, - text: text - }); - }); -}; - -/** - * Decrypts message - * @param {module:key~Key} privateKey private key with decrypted secret key data - * @param {module:message~Message} message the message object with the encrypted data - */ -AsyncProxy.prototype.decryptMessage = function(privateKey, message) { - var self = this; - - return self.execute(function() { - privateKey = privateKey.toPacketlist(); - self.worker.postMessage({ - event: 'decrypt-message', - privateKey: privateKey, - message: message - }); - }); -}; - -/** - * Decrypts message and verifies signatures - * @param {module:key~Key} privateKey private key with decrypted secret key data - * @param {(Array|module:key~Key)} publicKeys array of keys or single key to verify signatures - * @param {module:message~Message} message the message object with signed and encrypted data - */ -AsyncProxy.prototype.decryptAndVerifyMessage = function(privateKey, publicKeys, message) { - var self = this; - - var promise = new Promise(function(resolve, reject) { - privateKey = privateKey.toPacketlist(); - if (!publicKeys.length) { - publicKeys = [publicKeys]; - } - publicKeys = publicKeys.map(function(key) { - return key.toPacketlist(); - }); - self.worker.postMessage({ - event: 'decrypt-and-verify-message', - privateKey: privateKey, - publicKeys: publicKeys, - message: message - }); - - self.tasks.push({ resolve:function(data) { - data.signatures = data.signatures.map(function(sig) { - sig.keyid = type_keyid.fromClone(sig.keyid); - return sig; - }); - resolve(data); - }, reject:reject }); - }); - - return promise; -}; - -/** - * Signs a cleartext message - * @param {(Array|module:key~Key)} privateKeys array of keys or single key, with decrypted secret key data to sign cleartext - * @param {String} text cleartext - */ -AsyncProxy.prototype.signClearMessage = function(privateKeys, text) { - var self = this; - - return self.execute(function() { - if (!privateKeys.length) { - privateKeys = [privateKeys]; - } - privateKeys = privateKeys.map(function(key) { - return key.toPacketlist(); - }); - self.worker.postMessage({ - event: 'sign-clear-message', - privateKeys: privateKeys, - text: text - }); - }); -}; - -/** - * Verifies signatures of cleartext signed message - * @param {(Array|module:key~Key)} publicKeys array of keys or single key, to verify signatures - * @param {module:cleartext~CleartextMessage} message cleartext message object with signatures - */ -AsyncProxy.prototype.verifyClearSignedMessage = function(publicKeys, message) { - var self = this; - - var promise = new Promise(function(resolve, reject) { - if (!publicKeys.length) { - publicKeys = [publicKeys]; - } - publicKeys = publicKeys.map(function(key) { - return key.toPacketlist(); - }); - self.worker.postMessage({ - event: 'verify-clear-signed-message', - publicKeys: publicKeys, - message: message - }); - - self.tasks.push({ resolve:function(data) { - data.signatures = data.signatures.map(function(sig) { - sig.keyid = type_keyid.fromClone(sig.keyid); - return sig; - }); - resolve(data); - }, reject:reject }); - }); - - return promise; -}; - -/** - * Generates a new OpenPGP key pair. Currently only supports RSA keys. - * Primary and subkey will be of same type. - * @param {module:enums.publicKey} keyType to indicate what type of key to make. - * RSA is 1. See {@link http://tools.ietf.org/html/rfc4880#section-9.1} - * @param {Integer} numBits number of bits for the key creation. (should be 1024+, generally) - * @param {String} userId assumes already in form of "User Name " - * @param {String} passphrase The passphrase used to encrypt the resulting private key - */ -AsyncProxy.prototype.generateKeyPair = function(options) { - var self = this; - - var promise = new Promise(function(resolve, reject) { - self.worker.postMessage({ - event: 'generate-key-pair', - options: options - }); - - self.tasks.push({ resolve:function(data) { - var packetlist = packet.List.fromStructuredClone(data.key); - data.key = new key.Key(packetlist); - resolve(data); - }, reject:reject }); - }); - - return promise; -}; - -/** - * Decrypts secret part of all secret key packets of key. - * @param {module:key~Key} privateKey private key with encrypted secret key data - * @param {String} password password to unlock the key - */ -AsyncProxy.prototype.decryptKey = function(privateKey, password) { - var self = this; - - var promise = new Promise(function(resolve, reject) { - privateKey = privateKey.toPacketlist(); - self.worker.postMessage({ - event: 'decrypt-key', - privateKey: privateKey, - password: password - }); - - self.tasks.push({ resolve:function(data) { - var packetlist = packet.List.fromStructuredClone(data), - data = new key.Key(packetlist); - resolve(data); - }, reject:reject }); - }); - - return promise; -}; - -/** - * Decrypts secret part of key packets matching array of keyids. - * @param {module:key~Key} privateKey private key with encrypted secret key data - * @param {Array} keyIds - * @param {String} password password to unlock the key - */ -AsyncProxy.prototype.decryptKeyPacket = function(privateKey, keyIds, password) { - var self = this; - - var promise = new Promise(function(resolve, reject) { - privateKey = privateKey.toPacketlist(); - self.worker.postMessage({ - event: 'decrypt-key-packet', - privateKey: privateKey, - keyIds: keyIds, - password: password - }); - - self.tasks.push({ resolve:function(data) { - var packetlist = packet.List.fromStructuredClone(data), - data = new key.Key(packetlist); - resolve(data); - }, reject:reject }); - }); - - return promise; -}; - -module.exports = AsyncProxy; - -},{"../crypto":32,"../key.js":47,"../packet":55,"../type/keyid.js":73}]},{},[46])(46) +},{"../crypto":32,"../packet":55,"../util.js":76}]},{},[45])(45) }); \ No newline at end of file diff --git a/dist/openpgp.min.js b/dist/openpgp.min.js index f29e3934..260e6487 100644 --- a/dist/openpgp.min.js +++ b/dist/openpgp.min.js @@ -1,8 +1,10 @@ -/*! OpenPGPjs.org this is LGPL licensed code, see LICENSE/our website for more information.- v1.5.7 - 2016-01-31 */!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.openpgp=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g1)for(var c=1;cb;++b)e[b]=c[b];return a.buffer=e}function d(a){this.buffer=new(o?Uint16Array:Array)(2*a),this.length=0}function e(a,b){this.e=w,this.f=0,this.input=o&&a instanceof Array?new Uint8Array(a):a,this.c=0,b&&(b.lazy&&(this.f=b.lazy),"number"==typeof b.compressionType&&(this.e=b.compressionType),b.outputBuffer&&(this.b=o&&b.outputBuffer instanceof Array?new Uint8Array(b.outputBuffer):b.outputBuffer),"number"==typeof b.outputIndex&&(this.c=b.outputIndex)),this.b||(this.b=new(o?Uint8Array:Array)(32768))}function f(a,b){this.length=a,this.g=b}function g(a,b){function c(a,b){var c,d=a.g,e=[],f=0;c=z[a.length],e[f++]=65535&c,e[f++]=c>>16&255,e[f++]=c>>24;var g;switch(m){case 1===d:g=[0,d-1,0];break;case 2===d:g=[1,d-2,0];break;case 3===d:g=[2,d-3,0];break;case 4===d:g=[3,d-4,0];break;case 6>=d:g=[4,d-5,1];break;case 8>=d:g=[5,d-7,1];break;case 12>=d:g=[6,d-9,2];break;case 16>=d:g=[7,d-13,2];break;case 24>=d:g=[8,d-17,3];break;case 32>=d:g=[9,d-25,3];break;case 48>=d:g=[10,d-33,4];break;case 64>=d:g=[11,d-49,4];break;case 96>=d:g=[12,d-65,5];break;case 128>=d:g=[13,d-97,5];break;case 192>=d:g=[14,d-129,6];break;case 256>=d:g=[15,d-193,6];break;case 384>=d:g=[16,d-257,7];break;case 512>=d:g=[17,d-385,7];break;case 768>=d:g=[18,d-513,8];break;case 1024>=d:g=[19,d-769,8];break;case 1536>=d:g=[20,d-1025,9];break;case 2048>=d:g=[21,d-1537,9];break;case 3072>=d:g=[22,d-2049,10];break;case 4096>=d:g=[23,d-3073,10];break;case 6144>=d:g=[24,d-4097,11];break;case 8192>=d:g=[25,d-6145,11];break;case 12288>=d:g=[26,d-8193,12];break;case 16384>=d:g=[27,d-12289,12];break;case 24576>=d:g=[28,d-16385,13];break;case 32768>=d:g=[29,d-24577,13];break;default:throw"invalid distance"}c=g,e[f++]=c[0],e[f++]=c[1],e[f++]=c[2];var h,i;for(h=0,i=e.length;i>h;++h)r[s++]=e[h];u[e[0]]++,v[e[3]]++,t=a.length+b-1,n=null}var d,e,f,g,i,j,k,n,p,q={},r=o?new Uint16Array(2*b.length):[],s=0,t=0,u=new(o?Uint32Array:Array)(286),v=new(o?Uint32Array:Array)(30),w=a.f;if(!o){for(f=0;285>=f;)u[f++]=0;for(f=0;29>=f;)v[f++]=0}for(u[256]=1,d=0,e=b.length;e>d;++d){for(f=i=0,g=3;g>f&&d+f!==e;++f)i=i<<8|b[d+f];if(q[i]===l&&(q[i]=[]),j=q[i],!(0=e){for(n&&c(n,-1),f=0,g=e-d;g>f;++f)p=b[d+f],r[s++]=p,++u[p];break}0h;h++){if(d=c[j-h-1],g=3,k>3){for(i=k;i>3;i--)if(a[d+i-1]!==a[b+i-1])continue a;g=k}for(;258>g&&l>b+g&&a[d+g]===a[b+g];)++g;if(g>k&&(e=d,k=g),258===g)break}return new f(k,b-e)}function i(a,b){var c,e,f,g,h,i=a.length,k=new d(572),l=new(o?Uint8Array:Array)(i);if(!o)for(g=0;i>g;g++)l[g]=0;for(g=0;i>g;++g)0g;++g)c[g]=k.pop(),e[g]=c[g].value;for(f=j(e,e.length,b),g=0,h=c.length;h>g;++g)l[c[g].index]=f[g];return l}function j(a,b,c){function d(a){var c=n[a][p[a]];c===b?(d(a+1),d(a+1)):--l[c],++p[a]}var e,f,g,h,i,j=new(o?Uint16Array:Array)(c),k=new(o?Uint8Array:Array)(c),l=new(o?Uint8Array:Array)(b),m=Array(c),n=Array(c),p=Array(c),q=(1<f;++f)r>q?k[f]=0:(k[f]=1,q-=r),q<<=1,j[c-2-f]=(j[c-1-f]/2|0)+b;for(j[0]=k[0],m[0]=Array(j[0]),n[0]=Array(j[0]),f=1;c>f;++f)j[f]>2*j[f-1]+k[f]&&(j[f]=2*j[f-1]+k[f]),m[f]=Array(j[f]),n[f]=Array(j[f]);for(e=0;b>e;++e)l[e]=c;for(g=0;ge;++e)p[e]=0;for(1===k[c-1]&&(--l[0],++p[c-1]),f=c-2;f>=0;--f){for(h=e=0,i=p[f+1],g=0;ga[e]?(m[f][g]=h,n[f][g]=b,i+=2):(m[f][g]=a[e],n[f][g]=e,++e);p[f]=0,1===k[f]&&d(f)}return l}function k(a){var b,c,d,e,f=new(o?Uint16Array:Array)(a.length),g=[],h=[],i=0;for(b=0,c=a.length;c>b;b++)g[a[b]]=(0|g[a[b]])+1;for(b=1,c=16;c>=b;b++)h[b]=i,i+=0|g[b],i<<=1;for(b=0,c=a.length;c>b;b++)for(i=h[a[b]],h[a[b]]+=1,d=f[b]=0,e=a[b];e>d;d++)f[b]=f[b]<<1|1&i,i>>>=1;return f}var l=void 0,m=!0,n=this,o="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;b.prototype.a=function(a,b,d){var e,f=this.buffer,g=this.index,h=this.d,i=f[g];if(d&&b>1&&(a=b>8?(u[255&a]<<24|u[a>>>8&255]<<16|u[a>>>16&255]<<8|u[a>>>24&255])>>32-b:u[a]>>8-b),8>b+h)i=i<e;++e)i=i<<1|a>>b-e-1&1,8===++h&&(h=0,f[g++]=u[i],i=0,g===f.length&&(f=c(this)));f[g]=i,this.buffer=f,this.d=h,this.index=g},b.prototype.finish=function(){var a,b=this.buffer,c=this.index;return 0p;++p){for(var r=p,s=r,t=7,r=r>>>1;r;r>>>=1)s<<=1,s|=1&r,--t;q[p]=(s<>>0}var u=q;d.prototype.getParent=function(a){return 2*((a-2)/4|0)},d.prototype.push=function(a,b){var c,d,e,f=this.buffer;for(c=this.length,f[this.length++]=b,f[this.length++]=a;c>0&&(d=this.getParent(c),f[c]>f[d]);)e=f[c],f[c]=f[d],f[d]=e,e=f[c+1],f[c+1]=f[d+1],f[d+1]=e,c=d;return this.length},d.prototype.pop=function(){var a,b,c,d,e,f=this.buffer;for(b=f[0],a=f[1],this.length-=2,f[0]=f[this.length],f[1]=f[this.length+1],e=0;(d=2*e+2,!(d>=this.length))&&(d+2f[d]&&(d+=2),f[d]>f[e]);)c=f[e],f[e]=f[d],f[d]=c,c=f[e+1],f[e+1]=f[d+1],f[d+1]=c,e=d;return{index:a,value:b,length:this.length}};var v,w=2,x=[];for(v=0;288>v;v++)switch(m){case 143>=v:x.push([v+48,8]);break;case 255>=v:x.push([v-144+400,9]);break;case 279>=v:x.push([v-256+0,7]);break;case 287>=v:x.push([v-280+192,8]);break;default:throw"invalid literal: "+v}e.prototype.h=function(){var a,c,d,e,f=this.input;switch(this.e){case 0:for(d=0,e=f.length;e>d;){c=o?f.subarray(d,d+65535):f.slice(d,d+65535),d+=c.length;var h=c,j=d===e,n=l,p=l,q=l,r=l,s=l,t=this.b,u=this.c;if(o){for(t=new Uint8Array(this.b.buffer);t.length<=u+h.length+5;)t=new Uint8Array(t.length<<1);t.set(this.b)}if(n=j?1:0,t[u++]=0|n,p=h.length,q=~p+65536&65535,t[u++]=255&p,t[u++]=p>>>8&255,t[u++]=255&q,t[u++]=q>>>8&255,o)t.set(h,u),u+=h.length,t=t.subarray(0,u);else{for(r=0,s=h.length;s>r;++r)t[u++]=h[r];t.length=u}this.c=u,this.b=t}break;case 1:var v=new b(o?new Uint8Array(this.b.buffer):this.b,this.c);v.a(1,1,m),v.a(1,2,m);var y,z,A,B=g(this,f);for(y=0,z=B.length;z>y;y++)if(A=B[y],b.prototype.a.apply(v,x[A]),A>256)v.a(B[++y],B[++y],m),v.a(B[++y],5),v.a(B[++y],B[++y],m);else if(256===A)break;this.b=v.finish(),this.c=this.b.length;break;case w:var C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R=new b(o?new Uint8Array(this.b.buffer):this.b,this.c),S=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],T=Array(19);for(C=w,R.a(1,1,m),R.a(C,2,m),D=g(this,f),H=i(this.j,15),I=k(H),J=i(this.i,7),K=k(J),E=286;E>257&&0===H[E-1];E--);for(F=30;F>1&&0===J[F-1];F--);var U,V,W,X,Y,Z,$=E,_=F,aa=new(o?Uint32Array:Array)($+_),ba=new(o?Uint32Array:Array)(316),ca=new(o?Uint8Array:Array)(19);for(U=V=0;$>U;U++)aa[V++]=H[U];for(U=0;_>U;U++)aa[V++]=J[U];if(!o)for(U=0,X=ca.length;X>U;++U)ca[U]=0;for(U=Y=0,X=aa.length;X>U;U+=V){for(V=1;X>U+V&&aa[U+V]===aa[U];++V);if(W=V,0===aa[U])if(3>W)for(;00;)Z=138>W?W:138,Z>W-3&&W>Z&&(Z=W-3),10>=Z?(ba[Y++]=17,ba[Y++]=Z-3,ca[17]++):(ba[Y++]=18,ba[Y++]=Z-11,ca[18]++),W-=Z;else if(ba[Y++]=aa[U],ca[aa[U]]++,W--,3>W)for(;00;)Z=6>W?W:6,Z>W-3&&W>Z&&(Z=W-3),ba[Y++]=16,ba[Y++]=Z-3,ca[16]++,W-=Z}for(a=o?ba.subarray(0,Y):ba.slice(0,Y),L=i(ca,7),P=0;19>P;P++)T[P]=L[S[P]];for(G=19;G>4&&0===T[G-1];G--);for(M=k(L),R.a(E-257,5,m),R.a(F-1,5,m),R.a(G-4,4,m),P=0;G>P;P++)R.a(T[P],3,m);for(P=0,Q=a.length;Q>P;P++)if(N=a[P],R.a(M[N],L[N],m),N>=16){switch(P++,N){case 16:O=2;break;case 17:O=3;break;case 18:O=7;break;default:throw"invalid code: "+N}R.a(a[P],O,m)}var da,ea,fa,ga,ha,ia,ja,ka,la=[I,H],ma=[K,J];for(ha=la[0],ia=la[1],ja=ma[0],ka=ma[1],da=0,ea=D.length;ea>da;++da)if(fa=D[da],R.a(ha[fa],ia[fa],m),fa>256)R.a(D[++da],D[++da],m),ga=D[++da],R.a(ja[ga],ka[ga],m),R.a(D[++da],D[++da],m);else if(256===fa)break;this.b=R.finish(),this.c=this.b.length;break;default:throw"invalid compression type"}return this.b};var y=function(){function a(a){switch(m){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=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 b,c,d=[];for(b=3;258>=b;b++)c=a(b),d[b]=c[2]<<24|c[1]<<16|c[0];return d}(),z=o?new Uint32Array(y):y;a("Zlib.RawDeflate",e),a("Zlib.RawDeflate.prototype.compress",e.prototype.h);var A,B,C,D,E={NONE:0,FIXED:1,DYNAMIC:w};if(Object.keys)A=Object.keys(E);else for(B in A=[],C=0,E)A[C++]=B;for(C=0,D=A.length;D>C;++C)B=A[C],a("Zlib.RawDeflate.CompressionType."+B,E[B])}).call(this)},{}],14:[function(a,b,c){(function(){"use strict";function a(a,b){var c=a.split("."),d=g;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)c.length||void 0===b?d=d[e]?d[e]:d[e]={}:d[e]=b}function b(a){var b,c,d,e,f,g,i,j,k,l,m=a.length,n=0,o=Number.POSITIVE_INFINITY;for(j=0;m>j;++j)a[j]>n&&(n=a[j]),a[j]=d;){for(j=0;m>j;++j)if(a[j]===d){for(g=0,i=e,k=0;d>k;++k)g=g<<1|1&i,i>>=1;for(l=d<<16|j,k=g;b>k;k+=f)c[k]=l;++e}++d,e<<=1,f<<=1}return[c,n,o]}function c(a,b){switch(this.g=[],this.h=32768,this.c=this.f=this.d=this.k=0,this.input=h?new Uint8Array(a):a,this.l=!1,this.i=j,this.q=!1,(b||!(b={}))&&(b.index&&(this.d=b.index),b.bufferSize&&(this.h=b.bufferSize),b.bufferType&&(this.i=b.bufferType),b.resize&&(this.q=b.resize)),this.i){case i:this.a=32768,this.b=new(h?Uint8Array:Array)(32768+this.h+258);break;case j:this.a=0,this.b=new(h?Uint8Array:Array)(this.h),this.e=this.v,this.m=this.s,this.j=this.t;break;default:throw Error("invalid inflate mode")}}function d(a,b){for(var c,d=a.f,e=a.c,f=a.input,g=a.d,h=f.length;b>e;){if(g>=h)throw Error("input buffer is broken");d|=f[g++]<>>b,a.c=e-b,a.d=g,c}function e(a,b){for(var c,d,e=a.f,f=a.c,g=a.input,h=a.d,i=g.length,j=b[0],k=b[1];k>f&&!(h>=i);)e|=g[h++]<>>16,a.f=e>>d,a.c=f-d,a.d=h,65535&c}function f(a){function c(a,b,c){var f,g,h,i=this.p;for(h=0;a>h;)switch(f=e(this,b)){case 16:for(g=3+d(this,2);g--;)c[h++]=i;break;case 17:for(g=3+d(this,3);g--;)c[h++]=0;i=0;break;case 18:for(g=11+d(this,7);g--;)c[h++]=0;i=0;break;default:i=c[h++]=f}return this.p=i,c}var f,g,i,j,k=d(a,5)+257,l=d(a,5)+1,m=d(a,4)+4,o=new(h?Uint8Array:Array)(n.length);for(j=0;m>j;++j)o[n[j]]=d(a,3);if(!h)for(j=m,m=o.length;m>j;++j)o[n[j]]=0;f=b(o),g=new(h?Uint8Array:Array)(k),i=new(h?Uint8Array:Array)(l),a.p=0,a.j(b(c.call(a,k,f,g)),b(c.call(a,l,f,i)))}var g=this,h="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView,i=0,j=1;c.prototype.u=function(){for(;!this.l;){var a=d(this,3);switch(1&a&&(this.l=!0),a>>>=1){case 0:var b=this.input,c=this.d,e=this.b,g=this.a,k=b.length,l=void 0,m=void 0,n=e.length,o=void 0;if(this.c=this.f=0,c+1>=k)throw Error("invalid uncompressed block header: LEN");if(l=b[c++]|b[c++]<<8,c+1>=k)throw Error("invalid uncompressed block header: NLEN");if(m=b[c++]|b[c++]<<8,l===~m)throw Error("invalid uncompressed block header: length verify");if(c+l>b.length)throw Error("input buffer is broken");switch(this.i){case i:for(;g+l>e.length;){if(o=n-g,l-=o,h)e.set(b.subarray(c,c+o),g),g+=o,c+=o;else for(;o--;)e[g++]=b[c++];this.a=g,e=this.e(),g=this.a}break;case j:for(;g+l>e.length;)e=this.e({o:2});break;default:throw Error("invalid inflate mode")}if(h)e.set(b.subarray(c,c+l),g),g+=l,c+=l;else for(;l--;)e[g++]=b[c++];this.d=c,this.a=g,this.b=e;break;case 1:this.j(z,B);break;case 2:f(this);break;default:throw Error("unknown BTYPE: "+a)}}return this.m()};var k,l,m=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],n=h?new Uint16Array(m):m,o=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],p=h?new Uint16Array(o):o,q=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],r=h?new Uint8Array(q):q,s=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],t=h?new Uint16Array(s):s,u=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],v=h?new Uint8Array(u):u,w=new(h?Uint8Array:Array)(288);for(k=0,l=w.length;l>k;++k)w[k]=143>=k?8:255>=k?9:279>=k?7:8;var x,y,z=b(w),A=new(h?Uint8Array:Array)(30);for(x=0,y=A.length;y>x;++x)A[x]=5;var B=b(A);c.prototype.j=function(a,b){var c=this.b,f=this.a;this.n=a;for(var g,h,i,j,k=c.length-258;256!==(g=e(this,a));)if(256>g)f>=k&&(this.a=f,c=this.e(),f=this.a),c[f++]=g;else for(h=g-257,j=p[h],0=k&&(this.a=f,c=this.e(),f=this.a);j--;)c[f]=c[f++-i];for(;8<=this.c;)this.c-=8,this.d--;this.a=f},c.prototype.t=function(a,b){var c=this.b,f=this.a;this.n=a;for(var g,h,i,j,k=c.length;256!==(g=e(this,a));)if(256>g)f>=k&&(c=this.e(),k=c.length),c[f++]=g;else for(h=g-257,j=p[h],0k&&(c=this.e(),k=c.length);j--;)c[f]=c[f++-i];for(;8<=this.c;)this.c-=8,this.d--;this.a=f},c.prototype.e=function(){var a,b,c=new(h?Uint8Array:Array)(this.a-32768),d=this.a-32768,e=this.b;if(h)c.set(e.subarray(32768,c.length));else for(a=0,b=c.length;b>a;++a)c[a]=e[a+32768];if(this.g.push(c),this.k+=c.length,h)e.set(e.subarray(d,d+32768));else for(a=0;32768>a;++a)e[a]=e[d+a];return this.a=32768,e},c.prototype.v=function(a){var b,c,d,e,f=this.input.length/this.d+1|0,g=this.input,i=this.b;return a&&("number"==typeof a.o&&(f=a.o),"number"==typeof a.r&&(f+=a.r)),2>f?(c=(g.length-this.d)/this.n[2],e=258*(c/2)|0,d=eb;++b)for(a=i[b],d=0,e=a.length;e>d;++d)j[f++]=a[d];for(b=32768,c=this.a;c>b;++b)j[f++]=g[b];return this.g=[],this.buffer=j},c.prototype.s=function(){var a,b=this.a;return h?this.q?(a=new Uint8Array(b),a.set(this.b.subarray(0,b))):a=this.b.subarray(0,b):(this.b.length>b&&(this.b.length=b),a=this.b),this.buffer=a},a("Zlib.RawInflate",c),a("Zlib.RawInflate.prototype.decompress",c.prototype.u);var C,D,E,F,G={ADAPTIVE:j,BLOCK:i};if(Object.keys)C=Object.keys(G);else for(D in C=[],E=0,G)C[E++]=D;for(E=0,F=C.length;F>E;++E)D=C[E],a("Zlib.RawInflate.BufferType."+D,G[D])}).call(this)},{}],15:[function(a,b,c){(function(){"use strict";function a(a){throw a}function b(a,b){var c=a.split("."),d=w;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)c.length||b===u?d=d[e]?d[e]:d[e]={}:d[e]=b}function c(b,c){this.index="number"==typeof c?c:0,this.i=0,this.buffer=b instanceof(x?Uint8Array:Array)?b:new(x?Uint8Array:Array)(32768),2*this.buffer.length<=this.index&&a(Error("invalid index")),this.buffer.length<=this.index&&this.f()}function d(a){this.buffer=new(x?Uint16Array:Array)(2*a),this.length=0}function e(a){var b,c,d,e,f,g,h,i,j,k,l=a.length,m=0,n=Number.POSITIVE_INFINITY;for(i=0;l>i;++i)a[i]>m&&(m=a[i]),a[i]=d;){for(i=0;l>i;++i)if(a[i]===d){for(g=0,h=e,j=0;d>j;++j)g=g<<1|1&h,h>>=1;for(k=d<<16|i,j=g;b>j;j+=f)c[j]=k;++e}++d,e<<=1,f<<=1}return[c,m,n]}function f(a,b){this.h=F,this.w=0,this.input=x&&a instanceof Array?new Uint8Array(a):a,this.b=0,b&&(b.lazy&&(this.w=b.lazy),"number"==typeof b.compressionType&&(this.h=b.compressionType),b.outputBuffer&&(this.a=x&&b.outputBuffer instanceof Array?new Uint8Array(b.outputBuffer):b.outputBuffer),"number"==typeof b.outputIndex&&(this.b=b.outputIndex)),this.a||(this.a=new(x?Uint8Array:Array)(32768))}function g(a,b){this.length=a,this.H=b}function h(b,c){function d(b,c){var d,e=b.H,f=[],g=0;d=J[b.length],f[g++]=65535&d,f[g++]=d>>16&255,f[g++]=d>>24;var h;switch(v){case 1===e:h=[0,e-1,0];break;case 2===e:h=[1,e-2,0];break;case 3===e:h=[2,e-3,0];break;case 4===e:h=[3,e-4,0];break;case 6>=e:h=[4,e-5,1];break;case 8>=e:h=[5,e-7,1];break;case 12>=e:h=[6,e-9,2];break;case 16>=e:h=[7,e-13,2];break;case 24>=e:h=[8,e-17,3];break;case 32>=e:h=[9,e-25,3];break;case 48>=e:h=[10,e-33,4];break;case 64>=e:h=[11,e-49,4];break;case 96>=e:h=[12,e-65,5];break;case 128>=e:h=[13,e-97,5];break;case 192>=e:h=[14,e-129,6];break;case 256>=e:h=[15,e-193,6];break;case 384>=e:h=[16,e-257,7];break;case 512>=e:h=[17,e-385,7];break;case 768>=e:h=[18,e-513,8];break;case 1024>=e:h=[19,e-769,8];break;case 1536>=e:h=[20,e-1025,9];break;case 2048>=e:h=[21,e-1537,9];break;case 3072>=e:h=[22,e-2049,10];break;case 4096>=e:h=[23,e-3073,10];break;case 6144>=e:h=[24,e-4097,11];break;case 8192>=e:h=[25,e-6145,11];break;case 12288>=e:h=[26,e-8193,12];break;case 16384>=e:h=[27,e-12289,12];break;case 24576>=e:h=[28,e-16385,13];break;case 32768>=e:h=[29,e-24577,13];break;default:a("invalid distance")}d=h,f[g++]=d[0],f[g++]=d[1],f[g++]=d[2];var i,j;for(i=0,j=f.length;j>i;++i)p[q++]=f[i];s[f[0]]++,t[f[3]]++,r=b.length+c-1,m=null}var e,f,g,h,j,k,l,m,n,o={},p=x?new Uint16Array(2*c.length):[],q=0,r=0,s=new(x?Uint32Array:Array)(286),t=new(x?Uint32Array:Array)(30),w=b.w;if(!x){for(g=0;285>=g;)s[g++]=0;for(g=0;29>=g;)t[g++]=0}for(s[256]=1,e=0,f=c.length;f>e;++e){for(g=j=0,h=3;h>g&&e+g!==f;++g)j=j<<8|c[e+g];if(o[j]===u&&(o[j]=[]),k=o[j],!(0=f){for(m&&d(m,-1),g=0,h=f-e;h>g;++g)n=c[e+g],p[q++]=n,++s[n];break}0h;h++){if(d=c[j-h-1],f=3,k>3){for(i=k;i>3;i--)if(a[d+i-1]!==a[b+i-1])continue a;f=k}for(;258>f&&l>b+f&&a[d+f]===a[b+f];)++f;if(f>k&&(e=d,k=f),258===f)break}return new g(k,b-e)}function j(a,b){var c,e,f,g,h,i=a.length,j=new d(572),l=new(x?Uint8Array:Array)(i);if(!x)for(g=0;i>g;g++)l[g]=0;for(g=0;i>g;++g)0g;++g)c[g]=j.pop(),e[g]=c[g].value;for(f=k(e,e.length,b),g=0,h=c.length;h>g;++g)l[c[g].index]=f[g];return l}function k(a,b,c){function d(a){var c=n[a][o[a]];c===b?(d(a+1),d(a+1)):--l[c],++o[a]}var e,f,g,h,i,j=new(x?Uint16Array:Array)(c),k=new(x?Uint8Array:Array)(c),l=new(x?Uint8Array:Array)(b),m=Array(c),n=Array(c),o=Array(c),p=(1<f;++f)q>p?k[f]=0:(k[f]=1,p-=q),p<<=1,j[c-2-f]=(j[c-1-f]/2|0)+b;for(j[0]=k[0],m[0]=Array(j[0]),n[0]=Array(j[0]),f=1;c>f;++f)j[f]>2*j[f-1]+k[f]&&(j[f]=2*j[f-1]+k[f]),m[f]=Array(j[f]),n[f]=Array(j[f]);for(e=0;b>e;++e)l[e]=c;for(g=0;ge;++e)o[e]=0;for(1===k[c-1]&&(--l[0],++o[c-1]),f=c-2;f>=0;--f){for(h=e=0,i=o[f+1],g=0;ga[e]?(m[f][g]=h,n[f][g]=b,i+=2):(m[f][g]=a[e],n[f][g]=e,++e);o[f]=0,1===k[f]&&d(f)}return l}function l(a){var b,c,d,e,f=new(x?Uint16Array:Array)(a.length),g=[],h=[],i=0;for(b=0,c=a.length;c>b;b++)g[a[b]]=(0|g[a[b]])+1;for(b=1,c=16;c>=b;b++)h[b]=i,i+=0|g[b],i<<=1;for(b=0,c=a.length;c>b;b++)for(i=h[a[b]],h[a[b]]+=1,d=f[b]=0,e=a[b];e>d;d++)f[b]=f[b]<<1|1&i,i>>>=1;return f}function m(b,c){switch(this.l=[],this.m=32768,this.e=this.g=this.c=this.q=0,this.input=x?new Uint8Array(b):b,this.s=!1,this.n=L,this.C=!1,(c||!(c={}))&&(c.index&&(this.c=c.index),c.bufferSize&&(this.m=c.bufferSize),c.bufferType&&(this.n=c.bufferType),c.resize&&(this.C=c.resize)),this.n){case K:this.b=32768,this.a=new(x?Uint8Array:Array)(32768+this.m+258);break;case L:this.b=0,this.a=new(x?Uint8Array:Array)(this.m),this.f=this.K,this.t=this.I,this.o=this.J;break;default:a(Error("invalid inflate mode"))}}function n(b,c){for(var d,e=b.g,f=b.e,g=b.input,h=b.c,i=g.length;c>f;)h>=i&&a(Error("input buffer is broken")),e|=g[h++]<>>c,b.e=f-c,b.c=h,d}function o(a,b){for(var c,d,e=a.g,f=a.e,g=a.input,h=a.c,i=g.length,j=b[0],k=b[1];k>f&&!(h>=i);)e|=g[h++]<>>16,a.g=e>>d,a.e=f-d,a.c=h,65535&c}function p(a){function b(a,b,c){var d,e,f,g=this.z;for(f=0;a>f;)switch(d=o(this,b)){case 16:for(e=3+n(this,2);e--;)c[f++]=g;break;case 17:for(e=3+n(this,3);e--;)c[f++]=0;g=0;break;case 18:for(e=11+n(this,7);e--;)c[f++]=0;g=0;break;default:g=c[f++]=d}return this.z=g,c}var c,d,f,g,h=n(a,5)+257,i=n(a,5)+1,j=n(a,4)+4,k=new(x?Uint8Array:Array)(Q.length);for(g=0;j>g;++g)k[Q[g]]=n(a,3);if(!x)for(g=j,j=k.length;j>g;++g)k[Q[g]]=0;c=e(k),d=new(x?Uint8Array:Array)(h),f=new(x?Uint8Array:Array)(i),a.z=0,a.o(e(b.call(a,h,c,d)),e(b.call(a,i,c,f)))}function q(a){if("string"==typeof a){var b,c,d=a.split("");for(b=0,c=d.length;c>b;b++)d[b]=(255&d[b].charCodeAt(0))>>>0;a=d}for(var e,f=1,g=0,h=a.length,i=0;h>0;){e=h>1024?1024:h,h-=e;do f+=a[i++],g+=f;while(--e);f%=65521,g%=65521}return(g<<16|f)>>>0}function r(b,c){var d,e;switch(this.input=b,this.c=0,(c||!(c={}))&&(c.index&&(this.c=c.index),c.verify&&(this.N=c.verify)),d=b[this.c++],e=b[this.c++],15&d){case da:this.method=da;break;default:a(Error("unsupported compression method"))}0!==((d<<8)+e)%31&&a(Error("invalid fcheck flag:"+((d<<8)+e)%31)), -32&e&&a(Error("fdict flag is not supported")),this.B=new m(b,{index:this.c,bufferSize:c.bufferSize,bufferType:c.bufferType,resize:c.resize})}function s(a,b){this.input=a,this.a=new(x?Uint8Array:Array)(32768),this.h=ea.k;var c,d={};!b&&(b={})||"number"!=typeof b.compressionType||(this.h=b.compressionType);for(c in b)d[c]=b[c];d.outputBuffer=this.a,this.A=new f(this.input,d)}function t(a,c){var d,e,f,g;if(Object.keys)d=Object.keys(c);else for(e in d=[],f=0,c)d[f++]=e;for(f=0,g=d.length;g>f;++f)e=d[f],b(a+"."+e,c[e])}var u=void 0,v=!0,w=this,x="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;c.prototype.f=function(){var a,b=this.buffer,c=b.length,d=new(x?Uint8Array:Array)(c<<1);if(x)d.set(b);else for(a=0;c>a;++a)d[a]=b[a];return this.buffer=d},c.prototype.d=function(a,b,c){var d,e=this.buffer,f=this.index,g=this.i,h=e[f];if(c&&b>1&&(a=b>8?(D[255&a]<<24|D[a>>>8&255]<<16|D[a>>>16&255]<<8|D[a>>>24&255])>>32-b:D[a]>>8-b),8>b+g)h=h<d;++d)h=h<<1|a>>b-d-1&1,8===++g&&(g=0,e[f++]=D[h],h=0,f===e.length&&(e=this.f()));e[f]=h,this.buffer=e,this.i=g,this.index=f},c.prototype.finish=function(){var a,b=this.buffer,c=this.index;return 0y;++y){for(var A=y,B=A,C=7,A=A>>>1;A;A>>>=1)B<<=1,B|=1&A,--C;z[y]=(B<>>0}var D=z;d.prototype.getParent=function(a){return 2*((a-2)/4|0)},d.prototype.push=function(a,b){var c,d,e,f=this.buffer;for(c=this.length,f[this.length++]=b,f[this.length++]=a;c>0&&(d=this.getParent(c),f[c]>f[d]);)e=f[c],f[c]=f[d],f[d]=e,e=f[c+1],f[c+1]=f[d+1],f[d+1]=e,c=d;return this.length},d.prototype.pop=function(){var a,b,c,d,e,f=this.buffer;for(b=f[0],a=f[1],this.length-=2,f[0]=f[this.length],f[1]=f[this.length+1],e=0;(d=2*e+2,!(d>=this.length))&&(d+2f[d]&&(d+=2),f[d]>f[e]);)c=f[e],f[e]=f[d],f[d]=c,c=f[e+1],f[e+1]=f[d+1],f[d+1]=c,e=d;return{index:a,value:b,length:this.length}};var E,F=2,G={NONE:0,r:1,k:F,O:3},H=[];for(E=0;288>E;E++)switch(v){case 143>=E:H.push([E+48,8]);break;case 255>=E:H.push([E-144+400,9]);break;case 279>=E:H.push([E-256+0,7]);break;case 287>=E:H.push([E-280+192,8]);break;default:a("invalid literal: "+E)}f.prototype.j=function(){var b,d,e,f,g=this.input;switch(this.h){case 0:for(e=0,f=g.length;f>e;){d=x?g.subarray(e,e+65535):g.slice(e,e+65535),e+=d.length;var i=d,k=e===f,m=u,n=u,o=u,p=u,q=u,r=this.a,s=this.b;if(x){for(r=new Uint8Array(this.a.buffer);r.length<=s+i.length+5;)r=new Uint8Array(r.length<<1);r.set(this.a)}if(m=k?1:0,r[s++]=0|m,n=i.length,o=~n+65536&65535,r[s++]=255&n,r[s++]=n>>>8&255,r[s++]=255&o,r[s++]=o>>>8&255,x)r.set(i,s),s+=i.length,r=r.subarray(0,s);else{for(p=0,q=i.length;q>p;++p)r[s++]=i[p];r.length=s}this.b=s,this.a=r}break;case 1:var t=new c(x?new Uint8Array(this.a.buffer):this.a,this.b);t.d(1,1,v),t.d(1,2,v);var w,y,z,A=h(this,g);for(w=0,y=A.length;y>w;w++)if(z=A[w],c.prototype.d.apply(t,H[z]),z>256)t.d(A[++w],A[++w],v),t.d(A[++w],5),t.d(A[++w],A[++w],v);else if(256===z)break;this.a=t.finish(),this.b=this.a.length;break;case F:var B,C,D,E,G,I,J,K,L,M,N,O,P,Q,R,S=new c(x?new Uint8Array(this.a.buffer):this.a,this.b),T=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],U=Array(19);for(B=F,S.d(1,1,v),S.d(B,2,v),C=h(this,g),I=j(this.M,15),J=l(I),K=j(this.L,7),L=l(K),D=286;D>257&&0===I[D-1];D--);for(E=30;E>1&&0===K[E-1];E--);var V,W,X,Y,Z,$,_=D,aa=E,ba=new(x?Uint32Array:Array)(_+aa),ca=new(x?Uint32Array:Array)(316),da=new(x?Uint8Array:Array)(19);for(V=W=0;_>V;V++)ba[W++]=I[V];for(V=0;aa>V;V++)ba[W++]=K[V];if(!x)for(V=0,Y=da.length;Y>V;++V)da[V]=0;for(V=Z=0,Y=ba.length;Y>V;V+=W){for(W=1;Y>V+W&&ba[V+W]===ba[V];++W);if(X=W,0===ba[V])if(3>X)for(;00;)$=138>X?X:138,$>X-3&&X>$&&($=X-3),10>=$?(ca[Z++]=17,ca[Z++]=$-3,da[17]++):(ca[Z++]=18,ca[Z++]=$-11,da[18]++),X-=$;else if(ca[Z++]=ba[V],da[ba[V]]++,X--,3>X)for(;00;)$=6>X?X:6,$>X-3&&X>$&&($=X-3),ca[Z++]=16,ca[Z++]=$-3,da[16]++,X-=$}for(b=x?ca.subarray(0,Z):ca.slice(0,Z),M=j(da,7),Q=0;19>Q;Q++)U[Q]=M[T[Q]];for(G=19;G>4&&0===U[G-1];G--);for(N=l(M),S.d(D-257,5,v),S.d(E-1,5,v),S.d(G-4,4,v),Q=0;G>Q;Q++)S.d(U[Q],3,v);for(Q=0,R=b.length;R>Q;Q++)if(O=b[Q],S.d(N[O],M[O],v),O>=16){switch(Q++,O){case 16:P=2;break;case 17:P=3;break;case 18:P=7;break;default:a("invalid code: "+O)}S.d(b[Q],P,v)}var ea,fa,ga,ha,ia,ja,ka,la,ma=[J,I],na=[L,K];for(ia=ma[0],ja=ma[1],ka=na[0],la=na[1],ea=0,fa=C.length;fa>ea;++ea)if(ga=C[ea],S.d(ia[ga],ja[ga],v),ga>256)S.d(C[++ea],C[++ea],v),ha=C[++ea],S.d(ka[ha],la[ha],v),S.d(C[++ea],C[++ea],v);else if(256===ga)break;this.a=S.finish(),this.b=this.a.length;break;default:a("invalid compression type")}return this.a};var I=function(){function b(b){switch(v){case 3===b:return[257,b-3,0];case 4===b:return[258,b-4,0];case 5===b:return[259,b-5,0];case 6===b:return[260,b-6,0];case 7===b:return[261,b-7,0];case 8===b:return[262,b-8,0];case 9===b:return[263,b-9,0];case 10===b:return[264,b-10,0];case 12>=b:return[265,b-11,1];case 14>=b:return[266,b-13,1];case 16>=b:return[267,b-15,1];case 18>=b:return[268,b-17,1];case 22>=b:return[269,b-19,2];case 26>=b:return[270,b-23,2];case 30>=b:return[271,b-27,2];case 34>=b:return[272,b-31,2];case 42>=b:return[273,b-35,3];case 50>=b:return[274,b-43,3];case 58>=b:return[275,b-51,3];case 66>=b:return[276,b-59,3];case 82>=b:return[277,b-67,4];case 98>=b:return[278,b-83,4];case 114>=b:return[279,b-99,4];case 130>=b:return[280,b-115,4];case 162>=b:return[281,b-131,5];case 194>=b:return[282,b-163,5];case 226>=b:return[283,b-195,5];case 257>=b:return[284,b-227,5];case 258===b:return[285,b-258,0];default:a("invalid length: "+b)}}var c,d,e=[];for(c=3;258>=c;c++)d=b(c),e[c]=d[2]<<24|d[1]<<16|d[0];return e}(),J=x?new Uint32Array(I):I,K=0,L=1,M={F:K,D:L};m.prototype.p=function(){for(;!this.s;){var b=n(this,3);switch(1&b&&(this.s=v),b>>>=1){case 0:var c=this.input,d=this.c,e=this.a,f=this.b,g=c.length,h=u,i=u,j=e.length,k=u;switch(this.e=this.g=0,d+1>=g&&a(Error("invalid uncompressed block header: LEN")),h=c[d++]|c[d++]<<8,d+1>=g&&a(Error("invalid uncompressed block header: NLEN")),i=c[d++]|c[d++]<<8,h===~i&&a(Error("invalid uncompressed block header: length verify")),d+h>c.length&&a(Error("input buffer is broken")),this.n){case K:for(;f+h>e.length;){if(k=j-f,h-=k,x)e.set(c.subarray(d,d+k),f),f+=k,d+=k;else for(;k--;)e[f++]=c[d++];this.b=f,e=this.f(),f=this.b}break;case L:for(;f+h>e.length;)e=this.f({v:2});break;default:a(Error("invalid inflate mode"))}if(x)e.set(c.subarray(d,d+h),f),f+=h,d+=h;else for(;h--;)e[f++]=c[d++];this.c=d,this.b=f,this.a=e;break;case 1:this.o(aa,ca);break;case 2:p(this);break;default:a(Error("unknown BTYPE: "+b))}}return this.t()};var N,O,P=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Q=x?new Uint16Array(P):P,R=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],S=x?new Uint16Array(R):R,T=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],U=x?new Uint8Array(T):T,V=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],W=x?new Uint16Array(V):V,X=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Y=x?new Uint8Array(X):X,Z=new(x?Uint8Array:Array)(288);for(N=0,O=Z.length;O>N;++N)Z[N]=143>=N?8:255>=N?9:279>=N?7:8;var $,_,aa=e(Z),ba=new(x?Uint8Array:Array)(30);for($=0,_=ba.length;_>$;++$)ba[$]=5;var ca=e(ba);m.prototype.o=function(a,b){var c=this.a,d=this.b;this.u=a;for(var e,f,g,h,i=c.length-258;256!==(e=o(this,a));)if(256>e)d>=i&&(this.b=d,c=this.f(),d=this.b),c[d++]=e;else for(f=e-257,h=S[f],0=i&&(this.b=d,c=this.f(),d=this.b);h--;)c[d]=c[d++-g];for(;8<=this.e;)this.e-=8,this.c--;this.b=d},m.prototype.J=function(a,b){var c=this.a,d=this.b;this.u=a;for(var e,f,g,h,i=c.length;256!==(e=o(this,a));)if(256>e)d>=i&&(c=this.f(),i=c.length),c[d++]=e;else for(f=e-257,h=S[f],0i&&(c=this.f(),i=c.length);h--;)c[d]=c[d++-g];for(;8<=this.e;)this.e-=8,this.c--;this.b=d},m.prototype.f=function(){var a,b,c=new(x?Uint8Array:Array)(this.b-32768),d=this.b-32768,e=this.a;if(x)c.set(e.subarray(32768,c.length));else for(a=0,b=c.length;b>a;++a)c[a]=e[a+32768];if(this.l.push(c),this.q+=c.length,x)e.set(e.subarray(d,d+32768));else for(a=0;32768>a;++a)e[a]=e[d+a];return this.b=32768,e},m.prototype.K=function(a){var b,c,d,e,f=this.input.length/this.c+1|0,g=this.input,h=this.a;return a&&("number"==typeof a.v&&(f=a.v),"number"==typeof a.G&&(f+=a.G)),2>f?(c=(g.length-this.c)/this.u[2],e=258*(c/2)|0,d=eb;++b)for(a=h[b],d=0,e=a.length;e>d;++d)i[f++]=a[d];for(b=32768,c=this.b;c>b;++b)i[f++]=g[b];return this.l=[],this.buffer=i},m.prototype.I=function(){var a,b=this.b;return x?this.C?(a=new Uint8Array(b),a.set(this.a.subarray(0,b))):a=this.a.subarray(0,b):(this.a.length>b&&(this.a.length=b),a=this.a),this.buffer=a},r.prototype.p=function(){var b,c,d=this.input;return b=this.B.p(),this.c=this.B.c,this.N&&(c=(d[this.c++]<<24|d[this.c++]<<16|d[this.c++]<<8|d[this.c++])>>>0,c!==q(b)&&a(Error("invalid adler-32 checksum"))),b};var da=8,ea=G;s.prototype.j=function(){var b,c,d,e,f,g,h,i=0;switch(h=this.a,b=da){case da:c=Math.LOG2E*Math.log(32768)-8;break;default:a(Error("invalid compression method"))}switch(d=c<<4|b,h[i++]=d,b){case da:switch(this.h){case ea.NONE:f=0;break;case ea.r:f=1;break;case ea.k:f=2;break;default:a(Error("unsupported compression type"))}break;default:a(Error("invalid compression method"))}return e=f<<6|0,h[i++]=e|31-(256*d+e)%31,g=q(this.input),this.A.b=i,h=this.A.j(),i=h.length,x&&(h=new Uint8Array(h.buffer),h.length<=i+4&&(this.a=new Uint8Array(h.length+4),this.a.set(h),h=this.a),h=h.subarray(0,i+4)),h[i++]=g>>24&255,h[i++]=g>>16&255,h[i++]=g>>8&255,h[i++]=255&g,h},b("Zlib.Inflate",r),b("Zlib.Inflate.prototype.decompress",r.prototype.p),t("Zlib.Inflate.BufferType",{ADAPTIVE:M.D,BLOCK:M.F}),b("Zlib.Deflate",s),b("Zlib.Deflate.compress",function(a,b){return new s(a,b).j()}),b("Zlib.Deflate.prototype.compress",s.prototype.j),t("Zlib.Deflate.CompressionType",{NONE:ea.NONE,FIXED:ea.r,DYNAMIC:ea.k})}).call(this)},{}],16:[function(a,b,c){var d=a("../enums.js");b.exports={prefer_hash_algorithm:d.hash.sha256,encryption_cipher:d.symmetric.aes256,compression:d.compression.zip,integrity_protect:!0,ignore_mdc_error:!1,rsa_blinding:!0,useWebCrypto:!0,show_version:!0,show_comment:!0,versionstring:"OpenPGP.js v1.5.7",commentstring:"http://openpgpjs.org",keyserver:"https://keyserver.ubuntu.com",node_store:"./openpgp.store",debug:!1}},{"../enums.js":43}],17:[function(a,b,c){b.exports=a("./config.js")},{"./config.js":16}],18:[function(a,b,c){"use strict";var d=a("../util.js"),e=a("./cipher");b.exports={encrypt:function(a,b,c,f,g){b=new e[b](f);var h=b.blockSize,i=new Uint8Array(h),j=new Uint8Array(h);a=a+a.charAt(h-2)+a.charAt(h-1);var k,l,m,n=new Uint8Array(c.length+2+2*h),o=g?0:2;for(k=0;h>k;k++)i[k]=0;for(j=b.encrypt(i),k=0;h>k;k++)n[k]=j[k]^a.charCodeAt(k);for(i.set(n.subarray(0,h)),j=b.encrypt(i),n[h]=j[0]^a.charCodeAt(h),n[h+1]=j[1]^a.charCodeAt(h+1),g?i.set(n.subarray(2,h+2)):i.set(n.subarray(0,h)),j=b.encrypt(i),k=0;h>k;k++)n[h+2+k]=j[k+o]^c.charCodeAt(k);for(l=h;lk;k++)n[h+m+k]=j[k]^c.charCodeAt(l+k-o);return n=n.subarray(0,c.length+2+h),d.Uint8Array2str(n)},mdc:function(a,b,c){a=new e[a](b);var f,g=a.blockSize,h=new Uint8Array(g),i=new Uint8Array(g);for(f=0;g>f;f++)h[f]=0;for(h=a.encrypt(h),f=0;g>f;f++)i[f]=c.charCodeAt(f),h[f]^=i[f];return i=a.encrypt(i),d.bin2str(h)+String.fromCharCode(i[0]^c.charCodeAt(g))+String.fromCharCode(i[1]^c.charCodeAt(g+1))},decrypt:function(a,b,c,d){a=new e[a](b);var f,g=a.blockSize,h=new Uint8Array(g),i=new Uint8Array(g),j="",k=[];for(f=0;g>f;f++)h[f]=0;for(h=a.encrypt(h),f=0;g>f;f++)i[f]=c.charCodeAt(f),h[f]^=i[f];if(i=a.encrypt(i),h[g-2]!=(i[0]^c.charCodeAt(g))||h[g-1]!=(i[1]^c.charCodeAt(g+1)))throw new Error("CFB decrypt: invalid key");if(d){for(f=0;g>f;f++)h[f]=c.charCodeAt(f+2);for(j=g+2;jf&&f+jf;f++)h[f]=c.charCodeAt(f);for(j=g;jf&&f+jg*j;){var m=a.encrypt(d.str2bin(i));h=c.substring(j*g,j*g+g);for(var n=0;ng;g++)i+=String.fromCharCode(0);else i=f.substring(0,h);for(;c.length>h*j;){var m=a.encrypt(d.str2bin(i));for(i=c.substring(j*h+l,j*h+h+l),g=0;g>8&255}function f(a){return a>>16&255}function g(a){return a>>24&255}function h(a,b,c,d){return e(p[255&a])|e(p[b>>8&255])<<8|e(p[c>>16&255])<<16|e(p[d>>>24])<<24}function i(a){var b,c,d=a.length,e=new Array(d/4);if(a&&!(d%4)){for(b=0,c=0;d>c;c+=4)e[b++]=a[c]|a[c+1]<<8|a[c+2]<<16|a[c+3]<<24;return e}}function j(a){var b,c=0,h=a.length,i=new Array(4*h);for(b=0;h>b;b++)i[c++]=d(a[b]),i[c++]=e(a[b]),i[c++]=f(a[b]),i[c++]=g(a[b]);return i}function k(a){var b,c,h,i,j,k,l=new Array(u+1),m=a.length,p=new Array(t),q=new Array(t),r=0;if(16==m)k=10,b=4;else if(24==m)k=12,b=6;else{if(32!=m)throw new Error("Invalid key-length for AES key:"+m);k=14,b=8}for(c=0;u+1>c;c++)l[c]=new Uint32Array(4);for(c=0,h=0;m>h;h++,c+=4)p[h]=a.charCodeAt(c)|a.charCodeAt(c+1)<<8|a.charCodeAt(c+2)<<16|a.charCodeAt(c+3)<<24;for(h=b-1;h>=0;h--)q[h]=p[h];for(i=0,j=0,h=0;b>h&&k+1>i;){for(;b>h&&4>j;h++,j++)l[i][j]=q[h];4==j&&(i++,j=0)}for(;k+1>i;){var s=q[b-1];if(q[0]^=o[e(s)]|o[f(s)]<<8|o[g(s)]<<16|o[d(s)]<<24,q[0]^=n[r++],8!=b)for(h=1;b>h;h++)q[h]^=q[h-1];else{for(h=1;b/2>h;h++)q[h]^=q[h-1];for(s=q[b/2-1],q[b/2]^=o[d(s)]|o[e(s)]<<8|o[f(s)]<<16|o[g(s)]<<24,h=b/2+1;b>h;h++)q[h]^=q[h-1]}for(h=0;b>h&&k+1>i;){for(;b>h&&4>j;h++,j++)l[i][j]=q[h];4==j&&(i++,j=0)}}return{rounds:k,rk:l}}function l(a,b,c){var d,e,f;for(f=i(a),e=b.rounds,d=0;e-1>d;d++)c[0]=f[0]^b.rk[d][0],c[1]=f[1]^b.rk[d][1],c[2]=f[2]^b.rk[d][2],c[3]=f[3]^b.rk[d][3],f[0]=p[255&c[0]]^q[c[1]>>8&255]^r[c[2]>>16&255]^s[c[3]>>>24],f[1]=p[255&c[1]]^q[c[2]>>8&255]^r[c[3]>>16&255]^s[c[0]>>>24],f[2]=p[255&c[2]]^q[c[3]>>8&255]^r[c[0]>>16&255]^s[c[1]>>>24],f[3]=p[255&c[3]]^q[c[0]>>8&255]^r[c[1]>>16&255]^s[c[2]>>>24];return d=e-1,c[0]=f[0]^b.rk[d][0],c[1]=f[1]^b.rk[d][1],c[2]=f[2]^b.rk[d][2],c[3]=f[3]^b.rk[d][3],f[0]=h(c[0],c[1],c[2],c[3])^b.rk[e][0],f[1]=h(c[1],c[2],c[3],c[0])^b.rk[e][1],f[2]=h(c[2],c[3],c[0],c[1])^b.rk[e][2],f[3]=h(c[3],c[0],c[1],c[2])^b.rk[e][3],j(f)}function m(a){var b=function(a){this.key=k(a),this._temp=new Uint32Array(this.blockSize/4),this.encrypt=function(a){return l(a,this.key,this._temp)}};return b.blockSize=b.prototype.blockSize=16,b.keySize=b.prototype.keySize=a/8,b}var n=(a("../../util.js"),new Uint8Array([1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145])),o=new Uint8Array([99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22]),p=new Uint32Array([2774754246,2222750968,2574743534,2373680118,234025727,3177933782,2976870366,1422247313,1345335392,50397442,2842126286,2099981142,436141799,1658312629,3870010189,2591454956,1170918031,2642575903,1086966153,2273148410,368769775,3948501426,3376891790,200339707,3970805057,1742001331,4255294047,3937382213,3214711843,4154762323,2524082916,1539358875,3266819957,486407649,2928907069,1780885068,1513502316,1094664062,49805301,1338821763,1546925160,4104496465,887481809,150073849,2473685474,1943591083,1395732834,1058346282,201589768,1388824469,1696801606,1589887901,672667696,2711000631,251987210,3046808111,151455502,907153956,2608889883,1038279391,652995533,1764173646,3451040383,2675275242,453576978,2659418909,1949051992,773462580,756751158,2993581788,3998898868,4221608027,4132590244,1295727478,1641469623,3467883389,2066295122,1055122397,1898917726,2542044179,4115878822,1758581177,0,753790401,1612718144,536673507,3367088505,3982187446,3194645204,1187761037,3653156455,1262041458,3729410708,3561770136,3898103984,1255133061,1808847035,720367557,3853167183,385612781,3309519750,3612167578,1429418854,2491778321,3477423498,284817897,100794884,2172616702,4031795360,1144798328,3131023141,3819481163,4082192802,4272137053,3225436288,2324664069,2912064063,3164445985,1211644016,83228145,3753688163,3249976951,1977277103,1663115586,806359072,452984805,250868733,1842533055,1288555905,336333848,890442534,804056259,3781124030,2727843637,3427026056,957814574,1472513171,4071073621,2189328124,1195195770,2892260552,3881655738,723065138,2507371494,2690670784,2558624025,3511635870,2145180835,1713513028,2116692564,2878378043,2206763019,3393603212,703524551,3552098411,1007948840,2044649127,3797835452,487262998,1994120109,1004593371,1446130276,1312438900,503974420,3679013266,168166924,1814307912,3831258296,1573044895,1859376061,4021070915,2791465668,2828112185,2761266481,937747667,2339994098,854058965,1137232011,1496790894,3077402074,2358086913,1691735473,3528347292,3769215305,3027004632,4199962284,133494003,636152527,2942657994,2390391540,3920539207,403179536,3585784431,2289596656,1864705354,1915629148,605822008,4054230615,3350508659,1371981463,602466507,2094914977,2624877800,555687742,3712699286,3703422305,2257292045,2240449039,2423288032,1111375484,3300242801,2858837708,3628615824,84083462,32962295,302911004,2741068226,1597322602,4183250862,3501832553,2441512471,1489093017,656219450,3114180135,954327513,335083755,3013122091,856756514,3144247762,1893325225,2307821063,2811532339,3063651117,572399164,2458355477,552200649,1238290055,4283782570,2015897680,2061492133,2408352771,4171342169,2156497161,386731290,3669999461,837215959,3326231172,3093850320,3275833730,2962856233,1999449434,286199582,3417354363,4233385128,3602627437,974525996]),q=new Uint32Array([1667483301,2088564868,2004348569,2071721613,4076011277,1802229437,1869602481,3318059348,808476752,16843267,1734856361,724260477,4278118169,3621238114,2880130534,1987505306,3402272581,2189565853,3385428288,2105408135,4210749205,1499050731,1195871945,4042324747,2913812972,3570709351,2728550397,2947499498,2627478463,2762232823,1920132246,3233848155,3082253762,4261273884,2475900334,640044138,909536346,1061125697,4160222466,3435955023,875849820,2779075060,3857043764,4059166984,1903288979,3638078323,825320019,353708607,67373068,3351745874,589514341,3284376926,404238376,2526427041,84216335,2593796021,117902857,303178806,2155879323,3806519101,3958099238,656887401,2998042573,1970662047,151589403,2206408094,741103732,437924910,454768173,1852759218,1515893998,2694863867,1381147894,993752653,3604395873,3014884814,690573947,3823361342,791633521,2223248279,1397991157,3520182632,0,3991781676,538984544,4244431647,2981198280,1532737261,1785386174,3419114822,3200149465,960066123,1246401758,1280088276,1482207464,3486483786,3503340395,4025468202,2863288293,4227591446,1128498885,1296931543,859006549,2240090516,1162185423,4193904912,33686534,2139094657,1347461360,1010595908,2678007226,2829601763,1364304627,2745392638,1077969088,2408514954,2459058093,2644320700,943222856,4126535940,3166462943,3065411521,3671764853,555827811,269492272,4294960410,4092853518,3537026925,3452797260,202119188,320022069,3974939439,1600110305,2543269282,1145342156,387395129,3301217111,2812761586,2122251394,1027439175,1684326572,1566423783,421081643,1936975509,1616953504,2172721560,1330618065,3705447295,572671078,707417214,2425371563,2290617219,1179028682,4008625961,3099093971,336865340,3739133817,1583267042,185275933,3688607094,3772832571,842163286,976909390,168432670,1229558491,101059594,606357612,1549580516,3267534685,3553869166,2896970735,1650640038,2442213800,2509582756,3840201527,2038035083,3890730290,3368586051,926379609,1835915959,2374828428,3587551588,1313774802,2846444e3,1819072692,1448520954,4109693703,3941256997,1701169839,2054878350,2930657257,134746136,3132780501,2021191816,623200879,774790258,471611428,2795919345,3031724999,3334903633,3907570467,3722289532,1953818780,522141217,1263245021,3183305180,2341145990,2324303749,1886445712,1044282434,3048567236,1718013098,1212715224,50529797,4143380225,235805714,1633796771,892693087,1465364217,3115936208,2256934801,3250690392,488454695,2661164985,3789674808,4177062675,2560109491,286335539,1768542907,3654920560,2391672713,2492740519,2610638262,505297954,2273777042,3924412704,3469641545,1431677695,673730680,3755976058,2357986191,2711706104,2307459456,218962455,3216991706,3873888049,1111655622,1751699640,1094812355,2576951728,757946999,252648977,2964356043,1414834428,3149622742,370551866]),r=new Uint32Array([1673962851,2096661628,2012125559,2079755643,4076801522,1809235307,1876865391,3314635973,811618352,16909057,1741597031,727088427,4276558334,3618988759,2874009259,1995217526,3398387146,2183110018,3381215433,2113570685,4209972730,1504897881,1200539975,4042984432,2906778797,3568527316,2724199842,2940594863,2619588508,2756966308,1927583346,3231407040,3077948087,4259388669,2470293139,642542118,913070646,1065238847,4160029431,3431157708,879254580,2773611685,3855693029,4059629809,1910674289,3635114968,828527409,355090197,67636228,3348452039,591815971,3281870531,405809176,2520228246,84545285,2586817946,118360327,304363026,2149292928,3806281186,3956090603,659450151,2994720178,1978310517,152181513,2199756419,743994412,439627290,456535323,1859957358,1521806938,2690382752,1386542674,997608763,3602342358,3011366579,693271337,3822927587,794718511,2215876484,1403450707,3518589137,0,3988860141,541089824,4242743292,2977548465,1538714971,1792327274,3415033547,3194476990,963791673,1251270218,1285084236,1487988824,3481619151,3501943760,4022676207,2857362858,4226619131,1132905795,1301993293,862344499,2232521861,1166724933,4192801017,33818114,2147385727,1352724560,1014514748,2670049951,2823545768,1369633617,2740846243,1082179648,2399505039,2453646738,2636233885,946882616,4126213365,3160661948,3061301686,3668932058,557998881,270544912,4293204735,4093447923,3535760850,3447803085,202904588,321271059,3972214764,1606345055,2536874647,1149815876,388905239,3297990596,2807427751,2130477694,1031423805,1690872932,1572530013,422718233,1944491379,1623236704,2165938305,1335808335,3701702620,574907938,710180394,2419829648,2282455944,1183631942,4006029806,3094074296,338181140,3735517662,1589437022,185998603,3685578459,3772464096,845436466,980700730,169090570,1234361161,101452294,608726052,1555620956,3265224130,3552407251,2890133420,1657054818,2436475025,2503058581,3839047652,2045938553,3889509095,3364570056,929978679,1843050349,2365688973,3585172693,1318900302,2840191145,1826141292,1454176854,4109567988,3939444202,1707781989,2062847610,2923948462,135272456,3127891386,2029029496,625635109,777810478,473441308,2790781350,3027486644,3331805638,3905627112,3718347997,1961401460,524165407,1268178251,3177307325,2332919435,2316273034,1893765232,1048330814,3044132021,1724688998,1217452104,50726147,4143383030,236720654,1640145761,896163637,1471084887,3110719673,2249691526,3248052417,490350365,2653403550,3789109473,4176155640,2553000856,287453969,1775418217,3651760345,2382858638,2486413204,2603464347,507257374,2266337927,3922272489,3464972750,1437269845,676362280,3752164063,2349043596,2707028129,2299101321,219813645,3211123391,3872862694,1115997762,1758509160,1099088705,2569646233,760903469,253628687,2960903088,1420360788,3144537787,371997206]),s=new Uint32Array([3332727651,4169432188,4003034999,4136467323,4279104242,3602738027,3736170351,2438251973,1615867952,33751297,3467208551,1451043627,3877240574,3043153879,1306962859,3969545846,2403715786,530416258,2302724553,4203183485,4011195130,3001768281,2395555655,4211863792,1106029997,3009926356,1610457762,1173008303,599760028,1408738468,3835064946,2606481600,1975695287,3776773629,1034851219,1282024998,1817851446,2118205247,4110612471,2203045068,1750873140,1374987685,3509904869,4178113009,3801313649,2876496088,1649619249,708777237,135005188,2505230279,1181033251,2640233411,807933976,933336726,168756485,800430746,235472647,607523346,463175808,3745374946,3441880043,1315514151,2144187058,3936318837,303761673,496927619,1484008492,875436570,908925723,3702681198,3035519578,1543217312,2767606354,1984772923,3076642518,2110698419,1383803177,3711886307,1584475951,328696964,2801095507,3110654417,0,3240947181,1080041504,3810524412,2043195825,3069008731,3569248874,2370227147,1742323390,1917532473,2497595978,2564049996,2968016984,2236272591,3144405200,3307925487,1340451498,3977706491,2261074755,2597801293,1716859699,294946181,2328839493,3910203897,67502594,4269899647,2700103760,2017737788,632987551,1273211048,2733855057,1576969123,2160083008,92966799,1068339858,566009245,1883781176,4043634165,1675607228,2009183926,2943736538,1113792801,540020752,3843751935,4245615603,3211645650,2169294285,403966988,641012499,3274697964,3202441055,899848087,2295088196,775493399,2472002756,1441965991,4236410494,2051489085,3366741092,3135724893,841685273,3868554099,3231735904,429425025,2664517455,2743065820,1147544098,1417554474,1001099408,193169544,2362066502,3341414126,1809037496,675025940,2809781982,3168951902,371002123,2910247899,3678134496,1683370546,1951283770,337512970,2463844681,201983494,1215046692,3101973596,2673722050,3178157011,1139780780,3299238498,967348625,832869781,3543655652,4069226873,3576883175,2336475336,1851340599,3669454189,25988493,2976175573,2631028302,1239460265,3635702892,2902087254,4077384948,3475368682,3400492389,4102978170,1206496942,270010376,1876277946,4035475576,1248797989,1550986798,941890588,1475454630,1942467764,2538718918,3408128232,2709315037,3902567540,1042358047,2531085131,1641856445,226921355,260409994,3767562352,2084716094,1908716981,3433719398,2430093384,100991747,4144101110,470945294,3265487201,1784624437,2935576407,1775286713,395413126,2572730817,975641885,666476190,3644383713,3943954680,733190296,573772049,3535497577,2842745305,126455438,866620564,766942107,1008868894,361924487,3374377449,2269761230,2868860245,1350051880,2776293343,59739276,1509466529,159418761,437718285,1708834751,3610371814,2227585602,3501746280,2193834305,699439513,1517759789,504434447,2076946608,2835108948,1842789307,742004246]),t=8,u=14;b.exports={};var v=[128,192,256];for(var w in v)b.exports[v[w]]=m(v[w])},{"../../util.js":76}],20:[function(a,b,c){function d(){}function e(a){this.bf=new d,this.bf.init(f.str2bin(a)),this.encrypt=function(a){return this.bf.encrypt_block(a)}}d.prototype.BLOCKSIZE=8,d.prototype.SBOXES=[[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946],[1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055],[3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504],[976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462]], -d.prototype.PARRAY=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],d.prototype.NN=16,d.prototype._clean=function(a){if(0>a){var b=2147483647&a;a=b+2147483648}return a},d.prototype._F=function(a){var b,c,d,e,f;return e=255&a,a>>>=8,d=255&a,a>>>=8,c=255&a,a>>>=8,b=255&a,f=this.sboxes[0][b]+this.sboxes[1][c],f^=this.sboxes[2][d],f+=this.sboxes[3][e]},d.prototype._encrypt_block=function(a){var b,c=a[0],d=a[1];for(b=0;b>>24-8*b&255,e[b+d]=c[1]>>>24-8*b&255;return e},d.prototype._decrypt_block=function(a){var b,c=a[0],d=a[1];for(b=this.NN+1;b>1;--b){c^=this.parray[b],d=this._F(c)^d;var e=c;c=d,d=e}c^=this.parray[1],d^=this.parray[0],a[0]=this._clean(d),a[1]=this._clean(c)},d.prototype.init=function(a){var b,c=0;for(this.parray=[],b=0;bd;++d)e=e<<8|255&a[c],++c>=a.length&&(c=0);this.parray[b]=this.PARRAY[b]^e}for(this.sboxes=[],b=0;4>b;++b)for(this.sboxes[b]=[],c=0;256>c;++c)this.sboxes[b][c]=this.SBOXES[b][c];var f=[0,0];for(b=0;bb;++b)for(c=0;256>c;c+=2)this._encrypt_block(f),this.sboxes[b][c+0]=f[0],this.sboxes[b][c+1]=f[1]};var f=a("../../util.js");b.exports=e,b.exports.keySize=e.prototype.keySize=16,b.exports.blockSize=e.prototype.blockSize=16},{"../../util.js":76}],21:[function(a,b,c){function d(){function a(a,b,c){var d=b+a,e=d<>>32-c;return(f[0][e>>>24]^f[1][e>>>16&255])-f[2][e>>>8&255]+f[3][255&e]}function b(a,b,c){var d=b^a,e=d<>>32-c;return f[0][e>>>24]-f[1][e>>>16&255]+f[2][e>>>8&255]^f[3][255&e]}function c(a,b,c){var d=b-a,e=d<>>32-c;return(f[0][e>>>24]+f[1][e>>>16&255]^f[2][e>>>8&255])-f[3][255&e]}this.BlockSize=8,this.KeySize=16,this.setKey=function(a){if(this.masking=new Array(16),this.rotate=new Array(16),this.reset(),a.length!=this.KeySize)throw new Error("CAST-128: keys must be 16 bytes");return this.keySchedule(a),!0},this.reset=function(){for(var a=0;16>a;a++)this.masking[a]=0,this.rotate[a]=0},this.getBlockSize=function(){return BlockSize},this.encrypt=function(d){for(var e=new Array(d.length),f=0;f>>24&255,e[f+1]=i>>>16&255,e[f+2]=i>>>8&255,e[f+3]=255&i,e[f+4]=h>>>24&255,e[f+5]=h>>>16&255,e[f+6]=h>>>8&255,e[f+7]=255&h}return e},this.decrypt=function(d){for(var e=new Array(d.length),f=0;f>>24&255,e[f+1]=i>>>16&255,e[f+2]=i>>>8&255,e[f+3]=255&i,e[f+4]=h>>>24&255,e[f+5]=h>>16&255,e[f+6]=h>>8&255,e[f+7]=255&h}return e};var d=new Array(4);d[0]=new Array(4),d[0][0]=new Array(4,0,13,15,12,14,8),d[0][1]=new Array(5,2,16,18,17,19,10),d[0][2]=new Array(6,3,23,22,21,20,9),d[0][3]=new Array(7,1,26,25,27,24,11),d[1]=new Array(4),d[1][0]=new Array(0,6,21,23,20,22,16),d[1][1]=new Array(1,4,0,2,1,3,18),d[1][2]=new Array(2,5,7,6,5,4,17),d[1][3]=new Array(3,7,10,9,11,8,19),d[2]=new Array(4),d[2][0]=new Array(4,0,13,15,12,14,8),d[2][1]=new Array(5,2,16,18,17,19,10),d[2][2]=new Array(6,3,23,22,21,20,9),d[2][3]=new Array(7,1,26,25,27,24,11),d[3]=new Array(4),d[3][0]=new Array(0,6,21,23,20,22,16),d[3][1]=new Array(1,4,0,2,1,3,18),d[3][2]=new Array(2,5,7,6,5,4,17),d[3][3]=new Array(3,7,10,9,11,8,19);var e=new Array(4);e[0]=new Array(4),e[0][0]=new Array(24,25,23,22,18),e[0][1]=new Array(26,27,21,20,22),e[0][2]=new Array(28,29,19,18,25),e[0][3]=new Array(30,31,17,16,28),e[1]=new Array(4),e[1][0]=new Array(3,2,12,13,8),e[1][1]=new Array(1,0,14,15,13),e[1][2]=new Array(7,6,8,9,3),e[1][3]=new Array(5,4,10,11,7),e[2]=new Array(4),e[2][0]=new Array(19,18,28,29,25),e[2][1]=new Array(17,16,30,31,28),e[2][2]=new Array(23,22,24,25,18),e[2][3]=new Array(21,20,26,27,22),e[3]=new Array(4),e[3][0]=new Array(8,9,7,6,3),e[3][1]=new Array(10,11,5,4,7),e[3][2]=new Array(12,13,3,2,8),e[3][3]=new Array(14,15,1,0,13),this.keySchedule=function(a){var b,c,g=new Array(8),h=new Array(32);for(b=0;4>b;b++)c=4*b,g[b]=a[c]<<24|a[c+1]<<16|a[c+2]<<8|a[c+3];for(var i,j=[6,7,4,5],k=0,l=0;2>l;l++)for(var m=0;4>m;m++){for(c=0;4>c;c++){var n=d[m][c];i=g[n[1]],i^=f[4][g[n[2]>>>2]>>>24-8*(3&n[2])&255],i^=f[5][g[n[3]>>>2]>>>24-8*(3&n[3])&255],i^=f[6][g[n[4]>>>2]>>>24-8*(3&n[4])&255],i^=f[7][g[n[5]>>>2]>>>24-8*(3&n[5])&255],i^=f[j[c]][g[n[6]>>>2]>>>24-8*(3&n[6])&255],g[n[0]]=i}for(c=0;4>c;c++){var o=e[m][c];i=f[4][g[o[0]>>>2]>>>24-8*(3&o[0])&255],i^=f[5][g[o[1]>>>2]>>>24-8*(3&o[1])&255],i^=f[6][g[o[2]>>>2]>>>24-8*(3&o[2])&255],i^=f[7][g[o[3]>>>2]>>>24-8*(3&o[3])&255],i^=f[4+c][g[o[4]>>>2]>>>24-8*(3&o[4])&255],h[k]=i,k++}}for(b=0;16>b;b++)this.masking[b]=h[b],this.rotate[b]=31&h[16+b]};var f=new Array(8);f[0]=new Array(821772500,2678128395,1810681135,1059425402,505495343,2617265619,1610868032,3483355465,3218386727,2294005173,3791863952,2563806837,1852023008,365126098,3269944861,584384398,677919599,3229601881,4280515016,2002735330,1136869587,3744433750,2289869850,2731719981,2714362070,879511577,1639411079,575934255,717107937,2857637483,576097850,2731753936,1725645e3,2810460463,5111599,767152862,2543075244,1251459544,1383482551,3052681127,3089939183,3612463449,1878520045,1510570527,2189125840,2431448366,582008916,3163445557,1265446783,1354458274,3529918736,3202711853,3073581712,3912963487,3029263377,1275016285,4249207360,2905708351,3304509486,1442611557,3585198765,2712415662,2731849581,3248163920,2283946226,208555832,2766454743,1331405426,1447828783,3315356441,3108627284,2957404670,2981538698,3339933917,1669711173,286233437,1465092821,1782121619,3862771680,710211251,980974943,1651941557,430374111,2051154026,704238805,4128970897,3144820574,2857402727,948965521,3333752299,2227686284,718756367,2269778983,2731643755,718440111,2857816721,3616097120,1113355533,2478022182,410092745,1811985197,1944238868,2696854588,1415722873,1682284203,1060277122,1998114690,1503841958,82706478,2315155686,1068173648,845149890,2167947013,1768146376,1993038550,3566826697,3390574031,940016341,3355073782,2328040721,904371731,1205506512,4094660742,2816623006,825647681,85914773,2857843460,1249926541,1417871568,3287612,3211054559,3126306446,1975924523,1353700161,2814456437,2438597621,1800716203,722146342,2873936343,1151126914,4160483941,2877670899,458611604,2866078500,3483680063,770352098,2652916994,3367839148,3940505011,3585973912,3809620402,718646636,2504206814,2914927912,3631288169,2857486607,2860018678,575749918,2857478043,718488780,2069512688,3548183469,453416197,1106044049,3032691430,52586708,3378514636,3459808877,3211506028,1785789304,218356169,3571399134,3759170522,1194783844,1523787992,3007827094,1975193539,2555452411,1341901877,3045838698,3776907964,3217423946,2802510864,2889438986,1057244207,1636348243,3761863214,1462225785,2632663439,481089165,718503062,24497053,3332243209,3344655856,3655024856,3960371065,1195698900,2971415156,3710176158,2115785917,4027663609,3525578417,2524296189,2745972565,3564906415,1372086093,1452307862,2780501478,1476592880,3389271281,18495466,2378148571,901398090,891748256,3279637769,3157290713,2560960102,1447622437,4284372637,216884176,2086908623,1879786977,3588903153,2242455666,2938092967,3559082096,2810645491,758861177,1121993112,215018983,642190776,4169236812,1196255959,2081185372,3508738393,941322904,4124243163,2877523539,1848581667,2205260958,3180453958,2589345134,3694731276,550028657,2519456284,3789985535,2973870856,2093648313,443148163,46942275,2734146937,1117713533,1115362972,1523183689,3717140224,1551984063),f[1]=new Array(522195092,4010518363,1776537470,960447360,4267822970,4005896314,1435016340,1929119313,2913464185,1310552629,3579470798,3724818106,2579771631,1594623892,417127293,2715217907,2696228731,1508390405,3994398868,3925858569,3695444102,4019471449,3129199795,3770928635,3520741761,990456497,4187484609,2783367035,21106139,3840405339,631373633,3783325702,532942976,396095098,3548038825,4267192484,2564721535,2011709262,2039648873,620404603,3776170075,2898526339,3612357925,4159332703,1645490516,223693667,1567101217,3362177881,1029951347,3470931136,3570957959,1550265121,119497089,972513919,907948164,3840628539,1613718692,3594177948,465323573,2659255085,654439692,2575596212,2699288441,3127702412,277098644,624404830,4100943870,2717858591,546110314,2403699828,3655377447,1321679412,4236791657,1045293279,4010672264,895050893,2319792268,494945126,1914543101,2777056443,3894764339,2219737618,311263384,4275257268,3458730721,669096869,3584475730,3835122877,3319158237,3949359204,2005142349,2713102337,2228954793,3769984788,569394103,3855636576,1425027204,108000370,2736431443,3671869269,3043122623,1750473702,2211081108,762237499,3972989403,2798899386,3061857628,2943854345,867476300,964413654,1591880597,1594774276,2179821409,552026980,3026064248,3726140315,2283577634,3110545105,2152310760,582474363,1582640421,1383256631,2043843868,3322775884,1217180674,463797851,2763038571,480777679,2718707717,2289164131,3118346187,214354409,200212307,3810608407,3025414197,2674075964,3997296425,1847405948,1342460550,510035443,4080271814,815934613,833030224,1620250387,1945732119,2703661145,3966000196,1388869545,3456054182,2687178561,2092620194,562037615,1356438536,3409922145,3261847397,1688467115,2150901366,631725691,3840332284,549916902,3455104640,394546491,837744717,2114462948,751520235,2221554606,2415360136,3999097078,2063029875,803036379,2702586305,821456707,3019566164,360699898,4018502092,3511869016,3677355358,2402471449,812317050,49299192,2570164949,3259169295,2816732080,3331213574,3101303564,2156015656,3705598920,3546263921,143268808,3200304480,1638124008,3165189453,3341807610,578956953,2193977524,3638120073,2333881532,807278310,658237817,2969561766,1641658566,11683945,3086995007,148645947,1138423386,4158756760,1981396783,2401016740,3699783584,380097457,2680394679,2803068651,3334260286,441530178,4016580796,1375954390,761952171,891809099,2183123478,157052462,3683840763,1592404427,341349109,2438483839,1417898363,644327628,2233032776,2353769706,2201510100,220455161,1815641738,182899273,2995019788,3627381533,3702638151,2890684138,1052606899,588164016,1681439879,4038439418,2405343923,4229449282,167996282,1336969661,1688053129,2739224926,1543734051,1046297529,1138201970,2121126012,115334942,1819067631,1902159161,1941945968,2206692869,1159982321),f[2]=new Array(2381300288,637164959,3952098751,3893414151,1197506559,916448331,2350892612,2932787856,3199334847,4009478890,3905886544,1373570990,2450425862,4037870920,3778841987,2456817877,286293407,124026297,3001279700,1028597854,3115296800,4208886496,2691114635,2188540206,1430237888,1218109995,3572471700,308166588,570424558,2187009021,2455094765,307733056,1310360322,3135275007,1384269543,2388071438,863238079,2359263624,2801553128,3380786597,2831162807,1470087780,1728663345,4072488799,1090516929,532123132,2389430977,1132193179,2578464191,3051079243,1670234342,1434557849,2711078940,1241591150,3314043432,3435360113,3091448339,1812415473,2198440252,267246943,796911696,3619716990,38830015,1526438404,2806502096,374413614,2943401790,1489179520,1603809326,1920779204,168801282,260042626,2358705581,1563175598,2397674057,1356499128,2217211040,514611088,2037363785,2186468373,4022173083,2792511869,2913485016,1173701892,4200428547,3896427269,1334932762,2455136706,602925377,2835607854,1613172210,41346230,2499634548,2457437618,2188827595,41386358,4172255629,1313404830,2405527007,3801973774,2217704835,873260488,2528884354,2478092616,4012915883,2555359016,2006953883,2463913485,575479328,2218240648,2099895446,660001756,2341502190,3038761536,3888151779,3848713377,3286851934,1022894237,1620365795,3449594689,1551255054,15374395,3570825345,4249311020,4151111129,3181912732,310226346,1133119310,530038928,136043402,2476768958,3107506709,2544909567,1036173560,2367337196,1681395281,1758231547,3641649032,306774401,1575354324,3716085866,1990386196,3114533736,2455606671,1262092282,3124342505,2768229131,4210529083,1833535011,423410938,660763973,2187129978,1639812e3,3508421329,3467445492,310289298,272797111,2188552562,2456863912,310240523,677093832,1013118031,901835429,3892695601,1116285435,3036471170,1337354835,243122523,520626091,277223598,4244441197,4194248841,1766575121,594173102,316590669,742362309,3536858622,4176435350,3838792410,2501204839,1229605004,3115755532,1552908988,2312334149,979407927,3959474601,1148277331,176638793,3614686272,2083809052,40992502,1340822838,2731552767,3535757508,3560899520,1354035053,122129617,7215240,2732932949,3118912700,2718203926,2539075635,3609230695,3725561661,1928887091,2882293555,1988674909,2063640240,2491088897,1459647954,4189817080,2302804382,1113892351,2237858528,1927010603,4002880361,1856122846,1594404395,2944033133,3855189863,3474975698,1643104450,4054590833,3431086530,1730235576,2984608721,3084664418,2131803598,4178205752,267404349,1617849798,1616132681,1462223176,736725533,2327058232,551665188,2945899023,1749386277,2575514597,1611482493,674206544,2201269090,3642560800,728599968,1680547377,2620414464,1388111496,453204106,4156223445,1094905244,2754698257,2201108165,3757000246,2704524545,3922940700,3996465027),f[3]=new Array(2645754912,532081118,2814278639,3530793624,1246723035,1689095255,2236679235,4194438865,2116582143,3859789411,157234593,2045505824,4245003587,1687664561,4083425123,605965023,672431967,1336064205,3376611392,214114848,4258466608,3232053071,489488601,605322005,3998028058,264917351,1912574028,756637694,436560991,202637054,135989450,85393697,2152923392,3896401662,2895836408,2145855233,3535335007,115294817,3147733898,1922296357,3464822751,4117858305,1037454084,2725193275,2127856640,1417604070,1148013728,1827919605,642362335,2929772533,909348033,1346338451,3547799649,297154785,1917849091,4161712827,2883604526,3968694238,1469521537,3780077382,3375584256,1763717519,136166297,4290970789,1295325189,2134727907,2798151366,1566297257,3672928234,2677174161,2672173615,965822077,2780786062,289653839,1133871874,3491843819,35685304,1068898316,418943774,672553190,642281022,2346158704,1954014401,3037126780,4079815205,2030668546,3840588673,672283427,1776201016,359975446,3750173538,555499703,2769985273,1324923,69110472,152125443,3176785106,3822147285,1340634837,798073664,1434183902,15393959,216384236,1303690150,3881221631,3711134124,3960975413,106373927,2578434224,1455997841,1801814300,1578393881,1854262133,3188178946,3258078583,2302670060,1539295533,3505142565,3078625975,2372746020,549938159,3278284284,2620926080,181285381,2865321098,3970029511,68876850,488006234,1728155692,2608167508,836007927,2435231793,919367643,3339422534,3655756360,1457871481,40520939,1380155135,797931188,234455205,2255801827,3990488299,397000196,739833055,3077865373,2871719860,4022553888,772369276,390177364,3853951029,557662966,740064294,1640166671,1699928825,3535942136,622006121,3625353122,68743880,1742502,219489963,1664179233,1577743084,1236991741,410585305,2366487942,823226535,1050371084,3426619607,3586839478,212779912,4147118561,1819446015,1911218849,530248558,3486241071,3252585495,2886188651,3410272728,2342195030,20547779,2982490058,3032363469,3631753222,312714466,1870521650,1493008054,3491686656,615382978,4103671749,2534517445,1932181,2196105170,278426614,6369430,3274544417,2913018367,697336853,2143000447,2946413531,701099306,1558357093,2805003052,3500818408,2321334417,3567135975,216290473,3591032198,23009561,1996984579,3735042806,2024298078,3739440863,569400510,2339758983,3016033873,3097871343,3639523026,3844324983,3256173865,795471839,2951117563,4101031090,4091603803,3603732598,971261452,534414648,428311343,3389027175,2844869880,694888862,1227866773,2456207019,3043454569,2614353370,3749578031,3676663836,459166190,4132644070,1794958188,51825668,2252611902,3084671440,2036672799,3436641603,1099053433,2469121526,3059204941,1323291266,2061838604,1018778475,2233344254,2553501054,334295216,3556750194,1065731521,183467730),f[4]=new Array(2127105028,745436345,2601412319,2788391185,3093987327,500390133,1155374404,389092991,150729210,3891597772,3523549952,1935325696,716645080,946045387,2901812282,1774124410,3869435775,4039581901,3293136918,3438657920,948246080,363898952,3867875531,1286266623,1598556673,68334250,630723836,1104211938,1312863373,613332731,2377784574,1101634306,441780740,3129959883,1917973735,2510624549,3238456535,2544211978,3308894634,1299840618,4076074851,1756332096,3977027158,297047435,3790297736,2265573040,3621810518,1311375015,1667687725,47300608,3299642885,2474112369,201668394,1468347890,576830978,3594690761,3742605952,1958042578,1747032512,3558991340,1408974056,3366841779,682131401,1033214337,1545599232,4265137049,206503691,103024618,2855227313,1337551222,2428998917,2963842932,4015366655,3852247746,2796956967,3865723491,3747938335,247794022,3755824572,702416469,2434691994,397379957,851939612,2314769512,218229120,1380406772,62274761,214451378,3170103466,2276210409,3845813286,28563499,446592073,1693330814,3453727194,29968656,3093872512,220656637,2470637031,77972100,1667708854,1358280214,4064765667,2395616961,325977563,4277240721,4220025399,3605526484,3355147721,811859167,3069544926,3962126810,652502677,3075892249,4132761541,3498924215,1217549313,3250244479,3858715919,3053989961,1538642152,2279026266,2875879137,574252750,3324769229,2651358713,1758150215,141295887,2719868960,3515574750,4093007735,4194485238,1082055363,3417560400,395511885,2966884026,179534037,3646028556,3738688086,1092926436,2496269142,257381841,3772900718,1636087230,1477059743,2499234752,3811018894,2675660129,3285975680,90732309,1684827095,1150307763,1723134115,3237045386,1769919919,1240018934,815675215,750138730,2239792499,1234303040,1995484674,138143821,675421338,1145607174,1936608440,3238603024,2345230278,2105974004,323969391,779555213,3004902369,2861610098,1017501463,2098600890,2628620304,2940611490,2682542546,1171473753,3656571411,3687208071,4091869518,393037935,159126506,1662887367,1147106178,391545844,3452332695,1891500680,3016609650,1851642611,546529401,1167818917,3194020571,2848076033,3953471836,575554290,475796850,4134673196,450035699,2351251534,844027695,1080539133,86184846,1554234488,3692025454,1972511363,2018339607,1491841390,1141460869,1061690759,4244549243,2008416118,2351104703,2868147542,1598468138,722020353,1027143159,212344630,1387219594,1725294528,3745187956,2500153616,458938280,4129215917,1828119673,544571780,3503225445,2297937496,1241802790,267843827,2694610800,1397140384,1558801448,3782667683,1806446719,929573330,2234912681,400817706,616011623,4121520928,3603768725,1761550015,1968522284,4053731006,4192232858,4005120285,872482584,3140537016,3894607381,2287405443,1963876937,3663887957,1584857e3,2975024454,1833426440,4025083860),f[5]=new Array(4143615901,749497569,1285769319,3795025788,2514159847,23610292,3974978748,844452780,3214870880,3751928557,2213566365,1676510905,448177848,3730751033,4086298418,2307502392,871450977,3222878141,4110862042,3831651966,2735270553,1310974780,2043402188,1218528103,2736035353,4274605013,2702448458,3936360550,2693061421,162023535,2827510090,687910808,23484817,3784910947,3371371616,779677500,3503626546,3473927188,4157212626,3500679282,4248902014,2466621104,3899384794,1958663117,925738300,1283408968,3669349440,1840910019,137959847,2679828185,1239142320,1315376211,1547541505,1690155329,739140458,3128809933,3933172616,3876308834,905091803,1548541325,4040461708,3095483362,144808038,451078856,676114313,2861728291,2469707347,993665471,373509091,2599041286,4025009006,4170239449,2149739950,3275793571,3749616649,2794760199,1534877388,572371878,2590613551,1753320020,3467782511,1405125690,4270405205,633333386,3026356924,3475123903,632057672,2846462855,1404951397,3882875879,3915906424,195638627,2385783745,3902872553,1233155085,3355999740,2380578713,2702246304,2144565621,3663341248,3894384975,2502479241,4248018925,3094885567,1594115437,572884632,3385116731,767645374,1331858858,1475698373,3793881790,3532746431,1321687957,619889600,1121017241,3440213920,2070816767,2833025776,1933951238,4095615791,890643334,3874130214,859025556,360630002,925594799,1764062180,3920222280,4078305929,979562269,2810700344,4087740022,1949714515,546639971,1165388173,3069891591,1495988560,922170659,1291546247,2107952832,1813327274,3406010024,3306028637,4241950635,153207855,2313154747,1608695416,1150242611,1967526857,721801357,1220138373,3691287617,3356069787,2112743302,3281662835,1111556101,1778980689,250857638,2298507990,673216130,2846488510,3207751581,3562756981,3008625920,3417367384,2198807050,529510932,3547516680,3426503187,2364944742,102533054,2294910856,1617093527,1204784762,3066581635,1019391227,1069574518,1317995090,1691889997,3661132003,510022745,3238594800,1362108837,1817929911,2184153760,805817662,1953603311,3699844737,120799444,2118332377,207536705,2282301548,4120041617,145305846,2508124933,3086745533,3261524335,1877257368,2977164480,3160454186,2503252186,4221677074,759945014,254147243,2767453419,3801518371,629083197,2471014217,907280572,3900796746,940896768,2751021123,2625262786,3161476951,3661752313,3260732218,1425318020,2977912069,1496677566,3988592072,2140652971,3126511541,3069632175,977771578,1392695845,1698528874,1411812681,1369733098,1343739227,3620887944,1142123638,67414216,3102056737,3088749194,1626167401,2546293654,3941374235,697522451,33404913,143560186,2595682037,994885535,1247667115,3859094837,2699155541,3547024625,4114935275,2968073508,3199963069,2732024527,1237921620,951448369,1898488916,1211705605,2790989240,2233243581,3598044975),f[6]=new Array(2246066201,858518887,1714274303,3485882003,713916271,2879113490,3730835617,539548191,36158695,1298409750,419087104,1358007170,749914897,2989680476,1261868530,2995193822,2690628854,3443622377,3780124940,3796824509,2976433025,4259637129,1551479e3,512490819,1296650241,951993153,2436689437,2460458047,144139966,3136204276,310820559,3068840729,643875328,1969602020,1680088954,2185813161,3283332454,672358534,198762408,896343282,276269502,3014846926,84060815,197145886,376173866,3943890818,3813173521,3545068822,1316698879,1598252827,2633424951,1233235075,859989710,2358460855,3503838400,3409603720,1203513385,1193654839,2792018475,2060853022,207403770,1144516871,3068631394,1121114134,177607304,3785736302,326409831,1929119770,2983279095,4183308101,3474579288,3200513878,3228482096,119610148,1170376745,3378393471,3163473169,951863017,3337026068,3135789130,2907618374,1183797387,2015970143,4045674555,2182986399,2952138740,3928772205,384012900,2454997643,10178499,2879818989,2596892536,111523738,2995089006,451689641,3196290696,235406569,1441906262,3890558523,3013735005,4158569349,1644036924,376726067,1006849064,3664579700,2041234796,1021632941,1374734338,2566452058,371631263,4007144233,490221539,206551450,3140638584,1053219195,1853335209,3412429660,3562156231,735133835,1623211703,3104214392,2738312436,4096837757,3366392578,3110964274,3956598718,3196820781,2038037254,3877786376,2339753847,300912036,3766732888,2372630639,1516443558,4200396704,1574567987,4069441456,4122592016,2699739776,146372218,2748961456,2043888151,35287437,2596680554,655490400,1132482787,110692520,1031794116,2188192751,1324057718,1217253157,919197030,686247489,3261139658,1028237775,3135486431,3059715558,2460921700,986174950,2661811465,4062904701,2752986992,3709736643,367056889,1353824391,731860949,1650113154,1778481506,784341916,357075625,3608602432,1074092588,2480052770,3811426202,92751289,877911070,3600361838,1231880047,480201094,3756190983,3094495953,434011822,87971354,363687820,1717726236,1901380172,3926403882,2481662265,400339184,1490350766,2661455099,1389319756,2558787174,784598401,1983468483,30828846,3550527752,2716276238,3841122214,1765724805,1955612312,1277890269,1333098070,1564029816,2704417615,1026694237,3287671188,1260819201,3349086767,1016692350,1582273796,1073413053,1995943182,694588404,1025494639,3323872702,3551898420,4146854327,453260480,1316140391,1435673405,3038941953,3486689407,1622062951,403978347,817677117,950059133,4246079218,3278066075,1486738320,1417279718,481875527,2549965225,3933690356,760697757,1452955855,3897451437,1177426808,1702951038,4085348628,2447005172,1084371187,3516436277,3068336338,1073369276,1027665953,3284188590,1230553676,1368340146,2226246512,267243139,2274220762,4070734279,2497715176,2423353163,2504755875),f[7]=new Array(3793104909,3151888380,2817252029,895778965,2005530807,3871412763,237245952,86829237,296341424,3851759377,3974600970,2475086196,709006108,1994621201,2972577594,937287164,3734691505,168608556,3189338153,2225080640,3139713551,3033610191,3025041904,77524477,185966941,1208824168,2344345178,1721625922,3354191921,1066374631,1927223579,1971335949,2483503697,1551748602,2881383779,2856329572,3003241482,48746954,1398218158,2050065058,313056748,4255789917,393167848,1912293076,940740642,3465845460,3091687853,2522601570,2197016661,1727764327,364383054,492521376,1291706479,3264136376,1474851438,1685747964,2575719748,1619776915,1814040067,970743798,1561002147,2925768690,2123093554,1880132620,3151188041,697884420,2550985770,2607674513,2659114323,110200136,1489731079,997519150,1378877361,3527870668,478029773,2766872923,1022481122,431258168,1112503832,897933369,2635587303,669726182,3383752315,918222264,163866573,3246985393,3776823163,114105080,1903216136,761148244,3571337562,1690750982,3166750252,1037045171,1888456500,2010454850,642736655,616092351,365016990,1185228132,4174898510,1043824992,2023083429,2241598885,3863320456,3279669087,3674716684,108438443,2132974366,830746235,606445527,4173263986,2204105912,1844756978,2532684181,4245352700,2969441100,3796921661,1335562986,4061524517,2720232303,2679424040,634407289,885462008,3294724487,3933892248,2094100220,339117932,4048830727,3202280980,1458155303,2689246273,1022871705,2464987878,3714515309,353796843,2822958815,4256850100,4052777845,551748367,618185374,3778635579,4020649912,1904685140,3069366075,2670879810,3407193292,2954511620,4058283405,2219449317,3135758300,1120655984,3447565834,1474845562,3577699062,550456716,3466908712,2043752612,881257467,869518812,2005220179,938474677,3305539448,3850417126,1315485940,3318264702,226533026,965733244,321539988,1136104718,804158748,573969341,3708209826,937399083,3290727049,2901666755,1461057207,4013193437,4066861423,3242773476,2421326174,1581322155,3028952165,786071460,3900391652,3918438532,1485433313,4023619836,3708277595,3678951060,953673138,1467089153,1930354364,1533292819,2492563023,1346121658,1685000834,1965281866,3765933717,4190206607,2052792609,3515332758,690371149,3125873887,2180283551,2903598061,3933952357,436236910,289419410,14314871,1242357089,2904507907,1616633776,2666382180,585885352,3471299210,2699507360,1432659641,277164553,3354103607,770115018,2303809295,3741942315,3177781868,2853364978,2269453327,3774259834,987383833,1290892879,225909803,1741533526,890078084,1496906255,1111072499,916028167,243534141,1252605537,2204162171,531204876,290011180,3916834213,102027703,237315147,209093447,1486785922,220223953,2758195998,4175039106,82940208,3127791296,2569425252,518464269,1353887104,3941492737,2377294467,3935040926)}function e(a){this.cast5=new d,this.cast5.setKey(f.str2bin(a)),this.encrypt=function(a){return this.cast5.encrypt(a)}}var f=a("../../util.js");b.exports=e,b.exports.blockSize=e.prototype.blockSize=8,b.exports.keySize=e.prototype.keySize=16},{"../../util.js":76}],22:[function(a,b,c){"use strict";function d(a,b,c,d,e,h){var i,j,k,l,m,n,o,p,q,r,s,t,u,v,w=new Array(16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756),x=new Array(-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344),y=new Array(520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584),z=new Array(8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928),A=new Array(256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080),B=new Array(536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312),C=new Array(2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154),D=new Array(268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696),E=0,F=b.length,G=0,H=32==a.length?3:9; -p=3==H?c?new Array(0,32,2):new Array(30,-2,-2):c?new Array(0,32,2,62,30,-2,64,96,2):new Array(94,62,-2,32,64,2,30,-2,-2),c&&(b=f(b,h),F=b.length);var I="",J="";for(1==d&&(q=e.charCodeAt(E++)<<24|e.charCodeAt(E++)<<16|e.charCodeAt(E++)<<8|e.charCodeAt(E++),s=e.charCodeAt(E++)<<24|e.charCodeAt(E++)<<16|e.charCodeAt(E++)<<8|e.charCodeAt(E++),E=0);F>E;){for(n=b.charCodeAt(E++)<<24|b.charCodeAt(E++)<<16|b.charCodeAt(E++)<<8|b.charCodeAt(E++),o=b.charCodeAt(E++)<<24|b.charCodeAt(E++)<<16|b.charCodeAt(E++)<<8|b.charCodeAt(E++),1==d&&(c?(n^=q,o^=s):(r=q,t=s,q=n,s=o)),k=252645135&(n>>>4^o),o^=k,n^=k<<4,k=65535&(n>>>16^o),o^=k,n^=k<<16,k=858993459&(o>>>2^n),n^=k,o^=k<<2,k=16711935&(o>>>8^n),n^=k,o^=k<<8,k=1431655765&(n>>>1^o),o^=k,n^=k<<1,n=n<<1|n>>>31,o=o<<1|o>>>31,j=0;H>j;j+=3){for(u=p[j+1],v=p[j+2],i=p[j];i!=u;i+=v)l=o^a[i],m=(o>>>4|o<<28)^a[i+1],k=n,n=o,o=k^(x[l>>>24&63]|z[l>>>16&63]|B[l>>>8&63]|D[63&l]|w[m>>>24&63]|y[m>>>16&63]|A[m>>>8&63]|C[63&m]);k=n,n=o,o=k}n=n>>>1|n<<31,o=o>>>1|o<<31,k=1431655765&(n>>>1^o),o^=k,n^=k<<1,k=16711935&(o>>>8^n),n^=k,o^=k<<8,k=858993459&(o>>>2^n),n^=k,o^=k<<2,k=65535&(n>>>16^o),o^=k,n^=k<<16,k=252645135&(n>>>4^o),o^=k,n^=k<<4,1==d&&(c?(q=n,s=o):(n^=r,o^=t)),J+=String.fromCharCode(n>>>24,n>>>16&255,n>>>8&255,255&n,o>>>24,o>>>16&255,o>>>8&255,255&o),G+=8,512==G&&(I+=J,J="",G=0)}return I+=J,c||(I=g(I,h)),I}function e(a){for(var b,c,d,e=new Array(0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964),f=new Array(0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697),g=new Array(0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272),h=new Array(0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144),i=new Array(0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256),j=new Array(0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488),k=new Array(0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746),l=new Array(0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568),m=new Array(0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578),n=new Array(0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488),o=new Array(0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800),p=new Array(0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744),q=new Array(0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128),r=new Array(0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261),s=a.length>8?3:1,t=new Array(32*s),u=new Array(0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0),v=0,w=0,x=0;s>x;x++){var y=a.charCodeAt(v++)<<24|a.charCodeAt(v++)<<16|a.charCodeAt(v++)<<8|a.charCodeAt(v++),z=a.charCodeAt(v++)<<24|a.charCodeAt(v++)<<16|a.charCodeAt(v++)<<8|a.charCodeAt(v++);d=252645135&(y>>>4^z),z^=d,y^=d<<4,d=65535&(z>>>-16^y),y^=d,z^=d<<-16,d=858993459&(y>>>2^z),z^=d,y^=d<<2,d=65535&(z>>>-16^y),y^=d,z^=d<<-16,d=1431655765&(y>>>1^z),z^=d,y^=d<<1,d=16711935&(z>>>8^y),y^=d,z^=d<<8,d=1431655765&(y>>>1^z),z^=d,y^=d<<1,d=y<<8|z>>>20&240,y=z<<24|z<<8&16711680|z>>>8&65280|z>>>24&240,z=d;for(var A=0;A>>26,z=z<<2|z>>>26):(y=y<<1|y>>>27,z=z<<1|z>>>27),y&=-15,z&=-15,b=e[y>>>28]|f[y>>>24&15]|g[y>>>20&15]|h[y>>>16&15]|i[y>>>12&15]|j[y>>>8&15]|k[y>>>4&15],c=l[z>>>28]|m[z>>>24&15]|n[z>>>20&15]|o[z>>>16&15]|p[z>>>12&15]|q[z>>>8&15]|r[z>>>4&15],d=65535&(c>>>16^b),t[w++]=b^d,t[w++]=c^d<<16}return t}function f(a,b){var c=8-a.length%8;return 2==b&&8>c?a+=" ".substr(0,c):1==b?a+=String.fromCharCode(c,c,c,c,c,c,c,c).substr(0,c):!b&&8>c&&(a+="\x00\x00\x00\x00\x00\x00\x00\x00".substr(0,c)),a}function g(a,b){if(2==b)a=a.replace(/ *$/g,"");else if(1==b){var c=a.charCodeAt(a.length-1);a=a.substr(0,a.length-c)}else b||(a=a.replace(/\0*$/g,""));return a}function h(a){this.key=[];for(var b=0;3>b;b++)this.key.push(a.substr(8*b,8));this.encrypt=function(a){return j.str2bin(d(e(this.key[2]),d(e(this.key[1]),d(e(this.key[0]),j.bin2str(a),!0,0,null,null),!1,0,null,null),!0,0,null,null))}}function i(a){this.key=a,this.encrypt=function(a,b){var c=e(this.key);return j.str2bin(d(c,j.bin2str(a),!0,0,null,b))},this.decrypt=function(a,b){var c=e(this.key);return j.str2bin(d(c,j.bin2str(a),!1,0,null,b))}}var j=a("../../util.js");h.keySize=h.prototype.keySize=24,h.blockSize=h.prototype.blockSize=8,b.exports={des:h,originalDes:i}},{"../../util.js":76}],23:[function(a,b,c){var d=a("./des.js");b.exports={des:d.originalDes,tripledes:d.des,cast5:a("./cast5.js"),twofish:a("./twofish.js"),blowfish:a("./blowfish.js"),idea:function(){throw new Error("IDEA symmetric-key algorithm not implemented")}};var e=a("./aes.js");for(var f in e)b.exports["aes"+f]=e[f]},{"./aes.js":19,"./blowfish.js":20,"./cast5.js":21,"./des.js":22,"./twofish.js":24}],24:[function(a,b,c){function d(a,b){return(a<>>32-b)&k}function e(a,b){return a[b]|a[b+1]<<8|a[b+2]<<16|a[b+3]<<24}function f(a,b,c){a.splice(b,4,255&c,c>>>8&255,c>>>16&255,c>>>24&255)}function g(a,b){return a>>>8*b&255}function h(){function a(a){function b(a){return a^a>>2^[0,90,180,238][3&a]}function c(a){return a^a>>1^a>>2^[0,238,180,90][3&a]}function f(a,b){var c,d,e;for(c=0;8>c;c++)d=b>>>24,b=b<<8&k|a>>>24,a=a<<8&k,e=d<<1,128&d&&(e^=333),b^=d^e<<16,e^=d>>>1,1&d&&(e^=166),b^=e<<24|e<<8;return b}function h(a,b){var c,d,e,f;return c=b>>4,d=15&b,e=A[a][c^d],f=B[a][E[d]^F[c]],D[a][E[f]^F[e]]<<4|C[a][e^f]}function i(a,b){var c=g(a,0),d=g(a,1),e=g(a,2),f=g(a,3);switch(q){case 4:c=G[1][c]^g(b[3],0),d=G[0][d]^g(b[3],1),e=G[0][e]^g(b[3],2),f=G[1][f]^g(b[3],3);case 3:c=G[1][c]^g(b[2],0),d=G[1][d]^g(b[2],1),e=G[0][e]^g(b[2],2),f=G[0][f]^g(b[2],3);case 2:c=G[0][G[0][c]^g(b[1],0)]^g(b[0],0),d=G[0][G[1][d]^g(b[1],1)]^g(b[0],1),e=G[1][G[0][e]^g(b[1],2)]^g(b[0],2),f=G[1][G[1][f]^g(b[1],3)]^g(b[0],3)}return H[0][c]^H[1][d]^H[2][e]^H[3][f]}o=a;var j,l,m,n,p,q,r,u,v,w=[],x=[],y=[],z=[],A=[[8,1,7,13,6,15,3,2,0,11,5,9,14,12,10,4],[2,8,11,13,15,7,6,14,3,1,9,4,0,10,12,5]],B=[[14,12,11,8,1,2,3,5,15,4,10,6,7,0,9,13],[1,14,2,11,4,12,3,7,6,13,10,5,15,9,0,8]],C=[[11,10,5,14,6,13,9,0,12,8,15,3,2,4,7,1],[4,12,7,5,1,6,9,10,0,14,13,8,2,11,3,15]],D=[[13,7,15,4,1,2,6,14,9,11,3,0,8,5,12,10],[11,9,5,1,12,3,13,14,6,4,7,15,2,0,8,10]],E=[0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15],F=[0,9,2,11,4,13,6,15,8,1,10,3,12,5,14,7],G=[[],[]],H=[[],[],[],[]];for(o=o.slice(0,32),j=o.length;16!=j&&24!=j&&32!=j;)o[j++]=0;for(j=0;j>2]=e(o,j);for(j=0;256>j;j++)G[0][j]=h(0,j),G[1][j]=h(1,j);for(j=0;256>j;j++)r=G[1][j],u=b(r),v=c(r),H[0][j]=r+(u<<8)+(v<<16)+(v<<24),H[2][j]=u+(v<<8)+(r<<16)+(v<<24),r=G[0][j],u=b(r),v=c(r),H[1][j]=v+(v<<8)+(u<<16)+(r<<24),H[3][j]=u+(r<<8)+(v<<16)+(u<<24);for(q=y.length/2,j=0;q>j;j++)l=y[j+j],w[j]=l,m=y[j+j+1],x[j]=m,z[q-j-1]=f(l,m);for(j=0;40>j;j+=2)l=16843009*j,m=l+16843009,l=i(l,w),m=d(i(m,x),8),s[j]=l+m&k,s[j+1]=d(l+2*m,9);for(j=0;256>j;j++)switch(l=m=n=p=j,q){case 4:l=G[1][l]^g(z[3],0),m=G[0][m]^g(z[3],1),n=G[0][n]^g(z[3],2),p=G[1][p]^g(z[3],3);case 3:l=G[1][l]^g(z[2],0),m=G[1][m]^g(z[2],1),n=G[0][n]^g(z[2],2),p=G[0][p]^g(z[2],3);case 2:t[0][j]=H[0][G[0][G[0][l]^g(z[1],0)]^g(z[0],0)],t[1][j]=H[1][G[0][G[1][m]^g(z[1],1)]^g(z[0],1)],t[2][j]=H[2][G[1][G[0][n]^g(z[1],2)]^g(z[0],2)],t[3][j]=H[3][G[1][G[1][p]^g(z[1],3)]^g(z[0],3)]}}function b(a){return t[0][g(a,0)]^t[1][g(a,1)]^t[2][g(a,2)]^t[3][g(a,3)]}function c(a){return t[0][g(a,3)]^t[1][g(a,0)]^t[2][g(a,1)]^t[3][g(a,2)]}function h(a,e){var f=b(e[0]),g=c(e[1]);e[2]=d(e[2]^f+g+s[4*a+8]&k,31),e[3]=d(e[3],1)^f+2*g+s[4*a+9]&k,f=b(e[2]),g=c(e[3]),e[0]=d(e[0]^f+g+s[4*a+10]&k,31),e[1]=d(e[1],1)^f+2*g+s[4*a+11]&k}function i(a,e){var f=b(e[0]),g=c(e[1]);e[2]=d(e[2],1)^f+g+s[4*a+10]&k,e[3]=d(e[3]^f+2*g+s[4*a+11]&k,31),f=b(e[2]),g=c(e[3]),e[0]=d(e[0],1)^f+g+s[4*a+8]&k,e[1]=d(e[1]^f+2*g+s[4*a+9]&k,31)}function j(){s=[],t=[[],[],[],[]]}function l(a,b){p=a,q=b;for(var c=[e(p,q)^s[0],e(p,q+4)^s[1],e(p,q+8)^s[2],e(p,q+12)^s[3]],d=0;8>d;d++)h(d,c);return f(p,q,c[2]^s[4]),f(p,q+4,c[3]^s[5]),f(p,q+8,c[0]^s[6]),f(p,q+12,c[1]^s[7]),q+=16,p}function m(a,b){p=a,q=b;for(var c=[e(p,q)^s[4],e(p,q+4)^s[5],e(p,q+8)^s[6],e(p,q+12)^s[7]],d=7;d>=0;d--)i(d,c);f(p,q,c[2]^s[0]),f(p,q+4,c[3]^s[1]),f(p,q+8,c[0]^s[2]),f(p,q+12,c[1]^s[3]),q+=16}function n(){return p}var o=null,p=null,q=-1,r=null;r="twofish";var s=[],t=[[],[],[],[]];return{name:"twofish",blocksize:16,open:a,close:j,encrypt:l,decrypt:m,finalize:n}}function i(a){this.tf=h(),this.tf.open(l.str2bin(a),0),this.encrypt=function(a){return this.tf.encrypt(j(a),0)}}function j(a){for(var b=[],c=0;c=64;){for(k=0;16>k;++k)b[k]=c.getInt32();for(;64>k;++k)d=b[k-2],d=(d>>>17|d<<15)^(d>>>19|d<<13)^d>>>10,e=b[k-15],e=(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,b[k]=d+b[k-7]+e+b[k-16]&4294967295;for(l=a.h0,m=a.h1,n=a.h2,o=a.h3,p=a.h4,q=a.h5,r=a.h6,s=a.h7,k=0;64>k;++k)g=(p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7),i=r^p&(q^r),f=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),j=l&m|n&(l^m),d=s+g+i+h[k]+b[k],e=f+j,s=r,r=q,q=p,p=o+d&4294967295,o=n,n=m,m=l,l=d+e&4294967295;a.h0=a.h0+l&4294967295,a.h1=a.h1+m&4294967295,a.h2=a.h2+n&4294967295,a.h3=a.h3+o&4294967295,a.h4=a.h4+p&4294967295,a.h5=a.h5+q&4294967295,a.h6=a.h6+r&4294967295,a.h7=a.h7+s&4294967295,t-=64}};d.create=function(){g||i();var a=null,b=e.createBuffer(),c=new Array(64),d={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0};return d.start=function(){return d.messageLength=0,b=e.createBuffer(),a={h0:1779033703,h1:3144134277,h2:1013904242,h3:2773480762,h4:1359893119,h5:2600822924,h6:528734635,h7:1541459225},d},d.start(),d.update=function(f,g){return"utf8"===g&&(f=e.encodeUtf8(f)),d.messageLength+=f.length,b.putBytes(f),j(a,c,b),(b.read>2048||0===b.length())&&b.compact(),d},d.digest=function(){var g=d.messageLength,h=e.createBuffer();h.putBytes(b.bytes()),h.putBytes(f.substr(0,64-(g+8)%64)),h.putInt32(g>>>29&255),h.putInt32(g<<3&4294967295);var i={h0:a.h0,h1:a.h1,h2:a.h2,h3:a.h3,h4:a.h4,h5:a.h5,h6:a.h6,h7:a.h7};j(i,c,h);var k=e.createBuffer();return k.putInt32(i.h0),k.putInt32(i.h1),k.putInt32(i.h2),k.putInt32(i.h3),k.putInt32(i.h4),k.putInt32(i.h5),k.putInt32(i.h6),k.putInt32(i.h7),k},d}},{"./forge_util.js":27}],27:[function(a,b,c){var d=b.exports={};d.isArray=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},d.isArrayBuffer=function(a){return"undefined"!=typeof ArrayBuffer&&a instanceof ArrayBuffer};var e=[];"undefined"!=typeof Int8Array&&e.push(Int8Array),"undefined"!=typeof Uint8Array&&e.push(Uint8Array),"undefined"!=typeof Uint8ClampedArray&&e.push(Uint8ClampedArray),"undefined"!=typeof Int16Array&&e.push(Int16Array),"undefined"!=typeof Uint16Array&&e.push(Uint16Array),"undefined"!=typeof Int32Array&&e.push(Int32Array),"undefined"!=typeof Uint32Array&&e.push(Uint32Array),"undefined"!=typeof Float32Array&&e.push(Float32Array),"undefined"!=typeof Float64Array&&e.push(Float64Array),d.isArrayBufferView=function(a){for(var b=0;b0;)1&b&&(c+=a),b>>>=1,b>0&&(a+=a);return this.data=c,this},d.ByteBuffer.prototype.putBytes=function(a){return this.data+=a,this},d.ByteBuffer.prototype.putString=function(a){return this.data+=d.encodeUtf8(a),this},d.ByteBuffer.prototype.putInt16=function(a){return this.data+=String.fromCharCode(a>>8&255)+String.fromCharCode(255&a),this},d.ByteBuffer.prototype.putInt24=function(a){return this.data+=String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(255&a),this},d.ByteBuffer.prototype.putInt32=function(a){return this.data+=String.fromCharCode(a>>24&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(255&a),this},d.ByteBuffer.prototype.putInt16Le=function(a){return this.data+=String.fromCharCode(255&a)+String.fromCharCode(a>>8&255),this},d.ByteBuffer.prototype.putInt24Le=function(a){return this.data+=String.fromCharCode(255&a)+String.fromCharCode(a>>8&255)+String.fromCharCode(a>>16&255),this},d.ByteBuffer.prototype.putInt32Le=function(a){return this.data+=String.fromCharCode(255&a)+String.fromCharCode(a>>8&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>24&255),this},d.ByteBuffer.prototype.putInt=function(a,b){do b-=8,this.data+=String.fromCharCode(a>>b&255);while(b>0);return this},d.ByteBuffer.prototype.putSignedInt=function(a,b){return 0>a&&(a+=2<0);return b},d.ByteBuffer.prototype.getSignedInt=function(a){var b=this.getInt(a),c=2<=c&&(b-=c<<1),b},d.ByteBuffer.prototype.getBytes=function(a){var b;return a?(a=Math.min(this.length(),a),b=this.data.slice(this.read,this.read+a),this.read+=a):0===a?b="":(b=0===this.read?this.data:this.data.slice(this.read),this.clear()),b},d.ByteBuffer.prototype.bytes=function(a){return"undefined"==typeof a?this.data.slice(this.read):this.data.slice(this.read,this.read+a)},d.ByteBuffer.prototype.at=function(a){return this.data.charCodeAt(this.read+a)},d.ByteBuffer.prototype.setAt=function(a,b){return this.data=this.data.substr(0,this.read+a)+String.fromCharCode(b)+this.data.substr(this.read+a+1),this},d.ByteBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},d.ByteBuffer.prototype.copy=function(){var a=d.createBuffer(this.data);return a.read=this.read,a},d.ByteBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},d.ByteBuffer.prototype.clear=function(){return this.data="",this.read=0,this},d.ByteBuffer.prototype.truncate=function(a){var b=Math.max(0,this.length()-a);return this.data=this.data.substr(this.read,b),this.read=0,this},d.ByteBuffer.prototype.toHex=function(){for(var a="",b=this.read;bc&&(a+="0"),a+=c.toString(16)}return a},d.ByteBuffer.prototype.toString=function(){return d.decodeUtf8(this.bytes())},d.createBuffer=function(a,b){return b=b||"raw",void 0!==a&&"utf8"===b&&(a=d.encodeUtf8(a)),new d.ByteBuffer(a)},d.fillString=function(a,b){for(var c="";b>0;)1&b&&(c+=a),b>>>=1,b>0&&(a+=a);return c},d.xorBytes=function(a,b,c){for(var d="",e="",f="",g=0,h=0;c>0;--c,++g)e=a.charCodeAt(g)^b.charCodeAt(g),h>=10&&(d+=f,f="",h=0),f+=String.fromCharCode(e),++h;return d+=f},d.hexToBytes=function(a){var b="",c=0;for(a.length&!0&&(c=1,b+=String.fromCharCode(parseInt(a[0],16)));c>24&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(255&a)};var f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",g=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51];d.encode64=function(a,b){for(var c,d,e,g="",h="",i=0;i>2),g+=f.charAt((3&c)<<4|d>>4),isNaN(d)?g+="==":(g+=f.charAt((15&d)<<2|e>>6),g+=isNaN(e)?"=":f.charAt(63&e)),b&&g.length>b&&(h+=g.substr(0,b)+"\r\n",g=g.substr(b));return h+=g},d.decode64=function(a){a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var b,c,d,e,f="",h=0;h>4),64!==d&&(f+=String.fromCharCode((15&c)<<4|d>>2),64!==e&&(f+=String.fromCharCode((3&d)<<6|e)));return f},d.encodeUtf8=function(a){return unescape(encodeURIComponent(a))},d.decodeUtf8=function(a){return decodeURIComponent(escape(a))}},{}],28:[function(a,b,c){var d=a("./sha.js"),e=a("./forge_sha256.js");b.exports={md5:a("./md5.js"),sha1:d.sha1,sha224:d.sha224,sha256:d.sha256,sha384:d.sha384,sha512:d.sha512,ripemd:a("./ripe-md.js"),digest:function(a,b){switch(a){case 1:return this.md5(b);case 2:return this.sha1(b);case 3:return this.ripemd(b);case 8:var c=e.create();return c.update(b),c.digest().getBytes();case 9:return this.sha384(b);case 10:return this.sha512(b);case 11:return this.sha224(b);default:throw new Error("Invalid hash function.")}},getHashByteLength:function(a){switch(a){case 1:return 16;case 2:case 3:return 20;case 8:return 32;case 9:return 48;case 10:return 64;case 11:return 28;default:throw new Error("Invalid hash algorithm.")}}}},{"./forge_sha256.js":26,"./md5.js":29,"./ripe-md.js":30,"./sha.js":31}],29:[function(a,b,c){function d(a,b){var c=a[0],d=a[1],e=a[2],j=a[3];c=f(c,d,e,j,b[0],7,-680876936),j=f(j,c,d,e,b[1],12,-389564586),e=f(e,j,c,d,b[2],17,606105819),d=f(d,e,j,c,b[3],22,-1044525330),c=f(c,d,e,j,b[4],7,-176418897),j=f(j,c,d,e,b[5],12,1200080426),e=f(e,j,c,d,b[6],17,-1473231341),d=f(d,e,j,c,b[7],22,-45705983),c=f(c,d,e,j,b[8],7,1770035416),j=f(j,c,d,e,b[9],12,-1958414417),e=f(e,j,c,d,b[10],17,-42063),d=f(d,e,j,c,b[11],22,-1990404162),c=f(c,d,e,j,b[12],7,1804603682),j=f(j,c,d,e,b[13],12,-40341101),e=f(e,j,c,d,b[14],17,-1502002290),d=f(d,e,j,c,b[15],22,1236535329),c=g(c,d,e,j,b[1],5,-165796510),j=g(j,c,d,e,b[6],9,-1069501632),e=g(e,j,c,d,b[11],14,643717713),d=g(d,e,j,c,b[0],20,-373897302),c=g(c,d,e,j,b[5],5,-701558691),j=g(j,c,d,e,b[10],9,38016083),e=g(e,j,c,d,b[15],14,-660478335),d=g(d,e,j,c,b[4],20,-405537848),c=g(c,d,e,j,b[9],5,568446438),j=g(j,c,d,e,b[14],9,-1019803690),e=g(e,j,c,d,b[3],14,-187363961),d=g(d,e,j,c,b[8],20,1163531501),c=g(c,d,e,j,b[13],5,-1444681467),j=g(j,c,d,e,b[2],9,-51403784),e=g(e,j,c,d,b[7],14,1735328473),d=g(d,e,j,c,b[12],20,-1926607734),c=h(c,d,e,j,b[5],4,-378558),j=h(j,c,d,e,b[8],11,-2022574463),e=h(e,j,c,d,b[11],16,1839030562),d=h(d,e,j,c,b[14],23,-35309556),c=h(c,d,e,j,b[1],4,-1530992060),j=h(j,c,d,e,b[4],11,1272893353),e=h(e,j,c,d,b[7],16,-155497632),d=h(d,e,j,c,b[10],23,-1094730640),c=h(c,d,e,j,b[13],4,681279174),j=h(j,c,d,e,b[0],11,-358537222),e=h(e,j,c,d,b[3],16,-722521979),d=h(d,e,j,c,b[6],23,76029189),c=h(c,d,e,j,b[9],4,-640364487),j=h(j,c,d,e,b[12],11,-421815835),e=h(e,j,c,d,b[15],16,530742520),d=h(d,e,j,c,b[2],23,-995338651),c=i(c,d,e,j,b[0],6,-198630844),j=i(j,c,d,e,b[7],10,1126891415),e=i(e,j,c,d,b[14],15,-1416354905),d=i(d,e,j,c,b[5],21,-57434055),c=i(c,d,e,j,b[12],6,1700485571),j=i(j,c,d,e,b[3],10,-1894986606),e=i(e,j,c,d,b[10],15,-1051523),d=i(d,e,j,c,b[1],21,-2054922799),c=i(c,d,e,j,b[8],6,1873313359),j=i(j,c,d,e,b[15],10,-30611744),e=i(e,j,c,d,b[6],15,-1560198380),d=i(d,e,j,c,b[13],21,1309151649),c=i(c,d,e,j,b[4],6,-145523070),j=i(j,c,d,e,b[11],10,-1120210379),e=i(e,j,c,d,b[2],15,718787259),d=i(d,e,j,c,b[9],21,-343485551),a[0]=o(c,a[0]),a[1]=o(d,a[1]),a[2]=o(e,a[2]),a[3]=o(j,a[3])}function e(a,b,c,d,e,f){return b=o(o(b,a),o(d,f)),o(b<>>32-e,c)}function f(a,b,c,d,f,g,h){return e(b&c|~b&d,a,b,f,g,h)}function g(a,b,c,d,f,g,h){return e(b&d|c&~d,a,b,f,g,h)}function h(a,b,c,d,f,g,h){return e(b^c^d,a,b,f,g,h)}function i(a,b,c,d,f,g,h){return e(c^(b|~d),a,b,f,g,h)}function j(a){var b,c=a.length,e=[1732584193,-271733879,-1732584194,271733878];for(b=64;b<=a.length;b+=64)d(e,k(a.substring(b-64,b)));a=a.substring(b-64);var f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(b=0;b>2]|=a.charCodeAt(b)<<(b%4<<3);if(f[b>>2]|=128<<(b%4<<3),b>55)for(d(e,f),b=0;16>b;b++)f[b]=0;return f[14]=8*c,d(e,f),e}function k(a){var b,c=[];for(b=0;64>b;b+=4)c[b>>2]=a.charCodeAt(b)+(a.charCodeAt(b+1)<<8)+(a.charCodeAt(b+2)<<16)+(a.charCodeAt(b+3)<<24);return c}function l(a){for(var b="",c=0;4>c;c++)b+=q[a>>8*c+4&15]+q[a>>8*c&15];return b}function m(a){for(var b=0;b>16)+(b>>16)+(c>>16);return d<<16|65535&c}var p=a("../../util.js");b.exports=function(a){var b=n(a),c=p.hex2bin(b);return c};var q="0123456789abcdef".split("");"5d41402abc4b2a76b9719d911017c592"!=n("hello")},{"../../util.js":76}],30:[function(a,b,c){function d(a,b){return new Number(a<>>32-b)}function e(a,b,c){return new Number(a^b^c)}function f(a,b,c){return new Number(a&b|~a&c)}function g(a,b,c){return new Number((a|~b)^c)}function h(a,b,c){return new Number(a&c|b&~c)}function i(a,b,c){return new Number(a^(b|~c))}function j(a,b,c,j,k,l,m,n){switch(n){case 0:a+=e(b,c,j)+l+0;break;case 1:a+=f(b,c,j)+l+1518500249;break;case 2:a+=g(b,c,j)+l+1859775393;break;case 3:a+=h(b,c,j)+l+2400959708;break;case 4:a+=i(b,c,j)+l+2840853838;break;case 5:a+=i(b,c,j)+l+1352829926;break;case 6:a+=h(b,c,j)+l+1548603684;break;case 7:a+=g(b,c,j)+l+1836072691;break;case 8:a+=f(b,c,j)+l+2053994217;break;case 9:a+=e(b,c,j)+l+0;break;default:throw new Error("Bogus round number")}a=d(a,m)+k,c=d(c,10),a&=4294967295,b&=4294967295,c&=4294967295,j&=4294967295,k&=4294967295;var o=[];return o[0]=a,o[1]=b,o[2]=c,o[3]=j,o[4]=k,o[5]=l,o[6]=m,o}function k(a){a[0]=1732584193,a[1]=4023233417,a[2]=2562383102,a[3]=271733878,a[4]=3285377520}function l(a,b){var c,d,e,f=[],g=[];for(d=0;5>d;d++)f[d]=new Number(a[d]),g[d]=new Number(a[d]);var h=0;for(e=0;5>e;e++)for(d=0;16>d;d++)c=j(f[(h+0)%5],f[(h+1)%5],f[(h+2)%5],f[(h+3)%5],f[(h+4)%5],b[t[e][d]],s[e][d],e),f[(h+0)%5]=c[0],f[(h+1)%5]=c[1],f[(h+2)%5]=c[2],f[(h+3)%5]=c[3],f[(h+4)%5]=c[4],h+=4;for(h=0,e=5;10>e;e++)for(d=0;16>d;d++)c=j(g[(h+0)%5],g[(h+1)%5],g[(h+2)%5],g[(h+3)%5],g[(h+4)%5],b[t[e][d]],s[e][d],e),g[(h+0)%5]=c[0],g[(h+1)%5]=c[1],g[(h+2)%5]=c[2],g[(h+3)%5]=c[3],g[(h+4)%5]=c[4],h+=4;g[3]+=f[2]+a[1],a[1]=a[2]+f[3]+g[4],a[2]=a[3]+f[4]+g[0],a[3]=a[4]+f[0]+g[1],a[4]=a[0]+f[1]+g[2],a[0]=g[3]}function m(a){for(var b=0;16>b;b++)a[b]=0}function n(a,b,c,d){var e=new Array(16);m(e);for(var f=0,g=0;(63&c)>g;g++)e[g>>>2]^=(255&b.charCodeAt(f++))<<8*(3&g);e[c>>>2&15]^=1<<8*(3&c)+7,(63&c)>55&&(l(a,e),e=new Array(16),m(e)),e[14]=c<<3,e[15]=c>>>29|d<<3,l(a,e)}function o(a){var b=(255&a.charCodeAt(3))<<24;return b|=(255&a.charCodeAt(2))<<16,b|=(255&a.charCodeAt(1))<<8,b|=255&a.charCodeAt(0)}function p(a){var b,c,d=new Array(r/32),e=new Array(r/8);k(d),b=a.length;var f=new Array(16);m(f);var g,h=0;for(c=b;c>63;c-=64){for(g=0;16>g;g++)f[g]=o(a.substr(h,4)),h+=4;l(d,f)}for(n(d,a.substr(h),b,0),g=0;r/8>g;g+=4)e[g]=255&d[g>>>2],e[g+1]=d[g>>>2]>>>8&255,e[g+2]=d[g>>>2]>>>16&255,e[g+3]=d[g>>>2]>>>24&255;return e}function q(a){for(var b=p(a),c="",d=0;r/8>d;d++)c+=String.fromCharCode(b[d]);return c}var r=160,s=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12],[11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5],[11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12],[9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6],[9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11],[9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5],[15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8],[8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]],t=[[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],[7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8],[3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12],[1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2],[4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12],[6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2],[15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13],[8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14],[12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]];b.exports=q},{}],31:[function(a,b,c){var d=function(){var a=8,b="",c=0,d=function(a,b){this.highOrder=a,this.lowOrder=b},e=function(b){var c,d=[],e=(1<c;c+=a)d[c>>5]|=(b.charCodeAt(c/a)&e)<<32-a-c%32;return d},f=function(a){var b,c,d=[],e=a.length;for(b=0;e>b;b+=2){if(c=parseInt(a.substr(b,2),16),isNaN(c))throw new Error("INVALID HEX STRING");d[b>>3]|=c<<24-4*(b%8)}return d},g=function(a){var b,d,e=c?"0123456789ABCDEF":"0123456789abcdef",f="",g=4*a.length;for(b=0;g>b;b+=1)d=a[b>>2]>>8*(3-b%4),f+=e.charAt(d>>4&15)+e.charAt(15&d);return f},h=function(a){var c,d,e,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",g="",h=4*a.length;for(c=0;h>c;c+=3)for(e=(a[c>>2]>>8*(3-c%4)&255)<<16|(a[c+1>>2]>>8*(3-(c+1)%4)&255)<<8|a[c+2>>2]>>8*(3-(c+2)%4)&255,d=0;4>d;d+=1)g+=8*c+6*d<=32*a.length?f.charAt(e>>6*(3-d)&63):b;return g},i=function(a){for(var b="",c=255,d=0;d<32*a.length;d+=8)b+=String.fromCharCode(a[d>>5]>>>24-d%32&c);return b},j=function(a,b){return a<>>32-b},k=function(a,b){return a>>>b|a<<32-b},l=function(a,b){return 32>=b?new d(a.highOrder>>>b|a.lowOrder<<32-b,a.lowOrder>>>b|a.highOrder<<32-b):new d(a.lowOrder>>>b|a.highOrder<<32-b,a.highOrder>>>b|a.lowOrder<<32-b)},m=function(a,b){return a>>>b},n=function(a,b){return 32>=b?new d(a.highOrder>>>b,a.lowOrder>>>b|a.highOrder<<32-b):new d(0,a.highOrder<<32-b)},o=function(a,b,c){return a^b^c},p=function(a,b,c){return a&b^~a&c},q=function(a,b,c){return new d(a.highOrder&b.highOrder^~a.highOrder&c.highOrder,a.lowOrder&b.lowOrder^~a.lowOrder&c.lowOrder)},r=function(a,b,c){return a&b^a&c^b&c},s=function(a,b,c){return new d(a.highOrder&b.highOrder^a.highOrder&c.highOrder^b.highOrder&c.highOrder,a.lowOrder&b.lowOrder^a.lowOrder&c.lowOrder^b.lowOrder&c.lowOrder)},t=function(a){return k(a,2)^k(a,13)^k(a,22)},u=function(a){var b=l(a,28),c=l(a,34),e=l(a,39);return new d(b.highOrder^c.highOrder^e.highOrder,b.lowOrder^c.lowOrder^e.lowOrder)},v=function(a){return k(a,6)^k(a,11)^k(a,25)},w=function(a){var b=l(a,14),c=l(a,18),e=l(a,41);return new d(b.highOrder^c.highOrder^e.highOrder,b.lowOrder^c.lowOrder^e.lowOrder)},x=function(a){return k(a,7)^k(a,18)^m(a,3)},y=function(a){var b=l(a,1),c=l(a,8),e=n(a,7);return new d(b.highOrder^c.highOrder^e.highOrder,b.lowOrder^c.lowOrder^e.lowOrder)},z=function(a){return k(a,17)^k(a,19)^m(a,10)},A=function(a){var b=l(a,19),c=l(a,61),e=n(a,6);return new d(b.highOrder^c.highOrder^e.highOrder,b.lowOrder^c.lowOrder^e.lowOrder)},B=function(a,b){var c=(65535&a)+(65535&b),d=(a>>>16)+(b>>>16)+(c>>>16);return(65535&d)<<16|65535&c},C=function(a,b,c,d){var e=(65535&a)+(65535&b)+(65535&c)+(65535&d),f=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16);return(65535&f)<<16|65535&e},D=function(a,b,c,d,e){var f=(65535&a)+(65535&b)+(65535&c)+(65535&d)+(65535&e),g=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return(65535&g)<<16|65535&f},E=function(a,b){var c,e,f,g;return c=(65535&a.lowOrder)+(65535&b.lowOrder),e=(a.lowOrder>>>16)+(b.lowOrder>>>16)+(c>>>16),f=(65535&e)<<16|65535&c,c=(65535&a.highOrder)+(65535&b.highOrder)+(e>>>16),e=(a.highOrder>>>16)+(b.highOrder>>>16)+(c>>>16),g=(65535&e)<<16|65535&c,new d(g,f)},F=function(a,b,c,e){ -var f,g,h,i;return f=(65535&a.lowOrder)+(65535&b.lowOrder)+(65535&c.lowOrder)+(65535&e.lowOrder),g=(a.lowOrder>>>16)+(b.lowOrder>>>16)+(c.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16),h=(65535&g)<<16|65535&f,f=(65535&a.highOrder)+(65535&b.highOrder)+(65535&c.highOrder)+(65535&e.highOrder)+(g>>>16),g=(a.highOrder>>>16)+(b.highOrder>>>16)+(c.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16),i=(65535&g)<<16|65535&f,new d(i,h)},G=function(a,b,c,e,f){var g,h,i,j;return g=(65535&a.lowOrder)+(65535&b.lowOrder)+(65535&c.lowOrder)+(65535&e.lowOrder)+(65535&f.lowOrder),h=(a.lowOrder>>>16)+(b.lowOrder>>>16)+(c.lowOrder>>>16)+(e.lowOrder>>>16)+(f.lowOrder>>>16)+(g>>>16),i=(65535&h)<<16|65535&g,g=(65535&a.highOrder)+(65535&b.highOrder)+(65535&c.highOrder)+(65535&e.highOrder)+(65535&f.highOrder)+(h>>>16),h=(a.highOrder>>>16)+(b.highOrder>>>16)+(c.highOrder>>>16)+(e.highOrder>>>16)+(f.highOrder>>>16)+(g>>>16),j=(65535&h)<<16|65535&g,new d(j,i)},H=function(a,b){var c,d,e,f,g,h,i,k,l,m=[],n=p,q=o,s=r,t=j,u=B,v=D,w=[1732584193,4023233417,2562383102,271733878,3285377520],x=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];for(a[b>>5]|=128<<24-b%32,a[(b+65>>9<<4)+15]=b,l=a.length,i=0;l>i;i+=16){for(c=w[0],d=w[1],e=w[2],f=w[3],g=w[4],k=0;80>k;k+=1)16>k?m[k]=a[k+i]:m[k]=t(m[k-3]^m[k-8]^m[k-14]^m[k-16],1),h=20>k?v(t(c,5),n(d,e,f),g,x[k],m[k]):40>k?v(t(c,5),q(d,e,f),g,x[k],m[k]):60>k?v(t(c,5),s(d,e,f),g,x[k],m[k]):v(t(c,5),q(d,e,f),g,x[k],m[k]),g=f,f=e,e=t(d,30),d=c,c=h;w[0]=u(c,w[0]),w[1]=u(d,w[1]),w[2]=u(e,w[2]),w[3]=u(f,w[3]),w[4]=u(g,w[4])}return w},I=function(a,b,c){var e,f,g,h,i,j,k,l,m,n,o,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z=[];for("SHA-224"===c||"SHA-256"===c?(H=64,I=(b+65>>9<<4)+15,L=16,M=1,W=Number,N=B,O=C,P=D,Q=x,R=z,S=t,T=v,V=r,U=p,X=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],o="SHA-224"===c?[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]:[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]):("SHA-384"===c||"SHA-512"===c)&&(H=80,I=(b+128>>10<<5)+31,L=32,M=2,W=d,N=E,O=F,P=G,Q=y,R=A,S=u,T=w,V=s,U=q,X=[new W(1116352408,3609767458),new W(1899447441,602891725),new W(3049323471,3964484399),new W(3921009573,2173295548),new W(961987163,4081628472),new W(1508970993,3053834265),new W(2453635748,2937671579),new W(2870763221,3664609560),new W(3624381080,2734883394),new W(310598401,1164996542),new W(607225278,1323610764),new W(1426881987,3590304994),new W(1925078388,4068182383),new W(2162078206,991336113),new W(2614888103,633803317),new W(3248222580,3479774868),new W(3835390401,2666613458),new W(4022224774,944711139),new W(264347078,2341262773),new W(604807628,2007800933),new W(770255983,1495990901),new W(1249150122,1856431235),new W(1555081692,3175218132),new W(1996064986,2198950837),new W(2554220882,3999719339),new W(2821834349,766784016),new W(2952996808,2566594879),new W(3210313671,3203337956),new W(3336571891,1034457026),new W(3584528711,2466948901),new W(113926993,3758326383),new W(338241895,168717936),new W(666307205,1188179964),new W(773529912,1546045734),new W(1294757372,1522805485),new W(1396182291,2643833823),new W(1695183700,2343527390),new W(1986661051,1014477480),new W(2177026350,1206759142),new W(2456956037,344077627),new W(2730485921,1290863460),new W(2820302411,3158454273),new W(3259730800,3505952657),new W(3345764771,106217008),new W(3516065817,3606008344),new W(3600352804,1432725776),new W(4094571909,1467031594),new W(275423344,851169720),new W(430227734,3100823752),new W(506948616,1363258195),new W(659060556,3750685593),new W(883997877,3785050280),new W(958139571,3318307427),new W(1322822218,3812723403),new W(1537002063,2003034995),new W(1747873779,3602036899),new W(1955562222,1575990012),new W(2024104815,1125592928),new W(2227730452,2716904306),new W(2361852424,442776044),new W(2428436474,593698344),new W(2756734187,3733110249),new W(3204031479,2999351573),new W(3329325298,3815920427),new W(3391569614,3928383900),new W(3515267271,566280711),new W(3940187606,3454069534),new W(4118630271,4000239992),new W(116418474,1914138554),new W(174292421,2731055270),new W(289380356,3203993006),new W(460393269,320620315),new W(685471733,587496836),new W(852142971,1086792851),new W(1017036298,365543100),new W(1126000580,2618297676),new W(1288033470,3409855158),new W(1501505948,4234509866),new W(1607167915,987167468),new W(1816402316,1246189591)],o="SHA-384"===c?[new W(3418070365,3238371032),new W(1654270250,914150663),new W(2438529370,812702999),new W(355462360,4144912697),new W(1731405415,4290775857),new W(41048885895,1750603025),new W(3675008525,1694076839),new W(1203062813,3204075428)]:[new W(1779033703,4089235720),new W(3144134277,2227873595),new W(1013904242,4271175723),new W(2773480762,1595750129),new W(1359893119,2917565137),new W(2600822924,725511199),new W(528734635,4215389547),new W(1541459225,327033209)]),a[b>>5]|=128<<24-b%32,a[I]=b,Y=a.length,J=0;Y>J;J+=L){for(e=o[0],f=o[1],g=o[2],h=o[3],i=o[4],j=o[5],k=o[6],l=o[7],K=0;H>K;K+=1)16>K?Z[K]=new W(a[K*M+J],a[K*M+J+1]):Z[K]=O(R(Z[K-2]),Z[K-7],Q(Z[K-15]),Z[K-16]),m=P(l,T(i),U(i,j,k),X[K],Z[K]),n=N(S(e),V(e,f,g)),l=k,k=j,j=i,i=N(h,m),h=g,g=f,f=e,e=N(m,n);o[0]=N(e,o[0]),o[1]=N(f,o[1]),o[2]=N(g,o[2]),o[3]=N(h,o[3]),o[4]=N(i,o[4]),o[5]=N(j,o[5]),o[6]=N(k,o[6]),o[7]=N(l,o[7])}switch(c){case"SHA-224":return[o[0],o[1],o[2],o[3],o[4],o[5],o[6]];case"SHA-256":return o;case"SHA-384":return[o[0].highOrder,o[0].lowOrder,o[1].highOrder,o[1].lowOrder,o[2].highOrder,o[2].lowOrder,o[3].highOrder,o[3].lowOrder,o[4].highOrder,o[4].lowOrder,o[5].highOrder,o[5].lowOrder];case"SHA-512":return[o[0].highOrder,o[0].lowOrder,o[1].highOrder,o[1].lowOrder,o[2].highOrder,o[2].lowOrder,o[3].highOrder,o[3].lowOrder,o[4].highOrder,o[4].lowOrder,o[5].highOrder,o[5].lowOrder,o[6].highOrder,o[6].lowOrder,o[7].highOrder,o[7].lowOrder];default:throw new Error("Unknown SHA variant")}},J=function(b,c){if(this.sha1=null,this.sha224=null,this.sha256=null,this.sha384=null,this.sha512=null,this.strBinLen=null,this.strToHash=null,"HEX"===c){if(0!==b.length%2)throw new Error("TEXT MUST BE IN BYTE INCREMENTS");this.strBinLen=4*b.length,this.strToHash=f(b)}else{if("ASCII"!==c&&"undefined"!=typeof c)throw new Error("UNKNOWN TEXT INPUT TYPE");this.strBinLen=b.length*a,this.strToHash=e(b)}};return J.prototype={getHash:function(a,b){var c=null,d=this.strToHash.slice();switch(b){case"HEX":c=g;break;case"B64":c=h;break;case"ASCII":c=i;break;default:throw new Error("FORMAT NOT RECOGNIZED")}switch(a){case"SHA-1":return null===this.sha1&&(this.sha1=H(d,this.strBinLen)),c(this.sha1);case"SHA-224":return null===this.sha224&&(this.sha224=I(d,this.strBinLen,a)),c(this.sha224);case"SHA-256":return null===this.sha256&&(this.sha256=I(d,this.strBinLen,a)),c(this.sha256);case"SHA-384":return null===this.sha384&&(this.sha384=I(d,this.strBinLen,a)),c(this.sha384);case"SHA-512":return null===this.sha512&&(this.sha512=I(d,this.strBinLen,a)),c(this.sha512);default:throw new Error("HASH NOT RECOGNIZED")}},getHMAC:function(b,c,d,j){var k,l,m,n,o,p,q,r,s,t=[],u=[];switch(j){case"HEX":k=g;break;case"B64":k=h;break;case"ASCII":k=i;break;default:throw new Error("FORMAT NOT RECOGNIZED")}switch(d){case"SHA-1":m=64,s=160;break;case"SHA-224":m=64,s=224;break;case"SHA-256":m=64,s=256;break;case"SHA-384":m=128,s=384;break;case"SHA-512":m=128,s=512;break;default:throw new Error("HASH NOT RECOGNIZED")}if("HEX"===c){if(0!==b.length%2)throw new Error("KEY MUST BE IN BYTE INCREMENTS");l=f(b),r=4*b.length}else{if("ASCII"!==c)throw new Error("UNKNOWN KEY INPUT TYPE");l=e(b),r=b.length*a}for(n=8*m,q=m/4-1,r/8>m?(l="SHA-1"===d?H(l,r):I(l,r,d),l[q]&=4294967040):m>r/8&&(l[q]&=4294967040),o=0;q>=o;o+=1)t[o]=909522486^l[o],u[o]=1549556828^l[o];return"SHA-1"===d?(p=H(t.concat(this.strToHash),n+this.strBinLen),p=H(u.concat(p),n+s)):(p=I(t.concat(this.strToHash),n+this.strBinLen,d),p=I(u.concat(p),n+s,d)),k(p)}},J}();b.exports={sha1:function(a){var b=new d(a,"ASCII");return b.getHash("SHA-1","ASCII")},sha224:function(a){var b=new d(a,"ASCII");return b.getHash("SHA-224","ASCII")},sha256:function(a){var b=new d(a,"ASCII");return b.getHash("SHA-256","ASCII")},sha384:function(a){var b=new d(a,"ASCII");return b.getHash("SHA-384","ASCII")},sha512:function(a){var b=new d(a,"ASCII");return b.getHash("SHA-512","ASCII")}}},{}],32:[function(a,b,c){b.exports={cipher:a("./cipher"),hash:a("./hash"),cfb:a("./cfb.js"),publicKey:a("./public_key"),signature:a("./signature.js"),random:a("./random.js"),pkcs1:a("./pkcs1.js")};var d=a("./crypto.js");for(var e in d)b.exports[e]=d[e]},{"./cfb.js":18,"./cipher":23,"./crypto.js":25,"./hash":28,"./pkcs1.js":33,"./public_key":36,"./random.js":39,"./signature.js":40}],33:[function(a,b,c){function d(a){for(var b,c="";c.lengthb-11)throw new Error("Message too long");var e=d(b-c-3),f=String.fromCharCode(0)+String.fromCharCode(2)+e+String.fromCharCode(0)+a;return f},decode:function(a){0!==a.charCodeAt(0)&&(a=String.fromCharCode(0)+a);for(var b=a.charCodeAt(0),c=a.charCodeAt(1),d=2;0!==a.charCodeAt(d)&&d=8&&0===f)return a.substr(d);throw new Error("Decryption error")}},emsa:{encode:function(a,b,c){var d,f=i.digest(a,b);if(f.length!==i.getHashByteLength(a))throw new Error("Invalid hash length");var j="";for(d=0;dc)throw new Error("Intended encoded message length too short");var l="";for(d=0;c-k-3>d;d++)l+=String.fromCharCode(255);var m=String.fromCharCode(0)+String.fromCharCode(1)+l+String.fromCharCode(0)+j;return new h(g.hexstrdump(m),16)}}}},{"../util.js":76,"./crypto.js":25,"./hash":28,"./public_key/jsbn.js":37,"./random.js":39}],34:[function(a,b,c){function d(){function a(a,b,c,d,i,j){for(var k,l,m,n=h.getLeftNBits(g.digest(a,b),i.bitLength()),o=new e(h.hexstrdump(n),16);;)if(k=f.getRandomBigIntegerInRange(e.ONE,i.subtract(e.ONE)),l=c.modPow(k,d).mod(i),m=k.modInverse(i).multiply(o.add(j.multiply(l))).mod(i),0!=l&&0!=m)break;var p=[];return p[0]=l.toMPI(),p[1]=m.toMPI(),p}function b(a){var b=i.prefer_hash_algorithm;switch(Math.round(a.bitLength()/8)){case 20:return 2!=b&&b>11&&10!=b&&8>b?2:b;case 28:return b>11&&8>b?11:b;case 32:return b>10&&8>b?8:b;default:return h.print_debug("DSA select hash algorithm: returning null for an unknown length of q"),null}}function c(a,b,c,d,f,i,j,k){var l=h.getLeftNBits(g.digest(a,d),i.bitLength()),m=new e(h.hexstrdump(l),16);if(e.ZERO.compareTo(b)>=0||b.compareTo(i)>=0||e.ZERO.compareTo(c)>=0||c.compareTo(i)>=0)return h.print_debug("invalid DSA Signature"),null;var n=c.modInverse(i);if(0==e.ZERO.compareTo(n))return h.print_debug("invalid DSA Signature"),null;var o=m.multiply(n).mod(i),p=b.multiply(n).mod(i);return j.modPow(o,f).multiply(k.modPow(p,f)).mod(f).mod(i)}this.select_hash_algorithm=b,this.sign=a,this.verify=c}var e=a("./jsbn.js"),f=a("../random.js"),g=a("../hash"),h=a("../../util.js"),i=a("../../config");b.exports=d},{"../../config":17,"../../util.js":76,"../hash":28,"../random.js":39,"./jsbn.js":37}],35:[function(a,b,c){function d(){function a(a,b,c,d){var g=c.subtract(e.TWO),h=f.getRandomBigIntegerInRange(e.ONE,g);h=h.mod(g).add(e.ONE);var i=[];return i[0]=b.modPow(h,c),i[1]=d.modPow(h,c).multiply(a).mod(c),i}function b(a,b,c,d){return g.print_debug("Elgamal Decrypt:\nc1:"+g.hexstrdump(a.toMPI())+"\nc2:"+g.hexstrdump(b.toMPI())+"\np:"+g.hexstrdump(c.toMPI())+"\nx:"+g.hexstrdump(d.toMPI())),a.modPow(d,c).modInverse(c).multiply(b).mod(c)}this.encrypt=a,this.decrypt=b}var e=a("./jsbn.js"),f=a("../random.js"),g=a("../../util.js");b.exports=d},{"../../util.js":76,"../random.js":39,"./jsbn.js":37}],36:[function(a,b,c){b.exports={rsa:a("./rsa.js"),elgamal:a("./elgamal.js"),dsa:a("./dsa.js")}},{"./dsa.js":34,"./elgamal.js":35,"./rsa.js":38}],37:[function(a,b,c){function d(a,b,c){null!=a&&("number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))}function e(){return new d(null)}function f(a,b,c,d,e,f){for(;--f>=0;){var g=b*this[a++]+c[d]+e;e=Math.floor(g/67108864),c[d++]=67108863&g}return e}function g(a){return fb.charAt(a)}function h(a,b){var c=gb[a.charCodeAt(b)];return null==c?-1:c}function i(a){for(var b=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t,a.s=this.s}function j(a){this.t=1,this.s=0>a?-1:0,a>0?this[0]=a:-1>a?this[0]=a+this.DV:this.t=0}function k(a){var b=e();return b.fromInt(a),b}function l(a,b){var c;if(16==b)c=4;else if(8==b)c=3;else if(256==b)c=8;else if(2==b)c=1;else if(32==b)c=5;else{if(4!=b)return void this.fromRadix(a,b);c=2}this.t=0,this.s=0;for(var e=a.length,f=!1,g=0;--e>=0;){var i=8==c?255&a[e]:h(a,e);0>i?"-"==a.charAt(e)&&(f=!0):(f=!1,0==g?this[this.t++]=i:g+c>this.DB?(this[this.t-1]|=(i&(1<>this.DB-g):this[this.t-1]|=i<=this.DB&&(g-=this.DB))}8==c&&0!=(128&a[0])&&(this.s=-1,g>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==a;)--this.t}function n(a){if(this.s<0)return"-"+this.negate().toString(a);var b;if(16==a)b=4;else if(8==a)b=3;else if(2==a)b=1;else if(32==a)b=5;else{if(4!=a)return this.toRadix(a);b=2}var c,d=(1<0)for(i>i)>0&&(e=!0,f=g(c));h>=0;)b>i?(c=(this[h]&(1<>(i+=this.DB-b)):(c=this[h]>>(i-=b)&d,0>=i&&(i+=this.DB,--h)),c>0&&(e=!0),e&&(f+=g(c));return e?f:"0"}function o(){var a=e();return d.ZERO.subTo(this,a),a}function p(){return this.s<0?this.negate():this}function q(a){var b=this.s-a.s;if(0!=b)return b;var c=this.t;if(b=c-a.t,0!=b)return this.s<0?-b:b;for(;--c>=0;)if(0!=(b=this[c]-a[c]))return b;return 0}function r(a){var b,c=1;return 0!=(b=a>>>16)&&(a=b,c+=16),0!=(b=a>>8)&&(a=b,c+=8),0!=(b=a>>4)&&(a=b,c+=4),0!=(b=a>>2)&&(a=b,c+=2),0!=(b=a>>1)&&(a=b,c+=1),c}function s(){return this.t<=0?0:this.DB*(this.t-1)+r(this[this.t-1]^this.s&this.DM)}function t(a,b){var c;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a,b.s=this.s}function u(a,b){for(var c=a;c=0;--c)b[c+g+1]=this[c]>>e|h,h=(this[c]&f)<=0;--c)b[c]=0;b[g]=h,b.t=this.t+g+1,b.s=this.s,b.clamp()}function w(a,b){b.s=this.s;var c=Math.floor(a/this.DB);if(c>=this.t)return void(b.t=0);var d=a%this.DB,e=this.DB-d,f=(1<>d;for(var g=c+1;g>d;d>0&&(b[this.t-c-1]|=(this.s&f)<c;)d+=this[c]-a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t>=this.DB;d+=this.s}else{for(d+=this.s;c>=this.DB;d-=a.s}b.s=0>d?-1:0,-1>d?b[c++]=this.DV+d:d>0&&(b[c++]=d),b.t=c,b.clamp()}function y(a,b){var c=this.abs(),e=a.abs(),f=c.t;for(b.t=f+e.t;--f>=0;)b[f]=0;for(f=0;f=0;)a[c]=0;for(c=0;c=b.DV&&(a[c+b.t]-=b.DV,a[c+b.t+1]=1)}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1)),a.s=0,a.clamp()}function A(a,b,c){var f=a.abs();if(!(f.t<=0)){var g=this.abs();if(g.t0?(f.lShiftTo(k,h),g.lShiftTo(k,c)):(f.copyTo(h),g.copyTo(c));var l=h.t,m=h[l-1];if(0!=m){var n=m*(1<1?h[l-2]>>this.F2:0),o=this.FV/n,p=(1<=0&&(c[c.t++]=1,c.subTo(u,c)),d.ONE.dlShiftTo(l,u),u.subTo(h,h);h.t=0;){var v=c[--s]==m?this.DM:Math.floor(c[s]*o+(c[s-1]+q)*p);if((c[s]+=h.am(0,v,c,t,0,l))0&&c.rShiftTo(k,c),0>i&&d.ZERO.subTo(c,c)}}}function B(a){var b=e();return this.abs().divRemTo(a,null,b),this.s<0&&b.compareTo(d.ZERO)>0&&a.subTo(b,b),b}function C(a){this.m=a}function D(a){return a.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}function E(a){return a}function F(a){a.divRemTo(this.m,null,a)}function G(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function H(a,b){a.squareTo(b),this.reduce(b)}function I(){if(this.t<1)return 0;var a=this[0];if(0==(1&a))return 0;var b=3&a;return b=b*(2-(15&a)*b)&15,b=b*(2-(255&a)*b)&255,b=b*(2-((65535&a)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV,b>0?this.DV-b:-b}function J(a){this.m=a,this.mp=a.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<0&&this.m.subTo(b,b),b}function L(a){var b=e();return a.copyTo(b),this.reduce(b),b}function M(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(var b=0;b>15)*this.mpl&this.um)<<15)&a.DM;for(c=b+this.m.t,a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp(),a.drShiftTo(this.m.t,a),a.compareTo(this.m)>=0&&a.subTo(this.m,a)}function N(a,b){a.squareTo(b),this.reduce(b)}function O(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function P(){return 0==(this.t>0?1&this[0]:this.s)}function Q(a,b){if(a>4294967295||1>a)return d.ONE;var c=e(),f=e(),g=b.convert(this),h=r(a)-1;for(g.copyTo(c);--h>=0;)if(b.sqrTo(c,f),(a&1<0)b.mulTo(f,g,c);else{var i=c;c=f,f=i}return b.revert(c)}function R(a,b){var c;return c=256>a||b.isEven()?new C(b):new J(b),this.exp(a,c)}function S(){var a=e();return this.copyTo(a),a}function T(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<>24}function V(){return 0==this.t?this.s:this[0]<<16>>16}function W(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function X(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function Y(a){if(null==a&&(a=10),0==this.signum()||2>a||a>36)return"0";var b=this.chunkSize(a),c=Math.pow(a,b),d=k(c),f=e(),g=e(),h="";for(this.divRemTo(d,f,g);f.signum()>0;)h=(c+g.intValue()).toString(a).substr(1)+h,f.divRemTo(d,f,g);return g.intValue().toString(a)+h}function Z(a,b){this.fromInt(0),null==b&&(b=10);for(var c=this.chunkSize(b),e=Math.pow(b,c),f=!1,g=0,i=0,j=0;jk?"-"==a.charAt(j)&&0==this.signum()&&(f=!0):(i=b*i+k,++g>=c&&(this.dMultiply(e),this.dAddOffset(i,0),g=0,i=0))}g>0&&(this.dMultiply(Math.pow(b,g)),this.dAddOffset(i,0)),f&&d.ZERO.subTo(this,this)}function $(a,b,c){if("number"==typeof b)if(2>a)this.fromInt(1);else for(this.fromNumber(a,c),this.testBit(a-1)||this.bitwiseTo(d.ONE.shiftLeft(a-1),ga,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(b);)this.dAddOffset(2,0),this.bitLength()>a&&this.subTo(d.ONE.shiftLeft(a-1),this);else{var e=new Array,f=7&a;e.length=(a>>3)+1,b.nextBytes(e),f>0?e[0]&=(1<0)for(d>d)!=(this.s&this.DM)>>d&&(b[e++]=c|this.s<=0;)8>d?(c=(this[a]&(1<>(d+=this.DB-8)):(c=this[a]>>(d-=8)&255,0>=d&&(d+=this.DB,--a)),(e>0||c!=this.s)&&(b[e++]=c);return b}function aa(a){return 0==this.compareTo(a)}function ba(a){return this.compareTo(a)<0?this:a}function ca(a){return this.compareTo(a)>0?this:a}function da(a,b,c){var d,e,f=Math.min(a.t,this.t);for(d=0;f>d;++d)c[d]=b(this[d],a[d]);if(a.ta?this.rShiftTo(-a,b):this.lShiftTo(a,b),b}function oa(a){var b=e();return 0>a?this.lShiftTo(-a,b):this.rShiftTo(a,b),b}function pa(a){if(0==a)return-1;var b=0;return 0==(65535&a)&&(a>>=16,b+=16),0==(255&a)&&(a>>=8,b+=8),0==(15&a)&&(a>>=4,b+=4),0==(3&a)&&(a>>=2,b+=2),0==(1&a)&&++b,b}function qa(){for(var a=0;a=this.t?0!=this.s:0!=(this[b]&1<c;)d+=this[c]+a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t>=this.DB;d+=this.s}else{for(d+=this.s;c>=this.DB;d+=a.s}b.s=0>d?-1:0,d>0?b[c++]=d:-1>d&&(b[c++]=this.DV+d),b.t=c,b.clamp()}function za(a){var b=e();return this.addTo(a,b),b}function Aa(a){var b=e();return this.subTo(a,b),b}function Ba(a){var b=e();return this.multiplyTo(a,b),b}function Ca(){var a=e();return this.squareTo(a),a}function Da(a){var b=e();return this.divRemTo(a,b,null),b}function Ea(a){var b=e();return this.divRemTo(a,null,b),b}function Fa(a){var b=e(),c=e();return this.divRemTo(a,b,c),new Array(b,c)}function Ga(a){this[this.t]=this.am(0,a-1,this,0,0,this.t),++this.t,this.clamp()}function Ha(a,b){if(0!=a){for(;this.t<=b;)this[this.t++]=0;for(this[b]+=a;this[b]>=this.DV;)this[b]-=this.DV,++b>=this.t&&(this[this.t++]=0),++this[b]}}function Ia(){}function Ja(a){return a}function Ka(a,b,c){a.multiplyTo(b,c)}function La(a,b){a.squareTo(b)}function Ma(a){return this.exp(a,new Ia)}function Na(a,b,c){var d=Math.min(this.t+a.t,b);for(c.s=0,c.t=d;d>0;)c[--d]=0;var e;for(e=c.t-this.t;e>d;++d)c[d+this.t]=this.am(0,a[d],c,d,0,this.t);for(e=Math.min(a.t,b);e>d;++d)this.am(0,a[d],c,d,0,b-d);c.clamp()}function Oa(a,b,c){--b;var d=c.t=this.t+a.t-b;for(c.s=0;--d>=0;)c[d]=0;for(d=Math.max(b-this.t,0);d2*this.m.t)return a.mod(this.m);if(a.compareTo(this.m)<0)return a;var b=e();return a.copyTo(b),this.reduce(b),b}function Ra(a){return a}function Sa(a){for(a.drShiftTo(this.m.t-1,this.r2),a.t>this.m.t+1&&(a.t=this.m.t+1,a.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);a.compareTo(this.r2)<0;)a.dAddOffset(1,this.m.t+1);for(a.subTo(this.r2,a);a.compareTo(this.m)>=0;)a.subTo(this.m,a)}function Ta(a,b){a.squareTo(b),this.reduce(b)}function Ua(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function Va(a,b){var c,d,f=a.bitLength(),g=k(1);if(0>=f)return g;c=18>f?1:48>f?3:144>f?4:768>f?5:6,d=8>f?new C(b):b.isEven()?new Pa(b):new J(b);var h=new Array,i=3,j=c-1,l=(1<1){var m=e();for(d.sqrTo(h[1],m);l>=i;)h[i]=e(),d.mulTo(m,h[i-2],h[i]),i+=2}var n,o,p=a.t-1,q=!0,s=e();for(f=r(a[p])-1;p>=0;){for(f>=j?n=a[p]>>f-j&l:(n=(a[p]&(1<0&&(n|=a[p-1]>>this.DB+f-j)),i=c;0==(1&n);)n>>=1,--i;if((f-=i)<0&&(f+=this.DB,--p),q)h[n].copyTo(g),q=!1;else{for(;i>1;)d.sqrTo(g,s),d.sqrTo(s,g),i-=2;i>0?d.sqrTo(g,s):(o=g,g=s,s=o),d.mulTo(s,h[n],g)}for(;p>=0&&0==(a[p]&1<f)return b;for(f>e&&(f=e),f>0&&(b.rShiftTo(f,b),c.rShiftTo(f,c));b.signum()>0;)(e=b.getLowestSetBit())>0&&b.rShiftTo(e,b),(e=c.getLowestSetBit())>0&&c.rShiftTo(e,c),b.compareTo(c)>=0?(b.subTo(c,b),b.rShiftTo(1,b)):(c.subTo(b,c),c.rShiftTo(1,c));return f>0&&c.lShiftTo(f,c),c}function Xa(a){if(0>=a)return 0;var b=this.DV%a,c=this.s<0?a-1:0;if(this.t>0)if(0==b)c=this[0]%a;else for(var d=this.t-1;d>=0;--d)c=(b*c+this[d])%a;return c}function Ya(a){var b=a.isEven();if(this.isEven()&&b||0==a.signum())return d.ZERO;for(var c=a.clone(),e=this.clone(),f=k(1),g=k(0),h=k(0),i=k(1);0!=c.signum();){for(;c.isEven();)c.rShiftTo(1,c),b?(f.isEven()&&g.isEven()||(f.addTo(this,f),g.subTo(a,g)),f.rShiftTo(1,f)):g.isEven()||g.subTo(a,g),g.rShiftTo(1,g);for(;e.isEven();)e.rShiftTo(1,e),b?(h.isEven()&&i.isEven()||(h.addTo(this,h),i.subTo(a,i)),h.rShiftTo(1,h)):i.isEven()||i.subTo(a,i),i.rShiftTo(1,i);c.compareTo(e)>=0?(c.subTo(e,c),b&&f.subTo(h,f),g.subTo(i,g)):(e.subTo(c,e),b&&h.subTo(f,h),i.subTo(g,i))}return 0!=e.compareTo(d.ONE)?d.ZERO:i.compareTo(a)>=0?i.subtract(a):i.signum()<0?(i.addTo(a,i),i.signum()<0?i.add(a):i):i}function Za(a){var b,c=this.abs();if(1==c.t&&c[0]<=hb[hb.length-1]){for(b=0;bd;)d*=hb[e++];for(d=c.modInt(d);e>b;)if(d%hb[b++]==0)return!1}return c.millerRabin(a)}function r(a){var b,c=1;return 0!=(b=a>>>16)&&(a=b,c+=16),0!=(b=a>>8)&&(a=b,c+=8),0!=(b=a>>4)&&(a=b,c+=4),0!=(b=a>>2)&&(a=b,c+=2),0!=(b=a>>1)&&(a=b,c+=1),c}function $a(){var a=this.toByteArray(),b=8*(a.length-1)+r(a[0]),c="";return c+=String.fromCharCode((65280&b)>>8),c+=String.fromCharCode(255&b),c+=bb.bin2str(a)}function _a(a){var b=this.subtract(d.ONE),c=b.getLowestSetBit();if(0>=c)return!1;var f=b.shiftRight(c);a=a+1>>1,a>hb.length&&(a=hb.length);for(var g,h=e(),i=[],j=0;a>j;++j){for(;g=hb[Math.floor(Math.random()*hb.length)],-1!=i.indexOf(g););i.push(g),h.fromInt(g);var k=h.modPow(f,this);if(0!=k.compareTo(d.ONE)&&0!=k.compareTo(b)){for(var g=1;g++=eb;++eb)gb[db++]=eb;for(db="a".charCodeAt(0),eb=10;36>eb;++eb)gb[db++]=eb;for(db="A".charCodeAt(0),eb=10;36>eb;++eb)gb[db++]=eb;C.prototype.convert=D,C.prototype.revert=E,C.prototype.reduce=F,C.prototype.mulTo=G,C.prototype.sqrTo=H,J.prototype.convert=K,J.prototype.revert=L,J.prototype.reduce=M,J.prototype.mulTo=O,J.prototype.sqrTo=N,d.prototype.copyTo=i,d.prototype.fromInt=j,d.prototype.fromString=l,d.prototype.clamp=m,d.prototype.dlShiftTo=t,d.prototype.drShiftTo=u,d.prototype.lShiftTo=v,d.prototype.rShiftTo=w,d.prototype.subTo=x,d.prototype.multiplyTo=y,d.prototype.squareTo=z,d.prototype.divRemTo=A,d.prototype.invDigit=I,d.prototype.isEven=P,d.prototype.exp=Q,d.prototype.toString=n,d.prototype.negate=o,d.prototype.abs=p,d.prototype.compareTo=q,d.prototype.bitLength=s,d.prototype.mod=B,d.prototype.modPowInt=R,d.ZERO=k(0),d.ONE=k(1),d.TWO=k(2),b.exports=d,Ia.prototype.convert=Ja,Ia.prototype.revert=Ja,Ia.prototype.mulTo=Ka,Ia.prototype.sqrTo=La,Pa.prototype.convert=Qa,Pa.prototype.revert=Ra,Pa.prototype.reduce=Sa,Pa.prototype.mulTo=Ua,Pa.prototype.sqrTo=Ta;var hb=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],ib=(1<<26)/hb[hb.length-1],d=a("./jsbn.js");d.prototype.chunkSize=W,d.prototype.toRadix=Y,d.prototype.fromRadix=Z,d.prototype.fromNumber=$,d.prototype.bitwiseTo=da,d.prototype.changeBit=ua,d.prototype.addTo=ya,d.prototype.dMultiply=Ga,d.prototype.dAddOffset=Ha,d.prototype.multiplyLowerTo=Na,d.prototype.multiplyUpperTo=Oa,d.prototype.modInt=Xa,d.prototype.millerRabin=_a,d.prototype.clone=S,d.prototype.intValue=T,d.prototype.byteValue=U,d.prototype.shortValue=V,d.prototype.signum=X,d.prototype.toByteArray=_,d.prototype.equals=aa,d.prototype.min=ba,d.prototype.max=ca,d.prototype.and=fa,d.prototype.or=ha,d.prototype.xor=ja,d.prototype.andNot=la,d.prototype.not=ma,d.prototype.shiftLeft=na,d.prototype.shiftRight=oa,d.prototype.getLowestSetBit=qa,d.prototype.bitCount=sa,d.prototype.testBit=ta,d.prototype.setBit=va,d.prototype.clearBit=wa,d.prototype.flipBit=xa,d.prototype.add=za,d.prototype.subtract=Aa,d.prototype.multiply=Ba,d.prototype.divide=Da,d.prototype.remainder=Ea,d.prototype.divideAndRemainder=Fa,d.prototype.modPow=Va,d.prototype.modInverse=Ya,d.prototype.pow=Ma,d.prototype.gcd=Wa,d.prototype.isProbablePrime=Za,d.prototype.toMPI=$a,d.prototype.square=Ca},{"../../util.js":76,"./jsbn.js":37}],38:[function(a,b,c){function d(){function a(a){for(var b=0;b>1;for(e.e=parseInt(b,16),e.ee=new h(b,16);;){for(;e.p=new h(a-g,1,f),0!==e.p.subtract(h.ONE).gcd(e.ee).compareTo(h.ONE)||!e.p.isProbablePrime(10););for(;e.q=new h(g,1,f),0!==e.q.subtract(h.ONE).gcd(e.ee).compareTo(h.ONE)||!e.q.isProbablePrime(10););if(e.p.compareTo(e.q)<=0){var i=e.p;e.p=e.q,e.q=i}var k=e.p.subtract(h.ONE),l=e.q.subtract(h.ONE),m=k.multiply(l);if(0===m.gcd(e.ee).compareTo(h.ONE)){e.n=e.p.multiply(e.q),e.d=e.ee.modInverse(m),e.dmp1=e.d.mod(k),e.dmq1=e.d.mod(l),e.u=e.p.modInverse(e.q);break}}c(e)})}this.encrypt=b,this.decrypt=a,this.verify=g,this.sign=c,this.generate=l,this.keyObject=j}var h=a("./jsbn.js"),i=a("../../util.js"),j=a("../random.js"),k=a("../../config"),l=h.ZERO,m=h.ZERO;b.exports=g},{"../../config":17,"../../util.js":76,"../random.js":39,"./jsbn.js":37}],39:[function(a,b,c){function d(){this.buffer=null,this.size=null}var e=a("../type/mpi.js"),f=null;"undefined"==typeof window&&(f=a("crypto")),b.exports={getRandomBytes:function(a){for(var b="",c=0;a>c;c++)b+=String.fromCharCode(this.getSecureRandomOctet());return b},getSecureRandom:function(a,b){for(var c=this.getSecureRandomUint(),d=(b-a).toString(2).length;(c&Math.pow(2,d)-1)>b-a;)c=this.getSecureRandomUint();return a+Math.abs(c&Math.pow(2,d)-1)},getSecureRandomOctet:function(){var a=new Uint8Array(1);return this.getRandomValues(a),a[0]},getSecureRandomUint:function(){var a=new Uint8Array(4),b=new DataView(a.buffer);return this.getRandomValues(a),b.getUint32(0)},getRandomValues:function(a){if(!(a instanceof Uint8Array))throw new Error("Invalid type: buf not an Uint8Array");if("undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(a);else if("undefined"!=typeof window&&"object"==typeof window.msCrypto&&"function"==typeof window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(a);else if(f){var b=f.randomBytes(a.length);a.set(b)}else{if(!this.randomBuffer.buffer)throw new Error("No secure random number generator available.");this.randomBuffer.get(a)}},getRandomBigInteger:function(a){if(1>a)throw new Error("Illegal parameter value: bits < 1");var b=Math.floor((a+7)/8),c=this.getRandomBytes(b);a%8>0&&(c=String.fromCharCode(Math.pow(2,a%8)-1&c.charCodeAt(0))+c.substring(1));var d=new e;return d.fromBytes(c),d.toBigInteger()},getRandomBigIntegerInRange:function(a,b){if(b.compareTo(a)<=0)throw new Error("Illegal parameter value: max <= min");for(var c=b.subtract(a),d=this.getRandomBigInteger(c.bitLength());d.compareTo(c)>0;)d=this.getRandomBigInteger(c.bitLength());return a.add(d)},randomBuffer:new d},d.prototype.init=function(a){this.buffer=new Uint8Array(a),this.size=0},d.prototype.set=function(a){if(!this.buffer)throw new Error("RandomBuffer is not initialized");if(!(a instanceof Uint8Array))throw new Error("Invalid type: buf not an Uint8Array");var b=this.buffer.length-this.size;a.length>b&&(a=a.subarray(0,b)),this.buffer.set(a,this.size),this.size+=a.length},d.prototype.get=function(a){if(!this.buffer)throw new Error("RandomBuffer is not initialized");if(!(a instanceof Uint8Array))throw new Error("Invalid type: buf not an Uint8Array");if(this.size>16)+String.fromCharCode(b>>8&255)+String.fromCharCode(255&b);return n.encode(c)}function g(a,b){var c=f(a),d=b;return c[0]==d[0]&&c[1]==d[1]&&c[2]==d[2]&&c[3]==d[3]}function h(a){for(var b=11994318,c=0;a.length-c>16;)b=b<<8^q[255&(b>>16^a.charCodeAt(c))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+1))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+2))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+3))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+4))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+5))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+6))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+7))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+8))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+9))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+10))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+11))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+12))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+13))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+14))],b=b<<8^q[255&(b>>16^a.charCodeAt(c+15))],c+=16;for(var d=c;d>16^a.charCodeAt(c++))];return 16777215&b}function i(a){var b=/^[ \f\r\t\u00a0\u2000-\u200a\u202f\u205f\u3000]*\n/m,c="",d=a,e=b.exec(a);if(null===e)throw new Error("Mandatory blank line missing between armor headers and armor data");return c=a.slice(0,e.index),d=a.slice(e.index+e[0].length),c=c.split("\n"),c.pop(),{headers:c,body:d}}function j(a){for(var b=0;be;e++)d=a.charCodeAt(e),0===i?(g.push(f.charAt(d>>2&63)),c=(3&d)<<4):1==i?(g.push(f.charAt(c|d>>4&15)),c=(15&d)<<2):2==i&&(g.push(f.charAt(c|d>>6&3)),h+=1,h%60===0&&g.push("\n"),g.push(f.charAt(63&d))),h+=1,h%60===0&&g.push("\n"),i+=1,3==i&&(i=0);return i>0&&(g.push(f.charAt(c)),h+=1,h%60===0&&g.push("\n"),g.push("="),h+=1),1==i&&(h%60===0&&g.push("\n"),g.push("=")),b?void 0:g.join("")}function e(a){var b,c,d=[],e=0,g=0,h=a.length;for(c=0;h>c;c++)b=f.indexOf(a.charAt(c)),b>=0&&(e&&d.push(String.fromCharCode(g|b>>6-e&255)),e=e+2&7,g=b<>c,d.count++})}var e={prio:0,algo:q.encryption_cipher};for(var f in b)try{f!==o.symmetric.plaintext&&f!==o.symmetric.idea&&o.read(o.symmetric,f)&&b[f].count===a.length&&b[f].prio>e.prio&&(e=b[f])}catch(g){}return e.algo}var n=a("./packet"),o=a("./enums.js"),p=a("./encoding/armor.js"),q=a("./config"),r=a("./util");d.prototype.packetlist2structure=function(a){for(var b,c,d,e=0;ethis.primaryKey.created.getTime()+24*this.primaryKey.expirationTimeV3*3600*1e3)return o.keyStatus.expired;for(var a=!1,b=0;bthis.primaryKey.created.getTime()+1e3*c.selfCertificate.keyExpirationTime?o.keyStatus.expired:o.keyStatus.valid:o.keyStatus.invalid},d.prototype.getExpirationTime=function(){if(3==this.primaryKey.version)return g(this.primaryKey);if(4==this.primaryKey.version){var a=this.getPrimaryUser();return a?g(this.primaryKey,a.selfCertificate):null}},d.prototype.getPrimaryUser=function(){for(var a=[],b=0;bb.selfCertificate.isPrimaryUserID?-1:a.selfCertificate.isPrimaryUserIDb.selfCertificate.created?-1:a.selfCertificate.createdb?-1:b>a?1:0}),c=0;cthis.subKey.created.getTime()+24*this.subKey.expirationTimeV3*3600*1e3?o.keyStatus.expired:this.bindingSignature?this.bindingSignature.isExpired()?o.keyStatus.expired:this.bindingSignature.verified||this.bindingSignature.verify(a,{key:a,bind:this.subKey})?4==this.subKey.version&&this.bindingSignature.keyNeverExpires===!1&&Date.now()>this.subKey.created.getTime()+1e3*this.bindingSignature.keyExpirationTime?o.keyStatus.expired:o.keyStatus.valid:o.keyStatus.invalid:o.keyStatus.invalid},j.prototype.getExpirationTime=function(){return g(this.subKey,this.bindingSignature)},j.prototype.update=function(a,b){if(a.verify(b)!==o.keyStatus.invalid){if(this.subKey.getFingerprint()!==a.subKey.getFingerprint())throw new Error("SubKey update method: fingerprints of subkeys not equal");this.subKey.tag===o.packet.publicSubkey&&a.subKey.tag===o.packet.secretSubkey&&(this.subKey=a.subKey),!this.bindingSignature&&a.bindingSignature&&(a.bindingSignature.verified||a.bindingSignature.verify(b,{key:b,bind:this.subKey}))&&(this.bindingSignature=a.bindingSignature),this.revocationSignature||!a.revocationSignature||a.revocationSignature.isExpired()||!a.revocationSignature.verified&&!a.revocationSignature.verify(b,{key:b,bind:this.subKey})||(this.revocationSignature=a.revocationSignature)}},c.Key=d,c.readArmored=k,c.generate=l,c.getPreferredSymAlgo=m},{"./config":17,"./encoding/armor.js":41,"./enums.js":43,"./packet":55,"./util":76}],48:[function(a,b,c){b.exports=a("./keyring.js"),b.exports.localstore=a("./localstore.js")},{"./keyring.js":49,"./localstore.js":50}],49:[function(a,b,c){function d(b){this.storeHandler=b||new(a("./localstore.js")),this.publicKeys=new e(this.storeHandler.loadPublic()),this.privateKeys=new e(this.storeHandler.loadPrivate())}function e(a){this.keys=a}function f(a,b){a=a.toLowerCase();for(var c=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),d=new RegExp("<"+c+">"),e=b.getUserIds(),f=0;f=0;e--){var m=new i.Signature;if(m.signatureType=h,m.hashAlgorithm=l.prefer_hash_algorithm,m.publicKeyAlgorithm=f.algorithm,!f.isDecrypted)throw new Error("Private key is not decrypted.");m.sign(f,c),b.push(m)}return new d(b)},d.prototype.verify=function(a){var b=[],c=this.unwrapCompressed(),d=c.packets.filterByTag(j.packet.literal);if(1!==d.length)throw new Error("Can only verify message with one literal data packet.");for(var e=c.packets.filterByTag(j.packet.signature),f=0;fe?(c=a.charCodeAt(0),b=1):255>e?(c=(a.charCodeAt(0)-192<<8)+a.charCodeAt(1)+192,b=2):255==e&&(c=d.readNumber(a.substr(1,4)),b=5),{len:c,offset:b}},writeSimpleLength:function(a){var b="";return 192>a?b+=String.fromCharCode(a):a>191&&8384>a?(b+=String.fromCharCode((a-192>>8)+192),b+=String.fromCharCode(a-192&255)):(b+=String.fromCharCode(255),b+=d.writeNumber(a,4)),b},writeHeader:function(a,b){var c="";return c+=String.fromCharCode(192|a),c+=this.writeSimpleLength(b)},writeOldHeader:function(a,b){var c="";return 256>b?(c+=String.fromCharCode(128|a<<2),c+=String.fromCharCode(b)):65536>b?(c+=String.fromCharCode(128|a<<2|1),c+=d.writeNumber(b,2)):(c+=String.fromCharCode(128|a<<2|2),c+=d.writeNumber(b,4)),c},read:function(a,b,c){if(null===a||a.length<=b||a.substring(b).length<2||0===(128&a.charCodeAt(b)))throw new Error("Error during parsing. This message / key is probably not containing a valid OpenPGP format.");var e,f=b,g=-1,h=-1;h=0,0!==(64&a.charCodeAt(f))&&(h=1);var i;h?g=63&a.charCodeAt(f):(g=(63&a.charCodeAt(f))>>2,i=3&a.charCodeAt(f)),f++;var j=null,k=-1;if(h)if(a.charCodeAt(f)<192)e=a.charCodeAt(f++),d.print_debug("1 byte length:"+e);else if(a.charCodeAt(f)>=192&&a.charCodeAt(f)<224)e=(a.charCodeAt(f++)-192<<8)+a.charCodeAt(f++)+192,d.print_debug("2 byte length:"+e);else if(a.charCodeAt(f)>223&&a.charCodeAt(f)<255){e=1<<(31&a.charCodeAt(f++)),d.print_debug("4 byte length:"+e);var l=f+e;j=a.substring(f,f+e);for(var m;;){if(a.charCodeAt(l)<192){m=a.charCodeAt(l++),e+=m,j+=a.substring(l,l+m),l+=m;break}if(a.charCodeAt(l)>=192&&a.charCodeAt(l)<224){m=(a.charCodeAt(l++)-192<<8)+a.charCodeAt(l++)+192,e+=m,j+=a.substring(l,l+m),l+=m;break}if(!(a.charCodeAt(l)>223&&a.charCodeAt(l)<255)){l++,m=a.charCodeAt(l++)<<24|a.charCodeAt(l++)<<16|a.charCodeAt(l++)<<8|a.charCodeAt(l++),j+=a.substring(l,l+m),e+=m,l+=m;break}m=1<<(31&a.charCodeAt(l++)),e+=m,j+=a.substring(l,l+m),l+=m}k=l-f}else f++,e=a.charCodeAt(f++)<<24|a.charCodeAt(f++)<<16|a.charCodeAt(f++)<<8|a.charCodeAt(f++);else switch(i){case 0:e=a.charCodeAt(f++);break;case 1:e=a.charCodeAt(f++)<<8|a.charCodeAt(f++);break;case 2:e=a.charCodeAt(f++)<<24|a.charCodeAt(f++)<<16|a.charCodeAt(f++)<<8|a.charCodeAt(f++);break;default:e=c}return-1==k&&(k=e),null===j&&(j=a.substring(f,f+k)),{tag:g,packet:j,offset:f+k}}}},{"../enums.js":43,"../util.js":76}],60:[function(a,b,c){function d(){this.length=0}b.exports=d;var e=a("./packet.js"),f=a("./all_packets.js"),g=a("../enums.js");d.prototype.read=function(a){for(var b=0;be;e++)c.push(this[e]);return c},d.prototype.concat=function(a){if(a)for(var b=0;bj&&gd.length)throw new Error("Error reading MPI @:"+g);return g+6}throw new Error("Version "+this.version+" of the key packet is unsupported.")},d.prototype.readPublicKey=d.prototype.read,d.prototype.write=function(){var a=String.fromCharCode(this.version);a+=e.writeDate(this.created),3==this.version&&(a+=e.writeNumber(this.expirationTimeV3,2)),a+=String.fromCharCode(h.write(h.publicKey,this.algorithm));for(var b=i.getPublicMpiCount(this.algorithm),c=0;b>c;c++)a+=this.mpi[c].write();return a},d.prototype.writePublicKey=d.prototype.write,d.prototype.writeOld=function(){var a=this.writePublicKey();return String.fromCharCode(153)+e.writeNumber(a.length,2)+a},d.prototype.getKeyId=function(){return this.keyid?this.keyid:(this.keyid=new g,4==this.version?this.keyid.read(e.hex2bin(this.getFingerprint()).substr(12,8)):3==this.version&&this.keyid.read(this.mpi[0].write().substr(-8)),this.keyid)},d.prototype.getFingerprint=function(){if(this.fingerprint)return this.fingerprint;var a="";if(4==this.version)a=this.writeOld(),this.fingerprint=i.hash.sha1(a);else if(3==this.version){for(var b=i.getPublicMpiCount(this.algorithm),c=0;b>c;c++)a+=this.mpi[c].toBytes();this.fingerprint=i.hash.md5(a)}return this.fingerprint=e.hexstrdump(this.fingerprint),this.fingerprint},d.prototype.getBitSize=function(){return 8*this.mpi[0].byteLength()},d.prototype.postCloneTypeFix=function(){for(var a=0;ad;d++){var e=new g;b+=e.read(a.substr(b)),this.encrypted.push(e)}},d.prototype.write=function(){var a=String.fromCharCode(this.version);a+=this.publicKeyId.write(),a+=String.fromCharCode(h.write(h.publicKey,this.publicKeyAlgorithm));for(var b=0;bo&&kc;){var d=g.readSimpleLength(a.substr(c));c+=d.offset,this.read_sub_packet(a.substr(c,d.len)),c+=d.len}return c}var c=0;switch(this.version=a.charCodeAt(c++),this.version){case 3:5!=a.charCodeAt(c++)&&f.print_debug("packet/signature.js\ninvalid One-octet length of following hashed material.MUST be 5. @:"+(c-1));var d=c;this.signatureType=a.charCodeAt(c++),this.created=f.readDate(a.substr(c,4)),c+=4,this.signatureData=a.substring(d,c),this.issuerKeyId.read(a.substring(c,c+8)),c+=8,this.publicKeyAlgorithm=a.charCodeAt(c++),this.hashAlgorithm=a.charCodeAt(c++);break;case 4:this.signatureType=a.charCodeAt(c++),this.publicKeyAlgorithm=a.charCodeAt(c++),this.hashAlgorithm=a.charCodeAt(c++),c+=b.call(this,a.substr(c),!0),this.signatureData=a.substr(0,c);var e=c;c+=b.call(this,a.substr(c),!1),this.unhashedSubpackets=a.substr(e,c-e);break;default:throw new Error("Version "+this.version+" of the signature is unsupported.")}this.signedHashValue=a.substr(c,2),c+=2,this.signature=a.substr(c)},d.prototype.write=function(){var a="";switch(this.version){case 3:a+=String.fromCharCode(3),a+=String.fromCharCode(5),a+=this.signatureData,a+=this.issuerKeyId.write(),a+=String.fromCharCode(this.publicKeyAlgorithm),a+=String.fromCharCode(this.hashAlgorithm);break;case 4:a+=this.signatureData,a+=this.unhashedSubpackets?this.unhashedSubpackets:f.writeNumber(0,2)}return a+=this.signedHashValue+this.signature},d.prototype.sign=function(a,b){var c=h.write(h.signature,this.signatureType),d=h.write(h.publicKey,this.publicKeyAlgorithm),e=h.write(h.hash,this.hashAlgorithm),f=String.fromCharCode(4);f+=String.fromCharCode(c),f+=String.fromCharCode(d),f+=String.fromCharCode(e),this.issuerKeyId=a.getKeyId(),f+=this.write_all_sub_packets(),this.signatureData=f;var g=this.calculateTrailer(),j=this.toSign(c,b)+this.signatureData+g,k=i.hash.digest(e,j);this.signedHashValue=k.substr(0,2),this.signature=i.signature.sign(e,d,a.mpi,j)},d.prototype.write_all_sub_packets=function(){var a=h.signatureSubpacket,b="",c="";if(null!==this.created&&(b+=e(a.signature_creation_time,f.writeDate(this.created))),null!==this.signatureExpirationTime&&(b+=e(a.signature_expiration_time,f.writeNumber(this.signatureExpirationTime,4))),null!==this.exportable&&(b+=e(a.exportable_certification,String.fromCharCode(this.exportable?1:0))),null!==this.trustLevel&&(c=String.fromCharCode(this.trustLevel)+String.fromCharCode(this.trustAmount),b+=e(a.trust_signature,c)),null!==this.regularExpression&&(b+=e(a.regular_expression,this.regularExpression)),null!==this.revocable&&(b+=e(a.revocable,String.fromCharCode(this.revocable?1:0))),null!==this.keyExpirationTime&&(b+=e(a.key_expiration_time,f.writeNumber(this.keyExpirationTime,4))),null!==this.preferredSymmetricAlgorithms&&(c=f.bin2str(this.preferredSymmetricAlgorithms),b+=e(a.preferred_symmetric_algorithms,c)),null!==this.revocationKeyClass&&(c=String.fromCharCode(this.revocationKeyClass),c+=String.fromCharCode(this.revocationKeyAlgorithm),c+=this.revocationKeyFingerprint,b+=e(a.revocation_key,c)),this.issuerKeyId.isNull()||(b+=e(a.issuer,this.issuerKeyId.write())),null!==this.notation)for(var d in this.notation)if(this.notation.hasOwnProperty(d)){var g=this.notation[d];c=String.fromCharCode(128),c+=String.fromCharCode(0),c+=String.fromCharCode(0),c+=String.fromCharCode(0),c+=f.writeNumber(d.length,2),c+=f.writeNumber(g.length,2),c+=d+g,b+=e(a.notation_data,c)}return null!==this.preferredHashAlgorithms&&(c=f.bin2str(this.preferredHashAlgorithms),b+=e(a.preferred_hash_algorithms,c)),null!==this.preferredCompressionAlgorithms&&(c=f.bin2str(this.preferredCompressionAlgorithms),b+=e(a.preferred_compression_algorithms,c)),null!==this.keyServerPreferences&&(c=f.bin2str(this.keyServerPreferences),b+=e(a.key_server_preferences,c)),null!==this.preferredKeyServer&&(b+=e(a.preferred_key_server,this.preferredKeyServer)),null!==this.isPrimaryUserID&&(b+=e(a.primary_user_id,String.fromCharCode(this.isPrimaryUserID?1:0))),null!==this.policyURI&&(b+=e(a.policy_uri,this.policyURI)),null!==this.keyFlags&&(c=f.bin2str(this.keyFlags),b+=e(a.key_flags,c)),null!==this.signersUserId&&(b+=e(a.signers_user_id,this.signersUserId)),null!==this.reasonForRevocationFlag&&(c=String.fromCharCode(this.reasonForRevocationFlag),c+=this.reasonForRevocationString,b+=e(a.reason_for_revocation,c)),null!==this.features&&(c=f.bin2str(this.features),b+=e(a.features,c)),null!==this.signatureTargetPublicKeyAlgorithm&&(c=String.fromCharCode(this.signatureTargetPublicKeyAlgorithm),c+=String.fromCharCode(this.signatureTargetHashAlgorithm),c+=this.signatureTargetHash,b+=e(a.signature_target,c)),null!==this.embeddedSignature&&(b+=e(a.embedded_signature,this.embeddedSignature.write())),b=f.writeNumber(b.length,2)+b},d.prototype.read_sub_packet=function(a){function b(a,b){this[a]=[];for(var c=0;c0&&4>d?k=1:17==d&&(k=2);for(var l=[],m=0,n=0;k>n;n++)l[n]=new j,m+=l[n].read(this.signature.substr(m));return this.verified=i.signature.verify(d,e,l,a.mpi,f+this.signatureData+g),this.verified},d.prototype.isExpired=function(){return this.signatureNeverExpires?!1:Date.now()>this.created.getTime()+1e3*this.signatureExpirationTime},d.prototype.postCloneTypeFix=function(){this.issuerKeyId=k.fromClone(this.issuerKeyId)}},{"../crypto":32,"../enums.js":43,"../type/keyid.js":73,"../type/mpi.js":74,"../util.js":76,"./packet.js":59}],67:[function(a,b,c){function d(){this.tag=f.packet.symEncryptedIntegrityProtected,this.encrypted=null,this.modification=!1,this.packets=null}b.exports=d;var e=(a("../util.js"),a("../crypto")),f=a("../enums.js");d.prototype.read=function(a){var b=a.charCodeAt(0);if(1!=b)throw new Error("Invalid packet version.");this.encrypted=a.substr(1)},d.prototype.write=function(){return String.fromCharCode(1)+this.encrypted},d.prototype.encrypt=function(a,b){var c=this.packets.write(),d=e.getPrefixRandom(a),f=d+d.charAt(d.length-2)+d.charAt(d.length-1),g=c;g+=String.fromCharCode(211),g+=String.fromCharCode(20),g+=e.hash.sha1(f+g),this.encrypted=e.cfb.encrypt(d,a,g,b,!1),f.length+g.length!=this.encrypted.length&&(this.encrypted=this.encrypted.substring(0,f.length+g.length))},d.prototype.decrypt=function(a,b){var c=e.cfb.decrypt(a,b,this.encrypted,!1),d=c.slice(c.length-20,c.length).join("");if(c.splice(c.length-20),this.hash=e.hash.sha1(e.cfb.mdc(a,b,this.encrypted)+c.join("")),this.hash!=d)throw new Error("Modification detected.");c.splice(c.length-2),this.packets.read(c.join(""))}},{"../crypto":32,"../enums.js":43,"../util.js":76}],68:[function(a,b,c){function d(){this.tag=f.packet.symEncryptedSessionKey,this.version=4,this.sessionKeyEncryptionAlgorithm=null,this.sessionKeyAlgorithm="aes256",this.encrypted=null,this.s2k=new e}var e=a("../type/s2k.js"),f=a("../enums.js"),g=a("../crypto");b.exports=d,d.prototype.read=function(a){this.version=a.charCodeAt(0);var b=f.read(f.symmetric,a.charCodeAt(1)),c=this.s2k.read(a.substr(2)),d=c+2;d>4)+a},d.prototype.read=function(a){var b=0;switch(this.type=e.read(e.s2k,a.charCodeAt(b++)),this.algorithm=e.read(e.hash,a.charCodeAt(b++)),this.type){case"simple":break;case"salted":this.salt=a.substr(b,8),b+=8;break;case"iterated":this.salt=a.substr(b,8),b+=8,this.c=a.charCodeAt(b++);break;case"gnu":if("GNU"!=a.substr(b,3))throw new Error("Unknown s2k type.");b+=3;var c=1e3+a.charCodeAt(b++);if(1001!=c)throw new Error("Unknown s2k gnu protection mode.");this.type=c;break;default:throw new Error("Unknown s2k type.")}return b},d.prototype.write=function(){var a=String.fromCharCode(e.write(e.s2k,this.type));switch(a+=String.fromCharCode(e.write(e.hash,this.algorithm)),this.type){case"simple":break;case"salted":a+=this.salt;break;case"iterated":a+=this.salt,a+=String.fromCharCode(this.c);break;case"gnu":throw new Error("GNU s2k type not supported.");default:throw new Error("Unknown s2k type.")}return a},d.prototype.produce_key=function(a,b){function c(b,c){var d=e.write(e.hash,c.algorithm);switch(c.type){case"simple":return g.hash.digest(d,b+a);case"salted":return g.hash.digest(d,b+c.salt+a);case"iterated":for(var f=[],h=c.get_count(),i=c.salt+a;f.length*i.lengthh&&(f=f.substr(0,h)),g.hash.digest(d,b+f);case"gnu":throw new Error("GNU s2k type not supported.");default:throw new Error("Unknown s2k type.")}}a=f.encode_utf8(a);for(var d="",h="";d.length<=b;)d+=c(h,this),h+=String.fromCharCode(0);return d.substr(0,b)},b.exports.fromClone=function(a){var b=new d;return this.algorithm=a.algorithm,this.type=a.type,this.c=a.c,this.salt=a.salt,b}},{"../crypto":32,"../enums.js":43,"../util.js":76}],76:[function(a,b,c){"use strict";var d=a("./config");b.exports={readNumber:function(a){for(var b=0,c=0;cd;d++)c+=String.fromCharCode(a>>8*(b-d-1)&255);return c},readDate:function(a){var b=this.readNumber(a),c=new Date;return c.setTime(1e3*b),c},writeDate:function(a){var b=Math.round(a.getTime()/1e3);return this.writeNumber(b,4)},emailRegEx:/^[+a-zA-Z0-9_.-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,6}$/,hexdump:function(a){for(var b,c=[],d=a.length,e=0,f=0;d>e;){for(b=a.charCodeAt(e++).toString(16);b.length<2;)b="0"+b;c.push(" "+b),f++,f%32===0&&c.push("\n ")}return c.join("")},hexstrdump:function(a){if(null===a)return"";for(var b,c=[],d=a.length,e=0;d>e;){for(b=a.charCodeAt(e++).toString(16);b.length<2;)b="0"+b;c.push(""+b)}return c.join("")},hex2bin:function(a){for(var b="",c=0;ce;){for(b=a[e++].toString(16);b.length<2;)b="0"+b;c.push(""+b)}return c.join("")},encode_utf8:function(a){return unescape(encodeURIComponent(a))},decode_utf8:function(a){if("string"!=typeof a)throw new Error('Parameter "utf8" is not of type string');try{return decodeURIComponent(escape(a))}catch(b){return a}},bin2str:function(a){for(var b=[],c=0;c=0;d--)c[d]>>=b%8,d>0&&(c[d]|=c[d-1]<<8-b%8&255);return util.bin2str(c)},get_hashAlgorithmString:function(a){switch(a){case 1:return"MD5";case 2:return"SHA1";case 3:return"RIPEMD160";case 8:return"SHA256";case 9:return"SHA384";case 10:return"SHA512";case 11:return"SHA224"}return"unknown"},getWebCrypto:function(){if(d.useWebCrypto!==!1&&"undefined"!=typeof window){if(window.crypto)return window.crypto.subtle||window.crypto.webkitSubtle;if(window.msCrypto)return window.msCrypto.subtle}}}},{"./config":17}],77:[function(a,b,c){"use strict";function d(a,b){b&&b.worker?this.worker=b.worker:this.worker=new Worker(a||"openpgp.worker.js"),this.worker.onmessage=this.onMessage.bind(this),this.worker.onerror=function(a){throw new Error("Unhandled error in openpgp worker: "+a.message+" ("+a.filename+":"+a.lineno+")")},this.seedRandom(i),this.tasks=[],b&&b.config&&this.worker.postMessage({event:"configure",config:b.config})}var e=a("../crypto"),f=a("../packet"),g=a("../key.js"),h=a("../type/keyid.js"),i=5e4,j=2e4;d.prototype.execute=function(a){var b=this,c=new Promise(function(c,d){a(),b.tasks.push({resolve:c,reject:d})});return c},d.prototype.onMessage=function(a){var b=a.data;switch(b.event){case"method-return":b.err?this.tasks.shift().reject(new Error(b.err)):this.tasks.shift().resolve(b.data);break;case"request-seed":this.seedRandom(j);break;default:throw new Error("Unknown Worker Event.")}},d.prototype.seedRandom=function(a){var b=this.getRandomBuffer(a);this.worker.postMessage({event:"seed-random",buf:b})},d.prototype.getRandomBuffer=function(a){if(!a)return null;var b=new Uint8Array(a);return e.random.getRandomValues(b),b},d.prototype.terminate=function(){this.worker.terminate()},d.prototype.encryptMessage=function(a,b){var c=this;return c.execute(function(){a.length||(a=[a]),a=a.map(function(a){return a.toPacketlist()}),c.worker.postMessage({event:"encrypt-message",keys:a,text:b})})},d.prototype.signAndEncryptMessage=function(a,b,c){var d=this;return d.execute(function(){a.length||(a=[a]),a=a.map(function(a){return a.toPacketlist()}),b=b.toPacketlist(),d.worker.postMessage({event:"sign-and-encrypt-message",publicKeys:a,privateKey:b,text:c})})},d.prototype.decryptMessage=function(a,b){var c=this;return c.execute(function(){a=a.toPacketlist(),c.worker.postMessage({event:"decrypt-message",privateKey:a,message:b})})},d.prototype.decryptAndVerifyMessage=function(a,b,c){var d=this,e=new Promise(function(e,f){a=a.toPacketlist(),b.length||(b=[b]),b=b.map(function(a){return a.toPacketlist()}),d.worker.postMessage({event:"decrypt-and-verify-message",privateKey:a,publicKeys:b,message:c}),d.tasks.push({resolve:function(a){a.signatures=a.signatures.map(function(a){return a.keyid=h.fromClone(a.keyid),a}),e(a)},reject:f})});return e},d.prototype.signClearMessage=function(a,b){var c=this;return c.execute(function(){a.length||(a=[a]),a=a.map(function(a){return a.toPacketlist()}),c.worker.postMessage({event:"sign-clear-message",privateKeys:a,text:b})})},d.prototype.verifyClearSignedMessage=function(a,b){var c=this,d=new Promise(function(d,e){a.length||(a=[a]),a=a.map(function(a){return a.toPacketlist()}),c.worker.postMessage({event:"verify-clear-signed-message",publicKeys:a,message:b}),c.tasks.push({resolve:function(a){a.signatures=a.signatures.map(function(a){return a.keyid=h.fromClone(a.keyid),a}),d(a)},reject:e})});return d},d.prototype.generateKeyPair=function(a){var b=this,c=new Promise(function(c,d){b.worker.postMessage({event:"generate-key-pair",options:a}),b.tasks.push({resolve:function(a){var b=f.List.fromStructuredClone(a.key);a.key=new g.Key(b),c(a)},reject:d})});return c},d.prototype.decryptKey=function(a,b){var c=this,d=new Promise(function(d,e){a=a.toPacketlist(),c.worker.postMessage({event:"decrypt-key",privateKey:a,password:b}),c.tasks.push({resolve:function(a){var b=f.List.fromStructuredClone(a),a=new g.Key(b);d(a)},reject:e})});return d},d.prototype.decryptKeyPacket=function(a,b,c){var d=this,e=new Promise(function(e,h){a=a.toPacketlist(),d.worker.postMessage({event:"decrypt-key-packet",privateKey:a,keyIds:b,password:c}),d.tasks.push({resolve:function(a){var b=f.List.fromStructuredClone(a),a=new g.Key(b);e(a)},reject:h})});return e},b.exports=d},{"../crypto":32,"../key.js":47,"../packet":55,"../type/keyid.js":73}]},{},[46])(46)}); \ No newline at end of file +/*! OpenPGPjs.org this is LGPL licensed code, see LICENSE/our website for more information.- v2.0.0 - 2016-02-13 */!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.openpgp=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};a[g][0].call(k.exports,function(b){var c=a[g][1][b];return e(c?c:b)},k,k.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;ge;e++){var g=a.charCodeAt(e);if(b&&g>=55296&&56319>=g){if(++e>=c)throw new Error("Malformed string, low surrogate expected at position "+e);g=(55296^g)<<10|65536|56320^a.charCodeAt(e)}else if(!b&&g>>>8)throw new Error("Wide characters are not allowed.");!b||127>=g?d[f++]=g:2047>=g?(d[f++]=192|g>>6,d[f++]=128|63&g):65535>=g?(d[f++]=224|g>>12,d[f++]=128|g>>6&63,d[f++]=128|63&g):(d[f++]=240|g>>18,d[f++]=128|g>>12&63,d[f++]=128|g>>6&63,d[f++]=128|63&g)}return d.subarray(0,f)}function i(a,b){b=!!b;for(var c=a.length,d=new Array(c),e=0,f=0;c>e;e++){var g=a[e];if(!b||128>g)d[f++]=g;else if(g>=192&&224>g&&c>e+1)d[f++]=(31&g)<<6|63&a[++e];else if(g>=224&&240>g&&c>e+2)d[f++]=(15&g)<<12|(63&a[++e])<<6|63&a[++e];else{if(!(g>=240&&248>g&&c>e+3))throw new Error("Malformed UTF8 character at byte offset "+e);var h=(7&g)<<18|(63&a[++e])<<12|(63&a[++e])<<6|63&a[++e];65535>=h?d[f++]=h:(h^=65536,d[f++]=55296|h>>10,d[f++]=56320|1023&h)}}for(var i="",j=16384,e=0;f>e;e+=j)i+=String.fromCharCode.apply(String,d.slice(e,f>=e+j?e+j:f));return i}function j(a){for(var b="",c=0;c=d)throw new Error("heap size must be a positive integer and a multiple of 4096");return c=c||new a(new ArrayBuffer(d))}function p(a,b,c,d,e){var f=a.length-b,g=e>f?f:e;return a.set(c.subarray(d,d+g),b),g}function q(a){a=a||{},this.heap=o(Uint8Array,a).subarray(N.HEAP_DATA),this.asm=a.asm||N(d,null,this.heap.buffer),this.mode=null,this.key=null,this.reset(a)}function r(a){if(void 0!==a){if(m(a)||n(a))a=new Uint8Array(a);else{if(!l(a))throw new TypeError("unexpected key type");a=h(a)}var b=a.length;if(16!==b&&24!==b&&32!==b)throw new f("illegal key size");var c=new DataView(a.buffer,a.byteOffset,a.byteLength);this.asm.set_key(b>>2,c.getUint32(0),c.getUint32(4),c.getUint32(8),c.getUint32(12),b>16?c.getUint32(16):0,b>16?c.getUint32(20):0,b>24?c.getUint32(24):0,b>24?c.getUint32(28):0),this.key=a}else if(!this.key)throw new Error("key is required")}function s(a){if(void 0!==a){if(m(a)||n(a))a=new Uint8Array(a);else{if(!l(a))throw new TypeError("unexpected iv type");a=h(a)}if(16!==a.length)throw new f("illegal iv size");var b=new DataView(a.buffer,a.byteOffset,a.byteLength);this.iv=a,this.asm.set_iv(b.getUint32(0),b.getUint32(4),b.getUint32(8),b.getUint32(12))}else this.iv=null,this.asm.set_iv(0,0,0,0)}function t(a){void 0!==a?this.padding=!!a:this.padding=!0}function u(a){return a=a||{},this.result=null,this.pos=0,this.len=0,r.call(this,a.key),this.hasOwnProperty("iv")&&s.call(this,a.iv),this.hasOwnProperty("padding")&&t.call(this,a.padding),this}function v(a){if(l(a)&&(a=h(a)),m(a)&&(a=new Uint8Array(a)),!n(a))throw new TypeError("data isn't of expected type");for(var b=this.asm,c=this.heap,d=N.ENC[this.mode],e=N.HEAP_DATA,f=this.pos,g=this.len,i=0,j=a.length||0,k=0,o=g+j&-16,q=0,r=new Uint8Array(o);j>0;)q=p(c,f+g,a,i,j),g+=q,i+=q,j-=q,q=b.cipher(d,e+f,g),q&&r.set(c.subarray(f,f+q),k),k+=q,g>q?(f+=q,g-=q):(f=0,g=0);return this.result=r,this.pos=f,this.len=g,this}function w(a){var b=null,c=0;void 0!==a&&(b=v.call(this,a).result,c=b.length);var d=this.asm,e=this.heap,g=N.ENC[this.mode],h=N.HEAP_DATA,i=this.pos,j=this.len,k=16-j%16,l=j;if(this.hasOwnProperty("padding")){if(this.padding){for(var m=0;k>m;++m)e[i+j+m]=k;j+=k,l=j}else if(j%16)throw new f("data length must be a multiple of the block size")}else j+=k;var n=new Uint8Array(c+l);return c&&n.set(b),j&&d.cipher(g,h+i,j),l&&n.set(e.subarray(i,i+l),c),this.result=n,this.pos=0,this.len=0,this}function x(a){if(l(a)&&(a=h(a)),m(a)&&(a=new Uint8Array(a)),!n(a))throw new TypeError("data isn't of expected type");var b=this.asm,c=this.heap,d=N.DEC[this.mode],e=N.HEAP_DATA,f=this.pos,g=this.len,i=0,j=a.length||0,k=0,o=g+j&-16,q=0,r=0;this.hasOwnProperty("padding")&&this.padding&&(q=g+j-o||16,o-=q);for(var s=new Uint8Array(o);j>0;)r=p(c,f+g,a,i,j),g+=r,i+=r,j-=r,r=b.cipher(d,e+f,g-(j?0:q)),r&&s.set(c.subarray(f,f+r),k),k+=r,g>r?(f+=r,g-=r):(f=0,g=0);return this.result=s,this.pos=f,this.len=g,this}function y(a){var b=null,c=0;void 0!==a&&(b=x.call(this,a).result,c=b.length);var d=this.asm,e=this.heap,h=N.DEC[this.mode],i=N.HEAP_DATA,j=this.pos,k=this.len,l=k;if(k>0){if(k%16){if(this.hasOwnProperty("padding"))throw new f("data length must be a multiple of the block size");k+=16-k%16}if(d.cipher(h,i+j,k),this.hasOwnProperty("padding")&&this.padding){var m=e[j+l-1];if(1>m||m>16||m>l)throw new g("bad padding");for(var n=0,o=m;o>1;o--)n|=m^e[j+l-o];if(n)throw new g("bad padding");l-=m}}var p=new Uint8Array(c+l);return c>0&&p.set(b),l>0&&p.set(e.subarray(j,j+l),c),this.result=p,this.pos=0,this.len=0,this}function z(a){this.iv=null,q.call(this,a),this.mode="CFB"}function A(a){z.call(this,a)}function B(a){z.call(this,a)}function C(a,b,c){if(void 0===a)throw new SyntaxError("data required");if(void 0===b)throw new SyntaxError("key required");return new z({heap:R,asm:S,key:b,iv:c}).encrypt(a).result}function D(a,b,c){if(void 0===a)throw new SyntaxError("data required");if(void 0===b)throw new SyntaxError("key required");return new z({heap:R,asm:S,key:b,iv:c}).decrypt(a).result}function E(){return this.result=null,this.pos=0,this.len=0,this.asm.reset(),this}function F(a){if(null!==this.result)throw new e("state must be reset before processing new data");if(l(a)&&(a=h(a)),m(a)&&(a=new Uint8Array(a)),!n(a))throw new TypeError("data isn't of expected type");for(var b=this.asm,c=this.heap,d=this.pos,f=this.len,g=0,i=a.length,j=0;i>0;)j=p(c,d+f,a,g,i),f+=j,g+=j,i-=j,j=b.process(d,f),d+=j,f-=j,f||(d=0);return this.pos=d,this.len=f,this}function G(){if(null!==this.result)throw new e("state must be reset before processing new data");return 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,this}function H(a,b,c){"use asm";var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;var n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0;var D=new a.Uint8Array(c);function E(a,b,c,l,m,n,o,p,q,r,s,t,u,v,w,x){a=a|0;b=b|0;c=c|0;l=l|0;m=m|0;n=n|0;o=o|0;p=p|0;q=q|0;r=r|0;s=s|0;t=t|0;u=u|0;v=v|0;w=w|0;x=x|0;var y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0;y=d;z=e;A=f;B=g;C=h;D=i;E=j;F=k;G=a+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x428a2f98|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=b+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x71374491|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=c+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xb5c0fbcf|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=l+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xe9b5dba5|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=m+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x3956c25b|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=n+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x59f111f1|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=o+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x923f82a4|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=p+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xab1c5ed5|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=q+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xd807aa98|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=r+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x12835b01|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=s+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x243185be|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=t+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x550c7dc3|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=u+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x72be5d74|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=v+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x80deb1fe|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=w+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x9bdc06a7|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;G=x+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xc19bf174|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;a=G=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(w>>>17^w>>>19^w>>>10^w<<15^w<<13)+a+r|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xe49b69c1|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;b=G=(c>>>7^c>>>18^c>>>3^c<<25^c<<14)+(x>>>17^x>>>19^x>>>10^x<<15^x<<13)+b+s|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xefbe4786|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;c=G=(l>>>7^l>>>18^l>>>3^l<<25^l<<14)+(a>>>17^a>>>19^a>>>10^a<<15^a<<13)+c+t|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x0fc19dc6|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;l=G=(m>>>7^m>>>18^m>>>3^m<<25^m<<14)+(b>>>17^b>>>19^b>>>10^b<<15^b<<13)+l+u|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x240ca1cc|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;m=G=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+m+v|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x2de92c6f|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;n=G=(o>>>7^o>>>18^o>>>3^o<<25^o<<14)+(l>>>17^l>>>19^l>>>10^l<<15^l<<13)+n+w|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x4a7484aa|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;o=G=(p>>>7^p>>>18^p>>>3^p<<25^p<<14)+(m>>>17^m>>>19^m>>>10^m<<15^m<<13)+o+x|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x5cb0a9dc|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;p=G=(q>>>7^q>>>18^q>>>3^q<<25^q<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+p+a|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x76f988da|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;q=G=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+q+b|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x983e5152|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;r=G=(s>>>7^s>>>18^s>>>3^s<<25^s<<14)+(p>>>17^p>>>19^p>>>10^p<<15^p<<13)+r+c|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xa831c66d|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;s=G=(t>>>7^t>>>18^t>>>3^t<<25^t<<14)+(q>>>17^q>>>19^q>>>10^q<<15^q<<13)+s+l|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xb00327c8|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;t=G=(u>>>7^u>>>18^u>>>3^u<<25^u<<14)+(r>>>17^r>>>19^r>>>10^r<<15^r<<13)+t+m|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xbf597fc7|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;u=G=(v>>>7^v>>>18^v>>>3^v<<25^v<<14)+(s>>>17^s>>>19^s>>>10^s<<15^s<<13)+u+n|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xc6e00bf3|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;v=G=(w>>>7^w>>>18^w>>>3^w<<25^w<<14)+(t>>>17^t>>>19^t>>>10^t<<15^t<<13)+v+o|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xd5a79147|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;w=G=(x>>>7^x>>>18^x>>>3^x<<25^x<<14)+(u>>>17^u>>>19^u>>>10^u<<15^u<<13)+w+p|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x06ca6351|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;x=G=(a>>>7^a>>>18^a>>>3^a<<25^a<<14)+(v>>>17^v>>>19^v>>>10^v<<15^v<<13)+x+q|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x14292967|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;a=G=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(w>>>17^w>>>19^w>>>10^w<<15^w<<13)+a+r|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x27b70a85|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;b=G=(c>>>7^c>>>18^c>>>3^c<<25^c<<14)+(x>>>17^x>>>19^x>>>10^x<<15^x<<13)+b+s|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x2e1b2138|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;c=G=(l>>>7^l>>>18^l>>>3^l<<25^l<<14)+(a>>>17^a>>>19^a>>>10^a<<15^a<<13)+c+t|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x4d2c6dfc|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;l=G=(m>>>7^m>>>18^m>>>3^m<<25^m<<14)+(b>>>17^b>>>19^b>>>10^b<<15^b<<13)+l+u|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x53380d13|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;m=G=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+m+v|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x650a7354|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;n=G=(o>>>7^o>>>18^o>>>3^o<<25^o<<14)+(l>>>17^l>>>19^l>>>10^l<<15^l<<13)+n+w|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x766a0abb|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;o=G=(p>>>7^p>>>18^p>>>3^p<<25^p<<14)+(m>>>17^m>>>19^m>>>10^m<<15^m<<13)+o+x|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x81c2c92e|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;p=G=(q>>>7^q>>>18^q>>>3^q<<25^q<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+p+a|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x92722c85|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;q=G=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+q+b|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xa2bfe8a1|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;r=G=(s>>>7^s>>>18^s>>>3^s<<25^s<<14)+(p>>>17^p>>>19^p>>>10^p<<15^p<<13)+r+c|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xa81a664b|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;s=G=(t>>>7^t>>>18^t>>>3^t<<25^t<<14)+(q>>>17^q>>>19^q>>>10^q<<15^q<<13)+s+l|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xc24b8b70|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;t=G=(u>>>7^u>>>18^u>>>3^u<<25^u<<14)+(r>>>17^r>>>19^r>>>10^r<<15^r<<13)+t+m|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xc76c51a3|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;u=G=(v>>>7^v>>>18^v>>>3^v<<25^v<<14)+(s>>>17^s>>>19^s>>>10^s<<15^s<<13)+u+n|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xd192e819|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;v=G=(w>>>7^w>>>18^w>>>3^w<<25^w<<14)+(t>>>17^t>>>19^t>>>10^t<<15^t<<13)+v+o|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xd6990624|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;w=G=(x>>>7^x>>>18^x>>>3^x<<25^x<<14)+(u>>>17^u>>>19^u>>>10^u<<15^u<<13)+w+p|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xf40e3585|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;x=G=(a>>>7^a>>>18^a>>>3^a<<25^a<<14)+(v>>>17^v>>>19^v>>>10^v<<15^v<<13)+x+q|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x106aa070|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;a=G=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(w>>>17^w>>>19^w>>>10^w<<15^w<<13)+a+r|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x19a4c116|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;b=G=(c>>>7^c>>>18^c>>>3^c<<25^c<<14)+(x>>>17^x>>>19^x>>>10^x<<15^x<<13)+b+s|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x1e376c08|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;c=G=(l>>>7^l>>>18^l>>>3^l<<25^l<<14)+(a>>>17^a>>>19^a>>>10^a<<15^a<<13)+c+t|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x2748774c|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;l=G=(m>>>7^m>>>18^m>>>3^m<<25^m<<14)+(b>>>17^b>>>19^b>>>10^b<<15^b<<13)+l+u|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x34b0bcb5|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;m=G=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+m+v|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x391c0cb3|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;n=G=(o>>>7^o>>>18^o>>>3^o<<25^o<<14)+(l>>>17^l>>>19^l>>>10^l<<15^l<<13)+n+w|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x4ed8aa4a|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;o=G=(p>>>7^p>>>18^p>>>3^p<<25^p<<14)+(m>>>17^m>>>19^m>>>10^m<<15^m<<13)+o+x|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x5b9cca4f|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;p=G=(q>>>7^q>>>18^q>>>3^q<<25^q<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+p+a|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x682e6ff3|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;q=G=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+q+b|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x748f82ee|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;r=G=(s>>>7^s>>>18^s>>>3^s<<25^s<<14)+(p>>>17^p>>>19^p>>>10^p<<15^p<<13)+r+c|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x78a5636f|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;s=G=(t>>>7^t>>>18^t>>>3^t<<25^t<<14)+(q>>>17^q>>>19^q>>>10^q<<15^q<<13)+s+l|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x84c87814|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;t=G=(u>>>7^u>>>18^u>>>3^u<<25^u<<14)+(r>>>17^r>>>19^r>>>10^r<<15^r<<13)+t+m|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x8cc70208|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;u=G=(v>>>7^v>>>18^v>>>3^v<<25^v<<14)+(s>>>17^s>>>19^s>>>10^s<<15^s<<13)+u+n|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0x90befffa|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;v=G=(w>>>7^w>>>18^w>>>3^w<<25^w<<14)+(t>>>17^t>>>19^t>>>10^t<<15^t<<13)+v+o|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xa4506ceb|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;w=G=(x>>>7^x>>>18^x>>>3^x<<25^x<<14)+(u>>>17^u>>>19^u>>>10^u<<15^u<<13)+w+p|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xbef9a3f7|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;x=G=(a>>>7^a>>>18^a>>>3^a<<25^a<<14)+(v>>>17^v>>>19^v>>>10^v<<15^v<<13)+x+q|0;G=G+F+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(E^C&(D^E))+0xc67178f2|0;F=E;E=D;D=C;C=B+G|0;B=A;A=z;z=y;y=G+(z&A^B&(z^A))+(z>>>2^z>>>13^z>>>22^z<<30^z<<19^z<<10)|0;d=d+y|0;e=e+z|0;f=f+A|0;g=g+B|0;h=h+C|0;i=i+D|0;j=j+E|0;k=k+F|0}function F(a){a=a|0;E(D[a|0]<<24|D[a|1]<<16|D[a|2]<<8|D[a|3],D[a|4]<<24|D[a|5]<<16|D[a|6]<<8|D[a|7],D[a|8]<<24|D[a|9]<<16|D[a|10]<<8|D[a|11],D[a|12]<<24|D[a|13]<<16|D[a|14]<<8|D[a|15],D[a|16]<<24|D[a|17]<<16|D[a|18]<<8|D[a|19],D[a|20]<<24|D[a|21]<<16|D[a|22]<<8|D[a|23],D[a|24]<<24|D[a|25]<<16|D[a|26]<<8|D[a|27],D[a|28]<<24|D[a|29]<<16|D[a|30]<<8|D[a|31],D[a|32]<<24|D[a|33]<<16|D[a|34]<<8|D[a|35],D[a|36]<<24|D[a|37]<<16|D[a|38]<<8|D[a|39],D[a|40]<<24|D[a|41]<<16|D[a|42]<<8|D[a|43],D[a|44]<<24|D[a|45]<<16|D[a|46]<<8|D[a|47],D[a|48]<<24|D[a|49]<<16|D[a|50]<<8|D[a|51],D[a|52]<<24|D[a|53]<<16|D[a|54]<<8|D[a|55],D[a|56]<<24|D[a|57]<<16|D[a|58]<<8|D[a|59],D[a|60]<<24|D[a|61]<<16|D[a|62]<<8|D[a|63])}function G(a){a=a|0;D[a|0]=d>>>24;D[a|1]=d>>>16&255;D[a|2]=d>>>8&255;D[a|3]=d&255;D[a|4]=e>>>24;D[a|5]=e>>>16&255;D[a|6]=e>>>8&255;D[a|7]=e&255;D[a|8]=f>>>24;D[a|9]=f>>>16&255;D[a|10]=f>>>8&255;D[a|11]=f&255;D[a|12]=g>>>24;D[a|13]=g>>>16&255;D[a|14]=g>>>8&255;D[a|15]=g&255;D[a|16]=h>>>24;D[a|17]=h>>>16&255;D[a|18]=h>>>8&255;D[a|19]=h&255;D[a|20]=i>>>24;D[a|21]=i>>>16&255;D[a|22]=i>>>8&255;D[a|23]=i&255;D[a|24]=j>>>24;D[a|25]=j>>>16&255;D[a|26]=j>>>8&255;D[a|27]=j&255;D[a|28]=k>>>24;D[a|29]=k>>>16&255;D[a|30]=k>>>8&255;D[a|31]=k&255}function H(){d=0x6a09e667;e=0xbb67ae85;f=0x3c6ef372;g=0xa54ff53a;h=0x510e527f;i=0x9b05688c;j=0x1f83d9ab;k=0x5be0cd19;l=m=0}function I(a,b,c,n,o,p,q,r,s,t){a=a|0;b=b|0;c=c|0;n=n|0;o=o|0;p=p|0;q=q|0;r=r|0;s=s|0;t=t|0;d=a;e=b;f=c;g=n;h=o;i=p;j=q;k=r;l=s;m=t}function J(a,b){a=a|0;b=b|0;var c=0;if(a&63)return-1;while((b|0)>=64){F(a);a=a+64|0;b=b-64|0;c=c+64|0}l=l+c|0;if(l>>>0>>0)m=m+1|0;return c|0}function K(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;if(a&63)return-1;if(~c)if(c&31)return-1;if((b|0)>=64){d=J(a,b)|0;if((d|0)==-1)return-1;a=a+d|0;b=b-d|0}d=d+b|0;l=l+b|0;if(l>>>0>>0)m=m+1|0;D[a|b]=0x80;if((b|0)>=56){for(e=b+1|0;(e|0)<64;e=e+1|0)D[a|e]=0x00;F(a);b=0;D[a|0]=0}for(e=b+1|0;(e|0)<59;e=e+1|0)D[a|e]=0;D[a|56]=m>>>21&255;D[a|57]=m>>>13&255;D[a|58]=m>>>5&255;D[a|59]=m<<3&255|l>>>29;D[a|60]=l>>>21&255;D[a|61]=l>>>13&255;D[a|62]=l>>>5&255;D[a|63]=l<<3&255;F(a);if(~c)G(c);return d|0}function L(){d=n;e=o;f=p;g=q;h=r;i=s;j=t;k=u;l=64;m=0}function M(){d=v;e=w;f=x;g=y;h=z;i=A;j=B;k=C;l=64;m=0}function N(a,b,c,D,F,G,I,J,K,L,M,N,O,P,Q,R){a=a|0;b=b|0;c=c|0;D=D|0;F=F|0;G=G|0;I=I|0;J=J|0;K=K|0;L=L|0;M=M|0;N=N|0;O=O|0;P=P|0;Q=Q|0;R=R|0;H();E(a^0x5c5c5c5c,b^0x5c5c5c5c,c^0x5c5c5c5c,D^0x5c5c5c5c,F^0x5c5c5c5c,G^0x5c5c5c5c,I^0x5c5c5c5c,J^0x5c5c5c5c,K^0x5c5c5c5c,L^0x5c5c5c5c,M^0x5c5c5c5c,N^0x5c5c5c5c,O^0x5c5c5c5c,P^0x5c5c5c5c,Q^0x5c5c5c5c,R^0x5c5c5c5c);v=d;w=e;x=f;y=g;z=h;A=i;B=j;C=k;H();E(a^0x36363636,b^0x36363636,c^0x36363636,D^0x36363636,F^0x36363636,G^0x36363636,I^0x36363636,J^0x36363636,K^0x36363636,L^0x36363636,M^0x36363636,N^0x36363636,O^0x36363636,P^0x36363636,Q^0x36363636,R^0x36363636);n=d;o=e;p=f;q=g;r=h;s=i;t=j;u=k;l=64;m=0}function O(a,b,c){a=a|0;b=b|0;c=c|0;var l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0;if(a&63)return-1;if(~c)if(c&31)return-1;t=K(a,b,-1)|0;l=d,m=e,n=f,o=g,p=h,q=i,r=j,s=k;M();E(l,m,n,o,p,q,r,s,0x80000000,0,0,0,0,0,0,768);if(~c)G(c);return t|0}function P(a,b,c,l,m){a=a|0;b=b|0;c=c|0;l=l|0;m=m|0;var n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0;if(a&63)return-1;if(~m)if(m&31)return-1;D[a+b|0]=c>>>24;D[a+b+1|0]=c>>>16&255;D[a+b+2|0]=c>>>8&255;D[a+b+3|0]=c&255;O(a,b+4|0,-1)|0;n=v=d,o=w=e,p=x=f,q=y=g,r=z=h,s=A=i,t=B=j,u=C=k;l=l-1|0;while((l|0)>0){L();E(v,w,x,y,z,A,B,C,0x80000000,0,0,0,0,0,0,768);v=d,w=e,x=f,y=g,z=h,A=i,B=j,C=k;M();E(v,w,x,y,z,A,B,C,0x80000000,0,0,0,0,0,0,768);v=d,w=e,x=f,y=g,z=h,A=i,B=j,C=k;n=n^d;o=o^e;p=p^f;q=q^g;r=r^h;s=s^i;t=t^j;u=u^k;l=l-1|0}d=n;e=o;f=p;g=q;h=r;i=s;j=t;k=u;if(~m)G(m);return 0}return{reset:H,init:I,process:J,finish:K,hmac_reset:L,hmac_init:N,hmac_finish:O,pbkdf2_generate_block:P}}function I(a){a=a||{},this.heap=o(Uint8Array,a),this.asm=a.asm||H(d,null,this.heap.buffer),this.BLOCK_SIZE=T,this.HASH_SIZE=U,this.reset()}function J(){return null===W&&(W=new I({heapSize:1048576})),W}function K(a){if(void 0===a)throw new SyntaxError("data required");return J().reset().process(a).finish().result}function L(a){var b=K(a);return j(b)}function M(a){var b=K(a);return k(b)}e.prototype=Object.create(Error.prototype,{name:{value:"IllegalStateError"}}),f.prototype=Object.create(Error.prototype,{name:{value:"IllegalArgumentError"}}),g.prototype=Object.create(Error.prototype,{name:{value:"SecurityError"}});d.Float64Array||d.Float32Array;d.IllegalStateError=e,d.IllegalArgumentError=f,d.SecurityError=g;var N=function(){"use strict";function a(){e=[],f=[];var a,b,c=1;for(a=0;255>a;a++)e[a]=c,b=128&c,c<<=1,c&=255,128===b&&(c^=27),c^=e[a],f[e[a]]=a;e[255]=e[0],f[0]=0,k=!0}function b(a,b){var c=e[(f[a]+f[b])%255];return(0===a||0===b)&&(c=0),c}function c(a){var b=e[255-f[a]];return 0===a&&(b=0),b}function d(){function d(a){var b,d,e;for(d=e=c(a),b=0;4>b;b++)d=255&(d<<1|d>>>7),e^=d;return e^=99}k||a(),g=[],h=[],i=[[],[],[],[]],j=[[],[],[],[]];for(var e=0;256>e;e++){var f=d(e);g[e]=f,h[f]=e,i[0][e]=b(2,f)<<24|f<<16|f<<8|b(3,f),j[0][f]=b(14,e)<<24|b(9,e)<<16|b(13,e)<<8|b(11,e);for(var l=1;4>l;l++)i[l][e]=i[l-1][e]>>>8|i[l-1][e]<<24,j[l][f]=j[l-1][f]>>>8|j[l-1][f]<<24}}var e,f,g,h,i,j,k=!1,l=!1,m=function(a,b,c){function e(a,b,c,d,e,h,i,k,l){var n=f.subarray(0,60),o=f.subarray(256,316);n.set([b,c,d,e,h,i,k,l]);for(var p=a,q=1;4*a+28>p;p++){var r=n[p-1];(p%a===0||8===a&&p%a===4)&&(r=g[r>>>24]<<24^g[r>>>16&255]<<16^g[r>>>8&255]<<8^g[255&r]),p%a===0&&(r=r<<8^r>>>24^q<<24,q=q<<1^(128&q?27:0)),n[p]=n[p-a]^r}for(var s=0;p>s;s+=4)for(var t=0;4>t;t++){var r=n[p-(4+s)+(4-t)%4];4>s||s>=p-4?o[s+t]=r:o[s+t]=j[0][g[r>>>24]]^j[1][g[r>>>16&255]]^j[2][g[r>>>8&255]]^j[3][g[255&r]]}m.set_rounds(a+5)}l||d();var f=new Uint32Array(c);f.set(g,512),f.set(h,768);for(var k=0;4>k;k++)f.set(i[k],4096+1024*k>>2),f.set(j[k],8192+1024*k>>2);var m=function(a,b,c){"use asm";var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;var y=new a.Uint32Array(c),z=new a.Uint8Array(c);function A(a,b,c,h,i,j,k,l){a=a|0;b=b|0;c=c|0;h=h|0;i=i|0;j=j|0;k=k|0;l=l|0;var m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0;m=c|0x400,n=c|0x800,o=c|0xc00;i=i^y[(a|0)>>2],j=j^y[(a|4)>>2],k=k^y[(a|8)>>2],l=l^y[(a|12)>>2];for(t=16;(t|0)<=h<<4;t=t+16|0){p=y[(c|i>>22&1020)>>2]^y[(m|j>>14&1020)>>2]^y[(n|k>>6&1020)>>2]^y[(o|l<<2&1020)>>2]^y[(a|t|0)>>2],q=y[(c|j>>22&1020)>>2]^y[(m|k>>14&1020)>>2]^y[(n|l>>6&1020)>>2]^y[(o|i<<2&1020)>>2]^y[(a|t|4)>>2],r=y[(c|k>>22&1020)>>2]^y[(m|l>>14&1020)>>2]^y[(n|i>>6&1020)>>2]^y[(o|j<<2&1020)>>2]^y[(a|t|8)>>2],s=y[(c|l>>22&1020)>>2]^y[(m|i>>14&1020)>>2]^y[(n|j>>6&1020)>>2]^y[(o|k<<2&1020)>>2]^y[(a|t|12)>>2];i=p,j=q,k=r,l=s}d=y[(b|i>>22&1020)>>2]<<24^y[(b|j>>14&1020)>>2]<<16^y[(b|k>>6&1020)>>2]<<8^y[(b|l<<2&1020)>>2]^y[(a|t|0)>>2],e=y[(b|j>>22&1020)>>2]<<24^y[(b|k>>14&1020)>>2]<<16^y[(b|l>>6&1020)>>2]<<8^y[(b|i<<2&1020)>>2]^y[(a|t|4)>>2],f=y[(b|k>>22&1020)>>2]<<24^y[(b|l>>14&1020)>>2]<<16^y[(b|i>>6&1020)>>2]<<8^y[(b|j<<2&1020)>>2]^y[(a|t|8)>>2],g=y[(b|l>>22&1020)>>2]<<24^y[(b|i>>14&1020)>>2]<<16^y[(b|j>>6&1020)>>2]<<8^y[(b|k<<2&1020)>>2]^y[(a|t|12)>>2]}function B(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;A(0x0000,0x0800,0x1000,x,a,b,c,d)}function C(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var f=0;A(0x0400,0x0c00,0x2000,x,a,d,c,b);f=e,e=g,g=f}function D(a,b,c,l){a=a|0;b=b|0;c=c|0;l=l|0;A(0x0000,0x0800,0x1000,x,h^a,i^b,j^c,k^l);h=d,i=e,j=f,k=g}function E(a,b,c,l){a=a|0;b=b|0;c=c|0;l=l|0;var m=0;A(0x0400,0x0c00,0x2000,x,a,l,c,b);m=e,e=g,g=m;d=d^h,e=e^i,f=f^j,g=g^k;h=a,i=b,j=c,k=l}function F(a,b,c,l){a=a|0;b=b|0;c=c|0;l=l|0;A(0x0000,0x0800,0x1000,x,h,i,j,k);h=d=d^a,i=e=e^b,j=f=f^c,k=g=g^l}function G(a,b,c,l){a=a|0;b=b|0;c=c|0;l=l|0;A(0x0000,0x0800,0x1000,x,h,i,j,k);d=d^a,e=e^b,f=f^c,g=g^l;h=a,i=b,j=c,k=l}function H(a,b,c,l){a=a|0;b=b|0;c=c|0;l=l|0;A(0x0000,0x0800,0x1000,x,h,i,j,k);h=d,i=e,j=f,k=g;d=d^a,e=e^b,f=f^c,g=g^l}function I(a,b,c,h){a=a|0;b=b|0;c=c|0;h=h|0;A(0x0000,0x0800,0x1000,x,l,m,n,o);o=~s&o|s&o+1,n=~r&n|r&n+((o|0)==0),m=~q&m|q&m+((n|0)==0),l=~p&l|p&l+((m|0)==0);d=d^a,e=e^b,f=f^c,g=g^h}function J(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;a=a^h,b=b^i,c=c^j,d=d^k;e=t|0,f=u|0,g=v|0,l=w|0;for(;(q|0)<128;q=q+1|0){if(e>>>31){m=m^a,n=n^b,o=o^c,p=p^d}e=e<<1|f>>>31,f=f<<1|g>>>31,g=g<<1|l>>>31,l=l<<1;r=d&1;d=d>>>1|c<<31,c=c>>>1|b<<31,b=b>>>1|a<<31,a=a>>>1;if(r)a=a^0xe1000000}h=m,i=n,j=o,k=p}function K(a){a=a|0;x=a}function L(a,b,c,h){a=a|0;b=b|0;c=c|0;h=h|0;d=a,e=b,f=c,g=h}function M(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;h=a,i=b,j=c,k=d}function N(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;l=a,m=b,n=c,o=d}function O(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;p=a,q=b,r=c,s=d}function P(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;o=~s&o|s&d,n=~r&n|r&c,m=~q&m|q&b,l=~p&l|p&a}function Q(a){a=a|0;if(a&15)return-1;z[a|0]=d>>>24,z[a|1]=d>>>16&255,z[a|2]=d>>>8&255,z[a|3]=d&255,z[a|4]=e>>>24,z[a|5]=e>>>16&255,z[a|6]=e>>>8&255,z[a|7]=e&255,z[a|8]=f>>>24,z[a|9]=f>>>16&255,z[a|10]=f>>>8&255,z[a|11]=f&255,z[a|12]=g>>>24,z[a|13]=g>>>16&255,z[a|14]=g>>>8&255,z[a|15]=g&255;return 16}function R(a){a=a|0;if(a&15)return-1;z[a|0]=h>>>24,z[a|1]=h>>>16&255,z[a|2]=h>>>8&255,z[a|3]=h&255,z[a|4]=i>>>24,z[a|5]=i>>>16&255,z[a|6]=i>>>8&255,z[a|7]=i&255,z[a|8]=j>>>24,z[a|9]=j>>>16&255,z[a|10]=j>>>8&255,z[a|11]=j&255,z[a|12]=k>>>24,z[a|13]=k>>>16&255,z[a|14]=k>>>8&255,z[a|15]=k&255;return 16}function S(){B(0,0,0,0);t=d,u=e,v=f,w=g}function T(a,b,c){a=a|0;b=b|0;c=c|0;var h=0;if(b&15)return-1;while((c|0)>=16){V[a&7](z[b|0]<<24|z[b|1]<<16|z[b|2]<<8|z[b|3],z[b|4]<<24|z[b|5]<<16|z[b|6]<<8|z[b|7],z[b|8]<<24|z[b|9]<<16|z[b|10]<<8|z[b|11],z[b|12]<<24|z[b|13]<<16|z[b|14]<<8|z[b|15]);z[b|0]=d>>>24,z[b|1]=d>>>16&255,z[b|2]=d>>>8&255,z[b|3]=d&255,z[b|4]=e>>>24,z[b|5]=e>>>16&255,z[b|6]=e>>>8&255,z[b|7]=e&255,z[b|8]=f>>>24,z[b|9]=f>>>16&255,z[b|10]=f>>>8&255,z[b|11]=f&255,z[b|12]=g>>>24,z[b|13]=g>>>16&255,z[b|14]=g>>>8&255,z[b|15]=g&255;h=h+16|0,b=b+16|0,c=c-16|0}return h|0}function U(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;if(b&15)return-1;while((c|0)>=16){W[a&1](z[b|0]<<24|z[b|1]<<16|z[b|2]<<8|z[b|3],z[b|4]<<24|z[b|5]<<16|z[b|6]<<8|z[b|7],z[b|8]<<24|z[b|9]<<16|z[b|10]<<8|z[b|11],z[b|12]<<24|z[b|13]<<16|z[b|14]<<8|z[b|15]);d=d+16|0,b=b+16|0,c=c-16|0}return d|0}var V=[B,C,D,E,F,G,H,I];var W=[D,J]; +return{set_rounds:K,set_state:L,set_iv:M,set_nonce:N,set_mask:O,set_counter:P,get_state:Q,get_iv:R,gcm_init:S,cipher:T,mac:U}}(a,b,c);return m.set_key=e,m};return m.ENC={ECB:0,CBC:2,CFB:4,OFB:6,CTR:7},m.DEC={ECB:1,CBC:3,CFB:5,OFB:6,CTR:7},m.MAC={CBC:0,GCM:1},m.HEAP_DATA=16384,m}(),O=z.prototype;O.BLOCK_SIZE=16,O.reset=u,O.encrypt=w,O.decrypt=y;var P=A.prototype;P.BLOCK_SIZE=16,P.reset=u,P.process=v,P.finish=w;var Q=B.prototype;Q.BLOCK_SIZE=16,Q.reset=u,Q.process=x,Q.finish=y;var R=new Uint8Array(1048576),S=N(d,null,R.buffer);b.AES_CFB=z,b.AES_CFB.encrypt=C,b.AES_CFB.decrypt=D,b.AES_CFB.Encrypt=A,b.AES_CFB.Decrypt=B;var T=64,U=32;I.BLOCK_SIZE=T,I.HASH_SIZE=U;var V=I.prototype;V.reset=E,V.process=F,V.finish=G;var W=null;return I.bytes=K,I.hex=L,I.base64=M,b.SHA256=I,"function"==typeof a&&a.amd?a([],function(){return b}):"object"==typeof c&&c.exports?c.exports=b:d.asmCrypto=b,b}({},function(){return this}())},{}],2:[function(a,b,c){"use strict";var d=a("./promise/promise").Promise,e=a("./promise/polyfill").polyfill;c.Promise=d,c.polyfill=e},{"./promise/polyfill":6,"./promise/promise":7}],3:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to all.");return new b(function(b,c){function d(a){return function(b){e(a,b)}}function e(a,c){h[a]=c,0===--i&&b(h)}var g,h=[],i=a.length;0===i&&b([]);for(var j=0;j1)for(var c=1;c0;a+=1);return a},g=function(a,b){for(var c=b>>2;c>2]|=128<<24-(b%4<<3),a[((b>>2)+2&-16)+14]=c>>29,a[((b>>2)+2&-16)+15]=c<<3},i=function(a,b,c,d,e){var f,g=this,h=e%4,i=d%4,j=d-i;if(j>0)switch(h){case 0:a[e+3|0]=g.charCodeAt(c);case 1:a[e+2|0]=g.charCodeAt(c+1);case 2:a[e+1|0]=g.charCodeAt(c+2);case 3:a[0|e]=g.charCodeAt(c+3)}for(f=h;j>f;f=f+4|0)b[e+f>>2]=g.charCodeAt(c+f)<<24|g.charCodeAt(c+f+1)<<16|g.charCodeAt(c+f+2)<<8|g.charCodeAt(c+f+3);switch(i){case 3:a[e+j+1|0]=g.charCodeAt(c+j+2);case 2:a[e+j+2|0]=g.charCodeAt(c+j+1);case 1:a[e+j+3|0]=g.charCodeAt(c+j)}},j=function(a,b,c,d,e){var f,g=this,h=e%4,i=d%4,j=d-i;if(j>0)switch(h){case 0:a[e+3|0]=g[c];case 1:a[e+2|0]=g[c+1];case 2:a[e+1|0]=g[c+2];case 3:a[0|e]=g[c+3]}for(f=4-h;j>f;f=f+=4)b[e+f>>2]=g[c+f]<<24|g[c+f+1]<<16|g[c+f+2]<<8|g[c+f+3];switch(i){case 3:a[e+j+1|0]=g[c+j+2];case 2:a[e+j+2|0]=g[c+j+1];case 1:a[e+j+3|0]=g[c+j]}},k=function(a,b,c,d,f){var g,h=this,i=f%4,j=d%4,k=d-j,l=new Uint8Array(e.readAsArrayBuffer(h.slice(c,c+d)));if(k>0)switch(i){case 0:a[f+3|0]=l[0];case 1:a[f+2|0]=l[1];case 2:a[f+1|0]=l[2];case 3:a[0|f]=l[3]}for(g=4-i;k>g;g=g+=4)b[f+g>>2]=l[g]<<24|l[g+1]<<16|l[g+2]<<8|l[g+3];switch(j){case 3:a[f+k+1|0]=l[k+2];case 2:a[f+k+2|0]=l[k+1];case 1:a[f+k+3|0]=l[k]}},l=function(a){switch(d.getDataType(a)){case"string":return i.bind(a);case"array":return j.bind(a);case"buffer":return j.bind(a);case"arraybuffer":return j.bind(new Uint8Array(a));case"view":return j.bind(new Uint8Array(a.buffer,a.byteOffset,a.byteLength));case"blob":return k.bind(a)}},m=function(a){var b,c,d="0123456789abcdef",e=[],f=new Uint8Array(a);for(b=0;b>4&15)+d.charAt(c>>0&15);return e.join("")},n=function(a){var b;if(65536>=a)return 65536;if(16777216>a)for(b=1;a>b;b<<=1);else for(b=16777216;a>b;b+=16777216);return b},o=function(a){if(a%64>0)throw new Error("Chunk size must be a multiple of 128 bit");b.maxChunkLen=a,b.padMaxChunkLen=f(a),b.heap=new ArrayBuffer(n(b.padMaxChunkLen+320+20)),b.h32=new Int32Array(b.heap),b.h8=new Int8Array(b.heap),b.core=new c._core({Int32Array:Int32Array,DataView:DataView},{},b.heap),b.buffer=null};o(a||65536);var p=function(a,b){var c=new Int32Array(a,b+320,5);c[0]=1732584193,c[1]=-271733879,c[2]=-1732584194,c[3]=271733878,c[4]=-1009589776},q=function(a,c){var d=f(a),e=new Int32Array(b.heap,0,d>>2);return g(e,a),h(e,a,c),d},r=function(a,c,d){l(a)(b.h8,b.h32,c,d,0)},s=function(a,c,d,e,f){var g=d;f&&(g=q(d,e)),r(a,c,d),b.core.hash(g,b.padMaxChunkLen)},t=function(a,b){var c=new Int32Array(a,b+320,5),d=new Int32Array(5),e=new DataView(d.buffer);return e.setInt32(0,c[0],!1),e.setInt32(4,c[1],!1),e.setInt32(8,c[2],!1),e.setInt32(12,c[3],!1),e.setInt32(16,c[4],!1),d},u=this.rawDigest=function(a){var c=a.byteLength||a.length||a.size||0;p(b.heap,b.padMaxChunkLen);var d=0,e=b.maxChunkLen;for(d=0;c>d+e;d+=e)s(a,d,e,c,!1);return s(a,d,c-d,c,!0),t(b.heap,b.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(a){return m(u(a).buffer)}}var d={getDataType:function(b){if("string"==typeof b)return"string";if(b instanceof Array)return"array";if("undefined"!=typeof a&&a.Buffer&&a.Buffer.isBuffer(b))return"buffer";if(b instanceof ArrayBuffer)return"arraybuffer";if(b.buffer instanceof ArrayBuffer)return"view";if(b instanceof Blob)return"blob";throw new Error("Unsupported data type.")}};if(c._core=function g(a,b,c){"use asm";var d=new a.Int32Array(c);function e(a,b){a=a|0;b=b|0;var c=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;f=d[b+320>>2]|0;h=d[b+324>>2]|0;j=d[b+328>>2]|0;l=d[b+332>>2]|0;n=d[b+336>>2]|0;for(c=0;(c|0)<(a|0);c=c+64|0){g=f;i=h;k=j;m=l;o=n;for(e=0;(e|0)<64;e=e+4|0){q=d[c+e>>2]|0;p=((f<<5|f>>>27)+(h&j|~h&l)|0)+((q+n|0)+1518500249|0)|0;n=l;l=j;j=h<<30|h>>>2;h=f;f=p;d[a+e>>2]=q}for(e=a+64|0;(e|0)<(a+80|0);e=e+4|0){q=(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])<<1|(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])>>>31;p=((f<<5|f>>>27)+(h&j|~h&l)|0)+((q+n|0)+1518500249|0)|0;n=l;l=j;j=h<<30|h>>>2;h=f;f=p;d[e>>2]=q}for(e=a+80|0;(e|0)<(a+160|0);e=e+4|0){q=(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])<<1|(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])>>>31;p=((f<<5|f>>>27)+(h^j^l)|0)+((q+n|0)+1859775393|0)|0;n=l;l=j;j=h<<30|h>>>2;h=f;f=p;d[e>>2]=q}for(e=a+160|0;(e|0)<(a+240|0);e=e+4|0){q=(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])<<1|(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])>>>31;p=((f<<5|f>>>27)+(h&j|h&l|j&l)|0)+((q+n|0)-1894007588|0)|0;n=l;l=j;j=h<<30|h>>>2;h=f;f=p;d[e>>2]=q}for(e=a+240|0;(e|0)<(a+320|0);e=e+4|0){q=(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])<<1|(d[e-12>>2]^d[e-32>>2]^d[e-56>>2]^d[e-64>>2])>>>31;p=((f<<5|f>>>27)+(h^j^l)|0)+((q+n|0)-899497514|0)|0;n=l;l=j;j=h<<30|h>>>2;h=f;f=p;d[e>>2]=q}f=f+g|0;h=h+i|0;j=j+k|0;l=l+m|0;n=n+o|0}d[b+320>>2]=f;d[b+324>>2]=h;d[b+328>>2]=j;d[b+332>>2]=l;d[b+336>>2]=n}return{hash:e}},"undefined"!=typeof b?b.exports=c:"undefined"!=typeof window&&(window.Rusha=c),"undefined"!=typeof FileReaderSync){var e=new FileReaderSync,f=new c(4194304);self.onmessage=function(a){var b,c=a.data.data;try{b=f.digest(c),self.postMessage({id:a.data.id,hash:b})}catch(d){self.postMessage({id:a.data.id,error:d.name})}}}}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],14:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a,b){return this instanceof e?(this.text=a.replace(/\r/g,"").replace(/[\t ]+\n/g,"\n").replace(/\n/g,"\r\n"),void(this.packets=b||new k["default"].List)):new e(a,b)}function f(a){var b=o["default"].decode(a);if(b.type!==m["default"].armor.signed)throw new Error("No cleartext signed message.");var c=new k["default"].List;c.read(b.data),g(b.headers,c);var d=new e(b.text,c);return d}function g(a,b){var c=function(a){function c(a){return b[d].hashAlgorithm===a}for(var d=0;db;++b)e[b]=c[b];return a.buffer=e}function d(a){this.buffer=new(o?Uint16Array:Array)(2*a),this.length=0}function e(a,b){this.e=w,this.f=0,this.input=o&&a instanceof Array?new Uint8Array(a):a,this.c=0,b&&(b.lazy&&(this.f=b.lazy),"number"==typeof b.compressionType&&(this.e=b.compressionType),b.outputBuffer&&(this.b=o&&b.outputBuffer instanceof Array?new Uint8Array(b.outputBuffer):b.outputBuffer),"number"==typeof b.outputIndex&&(this.c=b.outputIndex)),this.b||(this.b=new(o?Uint8Array:Array)(32768))}function f(a,b){this.length=a,this.g=b}function g(a,b){function c(a,b){var c,d=a.g,e=[],f=0;c=z[a.length],e[f++]=65535&c,e[f++]=c>>16&255,e[f++]=c>>24;var g;switch(m){case 1===d:g=[0,d-1,0];break;case 2===d:g=[1,d-2,0];break;case 3===d:g=[2,d-3,0];break;case 4===d:g=[3,d-4,0];break;case 6>=d:g=[4,d-5,1];break;case 8>=d:g=[5,d-7,1];break;case 12>=d:g=[6,d-9,2];break;case 16>=d:g=[7,d-13,2];break;case 24>=d:g=[8,d-17,3];break;case 32>=d:g=[9,d-25,3];break;case 48>=d:g=[10,d-33,4];break;case 64>=d:g=[11,d-49,4];break;case 96>=d:g=[12,d-65,5];break;case 128>=d:g=[13,d-97,5];break;case 192>=d:g=[14,d-129,6];break;case 256>=d:g=[15,d-193,6];break;case 384>=d:g=[16,d-257,7];break;case 512>=d:g=[17,d-385,7];break;case 768>=d:g=[18,d-513,8];break;case 1024>=d:g=[19,d-769,8];break;case 1536>=d:g=[20,d-1025,9];break;case 2048>=d:g=[21,d-1537,9];break;case 3072>=d:g=[22,d-2049,10];break;case 4096>=d:g=[23,d-3073,10];break;case 6144>=d:g=[24,d-4097,11];break;case 8192>=d:g=[25,d-6145,11];break;case 12288>=d:g=[26,d-8193,12];break;case 16384>=d:g=[27,d-12289,12];break;case 24576>=d:g=[28,d-16385,13];break;case 32768>=d:g=[29,d-24577,13];break;default:throw"invalid distance"}c=g,e[f++]=c[0],e[f++]=c[1],e[f++]=c[2];var h,i;for(h=0,i=e.length;i>h;++h)r[s++]=e[h];u[e[0]]++,v[e[3]]++,t=a.length+b-1,n=null}var d,e,f,g,i,j,k,n,p,q={},r=o?new Uint16Array(2*b.length):[],s=0,t=0,u=new(o?Uint32Array:Array)(286),v=new(o?Uint32Array:Array)(30),w=a.f;if(!o){for(f=0;285>=f;)u[f++]=0;for(f=0;29>=f;)v[f++]=0}for(u[256]=1,d=0,e=b.length;e>d;++d){for(f=i=0,g=3;g>f&&d+f!==e;++f)i=i<<8|b[d+f];if(q[i]===l&&(q[i]=[]),j=q[i],!(0=e){for(n&&c(n,-1),f=0,g=e-d;g>f;++f)p=b[d+f],r[s++]=p,++u[p];break}0h;h++){if(d=c[j-h-1],g=3,k>3){for(i=k;i>3;i--)if(a[d+i-1]!==a[b+i-1])continue a;g=k}for(;258>g&&l>b+g&&a[d+g]===a[b+g];)++g;if(g>k&&(e=d,k=g),258===g)break}return new f(k,b-e)}function i(a,b){var c,e,f,g,h,i=a.length,k=new d(572),l=new(o?Uint8Array:Array)(i);if(!o)for(g=0;i>g;g++)l[g]=0;for(g=0;i>g;++g)0g;++g)c[g]=k.pop(),e[g]=c[g].value;for(f=j(e,e.length,b),g=0,h=c.length;h>g;++g)l[c[g].index]=f[g];return l}function j(a,b,c){function d(a){var c=n[a][p[a]];c===b?(d(a+1),d(a+1)):--l[c],++p[a]}var e,f,g,h,i,j=new(o?Uint16Array:Array)(c),k=new(o?Uint8Array:Array)(c),l=new(o?Uint8Array:Array)(b),m=Array(c),n=Array(c),p=Array(c),q=(1<f;++f)r>q?k[f]=0:(k[f]=1,q-=r),q<<=1,j[c-2-f]=(j[c-1-f]/2|0)+b;for(j[0]=k[0],m[0]=Array(j[0]),n[0]=Array(j[0]),f=1;c>f;++f)j[f]>2*j[f-1]+k[f]&&(j[f]=2*j[f-1]+k[f]),m[f]=Array(j[f]),n[f]=Array(j[f]);for(e=0;b>e;++e)l[e]=c;for(g=0;ge;++e)p[e]=0;for(1===k[c-1]&&(--l[0],++p[c-1]),f=c-2;f>=0;--f){for(h=e=0,i=p[f+1],g=0;ga[e]?(m[f][g]=h,n[f][g]=b,i+=2):(m[f][g]=a[e],n[f][g]=e,++e);p[f]=0,1===k[f]&&d(f)}return l}function k(a){var b,c,d,e,f=new(o?Uint16Array:Array)(a.length),g=[],h=[],i=0;for(b=0,c=a.length;c>b;b++)g[a[b]]=(0|g[a[b]])+1;for(b=1,c=16;c>=b;b++)h[b]=i,i+=0|g[b],i<<=1;for(b=0,c=a.length;c>b;b++)for(i=h[a[b]],h[a[b]]+=1,d=f[b]=0,e=a[b];e>d;d++)f[b]=f[b]<<1|1&i,i>>>=1;return f}var l=void 0,m=!0,n=this,o="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;b.prototype.a=function(a,b,d){var e,f=this.buffer,g=this.index,h=this.d,i=f[g];if(d&&b>1&&(a=b>8?(u[255&a]<<24|u[a>>>8&255]<<16|u[a>>>16&255]<<8|u[a>>>24&255])>>32-b:u[a]>>8-b),8>b+h)i=i<e;++e)i=i<<1|a>>b-e-1&1,8===++h&&(h=0,f[g++]=u[i],i=0,g===f.length&&(f=c(this)));f[g]=i,this.buffer=f,this.d=h,this.index=g},b.prototype.finish=function(){var a,b=this.buffer,c=this.index;return 0p;++p){for(var r=p,s=r,t=7,r=r>>>1;r;r>>>=1)s<<=1,s|=1&r,--t;q[p]=(s<>>0}var u=q;d.prototype.getParent=function(a){return 2*((a-2)/4|0)},d.prototype.push=function(a,b){var c,d,e,f=this.buffer;for(c=this.length,f[this.length++]=b,f[this.length++]=a;c>0&&(d=this.getParent(c),f[c]>f[d]);)e=f[c],f[c]=f[d],f[d]=e,e=f[c+1],f[c+1]=f[d+1],f[d+1]=e,c=d;return this.length},d.prototype.pop=function(){var a,b,c,d,e,f=this.buffer;for(b=f[0],a=f[1],this.length-=2,f[0]=f[this.length],f[1]=f[this.length+1],e=0;(d=2*e+2,!(d>=this.length))&&(d+2f[d]&&(d+=2),f[d]>f[e]);)c=f[e],f[e]=f[d],f[d]=c,c=f[e+1],f[e+1]=f[d+1],f[d+1]=c,e=d;return{index:a,value:b,length:this.length}};var v,w=2,x=[];for(v=0;288>v;v++)switch(m){case 143>=v:x.push([v+48,8]);break;case 255>=v:x.push([v-144+400,9]);break;case 279>=v:x.push([v-256+0,7]);break;case 287>=v:x.push([v-280+192,8]);break;default:throw"invalid literal: "+v}e.prototype.h=function(){var a,c,d,e,f=this.input;switch(this.e){case 0:for(d=0,e=f.length;e>d;){c=o?f.subarray(d,d+65535):f.slice(d,d+65535),d+=c.length;var h=c,j=d===e,n=l,p=l,q=l,r=l,s=l,t=this.b,u=this.c;if(o){for(t=new Uint8Array(this.b.buffer);t.length<=u+h.length+5;)t=new Uint8Array(t.length<<1);t.set(this.b)}if(n=j?1:0,t[u++]=0|n,p=h.length,q=~p+65536&65535,t[u++]=255&p,t[u++]=p>>>8&255,t[u++]=255&q,t[u++]=q>>>8&255,o)t.set(h,u),u+=h.length,t=t.subarray(0,u);else{for(r=0,s=h.length;s>r;++r)t[u++]=h[r];t.length=u}this.c=u,this.b=t}break;case 1:var v=new b(o?new Uint8Array(this.b.buffer):this.b,this.c);v.a(1,1,m),v.a(1,2,m);var y,z,A,B=g(this,f);for(y=0,z=B.length;z>y;y++)if(A=B[y],b.prototype.a.apply(v,x[A]),A>256)v.a(B[++y],B[++y],m),v.a(B[++y],5),v.a(B[++y],B[++y],m);else if(256===A)break;this.b=v.finish(),this.c=this.b.length;break;case w:var C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R=new b(o?new Uint8Array(this.b.buffer):this.b,this.c),S=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],T=Array(19);for(C=w,R.a(1,1,m),R.a(C,2,m),D=g(this,f),H=i(this.j,15),I=k(H),J=i(this.i,7),K=k(J),E=286;E>257&&0===H[E-1];E--);for(F=30;F>1&&0===J[F-1];F--);var U,V,W,X,Y,Z,$=E,_=F,aa=new(o?Uint32Array:Array)($+_),ba=new(o?Uint32Array:Array)(316),ca=new(o?Uint8Array:Array)(19);for(U=V=0;$>U;U++)aa[V++]=H[U];for(U=0;_>U;U++)aa[V++]=J[U];if(!o)for(U=0,X=ca.length;X>U;++U)ca[U]=0;for(U=Y=0,X=aa.length;X>U;U+=V){for(V=1;X>U+V&&aa[U+V]===aa[U];++V);if(W=V,0===aa[U])if(3>W)for(;00;)Z=138>W?W:138,Z>W-3&&W>Z&&(Z=W-3),10>=Z?(ba[Y++]=17,ba[Y++]=Z-3,ca[17]++):(ba[Y++]=18,ba[Y++]=Z-11,ca[18]++),W-=Z;else if(ba[Y++]=aa[U],ca[aa[U]]++,W--,3>W)for(;00;)Z=6>W?W:6,Z>W-3&&W>Z&&(Z=W-3),ba[Y++]=16,ba[Y++]=Z-3,ca[16]++,W-=Z}for(a=o?ba.subarray(0,Y):ba.slice(0,Y),L=i(ca,7),P=0;19>P;P++)T[P]=L[S[P]];for(G=19;G>4&&0===T[G-1];G--);for(M=k(L),R.a(E-257,5,m),R.a(F-1,5,m),R.a(G-4,4,m),P=0;G>P;P++)R.a(T[P],3,m);for(P=0,Q=a.length;Q>P;P++)if(N=a[P],R.a(M[N],L[N],m),N>=16){switch(P++,N){case 16:O=2;break;case 17:O=3;break;case 18:O=7;break;default:throw"invalid code: "+N}R.a(a[P],O,m)}var da,ea,fa,ga,ha,ia,ja,ka,la=[I,H],ma=[K,J];for(ha=la[0],ia=la[1],ja=ma[0],ka=ma[1],da=0,ea=D.length;ea>da;++da)if(fa=D[da],R.a(ha[fa],ia[fa],m),fa>256)R.a(D[++da],D[++da],m),ga=D[++da],R.a(ja[ga],ka[ga],m),R.a(D[++da],D[++da],m);else if(256===fa)break;this.b=R.finish(),this.c=this.b.length;break;default:throw"invalid compression type"}return this.b};var y=function(){function a(a){switch(m){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=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 b,c,d=[];for(b=3;258>=b;b++)c=a(b),d[b]=c[2]<<24|c[1]<<16|c[0];return d}(),z=o?new Uint32Array(y):y;a("Zlib.RawDeflate",e),a("Zlib.RawDeflate.prototype.compress",e.prototype.h);var A,B,C,D,E={NONE:0,FIXED:1,DYNAMIC:w};if(Object.keys)A=Object.keys(E);else for(B in A=[],C=0,E)A[C++]=B;for(C=0,D=A.length;D>C;++C)B=A[C],a("Zlib.RawDeflate.CompressionType."+B,E[B])}).call(this)},{}],16:[function(a,b,c){(function(){"use strict";function a(a,b){var c=a.split("."),d=g;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)c.length||void 0===b?d=d[e]?d[e]:d[e]={}:d[e]=b}function b(a){var b,c,d,e,f,g,i,j,k,l,m=a.length,n=0,o=Number.POSITIVE_INFINITY;for(j=0;m>j;++j)a[j]>n&&(n=a[j]),a[j]=d;){for(j=0;m>j;++j)if(a[j]===d){for(g=0,i=e,k=0;d>k;++k)g=g<<1|1&i,i>>=1;for(l=d<<16|j,k=g;b>k;k+=f)c[k]=l;++e}++d,e<<=1,f<<=1}return[c,n,o]}function c(a,b){switch(this.g=[],this.h=32768,this.c=this.f=this.d=this.k=0,this.input=h?new Uint8Array(a):a,this.l=!1,this.i=j,this.q=!1,(b||!(b={}))&&(b.index&&(this.d=b.index),b.bufferSize&&(this.h=b.bufferSize),b.bufferType&&(this.i=b.bufferType),b.resize&&(this.q=b.resize)),this.i){case i:this.a=32768,this.b=new(h?Uint8Array:Array)(32768+this.h+258);break;case j:this.a=0,this.b=new(h?Uint8Array:Array)(this.h),this.e=this.v,this.m=this.s,this.j=this.t;break;default:throw Error("invalid inflate mode")}}function d(a,b){for(var c,d=a.f,e=a.c,f=a.input,g=a.d,h=f.length;b>e;){if(g>=h)throw Error("input buffer is broken");d|=f[g++]<>>b,a.c=e-b,a.d=g,c}function e(a,b){for(var c,d,e=a.f,f=a.c,g=a.input,h=a.d,i=g.length,j=b[0],k=b[1];k>f&&!(h>=i);)e|=g[h++]<>>16,a.f=e>>d,a.c=f-d,a.d=h,65535&c}function f(a){function c(a,b,c){var f,g,h,i=this.p;for(h=0;a>h;)switch(f=e(this,b)){case 16:for(g=3+d(this,2);g--;)c[h++]=i;break;case 17:for(g=3+d(this,3);g--;)c[h++]=0;i=0;break;case 18:for(g=11+d(this,7);g--;)c[h++]=0;i=0;break;default:i=c[h++]=f}return this.p=i,c}var f,g,i,j,k=d(a,5)+257,l=d(a,5)+1,m=d(a,4)+4,o=new(h?Uint8Array:Array)(n.length);for(j=0;m>j;++j)o[n[j]]=d(a,3);if(!h)for(j=m,m=o.length;m>j;++j)o[n[j]]=0;f=b(o),g=new(h?Uint8Array:Array)(k),i=new(h?Uint8Array:Array)(l),a.p=0,a.j(b(c.call(a,k,f,g)),b(c.call(a,l,f,i)))}var g=this,h="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView,i=0,j=1;c.prototype.u=function(){for(;!this.l;){var a=d(this,3);switch(1&a&&(this.l=!0),a>>>=1){case 0:var b=this.input,c=this.d,e=this.b,g=this.a,k=b.length,l=void 0,m=void 0,n=e.length,o=void 0;if(this.c=this.f=0,c+1>=k)throw Error("invalid uncompressed block header: LEN");if(l=b[c++]|b[c++]<<8,c+1>=k)throw Error("invalid uncompressed block header: NLEN");if(m=b[c++]|b[c++]<<8,l===~m)throw Error("invalid uncompressed block header: length verify");if(c+l>b.length)throw Error("input buffer is broken");switch(this.i){case i:for(;g+l>e.length;){if(o=n-g,l-=o,h)e.set(b.subarray(c,c+o),g),g+=o,c+=o;else for(;o--;)e[g++]=b[c++];this.a=g,e=this.e(),g=this.a}break;case j:for(;g+l>e.length;)e=this.e({o:2});break;default:throw Error("invalid inflate mode")}if(h)e.set(b.subarray(c,c+l),g),g+=l,c+=l;else for(;l--;)e[g++]=b[c++];this.d=c,this.a=g,this.b=e;break;case 1:this.j(z,B);break;case 2:f(this);break;default:throw Error("unknown BTYPE: "+a)}}return this.m()};var k,l,m=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],n=h?new Uint16Array(m):m,o=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],p=h?new Uint16Array(o):o,q=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],r=h?new Uint8Array(q):q,s=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],t=h?new Uint16Array(s):s,u=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],v=h?new Uint8Array(u):u,w=new(h?Uint8Array:Array)(288);for(k=0,l=w.length;l>k;++k)w[k]=143>=k?8:255>=k?9:279>=k?7:8;var x,y,z=b(w),A=new(h?Uint8Array:Array)(30);for(x=0,y=A.length;y>x;++x)A[x]=5;var B=b(A);c.prototype.j=function(a,b){var c=this.b,f=this.a;this.n=a;for(var g,h,i,j,k=c.length-258;256!==(g=e(this,a));)if(256>g)f>=k&&(this.a=f,c=this.e(),f=this.a),c[f++]=g;else for(h=g-257,j=p[h],0=k&&(this.a=f,c=this.e(),f=this.a);j--;)c[f]=c[f++-i];for(;8<=this.c;)this.c-=8,this.d--;this.a=f},c.prototype.t=function(a,b){var c=this.b,f=this.a;this.n=a;for(var g,h,i,j,k=c.length;256!==(g=e(this,a));)if(256>g)f>=k&&(c=this.e(),k=c.length),c[f++]=g;else for(h=g-257,j=p[h],0k&&(c=this.e(),k=c.length);j--;)c[f]=c[f++-i];for(;8<=this.c;)this.c-=8,this.d--;this.a=f},c.prototype.e=function(){var a,b,c=new(h?Uint8Array:Array)(this.a-32768),d=this.a-32768,e=this.b;if(h)c.set(e.subarray(32768,c.length));else for(a=0,b=c.length;b>a;++a)c[a]=e[a+32768];if(this.g.push(c),this.k+=c.length,h)e.set(e.subarray(d,d+32768));else for(a=0;32768>a;++a)e[a]=e[d+a];return this.a=32768,e},c.prototype.v=function(a){var b,c,d,e,f=this.input.length/this.d+1|0,g=this.input,i=this.b;return a&&("number"==typeof a.o&&(f=a.o),"number"==typeof a.r&&(f+=a.r)),2>f?(c=(g.length-this.d)/this.n[2],e=258*(c/2)|0,d=eb;++b)for(a=i[b],d=0,e=a.length;e>d;++d)j[f++]=a[d];for(b=32768,c=this.a;c>b;++b)j[f++]=g[b];return this.g=[],this.buffer=j},c.prototype.s=function(){var a,b=this.a;return h?this.q?(a=new Uint8Array(b),a.set(this.b.subarray(0,b))):a=this.b.subarray(0,b):(this.b.length>b&&(this.b.length=b),a=this.b),this.buffer=a},a("Zlib.RawInflate",c),a("Zlib.RawInflate.prototype.decompress",c.prototype.u);var C,D,E,F,G={ADAPTIVE:j,BLOCK:i};if(Object.keys)C=Object.keys(G);else for(D in C=[],E=0,G)C[E++]=D;for(E=0,F=C.length;F>E;++E)D=C[E],a("Zlib.RawInflate.BufferType."+D,G[D])}).call(this)},{}],17:[function(a,b,c){(function(){"use strict";function a(a){throw a}function b(a,b){var c=a.split("."),d=w;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)c.length||b===u?d=d[e]?d[e]:d[e]={}:d[e]=b}function c(b,c){this.index="number"==typeof c?c:0,this.i=0,this.buffer=b instanceof(x?Uint8Array:Array)?b:new(x?Uint8Array:Array)(32768),2*this.buffer.length<=this.index&&a(Error("invalid index")),this.buffer.length<=this.index&&this.f()}function d(a){this.buffer=new(x?Uint16Array:Array)(2*a),this.length=0}function e(a){var b,c,d,e,f,g,h,i,j,k,l=a.length,m=0,n=Number.POSITIVE_INFINITY;for(i=0;l>i;++i)a[i]>m&&(m=a[i]),a[i]=d;){for(i=0;l>i;++i)if(a[i]===d){for(g=0,h=e, +j=0;d>j;++j)g=g<<1|1&h,h>>=1;for(k=d<<16|i,j=g;b>j;j+=f)c[j]=k;++e}++d,e<<=1,f<<=1}return[c,m,n]}function f(a,b){this.h=F,this.w=0,this.input=x&&a instanceof Array?new Uint8Array(a):a,this.b=0,b&&(b.lazy&&(this.w=b.lazy),"number"==typeof b.compressionType&&(this.h=b.compressionType),b.outputBuffer&&(this.a=x&&b.outputBuffer instanceof Array?new Uint8Array(b.outputBuffer):b.outputBuffer),"number"==typeof b.outputIndex&&(this.b=b.outputIndex)),this.a||(this.a=new(x?Uint8Array:Array)(32768))}function g(a,b){this.length=a,this.H=b}function h(b,c){function d(b,c){var d,e=b.H,f=[],g=0;d=J[b.length],f[g++]=65535&d,f[g++]=d>>16&255,f[g++]=d>>24;var h;switch(v){case 1===e:h=[0,e-1,0];break;case 2===e:h=[1,e-2,0];break;case 3===e:h=[2,e-3,0];break;case 4===e:h=[3,e-4,0];break;case 6>=e:h=[4,e-5,1];break;case 8>=e:h=[5,e-7,1];break;case 12>=e:h=[6,e-9,2];break;case 16>=e:h=[7,e-13,2];break;case 24>=e:h=[8,e-17,3];break;case 32>=e:h=[9,e-25,3];break;case 48>=e:h=[10,e-33,4];break;case 64>=e:h=[11,e-49,4];break;case 96>=e:h=[12,e-65,5];break;case 128>=e:h=[13,e-97,5];break;case 192>=e:h=[14,e-129,6];break;case 256>=e:h=[15,e-193,6];break;case 384>=e:h=[16,e-257,7];break;case 512>=e:h=[17,e-385,7];break;case 768>=e:h=[18,e-513,8];break;case 1024>=e:h=[19,e-769,8];break;case 1536>=e:h=[20,e-1025,9];break;case 2048>=e:h=[21,e-1537,9];break;case 3072>=e:h=[22,e-2049,10];break;case 4096>=e:h=[23,e-3073,10];break;case 6144>=e:h=[24,e-4097,11];break;case 8192>=e:h=[25,e-6145,11];break;case 12288>=e:h=[26,e-8193,12];break;case 16384>=e:h=[27,e-12289,12];break;case 24576>=e:h=[28,e-16385,13];break;case 32768>=e:h=[29,e-24577,13];break;default:a("invalid distance")}d=h,f[g++]=d[0],f[g++]=d[1],f[g++]=d[2];var i,j;for(i=0,j=f.length;j>i;++i)p[q++]=f[i];s[f[0]]++,t[f[3]]++,r=b.length+c-1,m=null}var e,f,g,h,j,k,l,m,n,o={},p=x?new Uint16Array(2*c.length):[],q=0,r=0,s=new(x?Uint32Array:Array)(286),t=new(x?Uint32Array:Array)(30),w=b.w;if(!x){for(g=0;285>=g;)s[g++]=0;for(g=0;29>=g;)t[g++]=0}for(s[256]=1,e=0,f=c.length;f>e;++e){for(g=j=0,h=3;h>g&&e+g!==f;++g)j=j<<8|c[e+g];if(o[j]===u&&(o[j]=[]),k=o[j],!(0=f){for(m&&d(m,-1),g=0,h=f-e;h>g;++g)n=c[e+g],p[q++]=n,++s[n];break}0h;h++){if(d=c[j-h-1],f=3,k>3){for(i=k;i>3;i--)if(a[d+i-1]!==a[b+i-1])continue a;f=k}for(;258>f&&l>b+f&&a[d+f]===a[b+f];)++f;if(f>k&&(e=d,k=f),258===f)break}return new g(k,b-e)}function j(a,b){var c,e,f,g,h,i=a.length,j=new d(572),l=new(x?Uint8Array:Array)(i);if(!x)for(g=0;i>g;g++)l[g]=0;for(g=0;i>g;++g)0g;++g)c[g]=j.pop(),e[g]=c[g].value;for(f=k(e,e.length,b),g=0,h=c.length;h>g;++g)l[c[g].index]=f[g];return l}function k(a,b,c){function d(a){var c=n[a][o[a]];c===b?(d(a+1),d(a+1)):--l[c],++o[a]}var e,f,g,h,i,j=new(x?Uint16Array:Array)(c),k=new(x?Uint8Array:Array)(c),l=new(x?Uint8Array:Array)(b),m=Array(c),n=Array(c),o=Array(c),p=(1<f;++f)q>p?k[f]=0:(k[f]=1,p-=q),p<<=1,j[c-2-f]=(j[c-1-f]/2|0)+b;for(j[0]=k[0],m[0]=Array(j[0]),n[0]=Array(j[0]),f=1;c>f;++f)j[f]>2*j[f-1]+k[f]&&(j[f]=2*j[f-1]+k[f]),m[f]=Array(j[f]),n[f]=Array(j[f]);for(e=0;b>e;++e)l[e]=c;for(g=0;ge;++e)o[e]=0;for(1===k[c-1]&&(--l[0],++o[c-1]),f=c-2;f>=0;--f){for(h=e=0,i=o[f+1],g=0;ga[e]?(m[f][g]=h,n[f][g]=b,i+=2):(m[f][g]=a[e],n[f][g]=e,++e);o[f]=0,1===k[f]&&d(f)}return l}function l(a){var b,c,d,e,f=new(x?Uint16Array:Array)(a.length),g=[],h=[],i=0;for(b=0,c=a.length;c>b;b++)g[a[b]]=(0|g[a[b]])+1;for(b=1,c=16;c>=b;b++)h[b]=i,i+=0|g[b],i<<=1;for(b=0,c=a.length;c>b;b++)for(i=h[a[b]],h[a[b]]+=1,d=f[b]=0,e=a[b];e>d;d++)f[b]=f[b]<<1|1&i,i>>>=1;return f}function m(b,c){switch(this.l=[],this.m=32768,this.e=this.g=this.c=this.q=0,this.input=x?new Uint8Array(b):b,this.s=!1,this.n=L,this.C=!1,(c||!(c={}))&&(c.index&&(this.c=c.index),c.bufferSize&&(this.m=c.bufferSize),c.bufferType&&(this.n=c.bufferType),c.resize&&(this.C=c.resize)),this.n){case K:this.b=32768,this.a=new(x?Uint8Array:Array)(32768+this.m+258);break;case L:this.b=0,this.a=new(x?Uint8Array:Array)(this.m),this.f=this.K,this.t=this.I,this.o=this.J;break;default:a(Error("invalid inflate mode"))}}function n(b,c){for(var d,e=b.g,f=b.e,g=b.input,h=b.c,i=g.length;c>f;)h>=i&&a(Error("input buffer is broken")),e|=g[h++]<>>c,b.e=f-c,b.c=h,d}function o(a,b){for(var c,d,e=a.g,f=a.e,g=a.input,h=a.c,i=g.length,j=b[0],k=b[1];k>f&&!(h>=i);)e|=g[h++]<>>16,a.g=e>>d,a.e=f-d,a.c=h,65535&c}function p(a){function b(a,b,c){var d,e,f,g=this.z;for(f=0;a>f;)switch(d=o(this,b)){case 16:for(e=3+n(this,2);e--;)c[f++]=g;break;case 17:for(e=3+n(this,3);e--;)c[f++]=0;g=0;break;case 18:for(e=11+n(this,7);e--;)c[f++]=0;g=0;break;default:g=c[f++]=d}return this.z=g,c}var c,d,f,g,h=n(a,5)+257,i=n(a,5)+1,j=n(a,4)+4,k=new(x?Uint8Array:Array)(Q.length);for(g=0;j>g;++g)k[Q[g]]=n(a,3);if(!x)for(g=j,j=k.length;j>g;++g)k[Q[g]]=0;c=e(k),d=new(x?Uint8Array:Array)(h),f=new(x?Uint8Array:Array)(i),a.z=0,a.o(e(b.call(a,h,c,d)),e(b.call(a,i,c,f)))}function q(a){if("string"==typeof a){var b,c,d=a.split("");for(b=0,c=d.length;c>b;b++)d[b]=(255&d[b].charCodeAt(0))>>>0;a=d}for(var e,f=1,g=0,h=a.length,i=0;h>0;){e=h>1024?1024:h,h-=e;do f+=a[i++],g+=f;while(--e);f%=65521,g%=65521}return(g<<16|f)>>>0}function r(b,c){var d,e;switch(this.input=b,this.c=0,(c||!(c={}))&&(c.index&&(this.c=c.index),c.verify&&(this.N=c.verify)),d=b[this.c++],e=b[this.c++],15&d){case da:this.method=da;break;default:a(Error("unsupported compression method"))}0!==((d<<8)+e)%31&&a(Error("invalid fcheck flag:"+((d<<8)+e)%31)),32&e&&a(Error("fdict flag is not supported")),this.B=new m(b,{index:this.c,bufferSize:c.bufferSize,bufferType:c.bufferType,resize:c.resize})}function s(a,b){this.input=a,this.a=new(x?Uint8Array:Array)(32768),this.h=ea.k;var c,d={};!b&&(b={})||"number"!=typeof b.compressionType||(this.h=b.compressionType);for(c in b)d[c]=b[c];d.outputBuffer=this.a,this.A=new f(this.input,d)}function t(a,c){var d,e,f,g;if(Object.keys)d=Object.keys(c);else for(e in d=[],f=0,c)d[f++]=e;for(f=0,g=d.length;g>f;++f)e=d[f],b(a+"."+e,c[e])}var u=void 0,v=!0,w=this,x="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;c.prototype.f=function(){var a,b=this.buffer,c=b.length,d=new(x?Uint8Array:Array)(c<<1);if(x)d.set(b);else for(a=0;c>a;++a)d[a]=b[a];return this.buffer=d},c.prototype.d=function(a,b,c){var d,e=this.buffer,f=this.index,g=this.i,h=e[f];if(c&&b>1&&(a=b>8?(D[255&a]<<24|D[a>>>8&255]<<16|D[a>>>16&255]<<8|D[a>>>24&255])>>32-b:D[a]>>8-b),8>b+g)h=h<d;++d)h=h<<1|a>>b-d-1&1,8===++g&&(g=0,e[f++]=D[h],h=0,f===e.length&&(e=this.f()));e[f]=h,this.buffer=e,this.i=g,this.index=f},c.prototype.finish=function(){var a,b=this.buffer,c=this.index;return 0y;++y){for(var A=y,B=A,C=7,A=A>>>1;A;A>>>=1)B<<=1,B|=1&A,--C;z[y]=(B<>>0}var D=z;d.prototype.getParent=function(a){return 2*((a-2)/4|0)},d.prototype.push=function(a,b){var c,d,e,f=this.buffer;for(c=this.length,f[this.length++]=b,f[this.length++]=a;c>0&&(d=this.getParent(c),f[c]>f[d]);)e=f[c],f[c]=f[d],f[d]=e,e=f[c+1],f[c+1]=f[d+1],f[d+1]=e,c=d;return this.length},d.prototype.pop=function(){var a,b,c,d,e,f=this.buffer;for(b=f[0],a=f[1],this.length-=2,f[0]=f[this.length],f[1]=f[this.length+1],e=0;(d=2*e+2,!(d>=this.length))&&(d+2f[d]&&(d+=2),f[d]>f[e]);)c=f[e],f[e]=f[d],f[d]=c,c=f[e+1],f[e+1]=f[d+1],f[d+1]=c,e=d;return{index:a,value:b,length:this.length}};var E,F=2,G={NONE:0,r:1,k:F,O:3},H=[];for(E=0;288>E;E++)switch(v){case 143>=E:H.push([E+48,8]);break;case 255>=E:H.push([E-144+400,9]);break;case 279>=E:H.push([E-256+0,7]);break;case 287>=E:H.push([E-280+192,8]);break;default:a("invalid literal: "+E)}f.prototype.j=function(){var b,d,e,f,g=this.input;switch(this.h){case 0:for(e=0,f=g.length;f>e;){d=x?g.subarray(e,e+65535):g.slice(e,e+65535),e+=d.length;var i=d,k=e===f,m=u,n=u,o=u,p=u,q=u,r=this.a,s=this.b;if(x){for(r=new Uint8Array(this.a.buffer);r.length<=s+i.length+5;)r=new Uint8Array(r.length<<1);r.set(this.a)}if(m=k?1:0,r[s++]=0|m,n=i.length,o=~n+65536&65535,r[s++]=255&n,r[s++]=n>>>8&255,r[s++]=255&o,r[s++]=o>>>8&255,x)r.set(i,s),s+=i.length,r=r.subarray(0,s);else{for(p=0,q=i.length;q>p;++p)r[s++]=i[p];r.length=s}this.b=s,this.a=r}break;case 1:var t=new c(x?new Uint8Array(this.a.buffer):this.a,this.b);t.d(1,1,v),t.d(1,2,v);var w,y,z,A=h(this,g);for(w=0,y=A.length;y>w;w++)if(z=A[w],c.prototype.d.apply(t,H[z]),z>256)t.d(A[++w],A[++w],v),t.d(A[++w],5),t.d(A[++w],A[++w],v);else if(256===z)break;this.a=t.finish(),this.b=this.a.length;break;case F:var B,C,D,E,G,I,J,K,L,M,N,O,P,Q,R,S=new c(x?new Uint8Array(this.a.buffer):this.a,this.b),T=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],U=Array(19);for(B=F,S.d(1,1,v),S.d(B,2,v),C=h(this,g),I=j(this.M,15),J=l(I),K=j(this.L,7),L=l(K),D=286;D>257&&0===I[D-1];D--);for(E=30;E>1&&0===K[E-1];E--);var V,W,X,Y,Z,$,_=D,aa=E,ba=new(x?Uint32Array:Array)(_+aa),ca=new(x?Uint32Array:Array)(316),da=new(x?Uint8Array:Array)(19);for(V=W=0;_>V;V++)ba[W++]=I[V];for(V=0;aa>V;V++)ba[W++]=K[V];if(!x)for(V=0,Y=da.length;Y>V;++V)da[V]=0;for(V=Z=0,Y=ba.length;Y>V;V+=W){for(W=1;Y>V+W&&ba[V+W]===ba[V];++W);if(X=W,0===ba[V])if(3>X)for(;00;)$=138>X?X:138,$>X-3&&X>$&&($=X-3),10>=$?(ca[Z++]=17,ca[Z++]=$-3,da[17]++):(ca[Z++]=18,ca[Z++]=$-11,da[18]++),X-=$;else if(ca[Z++]=ba[V],da[ba[V]]++,X--,3>X)for(;00;)$=6>X?X:6,$>X-3&&X>$&&($=X-3),ca[Z++]=16,ca[Z++]=$-3,da[16]++,X-=$}for(b=x?ca.subarray(0,Z):ca.slice(0,Z),M=j(da,7),Q=0;19>Q;Q++)U[Q]=M[T[Q]];for(G=19;G>4&&0===U[G-1];G--);for(N=l(M),S.d(D-257,5,v),S.d(E-1,5,v),S.d(G-4,4,v),Q=0;G>Q;Q++)S.d(U[Q],3,v);for(Q=0,R=b.length;R>Q;Q++)if(O=b[Q],S.d(N[O],M[O],v),O>=16){switch(Q++,O){case 16:P=2;break;case 17:P=3;break;case 18:P=7;break;default:a("invalid code: "+O)}S.d(b[Q],P,v)}var ea,fa,ga,ha,ia,ja,ka,la,ma=[J,I],na=[L,K];for(ia=ma[0],ja=ma[1],ka=na[0],la=na[1],ea=0,fa=C.length;fa>ea;++ea)if(ga=C[ea],S.d(ia[ga],ja[ga],v),ga>256)S.d(C[++ea],C[++ea],v),ha=C[++ea],S.d(ka[ha],la[ha],v),S.d(C[++ea],C[++ea],v);else if(256===ga)break;this.a=S.finish(),this.b=this.a.length;break;default:a("invalid compression type")}return this.a};var I=function(){function b(b){switch(v){case 3===b:return[257,b-3,0];case 4===b:return[258,b-4,0];case 5===b:return[259,b-5,0];case 6===b:return[260,b-6,0];case 7===b:return[261,b-7,0];case 8===b:return[262,b-8,0];case 9===b:return[263,b-9,0];case 10===b:return[264,b-10,0];case 12>=b:return[265,b-11,1];case 14>=b:return[266,b-13,1];case 16>=b:return[267,b-15,1];case 18>=b:return[268,b-17,1];case 22>=b:return[269,b-19,2];case 26>=b:return[270,b-23,2];case 30>=b:return[271,b-27,2];case 34>=b:return[272,b-31,2];case 42>=b:return[273,b-35,3];case 50>=b:return[274,b-43,3];case 58>=b:return[275,b-51,3];case 66>=b:return[276,b-59,3];case 82>=b:return[277,b-67,4];case 98>=b:return[278,b-83,4];case 114>=b:return[279,b-99,4];case 130>=b:return[280,b-115,4];case 162>=b:return[281,b-131,5];case 194>=b:return[282,b-163,5];case 226>=b:return[283,b-195,5];case 257>=b:return[284,b-227,5];case 258===b:return[285,b-258,0];default:a("invalid length: "+b)}}var c,d,e=[];for(c=3;258>=c;c++)d=b(c),e[c]=d[2]<<24|d[1]<<16|d[0];return e}(),J=x?new Uint32Array(I):I,K=0,L=1,M={F:K,D:L};m.prototype.p=function(){for(;!this.s;){var b=n(this,3);switch(1&b&&(this.s=v),b>>>=1){case 0:var c=this.input,d=this.c,e=this.a,f=this.b,g=c.length,h=u,i=u,j=e.length,k=u;switch(this.e=this.g=0,d+1>=g&&a(Error("invalid uncompressed block header: LEN")),h=c[d++]|c[d++]<<8,d+1>=g&&a(Error("invalid uncompressed block header: NLEN")),i=c[d++]|c[d++]<<8,h===~i&&a(Error("invalid uncompressed block header: length verify")),d+h>c.length&&a(Error("input buffer is broken")),this.n){case K:for(;f+h>e.length;){if(k=j-f,h-=k,x)e.set(c.subarray(d,d+k),f),f+=k,d+=k;else for(;k--;)e[f++]=c[d++];this.b=f,e=this.f(),f=this.b}break;case L:for(;f+h>e.length;)e=this.f({v:2});break;default:a(Error("invalid inflate mode"))}if(x)e.set(c.subarray(d,d+h),f),f+=h,d+=h;else for(;h--;)e[f++]=c[d++];this.c=d,this.b=f,this.a=e;break;case 1:this.o(aa,ca);break;case 2:p(this);break;default:a(Error("unknown BTYPE: "+b))}}return this.t()};var N,O,P=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Q=x?new Uint16Array(P):P,R=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],S=x?new Uint16Array(R):R,T=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],U=x?new Uint8Array(T):T,V=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],W=x?new Uint16Array(V):V,X=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Y=x?new Uint8Array(X):X,Z=new(x?Uint8Array:Array)(288);for(N=0,O=Z.length;O>N;++N)Z[N]=143>=N?8:255>=N?9:279>=N?7:8;var $,_,aa=e(Z),ba=new(x?Uint8Array:Array)(30);for($=0,_=ba.length;_>$;++$)ba[$]=5;var ca=e(ba);m.prototype.o=function(a,b){var c=this.a,d=this.b;this.u=a;for(var e,f,g,h,i=c.length-258;256!==(e=o(this,a));)if(256>e)d>=i&&(this.b=d,c=this.f(),d=this.b),c[d++]=e;else for(f=e-257,h=S[f],0=i&&(this.b=d,c=this.f(),d=this.b);h--;)c[d]=c[d++-g];for(;8<=this.e;)this.e-=8,this.c--;this.b=d},m.prototype.J=function(a,b){var c=this.a,d=this.b;this.u=a;for(var e,f,g,h,i=c.length;256!==(e=o(this,a));)if(256>e)d>=i&&(c=this.f(),i=c.length),c[d++]=e;else for(f=e-257,h=S[f],0i&&(c=this.f(),i=c.length);h--;)c[d]=c[d++-g];for(;8<=this.e;)this.e-=8,this.c--;this.b=d},m.prototype.f=function(){var a,b,c=new(x?Uint8Array:Array)(this.b-32768),d=this.b-32768,e=this.a;if(x)c.set(e.subarray(32768,c.length));else for(a=0,b=c.length;b>a;++a)c[a]=e[a+32768];if(this.l.push(c),this.q+=c.length,x)e.set(e.subarray(d,d+32768));else for(a=0;32768>a;++a)e[a]=e[d+a];return this.b=32768,e},m.prototype.K=function(a){var b,c,d,e,f=this.input.length/this.c+1|0,g=this.input,h=this.a;return a&&("number"==typeof a.v&&(f=a.v),"number"==typeof a.G&&(f+=a.G)),2>f?(c=(g.length-this.c)/this.u[2],e=258*(c/2)|0,d=eb;++b)for(a=h[b],d=0,e=a.length;e>d;++d)i[f++]=a[d];for(b=32768,c=this.b;c>b;++b)i[f++]=g[b];return this.l=[],this.buffer=i},m.prototype.I=function(){var a,b=this.b;return x?this.C?(a=new Uint8Array(b),a.set(this.a.subarray(0,b))):a=this.a.subarray(0,b):(this.a.length>b&&(this.a.length=b),a=this.a),this.buffer=a},r.prototype.p=function(){var b,c,d=this.input;return b=this.B.p(),this.c=this.B.c,this.N&&(c=(d[this.c++]<<24|d[this.c++]<<16|d[this.c++]<<8|d[this.c++])>>>0,c!==q(b)&&a(Error("invalid adler-32 checksum"))),b};var da=8,ea=G;s.prototype.j=function(){var b,c,d,e,f,g,h,i=0;switch(h=this.a,b=da){case da:c=Math.LOG2E*Math.log(32768)-8;break;default:a(Error("invalid compression method"))}switch(d=c<<4|b,h[i++]=d,b){case da:switch(this.h){case ea.NONE:f=0;break;case ea.r:f=1;break;case ea.k:f=2;break;default:a(Error("unsupported compression type"))}break;default:a(Error("invalid compression method"))}return e=f<<6|0,h[i++]=e|31-(256*d+e)%31,g=q(this.input),this.A.b=i,h=this.A.j(),i=h.length,x&&(h=new Uint8Array(h.buffer),h.length<=i+4&&(this.a=new Uint8Array(h.length+4),this.a.set(h),h=this.a),h=h.subarray(0,i+4)),h[i++]=g>>24&255,h[i++]=g>>16&255,h[i++]=g>>8&255,h[i++]=255&g,h},b("Zlib.Inflate",r),b("Zlib.Inflate.prototype.decompress",r.prototype.p),t("Zlib.Inflate.BufferType",{ADAPTIVE:M.D,BLOCK:M.F}),b("Zlib.Deflate",s),b("Zlib.Deflate.compress",function(a,b){return new s(a,b).j()}),b("Zlib.Deflate.prototype.compress",s.prototype.j),t("Zlib.Deflate.CompressionType",{NONE:ea.NONE,FIXED:ea.r,DYNAMIC:ea.k})}).call(this)},{}],18:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(c,"__esModule",{value:!0});var e=a("../enums.js"),f=d(e);c["default"]={prefer_hash_algorithm:f["default"].hash.sha256,encryption_cipher:f["default"].symmetric.aes256,compression:f["default"].compression.zip,integrity_protect:!0,ignore_mdc_error:!1,rsa_blinding:!0,useNative:!0,zeroCopy:!1,debug:!1,show_version:!0,show_comment:!0,versionstring:"OpenPGP.js v2.0.0",commentstring:"http://openpgpjs.org",keyserver:"https://keyserver.ubuntu.com",node_store:"./openpgp.store"}},{"../enums.js":43}],19:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(c,"__esModule",{value:!0});var e=a("./config.js");Object.defineProperty(c,"default",{enumerable:!0,get:function(){return d(e)["default"]}})},{"./config.js":18}],20:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(c,"__esModule",{value:!0});var e=a("./cipher"),f=d(e);c["default"]={encrypt:function(a,b,c,d,e){b=new f["default"][b](d);var g=b.blockSize,h=new Uint8Array(g),i=new Uint8Array(g),j=new Uint8Array(a.length+2);j.set(a),j[a.length]=a[g-2],j[a.length+1]=a[g-1],a=j;var k,l,m,n=new Uint8Array(c.length+2+2*g),o=e?0:2;for(k=0;g>k;k++)h[k]=0;for(i=b.encrypt(h),k=0;g>k;k++)n[k]=i[k]^a[k];for(h.set(n.subarray(0,g)),i=b.encrypt(h),n[g]=i[0]^a[g],n[g+1]=i[1]^a[g+1],e?h.set(n.subarray(2,g+2)):h.set(n.subarray(0,g)),i=b.encrypt(h),k=0;g>k;k++)n[g+2+k]=i[k+o]^c[k];for(l=g;lk;k++)n[g+m+k]=i[k]^c[l+k-o];return n=n.subarray(0,c.length+2+g)},mdc:function(a,b,c){a=new f["default"][a](b);var d,e=a.blockSize,g=new Uint8Array(e),h=new Uint8Array(e);for(d=0;e>d;d++)g[d]=0;for(g=a.encrypt(g),d=0;e>d;d++)h[d]=c[d],g[d]^=h[d];h=a.encrypt(h);var i=new Uint8Array(g.length+2);return i.set(g),i[g.length]=h[0]^c[e],i[g.length+1]=h[1]^c[e+1],i},decrypt:function(a,b,c,d){a=new f["default"][a](b);var e,g,h,i=a.blockSize,j=new Uint8Array(i),k=new Uint8Array(i),l=new Uint8Array(c.length-i);for(e=0;i>e;e++)j[e]=0;for(j=a.encrypt(j),e=0;i>e;e++)k[e]=c[e],j[e]^=k[e];if(k=a.encrypt(k),j[i-2]!==(k[0]^c[i])||j[i-1]!==(k[1]^c[i+1]))throw new Error("CFB decrypt: invalid key");if(g=0,d){for(e=0;i>e;e++)j[e]=c[e+2];for(h=i+2;he&&e+he;e++)j[e]=c[e];for(h=i;he&&e+he;e++)i[e]=0;else for(e=0;g>e;e++)i[e]=d[e];for(;c.length>g*j;){var m=a.encrypt(i);for(h=c.subarray(j*g,j*g+g),e=0;eg;g++)e[g]=0;else e=d.subarray(0,h);for(;c.length>h*i;){var m=a.encrypt(e);for(e=c.subarray(i*h+k,i*h+h+k),g=0;g>8&255}function f(a){return a>>16&255}function g(a){return a>>24&255}function h(a,b,c,d){return e(p[255&a])|e(p[b>>8&255])<<8|e(p[c>>16&255])<<16|e(p[d>>>24])<<24}function i(a){var b,c,d=a.length,e=new Array(d/4);if(a&&!(d%4)){for(b=0,c=0;d>c;c+=4)e[b++]=a[c]|a[c+1]<<8|a[c+2]<<16|a[c+3]<<24;return e}}function j(a){var b,c=0,h=a.length,i=new Array(4*h);for(b=0;h>b;b++)i[c++]=d(a[b]),i[c++]=e(a[b]),i[c++]=f(a[b]),i[c++]=g(a[b]);return i}function k(a){var b,c,h,i,j,k,l=new Array(u+1),m=a.length,p=new Array(t),q=new Array(t),r=0;if(16===m)k=10,b=4;else if(24===m)k=12,b=6;else{if(32!==m)throw new Error("Invalid key-length for AES key:"+m);k=14,b=8}for(c=0;u+1>c;c++)l[c]=new Uint32Array(4);for(c=0,h=0;m>h;h++,c+=4)p[h]=a[c]|a[c+1]<<8|a[c+2]<<16|a[c+3]<<24;for(h=b-1;h>=0;h--)q[h]=p[h];for(i=0,j=0,h=0;b>h&&k+1>i;){for(;b>h&&4>j;h++,j++)l[i][j]=q[h];4===j&&(i++,j=0)}for(;k+1>i;){var s=q[b-1];if(q[0]^=o[e(s)]|o[f(s)]<<8|o[g(s)]<<16|o[d(s)]<<24,q[0]^=n[r++],8!==b)for(h=1;b>h;h++)q[h]^=q[h-1];else{for(h=1;b/2>h;h++)q[h]^=q[h-1];for(s=q[b/2-1],q[b/2]^=o[d(s)]|o[e(s)]<<8|o[f(s)]<<16|o[g(s)]<<24,h=b/2+1;b>h;h++)q[h]^=q[h-1]}for(h=0;b>h&&k+1>i;){for(;b>h&&4>j;h++,j++)l[i][j]=q[h];4===j&&(i++,j=0)}}return{rounds:k,rk:l}}function l(a,b,c){var d,e,f;for(f=i(a),e=b.rounds,d=0;e-1>d;d++)c[0]=f[0]^b.rk[d][0],c[1]=f[1]^b.rk[d][1],c[2]=f[2]^b.rk[d][2],c[3]=f[3]^b.rk[d][3],f[0]=p[255&c[0]]^q[c[1]>>8&255]^r[c[2]>>16&255]^s[c[3]>>>24],f[1]=p[255&c[1]]^q[c[2]>>8&255]^r[c[3]>>16&255]^s[c[0]>>>24],f[2]=p[255&c[2]]^q[c[3]>>8&255]^r[c[0]>>16&255]^s[c[1]>>>24],f[3]=p[255&c[3]]^q[c[0]>>8&255]^r[c[1]>>16&255]^s[c[2]>>>24];return d=e-1,c[0]=f[0]^b.rk[d][0],c[1]=f[1]^b.rk[d][1],c[2]=f[2]^b.rk[d][2],c[3]=f[3]^b.rk[d][3],f[0]=h(c[0],c[1],c[2],c[3])^b.rk[e][0],f[1]=h(c[1],c[2],c[3],c[0])^b.rk[e][1],f[2]=h(c[2],c[3],c[0],c[1])^b.rk[e][2],f[3]=h(c[3],c[0],c[1],c[2])^b.rk[e][3],j(f)}function m(a){var b=function(a){this.key=k(a),this._temp=new Uint32Array(this.blockSize/4),this.encrypt=function(a){return l(a,this.key,this._temp)}};return b.blockSize=b.prototype.blockSize=16,b.keySize=b.prototype.keySize=a/8,b}Object.defineProperty(c,"__esModule",{value:!0});var n=new Uint8Array([1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145]),o=new Uint8Array([99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22]),p=new Uint32Array([2774754246,2222750968,2574743534,2373680118,234025727,3177933782,2976870366,1422247313,1345335392,50397442,2842126286,2099981142,436141799,1658312629,3870010189,2591454956,1170918031,2642575903,1086966153,2273148410,368769775,3948501426,3376891790,200339707,3970805057,1742001331,4255294047,3937382213,3214711843,4154762323,2524082916,1539358875,3266819957,486407649,2928907069,1780885068,1513502316,1094664062,49805301,1338821763,1546925160,4104496465,887481809,150073849,2473685474,1943591083,1395732834,1058346282,201589768,1388824469,1696801606,1589887901,672667696,2711000631,251987210,3046808111,151455502,907153956,2608889883,1038279391,652995533,1764173646,3451040383,2675275242,453576978,2659418909,1949051992,773462580,756751158,2993581788,3998898868,4221608027,4132590244,1295727478,1641469623,3467883389,2066295122,1055122397,1898917726,2542044179,4115878822,1758581177,0,753790401,1612718144,536673507,3367088505,3982187446,3194645204,1187761037,3653156455,1262041458,3729410708,3561770136,3898103984,1255133061,1808847035,720367557,3853167183,385612781,3309519750,3612167578,1429418854,2491778321,3477423498,284817897,100794884,2172616702,4031795360,1144798328,3131023141,3819481163,4082192802,4272137053,3225436288,2324664069,2912064063,3164445985,1211644016,83228145,3753688163,3249976951,1977277103,1663115586,806359072,452984805,250868733,1842533055,1288555905,336333848,890442534,804056259,3781124030,2727843637,3427026056,957814574,1472513171,4071073621,2189328124,1195195770,2892260552,3881655738,723065138,2507371494,2690670784,2558624025,3511635870,2145180835,1713513028,2116692564,2878378043,2206763019,3393603212,703524551,3552098411,1007948840,2044649127,3797835452,487262998,1994120109,1004593371,1446130276,1312438900,503974420,3679013266,168166924,1814307912,3831258296,1573044895,1859376061,4021070915,2791465668,2828112185,2761266481,937747667,2339994098,854058965,1137232011,1496790894,3077402074,2358086913,1691735473,3528347292,3769215305,3027004632,4199962284,133494003,636152527,2942657994,2390391540,3920539207,403179536,3585784431,2289596656,1864705354,1915629148,605822008,4054230615,3350508659,1371981463,602466507,2094914977,2624877800,555687742,3712699286,3703422305,2257292045,2240449039,2423288032,1111375484,3300242801,2858837708,3628615824,84083462,32962295,302911004,2741068226,1597322602,4183250862,3501832553,2441512471,1489093017,656219450,3114180135,954327513,335083755,3013122091,856756514,3144247762,1893325225,2307821063,2811532339,3063651117,572399164,2458355477,552200649,1238290055,4283782570,2015897680,2061492133,2408352771,4171342169,2156497161,386731290,3669999461,837215959,3326231172,3093850320,3275833730,2962856233,1999449434,286199582,3417354363,4233385128,3602627437,974525996]),q=new Uint32Array([1667483301,2088564868,2004348569,2071721613,4076011277,1802229437,1869602481,3318059348,808476752,16843267,1734856361,724260477,4278118169,3621238114,2880130534,1987505306,3402272581,2189565853,3385428288,2105408135,4210749205,1499050731,1195871945,4042324747,2913812972,3570709351,2728550397,2947499498,2627478463,2762232823,1920132246,3233848155,3082253762,4261273884,2475900334,640044138,909536346,1061125697,4160222466,3435955023,875849820,2779075060,3857043764,4059166984,1903288979,3638078323,825320019,353708607,67373068,3351745874,589514341,3284376926,404238376,2526427041,84216335,2593796021,117902857,303178806,2155879323,3806519101,3958099238,656887401,2998042573,1970662047,151589403,2206408094,741103732,437924910,454768173,1852759218,1515893998,2694863867,1381147894,993752653,3604395873,3014884814,690573947,3823361342,791633521,2223248279,1397991157,3520182632,0,3991781676,538984544,4244431647,2981198280,1532737261,1785386174,3419114822,3200149465,960066123,1246401758,1280088276,1482207464,3486483786,3503340395,4025468202,2863288293,4227591446,1128498885,1296931543,859006549,2240090516,1162185423,4193904912,33686534,2139094657,1347461360,1010595908,2678007226,2829601763,1364304627,2745392638,1077969088,2408514954,2459058093,2644320700,943222856,4126535940,3166462943,3065411521,3671764853,555827811,269492272,4294960410,4092853518,3537026925,3452797260,202119188,320022069,3974939439,1600110305,2543269282,1145342156,387395129,3301217111,2812761586,2122251394,1027439175,1684326572,1566423783,421081643,1936975509,1616953504,2172721560,1330618065,3705447295,572671078,707417214,2425371563,2290617219,1179028682,4008625961,3099093971,336865340,3739133817,1583267042,185275933,3688607094,3772832571,842163286,976909390,168432670,1229558491,101059594,606357612,1549580516,3267534685,3553869166,2896970735,1650640038,2442213800,2509582756,3840201527,2038035083,3890730290,3368586051,926379609,1835915959,2374828428,3587551588,1313774802,2846444e3,1819072692,1448520954,4109693703,3941256997,1701169839,2054878350,2930657257,134746136,3132780501,2021191816,623200879,774790258,471611428,2795919345,3031724999,3334903633,3907570467,3722289532,1953818780,522141217,1263245021,3183305180,2341145990,2324303749,1886445712,1044282434,3048567236,1718013098,1212715224,50529797,4143380225,235805714,1633796771,892693087,1465364217,3115936208,2256934801,3250690392,488454695,2661164985,3789674808,4177062675,2560109491,286335539,1768542907,3654920560,2391672713,2492740519,2610638262,505297954,2273777042,3924412704,3469641545,1431677695,673730680,3755976058,2357986191,2711706104,2307459456,218962455,3216991706,3873888049,1111655622,1751699640,1094812355,2576951728,757946999,252648977,2964356043,1414834428,3149622742,370551866]),r=new Uint32Array([1673962851,2096661628,2012125559,2079755643,4076801522,1809235307,1876865391,3314635973,811618352,16909057,1741597031,727088427,4276558334,3618988759,2874009259,1995217526,3398387146,2183110018,3381215433,2113570685,4209972730,1504897881,1200539975,4042984432,2906778797,3568527316,2724199842,2940594863,2619588508,2756966308,1927583346,3231407040,3077948087,4259388669,2470293139,642542118,913070646,1065238847,4160029431,3431157708,879254580,2773611685,3855693029,4059629809,1910674289,3635114968,828527409,355090197,67636228,3348452039,591815971,3281870531,405809176,2520228246,84545285,2586817946,118360327,304363026,2149292928,3806281186,3956090603,659450151,2994720178,1978310517,152181513,2199756419,743994412,439627290,456535323,1859957358,1521806938,2690382752,1386542674,997608763,3602342358,3011366579,693271337,3822927587,794718511,2215876484,1403450707,3518589137,0,3988860141,541089824,4242743292,2977548465,1538714971,1792327274,3415033547,3194476990,963791673,1251270218,1285084236,1487988824,3481619151,3501943760,4022676207,2857362858,4226619131,1132905795,1301993293,862344499,2232521861,1166724933,4192801017,33818114,2147385727,1352724560,1014514748,2670049951,2823545768,1369633617,2740846243,1082179648,2399505039,2453646738,2636233885,946882616,4126213365,3160661948,3061301686,3668932058,557998881,270544912,4293204735,4093447923,3535760850,3447803085,202904588,321271059,3972214764,1606345055,2536874647,1149815876,388905239,3297990596,2807427751,2130477694,1031423805,1690872932,1572530013,422718233,1944491379,1623236704,2165938305,1335808335,3701702620,574907938,710180394,2419829648,2282455944,1183631942,4006029806,3094074296,338181140,3735517662,1589437022,185998603,3685578459,3772464096,845436466,980700730,169090570,1234361161,101452294,608726052,1555620956,3265224130,3552407251,2890133420,1657054818,2436475025,2503058581,3839047652,2045938553,3889509095,3364570056,929978679,1843050349,2365688973,3585172693,1318900302,2840191145,1826141292,1454176854,4109567988,3939444202,1707781989,2062847610,2923948462,135272456,3127891386,2029029496,625635109,777810478,473441308,2790781350,3027486644,3331805638,3905627112,3718347997,1961401460,524165407,1268178251,3177307325,2332919435,2316273034,1893765232,1048330814,3044132021,1724688998,1217452104,50726147,4143383030,236720654,1640145761,896163637,1471084887,3110719673,2249691526,3248052417,490350365,2653403550,3789109473,4176155640,2553000856,287453969,1775418217,3651760345,2382858638,2486413204,2603464347,507257374,2266337927,3922272489,3464972750,1437269845,676362280,3752164063,2349043596,2707028129,2299101321,219813645,3211123391,3872862694,1115997762,1758509160,1099088705,2569646233,760903469,253628687,2960903088,1420360788,3144537787,371997206]),s=new Uint32Array([3332727651,4169432188,4003034999,4136467323,4279104242,3602738027,3736170351,2438251973,1615867952,33751297,3467208551,1451043627,3877240574,3043153879,1306962859,3969545846,2403715786,530416258,2302724553,4203183485,4011195130,3001768281,2395555655,4211863792,1106029997,3009926356,1610457762,1173008303,599760028,1408738468,3835064946,2606481600,1975695287,3776773629,1034851219,1282024998,1817851446,2118205247,4110612471,2203045068,1750873140,1374987685,3509904869,4178113009,3801313649,2876496088,1649619249,708777237,135005188,2505230279,1181033251,2640233411,807933976,933336726,168756485,800430746,235472647,607523346,463175808,3745374946,3441880043,1315514151,2144187058,3936318837,303761673,496927619,1484008492,875436570,908925723,3702681198,3035519578,1543217312,2767606354,1984772923,3076642518,2110698419,1383803177,3711886307,1584475951,328696964,2801095507,3110654417,0,3240947181,1080041504,3810524412,2043195825,3069008731,3569248874,2370227147,1742323390,1917532473,2497595978,2564049996,2968016984,2236272591,3144405200,3307925487,1340451498,3977706491,2261074755,2597801293,1716859699,294946181,2328839493,3910203897,67502594,4269899647,2700103760,2017737788,632987551,1273211048,2733855057,1576969123,2160083008,92966799,1068339858,566009245,1883781176,4043634165,1675607228,2009183926,2943736538,1113792801,540020752,3843751935,4245615603,3211645650,2169294285,403966988,641012499,3274697964,3202441055,899848087,2295088196,775493399,2472002756,1441965991,4236410494,2051489085,3366741092,3135724893,841685273,3868554099,3231735904,429425025,2664517455,2743065820,1147544098,1417554474,1001099408,193169544,2362066502,3341414126,1809037496,675025940,2809781982,3168951902,371002123,2910247899,3678134496,1683370546,1951283770,337512970,2463844681,201983494,1215046692,3101973596,2673722050,3178157011,1139780780,3299238498,967348625,832869781,3543655652,4069226873,3576883175,2336475336,1851340599,3669454189,25988493,2976175573,2631028302,1239460265,3635702892,2902087254,4077384948,3475368682,3400492389,4102978170,1206496942,270010376,1876277946,4035475576,1248797989,1550986798,941890588,1475454630,1942467764,2538718918,3408128232,2709315037,3902567540,1042358047,2531085131,1641856445,226921355,260409994,3767562352,2084716094,1908716981,3433719398,2430093384,100991747,4144101110,470945294,3265487201,1784624437,2935576407,1775286713,395413126,2572730817,975641885,666476190,3644383713,3943954680,733190296,573772049,3535497577,2842745305,126455438,866620564,766942107,1008868894,361924487,3374377449,2269761230,2868860245,1350051880,2776293343,59739276,1509466529,159418761,437718285,1708834751,3610371814,2227585602,3501746280,2193834305,699439513,1517759789,504434447,2076946608,2835108948,1842789307,742004246]),t=8,u=14; +c["default"]={128:m(128),192:m(192),256:m(256)}},{}],22:[function(a,b,c){"use strict";function d(){}function e(a){this.bf=new d,this.bf.init(a),this.encrypt=function(a){return this.bf.encrypt_block(a)}}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e,d.prototype.BLOCKSIZE=8,d.prototype.SBOXES=[[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946],[1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055],[3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504],[976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462]],d.prototype.PARRAY=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],d.prototype.NN=16,d.prototype._clean=function(a){if(0>a){var b=2147483647&a;a=b+2147483648}return a},d.prototype._F=function(a){var b,c,d,e,f;return e=255&a,a>>>=8,d=255&a,a>>>=8,c=255&a,a>>>=8,b=255&a,f=this.sboxes[0][b]+this.sboxes[1][c],f^=this.sboxes[2][d],f+=this.sboxes[3][e]},d.prototype._encrypt_block=function(a){var b,c=a[0],d=a[1];for(b=0;b>>24-8*b&255,e[b+d]=c[1]>>>24-8*b&255;return e},d.prototype._decrypt_block=function(a){var b,c=a[0],d=a[1];for(b=this.NN+1;b>1;--b){c^=this.parray[b],d=this._F(c)^d;var e=c;c=d,d=e}c^=this.parray[1],d^=this.parray[0],a[0]=this._clean(d),a[1]=this._clean(c)},d.prototype.init=function(a){var b,c=0;for(this.parray=[],b=0;bd;++d)e=e<<8|255&a[c],++c>=a.length&&(c=0);this.parray[b]=this.PARRAY[b]^e}for(this.sboxes=[],b=0;4>b;++b)for(this.sboxes[b]=[],c=0;256>c;++c)this.sboxes[b][c]=this.SBOXES[b][c];var f=[0,0];for(b=0;bb;++b)for(c=0;256>c;c+=2)this._encrypt_block(f),this.sboxes[b][c+0]=f[0],this.sboxes[b][c+1]=f[1]},e.keySize=e.prototype.keySize=16,e.blockSize=e.prototype.blockSize=16},{}],23:[function(a,b,c){"use strict";function d(){function a(a,b,c){var d=b+a,e=d<>>32-c;return(f[0][e>>>24]^f[1][e>>>16&255])-f[2][e>>>8&255]+f[3][255&e]}function b(a,b,c){var d=b^a,e=d<>>32-c;return f[0][e>>>24]-f[1][e>>>16&255]+f[2][e>>>8&255]^f[3][255&e]}function c(a,b,c){var d=b-a,e=d<>>32-c;return(f[0][e>>>24]+f[1][e>>>16&255]^f[2][e>>>8&255])-f[3][255&e]}this.BlockSize=8,this.KeySize=16,this.setKey=function(a){if(this.masking=new Array(16),this.rotate=new Array(16),this.reset(),a.length!==this.KeySize)throw new Error("CAST-128: keys must be 16 bytes");return this.keySchedule(a),!0},this.reset=function(){for(var a=0;16>a;a++)this.masking[a]=0,this.rotate[a]=0},this.getBlockSize=function(){return this.BlockSize},this.encrypt=function(d){for(var e=new Array(d.length),f=0;f>>24&255,e[f+1]=i>>>16&255,e[f+2]=i>>>8&255,e[f+3]=255&i,e[f+4]=h>>>24&255,e[f+5]=h>>>16&255,e[f+6]=h>>>8&255,e[f+7]=255&h}return e},this.decrypt=function(d){for(var e=new Array(d.length),f=0;f>>24&255,e[f+1]=i>>>16&255,e[f+2]=i>>>8&255,e[f+3]=255&i,e[f+4]=h>>>24&255,e[f+5]=h>>16&255,e[f+6]=h>>8&255,e[f+7]=255&h}return e};var d=new Array(4);d[0]=new Array(4),d[0][0]=new Array(4,0,13,15,12,14,8),d[0][1]=new Array(5,2,16,18,17,19,10),d[0][2]=new Array(6,3,23,22,21,20,9),d[0][3]=new Array(7,1,26,25,27,24,11),d[1]=new Array(4),d[1][0]=new Array(0,6,21,23,20,22,16),d[1][1]=new Array(1,4,0,2,1,3,18),d[1][2]=new Array(2,5,7,6,5,4,17),d[1][3]=new Array(3,7,10,9,11,8,19),d[2]=new Array(4),d[2][0]=new Array(4,0,13,15,12,14,8),d[2][1]=new Array(5,2,16,18,17,19,10),d[2][2]=new Array(6,3,23,22,21,20,9),d[2][3]=new Array(7,1,26,25,27,24,11),d[3]=new Array(4),d[3][0]=new Array(0,6,21,23,20,22,16),d[3][1]=new Array(1,4,0,2,1,3,18),d[3][2]=new Array(2,5,7,6,5,4,17),d[3][3]=new Array(3,7,10,9,11,8,19);var e=new Array(4);e[0]=new Array(4),e[0][0]=new Array(24,25,23,22,18),e[0][1]=new Array(26,27,21,20,22),e[0][2]=new Array(28,29,19,18,25),e[0][3]=new Array(30,31,17,16,28),e[1]=new Array(4),e[1][0]=new Array(3,2,12,13,8),e[1][1]=new Array(1,0,14,15,13),e[1][2]=new Array(7,6,8,9,3),e[1][3]=new Array(5,4,10,11,7),e[2]=new Array(4),e[2][0]=new Array(19,18,28,29,25),e[2][1]=new Array(17,16,30,31,28),e[2][2]=new Array(23,22,24,25,18),e[2][3]=new Array(21,20,26,27,22),e[3]=new Array(4),e[3][0]=new Array(8,9,7,6,3),e[3][1]=new Array(10,11,5,4,7),e[3][2]=new Array(12,13,3,2,8),e[3][3]=new Array(14,15,1,0,13),this.keySchedule=function(a){var b,c,g=new Array(8),h=new Array(32);for(b=0;4>b;b++)c=4*b,g[b]=a[c]<<24|a[c+1]<<16|a[c+2]<<8|a[c+3];for(var i,j=[6,7,4,5],k=0,l=0;2>l;l++)for(var m=0;4>m;m++){for(c=0;4>c;c++){var n=d[m][c];i=g[n[1]],i^=f[4][g[n[2]>>>2]>>>24-8*(3&n[2])&255],i^=f[5][g[n[3]>>>2]>>>24-8*(3&n[3])&255],i^=f[6][g[n[4]>>>2]>>>24-8*(3&n[4])&255],i^=f[7][g[n[5]>>>2]>>>24-8*(3&n[5])&255],i^=f[j[c]][g[n[6]>>>2]>>>24-8*(3&n[6])&255],g[n[0]]=i}for(c=0;4>c;c++){var o=e[m][c];i=f[4][g[o[0]>>>2]>>>24-8*(3&o[0])&255],i^=f[5][g[o[1]>>>2]>>>24-8*(3&o[1])&255],i^=f[6][g[o[2]>>>2]>>>24-8*(3&o[2])&255],i^=f[7][g[o[3]>>>2]>>>24-8*(3&o[3])&255],i^=f[4+c][g[o[4]>>>2]>>>24-8*(3&o[4])&255],h[k]=i,k++}}for(b=0;16>b;b++)this.masking[b]=h[b],this.rotate[b]=31&h[16+b]};var f=new Array(8);f[0]=new Array(821772500,2678128395,1810681135,1059425402,505495343,2617265619,1610868032,3483355465,3218386727,2294005173,3791863952,2563806837,1852023008,365126098,3269944861,584384398,677919599,3229601881,4280515016,2002735330,1136869587,3744433750,2289869850,2731719981,2714362070,879511577,1639411079,575934255,717107937,2857637483,576097850,2731753936,1725645e3,2810460463,5111599,767152862,2543075244,1251459544,1383482551,3052681127,3089939183,3612463449,1878520045,1510570527,2189125840,2431448366,582008916,3163445557,1265446783,1354458274,3529918736,3202711853,3073581712,3912963487,3029263377,1275016285,4249207360,2905708351,3304509486,1442611557,3585198765,2712415662,2731849581,3248163920,2283946226,208555832,2766454743,1331405426,1447828783,3315356441,3108627284,2957404670,2981538698,3339933917,1669711173,286233437,1465092821,1782121619,3862771680,710211251,980974943,1651941557,430374111,2051154026,704238805,4128970897,3144820574,2857402727,948965521,3333752299,2227686284,718756367,2269778983,2731643755,718440111,2857816721,3616097120,1113355533,2478022182,410092745,1811985197,1944238868,2696854588,1415722873,1682284203,1060277122,1998114690,1503841958,82706478,2315155686,1068173648,845149890,2167947013,1768146376,1993038550,3566826697,3390574031,940016341,3355073782,2328040721,904371731,1205506512,4094660742,2816623006,825647681,85914773,2857843460,1249926541,1417871568,3287612,3211054559,3126306446,1975924523,1353700161,2814456437,2438597621,1800716203,722146342,2873936343,1151126914,4160483941,2877670899,458611604,2866078500,3483680063,770352098,2652916994,3367839148,3940505011,3585973912,3809620402,718646636,2504206814,2914927912,3631288169,2857486607,2860018678,575749918,2857478043,718488780,2069512688,3548183469,453416197,1106044049,3032691430,52586708,3378514636,3459808877,3211506028,1785789304,218356169,3571399134,3759170522,1194783844,1523787992,3007827094,1975193539,2555452411,1341901877,3045838698,3776907964,3217423946,2802510864,2889438986,1057244207,1636348243,3761863214,1462225785,2632663439,481089165,718503062,24497053,3332243209,3344655856,3655024856,3960371065,1195698900,2971415156,3710176158,2115785917,4027663609,3525578417,2524296189,2745972565,3564906415,1372086093,1452307862,2780501478,1476592880,3389271281,18495466,2378148571,901398090,891748256,3279637769,3157290713,2560960102,1447622437,4284372637,216884176,2086908623,1879786977,3588903153,2242455666,2938092967,3559082096,2810645491,758861177,1121993112,215018983,642190776,4169236812,1196255959,2081185372,3508738393,941322904,4124243163,2877523539,1848581667,2205260958,3180453958,2589345134,3694731276,550028657,2519456284,3789985535,2973870856,2093648313,443148163,46942275,2734146937,1117713533,1115362972,1523183689,3717140224,1551984063),f[1]=new Array(522195092,4010518363,1776537470,960447360,4267822970,4005896314,1435016340,1929119313,2913464185,1310552629,3579470798,3724818106,2579771631,1594623892,417127293,2715217907,2696228731,1508390405,3994398868,3925858569,3695444102,4019471449,3129199795,3770928635,3520741761,990456497,4187484609,2783367035,21106139,3840405339,631373633,3783325702,532942976,396095098,3548038825,4267192484,2564721535,2011709262,2039648873,620404603,3776170075,2898526339,3612357925,4159332703,1645490516,223693667,1567101217,3362177881,1029951347,3470931136,3570957959,1550265121,119497089,972513919,907948164,3840628539,1613718692,3594177948,465323573,2659255085,654439692,2575596212,2699288441,3127702412,277098644,624404830,4100943870,2717858591,546110314,2403699828,3655377447,1321679412,4236791657,1045293279,4010672264,895050893,2319792268,494945126,1914543101,2777056443,3894764339,2219737618,311263384,4275257268,3458730721,669096869,3584475730,3835122877,3319158237,3949359204,2005142349,2713102337,2228954793,3769984788,569394103,3855636576,1425027204,108000370,2736431443,3671869269,3043122623,1750473702,2211081108,762237499,3972989403,2798899386,3061857628,2943854345,867476300,964413654,1591880597,1594774276,2179821409,552026980,3026064248,3726140315,2283577634,3110545105,2152310760,582474363,1582640421,1383256631,2043843868,3322775884,1217180674,463797851,2763038571,480777679,2718707717,2289164131,3118346187,214354409,200212307,3810608407,3025414197,2674075964,3997296425,1847405948,1342460550,510035443,4080271814,815934613,833030224,1620250387,1945732119,2703661145,3966000196,1388869545,3456054182,2687178561,2092620194,562037615,1356438536,3409922145,3261847397,1688467115,2150901366,631725691,3840332284,549916902,3455104640,394546491,837744717,2114462948,751520235,2221554606,2415360136,3999097078,2063029875,803036379,2702586305,821456707,3019566164,360699898,4018502092,3511869016,3677355358,2402471449,812317050,49299192,2570164949,3259169295,2816732080,3331213574,3101303564,2156015656,3705598920,3546263921,143268808,3200304480,1638124008,3165189453,3341807610,578956953,2193977524,3638120073,2333881532,807278310,658237817,2969561766,1641658566,11683945,3086995007,148645947,1138423386,4158756760,1981396783,2401016740,3699783584,380097457,2680394679,2803068651,3334260286,441530178,4016580796,1375954390,761952171,891809099,2183123478,157052462,3683840763,1592404427,341349109,2438483839,1417898363,644327628,2233032776,2353769706,2201510100,220455161,1815641738,182899273,2995019788,3627381533,3702638151,2890684138,1052606899,588164016,1681439879,4038439418,2405343923,4229449282,167996282,1336969661,1688053129,2739224926,1543734051,1046297529,1138201970,2121126012,115334942,1819067631,1902159161,1941945968,2206692869,1159982321),f[2]=new Array(2381300288,637164959,3952098751,3893414151,1197506559,916448331,2350892612,2932787856,3199334847,4009478890,3905886544,1373570990,2450425862,4037870920,3778841987,2456817877,286293407,124026297,3001279700,1028597854,3115296800,4208886496,2691114635,2188540206,1430237888,1218109995,3572471700,308166588,570424558,2187009021,2455094765,307733056,1310360322,3135275007,1384269543,2388071438,863238079,2359263624,2801553128,3380786597,2831162807,1470087780,1728663345,4072488799,1090516929,532123132,2389430977,1132193179,2578464191,3051079243,1670234342,1434557849,2711078940,1241591150,3314043432,3435360113,3091448339,1812415473,2198440252,267246943,796911696,3619716990,38830015,1526438404,2806502096,374413614,2943401790,1489179520,1603809326,1920779204,168801282,260042626,2358705581,1563175598,2397674057,1356499128,2217211040,514611088,2037363785,2186468373,4022173083,2792511869,2913485016,1173701892,4200428547,3896427269,1334932762,2455136706,602925377,2835607854,1613172210,41346230,2499634548,2457437618,2188827595,41386358,4172255629,1313404830,2405527007,3801973774,2217704835,873260488,2528884354,2478092616,4012915883,2555359016,2006953883,2463913485,575479328,2218240648,2099895446,660001756,2341502190,3038761536,3888151779,3848713377,3286851934,1022894237,1620365795,3449594689,1551255054,15374395,3570825345,4249311020,4151111129,3181912732,310226346,1133119310,530038928,136043402,2476768958,3107506709,2544909567,1036173560,2367337196,1681395281,1758231547,3641649032,306774401,1575354324,3716085866,1990386196,3114533736,2455606671,1262092282,3124342505,2768229131,4210529083,1833535011,423410938,660763973,2187129978,1639812e3,3508421329,3467445492,310289298,272797111,2188552562,2456863912,310240523,677093832,1013118031,901835429,3892695601,1116285435,3036471170,1337354835,243122523,520626091,277223598,4244441197,4194248841,1766575121,594173102,316590669,742362309,3536858622,4176435350,3838792410,2501204839,1229605004,3115755532,1552908988,2312334149,979407927,3959474601,1148277331,176638793,3614686272,2083809052,40992502,1340822838,2731552767,3535757508,3560899520,1354035053,122129617,7215240,2732932949,3118912700,2718203926,2539075635,3609230695,3725561661,1928887091,2882293555,1988674909,2063640240,2491088897,1459647954,4189817080,2302804382,1113892351,2237858528,1927010603,4002880361,1856122846,1594404395,2944033133,3855189863,3474975698,1643104450,4054590833,3431086530,1730235576,2984608721,3084664418,2131803598,4178205752,267404349,1617849798,1616132681,1462223176,736725533,2327058232,551665188,2945899023,1749386277,2575514597,1611482493,674206544,2201269090,3642560800,728599968,1680547377,2620414464,1388111496,453204106,4156223445,1094905244,2754698257,2201108165,3757000246,2704524545,3922940700,3996465027),f[3]=new Array(2645754912,532081118,2814278639,3530793624,1246723035,1689095255,2236679235,4194438865,2116582143,3859789411,157234593,2045505824,4245003587,1687664561,4083425123,605965023,672431967,1336064205,3376611392,214114848,4258466608,3232053071,489488601,605322005,3998028058,264917351,1912574028,756637694,436560991,202637054,135989450,85393697,2152923392,3896401662,2895836408,2145855233,3535335007,115294817,3147733898,1922296357,3464822751,4117858305,1037454084,2725193275,2127856640,1417604070,1148013728,1827919605,642362335,2929772533,909348033,1346338451,3547799649,297154785,1917849091,4161712827,2883604526,3968694238,1469521537,3780077382,3375584256,1763717519,136166297,4290970789,1295325189,2134727907,2798151366,1566297257,3672928234,2677174161,2672173615,965822077,2780786062,289653839,1133871874,3491843819,35685304,1068898316,418943774,672553190,642281022,2346158704,1954014401,3037126780,4079815205,2030668546,3840588673,672283427,1776201016,359975446,3750173538,555499703,2769985273,1324923,69110472,152125443,3176785106,3822147285,1340634837,798073664,1434183902,15393959,216384236,1303690150,3881221631,3711134124,3960975413,106373927,2578434224,1455997841,1801814300,1578393881,1854262133,3188178946,3258078583,2302670060,1539295533,3505142565,3078625975,2372746020,549938159,3278284284,2620926080,181285381,2865321098,3970029511,68876850,488006234,1728155692,2608167508,836007927,2435231793,919367643,3339422534,3655756360,1457871481,40520939,1380155135,797931188,234455205,2255801827,3990488299,397000196,739833055,3077865373,2871719860,4022553888,772369276,390177364,3853951029,557662966,740064294,1640166671,1699928825,3535942136,622006121,3625353122,68743880,1742502,219489963,1664179233,1577743084,1236991741,410585305,2366487942,823226535,1050371084,3426619607,3586839478,212779912,4147118561,1819446015,1911218849,530248558,3486241071,3252585495,2886188651,3410272728,2342195030,20547779,2982490058,3032363469,3631753222,312714466,1870521650,1493008054,3491686656,615382978,4103671749,2534517445,1932181,2196105170,278426614,6369430,3274544417,2913018367,697336853,2143000447,2946413531,701099306,1558357093,2805003052,3500818408,2321334417,3567135975,216290473,3591032198,23009561,1996984579,3735042806,2024298078,3739440863,569400510,2339758983,3016033873,3097871343,3639523026,3844324983,3256173865,795471839,2951117563,4101031090,4091603803,3603732598,971261452,534414648,428311343,3389027175,2844869880,694888862,1227866773,2456207019,3043454569,2614353370,3749578031,3676663836,459166190,4132644070,1794958188,51825668,2252611902,3084671440,2036672799,3436641603,1099053433,2469121526,3059204941,1323291266,2061838604,1018778475,2233344254,2553501054,334295216,3556750194,1065731521,183467730),f[4]=new Array(2127105028,745436345,2601412319,2788391185,3093987327,500390133,1155374404,389092991,150729210,3891597772,3523549952,1935325696,716645080,946045387,2901812282,1774124410,3869435775,4039581901,3293136918,3438657920,948246080,363898952,3867875531,1286266623,1598556673,68334250,630723836,1104211938,1312863373,613332731,2377784574,1101634306,441780740,3129959883,1917973735,2510624549,3238456535,2544211978,3308894634,1299840618,4076074851,1756332096,3977027158,297047435,3790297736,2265573040,3621810518,1311375015,1667687725,47300608,3299642885,2474112369,201668394,1468347890,576830978,3594690761,3742605952,1958042578,1747032512,3558991340,1408974056,3366841779,682131401,1033214337,1545599232,4265137049,206503691,103024618,2855227313,1337551222,2428998917,2963842932,4015366655,3852247746,2796956967,3865723491,3747938335,247794022,3755824572,702416469,2434691994,397379957,851939612,2314769512,218229120,1380406772,62274761,214451378,3170103466,2276210409,3845813286,28563499,446592073,1693330814,3453727194,29968656,3093872512,220656637,2470637031,77972100,1667708854,1358280214,4064765667,2395616961,325977563,4277240721,4220025399,3605526484,3355147721,811859167,3069544926,3962126810,652502677,3075892249,4132761541,3498924215,1217549313,3250244479,3858715919,3053989961,1538642152,2279026266,2875879137,574252750,3324769229,2651358713,1758150215,141295887,2719868960,3515574750,4093007735,4194485238,1082055363,3417560400,395511885,2966884026,179534037,3646028556,3738688086,1092926436,2496269142,257381841,3772900718,1636087230,1477059743,2499234752,3811018894,2675660129,3285975680,90732309,1684827095,1150307763,1723134115,3237045386,1769919919,1240018934,815675215,750138730,2239792499,1234303040,1995484674,138143821,675421338,1145607174,1936608440,3238603024,2345230278,2105974004,323969391,779555213,3004902369,2861610098,1017501463,2098600890,2628620304,2940611490,2682542546,1171473753,3656571411,3687208071,4091869518,393037935,159126506,1662887367,1147106178,391545844,3452332695,1891500680,3016609650,1851642611,546529401,1167818917,3194020571,2848076033,3953471836,575554290,475796850,4134673196,450035699,2351251534,844027695,1080539133,86184846,1554234488,3692025454,1972511363,2018339607,1491841390,1141460869,1061690759,4244549243,2008416118,2351104703,2868147542,1598468138,722020353,1027143159,212344630,1387219594,1725294528,3745187956,2500153616,458938280,4129215917,1828119673,544571780,3503225445,2297937496,1241802790,267843827,2694610800,1397140384,1558801448,3782667683,1806446719,929573330,2234912681,400817706,616011623,4121520928,3603768725,1761550015,1968522284,4053731006,4192232858,4005120285,872482584,3140537016,3894607381,2287405443,1963876937,3663887957,1584857e3,2975024454,1833426440,4025083860),f[5]=new Array(4143615901,749497569,1285769319,3795025788,2514159847,23610292,3974978748,844452780,3214870880,3751928557,2213566365,1676510905,448177848,3730751033,4086298418,2307502392,871450977,3222878141,4110862042,3831651966,2735270553,1310974780,2043402188,1218528103,2736035353,4274605013,2702448458,3936360550,2693061421,162023535,2827510090,687910808,23484817,3784910947,3371371616,779677500,3503626546,3473927188,4157212626,3500679282,4248902014,2466621104,3899384794,1958663117,925738300,1283408968,3669349440,1840910019,137959847,2679828185,1239142320,1315376211,1547541505,1690155329,739140458,3128809933,3933172616,3876308834,905091803,1548541325,4040461708,3095483362,144808038,451078856,676114313,2861728291,2469707347,993665471,373509091,2599041286,4025009006,4170239449,2149739950,3275793571,3749616649,2794760199,1534877388,572371878,2590613551,1753320020,3467782511,1405125690,4270405205,633333386,3026356924,3475123903,632057672,2846462855,1404951397,3882875879,3915906424,195638627,2385783745,3902872553,1233155085,3355999740,2380578713,2702246304,2144565621,3663341248,3894384975,2502479241,4248018925,3094885567,1594115437,572884632,3385116731,767645374,1331858858,1475698373,3793881790,3532746431,1321687957,619889600,1121017241,3440213920,2070816767,2833025776,1933951238,4095615791,890643334,3874130214,859025556,360630002,925594799,1764062180,3920222280,4078305929,979562269,2810700344,4087740022,1949714515,546639971,1165388173,3069891591,1495988560,922170659,1291546247,2107952832,1813327274,3406010024,3306028637,4241950635,153207855,2313154747,1608695416,1150242611,1967526857,721801357,1220138373,3691287617,3356069787,2112743302,3281662835,1111556101,1778980689,250857638,2298507990,673216130,2846488510,3207751581,3562756981,3008625920,3417367384,2198807050,529510932,3547516680,3426503187,2364944742,102533054,2294910856,1617093527,1204784762,3066581635,1019391227,1069574518,1317995090,1691889997,3661132003,510022745,3238594800,1362108837,1817929911,2184153760,805817662,1953603311,3699844737,120799444,2118332377,207536705,2282301548,4120041617,145305846,2508124933,3086745533,3261524335,1877257368,2977164480,3160454186,2503252186,4221677074,759945014,254147243,2767453419,3801518371,629083197,2471014217,907280572,3900796746,940896768,2751021123,2625262786,3161476951,3661752313,3260732218,1425318020,2977912069,1496677566,3988592072,2140652971,3126511541,3069632175,977771578,1392695845,1698528874,1411812681,1369733098,1343739227,3620887944,1142123638,67414216,3102056737,3088749194,1626167401,2546293654,3941374235,697522451,33404913,143560186,2595682037,994885535,1247667115,3859094837,2699155541,3547024625,4114935275,2968073508,3199963069,2732024527,1237921620,951448369,1898488916,1211705605,2790989240,2233243581,3598044975), +f[6]=new Array(2246066201,858518887,1714274303,3485882003,713916271,2879113490,3730835617,539548191,36158695,1298409750,419087104,1358007170,749914897,2989680476,1261868530,2995193822,2690628854,3443622377,3780124940,3796824509,2976433025,4259637129,1551479e3,512490819,1296650241,951993153,2436689437,2460458047,144139966,3136204276,310820559,3068840729,643875328,1969602020,1680088954,2185813161,3283332454,672358534,198762408,896343282,276269502,3014846926,84060815,197145886,376173866,3943890818,3813173521,3545068822,1316698879,1598252827,2633424951,1233235075,859989710,2358460855,3503838400,3409603720,1203513385,1193654839,2792018475,2060853022,207403770,1144516871,3068631394,1121114134,177607304,3785736302,326409831,1929119770,2983279095,4183308101,3474579288,3200513878,3228482096,119610148,1170376745,3378393471,3163473169,951863017,3337026068,3135789130,2907618374,1183797387,2015970143,4045674555,2182986399,2952138740,3928772205,384012900,2454997643,10178499,2879818989,2596892536,111523738,2995089006,451689641,3196290696,235406569,1441906262,3890558523,3013735005,4158569349,1644036924,376726067,1006849064,3664579700,2041234796,1021632941,1374734338,2566452058,371631263,4007144233,490221539,206551450,3140638584,1053219195,1853335209,3412429660,3562156231,735133835,1623211703,3104214392,2738312436,4096837757,3366392578,3110964274,3956598718,3196820781,2038037254,3877786376,2339753847,300912036,3766732888,2372630639,1516443558,4200396704,1574567987,4069441456,4122592016,2699739776,146372218,2748961456,2043888151,35287437,2596680554,655490400,1132482787,110692520,1031794116,2188192751,1324057718,1217253157,919197030,686247489,3261139658,1028237775,3135486431,3059715558,2460921700,986174950,2661811465,4062904701,2752986992,3709736643,367056889,1353824391,731860949,1650113154,1778481506,784341916,357075625,3608602432,1074092588,2480052770,3811426202,92751289,877911070,3600361838,1231880047,480201094,3756190983,3094495953,434011822,87971354,363687820,1717726236,1901380172,3926403882,2481662265,400339184,1490350766,2661455099,1389319756,2558787174,784598401,1983468483,30828846,3550527752,2716276238,3841122214,1765724805,1955612312,1277890269,1333098070,1564029816,2704417615,1026694237,3287671188,1260819201,3349086767,1016692350,1582273796,1073413053,1995943182,694588404,1025494639,3323872702,3551898420,4146854327,453260480,1316140391,1435673405,3038941953,3486689407,1622062951,403978347,817677117,950059133,4246079218,3278066075,1486738320,1417279718,481875527,2549965225,3933690356,760697757,1452955855,3897451437,1177426808,1702951038,4085348628,2447005172,1084371187,3516436277,3068336338,1073369276,1027665953,3284188590,1230553676,1368340146,2226246512,267243139,2274220762,4070734279,2497715176,2423353163,2504755875),f[7]=new Array(3793104909,3151888380,2817252029,895778965,2005530807,3871412763,237245952,86829237,296341424,3851759377,3974600970,2475086196,709006108,1994621201,2972577594,937287164,3734691505,168608556,3189338153,2225080640,3139713551,3033610191,3025041904,77524477,185966941,1208824168,2344345178,1721625922,3354191921,1066374631,1927223579,1971335949,2483503697,1551748602,2881383779,2856329572,3003241482,48746954,1398218158,2050065058,313056748,4255789917,393167848,1912293076,940740642,3465845460,3091687853,2522601570,2197016661,1727764327,364383054,492521376,1291706479,3264136376,1474851438,1685747964,2575719748,1619776915,1814040067,970743798,1561002147,2925768690,2123093554,1880132620,3151188041,697884420,2550985770,2607674513,2659114323,110200136,1489731079,997519150,1378877361,3527870668,478029773,2766872923,1022481122,431258168,1112503832,897933369,2635587303,669726182,3383752315,918222264,163866573,3246985393,3776823163,114105080,1903216136,761148244,3571337562,1690750982,3166750252,1037045171,1888456500,2010454850,642736655,616092351,365016990,1185228132,4174898510,1043824992,2023083429,2241598885,3863320456,3279669087,3674716684,108438443,2132974366,830746235,606445527,4173263986,2204105912,1844756978,2532684181,4245352700,2969441100,3796921661,1335562986,4061524517,2720232303,2679424040,634407289,885462008,3294724487,3933892248,2094100220,339117932,4048830727,3202280980,1458155303,2689246273,1022871705,2464987878,3714515309,353796843,2822958815,4256850100,4052777845,551748367,618185374,3778635579,4020649912,1904685140,3069366075,2670879810,3407193292,2954511620,4058283405,2219449317,3135758300,1120655984,3447565834,1474845562,3577699062,550456716,3466908712,2043752612,881257467,869518812,2005220179,938474677,3305539448,3850417126,1315485940,3318264702,226533026,965733244,321539988,1136104718,804158748,573969341,3708209826,937399083,3290727049,2901666755,1461057207,4013193437,4066861423,3242773476,2421326174,1581322155,3028952165,786071460,3900391652,3918438532,1485433313,4023619836,3708277595,3678951060,953673138,1467089153,1930354364,1533292819,2492563023,1346121658,1685000834,1965281866,3765933717,4190206607,2052792609,3515332758,690371149,3125873887,2180283551,2903598061,3933952357,436236910,289419410,14314871,1242357089,2904507907,1616633776,2666382180,585885352,3471299210,2699507360,1432659641,277164553,3354103607,770115018,2303809295,3741942315,3177781868,2853364978,2269453327,3774259834,987383833,1290892879,225909803,1741533526,890078084,1496906255,1111072499,916028167,243534141,1252605537,2204162171,531204876,290011180,3916834213,102027703,237315147,209093447,1486785922,220223953,2758195998,4175039106,82940208,3127791296,2569425252,518464269,1353887104,3941492737,2377294467,3935040926)}function e(a){this.cast5=new d,this.cast5.setKey(a),this.encrypt=function(a){return this.cast5.encrypt(a)}}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e,e.blockSize=e.prototype.blockSize=8,e.keySize=e.prototype.keySize=16},{}],24:[function(a,b,c){"use strict";function d(a,b,c,d,e,h){var i,j,k,l,m,n,o,p,q,r,s,t,u,v,w=new Array(16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756),x=new Array(-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344),y=new Array(520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584),z=new Array(8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928),A=new Array(256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080),B=new Array(536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312),C=new Array(2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154),D=new Array(268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696),E=0,F=b.length,G=32===a.length?3:9;p=3===G?c?new Array(0,32,2):new Array(30,-2,-2):c?new Array(0,32,2,62,30,-2,64,96,2):new Array(94,62,-2,32,64,2,30,-2,-2),c&&(b=f(b,h),F=b.length);var H=new Uint8Array(F),I=0;for(1===d&&(q=e[E++]<<24|e[E++]<<16|e[E++]<<8|e[E++],s=e[E++]<<24|e[E++]<<16|e[E++]<<8|e[E++],E=0);F>E;){for(n=b[E++]<<24|b[E++]<<16|b[E++]<<8|b[E++],o=b[E++]<<24|b[E++]<<16|b[E++]<<8|b[E++],1===d&&(c?(n^=q,o^=s):(r=q,t=s,q=n,s=o)),k=252645135&(n>>>4^o),o^=k,n^=k<<4,k=65535&(n>>>16^o),o^=k,n^=k<<16,k=858993459&(o>>>2^n),n^=k,o^=k<<2,k=16711935&(o>>>8^n),n^=k,o^=k<<8,k=1431655765&(n>>>1^o),o^=k,n^=k<<1,n=n<<1|n>>>31,o=o<<1|o>>>31,j=0;G>j;j+=3){for(u=p[j+1],v=p[j+2],i=p[j];i!==u;i+=v)l=o^a[i],m=(o>>>4|o<<28)^a[i+1],k=n,n=o,o=k^(x[l>>>24&63]|z[l>>>16&63]|B[l>>>8&63]|D[63&l]|w[m>>>24&63]|y[m>>>16&63]|A[m>>>8&63]|C[63&m]);k=n,n=o,o=k}n=n>>>1|n<<31,o=o>>>1|o<<31,k=1431655765&(n>>>1^o),o^=k,n^=k<<1,k=16711935&(o>>>8^n),n^=k,o^=k<<8,k=858993459&(o>>>2^n),n^=k,o^=k<<2,k=65535&(n>>>16^o),o^=k,n^=k<<16,k=252645135&(n>>>4^o),o^=k,n^=k<<4,1===d&&(c?(q=n,s=o):(n^=r,o^=t)),H[I++]=n>>>24,H[I++]=n>>>16&255,H[I++]=n>>>8&255,H[I++]=255&n,H[I++]=o>>>24,H[I++]=o>>>16&255,H[I++]=o>>>8&255,H[I++]=255&o}return c||(H=g(H,h)),H}function e(a){for(var b,c,d,e=new Array(0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964),f=new Array(0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697),g=new Array(0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272),h=new Array(0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144),i=new Array(0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256),j=new Array(0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488),k=new Array(0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746),l=new Array(0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568),m=new Array(0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578),n=new Array(0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488),o=new Array(0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800),p=new Array(0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744),q=new Array(0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128),r=new Array(0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261),s=a.length>8?3:1,t=new Array(32*s),u=new Array(0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0),v=0,w=0,x=0;s>x;x++){var y=a[v++]<<24|a[v++]<<16|a[v++]<<8|a[v++],z=a[v++]<<24|a[v++]<<16|a[v++]<<8|a[v++];d=252645135&(y>>>4^z),z^=d,y^=d<<4,d=65535&(z>>>-16^y),y^=d,z^=d<<-16,d=858993459&(y>>>2^z),z^=d,y^=d<<2,d=65535&(z>>>-16^y),y^=d,z^=d<<-16,d=1431655765&(y>>>1^z),z^=d,y^=d<<1,d=16711935&(z>>>8^y),y^=d,z^=d<<8,d=1431655765&(y>>>1^z),z^=d,y^=d<<1,d=y<<8|z>>>20&240,y=z<<24|z<<8&16711680|z>>>8&65280|z>>>24&240,z=d;for(var A=0;A>>26,z=z<<2|z>>>26):(y=y<<1|y>>>27,z=z<<1|z>>>27),y&=-15,z&=-15,b=e[y>>>28]|f[y>>>24&15]|g[y>>>20&15]|h[y>>>16&15]|i[y>>>12&15]|j[y>>>8&15]|k[y>>>4&15],c=l[z>>>28]|m[z>>>24&15]|n[z>>>20&15]|o[z>>>16&15]|p[z>>>12&15]|q[z>>>8&15]|r[z>>>4&15],d=65535&(c>>>16^b),t[w++]=b^d,t[w++]=c^d<<16}return t}function f(a,b){var c,d=8-a.length%8;if(2===b&&8>d)c=" ".charCodeAt(0);else if(1===b)c=d;else{if(b||!(8>d)){if(8===d)return a;throw new Error("des: invalid padding")}c=0}for(var e=new Uint8Array(a.length+d),f=0;fg;g++)e[a.length+g]=c;return e}function g(a,b){var c,d=null;if(2===b)c=" ".charCodeAt(0);else if(1===b)d=a[a.length-1];else{if(b)throw new Error("des: invalid padding");c=0}if(!d){for(d=1;a[a.length-d]===c;)d++;d--}return a.subarray(0,a.length-d)}function h(a){this.key=[];for(var b=0;3>b;b++)this.key.push(new Uint8Array(a.subarray(8*b,8*b+8)));this.encrypt=function(a){return d(e(this.key[2]),d(e(this.key[1]),d(e(this.key[0]),a,!0,0,null,null),!1,0,null,null),!0,0,null,null)}}function i(a){this.key=a,this.encrypt=function(a,b){var c=e(this.key);return d(c,a,!0,0,null,b)},this.decrypt=function(a,b){var c=e(this.key);return d(c,a,!1,0,null,b)}}Object.defineProperty(c,"__esModule",{value:!0}),h.keySize=h.prototype.keySize=24,h.blockSize=h.prototype.blockSize=8,c["default"]={des:h,originalDes:i}},{}],25:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(c,"__esModule",{value:!0});var e=a("./aes.js"),f=d(e),g=a("./des.js"),h=d(g),i=a("./cast5.js"),j=d(i),k=a("./twofish.js"),l=d(k),m=a("./blowfish.js"),n=d(m);c["default"]={aes128:f["default"][128],aes192:f["default"][192],aes256:f["default"][256],des:h["default"].originalDes,tripledes:h["default"].des,cast5:j["default"],twofish:l["default"],blowfish:n["default"],idea:function(){throw new Error("IDEA symmetric-key algorithm not implemented")}}},{"./aes.js":21,"./blowfish.js":22,"./cast5.js":23,"./des.js":24,"./twofish.js":26}],26:[function(a,b,c){"use strict";function d(a,b){return(a<>>32-b)&k}function e(a,b){return a[b]|a[b+1]<<8|a[b+2]<<16|a[b+3]<<24}function f(a,b,c){a.splice(b,4,255&c,c>>>8&255,c>>>16&255,c>>>24&255)}function g(a,b){return a>>>8*b&255}function h(){function a(a){function b(a){return a^a>>2^[0,90,180,238][3&a]}function c(a){return a^a>>1^a>>2^[0,238,180,90][3&a]}function f(a,b){var c,d,e;for(c=0;8>c;c++)d=b>>>24,b=b<<8&k|a>>>24,a=a<<8&k,e=d<<1,128&d&&(e^=333),b^=d^e<<16,e^=d>>>1,1&d&&(e^=166),b^=e<<24|e<<8;return b}function h(a,b){var c,d,e,f;return c=b>>4,d=15&b,e=A[a][c^d],f=B[a][E[d]^F[c]],D[a][E[f]^F[e]]<<4|C[a][e^f]}function i(a,b){var c=g(a,0),d=g(a,1),e=g(a,2),f=g(a,3);switch(q){case 4:c=G[1][c]^g(b[3],0),d=G[0][d]^g(b[3],1),e=G[0][e]^g(b[3],2),f=G[1][f]^g(b[3],3);case 3:c=G[1][c]^g(b[2],0),d=G[1][d]^g(b[2],1),e=G[0][e]^g(b[2],2),f=G[0][f]^g(b[2],3);case 2:c=G[0][G[0][c]^g(b[1],0)]^g(b[0],0),d=G[0][G[1][d]^g(b[1],1)]^g(b[0],1),e=G[1][G[0][e]^g(b[1],2)]^g(b[0],2),f=G[1][G[1][f]^g(b[1],3)]^g(b[0],3)}return H[0][c]^H[1][d]^H[2][e]^H[3][f]}o=a;var j,l,m,n,p,q,r,u,v,w=[],x=[],y=[],z=[],A=[[8,1,7,13,6,15,3,2,0,11,5,9,14,12,10,4],[2,8,11,13,15,7,6,14,3,1,9,4,0,10,12,5]],B=[[14,12,11,8,1,2,3,5,15,4,10,6,7,0,9,13],[1,14,2,11,4,12,3,7,6,13,10,5,15,9,0,8]],C=[[11,10,5,14,6,13,9,0,12,8,15,3,2,4,7,1],[4,12,7,5,1,6,9,10,0,14,13,8,2,11,3,15]],D=[[13,7,15,4,1,2,6,14,9,11,3,0,8,5,12,10],[11,9,5,1,12,3,13,14,6,4,7,15,2,0,8,10]],E=[0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15],F=[0,9,2,11,4,13,6,15,8,1,10,3,12,5,14,7],G=[[],[]],H=[[],[],[],[]];for(o=o.slice(0,32),j=o.length;16!==j&&24!==j&&32!==j;)o[j++]=0;for(j=0;j>2]=e(o,j);for(j=0;256>j;j++)G[0][j]=h(0,j),G[1][j]=h(1,j);for(j=0;256>j;j++)r=G[1][j],u=b(r),v=c(r),H[0][j]=r+(u<<8)+(v<<16)+(v<<24),H[2][j]=u+(v<<8)+(r<<16)+(v<<24),r=G[0][j],u=b(r),v=c(r),H[1][j]=v+(v<<8)+(u<<16)+(r<<24),H[3][j]=u+(r<<8)+(v<<16)+(u<<24);for(q=y.length/2,j=0;q>j;j++)l=y[j+j],w[j]=l,m=y[j+j+1],x[j]=m,z[q-j-1]=f(l,m);for(j=0;40>j;j+=2)l=16843009*j,m=l+16843009,l=i(l,w),m=d(i(m,x),8),s[j]=l+m&k,s[j+1]=d(l+2*m,9);for(j=0;256>j;j++)switch(l=m=n=p=j,q){case 4:l=G[1][l]^g(z[3],0),m=G[0][m]^g(z[3],1),n=G[0][n]^g(z[3],2),p=G[1][p]^g(z[3],3);case 3:l=G[1][l]^g(z[2],0),m=G[1][m]^g(z[2],1),n=G[0][n]^g(z[2],2),p=G[0][p]^g(z[2],3);case 2:t[0][j]=H[0][G[0][G[0][l]^g(z[1],0)]^g(z[0],0)],t[1][j]=H[1][G[0][G[1][m]^g(z[1],1)]^g(z[0],1)],t[2][j]=H[2][G[1][G[0][n]^g(z[1],2)]^g(z[0],2)],t[3][j]=H[3][G[1][G[1][p]^g(z[1],3)]^g(z[0],3)]}}function b(a){return t[0][g(a,0)]^t[1][g(a,1)]^t[2][g(a,2)]^t[3][g(a,3)]}function c(a){return t[0][g(a,3)]^t[1][g(a,0)]^t[2][g(a,1)]^t[3][g(a,2)]}function h(a,e){var f=b(e[0]),g=c(e[1]);e[2]=d(e[2]^f+g+s[4*a+8]&k,31),e[3]=d(e[3],1)^f+2*g+s[4*a+9]&k,f=b(e[2]),g=c(e[3]),e[0]=d(e[0]^f+g+s[4*a+10]&k,31),e[1]=d(e[1],1)^f+2*g+s[4*a+11]&k}function i(a,e){var f=b(e[0]),g=c(e[1]);e[2]=d(e[2],1)^f+g+s[4*a+10]&k,e[3]=d(e[3]^f+2*g+s[4*a+11]&k,31),f=b(e[2]),g=c(e[3]),e[0]=d(e[0],1)^f+g+s[4*a+8]&k,e[1]=d(e[1]^f+2*g+s[4*a+9]&k,31)}function j(){s=[],t=[[],[],[],[]]}function l(a,b){p=a,q=b;for(var c=[e(p,q)^s[0],e(p,q+4)^s[1],e(p,q+8)^s[2],e(p,q+12)^s[3]],d=0;8>d;d++)h(d,c);return f(p,q,c[2]^s[4]),f(p,q+4,c[3]^s[5]),f(p,q+8,c[0]^s[6]),f(p,q+12,c[1]^s[7]),q+=16,p}function m(a,b){p=a,q=b;for(var c=[e(p,q)^s[4],e(p,q+4)^s[5],e(p,q+8)^s[6],e(p,q+12)^s[7]],d=7;d>=0;d--)i(d,c);f(p,q,c[2]^s[0]),f(p,q+4,c[3]^s[1]),f(p,q+8,c[0]^s[2]),f(p,q+12,c[1]^s[3]),q+=16}function n(){return p}var o=null,p=null,q=-1,r=null;r="twofish";var s=[],t=[[],[],[],[]];return{name:"twofish",blocksize:16,open:a,close:j,encrypt:l,decrypt:m,finalize:n}}function i(a){this.tf=h(),this.tf.open(j(a),0),this.encrypt=function(a){return this.tf.encrypt(j(a),0)}}function j(a){for(var b=[],c=0;c>>32-e,c)}function g(a,b,c,d,e,g,h){return f(b&c|~b&d,a,b,e,g,h)}function h(a,b,c,d,e,g,h){return f(b&d|c&~d,a,b,e,g,h)}function i(a,b,c,d,e,g,h){return f(b^c^d,a,b,e,g,h)}function j(a,b,c,d,e,g,h){return f(c^(b|~d),a,b,e,g,h)}function k(a){var b,c=a.length,d=[1732584193,-271733879,-1732584194,271733878];for(b=64;b<=a.length;b+=64)e(d,l(a.substring(b-64,b)));a=a.substring(b-64);var f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(b=0;b>2]|=a.charCodeAt(b)<<(b%4<<3);if(f[b>>2]|=128<<(b%4<<3),b>55)for(e(d,f),b=0;16>b;b++)f[b]=0;return f[14]=8*c,e(d,f),d}function l(a){var b,c=[];for(b=0;64>b;b+=4)c[b>>2]=a.charCodeAt(b)+(a.charCodeAt(b+1)<<8)+(a.charCodeAt(b+2)<<16)+(a.charCodeAt(b+3)<<24);return c}function m(a){for(var b="",c=0;4>c;c++)b+=s[a>>8*c+4&15]+s[a>>8*c&15];return b}function n(a){for(var b=0;b>>32-b)}function f(a,b,c){return new Number(a^b^c)}function g(a,b,c){return new Number(a&b|~a&c)}function h(a,b,c){return new Number((a|~b)^c)}function i(a,b,c){return new Number(a&c|b&~c)}function j(a,b,c){return new Number(a^(b|~c))}function k(a,b,c,d,k,l,m,n){switch(n){case 0:a+=f(b,c,d)+l+0;break;case 1:a+=g(b,c,d)+l+1518500249;break;case 2:a+=h(b,c,d)+l+1859775393;break;case 3:a+=i(b,c,d)+l+2400959708;break;case 4:a+=j(b,c,d)+l+2840853838;break;case 5:a+=j(b,c,d)+l+1352829926;break;case 6:a+=i(b,c,d)+l+1548603684;break;case 7:a+=h(b,c,d)+l+1836072691;break;case 8:a+=g(b,c,d)+l+2053994217;break;case 9:a+=f(b,c,d)+l+0;break;default:throw new Error("Bogus round number")}a=e(a,m)+k,c=e(c,10),a&=4294967295,b&=4294967295,c&=4294967295,d&=4294967295,k&=4294967295;var o=[];return o[0]=a,o[1]=b,o[2]=c,o[3]=d,o[4]=k,o[5]=l,o[6]=m,o}function l(a){a[0]=1732584193,a[1]=4023233417,a[2]=2562383102,a[3]=271733878,a[4]=3285377520}function m(a,b){var c,d,e,f=[],g=[];for(d=0;5>d;d++)f[d]=new Number(a[d]),g[d]=new Number(a[d]);var h=0;for(e=0;5>e;e++)for(d=0;16>d;d++)c=k(f[(h+0)%5],f[(h+1)%5],f[(h+2)%5],f[(h+3)%5],f[(h+4)%5],b[w[e][d]],v[e][d],e),f[(h+0)%5]=c[0],f[(h+1)%5]=c[1],f[(h+2)%5]=c[2],f[(h+3)%5]=c[3],f[(h+4)%5]=c[4],h+=4;for(h=0,e=5;10>e;e++)for(d=0;16>d;d++)c=k(g[(h+0)%5],g[(h+1)%5],g[(h+2)%5],g[(h+3)%5],g[(h+4)%5],b[w[e][d]],v[e][d],e),g[(h+0)%5]=c[0],g[(h+1)%5]=c[1],g[(h+2)%5]=c[2],g[(h+3)%5]=c[3],g[(h+4)%5]=c[4],h+=4;g[3]+=f[2]+a[1],a[1]=a[2]+f[3]+g[4],a[2]=a[3]+f[4]+g[0],a[3]=a[4]+f[0]+g[1],a[4]=a[0]+f[1]+g[2],a[0]=g[3]}function n(a){for(var b=0;16>b;b++)a[b]=0}function o(a,b,c,d){var e=new Array(16);n(e);for(var f=0,g=0;(63&c)>g;g++)e[g>>>2]^=(255&b.charCodeAt(f++))<<8*(3&g);e[c>>>2&15]^=1<<8*(3&c)+7,(63&c)>55&&(m(a,e),e=new Array(16),n(e)),e[14]=c<<3,e[15]=c>>>29|d<<3,m(a,e)}function p(a){var b=(255&a.charCodeAt(3))<<24;return b|=(255&a.charCodeAt(2))<<16,b|=(255&a.charCodeAt(1))<<8,b|=255&a.charCodeAt(0)}function q(a){var b,c,d=new Array(u/32),e=new Array(u/8);l(d),b=a.length;var f=new Array(16);n(f);var g,h=0;for(c=b;c>63;c-=64){for(g=0;16>g;g++)f[g]=p(a.substr(h,4)),h+=4;m(d,f)}for(o(d,a.substr(h),b,0),g=0;u/8>g;g+=4)e[g]=255&d[g>>>2],e[g+1]=d[g>>>2]>>>8&255,e[g+2]=d[g>>>2]>>>16&255,e[g+3]=d[g>>>2]>>>24&255;return e}function r(a){for(var b=q(t["default"].Uint8Array2str(a)),c="",d=0;u/8>d;d++)c+=String.fromCharCode(b[d]);return t["default"].str2Uint8Array(c)}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=r;var s=a("../../util.js"),t=d(s),u=160,v=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12],[11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5],[11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12],[9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6],[9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11],[9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5],[15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8],[8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]],w=[[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],[7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8],[3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12],[1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2],[4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12],[6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2],[15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13],[8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14],[12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]]},{"../../util.js":76}],31:[function(a,b,c){"use strict";function d(a,b){this.highOrder=a,this.lowOrder=b}function e(a,b){var c,d,e,f,g=[],h=[],i=0;if("UTF8"===b)for(d=0;dc?h.push(c):2048>c?(h.push(192|c>>>6),h.push(128|63&c)):55296>c||c>=57344?h.push(224|c>>>12,128|c>>>6&63,128|63&c):(d+=1,c=65536+((1023&c)<<10|1023&a.charCodeAt(d)),h.push(240|c>>>18,128|c>>>12&63,128|c>>>6&63,128|63&c)),e=0;e>>2;g.length<=f;)g.push(0);g[f]|=h[e]<<24-8*(i%4),i+=1}else if("UTF16BE"===b||"UTF16LE"===b)for(d=0;d>8),f=i>>>2;g.length<=f;)g.push(0);g[f]|=c<<16-8*(i%4),i+=2}return{value:g,binLen:8*i}}function f(a){var b,c,d,e=[],f=a.length;if(0!==f%2)throw"String of HEX type must be in byte increments";for(b=0;f>b;b+=2){if(c=parseInt(a.substr(b,2),16),isNaN(c))throw"String of HEX type contains invalid characters";for(d=b>>>3;e.length<=d;)e.push(0);e[b>>>3]|=c<<24-4*(b%8)}return{value:e,binLen:4*f}}function g(a){var b,c,d,e=[];for(c=0;c>>2,e.length<=d&&e.push(0),e[d]|=b<<24-8*(c%4);return{value:e,binLen:8*a.length}}function h(a){var b,c,d,e=[];for(c=0;c>>2,e.length<=d&&e.push(0),e[d]|=b<<24-8*(c%4);return{value:e,binLen:8*a.length}}function i(a){var b,c,d,e,f,g,h,i=[],j=0,k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";if(-1===a.search(/^[a-zA-Z0-9=+\/]+$/))throw"Invalid character in base-64 string";if(g=a.indexOf("="),a=a.replace(/\=/g,""),-1!==g&&ge;e++)d=a[e],0===i?(g.push(f.charAt(d>>2&63)),c=(3&d)<<4):1===i?(g.push(f.charAt(c|d>>4&15)),c=(15&d)<<2):2===i&&(g.push(f.charAt(c|d>>6&3)),h+=1,h%60===0&&g.push("\n"),g.push(f.charAt(63&d))),h+=1,h%60===0&&g.push("\n"),i+=1,3===i&&(i=0);return i>0&&(g.push(f.charAt(c)),h+=1,h%60===0&&g.push("\n"),g.push("="),h+=1),1===i&&(h%60===0&&g.push("\n"),g.push("=")),b?void 0:g.join("")}function e(a){var b,c,d=[],e=0,g=0,h=a.length;for(c=0;h>c;c++)b=f.indexOf(a.charAt(c)),b>=0&&(e&&d.push(g|b>>6-e&255),e=e+2&7,g=b<>c,d.count++}):v["default"].encryption_cipher});var c={prio:0,algo:v["default"].encryption_cipher};for(var d in b)try{d!==r["default"].symmetric.plaintext&&d!==r["default"].symmetric.idea&&r["default"].read(r["default"].symmetric,d)&&b[d].count===a.length&&b[d].prio>c.prio&&(c=b[d])}catch(e){}return c.algo}Object.defineProperty(c,"__esModule",{value:!0}),c.Key=e,c.readArmored=l,c.generate=m,c.getPreferredSymAlgo=n;var o=a("./packet"),p=d(o),q=a("./enums.js"),r=d(q),s=a("./encoding/armor.js"),t=d(s),u=a("./config"),v=d(u),w=a("./util"),x=d(w);e.prototype.packetlist2structure=function(a){for(var b,c,d,e=0;ethis.primaryKey.created.getTime()+24*this.primaryKey.expirationTimeV3*3600*1e3)return r["default"].keyStatus.expired;for(var a=!1,b=0;bthis.primaryKey.created.getTime()+1e3*c.selfCertificate.keyExpirationTime?r["default"].keyStatus.expired:r["default"].keyStatus.valid:r["default"].keyStatus.invalid},e.prototype.getExpirationTime=function(){if(3===this.primaryKey.version)return h(this.primaryKey);if(4===this.primaryKey.version){var a=this.getPrimaryUser();return a?h(this.primaryKey,a.selfCertificate):null}},e.prototype.getPrimaryUser=function(){for(var a=[],b=0;bb.selfCertificate.isPrimaryUserID?-1:a.selfCertificate.isPrimaryUserIDb.selfCertificate.created?-1:a.selfCertificate.createdb?-1:b>a?1:0}),c=0;cthis.subKey.created.getTime()+24*this.subKey.expirationTimeV3*3600*1e3?r["default"].keyStatus.expired:this.bindingSignature?this.bindingSignature.isExpired()?r["default"].keyStatus.expired:this.bindingSignature.verified||this.bindingSignature.verify(a,{key:a,bind:this.subKey})?4===this.subKey.version&&this.bindingSignature.keyNeverExpires===!1&&Date.now()>this.subKey.created.getTime()+1e3*this.bindingSignature.keyExpirationTime?r["default"].keyStatus.expired:r["default"].keyStatus.valid:r["default"].keyStatus.invalid:r["default"].keyStatus.invalid},k.prototype.getExpirationTime=function(){return h(this.subKey,this.bindingSignature)},k.prototype.update=function(a,b){if(a.verify(b)!==r["default"].keyStatus.invalid){if(this.subKey.getFingerprint()!==a.subKey.getFingerprint())throw new Error("SubKey update method: fingerprints of subkeys not equal");this.subKey.tag===r["default"].packet.publicSubkey&&a.subKey.tag===r["default"].packet.secretSubkey&&(this.subKey=a.subKey),!this.bindingSignature&&a.bindingSignature&&(a.bindingSignature.verified||a.bindingSignature.verify(b,{key:b,bind:this.subKey}))&&(this.bindingSignature=a.bindingSignature),this.revocationSignature||!a.revocationSignature||a.revocationSignature.isExpired()||!a.revocationSignature.verified&&!a.revocationSignature.verify(b,{key:b,bind:this.subKey})||(this.revocationSignature=a.revocationSignature)}}},{"./config":19,"./encoding/armor.js":41,"./enums.js":43,"./packet":55,"./util":76}],47:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(c,"__esModule",{value:!0});var e=a("./keyring.js"),f=d(e),g=a("./localstore.js"),h=d(g);f["default"].localstore=h["default"],c["default"]=f["default"]},{"./keyring.js":48,"./localstore.js":49}],48:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b}function f(a){this.storeHandler=a||new m["default"],this.publicKeys=new g(this.storeHandler.loadPublic()),this.privateKeys=new g(this.storeHandler.loadPrivate())}function g(a){this.keys=a}function h(a,b){a=a.toLowerCase();for(var c=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),d=new RegExp("<"+c+">"),e=b.getUserIds(),f=0;ff;f++){c=d[f];try{c.decrypt(b);break}catch(g){if(f===e-1)throw g}}if(!c)throw new Error("No symmetrically encrypted session key packet found.")}else{if(!a)throw new Error("No key or password specified.");var h=this.getEncryptionKeyIds();if(!h.length)return;var i=a.getKeyPacket(h);if(!i.isDecrypted)throw new Error("Private key is not decrypted.");for(var j=this.packets.filterByTag(r["default"].packet.publicKeyEncryptedSessionKey),k=0;k=0;d--){var j=new p["default"].Signature;if(j.signatureType=h,j.hashAlgorithm=v["default"].prefer_hash_algorithm,j.publicKeyAlgorithm=e.algorithm,!e.isDecrypted)throw new Error("Private key is not decrypted.");j.sign(e,c),b.push(j)}return new f(b)},f.prototype.verify=function(a){var b=[],c=this.unwrapCompressed(),d=c.packets.filterByTag(r["default"].packet.literal);if(1!==d.length)throw new Error("Can only verify message with one literal data packet.");for(var e=c.packets.filterByTag(r["default"].packet.signature),f=0;f"}),a):a}function w(a){return a&&!K["default"].isArray(a)&&(a=[a]),a}function x(a,b){var c=void 0;if(K["default"].isUint8Array(a))c=C.fromBinary(a,b);else{if(!K["default"].isString(a))throw new Error("Data must be of type String or Uint8Array");c=C.fromText(a,b)}return c}function y(a,b){if("binary"===b)return{data:a.getLiteralData(),filename:a.getFilename()};if("utf8"===b)return{data:a.getText(),filename:a.getFilename()};throw new Error("Invalid format")}function z(a,b){var c=new Promise(function(b){return b(a())});return c["catch"](A.bind(null,b))}function A(a,b){throw I["default"].debug&&console.error(b.stack),new Error(a+": "+b.message)}Object.defineProperty(c,"__esModule",{value:!0}),c.initWorker=f,c.getWorker=g,c.destroyWorker=h,c.generateKey=i,c.decryptKey=j,c.encrypt=k,c.decrypt=l,c.sign=m,c.verify=n,c.encryptSessionKey=o,c.decryptSessionKey=p;var B=a("./message.js"),C=e(B),D=a("./cleartext.js"),E=e(D),F=a("./key.js"),G=e(F),H=a("./config/config.js"),I=d(H),J=a("./util"),K=d(J),L=a("./worker/async_proxy.js"),M=d(L),N=a("es6-promise"),O=d(N);O["default"].polyfill();var P=void 0},{"./cleartext.js":14,"./config/config.js":18,"./key.js":46,"./message.js":50,"./util":76,"./worker/async_proxy.js":77,"es6-promise":2}],52:[function(a,b,c){"use strict";function d(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b}function e(a){return a&&a.__esModule?a:{"default":a}}function f(a){return new(B[h(a)])}function g(a){var b=z["default"].read(z["default"].packet,a.tag),c=f(b);for(var d in a)a.hasOwnProperty(d)&&(c[d]=a[d]);return c.postCloneTypeFix&&c.postCloneTypeFix(),c}function h(a){return a.substr(0,1).toUpperCase()+a.substr(1)}Object.defineProperty(c,"__esModule",{value:!0}),c.Trust=c.Signature=c.SecretSubkey=c.Userid=c.SecretKey=c.OnePassSignature=c.UserAttribute=c.PublicSubkey=c.Marker=c.SymmetricallyEncrypted=c.PublicKey=c.Literal=c.SymEncryptedSessionKey=c.PublicKeyEncryptedSessionKey=c.SymEncryptedIntegrityProtected=c.Compressed=void 0;var i=a("./compressed.js");Object.defineProperty(c,"Compressed",{enumerable:!0,get:function(){return e(i)["default"]}});var j=a("./sym_encrypted_integrity_protected.js");Object.defineProperty(c,"SymEncryptedIntegrityProtected",{enumerable:!0,get:function(){return e(j)["default"]}});var k=a("./public_key_encrypted_session_key.js");Object.defineProperty(c,"PublicKeyEncryptedSessionKey",{enumerable:!0,get:function(){return e(k)["default"]}});var l=a("./sym_encrypted_session_key.js");Object.defineProperty(c,"SymEncryptedSessionKey",{enumerable:!0,get:function(){return e(l)["default"]}});var m=a("./literal.js");Object.defineProperty(c,"Literal",{enumerable:!0,get:function(){return e(m)["default"]}});var n=a("./public_key.js");Object.defineProperty(c,"PublicKey",{enumerable:!0,get:function(){return e(n)["default"]}});var o=a("./symmetrically_encrypted.js");Object.defineProperty(c,"SymmetricallyEncrypted",{enumerable:!0,get:function(){return e(o)["default"]}});var p=a("./marker.js");Object.defineProperty(c,"Marker",{enumerable:!0,get:function(){return e(p)["default"]}});var q=a("./public_subkey.js");Object.defineProperty(c,"PublicSubkey",{enumerable:!0,get:function(){return e(q)["default"]}});var r=a("./user_attribute.js");Object.defineProperty(c,"UserAttribute",{enumerable:!0,get:function(){return e(r)["default"]}});var s=a("./one_pass_signature.js");Object.defineProperty(c,"OnePassSignature",{enumerable:!0,get:function(){return e(s)["default"]}});var t=a("./secret_key.js");Object.defineProperty(c,"SecretKey",{enumerable:!0,get:function(){return e(t)["default"]}});var u=a("./userid.js");Object.defineProperty(c,"Userid",{enumerable:!0,get:function(){return e(u)["default"]}});var v=a("./secret_subkey.js");Object.defineProperty(c,"SecretSubkey",{enumerable:!0,get:function(){return e(v)["default"]}});var w=a("./signature.js");Object.defineProperty(c,"Signature",{enumerable:!0,get:function(){return e(w)["default"]}});var x=a("./trust.js");Object.defineProperty(c,"Trust",{enumerable:!0,get:function(){return e(x)["default"]}}),c.newPacketFromTag=f,c.fromStructuredClone=g;var y=a("../enums.js"),z=e(y),A=a("./all_packets.js"),B=d(A)},{"../enums.js":43,"./all_packets.js":52,"./compressed.js":54,"./literal.js":56,"./marker.js":57,"./one_pass_signature.js":58,"./public_key.js":61,"./public_key_encrypted_session_key.js":62,"./public_subkey.js":63,"./secret_key.js":64,"./secret_subkey.js":65,"./signature.js":66,"./sym_encrypted_integrity_protected.js":67,"./sym_encrypted_session_key.js":68,"./symmetrically_encrypted.js":69,"./trust.js":70,"./user_attribute.js":71,"./userid.js":72}],53:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b}function f(a){return a.publicKeys&&(a.publicKeys=a.publicKeys.map(function(a){return a.toPacketlist()})),a.privateKeys&&(a.privateKeys=a.privateKeys.map(function(a){return a.toPacketlist()})),a.privateKey&&(a.privateKey=a.privateKey.toPacketlist()),a.key&&(a.key=a.key.toPacketlist()),a}function g(a,b){return a.publicKeys&&(a.publicKeys=a.publicKeys.map(h)),a.privateKeys&&(a.privateKeys=a.privateKeys.map(h)),a.privateKey&&(a.privateKey=h(a.privateKey)),a.key&&(a.key=h(a.key)),!a.message||"sign"!==b&&"verify"!==b?a.message&&(a.message=i(a.message)):a.message=j(a.message),a.signatures&&(a.signatures=a.signatures.map(k)),a}function h(a){var b=s["default"].fromStructuredClone(a); +return new m.Key(b)}function i(a){var b=s["default"].fromStructuredClone(a.packets);return new o.Message(b)}function j(a){var b=s["default"].fromStructuredClone(a.packets);return new q.CleartextMessage(a.text,b)}function k(a){return a.keyid=u["default"].fromClone(a.keyid),a}Object.defineProperty(c,"__esModule",{value:!0}),c.clonePackets=f,c.parseClonedPackets=g;var l=a("../key.js"),m=e(l),n=a("../message.js"),o=e(n),p=a("../cleartext.js"),q=e(p),r=a("./packetlist.js"),s=d(r),t=a("../type/keyid.js"),u=d(t)},{"../cleartext.js":14,"../key.js":46,"../message.js":50,"../type/keyid.js":73,"./packetlist.js":60}],54:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(){this.tag=g["default"].packet.compressed,this.packets=null,this.algorithm="zip",this.compressed=null}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e;var f=a("../enums.js"),g=d(f),h=a("../util.js"),i=d(h),j=a("../compression/zlib.min.js"),k=d(j),l=a("../compression/rawinflate.min.js"),m=d(l),n=a("../compression/rawdeflate.min.js"),o=d(n);e.prototype.read=function(a){this.algorithm=g["default"].read(g["default"].compression,a[0]),this.compressed=a.subarray(1,a.length),this.decompress()},e.prototype.write=function(){return null===this.compressed&&this.compress(),i["default"].concatUint8Array(new Uint8Array([g["default"].write(g["default"].compression,this.algorithm)]),this.compressed)},e.prototype.decompress=function(){var a,b;switch(this.algorithm){case"uncompressed":a=this.compressed;break;case"zip":b=new m["default"].Zlib.RawInflate(this.compressed),a=b.decompress();break;case"zlib":b=new k["default"].Zlib.Inflate(this.compressed),a=b.decompress();break;case"bzip2":throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");default:throw new Error("Compression algorithm unknown :"+this.alogrithm)}this.packets.read(a)},e.prototype.compress=function(){var a,b;switch(a=this.packets.write(),this.algorithm){case"uncompressed":this.compressed=a;break;case"zip":b=new o["default"].Zlib.RawDeflate(a),this.compressed=b.compress();break;case"zlib":b=new k["default"].Zlib.Deflate(a),this.compressed=b.compress();break;case"bzip2":throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");default:throw new Error("Compression algorithm unknown :"+this.type)}}},{"../compression/rawdeflate.min.js":15,"../compression/rawinflate.min.js":16,"../compression/zlib.min.js":17,"../enums.js":43,"../util.js":76}],55:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b}Object.defineProperty(c,"__esModule",{value:!0});var f=a("./all_packets.js"),g=e(f),h=a("./clone.js"),i=e(h),j=a("./packetlist.js"),k=d(j),l={List:k["default"],clone:i};for(var m in g)l[m]=g[m];c["default"]=l},{"./all_packets.js":52,"./clone.js":53,"./packetlist.js":60}],56:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(){this.tag=i["default"].packet.literal,this.format="utf8",this.date=new Date,this.data=new Uint8Array(0),this.filename="msg.txt"}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e;var f=a("../util.js"),g=d(f),h=a("../enums.js"),i=d(h);e.prototype.setText=function(a){a=a.replace(/\r/g,"").replace(/\n/g,"\r\n"),this.data="utf8"===this.format?g["default"].str2Uint8Array(g["default"].encode_utf8(a)):g["default"].str2Uint8Array(a)},e.prototype.getText=function(){var a=g["default"].decode_utf8(g["default"].Uint8Array2str(this.data));return a.replace(/\r\n/g,"\n")},e.prototype.setBytes=function(a,b){this.format=b,this.data=a},e.prototype.getBytes=function(){return this.data},e.prototype.setFilename=function(a){this.filename=a},e.prototype.getFilename=function(){return this.filename},e.prototype.read=function(a){var b=i["default"].read(i["default"].literal,a[0]),c=a[1];this.filename=g["default"].decode_utf8(g["default"].Uint8Array2str(a.subarray(2,2+c))),this.date=g["default"].readDate(a.subarray(2+c,2+c+4));var d=a.subarray(6+c,a.length);this.setBytes(d,b)},e.prototype.write=function(){var a=g["default"].str2Uint8Array(g["default"].encode_utf8(this.filename)),b=new Uint8Array([a.length]),c=new Uint8Array([i["default"].write(i["default"].literal,this.format)]),d=g["default"].writeDate(this.date),e=this.getBytes();return g["default"].concatUint8Array([c,b,a,d,e])}},{"../enums.js":43,"../util.js":76}],57:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(){this.tag=g["default"].packet.marker}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e;var f=a("../enums.js"),g=d(f);e.prototype.read=function(a){return 80===a[0]&&71===a[1]&&80===a[2]?!0:!1}},{"../enums.js":43}],58:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(){this.tag=i["default"].packet.onePassSignature,this.version=null,this.type=null,this.hashAlgorithm=null,this.publicKeyAlgorithm=null,this.signingKeyId=null,this.flags=null}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e;var f=a("../util.js"),g=d(f),h=a("../enums.js"),i=d(h),j=a("../type/keyid.js"),k=d(j);e.prototype.read=function(a){var b=0;return this.version=a[b++],this.type=i["default"].read(i["default"].signature,a[b++]),this.hashAlgorithm=i["default"].read(i["default"].hash,a[b++]),this.publicKeyAlgorithm=i["default"].read(i["default"].publicKey,a[b++]),this.signingKeyId=new k["default"],this.signingKeyId.read(a.subarray(b,b+8)),b+=8,this.flags=a[b++],this},e.prototype.write=function(){var a=new Uint8Array([3,i["default"].write(i["default"].signature,this.type),i["default"].write(i["default"].hash,this.hashAlgorithm),i["default"].write(i["default"].publicKey,this.publicKeyAlgorithm)]),b=new Uint8Array([this.flags]);return g["default"].concatUint8Array([a,this.signingKeyId.write(),b])},e.prototype.postCloneTypeFix=function(){this.signingKeyId=k["default"].fromClone(this.signingKeyId)}},{"../enums.js":43,"../type/keyid.js":73,"../util.js":76}],59:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(c,"__esModule",{value:!0});var e=a("../util.js"),f=d(e);c["default"]={readSimpleLength:function(a){var b,c=0,d=a[0];return 192>d?(c=a[0],b=1):255>d?(c=(a[0]-192<<8)+a[1]+192,b=2):255===d&&(c=f["default"].readNumber(a.subarray(1,5)),b=5),{len:c,offset:b}},writeSimpleLength:function(a){return 192>a?new Uint8Array([a]):a>191&&8384>a?new Uint8Array([(a-192>>8)+192,a-192&255]):f["default"].concatUint8Array([new Uint8Array([255]),f["default"].writeNumber(a,4)])},writeHeader:function(a,b){return f["default"].concatUint8Array([new Uint8Array([192|a]),this.writeSimpleLength(b)])},writeOldHeader:function(a,b){return 256>b?new Uint8Array([128|a<<2,b]):65536>b?f["default"].concatUint8Array([128|a<<2|1,f["default"].writeNumber(b,2)]):f["default"].concatUint8Array([128|a<<2|2,f["default"].writeNumber(b,4)])},read:function(a,b,c){if(null===a||a.length<=b||a.subarray(b,a.length).length<2||0===(128&a[b]))throw new Error("Error during parsing. This message / key probably does not conform to a valid OpenPGP format.");var d,e=b,g=-1,h=-1;h=0,0!==(64&a[e])&&(h=1);var i;h?g=63&a[e]:(g=(63&a[e])>>2,i=3&a[e]),e++;var j=null,k=-1;if(h)if(a[e]<192)d=a[e++],f["default"].print_debug("1 byte length:"+d);else if(a[e]>=192&&a[e]<224)d=(a[e++]-192<<8)+a[e++]+192,f["default"].print_debug("2 byte length:"+d);else if(a[e]>223&&a[e]<255){d=1<<(31&a[e++]),f["default"].print_debug("4 byte length:"+d);var l=e+d;j=[a.subarray(e,e+d)];for(var m;;){if(a[l]<192){m=a[l++],d+=m,j.push(a.subarray(l,l+m)),l+=m;break}if(a[l]>=192&&a[l]<224){m=(a[l++]-192<<8)+a[l++]+192,d+=m,j.push(a.subarray(l,l+m)),l+=m;break}if(!(a[l]>223&&a[l]<255)){l++,m=a[l++]<<24|a[l++]<<16|a[l++]<<8|a[l++],j.push(a.subarray(l,l+m)),d+=m,l+=m;break}m=1<<(31&a[l++]),d+=m,j.push(a.subarray(l,l+m)),l+=m}k=l-e}else e++,d=a[e++]<<24|a[e++]<<16|a[e++]<<8|a[e++];else switch(i){case 0:d=a[e++];break;case 1:d=a[e++]<<8|a[e++];break;case 2:d=a[e++]<<24|a[e++]<<16|a[e++]<<8|a[e++];break;default:d=c}return-1===k&&(k=d),null===j?j=a.subarray(e,e+k):j instanceof Array&&(j=f["default"].concatUint8Array(j)),{tag:g,packet:j,offset:e+k}}}},{"../util.js":76}],60:[function(a,b,c){"use strict";function d(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b}function e(a){return a&&a.__esModule?a:{"default":a}}function f(){this.length=0}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=f;var g=a("../util"),h=e(g),i=a("./packet.js"),j=e(i),k=a("./all_packets.js"),l=d(k),m=a("../enums.js"),n=e(m);f.prototype.read=function(a){for(var b=0;bd;d++)c.push(this[d]);return c},f.prototype.concat=function(a){if(a)for(var b=0;bf&&ed.length)throw new Error("Error reading MPI @:"+e);return e+6}throw new Error("Version "+this.version+" of the key packet is unsupported.")},e.prototype.readPublicKey=e.prototype.read,e.prototype.write=function(){var a=[];a.push(new Uint8Array([this.version])),a.push(g["default"].writeDate(this.created)),3===this.version&&a.push(g["default"].writeNumber(this.expirationTimeV3,2)),a.push(new Uint8Array([m["default"].write(m["default"].publicKey,this.algorithm)]));for(var b=o["default"].getPublicMpiCount(this.algorithm),c=0;b>c;c++)a.push(this.mpi[c].write());return g["default"].concatUint8Array(a)},e.prototype.writePublicKey=e.prototype.write,e.prototype.writeOld=function(){var a=this.writePublicKey();return g["default"].concatUint8Array([new Uint8Array([153]),g["default"].writeNumber(a.length,2),a])},e.prototype.getKeyId=function(){if(this.keyid)return this.keyid;if(this.keyid=new k["default"],4===this.version)this.keyid.read(g["default"].str2Uint8Array(g["default"].hex2bin(this.getFingerprint()).substr(12,8)));else if(3===this.version){var a=this.mpi[0].write();this.keyid.read(a.subarray(a.length-8,a.length))}return this.keyid},e.prototype.getFingerprint=function(){if(this.fingerprint)return this.fingerprint;var a="";if(4===this.version)a=this.writeOld(),this.fingerprint=g["default"].Uint8Array2str(o["default"].hash.sha1(a));else if(3===this.version){for(var b=o["default"].getPublicMpiCount(this.algorithm),c=0;b>c;c++)a+=this.mpi[c].toBytes();this.fingerprint=g["default"].Uint8Array2str(o["default"].hash.md5(g["default"].str2Uint8Array(a)))}return this.fingerprint=g["default"].hexstrdump(this.fingerprint),this.fingerprint},e.prototype.getBitSize=function(){return 8*this.mpi[0].byteLength()},e.prototype.postCloneTypeFix=function(){for(var a=0;ad;d++){var e=new k["default"];b+=e.read(a.subarray(b,a.length)),this.encrypted.push(e)}},e.prototype.write=function(){for(var a=[new Uint8Array([this.version]),this.publicKeyId.write(),new Uint8Array([m["default"].write(m["default"].publicKey,this.publicKeyAlgorithm)])],b=0;bm&&kc;){var d=j["default"].readSimpleLength(a.subarray(c,a.length));c+=d.offset,this.read_sub_packet(a.subarray(c,c+d.len)),c+=d.len}return c};b+=d.call(this,a.subarray(b,a.length),!0),this.signatureData=a.subarray(0,b);var e=b;b+=d.call(this,a.subarray(b,a.length),!1),this.unhashedSubpackets=a.subarray(e,b);break;default:throw new Error("Version "+this.version+" of the signature is unsupported.")}this.signedHashValue=a.subarray(b,b+2),b+=2,this.signature=a.subarray(b,a.length)},e.prototype.write=function(){var a=[];switch(this.version){case 3:a.push(new Uint8Array([3,5])),a.push(this.signatureData),a.push(this.issuerKeyId.write()),a.push(new Uint8Array([this.publicKeyAlgorithm,this.hashAlgorithm]));break;case 4:a.push(this.signatureData),a.push(this.unhashedSubpackets?this.unhashedSubpackets:h["default"].writeNumber(0,2))}return a.push(this.signedHashValue),a.push(this.signature),h["default"].concatUint8Array(a)},e.prototype.sign=function(a,b){var c=l["default"].write(l["default"].signature,this.signatureType),d=l["default"].write(l["default"].publicKey,this.publicKeyAlgorithm),e=l["default"].write(l["default"].hash,this.hashAlgorithm),f=[new Uint8Array([4,c,d,e])];this.issuerKeyId=a.getKeyId(),f.push(this.write_all_sub_packets()),this.signatureData=h["default"].concatUint8Array(f);var g=this.calculateTrailer(),i=h["default"].concatUint8Array([this.toSign(c,b),this.signatureData,g]),j=n["default"].hash.digest(e,i);this.signedHashValue=j.subarray(0,2),this.signature=n["default"].signature.sign(e,d,a.mpi,i)},e.prototype.write_all_sub_packets=function(){var a,b=l["default"].signatureSubpacket,c=[];if(null!==this.created&&c.push(f(b.signature_creation_time,h["default"].writeDate(this.created))),null!==this.signatureExpirationTime&&c.push(f(b.signature_expiration_time,h["default"].writeNumber(this.signatureExpirationTime,4))),null!==this.exportable&&c.push(f(b.exportable_certification,new Uint8Array([this.exportable?1:0]))),null!==this.trustLevel&&(a=new Uint8Array([this.trustLevel,this.trustAmount]),c.push(f(b.trust_signature,a))),null!==this.regularExpression&&c.push(f(b.regular_expression,this.regularExpression)),null!==this.revocable&&c.push(f(b.revocable,new Uint8Array([this.revocable?1:0]))),null!==this.keyExpirationTime&&c.push(f(b.key_expiration_time,h["default"].writeNumber(this.keyExpirationTime,4))),null!==this.preferredSymmetricAlgorithms&&(a=h["default"].str2Uint8Array(h["default"].bin2str(this.preferredSymmetricAlgorithms)),c.push(f(b.preferred_symmetric_algorithms,a))),null!==this.revocationKeyClass&&(a=new Uint8Array([this.revocationKeyClass,this.revocationKeyAlgorithm]),a=h["default"].concatUint8Array([a,this.revocationKeyFingerprint]),c.push(f(b.revocation_key,a))),this.issuerKeyId.isNull()||c.push(f(b.issuer,this.issuerKeyId.write())),null!==this.notation)for(var d in this.notation)if(this.notation.hasOwnProperty(d)){var e=this.notation[d];a=[new Uint8Array([128,0,0,0])],a.push(h["default"].writeNumber(d.length,2)),a.push(h["default"].writeNumber(e.length,2)),a.push(h["default"].str2Uint8Array(d+e)),a=h["default"].concatUint8Array(a),c.push(f(b.notation_data,a))}null!==this.preferredHashAlgorithms&&(a=h["default"].str2Uint8Array(h["default"].bin2str(this.preferredHashAlgorithms)),c.push(f(b.preferred_hash_algorithms,a))),null!==this.preferredCompressionAlgorithms&&(a=h["default"].str2Uint8Array(h["default"].bin2str(this.preferredCompressionAlgorithms)),c.push(f(b.preferred_compression_algorithms,a))),null!==this.keyServerPreferences&&(a=h["default"].str2Uint8Array(h["default"].bin2str(this.keyServerPreferences)),c.push(f(b.key_server_preferences,a))),null!==this.preferredKeyServer&&c.push(f(b.preferred_key_server,h["default"].str2Uint8Array(this.preferredKeyServer))),null!==this.isPrimaryUserID&&c.push(f(b.primary_user_id,new Uint8Array([this.isPrimaryUserID?1:0]))),null!==this.policyURI&&c.push(f(b.policy_uri,h["default"].str2Uint8Array(this.policyURI))),null!==this.keyFlags&&(a=h["default"].str2Uint8Array(h["default"].bin2str(this.keyFlags)),c.push(f(b.key_flags,a))),null!==this.signersUserId&&c.push(f(b.signers_user_id,h["default"].str2Uint8Array(this.signersUserId))),null!==this.reasonForRevocationFlag&&(a=h["default"].str2Uint8Array(String.fromCharCode(this.reasonForRevocationFlag)+this.reasonForRevocationString),c.push(f(b.reason_for_revocation,a))),null!==this.features&&(a=h["default"].str2Uint8Array(h["default"].bin2str(this.features)),c.push(f(b.features,a))),null!==this.signatureTargetPublicKeyAlgorithm&&(a=[new Uint8Array([this.signatureTargetPublicKeyAlgorithm,this.signatureTargetHashAlgorithm])],a.push(h["default"].str2Uint8Array(this.signatureTargetHash)),a=h["default"].concatUint8Array(a),c.push(f(b.signature_target,a))),null!==this.embeddedSignature&&c.push(f(b.embedded_signature,this.embeddedSignature.write()));var g=h["default"].concatUint8Array(c),i=h["default"].writeNumber(g.length,2);return h["default"].concatUint8Array([i,g])},e.prototype.read_sub_packet=function(a){function b(a,b){this[a]=[];for(var c=0;c0&&4>d?i=1:17===d&&(i=2);for(var j=[],k=0,m=0;i>m;m++)j[m]=new p["default"],k+=j[m].read(this.signature.subarray(k,this.signature.length));return this.verified=n["default"].signature.verify(d,e,j,a.mpi,h["default"].concatUint8Array([f,this.signatureData,g])),this.verified},e.prototype.isExpired=function(){return this.signatureNeverExpires?!1:Date.now()>this.created.getTime()+1e3*this.signatureExpirationTime},e.prototype.postCloneTypeFix=function(){this.issuerKeyId=r["default"].fromClone(this.issuerKeyId); +}},{"../crypto":32,"../enums.js":43,"../type/keyid.js":73,"../type/mpi.js":74,"../util.js":76,"./packet.js":59}],67:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(){this.tag=k["default"].packet.symEncryptedIntegrityProtected,this.encrypted=null,this.modification=!1,this.packets=null}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e;var f=a("../util.js"),g=d(f),h=a("../crypto"),i=d(h),j=a("../enums.js"),k=d(j),l=a("asmcrypto-lite"),m=d(l),n=g["default"].getNodeCrypto(),o=g["default"].getNodeBuffer();e.prototype.read=function(a){var b=a[0];if(1!==b)throw new Error("Invalid packet version.");this.encrypted=a.subarray(1,a.length)},e.prototype.write=function(){return g["default"].concatUint8Array([new Uint8Array([1]),this.encrypted])},e.prototype.encrypt=function(a,b){var c=this.packets.write(),d=i["default"].getPrefixRandom(a),e=new Uint8Array([d[d.length-2],d[d.length-1]]),f=g["default"].concatUint8Array([d,e]),h=new Uint8Array([211,20]),j=g["default"].concatUint8Array([c,h]),k=i["default"].hash.sha1(g["default"].concatUint8Array([f,j]));if(j=g["default"].concatUint8Array([j,k]),"aes"===a.substr(0,3)){var l=i["default"].cipher[a].blockSize;if(n){var p=new n.createCipheriv("aes-"+a.substr(3,3)+"-cfb",new o(b),new o(new Uint8Array(l)));this.encrypted=new Uint8Array(p.update(new o(g["default"].concatUint8Array([f,j]))))}else this.encrypted=m["default"].AES_CFB.encrypt(g["default"].concatUint8Array([f,j]),b)}else this.encrypted=i["default"].cfb.encrypt(d,a,j,b,!1).subarray(0,f.length+j.length)},e.prototype.decrypt=function(a,b){var c;if("aes"===a.substr(0,3)){var d=i["default"].cipher[a].blockSize;if(n){var e=new n.createDecipheriv("aes-"+a.substr(3,3)+"-cfb",new o(b),new o(new Uint8Array(d)));c=new Uint8Array(e.update(new o(this.encrypted)))}else c=m["default"].AES_CFB.decrypt(this.encrypted,b);c=c.subarray(d+2,c.length)}else c=i["default"].cfb.decrypt(a,b,this.encrypted,!1);this.hash=g["default"].Uint8Array2str(i["default"].hash.sha1(g["default"].concatUint8Array([i["default"].cfb.mdc(a,b,this.encrypted),c.subarray(0,c.length-20)])));var f=g["default"].Uint8Array2str(c.subarray(c.length-20,c.length));if(this.hash!==f)throw new Error("Modification detected.");this.packets.read(c.subarray(0,c.length-22))}},{"../crypto":32,"../enums.js":43,"../util.js":76,"asmcrypto-lite":1}],68:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(){this.tag=k["default"].packet.symEncryptedSessionKey,this.version=4,this.sessionKey=null,this.sessionKeyEncryptionAlgorithm=null,this.sessionKeyAlgorithm="aes256",this.encrypted=null,this.s2k=new i["default"]}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e;var f=a("../util.js"),g=d(f),h=a("../type/s2k.js"),i=d(h),j=a("../enums.js"),k=d(j),l=a("../crypto"),m=d(l);e.prototype.read=function(a){this.version=a[0];var b=k["default"].read(k["default"].symmetric,a[1]),c=this.s2k.read(a.subarray(2,a.length)),d=c+2;d>4)+a},e.prototype.read=function(a){var b=0;switch(this.type=g["default"].read(g["default"].s2k,a[b++]),this.algorithm=g["default"].read(g["default"].hash,a[b++]),this.type){case"simple":break;case"salted":this.salt=a.subarray(b,b+8),b+=8;break;case"iterated":this.salt=a.subarray(b,b+8),b+=8,this.c=a[b++];break;case"gnu":if("GNU"!==i["default"].Uint8Array2str(a.subarray(b,3)))throw new Error("Unknown s2k type.");b+=3;var c=1e3+a[b++];if(1001!==c)throw new Error("Unknown s2k gnu protection mode.");this.type=c;break;default:throw new Error("Unknown s2k type.")}return b},e.prototype.write=function(){var a=[new Uint8Array([g["default"].write(g["default"].s2k,this.type),g["default"].write(g["default"].hash,this.algorithm)])];switch(this.type){case"simple":break;case"salted":a.push(this.salt);break;case"iterated":a.push(this.salt),a.push(new Uint8Array([this.c]));break;case"gnu":throw new Error("GNU s2k type not supported.");default:throw new Error("Unknown s2k type.")}return i["default"].concatUint8Array(a)},e.prototype.produce_key=function(a,b){function c(b,c){var d=g["default"].write(g["default"].hash,c.algorithm);switch(c.type){case"simple":return k["default"].hash.digest(d,i["default"].concatUint8Array([b,a]));case"salted":return k["default"].hash.digest(d,i["default"].concatUint8Array([b,c.salt,a]));case"iterated":for(var e=[],f=c.get_count(),h=i["default"].concatUint8Array([c.salt,a]);e.length*h.lengthf&&(e=e.subarray(0,f)),k["default"].hash.digest(d,i["default"].concatUint8Array([b,e]));case"gnu":throw new Error("GNU s2k type not supported.");default:throw new Error("Unknown s2k type.")}}a=i["default"].str2Uint8Array(i["default"].encode_utf8(a));for(var d=[],e=0,f=new Uint8Array(b),h=0;b>h;h++)f[h]=0;for(h=0;b>=e;){var j=c(f.subarray(0,h),this);d.push(j),e+=j.length,h++}return i["default"].concatUint8Array(d).subarray(0,b)},e.fromClone=function(a){var b=new e;return b.algorithm=a.algorithm,b.type=a.type,b.c=a.c,b.salt=a.salt,b}},{"../crypto":32,"../enums.js":43,"../util.js":76}],76:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}Object.defineProperty(c,"__esModule",{value:!0});var e=a("./config"),f=d(e);c["default"]={isString:function(a){return"string"==typeof a||String.prototype.isPrototypeOf(a)},isArray:function(a){return Array.prototype.isPrototypeOf(a)},isUint8Array:function(a){return Uint8Array.prototype.isPrototypeOf(a)},isEmailAddress:function(a){if(!this.isString(a))return!1;var b=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return b.test(a)},isUserId:function(a){return this.isString(a)?/ $/.test(a):!1},getTransferables:function(a){if(f["default"].zeroCopy&&Object.prototype.isPrototypeOf(a)){var b=[];return this.collectBuffers(a,b),b.length?b:void 0}},collectBuffers:function(a,b){if(a){if(this.isUint8Array(a)&&-1===b.indexOf(a.buffer))return void b.push(a.buffer);if(Object.prototype.isPrototypeOf(a))for(var c in a)this.collectBuffers(a[c],b)}},readNumber:function(a){for(var b=0,c=0;cd;d++)c[d]=a>>8*(b-d-1)&255;return c},readDate:function(a){var b=this.readNumber(a),c=new Date;return c.setTime(1e3*b),c},writeDate:function(a){var b=Math.round(a.getTime()/1e3);return this.writeNumber(b,4)},emailRegEx:/^[+a-zA-Z0-9_.-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,6}$/,hexdump:function(a){for(var b,c=[],d=a.length,e=0,f=0;d>e;){for(b=a.charCodeAt(e++).toString(16);b.length<2;)b="0"+b;c.push(" "+b),f++,f%32===0&&c.push("\n ")}return c.join("")},hexstrdump:function(a){if(null===a)return"";for(var b,c=[],d=a.length,e=0;d>e;){for(b=a.charCodeAt(e++).toString(16);b.length<2;)b="0"+b;c.push(""+b)}return c.join("")},hex2bin:function(a){for(var b="",c=0;ce;){for(b=a[e++].toString(16);b.length<2;)b="0"+b;c.push(""+b)}return c.join("")},encode_utf8:function(a){return unescape(encodeURIComponent(a))},decode_utf8:function(a){if("string"!=typeof a)throw new Error('Parameter "utf8" is not of type string');try{return decodeURIComponent(escape(a))}catch(b){return a}},bin2str:function(a){for(var b=[],c=0;c=0;d--)c[d]>>=b%8,d>0&&(c[d]|=c[d-1]<<8-b%8&255);return this.bin2str(c)},get_hashAlgorithmString:function(a){switch(a){case 1:return"MD5";case 2:return"SHA1";case 3:return"RIPEMD160";case 8:return"SHA256";case 9:return"SHA384";case 10:return"SHA512";case 11:return"SHA224"}return"unknown"},getWebCrypto:function(){if(f["default"].useNative&&"undefined"!=typeof window){if(window.crypto)return window.crypto.subtle||window.crypto.webkitSubtle;if(window.msCrypto)return window.msCrypto.subtle}},promisify:function(a){return function(){var b=arguments;return new Promise(function(c){var d=a.apply(null,b);c(d)})}},promisifyIE11Op:function(a,b){return new Promise(function(c,d){a.onerror=function(){d(new Error(b))},a.oncomplete=function(a){c(a.target.result)}})},detectNode:function(){return"undefined"==typeof window},getNodeCrypto:function(){return this.detectNode()&&f["default"].useNative?a("crypto"):void 0},getNodeBuffer:function(){return this.detectNode()?a("buffer").Buffer:void 0}}},{"./config":19,buffer:"buffer",crypto:"crypto"}],77:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{"default":a}}function e(){var a=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],b=a.path,c=void 0===b?"openpgp.worker.js":b,d=a.worker,e=a.config;this.worker=d||new Worker(c),this.worker.onmessage=this.onMessage.bind(this),this.worker.onerror=function(a){throw new Error("Unhandled error in openpgp worker: "+a.message+" ("+a.filename+":"+a.lineno+")")},this.seedRandom(l),this.tasks=[],e&&this.worker.postMessage({event:"configure",config:e})}Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=e;var f=a("../util.js"),g=d(f),h=a("../crypto"),i=d(h),j=a("../packet"),k=d(j),l=5e4,m=2e4;e.prototype.onMessage=function(a){var b=a.data;switch(b.event){case"method-return":b.err?this.tasks.shift().reject(new Error(b.err)):this.tasks.shift().resolve(b.data);break;case"request-seed":this.seedRandom(m);break;default:throw new Error("Unknown Worker Event.")}},e.prototype.seedRandom=function(a){var b=this.getRandomBuffer(a);this.worker.postMessage({event:"seed-random",buf:b},g["default"].getTransferables.call(g["default"],b))},e.prototype.getRandomBuffer=function(a){if(!a)return null;var b=new Uint8Array(a);return i["default"].random.getRandomValues(b),b},e.prototype.terminate=function(){this.worker.terminate()},e.prototype.delegate=function(a,b){var c=this;return new Promise(function(d,e){c.worker.postMessage({event:a,options:k["default"].clone.clonePackets(b)},g["default"].getTransferables.call(g["default"],b)),c.tasks.push({resolve:function(b){return d(k["default"].clone.parseClonedPackets(b,a))},reject:e})})}},{"../crypto":32,"../packet":55,"../util.js":76}]},{},[45])(45)}); \ No newline at end of file diff --git a/dist/openpgp.worker.js b/dist/openpgp.worker.js index a3ca1ae3..295c80eb 100644 --- a/dist/openpgp.worker.js +++ b/dist/openpgp.worker.js @@ -16,7 +16,9 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -window = {}; // to make UMD bundles work +/* globals self: true */ + +self.window = {}; // to make UMD bundles work // Mozilla bind polyfill because phantomjs is stupid if (!Function.prototype.bind) { @@ -41,152 +43,50 @@ if (!Function.prototype.bind) { } importScripts('openpgp.js'); +var openpgp = window.openpgp; var MIN_SIZE_RANDOM_BUFFER = 40000; var MAX_SIZE_RANDOM_BUFFER = 60000; -window.openpgp.crypto.random.randomBuffer.init(MAX_SIZE_RANDOM_BUFFER); +openpgp.crypto.random.randomBuffer.init(MAX_SIZE_RANDOM_BUFFER); self.onmessage = function (event) { - var data = null, - err = null, - msg = event.data, - correct = false; + var msg = event.data || {}, + options = msg.options || {}; switch (msg.event) { case 'configure': for (var i in msg.config) { - window.openpgp.config[i] = msg.config[i]; + openpgp.config[i] = msg.config[i]; } break; + case 'seed-random': if (!(msg.buf instanceof Uint8Array)) { msg.buf = new Uint8Array(msg.buf); } - window.openpgp.crypto.random.randomBuffer.set(msg.buf); - break; - case 'encrypt-message': - if (!msg.keys.length) { - msg.keys = [msg.keys]; - } - msg.keys = msg.keys.map(packetlistCloneToKey); - window.openpgp.encryptMessage(msg.keys, msg.text).then(function(data) { - response({event: 'method-return', data: data}); - }).catch(function(e) { - response({event: 'method-return', err: e.message}); - }); - break; - case 'sign-and-encrypt-message': - if (!msg.publicKeys.length) { - msg.publicKeys = [msg.publicKeys]; - } - msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey); - msg.privateKey = packetlistCloneToKey(msg.privateKey); - window.openpgp.signAndEncryptMessage(msg.publicKeys, msg.privateKey, msg.text).then(function(data) { - response({event: 'method-return', data: data}); - }).catch(function(e) { - response({event: 'method-return', err: e.message}); - }); - break; - case 'decrypt-message': - msg.privateKey = packetlistCloneToKey(msg.privateKey); - msg.message = packetlistCloneToMessage(msg.message.packets); - window.openpgp.decryptMessage(msg.privateKey, msg.message).then(function(data) { - response({event: 'method-return', data: data}); - }).catch(function(e) { - response({event: 'method-return', err: e.message}); - }); - break; - case 'decrypt-and-verify-message': - msg.privateKey = packetlistCloneToKey(msg.privateKey); - if (!msg.publicKeys.length) { - msg.publicKeys = [msg.publicKeys]; - } - msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey); - msg.message = packetlistCloneToMessage(msg.message.packets); - window.openpgp.decryptAndVerifyMessage(msg.privateKey, msg.publicKeys, msg.message).then(function(data) { - response({event: 'method-return', data: data}); - }).catch(function(e) { - response({event: 'method-return', err: e.message}); - }); - break; - case 'sign-clear-message': - msg.privateKeys = msg.privateKeys.map(packetlistCloneToKey); - window.openpgp.signClearMessage(msg.privateKeys, msg.text).then(function(data) { - response({event: 'method-return', data: data}); - }).catch(function(e) { - response({event: 'method-return', err: e.message}); - }); - break; - case 'verify-clear-signed-message': - if (!msg.publicKeys.length) { - msg.publicKeys = [msg.publicKeys]; - } - msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey); - var packetlist = window.openpgp.packet.List.fromStructuredClone(msg.message.packets); - msg.message = new window.openpgp.cleartext.CleartextMessage(msg.message.text, packetlist); - window.openpgp.verifyClearSignedMessage(msg.publicKeys, msg.message).then(function(data) { - response({event: 'method-return', data: data}); - }).catch(function(e) { - response({event: 'method-return', err: e.message}); - }); - break; - case 'generate-key-pair': - window.openpgp.generateKeyPair(msg.options).then(function(data) { - data.key = data.key.toPacketlist(); - response({event: 'method-return', data: data}); - }).catch(function(e) { - response({event: 'method-return', err: e.message}); - }); - break; - case 'decrypt-key': - try { - msg.privateKey = packetlistCloneToKey(msg.privateKey); - correct = msg.privateKey.decrypt(msg.password); - if (correct) { - data = msg.privateKey.toPacketlist(); - } else { - err = 'Wrong password'; - } - } catch (e) { - err = e.message; - } - response({event: 'method-return', data: data, err: err}); - break; - case 'decrypt-key-packet': - try { - msg.privateKey = packetlistCloneToKey(msg.privateKey); - msg.keyIds = msg.keyIds.map(window.openpgp.Keyid.fromClone); - correct = msg.privateKey.decryptKeyPacket(msg.keyIds, msg.password); - if (correct) { - data = msg.privateKey.toPacketlist(); - } else { - err = 'Wrong password'; - } - } catch (e) { - err = e.message; - } - response({event: 'method-return', data: data, err: err}); + openpgp.crypto.random.randomBuffer.set(msg.buf); break; + default: - throw new Error('Unknown Worker Event.'); + if (typeof openpgp[msg.event] !== 'function') { + throw new Error('Unknown Worker Event'); + } + + // parse cloned packets + openpgp[msg.event](openpgp.packet.clone.parseClonedPackets(options, msg.event)).then(function(data) { + // clone packets (for web worker structured cloning algorithm) + response({ event:'method-return', data:openpgp.packet.clone.clonePackets(data) }); + }).catch(function(e) { + response({ event:'method-return', err:e.message }); + }); } }; function response(event) { - if (window.openpgp.crypto.random.randomBuffer.size < MIN_SIZE_RANDOM_BUFFER) { - postMessage({event: 'request-seed'}); + if (openpgp.crypto.random.randomBuffer.size < MIN_SIZE_RANDOM_BUFFER) { + self.postMessage({event: 'request-seed'}); } - postMessage(event); -} - -function packetlistCloneToKey(packetlistClone) { - var packetlist = window.openpgp.packet.List.fromStructuredClone(packetlistClone); - return new window.openpgp.key.Key(packetlist); -} - -function packetlistCloneToMessage(packetlistClone) { - var packetlist = window.openpgp.packet.List.fromStructuredClone(packetlistClone); - return new window.openpgp.message.Message(packetlist); + self.postMessage(event, openpgp.util.getTransferables.call(openpgp.util, event.data)); } },{}]},{},[1]); diff --git a/dist/openpgp.worker.min.js b/dist/openpgp.worker.min.js index 6a1c3d3d..1744fe91 100644 --- a/dist/openpgp.worker.min.js +++ b/dist/openpgp.worker.min.js @@ -1 +1 @@ -/*! OpenPGPjs.org this is LGPL licensed code, see LICENSE/our website for more information.- v1.5.7 - 2016-01-31 */!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g