A JavaScript implementation of the SHA family of hashes, as
defined in FIPS PUB 180-4 and FIPS PUB 202, as well as the corresponding
HMAC implementation as defined in FIPS PUB 198a
Copyright Brian Turek 2008-2017
/* SHA-1
Copyright 2008-2018 Brian Turek, 1998-2009 Paul Johnston & Contributors
Distributed under the BSD License
See http://caligatio.github.com/jsSHA/ for more information
Several functions taken from Paul Johnston
See https://caligatio.github.com/jsSHA/ for more information
*/
'use strict';(function(G){functionr(d,b,c){varh=0,a=[],f=0,g,m,k,e,l,p,q,t,w=!1,n=[],u=[],v,r=!1;c=c||{};g=c.encoding||"UTF8";v=c.numRounds||1;if(v!==parseInt(v,10)||1>v)throwError("numRounds must a integer >= 1");if("SHA-1"===d)l=512,p=z,q=H,e=160,t=function(a){returna.slice()};elsethrowError("Chosen SHA variant is not supported");k=A(b,g);m=x(d);this.setHMACKey=function(a,f,b){varc;if(!0===w)throwError("HMAC key already set");if(!0===r)throwError("Cannot set HMAC key after calling update");
w)throwError("Cannot call getHash after setting HMAC key");l=B(g);switch(b){case"HEX":c=function(a){returnC(a,e,l)};break;case"B64":c=function(a){returnD(a,e,l)};break;case"BYTES":c=function(a){returnE(a,e)};break;case"ARRAYBUFFER":try{k=newArrayBuffer(0)}catch(I){throwError("ARRAYBUFFER not supported by this environment");}c=function(a){returnF(a,e)};break;default:throwError("format must be HEX, B64, BYTES, or ARRAYBUFFER");}p=q(a.slice(),f,h,t(m),e);for(k=1;k<v;k+=1)p=q(p,e,0,x(d),e);
returnc(p)};this.getHMAC=function(b,g){varc,k,n,r;if(!1===w)throwError("Cannot call getHMAC without first setting HMAC key");n=B(g);switch(b){case"HEX":c=function(a){returnC(a,e,n)};break;case"B64":c=function(a){returnD(a,e,n)};break;case"BYTES":c=function(a){returnE(a,e)};break;case"ARRAYBUFFER":try{c=newArrayBuffer(0)}catch(I){throwError("ARRAYBUFFER not supported by this environment");}c=function(a){returnF(a,e)};break;default:throwError("outputFormat must be HEX, B64, BYTES, or ARRAYBUFFER");
if("string"!==typeofb.b64Pad)throwError("Invalid b64Pad formatting option");returnb}functionA(d,b){varc;switch(b){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throwError("encoding must be UTF8, UTF16BE, or UTF16LE");}switch(d){case"HEX":c=function(b,a,f){varg=b.length,c,d,e,l,p;if(0!==g%2)throwError("String of HEX type must be in byte increments");a=a||[0];f=f||0;p=f>>>3;for(c=0;c<g;c+=2){d=parseInt(b.substr(c,2),16);if(isNaN(d))throwError("String of HEX type contains invalid characters");
p;for(q=t>>>2;a.length<=q;)a.push(0);a[q]|=d[l]<<8*(n+t%4*-1);k+=1}elseif("UTF16BE"===b||"UTF16LE"===b)for(n=2,d="UTF16LE"===b&&!0||"UTF16LE"!==b&&!1,e=0;e<c.length;e+=1){g=c.charCodeAt(e);!0===d&&(l=g&255,g=l<<8|g>>>8);t=k+p;for(q=t>>>2;a.length<=q;)a.push(0);a[q]|=g<<8*(n+t%4*-1);k+=2}return{value:a,binLen:8*k+f}};break;case"B64":c=function(b,a,f){varc=0,d,k,e,l,p,q,n;if(-1===b.search(/^[a-zA-Z0-9=+\/]+$/))throwError("Invalid character in base-64 string");k=b.indexOf("=");b=b.replace(/\=/g,
"");if(-1!==k&&k<b.length)throwError("Invalid '=' found in base-64 string");a=a||[0];f=f||0;q=f>>>3;for(k=0;k<b.length;k+=4){p=b.substr(k,4);for(e=l=0;e<p.length;e+=1)d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(p[e]),l|=d<<18-6*e;for(e=0;e<p.length-1;e+=1){n=c+q;for(d=n>>>2;a.length<=d;)a.push(0);a[d]|=(l>>>16-8*e&255)<<8*(3+n%4*-1);c+=1}}return{value:a,binLen:8*c+f}};break;case"BYTES":c=function(b,a,c){vard,m,k,e,l;a=a||[0];c=c||0;k=c>>>3;for(m=0;m<b.length;m+=
1)d=b.charCodeAt(m),l=m+k,e=l>>>2,a.length<=e&&a.push(0),a[e]|=d<<8*(3+l%4*-1);return{value:a,binLen:8*b.length+c}};break;case"ARRAYBUFFER":try{c=newArrayBuffer(0)}catch(h){throwError("ARRAYBUFFER not supported by this environment");}c=function(b,a,c){vard,m,k,e,l;a=a||[0];c=c||0;m=c>>>3;l=newUint8Array(b);for(d=0;d<b.byteLength;d+=1)e=d+m,k=e>>>2,a.length<=k&&a.push(0),a[k]|=l[d]<<8*(3+e%4*-1);return{value:a,binLen:8*b.byteLength+c}};break;default:throwError("format must be HEX, TEXT, B64, BYTES, or ARRAYBUFFER");
A JavaScript implementation of the SHA family of hashes, as
defined in FIPS PUB 180-4 and FIPS PUB 202, as well as the corresponding
HMAC implementation as defined in FIPS PUB 198a
Copyright Brian Turek 2008-2017
/* SHA-1
Copyright 2008-2018 Brian Turek, 1998-2009 Paul Johnston & Contributors
Distributed under the BSD License
See http://caligatio.github.com/jsSHA/ for more information
Several functions taken from Paul Johnston
See https://caligatio.github.com/jsSHA/ for more information
*/
'use strict';(function(G){functionr(d,b,c){varh=0,a=[],f=0,g,m,k,e,l,p,q,t,w=!1,n=[],u=[],v,r=!1;c=c||{};g=c.encoding||"UTF8";v=c.numRounds||1;if(v!==parseInt(v,10)||1>v)throwError("numRounds must a integer >= 1");if("SHA-1"===d)l=512,p=z,q=H,e=160,t=function(a){returna.slice()};elsethrowError("Chosen SHA variant is not supported");k=A(b,g);m=x(d);this.setHMACKey=function(a,f,b){varc;if(!0===w)throwError("HMAC key already set");if(!0===r)throwError("Cannot set HMAC key after calling update");
w)throwError("Cannot call getHash after setting HMAC key");l=B(g);switch(b){case"HEX":c=function(a){returnC(a,e,l)};break;case"B64":c=function(a){returnD(a,e,l)};break;case"BYTES":c=function(a){returnE(a,e)};break;case"ARRAYBUFFER":try{k=newArrayBuffer(0)}catch(I){throwError("ARRAYBUFFER not supported by this environment");}c=function(a){returnF(a,e)};break;default:throwError("format must be HEX, B64, BYTES, or ARRAYBUFFER");}p=q(a.slice(),f,h,t(m),e);for(k=1;k<v;k+=1)p=q(p,e,0,x(d),e);
returnc(p)};this.getHMAC=function(b,g){varc,k,n,r;if(!1===w)throwError("Cannot call getHMAC without first setting HMAC key");n=B(g);switch(b){case"HEX":c=function(a){returnC(a,e,n)};break;case"B64":c=function(a){returnD(a,e,n)};break;case"BYTES":c=function(a){returnE(a,e)};break;case"ARRAYBUFFER":try{c=newArrayBuffer(0)}catch(I){throwError("ARRAYBUFFER not supported by this environment");}c=function(a){returnF(a,e)};break;default:throwError("outputFormat must be HEX, B64, BYTES, or ARRAYBUFFER");
if("string"!==typeofb.b64Pad)throwError("Invalid b64Pad formatting option");returnb}functionA(d,b){varc;switch(b){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throwError("encoding must be UTF8, UTF16BE, or UTF16LE");}switch(d){case"HEX":c=function(b,a,f){varg=b.length,c,d,e,l,p;if(0!==g%2)throwError("String of HEX type must be in byte increments");a=a||[0];f=f||0;p=f>>>3;for(c=0;c<g;c+=2){d=parseInt(b.substr(c,2),16);if(isNaN(d))throwError("String of HEX type contains invalid characters");
p;for(q=t>>>2;a.length<=q;)a.push(0);a[q]|=d[l]<<8*(n+t%4*-1);k+=1}elseif("UTF16BE"===b||"UTF16LE"===b)for(n=2,d="UTF16LE"===b&&!0||"UTF16LE"!==b&&!1,e=0;e<c.length;e+=1){g=c.charCodeAt(e);!0===d&&(l=g&255,g=l<<8|g>>>8);t=k+p;for(q=t>>>2;a.length<=q;)a.push(0);a[q]|=g<<8*(n+t%4*-1);k+=2}return{value:a,binLen:8*k+f}};break;case"B64":c=function(b,a,f){varc=0,d,k,e,l,p,q,n;if(-1===b.search(/^[a-zA-Z0-9=+\/]+$/))throwError("Invalid character in base-64 string");k=b.indexOf("=");b=b.replace(/\=/g,
"");if(-1!==k&&k<b.length)throwError("Invalid '=' found in base-64 string");a=a||[0];f=f||0;q=f>>>3;for(k=0;k<b.length;k+=4){p=b.substr(k,4);for(e=l=0;e<p.length;e+=1)d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(p[e]),l|=d<<18-6*e;for(e=0;e<p.length-1;e+=1){n=c+q;for(d=n>>>2;a.length<=d;)a.push(0);a[d]|=(l>>>16-8*e&255)<<8*(3+n%4*-1);c+=1}}return{value:a,binLen:8*c+f}};break;case"BYTES":c=function(b,a,c){vard,m,k,e,l;a=a||[0];c=c||0;k=c>>>3;for(m=0;m<b.length;m+=
1)d=b.charCodeAt(m),l=m+k,e=l>>>2,a.length<=e&&a.push(0),a[e]|=d<<8*(3+l%4*-1);return{value:a,binLen:8*b.length+c}};break;case"ARRAYBUFFER":try{c=newArrayBuffer(0)}catch(h){throwError("ARRAYBUFFER not supported by this environment");}c=function(b,a,c){vard,m,k,e,l;a=a||[0];c=c||0;m=c>>>3;l=newUint8Array(b);for(d=0;d<b.byteLength;d+=1)e=d+m,k=e>>>2,a.length<=k&&a.push(0),a[k]|=l[d]<<8*(3+e%4*-1);return{value:a,binLen:8*b.byteLength+c}};break;default:throwError("format must be HEX, TEXT, B64, BYTES, or ARRAYBUFFER");