@protontech/openpgp
Version:
OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.
4 lines (3 loc) • 8.69 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. */
"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;import{H as t,h as s,b as h,t as e,i,w as c,j as a,k as r}from"./sha3.min.mjs";const f=(t,s,h)=>t&s^~t&h,d=(t,s,h)=>t&s^t&h^s&h;class o extends t{constructor(t,h,e,i){super(),this.blockLen=t,this.outputLen=h,this.padOffset=e,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=s(this.buffer)}update(t){h(this);const{view:i,buffer:c,blockLen:a}=this,r=(t=e(t)).length;for(let h=0;h<r;){const e=Math.min(a-this.pos,r-h);if(e!==a)c.set(t.subarray(h,h+e),this.pos),this.pos+=e,h+=e,this.pos===a&&(this.process(i,0),this.pos=0);else{const e=s(t);for(;a<=r-h;h+=a)this.process(e,h)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){h(this),i(t,this),this.finished=!0;const{buffer:e,view:c,blockLen:a,isLE:r}=this;let{pos:f}=this;e[f++]=128,this.buffer.subarray(f).fill(0),this.padOffset>a-f&&(this.process(c,0),f=0);for(let t=f;t<a;t++)e[t]=0;!function(t,s,h,e){if("function"==typeof t.setBigUint64)return t.setBigUint64(s,h,e);const i=BigInt(32),c=BigInt(4294967295),a=Number(h>>i&c),r=Number(h&c),f=e?4:0,d=e?0:4;t.setUint32(s+f,a,e),t.setUint32(s+d,r,e)}(c,a-8,BigInt(8*this.length),r),this.process(c,0);const d=s(t),o=this.outputLen;if(o%4)throw Error("_sha2: outputLen should be aligned to 32bit");const b=o/4,n=this.get();if(b>n.length)throw Error("_sha2: outputLen bigger than state");for(let t=0;t<b;t++)d.setUint32(4*t,n[t],r)}digest(){const{buffer:t,outputLen:s}=this;this.digestInto(t);const h=t.slice(0,s);return this.destroy(),h}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:s,buffer:h,length:e,finished:i,destroyed:c,pos:a}=this;return t.length=e,t.pos=a,t.finished=i,t.destroyed=c,e%s&&t.buffer.set(h),t}}const b=/* @__PURE__ */new Uint32Array([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]),n=/* @__PURE__ */new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),l=/* @__PURE__ */new Uint32Array(64);class x extends o{constructor(){super(64,32,8,!1),this.A=0|n[0],this.B=0|n[1],this.C=0|n[2],this.D=0|n[3],this.E=0|n[4],this.F=0|n[5],this.G=0|n[6],this.H=0|n[7]}get(){const{A:t,B:s,C:h,D:e,E:i,F:c,G:a,H:r}=this;return[t,s,h,e,i,c,a,r]}set(t,s,h,e,i,c,a,r){this.A=0|t,this.B=0|s,this.C=0|h,this.D=0|e,this.E=0|i,this.F=0|c,this.G=0|a,this.H=0|r}process(t,s){for(let h=0;h<16;h++,s+=4)l[h]=t.getUint32(s,!1);for(let t=16;t<64;t++){const s=l[t-15],h=l[t-2],e=a(s,7)^a(s,18)^s>>>3,i=a(h,17)^a(h,19)^h>>>10;l[t]=i+l[t-7]+e+l[t-16]|0}let{A:h,B:e,C:i,D:c,E:r,F:o,G:n,H:x}=this;for(let t=0;t<64;t++){const s=x+(a(r,6)^a(r,11)^a(r,25))+f(r,o,n)+b[t]+l[t]|0,u=(a(h,2)^a(h,13)^a(h,22))+d(h,e,i)|0;x=n,n=o,o=r,r=c+s|0,c=i,i=e,e=h,h=s+u|0}h=h+this.A|0,e=e+this.B|0,i=i+this.C|0,c=c+this.D|0,r=r+this.E|0,o=o+this.F|0,n=n+this.G|0,x=x+this.H|0,this.set(h,e,i,c,r,o,n,x)}roundClean(){l.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class u extends x{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const p=/* @__PURE__ */c((()=>new x)),H=/* @__PURE__ */c((()=>new u)),[B,g]=/* @__PURE__ */(()=>r.split(["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)))))(),L=/* @__PURE__ */new Uint32Array(80),A=/* @__PURE__ */new Uint32Array(80);class C extends o{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:s,Bh:h,Bl:e,Ch:i,Cl:c,Dh:a,Dl:r,Eh:f,El:d,Fh:o,Fl:b,Gh:n,Gl:l,Hh:x,Hl:u}=this;return[t,s,h,e,i,c,a,r,f,d,o,b,n,l,x,u]}set(t,s,h,e,i,c,a,r,f,d,o,b,n,l,x,u){this.Ah=0|t,this.Al=0|s,this.Bh=0|h,this.Bl=0|e,this.Ch=0|i,this.Cl=0|c,this.Dh=0|a,this.Dl=0|r,this.Eh=0|f,this.El=0|d,this.Fh=0|o,this.Fl=0|b,this.Gh=0|n,this.Gl=0|l,this.Hh=0|x,this.Hl=0|u}process(t,s){for(let h=0;h<16;h++,s+=4)L[h]=t.getUint32(s),A[h]=t.getUint32(s+=4);for(let t=16;t<80;t++){const s=0|L[t-15],h=0|A[t-15],e=r.rotrSH(s,h,1)^r.rotrSH(s,h,8)^r.shrSH(s,h,7),i=r.rotrSL(s,h,1)^r.rotrSL(s,h,8)^r.shrSL(s,h,7),c=0|L[t-2],a=0|A[t-2],f=r.rotrSH(c,a,19)^r.rotrBH(c,a,61)^r.shrSH(c,a,6),d=r.rotrSL(c,a,19)^r.rotrBL(c,a,61)^r.shrSL(c,a,6),o=r.add4L(i,d,A[t-7],A[t-16]),b=r.add4H(o,e,f,L[t-7],L[t-16]);L[t]=0|b,A[t]=0|o}let{Ah:h,Al:e,Bh:i,Bl:c,Ch:a,Cl:f,Dh:d,Dl:o,Eh:b,El:n,Fh:l,Fl:x,Gh:u,Gl:p,Hh:H,Hl:C}=this;for(let t=0;t<80;t++){const s=r.rotrSH(b,n,14)^r.rotrSH(b,n,18)^r.rotrBH(b,n,41),E=r.rotrSL(b,n,14)^r.rotrSL(b,n,18)^r.rotrBL(b,n,41),w=b&l^~b&u,y=n&x^~n&p,D=r.add5L(C,E,y,g[t],A[t]),F=r.add5H(D,H,s,w,B[t],L[t]),G=0|D,S=r.rotrSH(h,e,28)^r.rotrBH(h,e,34)^r.rotrBH(h,e,39),U=r.rotrSL(h,e,28)^r.rotrBL(h,e,34)^r.rotrBL(h,e,39),m=h&i^h&a^i&a,I=e&c^e&f^c&f;H=0|u,C=0|p,u=0|l,p=0|x,l=0|b,x=0|n,({h:b,l:n}=r.add(0|d,0|o,0|F,0|G)),d=0|a,o=0|f,a=0|i,f=0|c,i=0|h,c=0|e;const k=r.add3L(G,U,I);h=r.add3H(k,F,S,m),e=0|k}({h,l:e}=r.add(0|this.Ah,0|this.Al,0|h,0|e)),({h:i,l:c}=r.add(0|this.Bh,0|this.Bl,0|i,0|c)),({h:a,l:f}=r.add(0|this.Ch,0|this.Cl,0|a,0|f)),({h:d,l:o}=r.add(0|this.Dh,0|this.Dl,0|d,0|o)),({h:b,l:n}=r.add(0|this.Eh,0|this.El,0|b,0|n)),({h:l,l:x}=r.add(0|this.Fh,0|this.Fl,0|l,0|x)),({h:u,l:p}=r.add(0|this.Gh,0|this.Gl,0|u,0|p)),({h:H,l:C}=r.add(0|this.Hh,0|this.Hl,0|H,0|C)),this.set(h,e,i,c,a,f,d,o,b,n,l,x,u,p,H,C)}roundClean(){L.fill(0),A.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class E extends C{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}const w=/* @__PURE__ */c((()=>new C)),y=/* @__PURE__ */c((()=>new E));export{f as C,o as H,d as M,y as a,w as b,H as c,p as s};
//# sourceMappingURL=sha512.min.mjs.map