UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 8.63 kB
/*! Copyright 2025 the gnablib contributors MPL-1.1 */ var t,o,r=this&&this.__classPrivateFieldSet||function(t,o,r,e,s){if("m"===e)throw new TypeError("Private method is not writable");if("a"===e&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof o?t!==o||!s:!o.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===e?s.call(t,r):s?s.value=r:o.set(t,r),r},e=this&&this.__classPrivateFieldGet||function(t,o,r,e){if("a"===r&&!e)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof o?t!==o||!e:!o.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?e:"a"===r?e.call(t):e?e.value:o.get(t)};import{U128 as s,U128Mut as a}from"../../primitive/number/U128.js";import{sLen as i}from"../../safe/safe.js";const n=16,c=[Uint8Array.of(99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22),Uint8Array.of(226,78,84,252,148,194,74,204,98,13,106,70,60,77,139,209,94,250,100,203,180,151,190,43,188,119,46,3,211,25,89,193,29,6,65,107,85,240,153,105,234,156,24,174,99,223,231,187,0,115,102,251,150,76,133,228,58,9,69,170,15,238,16,235,45,127,244,41,172,207,173,145,141,120,200,149,249,47,206,205,8,122,136,56,92,131,42,40,71,219,184,199,147,164,18,83,255,135,14,49,54,33,88,72,1,142,55,116,50,202,233,177,183,171,12,215,196,86,66,38,7,152,96,217,182,185,17,64,236,32,140,189,160,201,132,4,73,35,241,79,80,31,19,220,216,192,158,87,227,195,123,101,59,2,143,62,232,37,146,229,21,221,253,23,169,191,212,154,126,197,57,103,254,118,157,67,167,225,208,245,104,242,27,52,112,5,163,138,213,121,134,168,48,198,81,75,30,166,39,246,53,210,110,36,22,130,95,218,230,117,162,239,44,178,28,159,93,111,128,10,114,68,155,108,144,11,91,51,125,90,82,243,97,161,247,176,214,63,124,109,237,20,224,165,61,34,179,248,137,222,113,26,175,186,181,129),Uint8Array.of(82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125),Uint8Array.of(48,104,153,27,135,185,33,120,80,57,219,225,114,9,98,60,62,126,94,142,241,160,204,163,42,29,251,182,214,32,196,141,129,101,245,137,203,157,119,198,87,67,86,23,212,64,26,77,192,99,108,227,183,200,100,106,83,170,56,152,12,244,155,237,127,34,118,175,221,58,11,88,103,136,6,195,53,13,1,139,140,194,230,95,2,36,117,147,102,30,229,226,84,216,16,206,122,232,8,44,18,151,50,171,180,39,10,35,223,239,202,217,184,250,220,49,107,209,173,25,73,189,81,150,238,228,168,65,218,255,205,85,134,54,190,97,82,248,187,14,130,72,105,154,224,71,158,92,4,75,52,21,121,38,167,222,41,174,146,215,132,233,210,186,93,243,197,176,191,164,59,113,68,70,43,252,235,111,213,246,20,254,124,112,90,125,253,47,24,131,22,165,145,31,5,149,116,169,193,91,74,133,109,19,7,79,78,69,178,15,201,28,166,188,236,115,144,123,207,89,143,161,249,45,242,177,0,148,55,159,208,46,156,110,40,63,128,240,61,211,37,138,181,231,66,179,199,234,247,76,17,51,3,162,172,96)],u=new Uint8Array(16);function f(t){u[0]=t[3]^t[4]^t[6]^t[8]^t[9]^t[13]^t[14],u[1]=t[2]^t[5]^t[7]^t[8]^t[9]^t[12]^t[15],u[2]=t[1]^t[4]^t[6]^t[10]^t[11]^t[12]^t[15],u[3]=t[0]^t[5]^t[7]^t[10]^t[11]^t[13]^t[14],u[4]=t[0]^t[2]^t[5]^t[8]^t[11]^t[14]^t[15],u[5]=t[1]^t[3]^t[4]^t[9]^t[10]^t[14]^t[15],u[6]=t[0]^t[2]^t[7]^t[9]^t[10]^t[12]^t[13],u[7]=t[1]^t[3]^t[6]^t[8]^t[11]^t[12]^t[13],u[8]=t[0]^t[1]^t[4]^t[7]^t[10]^t[13]^t[15],u[9]=t[0]^t[1]^t[5]^t[6]^t[11]^t[12]^t[14],u[10]=t[2]^t[3]^t[5]^t[6]^t[8]^t[13]^t[15],u[11]=t[2]^t[3]^t[4]^t[7]^t[9]^t[12]^t[14],u[12]=t[1]^t[2]^t[6]^t[7]^t[9]^t[11]^t[12],u[13]=t[0]^t[3]^t[6]^t[7]^t[8]^t[10]^t[13],u[14]=t[0]^t[3]^t[4]^t[5]^t[9]^t[11]^t[14],u[15]=t[1]^t[2]^t[4]^t[5]^t[8]^t[10]^t[15],t.set(u)}function y(t){t[0]=c[2][t[0]],t[1]=c[3][t[1]],t[2]=c[0][t[2]],t[3]=c[1][t[3]],t[4]=c[2][t[4]],t[5]=c[3][t[5]],t[6]=c[0][t[6]],t[7]=c[1][t[7]],t[8]=c[2][t[8]],t[9]=c[3][t[9]],t[10]=c[0][t[10]],t[11]=c[1][t[11]],t[12]=c[2][t[12]],t[13]=c[3][t[13]],t[14]=c[0][t[14]],t[15]=c[1][t[15]]}function B(t,o){for(let r=0;r<16;r++)t[r]^=o[r];!function(t){t[0]=c[0][t[0]],t[1]=c[1][t[1]],t[2]=c[2][t[2]],t[3]=c[3][t[3]],t[4]=c[0][t[4]],t[5]=c[1][t[5]],t[6]=c[2][t[6]],t[7]=c[3][t[7]],t[8]=c[0][t[8]],t[9]=c[1][t[9]],t[10]=c[2][t[10]],t[11]=c[3][t[11]],t[12]=c[0][t[12]],t[13]=c[1][t[13]],t[14]=c[2][t[14]],t[15]=c[3][t[15]]}(t),f(t)}function l(t,o){for(let r=0;r<16;r++)t[r]^=o[r];y(t),f(t)}const E=Uint8Array.of(81,124,193,183,39,34,10,148,254,19,171,232,250,154,110,224),h=Uint8Array.of(109,177,74,204,158,33,200,32,255,40,177,213,239,93,226,176),m=Uint8Array.of(219,146,55,29,33,38,233,112,3,36,151,117,4,232,201,14);class d{constructor(e,i,c,u,y){this.blockSize=n,t.set(this,void 0),o.set(this,void 0);const E=s.fromBytesBE(i),h=i.slice(0,16);B(h,c);for(let t=0;t<16;t++)h[t]^=i[t+16];const m=s.fromBytesBE(h),d=m.toBytesBE();l(d,u);const w=a.fromBytesBE(d).xorEq(E),x=w.toBytesBE();B(x,y);const p=a.fromBytesBE(x).xorEq(m),b=new Uint8Array(272);b.set(E.mut().xorEq(m.rRot(19)).toBytesBE(),0),b.set(m.mut().xorEq(w.rRot(19)).toBytesBE(),16),b.set(w.mut().xorEq(p.rRot(19)).toBytesBE(),32),b.set(p.mut().xorEq(E.rRot(19)).toBytesBE(),48),b.set(E.mut().xorEq(m.rRot(31)).toBytesBE(),64),b.set(m.mut().xorEq(w.rRot(31)).toBytesBE(),80),b.set(w.mut().xorEq(p.rRot(31)).toBytesBE(),96),b.set(p.mut().xorEq(E.rRot(31)).toBytesBE(),112),b.set(E.mut().xorEq(m.lRot(61)).toBytesBE(),128),b.set(m.mut().xorEq(w.lRot(61)).toBytesBE(),144),b.set(w.mut().xorEq(p.lRot(61)).toBytesBE(),160),b.set(p.mut().xorEq(E.lRot(61)).toBytesBE(),176),b.set(E.mut().xorEq(m.lRot(31)).toBytesBE(),192),b.set(m.mut().xorEq(w.lRot(31)).toBytesBE(),208),b.set(w.mut().xorEq(p.lRot(31)).toBytesBE(),224),b.set(p.mut().xorEq(E.lRot(31)).toBytesBE(),240),b.set(E.mut().xorEq(m.lRot(19)).toBytesBE(),256);const q=new Uint8Array(272);q.set(b.subarray(16*e,16*(e+1)));for(let t=e-1;t>0;t--)q.set(b.subarray(16*t,16*(t+1)),16*(e-t)),f(q.subarray(16*(e-t)));q.set(b.subarray(0,16),16*e),this.rounds=e,r(this,t,b,"f"),r(this,o,q,"f")}_encBlock(o){let r=0;const s=this.rounds-2;do{B(o,e(this,t,"f").subarray(16*r++)),l(o,e(this,t,"f").subarray(16*r++))}while(r<s);B(o,e(this,t,"f").subarray(16*r++));for(let s=0;s<16;s++)o[s]^=e(this,t,"f")[16*r+s];y(o),r++;for(let s=0;s<16;s++)o[s]^=e(this,t,"f")[16*r+s]}_decBlock(t){let r=0;const s=this.rounds-2;do{B(t,e(this,o,"f").subarray(16*r++)),l(t,e(this,o,"f").subarray(16*r++))}while(r<s);B(t,e(this,o,"f").subarray(16*r++));for(let s=0;s<16;s++)t[s]^=e(this,o,"f")[16*r+s];y(t),r++;for(let s=0;s<16;s++)t[s]^=e(this,o,"f")[16*r+s]}decryptBlock(t,o=0){const r=o*n;i("block",t).atLeast(r+n).throwNot(),this._decBlock(t.subarray(r,r+n))}encryptBlock(t,o=0){const r=o*n;i("block",t).atLeast(r+n).throwNot(),this._encBlock(t.subarray(r,r+n))}}t=new WeakMap,o=new WeakMap;export class Aria128 extends d{constructor(t){super(12,t,E,h,m)}}export class Aria192 extends d{constructor(t){super(14,t,h,m,E)}}export class Aria256 extends d{constructor(t){super(16,t,m,E,h)}}