UNPKG

sha256-es

Version:

Cryptographic hash library producing a 256-bit (32-byte) hash value

2 lines 4.03 kB
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["sha256-es"]=e():r["sha256-es"]=e()}(this,function(){return function(r){function e(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=r,e.c=n,e.i=function(r){return r},e.d=function(r,n,t){e.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:t})},e.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(n,"a",n),n},e.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},e.p="",e(e.s=1)}([function(r,e,n){"use strict";function t(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function r(r,e){for(var n=0;n<e.length;n++){var t=e[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(r,t.key,t)}}return function(e,n,t){return n&&r(e.prototype,n),t&&r(e,t),e}}(),a=function(){function r(){t(this,r)}return o(r,null,[{key:"hash",value:function(e){return r.stringToHex(r.arrayToString(r.run(r.stringToArray(e),8*e.length)))}},{key:"run",value:function(e,n){var t=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],o=15+(n+64>>9<<4),a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],u=0,i=1779033703,l=-1150833019,f=1013904242,c=-1521486534,d=1359893119,s=-1694144372,y=528734635,v=1541459225,g=i,p=l,h=f,m=c,k=d,b=s,x=y,j=v;for(e[n>>5]|=128<<24-n%32,e[o]=n;u<o;u+=16){i=g,l=p,f=h,c=m,d=k,s=b,y=x,v=j;for(var A=0,T=null,C=null;A<64;A+=1)a[A]=A<16?e[A+u]:r.add(r.add(r.add(r.gamma1256(a[A-2]),a[A-7]),r.gamma0256(a[A-15])),a[A-16]),T=r.add(r.add(r.add(r.add(j,r.sigma1256(k)),r.ch(k,b,x)),t[A]),a[A]),C=r.add(r.sigma0256(g),r.maj(g,p,h)),j=x,x=b,b=k,k=r.add(m,T),m=h,h=p,p=g,g=r.add(T,C);g=r.add(g,i),p=r.add(p,l),h=r.add(h,f),m=r.add(m,c),k=r.add(k,d),b=r.add(b,s),x=r.add(x,y),j=r.add(j,v)}return[g,p,h,m,k,b,x,j]}},{key:"arrayToString",value:function(r){for(var e=32*r.length,n=0,t="";n<e;n+=8)t+=String.fromCharCode(r[n>>5]>>>24-n%32&255);return t}},{key:"stringToArray",value:function(r){for(var e=8*r.length,n=Array(r.length>>2),t=n.length,o=0;o<t;o+=1)n[o]=0;for(o=0;o<e;o+=8)n[o>>5]|=(255&r.charCodeAt(o/8))<<24-o%32;return n}},{key:"stringToHex",value:function(r){for(var e="0123456789abcdef",n=r.length,t="",o=null,a=0;a<n;a+=1)o=r.charCodeAt(a),t+=e.charAt(o>>>4&15)+e.charAt(15&o);return t}},{key:"rotl",value:function(r,e){return r>>>e|r<<32-e}},{key:"rotr",value:function(r,e){return r>>>e}},{key:"ch",value:function(r,e,n){return r&e^~r&n}},{key:"maj",value:function(r,e,n){return r&e^r&n^e&n}},{key:"sigma0256",value:function(e){return r.rotl(e,2)^r.rotl(e,13)^r.rotl(e,22)}},{key:"sigma1256",value:function(e){return r.rotl(e,6)^r.rotl(e,11)^r.rotl(e,25)}},{key:"gamma0256",value:function(e){return r.rotl(e,7)^r.rotl(e,18)^r.rotr(e,3)}},{key:"gamma1256",value:function(e){return r.rotl(e,17)^r.rotl(e,19)^r.rotr(e,10)}},{key:"add",value:function(r,e){var n=(65535&r)+(65535&e);return(r>>16)+(e>>16)+(n>>16)<<16|65535&n}}]),r}();e.default=a},function(r,e,n){r.exports=n(0)}])}); //# sourceMappingURL=sha256-es.min.js.map