From c571a4fbe7ebb2ff05caa6bde7afa213d51c644a Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 18 May 2021 10:59:13 +0200 Subject: [PATCH] Cleanup OpenPGP.js and prepare for using Rollup --- vendors/openpgp-2.6.2/dist/openpgp.js | 1319 ++++++-- vendors/openpgp-2.6.2/rollup.config.js | 56 + vendors/openpgp-2.6.2/src/asmcrypto.js | 2898 +++++++++++++++++ .../src/compression/rawdeflate.min.js | 23 - .../src/compression/rawinflate.min.js | 14 - .../openpgp-2.6.2/src/compression/zlib.min.js | 1017 +++++- vendors/openpgp-2.6.2/src/config/config.js | 11 +- vendors/openpgp-2.6.2/src/crypto/gcm.js | 6 +- .../openpgp-2.6.2/src/crypto/hash/index.js | 4 +- .../src/crypto/public_key/dsa.js | 3 - .../src/crypto/public_key/elgamal.js | 4 - .../src/crypto/public_key/rsa.js | 9 +- vendors/openpgp-2.6.2/src/encoding/armor.js | 31 - vendors/openpgp-2.6.2/src/key.js | 3 - .../openpgp-2.6.2/src/keyring/localstore.js | 2 - vendors/openpgp-2.6.2/src/openpgp.js | 3 - .../openpgp-2.6.2/src/packet/compressed.js | 237 +- vendors/openpgp-2.6.2/src/packet/packet.js | 3 - vendors/openpgp-2.6.2/src/packet/signature.js | 11 - .../sym_encrypted_integrity_protected.js | 2 +- vendors/openpgp-2.6.2/src/rusha.js | 410 +++ vendors/openpgp-2.6.2/src/util.js | 38 +- 22 files changed, 5522 insertions(+), 582 deletions(-) create mode 100644 vendors/openpgp-2.6.2/rollup.config.js create mode 100644 vendors/openpgp-2.6.2/src/asmcrypto.js delete mode 100644 vendors/openpgp-2.6.2/src/compression/rawdeflate.min.js delete mode 100644 vendors/openpgp-2.6.2/src/compression/rawinflate.min.js create mode 100644 vendors/openpgp-2.6.2/src/rusha.js diff --git a/vendors/openpgp-2.6.2/dist/openpgp.js b/vendors/openpgp-2.6.2/dist/openpgp.js index f4c10c465..54c4f8c90 100644 --- a/vendors/openpgp-2.6.2/dist/openpgp.js +++ b/vendors/openpgp-2.6.2/dist/openpgp.js @@ -1,16 +1,42 @@ -(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{ + if (typeof exports === "object" && typeof module !== "undefined") { + module.exports = f() + } else { + (window||global||self||this).openpgp = f() + } +})(() => { + 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 < r.length; o++) s(r[o]); + return s + })({ +1:[function(_dereq_,module){ /*! asmCrypto Lite v1.1.0, (c) 2013 Artem S Vybornov, opensource.org/licenses/MIT */ (function ( exports, global ) { -function IllegalStateError () { var err = Error.apply( this, arguments ); this.message = err.message, this.stack = err.stack; } -IllegalStateError.prototype = Object.create( Error.prototype, { name: { value: 'IllegalStateError' } } ); - -function IllegalArgumentError () { var err = Error.apply( this, arguments ); this.message = err.message, this.stack = err.stack; } -IllegalArgumentError.prototype = Object.create( Error.prototype, { name: { value: 'IllegalArgumentError' } } ); - -function SecurityError () { var err = Error.apply( this, arguments ); this.message = err.message, this.stack = err.stack; } -SecurityError.prototype = Object.create( Error.prototype, { name: { value: 'SecurityError' } } ); +class IllegalStateError extends Error {} +class IllegalArgumentError extends Error {} +class SecurityError extends Error {} function string_to_bytes ( str, utf8 ) { utf8 = !!utf8; @@ -55,10 +81,11 @@ function string_to_bytes ( str, utf8 ) { function bytes_to_string ( bytes, utf8 ) { utf8 = !!utf8; - var len = bytes.length, + var i, j = 0, + len = bytes.length, chars = new Array(len); - for ( var i = 0, j = 0; i < len; i++ ) { + for ( i = 0; i < len; i++ ) { var b = bytes[i]; if ( !utf8 || b < 128 ) { chars[j++] = b; @@ -87,7 +114,7 @@ function bytes_to_string ( bytes, utf8 ) { var str = '', bs = 16384; - for ( var i = 0; i < j; i += bs ) { + for ( i = 0; i < j; i += bs ) { str += String.fromCharCode.apply( String, chars.slice( i, i+bs <= j ? i+bs : j ) ); } @@ -316,13 +343,14 @@ var AES_asm = function () { * @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 ), + var k, + 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]; + 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]; } @@ -336,7 +364,7 @@ var AES_asm = function () { // 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]; + k = ekeys[i-(4+j)+(4-jj)%4]; if ( j < 4 || j >= i-4 ) { dkeys[j+jj] = k; } else { @@ -1856,7 +1884,7 @@ function AES_GCM_Decrypt_finish () { asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA, 16 ); var acheck = 0; - for ( var i = 0; i < tagSize; ++i ) acheck |= atag[i] ^ heap[i]; + for ( i = 0; i < tagSize; ++i ) acheck |= atag[i] ^ heap[i]; if ( acheck ) throw new SecurityError("data integrity check failed"); @@ -2898,12 +2926,12 @@ 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; +'object'==typeof module&&module.exports?module.exports=exports:global.asmCrypto=exports; return exports; })( {}, function(){return this}() ); },{}], -4:[function(_dereq_,module,exports){ +4:[function(_dereq_,module){ (function (global){ (function () { function Rusha(chunkSize) { @@ -3658,89 +3686,986 @@ function verifyHeaders(headers, packetlist) { } },{"./config":10,"./encoding/armor.js":33,"./enums.js":35,"./packet":47,"./signature.js":66}], -6:[function(_dereq_,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}; -ja.prototype.pop=function(){var e,d,c=this.buffer,f,a,b;d=c[0];e=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(b=0;;){a=2*b+2;if(a>=this.length)break;a+2c[a]&&(a+=2);if(c[a]>c[b])f=c[b],c[b]=c[a],c[a]=f,f=c[b+1],c[b+1]=c[a+1],c[a+1]=f;else break;b=a}return{index:e,value:d,length:this.length}};function ka(e,d){this.e=ma;this.f=0;this.input=C&&e instanceof Array?new Uint8Array(e):e;this.c=0;d&&(d.lazy&&(this.f=d.lazy),"number"===typeof d.compressionType&&(this.e=d.compressionType),d.outputBuffer&&(this.b=C&&d.outputBuffer instanceof Array?new Uint8Array(d.outputBuffer):d.outputBuffer),"number"===typeof d.outputIndex&&(this.c=d.outputIndex));this.b||(this.b=new (C?Uint8Array:Array)(32768))}var ma=2,T=[],U; -for(U=0;288>U;U++)switch(u){case 143>=U:T.push([U+48,8]);break;case 255>=U:T.push([U-144+400,9]);break;case 279>=U:T.push([U-256+0,7]);break;case 287>=U:T.push([U-280+192,8]);break;default:throw"invalid literal: "+U;} -ka.prototype.h=function(){var e,d,c,f,a=this.input;switch(this.e){case 0:c=0;for(f=a.length;c>>8&255;l[h++]=p&255;l[h++]=p>>>8&255;if(C)l.set(b,h),h+=b.length,l=l.subarray(0,h);else{v=0;for(x=b.length;vs)for(;0s?s:138,A>s-3&&A=A?(E[D++]=17,E[D++]=A-3,H[17]++):(E[D++]=18,E[D++]=A-11,H[18]++),s-=A;else if(E[D++]=F[r],H[F[r]]++,s--,3>s)for(;0s?s:6,A>s-3&&Ay;y++)ia[y]=ea[Ia[y]];for(P=19;4=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272, -a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:throw"invalid length: "+a;}}var d=[],c,f;for(c=3;258>=c;c++)f=e(c),d[c]=f[2]<<24| -f[1]<<16|f[0];return d}(),Ga=C?new Uint32Array(Fa):Fa; -function na(e,d){function c(a,c){var b=a.g,d=[],f=0,e;e=Ga[a.length];d[f++]=e&65535;d[f++]=e>>16&255;d[f++]=e>>24;var g;switch(u){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b- -65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>= -b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:throw"invalid distance";}e=g;d[f++]=e[0];d[f++]=e[1];d[f++]=e[2];var k,m;k=0;for(m=d.length;k=b;)t[b++]=0;for(b=0;29>=b;)w[b++]=0}t[256]=1;f=0;for(a=d.length;f=a){x&&c(x,-1);b=0;for(k=a-f;bk&&d+kb&&(a=f,b=k);if(258===k)break}return new qa(b,d-a)} -function oa(e,d){var c=e.length,f=new ja(572),a=new (C?Uint8Array:Array)(c),b,k,m,g,p;if(!C)for(g=0;g2*a[h-1]+b[h]&&(a[h]=2*a[h-1]+b[h]),m[h]=Array(a[h]),g[h]=Array(a[h]);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;$ { + 'use strict'; + function m(d) { + throw d; + } + var w = void 0, + z = !0, + Q = new Uint8Array(256), + T = 0, + ca, + pa = [], -},{}], -7:[function(_dereq_,module,exports){ -/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var k=void 0,aa=this;function r(c,d){var a=c.split("."),b=aa;!(a[0]in b)&&b.execScript&&b.execScript("var "+a[0]);for(var e;a.length&&(e=a.shift());)!a.length&&d!==k?b[e]=d:b=b[e]?b[e]:b[e]={}};var t="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function u(c){var d=c.length,a=0,b=Number.POSITIVE_INFINITY,e,f,g,h,l,n,m,p,s,x;for(p=0;pa&&(a=c[p]),c[p]>=1;x=g<<16|p;for(s=n;s>>=1;switch(c){case 0:var d=this.input,a=this.d,b=this.b,e=this.a,f=d.length,g=k,h=k,l=b.length,n=k;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=d[a++]|d[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=d[a++]|d[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>d.length)throw Error("input buffer is broken");switch(this.i){case A:for(;e+g> -b.length;){n=l-e;g-=n;if(t)b.set(d.subarray(a,a+n),e),e+=n,a+=n;else for(;n--;)b[e++]=d[a++];this.a=e;b=this.e();e=this.a}break;case y:for(;e+g>b.length;)b=this.e({o:2});break;default:throw Error("invalid inflate mode");}if(t)b.set(d.subarray(a,a+g),e),e+=g,a+=g;else for(;g--;)b[e++]=d[a++];this.d=a;this.a=e;this.b=b;break;case 1:this.j(ba,ca);break;case 2:for(var m=B(this,5)+257,p=B(this,5)+1,s=B(this,4)+4,x=new (t?Uint8Array:Array)(C.length),Q=k,R=k,S=k,v=k,M=k,F=k,z=k,q=k,T=k,q=0;q=U?8:255>=U?9:279>=U?7:8;var ba=u(P),V=new (t?Uint8Array:Array)(30),W,ea;W=0;for(ea=V.length;W=g)throw Error("input buffer is broken");a|=e[f++]<>>d;c.c=b-d;c.d=f;return h} -function D(c,d){for(var a=c.f,b=c.c,e=c.input,f=c.d,g=e.length,h=d[0],l=d[1],n,m;b=g);)a|=e[f++]<>>16;if(m>b)throw Error("invalid code length: "+m);c.f=a>>m;c.c=b-m;c.d=f;return n&65535} -w.prototype.j=function(c,d){var a=this.b,b=this.a;this.n=c;for(var e=a.length-258,f,g,h,l;256!==(f=D(this,c));)if(256>f)b>=e&&(this.a=b,a=this.e(),b=this.a),a[b++]=f;else{g=f-257;l=H[g];0=e&&(this.a=b,a=this.e(),b=this.a);for(;l--;)a[b]=a[b++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=b}; -w.prototype.s=function(c,d){var a=this.b,b=this.a;this.n=c;for(var e=a.length,f,g,h,l;256!==(f=D(this,c));)if(256>f)b>=e&&(a=this.e(),e=a.length),a[b++]=f;else{g=f-257;l=H[g];0e&&(a=this.e(),e=a.length);for(;l--;)a[b]=a[b++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=b}; -w.prototype.e=function(){var c=new (t?Uint8Array:Array)(this.a-32768),d=this.a-32768,a,b,e=this.b;if(t)c.set(e.subarray(32768,c.length));else{a=0;for(b=c.length;aa;++a)e[a]=e[d+a];this.a=32768;return e}; -w.prototype.u=function(c){var d,a=this.input.length/this.d+1|0,b,e,f,g=this.input,h=this.b;c&&("number"===typeof c.o&&(a=c.o),"number"===typeof c.q&&(a+=c.q));2>a?(b=(g.length-this.d)/this.n[2],f=258*(b/2)|0,e=fd&&(this.b.length=d),c=this.b);return this.buffer=c};r("Zlib.RawInflate",w);r("Zlib.RawInflate.prototype.decompress",w.prototype.t);var X={ADAPTIVE:y,BLOCK:A},Y,Z,$,fa;if(Object.keys)Y=Object.keys(X);else for(Z in Y=[],$=0,X)Y[$++]=Z;$=0;for(fa=Y.length;$ { + switch (z) { + 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: + m("invalid length: " + b) + } + }, -},{}], -8:[function(_dereq_,module,exports){ -/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';function m(d){throw d;}var w=void 0,z=!0,aa=this;function A(d,a){var c=d.split("."),e=aa;!(c[0]in e)&&e.execScript&&e.execScript("var "+c[0]);for(var b;c.length&&(b=c.shift());)!c.length&&a!==w?e[b]=a:e=e[b]?e[b]:e[b]={}};var G="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function I(d,a){this.index="number"===typeof a?a:0;this.i=0;this.buffer=d instanceof(G?Uint8Array:Array)?d:new (G?Uint8Array:Array)(32768);2*this.buffer.length<=this.index&&m(Error("invalid index"));this.buffer.length<=this.index&&this.f()}I.prototype.f=function(){var d=this.buffer,a,c=d.length,e=new (G?Uint8Array:Array)(c<<1);if(G)e.set(d);else for(a=0;a>>8&255]<<16|Q[d>>>16&255]<<8|Q[d>>>24&255])>>32-a:Q[d]>>8-a);if(8>a+f)g=g<>a-h-1&1,8===++f&&(f=0,e[b++]=Q[g],g=0,b===e.length&&(e=this.f()));e[b]=g;this.buffer=e;this.i=f;this.index=b};I.prototype.finish=function(){var d=this.buffer,a=this.index,c;0ca;++ca){for(var R=ca,ha=R,ia=7,R=R>>>1;R;R>>>=1)ha<<=1,ha|=R&1,--ia;ba[ca]=(ha<>>0}var Q=ba;function ja(d){this.buffer=new (G?Uint16Array:Array)(2*d);this.length=0}ja.prototype.getParent=function(d){return 2*((d-2)/4|0)};ja.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}; -ja.prototype.pop=function(){var d,a,c=this.buffer,e,b,f;a=c[0];d=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(f=0;;){b=2*f+2;if(b>=this.length)break;b+2c[b]&&(b+=2);if(c[b]>c[f])e=c[f],c[f]=c[b],c[b]=e,e=c[f+1],c[f+1]=c[b+1],c[b+1]=e;else break;f=b}return{index:d,value:a,length:this.length}};function S(d){var a=d.length,c=0,e=Number.POSITIVE_INFINITY,b,f,g,h,k,p,q,r,n,l;for(r=0;rc&&(c=d[r]),d[r]>=1;l=g<<16|r;for(n=p;nT;T++)switch(z){case 143>=T:pa.push([T+48,8]);break;case 255>=T:pa.push([T-144+400,9]);break;case 279>=T:pa.push([T-256+0,7]);break;case 287>=T:pa.push([T-280+192,8]);break;default:m("invalid literal: "+T)} -ka.prototype.j=function(){var d,a,c,e,b=this.input;switch(this.h){case 0:c=0;for(e=b.length;c>>8&255;n[l++]=p&255;n[l++]=p>>>8&255;if(G)n.set(f,l),l+=f.length,n=n.subarray(0,l);else{q=0;for(r=f.length;qy)for(;0y?y:138,F>y-3&&F=F?(J[H++]=17,J[H++]=F-3,O[17]++):(J[H++]=18,J[H++]=F-11,O[18]++),y-=F;else if(J[H++]=K[u],O[K[u]]++,y--,3>y)for(;0y?y:6,F>y-3&&FD;D++)sa[D]=la[gb[D]];for(Z=19;4=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:m("invalid length: "+b)}}var a=[],c,e;for(c=3;258>=c;c++)e=d(c),a[c]=e[2]<<24|e[1]<< -16|e[0];return a}(),xa=G?new Uint32Array(wa):wa; -function qa(d,a){function c(b,c){var a=b.G,d=[],e=0,f;f=xa[b.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(z){case 1===a:g=[0,a-1,0];break;case 2===a:g=[1,a-2,0];break;case 3===a:g=[2,a-3,0];break;case 4===a:g=[3,a-4,0];break;case 6>=a:g=[4,a-5,1];break;case 8>=a:g=[5,a-7,1];break;case 12>=a:g=[6,a-9,2];break;case 16>=a:g=[7,a-13,2];break;case 24>=a:g=[8,a-17,3];break;case 32>=a:g=[9,a-25,3];break;case 48>=a:g=[10,a-33,4];break;case 64>=a:g=[11,a-49,4];break;case 96>=a:g=[12,a- -65,5];break;case 128>=a:g=[13,a-97,5];break;case 192>=a:g=[14,a-129,6];break;case 256>=a:g=[15,a-193,6];break;case 384>=a:g=[16,a-257,7];break;case 512>=a:g=[17,a-385,7];break;case 768>=a:g=[18,a-513,8];break;case 1024>=a:g=[19,a-769,8];break;case 1536>=a:g=[20,a-1025,9];break;case 2048>=a:g=[21,a-1537,9];break;case 3072>=a:g=[22,a-2049,10];break;case 4096>=a:g=[23,a-3073,10];break;case 6144>=a:g=[24,a-4097,11];break;case 8192>=a:g=[25,a-6145,11];break;case 12288>=a:g=[26,a-8193,12];break;case 16384>= -a:g=[27,a-12289,12];break;case 24576>=a:g=[28,a-16385,13];break;case 32768>=a:g=[29,a-24577,13];break;default:m("invalid distance")}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var h,k;h=0;for(k=d.length;h=f;)t[f++]=0;for(f=0;29>=f;)x[f++]=0}t[256]=1;e=0;for(b=a.length;e=b){r&&c(r,-1);f=0;for(g=b-e;fg&&a+gf&&(b=e,f=g);if(258===g)break}return new ua(f,a-b)} -function ra(d,a){var c=d.length,e=new ja(572),b=new (G?Uint8Array:Array)(c),f,g,h,k,p;if(!G)for(k=0;k2*b[l-1]+f[l]&&(b[l]=2*b[l-1]+f[l]),h[l]=Array(b[l]),k[l]=Array(b[l]);for(n=0;nd[n]?(h[l][s]=t,k[l][s]=a,x+=2):(h[l][s]=d[n],k[l][s]=n,++n);p[l]=0;1===f[l]&&e(l)}return g} -function ta(d){var a=new (G?Uint16Array:Array)(d.length),c=[],e=[],b=0,f,g,h,k;f=0;for(g=d.length;f>>=1}return a};function U(d,a){this.l=[];this.m=32768;this.e=this.g=this.c=this.q=0;this.input=G?new Uint8Array(d):d;this.s=!1;this.n=Aa;this.B=!1;if(a||!(a={}))a.index&&(this.c=a.index),a.bufferSize&&(this.m=a.bufferSize),a.bufferType&&(this.n=a.bufferType),a.resize&&(this.B=a.resize);switch(this.n){case Ba:this.b=32768;this.a=new (G?Uint8Array:Array)(32768+this.m+258);break;case Aa:this.b=0;this.a=new (G?Uint8Array:Array)(this.m);this.f=this.J;this.t=this.H;this.o=this.I;break;default:m(Error("invalid inflate mode"))}} -var Ba=0,Aa=1,Ca={D:Ba,C:Aa}; -U.prototype.p=function(){for(;!this.s;){var d=V(this,3);d&1&&(this.s=z);d>>>=1;switch(d){case 0:var a=this.input,c=this.c,e=this.a,b=this.b,f=a.length,g=w,h=w,k=e.length,p=w;this.e=this.g=0;c+1>=f&&m(Error("invalid uncompressed block header: LEN"));g=a[c++]|a[c++]<<8;c+1>=f&&m(Error("invalid uncompressed block header: NLEN"));h=a[c++]|a[c++]<<8;g===~h&&m(Error("invalid uncompressed block header: length verify"));c+g>a.length&&m(Error("input buffer is broken"));switch(this.n){case Ba:for(;b+g>e.length;){p= -k-b;g-=p;if(G)e.set(a.subarray(c,c+p),b),b+=p,c+=p;else for(;p--;)e[b++]=a[c++];this.b=b;e=this.f();b=this.b}break;case Aa:for(;b+g>e.length;)e=this.f({v:2});break;default:m(Error("invalid inflate mode"))}if(G)e.set(a.subarray(c,c+g),b),b+=g,c+=g;else for(;g--;)e[b++]=a[c++];this.c=c;this.b=b;this.a=e;break;case 1:this.o(Da,Ea);break;case 2:for(var q=V(this,5)+257,r=V(this,5)+1,n=V(this,4)+4,l=new (G?Uint8Array:Array)(Sa.length),s=w,t=w,x=w,E=w,B=w,C=w,L=w,v=w,M=w,v=0;v=W?8:255>=W?9:279>=W?7:8;var Da=S(cb),eb=new (G?Uint8Array:Array)(30),fb,hb;fb=0;for(hb=eb.length;fb=g&&m(Error("input buffer is broken")),c|=b[f++]<>>a;d.e=e-a;d.c=f;return h} -function Ta(d,a){for(var c=d.g,e=d.e,b=d.input,f=d.c,g=b.length,h=a[0],k=a[1],p,q;e=g);)c|=b[f++]<>>16;q>e&&m(Error("invalid code length: "+q));d.g=c>>q;d.e=e-q;d.c=f;return p&65535} -U.prototype.o=function(d,a){var c=this.a,e=this.b;this.u=d;for(var b=c.length-258,f,g,h,k;256!==(f=Ta(this,d));)if(256>f)e>=b&&(this.b=e,c=this.f(),e=this.b),c[e++]=f;else{g=f-257;k=Wa[g];0=b&&(this.b=e,c=this.f(),e=this.b);for(;k--;)c[e]=c[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e}; -U.prototype.I=function(d,a){var c=this.a,e=this.b;this.u=d;for(var b=c.length,f,g,h,k;256!==(f=Ta(this,d));)if(256>f)e>=b&&(c=this.f(),b=c.length),c[e++]=f;else{g=f-257;k=Wa[g];0b&&(c=this.f(),b=c.length);for(;k--;)c[e]=c[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e}; -U.prototype.f=function(){var d=new (G?Uint8Array:Array)(this.b-32768),a=this.b-32768,c,e,b=this.a;if(G)d.set(b.subarray(32768,d.length));else{c=0;for(e=d.length;cc;++c)b[c]=b[a+c];this.b=32768;return b}; -U.prototype.J=function(d){var a,c=this.input.length/this.c+1|0,e,b,f,g=this.input,h=this.a;d&&("number"===typeof d.v&&(c=d.v),"number"===typeof d.F&&(c+=d.F));2>c?(e=(g.length-this.c)/this.u[2],f=258*(e/2)|0,b=fa&&(this.a.length=a),d=this.a);return this.buffer=d};function ib(d){if("string"===typeof d){var a=d.split(""),c,e;c=0;for(e=a.length;c>>0;d=a}for(var b=1,f=0,g=d.length,h,k=0;0>>0};function jb(d,a){var c,e;this.input=d;this.c=0;if(a||!(a={}))a.index&&(this.c=a.index),a.verify&&(this.M=a.verify);c=d[this.c++];e=d[this.c++];switch(c&15){case kb:this.method=kb;break;default:m(Error("unsupported compression method"))}0!==((c<<8)+e)%31&&m(Error("invalid fcheck flag:"+((c<<8)+e)%31));e&32&&m(Error("fdict flag is not supported"));this.A=new U(d,{index:this.c,bufferSize:a.bufferSize,bufferType:a.bufferType,resize:a.resize})} -jb.prototype.p=function(){var d=this.input,a,c;a=this.A.p();this.c=this.A.c;this.M&&(c=(d[this.c++]<<24|d[this.c++]<<16|d[this.c++]<<8|d[this.c++])>>>0,c!==ib(a)&&m(Error("invalid adler-32 checksum")));return a};var kb=8;function lb(d,a){this.input=d;this.a=new (G?Uint8Array:Array)(32768);this.h=X.k;var c={},e;if((a||!(a={}))&&"number"===typeof a.compressionType)this.h=a.compressionType;for(e in a)c[e]=a[e];c.outputBuffer=this.a;this.z=new ka(this.input,c)}var X=oa; -lb.prototype.j=function(){var d,a,c,e,b,f,g,h=0;g=this.a;d=kb;switch(d){case kb:a=Math.LOG2E*Math.log(32768)-8;break;default:m(Error("invalid compression method"))}c=a<<4|d;g[h++]=c;switch(d){case kb:switch(this.h){case X.NONE:b=0;break;case X.r:b=1;break;case X.k:b=2;break;default:m(Error("unsupported compression type"))}break;default:m(Error("invalid compression method"))}e=b<<6|0;g[h++]=e|31-(256*c+e)%31;f=ib(this.input);this.z.b=h;g=this.z.j();h=g.length;G&&(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 mb(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 { + var a = new Uint32Array(), + c, e; + for (c = 3; 258 >= c; c++) e = d(c), a[c] = e[2] << 24 | e[1] << 16 | e[0]; + return a + })(), + + qa = (d, a) => { + function c(b, c) { + var a = b.G, + d = [], + e = 0, + f = xa[b.length]; + d[e++] = f & 65535; + d[e++] = f >> 16 & 255; + d[e++] = f >> 24; + var g; + switch (z) { + case 1 === a: + g = [0, a - 1, 0]; + break; + case 2 === a: + g = [1, a - 2, 0]; + break; + case 3 === a: + g = [2, a - 3, 0]; + break; + case 4 === a: + g = [3, a - 4, 0]; + break; + case 6 >= a: + g = [4, a - 5, 1]; + break; + case 8 >= a: + g = [5, a - 7, 1]; + break; + case 12 >= a: + g = [6, a - 9, 2]; + break; + case 16 >= a: + g = [7, a - 13, 2]; + break; + case 24 >= a: + g = [8, a - 17, 3]; + break; + case 32 >= a: + g = [9, a - 25, 3]; + break; + case 48 >= a: + g = [10, a - 33, 4]; + break; + case 64 >= a: + g = [11, a - 49, 4]; + break; + case 96 >= a: + g = [12, a - 65, 5]; + break; + case 128 >= a: + g = [13, a - 97, 5]; + break; + case 192 >= a: + g = [14, a - 129, 6]; + break; + case 256 >= a: + g = [15, a - 193, 6]; + break; + case 384 >= a: + g = [16, a - 257, 7]; + break; + case 512 >= a: + g = [17, a - 385, 7]; + break; + case 768 >= a: + g = [18, a - 513, 8]; + break; + case 1024 >= a: + g = [19, a - 769, 8]; + break; + case 1536 >= a: + g = [20, a - 1025, 9]; + break; + case 2048 >= a: + g = [21, a - 1537, 9]; + break; + case 3072 >= a: + g = [22, a - 2049, 10]; + break; + case 4096 >= a: + g = [23, a - 3073, 10]; + break; + case 6144 >= a: + g = [24, a - 4097, 11]; + break; + case 8192 >= a: + g = [25, a - 6145, 11]; + break; + case 12288 >= a: + g = [26, a - 8193, 12]; + break; + case 16384 >= a: + g = [27, a - 12289, 12]; + break; + case 24576 >= a: + g = [28, a - 16385, 13]; + break; + case 32768 >= a: + g = [29, a - 24577, 13]; + break; + default: + m("invalid distance") + } + f = g; + d[e++] = f[0]; + d[e++] = f[1]; + d[e++] = f[2]; + var h, k; + h = 0; + for (k = d.length; h < k; ++h) n[l++] = d[h]; + t[d[0]]++; + x[d[3]]++; + s = b.length + c - 1; + r = null + } + var e, b, f, g, h, k = {}, + p, q, r, n = new Uint16Array(2 * a.length), + l = 0, + s = 0, + t = new Uint32Array(286), + x = new Uint32Array(30), + E = d.w, + B; + t[256] = 1; + e = 0; + for (b = a.length; e < b; ++e) { + f = h = 0; + for (g = 3; f < g && e + f !== b; ++f) h = h << 8 | a[e + f]; + k[h] === w && (k[h] = []); + p = k[h]; + if (!(0 < s--)) { + for (; 0 < p.length && 32768 < e - p[0];) p.shift(); + if (e + 3 >= b) { + r && c(r, -1); + f = 0; + for (g = b - e; f < g; ++f) B = a[e + f], n[l++] = B, ++t[B]; + break + } + 0 < p.length ? (q = ya(a, e, p), r ? r.length < q.length ? (B = a[e - 1], n[l++] = B, ++t[B], c(q, 0)) : c(r, -1) : q.length < E ? r = q : c(q, 0)) : r ? c(r, -1) : (B = a[e], n[l++] = B, ++t[B]) + } + p.push(e) + } + n[l++] = 256; + t[256]++; + d.L = t; + d.K = x; + return n.subarray(0, l) + }, + + ya = (d, a, c) => { + var e, b, f = 0, + g, h, k, p, q = d.length; + h = 0; + p = c.length; + a: for (; h < p; h++) { + e = c[p - h - 1]; + g = 3; + if (3 < f) { + for (k = f; 3 < k; k--) + if (d[e + k - 1] !== d[a + k - 1]) continue a; + g = f + } + for (; 258 > g && a + g < q && d[e + g] === d[a + g];) ++g; + g > f && (b = e, f = g); + if (258 === g) break + } + return {length: f, G: a - b} + }, + + ra = (d, a) => { + var c = d.length, + e = new ja(572), + b = new Uint8Array(c), + f, g, h, k, p; + for (k = 0; k < c; ++k) 0 < d[k] && e.push(k, d[k]); + f = Array(e.length / 2); + g = new Uint32Array(e.length / 2); + if (1 === f.length) return b[e.pop().index] = 1, b; + k = 0; + for (p = e.length / 2; k < p; ++k) f[k] = e.pop(), g[k] = f[k].value; + h = za(g, g.length, a); + k = 0; + for (p = f.length; k < p; ++k) b[f[k].index] = h[k]; + return b + }, + + za = (d, a, c) => { + function e(b) { + var c = k[b][p[b]]; + c === a ? (e(b + 1), e(b + 1)) : --g[c]; + ++p[b] + } + var b = new Uint16Array(c), + f = new Uint8Array(c), + g = new Uint8Array(a), + h = Array(c), + k = Array(c), + p = Array(c), + q = (1 << c) - a, + r = 1 << c - 1, + n, l, s, t, x; + b[c - 1] = a; + for (l = 0; l < c; ++l) q < r ? f[l] = 0 : (f[l] = 1, q -= r), q <<= 1, b[c - 2 - l] = (b[c - 1 - l] / 2 | 0) + a; + b[0] = f[0]; + h[0] = Array(b[0]); + k[0] = Array(b[0]); + for (l = 1; l < c; ++l) b[l] > 2 * b[l - 1] + f[l] && (b[l] = 2 * b[l - 1] + f[l]), h[l] = Array(b[l]), k[l] = Array(b[l]); + for (n = 0; n < a; ++n) g[n] = c; + for (s = 0; s < b[c - 1]; ++s) h[c - + 1][s] = d[s], k[c - 1][s] = s; + for (n = 0; n < c; ++n) p[n] = 0; + 1 === f[c - 1] && (--g[0], ++p[c - 1]); + for (l = c - 2; 0 <= l; --l) { + t = n = 0; + x = p[l + 1]; + for (s = 0; s < b[l]; s++) t = h[l + 1][x] + h[l + 1][x + 1], t > d[n] ? (h[l][s] = t, k[l][s] = a, x += 2) : (h[l][s] = d[n], k[l][s] = n, ++n); + p[l] = 0; + 1 === f[l] && e(l) + } + return g + }, + + ta = d => { + var a = new Uint16Array(d.length), + c = [], + e = [], + b = 0, + f, g, h, k; + f = 0; + for (g = d.length; f < g; f++) c[d[f]] = (c[d[f]] | 0) + 1; + f = 1; + for (g = 16; f <= g; f++) e[f] = b, b += c[f] | 0, b <<= 1; + f = 0; + for (g = d.length; f < g; f++) { + b = e[d[f]]; + e[d[f]] += 1; + h = a[f] = 0; + for (k = d[f]; h < k; h++) a[f] = a[f] << 1 | b & 1, b >>>= 1 + } + return a + }; + + for (; 288 > T; T++) switch (z) { + case 143 >= T: + pa.push([T + 48, 8]); + break; + case 255 >= T: + pa.push([T - 144 + 400, 9]); + break; + case 279 >= T: + pa.push([T - 256 + 0, 7]); + break; + case 287 >= T: + pa.push([T - 280 + 192, 8]); + break; + default: + m("invalid literal: " + T) + } + + for (ca = 0; 256 > ca; ++ca) { + for (var R = ca, ha = R, ia = 7, R = R >>> 1; R; R >>>= 1) ha <<= 1, ha |= R & 1, --ia; + Q[ca] = (ha << ia & 255) >>> 0 + } + + class I + { + constructor(d, a) { + this.index = "number" === typeof a ? a : 0; + this.i = 0; + this.buffer = d instanceof Uint8Array ? d : new Uint8Array(32768); + 2 * this.buffer.length <= this.index && m(Error("invalid index")); + this.buffer.length <= this.index && this.f() + } + + f() { + var d = this.buffer, + c = d.length, + e = new Uint8Array(c << 1); + e.set(d); + return this.buffer = e + } + + d(d, a, c) { + var e = this.buffer, + b = this.index, + f = this.i, + g = e[b], + h; + c && 1 < a && (d = 8 < a ? (Q[d & 255] << 24 | Q[d >>> 8 & 255] << 16 | Q[d >>> 16 & 255] << 8 | Q[d >>> 24 & 255]) >> 32 - a : Q[d] >> 8 - a); + if (8 > a + f) g = g << a | d, f += a; + else + for (h = 0; h < a; ++h) g = g << 1 | d >> a - h - 1 & 1, 8 === ++f && (f = 0, e[b++] = Q[g], g = 0, b === e.length && (e = this.f())); + e[b] = g; + this.buffer = e; + this.i = f; + this.index = b + } + + finish() { + var d = this.buffer, + a = this.index, + c; + 0 < this.i && (d[a] <<= 8 - this.i, d[a] = Q[d[a]], a++); + c = d.subarray(0, a); + return c + } + } + + class ja + { + constructor(d) { + this.buffer = new Uint16Array(2 * d); + this.length = 0 + } + + getParent(d) { + return 2 * ((d - 2) / 4 | 0) + } + + push(d, a) { + var c, e, b = this.buffer, + f; + c = this.length; + b[this.length++] = a; + for (b[this.length++] = d; 0 < c;) + if (e = this.getParent(c), b[c] > b[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 + } + + pop() { + var d, a, c = this.buffer, + e, b, f; + a = c[0]; + d = c[1]; + this.length -= 2; + c[0] = c[this.length]; + c[1] = c[this.length + 1]; + for (f = 0;;) { + b = 2 * f + 2; + if (b >= this.length) break; + b + 2 < this.length && c[b + 2] > c[b] && (b += 2); + if (c[b] > c[f]) e = c[f], c[f] = c[b], c[b] = e, e = c[f + 1], c[f + 1] = c[b + 1], c[b + 1] = e; + else break; + f = b + } + return { + index: d, + value: a, + length: this.length + } + } + } + + class ka + { + constructor(d, a) { + this.h = 2; + this.w = 0; + this.input = d instanceof Array ? new Uint8Array(d) : d; + this.b = 0; + a && (a.lazy && (this.w = a.lazy), "number" === typeof a.compressionType && (this.h = a.compressionType), a.outputBuffer && (this.a = a.outputBuffer instanceof Array ? new Uint8Array(a.outputBuffer) : a.outputBuffer), "number" === typeof a.outputIndex && (this.b = a.outputIndex)); + this.a || (this.a = new Uint8Array(32768)) + } + + compress() { + this.j(); + } + j() { + var d, a, c, e, b = this.input; + switch (this.h) { + case 0: + c = 0; + for (e = b.length; c < e;) { + a = b.subarray(c, c + 65535); + c += a.length; + var f = a, + g = c === e, + h = w, + k = w, + p = w, + n = this.a, + l = this.b; + for (n = new Uint8Array(this.a.buffer); n.length <= l + f.length + 5;) n = new Uint8Array(n.length << 1); + n.set(this.a) + h = g ? 1 : 0; + n[l++] = h | 0; + k = f.length; + p = ~k + 65536 & 65535; + n[l++] = k & 255; + n[l++] = k >>> 8 & 255; + n[l++] = p & 255; + n[l++] = p >>> 8 & 255; + n.set(f, l), l += f.length, n = n.subarray(0, l); + this.b = l; + this.a = n + } + break; + case 1: + var s = new I(new Uint8Array(this.a.buffer), this.b); + s.d(1, 1, z); + s.d(1, 2, z); + var t = qa(this, b), + x, E, B; + x = 0; + for (E = t.length; x < E; x++) + if (B = t[x], I.prototype.d.apply(s, pa[B]), 256 < B) s.d(t[++x], t[++x], z), s.d(t[++x], 5), s.d(t[++x], t[++x], z); + else if (256 === B) break; + this.a = s.finish(); + this.b = this.a.length; + break; + case 2: + var C = new I(new Uint8Array(this.a.buffer), this.b), + L, v, M, Y, Z, gb = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15], + da, Fa, ea, Ga, la, sa = Array(19), + Ha, $, ma, D, Ia; + L = 2; + C.d(1, 1, z); + C.d(L, 2, z); + v = qa(this, b); + da = ra(this.L, 15); + Fa = ta(da); + ea = ra(this.K, 7); + Ga = ta(ea); + for (M = 286; 257 < M && 0 === da[M - 1]; M--); + for (Y = 30; 1 < Y && 0 === ea[Y - 1]; Y--); + var Ja = M, + Ka = Y, + K = new Uint32Array(Ja + Ka), + u, N, y, fa, J = new Uint32Array(316), + H, F, O = new Uint8Array(19); + for (u = N = 0; u < Ja; u++) K[N++] = da[u]; + for (u = 0; u < Ka; u++) K[N++] = ea[u]; + u = H = 0; + for (fa = K.length; u < fa; u += N) { + for (N = 1; u + N < fa && K[u + N] === K[u]; ++N); + y = N; + if (0 === K[u]) + if (3 > y) + for (; 0 < y--;) J[H++] = + 0, O[0]++; + else + for (; 0 < y;) F = 138 > y ? y : 138, F > y - 3 && F < y && (F = y - 3), 10 >= F ? (J[H++] = 17, J[H++] = F - 3, O[17]++) : (J[H++] = 18, J[H++] = F - 11, O[18]++), y -= F; + else if (J[H++] = K[u], O[K[u]]++, y--, 3 > y) + for (; 0 < y--;) J[H++] = K[u], O[K[u]]++; + else + for (; 0 < y;) F = 6 > y ? y : 6, F > y - 3 && F < y && (F = y - 3), J[H++] = 16, J[H++] = F - 3, O[16]++, y -= F + } + d = J.subarray(0, H); + la = ra(O, 7); + for (D = 0; 19 > D; D++) sa[D] = la[gb[D]]; + for (Z = 19; 4 < Z && 0 === sa[Z - 1]; Z--); + Ha = ta(la); + C.d(M - 257, 5, z); + C.d(Y - 1, 5, z); + C.d(Z - 4, 4, z); + for (D = 0; D < Z; D++) C.d(sa[D], 3, z); + D = 0; + for (Ia = d.length; D < Ia; D++) + if ($ = + d[D], C.d(Ha[$], la[$], z), 16 <= $) { + D++; + switch ($) { + case 16: + ma = 2; + break; + case 17: + ma = 3; + break; + case 18: + ma = 7; + break; + default: + m("invalid code: " + $) + } + C.d(d[D], ma, z) + } + var La = [Fa, da], + Ma = [Ga, ea], + P, Na, ga, va, Oa, Pa, Qa, Ra; + Oa = La[0]; + Pa = La[1]; + Qa = Ma[0]; + Ra = Ma[1]; + P = 0; + for (Na = v.length; P < Na; ++P) + if (ga = v[P], C.d(Oa[ga], Pa[ga], z), 256 < ga) C.d(v[++P], v[++P], z), va = v[++P], C.d(Qa[va], Ra[va], z), C.d(v[++P], v[++P], z); + else if (256 === ga) break; + this.a = C.finish(); + this.b = this.a.length; + break; + default: + m("invalid compression type") + } + return this.a + } + } + + var S = d => { + var a = d.length, + c = 0, + e = Number.POSITIVE_INFINITY, + b, f, g, h, k, p, q, r, n, l; + for (r = 0; r < a; ++r) d[r] > c && (c = d[r]), d[r] < e && (e = d[r]); + b = 1 << c; + f = new Uint32Array(b); + g = 1; + h = 0; + for (k = 2; g <= c;) { + for (r = 0; r < a; ++r) + if (d[r] === g) { + p = 0; + q = h; + for (n = 0; n < g; ++n) p = p << 1 | q & 1, q >>= 1; + l = g << 16 | r; + for (n = p; n < b; n += k) f[n] = l; + ++h + }++g; + h <<= 1; + k <<= 1 + } + return [f, c, e] + }, + + Sa = new Uint16Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + Wa = new Uint16Array([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]), + Ya = new Uint8Array([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]), + $a = new Uint16Array([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]), + bb = new Uint8Array([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]), + W = 288, + cb = new Uint8Array(W), + Ea = S((new Uint8Array(30)).fill(5)), + + V = (d, a) => { + for (var c = d.g, e = d.e, b = d.input, f = d.c, g = b.length, h; e < a;) f >= g && m(Error("input buffer is broken")), c |= b[f++] << e, e += 8; + h = c & (1 << a) - 1; + d.g = c >>> a; + d.e = e - a; + d.c = f; + return h + }, + + Ta = (d, a) => { + for (var c = d.g, e = d.e, b = d.input, f = d.c, g = b.length, h = a[0], k = a[1], p, q; e < k && !(f >= g);) c |= b[f++] << e, e += 8; + p = h[c & (1 << k) - 1]; + q = p >>> 16; + q > e && m(Error("invalid code length: " + q)); + d.g = c >> q; + d.e = e - q; + d.c = f; + return p & 65535 + }; + + while (W--) cb[W] = 143 >= W ? 8 : 255 >= W ? 9 : 279 >= W ? 7 : 8; + var Da = S(cb); + + class U + { + constructor(d, a) { + this.l = []; + this.m = 32768; + this.e = this.g = this.c = this.q = 0; + this.input = new Uint8Array(d); + this.s = !1; + this.n = 1; + this.B = !1; + if (a || !(a = {})) a.index && (this.c = a.index), a.bufferSize && (this.m = a.bufferSize), a.bufferType && (this.n = a.bufferType), a.resize && (this.B = a.resize); + switch (this.n) { + case 0: + this.b = 32768; + this.a = new Uint8Array(32768 + this.m + 258); + break; + case 1: + this.b = 0; + this.a = new Uint8Array(this.m); + this.f = this.J; + this.t = this.H; + this.o = this.I; + break; + default: + m(Error("invalid inflate mode")) + } + } + + decompress() { + this.p(); + } + p() { + for (; !this.s;) { + var d = V(this, 3); + d & 1 && (this.s = z); + d >>>= 1; + switch (d) { + case 0: + var a = this.input, + c = this.c, + e = this.a, + b = this.b, + f = a.length, + g = w, + h = w, + k = e.length, + p = w; + this.e = this.g = 0; + c + 1 >= f && m(Error("invalid uncompressed block header: LEN")); + g = a[c++] | a[c++] << 8; + c + 1 >= f && m(Error("invalid uncompressed block header: NLEN")); + h = a[c++] | a[c++] << 8; + g === ~h && m(Error("invalid uncompressed block header: length verify")); + c + g > a.length && m(Error("input buffer is broken")); + switch (this.n) { + case 0: + for (; b + g > e.length;) { + p = + k - b; + g -= p; + e.set(a.subarray(c, c + p), b), b += p, c += p; + this.b = b; + e = this.f(); + b = this.b + } + break; + case 1: + for (; b + g > e.length;) e = this.f({ + v: 2 + }); + break; + default: + m(Error("invalid inflate mode")) + } + e.set(a.subarray(c, c + g), b), b += g, c += g; + this.c = c; + this.b = b; + this.a = e; + break; + case 1: + this.o(Da, Ea); + break; + case 2: + for (var q = V(this, 5) + 257, r = V(this, 5) + 1, n = V(this, 4) + 4, l = new Uint8Array(Sa.length), s = w, t = w, x = w, E = w, B = w, C = w, L = w, v = w, M = w, v = 0; v < n; ++v) l[Sa[v]] = V(this, 3); + s = S(l); + E = new Uint8Array(q + r); + v = 0; + for (M = q + r; v < M;) switch (B = Ta(this, s), B) { + case 16: + for (L = 3 + V(this, 2); L--;) E[v++] = C; + break; + case 17: + for (L = 3 + V(this, 3); L--;) E[v++] = 0; + C = 0; + break; + case 18: + for (L = 11 + V(this, 7); L--;) E[v++] = 0; + C = 0; + break; + default: + C = E[v++] = B + } + t = S(E.subarray(0, q)); + x = S(E.subarray(q)); + this.o(t, x); + break; + default: + m(Error("unknown BTYPE: " + d)) + } + } + return this.t() + } + + o(d, a) { + var c = this.a, + e = this.b; + this.u = d; + for (var b = c.length - 258, f, g, h, k; 256 !== (f = Ta(this, d));) + if (256 > f) e >= b && (this.b = e, c = this.f(), e = this.b), c[e++] = f; + else { + g = f - 257; + k = Wa[g]; + 0 < Ya[g] && (k += V(this, Ya[g])); + f = Ta(this, a); + h = $a[f]; + 0 < bb[f] && (h += V(this, bb[f])); + e >= b && (this.b = e, c = this.f(), e = this.b); + for (; k--;) c[e] = c[e++ - h] + } + for (; 8 <= this.e;) this.e -= 8, this.c--; + this.b = e + } + + I(d, a) { + var c = this.a, + e = this.b; + this.u = d; + for (var b = c.length, f, g, h, k; 256 !== (f = Ta(this, d));) + if (256 > f) e >= b && (c = this.f(), b = c.length), c[e++] = f; + else { + g = f - 257; + k = Wa[g]; + 0 < Ya[g] && (k += V(this, Ya[g])); + f = Ta(this, a); + h = $a[f]; + 0 < bb[f] && (h += V(this, bb[f])); + e + k > b && (c = this.f(), b = c.length); + for (; k--;) c[e] = c[e++ - h] + } + for (; 8 <= this.e;) this.e -= 8, this.c--; + this.b = e + } + + f() { + var d = new Uint8Array(this.b - 32768), + a = this.b - 32768, + b = this.a; + d.set(b.subarray(32768, d.length)); + this.l.push(d); + this.q += d.length; + b.set(b.subarray(a, a + 32768)); + this.b = 32768; + return b + } + + J(d) { + var a, c = this.input.length / this.c + 1 | 0, + e, b, f, g = this.input, + h = this.a; + d && ("number" === typeof d.v && (c = d.v), "number" === typeof d.F && (c += d.F)); + 2 > c ? (e = (g.length - this.c) / this.u[2], f = 258 * (e / 2) | 0, b = f < h.length ? h.length + f : h.length << 1) : b = h.length * c; + a = new Uint8Array(b), a.set(h); + return this.a = a + } + + t() { + var d = 0, + a = this.a, + c = this.l, + e, b = new Uint8Array(this.q + (this.b - 32768)), + f, g, h, k; + if (0 === c.length) return this.a.subarray(32768, this.b); + f = 0; + for (g = c.length; f < g; ++f) { + e = c[f]; + h = 0; + for (k = e.length; h < k; ++h) b[d++] = e[h] + } + f = 32768; + for (g = this.b; f < g; ++f) b[d++] = a[f]; + this.l = []; + return this.buffer = b + } + + H() { + var d, a = this.b; + this.B ? (d = new Uint8Array(a), d.set(this.a.subarray(0, a))) : d = this.a.subarray(0, a); + return this.buffer = d + } + } + + function ib(d) { + if ("string" === typeof d) { + var a = d.split(""), + c, e; + c = 0; + for (e = a.length; c < e; c++) a[c] = (a[c].charCodeAt(0) & 255) >>> 0; + d = a + } + for (var b = 1, f = 0, g = d.length, h, k = 0; 0 < g;) { + h = 1024 < g ? 1024 : g; + g -= h; + do b += d[k++], f += b; while (--h); + b %= 65521; + f %= 65521 + } + return (f << 16 | b) >>> 0 + } + + class jb + { + constructor(d, a) { + var c, e; + this.input = d; + this.c = 0; + if (a || !(a = {})) a.index && (this.c = a.index), a.verify && (this.M = a.verify); + c = d[this.c++]; + e = d[this.c++]; + switch (c & 15) { + case 8: + this.method = 8; + break; + default: + m(Error("unsupported compression method")) + } + 0 !== ((c << 8) + e) % 31 && m(Error("invalid fcheck flag:" + ((c << 8) + e) % 31)); + e & 32 && m(Error("fdict flag is not supported")); + this.A = new U(d, { + index: this.c, + bufferSize: a.bufferSize, + bufferType: a.bufferType, + resize: a.resize + }) + } + + decompress() { + var d = this.input, + a, c; + a = this.A.p(); + this.c = this.A.c; + this.M && (c = (d[this.c++] << 24 | d[this.c++] << 16 | d[this.c++] << 8 | d[this.c++]) >>> 0, c !== ib(a) && m(Error("invalid adler-32 checksum"))); + return a + } + } + + class lb + { + constructor(d, a) { + this.input = d; + this.a = new Uint8Array(32768); + this.h = 2; + var c = {}, + e; + if ((a || !(a = {})) && "number" === typeof a.compressionType) this.h = a.compressionType; + for (e in a) c[e] = a[e]; + c.outputBuffer = this.a; + this.z = new ka(this.input, c) + } + + compress = function () { + var d, a, c, e, b, f, g, h = 0; + g = this.a; + d = 8; + switch (d) { + case 8: + a = Math.LOG2E * Math.log(32768) - 8; + break; + default: + m(Error("invalid compression method")) + } + c = a << 4 | d; + g[h++] = c; + switch (d) { + case 8: + switch (this.h) { + case 0: + b = 0; + break; + case 1: + b = 1; + break; + case 2: + b = 2; + break; + default: + m(Error("unsupported compression type")) + } + break; + default: + m(Error("invalid compression method")) + } + e = b << 6 | 0; + g[h++] = e | 31 - (256 * c + e) % 31; + f = ib(this.input); + this.z.b = h; + g = this.z.j(); + h = g.length; + (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 + } + } + + U.BufferType = jb.BufferType = { + ADAPTIVE: 1, + BLOCK: 0 + }; + + ka.CompressionType = lb.CompressionType = { + NONE: 0, + FIXED: 1, + DYNAMIC: 2 + }; + lb.compress = (d, a) => (new lb(d, a)).compress(); + + aa.Zlib = { + Inflate: jb, + Deflate: lb, + RawDeflate: ka, + RawInflate: U + }; + +})(this); },{}], 9:[function(_dereq_,module,exports){ @@ -3767,11 +4692,8 @@ h+4&&(this.a=new Uint8Array(g.length+4),this.a.set(g),g=this.a),g=g.subarray(0,h * @property {Integer} prefer_hash_algorithm * @property {Integer} encryption_cipher * @property {Integer} compression - * @property {Boolean} show_version - * @property {Boolean} show_comment * @property {Boolean} integrity_protect * @property {String} keyserver - * @property {Boolean} debug If enabled, debug messages will be printed * @module config/config */ @@ -3796,17 +4718,9 @@ exports.default = { ignore_mdc_error: false, // fail on decrypt if message is not integrity protected checksum_required: false, // do not throw error when armor is missing a checksum verify_expired_keys: true, // allow signature verification with expired keys - rsa_blinding: true, - use_native: true, // use native node.js crypto and Web Crypto apis (if available) zero_copy: false, // use transferable objects between the Web Worker and main thread - debug: false, tolerant: true, // ignore unsupported/unrecognizable packets instead of throwing an error - show_version: true, - show_comment: true, - versionstring: "OpenPGP.js v2.6.2", - commentstring: "https://openpgpjs.org", - keyserver: "https://keyserver.ubuntu.com", - node_store: './openpgp.store' + keyserver: "https://keyserver.ubuntu.com" }; },{"../enums.js":35}], @@ -6025,7 +6939,7 @@ exports.default = { Object.defineProperty(exports, "__esModule", { value: true }); -exports.ivLength = undefined; +exports.ivLength = 12; exports.encrypt = encrypt; exports.decrypt = decrypt; @@ -6033,10 +6947,6 @@ var _util = _dereq_('../util.js'); var _util2 = _interopRequireDefault(_util); -var _config = _dereq_('../config'); - -var _config2 = _interopRequireDefault(_config); - var _asmcryptoLite = _dereq_('asmcrypto-lite'); var _asmcryptoLite2 = _interopRequireDefault(_asmcryptoLite); @@ -6045,8 +6955,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var webCrypto = _util2.default.getWebCrypto(); // no GCM support in IE11, Safari 9 -var ivLength = exports.ivLength = 12; // size of the IV in bytes -var TAG_LEN = 16; // size of the tag in bytes var ALGO = 'AES-GCM'; /** @@ -6062,7 +6970,7 @@ function encrypt(cipher, plaintext, key, iv) { return Promise.reject(new Error('GCM mode supports only AES cipher')); } - if (webCrypto && _config2.default.use_native && key.length !== 24) { + if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support return webEncrypt(plaintext, key, iv); } @@ -6083,7 +6991,7 @@ function decrypt(cipher, ciphertext, key, iv) { return Promise.reject(new Error('GCM mode supports only AES cipher')); } - if (webCrypto && _config2.default.use_native && key.length !== 24) { + if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support return webDecrypt(ciphertext, key, iv); } @@ -6969,11 +7877,11 @@ function b642binb(str) { offset, b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - if (-1 === str.search(/^[a-zA-Z0-9=+\/]+$/)) { + if (-1 === str.search(/^[a-zA-Z0-9=+/]+$/)) { throw "Invalid character in base-64 string"; } firstEqual = str.indexOf('='); - str = str.replace(/\=/g, ''); + str = str.replace(/=/g, ''); if (-1 !== firstEqual && firstEqual < str.length) { throw "Invalid '=' found in base-64 string"; } @@ -8445,7 +9353,6 @@ function DSA() { } return usersetting; default: - _util2.default.print_debug("DSA select hash algorithm: returning null for an unknown length of q"); return null; } } @@ -8455,12 +9362,10 @@ function DSA() { 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 (_jsbn2.default.ZERO.compareTo(w) === 0) { - _util2.default.print_debug("invalid DSA Signature"); return null; } var u1 = hash.multiply(w).mod(q); @@ -8515,10 +9420,6 @@ var _random = _dereq_('../random.js'); var _random2 = _interopRequireDefault(_random); -var _util = _dereq_('../../util.js'); - -var _util2 = _interopRequireDefault(_util); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function Elgamal() { @@ -8535,7 +9436,6 @@ function Elgamal() { } function decrypt(c1, c2, p, x) { - _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); @@ -10135,7 +11035,7 @@ function bnpMillerRabin(t) { a.fromInt(j); var y = a.modPow(r, this); if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1; + j = 1; while (j++ < k && y.compareTo(n1) != 0) { y = y.modPowInt(2, this); if (y.compareTo(BigInteger.ONE) == 0) return false; @@ -10247,10 +11147,6 @@ var _random = _dereq_('../random.js'); var _random2 = _interopRequireDefault(_random); -var _config = _dereq_('../../config'); - -var _config2 = _interopRequireDefault(_config); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function SecureRandom() { @@ -10299,12 +11195,9 @@ function RSA() { * @return {BigInteger} The decrypted value of the message */ function decrypt(m, n, e, d, p, q, u) { - if (_config2.default.rsa_blinding) { - m = blind(m, n, e); - } + m = blind(m, n, e); 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) { @@ -10314,11 +11207,7 @@ function RSA() { } else { t = t.multiply(u).mod(q); } - t = t.multiply(p).add(xp); - if (_config2.default.rsa_blinding) { - t = unblind(t, n); - } - return t; + return unblind(t.multiply(p).add(xp), n); } /** @@ -10421,7 +11310,7 @@ function RSA() { key.u = key.p.modInverse(key.q); function toBigInteger(base64url) { - var base64 = base64url.replace(/\-/g, '+').replace(/_/g, '/'); + var base64 = base64url.replace(/-/g, '+').replace(/_/g, '/'); var hex = _util2.default.hexstrdump(atob(base64)); return new _jsbn2.default(hex, 16); } @@ -10925,25 +11814,6 @@ function getType(text) { } } -/** - * Add additional information to the armor version of an OpenPGP binary - * packet block. - * @author Alex - * @version 2011-12-16 - * @returns {String} The header information - */ -function addheader() { - var result = ""; - if (_config2.default.show_version) { - result += "Version: " + _config2.default.versionstring + '\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 @@ -11022,9 +11892,6 @@ function verifyHeaders(headers) { if (!/^([^\s:]|[^\s:][^:]*[^\s:]): .+$/.test(headers[i])) { throw new Error('Improperly formatted armor header: ' + headers[i]); } - if (_config2.default.debug && !/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) { - console.log('Unknown header: ' + headers[i]); - } } } @@ -11131,15 +11998,13 @@ function armor(messagetype, body, partindex, parttotal) { var result = []; switch (messagetype) { case _enums2.default.armor.multipart_section: - result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n"); - result.push(addheader()); + result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n\r\n"); 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 _enums2.default.armor.multipart_last: - result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n"); - result.push(addheader()); + result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n\r\n"); result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP MESSAGE, PART " + partindex + "-----\r\n"); @@ -11148,36 +12013,31 @@ function armor(messagetype, body, partindex, parttotal) { 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("\r\n-----BEGIN PGP SIGNATURE-----\r\n\r\n"); 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 _enums2.default.armor.message: - result.push("-----BEGIN PGP MESSAGE-----\r\n"); - result.push(addheader()); + result.push("-----BEGIN PGP MESSAGE-----\r\n\r\n"); result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP MESSAGE-----\r\n"); break; case _enums2.default.armor.public_key: - result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n"); - result.push(addheader()); + result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\r\n"); 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 _enums2.default.armor.private_key: - result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n"); - result.push(addheader()); + result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n\r\n"); result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP PRIVATE KEY BLOCK-----\r\n"); break; case _enums2.default.armor.signature: - result.push("-----BEGIN PGP SIGNATURE-----\r\n"); - result.push(addheader()); + result.push("-----BEGIN PGP SIGNATURE-----\r\n\r\n"); result.push(_base2.default.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP SIGNATURE-----\r\n"); @@ -12062,7 +12922,6 @@ Key.prototype.packetlist2structure = function (packetlist) { case _enums2.default.signature.cert_casual: case _enums2.default.signature.cert_positive: if (!user) { - _util2.default.print_debug('Dropping certification signatures without preceding user packet'); continue; } if (packetlist[i].issuerKeyId.equals(primaryKeyId)) { @@ -12098,7 +12957,6 @@ Key.prototype.packetlist2structure = function (packetlist) { break; case _enums2.default.signature.subkey_binding: if (!subKey) { - _util2.default.print_debug('Dropping subkey binding signature without preceding subkey packet'); continue; } subKey.bindingSignatures.push(packetlist[i]); @@ -12108,7 +12966,6 @@ Key.prototype.packetlist2structure = function (packetlist) { break; case _enums2.default.signature.subkey_revocation: if (!subKey) { - _util2.default.print_debug('Dropping subkey revocation signature without preceding subkey packet'); continue; } subKey.revocationSignature = packetlist[i]; @@ -13566,14 +14423,8 @@ var _key = _dereq_('../key.js'); var keyModule = _interopRequireWildcard(_key); -var _util = _dereq_('../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; @@ -13612,8 +14463,6 @@ function loadKeys(storage, itemname) { key = keyModule.readArmored(armoredKeys[i]); if (!key.err) { keys.push(key.keys[0]); - } else { - _util2.default.print_debug("Error reading armored key from keyring index: " + i); } } } @@ -14444,11 +15293,6 @@ function generateKey() { var options = formatUserIds({ userIds: userIds, passphrase: passphrase, numBits: numBits, unlocked: unlocked, keyExpirationTime: keyExpirationTime }); - if (!_util2.default.getWebCryptoAll() && asyncProxy) { - // use web worker if web crypto apis are not supported - return asyncProxy.delegate('generateKey', options); - } - return key.generate(options).then(function (newKey) { return { @@ -14967,13 +15811,10 @@ function execute(cmd, message) { * @param {Error} error The internal error that caused the failure */ function onError(message, error) { - // log the stack trace - if (_config2.default.debug) { - console.error(error.stack); - } - + console.error(message + ': ' + error.message); // update error message - error.message = message + ': ' + error.message; + // setting getter-only property "message" +// error.message = message + ': ' + error.message; throw error; } @@ -15417,8 +16258,6 @@ function packetlistCloneToSignature(clone) { * this packet is found as the contents of an encrypted packet, or following * a Signature or One-Pass Signature packet, and contains a literal data packet. * @requires compression/zlib - * @requires compression/rawinflate - * @requires compression/rawdeflate * @requires enums * @requires util * @module packet/compressed @@ -15443,14 +16282,6 @@ var _zlibMin = _dereq_('../compression/zlib.min.js'); var _zlibMin2 = _interopRequireDefault(_zlibMin); -var _rawinflateMin = _dereq_('../compression/rawinflate.min.js'); - -var _rawinflateMin2 = _interopRequireDefault(_rawinflateMin); - -var _rawdeflateMin = _dereq_('../compression/rawdeflate.min.js'); - -var _rawdeflateMin2 = _interopRequireDefault(_rawdeflateMin); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** @@ -15519,7 +16350,7 @@ Compressed.prototype.decompress = function () { break; case 'zip': - inflate = new _rawinflateMin2.default.Zlib.RawInflate(this.compressed); + inflate = new _zlibMin2.default.Zlib.RawInflate(this.compressed); decompressed = inflate.decompress(); break; @@ -15555,7 +16386,7 @@ Compressed.prototype.compress = function () { case 'zip': // - ZIP [RFC1951] - deflate = new _rawdeflateMin2.default.Zlib.RawDeflate(uncompressed); + deflate = new _zlibMin2.default.Zlib.RawDeflate(uncompressed); this.compressed = deflate.compress(); break; @@ -15575,7 +16406,7 @@ Compressed.prototype.compress = function () { } }; -},{"../compression/rawdeflate.min.js":6,"../compression/rawinflate.min.js":7,"../compression/zlib.min.js":8,"../enums.js":35,"../util.js":70}], +},{"../compression/zlib.min.js":8,"../enums.js":35,"../util.js":70}], 47:[function(_dereq_,module,exports){ 'use strict'; @@ -16151,15 +16982,12 @@ exports.default = { // 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)]; @@ -17468,11 +18296,6 @@ Signature.prototype.read = function (bytes) { // switch on version (3 and 4) switch (this.version) { case 3: - // One-octet length of following hashed material. MUST be 5. - 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[i++]; @@ -17827,8 +18650,6 @@ Signature.prototype.read_sub_packet = function (bytes) { this.notation = this.notation || {}; this.notation[name] = value; - } else { - _util2.default.print_debug("Unsupported notation flag " + bytes[mypos]); } break; case 21: @@ -17887,8 +18708,6 @@ Signature.prototype.read_sub_packet = function (bytes) { this.embeddedSignature = new Signature(); this.embeddedSignature.read(bytes.subarray(mypos, bytes.length)); break; - default: - _util2.default.print_debug("Unknown signature subpacket type " + type + " @:" + mypos); } }; @@ -19392,7 +20211,7 @@ exports.default = { 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,}))$/; + 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); }, @@ -19712,32 +20531,6 @@ exports.default = { return checksum.s; }, - /** - * Helper function to print a debug message. Debug - * messages are only printed if - * @link module:config/config.debug is set to true. - * @param {String} str String of the debug message - */ - print_debug: function print_debug(str) { - if (_config2.default.debug) { - console.log(str); - } - }, - - /** - * Helper function to print a debug message. Debug - * messages are only printed if - * @link module:config/config.debug is set to true. - * Different than print_debug because will call hexstrdump iff necessary. - * @param {String} str String of the debug message - */ - 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 getLeftNBits(string, bitcount) { var rest = bitcount % 8; if (rest === 0) { @@ -19796,30 +20589,20 @@ exports.default = { /** * Get native Web Cryptography api, only the current version of the spec. - * The default configuration is to use the api when available. But it can - * be deactivated with config.use_native + * The default configuration is to use the api when available. * @return {Object} The SubtleCrypto api or 'undefined' */ getWebCrypto: function getWebCrypto() { - if (!_config2.default.use_native) { - return; - } - return typeof window !== 'undefined' && window.crypto && window.crypto.subtle; }, /** * Get native Web Cryptography api for all browsers, including legacy * implementations of the spec e.g IE11 and Safari 8/9. The default - * configuration is to use the api when available. But it can be deactivated - * with config.use_native + * configuration is to use the api when available. * @return {Object} The SubtleCrypto api or 'undefined' */ getWebCryptoAll: function getWebCryptoAll() { - if (!_config2.default.use_native) { - return; - } - if (typeof window !== 'undefined') { if (window.crypto) { return window.crypto.subtle || window.crypto.webkitSubtle; diff --git a/vendors/openpgp-2.6.2/rollup.config.js b/vendors/openpgp-2.6.2/rollup.config.js new file mode 100644 index 000000000..deecb1e4f --- /dev/null +++ b/vendors/openpgp-2.6.2/rollup.config.js @@ -0,0 +1,56 @@ +/* +npm install rollup rollup-plugin-includepaths rollup-plugin-babel rollup-plugin-external-globals rollup-plugin-html rollup-plugin-terser +rollup -c +*/ + +import includePaths from 'rollup-plugin-includepaths'; +import { terser } from "rollup-plugin-terser"; +//import resolve from '@rollup/plugin-node-resolve'; +//import replace from '@rollup/plugin-replace'; +//import commonjs from '@rollup/plugin-commonjs'; + +let includePathOptions = { + include: {}, + paths: ['src'], + external: [], + extensions: ['.js'] +}; + +let terserConfig = { + output: { + comments: false + }, + keep_classnames: true, // Required for AbstractModel and AbstractCollectionModel + compress:{ + ecma: 6, + drop_console: true +/* + ,hoist_props: false + ,keep_fargs: false + ,toplevel: true + ,unsafe_arrows: true // Issue with knockoutjs + ,unsafe_methods: true + ,unsafe_proto: true +*/ + } +// ,mangle: {reserved:['SendMessage']} +}; + +export default [{ + input: 'src/index.js', + output: [ + {file: 'dist/snappymail/openpgp.js', format: 'iife'}, // format: 'es' + {file: 'dist/snappymail/openpgp.min.js', format: 'iife', plugins: [terser(terserConfig)], } + ], + plugins: [ + includePaths(includePathOptions) +// ,commonjs() +/* + replace({ + 'OpenPGP.js VERSION': `OpenPGP.js ${pkg.version}`, + 'require(': 'void(', + delimiters: ['', ''] + }) +*/ + ] +}]; diff --git a/vendors/openpgp-2.6.2/src/asmcrypto.js b/vendors/openpgp-2.6.2/src/asmcrypto.js new file mode 100644 index 000000000..06425e620 --- /dev/null +++ b/vendors/openpgp-2.6.2/src/asmcrypto.js @@ -0,0 +1,2898 @@ +/*! asmCrypto Lite v1.1.0, (c) 2013 Artem S Vybornov, opensource.org/licenses/MIT */ +(function ( exports, global ) { + +class IllegalStateError extends Error {} +class IllegalArgumentError extends Error {} +class SecurityError extends Error {} + +function string_to_bytes ( str, utf8 ) { + utf8 = !!utf8; + + var len = str.length, + bytes = new Uint8Array( utf8 ? 4*len : len ); + + for ( var i = 0, j = 0; i < len; i++ ) { + var c = str.charCodeAt(i); + + if ( utf8 && 0xd800 <= c && c <= 0xdbff ) { + if ( ++i >= 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 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 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 _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; + +/** + * Counter Mode (CTR) + */ + +function AES_CTR ( options ) { + this.nonce = null, + this.counter = 0, + this.counterSize = 0; + + AES.call( this, options ); + + this.mode = 'CTR'; +} + +function AES_CTR_Crypt ( options ) { + AES_CTR.call( this, options ); +} + +function AES_CTR_set_options ( nonce, counter, size ) { + if ( size !== undefined ) { + if ( size < 8 || size > 48 ) + throw new IllegalArgumentError("illegal counter size"); + + this.counterSize = size; + + var mask = Math.pow( 2, size ) - 1; + this.asm.set_mask( 0, 0, (mask / 0x100000000)|0, mask|0 ); + } + else { + this.counterSize = size = 48; + this.asm.set_mask( 0, 0, 0xffff, 0xffffffff ); + } + + if ( nonce !== undefined ) { + if ( is_buffer(nonce) || is_bytes(nonce) ) { + nonce = new Uint8Array(nonce); + } + else if ( is_string(nonce) ) { + nonce = string_to_bytes(nonce); + } + else { + throw new TypeError("unexpected nonce type"); + } + + var len = nonce.length; + if ( !len || len > 16 ) + throw new IllegalArgumentError("illegal nonce size"); + + this.nonce = nonce; + + var view = new DataView( new ArrayBuffer(16) ); + new Uint8Array(view.buffer).set(nonce); + + this.asm.set_nonce( view.getUint32(0), view.getUint32(4), view.getUint32(8), view.getUint32(12) ); + } + else { + throw new Error("nonce is required"); + } + + if ( counter !== undefined ) { + if ( !is_number(counter) ) + throw new TypeError("unexpected counter type"); + + if ( counter < 0 || counter >= Math.pow( 2, size ) ) + throw new IllegalArgumentError("illegal counter value"); + + this.counter = counter; + + this.asm.set_counter( 0, 0, (counter / 0x100000000)|0, counter|0 ); + } + else { + this.counter = counter = 0; + } +} + +function AES_CTR_reset ( options ) { + options = options || {}; + + AES_reset.call( this, options ); + + AES_CTR_set_options.call( this, options.nonce, options.counter, options.counterSize ); + + return this; +} + +var AES_CTR_prototype = AES_CTR.prototype; +AES_CTR_prototype.BLOCK_SIZE = 16; +AES_CTR_prototype.reset = AES_CTR_reset; +AES_CTR_prototype.encrypt = AES_Encrypt_finish; +AES_CTR_prototype.decrypt = AES_Encrypt_finish; + +var AES_CTR_Crypt_prototype = AES_CTR_Crypt.prototype; +AES_CTR_Crypt_prototype.BLOCK_SIZE = 16; +AES_CTR_Crypt_prototype.reset = AES_CTR_reset; +AES_CTR_Crypt_prototype.process = AES_Encrypt_process; +AES_CTR_Crypt_prototype.finish = AES_Encrypt_finish; + +/** + * Galois/Counter mode + */ + +var _AES_GCM_data_maxLength = 68719476704; // 2^36 - 2^5 + +function _gcm_mac_process ( data ) { + var heap = this.heap, + asm = this.asm, + dpos = 0, + dlen = data.length || 0, + wlen = 0; + + while ( dlen > 0 ) { + wlen = _heap_write( heap, 0, data, dpos, dlen ); + dpos += wlen; + dlen -= wlen; + + while ( wlen & 15 ) heap[ wlen++ ] = 0; + + asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, wlen ); + } +} + +function AES_GCM ( options ) { + this.nonce = null; + this.adata = null; + this.iv = null; + this.counter = 1; + this.tagSize = 16; + + AES.call( this, options ); + + this.mode = 'GCM'; +} + +function AES_GCM_Encrypt ( options ) { + AES_GCM.call( this, options ); +} + +function AES_GCM_Decrypt ( options ) { + AES_GCM.call( this, options ); +} + +function AES_GCM_reset ( options ) { + options = options || {}; + + AES_reset.call( this, options ); + + var asm = this.asm, + heap = this.heap; + + asm.gcm_init(); + + var tagSize = options.tagSize; + if ( tagSize !== undefined ) { + if ( !is_number(tagSize) ) + throw new TypeError("tagSize must be a number"); + + if ( tagSize < 4 || tagSize > 16 ) + throw new IllegalArgumentError("illegal tagSize value"); + + this.tagSize = tagSize; + } + else { + this.tagSize = 16; + } + + var nonce = options.nonce; + if ( nonce !== undefined ) { + if ( is_bytes(nonce) || is_buffer(nonce) ) { + nonce = new Uint8Array(nonce); + } + else if ( is_string(nonce) ) { + nonce = string_to_bytes(nonce); + } + else { + throw new TypeError("unexpected nonce type"); + } + + this.nonce = nonce; + + var noncelen = nonce.length || 0, + noncebuf = new Uint8Array(16); + if ( noncelen !== 12 ) { + _gcm_mac_process.call( this, nonce ); + + heap[0] = heap[1] = heap[2] = heap[3] = heap[4] = heap[5] = heap[6] = heap[7] = heap[8] = heap[9] = heap[10] = 0, + heap[11] = noncelen>>>29, + heap[12] = noncelen>>>21&255, + heap[13] = noncelen>>>13&255, + heap[14] = noncelen>>>5&255, + heap[15] = noncelen<<3&255; + asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, 16 ); + + asm.get_iv( AES_asm.HEAP_DATA ); + asm.set_iv(); + + noncebuf.set( heap.subarray( 0, 16 ) ); + } + else { + noncebuf.set(nonce); + noncebuf[15] = 1; + } + + var nonceview = new DataView( noncebuf.buffer ); + this.gamma0 = nonceview.getUint32(12); + + asm.set_nonce( nonceview.getUint32(0), nonceview.getUint32(4), nonceview.getUint32(8), 0 ); + asm.set_mask( 0, 0, 0, 0xffffffff ); + } + else { + throw new Error("nonce is required"); + } + + var adata = options.adata; + if ( adata !== undefined && adata !== null ) { + if ( is_bytes(adata) || is_buffer(adata) ) { + adata = new Uint8Array(adata); + } + else if ( is_string(adata) ) { + adata = string_to_bytes(adata); + } + else { + throw new TypeError("unexpected adata type"); + } + + if ( adata.length > _AES_GCM_data_maxLength ) + throw new IllegalArgumentError("illegal adata length"); + + if ( adata.length ) { + this.adata = adata; + _gcm_mac_process.call( this, adata ); + } + else { + this.adata = null; + } + } + else { + this.adata = null; + } + + var counter = options.counter; + if ( counter !== undefined ) { + if ( !is_number(counter) ) + throw new TypeError("counter must be a number"); + + if ( counter < 1 || counter > 0xffffffff ) + throw new RangeError("counter must be a positive 32-bit integer"); + + this.counter = counter; + asm.set_counter( 0, 0, 0, this.gamma0+counter|0 ); + } + else { + this.counter = 1; + asm.set_counter( 0, 0, 0, this.gamma0+1|0 ); + } + + var iv = options.iv; + if ( iv !== undefined ) { + if ( !is_number(counter) ) + throw new TypeError("counter must be a number"); + + this.iv = iv; + + AES_set_iv.call( this, iv ); + } + + return this; +} + +function AES_GCM_Encrypt_process ( data ) { + if ( is_string(data) ) + data = string_to_bytes(data); + + if ( is_buffer(data) ) + data = new Uint8Array(data); + + if ( !is_bytes(data) ) + throw new TypeError("data isn't of expected type"); + + var dpos = 0, + dlen = data.length || 0, + asm = this.asm, + heap = this.heap, + counter = this.counter, + pos = this.pos, + len = this.len, + rpos = 0, + rlen = ( len + dlen ) & -16, + wlen = 0; + + if ( ((counter-1)<<4) + len + dlen > _AES_GCM_data_maxLength ) + throw new RangeError("counter overflow"); + + var result = new Uint8Array(rlen); + + while ( dlen > 0 ) { + wlen = _heap_write( heap, pos+len, data, dpos, dlen ); + len += wlen; + dpos += wlen; + dlen -= wlen; + + wlen = asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA + pos, len ); + wlen = asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, wlen ); + + if ( wlen ) result.set( heap.subarray( pos, pos + wlen ), rpos ); + counter += (wlen>>>4); + rpos += wlen; + + if ( wlen < len ) { + pos += wlen; + len -= wlen; + } else { + pos = 0; + len = 0; + } + } + + this.result = result; + this.counter = counter; + this.pos = pos; + this.len = len; + + return this; +} + +function AES_GCM_Encrypt_finish () { + var asm = this.asm, + heap = this.heap, + counter = this.counter, + tagSize = this.tagSize, + adata = this.adata, + pos = this.pos, + len = this.len; + + var result = new Uint8Array( len + tagSize ); + + asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA + pos, (len + 15) & -16 ); + if ( len ) result.set( heap.subarray( pos, pos + len ) ); + + for ( var i = len; i & 15; i++ ) heap[ pos + i ] = 0; + asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, i ); + + var alen = ( adata !== null ) ? adata.length : 0, + clen = ( (counter-1) << 4) + len; + heap[0] = heap[1] = heap[2] = 0, + heap[3] = alen>>>29, + heap[4] = alen>>>21, + heap[5] = alen>>>13&255, + heap[6] = alen>>>5&255, + heap[7] = alen<<3&255, + heap[8] = heap[9] = heap[10] = 0, + heap[11] = clen>>>29, + heap[12] = clen>>>21&255, + heap[13] = clen>>>13&255, + heap[14] = clen>>>5&255, + heap[15] = clen<<3&255; + asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, 16 ); + asm.get_iv( AES_asm.HEAP_DATA ); + + asm.set_counter( 0, 0, 0, this.gamma0 ); + asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA, 16 ); + result.set( heap.subarray( 0, tagSize ), len ); + + this.result = result; + this.counter = 1; + this.pos = 0; + this.len = 0; + + return this; +} + +function AES_GCM_encrypt ( data ) { + var result1 = AES_GCM_Encrypt_process.call( this, data ).result, + result2 = AES_GCM_Encrypt_finish.call(this).result; + + var result = new Uint8Array( result1.length + result2.length ); + if ( result1.length ) result.set( result1 ); + if ( result2.length ) result.set( result2, result1.length ); + this.result = result; + + return this; +} + +function AES_GCM_Decrypt_process ( data ) { + if ( is_string(data) ) + data = string_to_bytes(data); + + if ( is_buffer(data) ) + data = new Uint8Array(data); + + if ( !is_bytes(data) ) + throw new TypeError("data isn't of expected type"); + + var dpos = 0, + dlen = data.length || 0, + asm = this.asm, + heap = this.heap, + counter = this.counter, + tagSize = this.tagSize, + pos = this.pos, + len = this.len, + rpos = 0, + rlen = len + dlen > tagSize ? ( len + dlen - tagSize ) & -16 : 0, + tlen = len + dlen - rlen, + wlen = 0; + + if ( ((counter-1)<<4) + len + dlen > _AES_GCM_data_maxLength ) + throw new RangeError("counter overflow"); + + var result = new Uint8Array(rlen); + + while ( dlen > tlen ) { + wlen = _heap_write( heap, pos+len, data, dpos, dlen-tlen ); + len += wlen; + dpos += wlen; + dlen -= wlen; + + wlen = asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, wlen ); + wlen = asm.cipher( AES_asm.DEC.CTR, AES_asm.HEAP_DATA + pos, wlen ); + + if ( wlen ) result.set( heap.subarray( pos, pos+wlen ), rpos ); + counter += (wlen>>>4); + rpos += wlen; + + pos = 0; + len = 0; + } + + if ( dlen > 0 ) { + len += _heap_write( heap, 0, data, dpos, dlen ); + } + + this.result = result; + this.counter = counter; + this.pos = pos; + this.len = len; + + return this; +} + +function AES_GCM_Decrypt_finish () { + var asm = this.asm, + heap = this.heap, + tagSize = this.tagSize, + adata = this.adata, + counter = this.counter, + pos = this.pos, + len = this.len, + rlen = len - tagSize, + wlen = 0; + + if ( len < tagSize ) + throw new IllegalStateError("authentication tag not found"); + + var result = new Uint8Array(rlen), + atag = new Uint8Array( heap.subarray( pos+rlen, pos+len ) ); + + for ( var i = rlen; i & 15; i++ ) heap[ pos + i ] = 0; + + wlen = asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, i ); + wlen = asm.cipher( AES_asm.DEC.CTR, AES_asm.HEAP_DATA + pos, i ); + if ( rlen ) result.set( heap.subarray( pos, pos+rlen ) ); + + var alen = ( adata !== null ) ? adata.length : 0, + clen = ( (counter-1) << 4) + len - tagSize; + heap[0] = heap[1] = heap[2] = 0, + heap[3] = alen>>>29, + heap[4] = alen>>>21, + heap[5] = alen>>>13&255, + heap[6] = alen>>>5&255, + heap[7] = alen<<3&255, + heap[8] = heap[9] = heap[10] = 0, + heap[11] = clen>>>29, + heap[12] = clen>>>21&255, + heap[13] = clen>>>13&255, + heap[14] = clen>>>5&255, + heap[15] = clen<<3&255; + asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA, 16 ); + asm.get_iv( AES_asm.HEAP_DATA ); + + asm.set_counter( 0, 0, 0, this.gamma0 ); + asm.cipher( AES_asm.ENC.CTR, AES_asm.HEAP_DATA, 16 ); + + var acheck = 0; + for ( var i = 0; i < tagSize; ++i ) acheck |= atag[i] ^ heap[i]; + if ( acheck ) + throw new SecurityError("data integrity check failed"); + + this.result = result; + this.counter = 1; + this.pos = 0; + this.len = 0; + + return this; +} + +function AES_GCM_decrypt ( data ) { + var result1 = AES_GCM_Decrypt_process.call( this, data ).result, + result2 = AES_GCM_Decrypt_finish.call( this ).result; + + var result = new Uint8Array( result1.length + result2.length ); + if ( result1.length ) result.set( result1 ); + if ( result2.length ) result.set( result2, result1.length ); + this.result = result; + + return this; +} + +var AES_GCM_prototype = AES_GCM.prototype; +AES_GCM_prototype.BLOCK_SIZE = 16; +AES_GCM_prototype.reset = AES_GCM_reset; +AES_GCM_prototype.encrypt = AES_GCM_encrypt; +AES_GCM_prototype.decrypt = AES_GCM_decrypt; + +var AES_GCM_Encrypt_prototype = AES_GCM_Encrypt.prototype; +AES_GCM_Encrypt_prototype.BLOCK_SIZE = 16; +AES_GCM_Encrypt_prototype.reset = AES_GCM_reset; +AES_GCM_Encrypt_prototype.process = AES_GCM_Encrypt_process; +AES_GCM_Encrypt_prototype.finish = AES_GCM_Encrypt_finish; + +var AES_GCM_Decrypt_prototype = AES_GCM_Decrypt.prototype; +AES_GCM_Decrypt_prototype.BLOCK_SIZE = 16; +AES_GCM_Decrypt_prototype.reset = AES_GCM_reset; +AES_GCM_Decrypt_prototype.process = AES_GCM_Decrypt_process; +AES_GCM_Decrypt_prototype.finish = AES_GCM_Decrypt_finish; + +// shared asm.js module and heap +var _AES_heap_instance = new Uint8Array(0x100000), + _AES_asm_instance = AES_asm( global, null, _AES_heap_instance.buffer ); + +/** + * AES-CFB exports + */ + +function AES_CFB_encrypt_bytes ( data, key, iv ) { + if ( data === undefined ) throw new SyntaxError("data required"); + if ( key === undefined ) throw new SyntaxError("key required"); + return new AES_CFB( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, iv: iv } ).encrypt(data).result; +} + +function AES_CFB_decrypt_bytes ( data, key, iv ) { + if ( data === undefined ) throw new SyntaxError("data required"); + if ( key === undefined ) throw new SyntaxError("key required"); + return new AES_CFB( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, iv: iv } ).decrypt(data).result; +} + +exports.AES_CFB = AES_CFB; +exports.AES_CFB.encrypt = AES_CFB_encrypt_bytes; +exports.AES_CFB.decrypt = AES_CFB_decrypt_bytes; + +exports.AES_CFB.Encrypt = AES_CFB_Encrypt; +exports.AES_CFB.Decrypt = AES_CFB_Decrypt; + +/** + * AES-GCM exports + */ + +function AES_GCM_encrypt_bytes ( data, key, nonce, adata, tagSize ) { + if ( data === undefined ) throw new SyntaxError("data required"); + if ( key === undefined ) throw new SyntaxError("key required"); + if ( nonce === undefined ) throw new SyntaxError("nonce required"); + return new AES_GCM( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, nonce: nonce, adata: adata, tagSize: tagSize } ).encrypt(data).result; +} + +function AES_GCM_decrypt_bytes ( data, key, nonce, adata, tagSize ) { + if ( data === undefined ) throw new SyntaxError("data required"); + if ( key === undefined ) throw new SyntaxError("key required"); + if ( nonce === undefined ) throw new SyntaxError("nonce required"); + return new AES_GCM( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, nonce: nonce, adata: adata, tagSize: tagSize } ).decrypt(data).result; +} + +exports.AES_GCM = AES_GCM; +exports.AES_GCM.encrypt = AES_GCM_encrypt_bytes; +exports.AES_GCM.decrypt = AES_GCM_decrypt_bytes; + +exports.AES_GCM.Encrypt = AES_GCM_Encrypt; +exports.AES_GCM.Decrypt = AES_GCM_Decrypt; + +function hash_reset () { + this.result = null; + this.pos = 0; + this.len = 0; + + this.asm.reset(); + + return this; +} + +function hash_process ( data ) { + if ( this.result !== null ) + throw new IllegalStateError("state must be reset before processing new data"); + + if ( is_string(data) ) + data = string_to_bytes(data); + + if ( is_buffer(data) ) + data = new Uint8Array(data); + + if ( !is_bytes(data) ) + throw new TypeError("data isn't of expected type"); + + var asm = this.asm, + heap = this.heap, + hpos = this.pos, + hlen = this.len, + dpos = 0, + dlen = data.length, + wlen = 0; + + while ( dlen > 0 ) { + wlen = _heap_write( heap, hpos+hlen, data, dpos, dlen ); + hlen += wlen; + dpos += wlen; + dlen -= wlen; + + wlen = asm.process( hpos, hlen ); + + hpos += wlen; + hlen -= wlen; + + if ( !hlen ) hpos = 0; + } + + this.pos = hpos; + this.len = hlen; + + return this; +} + +function hash_finish () { + if ( this.result !== null ) + throw new IllegalStateError("state must be reset before processing new data"); + + this.asm.finish( this.pos, this.len, 0 ); + + this.result = new Uint8Array(this.HASH_SIZE); + this.result.set( this.heap.subarray( 0, this.HASH_SIZE ) ); + + this.pos = 0; + this.len = 0; + + return this; +} + +function sha256_asm ( stdlib, foreign, buffer ) { + "use asm"; + + // SHA256 state + var H0 = 0, H1 = 0, H2 = 0, H3 = 0, H4 = 0, H5 = 0, H6 = 0, H7 = 0, + TOTAL0 = 0, TOTAL1 = 0; + + // HMAC state + var I0 = 0, I1 = 0, I2 = 0, I3 = 0, I4 = 0, I5 = 0, I6 = 0, I7 = 0, + O0 = 0, O1 = 0, O2 = 0, O3 = 0, O4 = 0, O5 = 0, O6 = 0, O7 = 0; + + // I/O buffer + var HEAP = new stdlib.Uint8Array(buffer); + + function _core ( w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15 ) { + w0 = w0|0; + w1 = w1|0; + w2 = w2|0; + w3 = w3|0; + w4 = w4|0; + w5 = w5|0; + w6 = w6|0; + w7 = w7|0; + w8 = w8|0; + w9 = w9|0; + w10 = w10|0; + w11 = w11|0; + w12 = w12|0; + w13 = w13|0; + w14 = w14|0; + w15 = w15|0; + + var a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, + t = 0; + + a = H0; + b = H1; + c = H2; + d = H3; + e = H4; + f = H5; + g = H6; + h = H7; + + // 0 + t = ( w0 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x428a2f98 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 1 + t = ( w1 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x71374491 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 2 + t = ( w2 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xb5c0fbcf )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 3 + t = ( w3 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xe9b5dba5 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 4 + t = ( w4 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x3956c25b )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 5 + t = ( w5 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x59f111f1 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 6 + t = ( w6 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x923f82a4 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 7 + t = ( w7 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xab1c5ed5 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 8 + t = ( w8 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd807aa98 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 9 + t = ( w9 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x12835b01 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 10 + t = ( w10 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x243185be )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 11 + t = ( w11 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x550c7dc3 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 12 + t = ( w12 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x72be5d74 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 13 + t = ( w13 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x80deb1fe )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 14 + t = ( w14 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x9bdc06a7 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 15 + t = ( w15 + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc19bf174 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 16 + w0 = t = ( ( w1>>>7 ^ w1>>>18 ^ w1>>>3 ^ w1<<25 ^ w1<<14 ) + ( w14>>>17 ^ w14>>>19 ^ w14>>>10 ^ w14<<15 ^ w14<<13 ) + w0 + w9 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xe49b69c1 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 17 + w1 = t = ( ( w2>>>7 ^ w2>>>18 ^ w2>>>3 ^ w2<<25 ^ w2<<14 ) + ( w15>>>17 ^ w15>>>19 ^ w15>>>10 ^ w15<<15 ^ w15<<13 ) + w1 + w10 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xefbe4786 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 18 + w2 = t = ( ( w3>>>7 ^ w3>>>18 ^ w3>>>3 ^ w3<<25 ^ w3<<14 ) + ( w0>>>17 ^ w0>>>19 ^ w0>>>10 ^ w0<<15 ^ w0<<13 ) + w2 + w11 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x0fc19dc6 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 19 + w3 = t = ( ( w4>>>7 ^ w4>>>18 ^ w4>>>3 ^ w4<<25 ^ w4<<14 ) + ( w1>>>17 ^ w1>>>19 ^ w1>>>10 ^ w1<<15 ^ w1<<13 ) + w3 + w12 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x240ca1cc )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 20 + w4 = t = ( ( w5>>>7 ^ w5>>>18 ^ w5>>>3 ^ w5<<25 ^ w5<<14 ) + ( w2>>>17 ^ w2>>>19 ^ w2>>>10 ^ w2<<15 ^ w2<<13 ) + w4 + w13 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x2de92c6f )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 21 + w5 = t = ( ( w6>>>7 ^ w6>>>18 ^ w6>>>3 ^ w6<<25 ^ w6<<14 ) + ( w3>>>17 ^ w3>>>19 ^ w3>>>10 ^ w3<<15 ^ w3<<13 ) + w5 + w14 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x4a7484aa )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 22 + w6 = t = ( ( w7>>>7 ^ w7>>>18 ^ w7>>>3 ^ w7<<25 ^ w7<<14 ) + ( w4>>>17 ^ w4>>>19 ^ w4>>>10 ^ w4<<15 ^ w4<<13 ) + w6 + w15 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x5cb0a9dc )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 23 + w7 = t = ( ( w8>>>7 ^ w8>>>18 ^ w8>>>3 ^ w8<<25 ^ w8<<14 ) + ( w5>>>17 ^ w5>>>19 ^ w5>>>10 ^ w5<<15 ^ w5<<13 ) + w7 + w0 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x76f988da )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 24 + w8 = t = ( ( w9>>>7 ^ w9>>>18 ^ w9>>>3 ^ w9<<25 ^ w9<<14 ) + ( w6>>>17 ^ w6>>>19 ^ w6>>>10 ^ w6<<15 ^ w6<<13 ) + w8 + w1 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x983e5152 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 25 + w9 = t = ( ( w10>>>7 ^ w10>>>18 ^ w10>>>3 ^ w10<<25 ^ w10<<14 ) + ( w7>>>17 ^ w7>>>19 ^ w7>>>10 ^ w7<<15 ^ w7<<13 ) + w9 + w2 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa831c66d )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 26 + w10 = t = ( ( w11>>>7 ^ w11>>>18 ^ w11>>>3 ^ w11<<25 ^ w11<<14 ) + ( w8>>>17 ^ w8>>>19 ^ w8>>>10 ^ w8<<15 ^ w8<<13 ) + w10 + w3 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xb00327c8 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 27 + w11 = t = ( ( w12>>>7 ^ w12>>>18 ^ w12>>>3 ^ w12<<25 ^ w12<<14 ) + ( w9>>>17 ^ w9>>>19 ^ w9>>>10 ^ w9<<15 ^ w9<<13 ) + w11 + w4 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xbf597fc7 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 28 + w12 = t = ( ( w13>>>7 ^ w13>>>18 ^ w13>>>3 ^ w13<<25 ^ w13<<14 ) + ( w10>>>17 ^ w10>>>19 ^ w10>>>10 ^ w10<<15 ^ w10<<13 ) + w12 + w5 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc6e00bf3 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 29 + w13 = t = ( ( w14>>>7 ^ w14>>>18 ^ w14>>>3 ^ w14<<25 ^ w14<<14 ) + ( w11>>>17 ^ w11>>>19 ^ w11>>>10 ^ w11<<15 ^ w11<<13 ) + w13 + w6 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd5a79147 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 30 + w14 = t = ( ( w15>>>7 ^ w15>>>18 ^ w15>>>3 ^ w15<<25 ^ w15<<14 ) + ( w12>>>17 ^ w12>>>19 ^ w12>>>10 ^ w12<<15 ^ w12<<13 ) + w14 + w7 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x06ca6351 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 31 + w15 = t = ( ( w0>>>7 ^ w0>>>18 ^ w0>>>3 ^ w0<<25 ^ w0<<14 ) + ( w13>>>17 ^ w13>>>19 ^ w13>>>10 ^ w13<<15 ^ w13<<13 ) + w15 + w8 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x14292967 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 32 + w0 = t = ( ( w1>>>7 ^ w1>>>18 ^ w1>>>3 ^ w1<<25 ^ w1<<14 ) + ( w14>>>17 ^ w14>>>19 ^ w14>>>10 ^ w14<<15 ^ w14<<13 ) + w0 + w9 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x27b70a85 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 33 + w1 = t = ( ( w2>>>7 ^ w2>>>18 ^ w2>>>3 ^ w2<<25 ^ w2<<14 ) + ( w15>>>17 ^ w15>>>19 ^ w15>>>10 ^ w15<<15 ^ w15<<13 ) + w1 + w10 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x2e1b2138 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 34 + w2 = t = ( ( w3>>>7 ^ w3>>>18 ^ w3>>>3 ^ w3<<25 ^ w3<<14 ) + ( w0>>>17 ^ w0>>>19 ^ w0>>>10 ^ w0<<15 ^ w0<<13 ) + w2 + w11 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x4d2c6dfc )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 35 + w3 = t = ( ( w4>>>7 ^ w4>>>18 ^ w4>>>3 ^ w4<<25 ^ w4<<14 ) + ( w1>>>17 ^ w1>>>19 ^ w1>>>10 ^ w1<<15 ^ w1<<13 ) + w3 + w12 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x53380d13 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 36 + w4 = t = ( ( w5>>>7 ^ w5>>>18 ^ w5>>>3 ^ w5<<25 ^ w5<<14 ) + ( w2>>>17 ^ w2>>>19 ^ w2>>>10 ^ w2<<15 ^ w2<<13 ) + w4 + w13 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x650a7354 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 37 + w5 = t = ( ( w6>>>7 ^ w6>>>18 ^ w6>>>3 ^ w6<<25 ^ w6<<14 ) + ( w3>>>17 ^ w3>>>19 ^ w3>>>10 ^ w3<<15 ^ w3<<13 ) + w5 + w14 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x766a0abb )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 38 + w6 = t = ( ( w7>>>7 ^ w7>>>18 ^ w7>>>3 ^ w7<<25 ^ w7<<14 ) + ( w4>>>17 ^ w4>>>19 ^ w4>>>10 ^ w4<<15 ^ w4<<13 ) + w6 + w15 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x81c2c92e )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 39 + w7 = t = ( ( w8>>>7 ^ w8>>>18 ^ w8>>>3 ^ w8<<25 ^ w8<<14 ) + ( w5>>>17 ^ w5>>>19 ^ w5>>>10 ^ w5<<15 ^ w5<<13 ) + w7 + w0 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x92722c85 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 40 + w8 = t = ( ( w9>>>7 ^ w9>>>18 ^ w9>>>3 ^ w9<<25 ^ w9<<14 ) + ( w6>>>17 ^ w6>>>19 ^ w6>>>10 ^ w6<<15 ^ w6<<13 ) + w8 + w1 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa2bfe8a1 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 41 + w9 = t = ( ( w10>>>7 ^ w10>>>18 ^ w10>>>3 ^ w10<<25 ^ w10<<14 ) + ( w7>>>17 ^ w7>>>19 ^ w7>>>10 ^ w7<<15 ^ w7<<13 ) + w9 + w2 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa81a664b )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 42 + w10 = t = ( ( w11>>>7 ^ w11>>>18 ^ w11>>>3 ^ w11<<25 ^ w11<<14 ) + ( w8>>>17 ^ w8>>>19 ^ w8>>>10 ^ w8<<15 ^ w8<<13 ) + w10 + w3 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc24b8b70 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 43 + w11 = t = ( ( w12>>>7 ^ w12>>>18 ^ w12>>>3 ^ w12<<25 ^ w12<<14 ) + ( w9>>>17 ^ w9>>>19 ^ w9>>>10 ^ w9<<15 ^ w9<<13 ) + w11 + w4 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc76c51a3 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 44 + w12 = t = ( ( w13>>>7 ^ w13>>>18 ^ w13>>>3 ^ w13<<25 ^ w13<<14 ) + ( w10>>>17 ^ w10>>>19 ^ w10>>>10 ^ w10<<15 ^ w10<<13 ) + w12 + w5 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd192e819 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 45 + w13 = t = ( ( w14>>>7 ^ w14>>>18 ^ w14>>>3 ^ w14<<25 ^ w14<<14 ) + ( w11>>>17 ^ w11>>>19 ^ w11>>>10 ^ w11<<15 ^ w11<<13 ) + w13 + w6 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xd6990624 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 46 + w14 = t = ( ( w15>>>7 ^ w15>>>18 ^ w15>>>3 ^ w15<<25 ^ w15<<14 ) + ( w12>>>17 ^ w12>>>19 ^ w12>>>10 ^ w12<<15 ^ w12<<13 ) + w14 + w7 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xf40e3585 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 47 + w15 = t = ( ( w0>>>7 ^ w0>>>18 ^ w0>>>3 ^ w0<<25 ^ w0<<14 ) + ( w13>>>17 ^ w13>>>19 ^ w13>>>10 ^ w13<<15 ^ w13<<13 ) + w15 + w8 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x106aa070 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 48 + w0 = t = ( ( w1>>>7 ^ w1>>>18 ^ w1>>>3 ^ w1<<25 ^ w1<<14 ) + ( w14>>>17 ^ w14>>>19 ^ w14>>>10 ^ w14<<15 ^ w14<<13 ) + w0 + w9 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x19a4c116 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 49 + w1 = t = ( ( w2>>>7 ^ w2>>>18 ^ w2>>>3 ^ w2<<25 ^ w2<<14 ) + ( w15>>>17 ^ w15>>>19 ^ w15>>>10 ^ w15<<15 ^ w15<<13 ) + w1 + w10 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x1e376c08 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 50 + w2 = t = ( ( w3>>>7 ^ w3>>>18 ^ w3>>>3 ^ w3<<25 ^ w3<<14 ) + ( w0>>>17 ^ w0>>>19 ^ w0>>>10 ^ w0<<15 ^ w0<<13 ) + w2 + w11 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x2748774c )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 51 + w3 = t = ( ( w4>>>7 ^ w4>>>18 ^ w4>>>3 ^ w4<<25 ^ w4<<14 ) + ( w1>>>17 ^ w1>>>19 ^ w1>>>10 ^ w1<<15 ^ w1<<13 ) + w3 + w12 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x34b0bcb5 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 52 + w4 = t = ( ( w5>>>7 ^ w5>>>18 ^ w5>>>3 ^ w5<<25 ^ w5<<14 ) + ( w2>>>17 ^ w2>>>19 ^ w2>>>10 ^ w2<<15 ^ w2<<13 ) + w4 + w13 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x391c0cb3 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 53 + w5 = t = ( ( w6>>>7 ^ w6>>>18 ^ w6>>>3 ^ w6<<25 ^ w6<<14 ) + ( w3>>>17 ^ w3>>>19 ^ w3>>>10 ^ w3<<15 ^ w3<<13 ) + w5 + w14 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x4ed8aa4a )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 54 + w6 = t = ( ( w7>>>7 ^ w7>>>18 ^ w7>>>3 ^ w7<<25 ^ w7<<14 ) + ( w4>>>17 ^ w4>>>19 ^ w4>>>10 ^ w4<<15 ^ w4<<13 ) + w6 + w15 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x5b9cca4f )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 55 + w7 = t = ( ( w8>>>7 ^ w8>>>18 ^ w8>>>3 ^ w8<<25 ^ w8<<14 ) + ( w5>>>17 ^ w5>>>19 ^ w5>>>10 ^ w5<<15 ^ w5<<13 ) + w7 + w0 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x682e6ff3 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 56 + w8 = t = ( ( w9>>>7 ^ w9>>>18 ^ w9>>>3 ^ w9<<25 ^ w9<<14 ) + ( w6>>>17 ^ w6>>>19 ^ w6>>>10 ^ w6<<15 ^ w6<<13 ) + w8 + w1 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x748f82ee )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 57 + w9 = t = ( ( w10>>>7 ^ w10>>>18 ^ w10>>>3 ^ w10<<25 ^ w10<<14 ) + ( w7>>>17 ^ w7>>>19 ^ w7>>>10 ^ w7<<15 ^ w7<<13 ) + w9 + w2 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x78a5636f )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 58 + w10 = t = ( ( w11>>>7 ^ w11>>>18 ^ w11>>>3 ^ w11<<25 ^ w11<<14 ) + ( w8>>>17 ^ w8>>>19 ^ w8>>>10 ^ w8<<15 ^ w8<<13 ) + w10 + w3 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x84c87814 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 59 + w11 = t = ( ( w12>>>7 ^ w12>>>18 ^ w12>>>3 ^ w12<<25 ^ w12<<14 ) + ( w9>>>17 ^ w9>>>19 ^ w9>>>10 ^ w9<<15 ^ w9<<13 ) + w11 + w4 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x8cc70208 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 60 + w12 = t = ( ( w13>>>7 ^ w13>>>18 ^ w13>>>3 ^ w13<<25 ^ w13<<14 ) + ( w10>>>17 ^ w10>>>19 ^ w10>>>10 ^ w10<<15 ^ w10<<13 ) + w12 + w5 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0x90befffa )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 61 + w13 = t = ( ( w14>>>7 ^ w14>>>18 ^ w14>>>3 ^ w14<<25 ^ w14<<14 ) + ( w11>>>17 ^ w11>>>19 ^ w11>>>10 ^ w11<<15 ^ w11<<13 ) + w13 + w6 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xa4506ceb )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 62 + w14 = t = ( ( w15>>>7 ^ w15>>>18 ^ w15>>>3 ^ w15<<25 ^ w15<<14 ) + ( w12>>>17 ^ w12>>>19 ^ w12>>>10 ^ w12<<15 ^ w12<<13 ) + w14 + w7 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xbef9a3f7 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + // 63 + w15 = t = ( ( w0>>>7 ^ w0>>>18 ^ w0>>>3 ^ w0<<25 ^ w0<<14 ) + ( w13>>>17 ^ w13>>>19 ^ w13>>>10 ^ w13<<15 ^ w13<<13 ) + w15 + w8 )|0; + t = ( t + h + ( e>>>6 ^ e>>>11 ^ e>>>25 ^ e<<26 ^ e<<21 ^ e<<7 ) + ( g ^ e & (f^g) ) + 0xc67178f2 )|0; + h = g; g = f; f = e; e = ( d + t )|0; d = c; c = b; b = a; + a = ( t + ( (b & c) ^ ( d & (b ^ c) ) ) + ( b>>>2 ^ b>>>13 ^ b>>>22 ^ b<<30 ^ b<<19 ^ b<<10 ) )|0; + + H0 = ( H0 + a )|0; + H1 = ( H1 + b )|0; + H2 = ( H2 + c )|0; + H3 = ( H3 + d )|0; + H4 = ( H4 + e )|0; + H5 = ( H5 + f )|0; + H6 = ( H6 + g )|0; + H7 = ( H7 + h )|0; + } + + function _core_heap ( offset ) { + offset = offset|0; + + _core( + HEAP[offset|0]<<24 | HEAP[offset|1]<<16 | HEAP[offset|2]<<8 | HEAP[offset|3], + HEAP[offset|4]<<24 | HEAP[offset|5]<<16 | HEAP[offset|6]<<8 | HEAP[offset|7], + HEAP[offset|8]<<24 | HEAP[offset|9]<<16 | HEAP[offset|10]<<8 | HEAP[offset|11], + HEAP[offset|12]<<24 | HEAP[offset|13]<<16 | HEAP[offset|14]<<8 | HEAP[offset|15], + HEAP[offset|16]<<24 | HEAP[offset|17]<<16 | HEAP[offset|18]<<8 | HEAP[offset|19], + HEAP[offset|20]<<24 | HEAP[offset|21]<<16 | HEAP[offset|22]<<8 | HEAP[offset|23], + HEAP[offset|24]<<24 | HEAP[offset|25]<<16 | HEAP[offset|26]<<8 | HEAP[offset|27], + HEAP[offset|28]<<24 | HEAP[offset|29]<<16 | HEAP[offset|30]<<8 | HEAP[offset|31], + HEAP[offset|32]<<24 | HEAP[offset|33]<<16 | HEAP[offset|34]<<8 | HEAP[offset|35], + HEAP[offset|36]<<24 | HEAP[offset|37]<<16 | HEAP[offset|38]<<8 | HEAP[offset|39], + HEAP[offset|40]<<24 | HEAP[offset|41]<<16 | HEAP[offset|42]<<8 | HEAP[offset|43], + HEAP[offset|44]<<24 | HEAP[offset|45]<<16 | HEAP[offset|46]<<8 | HEAP[offset|47], + HEAP[offset|48]<<24 | HEAP[offset|49]<<16 | HEAP[offset|50]<<8 | HEAP[offset|51], + HEAP[offset|52]<<24 | HEAP[offset|53]<<16 | HEAP[offset|54]<<8 | HEAP[offset|55], + HEAP[offset|56]<<24 | HEAP[offset|57]<<16 | HEAP[offset|58]<<8 | HEAP[offset|59], + HEAP[offset|60]<<24 | HEAP[offset|61]<<16 | HEAP[offset|62]<<8 | HEAP[offset|63] + ); + } + + // offset — multiple of 32 + function _state_to_heap ( output ) { + output = output|0; + + HEAP[output|0] = H0>>>24; + HEAP[output|1] = H0>>>16&255; + HEAP[output|2] = H0>>>8&255; + HEAP[output|3] = H0&255; + HEAP[output|4] = H1>>>24; + HEAP[output|5] = H1>>>16&255; + HEAP[output|6] = H1>>>8&255; + HEAP[output|7] = H1&255; + HEAP[output|8] = H2>>>24; + HEAP[output|9] = H2>>>16&255; + HEAP[output|10] = H2>>>8&255; + HEAP[output|11] = H2&255; + HEAP[output|12] = H3>>>24; + HEAP[output|13] = H3>>>16&255; + HEAP[output|14] = H3>>>8&255; + HEAP[output|15] = H3&255; + HEAP[output|16] = H4>>>24; + HEAP[output|17] = H4>>>16&255; + HEAP[output|18] = H4>>>8&255; + HEAP[output|19] = H4&255; + HEAP[output|20] = H5>>>24; + HEAP[output|21] = H5>>>16&255; + HEAP[output|22] = H5>>>8&255; + HEAP[output|23] = H5&255; + HEAP[output|24] = H6>>>24; + HEAP[output|25] = H6>>>16&255; + HEAP[output|26] = H6>>>8&255; + HEAP[output|27] = H6&255; + HEAP[output|28] = H7>>>24; + HEAP[output|29] = H7>>>16&255; + HEAP[output|30] = H7>>>8&255; + HEAP[output|31] = H7&255; + } + + function reset () { + H0 = 0x6a09e667; + H1 = 0xbb67ae85; + H2 = 0x3c6ef372; + H3 = 0xa54ff53a; + H4 = 0x510e527f; + H5 = 0x9b05688c; + H6 = 0x1f83d9ab; + H7 = 0x5be0cd19; + TOTAL0 = TOTAL1 = 0; + } + + function init ( h0, h1, h2, h3, h4, h5, h6, h7, total0, total1 ) { + h0 = h0|0; + h1 = h1|0; + h2 = h2|0; + h3 = h3|0; + h4 = h4|0; + h5 = h5|0; + h6 = h6|0; + h7 = h7|0; + total0 = total0|0; + total1 = total1|0; + + H0 = h0; + H1 = h1; + H2 = h2; + H3 = h3; + H4 = h4; + H5 = h5; + H6 = h6; + H7 = h7; + TOTAL0 = total0; + TOTAL1 = total1; + } + + // offset — multiple of 64 + function process ( offset, length ) { + offset = offset|0; + length = length|0; + + var hashed = 0; + + if ( offset & 63 ) + return -1; + + while ( (length|0) >= 64 ) { + _core_heap(offset); + + offset = ( offset + 64 )|0; + length = ( length - 64 )|0; + + hashed = ( hashed + 64 )|0; + } + + TOTAL0 = ( TOTAL0 + hashed )|0; + if ( TOTAL0>>>0 < hashed>>>0 ) TOTAL1 = ( TOTAL1 + 1 )|0; + + return hashed|0; + } + + // offset — multiple of 64 + // output — multiple of 32 + function finish ( offset, length, output ) { + offset = offset|0; + length = length|0; + output = output|0; + + var hashed = 0, + i = 0; + + if ( offset & 63 ) + return -1; + + if ( ~output ) + if ( output & 31 ) + return -1; + + if ( (length|0) >= 64 ) { + hashed = process( offset, length )|0; + if ( (hashed|0) == -1 ) + return -1; + + offset = ( offset + hashed )|0; + length = ( length - hashed )|0; + } + + hashed = ( hashed + length )|0; + TOTAL0 = ( TOTAL0 + length )|0; + if ( TOTAL0>>>0 < length>>>0 ) TOTAL1 = ( TOTAL1 + 1 )|0; + + HEAP[offset|length] = 0x80; + + if ( (length|0) >= 56 ) { + for ( i = (length+1)|0; (i|0) < 64; i = (i+1)|0 ) + HEAP[offset|i] = 0x00; + + _core_heap(offset); + + length = 0; + + HEAP[offset|0] = 0; + } + + for ( i = (length+1)|0; (i|0) < 59; i = (i+1)|0 ) + HEAP[offset|i] = 0; + + HEAP[offset|56] = TOTAL1>>>21&255; + HEAP[offset|57] = TOTAL1>>>13&255; + HEAP[offset|58] = TOTAL1>>>5&255; + HEAP[offset|59] = TOTAL1<<3&255 | TOTAL0>>>29; + HEAP[offset|60] = TOTAL0>>>21&255; + HEAP[offset|61] = TOTAL0>>>13&255; + HEAP[offset|62] = TOTAL0>>>5&255; + HEAP[offset|63] = TOTAL0<<3&255; + _core_heap(offset); + + if ( ~output ) + _state_to_heap(output); + + return hashed|0; + } + + function hmac_reset () { + H0 = I0; + H1 = I1; + H2 = I2; + H3 = I3; + H4 = I4; + H5 = I5; + H6 = I6; + H7 = I7; + TOTAL0 = 64; + TOTAL1 = 0; + } + + function _hmac_opad () { + H0 = O0; + H1 = O1; + H2 = O2; + H3 = O3; + H4 = O4; + H5 = O5; + H6 = O6; + H7 = O7; + TOTAL0 = 64; + TOTAL1 = 0; + } + + function hmac_init ( p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15 ) { + p0 = p0|0; + p1 = p1|0; + p2 = p2|0; + p3 = p3|0; + p4 = p4|0; + p5 = p5|0; + p6 = p6|0; + p7 = p7|0; + p8 = p8|0; + p9 = p9|0; + p10 = p10|0; + p11 = p11|0; + p12 = p12|0; + p13 = p13|0; + p14 = p14|0; + p15 = p15|0; + + // opad + reset(); + _core( + p0 ^ 0x5c5c5c5c, + p1 ^ 0x5c5c5c5c, + p2 ^ 0x5c5c5c5c, + p3 ^ 0x5c5c5c5c, + p4 ^ 0x5c5c5c5c, + p5 ^ 0x5c5c5c5c, + p6 ^ 0x5c5c5c5c, + p7 ^ 0x5c5c5c5c, + p8 ^ 0x5c5c5c5c, + p9 ^ 0x5c5c5c5c, + p10 ^ 0x5c5c5c5c, + p11 ^ 0x5c5c5c5c, + p12 ^ 0x5c5c5c5c, + p13 ^ 0x5c5c5c5c, + p14 ^ 0x5c5c5c5c, + p15 ^ 0x5c5c5c5c + ); + O0 = H0; + O1 = H1; + O2 = H2; + O3 = H3; + O4 = H4; + O5 = H5; + O6 = H6; + O7 = H7; + + // ipad + reset(); + _core( + p0 ^ 0x36363636, + p1 ^ 0x36363636, + p2 ^ 0x36363636, + p3 ^ 0x36363636, + p4 ^ 0x36363636, + p5 ^ 0x36363636, + p6 ^ 0x36363636, + p7 ^ 0x36363636, + p8 ^ 0x36363636, + p9 ^ 0x36363636, + p10 ^ 0x36363636, + p11 ^ 0x36363636, + p12 ^ 0x36363636, + p13 ^ 0x36363636, + p14 ^ 0x36363636, + p15 ^ 0x36363636 + ); + I0 = H0; + I1 = H1; + I2 = H2; + I3 = H3; + I4 = H4; + I5 = H5; + I6 = H6; + I7 = H7; + + TOTAL0 = 64; + TOTAL1 = 0; + } + + // offset — multiple of 64 + // output — multiple of 32 + function hmac_finish ( offset, length, output ) { + offset = offset|0; + length = length|0; + output = output|0; + + var t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + hashed = 0; + + if ( offset & 63 ) + return -1; + + if ( ~output ) + if ( output & 31 ) + return -1; + + hashed = finish( offset, length, -1 )|0; + t0 = H0, t1 = H1, t2 = H2, t3 = H3, t4 = H4, t5 = H5, t6 = H6, t7 = H7; + + _hmac_opad(); + _core( t0, t1, t2, t3, t4, t5, t6, t7, 0x80000000, 0, 0, 0, 0, 0, 0, 768 ); + + if ( ~output ) + _state_to_heap(output); + + return hashed|0; + } + + // salt is assumed to be already processed + // offset — multiple of 64 + // output — multiple of 32 + function pbkdf2_generate_block ( offset, length, block, count, output ) { + offset = offset|0; + length = length|0; + block = block|0; + count = count|0; + output = output|0; + + var h0 = 0, h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0, h7 = 0, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0; + + if ( offset & 63 ) + return -1; + + if ( ~output ) + if ( output & 31 ) + return -1; + + // pad block number into heap + // FIXME probable OOB write + HEAP[(offset+length)|0] = block>>>24; + HEAP[(offset+length+1)|0] = block>>>16&255; + HEAP[(offset+length+2)|0] = block>>>8&255; + HEAP[(offset+length+3)|0] = block&255; + + // finish first iteration + hmac_finish( offset, (length+4)|0, -1 )|0; + h0 = t0 = H0, h1 = t1 = H1, h2 = t2 = H2, h3 = t3 = H3, h4 = t4 = H4, h5 = t5 = H5, h6 = t6 = H6, h7 = t7 = H7; + count = (count-1)|0; + + // perform the rest iterations + while ( (count|0) > 0 ) { + hmac_reset(); + _core( t0, t1, t2, t3, t4, t5, t6, t7, 0x80000000, 0, 0, 0, 0, 0, 0, 768 ); + t0 = H0, t1 = H1, t2 = H2, t3 = H3, t4 = H4, t5 = H5, t6 = H6, t7 = H7; + + _hmac_opad(); + _core( t0, t1, t2, t3, t4, t5, t6, t7, 0x80000000, 0, 0, 0, 0, 0, 0, 768 ); + t0 = H0, t1 = H1, t2 = H2, t3 = H3, t4 = H4, t5 = H5, t6 = H6, t7 = H7; + + h0 = h0 ^ H0; + h1 = h1 ^ H1; + h2 = h2 ^ H2; + h3 = h3 ^ H3; + h4 = h4 ^ H4; + h5 = h5 ^ H5; + h6 = h6 ^ H6; + h7 = h7 ^ H7; + + count = (count-1)|0; + } + + H0 = h0; + H1 = h1; + H2 = h2; + H3 = h3; + H4 = h4; + H5 = h5; + H6 = h6; + H7 = h7; + + if ( ~output ) + _state_to_heap(output); + + return 0; + } + + return { + // SHA256 + reset: reset, + init: init, + process: process, + finish: finish, + + // HMAC-SHA256 + hmac_reset: hmac_reset, + hmac_init: hmac_init, + hmac_finish: hmac_finish, + + // PBKDF2-HMAC-SHA256 + pbkdf2_generate_block: pbkdf2_generate_block + } +} + +var _sha256_block_size = 64, + _sha256_hash_size = 32; + +function sha256_constructor ( options ) { + options = options || {}; + + this.heap = _heap_init( Uint8Array, options ); + this.asm = options.asm || sha256_asm( global, null, this.heap.buffer ); + + this.BLOCK_SIZE = _sha256_block_size; + this.HASH_SIZE = _sha256_hash_size; + + this.reset(); +} + +sha256_constructor.BLOCK_SIZE = _sha256_block_size; +sha256_constructor.HASH_SIZE = _sha256_hash_size; +var sha256_prototype = sha256_constructor.prototype; +sha256_prototype.reset = hash_reset; +sha256_prototype.process = hash_process; +sha256_prototype.finish = hash_finish; + +var sha256_instance = null; + +function get_sha256_instance () { + if ( sha256_instance === null ) sha256_instance = new sha256_constructor( { heapSize: 0x100000 } ); + return sha256_instance; +} + +/** + * SHA256 exports + */ + +function sha256_bytes ( data ) { + if ( data === undefined ) throw new SyntaxError("data required"); + return get_sha256_instance().reset().process(data).finish().result; +} + +function sha256_hex ( data ) { + var result = sha256_bytes(data); + return bytes_to_hex(result); +} + +function sha256_base64 ( data ) { + var result = sha256_bytes(data); + return bytes_to_base64(result); +} + +sha256_constructor.bytes = sha256_bytes; +sha256_constructor.hex = sha256_hex; +sha256_constructor.base64 = sha256_base64; + +exports.SHA256 = sha256_constructor; + + +'object'==typeof module&&module.exports?module.exports=exports:global.asmCrypto=exports; + +return exports; +})( {}, this ); diff --git a/vendors/openpgp-2.6.2/src/compression/rawdeflate.min.js b/vendors/openpgp-2.6.2/src/compression/rawdeflate.min.js deleted file mode 100644 index 1e5fc422a..000000000 --- a/vendors/openpgp-2.6.2/src/compression/rawdeflate.min.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @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}; -ja.prototype.pop=function(){var e,d,c=this.buffer,f,a,b;d=c[0];e=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(b=0;;){a=2*b+2;if(a>=this.length)break;a+2c[a]&&(a+=2);if(c[a]>c[b])f=c[b],c[b]=c[a],c[a]=f,f=c[b+1],c[b+1]=c[a+1],c[a+1]=f;else break;b=a}return{index:e,value:d,length:this.length}};function ka(e,d){this.e=ma;this.f=0;this.input=C&&e instanceof Array?new Uint8Array(e):e;this.c=0;d&&(d.lazy&&(this.f=d.lazy),"number"===typeof d.compressionType&&(this.e=d.compressionType),d.outputBuffer&&(this.b=C&&d.outputBuffer instanceof Array?new Uint8Array(d.outputBuffer):d.outputBuffer),"number"===typeof d.outputIndex&&(this.c=d.outputIndex));this.b||(this.b=new (C?Uint8Array:Array)(32768))}var ma=2,T=[],U; -for(U=0;288>U;U++)switch(u){case 143>=U:T.push([U+48,8]);break;case 255>=U:T.push([U-144+400,9]);break;case 279>=U:T.push([U-256+0,7]);break;case 287>=U:T.push([U-280+192,8]);break;default:throw"invalid literal: "+U;} -ka.prototype.h=function(){var e,d,c,f,a=this.input;switch(this.e){case 0:c=0;for(f=a.length;c>>8&255;l[h++]=p&255;l[h++]=p>>>8&255;if(C)l.set(b,h),h+=b.length,l=l.subarray(0,h);else{v=0;for(x=b.length;vs)for(;0s?s:138,A>s-3&&A=A?(E[D++]=17,E[D++]=A-3,H[17]++):(E[D++]=18,E[D++]=A-11,H[18]++),s-=A;else if(E[D++]=F[r],H[F[r]]++,s--,3>s)for(;0s?s:6,A>s-3&&Ay;y++)ia[y]=ea[Ia[y]];for(P=19;4=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272, -a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:throw"invalid length: "+a;}}var d=[],c,f;for(c=3;258>=c;c++)f=e(c),d[c]=f[2]<<24| -f[1]<<16|f[0];return d}(),Ga=C?new Uint32Array(Fa):Fa; -function na(e,d){function c(a,c){var b=a.g,d=[],f=0,e;e=Ga[a.length];d[f++]=e&65535;d[f++]=e>>16&255;d[f++]=e>>24;var g;switch(u){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b- -65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>= -b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:throw"invalid distance";}e=g;d[f++]=e[0];d[f++]=e[1];d[f++]=e[2];var k,m;k=0;for(m=d.length;k=b;)t[b++]=0;for(b=0;29>=b;)w[b++]=0}t[256]=1;f=0;for(a=d.length;f=a){x&&c(x,-1);b=0;for(k=a-f;bk&&d+kb&&(a=f,b=k);if(258===k)break}return new qa(b,d-a)} -function oa(e,d){var c=e.length,f=new ja(572),a=new (C?Uint8Array:Array)(c),b,k,m,g,p;if(!C)for(g=0;g2*a[h-1]+b[h]&&(a[h]=2*a[h-1]+b[h]),m[h]=Array(a[h]),g[h]=Array(a[h]);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=c[p]),c[p]>=1;x=g<<16|p;for(s=n;s>>=1;switch(c){case 0:var d=this.input,a=this.d,b=this.b,e=this.a,f=d.length,g=k,h=k,l=b.length,n=k;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=d[a++]|d[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=d[a++]|d[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>d.length)throw Error("input buffer is broken");switch(this.i){case A:for(;e+g> -b.length;){n=l-e;g-=n;if(t)b.set(d.subarray(a,a+n),e),e+=n,a+=n;else for(;n--;)b[e++]=d[a++];this.a=e;b=this.e();e=this.a}break;case y:for(;e+g>b.length;)b=this.e({o:2});break;default:throw Error("invalid inflate mode");}if(t)b.set(d.subarray(a,a+g),e),e+=g,a+=g;else for(;g--;)b[e++]=d[a++];this.d=a;this.a=e;this.b=b;break;case 1:this.j(ba,ca);break;case 2:for(var m=B(this,5)+257,p=B(this,5)+1,s=B(this,4)+4,x=new (t?Uint8Array:Array)(C.length),Q=k,R=k,S=k,v=k,M=k,F=k,z=k,q=k,T=k,q=0;q=U?8:255>=U?9:279>=U?7:8;var ba=u(P),V=new (t?Uint8Array:Array)(30),W,ea;W=0;for(ea=V.length;W=g)throw Error("input buffer is broken");a|=e[f++]<>>d;c.c=b-d;c.d=f;return h} -function D(c,d){for(var a=c.f,b=c.c,e=c.input,f=c.d,g=e.length,h=d[0],l=d[1],n,m;b=g);)a|=e[f++]<>>16;if(m>b)throw Error("invalid code length: "+m);c.f=a>>m;c.c=b-m;c.d=f;return n&65535} -w.prototype.j=function(c,d){var a=this.b,b=this.a;this.n=c;for(var e=a.length-258,f,g,h,l;256!==(f=D(this,c));)if(256>f)b>=e&&(this.a=b,a=this.e(),b=this.a),a[b++]=f;else{g=f-257;l=H[g];0=e&&(this.a=b,a=this.e(),b=this.a);for(;l--;)a[b]=a[b++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=b}; -w.prototype.s=function(c,d){var a=this.b,b=this.a;this.n=c;for(var e=a.length,f,g,h,l;256!==(f=D(this,c));)if(256>f)b>=e&&(a=this.e(),e=a.length),a[b++]=f;else{g=f-257;l=H[g];0e&&(a=this.e(),e=a.length);for(;l--;)a[b]=a[b++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=b}; -w.prototype.e=function(){var c=new (t?Uint8Array:Array)(this.a-32768),d=this.a-32768,a,b,e=this.b;if(t)c.set(e.subarray(32768,c.length));else{a=0;for(b=c.length;aa;++a)e[a]=e[d+a];this.a=32768;return e}; -w.prototype.u=function(c){var d,a=this.input.length/this.d+1|0,b,e,f,g=this.input,h=this.b;c&&("number"===typeof c.o&&(a=c.o),"number"===typeof c.q&&(a+=c.q));2>a?(b=(g.length-this.d)/this.n[2],f=258*(b/2)|0,e=fd&&(this.b.length=d),c=this.b);return this.buffer=c};r("Zlib.RawInflate",w);r("Zlib.RawInflate.prototype.decompress",w.prototype.t);var X={ADAPTIVE:y,BLOCK:A},Y,Z,$,fa;if(Object.keys)Y=Object.keys(X);else for(Z in Y=[],$=0,X)Y[$++]=Z;$=0;for(fa=Y.length;$>>8&255]<<16|Q[d>>>16&255]<<8|Q[d>>>24&255])>>32-a:Q[d]>>8-a);if(8>a+f)g=g<>a-h-1&1,8===++f&&(f=0,e[b++]=Q[g],g=0,b===e.length&&(e=this.f()));e[b]=g;this.buffer=e;this.i=f;this.index=b};I.prototype.finish=function(){var d=this.buffer,a=this.index,c;0ca;++ca){for(var R=ca,ha=R,ia=7,R=R>>>1;R;R>>>=1)ha<<=1,ha|=R&1,--ia;ba[ca]=(ha<>>0}var Q=ba;function ja(d){this.buffer=new (G?Uint16Array:Array)(2*d);this.length=0}ja.prototype.getParent=function(d){return 2*((d-2)/4|0)};ja.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}; -ja.prototype.pop=function(){var d,a,c=this.buffer,e,b,f;a=c[0];d=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(f=0;;){b=2*f+2;if(b>=this.length)break;b+2c[b]&&(b+=2);if(c[b]>c[f])e=c[f],c[f]=c[b],c[b]=e,e=c[f+1],c[f+1]=c[b+1],c[b+1]=e;else break;f=b}return{index:d,value:a,length:this.length}};function S(d){var a=d.length,c=0,e=Number.POSITIVE_INFINITY,b,f,g,h,k,p,q,r,n,l;for(r=0;rc&&(c=d[r]),d[r]>=1;l=g<<16|r;for(n=p;nT;T++)switch(z){case 143>=T:pa.push([T+48,8]);break;case 255>=T:pa.push([T-144+400,9]);break;case 279>=T:pa.push([T-256+0,7]);break;case 287>=T:pa.push([T-280+192,8]);break;default:m("invalid literal: "+T)} -ka.prototype.j=function(){var d,a,c,e,b=this.input;switch(this.h){case 0:c=0;for(e=b.length;c>>8&255;n[l++]=p&255;n[l++]=p>>>8&255;if(G)n.set(f,l),l+=f.length,n=n.subarray(0,l);else{q=0;for(r=f.length;qy)for(;0y?y:138,F>y-3&&F=F?(J[H++]=17,J[H++]=F-3,O[17]++):(J[H++]=18,J[H++]=F-11,O[18]++),y-=F;else if(J[H++]=K[u],O[K[u]]++,y--,3>y)for(;0y?y:6,F>y-3&&FD;D++)sa[D]=la[gb[D]];for(Z=19;4=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:m("invalid length: "+b)}}var a=[],c,e;for(c=3;258>=c;c++)e=d(c),a[c]=e[2]<<24|e[1]<< -16|e[0];return a}(),xa=G?new Uint32Array(wa):wa; -function qa(d,a){function c(b,c){var a=b.G,d=[],e=0,f;f=xa[b.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(z){case 1===a:g=[0,a-1,0];break;case 2===a:g=[1,a-2,0];break;case 3===a:g=[2,a-3,0];break;case 4===a:g=[3,a-4,0];break;case 6>=a:g=[4,a-5,1];break;case 8>=a:g=[5,a-7,1];break;case 12>=a:g=[6,a-9,2];break;case 16>=a:g=[7,a-13,2];break;case 24>=a:g=[8,a-17,3];break;case 32>=a:g=[9,a-25,3];break;case 48>=a:g=[10,a-33,4];break;case 64>=a:g=[11,a-49,4];break;case 96>=a:g=[12,a- -65,5];break;case 128>=a:g=[13,a-97,5];break;case 192>=a:g=[14,a-129,6];break;case 256>=a:g=[15,a-193,6];break;case 384>=a:g=[16,a-257,7];break;case 512>=a:g=[17,a-385,7];break;case 768>=a:g=[18,a-513,8];break;case 1024>=a:g=[19,a-769,8];break;case 1536>=a:g=[20,a-1025,9];break;case 2048>=a:g=[21,a-1537,9];break;case 3072>=a:g=[22,a-2049,10];break;case 4096>=a:g=[23,a-3073,10];break;case 6144>=a:g=[24,a-4097,11];break;case 8192>=a:g=[25,a-6145,11];break;case 12288>=a:g=[26,a-8193,12];break;case 16384>= -a:g=[27,a-12289,12];break;case 24576>=a:g=[28,a-16385,13];break;case 32768>=a:g=[29,a-24577,13];break;default:m("invalid distance")}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var h,k;h=0;for(k=d.length;h=f;)t[f++]=0;for(f=0;29>=f;)x[f++]=0}t[256]=1;e=0;for(b=a.length;e=b){r&&c(r,-1);f=0;for(g=b-e;fg&&a+gf&&(b=e,f=g);if(258===g)break}return new ua(f,a-b)} -function ra(d,a){var c=d.length,e=new ja(572),b=new (G?Uint8Array:Array)(c),f,g,h,k,p;if(!G)for(k=0;k2*b[l-1]+f[l]&&(b[l]=2*b[l-1]+f[l]),h[l]=Array(b[l]),k[l]=Array(b[l]);for(n=0;nd[n]?(h[l][s]=t,k[l][s]=a,x+=2):(h[l][s]=d[n],k[l][s]=n,++n);p[l]=0;1===f[l]&&e(l)}return g} -function ta(d){var a=new (G?Uint16Array:Array)(d.length),c=[],e=[],b=0,f,g,h,k;f=0;for(g=d.length;f>>=1}return a};function U(d,a){this.l=[];this.m=32768;this.e=this.g=this.c=this.q=0;this.input=G?new Uint8Array(d):d;this.s=!1;this.n=Aa;this.B=!1;if(a||!(a={}))a.index&&(this.c=a.index),a.bufferSize&&(this.m=a.bufferSize),a.bufferType&&(this.n=a.bufferType),a.resize&&(this.B=a.resize);switch(this.n){case Ba:this.b=32768;this.a=new (G?Uint8Array:Array)(32768+this.m+258);break;case Aa:this.b=0;this.a=new (G?Uint8Array:Array)(this.m);this.f=this.J;this.t=this.H;this.o=this.I;break;default:m(Error("invalid inflate mode"))}} -var Ba=0,Aa=1,Ca={D:Ba,C:Aa}; -U.prototype.p=function(){for(;!this.s;){var d=V(this,3);d&1&&(this.s=z);d>>>=1;switch(d){case 0:var a=this.input,c=this.c,e=this.a,b=this.b,f=a.length,g=w,h=w,k=e.length,p=w;this.e=this.g=0;c+1>=f&&m(Error("invalid uncompressed block header: LEN"));g=a[c++]|a[c++]<<8;c+1>=f&&m(Error("invalid uncompressed block header: NLEN"));h=a[c++]|a[c++]<<8;g===~h&&m(Error("invalid uncompressed block header: length verify"));c+g>a.length&&m(Error("input buffer is broken"));switch(this.n){case Ba:for(;b+g>e.length;){p= -k-b;g-=p;if(G)e.set(a.subarray(c,c+p),b),b+=p,c+=p;else for(;p--;)e[b++]=a[c++];this.b=b;e=this.f();b=this.b}break;case Aa:for(;b+g>e.length;)e=this.f({v:2});break;default:m(Error("invalid inflate mode"))}if(G)e.set(a.subarray(c,c+g),b),b+=g,c+=g;else for(;g--;)e[b++]=a[c++];this.c=c;this.b=b;this.a=e;break;case 1:this.o(Da,Ea);break;case 2:for(var q=V(this,5)+257,r=V(this,5)+1,n=V(this,4)+4,l=new (G?Uint8Array:Array)(Sa.length),s=w,t=w,x=w,E=w,B=w,C=w,L=w,v=w,M=w,v=0;v=W?8:255>=W?9:279>=W?7:8;var Da=S(cb),eb=new (G?Uint8Array:Array)(30),fb,hb;fb=0;for(hb=eb.length;fb=g&&m(Error("input buffer is broken")),c|=b[f++]<>>a;d.e=e-a;d.c=f;return h} -function Ta(d,a){for(var c=d.g,e=d.e,b=d.input,f=d.c,g=b.length,h=a[0],k=a[1],p,q;e=g);)c|=b[f++]<>>16;q>e&&m(Error("invalid code length: "+q));d.g=c>>q;d.e=e-q;d.c=f;return p&65535} -U.prototype.o=function(d,a){var c=this.a,e=this.b;this.u=d;for(var b=c.length-258,f,g,h,k;256!==(f=Ta(this,d));)if(256>f)e>=b&&(this.b=e,c=this.f(),e=this.b),c[e++]=f;else{g=f-257;k=Wa[g];0=b&&(this.b=e,c=this.f(),e=this.b);for(;k--;)c[e]=c[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e}; -U.prototype.I=function(d,a){var c=this.a,e=this.b;this.u=d;for(var b=c.length,f,g,h,k;256!==(f=Ta(this,d));)if(256>f)e>=b&&(c=this.f(),b=c.length),c[e++]=f;else{g=f-257;k=Wa[g];0b&&(c=this.f(),b=c.length);for(;k--;)c[e]=c[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e}; -U.prototype.f=function(){var d=new (G?Uint8Array:Array)(this.b-32768),a=this.b-32768,c,e,b=this.a;if(G)d.set(b.subarray(32768,d.length));else{c=0;for(e=d.length;cc;++c)b[c]=b[a+c];this.b=32768;return b}; -U.prototype.J=function(d){var a,c=this.input.length/this.c+1|0,e,b,f,g=this.input,h=this.a;d&&("number"===typeof d.v&&(c=d.v),"number"===typeof d.F&&(c+=d.F));2>c?(e=(g.length-this.c)/this.u[2],f=258*(e/2)|0,b=fa&&(this.a.length=a),d=this.a);return this.buffer=d};function ib(d){if("string"===typeof d){var a=d.split(""),c,e;c=0;for(e=a.length;c>>0;d=a}for(var b=1,f=0,g=d.length,h,k=0;0>>0};function jb(d,a){var c,e;this.input=d;this.c=0;if(a||!(a={}))a.index&&(this.c=a.index),a.verify&&(this.M=a.verify);c=d[this.c++];e=d[this.c++];switch(c&15){case kb:this.method=kb;break;default:m(Error("unsupported compression method"))}0!==((c<<8)+e)%31&&m(Error("invalid fcheck flag:"+((c<<8)+e)%31));e&32&&m(Error("fdict flag is not supported"));this.A=new U(d,{index:this.c,bufferSize:a.bufferSize,bufferType:a.bufferType,resize:a.resize})} -jb.prototype.p=function(){var d=this.input,a,c;a=this.A.p();this.c=this.A.c;this.M&&(c=(d[this.c++]<<24|d[this.c++]<<16|d[this.c++]<<8|d[this.c++])>>>0,c!==ib(a)&&m(Error("invalid adler-32 checksum")));return a};var kb=8;function lb(d,a){this.input=d;this.a=new (G?Uint8Array:Array)(32768);this.h=X.k;var c={},e;if((a||!(a={}))&&"number"===typeof a.compressionType)this.h=a.compressionType;for(e in a)c[e]=a[e];c.outputBuffer=this.a;this.z=new ka(this.input,c)}var X=oa; -lb.prototype.j=function(){var d,a,c,e,b,f,g,h=0;g=this.a;d=kb;switch(d){case kb:a=Math.LOG2E*Math.log(32768)-8;break;default:m(Error("invalid compression method"))}c=a<<4|d;g[h++]=c;switch(d){case kb:switch(this.h){case X.NONE:b=0;break;case X.r:b=1;break;case X.k:b=2;break;default:m(Error("unsupported compression type"))}break;default:m(Error("invalid compression method"))}e=b<<6|0;g[h++]=e|31-(256*c+e)%31;f=ib(this.input);this.z.b=h;g=this.z.j();h=g.length;G&&(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 mb(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 { + 'use strict'; + function m(d) { + throw d; + } + var w = void 0, + z = !0, + Q = new Uint8Array(256), + T = 0, + ca, + pa = [], + + d = b => { + switch (z) { + 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: + m("invalid length: " + b) + } + }, + + xa = (() => { + var a = new Uint32Array(), + c, e; + for (c = 3; 258 >= c; c++) e = d(c), a[c] = e[2] << 24 | e[1] << 16 | e[0]; + return a + })(), + + qa = (d, a) => { + function c(b, c) { + var a = b.G, + d = [], + e = 0, + f = xa[b.length]; + d[e++] = f & 65535; + d[e++] = f >> 16 & 255; + d[e++] = f >> 24; + var g; + switch (z) { + case 1 === a: + g = [0, a - 1, 0]; + break; + case 2 === a: + g = [1, a - 2, 0]; + break; + case 3 === a: + g = [2, a - 3, 0]; + break; + case 4 === a: + g = [3, a - 4, 0]; + break; + case 6 >= a: + g = [4, a - 5, 1]; + break; + case 8 >= a: + g = [5, a - 7, 1]; + break; + case 12 >= a: + g = [6, a - 9, 2]; + break; + case 16 >= a: + g = [7, a - 13, 2]; + break; + case 24 >= a: + g = [8, a - 17, 3]; + break; + case 32 >= a: + g = [9, a - 25, 3]; + break; + case 48 >= a: + g = [10, a - 33, 4]; + break; + case 64 >= a: + g = [11, a - 49, 4]; + break; + case 96 >= a: + g = [12, a - 65, 5]; + break; + case 128 >= a: + g = [13, a - 97, 5]; + break; + case 192 >= a: + g = [14, a - 129, 6]; + break; + case 256 >= a: + g = [15, a - 193, 6]; + break; + case 384 >= a: + g = [16, a - 257, 7]; + break; + case 512 >= a: + g = [17, a - 385, 7]; + break; + case 768 >= a: + g = [18, a - 513, 8]; + break; + case 1024 >= a: + g = [19, a - 769, 8]; + break; + case 1536 >= a: + g = [20, a - 1025, 9]; + break; + case 2048 >= a: + g = [21, a - 1537, 9]; + break; + case 3072 >= a: + g = [22, a - 2049, 10]; + break; + case 4096 >= a: + g = [23, a - 3073, 10]; + break; + case 6144 >= a: + g = [24, a - 4097, 11]; + break; + case 8192 >= a: + g = [25, a - 6145, 11]; + break; + case 12288 >= a: + g = [26, a - 8193, 12]; + break; + case 16384 >= a: + g = [27, a - 12289, 12]; + break; + case 24576 >= a: + g = [28, a - 16385, 13]; + break; + case 32768 >= a: + g = [29, a - 24577, 13]; + break; + default: + m("invalid distance") + } + f = g; + d[e++] = f[0]; + d[e++] = f[1]; + d[e++] = f[2]; + var h, k; + h = 0; + for (k = d.length; h < k; ++h) n[l++] = d[h]; + t[d[0]]++; + x[d[3]]++; + s = b.length + c - 1; + r = null + } + var e, b, f, g, h, k = {}, + p, q, r, n = new Uint16Array(2 * a.length), + l = 0, + s = 0, + t = new Uint32Array(286), + x = new Uint32Array(30), + E = d.w, + B; + t[256] = 1; + e = 0; + for (b = a.length; e < b; ++e) { + f = h = 0; + for (g = 3; f < g && e + f !== b; ++f) h = h << 8 | a[e + f]; + k[h] === w && (k[h] = []); + p = k[h]; + if (!(0 < s--)) { + for (; 0 < p.length && 32768 < e - p[0];) p.shift(); + if (e + 3 >= b) { + r && c(r, -1); + f = 0; + for (g = b - e; f < g; ++f) B = a[e + f], n[l++] = B, ++t[B]; + break + } + 0 < p.length ? (q = ya(a, e, p), r ? r.length < q.length ? (B = a[e - 1], n[l++] = B, ++t[B], c(q, 0)) : c(r, -1) : q.length < E ? r = q : c(q, 0)) : r ? c(r, -1) : (B = a[e], n[l++] = B, ++t[B]) + } + p.push(e) + } + n[l++] = 256; + t[256]++; + d.L = t; + d.K = x; + return n.subarray(0, l) + }, + + ya = (d, a, c) => { + var e, b, f = 0, + g, h, k, p, q = d.length; + h = 0; + p = c.length; + a: for (; h < p; h++) { + e = c[p - h - 1]; + g = 3; + if (3 < f) { + for (k = f; 3 < k; k--) + if (d[e + k - 1] !== d[a + k - 1]) continue a; + g = f + } + for (; 258 > g && a + g < q && d[e + g] === d[a + g];) ++g; + g > f && (b = e, f = g); + if (258 === g) break + } + return {length: f, G: a - b} + }, + + ra = (d, a) => { + var c = d.length, + e = new ja(572), + b = new Uint8Array(c), + f, g, h, k, p; + for (k = 0; k < c; ++k) 0 < d[k] && e.push(k, d[k]); + f = Array(e.length / 2); + g = new Uint32Array(e.length / 2); + if (1 === f.length) return b[e.pop().index] = 1, b; + k = 0; + for (p = e.length / 2; k < p; ++k) f[k] = e.pop(), g[k] = f[k].value; + h = za(g, g.length, a); + k = 0; + for (p = f.length; k < p; ++k) b[f[k].index] = h[k]; + return b + }, + + za = (d, a, c) => { + function e(b) { + var c = k[b][p[b]]; + c === a ? (e(b + 1), e(b + 1)) : --g[c]; + ++p[b] + } + var b = new Uint16Array(c), + f = new Uint8Array(c), + g = new Uint8Array(a), + h = Array(c), + k = Array(c), + p = Array(c), + q = (1 << c) - a, + r = 1 << c - 1, + n, l, s, t, x; + b[c - 1] = a; + for (l = 0; l < c; ++l) q < r ? f[l] = 0 : (f[l] = 1, q -= r), q <<= 1, b[c - 2 - l] = (b[c - 1 - l] / 2 | 0) + a; + b[0] = f[0]; + h[0] = Array(b[0]); + k[0] = Array(b[0]); + for (l = 1; l < c; ++l) b[l] > 2 * b[l - 1] + f[l] && (b[l] = 2 * b[l - 1] + f[l]), h[l] = Array(b[l]), k[l] = Array(b[l]); + for (n = 0; n < a; ++n) g[n] = c; + for (s = 0; s < b[c - 1]; ++s) h[c - + 1][s] = d[s], k[c - 1][s] = s; + for (n = 0; n < c; ++n) p[n] = 0; + 1 === f[c - 1] && (--g[0], ++p[c - 1]); + for (l = c - 2; 0 <= l; --l) { + t = n = 0; + x = p[l + 1]; + for (s = 0; s < b[l]; s++) t = h[l + 1][x] + h[l + 1][x + 1], t > d[n] ? (h[l][s] = t, k[l][s] = a, x += 2) : (h[l][s] = d[n], k[l][s] = n, ++n); + p[l] = 0; + 1 === f[l] && e(l) + } + return g + }, + + ta = d => { + var a = new Uint16Array(d.length), + c = [], + e = [], + b = 0, + f, g, h, k; + f = 0; + for (g = d.length; f < g; f++) c[d[f]] = (c[d[f]] | 0) + 1; + f = 1; + for (g = 16; f <= g; f++) e[f] = b, b += c[f] | 0, b <<= 1; + f = 0; + for (g = d.length; f < g; f++) { + b = e[d[f]]; + e[d[f]] += 1; + h = a[f] = 0; + for (k = d[f]; h < k; h++) a[f] = a[f] << 1 | b & 1, b >>>= 1 + } + return a + }; + + for (; 288 > T; T++) switch (z) { + case 143 >= T: + pa.push([T + 48, 8]); + break; + case 255 >= T: + pa.push([T - 144 + 400, 9]); + break; + case 279 >= T: + pa.push([T - 256 + 0, 7]); + break; + case 287 >= T: + pa.push([T - 280 + 192, 8]); + break; + default: + m("invalid literal: " + T) + } + + for (ca = 0; 256 > ca; ++ca) { + for (var R = ca, ha = R, ia = 7, R = R >>> 1; R; R >>>= 1) ha <<= 1, ha |= R & 1, --ia; + Q[ca] = (ha << ia & 255) >>> 0 + } + + class I + { + constructor(d, a) { + this.index = "number" === typeof a ? a : 0; + this.i = 0; + this.buffer = d instanceof Uint8Array ? d : new Uint8Array(32768); + 2 * this.buffer.length <= this.index && m(Error("invalid index")); + this.buffer.length <= this.index && this.f() + } + + f() { + var d = this.buffer, + c = d.length, + e = new Uint8Array(c << 1); + e.set(d); + return this.buffer = e + } + + d(d, a, c) { + var e = this.buffer, + b = this.index, + f = this.i, + g = e[b], + h; + c && 1 < a && (d = 8 < a ? (Q[d & 255] << 24 | Q[d >>> 8 & 255] << 16 | Q[d >>> 16 & 255] << 8 | Q[d >>> 24 & 255]) >> 32 - a : Q[d] >> 8 - a); + if (8 > a + f) g = g << a | d, f += a; + else + for (h = 0; h < a; ++h) g = g << 1 | d >> a - h - 1 & 1, 8 === ++f && (f = 0, e[b++] = Q[g], g = 0, b === e.length && (e = this.f())); + e[b] = g; + this.buffer = e; + this.i = f; + this.index = b + } + + finish() { + var d = this.buffer, + a = this.index, + c; + 0 < this.i && (d[a] <<= 8 - this.i, d[a] = Q[d[a]], a++); + c = d.subarray(0, a); + return c + } + } + + class ja + { + constructor(d) { + this.buffer = new Uint16Array(2 * d); + this.length = 0 + } + + getParent(d) { + return 2 * ((d - 2) / 4 | 0) + } + + push(d, a) { + var c, e, b = this.buffer, + f; + c = this.length; + b[this.length++] = a; + for (b[this.length++] = d; 0 < c;) + if (e = this.getParent(c), b[c] > b[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 + } + + pop() { + var d, a, c = this.buffer, + e, b, f; + a = c[0]; + d = c[1]; + this.length -= 2; + c[0] = c[this.length]; + c[1] = c[this.length + 1]; + for (f = 0;;) { + b = 2 * f + 2; + if (b >= this.length) break; + b + 2 < this.length && c[b + 2] > c[b] && (b += 2); + if (c[b] > c[f]) e = c[f], c[f] = c[b], c[b] = e, e = c[f + 1], c[f + 1] = c[b + 1], c[b + 1] = e; + else break; + f = b + } + return { + index: d, + value: a, + length: this.length + } + } + } + + class ka + { + constructor(d, a) { + this.h = 2; + this.w = 0; + this.input = d instanceof Array ? new Uint8Array(d) : d; + this.b = 0; + a && (a.lazy && (this.w = a.lazy), "number" === typeof a.compressionType && (this.h = a.compressionType), a.outputBuffer && (this.a = a.outputBuffer instanceof Array ? new Uint8Array(a.outputBuffer) : a.outputBuffer), "number" === typeof a.outputIndex && (this.b = a.outputIndex)); + this.a || (this.a = new Uint8Array(32768)) + } + + compress() { + this.j(); + } + j() { + var d, a, c, e, b = this.input; + switch (this.h) { + case 0: + c = 0; + for (e = b.length; c < e;) { + a = b.subarray(c, c + 65535); + c += a.length; + var f = a, + g = c === e, + h = w, + k = w, + p = w, + n = this.a, + l = this.b; + for (n = new Uint8Array(this.a.buffer); n.length <= l + f.length + 5;) n = new Uint8Array(n.length << 1); + n.set(this.a) + h = g ? 1 : 0; + n[l++] = h | 0; + k = f.length; + p = ~k + 65536 & 65535; + n[l++] = k & 255; + n[l++] = k >>> 8 & 255; + n[l++] = p & 255; + n[l++] = p >>> 8 & 255; + n.set(f, l), l += f.length, n = n.subarray(0, l); + this.b = l; + this.a = n + } + break; + case 1: + var s = new I(new Uint8Array(this.a.buffer), this.b); + s.d(1, 1, z); + s.d(1, 2, z); + var t = qa(this, b), + x, E, B; + x = 0; + for (E = t.length; x < E; x++) + if (B = t[x], I.prototype.d.apply(s, pa[B]), 256 < B) s.d(t[++x], t[++x], z), s.d(t[++x], 5), s.d(t[++x], t[++x], z); + else if (256 === B) break; + this.a = s.finish(); + this.b = this.a.length; + break; + case 2: + var C = new I(new Uint8Array(this.a.buffer), this.b), + L, v, M, Y, Z, gb = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15], + da, Fa, ea, Ga, la, sa = Array(19), + Ha, $, ma, D, Ia; + L = 2; + C.d(1, 1, z); + C.d(L, 2, z); + v = qa(this, b); + da = ra(this.L, 15); + Fa = ta(da); + ea = ra(this.K, 7); + Ga = ta(ea); + for (M = 286; 257 < M && 0 === da[M - 1]; M--); + for (Y = 30; 1 < Y && 0 === ea[Y - 1]; Y--); + var Ja = M, + Ka = Y, + K = new Uint32Array(Ja + Ka), + u, N, y, fa, J = new Uint32Array(316), + H, F, O = new Uint8Array(19); + for (u = N = 0; u < Ja; u++) K[N++] = da[u]; + for (u = 0; u < Ka; u++) K[N++] = ea[u]; + u = H = 0; + for (fa = K.length; u < fa; u += N) { + for (N = 1; u + N < fa && K[u + N] === K[u]; ++N); + y = N; + if (0 === K[u]) + if (3 > y) + for (; 0 < y--;) J[H++] = + 0, O[0]++; + else + for (; 0 < y;) F = 138 > y ? y : 138, F > y - 3 && F < y && (F = y - 3), 10 >= F ? (J[H++] = 17, J[H++] = F - 3, O[17]++) : (J[H++] = 18, J[H++] = F - 11, O[18]++), y -= F; + else if (J[H++] = K[u], O[K[u]]++, y--, 3 > y) + for (; 0 < y--;) J[H++] = K[u], O[K[u]]++; + else + for (; 0 < y;) F = 6 > y ? y : 6, F > y - 3 && F < y && (F = y - 3), J[H++] = 16, J[H++] = F - 3, O[16]++, y -= F + } + d = J.subarray(0, H); + la = ra(O, 7); + for (D = 0; 19 > D; D++) sa[D] = la[gb[D]]; + for (Z = 19; 4 < Z && 0 === sa[Z - 1]; Z--); + Ha = ta(la); + C.d(M - 257, 5, z); + C.d(Y - 1, 5, z); + C.d(Z - 4, 4, z); + for (D = 0; D < Z; D++) C.d(sa[D], 3, z); + D = 0; + for (Ia = d.length; D < Ia; D++) + if ($ = + d[D], C.d(Ha[$], la[$], z), 16 <= $) { + D++; + switch ($) { + case 16: + ma = 2; + break; + case 17: + ma = 3; + break; + case 18: + ma = 7; + break; + default: + m("invalid code: " + $) + } + C.d(d[D], ma, z) + } + var La = [Fa, da], + Ma = [Ga, ea], + P, Na, ga, va, Oa, Pa, Qa, Ra; + Oa = La[0]; + Pa = La[1]; + Qa = Ma[0]; + Ra = Ma[1]; + P = 0; + for (Na = v.length; P < Na; ++P) + if (ga = v[P], C.d(Oa[ga], Pa[ga], z), 256 < ga) C.d(v[++P], v[++P], z), va = v[++P], C.d(Qa[va], Ra[va], z), C.d(v[++P], v[++P], z); + else if (256 === ga) break; + this.a = C.finish(); + this.b = this.a.length; + break; + default: + m("invalid compression type") + } + return this.a + } + } + + var S = d => { + var a = d.length, + c = 0, + e = Number.POSITIVE_INFINITY, + b, f, g, h, k, p, q, r, n, l; + for (r = 0; r < a; ++r) d[r] > c && (c = d[r]), d[r] < e && (e = d[r]); + b = 1 << c; + f = new Uint32Array(b); + g = 1; + h = 0; + for (k = 2; g <= c;) { + for (r = 0; r < a; ++r) + if (d[r] === g) { + p = 0; + q = h; + for (n = 0; n < g; ++n) p = p << 1 | q & 1, q >>= 1; + l = g << 16 | r; + for (n = p; n < b; n += k) f[n] = l; + ++h + }++g; + h <<= 1; + k <<= 1 + } + return [f, c, e] + }, + + Sa = new Uint16Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + Wa = new Uint16Array([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]), + Ya = new Uint8Array([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]), + $a = new Uint16Array([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]), + bb = new Uint8Array([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]), + W = 288, + cb = new Uint8Array(W), + Ea = S((new Uint8Array(30)).fill(5)), + + V = (d, a) => { + for (var c = d.g, e = d.e, b = d.input, f = d.c, g = b.length, h; e < a;) f >= g && m(Error("input buffer is broken")), c |= b[f++] << e, e += 8; + h = c & (1 << a) - 1; + d.g = c >>> a; + d.e = e - a; + d.c = f; + return h + }, + + Ta = (d, a) => { + for (var c = d.g, e = d.e, b = d.input, f = d.c, g = b.length, h = a[0], k = a[1], p, q; e < k && !(f >= g);) c |= b[f++] << e, e += 8; + p = h[c & (1 << k) - 1]; + q = p >>> 16; + q > e && m(Error("invalid code length: " + q)); + d.g = c >> q; + d.e = e - q; + d.c = f; + return p & 65535 + }; + + while (W--) cb[W] = 143 >= W ? 8 : 255 >= W ? 9 : 279 >= W ? 7 : 8; + var Da = S(cb); + + class U + { + constructor(d, a) { + this.l = []; + this.m = 32768; + this.e = this.g = this.c = this.q = 0; + this.input = new Uint8Array(d); + this.s = !1; + this.n = 1; + this.B = !1; + if (a || !(a = {})) a.index && (this.c = a.index), a.bufferSize && (this.m = a.bufferSize), a.bufferType && (this.n = a.bufferType), a.resize && (this.B = a.resize); + switch (this.n) { + case 0: + this.b = 32768; + this.a = new Uint8Array(32768 + this.m + 258); + break; + case 1: + this.b = 0; + this.a = new Uint8Array(this.m); + this.f = this.J; + this.t = this.H; + this.o = this.I; + break; + default: + m(Error("invalid inflate mode")) + } + } + + decompress() { + this.p(); + } + p() { + for (; !this.s;) { + var d = V(this, 3); + d & 1 && (this.s = z); + d >>>= 1; + switch (d) { + case 0: + var a = this.input, + c = this.c, + e = this.a, + b = this.b, + f = a.length, + g = w, + h = w, + k = e.length, + p = w; + this.e = this.g = 0; + c + 1 >= f && m(Error("invalid uncompressed block header: LEN")); + g = a[c++] | a[c++] << 8; + c + 1 >= f && m(Error("invalid uncompressed block header: NLEN")); + h = a[c++] | a[c++] << 8; + g === ~h && m(Error("invalid uncompressed block header: length verify")); + c + g > a.length && m(Error("input buffer is broken")); + switch (this.n) { + case 0: + for (; b + g > e.length;) { + p = + k - b; + g -= p; + e.set(a.subarray(c, c + p), b), b += p, c += p; + this.b = b; + e = this.f(); + b = this.b + } + break; + case 1: + for (; b + g > e.length;) e = this.f({ + v: 2 + }); + break; + default: + m(Error("invalid inflate mode")) + } + e.set(a.subarray(c, c + g), b), b += g, c += g; + this.c = c; + this.b = b; + this.a = e; + break; + case 1: + this.o(Da, Ea); + break; + case 2: + for (var q = V(this, 5) + 257, r = V(this, 5) + 1, n = V(this, 4) + 4, l = new Uint8Array(Sa.length), s = w, t = w, x = w, E = w, B = w, C = w, L = w, v = w, M = w, v = 0; v < n; ++v) l[Sa[v]] = V(this, 3); + s = S(l); + E = new Uint8Array(q + r); + v = 0; + for (M = q + r; v < M;) switch (B = Ta(this, s), B) { + case 16: + for (L = 3 + V(this, 2); L--;) E[v++] = C; + break; + case 17: + for (L = 3 + V(this, 3); L--;) E[v++] = 0; + C = 0; + break; + case 18: + for (L = 11 + V(this, 7); L--;) E[v++] = 0; + C = 0; + break; + default: + C = E[v++] = B + } + t = S(E.subarray(0, q)); + x = S(E.subarray(q)); + this.o(t, x); + break; + default: + m(Error("unknown BTYPE: " + d)) + } + } + return this.t() + } + + o(d, a) { + var c = this.a, + e = this.b; + this.u = d; + for (var b = c.length - 258, f, g, h, k; 256 !== (f = Ta(this, d));) + if (256 > f) e >= b && (this.b = e, c = this.f(), e = this.b), c[e++] = f; + else { + g = f - 257; + k = Wa[g]; + 0 < Ya[g] && (k += V(this, Ya[g])); + f = Ta(this, a); + h = $a[f]; + 0 < bb[f] && (h += V(this, bb[f])); + e >= b && (this.b = e, c = this.f(), e = this.b); + for (; k--;) c[e] = c[e++ - h] + } + for (; 8 <= this.e;) this.e -= 8, this.c--; + this.b = e + } + + I(d, a) { + var c = this.a, + e = this.b; + this.u = d; + for (var b = c.length, f, g, h, k; 256 !== (f = Ta(this, d));) + if (256 > f) e >= b && (c = this.f(), b = c.length), c[e++] = f; + else { + g = f - 257; + k = Wa[g]; + 0 < Ya[g] && (k += V(this, Ya[g])); + f = Ta(this, a); + h = $a[f]; + 0 < bb[f] && (h += V(this, bb[f])); + e + k > b && (c = this.f(), b = c.length); + for (; k--;) c[e] = c[e++ - h] + } + for (; 8 <= this.e;) this.e -= 8, this.c--; + this.b = e + } + + f() { + var d = new Uint8Array(this.b - 32768), + a = this.b - 32768, + b = this.a; + d.set(b.subarray(32768, d.length)); + this.l.push(d); + this.q += d.length; + b.set(b.subarray(a, a + 32768)); + this.b = 32768; + return b + } + + J(d) { + var a, c = this.input.length / this.c + 1 | 0, + e, b, f, g = this.input, + h = this.a; + d && ("number" === typeof d.v && (c = d.v), "number" === typeof d.F && (c += d.F)); + 2 > c ? (e = (g.length - this.c) / this.u[2], f = 258 * (e / 2) | 0, b = f < h.length ? h.length + f : h.length << 1) : b = h.length * c; + a = new Uint8Array(b), a.set(h); + return this.a = a + } + + t() { + var d = 0, + a = this.a, + c = this.l, + e, b = new Uint8Array(this.q + (this.b - 32768)), + f, g, h, k; + if (0 === c.length) return this.a.subarray(32768, this.b); + f = 0; + for (g = c.length; f < g; ++f) { + e = c[f]; + h = 0; + for (k = e.length; h < k; ++h) b[d++] = e[h] + } + f = 32768; + for (g = this.b; f < g; ++f) b[d++] = a[f]; + this.l = []; + return this.buffer = b + } + + H() { + var d, a = this.b; + this.B ? (d = new Uint8Array(a), d.set(this.a.subarray(0, a))) : d = this.a.subarray(0, a); + return this.buffer = d + } + } + + function ib(d) { + if ("string" === typeof d) { + var a = d.split(""), + c, e; + c = 0; + for (e = a.length; c < e; c++) a[c] = (a[c].charCodeAt(0) & 255) >>> 0; + d = a + } + for (var b = 1, f = 0, g = d.length, h, k = 0; 0 < g;) { + h = 1024 < g ? 1024 : g; + g -= h; + do b += d[k++], f += b; while (--h); + b %= 65521; + f %= 65521 + } + return (f << 16 | b) >>> 0 + } + + class jb + { + constructor(d, a) { + var c, e; + this.input = d; + this.c = 0; + if (a || !(a = {})) a.index && (this.c = a.index), a.verify && (this.M = a.verify); + c = d[this.c++]; + e = d[this.c++]; + switch (c & 15) { + case 8: + this.method = 8; + break; + default: + m(Error("unsupported compression method")) + } + 0 !== ((c << 8) + e) % 31 && m(Error("invalid fcheck flag:" + ((c << 8) + e) % 31)); + e & 32 && m(Error("fdict flag is not supported")); + this.A = new U(d, { + index: this.c, + bufferSize: a.bufferSize, + bufferType: a.bufferType, + resize: a.resize + }) + } + + decompress() { + var d = this.input, + a, c; + a = this.A.p(); + this.c = this.A.c; + this.M && (c = (d[this.c++] << 24 | d[this.c++] << 16 | d[this.c++] << 8 | d[this.c++]) >>> 0, c !== ib(a) && m(Error("invalid adler-32 checksum"))); + return a + } + } + + class lb + { + constructor(d, a) { + this.input = d; + this.a = new Uint8Array(32768); + this.h = 2; + var c = {}, + e; + if ((a || !(a = {})) && "number" === typeof a.compressionType) this.h = a.compressionType; + for (e in a) c[e] = a[e]; + c.outputBuffer = this.a; + this.z = new ka(this.input, c) + } + + compress = function () { + var d, a, c, e, b, f, g, h = 0; + g = this.a; + d = 8; + switch (d) { + case 8: + a = Math.LOG2E * Math.log(32768) - 8; + break; + default: + m(Error("invalid compression method")) + } + c = a << 4 | d; + g[h++] = c; + switch (d) { + case 8: + switch (this.h) { + case 0: + b = 0; + break; + case 1: + b = 1; + break; + case 2: + b = 2; + break; + default: + m(Error("unsupported compression type")) + } + break; + default: + m(Error("invalid compression method")) + } + e = b << 6 | 0; + g[h++] = e | 31 - (256 * c + e) % 31; + f = ib(this.input); + this.z.b = h; + g = this.z.j(); + h = g.length; + (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 + } + } + + U.BufferType = jb.BufferType = { + ADAPTIVE: 1, + BLOCK: 0 + }; + + ka.CompressionType = lb.CompressionType = { + NONE: 0, + FIXED: 1, + DYNAMIC: 2 + }; + + aa.Zlib = { + Inflate: jb, + Deflate: lb, + RawDeflate: ka, + RawInflate: U + }; + +})(this); diff --git a/vendors/openpgp-2.6.2/src/config/config.js b/vendors/openpgp-2.6.2/src/config/config.js index 0e9b22874..b9a42b02b 100644 --- a/vendors/openpgp-2.6.2/src/config/config.js +++ b/vendors/openpgp-2.6.2/src/config/config.js @@ -25,7 +25,6 @@ * @property {Boolean} show_comment * @property {Boolean} integrity_protect * @property {String} keyserver - * @property {Boolean} debug If enabled, debug messages will be printed * @module config/config */ @@ -42,15 +41,7 @@ export default { ignore_mdc_error: false, // fail on decrypt if message is not integrity protected checksum_required: false, // do not throw error when armor is missing a checksum verify_expired_keys: true, // allow signature verification with expired keys - rsa_blinding: true, - use_native: true, // use native node.js crypto and Web Crypto apis (if available) zero_copy: false, // use transferable objects between the Web Worker and main thread - debug: false, tolerant: true, // ignore unsupported/unrecognizable packets instead of throwing an error - show_version: true, - show_comment: true, - versionstring: "OpenPGP.js VERSION", - commentstring: "https://openpgpjs.org", - keyserver: "https://keyserver.ubuntu.com", - node_store: './openpgp.store' + keyserver: "https://keyserver.ubuntu.com" }; diff --git a/vendors/openpgp-2.6.2/src/crypto/gcm.js b/vendors/openpgp-2.6.2/src/crypto/gcm.js index 1ce54c2cb..c7b1734f0 100644 --- a/vendors/openpgp-2.6.2/src/crypto/gcm.js +++ b/vendors/openpgp-2.6.2/src/crypto/gcm.js @@ -24,7 +24,7 @@ import util from '../util.js'; import config from '../config'; -import asmCrypto from '../asmcrypto.js'; +import '../asmcrypto.js'; const webCrypto = util.getWebCrypto(); // no GCM support in IE11, Safari 9 export const ivLength = 12; // size of the IV in bytes @@ -43,7 +43,7 @@ export function encrypt(cipher, plaintext, key, iv) { return Promise.reject(new Error('GCM mode supports only AES cipher')); } - if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support + if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support return webEncrypt(plaintext, key, iv); } // asm.js fallback @@ -63,7 +63,7 @@ export function decrypt(cipher, ciphertext, key, iv) { return Promise.reject(new Error('GCM mode supports only AES cipher')); } - if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support + if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support return webDecrypt(ciphertext, key, iv); } // asm.js fallback diff --git a/vendors/openpgp-2.6.2/src/crypto/hash/index.js b/vendors/openpgp-2.6.2/src/crypto/hash/index.js index bc5d90584..48e712039 100644 --- a/vendors/openpgp-2.6.2/src/crypto/hash/index.js +++ b/vendors/openpgp-2.6.2/src/crypto/hash/index.js @@ -9,8 +9,8 @@ 'use strict'; import sha from './sha.js'; -import asmCrypto from '../../asmcrypto.js'; -import Rusha from '../../rusha.js'; +import '../../asmcrypto.js'; +import '../../rusha.js'; import md5 from './md5.js'; import ripemd from './ripe-md.js'; import util from '../../util.js'; diff --git a/vendors/openpgp-2.6.2/src/crypto/public_key/dsa.js b/vendors/openpgp-2.6.2/src/crypto/public_key/dsa.js index d9c20eedd..55aeb535b 100644 --- a/vendors/openpgp-2.6.2/src/crypto/public_key/dsa.js +++ b/vendors/openpgp-2.6.2/src/crypto/public_key/dsa.js @@ -97,7 +97,6 @@ export default function DSA() { } return usersetting; default: - util.print_debug("DSA select hash algorithm: returning null for an unknown length of q"); return null; } } @@ -110,12 +109,10 @@ export default function DSA() { s1.compareTo(q) >= 0 || BigInteger.ZERO.compareTo(s2) >= 0 || s2.compareTo(q) >= 0) { - util.print_debug("invalid DSA Signature"); return null; } var w = s2.modInverse(q); if (BigInteger.ZERO.compareTo(w) === 0) { - util.print_debug("invalid DSA Signature"); return null; } var u1 = hash.multiply(w).mod(q); diff --git a/vendors/openpgp-2.6.2/src/crypto/public_key/elgamal.js b/vendors/openpgp-2.6.2/src/crypto/public_key/elgamal.js index 14b39016c..255707587 100644 --- a/vendors/openpgp-2.6.2/src/crypto/public_key/elgamal.js +++ b/vendors/openpgp-2.6.2/src/crypto/public_key/elgamal.js @@ -44,10 +44,6 @@ export default 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); //var c = c1.pow(x).modInverse(p); // c0^-a mod p //return c.multiply(c2).mod(p); diff --git a/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js b/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js index af53cf126..d9150604e 100644 --- a/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js +++ b/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js @@ -77,12 +77,9 @@ export default function RSA() { * @return {BigInteger} The decrypted value of the message */ function decrypt(m, n, e, d, p, q, u) { - if (config.rsa_blinding) { - m = blind(m, n, e); - } + 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 t = xq.subtract(xp); if (t[0] === 0) { @@ -93,9 +90,7 @@ export default function RSA() { t = t.multiply(u).mod(q); } t = t.multiply(p).add(xp); - if (config.rsa_blinding) { - t = unblind(t, n); - } + t = unblind(t, n); return t; } diff --git a/vendors/openpgp-2.6.2/src/encoding/armor.js b/vendors/openpgp-2.6.2/src/encoding/armor.js index 8db6ff36d..22cb2fff2 100644 --- a/vendors/openpgp-2.6.2/src/encoding/armor.js +++ b/vendors/openpgp-2.6.2/src/encoding/armor.js @@ -95,27 +95,6 @@ function getType(text) { } } -/** - * Add additional information to the armor version of an OpenPGP binary - * packet block. - * @author Alex - * @version 2011-12-16 - * @returns {String} The header information - */ -function addheader() { - var result = ""; - if (config.show_version) { - result += "Version: " + config.versionstring + '\r\n'; - } - if (config.show_comment) { - result += "Comment: " + config.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 @@ -227,9 +206,6 @@ function verifyHeaders(headers) { if (!/^([^\s:]|[^\s:][^:]*[^\s:]): .+$/.test(headers[i])) { throw new Error('Improperly formatted armor header: ' + headers[i]); } - if (config.debug && !/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) { - console.log('Unknown header: ' + headers[i]); - } } } @@ -338,14 +314,12 @@ function armor(messagetype, body, partindex, parttotal) { switch (messagetype) { case enums.armor.multipart_section: result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n"); - result.push(addheader()); result.push(base64.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: result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n"); - result.push(addheader()); result.push(base64.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP MESSAGE, PART " + partindex + "-----\r\n"); @@ -355,35 +329,30 @@ function armor(messagetype, body, partindex, parttotal) { 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("\r\n=" + getCheckSum(body.data) + "\r\n"); result.push("-----END PGP SIGNATURE-----\r\n"); break; case enums.armor.message: result.push("-----BEGIN PGP MESSAGE-----\r\n"); - result.push(addheader()); result.push(base64.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP MESSAGE-----\r\n"); break; case enums.armor.public_key: result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n"); - result.push(addheader()); result.push(base64.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: result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n"); - result.push(addheader()); result.push(base64.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP PRIVATE KEY BLOCK-----\r\n"); break; case enums.armor.signature: result.push("-----BEGIN PGP SIGNATURE-----\r\n"); - result.push(addheader()); result.push(base64.encode(body)); result.push("\r\n=" + getCheckSum(body) + "\r\n"); result.push("-----END PGP SIGNATURE-----\r\n"); diff --git a/vendors/openpgp-2.6.2/src/key.js b/vendors/openpgp-2.6.2/src/key.js index e93ffb308..c575c30a2 100644 --- a/vendors/openpgp-2.6.2/src/key.js +++ b/vendors/openpgp-2.6.2/src/key.js @@ -91,7 +91,6 @@ Key.prototype.packetlist2structure = function(packetlist) { case enums.signature.cert_casual: case enums.signature.cert_positive: if (!user) { - util.print_debug('Dropping certification signatures without preceding user packet'); continue; } if (packetlist[i].issuerKeyId.equals(primaryKeyId)) { @@ -127,7 +126,6 @@ Key.prototype.packetlist2structure = function(packetlist) { break; case enums.signature.subkey_binding: if (!subKey) { - util.print_debug('Dropping subkey binding signature without preceding subkey packet'); continue; } subKey.bindingSignatures.push(packetlist[i]); @@ -137,7 +135,6 @@ Key.prototype.packetlist2structure = function(packetlist) { break; case enums.signature.subkey_revocation: if (!subKey) { - util.print_debug('Dropping subkey revocation signature without preceding subkey packet'); continue; } subKey.revocationSignature = packetlist[i]; diff --git a/vendors/openpgp-2.6.2/src/keyring/localstore.js b/vendors/openpgp-2.6.2/src/keyring/localstore.js index 06c9b5ced..4ef9809d7 100644 --- a/vendors/openpgp-2.6.2/src/keyring/localstore.js +++ b/vendors/openpgp-2.6.2/src/keyring/localstore.js @@ -36,8 +36,6 @@ function loadKeys(storage, itemname) { key = keyModule.readArmored(armoredKeys[i]); if (!key.err) { keys.push(key.keys[0]); - } else { - util.print_debug("Error reading armored key from keyring index: " + i); } } } diff --git a/vendors/openpgp-2.6.2/src/openpgp.js b/vendors/openpgp-2.6.2/src/openpgp.js index 2d846d889..f77eb50ef 100644 --- a/vendors/openpgp-2.6.2/src/openpgp.js +++ b/vendors/openpgp-2.6.2/src/openpgp.js @@ -551,9 +551,6 @@ function execute(cmd, message) { * @param {Error} error The internal error that caused the failure */ function onError(message, error) { - // log the stack trace - if (config.debug) { console.error(error.stack); } - // update error message error.message = message + ': ' + error.message; diff --git a/vendors/openpgp-2.6.2/src/packet/compressed.js b/vendors/openpgp-2.6.2/src/packet/compressed.js index 619a87da1..c997467e2 100644 --- a/vendors/openpgp-2.6.2/src/packet/compressed.js +++ b/vendors/openpgp-2.6.2/src/packet/compressed.js @@ -33,131 +33,128 @@ import enums from '../enums.js'; import util from '../util.js'; -import Zlib from '../compression/zlib.min.js'; -import RawInflate from '../compression/rawinflate.min.js'; -import RawDeflate from '../compression/rawdeflate.min.js'; +import '../compression/zlib.min.js'; /** * @constructor */ -export default function Compressed() { - /** - * Packet type - * @type {module:enums.packet} - */ - this.tag = enums.packet.compressed; - /** - * List of packets - * @type {module:packet/packetlist} - */ - this.packets = null; - /** - * Compression algorithm - * @type {compression} - */ - this.algorithm = 'zip'; +export default class Compressed +{ + constructor() + { + /** + * Packet type + * @type {module:enums.packet} + */ + this.tag = enums.packet.compressed; + /** + * List of packets + * @type {module:packet/packetlist} + */ + this.packets = null; + /** + * Compression algorithm + * @type {compression} + */ + this.algorithm = 'zip'; + + /** + * Compressed packet data + * @type {String} + */ + this.compressed = null; + } /** - * Compressed packet data - * @type {String} + * Parsing function for the packet. + * @param {String} bytes Payload of a tag 8 packet */ - this.compressed = null; + read(bytes) { + // One octet that gives the algorithm used to compress the packet. + this.algorithm = enums.read(enums.compression, bytes[0]); + + // Compressed data, which makes up the remainder of the packet. + this.compressed = bytes.subarray(1, bytes.length); + + this.decompress(); + } + + + + /** + * Return the compressed packet. + * @return {String} binary compressed packet + */ + write() { + if (this.compressed === null) { + this.compress(); + } + + return util.concatUint8Array(new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed); + } + + + /** + * Decompression method for decompressing the compressed data + * read by read_packet + */ + decompress() { + var decompressed; + + switch (this.algorithm) { + case 'uncompressed': + decompressed = this.compressed; + break; + + case 'zip': + decompressed = (new Zlib.RawInflate(this.compressed)).decompress(); + break; + + case 'zlib': + decompressed = (new Zlib.Inflate(this.compressed)).decompress(); + break; + + case 'bzip2': + // TODO: need to implement this + throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.'); + + default: + throw new Error("Compression algorithm unknown :" + this.algorithm); + } + + this.packets.read(decompressed); + } + + /** + * Compress the packet data (member decompressedData) + */ + compress() { + var uncompressed = this.packets.write(); + + switch (this.algorithm) { + + case 'uncompressed': + // - Uncompressed + this.compressed = uncompressed; + break; + + case 'zip': + // - ZIP [RFC1951] + this.compressed = (new Zlib.RawDeflate(uncompressed)).compress(); + break; + + case 'zlib': + // - ZLIB [RFC1950] + this.compressed = (new Zlib.Deflate(uncompressed)).compress(); + break; + + case 'bzip2': + // - BZip2 [BZ2] + // TODO: need to implement this + throw new Error("Compression algorithm BZip2 [BZ2] is not implemented."); + + default: + throw new Error("Compression algorithm unknown :" + this.type); + } + } } - -/** - * Parsing function for the packet. - * @param {String} bytes Payload of a tag 8 packet - */ -Compressed.prototype.read = function (bytes) { - // One octet that gives the algorithm used to compress the packet. - this.algorithm = enums.read(enums.compression, bytes[0]); - - // Compressed data, which makes up the remainder of the packet. - 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) { - this.compress(); - } - - return util.concatUint8Array(new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed); -}; - - -/** - * Decompression method for decompressing the compressed data - * read by read_packet - */ -Compressed.prototype.decompress = function () { - var decompressed, inflate; - - switch (this.algorithm) { - case 'uncompressed': - decompressed = this.compressed; - break; - - case 'zip': - inflate = new RawInflate.Zlib.RawInflate(this.compressed); - decompressed = inflate.decompress(); - break; - - case 'zlib': - inflate = new Zlib.Zlib.Inflate(this.compressed); - decompressed = inflate.decompress(); - break; - - case 'bzip2': - // TODO: need to implement this - throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.'); - - default: - throw new Error("Compression algorithm unknown :" + this.algorithm); - } - - this.packets.read(decompressed); -}; - -/** - * Compress the packet data (member decompressedData) - */ -Compressed.prototype.compress = function () { - var uncompressed, deflate; - uncompressed = this.packets.write(); - - switch (this.algorithm) { - - case 'uncompressed': - // - Uncompressed - this.compressed = uncompressed; - break; - - case 'zip': - // - ZIP [RFC1951] - deflate = new RawDeflate.Zlib.RawDeflate(uncompressed); - this.compressed = deflate.compress(); - break; - - case 'zlib': - // - ZLIB [RFC1950] - deflate = new Zlib.Zlib.Deflate(uncompressed); - this.compressed = deflate.compress(); - break; - - case 'bzip2': - // - BZip2 [BZ2] - // TODO: need to implement this - throw new Error("Compression algorithm BZip2 [BZ2] is not implemented."); - - default: - throw new Error("Compression algorithm unknown :" + this.type); - } -}; diff --git a/vendors/openpgp-2.6.2/src/packet/packet.js b/vendors/openpgp-2.6.2/src/packet/packet.js index 866e65247..bb6086f90 100644 --- a/vendors/openpgp-2.6.2/src/packet/packet.js +++ b/vendors/openpgp-2.6.2/src/packet/packet.js @@ -185,15 +185,12 @@ export default { // 4.2.2.1. One-Octet Lengths if (input[mypos] < 192) { packet_length = input[mypos++]; - util.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; - util.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); - util.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)]; diff --git a/vendors/openpgp-2.6.2/src/packet/signature.js b/vendors/openpgp-2.6.2/src/packet/signature.js index 25e545c95..0bbdd7f5b 100644 --- a/vendors/openpgp-2.6.2/src/packet/signature.js +++ b/vendors/openpgp-2.6.2/src/packet/signature.js @@ -100,13 +100,6 @@ Signature.prototype.read = function (bytes) { // switch on version (3 and 4) switch (this.version) { case 3: - // One-octet length of following hashed material. MUST be 5. - if (bytes[i++] !== 5) { - util.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[i++]; @@ -463,8 +456,6 @@ Signature.prototype.read_sub_packet = function (bytes) { this.notation = this.notation || {}; this.notation[name] = value; - } else { - util.print_debug("Unsupported notation flag "+bytes[mypos]); } break; case 21: @@ -523,8 +514,6 @@ Signature.prototype.read_sub_packet = function (bytes) { this.embeddedSignature = new Signature(); this.embeddedSignature.read(bytes.subarray(mypos, bytes.length)); break; - default: - util.print_debug("Unknown signature subpacket type " + type + " @:" + mypos); } }; diff --git a/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js b/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js index 5ac8c8bc4..a50df57ba 100644 --- a/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js +++ b/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js @@ -37,7 +37,7 @@ import util from '../util.js'; import crypto from '../crypto'; import enums from '../enums.js'; -import asmCrypto from '../asmcrypto.js'; +import '../asmcrypto.js'; const VERSION = 1; // A one-octet version number of the data packet. diff --git a/vendors/openpgp-2.6.2/src/rusha.js b/vendors/openpgp-2.6.2/src/rusha.js new file mode 100644 index 000000000..88f091b13 --- /dev/null +++ b/vendors/openpgp-2.6.2/src/rusha.js @@ -0,0 +1,410 @@ +(w => { + 'use strict'; + + // 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. + function RushaCore(stdlib$840, foreign$841, heap$842) { + 'use asm'; + let H$843 = new stdlib$840.Int32Array(heap$842); + function hash$844(k$845, x$846) { + // k in bytes + k$845 = k$845 | 0; + x$846 = x$846 | 0; + let i$847 = 0, j$848 = 0, y0$849 = 0, z0$850 = 0, y1$851 = 0, z1$852 = 0, y2$853 = 0, z2$854 = 0, y3$855 = 0, z3$856 = 0, y4$857 = 0, z4$858 = 0, t0$859 = 0, t1$860 = 0; + y0$849 = H$843[x$846 + 320 >> 2] | 0; + y1$851 = H$843[x$846 + 324 >> 2] | 0; + y2$853 = H$843[x$846 + 328 >> 2] | 0; + y3$855 = H$843[x$846 + 332 >> 2] | 0; + y4$857 = H$843[x$846 + 336 >> 2] | 0; + for (i$847 = 0; (i$847 | 0) < (k$845 | 0); i$847 = i$847 + 64 | 0) { + z0$850 = y0$849; + z1$852 = y1$851; + z2$854 = y2$853; + z3$856 = y3$855; + z4$858 = y4$857; + for (j$848 = 0; (j$848 | 0) < 64; j$848 = j$848 + 4 | 0) { + t1$860 = H$843[i$847 + j$848 >> 2] | 0; + t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 & y2$853 | ~y1$851 & y3$855) | 0) + ((t1$860 + y4$857 | 0) + 1518500249 | 0) | 0; + y4$857 = y3$855; + y3$855 = y2$853; + y2$853 = y1$851 << 30 | y1$851 >>> 2; + y1$851 = y0$849; + y0$849 = t0$859; + H$843[k$845 + j$848 >> 2] = t1$860; + } + for (j$848 = k$845 + 64 | 0; (j$848 | 0) < (k$845 + 80 | 0); j$848 = j$848 + 4 | 0) { + t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31; + t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 & y2$853 | ~y1$851 & y3$855) | 0) + ((t1$860 + y4$857 | 0) + 1518500249 | 0) | 0; + y4$857 = y3$855; + y3$855 = y2$853; + y2$853 = y1$851 << 30 | y1$851 >>> 2; + y1$851 = y0$849; + y0$849 = t0$859; + H$843[j$848 >> 2] = t1$860; + } + for (j$848 = k$845 + 80 | 0; (j$848 | 0) < (k$845 + 160 | 0); j$848 = j$848 + 4 | 0) { + t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31; + t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 ^ y2$853 ^ y3$855) | 0) + ((t1$860 + y4$857 | 0) + 1859775393 | 0) | 0; + y4$857 = y3$855; + y3$855 = y2$853; + y2$853 = y1$851 << 30 | y1$851 >>> 2; + y1$851 = y0$849; + y0$849 = t0$859; + H$843[j$848 >> 2] = t1$860; + } + for (j$848 = k$845 + 160 | 0; (j$848 | 0) < (k$845 + 240 | 0); j$848 = j$848 + 4 | 0) { + t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31; + t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 & y2$853 | y1$851 & y3$855 | y2$853 & y3$855) | 0) + ((t1$860 + y4$857 | 0) - 1894007588 | 0) | 0; + y4$857 = y3$855; + y3$855 = y2$853; + y2$853 = y1$851 << 30 | y1$851 >>> 2; + y1$851 = y0$849; + y0$849 = t0$859; + H$843[j$848 >> 2] = t1$860; + } + for (j$848 = k$845 + 240 | 0; (j$848 | 0) < (k$845 + 320 | 0); j$848 = j$848 + 4 | 0) { + t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31; + t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 ^ y2$853 ^ y3$855) | 0) + ((t1$860 + y4$857 | 0) - 899497514 | 0) | 0; + y4$857 = y3$855; + y3$855 = y2$853; + y2$853 = y1$851 << 30 | y1$851 >>> 2; + y1$851 = y0$849; + y0$849 = t0$859; + H$843[j$848 >> 2] = t1$860; + } + y0$849 = y0$849 + z0$850 | 0; + y1$851 = y1$851 + z1$852 | 0; + y2$853 = y2$853 + z2$854 | 0; + y3$855 = y3$855 + z3$856 | 0; + y4$857 = y4$857 + z4$858 | 0; + } + H$843[x$846 + 320 >> 2] = y0$849; + H$843[x$846 + 324 >> 2] = y1$851; + H$843[x$846 + 328 >> 2] = y2$853; + H$843[x$846 + 332 >> 2] = y3$855; + H$843[x$846 + 336 >> 2] = y4$857; + } + return { hash: hash$844 }; + } + + var core = /*#__PURE__*/Object.freeze({ + __proto__: null, + RushaCore: RushaCore + }); + + /* eslint-env commonjs, browser */ + // + // toHex + // + + const precomputedHex = new Array(256); + for (let i = 0; i < 256; i++) { + precomputedHex[i] = (i < 0x10 ? '0' : '') + i.toString(16); + } + + var toHex = (arrayBuffer) => { + const binarray = new Uint8Array(arrayBuffer); + const res = new Array(arrayBuffer.byteLength); + for (let i = 0; i < res.length; i++) { + res[i] = precomputedHex[binarray[i]]; + } + return res.join(''); + }; + + // + // ceilHeapSize + // + + var ceilHeapSize = (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. + let p = 0; + // 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; + }; + + // + // isDedicatedWorkerScope + // + + var isDedicatedWorkerScope = (self) => { + const isRunningInWorker = 'WorkerGlobalScope' in self + && self instanceof self.WorkerGlobalScope; + const isRunningInSharedWorker = 'SharedWorkerGlobalScope' in self + && self instanceof self.SharedWorkerGlobalScope; + const isRunningInServiceWorker = 'ServiceWorkerGlobalScope' in self + && self instanceof self.ServiceWorkerGlobalScope; + + // Detects whether we run inside a dedicated worker or not. + // + // We can't just check for `DedicatedWorkerGlobalScope`, since IE11 + // has a bug where it only supports `WorkerGlobalScope`. + // + // Therefore, we consider us as running inside a dedicated worker + // when we are running inside a worker, but not in a shared or service worker. + // + // When new types of workers are introduced, we will need to adjust this code. + return isRunningInWorker + && !isRunningInSharedWorker + && !isRunningInServiceWorker; + }; + + var utils = { + toHex: toHex, + ceilHeapSize: ceilHeapSize, + isDedicatedWorkerScope: isDedicatedWorkerScope + }; + + /* eslint-env commonjs, browser */ + let reader; + if (typeof self !== 'undefined' && typeof self.FileReaderSync !== 'undefined') { + reader = new self.FileReaderSync(); + } + + // Convert a binary string and write it to the heap. + // A binary string is expected to only contain char codes < 256. + const convStr = (str, H8, H32, start, len, off) => { + let i, om = off % 4, lm = (len + om) % 4, j = len - lm; + switch (om) { + case 0: H8[off] = str.charCodeAt(start+3); + case 1: H8[off+1-(om<<1)|0] = str.charCodeAt(start+2); + case 2: H8[off+2-(om<<1)|0] = str.charCodeAt(start+1); + case 3: H8[off+3-(om<<1)|0] = str.charCodeAt(start); + } + if (len < lm + (4-om)) { + return; + } + for (i = 4 - 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. + const convBuf = (buf, H8, H32, start, len, off) => { + let i, om = off % 4, lm = (len + om) % 4, j = len - lm; + switch (om) { + case 0: H8[off] = buf[start + 3]; + case 1: H8[off+1-(om<<1)|0] = buf[start+2]; + case 2: H8[off+2-(om<<1)|0] = buf[start+1]; + case 3: H8[off+3-(om<<1)|0] = buf[start]; + } + if (len < lm + (4-om)) { + return; + } + for (i = 4 - om; i < j; i = i + 4 | 0) { + H32[off+i>>2|0] = 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]; + } + }; + + const convBlob = (blob, H8, H32, start, len, off) => { + let i, om = off % 4, lm = (len + om) % 4, j = len - lm; + const buf = new Uint8Array(reader.readAsArrayBuffer(blob.slice(start, start + len))); + switch (om) { + case 0: H8[off] = buf[3]; + case 1: H8[off+1-(om<<1)|0] = buf[2]; + case 2: H8[off+2-(om<<1)|0] = buf[1]; + case 3: H8[off+3-(om<<1)|0] = buf[0]; + } + if (len < lm + (4-om)) { + return; + } + for (i = 4 - om; i < j; i = i + 4 | 0) { + H32[off+i>>2|0] = 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 conv = (data, H8, H32, start, len, off) => { + if (typeof data === 'string') { + return convStr(data, H8, H32, start, len, off); + } + if (data instanceof Array) { + return convBuf(data, H8, H32, start, len, off); + } + // Safely doing a Buffer check using "this" to avoid Buffer polyfill to be included in the dist + if ((self||window).Buffer && Buffer.isBuffer(data)) { + return convBuf(data, H8, H32, start, len, off); + } + if (data instanceof ArrayBuffer) { + return convBuf(new Uint8Array(data), H8, H32, start, len, off); + } + if (data.buffer instanceof ArrayBuffer) { + return convBuf(new Uint8Array(data.buffer, data.byteOffset, data.byteLength), H8, H32, start, len, off); + } + if (data instanceof Blob) { + return convBlob(data, H8, H32, start, len, off); + } + throw new Error('Unsupported data type.'); + }; + + function getAugmentedNamespace(n) { + if (n.__esModule) return n; + var a = Object.defineProperty({}, '__esModule', {value: true}); + Object.keys(n).forEach(function (k) { + var d = Object.getOwnPropertyDescriptor(n, k); + Object.defineProperty(a, k, d.get ? d : { + enumerable: true, + get: function () { + return n[k]; + } + }); + }); + return a; + } + + var RushaCore$1 = /*@__PURE__*/getAugmentedNamespace(core); + + /* eslint-env commonjs, browser */ + + const {toHex: toHex$1, ceilHeapSize: ceilHeapSize$1} = utils; + + + // Calculate the length of buffer that the sha1 routine uses + // including the padding. + const padlen = (len) => { + for (len += 9; len % 64 > 0; len += 1); + return len; + }; + + const padZeroes = (bin, len) => { + const h8 = new Uint8Array(bin.buffer); + const om = len % 4, align = len - om; + switch (om) { + case 0: h8[align + 3] = 0; + case 1: h8[align + 2] = 0; + case 2: h8[align + 1] = 0; + case 3: h8[align + 0] = 0; + } + for (let i = (len >> 2) + 1; i < bin.length; i++) { + bin[i] = 0; + } + }; + + const padData = (bin, chunkLen, msgLen) => { + bin[chunkLen>>2] |= 0x80 << (24 - (chunkLen % 4 << 3)); + // To support msgLen >= 2 GiB, use a float division when computing the + // high 32-bits of the big-endian message length in bits. + bin[(((chunkLen >> 2) + 2) & ~0x0f) + 14] = (msgLen / (1 << 29)) |0; + bin[(((chunkLen >> 2) + 2) & ~0x0f) + 15] = msgLen << 3; + }; + + const getRawDigest = (heap, padMaxChunkLen) => { + const io = new Int32Array(heap, padMaxChunkLen + 320, 5); + const out = new Int32Array(5); + const 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; + }; + + class Rusha { + constructor(chunkSize) { + chunkSize = chunkSize || 64 * 1024; + if (chunkSize % 64 > 0) { + throw new Error('Chunk size must be a multiple of 128 bit'); + } + this._offset = 0; + this._maxChunkLen = chunkSize; + this._padMaxChunkLen = padlen(chunkSize); + // 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 + this._heap = new ArrayBuffer(ceilHeapSize$1(this._padMaxChunkLen + 320 + 20)); + this._h32 = new Int32Array(this._heap); + this._h8 = new Int8Array(this._heap); + this._core = new RushaCore$1({Int32Array: Int32Array}, {}, this._heap); + } + + _initState(heap, padMsgLen) { + this._offset = 0; + const io = new Int32Array(heap, padMsgLen + 320, 5); + io[0] = 1732584193; + io[1] = -271733879; + io[2] = -1732584194; + io[3] = 271733878; + io[4] = -1009589776; + } + + _padChunk(chunkLen, msgLen) { + const padChunkLen = padlen(chunkLen); + const view = new Int32Array(this._heap, 0, padChunkLen >> 2); + padZeroes(view, chunkLen); + padData(view, chunkLen, msgLen); + return padChunkLen; + } + + _write(data, chunkOffset, chunkLen, off) { + conv(data, this._h8, this._h32, chunkOffset, chunkLen, off || 0); + } + + _coreCall(data, chunkOffset, chunkLen, msgLen, finalize) { + let padChunkLen = chunkLen; + this._write(data, chunkOffset, chunkLen); + if (finalize) { + padChunkLen = this._padChunk(chunkLen, msgLen); + } + this._core.hash(padChunkLen, this._padMaxChunkLen); + } + + rawDigest(str) { + const msgLen = str.byteLength || str.length || str.size || 0; + this._initState(this._heap, this._padMaxChunkLen); + let chunkOffset = 0, chunkLen = this._maxChunkLen; + for (chunkOffset = 0; msgLen > chunkOffset + chunkLen; chunkOffset += chunkLen) { + this._coreCall(str, chunkOffset, chunkLen, msgLen, false); + } + this._coreCall(str, chunkOffset, msgLen - chunkOffset, msgLen, true); + return getRawDigest(this._heap, this._padMaxChunkLen); + } + + digest(str) { + return toHex$1(this.rawDigest(str).buffer); + } + } + + w.Rusha = Rusha; + +})(this); diff --git a/vendors/openpgp-2.6.2/src/util.js b/vendors/openpgp-2.6.2/src/util.js index 92ebe36af..62bb3f76b 100644 --- a/vendors/openpgp-2.6.2/src/util.js +++ b/vendors/openpgp-2.6.2/src/util.js @@ -360,32 +360,6 @@ export default { return checksum.s; }, - /** - * Helper function to print a debug message. Debug - * messages are only printed if - * @link module:config/config.debug is set to true. - * @param {String} str String of the debug message - */ - print_debug: function (str) { - if (config.debug) { - console.log(str); - } - }, - - /** - * Helper function to print a debug message. Debug - * messages are only printed if - * @link module:config/config.debug is set to true. - * 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) { - str = str + this.hexstrdump(strToHex); - console.log(str); - } - }, - getLeftNBits: function (string, bitcount) { var rest = bitcount % 8; if (rest === 0) { @@ -444,24 +418,18 @@ export default { /** * Get native Web Cryptography api, only the current version of the spec. - * The default configuration is to use the api when available. But it can - * be deactivated with config.use_native + * The default configuration is to use the api when available. * @return {Object} The SubtleCrypto api or 'undefined' */ - getWebCrypto: () => config.use_native && browser && browser.crypto && browser.crypto.subtle, + getWebCrypto: () => browser && browser.crypto && browser.crypto.subtle, /** * Get native Web Cryptography api for all browsers, including legacy * implementations of the spec e.g IE11 and Safari 8/9. The default - * configuration is to use the api when available. But it can be deactivated - * with config.use_native + * configuration is to use the api when available. * @return {Object} The SubtleCrypto api or 'undefined' */ getWebCryptoAll: function() { - if (!config.use_native) { - return; - } - if (browser) { if (browser.crypto) { return browser.crypto.subtle || browser.crypto.webkitSubtle;