@protontech/openpgp
Version:
OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.
5 lines (4 loc) • 6.72 kB
JavaScript
/*! OpenPGP.js v6.1.1-patch.4 - 2025-07-14 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
const t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){if(!Number.isSafeInteger(t)||t<0)throw Error("positive integer expected, got "+t)}function n(t,...e){if(!((n=t)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw Error("Uint8Array expected");var n;if(e.length>0&&!e.includes(t.length))throw Error("Uint8Array expected of length "+e+", got length="+t.length)}function s(t){if("function"!=typeof t||"function"!=typeof t.create)throw Error("Hash should be wrapped by utils.wrapConstructor");e(t.outputLen),e(t.blockLen)}function o(t,e=!0){if(t.destroyed)throw Error("Hash instance has been destroyed");if(e&&t.finished)throw Error("Hash#digest() has already been called")}function r(t,e){n(t);const s=e.outputLen;if(t.length<s)throw Error("digestInto() expects output buffer of length at least "+s)}const i="object"==typeof t&&"crypto"in t?t.crypto:void 0,h=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),a=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),f=(t,e)=>t<<32-e|t>>>e,u=(t,e)=>t<<e|t>>>32-e>>>0,c=/* @__PURE__ */(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function l(t){for(let n=0;n<t.length;n++)t[n]=(e=t[n])<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;var e}function d(t){if("string"!=typeof t)throw Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}function p(t){return"string"==typeof t&&(t=d(t)),n(t),t}function g(...t){let e=0;for(let s=0;s<t.length;s++){const o=t[s];n(o),e+=o.length}const s=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const o=t[e];s.set(o,n),n+=o.length}return s}class y{clone(){return this._cloneInto()}}function w(t){const e=e=>t().update(p(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function b(t=32){if(i&&"function"==typeof i.getRandomValues)return i.getRandomValues(new Uint8Array(t));if(i&&"function"==typeof i.randomBytes)return i.randomBytes(t);throw Error("crypto.getRandomValues must be defined")}const L=/* @__PURE__ */BigInt(2**32-1),k=/* @__PURE__ */BigInt(32);function I(t,e=!1){return e?{h:Number(t&L),l:Number(t>>k&L)}:{h:0|Number(t>>k&L),l:0|Number(t&L)}}function B(t,e=!1){let n=new Uint32Array(t.length),s=new Uint32Array(t.length);for(let o=0;o<t.length;o++){const{h:r,l:i}=I(t[o],e);[n[o],s[o]]=[r,i]}return[n,s]}const A=(t,e,n)=>t<<n|e>>>32-n,m=(t,e,n)=>e<<n|t>>>32-n,O=(t,e,n)=>e<<n-32|t>>>64-n,U=(t,e,n)=>t<<n-32|e>>>64-n;const x={fromBig:I,split:B,toBig:(t,e)=>BigInt(t>>>0)<<k|BigInt(e>>>0),shrSH:(t,e,n)=>t>>>n,shrSL:(t,e,n)=>t<<32-n|e>>>n,rotrSH:(t,e,n)=>t>>>n|e<<32-n,rotrSL:(t,e,n)=>t<<32-n|e>>>n,rotrBH:(t,e,n)=>t<<64-n|e>>>n-32,rotrBL:(t,e,n)=>t>>>n-32|e<<64-n,rotr32H:(t,e)=>e,rotr32L:(t,e)=>t,rotlSH:A,rotlSL:m,rotlBH:O,rotlBL:U,add:function(t,e,n,s){const o=(e>>>0)+(s>>>0);return{h:t+n+(o/2**32|0)|0,l:0|o}},add3L:(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),add3H:(t,e,n,s)=>e+n+s+(t/2**32|0)|0,add4L:(t,e,n,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),add4H:(t,e,n,s,o)=>e+n+s+o+(t/2**32|0)|0,add5H:(t,e,n,s,o,r)=>e+n+s+o+r+(t/2**32|0)|0,add5L:(t,e,n,s,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0)+(o>>>0)},E=[],H=[],S=[],v=/* @__PURE__ */BigInt(0),F=/* @__PURE__ */BigInt(1),N=/* @__PURE__ */BigInt(2),V=/* @__PURE__ */BigInt(7),X=/* @__PURE__ */BigInt(256),M=/* @__PURE__ */BigInt(113);for(let t=0,e=F,n=1,s=0;t<24;t++){[n,s]=[s,(2*n+3*s)%5],E.push(2*(5*s+n)),H.push((t+1)*(t+2)/2%64);let o=v;for(let t=0;t<7;t++)e=(e<<F^(e>>V)*M)%X,e&N&&(o^=F<<(F<</* @__PURE__ */BigInt(t))-F);S.push(o)}const[R,j]=/* @__PURE__ */B(S,!0),T=(t,e,n)=>n>32?O(t,e,n):A(t,e,n),_=(t,e,n)=>n>32?U(t,e,n):m(t,e,n);class C extends y{constructor(t,n,s,o=!1,r=24){if(super(),this.blockLen=t,this.suffix=n,this.outputLen=s,this.enableXOF=o,this.rounds=r,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,e(s),0>=this.blockLen||this.blockLen>=200)throw Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=h(this.state)}keccak(){c||l(this.state32),function(t,e=24){const n=new Uint32Array(10);for(let s=24-e;s<24;s++){for(let e=0;e<10;e++)n[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const s=(e+8)%10,o=(e+2)%10,r=n[o],i=n[o+1],h=T(r,i,1)^n[s],a=_(r,i,1)^n[s+1];for(let n=0;n<50;n+=10)t[e+n]^=h,t[e+n+1]^=a}let e=t[2],o=t[3];for(let n=0;n<24;n++){const s=H[n],r=T(e,o,s),i=_(e,o,s),h=E[n];e=t[h],o=t[h+1],t[h]=r,t[h+1]=i}for(let e=0;e<50;e+=10){for(let s=0;s<10;s++)n[s]=t[e+s];for(let s=0;s<10;s++)t[e+s]^=~n[(s+2)%10]&n[(s+4)%10]}t[0]^=R[s],t[1]^=j[s]}n.fill(0)}(this.state32,this.rounds),c||l(this.state32),this.posOut=0,this.pos=0}update(t){o(this);const{blockLen:e,state:n}=this,s=(t=p(t)).length;for(let o=0;o<s;){const r=Math.min(e-this.pos,s-o);for(let e=0;e<r;e++)n[this.pos++]^=t[o++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:e,pos:n,blockLen:s}=this;t[n]^=e,128&e&&n===s-1&&this.keccak(),t[s-1]^=128,this.keccak()}writeInto(t){o(this,!1),n(t),this.finish();const e=this.state,{blockLen:s}=this;for(let n=0,o=t.length;n<o;){this.posOut>=s&&this.keccak();const r=Math.min(s-this.posOut,o-n);t.set(e.subarray(this.posOut,this.posOut+r),n),this.posOut+=r,n+=r}return t}xofInto(t){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return e(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(r(t,this),this.finished)throw Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:e,suffix:n,outputLen:s,rounds:o,enableXOF:r}=this;return t||(t=new C(e,n,s,r,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=n,t.outputLen=s,t.enableXOF=r,t.destroyed=this.destroyed,t}}const D=(t,e,n)=>w((()=>new C(e,t,n))),q=/* @__PURE__ */D(6,136,32),z=/* @__PURE__ */D(6,72,64),G=(t,e,n)=>function(t){const e=(e,n)=>t(n).update(p(e)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=e=>t(e),e}(((s={})=>new C(e,t,void 0===s.dkLen?n:s.dkLen,!0))),J=/* @__PURE__ */G(31,168,16),K=/* @__PURE__ */G(31,136,32);export{y as H,s as a,o as b,n as c,g as d,u as e,q as f,z as g,a as h,r as i,f as j,x as k,J as l,h as m,b as r,K as s,p as t,d as u,w};
//# sourceMappingURL=sha3.min.mjs.map