var forge=require("./forge");require("./md"),require("./util");var md5=module.exports=forge.md5=forge.md5||{};forge.md.md5=forge.md.algorithms.md5=md5,md5.create=function(){_initialized||_init();var e=null,t=forge.util.createBuffer(),r=Array(16),g={algorithm:"md5",blockLength:64,digestLength:16,messageLength:0,fullMessageLength:null,messageLengthSize:8};return g.start=function(){g.messageLength=0,g.fullMessageLength=g.messageLength64=[];for(var r=g.messageLengthSize/4,n=0;n<r;++n)g.fullMessageLength.push(0);return t=forge.util.createBuffer(),e={h0:0x67452301,h1:0xefcdab89,h2:0x98badcfe,h3:0x10325476},g},g.start(),g.update=function(n,h){"utf8"===h&&(n=forge.util.encodeUtf8(n));var a=n.length;g.messageLength+=a,a=[a/0x100000000>>>0,a>>>0];for(var l=g.fullMessageLength.length-1;l>=0;--l)g.fullMessageLength[l]+=a[1],a[1]=a[0]+(g.fullMessageLength[l]/0x100000000>>>0),g.fullMessageLength[l]=g.fullMessageLength[l]>>>0,a[0]=a[1]/0x100000000>>>0;return t.putBytes(n),_update(e,r,t),(t.read>2048||0===t.length())&&t.compact(),g},g.digest=function(){var n=forge.util.createBuffer();n.putBytes(t.bytes());var h=g.fullMessageLength[g.fullMessageLength.length-1]+g.messageLengthSize&g.blockLength-1;n.putBytes(_padding.substr(0,g.blockLength-h));for(var a,l=0,u=g.fullMessageLength.length-1;u>=0;--u)l=(a=8*g.fullMessageLength[u]+l)/0x100000000>>>0,n.putInt32Le(a>>>0);var f={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3};_update(f,r,n);var s=forge.util.createBuffer();return s.putInt32Le(f.h0),s.putInt32Le(f.h1),s.putInt32Le(f.h2),s.putInt32Le(f.h3),s},g};var _padding=null,_g=null,_r=null,_k=null,_initialized=!1;function _init(){_padding=String.fromCharCode(128)+forge.util.fillString("\0",64),_g=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12,5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2,0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9],_r=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],_k=Array(64);for(var e=0;e<64;++e)_k[e]=Math.floor(0x100000000*Math.abs(Math.sin(e+1)));_initialized=!0}function _update(e,t,r){for(var g,n,h,a,l,u,f,s,i=r.length();i>=64;){for(n=e.h0,h=e.h1,a=e.h2,l=e.h3,s=0;s<16;++s)t[s]=r.getInt32Le(),g=n+(l^h&(a^l))+_k[s]+t[s],f=_r[s],n=l,l=a,a=h,h+=g<<f|g>>>32-f;for(;s<32;++s)g=n+(a^l&(h^a))+_k[s]+t[_g[s]],f=_r[s],n=l,l=a,a=h,h+=g<<f|g>>>32-f;for(;s<48;++s)g=n+(h^a^l)+_k[s]+t[_g[s]],f=_r[s],n=l,l=a,a=h,h+=g<<f|g>>>32-f;for(;s<64;++s)g=n+(a^(h|~l))+_k[s]+t[_g[s]],f=_r[s],n=l,l=a,a=h,h+=g<<f|g>>>32-f;e.h0=e.h0+n|0,e.h1=e.h1+h|0,e.h2=e.h2+a|0,e.h3=e.h3+l|0,i-=64}}