gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 2.14 kB
JavaScript
/*! Copyright 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";class i{constructor(r,o){this.blockSize=8,t.set(this,void 0),this.rounds=r,e(this,t,o,"f")}_encBlock(e){const s=new Uint32Array(e.buffer,e.byteOffset,2);for(let e=0;e<this.rounds;)s[1]=o.rRot(s[1],8)+s[0]^r(this,t,"f")[e++],s[0]=o.lRot(s[0],3)^s[1]}_decBlock(e){const s=new Uint32Array(e.buffer,e.byteOffset,2);for(let e=this.rounds-1;e>=0;)s[0]=o.rRot(s[0]^s[1],3),s[1]=o.lRot((s[1]^r(this,t,"f")[e--])-s[0],8)}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 Speck64_96 extends i{constructor(t){const e=new Uint32Array(t.buffer,t.byteOffset,t.length/4).slice(),r=new Uint32Array(26);let s=e[0],i=e[1],n=e[2];for(let t=0;t<26;)r[t]=s,i=o.rRot(i,8)+s^t,s=o.lRot(s,3)^i,t++,r[t]=s,n=o.rRot(n,8)+s^t,s=o.lRot(s,3)^n,t++;super(26,r)}}export class Speck64_128 extends i{constructor(t){const e=new Uint32Array(t.buffer,t.byteOffset,t.length/4).slice(),r=new Uint32Array(27);let s=e[0],i=e[1],n=e[2],a=e[3];for(let t=0;t<27;)r[t]=s,i=o.rRot(i,8)+s^t,s=o.lRot(s,3)^i,t++,r[t]=s,n=o.rRot(n,8)+s^t,s=o.lRot(s,3)^n,t++,r[t]=s,a=o.rRot(a,8)+s^t,s=o.lRot(s,3)^a,t++;super(27,r)}}