diff --git a/.travis.yml b/.travis.yml index 4036a6f..5db325c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: node_js node_js: - - "0.12.15" - - "4.5" - - "6.5.0" + - "6.11.4" + - "8.6.0" before_install: - npm install coveralls - npm install mocha-lcov-reporter diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d4672..d030b4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## v0.5.0 / 2017-10-07 +### Added +- support for web worker. #5 + +### Changed +- throw error if input type is incorrect. + ## v0.4.0 / 2017-07-08 ### Added - Streaming support(update). diff --git a/bower.json b/bower.json index 71c9f7b..14484c9 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-sha512", - "version": "0.4.0", + "version": "0.5.0", "main": ["src/sha512.js"], "ignore": [ "samples", diff --git a/build/sha512.min.js b/build/sha512.min.js index 0e842c1..0575e47 100644 --- a/build/sha512.min.js +++ b/build/sha512.min.js @@ -1,9 +1,9 @@ /* * [js-sha512]{@link https://github.com/emn178/js-sha512} * - * @version 0.4.0 + * @version 0.5.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2017 * @license MIT */ -!function(){"use strict";function h(h,t){t?(u[0]=u[1]=u[2]=u[3]=u[4]=u[5]=u[6]=u[7]=u[8]=u[9]=u[10]=u[11]=u[12]=u[13]=u[14]=u[15]=u[16]=u[17]=u[18]=u[19]=u[20]=u[21]=u[22]=u[23]=u[24]=u[25]=u[26]=u[27]=u[28]=u[29]=u[30]=u[31]=u[32]=0,this.blocks=u):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],384==h?(this.h0h=3418070365,this.h0l=3238371032,this.h1h=1654270250,this.h1l=914150663,this.h2h=2438529370,this.h2l=812702999,this.h3h=355462360,this.h3l=4144912697,this.h4h=1731405415,this.h4l=4290775857,this.h5h=2394180231,this.h5l=1750603025,this.h6h=3675008525,this.h6l=1694076839,this.h7h=1203062813,this.h7l=3204075428):256==h?(this.h0h=573645204,this.h0l=4230739756,this.h1h=2673172387,this.h1l=3360449730,this.h2h=596883563,this.h2l=1867755857,this.h3h=2520282905,this.h3l=1497426621,this.h4h=2519219938,this.h4l=2827943907,this.h5h=3193839141,this.h5l=1401305490,this.h6h=721525244,this.h6l=746961066,this.h7h=246885852,this.h7l=2177182882):224==h?(this.h0h=2352822216,this.h0l=424955298,this.h1h=1944164710,this.h1l=2312950998,this.h2h=502970286,this.h2l=855612546,this.h3h=1738396948,this.h3l=1479516111,this.h4h=258812777,this.h4l=2077511080,this.h5h=2011393907,this.h5l=79989058,this.h6h=1067287976,this.h6l=1780299464,this.h7h=286451373,this.h7l=2446758561):(this.h0h=1779033703,this.h0l=4089235720,this.h1h=3144134277,this.h1l=2227873595,this.h2h=1013904242,this.h2l=4271175723,this.h3h=2773480762,this.h3l=1595750129,this.h4h=1359893119,this.h4l=2917565137,this.h5h=2600822924,this.h5l=725511199,this.h6h=528734635,this.h6l=4215389547,this.h7h=1541459225,this.h7l=327033209),this.bits=h,this.block=this.start=this.bytes=0,this.finalized=this.hashed=!1}var t="object"==typeof window?window:{},s=!t.JS_SHA512_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;s&&(t=global);var i=!t.JS_SHA512_NO_COMMON_JS&&"object"==typeof module&&module.exports,e="function"==typeof define&&define.amd,l="undefined"!=typeof ArrayBuffer,r="0123456789abcdef".split(""),n=[-2147483648,8388608,32768,128],o=[24,16,8,0],a=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],f=["hex","array","digest","arrayBuffer"],u=[],c=function(t,s){return function(i){return new h(s,!0).update(i)[t]()}},p=function(t){var s=c("hex",t);s.create=function(){return new h(t)},s.update=function(h){return s.create().update(h)};for(var i=0;ir;){if(this.hashed&&(this.hashed=!1,a[0]=this.block,a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=a[16]=a[17]=a[18]=a[19]=a[20]=a[21]=a[22]=a[23]=a[24]=a[25]=a[26]=a[27]=a[28]=a[29]=a[30]=a[31]=a[32]=0),s)for(e=this.start;n>r&&128>e;++r)a[e>>2]|=h[r]<r&&128>e;++r)i=h.charCodeAt(r),128>i?a[e>>2]|=i<i?(a[e>>2]|=(192|i>>6)<>2]|=(128|63&i)<i||i>=57344?(a[e>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<=128?(this.block=a[32],this.start=e-128,this.hash(),this.hashed=!0):this.start=e}return this}},h.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var h=this.blocks,t=this.lastByteIndex;h[32]=this.block,h[t>>2]|=n[3&t],this.block=h[32],t>=112&&(this.hashed||this.hash(),h[0]=this.block,h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7]=h[8]=h[9]=h[10]=h[11]=h[12]=h[13]=h[14]=h[15]=h[16]=h[17]=h[18]=h[19]=h[20]=h[21]=h[22]=h[23]=h[24]=h[25]=h[26]=h[27]=h[28]=h[29]=h[30]=h[31]=h[32]=0),h[31]=this.bytes<<3,this.hash()}},h.prototype.hash=function(){var h,t,s,i,e,l,r,n,o,f,u,c,p,d,y,b,U,v,_,k,w,g,x,z,A,B=this.h0h,S=this.h0l,O=this.h1h,m=this.h1l,J=this.h2h,N=this.h2l,j=this.h3h,C=this.h3l,D=this.h4h,H=this.h4l,I=this.h5h,M=this.h5l,E=this.h6h,V=this.h6l,q=this.h7h,F=this.h7l,G=this.blocks;for(h=32;160>h;h+=2)k=G[h-30],w=G[h-29],t=(k>>>1|w<<31)^(k>>>8|w<<24)^k>>>7,s=(w>>>1|k<<31)^(w>>>8|k<<24)^(w>>>7|k<<25),k=G[h-4],w=G[h-3],i=(k>>>19|w<<13)^(w>>>29|k<<3)^k>>>6,e=(w>>>19|k<<13)^(k>>>29|w<<3)^(w>>>6|k<<26),k=G[h-32],w=G[h-31],g=G[h-14],x=G[h-13],l=(65535&x)+(65535&w)+(65535&s)+(65535&e),r=(x>>>16)+(w>>>16)+(s>>>16)+(e>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(65535&t)+(65535&i)+(r>>>16),o=(g>>>16)+(k>>>16)+(t>>>16)+(i>>>16)+(n>>>16),G[h]=o<<16|65535&n,G[h+1]=r<<16|65535&l;var K=B,L=S,P=O,Q=m,R=J,T=N,W=j,X=C,Y=D,Z=H,$=I,hh=M,th=E,sh=V,ih=q,eh=F;for(b=P&R,U=Q&T,h=0;160>h;h+=8)t=(K>>>28|L<<4)^(L>>>2|K<<30)^(L>>>7|K<<25),s=(L>>>28|K<<4)^(K>>>2|L<<30)^(K>>>7|L<<25),i=(Y>>>14|Z<<18)^(Y>>>18|Z<<14)^(Z>>>9|Y<<23),e=(Z>>>14|Y<<18)^(Z>>>18|Y<<14)^(Y>>>9|Z<<23),f=K&P,u=L&Q,v=f^K&R^b,_=u^L&T^U,z=Y&$^~Y&th,A=Z&hh^~Z&sh,k=G[h],w=G[h+1],g=a[h],x=a[h+1],l=(65535&x)+(65535&w)+(65535&A)+(65535&e)+(65535&eh),r=(x>>>16)+(w>>>16)+(A>>>16)+(e>>>16)+(eh>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(65535&z)+(65535&i)+(65535&ih)+(r>>>16),o=(g>>>16)+(k>>>16)+(z>>>16)+(i>>>16)+(ih>>>16)+(n>>>16),k=o<<16|65535&n,w=r<<16|65535&l,l=(65535&_)+(65535&s),r=(_>>>16)+(s>>>16)+(l>>>16),n=(65535&v)+(65535&t)+(r>>>16),o=(v>>>16)+(t>>>16)+(n>>>16),g=o<<16|65535&n,x=r<<16|65535&l,l=(65535&X)+(65535&w),r=(X>>>16)+(w>>>16)+(l>>>16),n=(65535&W)+(65535&k)+(r>>>16),o=(W>>>16)+(k>>>16)+(n>>>16),ih=o<<16|65535&n,eh=r<<16|65535&l,l=(65535&x)+(65535&w),r=(x>>>16)+(w>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(r>>>16),o=(g>>>16)+(k>>>16)+(n>>>16),W=o<<16|65535&n,X=r<<16|65535&l,t=(W>>>28|X<<4)^(X>>>2|W<<30)^(X>>>7|W<<25),s=(X>>>28|W<<4)^(W>>>2|X<<30)^(W>>>7|X<<25),i=(ih>>>14|eh<<18)^(ih>>>18|eh<<14)^(eh>>>9|ih<<23),e=(eh>>>14|ih<<18)^(eh>>>18|ih<<14)^(ih>>>9|eh<<23),c=W&K,p=X&L,v=c^W&P^f,_=p^X&Q^u,z=ih&Y^~ih&$,A=eh&Z^~eh&hh,k=G[h+2],w=G[h+3],g=a[h+2],x=a[h+3],l=(65535&x)+(65535&w)+(65535&A)+(65535&e)+(65535&sh),r=(x>>>16)+(w>>>16)+(A>>>16)+(e>>>16)+(sh>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(65535&z)+(65535&i)+(65535&th)+(r>>>16),o=(g>>>16)+(k>>>16)+(z>>>16)+(i>>>16)+(th>>>16)+(n>>>16),k=o<<16|65535&n,w=r<<16|65535&l,l=(65535&_)+(65535&s),r=(_>>>16)+(s>>>16)+(l>>>16),n=(65535&v)+(65535&t)+(r>>>16),o=(v>>>16)+(t>>>16)+(n>>>16),g=o<<16|65535&n,x=r<<16|65535&l,l=(65535&T)+(65535&w),r=(T>>>16)+(w>>>16)+(l>>>16),n=(65535&R)+(65535&k)+(r>>>16),o=(R>>>16)+(k>>>16)+(n>>>16),th=o<<16|65535&n,sh=r<<16|65535&l,l=(65535&x)+(65535&w),r=(x>>>16)+(w>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(r>>>16),o=(g>>>16)+(k>>>16)+(n>>>16),R=o<<16|65535&n,T=r<<16|65535&l,t=(R>>>28|T<<4)^(T>>>2|R<<30)^(T>>>7|R<<25),s=(T>>>28|R<<4)^(R>>>2|T<<30)^(R>>>7|T<<25),i=(th>>>14|sh<<18)^(th>>>18|sh<<14)^(sh>>>9|th<<23),e=(sh>>>14|th<<18)^(sh>>>18|th<<14)^(th>>>9|sh<<23),d=R&W,y=T&X,v=d^R&K^c,_=y^T&L^p,z=th&ih^~th&Y,A=sh&eh^~sh&Z,k=G[h+4],w=G[h+5],g=a[h+4],x=a[h+5],l=(65535&x)+(65535&w)+(65535&A)+(65535&e)+(65535&hh),r=(x>>>16)+(w>>>16)+(A>>>16)+(e>>>16)+(hh>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(65535&z)+(65535&i)+(65535&$)+(r>>>16),o=(g>>>16)+(k>>>16)+(z>>>16)+(i>>>16)+($>>>16)+(n>>>16),k=o<<16|65535&n,w=r<<16|65535&l,l=(65535&_)+(65535&s),r=(_>>>16)+(s>>>16)+(l>>>16),n=(65535&v)+(65535&t)+(r>>>16),o=(v>>>16)+(t>>>16)+(n>>>16),g=o<<16|65535&n,x=r<<16|65535&l,l=(65535&Q)+(65535&w),r=(Q>>>16)+(w>>>16)+(l>>>16),n=(65535&P)+(65535&k)+(r>>>16),o=(P>>>16)+(k>>>16)+(n>>>16),$=o<<16|65535&n,hh=r<<16|65535&l,l=(65535&x)+(65535&w),r=(x>>>16)+(w>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(r>>>16),o=(g>>>16)+(k>>>16)+(n>>>16),P=o<<16|65535&n,Q=r<<16|65535&l,t=(P>>>28|Q<<4)^(Q>>>2|P<<30)^(Q>>>7|P<<25),s=(Q>>>28|P<<4)^(P>>>2|Q<<30)^(P>>>7|Q<<25),i=($>>>14|hh<<18)^($>>>18|hh<<14)^(hh>>>9|$<<23),e=(hh>>>14|$<<18)^(hh>>>18|$<<14)^($>>>9|hh<<23),b=P&R,U=Q&T,v=b^P&W^d,_=U^Q&X^y,z=$&th^~$&ih,A=hh&sh^~hh&eh,k=G[h+6],w=G[h+7],g=a[h+6],x=a[h+7],l=(65535&x)+(65535&w)+(65535&A)+(65535&e)+(65535&Z),r=(x>>>16)+(w>>>16)+(A>>>16)+(e>>>16)+(Z>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(65535&z)+(65535&i)+(65535&Y)+(r>>>16),o=(g>>>16)+(k>>>16)+(z>>>16)+(i>>>16)+(Y>>>16)+(n>>>16),k=o<<16|65535&n,w=r<<16|65535&l,l=(65535&_)+(65535&s),r=(_>>>16)+(s>>>16)+(l>>>16),n=(65535&v)+(65535&t)+(r>>>16),o=(v>>>16)+(t>>>16)+(n>>>16),g=o<<16|65535&n,x=r<<16|65535&l,l=(65535&L)+(65535&w),r=(L>>>16)+(w>>>16)+(l>>>16),n=(65535&K)+(65535&k)+(r>>>16),o=(K>>>16)+(k>>>16)+(n>>>16),Y=o<<16|65535&n,Z=r<<16|65535&l,l=(65535&x)+(65535&w),r=(x>>>16)+(w>>>16)+(l>>>16),n=(65535&g)+(65535&k)+(r>>>16),o=(g>>>16)+(k>>>16)+(n>>>16),K=o<<16|65535&n,L=r<<16|65535&l;l=(65535&S)+(65535&L),r=(S>>>16)+(L>>>16)+(l>>>16),n=(65535&B)+(65535&K)+(r>>>16),o=(B>>>16)+(K>>>16)+(n>>>16),this.h0h=o<<16|65535&n,this.h0l=r<<16|65535&l,l=(65535&m)+(65535&Q),r=(m>>>16)+(Q>>>16)+(l>>>16),n=(65535&O)+(65535&P)+(r>>>16),o=(O>>>16)+(P>>>16)+(n>>>16),this.h1h=o<<16|65535&n,this.h1l=r<<16|65535&l,l=(65535&N)+(65535&T),r=(N>>>16)+(T>>>16)+(l>>>16),n=(65535&J)+(65535&R)+(r>>>16),o=(J>>>16)+(R>>>16)+(n>>>16),this.h2h=o<<16|65535&n,this.h2l=r<<16|65535&l,l=(65535&C)+(65535&X),r=(C>>>16)+(X>>>16)+(l>>>16),n=(65535&j)+(65535&W)+(r>>>16),o=(j>>>16)+(W>>>16)+(n>>>16),this.h3h=o<<16|65535&n,this.h3l=r<<16|65535&l,l=(65535&H)+(65535&Z),r=(H>>>16)+(Z>>>16)+(l>>>16),n=(65535&D)+(65535&Y)+(r>>>16),o=(D>>>16)+(Y>>>16)+(n>>>16),this.h4h=o<<16|65535&n,this.h4l=r<<16|65535&l,l=(65535&M)+(65535&hh),r=(M>>>16)+(hh>>>16)+(l>>>16),n=(65535&I)+(65535&$)+(r>>>16),o=(I>>>16)+($>>>16)+(n>>>16),this.h5h=o<<16|65535&n,this.h5l=r<<16|65535&l,l=(65535&V)+(65535&sh),r=(V>>>16)+(sh>>>16)+(l>>>16),n=(65535&E)+(65535&th)+(r>>>16),o=(E>>>16)+(th>>>16)+(n>>>16),this.h6h=o<<16|65535&n,this.h6l=r<<16|65535&l,l=(65535&F)+(65535&eh),r=(F>>>16)+(eh>>>16)+(l>>>16),n=(65535&q)+(65535&ih)+(r>>>16),o=(q>>>16)+(ih>>>16)+(n>>>16),this.h7h=o<<16|65535&n,this.h7l=r<<16|65535&l},h.prototype.hex=function(){this.finalize();var h=this.h0h,t=this.h0l,s=this.h1h,i=this.h1l,e=this.h2h,l=this.h2l,n=this.h3h,o=this.h3l,a=this.h4h,f=this.h4l,u=this.h5h,c=this.h5l,p=this.h6h,d=this.h6l,y=this.h7h,b=this.h7l,U=this.bits,v=r[h>>28&15]+r[h>>24&15]+r[h>>20&15]+r[h>>16&15]+r[h>>12&15]+r[h>>8&15]+r[h>>4&15]+r[15&h]+r[t>>28&15]+r[t>>24&15]+r[t>>20&15]+r[t>>16&15]+r[t>>12&15]+r[t>>8&15]+r[t>>4&15]+r[15&t]+r[s>>28&15]+r[s>>24&15]+r[s>>20&15]+r[s>>16&15]+r[s>>12&15]+r[s>>8&15]+r[s>>4&15]+r[15&s]+r[i>>28&15]+r[i>>24&15]+r[i>>20&15]+r[i>>16&15]+r[i>>12&15]+r[i>>8&15]+r[i>>4&15]+r[15&i]+r[e>>28&15]+r[e>>24&15]+r[e>>20&15]+r[e>>16&15]+r[e>>12&15]+r[e>>8&15]+r[e>>4&15]+r[15&e]+r[l>>28&15]+r[l>>24&15]+r[l>>20&15]+r[l>>16&15]+r[l>>12&15]+r[l>>8&15]+r[l>>4&15]+r[15&l]+r[n>>28&15]+r[n>>24&15]+r[n>>20&15]+r[n>>16&15]+r[n>>12&15]+r[n>>8&15]+r[n>>4&15]+r[15&n];return U>=256&&(v+=r[o>>28&15]+r[o>>24&15]+r[o>>20&15]+r[o>>16&15]+r[o>>12&15]+r[o>>8&15]+r[o>>4&15]+r[15&o]),U>=384&&(v+=r[a>>28&15]+r[a>>24&15]+r[a>>20&15]+r[a>>16&15]+r[a>>12&15]+r[a>>8&15]+r[a>>4&15]+r[15&a]+r[f>>28&15]+r[f>>24&15]+r[f>>20&15]+r[f>>16&15]+r[f>>12&15]+r[f>>8&15]+r[f>>4&15]+r[15&f]+r[u>>28&15]+r[u>>24&15]+r[u>>20&15]+r[u>>16&15]+r[u>>12&15]+r[u>>8&15]+r[u>>4&15]+r[15&u]+r[c>>28&15]+r[c>>24&15]+r[c>>20&15]+r[c>>16&15]+r[c>>12&15]+r[c>>8&15]+r[c>>4&15]+r[15&c]),512==U&&(v+=r[p>>28&15]+r[p>>24&15]+r[p>>20&15]+r[p>>16&15]+r[p>>12&15]+r[p>>8&15]+r[p>>4&15]+r[15&p]+r[d>>28&15]+r[d>>24&15]+r[d>>20&15]+r[d>>16&15]+r[d>>12&15]+r[d>>8&15]+r[d>>4&15]+r[15&d]+r[y>>28&15]+r[y>>24&15]+r[y>>20&15]+r[y>>16&15]+r[y>>12&15]+r[y>>8&15]+r[y>>4&15]+r[15&y]+r[b>>28&15]+r[b>>24&15]+r[b>>20&15]+r[b>>16&15]+r[b>>12&15]+r[b>>8&15]+r[b>>4&15]+r[15&b]),v},h.prototype.toString=h.prototype.hex,h.prototype.digest=function(){this.finalize();var h=this.h0h,t=this.h0l,s=this.h1h,i=this.h1l,e=this.h2h,l=this.h2l,r=this.h3h,n=this.h3l,o=this.h4h,a=this.h4l,f=this.h5h,u=this.h5l,c=this.h6h,p=this.h6l,d=this.h7h,y=this.h7l,b=this.bits,U=[h>>24&255,h>>16&255,h>>8&255,255&h,t>>24&255,t>>16&255,t>>8&255,255&t,s>>24&255,s>>16&255,s>>8&255,255&s,i>>24&255,i>>16&255,i>>8&255,255&i,e>>24&255,e>>16&255,e>>8&255,255&e,l>>24&255,l>>16&255,l>>8&255,255&l,r>>24&255,r>>16&255,r>>8&255,255&r];return b>=256&&U.push(n>>24&255,n>>16&255,n>>8&255,255&n),b>=384&&U.push(o>>24&255,o>>16&255,o>>8&255,255&o,a>>24&255,a>>16&255,a>>8&255,255&a,f>>24&255,f>>16&255,f>>8&255,255&f,u>>24&255,u>>16&255,u>>8&255,255&u),512==b&&U.push(c>>24&255,c>>16&255,c>>8&255,255&c,p>>24&255,p>>16&255,p>>8&255,255&p,d>>24&255,d>>16&255,d>>8&255,255&d,y>>24&255,y>>16&255,y>>8&255,255&y),U},h.prototype.array=h.prototype.digest,h.prototype.arrayBuffer=function(){this.finalize();var h=this.bits,t=new ArrayBuffer(h/8),s=new DataView(t);return s.setUint32(0,this.h0h),s.setUint32(4,this.h0l),s.setUint32(8,this.h1h),s.setUint32(12,this.h1l),s.setUint32(16,this.h2h),s.setUint32(20,this.h2l),s.setUint32(24,this.h3h),h>=256&&s.setUint32(28,this.h3l),h>=384&&(s.setUint32(32,this.h4h),s.setUint32(36,this.h4l),s.setUint32(40,this.h5h),s.setUint32(44,this.h5l)),512==h&&(s.setUint32(48,this.h6h),s.setUint32(52,this.h6l),s.setUint32(56,this.h7h),s.setUint32(60,this.h7l)),t};var d=p(512);d.sha512=d,d.sha384=p(384),d.sha512_256=p(256),d.sha512_224=p(224),i?module.exports=d:(t.sha512=d.sha512,t.sha384=d.sha384,t.sha512_256=d.sha512_256,t.sha512_224=d.sha512_224,e&&define(function(){return d}))}(); \ No newline at end of file +!function(){"use strict";function h(h,t){t?(y[0]=y[1]=y[2]=y[3]=y[4]=y[5]=y[6]=y[7]=y[8]=y[9]=y[10]=y[11]=y[12]=y[13]=y[14]=y[15]=y[16]=y[17]=y[18]=y[19]=y[20]=y[21]=y[22]=y[23]=y[24]=y[25]=y[26]=y[27]=y[28]=y[29]=y[30]=y[31]=y[32]=0,this.blocks=y):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],384==h?(this.h0h=3418070365,this.h0l=3238371032,this.h1h=1654270250,this.h1l=914150663,this.h2h=2438529370,this.h2l=812702999,this.h3h=355462360,this.h3l=4144912697,this.h4h=1731405415,this.h4l=4290775857,this.h5h=2394180231,this.h5l=1750603025,this.h6h=3675008525,this.h6l=1694076839,this.h7h=1203062813,this.h7l=3204075428):256==h?(this.h0h=573645204,this.h0l=4230739756,this.h1h=2673172387,this.h1l=3360449730,this.h2h=596883563,this.h2l=1867755857,this.h3h=2520282905,this.h3l=1497426621,this.h4h=2519219938,this.h4l=2827943907,this.h5h=3193839141,this.h5l=1401305490,this.h6h=721525244,this.h6l=746961066,this.h7h=246885852,this.h7l=2177182882):224==h?(this.h0h=2352822216,this.h0l=424955298,this.h1h=1944164710,this.h1l=2312950998,this.h2h=502970286,this.h2l=855612546,this.h3h=1738396948,this.h3l=1479516111,this.h4h=258812777,this.h4l=2077511080,this.h5h=2011393907,this.h5l=79989058,this.h6h=1067287976,this.h6l=1780299464,this.h7h=286451373,this.h7l=2446758561):(this.h0h=1779033703,this.h0l=4089235720,this.h1h=3144134277,this.h1l=2227873595,this.h2h=1013904242,this.h2l=4271175723,this.h3h=2773480762,this.h3l=1595750129,this.h4h=1359893119,this.h4l=2917565137,this.h5h=2600822924,this.h5l=725511199,this.h6h=528734635,this.h6l=4215389547,this.h7h=1541459225,this.h7l=327033209),this.bits=h,this.block=this.start=this.bytes=0,this.finalized=this.hashed=!1}var t="input is invalid type",i="object"==typeof window,s=i?window:{};s.JS_SHA512_NO_WINDOW&&(i=!1);var e=!i&&"object"==typeof self,r=!s.JS_SHA512_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;r?s=global:e&&(s=self);var l=!s.JS_SHA512_NO_COMMON_JS&&"object"==typeof module&&module.exports,n="function"==typeof define&&define.amd,o=!s.JS_SHA512_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,a="0123456789abcdef".split(""),f=[-2147483648,8388608,32768,128],u=[24,16,8,0],c=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],p=["hex","array","digest","arrayBuffer"],y=[];(s.JS_SHA512_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(h){return"[object Array]"===Object.prototype.toString.call(h)}),!o||!s.JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(h){return"object"==typeof h&&h.buffer&&h.buffer.constructor===ArrayBuffer});var d=function(t,i){return function(s){return new h(i,!0).update(s)[t]()}},_=function(t){var i=d("hex",t);i.create=function(){return new h(t)},i.update=function(h){return i.create().update(h)};for(var s=0;sn;){if(this.hashed&&(this.hashed=!1,a[0]=this.block,a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=a[16]=a[17]=a[18]=a[19]=a[20]=a[21]=a[22]=a[23]=a[24]=a[25]=a[26]=a[27]=a[28]=a[29]=a[30]=a[31]=a[32]=0),i)for(r=this.start;l>n&&128>r;++n)a[r>>2]|=h[n]<n&&128>r;++n)e=h.charCodeAt(n),128>e?a[r>>2]|=e<e?(a[r>>2]|=(192|e>>6)<>2]|=(128|63&e)<e||e>=57344?(a[r>>2]|=(224|e>>12)<>2]|=(128|e>>6&63)<>2]|=(128|63&e)<>2]|=(240|e>>18)<>2]|=(128|e>>12&63)<>2]|=(128|e>>6&63)<>2]|=(128|63&e)<=128?(this.block=a[32],this.start=r-128,this.hash(),this.hashed=!0):this.start=r}return this}},h.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var h=this.blocks,t=this.lastByteIndex;h[32]=this.block,h[t>>2]|=f[3&t],this.block=h[32],t>=112&&(this.hashed||this.hash(),h[0]=this.block,h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7]=h[8]=h[9]=h[10]=h[11]=h[12]=h[13]=h[14]=h[15]=h[16]=h[17]=h[18]=h[19]=h[20]=h[21]=h[22]=h[23]=h[24]=h[25]=h[26]=h[27]=h[28]=h[29]=h[30]=h[31]=h[32]=0),h[31]=this.bytes<<3,this.hash()}},h.prototype.hash=function(){var h,t,i,s,e,r,l,n,o,a,f,u,p,y,d,_,b,A,v,U,S,w,B,O,k,g=this.h0h,N=this.h0l,J=this.h1h,j=this.h1l,x=this.h2h,z=this.h2l,H=this.h3h,R=this.h3l,E=this.h4h,I=this.h4l,V=this.h5h,m=this.h5l,D=this.h6h,F=this.h6l,C=this.h7h,W=this.h7l,M=this.blocks;for(h=32;160>h;h+=2)U=M[h-30],S=M[h-29],t=(U>>>1|S<<31)^(U>>>8|S<<24)^U>>>7,i=(S>>>1|U<<31)^(S>>>8|U<<24)^(S>>>7|U<<25),U=M[h-4],S=M[h-3],s=(U>>>19|S<<13)^(S>>>29|U<<3)^U>>>6,e=(S>>>19|U<<13)^(U>>>29|S<<3)^(S>>>6|U<<26),U=M[h-32],S=M[h-31],w=M[h-14],B=M[h-13],r=(65535&B)+(65535&S)+(65535&i)+(65535&e),l=(B>>>16)+(S>>>16)+(i>>>16)+(e>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(65535&t)+(65535&s)+(l>>>16),o=(w>>>16)+(U>>>16)+(t>>>16)+(s>>>16)+(n>>>16),M[h]=o<<16|65535&n,M[h+1]=l<<16|65535&r;var Y=g,q=N,G=J,K=j,L=x,P=z,Q=H,T=R,X=E,Z=I,$=V,ht=m,tt=D,it=F,st=C,et=W;for(_=G&L,b=K&P,h=0;160>h;h+=8)t=(Y>>>28|q<<4)^(q>>>2|Y<<30)^(q>>>7|Y<<25),i=(q>>>28|Y<<4)^(Y>>>2|q<<30)^(Y>>>7|q<<25),s=(X>>>14|Z<<18)^(X>>>18|Z<<14)^(Z>>>9|X<<23),e=(Z>>>14|X<<18)^(Z>>>18|X<<14)^(X>>>9|Z<<23),a=Y&G,f=q&K,A=a^Y&L^_,v=f^q&P^b,O=X&$^~X&tt,k=Z&ht^~Z&it,U=M[h],S=M[h+1],w=c[h],B=c[h+1],r=(65535&B)+(65535&S)+(65535&k)+(65535&e)+(65535&et),l=(B>>>16)+(S>>>16)+(k>>>16)+(e>>>16)+(et>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(65535&O)+(65535&s)+(65535&st)+(l>>>16),o=(w>>>16)+(U>>>16)+(O>>>16)+(s>>>16)+(st>>>16)+(n>>>16),U=o<<16|65535&n,S=l<<16|65535&r,r=(65535&v)+(65535&i),l=(v>>>16)+(i>>>16)+(r>>>16),n=(65535&A)+(65535&t)+(l>>>16),o=(A>>>16)+(t>>>16)+(n>>>16),w=o<<16|65535&n,B=l<<16|65535&r,r=(65535&T)+(65535&S),l=(T>>>16)+(S>>>16)+(r>>>16),n=(65535&Q)+(65535&U)+(l>>>16),o=(Q>>>16)+(U>>>16)+(n>>>16),st=o<<16|65535&n,et=l<<16|65535&r,r=(65535&B)+(65535&S),l=(B>>>16)+(S>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(l>>>16),o=(w>>>16)+(U>>>16)+(n>>>16),Q=o<<16|65535&n,T=l<<16|65535&r,t=(Q>>>28|T<<4)^(T>>>2|Q<<30)^(T>>>7|Q<<25),i=(T>>>28|Q<<4)^(Q>>>2|T<<30)^(Q>>>7|T<<25),s=(st>>>14|et<<18)^(st>>>18|et<<14)^(et>>>9|st<<23),e=(et>>>14|st<<18)^(et>>>18|st<<14)^(st>>>9|et<<23),u=Q&Y,p=T&q,A=u^Q&G^a,v=p^T&K^f,O=st&X^~st&$,k=et&Z^~et&ht,U=M[h+2],S=M[h+3],w=c[h+2],B=c[h+3],r=(65535&B)+(65535&S)+(65535&k)+(65535&e)+(65535&it),l=(B>>>16)+(S>>>16)+(k>>>16)+(e>>>16)+(it>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(65535&O)+(65535&s)+(65535&tt)+(l>>>16),o=(w>>>16)+(U>>>16)+(O>>>16)+(s>>>16)+(tt>>>16)+(n>>>16),U=o<<16|65535&n,S=l<<16|65535&r,r=(65535&v)+(65535&i),l=(v>>>16)+(i>>>16)+(r>>>16),n=(65535&A)+(65535&t)+(l>>>16),o=(A>>>16)+(t>>>16)+(n>>>16),w=o<<16|65535&n,B=l<<16|65535&r,r=(65535&P)+(65535&S),l=(P>>>16)+(S>>>16)+(r>>>16),n=(65535&L)+(65535&U)+(l>>>16),o=(L>>>16)+(U>>>16)+(n>>>16),tt=o<<16|65535&n,it=l<<16|65535&r,r=(65535&B)+(65535&S),l=(B>>>16)+(S>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(l>>>16),o=(w>>>16)+(U>>>16)+(n>>>16),L=o<<16|65535&n,P=l<<16|65535&r,t=(L>>>28|P<<4)^(P>>>2|L<<30)^(P>>>7|L<<25),i=(P>>>28|L<<4)^(L>>>2|P<<30)^(L>>>7|P<<25),s=(tt>>>14|it<<18)^(tt>>>18|it<<14)^(it>>>9|tt<<23),e=(it>>>14|tt<<18)^(it>>>18|tt<<14)^(tt>>>9|it<<23),y=L&Q,d=P&T,A=y^L&Y^u,v=d^P&q^p,O=tt&st^~tt&X,k=it&et^~it&Z,U=M[h+4],S=M[h+5],w=c[h+4],B=c[h+5],r=(65535&B)+(65535&S)+(65535&k)+(65535&e)+(65535&ht),l=(B>>>16)+(S>>>16)+(k>>>16)+(e>>>16)+(ht>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(65535&O)+(65535&s)+(65535&$)+(l>>>16),o=(w>>>16)+(U>>>16)+(O>>>16)+(s>>>16)+($>>>16)+(n>>>16),U=o<<16|65535&n,S=l<<16|65535&r,r=(65535&v)+(65535&i),l=(v>>>16)+(i>>>16)+(r>>>16),n=(65535&A)+(65535&t)+(l>>>16),o=(A>>>16)+(t>>>16)+(n>>>16),w=o<<16|65535&n,B=l<<16|65535&r,r=(65535&K)+(65535&S),l=(K>>>16)+(S>>>16)+(r>>>16),n=(65535&G)+(65535&U)+(l>>>16),o=(G>>>16)+(U>>>16)+(n>>>16),$=o<<16|65535&n,ht=l<<16|65535&r,r=(65535&B)+(65535&S),l=(B>>>16)+(S>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(l>>>16),o=(w>>>16)+(U>>>16)+(n>>>16),G=o<<16|65535&n,K=l<<16|65535&r,t=(G>>>28|K<<4)^(K>>>2|G<<30)^(K>>>7|G<<25),i=(K>>>28|G<<4)^(G>>>2|K<<30)^(G>>>7|K<<25),s=($>>>14|ht<<18)^($>>>18|ht<<14)^(ht>>>9|$<<23),e=(ht>>>14|$<<18)^(ht>>>18|$<<14)^($>>>9|ht<<23),_=G&L,b=K&P,A=_^G&Q^y,v=b^K&T^d,O=$&tt^~$&st,k=ht&it^~ht&et,U=M[h+6],S=M[h+7],w=c[h+6],B=c[h+7],r=(65535&B)+(65535&S)+(65535&k)+(65535&e)+(65535&Z),l=(B>>>16)+(S>>>16)+(k>>>16)+(e>>>16)+(Z>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(65535&O)+(65535&s)+(65535&X)+(l>>>16),o=(w>>>16)+(U>>>16)+(O>>>16)+(s>>>16)+(X>>>16)+(n>>>16),U=o<<16|65535&n,S=l<<16|65535&r,r=(65535&v)+(65535&i),l=(v>>>16)+(i>>>16)+(r>>>16),n=(65535&A)+(65535&t)+(l>>>16),o=(A>>>16)+(t>>>16)+(n>>>16),w=o<<16|65535&n,B=l<<16|65535&r,r=(65535&q)+(65535&S),l=(q>>>16)+(S>>>16)+(r>>>16),n=(65535&Y)+(65535&U)+(l>>>16),o=(Y>>>16)+(U>>>16)+(n>>>16),X=o<<16|65535&n,Z=l<<16|65535&r,r=(65535&B)+(65535&S),l=(B>>>16)+(S>>>16)+(r>>>16),n=(65535&w)+(65535&U)+(l>>>16),o=(w>>>16)+(U>>>16)+(n>>>16),Y=o<<16|65535&n,q=l<<16|65535&r;r=(65535&N)+(65535&q),l=(N>>>16)+(q>>>16)+(r>>>16),n=(65535&g)+(65535&Y)+(l>>>16),o=(g>>>16)+(Y>>>16)+(n>>>16),this.h0h=o<<16|65535&n,this.h0l=l<<16|65535&r,r=(65535&j)+(65535&K),l=(j>>>16)+(K>>>16)+(r>>>16),n=(65535&J)+(65535&G)+(l>>>16),o=(J>>>16)+(G>>>16)+(n>>>16),this.h1h=o<<16|65535&n,this.h1l=l<<16|65535&r,r=(65535&z)+(65535&P),l=(z>>>16)+(P>>>16)+(r>>>16),n=(65535&x)+(65535&L)+(l>>>16),o=(x>>>16)+(L>>>16)+(n>>>16),this.h2h=o<<16|65535&n,this.h2l=l<<16|65535&r,r=(65535&R)+(65535&T),l=(R>>>16)+(T>>>16)+(r>>>16),n=(65535&H)+(65535&Q)+(l>>>16),o=(H>>>16)+(Q>>>16)+(n>>>16),this.h3h=o<<16|65535&n,this.h3l=l<<16|65535&r,r=(65535&I)+(65535&Z),l=(I>>>16)+(Z>>>16)+(r>>>16),n=(65535&E)+(65535&X)+(l>>>16),o=(E>>>16)+(X>>>16)+(n>>>16),this.h4h=o<<16|65535&n,this.h4l=l<<16|65535&r,r=(65535&m)+(65535&ht),l=(m>>>16)+(ht>>>16)+(r>>>16),n=(65535&V)+(65535&$)+(l>>>16),o=(V>>>16)+($>>>16)+(n>>>16),this.h5h=o<<16|65535&n,this.h5l=l<<16|65535&r,r=(65535&F)+(65535&it),l=(F>>>16)+(it>>>16)+(r>>>16),n=(65535&D)+(65535&tt)+(l>>>16),o=(D>>>16)+(tt>>>16)+(n>>>16),this.h6h=o<<16|65535&n,this.h6l=l<<16|65535&r,r=(65535&W)+(65535&et),l=(W>>>16)+(et>>>16)+(r>>>16),n=(65535&C)+(65535&st)+(l>>>16),o=(C>>>16)+(st>>>16)+(n>>>16),this.h7h=o<<16|65535&n,this.h7l=l<<16|65535&r},h.prototype.hex=function(){this.finalize();var h=this.h0h,t=this.h0l,i=this.h1h,s=this.h1l,e=this.h2h,r=this.h2l,l=this.h3h,n=this.h3l,o=this.h4h,f=this.h4l,u=this.h5h,c=this.h5l,p=this.h6h,y=this.h6l,d=this.h7h,_=this.h7l,b=this.bits,A=a[h>>28&15]+a[h>>24&15]+a[h>>20&15]+a[h>>16&15]+a[h>>12&15]+a[h>>8&15]+a[h>>4&15]+a[15&h]+a[t>>28&15]+a[t>>24&15]+a[t>>20&15]+a[t>>16&15]+a[t>>12&15]+a[t>>8&15]+a[t>>4&15]+a[15&t]+a[i>>28&15]+a[i>>24&15]+a[i>>20&15]+a[i>>16&15]+a[i>>12&15]+a[i>>8&15]+a[i>>4&15]+a[15&i]+a[s>>28&15]+a[s>>24&15]+a[s>>20&15]+a[s>>16&15]+a[s>>12&15]+a[s>>8&15]+a[s>>4&15]+a[15&s]+a[e>>28&15]+a[e>>24&15]+a[e>>20&15]+a[e>>16&15]+a[e>>12&15]+a[e>>8&15]+a[e>>4&15]+a[15&e]+a[r>>28&15]+a[r>>24&15]+a[r>>20&15]+a[r>>16&15]+a[r>>12&15]+a[r>>8&15]+a[r>>4&15]+a[15&r]+a[l>>28&15]+a[l>>24&15]+a[l>>20&15]+a[l>>16&15]+a[l>>12&15]+a[l>>8&15]+a[l>>4&15]+a[15&l];return b>=256&&(A+=a[n>>28&15]+a[n>>24&15]+a[n>>20&15]+a[n>>16&15]+a[n>>12&15]+a[n>>8&15]+a[n>>4&15]+a[15&n]),b>=384&&(A+=a[o>>28&15]+a[o>>24&15]+a[o>>20&15]+a[o>>16&15]+a[o>>12&15]+a[o>>8&15]+a[o>>4&15]+a[15&o]+a[f>>28&15]+a[f>>24&15]+a[f>>20&15]+a[f>>16&15]+a[f>>12&15]+a[f>>8&15]+a[f>>4&15]+a[15&f]+a[u>>28&15]+a[u>>24&15]+a[u>>20&15]+a[u>>16&15]+a[u>>12&15]+a[u>>8&15]+a[u>>4&15]+a[15&u]+a[c>>28&15]+a[c>>24&15]+a[c>>20&15]+a[c>>16&15]+a[c>>12&15]+a[c>>8&15]+a[c>>4&15]+a[15&c]),512==b&&(A+=a[p>>28&15]+a[p>>24&15]+a[p>>20&15]+a[p>>16&15]+a[p>>12&15]+a[p>>8&15]+a[p>>4&15]+a[15&p]+a[y>>28&15]+a[y>>24&15]+a[y>>20&15]+a[y>>16&15]+a[y>>12&15]+a[y>>8&15]+a[y>>4&15]+a[15&y]+a[d>>28&15]+a[d>>24&15]+a[d>>20&15]+a[d>>16&15]+a[d>>12&15]+a[d>>8&15]+a[d>>4&15]+a[15&d]+a[_>>28&15]+a[_>>24&15]+a[_>>20&15]+a[_>>16&15]+a[_>>12&15]+a[_>>8&15]+a[_>>4&15]+a[15&_]),A},h.prototype.toString=h.prototype.hex,h.prototype.digest=function(){this.finalize();var h=this.h0h,t=this.h0l,i=this.h1h,s=this.h1l,e=this.h2h,r=this.h2l,l=this.h3h,n=this.h3l,o=this.h4h,a=this.h4l,f=this.h5h,u=this.h5l,c=this.h6h,p=this.h6l,y=this.h7h,d=this.h7l,_=this.bits,b=[h>>24&255,h>>16&255,h>>8&255,255&h,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24&255,i>>16&255,i>>8&255,255&i,s>>24&255,s>>16&255,s>>8&255,255&s,e>>24&255,e>>16&255,e>>8&255,255&e,r>>24&255,r>>16&255,r>>8&255,255&r,l>>24&255,l>>16&255,l>>8&255,255&l];return _>=256&&b.push(n>>24&255,n>>16&255,n>>8&255,255&n),_>=384&&b.push(o>>24&255,o>>16&255,o>>8&255,255&o,a>>24&255,a>>16&255,a>>8&255,255&a,f>>24&255,f>>16&255,f>>8&255,255&f,u>>24&255,u>>16&255,u>>8&255,255&u),512==_&&b.push(c>>24&255,c>>16&255,c>>8&255,255&c,p>>24&255,p>>16&255,p>>8&255,255&p,y>>24&255,y>>16&255,y>>8&255,255&y,d>>24&255,d>>16&255,d>>8&255,255&d),b},h.prototype.array=h.prototype.digest,h.prototype.arrayBuffer=function(){this.finalize();var h=this.bits,t=new ArrayBuffer(h/8),i=new DataView(t);return i.setUint32(0,this.h0h),i.setUint32(4,this.h0l),i.setUint32(8,this.h1h),i.setUint32(12,this.h1l),i.setUint32(16,this.h2h),i.setUint32(20,this.h2l),i.setUint32(24,this.h3h),h>=256&&i.setUint32(28,this.h3l),h>=384&&(i.setUint32(32,this.h4h),i.setUint32(36,this.h4l),i.setUint32(40,this.h5h),i.setUint32(44,this.h5l)),512==h&&(i.setUint32(48,this.h6h),i.setUint32(52,this.h6l),i.setUint32(56,this.h7h),i.setUint32(60,this.h7l)),t};var b=_(512);b.sha512=b,b.sha384=_(384),b.sha512_256=_(256),b.sha512_224=_(224),l?module.exports=b:(s.sha512=b.sha512,s.sha384=b.sha384,s.sha512_256=b.sha512_256,s.sha512_224=b.sha512_224,n&&define(function(){return b}))}(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..0616b5d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,308 @@ +{ + "name": "js-sha512", + "version": "0.5.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "amdefine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", + "dev": true + }, + "async": { + "version": "0.2.10", + "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", + "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=", + "dev": true + }, + "bindings": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz", + "integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw==", + "dev": true + }, + "coffee-script": { + "version": "1.12.7", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz", + "integrity": "sha512-fLeEhqwymYat/MpTPUjSKHVYYl0ec2mOyALEMLmzr5i1isuG+6jfI2j2d5oBO3VIzgUXgBVIcOT9uH1TFxBckw==", + "dev": true + }, + "commander": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", + "integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=", + "dev": true + }, + "debug": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-1.0.3.tgz", + "integrity": "sha1-/IxrLWACgEtAgcAgjg9kYLofo+Q=", + "dev": true, + "requires": { + "ms": "0.6.2" + } + }, + "diff": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz", + "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=", + "dev": true + }, + "ejs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-1.0.0.tgz", + "integrity": "sha1-ycYKSKRu5FL7MqccMXuV5aofyz0=", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz", + "integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=", + "dev": true + }, + "expect.js": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/expect.js/-/expect.js-0.3.1.tgz", + "integrity": "sha1-sKWaDS7/VDdUTr8M6qYBWEHQm1s=", + "dev": true + }, + "glob": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz", + "integrity": "sha1-4xPusknHr/qlxHUoaw4RW1mDlGc=", + "dev": true, + "requires": { + "graceful-fs": "2.0.3", + "inherits": "2.0.3", + "minimatch": "0.2.14" + } + }, + "graceful-fs": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz", + "integrity": "sha1-fNLNsiiko/Nule+mzBQt59GhNtA=", + "dev": true + }, + "growl": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.8.1.tgz", + "integrity": "sha1-Sy3sjZB+k9szZiTc7AGDUC+MlCg=", + "dev": true + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "jade": { + "version": "0.26.3", + "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + }, + "mkdirp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", + "dev": true + } + } + }, + "jscoverage": { + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/jscoverage/-/jscoverage-0.5.9.tgz", + "integrity": "sha1-M3tR3ZBU6OyTwLCxU3VTtSvwst8=", + "dev": true, + "requires": { + "coffee-script": "1.12.7", + "debug": "1.0.3", + "ejs": "1.0.0", + "optimist": "0.3.1", + "uglify-js": "2.4.15", + "xfs": "0.1.8" + } + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "minimatch": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", + "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", + "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-2.3.4.tgz", + "integrity": "sha1-himm+wRPLSJapLgaKuLQAWmesmY=", + "dev": true, + "requires": { + "commander": "2.3.0", + "debug": "2.2.0", + "diff": "1.4.0", + "escape-string-regexp": "1.0.2", + "glob": "3.2.3", + "growl": "1.8.1", + "jade": "0.26.3", + "mkdirp": "0.5.0", + "supports-color": "1.2.0" + }, + "dependencies": { + "debug": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", + "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", + "dev": true, + "requires": { + "ms": "0.7.1" + } + }, + "ms": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", + "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=", + "dev": true + } + } + }, + "ms": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz", + "integrity": "sha1-2JwhJMb9wTU9Zai3e/GqxLGTcIw=", + "dev": true + }, + "nan": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.7.0.tgz", + "integrity": "sha1-2Vv3IeyHfgjbJ27T/G63j5CDrUY=", + "dev": true + }, + "optimist": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.3.1.tgz", + "integrity": "sha1-ZoDTBWAZOvWlXrZDlIg+17y5jy4=", + "dev": true, + "requires": { + "wordwrap": "0.0.3" + } + }, + "requirejs": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.5.tgz", + "integrity": "sha512-svnO+aNcR/an9Dpi44C7KSAy5fFGLtmPbaaCeQaklUz8BQhS64tWWIIlvEA5jrWICzlO/X9KSzSeXFnZdBu8nw==", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "source-map": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.34.tgz", + "integrity": "sha1-p8/omux7FoLDsZjQrPtH19CQVms=", + "dev": true, + "requires": { + "amdefine": "1.0.1" + } + }, + "supports-color": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.0.tgz", + "integrity": "sha1-/x7R5hFp0Gs88tWI4YixjYhH4X4=", + "dev": true + }, + "uglify-js": { + "version": "2.4.15", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.4.15.tgz", + "integrity": "sha1-ErxthDRfvDBuE/cHXWQ3qL9k1+M=", + "dev": true, + "requires": { + "async": "0.2.10", + "optimist": "0.3.7", + "source-map": "0.1.34", + "uglify-to-browserify": "1.0.2" + }, + "dependencies": { + "optimist": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.3.7.tgz", + "integrity": "sha1-yQlBrVnkJzMokjB00s8ufLxuwNk=", + "dev": true, + "requires": { + "wordwrap": "0.0.3" + } + } + } + }, + "uglify-to-browserify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", + "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", + "dev": true + }, + "uglifyjs": { + "version": "2.4.11", + "resolved": "https://registry.npmjs.org/uglifyjs/-/uglifyjs-2.4.11.tgz", + "integrity": "sha1-NEDWTgRXWViVJEGOtkHGi7kNET4=", + "dev": true + }, + "webworker-threads": { + "version": "0.7.13", + "resolved": "https://registry.npmjs.org/webworker-threads/-/webworker-threads-0.7.13.tgz", + "integrity": "sha1-yEsYtrokElu503NC5E3rgVFi+4M=", + "dev": true, + "requires": { + "bindings": "1.3.0", + "nan": "2.7.0" + } + }, + "wordwrap": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", + "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", + "dev": true + }, + "xfs": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/xfs/-/xfs-0.1.8.tgz", + "integrity": "sha1-iHY8QtEdHvlWy9ZNnU2GunM1n9A=", + "dev": true + } + } +} diff --git a/package.json b/package.json index 7583a0d..40e798a 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,15 @@ { "name": "js-sha512", - "version": "0.4.0", + "version": "0.5.0", "description": "This is a simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.", "main": "src/sha512.js", "devDependencies": { "expect.js": "~0.3.1", "jscoverage": "~0.5.9", "mocha": "~2.3.4", - "uglifyjs": "~2.4.10" + "requirejs": "^2.1.22", + "uglifyjs": "~2.4.10", + "webworker-threads": "^0.7.11" }, "scripts": { "test": "mocha tests/node-test.js -r jscoverage", diff --git a/src/sha512.js b/src/sha512.js index a179a3a..c599eb3 100644 --- a/src/sha512.js +++ b/src/sha512.js @@ -1,7 +1,7 @@ /* * [js-sha512]{@link https://github.com/emn178/js-sha512} * - * @version 0.4.0 + * @version 0.5.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2017 * @license MIT @@ -10,14 +10,22 @@ (function () { 'use strict'; - var root = typeof window === 'object' ? window : {}; + var ERROR = 'input is invalid type'; + var WINDOW = typeof window === 'object'; + var root = WINDOW ? window : {}; + if (root.JS_SHA512_NO_WINDOW) { + WINDOW = false; + } + var WEB_WORKER = !WINDOW && typeof self === 'object'; var NODE_JS = !root.JS_SHA512_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; if (NODE_JS) { root = global; + } else if (WEB_WORKER) { + root = self; } var COMMON_JS = !root.JS_SHA512_NO_COMMON_JS && typeof module === 'object' && module.exports; var AMD = typeof define === 'function' && define.amd; - var ARRAY_BUFFER = typeof ArrayBuffer !== 'undefined'; + var ARRAY_BUFFER = !root.JS_SHA512_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; var HEX_CHARS = '0123456789abcdef'.split(''); var EXTRA = [-2147483648, 8388608, 32768, 128]; var SHIFT = [24, 16, 8, 0]; @@ -68,6 +76,18 @@ var blocks = []; + if (root.JS_SHA512_NO_NODE_JS || !Array.isArray) { + Array.isArray = function (obj) { + return Object.prototype.toString.call(obj) === '[object Array]'; + }; + } + + if (ARRAY_BUFFER && (root.JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { + ArrayBuffer.isView = function (obj) { + return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer; + }; + } + var createOutputMethod = function (outputType, bits) { return function (message) { return new Sha512(bits, true).update(message)[outputType](); @@ -91,10 +111,10 @@ function Sha512(bits, sharedMemory) { if (sharedMemory) { - blocks[0] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = - blocks[5] = blocks[6] = blocks[7] = blocks[8] = - blocks[9] = blocks[10] = blocks[11] = blocks[12] = - blocks[13] = blocks[14] = blocks[15] = blocks[16] = + blocks[0] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = + blocks[5] = blocks[6] = blocks[7] = blocks[8] = + blocks[9] = blocks[10] = blocks[11] = blocks[12] = + blocks[13] = blocks[14] = blocks[15] = blocks[16] = blocks[17] = blocks[18] = blocks[19] = blocks[20] = blocks[21] = blocks[22] = blocks[23] = blocks[24] = blocks[25] = blocks[26] = blocks[27] = blocks[28] = @@ -183,20 +203,34 @@ if (this.finalized) { return; } - var notString = typeof(message) !== 'string'; - if (notString && ARRAY_BUFFER && message instanceof root.ArrayBuffer) { - message = new Uint8Array(message); + var notString, type = typeof message; + if (type !== 'string') { + if (type === 'object') { + if (message === null) { + throw ERROR; + } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { + message = new Uint8Array(message); + } else if (!Array.isArray(message)) { + if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { + throw ERROR; + } + } + } else { + throw ERROR; + } + notString = true; } - var code, index = 0, i, length = message.length || 0, blocks = this.blocks; + var length = message.length; + var code, index = 0, i, length = message.length, blocks = this.blocks; while (index < length) { if (this.hashed) { this.hashed = false; blocks[0] = this.block; - blocks[1] = blocks[2] = blocks[3] = blocks[4] = - blocks[5] = blocks[6] = blocks[7] = blocks[8] = - blocks[9] = blocks[10] = blocks[11] = blocks[12] = - blocks[13] = blocks[14] = blocks[15] = blocks[16] = + blocks[1] = blocks[2] = blocks[3] = blocks[4] = + blocks[5] = blocks[6] = blocks[7] = blocks[8] = + blocks[9] = blocks[10] = blocks[11] = blocks[12] = + blocks[13] = blocks[14] = blocks[15] = blocks[16] = blocks[17] = blocks[18] = blocks[19] = blocks[20] = blocks[21] = blocks[22] = blocks[23] = blocks[24] = blocks[25] = blocks[26] = blocks[27] = blocks[28] = @@ -257,10 +291,10 @@ this.hash(); } blocks[0] = this.block; - blocks[1] = blocks[2] = blocks[3] = blocks[4] = - blocks[5] = blocks[6] = blocks[7] = blocks[8] = - blocks[9] = blocks[10] = blocks[11] = blocks[12] = - blocks[13] = blocks[14] = blocks[15] = blocks[16] = + blocks[1] = blocks[2] = blocks[3] = blocks[4] = + blocks[5] = blocks[6] = blocks[7] = blocks[8] = + blocks[9] = blocks[10] = blocks[11] = blocks[12] = + blocks[13] = blocks[14] = blocks[15] = blocks[16] = blocks[17] = blocks[18] = blocks[19] = blocks[20] = blocks[21] = blocks[22] = blocks[23] = blocks[24] = blocks[25] = blocks[26] = blocks[27] = blocks[28] = @@ -272,10 +306,10 @@ Sha512.prototype.hash = function () { var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, - h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, + h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, - blocks = this.blocks, j, s0h, s0l, s1h, s1l, c1, c2, c3, c4, + blocks = this.blocks, j, s0h, s0l, s1h, s1l, c1, c2, c3, c4, abh, abl, dah, dal, cdh, cdl, bch, bcl, majh, majl, t1h, t1l, t2h, t2l, chh, chl; @@ -582,7 +616,7 @@ this.finalize(); var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, - h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, + h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, bits = this.bits; @@ -666,7 +700,7 @@ this.finalize(); var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, - h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, + h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, bits = this.bits; diff --git a/tests/index.html b/tests/index.html index f64f790..be53687 100644 --- a/tests/index.html +++ b/tests/index.html @@ -3,9 +3,9 @@ SHA512 - - - + + + diff --git a/tests/node-test.js b/tests/node-test.js index 9248404..e800827 100644 --- a/tests/node-test.js +++ b/tests/node-test.js @@ -1,51 +1,72 @@ -// Node.js env expect = require('expect.js'); -sha512 = require('../src/sha512.js').sha512; -sha384 = require('../src/sha512.js').sha384; -sha512_256 = require('../src/sha512.js').sha512_256; -sha512_224 = require('../src/sha512.js').sha512_224; -require('./test.js'); - -delete require.cache[require.resolve('../src/sha512.js')]; -delete require.cache[require.resolve('./test.js')]; -sha512 = null; -sha384 = null; -sha512_256 = null; -sha512_224 = null; +Worker = require('webworker-threads').Worker; + +function unset() { + delete require.cache[require.resolve('../src/sha512.js')]; + delete require.cache[require.resolve('./test.js')]; + sha512 = null; + sha384 = null; + sha512_256 = null; + sha512_224 = null; + BUFFER = undefined; + JS_SHA512_NO_WINDOW = undefined; + JS_SHA512_NO_NODE_JS = undefined; + JS_SHA512_NO_COMMON_JS = undefined; + JS_SHA512_NO_ARRAY_BUFFER = undefined; + JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = undefined; + window = undefined; +} + +function requireToGlobal() { + sha512 = require('../src/sha512.js').sha512; + sha384 = require('../src/sha512.js').sha384; + sha512_256 = require('../src/sha512.js').sha512_256; + sha512_224 = require('../src/sha512.js').sha512_224; +} + +function runCommonJsTest() { + requireToGlobal(); + require('./test.js'); + unset(); +} + +function runWindowTest() { + window = global; + require('../src/sha512.js'); + require('./test.js'); + unset(); +} + +// Node.js env +BUFFER = true; +runCommonJsTest(); // Webpack browser env JS_SHA512_NO_NODE_JS = true; window = global; -sha512 = require('../src/sha512.js').sha512; -sha384 = require('../src/sha512.js').sha384; -sha512_256 = require('../src/sha512.js').sha512_256; -sha512_224 = require('../src/sha512.js').sha512_224; -require('./test.js'); - -delete require.cache[require.resolve('../src/sha512.js')]; -delete require.cache[require.resolve('./test.js')]; -sha512 = null; -sha384 = null; -sha512_256 = null; -sha512_224 = null; +runCommonJsTest(); // browser env JS_SHA512_NO_NODE_JS = true; JS_SHA512_NO_COMMON_JS = true; -window = global; -require('../src/sha512.js'); -require('./test.js'); +runWindowTest(); -delete require.cache[require.resolve('../src/sha512.js')]; -delete require.cache[require.resolve('./test.js')]; -sha512 = null; -sha384 = null; -sha512_256 = null; -sha512_224 = null; +// browser env and no array buffer +JS_SHA512_NO_NODE_JS = true; +JS_SHA512_NO_COMMON_JS = true; +JS_SHA512_NO_ARRAY_BUFFER = true; +runWindowTest(); + +// browser env and no isView +JS_SHA512_NO_NODE_JS = true; +JS_SHA512_NO_COMMON_JS = true; +JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = true; +runWindowTest(); // browser AMD JS_SHA512_NO_NODE_JS = true; JS_SHA512_NO_COMMON_JS = true; +JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = false; window = global; define = function (func) { sha512 = func(); @@ -57,3 +78,38 @@ define = function (func) { define.amd = true; require('../src/sha512.js'); +unset(); + +// webworker +WORKER = 'tests/worker.js'; +SOURCE = 'src/sha512.js'; + +require('./worker-test.js'); + +delete require.cache[require.resolve('./worker-test.js')]; + +// cover webworker +JS_SHA512_NO_WINDOW = true; +JS_SHA512_NO_NODE_JS = true; +WORKER = './worker.js'; +SOURCE = '../src/sha512.js'; +window = global; +self = global; + +Worker = function (file) { + require(file); + currentWorker = this; + + this.postMessage = function (data) { + onmessage({data: data}); + }; +} + +postMessage = function (data) { + currentWorker.onmessage({data: data}); +} + +importScripts = function () {}; + +requireToGlobal(); +require('./worker-test.js'); diff --git a/tests/requirejs.html b/tests/requirejs.html new file mode 100644 index 0000000..8f11101 --- /dev/null +++ b/tests/requirejs.html @@ -0,0 +1,27 @@ + + + + + SHA512 + + + + + + +
+ + + diff --git a/tests/test.js b/tests/test.js index a09c493..c17f8d3 100644 --- a/tests/test.js +++ b/tests/test.js @@ -37,19 +37,6 @@ 'Array': { 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': [], '07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': [84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103] - }, - 'Uint8Array': { - '07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'Int8Array': { - '07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'ArrayBuffer': { - 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': new ArrayBuffer(0), - 'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee': new ArrayBuffer(1), - }, - 'Object': { - 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': {what: 'ever'} } }, sha384: { @@ -79,19 +66,6 @@ 'Array': { '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': [], 'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': [84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103] - }, - 'Uint8Array': { - 'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'Int8Array': { - 'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'ArrayBuffer': { - '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': new ArrayBuffer(0), - 'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717': new ArrayBuffer(1), - }, - 'Object': { - '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': {what: 'ever'} } }, sha512_256: { @@ -121,19 +95,6 @@ 'Array': { 'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': [], 'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': [84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103] - }, - 'Uint8Array': { - 'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'Int8Array': { - 'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'ArrayBuffer': { - 'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': new ArrayBuffer(0), - '10baad1713566ac2333467bddb0597dec9066120dd72ac2dcb8394221dcbe43d': new ArrayBuffer(1), - }, - 'Object': { - 'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': {what: 'ever'} } }, sha512_224: { @@ -163,23 +124,70 @@ 'Array': { '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': [], '944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': [84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103] - }, - 'Uint8Array': { - '944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'Int8Array': { - '944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) - }, - 'ArrayBuffer': { - '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': new ArrayBuffer(0), - '283bb59af7081ed08197227d8f65b9591ffe1155be43e9550e57f941': new ArrayBuffer(1), - }, - 'Object': { - '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': {what: 'ever'} } } }; + if (!(typeof JS_SHA512_NO_ARRAY_BUFFER === 'boolean' && JS_SHA512_NO_ARRAY_BUFFER)) { + testCases.sha512['Uint8Array'] = { + '07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha512['Int8Array'] = { + '07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha512['ArrayBuffer'] = { + 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': new ArrayBuffer(0), + 'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee': new ArrayBuffer(1) + }; + testCases.sha384['Uint8Array'] = { + 'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha384['Int8Array'] = { + 'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha384['ArrayBuffer'] = { + '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': new ArrayBuffer(0), + 'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717': new ArrayBuffer(1) + }; + testCases.sha512_256['Uint8Array'] = { + 'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha512_256['Int8Array'] = { + 'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha512_256['ArrayBuffer'] = { + 'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': new ArrayBuffer(0), + '10baad1713566ac2333467bddb0597dec9066120dd72ac2dcb8394221dcbe43d': new ArrayBuffer(1) + }; + testCases.sha512_224['Uint8Array'] = { + '944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha512_224['Int8Array'] = { + '944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) + }; + testCases.sha512_224['ArrayBuffer'] = { + '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': new ArrayBuffer(0), + '283bb59af7081ed08197227d8f65b9591ffe1155be43e9550e57f941': new ArrayBuffer(1) + }; + } + + if (typeof BUFFER === 'boolean' && BUFFER) { + testCases.sha512['Buffer'] = { + '07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': new Buffer(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])) + }; + testCases.sha384['Buffer'] = { + 'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': new Buffer(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])) + }; + testCases.sha512_256['Buffer'] = { + 'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': new Buffer(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])) + }; + testCases.sha512_224['Buffer'] = { + '944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': new Buffer(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])) + }; + } + + var errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}]; + function runTestCases(name, algorithm) { var methods = [ { @@ -298,6 +306,16 @@ } }); }); + + errorTestCases.forEach(function (testCase) { + context('when ' + testCase, function () { + it('should throw error', function () { + expect(function () { + algorithm(testCase); + }).to.throwError(/input is invalid type/); + }); + }); + }); }); } diff --git a/tests/worker-test.js b/tests/worker-test.js new file mode 100644 index 0000000..75f588d --- /dev/null +++ b/tests/worker-test.js @@ -0,0 +1,21 @@ +(function (Worker, WORKER, SOURCE) { + var cases = { + 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': '', + '07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': 'The quick brown fox jumps over the lazy dog', + '91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed': 'The quick brown fox jumps over the lazy dog.' + }; + + describe('#sha512', function () { + Object.keys(cases).forEach(function (hash) { + it('should be equal', function (done) { + var worker = new Worker(WORKER); + worker.onmessage = function(event) { + expect(event.data).to.be(hash); + done(); + }; + worker.postMessage(SOURCE); + worker.postMessage(cases[hash]); + }); + }); + }); +})(Worker, WORKER, SOURCE); diff --git a/tests/worker.html b/tests/worker.html new file mode 100644 index 0000000..b09b533 --- /dev/null +++ b/tests/worker.html @@ -0,0 +1,26 @@ + + + + + SHA512 + + + + + + +
+ + + + + + diff --git a/tests/worker.js b/tests/worker.js new file mode 100644 index 0000000..8abeb8f --- /dev/null +++ b/tests/worker.js @@ -0,0 +1,12 @@ +var imported = false; +onmessage = function(e) { + if (imported) { + postMessage(sha512(e.data)); + if (typeof exports !== 'undefined') { + imported = false; + } + } else { + imported = true; + importScripts(e.data); + } +}