diff --git a/dist/jsOTP-es5.js b/dist/jsOTP-es5.js index 31bb8f6..fd22f0a 100644 --- a/dist/jsOTP-es5.js +++ b/dist/jsOTP-es5.js @@ -5,11 +5,7 @@ var _createClass = function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } (function () { - var Hotp, Totp, global; - - if (global === void 0 && window !== void 0) { - global = window; - } + var Hotp, Totp; Totp = function () { // pass in the secret, code dom element, ticker dom element @@ -40,7 +36,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }, { key: "base32tohex", value: function base32tohex(base32) { - var base32chars, bits, chunk, hex, i, val; + var base32chars, bits, checklength, chunk, hex, i, val; base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; bits = ""; hex = ""; @@ -50,8 +46,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons bits += this.leftpad(val.toString(2), 5, "0"); i++; } + checklength = bits.length - bits.length % 8; i = 0; - while (i + 4 <= bits.length) { + while (i + 4 <= checklength) { chunk = bits.substr(i, 4); hex = hex + parseInt(chunk, 2).toString(16); i += 4; diff --git a/dist/jsOTP-es5.min.js b/dist/jsOTP-es5.min.js index d914f36..27f995f 100644 --- a/dist/jsOTP-es5.min.js +++ b/dist/jsOTP-es5.min.js @@ -4,4 +4,4 @@ * (2) and a modified js OTP implementation found on JSFiddle */ -"use strict";var _createClass=function(){function r(r,e){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:30,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6;if(_classCallCheck(this,r),this.expiry=e,this.length=n,this.length>8||this.length<6)throw"Error: invalid code length"}return _createClass(r,[{key:"dec2hex",value:function(r){return(r<15.5?"0":"")+Math.round(r).toString(16)}},{key:"hex2dec",value:function(r){return parseInt(r,16)}},{key:"base32tohex",value:function(r){var e,n,t,o,i;for("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",e="",t="",o=0;o=r.length&&(r=Array(e+1-r.length).join(n)+r),r}},{key:"getOtp",value:function(r){var e,n,t,o,i,h,w,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(new Date).getTime();if(t=this.base32tohex(r),e=Math.round(u/1e3),w=this.leftpad(this.dec2hex(Math.floor(e/this.expiry)),16,"0"),(h=new jsSHA("SHA-1","HEX")).setHMACKey(t,"HEX"),h.update(w),"KEY MUST BE IN BYTE INCREMENTS"===(n=h.getHMAC("HEX")))throw"Error: hex key must be in byte increments";return o=this.hex2dec(n.substring(n.length-1)),i=(i=(this.hex2dec(n.substr(2*o,8))&this.hex2dec("7fffffff"))+"").length>this.length?i.substr(i.length-this.length,this.length):this.leftpad(i,this.length,"0")}}]),r}(),r=function(){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6;if(_classCallCheck(this,r),this.length=e,this.length>8||this.length<6)throw"Error: invalid code length"}return _createClass(r,[{key:"uintToString",value:function(r){var e;return e=String.fromCharCode.apply(null,r),decodeURIComponent(escape(e))}},{key:"getOtp",value:function(r,e){var n,t,o,i,h;return(i=new jsSHA("SHA-1","TEXT")).setHMACKey(r,"TEXT"),i.update(this.uintToString(new Uint8Array(this.intToBytes(e)))),n=i.getHMAC("HEX"),h=(127&(t=this.hexToBytes(n))[o=15&t[19]])<<24|(255&t[o+1])<<16|(255&t[o+2])<<8|255&t[o+3],(h+="").substr(h.length-this.length,this.length)}},{key:"intToBytes",value:function(r){var e,n;for(e=[],n=7;n>=0;)e[n]=255&r,r>>=8,--n;return e}},{key:"hexToBytes",value:function(r){var e,n,t;for(n=[],t=0,e=r.length;t>>3,0!=a%2)throw new Error("String of HEX type must be in byte increments");for(o=0;o>>1)+u)>>>2;t.length<=h;)t.push(0);t[h]|=i<<8*(3-w%4)}return{value:t,binLen:4*a+n}}function t(r,e,n){var t,o,i,h,w,u=[];for(u=e||[0],i=(n=n||0)>>>3,o=0;o>>2,u.length<=h&&u.push(0),u[h]|=t<<8*(3-w%4);return{value:u,binLen:8*r.length+n}}function o(r,e,n){var t,o,i,h,w,u,a,d,l=[],f=0;if(l=e||[0],u=(n=n||0)>>>3,-1===r.search(/^[a-zA-Z0-9=+\/]+$/))throw new Error("Invalid character in base-64 string");if(w=r.indexOf("="),r=r.replace(/\=/g,""),-1!==w&&w>>2;l.length<=a;)l.push(0);l[a]|=(i>>>16-8*o&255)<<8*(3-d%4),f+=1}}return{value:l,binLen:8*f+n}}function i(r,e){var n,t,o="",i=4*r.length;for(n=0;n>>2]>>>8*(3-n%4),o+="0123456789abcdef".charAt(t>>>4&15)+"0123456789abcdef".charAt(15&t);return e.outputUpper?o.toUpperCase():o}function h(r,e){var n,t,o,i,h,w,u="",a=4*r.length;for(n=0;n>>2,h=r.length<=i?0:r[i],i=n+2>>>2,w=r.length<=i?0:r[i],o=(r[n>>>2]>>>8*(3-n%4)&255)<<16|(h>>>8*(3-(n+1)%4)&255)<<8|w>>>8*(3-(n+2)%4)&255,t=0;t<4;t+=1)8*n+6*t<=32*r.length?u+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(o>>>6*(3-t)&63):u+=e.b64Pad;return u}function w(r){var e,n,t="",o=4*r.length;for(e=0;e>>2]>>>8*(3-e%4)&255,t+=String.fromCharCode(n);return t}function u(r){var e,n={outputUpper:!1,b64Pad:"="};if(e=r||{},n.outputUpper=e.outputUpper||!1,n.b64Pad=e.b64Pad||"=","boolean"!=typeof n.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof n.b64Pad)throw new Error("Invalid b64Pad formatting option");return n}function a(r,e){var i;switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(r){case"HEX":i=n;break;case"TEXT":i=function(r,n,t){return function(r,e,n,t){var o,i,h,w,u,a,d=[],l=[],f=0;if(d=n||[0],w=(t=t||0)>>>3,"UTF8"===e)for(i=0;i(o=r.charCodeAt(i))?l.push(o):2048>o?(l.push(192|o>>>6),l.push(128|63&o)):55296>o||57344<=o?l.push(224|o>>>12,128|o>>>6&63,128|63&o):(i+=1,o=65536+((1023&o)<<10|1023&r.charCodeAt(i)),l.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),h=0;h>>2;d.length<=u;)d.push(0);d[u]|=l[h]<<8*(3-a%4),f+=1}else if("UTF16BE"===e||"UTF16LE"===e)for(i=0;i>>8),u=(a=f+w)>>>2;d.length<=u;)d.push(0);d[u]|=o<<8*(2-a%4),f+=2}return{value:d,binLen:8*f+t}}(r,e,n,t)};break;case"B64":i=o;break;case"BYTES":i=t;break;default:throw new Error("format must be HEX, TEXT, B64, or BYTES")}return i}function d(r,e){return r<>>32-e}function l(r,e){return r>>>e|r<<32-e}function f(r,n){var t=new e(r.highOrder,r.lowOrder);return 32>=n?new e(t.highOrder>>>n|t.lowOrder<<32-n&4294967295,t.lowOrder>>>n|t.highOrder<<32-n&4294967295):new e(t.lowOrder>>>n-32|t.highOrder<<64-n&4294967295,t.highOrder>>>n-32|t.lowOrder<<64-n&4294967295)}function s(r,e){return r>>>e}function O(r,n){return 32>=n?new e(r.highOrder>>>n,r.lowOrder>>>n|r.highOrder<<32-n&4294967295):new e(0,r.highOrder>>>n-32)}function g(r,e,n){return r^e^n}function c(r,e,n){return r&e^~r&n}function p(r,n,t){return new e(r.highOrder&n.highOrder^~r.highOrder&t.highOrder,r.lowOrder&n.lowOrder^~r.lowOrder&t.lowOrder)}function S(r,e,n){return r&e^r&n^e&n}function E(r,n,t){return new e(r.highOrder&n.highOrder^r.highOrder&t.highOrder^n.highOrder&t.highOrder,r.lowOrder&n.lowOrder^r.lowOrder&t.lowOrder^n.lowOrder&t.lowOrder)}function A(r){return l(r,2)^l(r,13)^l(r,22)}function v(r){var n=f(r,28),t=f(r,34),o=f(r,39);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function H(r){return l(r,6)^l(r,11)^l(r,25)}function T(r){var n=f(r,14),t=f(r,18),o=f(r,41);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function b(r){return l(r,7)^l(r,18)^s(r,3)}function P(r){var n=f(r,1),t=f(r,8),o=O(r,7);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function U(r){return l(r,17)^l(r,19)^s(r,10)}function y(r){var n=f(r,19),t=f(r,61),o=O(r,6);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function C(r,e){var n=(65535&r)+(65535&e);return(65535&(r>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function k(r,e,n,t){var o=(65535&r)+(65535&e)+(65535&n)+(65535&t);return(65535&(r>>>16)+(e>>>16)+(n>>>16)+(t>>>16)+(o>>>16))<<16|65535&o}function m(r,e,n,t,o){var i=(65535&r)+(65535&e)+(65535&n)+(65535&t)+(65535&o);return(65535&(r>>>16)+(e>>>16)+(n>>>16)+(t>>>16)+(o>>>16)+(i>>>16))<<16|65535&i}function L(r,n){var t,o,i;return t=(65535&r.lowOrder)+(65535&n.lowOrder),i=(65535&(o=(r.lowOrder>>>16)+(n.lowOrder>>>16)+(t>>>16)))<<16|65535&t,t=(65535&r.highOrder)+(65535&n.highOrder)+(o>>>16),new e((65535&(o=(r.highOrder>>>16)+(n.highOrder>>>16)+(t>>>16)))<<16|65535&t,i)}function R(r,n,t,o){var i,h,w;return i=(65535&r.lowOrder)+(65535&n.lowOrder)+(65535&t.lowOrder)+(65535&o.lowOrder),w=(65535&(h=(r.lowOrder>>>16)+(n.lowOrder>>>16)+(t.lowOrder>>>16)+(o.lowOrder>>>16)+(i>>>16)))<<16|65535&i,i=(65535&r.highOrder)+(65535&n.highOrder)+(65535&t.highOrder)+(65535&o.highOrder)+(h>>>16),new e((65535&(h=(r.highOrder>>>16)+(n.highOrder>>>16)+(t.highOrder>>>16)+(o.highOrder>>>16)+(i>>>16)))<<16|65535&i,w)}function x(r,n,t,o,i){var h,w,u;return h=(65535&r.lowOrder)+(65535&n.lowOrder)+(65535&t.lowOrder)+(65535&o.lowOrder)+(65535&i.lowOrder),u=(65535&(w=(r.lowOrder>>>16)+(n.lowOrder>>>16)+(t.lowOrder>>>16)+(o.lowOrder>>>16)+(i.lowOrder>>>16)+(h>>>16)))<<16|65535&h,h=(65535&r.highOrder)+(65535&n.highOrder)+(65535&t.highOrder)+(65535&o.highOrder)+(65535&i.highOrder)+(w>>>16),new e((65535&(w=(r.highOrder>>>16)+(n.highOrder>>>16)+(t.highOrder>>>16)+(o.highOrder>>>16)+(i.highOrder>>>16)+(h>>>16)))<<16|65535&h,u)}function B(r){var n,t,o;if("SHA-1"===r&&1&SUPPORTED_ALGS)n=[1732584193,4023233417,2562383102,271733878,3285377520];else{if(!(6&SUPPORTED_ALGS))throw new Error("No SHA variants supported");switch(t=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],o=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r){case"SHA-224":n=t;break;case"SHA-256":n=o;break;case"SHA-384":n=[new e(3418070365,t[0]),new e(1654270250,t[1]),new e(2438529370,t[2]),new e(355462360,t[3]),new e(1731405415,t[4]),new e(41048885895,t[5]),new e(3675008525,t[6]),new e(1203062813,t[7])];break;case"SHA-512":n=[new e(o[0],4089235720),new e(o[1],2227873595),new e(o[2],4271175723),new e(o[3],1595750129),new e(o[4],2917565137),new e(o[5],725511199),new e(o[6],4215389547),new e(o[7],327033209)];break;default:throw new Error("Unknown SHA variant")}}return n}function _(r,e){var n,t,o,i,h,w,u,a=[],l=c,f=g,s=S,O=d,p=C,E=m;for(n=e[0],t=e[1],o=e[2],i=e[3],h=e[4],u=0;u<80;u+=1)a[u]=u<16?r[u]:O(a[u-3]^a[u-8]^a[u-14]^a[u-16],1),w=u<20?E(O(n,5),l(t,o,i),h,1518500249,a[u]):u<40?E(O(n,5),f(t,o,i),h,1859775393,a[u]):u<60?E(O(n,5),s(t,o,i),h,2400959708,a[u]):E(O(n,5),f(t,o,i),h,3395469782,a[u]),h=i,i=o,o=O(t,30),t=n,n=w;return e[0]=p(n,e[0]),e[1]=p(t,e[1]),e[2]=p(o,e[2]),e[3]=p(i,e[3]),e[4]=p(h,e[4]),e}function D(r,e,n,t){var o,i,h;for(h=15+(e+65>>>9<<4);r.length<=h;)r.push(0);for(r[e>>>5]|=128<<24-e%32,r[h]=e+n,i=r.length,o=0;og)throw new Error("numRounds must a integer >= 1");if("SHA-1"===A&&1&SUPPORTED_ALGS)f=512,s=_,O=D,l=160;else if(6&SUPPORTED_ALGS&&(s=function(r,e){return X(r,e,A)},O=function(r,e,n,t){return function(r,e,n,t,o){var i,h,w,u,a;if(("SHA-224"===o||"SHA-256"===o)&&2&SUPPORTED_ALGS)w=15+(e+65>>>9<<4),a=16;else{if("SHA-384"!==o&&"SHA-512"!==o||!(4&SUPPORTED_ALGS))throw new Error("Unexpected error in SHA-2 implementation");w=31+(e+129>>>10<<5),a=32}for(;r.length<=w;)r.push(0);for(r[e>>>5]|=128<<24-e%32,r[w]=e+n,h=r.length,i=0;i>>3)/4-1,uh/8){for(;w.length<=l;)w.push(0);w[l]&=4294967040}for(d=0;d<=l;d+=1)T[d]=909522486^w[d],b[d]=1549556828^w[d];o=s(T,o),p=f,H=!0},this.update=function(r){var e,n,t,i,h,w=0,u=f>>>5;for(n=(e=d(r,S,E)).binLen,i=e.value,t=n>>>5,h=0;h>>5),E=n%f,P=!0},this.getHash=function(r,e){var n,t,a;if(!0===H)throw new Error("Cannot call getHash after setting HMAC key");switch(a=u(e),r){case"HEX":n=function(r){return i(r,a)};break;case"B64":n=function(r){return h(r,a)};break;case"BYTES":n=w;break;default:throw new Error("format must be HEX, B64, or BYTES")}if(!1===v)for(o=O(S,E,p,o),t=1;t8||this.length<6)throw"Error: invalid code length"}dec2hex(r){return(r<15.5?"0":"")+Math.round(r).toString(16)}hex2dec(r){return parseInt(r,16)}base32tohex(r){var e,n,t,o,h;for("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",e="",t="",o=0;o=r.length&&(r=Array(e+1-r.length).join(n)+r),r}getOtp(r,e=(new Date).getTime()){var n,t,o,h,i,w,d;if(o=this.base32tohex(r),n=Math.round(e/1e3),d=this.leftpad(this.dec2hex(Math.floor(n/this.expiry)),16,"0"),(w=new jsSHA("SHA-1","HEX")).setHMACKey(o,"HEX"),w.update(d),"KEY MUST BE IN BYTE INCREMENTS"===(t=w.getHMAC("HEX")))throw"Error: hex key must be in byte increments";return h=this.hex2dec(t.substring(t.length-1)),i=(i=(this.hex2dec(t.substr(2*h,8))&this.hex2dec("7fffffff"))+"").length>this.length?i.substr(i.length-this.length,this.length):this.leftpad(i,this.length,"0")}},r=class{constructor(r=6){if(this.length=r,this.length>8||this.length<6)throw"Error: invalid code length"}uintToString(r){var e;return e=String.fromCharCode.apply(null,r),decodeURIComponent(escape(e))}getOtp(r,e){var n,t,o,h,i;return(h=new jsSHA("SHA-1","TEXT")).setHMACKey(r,"TEXT"),h.update(this.uintToString(new Uint8Array(this.intToBytes(e)))),n=h.getHMAC("HEX"),i=(127&(t=this.hexToBytes(n))[o=15&t[19]])<<24|(255&t[o+1])<<16|(255&t[o+2])<<8|255&t[o+3],(i+="").substr(i.length-this.length,this.length)}intToBytes(r){var e,n;for(e=[],n=7;n>=0;)e[n]=255&r,r>>=8,--n;return e}hexToBytes(r){var e,n,t;for(n=[],t=0,e=r.length;t>>3,0!=u%2)throw new Error("String of HEX type must be in byte increments");for(o=0;o>>1)+d)>>>2;t.length<=i;)t.push(0);t[i]|=h<<8*(3-w%4)}return{value:t,binLen:4*u+n}}function t(r,e,n){var t,o,h,i,w,d=[];for(d=e||[0],h=(n=n||0)>>>3,o=0;o>>2,d.length<=i&&d.push(0),d[i]|=t<<8*(3-w%4);return{value:d,binLen:8*r.length+n}}function o(r,e,n){var t,o,h,i,w,d,u,a,l=[],s=0;if(l=e||[0],d=(n=n||0)>>>3,-1===r.search(/^[a-zA-Z0-9=+\/]+$/))throw new Error("Invalid character in base-64 string");if(w=r.indexOf("="),r=r.replace(/\=/g,""),-1!==w&&w>>2;l.length<=u;)l.push(0);l[u]|=(h>>>16-8*o&255)<<8*(3-a%4),s+=1}}return{value:l,binLen:8*s+n}}function h(r,e){var n,t,o="",h=4*r.length;for(n=0;n>>2]>>>8*(3-n%4),o+="0123456789abcdef".charAt(t>>>4&15)+"0123456789abcdef".charAt(15&t);return e.outputUpper?o.toUpperCase():o}function i(r,e){var n,t,o,h,i,w,d="",u=4*r.length;for(n=0;n>>2,i=r.length<=h?0:r[h],h=n+2>>>2,w=r.length<=h?0:r[h],o=(r[n>>>2]>>>8*(3-n%4)&255)<<16|(i>>>8*(3-(n+1)%4)&255)<<8|w>>>8*(3-(n+2)%4)&255,t=0;t<4;t+=1)8*n+6*t<=32*r.length?d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(o>>>6*(3-t)&63):d+=e.b64Pad;return d}function w(r){var e,n,t="",o=4*r.length;for(e=0;e>>2]>>>8*(3-e%4)&255,t+=String.fromCharCode(n);return t}function d(r){var e,n={outputUpper:!1,b64Pad:"="};if(e=r||{},n.outputUpper=e.outputUpper||!1,n.b64Pad=e.b64Pad||"=","boolean"!=typeof n.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof n.b64Pad)throw new Error("Invalid b64Pad formatting option");return n}function u(r,e){var h;switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(r){case"HEX":h=n;break;case"TEXT":h=function(r,n,t){return function(r,e,n,t){var o,h,i,w,d,u,a=[],l=[],s=0;if(a=n||[0],w=(t=t||0)>>>3,"UTF8"===e)for(h=0;h(o=r.charCodeAt(h))?l.push(o):2048>o?(l.push(192|o>>>6),l.push(128|63&o)):55296>o||57344<=o?l.push(224|o>>>12,128|o>>>6&63,128|63&o):(h+=1,o=65536+((1023&o)<<10|1023&r.charCodeAt(h)),l.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),i=0;i>>2;a.length<=d;)a.push(0);a[d]|=l[i]<<8*(3-u%4),s+=1}else if("UTF16BE"===e||"UTF16LE"===e)for(h=0;h>>8),d=(u=s+w)>>>2;a.length<=d;)a.push(0);a[d]|=o<<8*(2-u%4),s+=2}return{value:a,binLen:8*s+t}}(r,e,n,t)};break;case"B64":h=o;break;case"BYTES":h=t;break;default:throw new Error("format must be HEX, TEXT, B64, or BYTES")}return h}function a(r,e){return r<>>32-e}function l(r,e){return r>>>e|r<<32-e}function s(r,n){var t=new e(r.highOrder,r.lowOrder);return 32>=n?new e(t.highOrder>>>n|t.lowOrder<<32-n&4294967295,t.lowOrder>>>n|t.highOrder<<32-n&4294967295):new e(t.lowOrder>>>n-32|t.highOrder<<64-n&4294967295,t.highOrder>>>n-32|t.lowOrder<<64-n&4294967295)}function f(r,e){return r>>>e}function O(r,n){return 32>=n?new e(r.highOrder>>>n,r.lowOrder>>>n|r.highOrder<<32-n&4294967295):new e(0,r.highOrder>>>n-32)}function g(r,e,n){return r^e^n}function c(r,e,n){return r&e^~r&n}function S(r,n,t){return new e(r.highOrder&n.highOrder^~r.highOrder&t.highOrder,r.lowOrder&n.lowOrder^~r.lowOrder&t.lowOrder)}function p(r,e,n){return r&e^r&n^e&n}function E(r,n,t){return new e(r.highOrder&n.highOrder^r.highOrder&t.highOrder^n.highOrder&t.highOrder,r.lowOrder&n.lowOrder^r.lowOrder&t.lowOrder^n.lowOrder&t.lowOrder)}function A(r){return l(r,2)^l(r,13)^l(r,22)}function H(r){var n=s(r,28),t=s(r,34),o=s(r,39);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function T(r){return l(r,6)^l(r,11)^l(r,25)}function v(r){var n=s(r,14),t=s(r,18),o=s(r,41);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function b(r){return l(r,7)^l(r,18)^f(r,3)}function P(r){var n=s(r,1),t=s(r,8),o=O(r,7);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function U(r){return l(r,17)^l(r,19)^f(r,10)}function m(r){var n=s(r,19),t=s(r,61),o=O(r,6);return new e(n.highOrder^t.highOrder^o.highOrder,n.lowOrder^t.lowOrder^o.lowOrder)}function C(r,e){var n=(65535&r)+(65535&e);return(65535&(r>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function L(r,e,n,t){var o=(65535&r)+(65535&e)+(65535&n)+(65535&t);return(65535&(r>>>16)+(e>>>16)+(n>>>16)+(t>>>16)+(o>>>16))<<16|65535&o}function y(r,e,n,t,o){var h=(65535&r)+(65535&e)+(65535&n)+(65535&t)+(65535&o);return(65535&(r>>>16)+(e>>>16)+(n>>>16)+(t>>>16)+(o>>>16)+(h>>>16))<<16|65535&h}function R(r,n){var t,o,h;return t=(65535&r.lowOrder)+(65535&n.lowOrder),h=(65535&(o=(r.lowOrder>>>16)+(n.lowOrder>>>16)+(t>>>16)))<<16|65535&t,t=(65535&r.highOrder)+(65535&n.highOrder)+(o>>>16),new e((65535&(o=(r.highOrder>>>16)+(n.highOrder>>>16)+(t>>>16)))<<16|65535&t,h)}function x(r,n,t,o){var h,i,w;return h=(65535&r.lowOrder)+(65535&n.lowOrder)+(65535&t.lowOrder)+(65535&o.lowOrder),w=(65535&(i=(r.lowOrder>>>16)+(n.lowOrder>>>16)+(t.lowOrder>>>16)+(o.lowOrder>>>16)+(h>>>16)))<<16|65535&h,h=(65535&r.highOrder)+(65535&n.highOrder)+(65535&t.highOrder)+(65535&o.highOrder)+(i>>>16),new e((65535&(i=(r.highOrder>>>16)+(n.highOrder>>>16)+(t.highOrder>>>16)+(o.highOrder>>>16)+(h>>>16)))<<16|65535&h,w)}function B(r,n,t,o,h){var i,w,d;return i=(65535&r.lowOrder)+(65535&n.lowOrder)+(65535&t.lowOrder)+(65535&o.lowOrder)+(65535&h.lowOrder),d=(65535&(w=(r.lowOrder>>>16)+(n.lowOrder>>>16)+(t.lowOrder>>>16)+(o.lowOrder>>>16)+(h.lowOrder>>>16)+(i>>>16)))<<16|65535&i,i=(65535&r.highOrder)+(65535&n.highOrder)+(65535&t.highOrder)+(65535&o.highOrder)+(65535&h.highOrder)+(w>>>16),new e((65535&(w=(r.highOrder>>>16)+(n.highOrder>>>16)+(t.highOrder>>>16)+(o.highOrder>>>16)+(h.highOrder>>>16)+(i>>>16)))<<16|65535&i,d)}function k(r){var n,t,o;if("SHA-1"===r&&1&SUPPORTED_ALGS)n=[1732584193,4023233417,2562383102,271733878,3285377520];else{if(!(6&SUPPORTED_ALGS))throw new Error("No SHA variants supported");switch(t=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],o=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r){case"SHA-224":n=t;break;case"SHA-256":n=o;break;case"SHA-384":n=[new e(3418070365,t[0]),new e(1654270250,t[1]),new e(2438529370,t[2]),new e(355462360,t[3]),new e(1731405415,t[4]),new e(41048885895,t[5]),new e(3675008525,t[6]),new e(1203062813,t[7])];break;case"SHA-512":n=[new e(o[0],4089235720),new e(o[1],2227873595),new e(o[2],4271175723),new e(o[3],1595750129),new e(o[4],2917565137),new e(o[5],725511199),new e(o[6],4215389547),new e(o[7],327033209)];break;default:throw new Error("Unknown SHA variant")}}return n}function D(r,e){var n,t,o,h,i,w,d,u=[],l=c,s=g,f=p,O=a,S=C,E=y;for(n=e[0],t=e[1],o=e[2],h=e[3],i=e[4],d=0;d<80;d+=1)u[d]=d<16?r[d]:O(u[d-3]^u[d-8]^u[d-14]^u[d-16],1),w=d<20?E(O(n,5),l(t,o,h),i,1518500249,u[d]):d<40?E(O(n,5),s(t,o,h),i,1859775393,u[d]):d<60?E(O(n,5),f(t,o,h),i,2400959708,u[d]):E(O(n,5),s(t,o,h),i,3395469782,u[d]),i=h,h=o,o=O(t,30),t=n,n=w;return e[0]=S(n,e[0]),e[1]=S(t,e[1]),e[2]=S(o,e[2]),e[3]=S(h,e[3]),e[4]=S(i,e[4]),e}function G(r,e,n,t){var o,h,i;for(i=15+(e+65>>>9<<4);r.length<=i;)r.push(0);for(r[e>>>5]|=128<<24-e%32,r[i]=e+n,h=r.length,o=0;og)throw new Error("numRounds must a integer >= 1");if("SHA-1"===A&&1&SUPPORTED_ALGS)s=512,f=D,O=G,l=160;else if(6&SUPPORTED_ALGS&&(f=function(r,e){return _(r,e,A)},O=function(r,e,n,t){return function(r,e,n,t,o){var h,i,w,d,u;if(("SHA-224"===o||"SHA-256"===o)&&2&SUPPORTED_ALGS)w=15+(e+65>>>9<<4),u=16;else{if("SHA-384"!==o&&"SHA-512"!==o||!(4&SUPPORTED_ALGS))throw new Error("Unexpected error in SHA-2 implementation");w=31+(e+129>>>10<<5),u=32}for(;r.length<=w;)r.push(0);for(r[e>>>5]|=128<<24-e%32,r[w]=e+n,i=r.length,h=0;h>>3)/4-1,di/8){for(;w.length<=l;)w.push(0);w[l]&=4294967040}for(a=0;a<=l;a+=1)v[a]=909522486^w[a],b[a]=1549556828^w[a];o=f(v,o),S=s,T=!0},this.update=function(r){var e,n,t,h,i,w=0,d=s>>>5;for(n=(e=a(r,p,E)).binLen,h=e.value,t=n>>>5,i=0;i>>5),E=n%s,P=!0},this.getHash=function(r,e){var n,t,u;if(!0===T)throw new Error("Cannot call getHash after setting HMAC key");switch(u=d(e),r){case"HEX":n=function(r){return h(r,u)};break;case"B64":n=function(r){return i(r,u)};break;case"BYTES":n=w;break;default:throw new Error("format must be HEX, B64, or BYTES")}if(!1===H)for(o=O(p,E,S,o),t=1;t