mirror of
https://github.com/emn178/js-sha512.git
synced 2026-08-12 20:31:34 +08:00
* Add test cases.
* Improve performance.
This commit is contained in:
+5
-4
@@ -3,10 +3,11 @@ node_js:
|
||||
- "0.11"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
install:
|
||||
before_install:
|
||||
- npm install mocha -g
|
||||
- npm install coveralls -g
|
||||
- npm install mocha-lcov-reporter -g
|
||||
- npm install
|
||||
script:
|
||||
- npm run-script coveralls
|
||||
script: npm run-script coveralls
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
# v0.2.0 / 2015-02-02
|
||||
|
||||
* Add test cases.
|
||||
* Improve performance.
|
||||
|
||||
# v0.1.3 / 2015-01-26
|
||||
|
||||
* Add test cases.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# js-sha512
|
||||
[](https://travis-ci.org/emn178/js-sha512)
|
||||
[](https://coveralls.io/r/emn178/js-sha512?branch=master)
|
||||
[](https://travis-ci.org/emn178/js-sha512)
|
||||
[](https://coveralls.io/r/emn178/js-sha512?branch=master)
|
||||
[](https://nodei.co/npm/js-sha512/)
|
||||
A simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "js-sha512",
|
||||
"version": "0.1.3",
|
||||
"version": "0.2.0",
|
||||
"main": ["build/sha512.min.js"],
|
||||
"ignore": [
|
||||
"samples",
|
||||
|
||||
Vendored
+14
-14
@@ -1,14 +1,14 @@
|
||||
(function(l,J){var y="undefined"!=typeof module;y&&(l=global);var g="0123456789abcdef".split(""),B=[24,16,8,0],a=function(a,h){this.high=a<<0;this.low=h<<0};l.JS_SHA512_TEST&&(l.Long=a);a.prototype.and=function(c){return new a(this.high&c.high,this.low&c.low)};a.prototype.xor=function(c){return new a(this.high^c.high,this.low^c.low)};a.prototype.not=function(){return new a(~this.high,~this.low)};a.prototype.shiftRightUnsigned=function(c){c&=63;return 0===c?new a(this.high,this.low):32>c?new a(this.high>>>
|
||||
c,this.low>>>c|this.high<<32-c):32==c?new a(0,this.high):new a(0,this.high>>>c-32)};a.prototype.rightRotate=function(c){c&=63;return 0===c?new a(this.high,this.low):32>c?new a(this.high>>>c|this.low<<32-c,this.low>>>c|this.high<<32-c):32==c?new a(this.low,this.high):new a(this.low>>>c-32|this.high<<64-c,this.high>>>c-32|this.low<<64-c)};a.prototype.add=function(c){var h=(this.low&65535)+(c.low&65535),f=(this.low>>>16)+(c.low>>>16)+(h>>>16),k=(this.high&65535)+(c.high&65535)+(f>>>16);return new a((this.high>>>
|
||||
16)+(c.high>>>16)+(k>>>16)<<16|k&65535,f<<16|h&65535)};a.prototype.toHexString=function(){return g[this.high>>28&15]+g[this.high>>24&15]+g[this.high>>20&15]+g[this.high>>16&15]+g[this.high>>12&15]+g[this.high>>8&15]+g[this.high>>4&15]+g[this.high&15]+g[this.low>>28&15]+g[this.low>>24&15]+g[this.low>>20&15]+g[this.low>>16&15]+g[this.low>>12&15]+g[this.low>>8&15]+g[this.low>>4&15]+g[this.low&15]};var I=[new a(1116352408,3609767458),new a(1899447441,602891725),new a(3049323471,3964484399),new a(3921009573,
|
||||
2173295548),new a(961987163,4081628472),new a(1508970993,3053834265),new a(2453635748,2937671579),new a(2870763221,3664609560),new a(3624381080,2734883394),new a(310598401,1164996542),new a(607225278,1323610764),new a(1426881987,3590304994),new a(1925078388,4068182383),new a(2162078206,991336113),new a(2614888103,633803317),new a(3248222580,3479774868),new a(3835390401,2666613458),new a(4022224774,944711139),new a(264347078,2341262773),new a(604807628,2007800933),new a(770255983,1495990901),new a(1249150122,
|
||||
1856431235),new a(1555081692,3175218132),new a(1996064986,2198950837),new a(2554220882,3999719339),new a(2821834349,766784016),new a(2952996808,2566594879),new a(3210313671,3203337956),new a(3336571891,1034457026),new a(3584528711,2466948901),new a(113926993,3758326383),new a(338241895,168717936),new a(666307205,1188179964),new a(773529912,1546045734),new a(1294757372,1522805485),new a(1396182291,2643833823),new a(1695183700,2343527390),new a(1986661051,1014477480),new a(2177026350,1206759142),new a(2456956037,
|
||||
344077627),new a(2730485921,1290863460),new a(2820302411,3158454273),new a(3259730800,3505952657),new a(3345764771,106217008),new a(3516065817,3606008344),new a(3600352804,1432725776),new a(4094571909,1467031594),new a(275423344,851169720),new a(430227734,3100823752),new a(506948616,1363258195),new a(659060556,3750685593),new a(883997877,3785050280),new a(958139571,3318307427),new a(1322822218,3812723403),new a(1537002063,2003034995),new a(1747873779,3602036899),new a(1955562222,1575990012),new a(2024104815,
|
||||
1125592928),new a(2227730452,2716904306),new a(2361852424,442776044),new a(2428436474,593698344),new a(2756734187,3733110249),new a(3204031479,2999351573),new a(3329325298,3815920427),new a(3391569614,3928383900),new a(3515267271,566280711),new a(3940187606,3454069534),new a(4118630271,4000239992),new a(116418474,1914138554),new a(174292421,2731055270),new a(289380356,3203993006),new a(460393269,320620315),new a(685471733,587496836),new a(852142971,1086792851),new a(1017036298,365543100),new a(1126000580,
|
||||
2618297676),new a(1288033470,3409855158),new a(1501505948,4234509866),new a(1607167915,987167468),new a(1816402316,1246189591)],m=function(a,h){return p(a,512,h)},F=function(a,h){return p(a,384,h)},G=function(a,h){return p(a,256,h)},H=function(a,h){return p(a,224,h)},p=function(c,h,f){var k,g,l,q,r,t,u,v;if(!f&&/[^\x00-\x7F]/.test(c)){f=[];for(var e=0,b=0;b<c.length;b++){var d=c.charCodeAt(b);128>d?f[e++]=d:(2048>d?f[e++]=192|d>>6:(55296>d||57344<=d?f[e++]=224|d>>12:(d=65536+((d&1023)<<10|c.charCodeAt(++b)&
|
||||
1023),f[e++]=240|d>>18,f[e++]=128|d>>12&63),f[e++]=128|d>>6&63),f[e++]=128|d&63)}d=f.length;c=(d+16>>7)+1<<5;e=[];for(b=0;b<c;++b)e[b]=0;for(b=0;b<d;++b)e[b>>2]|=f[b]<<B[b&3];e[b>>2]|=128<<B[b&3];e[c-1]=d<<3;f=[];for(b=0;b<c;b+=2)f[b>>1]=new a(e[b],e[b+1]);c=f}else{d=c.length;f=(d+16>>7)+1<<5;e=[];for(b=0;b<f;++b)e[b]=0;for(b=0;b<d;++b)e[b>>2]|=c.charCodeAt(b)<<B[b&3];e[b>>2]|=128<<B[b&3];e[f-1]=d<<3;c=[];for(b=0;b<f;b+=2)c[b>>1]=new a(e[b],e[b+1])}512==h?(k=new a(1779033703,4089235720),g=new a(3144134277,
|
||||
2227873595),l=new a(1013904242,4271175723),q=new a(2773480762,1595750129),r=new a(1359893119,2917565137),t=new a(2600822924,725511199),u=new a(528734635,4215389547),v=new a(1541459225,327033209)):384==h?(k=new a(3418070365,3238371032),g=new a(1654270250,914150663),l=new a(2438529370,812702999),q=new a(355462360,4144912697),r=new a(1731405415,4290775857),t=new a(2394180231,1750603025),u=new a(3675008525,1694076839),v=new a(1203062813,3204075428)):256==h?(k=new a(573645204,4230739756),g=new a(2673172387,
|
||||
3360449730),l=new a(596883563,1867755857),q=new a(2520282905,1497426621),r=new a(2519219938,2827943907),t=new a(3193839141,1401305490),u=new a(721525244,746961066),v=new a(246885852,2177182882)):224==h&&(k=new a(2352822216,424955298),g=new a(1944164710,2312950998),l=new a(502970286,855612546),q=new a(1738396948,1479516111),r=new a(258812777,2077511080),t=new a(2011393907,79989058),u=new a(1067287976,1780299464),v=new a(286451373,2446758561));f=0;for(e=c.length;f<e;f+=16){for(var b=[],m,n,d=0;16>d;++d)b[d]=
|
||||
c[f+d];for(d=16;80>d;++d)m=b[d-15].rightRotate(1).xor(b[d-15].rightRotate(8)).xor(b[d-15].shiftRightUnsigned(7)),n=b[d-2].rightRotate(19).xor(b[d-2].rightRotate(61)).xor(b[d-2].shiftRightUnsigned(6)),b[d]=b[d-16].add(m).add(b[d-7]).add(n);for(var w=k,z=g,A=l,p=q,x=r,C=t,D=u,E=v,y,d=0;80>d;++d)m=w.rightRotate(28).xor(w.rightRotate(34)).xor(w.rightRotate(39)),n=w.and(z).xor(w.and(A)).xor(z.and(A)),m=m.add(n),n=x.rightRotate(14).xor(x.rightRotate(18)).xor(x.rightRotate(41)),y=x.and(C).xor(x.not().and(D)),
|
||||
n=E.add(n).add(y).add(I[d]).add(b[d]),E=D,D=C,C=x,x=p.add(n),p=A,A=z,z=w,w=n.add(m);k=k.add(w);g=g.add(z);l=l.add(A);q=q.add(p);r=r.add(x);t=t.add(C);u=u.add(D);v=v.add(E)}k=k.toHexString()+g.toHexString()+l.toHexString()+q.toHexString();if(224==h)return k.substr(0,k.length-8);384<=h&&(k+=r.toHexString()+t.toHexString());512==h&&(k+=u.toHexString()+v.toHexString());return k};!l.JS_SHA512_TEST&&y?(m.sha512=m,m.sha384=F,m.sha512_256=G,m.sha512_224=H,module.exports=m):l&&(l.sha512=m,l.sha384=F,l.sha512_256=
|
||||
G,l.sha512_224=H)})(this);
|
||||
(function(q,ha){var ca="undefined"!=typeof module;ca&&(q=global);var p="0123456789abcdef".split(""),ba=[24,16,8,0],da=[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],r=function(f,l){return Q(f,512,l)},ea=function(f,l){return Q(f,384,l)},fa=function(f,l){return Q(f,256,l)},ga=function(f,l){return Q(f,224,l)},Q=function(f,p,m){var n,A,B,C,D,E,F,G,
|
||||
H,I,J,K,L,M,N,O;if(!m&&/[^\x00-\x7F]/.test(f)){m=[];for(var t=0,d=0;d<f.length;d++){var a=f.charCodeAt(d);128>a?m[t++]=a:(2048>a?m[t++]=192|a>>6:(55296>a||57344<=a?m[t++]=224|a>>12:(a=65536+((a&1023)<<10|f.charCodeAt(++d)&1023),m[t++]=240|a>>18,m[t++]=128|a>>12&63),m[t++]=128|a>>6&63),m[t++]=128|a&63)}f=m.length;t=(f+16>>7)+1<<5;d=[];for(a=0;a<t;++a)d[a]=0;for(a=0;a<f;++a)d[a>>2]|=m[a]<<ba[a&3];d[a>>2]|=128<<ba[a&3];d[t-1]=f<<3}else{m=f.length;t=(m+16>>7)+1<<5;d=[];for(a=0;a<t;++a)d[a]=0;for(a=0;a<
|
||||
m;++a)d[a>>2]|=f.charCodeAt(a)<<ba[a&3];d[a>>2]|=128<<ba[a&3];d[t-1]=m<<3}f=d;512==p?(n=1779033703,A=4089235720,B=3144134277,C=2227873595,D=1013904242,E=4271175723,F=2773480762,G=1595750129,H=1359893119,I=2917565137,J=2600822924,K=725511199,L=528734635,M=4215389547,N=1541459225,O=327033209):384==p?(n=3418070365,A=3238371032,B=1654270250,C=914150663,D=2438529370,E=812702999,F=355462360,G=4144912697,H=1731405415,I=4290775857,J=2394180231,K=1750603025,L=3675008525,M=1694076839,N=1203062813,O=3204075428):
|
||||
256==p?(n=573645204,A=4230739756,B=2673172387,C=3360449730,D=596883563,E=1867755857,F=2520282905,G=1497426621,H=2519219938,I=2827943907,J=3193839141,K=1401305490,L=721525244,M=746961066,N=246885852,O=2177182882):224==p&&(n=2352822216,A=424955298,B=1944164710,C=2312950998,D=502970286,E=855612546,F=1738396948,G=1479516111,H=258812777,I=2077511080,J=2011393907,K=79989058,L=1067287976,M=1780299464,N=286451373,O=2446758561);m=0;for(t=f.length;m<t;m+=32){var d=[],P,b,y,z,g,k,c,e,h,u,v,q,r,R,S,T,U,w,x,V,
|
||||
W,X,Y,Z,aa,Q;for(h=0;32>h;++h)d[h]=f[m+h];for(h=32;160>h;h+=2)g=d[h-30],k=d[h-29],P=(g>>>1|k<<31)^(g>>>8|k<<24)^g>>>7,b=(k>>>1|g<<31)^(k>>>8|g<<24)^(k>>>7|g<<25),g=d[h-4],k=d[h-3],y=(g>>>19|k<<13)^(k>>>29|g<<3)^g>>>6,z=(k>>>19|g<<13)^(g>>>29|k<<3)^(k>>>6|g<<26),g=d[h-32],k=d[h-31],a=(k&65535)+(b&65535)+(z&65535),b=(k>>>16)+(b>>>16)+(z>>>16),c=(g&65535)+(P&65535)+(y&65535),e=(g>>>16)+(P>>>16)+(y>>>16),g=d[h-14],k=d[h-13],a+=k&65535,b+=(k>>>16)+(a>>>16),c+=(g&65535)+(b>>>16),e+=(g>>>16)+(c>>>16),d[h]=
|
||||
e<<16|c&65535,d[h+1]=b<<16|a&65535;u=n;v=A;q=B;r=C;R=D;S=E;T=F;U=G;w=H;x=I;V=J;W=K;X=L;Y=M;Z=N;aa=O;for(h=0;160>h;h+=2)P=(u>>>28|v<<4)^(v>>>2|u<<30)^(v>>>7|u<<25),b=(v>>>28|u<<4)^(u>>>2|v<<30)^(u>>>7|v<<25),y=(w>>>14|x<<18)^(w>>>18|x<<14)^(x>>>9|w<<23),z=(x>>>14|w<<18)^(x>>>18|w<<14)^(w>>>9|x<<23),g=u&q^u&R^q&R,c=v&r^v&S^r&S,a=(c&65535)+(b&65535),b=(c>>>16)+(b>>>16)+(a>>>16),c=(g&65535)+(P&65535)+(b>>>16),e=(g>>>16)+(P>>>16)+(c>>>16),P=e<<16|c&65535,Q=b<<16|a&65535,e=w&V^~w&X,b=x&W^~x&Y,g=d[h],k=
|
||||
d[h+1],a=(k&65535)+(b&65535)+(z&65535)+(aa&65535),b=(k>>>16)+(b>>>16)+(z>>>16)+(aa>>>16),c=(g&65535)+(e&65535)+(y&65535)+(Z&65535),e=(g>>>16)+(e>>>16)+(y>>>16)+(Z>>>16),g=da[h],k=da[h+1],a+=k&65535,b+=(k>>>16)+(a>>>16),c+=(g&65535)+(b>>>16),e+=(g>>>16)+(c>>>16),y=e<<16|c&65535,z=b<<16|a&65535,Z=X,aa=Y,X=V,Y=W,V=w,W=x,a=(U&65535)+(z&65535),b=(U>>>16)+(z>>>16)+(a>>>16),c=(T&65535)+(y&65535)+(b>>>16),e=(T>>>16)+(y>>>16)+(c>>>16),w=e<<16|c&65535,x=b<<16|a&65535,T=R,U=S,R=q,S=r,q=u,r=v,a=(Q&65535)+(z&
|
||||
65535),b=(Q>>>16)+(z>>>16)+(a>>>16),c=(P&65535)+(y&65535)+(b>>>16),e=(P>>>16)+(y>>>16)+(c>>>16),u=e<<16|c&65535,v=b<<16|a&65535;a=(A&65535)+(v&65535);b=(A>>>16)+(v>>>16)+(a>>>16);c=(n&65535)+(u&65535)+(b>>>16);e=(n>>>16)+(u>>>16)+(c>>>16);n=e<<16|c&65535;A=b<<16|a&65535;a=(C&65535)+(r&65535);b=(C>>>16)+(r>>>16)+(a>>>16);c=(B&65535)+(q&65535)+(b>>>16);e=(B>>>16)+(q>>>16)+(c>>>16);B=e<<16|c&65535;C=b<<16|a&65535;a=(E&65535)+(S&65535);b=(E>>>16)+(S>>>16)+(a>>>16);c=(D&65535)+(R&65535)+(b>>>16);e=(D>>>
|
||||
16)+(R>>>16)+(c>>>16);D=e<<16|c&65535;E=b<<16|a&65535;a=(G&65535)+(U&65535);b=(G>>>16)+(U>>>16)+(a>>>16);c=(F&65535)+(T&65535)+(b>>>16);e=(F>>>16)+(T>>>16)+(c>>>16);F=e<<16|c&65535;G=b<<16|a&65535;a=(I&65535)+(x&65535);b=(I>>>16)+(x>>>16)+(a>>>16);c=(H&65535)+(w&65535)+(b>>>16);e=(H>>>16)+(w>>>16)+(c>>>16);H=e<<16|c&65535;I=b<<16|a&65535;a=(K&65535)+(W&65535);b=(K>>>16)+(W>>>16)+(a>>>16);c=(J&65535)+(V&65535)+(b>>>16);e=(J>>>16)+(V>>>16)+(c>>>16);J=e<<16|c&65535;K=b<<16|a&65535;a=(M&65535)+(Y&65535);
|
||||
b=(M>>>16)+(Y>>>16)+(a>>>16);c=(L&65535)+(X&65535)+(b>>>16);e=(L>>>16)+(X>>>16)+(c>>>16);L=e<<16|c&65535;M=b<<16|a&65535;a=(O&65535)+(aa&65535);b=(O>>>16)+(aa>>>16)+(a>>>16);c=(N&65535)+(Z&65535)+(b>>>16);e=(N>>>16)+(Z>>>16)+(c>>>16);N=e<<16|c&65535;O=b<<16|a&65535}n=l(n)+l(A)+l(B)+l(C)+l(D)+l(E)+l(F)+l(G);if(224==p)return n.substr(0,n.length-8);384<=p&&(n+=l(H)+l(I)+l(J)+l(K));512==p&&(n+=l(L)+l(M)+l(N)+l(O));return n},l=function(f){return p[f>>28&15]+p[f>>24&15]+p[f>>20&15]+p[f>>16&15]+p[f>>12&
|
||||
15]+p[f>>8&15]+p[f>>4&15]+p[f&15]};!q.JS_SHA512_TEST&&ca?(r.sha512=r,r.sha384=ea,r.sha512_256=fa,r.sha512_224=ga,module.exports=r):q&&(q.sha512=r,q.sha384=ea,q.sha512_256=fa,q.sha512_224=ga)})(this);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "js-sha512",
|
||||
"version": "0.1.3",
|
||||
"version": "0.2.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": {
|
||||
|
||||
+300
-205
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* js-sha512 v0.1.3
|
||||
* js-sha512 v0.2.0
|
||||
* https://github.com/emn178/js-sha512
|
||||
*
|
||||
* Copyright 2014-2015, emn178@gmail.com
|
||||
@@ -17,125 +17,46 @@
|
||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||
var SHIFT = [24, 16, 8, 0];
|
||||
|
||||
// Class Long
|
||||
var Long = function(high, low) {
|
||||
this.high = high << 0;
|
||||
this.low = low << 0;
|
||||
};
|
||||
|
||||
if(root.JS_SHA512_TEST) {
|
||||
root.Long = Long;
|
||||
}
|
||||
|
||||
Long.prototype.and = function(other) {
|
||||
return new Long(this.high & other.high, this.low & other.low);
|
||||
};
|
||||
|
||||
Long.prototype.xor = function(other) {
|
||||
return new Long(this.high ^ other.high, this.low ^ other.low);
|
||||
};
|
||||
|
||||
Long.prototype.not = function() {
|
||||
return new Long(~this.high, ~this.low);
|
||||
};
|
||||
|
||||
Long.prototype.shiftRightUnsigned = function(numBits) {
|
||||
numBits &= 63;
|
||||
if(numBits === 0) {
|
||||
return new Long(this.high, this.low);
|
||||
}
|
||||
if(numBits < 32) {
|
||||
return new Long(this.high >>> numBits, (this.low >>> numBits) | (this.high << (32 - numBits)));
|
||||
} else if(numBits == 32) {
|
||||
return new Long(0, this.high);
|
||||
} else {
|
||||
return new Long(0, this.high >>> (numBits - 32));
|
||||
}
|
||||
};
|
||||
|
||||
Long.prototype.rightRotate = function(numBits) {
|
||||
numBits &= 63;
|
||||
if(numBits === 0) {
|
||||
return new Long(this.high, this.low);
|
||||
}
|
||||
if(numBits < 32) {
|
||||
return new Long((this.high >>> numBits) | (this.low << (32 - numBits)), (this.low >>> numBits) | (this.high << (32 - numBits)));
|
||||
} else if(numBits == 32) {
|
||||
return new Long(this.low, this.high);
|
||||
} else {
|
||||
return new Long((this.low >>> (numBits - 32)) | (this.high << (64 - numBits)), (this.high >>> (numBits - 32)) | (this.low << (64 - numBits)));
|
||||
}
|
||||
};
|
||||
|
||||
Long.prototype.add = function(other) {
|
||||
var a1 = this.low & 0xFFFF;
|
||||
var a2 = this.low >>> 16;
|
||||
var a3 = this.high & 0xFFFF;
|
||||
var a4 = this.high >>> 16;
|
||||
|
||||
var b1 = other.low & 0xFFFF;
|
||||
var b2 = other.low >>> 16;
|
||||
var b3 = other.high & 0xFFFF;
|
||||
var b4 = other.high >>> 16;
|
||||
|
||||
var c1 = a1 + b1;
|
||||
var c2 = a2 + b2 + (c1 >>> 16);
|
||||
var c3 = a3 + b3 + (c2 >>> 16);
|
||||
var c4 = a4 + b4 + (c3 >>> 16);
|
||||
return new Long((c4 << 16) | (c3 & 0xFFFF), (c2 << 16) | (c1 & 0xFFFF));
|
||||
};
|
||||
|
||||
Long.prototype.toHexString = function() {
|
||||
return HEX_CHARS[(this.high >> 28) & 0x0F] + HEX_CHARS[(this.high >> 24) & 0x0F] +
|
||||
HEX_CHARS[(this.high >> 20) & 0x0F] + HEX_CHARS[(this.high >> 16) & 0x0F] +
|
||||
HEX_CHARS[(this.high >> 12) & 0x0F] + HEX_CHARS[(this.high >> 8) & 0x0F] +
|
||||
HEX_CHARS[(this.high >> 4) & 0x0F] + HEX_CHARS[this.high & 0x0F] +
|
||||
HEX_CHARS[(this.low >> 28) & 0x0F] + HEX_CHARS[(this.low >> 24) & 0x0F] +
|
||||
HEX_CHARS[(this.low >> 20) & 0x0F] + HEX_CHARS[(this.low >> 16) & 0x0F] +
|
||||
HEX_CHARS[(this.low >> 12) & 0x0F] + HEX_CHARS[(this.low >> 8) & 0x0F] +
|
||||
HEX_CHARS[(this.low >> 4) & 0x0F] + HEX_CHARS[this.low & 0x0F];
|
||||
};
|
||||
|
||||
var K =[new Long(0x428A2F98, 0xD728AE22), new Long(0x71374491, 0x23EF65CD),
|
||||
new Long(0xB5C0FBCF, 0xEC4D3B2F), new Long(0xE9B5DBA5, 0x8189DBBC),
|
||||
new Long(0x3956C25B, 0xF348B538), new Long(0x59F111F1, 0xB605D019),
|
||||
new Long(0x923F82A4, 0xAF194F9B), new Long(0xAB1C5ED5, 0xDA6D8118),
|
||||
new Long(0xD807AA98, 0xA3030242), new Long(0x12835B01, 0x45706FBE),
|
||||
new Long(0x243185BE, 0x4EE4B28C), new Long(0x550C7DC3, 0xD5FFB4E2),
|
||||
new Long(0x72BE5D74, 0xF27B896F), new Long(0x80DEB1FE, 0x3B1696B1),
|
||||
new Long(0x9BDC06A7, 0x25C71235), new Long(0xC19BF174, 0xCF692694),
|
||||
new Long(0xE49B69C1, 0x9EF14AD2), new Long(0xEFBE4786, 0x384F25E3),
|
||||
new Long(0x0FC19DC6, 0x8B8CD5B5), new Long(0x240CA1CC, 0x77AC9C65),
|
||||
new Long(0x2DE92C6F, 0x592B0275), new Long(0x4A7484AA, 0x6EA6E483),
|
||||
new Long(0x5CB0A9DC, 0xBD41FBD4), new Long(0x76F988DA, 0x831153B5),
|
||||
new Long(0x983E5152, 0xEE66DFAB), new Long(0xA831C66D, 0x2DB43210),
|
||||
new Long(0xB00327C8, 0x98FB213F), new Long(0xBF597FC7, 0xBEEF0EE4),
|
||||
new Long(0xC6E00BF3, 0x3DA88FC2), new Long(0xD5A79147, 0x930AA725),
|
||||
new Long(0x06CA6351, 0xE003826F), new Long(0x14292967, 0x0A0E6E70),
|
||||
new Long(0x27B70A85, 0x46D22FFC), new Long(0x2E1B2138, 0x5C26C926),
|
||||
new Long(0x4D2C6DFC, 0x5AC42AED), new Long(0x53380D13, 0x9D95B3DF),
|
||||
new Long(0x650A7354, 0x8BAF63DE), new Long(0x766A0ABB, 0x3C77B2A8),
|
||||
new Long(0x81C2C92E, 0x47EDAEE6), new Long(0x92722C85, 0x1482353B),
|
||||
new Long(0xA2BFE8A1, 0x4CF10364), new Long(0xA81A664B, 0xBC423001),
|
||||
new Long(0xC24B8B70, 0xD0F89791), new Long(0xC76C51A3, 0x0654BE30),
|
||||
new Long(0xD192E819, 0xD6EF5218), new Long(0xD6990624, 0x5565A910),
|
||||
new Long(0xF40E3585, 0x5771202A), new Long(0x106AA070, 0x32BBD1B8),
|
||||
new Long(0x19A4C116, 0xB8D2D0C8), new Long(0x1E376C08, 0x5141AB53),
|
||||
new Long(0x2748774C, 0xDF8EEB99), new Long(0x34B0BCB5, 0xE19B48A8),
|
||||
new Long(0x391C0CB3, 0xC5C95A63), new Long(0x4ED8AA4A, 0xE3418ACB),
|
||||
new Long(0x5B9CCA4F, 0x7763E373), new Long(0x682E6FF3, 0xD6B2B8A3),
|
||||
new Long(0x748F82EE, 0x5DEFB2FC), new Long(0x78A5636F, 0x43172F60),
|
||||
new Long(0x84C87814, 0xA1F0AB72), new Long(0x8CC70208, 0x1A6439EC),
|
||||
new Long(0x90BEFFFA, 0x23631E28), new Long(0xA4506CEB, 0xDE82BDE9),
|
||||
new Long(0xBEF9A3F7, 0xB2C67915), new Long(0xC67178F2, 0xE372532B),
|
||||
new Long(0xCA273ECE, 0xEA26619C), new Long(0xD186B8C7, 0x21C0C207),
|
||||
new Long(0xEADA7DD6, 0xCDE0EB1E), new Long(0xF57D4F7F, 0xEE6ED178),
|
||||
new Long(0x06F067AA, 0x72176FBA), new Long(0x0A637DC5, 0xA2C898A6),
|
||||
new Long(0x113F9804, 0xBEF90DAE), new Long(0x1B710B35, 0x131C471B),
|
||||
new Long(0x28DB77F5, 0x23047D84), new Long(0x32CAAB7B, 0x40C72493),
|
||||
new Long(0x3C9EBE0A, 0x15C9BEBC), new Long(0x431D67C4, 0x9C100D4C),
|
||||
new Long(0x4CC5D4BE, 0xCB3E42B6), new Long(0x597F299C, 0xFC657E2A),
|
||||
new Long(0x5FCB6FAB, 0x3AD6FAEC), new Long(0x6C44198C, 0x4A475817)];
|
||||
var K =[0x428A2F98, 0xD728AE22, 0x71374491, 0x23EF65CD,
|
||||
0xB5C0FBCF, 0xEC4D3B2F, 0xE9B5DBA5, 0x8189DBBC,
|
||||
0x3956C25B, 0xF348B538, 0x59F111F1, 0xB605D019,
|
||||
0x923F82A4, 0xAF194F9B, 0xAB1C5ED5, 0xDA6D8118,
|
||||
0xD807AA98, 0xA3030242, 0x12835B01, 0x45706FBE,
|
||||
0x243185BE, 0x4EE4B28C, 0x550C7DC3, 0xD5FFB4E2,
|
||||
0x72BE5D74, 0xF27B896F, 0x80DEB1FE, 0x3B1696B1,
|
||||
0x9BDC06A7, 0x25C71235, 0xC19BF174, 0xCF692694,
|
||||
0xE49B69C1, 0x9EF14AD2, 0xEFBE4786, 0x384F25E3,
|
||||
0x0FC19DC6, 0x8B8CD5B5, 0x240CA1CC, 0x77AC9C65,
|
||||
0x2DE92C6F, 0x592B0275, 0x4A7484AA, 0x6EA6E483,
|
||||
0x5CB0A9DC, 0xBD41FBD4, 0x76F988DA, 0x831153B5,
|
||||
0x983E5152, 0xEE66DFAB, 0xA831C66D, 0x2DB43210,
|
||||
0xB00327C8, 0x98FB213F, 0xBF597FC7, 0xBEEF0EE4,
|
||||
0xC6E00BF3, 0x3DA88FC2, 0xD5A79147, 0x930AA725,
|
||||
0x06CA6351, 0xE003826F, 0x14292967, 0x0A0E6E70,
|
||||
0x27B70A85, 0x46D22FFC, 0x2E1B2138, 0x5C26C926,
|
||||
0x4D2C6DFC, 0x5AC42AED, 0x53380D13, 0x9D95B3DF,
|
||||
0x650A7354, 0x8BAF63DE, 0x766A0ABB, 0x3C77B2A8,
|
||||
0x81C2C92E, 0x47EDAEE6, 0x92722C85, 0x1482353B,
|
||||
0xA2BFE8A1, 0x4CF10364, 0xA81A664B, 0xBC423001,
|
||||
0xC24B8B70, 0xD0F89791, 0xC76C51A3, 0x0654BE30,
|
||||
0xD192E819, 0xD6EF5218, 0xD6990624, 0x5565A910,
|
||||
0xF40E3585, 0x5771202A, 0x106AA070, 0x32BBD1B8,
|
||||
0x19A4C116, 0xB8D2D0C8, 0x1E376C08, 0x5141AB53,
|
||||
0x2748774C, 0xDF8EEB99, 0x34B0BCB5, 0xE19B48A8,
|
||||
0x391C0CB3, 0xC5C95A63, 0x4ED8AA4A, 0xE3418ACB,
|
||||
0x5B9CCA4F, 0x7763E373, 0x682E6FF3, 0xD6B2B8A3,
|
||||
0x748F82EE, 0x5DEFB2FC, 0x78A5636F, 0x43172F60,
|
||||
0x84C87814, 0xA1F0AB72, 0x8CC70208, 0x1A6439EC,
|
||||
0x90BEFFFA, 0x23631E28, 0xA4506CEB, 0xDE82BDE9,
|
||||
0xBEF9A3F7, 0xB2C67915, 0xC67178F2, 0xE372532B,
|
||||
0xCA273ECE, 0xEA26619C, 0xD186B8C7, 0x21C0C207,
|
||||
0xEADA7DD6, 0xCDE0EB1E, 0xF57D4F7F, 0xEE6ED178,
|
||||
0x06F067AA, 0x72176FBA, 0x0A637DC5, 0xA2C898A6,
|
||||
0x113F9804, 0xBEF90DAE, 0x1B710B35, 0x131C471B,
|
||||
0x28DB77F5, 0x23047D84, 0x32CAAB7B, 0x40C72493,
|
||||
0x3C9EBE0A, 0x15C9BEBC, 0x431D67C4, 0x9C100D4C,
|
||||
0x4CC5D4BE, 0xCB3E42B6, 0x597F299C, 0xFC657E2A,
|
||||
0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817];
|
||||
|
||||
var sha512 = function(message, asciiOnly) {
|
||||
return sha2(message, 512, asciiOnly);
|
||||
@@ -154,7 +75,8 @@
|
||||
};
|
||||
|
||||
var sha2 = function(message, tbit, asciiOnly) {
|
||||
var blocks, h0, h1, h2, h3, h4, h5, h6, h7;
|
||||
var blocks, h0h, h0l, h1h, h1l, h2h, h2l, h3h, h3l,
|
||||
h4h, h4l, h5h, h5l, h6h, h6l, h7h, h7l;
|
||||
if(!asciiOnly && /[^\x00-\x7F]/.test(message)) {
|
||||
blocks = getBlocksFromUtf8(message);
|
||||
} else {
|
||||
@@ -162,105 +84,286 @@
|
||||
}
|
||||
|
||||
if(tbit == 512) {
|
||||
h0 = new Long(0x6A09E667, 0xF3BCC908);
|
||||
h1 = new Long(0xBB67AE85, 0x84CAA73B);
|
||||
h2 = new Long(0x3C6EF372, 0xFE94F82B);
|
||||
h3 = new Long(0xA54FF53A, 0x5F1D36F1);
|
||||
h4 = new Long(0x510E527F, 0xADE682D1);
|
||||
h5 = new Long(0x9B05688C, 0x2B3E6C1F);
|
||||
h6 = new Long(0x1F83D9AB, 0xFB41BD6B);
|
||||
h7 = new Long(0x5BE0CD19, 0x137E2179);
|
||||
h0h = 0x6A09E667;
|
||||
h0l = 0xF3BCC908;
|
||||
h1h = 0xBB67AE85;
|
||||
h1l = 0x84CAA73B;
|
||||
h2h = 0x3C6EF372;
|
||||
h2l = 0xFE94F82B;
|
||||
h3h = 0xA54FF53A;
|
||||
h3l = 0x5F1D36F1;
|
||||
h4h = 0x510E527F;
|
||||
h4l = 0xADE682D1;
|
||||
h5h = 0x9B05688C;
|
||||
h5l = 0x2B3E6C1F;
|
||||
h6h = 0x1F83D9AB;
|
||||
h6l = 0xFB41BD6B;
|
||||
h7h = 0x5BE0CD19;
|
||||
h7l = 0x137E2179;
|
||||
} else if(tbit == 384) {
|
||||
h0 = new Long(0xCBBB9D5D, 0xC1059ED8);
|
||||
h1 = new Long(0x629A292A, 0x367CD507);
|
||||
h2 = new Long(0x9159015A, 0x3070DD17);
|
||||
h3 = new Long(0x152FECD8, 0xF70E5939);
|
||||
h4 = new Long(0x67332667, 0xFFC00B31);
|
||||
h5 = new Long(0x8EB44A87, 0x68581511);
|
||||
h6 = new Long(0xDB0C2E0D, 0x64F98FA7);
|
||||
h7 = new Long(0x47B5481D, 0xBEFA4FA4);
|
||||
h0h = 0xCBBB9D5D;
|
||||
h0l = 0xC1059ED8;
|
||||
h1h = 0x629A292A;
|
||||
h1l = 0x367CD507;
|
||||
h2h = 0x9159015A;
|
||||
h2l = 0x3070DD17;
|
||||
h3h = 0x152FECD8;
|
||||
h3l = 0xF70E5939;
|
||||
h4h = 0x67332667;
|
||||
h4l = 0xFFC00B31;
|
||||
h5h = 0x8EB44A87;
|
||||
h5l = 0x68581511;
|
||||
h6h = 0xDB0C2E0D;
|
||||
h6l = 0x64F98FA7;
|
||||
h7h = 0x47B5481D;
|
||||
h7l = 0xBEFA4FA4;
|
||||
} else if(tbit == 256) {
|
||||
h0 = new Long(0x22312194, 0xFC2BF72C);
|
||||
h1 = new Long(0x9F555FA3, 0xC84C64C2);
|
||||
h2 = new Long(0x2393B86B, 0x6F53B151);
|
||||
h3 = new Long(0x96387719, 0x5940EABD);
|
||||
h4 = new Long(0x96283EE2, 0xA88EFFE3);
|
||||
h5 = new Long(0xBE5E1E25, 0x53863992);
|
||||
h6 = new Long(0x2B0199FC, 0x2C85B8AA);
|
||||
h7 = new Long(0x0EB72DDC, 0x81C52CA2);
|
||||
h0h = 0x22312194;
|
||||
h0l = 0xFC2BF72C;
|
||||
h1h = 0x9F555FA3;
|
||||
h1l = 0xC84C64C2;
|
||||
h2h = 0x2393B86B;
|
||||
h2l = 0x6F53B151;
|
||||
h3h = 0x96387719;
|
||||
h3l = 0x5940EABD;
|
||||
h4h = 0x96283EE2;
|
||||
h4l = 0xA88EFFE3;
|
||||
h5h = 0xBE5E1E25;
|
||||
h5l = 0x53863992;
|
||||
h6h = 0x2B0199FC;
|
||||
h6l = 0x2C85B8AA;
|
||||
h7h = 0x0EB72DDC;
|
||||
h7l = 0x81C52CA2;
|
||||
} else if(tbit == 224) {
|
||||
h0 = new Long(0x8C3D37C8, 0x19544DA2);
|
||||
h1 = new Long(0x73E19966, 0x89DCD4D6);
|
||||
h2 = new Long(0x1DFAB7AE, 0x32FF9C82);
|
||||
h3 = new Long(0x679DD514, 0x582F9FCF);
|
||||
h4 = new Long(0x0F6D2B69, 0x7BD44DA8);
|
||||
h5 = new Long(0x77E36F73, 0x04C48942);
|
||||
h6 = new Long(0x3F9D85A8, 0x6A1D36C8);
|
||||
h7 = new Long(0x1112E6AD, 0x91D692A1);
|
||||
h0h = 0x8C3D37C8;
|
||||
h0l = 0x19544DA2;
|
||||
h1h = 0x73E19966;
|
||||
h1l = 0x89DCD4D6;
|
||||
h2h = 0x1DFAB7AE;
|
||||
h2l = 0x32FF9C82;
|
||||
h3h = 0x679DD514;
|
||||
h3l = 0x582F9FCF;
|
||||
h4h = 0x0F6D2B69;
|
||||
h4l = 0x7BD44DA8;
|
||||
h5h = 0x77E36F73;
|
||||
h5l = 0x04C48942;
|
||||
h6h = 0x3F9D85A8;
|
||||
h6l = 0x6A1D36C8;
|
||||
h7h = 0x1112E6AD;
|
||||
h7l = 0x91D692A1;
|
||||
}
|
||||
|
||||
for(var i = 0, length = blocks.length;i < length;i += 16) {
|
||||
var w = [], s0, s1, j;
|
||||
for(j = 0;j < 16;++j) {
|
||||
for(var i = 0, length = blocks.length;i < length;i += 32) {
|
||||
var w = [], s0h, s0l, s1h, s1l, th, tl, c1, c2, c3, c4, j,
|
||||
ah, al, bh, bl, ch, cl, dh, dl, eh, el, fh, fl, gh, gl, hh, hl,
|
||||
majh, majl, t1h, t1l, t2h, t2l, chh, chl;
|
||||
for(j = 0;j < 32;++j) {
|
||||
w[j] = blocks[i + j];
|
||||
}
|
||||
for(j = 16;j < 80;++j) {
|
||||
s0 = w[j - 15].rightRotate(1).xor(w[j - 15].rightRotate(8)).xor(w[j - 15].shiftRightUnsigned(7));
|
||||
s1 = w[j - 2].rightRotate(19).xor(w[j - 2].rightRotate(61)).xor(w[j - 2].shiftRightUnsigned(6));
|
||||
w[j] = w[j - 16].add(s0).add(w[j - 7]).add(s1);
|
||||
for(j = 32;j < 160;j += 2) {
|
||||
th = w[j - 30];
|
||||
tl = w[j - 29];
|
||||
s0h = ((th >>> 1) | (tl << 31)) ^ ((th >>> 8) | (tl << 24)) ^ (th >>> 7);
|
||||
s0l = ((tl >>> 1) | (th << 31)) ^ ((tl >>> 8) | (th << 24)) ^ ((tl >>> 7) | th << 25);
|
||||
|
||||
th = w[j - 4];
|
||||
tl = w[j - 3];
|
||||
s1h = ((th >>> 19) | (tl << 13)) ^ ((tl >>> 29) | (th << 3)) ^ (th >>> 6);
|
||||
s1l = ((tl >>> 19) | (th << 13)) ^ ((th >>> 29) | (tl << 3)) ^ ((tl >>> 6) | th << 26);
|
||||
|
||||
th = w[j - 32];
|
||||
tl = w[j - 31];
|
||||
|
||||
c1 = (tl & 0xFFFF) + (s0l & 0xFFFF) + (s1l & 0xFFFF);
|
||||
c2 = (tl >>> 16) + (s0l >>> 16) + (s1l >>> 16);
|
||||
c3 = (th & 0xFFFF) + (s0h & 0xFFFF) + (s1h & 0xFFFF);
|
||||
c4 = (th >>> 16) + (s0h >>> 16) + (s1h >>> 16);
|
||||
|
||||
th = w[j - 14];
|
||||
tl = w[j - 13];
|
||||
|
||||
c1 += (tl & 0xFFFF);
|
||||
c2 += (tl >>> 16) + (c1 >>> 16);
|
||||
c3 += (th & 0xFFFF) + (c2 >>> 16);
|
||||
c4 += (th >>> 16) + (c3 >>> 16);
|
||||
|
||||
w[j] = (c4 << 16) | (c3 & 0xFFFF);
|
||||
w[j + 1] = (c2 << 16) | (c1 & 0xFFFF);
|
||||
}
|
||||
|
||||
var a = h0;
|
||||
var b = h1;
|
||||
var c = h2;
|
||||
var d = h3;
|
||||
var e = h4;
|
||||
var f = h5;
|
||||
var g = h6;
|
||||
var h = h7;
|
||||
var maj, t1, t2, ch;
|
||||
ah = h0h;
|
||||
al = h0l;
|
||||
bh = h1h;
|
||||
bl = h1l;
|
||||
ch = h2h;
|
||||
cl = h2l;
|
||||
dh = h3h;
|
||||
dl = h3l;
|
||||
eh = h4h;
|
||||
el = h4l;
|
||||
fh = h5h;
|
||||
fl = h5l;
|
||||
gh = h6h;
|
||||
gl = h6l;
|
||||
hh = h7h;
|
||||
hl = h7l;
|
||||
for(j = 0;j < 160;j += 2) {
|
||||
s0h = ((ah >>> 28) | (al << 4)) ^ ((al >>> 2) | (ah << 30)) ^ ((al >>> 7) | (ah << 25));
|
||||
s0l = ((al >>> 28) | (ah << 4)) ^ ((ah >>> 2) | (al << 30)) ^ ((ah >>> 7) | (al << 25));
|
||||
|
||||
for(j = 0;j < 80;++j) {
|
||||
s0 = a.rightRotate(28).xor(a.rightRotate(34)).xor(a.rightRotate(39));
|
||||
maj = a.and(b).xor(a.and(c)).xor(b.and(c));
|
||||
t2 = s0.add(maj);
|
||||
s1 = e.rightRotate(14).xor(e.rightRotate(18)).xor(e.rightRotate(41));
|
||||
ch = e.and(f).xor(e.not().and(g));
|
||||
t1 = h.add(s1).add(ch).add(K[j]).add(w[j]);
|
||||
s1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((el >>> 9) | (eh << 23));
|
||||
s1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((eh >>> 9) | (el << 23));
|
||||
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d.add(t1);
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1.add(t2);
|
||||
majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
|
||||
majl = (al & bl) ^ (al & cl) ^ (bl & cl);
|
||||
|
||||
c1 = (majl & 0xFFFF) + (s0l & 0xFFFF);
|
||||
c2 = (majl >>> 16) + (s0l >>> 16) + (c1 >>> 16);
|
||||
c3 = (majh & 0xFFFF) + (s0h & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (majh >>> 16) + (s0h >>> 16) + (c3 >>> 16);
|
||||
|
||||
t2h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
t2l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
chh = (eh & fh) ^ (~eh & gh);
|
||||
chl = (el & fl) ^ (~el & gl);
|
||||
|
||||
th = w[j];
|
||||
tl = w[j + 1];
|
||||
|
||||
c1 = (tl & 0xFFFF) + (chl & 0xFFFF) + (s1l & 0xFFFF) + (hl & 0xFFFF);
|
||||
c2 = (tl >>> 16) + (chl >>> 16) + (s1l >>> 16) + (hl >>> 16);
|
||||
c3 = (th & 0xFFFF) + (chh & 0xFFFF) + (s1h & 0xFFFF) + (hh & 0xFFFF);
|
||||
c4 = (th >>> 16) + (chh >>> 16) + (s1h >>> 16) + (hh >>> 16);
|
||||
|
||||
th = K[j];
|
||||
tl = K[j + 1];
|
||||
|
||||
c1 += (tl & 0xFFFF);
|
||||
c2 += (tl >>> 16) + (c1 >>> 16);
|
||||
c3 += (th & 0xFFFF) + (c2 >>> 16);
|
||||
c4 += (th >>> 16) + (c3 >>> 16);
|
||||
|
||||
t1h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
t1l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
hh = gh;
|
||||
hl = gl;
|
||||
gh = fh;
|
||||
gl = fl;
|
||||
fh = eh;
|
||||
fl = el;
|
||||
|
||||
c1 = (dl & 0xFFFF) + (t1l & 0xFFFF);
|
||||
c2 = (dl >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
||||
c3 = (dh & 0xFFFF) + (t1h & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (dh >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
||||
|
||||
eh = (c4 << 16) | (c3 & 0xFFFF);
|
||||
el = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
dh = ch;
|
||||
dl = cl;
|
||||
ch = bh;
|
||||
cl = bl;
|
||||
bh = ah;
|
||||
bl = al;
|
||||
|
||||
c1 = (t2l & 0xFFFF) + (t1l & 0xFFFF);
|
||||
c2 = (t2l >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
||||
c3 = (t2h & 0xFFFF) + (t1h & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (t2h >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
||||
|
||||
ah = (c4 << 16) | (c3 & 0xFFFF);
|
||||
al = (c2 << 16) | (c1 & 0xFFFF);
|
||||
}
|
||||
|
||||
h0 = h0.add(a);
|
||||
h1 = h1.add(b);
|
||||
h2 = h2.add(c);
|
||||
h3 = h3.add(d);
|
||||
h4 = h4.add(e);
|
||||
h5 = h5.add(f);
|
||||
h6 = h6.add(g);
|
||||
h7 = h7.add(h);
|
||||
c1 = (h0l & 0xFFFF) + (al & 0xFFFF);
|
||||
c2 = (h0l >>> 16) + (al >>> 16) + (c1 >>> 16);
|
||||
c3 = (h0h & 0xFFFF) + (ah & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h0h >>> 16) + (ah >>> 16) + (c3 >>> 16);
|
||||
|
||||
h0h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h0l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
c1 = (h1l & 0xFFFF) + (bl & 0xFFFF);
|
||||
c2 = (h1l >>> 16) + (bl >>> 16) + (c1 >>> 16);
|
||||
c3 = (h1h & 0xFFFF) + (bh & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h1h >>> 16) + (bh >>> 16) + (c3 >>> 16);
|
||||
|
||||
h1h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h1l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
c1 = (h2l & 0xFFFF) + (cl & 0xFFFF);
|
||||
c2 = (h2l >>> 16) + (cl >>> 16) + (c1 >>> 16);
|
||||
c3 = (h2h & 0xFFFF) + (ch & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h2h >>> 16) + (ch >>> 16) + (c3 >>> 16);
|
||||
|
||||
h2h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h2l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
c1 = (h3l & 0xFFFF) + (dl & 0xFFFF);
|
||||
c2 = (h3l >>> 16) + (dl >>> 16) + (c1 >>> 16);
|
||||
c3 = (h3h & 0xFFFF) + (dh & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h3h >>> 16) + (dh >>> 16) + (c3 >>> 16);
|
||||
|
||||
h3h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h3l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
c1 = (h4l & 0xFFFF) + (el & 0xFFFF);
|
||||
c2 = (h4l >>> 16) + (el >>> 16) + (c1 >>> 16);
|
||||
c3 = (h4h & 0xFFFF) + (eh & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h4h >>> 16) + (eh >>> 16) + (c3 >>> 16);
|
||||
|
||||
h4h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h4l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
c1 = (h5l & 0xFFFF) + (fl & 0xFFFF);
|
||||
c2 = (h5l >>> 16) + (fl >>> 16) + (c1 >>> 16);
|
||||
c3 = (h5h & 0xFFFF) + (fh & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h5h >>> 16) + (fh >>> 16) + (c3 >>> 16);
|
||||
|
||||
h5h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h5l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
c1 = (h6l & 0xFFFF) + (gl & 0xFFFF);
|
||||
c2 = (h6l >>> 16) + (gl >>> 16) + (c1 >>> 16);
|
||||
c3 = (h6h & 0xFFFF) + (gh & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h6h >>> 16) + (gh >>> 16) + (c3 >>> 16);
|
||||
|
||||
h6h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h6l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
|
||||
c1 = (h7l & 0xFFFF) + (hl & 0xFFFF);
|
||||
c2 = (h7l >>> 16) + (hl >>> 16) + (c1 >>> 16);
|
||||
c3 = (h7h & 0xFFFF) + (hh & 0xFFFF) + (c2 >>> 16);
|
||||
c4 = (h7h >>> 16) + (hh >>> 16) + (c3 >>> 16);
|
||||
|
||||
h7h = (c4 << 16) | (c3 & 0xFFFF);
|
||||
h7l = (c2 << 16) | (c1 & 0xFFFF);
|
||||
}
|
||||
|
||||
var hex = h0.toHexString() + h1.toHexString() + h2.toHexString() + h3.toHexString();
|
||||
var hex = toHexString(h0h) + toHexString(h0l) + toHexString(h1h) + toHexString(h1l) +
|
||||
toHexString(h2h) + toHexString(h2l) + toHexString(h3h) + toHexString(h3l);
|
||||
if(tbit == 224) {
|
||||
return hex.substr(0, hex.length - 8);
|
||||
}
|
||||
if(tbit >= 384) {
|
||||
hex += h4.toHexString() + h5.toHexString();
|
||||
hex += toHexString(h4h) + toHexString(h4l) + toHexString(h5h) + toHexString(h5l);
|
||||
}
|
||||
if(tbit == 512) {
|
||||
hex += h6.toHexString() + h7.toHexString();
|
||||
hex += toHexString(h6h) + toHexString(h6l) + toHexString(h7h) + toHexString(h7l);
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
|
||||
var toHexString = function(v) {
|
||||
return HEX_CHARS[(v >> 28) & 0x0F] + HEX_CHARS[(v >> 24) & 0x0F] +
|
||||
HEX_CHARS[(v >> 20) & 0x0F] + HEX_CHARS[(v >> 16) & 0x0F] +
|
||||
HEX_CHARS[(v >> 12) & 0x0F] + HEX_CHARS[(v >> 8) & 0x0F] +
|
||||
HEX_CHARS[(v >> 4) & 0x0F] + HEX_CHARS[v & 0x0F];
|
||||
};
|
||||
|
||||
var getBytesFromUtf8 = function(str) {
|
||||
var bytes = [], index = 0;
|
||||
for (var i = 0;i < str.length; i++) {
|
||||
@@ -299,11 +402,7 @@
|
||||
}
|
||||
blocks[i >> 2] |= 0x80 << SHIFT[i & 3];
|
||||
blocks[blockCount - 1] = length << 3; // length * 8
|
||||
var blocks64 = [];
|
||||
for(i = 0;i < blockCount;i += 2) {
|
||||
blocks64[i >> 1] = new Long(blocks[i], blocks[i + 1]);
|
||||
}
|
||||
return blocks64;
|
||||
return blocks;
|
||||
};
|
||||
|
||||
var getBlocksFromUtf8 = function(message) {
|
||||
@@ -320,11 +419,7 @@
|
||||
}
|
||||
blocks[i >> 2] |= 0x80 << SHIFT[i & 3];
|
||||
blocks[blockCount - 1] = length << 3; // length * 8
|
||||
var blocks64 = [];
|
||||
for(i = 0;i < blockCount;i += 2) {
|
||||
blocks64[i >> 1] = new Long(blocks[i], blocks[i + 1]);
|
||||
}
|
||||
return blocks64;
|
||||
return blocks;
|
||||
};
|
||||
|
||||
if(!root.JS_SHA512_TEST && NODE_JS) {
|
||||
|
||||
@@ -15,30 +15,3 @@ sha512_224 = null;
|
||||
JS_SHA512_TEST = true;
|
||||
require('../src/sha512.js');
|
||||
require('./test.js');
|
||||
|
||||
describe('Long', function() {
|
||||
var l = new Long(0xff, 0xff00);
|
||||
describe('shiftRightUnsigned', function() {
|
||||
it('should be not change', function() {
|
||||
expect(l.shiftRightUnsigned(0).toHexString()).to.be('000000ff0000ff00');
|
||||
});
|
||||
|
||||
it('should be equal to high', function() {
|
||||
expect(l.shiftRightUnsigned(32).toHexString()).to.be('00000000000000ff');
|
||||
});
|
||||
|
||||
it('should be sucessful', function() {
|
||||
expect(l.shiftRightUnsigned(36).toHexString()).to.be('000000000000000f');
|
||||
});
|
||||
});
|
||||
|
||||
describe('rightRotate', function() {
|
||||
it('should be not change', function() {
|
||||
expect(l.rightRotate(0).toHexString()).to.be('000000ff0000ff00');
|
||||
});
|
||||
|
||||
it('should exchange', function() {
|
||||
expect(l.rightRotate(32).toHexString()).to.be('0000ff00000000ff');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,12 +5,16 @@ describe('sha512', function() {
|
||||
expect(sha512('')).to.be('cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e');
|
||||
expect(sha512('The quick brown fox jumps over the lazy dog')).to.be('07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6');
|
||||
expect(sha512('The quick brown fox jumps over the lazy dog.', true)).to.be('91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed');
|
||||
expect(sha512('01234567801234567801234567801234567801234567801234567801234')).to.be('20caf4b6d9df9eb55dedd917bbb22ca81f1629c3877501fc33fd6d58729d7fe917dae36901fa45ea682c7660f68a4593c7594f538828ded46a1f6cf33ff97c25');
|
||||
expect(sha512('012345678012345678012345678012345678012345678012345678012345')).to.be('78a3041f566c0fa6573251dd584cf8532406cbe643e7198f093ce7f07eca1bc8852e8d25c2d50cfacb781c488a1517fba4b34c05e5c21ac3699c48328dd12c22');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha512('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('a8dedff31e3be9df6413ef5b4ecb93d62d3fbcb04297552eab5370e04afd45927854a4373037e81a50186e678d818c9ba824f4c850f3d0f02764af0252076979');
|
||||
expect(sha512('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('4555ce42c2e19f9a09a34b3e40f85178c22cde939ac42de4d33ca0e08e3c6a2e531a3abd9265a72cc22a19d085eb2c468c20d6cfb022d8914b53d6a2b485b7c9');
|
||||
expect(sha512('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('8bfa769385fe4b7d4aabf304498522d5aefa5356e42e9ae5ac9fa6b00a483685586cc0fa44da3df335719cbb524b12433afda18361d70e4c584ea81a927c670c');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -26,6 +30,7 @@ describe('sha512', function() {
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('6cb7f6d3381a187edadb43c7cdcfbbed4d2c213a7dce8ea08fe42b9882b64e643202b4974a6db94f94650ab9173d97c58bd59f6d19d27e01aab76d8d08855c65');
|
||||
expect(sha512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('d24af1901aaf1458f089a6eddf784ce61c3012aee0df98bdb67ad2dc6b41a3b4051d40caac524373930ae396a2dde99a9204871b40892eea3e5f3c8d46da0c3c');
|
||||
});
|
||||
});
|
||||
@@ -39,12 +44,16 @@ describe('sha384', function() {
|
||||
expect(sha384('')).to.be('38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b');
|
||||
expect(sha384('The quick brown fox jumps over the lazy dog')).to.be('ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1');
|
||||
expect(sha384('The quick brown fox jumps over the lazy dog.', true)).to.be('ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7');
|
||||
expect(sha384('01234567801234567801234567801234567801234567801234567801234')).to.be('1a5b170da97d4042ae4759f0b8966a3007d8d1132e1881785bd8ac1b07b5f6dc427fc6bdf14104305abb8cafb071625f');
|
||||
expect(sha384('012345678012345678012345678012345678012345678012345678012345')).to.be('c285661ebb1b808a8e6dc3f4c5252bb3cd2b2d74cffa91ad0b7009402a088b9032476320791398ab438bfd66ec3e90c8');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha384('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('3ab853dee5785c19346e8578d9cdb3b7258a8212c15fdf25d3055b4fbbc892a529e552788992fdae68dfa34f13f0af4e');
|
||||
expect(sha384('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('e4c83d6e5e18b4391a0b2e5fab84234ce9fc1071d87a9dcf38ca050ca3635781ef1d65ad4f9a835df26d186384105eac');
|
||||
expect(sha384('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('d7f6874057808f9e2eaa4eddace032c7bd548fbe3989be6591910277a25dee5972e1297deced3ad7b4e3040de88855f6');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -60,6 +69,7 @@ describe('sha384', function() {
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('143f4bb1a89e576ea05bd8433a3903352c199bf6ef35bfa30afa1505d6fcef77476d1b1824105da160a5164b7c792328');
|
||||
expect(sha384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('432a8d25efb1a8d463acc7bbbed57365cddc72de3cc19d42e1d260b1479770ecea9dd403fead2949d4fabb36939f263a');
|
||||
});
|
||||
});
|
||||
@@ -73,12 +83,16 @@ describe('sha512/256', function() {
|
||||
expect(sha512_256('')).to.be('c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a');
|
||||
expect(sha512_256('The quick brown fox jumps over the lazy dog')).to.be('dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d');
|
||||
expect(sha512_256('The quick brown fox jumps over the lazy dog.', true)).to.be('1546741840f8a492b959d9b8b2344b9b0eb51b004bba35c0aebaac86d45264c3');
|
||||
expect(sha512_256('01234567801234567801234567801234567801234567801234567801234')).to.be('e137e353ba2d34a94341dbb8d69ed1f2eefb1f045ff48f5b61272be51dc4bb61');
|
||||
expect(sha512_256('012345678012345678012345678012345678012345678012345678012345')).to.be('a5dcc9632aba17ce3c38de2c9674b75389931bfb6dc4836f8c31643013e0cd7d');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha512_256('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('21e2e940930b23f1de6377086d07e22033c6bbf3fd9fbf4b62ec66e6c08c25be');
|
||||
expect(sha512_256('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('44da7ca023996ec4b4ded88410e4acc209ca26c34dc0f26550d28503974fe2d1');
|
||||
expect(sha512_256('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('465859c0edc706a2a9c39d3175a715fdf6b764ccc43d45b5668c56f6d8aa9b9e');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -94,6 +108,7 @@ describe('sha512/256', function() {
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha512_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('d32a41d9858e45b68402f77cf9f3c3f992c36a4bffd230f78d666c87f97eaf7e');
|
||||
expect(sha512_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('bd1abad59e6b8ad69bc17b6e05aa13f0cb725467fbeb45b83d3e4094332d1367');
|
||||
});
|
||||
});
|
||||
@@ -107,12 +122,16 @@ describe('sha512/224', function() {
|
||||
expect(sha512_224('')).to.be('6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4');
|
||||
expect(sha512_224('The quick brown fox jumps over the lazy dog')).to.be('944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37');
|
||||
expect(sha512_224('The quick brown fox jumps over the lazy dog.', true)).to.be('6d6a9279495ec4061769752e7ff9c68b6b0b3c5a281b7917ce0572de');
|
||||
expect(sha512_224('01234567801234567801234567801234567801234567801234567801234')).to.be('1dfaaf5806ec0ceba60da809c2b4151e5dc5081c6a346e504ea556ea');
|
||||
expect(sha512_224('012345678012345678012345678012345678012345678012345678012345')).to.be('10dced83a53416883dbd7ace74955bb3d42de0b65b2087b902537c91');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha512_224('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('2e962464977b198ee758d615bbc92251ad2e3c0960068e279fd21d2f');
|
||||
expect(sha512_224('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('1d60954ce7bee0bf5d235fe6bfc928c0f32c0f1c4992451dbc0f4dbf');
|
||||
expect(sha512_224('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('672aef84d579799cedf2fec090ce4ea0d72e0edd2788deaa8200fd67');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -128,6 +147,7 @@ describe('sha512/224', function() {
|
||||
|
||||
describe('more than 64 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha512_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('f67e191a5d4ee67a272ccaf6cf597f0c4d6a0c46bd631be7cadb0944');
|
||||
expect(sha512_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('009c3d1e3172d6df71344982eada855421592aea28acbf660ada7569');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user