gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 6.86 kB
JavaScript
/*! Copyright 2022-2026 the gnablib contributors MPL-1.1 */
var t,s,e,i,o=this&&this.__classPrivateFieldSet||function(t,s,e,i,o){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof s?t!==s||!o:!s.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?o.call(t,e):o?o.value=e:s.set(t,e),e},r=this&&this.__classPrivateFieldGet||function(t,s,e,i){if("a"===e&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof s?t!==s||!i:!s.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===e?i:"a"===e?i.call(t):i?i.value:s.get(t)};import{asLE as h}from"../../endian/platform.js";import{U32 as a}from"../../primitive/number/U32Static.js";const n=[1732584193,4023233417,2562383102,271733878,3285377520],l=[1985229328,4275878552,2309737967,19088743,1009589775],f=[(t,s,e)=>t^s^e,(t,s,e)=>e^t&(s^e),(t,s,e)=>(t|~s)^e,(t,s,e)=>s^e&(t^s),(t,s,e)=>t^(s|~e)],c=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],R=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],p=[0,1518500249,1859775393,2400959708,2840853838],u=[1352829926,1548603684,1836072691,2053994217,0],d=[1352829926,1548603684,1836072691,0],b=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],w=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11];class _{constructor(h,a,n){this.blockSize=64,t.set(this,void 0),s.set(this,new Uint8Array(64)),e.set(this,new Uint32Array(r(this,s,"f").buffer)),this._ingestBytes=0,this._bPos=0,i.set(this,void 0),this.size=h,o(this,t,new Uint32Array(h>>2),"f"),o(this,i,a,"f"),this._hash=n,this.reset()}hash(){for(let t=0;t<16;t++)h.i32(r(this,s,"f"),4*t);this._hash(r(this,t,"f"),r(this,e,"f")),this._bPos=0}write(t){this._ingestBytes+=t.length;let e=t.length,i=0,o=64-this._bPos;for(;e>0;){if(o>e)return r(this,s,"f").set(t.subarray(i),this._bPos),void(this._bPos+=e);r(this,s,"f").set(t.subarray(i,i+o),this._bPos),this._bPos+=o,this.hash(),i+=o,e-=o,o=64}}sum(){return this.clone().sumIn()}sumIn(){r(this,s,"f")[this._bPos]=128,this._bPos++;this._bPos>56&&(r(this,s,"f").fill(0,this._bPos),this.hash()),r(this,s,"f").fill(0,this._bPos);r(this,e,"f")[14]=this._ingestBytes<<3,r(this,e,"f")[15]=this._ingestBytes/536870912,h.i32(r(this,s,"f"),56),h.i32(r(this,s,"f"),60),this.hash();const i=new Uint8Array(r(this,t,"f").buffer,r(this,t,"f").byteOffset);for(let t=0;t<this.size;t++)h.i32(i,4*t);return i.slice(0,this.size)}reset(){r(this,i,"f").call(this,r(this,t,"f")),this._ingestBytes=0,this._bPos=0}newEmpty(){return new _(this.size,r(this,i,"f"),this._hash)}clone(){const e=new _(this.size,r(this,i,"f"),this._hash);return r(e,t,"f").set(r(this,t,"f")),r(e,s,"f").set(r(this,s,"f")),e._ingestBytes=this._ingestBytes,e._bPos=this._bPos,e}}t=new WeakMap,s=new WeakMap,e=new WeakMap,i=new WeakMap;export class RipeMd128 extends _{constructor(){super(16,RipeMd128.iv,RipeMd128.hash)}static iv(t){t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3]}static hash(t,s){let e,i=t[0],o=t[1],r=t[2],h=t[3],n=t[0],l=t[1],u=t[2],_=t[3];for(let t=0;t<64;t++){const y=t>>4;e=a.lRot(i+f[y](o,r,h)+s[c[t]]+p[y],b[t]),i=h,h=r,r=o,o=e,e=a.lRot(n+f[3-y](l,u,_)+s[R[t]]+d[y],w[t]),n=_,_=u,u=l,l=e}e=t[1]+r+_,t[1]=t[2]+h+n,t[2]=t[3]+i+l,t[3]=t[0]+o+u,t[0]=e}get[Symbol.toStringTag](){return"RIPEMD-128"}}export class RipeMd160 extends _{constructor(){super(20,RipeMd160.iv,RipeMd160.hash)}static iv(t){t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4]}static hash(t,s){let e,i=t[0],o=t[1],r=t[2],h=t[3],n=t[4],l=t[0],d=t[1],_=t[2],y=t[3],P=t[4];for(let t=0;t<80;t++){const g=Math.floor(t/16);e=n+a.lRot(i+f[g](o,r,h)+s[c[t]]+p[g],b[t]),i=n,n=h,h=a.lRot(r,10),r=o,o=e,e=P+a.lRot(l+f[4-g](d,_,y)+s[R[t]]+u[g],w[t]),l=P,P=y,y=a.lRot(_,10),_=d,d=e}e=t[1]+r+y,t[1]=t[2]+h+P,t[2]=t[3]+n+l,t[3]=t[4]+i+d,t[4]=t[0]+o+_,t[0]=e}get[Symbol.toStringTag](){return"RIPEMD-160"}}export class RipeMd256 extends _{constructor(){super(32,RipeMd256.iv,RipeMd256.hash)}static iv(t){t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=l[0],t[5]=l[1],t[6]=l[2],t[7]=l[3]}static hash(t,s){let e,i=t[0],o=t[1],r=t[2],h=t[3],n=t[4],l=t[5],u=t[6],_=t[7],y=0,P=0;for(;y<16;y++)e=a.lRot(i+f[P](o,r,h)+s[c[y]]+p[P],b[y]),i=h,h=r,r=o,o=e,e=a.lRot(n+f[3-P](l,u,_)+s[R[y]]+d[P],w[y]),n=_,_=u,u=l,l=e;for(e=i,i=n,n=e,P=1;y<32;y++)e=a.lRot(i+f[P](o,r,h)+s[c[y]]+p[P],b[y]),i=h,h=r,r=o,o=e,e=a.lRot(n+f[3-P](l,u,_)+s[R[y]]+d[P],w[y]),n=_,_=u,u=l,l=e;for(e=o,o=l,l=e,P=2;y<48;y++)e=a.lRot(i+f[P](o,r,h)+s[c[y]]+p[P],b[y]),i=h,h=r,r=o,o=e,e=a.lRot(n+f[3-P](l,u,_)+s[R[y]]+d[P],w[y]),n=_,_=u,u=l,l=e;for(e=r,r=u,u=e,P=3;y<64;y++)e=a.lRot(i+f[P](o,r,h)+s[c[y]]+p[P],b[y]),i=h,h=r,r=o,o=e,e=a.lRot(n+f[3-P](l,u,_)+s[R[y]]+d[P],w[y]),n=_,_=u,u=l,l=e;e=h,h=_,_=e,t[0]+=i,t[1]+=o,t[2]+=r,t[3]+=h,t[4]+=n,t[5]+=l,t[6]+=u,t[7]+=_}get[Symbol.toStringTag](){return"RIPEMD-256"}}export class RipeMd320 extends _{constructor(){super(40,RipeMd320.iv,RipeMd320.hash)}static iv(t){t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=l[0],t[6]=l[1],t[7]=l[2],t[8]=l[3],t[9]=l[4]}static hash(t,s){let e,i=t[0],o=t[1],r=t[2],h=t[3],n=t[4],l=t[5],d=t[6],_=t[7],y=t[8],P=t[9],g=0,m=0;for(;g<16;g++)e=n+a.lRot(i+f[m](o,r,h)+s[c[g]]+p[m],b[g]),i=n,n=h,h=a.lRot(r,10),r=o,o=e,e=P+a.lRot(l+f[4-m](d,_,y)+s[R[g]]+u[m],w[g]),l=P,P=y,y=a.lRot(_,10),_=d,d=e;for(e=o,o=d,d=e,m=1;g<32;g++)e=n+a.lRot(i+f[m](o,r,h)+s[c[g]]+p[m],b[g]),i=n,n=h,h=a.lRot(r,10),r=o,o=e,e=P+a.lRot(l+f[4-m](d,_,y)+s[R[g]]+u[m],w[g]),l=P,P=y,y=a.lRot(_,10),_=d,d=e;for(e=h,h=y,y=e,m=2;g<48;g++)e=n+a.lRot(i+f[m](o,r,h)+s[c[g]]+p[m],b[g]),i=n,n=h,h=a.lRot(r,10),r=o,o=e,e=P+a.lRot(l+f[4-m](d,_,y)+s[R[g]]+u[m],w[g]),l=P,P=y,y=a.lRot(_,10),_=d,d=e;for(e=i,i=l,l=e,m=3;g<64;g++)e=n+a.lRot(i+f[m](o,r,h)+s[c[g]]+p[m],b[g]),i=n,n=h,h=a.lRot(r,10),r=o,o=e,e=P+a.lRot(l+f[4-m](d,_,y)+s[R[g]]+u[m],w[g]),l=P,P=y,y=a.lRot(_,10),_=d,d=e;for(e=r,r=_,_=e,m=4;g<80;g++)e=n+a.lRot(i+f[m](o,r,h)+s[c[g]]+p[m],b[g]),i=n,n=h,h=a.lRot(r,10),r=o,o=e,e=P+a.lRot(l+f[4-m](d,_,y)+s[R[g]]+u[m],w[g]),l=P,P=y,y=a.lRot(_,10),_=d,d=e;e=n,n=P,P=e,t[0]+=i,t[1]+=o,t[2]+=r,t[3]+=h,t[4]+=n,t[5]+=l,t[6]+=d,t[7]+=_,t[8]+=y,t[9]+=P}get[Symbol.toStringTag](){return"RIPEMD-320"}}