* Add test cases.

* Improve performance.
pull/1/head v0.1.3
emn178 11 years ago
parent f1daa5bc4c
commit 07821b3bac

1
.gitignore vendored

@ -0,0 +1 @@
node_modules/

@ -1,3 +1,8 @@
# v0.1.3 / 2015-01-26
* Add test cases.
* Improve performance.
# v0.1.2 / 2015-01-07 # v0.1.2 / 2015-01-07
* Add bower package. * Add bower package.

@ -1,5 +1,5 @@
# js-sha512 # js-sha512
[![Build Status](https://api.travis-ci.org/emn178/js-sha512.png)](https://travis-ci.org/emn178/js-sha512) [![Build Status](https://api.travis-ci.org/emn178/js-sha512.png?branch=master)](https://travis-ci.org/emn178/js-sha512)
[![Build Status](https://coveralls.io/repos/emn178/js-sha512/badge.png?branch=master)](https://coveralls.io/r/emn178/js-sha512?branch=master) [![Build Status](https://coveralls.io/repos/emn178/js-sha512/badge.png?branch=master)](https://coveralls.io/r/emn178/js-sha512?branch=master)
[![NPM](https://nodei.co/npm/js-sha512.png?stars&downloads)](https://nodei.co/npm/js-sha512/) [![NPM](https://nodei.co/npm/js-sha512.png?stars&downloads)](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. A simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.

@ -1,6 +1,6 @@
{ {
"name": "js-sha512", "name": "js-sha512",
"version": "0.1.2", "version": "0.1.3",
"main": ["build/sha512.min.js"], "main": ["build/sha512.min.js"],
"ignore": [ "ignore": [
"samples", "samples",

@ -1,13 +1,14 @@
(function(l,J){var a=function(a,g){this.high=a<<0;this.low=g<<0};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&= (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>>>
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 g=(this.low&65535)+(c.low&65535),e=(this.low>>>16)+(c.low>>>16)+(g>>>16),h=(this.high&65535)+(c.high&65535)+(e>>>16);return new a((this.high>>>16)+(c.high>>>16)+(h>>>16)<<16|h&65535,e<<16|g&65535)};a.prototype.toHexString=function(){return z(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>>>
z(this.low)};var E="0123456789abcdef".split(""),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), 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,
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), 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,
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, 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,
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, 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,
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)],k=function(a,g){return n(a,512,g)},F=function(a,g){return n(a,384,g)},G=function(a,g){return n(a,256,g)},H=function(a,g){return n(a,224,g)},n=function(c,g,e){var h,p,q,r,t,u,v,w;if(!e&&/[^\x00-\x7F]/.test(c)){e= 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,
[];for(var f=0,b=0;b<c.length;b++){var d=c.charCodeAt(b);128>d?e[f++]=d:(2048>d?e[f++]=192|d>>6:(55296>d||57344<=d?e[f++]=224|d>>12:(d=65536+((d&1023)<<10|c.charCodeAt(++b)&1023),e[f++]=240|d>>18,e[f++]=128|d>>12&63),e[f++]=128|d>>6&63),e[f++]=128|d&63)}d=e.length;c=(d+16>>7)+1<<5;f=[];for(b=0;b<c;++b)f[b]=0;for(b=0;b<d;++b)f[b>>2]|=e[b]<<(3-(b&3)<<3);f[b>>2]|=128<<(3-(b&3)<<3);f[c-1]=d<<3;e=[];for(b=0;b<c;b+=2)e[b>>1]=new a(f[b],f[b+1]);c=e}else{d=c.length;e=(d+16>>7)+1<<5;f=[];for(b=0;b<e;++b)f[b]= 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)&
0;for(b=0;b<d;++b)f[b>>2]|=c.charCodeAt(b)<<(3-(b&3)<<3);f[b>>2]|=128<<(3-(b&3)<<3);f[e-1]=d<<3;c=[];for(b=0;b<e;b+=2)c[b>>1]=new a(f[b],f[b+1])}512==g?(h=new a(1779033703,4089235720),p=new a(3144134277,2227873595),q=new a(1013904242,4271175723),r=new a(2773480762,1595750129),t=new a(1359893119,2917565137),u=new a(2600822924,725511199),v=new a(528734635,4215389547),w=new a(1541459225,327033209)):384==g?(h=new a(3418070365,3238371032),p=new a(1654270250,914150663),q=new a(2438529370,812702999),r=new a(355462360, 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,
4144912697),t=new a(1731405415,4290775857),u=new a(2394180231,1750603025),v=new a(3675008525,1694076839),w=new a(1203062813,3204075428)):256==g?(h=new a(573645204,4230739756),p=new a(2673172387,3360449730),q=new a(596883563,1867755857),r=new a(2520282905,1497426621),t=new a(2519219938,2827943907),u=new a(3193839141,1401305490),v=new a(721525244,746961066),w=new a(246885852,2177182882)):224==g&&(h=new a(2352822216,424955298),p=new a(1944164710,2312950998),q=new a(502970286,855612546),r=new a(1738396948, 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,
1479516111),t=new a(258812777,2077511080),u=new a(2011393907,79989058),v=new a(1067287976,1780299464),w=new a(286451373,2446758561));e=0;for(f=c.length;e<f;e+=16){for(var b=[],k,m,d=0;16>d;++d)b[d]=c[e+d];for(d=16;80>d;++d)k=b[d-15].rightRotate(1).xor(b[d-15].rightRotate(8)).xor(b[d-15].shiftRightUnsigned(7)),m=b[d-2].rightRotate(19).xor(b[d-2].rightRotate(61)).xor(b[d-2].shiftRightUnsigned(6)),b[d]=b[d-16].add(k).add(b[d-7]).add(m);for(var x=h,l=p,A=q,n=r,y=t,B=u,C=v,D=w,z,d=0;80>d;++d)k=x.rightRotate(28).xor(x.rightRotate(34)).xor(x.rightRotate(39)), 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]=
m=x.and(l).xor(x.and(A)).xor(l.and(A)),k=k.add(m),m=y.rightRotate(14).xor(y.rightRotate(18)).xor(y.rightRotate(41)),z=y.and(B).xor(y.not().and(C)),m=D.add(m).add(z).add(I[d]).add(b[d]),D=C,C=B,B=y,y=n.add(m),n=A,A=l,l=x,x=m.add(k);h=h.add(x);p=p.add(l);q=q.add(A);r=r.add(n);t=t.add(y);u=u.add(B);v=v.add(C);w=w.add(D)}h=h.toHexString()+p.toHexString()+q.toHexString()+r.toHexString();if(224==g)return h.substr(0,h.length-8);384<=g&&(h+=t.toHexString()+u.toHexString());512==g&&(h+=v.toHexString()+w.toHexString()); 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)),
return h},z=function(a){for(var g="",e=0;4>e;e++)var h=3-e<<3,g=g+(E[a>>h+4&15]+E[a>>h&15]);return g};"undefined"!=typeof module?(k.sha512=k,k.sha384=F,k.sha512_256=G,k.sha512_224=H,module.exports=k):l&&(l.sha512=k,l.sha384=F,l.sha512_256=G,l.sha512_224=H)})(this); 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);

@ -1,6 +1,6 @@
{ {
"name": "js-sha512", "name": "js-sha512",
"version": "0.1.2", "version": "0.1.3",
"description": "This is a simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.", "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", "main": "src/sha512.js",
"devDependencies": { "devDependencies": {

@ -1,5 +1,5 @@
/* /*
* js-sha512 v0.1.2 * js-sha512 v0.1.3
* https://github.com/emn178/js-sha512 * https://github.com/emn178/js-sha512
* *
* Copyright 2014-2015, emn178@gmail.com * Copyright 2014-2015, emn178@gmail.com
@ -10,12 +10,23 @@
;(function(root, undefined) { ;(function(root, undefined) {
'use strict'; 'use strict';
var NODE_JS = typeof(module) != 'undefined';
if(NODE_JS) {
root = global;
}
var HEX_CHARS = '0123456789abcdef'.split('');
var SHIFT = [24, 16, 8, 0];
// Class Long // Class Long
var Long = function(high, low) { var Long = function(high, low) {
this.high = high << 0; this.high = high << 0;
this.low = low << 0; this.low = low << 0;
}; };
if(root.JS_SHA512_TEST) {
root.Long = Long;
}
Long.prototype.and = function(other) { Long.prototype.and = function(other) {
return new Long(this.high & other.high, this.low & other.low); return new Long(this.high & other.high, this.low & other.low);
}; };
@ -75,11 +86,16 @@
}; };
Long.prototype.toHexString = function() { Long.prototype.toHexString = function() {
return toHexString(this.high) + toHexString(this.low); 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 HEX_CHARS = '0123456789abcdef'.split('');
var K =[new Long(0x428A2F98, 0xD728AE22), new Long(0x71374491, 0x23EF65CD), var K =[new Long(0x428A2F98, 0xD728AE22), new Long(0x71374491, 0x23EF65CD),
new Long(0xB5C0FBCF, 0xEC4D3B2F), new Long(0xE9B5DBA5, 0x8189DBBC), new Long(0xB5C0FBCF, 0xEC4D3B2F), new Long(0xE9B5DBA5, 0x8189DBBC),
new Long(0x3956C25B, 0xF348B538), new Long(0x59F111F1, 0xB605D019), new Long(0x3956C25B, 0xF348B538), new Long(0x59F111F1, 0xB605D019),
@ -279,9 +295,9 @@
blocks[i] = 0; blocks[i] = 0;
} }
for(i = 0;i < length;++i) { for(i = 0;i < length;++i) {
blocks[i >> 2] |= message.charCodeAt(i) << (3 - (i & 3) << 3); blocks[i >> 2] |= message.charCodeAt(i) << SHIFT[i & 3];
} }
blocks[i >> 2] |= 0x80 << (3 - (i & 3) << 3); blocks[i >> 2] |= 0x80 << SHIFT[i & 3];
blocks[blockCount - 1] = length << 3; // length * 8 blocks[blockCount - 1] = length << 3; // length * 8
var blocks64 = []; var blocks64 = [];
for(i = 0;i < blockCount;i += 2) { for(i = 0;i < blockCount;i += 2) {
@ -300,9 +316,9 @@
blocks[i] = 0; blocks[i] = 0;
} }
for(i = 0;i < length;++i) { for(i = 0;i < length;++i) {
blocks[i >> 2] |= bytes[i] << (3 - (i & 3) << 3); blocks[i >> 2] |= bytes[i] << SHIFT[i & 3];
} }
blocks[i >> 2] |= 0x80 << (3 - (i & 3) << 3); blocks[i >> 2] |= 0x80 << SHIFT[i & 3];
blocks[blockCount - 1] = length << 3; // length * 8 blocks[blockCount - 1] = length << 3; // length * 8
var blocks64 = []; var blocks64 = [];
for(i = 0;i < blockCount;i += 2) { for(i = 0;i < blockCount;i += 2) {
@ -311,16 +327,7 @@
return blocks64; return blocks64;
}; };
var toHexString = function(num) { if(!root.JS_SHA512_TEST && NODE_JS) {
var hex = '';
for(var i = 0; i < 4; i++) {
var offset = 3 - i << 3;
hex += HEX_CHARS[(num >> (offset + 4)) & 0x0F] + HEX_CHARS[(num >> offset) & 0x0F];
}
return hex;
};
if(typeof(module) != 'undefined') {
sha512.sha512 = sha512; sha512.sha512 = sha512;
sha512.sha384 = sha384; sha512.sha384 = sha384;
sha512.sha512_256 = sha512_256; sha512.sha512_256 = sha512_256;

@ -4,3 +4,41 @@ sha512_256 = require('../src/sha512.js').sha512_256;
sha512_224 = require('../src/sha512.js').sha512_224; sha512_224 = require('../src/sha512.js').sha512_224;
expect = require('expect.js'); expect = require('expect.js');
require('./test.js'); 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;
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');
});
});
});

@ -20,6 +20,7 @@ describe('sha512', function() {
it('should be successful', function() { it('should be successful', function() {
expect(sha512('中文')).to.be('8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468'); expect(sha512('中文')).to.be('8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468');
expect(sha512('aécio')).to.be('e1c6925243db76985abacaf9fa85e22697f549e67f65a36c88e4046a2260990ff9eefc3402396ea8dcbe8c592d8d5671bea612156eda38d3708d394bbd17d493'); expect(sha512('aécio')).to.be('e1c6925243db76985abacaf9fa85e22697f549e67f65a36c88e4046a2260990ff9eefc3402396ea8dcbe8c592d8d5671bea612156eda38d3708d394bbd17d493');
expect(sha512('𠜎')).to.be('f3e7ee9cdf7dbb52f7edd59ce3d49868c64f2b3aceceab060b8eaaebdf9de0dae5866d660e3319c5aad426a2176cb1703efc73eb24d1a90458ceda1b7f4e3940');
}); });
}); });
@ -53,6 +54,7 @@ describe('sha384', function() {
it('should be successful', function() { it('should be successful', function() {
expect(sha384('中文')).to.be('93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c'); expect(sha384('中文')).to.be('93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c');
expect(sha384('aécio')).to.be('a2146805faafc45b0055b49386768811c803ef9fa8a85b648e114276c1bf49ef1092ec1bc2d3f7e036238a97eace2087'); expect(sha384('aécio')).to.be('a2146805faafc45b0055b49386768811c803ef9fa8a85b648e114276c1bf49ef1092ec1bc2d3f7e036238a97eace2087');
expect(sha384('𠜎')).to.be('e929475cf9b4d73e2a2366146381ac779b17499c92ddf910e028eb9f30280878a2843643ed8a539af5dffed64143b93d');
}); });
}); });
@ -86,6 +88,7 @@ describe('sha512/256', function() {
it('should be successful', function() { it('should be successful', function() {
expect(sha512_256('中文')).to.be('b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72'); expect(sha512_256('中文')).to.be('b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72');
expect(sha512_256('aécio')).to.be('122802ca08e39c2ef46f6a81379dc5683bd8aa074dfb54259f0add4d8b5504bc'); expect(sha512_256('aécio')).to.be('122802ca08e39c2ef46f6a81379dc5683bd8aa074dfb54259f0add4d8b5504bc');
expect(sha512_256('𠜎')).to.be('1032308151c0f4f5f8d4e0d96956352eb8ff87da98df8878d8795a858a7e7c08');
}); });
}); });
@ -119,6 +122,7 @@ describe('sha512/224', function() {
it('should be successful', function() { it('should be successful', function() {
expect(sha512_224('中文')).to.be('0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188'); expect(sha512_224('中文')).to.be('0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188');
expect(sha512_224('aécio')).to.be('562f2e4ee7f7451d20dcc6a0ac1a1e1c4a75f09baaf1cf19af3e15f4'); expect(sha512_224('aécio')).to.be('562f2e4ee7f7451d20dcc6a0ac1a1e1c4a75f09baaf1cf19af3e15f4');
expect(sha512_224('𠜎')).to.be('0533318c52b3d4ad355c2a6c7e727ae3d2efa749db480ac33560b059');
}); });
}); });

Loading…
Cancel
Save