var forge=require("./forge");require("./md"),require("./util");var sha256=module.exports=forge.sha256=forge.sha256||{};forge.md.sha256=forge.md.algorithms.sha256=sha256,sha256.create=function(){_initialized||_init();var e=null,a=forge.util.createBuffer(),t=Array(64),h={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0,fullMessageLength:null,messageLengthSize:8};return h.start=function(){h.messageLength=0,h.fullMessageLength=h.messageLength64=[];for(var t=h.messageLengthSize/4,f=0;f<t;++f)h.fullMessageLength.push(0);return a=forge.util.createBuffer(),e={h0:0x6a09e667,h1:0xbb67ae85,h2:0x3c6ef372,h3:0xa54ff53a,h4:0x510e527f,h5:0x9b05688c,h6:0x1f83d9ab,h7:0x5be0cd19},h},h.start(),h.update=function(f,x){"utf8"===x&&(f=forge.util.encodeUtf8(f));var g=f.length;h.messageLength+=g,g=[g/0x100000000>>>0,g>>>0];for(var n=h.fullMessageLength.length-1;n>=0;--n)h.fullMessageLength[n]+=g[1],g[1]=g[0]+(h.fullMessageLength[n]/0x100000000>>>0),h.fullMessageLength[n]=h.fullMessageLength[n]>>>0,g[0]=g[1]/0x100000000>>>0;return a.putBytes(f),_update(e,t,a),(a.read>2048||0===a.length())&&a.compact(),h},h.digest=function(){var f,x=forge.util.createBuffer();x.putBytes(a.bytes());var g=h.fullMessageLength[h.fullMessageLength.length-1]+h.messageLengthSize&h.blockLength-1;x.putBytes(_padding.substr(0,h.blockLength-g));for(var n=8*h.fullMessageLength[0],r=0;r<h.fullMessageLength.length-1;++r)n+=(f=8*h.fullMessageLength[r+1])/0x100000000>>>0,x.putInt32(n>>>0),n=f>>>0;x.putInt32(n);var c={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4,h5:e.h5,h6:e.h6,h7:e.h7};_update(c,t,x);var u=forge.util.createBuffer();return u.putInt32(c.h0),u.putInt32(c.h1),u.putInt32(c.h2),u.putInt32(c.h3),u.putInt32(c.h4),u.putInt32(c.h5),u.putInt32(c.h6),u.putInt32(c.h7),u},h};var _padding=null,_initialized=!1,_k=null;function _init(){_padding=String.fromCharCode(128)+forge.util.fillString("\0",64),_k=[0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0xfc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x6ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2],_initialized=!0}function _update(e,a,t){for(var h,f,x,g,n,r,c,u,s,l,i,b,d,o,L,p=t.length();p>=64;){for(c=0;c<16;++c)a[c]=t.getInt32();for(;c<64;++c)h=((h=a[c-2])>>>17|h<<15)^(h>>>19|h<<13)^h>>>10,f=((f=a[c-15])>>>7|f<<25)^(f>>>18|f<<14)^f>>>3,a[c]=h+a[c-7]+f+a[c-16]|0;for(u=e.h0,s=e.h1,l=e.h2,i=e.h3,b=e.h4,d=e.h5,o=e.h6,L=e.h7,c=0;c<64;++c)g=(b>>>6|b<<26)^(b>>>11|b<<21)^(b>>>25|b<<7),n=o^b&(d^o),x=(u>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10),r=u&s|l&(u^s),h=L+g+n+_k[c]+a[c],f=x+r,L=o,o=d,d=b,b=i+h>>>0,i=l,l=s,s=u,u=h+f>>>0;e.h0=e.h0+u|0,e.h1=e.h1+s|0,e.h2=e.h2+l|0,e.h3=e.h3+i|0,e.h4=e.h4+b|0,e.h5=e.h5+d|0,e.h6=e.h6+o|0,e.h7=e.h7+L|0,p-=64}}