diff --git a/test/testMiddleState.html b/test/testMiddleState.html new file mode 100644 index 0000000..7842625 --- /dev/null +++ b/test/testMiddleState.html @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + diff --git a/yamd5.js b/yamd5.js index 582b576..ad12dbd 100644 --- a/yamd5.js +++ b/yamd5.js @@ -335,6 +335,28 @@ THE SOFTWARE. return this; }; + MD5.prototype.getState = function() { + var middleState = { + state: this._state.buffer.slice(0), + dataLength: this._dataLength, + bufferLength: this._bufferLength + }; + if (this._bufferLength) { + middleState.buffer = this._buffer.slice(0); + } + return middleState; + }; + + MD5.prototype.setState = function(state) { + this._state.set(new Int32Array(state.state)); + this._dataLength = state.dataLength; + this._bufferLength = state.bufferLength; + if (state.bufferLength) { + this._buffer32.set(new Uint32Array(state.buffer)); + } + return this; + }; + MD5.prototype.start = function() { this._dataLength = 0; this._bufferLength = 0; diff --git a/yamd5.min.js b/yamd5.min.js index 653d511..db40855 100644 --- a/yamd5.min.js +++ b/yamd5.min.js @@ -1,46 +1,3 @@ // project home: https://github.com/gorhill/yamd5.js -// minified using http://refresh-sf.com/yui/ -;(function(g){var b=function(l,n){var m=l[0],j=l[1],p=l[2],o=l[3];m+=(j&p|~j&o)+n[0]-680876936|0;m=(m<<7|m>>>25)+j|0;o+=(m&j|~m&p)+n[1]-389564586|0; -o=(o<<12|o>>>20)+m|0;p+=(o&m|~o&j)+n[2]+606105819|0;p=(p<<17|p>>>15)+o|0;j+=(p&o|~p&m)+n[3]-1044525330|0;j=(j<<22|j>>>10)+p|0; -m+=(j&p|~j&o)+n[4]-176418897|0;m=(m<<7|m>>>25)+j|0;o+=(m&j|~m&p)+n[5]+1200080426|0;o=(o<<12|o>>>20)+m|0;p+=(o&m|~o&j)+n[6]-1473231341|0; -p=(p<<17|p>>>15)+o|0;j+=(p&o|~p&m)+n[7]-45705983|0;j=(j<<22|j>>>10)+p|0;m+=(j&p|~j&o)+n[8]+1770035416|0;m=(m<<7|m>>>25)+j|0; -o+=(m&j|~m&p)+n[9]-1958414417|0;o=(o<<12|o>>>20)+m|0;p+=(o&m|~o&j)+n[10]-42063|0;p=(p<<17|p>>>15)+o|0;j+=(p&o|~p&m)+n[11]-1990404162|0; -j=(j<<22|j>>>10)+p|0;m+=(j&p|~j&o)+n[12]+1804603682|0;m=(m<<7|m>>>25)+j|0;o+=(m&j|~m&p)+n[13]-40341101|0;o=(o<<12|o>>>20)+m|0; -p+=(o&m|~o&j)+n[14]-1502002290|0;p=(p<<17|p>>>15)+o|0;j+=(p&o|~p&m)+n[15]+1236535329|0;j=(j<<22|j>>>10)+p|0;m+=(j&o|p&~o)+n[1]-165796510|0; -m=(m<<5|m>>>27)+j|0;o+=(m&p|j&~p)+n[6]-1069501632|0;o=(o<<9|o>>>23)+m|0;p+=(o&j|m&~j)+n[11]+643717713|0;p=(p<<14|p>>>18)+o|0; -j+=(p&m|o&~m)+n[0]-373897302|0;j=(j<<20|j>>>12)+p|0;m+=(j&o|p&~o)+n[5]-701558691|0;m=(m<<5|m>>>27)+j|0;o+=(m&p|j&~p)+n[10]+38016083|0; -o=(o<<9|o>>>23)+m|0;p+=(o&j|m&~j)+n[15]-660478335|0;p=(p<<14|p>>>18)+o|0;j+=(p&m|o&~m)+n[4]-405537848|0;j=(j<<20|j>>>12)+p|0; -m+=(j&o|p&~o)+n[9]+568446438|0;m=(m<<5|m>>>27)+j|0;o+=(m&p|j&~p)+n[14]-1019803690|0;o=(o<<9|o>>>23)+m|0;p+=(o&j|m&~j)+n[3]-187363961|0; -p=(p<<14|p>>>18)+o|0;j+=(p&m|o&~m)+n[8]+1163531501|0;j=(j<<20|j>>>12)+p|0;m+=(j&o|p&~o)+n[13]-1444681467|0;m=(m<<5|m>>>27)+j|0; -o+=(m&p|j&~p)+n[2]-51403784|0;o=(o<<9|o>>>23)+m|0;p+=(o&j|m&~j)+n[7]+1735328473|0;p=(p<<14|p>>>18)+o|0;j+=(p&m|o&~m)+n[12]-1926607734|0; -j=(j<<20|j>>>12)+p|0;m+=(j^p^o)+n[5]-378558|0;m=(m<<4|m>>>28)+j|0;o+=(m^j^p)+n[8]-2022574463|0;o=(o<<11|o>>>21)+m|0;p+=(o^m^j)+n[11]+1839030562|0; -p=(p<<16|p>>>16)+o|0;j+=(p^o^m)+n[14]-35309556|0;j=(j<<23|j>>>9)+p|0;m+=(j^p^o)+n[1]-1530992060|0;m=(m<<4|m>>>28)+j|0;o+=(m^j^p)+n[4]+1272893353|0; -o=(o<<11|o>>>21)+m|0;p+=(o^m^j)+n[7]-155497632|0;p=(p<<16|p>>>16)+o|0;j+=(p^o^m)+n[10]-1094730640|0;j=(j<<23|j>>>9)+p|0;m+=(j^p^o)+n[13]+681279174|0; -m=(m<<4|m>>>28)+j|0;o+=(m^j^p)+n[0]-358537222|0;o=(o<<11|o>>>21)+m|0;p+=(o^m^j)+n[3]-722521979|0;p=(p<<16|p>>>16)+o|0;j+=(p^o^m)+n[6]+76029189|0; -j=(j<<23|j>>>9)+p|0;m+=(j^p^o)+n[9]-640364487|0;m=(m<<4|m>>>28)+j|0;o+=(m^j^p)+n[12]-421815835|0;o=(o<<11|o>>>21)+m|0;p+=(o^m^j)+n[15]+530742520|0; -p=(p<<16|p>>>16)+o|0;j+=(p^o^m)+n[2]-995338651|0;j=(j<<23|j>>>9)+p|0;m+=(p^(j|~o))+n[0]-198630844|0;m=(m<<6|m>>>26)+j|0;o+=(j^(m|~p))+n[7]+1126891415|0; -o=(o<<10|o>>>22)+m|0;p+=(m^(o|~j))+n[14]-1416354905|0;p=(p<<15|p>>>17)+o|0;j+=(o^(p|~m))+n[5]-57434055|0;j=(j<<21|j>>>11)+p|0; -m+=(p^(j|~o))+n[12]+1700485571|0;m=(m<<6|m>>>26)+j|0;o+=(j^(m|~p))+n[3]-1894986606|0;o=(o<<10|o>>>22)+m|0;p+=(m^(o|~j))+n[10]-1051523|0; -p=(p<<15|p>>>17)+o|0;j+=(o^(p|~m))+n[1]-2054922799|0;j=(j<<21|j>>>11)+p|0;m+=(p^(j|~o))+n[8]+1873313359|0;m=(m<<6|m>>>26)+j|0; -o+=(j^(m|~p))+n[15]-30611744|0;o=(o<<10|o>>>22)+m|0;p+=(m^(o|~j))+n[6]-1560198380|0;p=(p<<15|p>>>17)+o|0;j+=(o^(p|~m))+n[13]+1309151649|0; -j=(j<<21|j>>>11)+p|0;m+=(p^(j|~o))+n[4]-145523070|0;m=(m<<6|m>>>26)+j|0;o+=(j^(m|~p))+n[11]-1120210379|0;o=(o<<10|o>>>22)+m|0; -p+=(m^(o|~j))+n[2]+718787259|0;p=(p<<15|p>>>17)+o|0;j+=(o^(p|~m))+n[9]-343485551|0;j=(j<<21|j>>>11)+p|0;l[0]=m+l[0]|0;l[1]=j+l[1]|0; -l[2]=p+l[2]|0;l[3]=o+l[3]|0};var e="0123456789abcdef";var d=[];var c=function(k){var q=e;var o=d;var r,p,l;for(var m=0;m<4; -m++){p=m*8;r=k[m];for(l=0;l<8;l+=2){o[p+1+l]=q.charAt(r&15);r>>>=4;o[p+0+l]=q.charAt(r&15);r>>>=4}}return o.join("")};var i=function(){this._dataLength=0; -this._state=new Int32Array(4);this._buffer=new ArrayBuffer(68);this._bufferLength=0;this._buffer8=new Uint8Array(this._buffer,0,68); -this._buffer32=new Uint32Array(this._buffer,0,17);this.start()};var a=new Int32Array([1732584193,-271733879,-1732584194,271733878]); -var h=new Int32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);i.prototype.appendStr=function(n){var k=this._buffer8;var j=this._buffer32; -var o=this._bufferLength;var m;for(var l=0;l>>6)+192; -k[o++]=m&63|128}else{if(m<55296||m>56319){k[o++]=(m>>>12)+224;k[o++]=(m>>>6&63)|128;k[o++]=(m&63)|128}else{m=((m-55296)*1024)+(n.charCodeAt(++l)-56320)+65536; -if(m>1114111){throw"Unicode standard supports code points up to U+10FFFF"}k[o++]=(m>>>18)+240;k[o++]=(m>>>12&63)|128;k[o++]=(m>>>6&63)|128; -k[o++]=(m&63)|128}}}if(o>=64){this._dataLength+=64;b(this._state,j);o-=64;j[0]=j[16]}}this._bufferLength=o;return this};i.prototype.appendAsciiStr=function(o){var l=this._buffer8; -var k=this._buffer32;var p=this._bufferLength;var n,m=0;for(;;){n=Math.min(o.length-m,64-p);while(n--){l[p++]=o.charCodeAt(m++) -}if(p<64){break}this._dataLength+=64;b(this._state,k);p=0}this._bufferLength=p;return this};i.prototype.appendByteArray=function(m){var l=this._buffer8; -var k=this._buffer32;var p=this._bufferLength;var o,n=0;for(;;){o=Math.min(m.length-n,64-p);while(o--){l[p++]=m[n++]}if(p<64){break -}this._dataLength+=64;b(this._state,k);p=0}this._bufferLength=p;return this};i.prototype.start=function(){this._dataLength=0; -this._bufferLength=0;this._state.set(a);return this};i.prototype.end=function(p){var q=this._bufferLength;this._dataLength+=q; -var r=this._buffer8;r[q]=128;r[q+1]=r[q+2]=r[q+3]=0;var k=this._buffer32;var m=(q>>2)+1;k.set(h.subarray(m),m);if(q>55){b(this._state,k); -k.set(h)}var j=this._dataLength*8;if(j<=4294967295){k[14]=j}else{var n=j.toString(16).match(/(.*?)(.{0,8})$/);var o=parseInt(n[2],16); -var l=parseInt(n[1],16)||0;k[14]=o;k[15]=l}b(this._state,k);return !!p?this._state:c(this._state)};var f=new i();i.hashStr=function(k,j){return f.start().appendStr(k).end(j) -};i.hashAsciiStr=function(k,j){return f.start().appendAsciiStr(k).end(j)};if(i.hashStr("hello")!=="5d41402abc4b2a76b9719d911017c592"){console.error("YaMD5> this javascript engine does not support YaMD5. Sorry.") -}if(typeof g==="object"){g.YaMD5=i}return i})(this); \ No newline at end of file +// minified using grunt-contrib-uglify +!function(a){"use strict";var b=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3];c+=(d&e|~d&f)+b[0]-680876936|0,c=(c<<7|c>>>25)+d|0,f+=(c&d|~c&e)+b[1]-389564586|0,f=(f<<12|f>>>20)+c|0,e+=(f&c|~f&d)+b[2]+606105819|0,e=(e<<17|e>>>15)+f|0,d+=(e&f|~e&c)+b[3]-1044525330|0,d=(d<<22|d>>>10)+e|0,c+=(d&e|~d&f)+b[4]-176418897|0,c=(c<<7|c>>>25)+d|0,f+=(c&d|~c&e)+b[5]+1200080426|0,f=(f<<12|f>>>20)+c|0,e+=(f&c|~f&d)+b[6]-1473231341|0,e=(e<<17|e>>>15)+f|0,d+=(e&f|~e&c)+b[7]-45705983|0,d=(d<<22|d>>>10)+e|0,c+=(d&e|~d&f)+b[8]+1770035416|0,c=(c<<7|c>>>25)+d|0,f+=(c&d|~c&e)+b[9]-1958414417|0,f=(f<<12|f>>>20)+c|0,e+=(f&c|~f&d)+b[10]-42063|0,e=(e<<17|e>>>15)+f|0,d+=(e&f|~e&c)+b[11]-1990404162|0,d=(d<<22|d>>>10)+e|0,c+=(d&e|~d&f)+b[12]+1804603682|0,c=(c<<7|c>>>25)+d|0,f+=(c&d|~c&e)+b[13]-40341101|0,f=(f<<12|f>>>20)+c|0,e+=(f&c|~f&d)+b[14]-1502002290|0,e=(e<<17|e>>>15)+f|0,d+=(e&f|~e&c)+b[15]+1236535329|0,d=(d<<22|d>>>10)+e|0,c+=(d&f|e&~f)+b[1]-165796510|0,c=(c<<5|c>>>27)+d|0,f+=(c&e|d&~e)+b[6]-1069501632|0,f=(f<<9|f>>>23)+c|0,e+=(f&d|c&~d)+b[11]+643717713|0,e=(e<<14|e>>>18)+f|0,d+=(e&c|f&~c)+b[0]-373897302|0,d=(d<<20|d>>>12)+e|0,c+=(d&f|e&~f)+b[5]-701558691|0,c=(c<<5|c>>>27)+d|0,f+=(c&e|d&~e)+b[10]+38016083|0,f=(f<<9|f>>>23)+c|0,e+=(f&d|c&~d)+b[15]-660478335|0,e=(e<<14|e>>>18)+f|0,d+=(e&c|f&~c)+b[4]-405537848|0,d=(d<<20|d>>>12)+e|0,c+=(d&f|e&~f)+b[9]+568446438|0,c=(c<<5|c>>>27)+d|0,f+=(c&e|d&~e)+b[14]-1019803690|0,f=(f<<9|f>>>23)+c|0,e+=(f&d|c&~d)+b[3]-187363961|0,e=(e<<14|e>>>18)+f|0,d+=(e&c|f&~c)+b[8]+1163531501|0,d=(d<<20|d>>>12)+e|0,c+=(d&f|e&~f)+b[13]-1444681467|0,c=(c<<5|c>>>27)+d|0,f+=(c&e|d&~e)+b[2]-51403784|0,f=(f<<9|f>>>23)+c|0,e+=(f&d|c&~d)+b[7]+1735328473|0,e=(e<<14|e>>>18)+f|0,d+=(e&c|f&~c)+b[12]-1926607734|0,d=(d<<20|d>>>12)+e|0,c+=(d^e^f)+b[5]-378558|0,c=(c<<4|c>>>28)+d|0,f+=(c^d^e)+b[8]-2022574463|0,f=(f<<11|f>>>21)+c|0,e+=(f^c^d)+b[11]+1839030562|0,e=(e<<16|e>>>16)+f|0,d+=(e^f^c)+b[14]-35309556|0,d=(d<<23|d>>>9)+e|0,c+=(d^e^f)+b[1]-1530992060|0,c=(c<<4|c>>>28)+d|0,f+=(c^d^e)+b[4]+1272893353|0,f=(f<<11|f>>>21)+c|0,e+=(f^c^d)+b[7]-155497632|0,e=(e<<16|e>>>16)+f|0,d+=(e^f^c)+b[10]-1094730640|0,d=(d<<23|d>>>9)+e|0,c+=(d^e^f)+b[13]+681279174|0,c=(c<<4|c>>>28)+d|0,f+=(c^d^e)+b[0]-358537222|0,f=(f<<11|f>>>21)+c|0,e+=(f^c^d)+b[3]-722521979|0,e=(e<<16|e>>>16)+f|0,d+=(e^f^c)+b[6]+76029189|0,d=(d<<23|d>>>9)+e|0,c+=(d^e^f)+b[9]-640364487|0,c=(c<<4|c>>>28)+d|0,f+=(c^d^e)+b[12]-421815835|0,f=(f<<11|f>>>21)+c|0,e+=(f^c^d)+b[15]+530742520|0,e=(e<<16|e>>>16)+f|0,d+=(e^f^c)+b[2]-995338651|0,d=(d<<23|d>>>9)+e|0,c+=(e^(d|~f))+b[0]-198630844|0,c=(c<<6|c>>>26)+d|0,f+=(d^(c|~e))+b[7]+1126891415|0,f=(f<<10|f>>>22)+c|0,e+=(c^(f|~d))+b[14]-1416354905|0,e=(e<<15|e>>>17)+f|0,d+=(f^(e|~c))+b[5]-57434055|0,d=(d<<21|d>>>11)+e|0,c+=(e^(d|~f))+b[12]+1700485571|0,c=(c<<6|c>>>26)+d|0,f+=(d^(c|~e))+b[3]-1894986606|0,f=(f<<10|f>>>22)+c|0,e+=(c^(f|~d))+b[10]-1051523|0,e=(e<<15|e>>>17)+f|0,d+=(f^(e|~c))+b[1]-2054922799|0,d=(d<<21|d>>>11)+e|0,c+=(e^(d|~f))+b[8]+1873313359|0,c=(c<<6|c>>>26)+d|0,f+=(d^(c|~e))+b[15]-30611744|0,f=(f<<10|f>>>22)+c|0,e+=(c^(f|~d))+b[6]-1560198380|0,e=(e<<15|e>>>17)+f|0,d+=(f^(e|~c))+b[13]+1309151649|0,d=(d<<21|d>>>11)+e|0,c+=(e^(d|~f))+b[4]-145523070|0,c=(c<<6|c>>>26)+d|0,f+=(d^(c|~e))+b[11]-1120210379|0,f=(f<<10|f>>>22)+c|0,e+=(c^(f|~d))+b[2]+718787259|0,e=(e<<15|e>>>17)+f|0,d+=(f^(e|~c))+b[9]-343485551|0,d=(d<<21|d>>>11)+e|0,a[0]=c+a[0]|0,a[1]=d+a[1]|0,a[2]=e+a[2]|0,a[3]=f+a[3]|0},c="0123456789abcdef",d=[],e=function(a){for(var b,e,f,g=c,h=d,i=0;i<4;i++)for(e=8*i,b=a[i],f=0;f<8;f+=2)h[e+1+f]=g.charAt(15&b),b>>>=4,h[e+0+f]=g.charAt(15&b),b>>>=4;return h.join("")},f=function(){this._dataLength=0,this._state=new Int32Array(4),this._buffer=new ArrayBuffer(68),this._bufferLength=0,this._buffer8=new Uint8Array(this._buffer,0,68),this._buffer32=new Uint32Array(this._buffer,0,17),this.start()},g=new Int32Array([1732584193,-271733879,-1732584194,271733878]),h=new Int32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);f.prototype.appendStr=function(a){for(var c,d=this._buffer8,e=this._buffer32,f=this._bufferLength,g=0;g>>6)+192,d[f++]=63&c|128;else if(c<55296||c>56319)d[f++]=(c>>>12)+224,d[f++]=c>>>6&63|128,d[f++]=63&c|128;else{if(c=1024*(c-55296)+(a.charCodeAt(++g)-56320)+65536,c>1114111)throw"Unicode standard supports code points up to U+10FFFF";d[f++]=(c>>>18)+240,d[f++]=c>>>12&63|128,d[f++]=c>>>6&63|128,d[f++]=63&c|128}f>=64&&(this._dataLength+=64,b(this._state,e),f-=64,e[0]=e[16])}return this._bufferLength=f,this},f.prototype.appendAsciiStr=function(a){for(var c,d=this._buffer8,e=this._buffer32,f=this._bufferLength,g=0;;){for(c=Math.min(a.length-g,64-f);c--;)d[f++]=a.charCodeAt(g++);if(f<64)break;this._dataLength+=64,b(this._state,e),f=0}return this._bufferLength=f,this},f.prototype.appendByteArray=function(a){for(var c,d=this._buffer8,e=this._buffer32,f=this._bufferLength,g=0;;){for(c=Math.min(a.length-g,64-f);c--;)d[f++]=a[g++];if(f<64)break;this._dataLength+=64,b(this._state,e),f=0}return this._bufferLength=f,this},f.prototype.getState=function(){var a={state:this._state.buffer.slice(0),dataLength:this._dataLength,bufferLength:this._bufferLength};return this._bufferLength&&(a.buffer=this._buffer.slice(0)),a},f.prototype.setState=function(a){return this._state.set(new Int32Array(a.state)),this._dataLength=a.dataLength,this._bufferLength=a.bufferLength,a.bufferLength&&this._buffer32.set(new Uint32Array(a.buffer)),this},f.prototype.start=function(){return this._dataLength=0,this._bufferLength=0,this._state.set(g),this},f.prototype.end=function(a){var c=this._bufferLength;this._dataLength+=c;var d=this._buffer8;d[c]=128,d[c+1]=d[c+2]=d[c+3]=0;var f=this._buffer32,g=(c>>2)+1;f.set(h.subarray(g),g),c>55&&(b(this._state,f),f.set(h));var i=8*this._dataLength;if(i<=4294967295)f[14]=i;else{var j=i.toString(16).match(/(.*?)(.{0,8})$/),k=parseInt(j[2],16),l=parseInt(j[1],16)||0;f[14]=k,f[15]=l}return b(this._state,f),a?this._state:e(this._state)};var i=new f;return f.hashStr=function(a,b){return i.start().appendStr(a).end(b)},f.hashAsciiStr=function(a,b){return i.start().appendAsciiStr(a).end(b)},"5d41402abc4b2a76b9719d911017c592"!==f.hashStr("hello")&&console.error("YaMD5> this javascript engine does not support YaMD5. Sorry."),"object"==typeof a&&(a.YaMD5=f),f}(this); \ No newline at end of file