// https://tools.ietf.org/html/rfc7693 const MASK=0xffffffff; const BLOCK_LEN=64; const IV=[0x6A09E667,0xBB67AE85,0x3C6EF372,0xA54FF53A,0x510E527F,0x9B05688C,0x1F83D9AB,0x5BE0CD19]; function padEnd(arr,length,val=0){ return arr.concat((new Array(length-arr.length)).fill(0)); } function rrot(x,shift){ return ((x>>>shift)|(x<<(32-shift)))&MASK; } function BLAKE2S(outputLen=32,key=[]){ this._buffer=[]; this._dataLen=0; this._outputLen=outputLen; this._state=IV.slice(); this._state[0]^=0x01010000^(key.length<<8)^this._outputLen; if(key.length>0){this.update(padEnd(key,BLOCK_LEN,0));} } BLAKE2S.prototype.update=function(data){ for(let i=0;ix^v[i]^v[i+8]); } BLAKE2S.prototype._mix=function(arr,ia,ib,ic,id,x,y){ let a=arr[ia], b=arr[ib], c=arr[ic], d=arr[id]; a=(a+b+x)&MASK; d=rrot(d^a,16); c=(c+d)&MASK; b=rrot(b^c,12); a=(a+b+y)&MASK; d=rrot(d^a,8); c=(c+d)&MASK; b=rrot(b^c,7); arr[ia]=a; arr[ib]=b; arr[ic]=c; arr[id]=d; }; function blake2s(data,outputLen=32,key=[]){ let h=new BLAKE2S(outputLen,key); for(let i=0;i