UNPKG

gnablib

Version:

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

2 lines 891 B
/*! Copyright 2023-2025 the gnablib contributors MPL-1.1 */ import{toGlScaleBytes as t}from"./number/xtUint.js";export function toGlBytes(e){const n=t(e.length),r=new Uint8Array(n.length+e.length);return r.set(n),r.set(e,n.length),r}export function ctEq(t,e){if(t.length!=e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return 0===n}export function ctSelect(t,e,n){if(t.length!=e.length)throw new Error("Inputs are of different length");const r=(0|n)-1,l=new Uint8Array(t.length);for(let n=0;n<t.length;n++)l[n]=~r&t[n]|r&e[n];return l}export function incrBE(t){let e=t.length-1;for(;t[e]+=1,0==t[e]&&t.length>1;)e=(e-1)%t.length}export function lShiftEq(t,e){const n=0|e/8,r=e%8,l=8-r,o=t.length-n;let h=0;for(;h<o;h++)t[h]=t[h+n]<<r|t[h+n+1]>>>l;for(;h<t.length;h++)t[h]=0}export function xorEq(t,e){let n=t.length;e.length<n&&(n=e.length);for(let r=0;r<n;r++)t[r]^=e[r]}