gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 2.3 kB
JavaScript
/*! Copyright 2023-2025 the gnablib contributors MPL-1.1 */
var t,e=this&&this.__classPrivateFieldSet||function(t,e,r,o,s){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?s.call(t,r):s?s.value=r:e.set(t,r),r},r=this&&this.__classPrivateFieldGet||function(t,e,r,o){if("a"===r&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?o:"a"===r?o.call(t):o?o.value:e.get(t)};import{U32 as o}from"../../primitive/number/U32Static.js";import{sLen as s}from"../../safe/safe.js";const i=t=>o.lRot(t,1)&o.lRot(t,8)^o.lRot(t,2),n=4294967292;class a{constructor(r,o){this.blockSize=8,t.set(this,void 0),this.rounds=r,e(this,t,o,"f")}_encBlock(e){const o=new Uint32Array(e.buffer,e.byteOffset,2);for(let e=0;e<this.rounds;)o[0]^=i(o[1])^r(this,t,"f")[e++],o[1]^=i(o[0])^r(this,t,"f")[e++]}_decBlock(e){const o=new Uint32Array(e.buffer,e.byteOffset,2);for(let e=this.rounds-1;e>=0;)o[1]^=i(o[0])^r(this,t,"f")[e--],o[0]^=i(o[1])^r(this,t,"f")[e--]}encryptBlock(t,e=0){const r=8*e;s("block",t).atLeast(r+8).throwNot(),this._encBlock(t.subarray(r,r+8))}decryptBlock(t,e=0){const r=8*e;s("block",t).atLeast(r+8).throwNot(),this._decBlock(t.subarray(r,r+8))}}t=new WeakMap;export class Simon64_96 extends a{constructor(t){const e=new Uint32Array(t.buffer,t.byteOffset,t.length/4).slice(),r=new Uint32Array(42);r.set(e);let s=422317813,i=3;for(;i<35;i++)r[i]=n^1&s^r[i-3]^o.rRot(r[i-1],3)^o.rRot(r[i-1],4),s>>>=1;for(s=1936324741;i<42;i++)r[i]=n^1&s^r[i-3]^o.rRot(r[i-1],3)^o.rRot(r[i-1],4),s>>>=1;super(42,r)}}export class Simon64_128 extends a{constructor(t){const e=new Uint32Array(t.buffer,t.byteOffset,t.length/4).slice(),r=new Uint32Array(44);r.set(e);let s=128333275,i=4;for(;i<36;i++)r[i]=n^1&s^r[i-4]^o.rRot(r[i-1],3)^r[i-3]^o.rRot(r[i-1],4)^o.rRot(r[i-3],1),s>>>=1;for(s=4230800658;i<44;i++)r[i]=n^1&s^r[i-4]^o.rRot(r[i-1],3)^r[i-3]^o.rRot(r[i-1],4)^o.rRot(r[i-3],1),s>>>=1;super(44,r)}}