UNPKG

openpgp

Version:

OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.

6 lines (5 loc) 16.1 kB
/*! OpenPGP.js v6.2.1 - 2025-08-26 - 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:{},e="object"==typeof t&&"crypto"in t?t.crypto:void 0; /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ function s(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name}function i(t){if(!Number.isSafeInteger(t)||t<0)throw Error("positive integer expected, got "+t)}function n(t,...e){if(!s(t))throw Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw Error("Uint8Array expected of length "+e+", got length="+t.length)}function r(t){if("function"!=typeof t||"function"!=typeof t.create)throw Error("Hash should be wrapped by utils.createHasher");i(t.outputLen),i(t.blockLen)}function h(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 o(t,e){n(t);const s=e.outputLen;if(t.length<s)throw Error("digestInto() expects output buffer of length at least "+s)}function c(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function f(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function a(t,e){return t<<32-e|t>>>e}function l(t,e){return t<<e|t>>>32-e>>>0}const u=/* @__PURE__ */(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?t=>t:function(t){for(let s=0;s<t.length;s++)t[s]=(e=t[s])<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;var e;return t},d=/* @__PURE__ */(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),b=/* @__PURE__ */Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function x(t){if(n(t),d)return t.toHex();let e="";for(let s=0;s<t.length;s++)e+=b[t[s]];return e}const p=48,g=57,y=65,w=70,A=97,E=102;function U(t){return t>=p&&t<=g?t-p:t>=y&&t<=w?t-(y-10):t>=A&&t<=E?t-(A-10):void 0}function B(t){if("string"!=typeof t)throw Error("hex string expected, got "+typeof t);if(d)return Uint8Array.fromHex(t);const e=t.length,s=e/2;if(e%2)throw Error("hex string expected, got unpadded hex of length "+e);const i=new Uint8Array(s);for(let e=0,n=0;e<s;e++,n+=2){const s=U(t.charCodeAt(n)),r=U(t.charCodeAt(n+1));if(void 0===s||void 0===r){const e=t[n]+t[n+1];throw Error('hex string expected, got non-hex character "'+e+'" at index '+n)}i[e]=16*s+r}return i}function L(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t)),n(t),t}function k(...t){let e=0;for(let s=0;s<t.length;s++){const i=t[s];n(i),e+=i.length}const s=new Uint8Array(e);for(let e=0,i=0;e<t.length;e++){const n=t[e];s.set(n,i),i+=n.length}return s}class m{}function I(t){const e=e=>t().update(L(e)).digest(),s=t();return e.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=()=>t(),e}const H=I;function C(t=32){if(e&&"function"==typeof e.getRandomValues)return e.getRandomValues(new Uint8Array(t));if(e&&"function"==typeof e.randomBytes)return Uint8Array.from(e.randomBytes(t));throw Error("crypto.getRandomValues must be defined")}function F(t,e,s){return t&e^~t&s}function D(t,e,s){return t&e^t&s^e&s}class O extends m{constructor(t,e,s,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=s,this.isLE=i,this.buffer=new Uint8Array(t),this.view=f(this.buffer)}update(t){h(this),n(t=L(t));const{view:e,buffer:s,blockLen:i}=this,r=t.length;for(let n=0;n<r;){const h=Math.min(i-this.pos,r-n);if(h!==i)s.set(t.subarray(n,n+h),this.pos),this.pos+=h,n+=h,this.pos===i&&(this.process(e,0),this.pos=0);else{const e=f(t);for(;i<=r-n;n+=i)this.process(e,n)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){h(this),o(t,this),this.finished=!0;const{buffer:e,view:s,blockLen:i,isLE:n}=this;let{pos:r}=this;e[r++]=128,c(this.buffer.subarray(r)),this.padOffset>i-r&&(this.process(s,0),r=0);for(let t=r;t<i;t++)e[t]=0;!function(t,e,s,i){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,s,i);const n=BigInt(32),r=BigInt(4294967295),h=Number(s>>n&r),o=Number(s&r),c=i?4:0,f=i?0:4;t.setUint32(e+c,h,i),t.setUint32(e+f,o,i)}(s,i-8,BigInt(8*this.length),n),this.process(s,0);const a=f(t),l=this.outputLen;if(l%4)throw Error("_sha2: outputLen should be aligned to 32bit");const u=l/4,d=this.get();if(u>d.length)throw Error("_sha2: outputLen bigger than state");for(let t=0;t<u;t++)a.setUint32(4*t,d[t],n)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const s=t.slice(0,e);return this.destroy(),s}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:s,length:i,finished:n,destroyed:r,pos:h}=this;return t.destroyed=r,t.finished=n,t.length=i,t.pos=h,i%e&&t.buffer.set(s),t}clone(){return this._cloneInto()}}const G=/* @__PURE__ */Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),v=/* @__PURE__ */Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),N=/* @__PURE__ */Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),X=/* @__PURE__ */Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),_=/* @__PURE__ */BigInt(2**32-1),M=/* @__PURE__ */BigInt(32);function V(t,e=!1){return e?{h:Number(t&_),l:Number(t>>M&_)}:{h:0|Number(t>>M&_),l:0|Number(t&_)}}function R(t,e=!1){const s=t.length;let i=new Uint32Array(s),n=new Uint32Array(s);for(let r=0;r<s;r++){const{h:s,l:h}=V(t[r],e);[i[r],n[r]]=[s,h]}return[i,n]}const S=(t,e,s)=>t>>>s,j=(t,e,s)=>t<<32-s|e>>>s,q=(t,e,s)=>t>>>s|e<<32-s,T=(t,e,s)=>t<<32-s|e>>>s,z=(t,e,s)=>t<<64-s|e>>>s-32,J=(t,e,s)=>t>>>s-32|e<<64-s;function K(t,e,s,i){const n=(e>>>0)+(i>>>0);return{h:t+s+(n/2**32|0)|0,l:0|n}}const P=(t,e,s)=>(t>>>0)+(e>>>0)+(s>>>0),Q=(t,e,s,i)=>e+s+i+(t/2**32|0)|0,W=(t,e,s,i)=>(t>>>0)+(e>>>0)+(s>>>0)+(i>>>0),Y=(t,e,s,i,n)=>e+s+i+n+(t/2**32|0)|0,Z=(t,e,s,i,n)=>(t>>>0)+(e>>>0)+(s>>>0)+(i>>>0)+(n>>>0),$=(t,e,s,i,n,r)=>e+s+i+n+r+(t/2**32|0)|0,tt=/* @__PURE__ */Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),et=/* @__PURE__ */new Uint32Array(64);class st extends O{constructor(t=32){super(64,t,8,!1),this.A=0|G[0],this.B=0|G[1],this.C=0|G[2],this.D=0|G[3],this.E=0|G[4],this.F=0|G[5],this.G=0|G[6],this.H=0|G[7]}get(){const{A:t,B:e,C:s,D:i,E:n,F:r,G:h,H:o}=this;return[t,e,s,i,n,r,h,o]}set(t,e,s,i,n,r,h,o){this.A=0|t,this.B=0|e,this.C=0|s,this.D=0|i,this.E=0|n,this.F=0|r,this.G=0|h,this.H=0|o}process(t,e){for(let s=0;s<16;s++,e+=4)et[s]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=et[t-15],s=et[t-2],i=a(e,7)^a(e,18)^e>>>3,n=a(s,17)^a(s,19)^s>>>10;et[t]=n+et[t-7]+i+et[t-16]|0}let{A:s,B:i,C:n,D:r,E:h,F:o,G:c,H:f}=this;for(let t=0;t<64;t++){const e=f+(a(h,6)^a(h,11)^a(h,25))+F(h,o,c)+tt[t]+et[t]|0,l=(a(s,2)^a(s,13)^a(s,22))+D(s,i,n)|0;f=c,c=o,o=h,h=r+e|0,r=n,n=i,i=s,s=e+l|0}s=s+this.A|0,i=i+this.B|0,n=n+this.C|0,r=r+this.D|0,h=h+this.E|0,o=o+this.F|0,c=c+this.G|0,f=f+this.H|0,this.set(s,i,n,r,h,o,c,f)}roundClean(){c(et)}destroy(){this.set(0,0,0,0,0,0,0,0),c(this.buffer)}}class it extends st{constructor(){super(28),this.A=0|v[0],this.B=0|v[1],this.C=0|v[2],this.D=0|v[3],this.E=0|v[4],this.F=0|v[5],this.G=0|v[6],this.H=0|v[7]}}const nt=/* @__PURE__ */(()=>R(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((t=>BigInt(t)))))(),rt=/* @__PURE__ */(()=>nt[0])(),ht=/* @__PURE__ */(()=>nt[1])(),ot=/* @__PURE__ */new Uint32Array(80),ct=/* @__PURE__ */new Uint32Array(80);class ft extends O{constructor(t=64){super(128,t,16,!1),this.Ah=0|X[0],this.Al=0|X[1],this.Bh=0|X[2],this.Bl=0|X[3],this.Ch=0|X[4],this.Cl=0|X[5],this.Dh=0|X[6],this.Dl=0|X[7],this.Eh=0|X[8],this.El=0|X[9],this.Fh=0|X[10],this.Fl=0|X[11],this.Gh=0|X[12],this.Gl=0|X[13],this.Hh=0|X[14],this.Hl=0|X[15]}get(){const{Ah:t,Al:e,Bh:s,Bl:i,Ch:n,Cl:r,Dh:h,Dl:o,Eh:c,El:f,Fh:a,Fl:l,Gh:u,Gl:d,Hh:b,Hl:x}=this;return[t,e,s,i,n,r,h,o,c,f,a,l,u,d,b,x]}set(t,e,s,i,n,r,h,o,c,f,a,l,u,d,b,x){this.Ah=0|t,this.Al=0|e,this.Bh=0|s,this.Bl=0|i,this.Ch=0|n,this.Cl=0|r,this.Dh=0|h,this.Dl=0|o,this.Eh=0|c,this.El=0|f,this.Fh=0|a,this.Fl=0|l,this.Gh=0|u,this.Gl=0|d,this.Hh=0|b,this.Hl=0|x}process(t,e){for(let s=0;s<16;s++,e+=4)ot[s]=t.getUint32(e),ct[s]=t.getUint32(e+=4);for(let t=16;t<80;t++){const e=0|ot[t-15],s=0|ct[t-15],i=q(e,s,1)^q(e,s,8)^S(e,0,7),n=T(e,s,1)^T(e,s,8)^j(e,s,7),r=0|ot[t-2],h=0|ct[t-2],o=q(r,h,19)^z(r,h,61)^S(r,0,6),c=T(r,h,19)^J(r,h,61)^j(r,h,6),f=W(n,c,ct[t-7],ct[t-16]),a=Y(f,i,o,ot[t-7],ot[t-16]);ot[t]=0|a,ct[t]=0|f}let{Ah:s,Al:i,Bh:n,Bl:r,Ch:h,Cl:o,Dh:c,Dl:f,Eh:a,El:l,Fh:u,Fl:d,Gh:b,Gl:x,Hh:p,Hl:g}=this;for(let t=0;t<80;t++){const e=q(a,l,14)^q(a,l,18)^z(a,l,41),y=T(a,l,14)^T(a,l,18)^J(a,l,41),w=a&u^~a&b,A=Z(g,y,l&d^~l&x,ht[t],ct[t]),E=$(A,p,e,w,rt[t],ot[t]),U=0|A,B=q(s,i,28)^z(s,i,34)^z(s,i,39),L=T(s,i,28)^J(s,i,34)^J(s,i,39),k=s&n^s&h^n&h,m=i&r^i&o^r&o;p=0|b,g=0|x,b=0|u,x=0|d,u=0|a,d=0|l,({h:a,l}=K(0|c,0|f,0|E,0|U)),c=0|h,f=0|o,h=0|n,o=0|r,n=0|s,r=0|i;const I=P(U,L,m);s=Q(I,E,B,k),i=0|I}({h:s,l:i}=K(0|this.Ah,0|this.Al,0|s,0|i)),({h:n,l:r}=K(0|this.Bh,0|this.Bl,0|n,0|r)),({h,l:o}=K(0|this.Ch,0|this.Cl,0|h,0|o)),({h:c,l:f}=K(0|this.Dh,0|this.Dl,0|c,0|f)),({h:a,l}=K(0|this.Eh,0|this.El,0|a,0|l)),({h:u,l:d}=K(0|this.Fh,0|this.Fl,0|u,0|d)),({h:b,l:x}=K(0|this.Gh,0|this.Gl,0|b,0|x)),({h:p,l:g}=K(0|this.Hh,0|this.Hl,0|p,0|g)),this.set(s,i,n,r,h,o,c,f,a,l,u,d,b,x,p,g)}roundClean(){c(ot,ct)}destroy(){c(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class at extends ft{constructor(){super(48),this.Ah=0|N[0],this.Al=0|N[1],this.Bh=0|N[2],this.Bl=0|N[3],this.Ch=0|N[4],this.Cl=0|N[5],this.Dh=0|N[6],this.Dl=0|N[7],this.Eh=0|N[8],this.El=0|N[9],this.Fh=0|N[10],this.Fl=0|N[11],this.Gh=0|N[12],this.Gl=0|N[13],this.Hh=0|N[14],this.Hl=0|N[15]}}const lt=/* @__PURE__ */I((()=>new st)),ut=/* @__PURE__ */I((()=>new it)),dt=/* @__PURE__ */I((()=>new ft)),bt=/* @__PURE__ */I((()=>new at)),xt=BigInt(0),pt=BigInt(1),gt=BigInt(2),yt=BigInt(7),wt=BigInt(256),At=BigInt(113),Et=[],Ut=[],Bt=[];for(let t=0,e=pt,s=1,i=0;t<24;t++){[s,i]=[i,(2*s+3*i)%5],Et.push(2*(5*i+s)),Ut.push((t+1)*(t+2)/2%64);let n=xt;for(let t=0;t<7;t++)e=(e<<pt^(e>>yt)*At)%wt,e&gt&&(n^=pt<<(pt<</* @__PURE__ */BigInt(t))-pt);Bt.push(n)}const Lt=R(Bt,!0),kt=Lt[0],mt=Lt[1],It=(t,e,s)=>s>32?((t,e,s)=>e<<s-32|t>>>64-s)(t,e,s):((t,e,s)=>t<<s|e>>>32-s)(t,e,s),Ht=(t,e,s)=>s>32?((t,e,s)=>t<<s-32|e>>>64-s)(t,e,s):((t,e,s)=>e<<s|t>>>32-s)(t,e,s);class Ct extends m{constructor(t,e,s,n=!1,r=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=e,this.outputLen=s,this.enableXOF=n,this.rounds=r,i(s),!(0<t&&t<200))throw Error("only keccak-f1600 function is supported");var h;this.state=new Uint8Array(200),this.state32=(h=this.state,new Uint32Array(h.buffer,h.byteOffset,Math.floor(h.byteLength/4)))}clone(){return this._cloneInto()}keccak(){u(this.state32),function(t,e=24){const s=new Uint32Array(10);for(let i=24-e;i<24;i++){for(let e=0;e<10;e++)s[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const i=(e+8)%10,n=(e+2)%10,r=s[n],h=s[n+1],o=It(r,h,1)^s[i],c=Ht(r,h,1)^s[i+1];for(let s=0;s<50;s+=10)t[e+s]^=o,t[e+s+1]^=c}let e=t[2],n=t[3];for(let s=0;s<24;s++){const i=Ut[s],r=It(e,n,i),h=Ht(e,n,i),o=Et[s];e=t[o],n=t[o+1],t[o]=r,t[o+1]=h}for(let e=0;e<50;e+=10){for(let i=0;i<10;i++)s[i]=t[e+i];for(let i=0;i<10;i++)t[e+i]^=~s[(i+2)%10]&s[(i+4)%10]}t[0]^=kt[i],t[1]^=mt[i]}c(s)}(this.state32,this.rounds),u(this.state32),this.posOut=0,this.pos=0}update(t){h(this),n(t=L(t));const{blockLen:e,state:s}=this,i=t.length;for(let n=0;n<i;){const r=Math.min(e-this.pos,i-n);for(let e=0;e<r;e++)s[this.pos++]^=t[n++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:e,pos:s,blockLen:i}=this;t[s]^=e,128&e&&s===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){h(this,!1),n(t),this.finish();const e=this.state,{blockLen:s}=this;for(let i=0,n=t.length;i<n;){this.posOut>=s&&this.keccak();const r=Math.min(s-this.posOut,n-i);t.set(e.subarray(this.posOut,this.posOut+r),i),this.posOut+=r,i+=r}return t}xofInto(t){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return i(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(o(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,c(this.state)}_cloneInto(t){const{blockLen:e,suffix:s,outputLen:i,rounds:n,enableXOF:r}=this;return t||(t=new Ct(e,s,i,r,n)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=n,t.suffix=s,t.outputLen=i,t.enableXOF=r,t.destroyed=this.destroyed,t}}const Ft=(t,e,s)=>I((()=>new Ct(e,t,s))),Dt=/* @__PURE__ */(()=>Ft(6,136,32))(),Ot=/* @__PURE__ */(()=>Ft(6,72,64))(),Gt=(t,e,s)=>function(t){const e=(e,s)=>t(s).update(L(e)).digest(),s=t({});return e.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=e=>t(e),e}(((i={})=>new Ct(e,t,void 0===i.dkLen?s:i.dkLen,!0))),vt=/* @__PURE__ */(()=>Gt(31,136,32))(),Nt=lt,Xt=ut,_t=dt,Mt=bt;export{F as C,m as H,D as M,n as a,x as b,k as c,i as d,r as e,c as f,h as g,B as h,s as i,bt as j,dt as k,I as l,vt as m,Nt as n,Mt as o,_t as p,O as q,C as r,lt as s,L as t,l as u,Ot as v,H as w,Dt as x,Xt as y}; //# sourceMappingURL=sha512.min.mjs.map