-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha256.min.js
1 lines (1 loc) · 1.68 KB
/
sha256.min.js
1
function sha256(t){const u=[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];const w=[0x6A09E667,0xBB67AE85,0x3C6EF372,0xA54FF53A,0x510E527F,0x9B05688C,0x1F83D9AB,0x5BE0CD19];const a=new Array(64);const n=(new TextEncoder).encode(t);const o=n.length*8;const d=[];for(let t=0;t<o;t+=8)d[t>>5]|=(n[t/8]&(1<<8)-1)<<24-t%32;d[o>>5]|=128<<24-o%32;d[(o+64>>9<<4)+15]=o;for(let i=0;i<d.length;i+=16){let n=w[0];let o=w[1];let c=w[2];let e=w[3];let s=w[4];let l=w[5];let r=w[6];let f=w[7];for(let t=0;t<64;t++){if(t<16){a[t]=d[t+i]|0}else{const g=a[t-15];const h=(g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3;const j=a[t-2];const k=(j<<15|j>>>17)^(j<<13|j>>>19)^j>>>10;a[t]=h+a[t-7]+k+a[t-16]}const x=s&l^~s&r;const y=n&o^n&c^o&c;const A=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22);const E=(s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25);const T=f+E+x+u[t]+a[t];const b=A+y;f=r;r=l;l=s;s=e+T|0;e=c;c=o;o=n;n=T+b|0}w[0]=w[0]+n|0;w[1]=w[1]+o|0;w[2]=w[2]+c|0;w[3]=w[3]+e|0;w[4]=w[4]+s|0;w[5]=w[5]+l|0;w[6]=w[6]+r|0;w[7]=w[7]+f|0}return w.reduce((t,n)=>t+(n>>>0).toString(16).padStart(8,"0"),"")}