You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
js-sha3/build/sha3.min.js

9 lines
9.5 KiB
JavaScript

/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.9.1
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2023
* @license MIT
*/
!function(){"use strict";function t(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function e(e,r,n){t.call(this,e,r,n)}var r="input is invalid type",n="object"==typeof window,i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?i=global:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,u=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[4,1024,262144,67108864],h=[0,8,16,24],p=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],l=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136},v=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,A=!u||!i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},g=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(r);if(u&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!v(t)&&!A(t))throw new Error(r);return[t,!1]},B=function(t){return 0===g(t)[0].length},_=function(e,r,n){return function(i){return new t(e,r,e).update(i)[n]()}},k=function(e,r,n){return function(i,o){return new t(e,r,o).update(i)[n]()}},w=function(t,e,r){return function(e,n,i,o){return O["cshake"+t].update(e,n,i,o)[r]()}},S=function(t,e,r){return function(e,n,i,o){return O["kmac"+t].update(e,n,i,o)[r]()}},C=function(t,e,r,n){for(var i=0;i<y.length;++i){var o=y[i];t[o]=e(r,n,o)}return t},x=function(e,r){var n=_(e,r,"hex");return n.create=function(){return new t(e,r,e)},n.update=function(t){return n.create().update(t)},C(n,_,e,r)},m=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:x},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:x},{name:"shake",padding:[31,7936,2031616,520093696],bits:l,createMethod:function(e,r){var n=k(e,r,"hex");return n.create=function(n){return new t(e,r,n)},n.update=function(t,e){return n.create(e).update(t)},C(n,k,e,r)}},{name:"cshake",padding:c,bits:l,createMethod:function(e,r){var n=b[e],i=w(e,0,"hex");return i.create=function(i,o,a){return B(o)&&B(a)?O["shake"+e].create(i):new t(e,r,i).bytepad([o,a],n)},i.update=function(t,e,r,n){return i.create(e,r,n).update(t)},C(i,w,e,r)}},{name:"kmac",padding:c,bits:l,createMethod:function(t,r){var n=b[t],i=S(t,0,"hex");return i.create=function(i,o,a){return new e(t,r,o).bytepad(["KMAC",a],n).bytepad([i],n)},i.update=function(t,e,r,n){return i.create(t,r,n).update(e)},C(i,S,t,r)}}],O={},z=[],N=0;N<m.length;++N)for(var J=m[N],M=J.bits,j=0;j<M.length;++j){var E=J.name+"_"+M[j];if(z.push(E),O[E]=J.createMethod(M[j],J.padding),"sha3"!==J.name){var H=J.name+M[j];z.push(H),O[H]=O[E]}}t.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=g(t);t=e[0];for(var r,n,i=e[1],o=this.blocks,a=this.byteCount,s=t.length,u=this.blockCount,f=0,c=this.s;f<s;){if(this.reset)for(this.reset=!1,o[0]=this.block,r=1;r<u+1;++r)o[r]=0;if(i)for(r=this.start;f<s&&r<a;++f)(n=t.charCodeAt(f))<128?o[r>>2]|=n<<h[3&r++]:n<2048?(o[r>>2]|=(192|n>>6)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):n<55296||n>=57344?(o[r>>2]|=(224|n>>12)<<h[3&r++],o[r>>2]|=(128|n>>6&63)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),o[r>>2]|=(240|n>>18)<<h[3&r++],o[r>>2]|=(128|n>>12&63)<<h