@protontech/openpgp 6.0.0-beta.0.patch.0 → 6.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/lightweight/argon2id.min.mjs +2 -2
  2. package/dist/lightweight/argon2id.min.mjs.map +1 -1
  3. package/dist/lightweight/argon2id.mjs +5 -28
  4. package/dist/lightweight/legacy_ciphers.min.mjs +2 -2
  5. package/dist/lightweight/legacy_ciphers.min.mjs.map +1 -1
  6. package/dist/lightweight/legacy_ciphers.mjs +6 -51
  7. package/dist/lightweight/noble_curves.min.mjs +11 -11
  8. package/dist/lightweight/noble_curves.min.mjs.map +1 -1
  9. package/dist/lightweight/noble_curves.mjs +477 -465
  10. package/dist/lightweight/noble_hashes.min.mjs +2 -2
  11. package/dist/lightweight/noble_hashes.min.mjs.map +1 -1
  12. package/dist/lightweight/noble_hashes.mjs +19 -31
  13. package/dist/lightweight/openpgp.min.mjs +2 -2
  14. package/dist/lightweight/openpgp.min.mjs.map +1 -1
  15. package/dist/lightweight/openpgp.mjs +591 -457
  16. package/dist/lightweight/sha3.min.mjs +3 -3
  17. package/dist/lightweight/sha3.min.mjs.map +1 -1
  18. package/dist/lightweight/sha3.mjs +80 -80
  19. package/dist/node/openpgp.cjs +1245 -5442
  20. package/dist/node/openpgp.min.cjs +11 -12
  21. package/dist/node/openpgp.min.cjs.map +1 -1
  22. package/dist/node/openpgp.min.mjs +11 -12
  23. package/dist/node/openpgp.min.mjs.map +1 -1
  24. package/dist/node/openpgp.mjs +1245 -5442
  25. package/dist/openpgp.js +1238 -5435
  26. package/dist/openpgp.min.js +11 -12
  27. package/dist/openpgp.min.js.map +1 -1
  28. package/dist/openpgp.min.mjs +11 -12
  29. package/dist/openpgp.min.mjs.map +1 -1
  30. package/dist/openpgp.mjs +1238 -5435
  31. package/openpgp.d.ts +61 -60
  32. package/package.json +16 -10
  33. package/dist/lightweight/bn.interface.min.mjs +0 -3
  34. package/dist/lightweight/bn.interface.min.mjs.map +0 -1
  35. package/dist/lightweight/bn.interface.mjs +0 -3807
  36. package/dist/lightweight/interface.min.mjs +0 -3
  37. package/dist/lightweight/interface.min.mjs.map +0 -1
  38. package/dist/lightweight/interface.mjs +0 -16
  39. package/dist/lightweight/native.interface.min.mjs +0 -3
  40. package/dist/lightweight/native.interface.min.mjs.map +0 -1
  41. package/dist/lightweight/native.interface.mjs +0 -456
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v6.0.0-beta.0.patch.0 - 2024-04-19 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v6.0.0-beta.1 - 2024-05-17 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
2
2
  const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3
3
 
4
4
  const doneWritingPromise = Symbol('doneWritingPromise');
@@ -1660,7 +1660,7 @@ var config = {
1660
1660
  * @memberof module:config
1661
1661
  * @property {String} versionString A version string to be included in armored messages
1662
1662
  */
1663
- versionString: 'OpenPGP.js 6.0.0-beta.0.patch.0',
1663
+ versionString: 'OpenPGP.js 6.0.0-beta.1',
1664
1664
  /**
1665
1665
  * @memberof module:config
1666
1666
  * @property {String} commentString A comment string to be included in armored messages
@@ -1721,27 +1721,6 @@ var config = {
1721
1721
  rejectCurves: new Set([enums.curve.secp256k1])
1722
1722
  };
1723
1723
 
1724
- /**
1725
- * We don't use the BigIntegerInterface wrapper from noble-hashes because:
1726
- * - importing the instance results in it being shared with noble-hashes, which separately calls `setImplementation()`
1727
- * on load, causing it to throw due to duplicate initialization.
1728
- * - even duplicating the interface code here to keep a separate instance requires handing a race-conditions the first time
1729
- * `getBigInteger` is called, when the code needs to check if the implementation is set, and initialize it if not.
1730
- * Ultimately, the interface provides no advantages and it's only needed because of TS.
1731
- */
1732
- const detectBigInt = () => typeof BigInt !== 'undefined';
1733
- async function getBigInteger() {
1734
- if (detectBigInt()) {
1735
- // NativeBigInteger is small, so it's imported in isolation (it could also be imported at the top level)
1736
- const { default: NativeBigInteger } = await import('./native.interface.mjs');
1737
- return NativeBigInteger;
1738
- } else {
1739
- // FallbackBigInteger relies on large BN.js lib, which is also used by noble-hashes and noble-curves
1740
- const { default: FallbackBigInteger } = await import('./bn.interface.mjs');
1741
- return FallbackBigInteger;
1742
- }
1743
- }
1744
-
1745
1724
  // GPG4Browsers - An OpenPGP implementation in javascript
1746
1725
  // Copyright (C) 2011 Recurity Labs GmbH
1747
1726
  //
@@ -1783,8 +1762,6 @@ const util = {
1783
1762
 
1784
1763
  isStream: isStream,
1785
1764
 
1786
- getBigInteger,
1787
-
1788
1765
  /**
1789
1766
  * Load noble-curves lib on demand and return the requested curve function
1790
1767
  * @param {enums.publicKey} publicKeyAlgo
@@ -2506,7 +2483,7 @@ function b64ToUint8Array(base64) {
2506
2483
  */
2507
2484
  function uint8ArrayToB64(bytes, url) {
2508
2485
  let encoded = encode$1(bytes).replace(/[\r\n]/g, '');
2509
- if (url) {
2486
+ {
2510
2487
  encoded = encoded.replace(/[+]/g, '-').replace(/[/]/g, '_').replace(/[=]/g, '');
2511
2488
  }
2512
2489
  return encoded;
@@ -4293,7 +4270,7 @@ function is_bytes(a) {
4293
4270
  return a instanceof Uint8Array;
4294
4271
  }
4295
4272
  function _heap_init(heap, heapSize) {
4296
- const size = heap ? heap.byteLength : heapSize || 65536;
4273
+ const size = heap ? heap.byteLength : 65536;
4297
4274
  if (size & 0xfff || size <= 0)
4298
4275
  throw new Error('heap size must be a positive integer and a multiple of 4096');
4299
4276
  heap = heap || new Uint8Array(new ArrayBuffer(size));
@@ -5850,6 +5827,202 @@ var mode = {
5850
5827
  ocb: OCB
5851
5828
  };
5852
5829
 
5830
+ // Operations are not constant time, but we try and limit timing leakage where we can
5831
+ const _0n$1 = BigInt(0);
5832
+ const _1n$4 = BigInt(1);
5833
+ function uint8ArrayToBigInt(bytes) {
5834
+ const hexAlphabet = '0123456789ABCDEF';
5835
+ let s = '';
5836
+ bytes.forEach(v => {
5837
+ s += hexAlphabet[v >> 4] + hexAlphabet[v & 15];
5838
+ });
5839
+ return BigInt('0x0' + s);
5840
+ }
5841
+ function mod$1(a, m) {
5842
+ const reduced = a % m;
5843
+ return reduced < _0n$1 ? reduced + m : reduced;
5844
+ }
5845
+ /**
5846
+ * Compute modular exponentiation using square and multiply
5847
+ * @param {BigInt} a - Base
5848
+ * @param {BigInt} e - Exponent
5849
+ * @param {BigInt} n - Modulo
5850
+ * @returns {BigInt} b ** e mod n.
5851
+ */
5852
+ function modExp(b, e, n) {
5853
+ if (n === _0n$1)
5854
+ throw Error('Modulo cannot be zero');
5855
+ if (n === _1n$4)
5856
+ return BigInt(0);
5857
+ if (e < _0n$1)
5858
+ throw Error('Unsopported negative exponent');
5859
+ let exp = e;
5860
+ let x = b;
5861
+ x %= n;
5862
+ let r = BigInt(1);
5863
+ while (exp > _0n$1) {
5864
+ const lsb = exp & _1n$4;
5865
+ exp >>= _1n$4; // e / 2
5866
+ // Always compute multiplication step, to reduce timing leakage
5867
+ const rx = (r * x) % n;
5868
+ // Update r only if lsb is 1 (odd exponent)
5869
+ r = lsb ? rx : r;
5870
+ x = (x * x) % n; // Square
5871
+ }
5872
+ return r;
5873
+ }
5874
+ function abs(x) {
5875
+ return x >= _0n$1 ? x : -x;
5876
+ }
5877
+ /**
5878
+ * Extended Eucleadian algorithm (http://anh.cs.luc.edu/331/notes/xgcd.pdf)
5879
+ * Given a and b, compute (x, y) such that ax + by = gdc(a, b).
5880
+ * Negative numbers are also supported.
5881
+ * @param {BigInt} a - First operand
5882
+ * @param {BigInt} b - Second operand
5883
+ * @returns {{ gcd, x, y: bigint }}
5884
+ */
5885
+ function _egcd(aInput, bInput) {
5886
+ let x = BigInt(0);
5887
+ let y = BigInt(1);
5888
+ let xPrev = BigInt(1);
5889
+ let yPrev = BigInt(0);
5890
+ // Deal with negative numbers: run algo over absolute values,
5891
+ // and "move" the sign to the returned x and/or y.
5892
+ // See https://math.stackexchange.com/questions/37806/extended-euclidean-algorithm-with-negative-numbers
5893
+ let a = abs(aInput);
5894
+ let b = abs(bInput);
5895
+ const aNegated = aInput < _0n$1;
5896
+ const bNegated = bInput < _0n$1;
5897
+ while (b !== _0n$1) {
5898
+ const q = a / b;
5899
+ let tmp = x;
5900
+ x = xPrev - q * x;
5901
+ xPrev = tmp;
5902
+ tmp = y;
5903
+ y = yPrev - q * y;
5904
+ yPrev = tmp;
5905
+ tmp = b;
5906
+ b = a % b;
5907
+ a = tmp;
5908
+ }
5909
+ return {
5910
+ x: aNegated ? -xPrev : xPrev,
5911
+ y: bNegated ? -yPrev : yPrev,
5912
+ gcd: a
5913
+ };
5914
+ }
5915
+ /**
5916
+ * Compute the inverse of `a` modulo `n`
5917
+ * Note: `a` and and `n` must be relatively prime
5918
+ * @param {BigInt} a
5919
+ * @param {BigInt} n - Modulo
5920
+ * @returns {BigInt} x such that a*x = 1 mod n
5921
+ * @throws {Error} if the inverse does not exist
5922
+ */
5923
+ function modInv(a, n) {
5924
+ const { gcd, x } = _egcd(a, n);
5925
+ if (gcd !== _1n$4) {
5926
+ throw new Error('Inverse does not exist');
5927
+ }
5928
+ return mod$1(x + n, n);
5929
+ }
5930
+ /**
5931
+ * Compute greatest common divisor between this and n
5932
+ * @param {BigInt} aInput - Operand
5933
+ * @param {BigInt} bInput - Operand
5934
+ * @returns {BigInt} gcd
5935
+ */
5936
+ function gcd(aInput, bInput) {
5937
+ let a = aInput;
5938
+ let b = bInput;
5939
+ while (b !== _0n$1) {
5940
+ const tmp = b;
5941
+ b = a % b;
5942
+ a = tmp;
5943
+ }
5944
+ return a;
5945
+ }
5946
+ /**
5947
+ * Get this value as an exact Number (max 53 bits)
5948
+ * Fails if this value is too large
5949
+ * @returns {Number}
5950
+ */
5951
+ function bigIntToNumber(x) {
5952
+ const number = Number(x);
5953
+ if (number > Number.MAX_SAFE_INTEGER) {
5954
+ // We throw and error to conform with the bn.js implementation
5955
+ throw new Error('Number can only safely store up to 53 bits');
5956
+ }
5957
+ return number;
5958
+ }
5959
+ /**
5960
+ * Get value of i-th bit
5961
+ * @param {BigInt} x
5962
+ * @param {Number} i - Bit index
5963
+ * @returns {Number} Bit value.
5964
+ */
5965
+ function getBit(x, i) {
5966
+ const bit = (x >> BigInt(i)) & _1n$4;
5967
+ return bit === _0n$1 ? 0 : 1;
5968
+ }
5969
+ /**
5970
+ * Compute bit length
5971
+ */
5972
+ function bitLength(x) {
5973
+ // -1n >> -1n is -1n
5974
+ // 1n >> 1n is 0n
5975
+ const target = x < _0n$1 ? BigInt(-1) : _0n$1;
5976
+ let bitlen = 1;
5977
+ let tmp = x;
5978
+ // eslint-disable-next-line no-cond-assign
5979
+ while ((tmp >>= _1n$4) !== target) {
5980
+ bitlen++;
5981
+ }
5982
+ return bitlen;
5983
+ }
5984
+ /**
5985
+ * Compute byte length
5986
+ */
5987
+ function byteLength(x) {
5988
+ const target = x < _0n$1 ? BigInt(-1) : _0n$1;
5989
+ const _8n = BigInt(8);
5990
+ let len = 1;
5991
+ let tmp = x;
5992
+ // eslint-disable-next-line no-cond-assign
5993
+ while ((tmp >>= _8n) !== target) {
5994
+ len++;
5995
+ }
5996
+ return len;
5997
+ }
5998
+ /**
5999
+ * Get Uint8Array representation of this number
6000
+ * @param {String} endian - Endianess of output array (defaults to 'be')
6001
+ * @param {Number} length - Of output array
6002
+ * @returns {Uint8Array}
6003
+ */
6004
+ function bigIntToUint8Array(x, endian = 'be', length) {
6005
+ // we get and parse the hex string (https://coolaj86.com/articles/convert-js-bigints-to-typedarrays/)
6006
+ // this is faster than shift+mod iterations
6007
+ let hex = x.toString(16);
6008
+ if (hex.length % 2 === 1) {
6009
+ hex = '0' + hex;
6010
+ }
6011
+ const rawLength = hex.length / 2;
6012
+ const bytes = new Uint8Array(length || rawLength);
6013
+ // parse hex
6014
+ const offset = length ? length - rawLength : 0;
6015
+ let i = 0;
6016
+ while (i < rawLength) {
6017
+ bytes[i + offset] = parseInt(hex.slice(2 * i, 2 * i + 2), 16);
6018
+ i++;
6019
+ }
6020
+ if (endian !== 'be') {
6021
+ bytes.reverse();
6022
+ }
6023
+ return bytes;
6024
+ }
6025
+
5853
6026
  // GPG4Browsers - An OpenPGP implementation in javascript
5854
6027
  // Copyright (C) 2011 Recurity Labs GmbH
5855
6028
  //
@@ -5889,27 +6062,25 @@ function getRandomBytes(length) {
5889
6062
  }
5890
6063
 
5891
6064
  /**
5892
- * Create a secure random BigInteger that is greater than or equal to min and less than max.
5893
- * @param {module:BigInteger} min - Lower bound, included
5894
- * @param {module:BigInteger} max - Upper bound, excluded
5895
- * @returns {Promise<module:BigInteger>} Random BigInteger.
6065
+ * Create a secure random BigInt that is greater than or equal to min and less than max.
6066
+ * @param {bigint} min - Lower bound, included
6067
+ * @param {bigint} max - Upper bound, excluded
6068
+ * @returns {bigint} Random BigInt.
5896
6069
  * @async
5897
6070
  */
5898
- async function getRandomBigInteger(min, max) {
5899
- const BigInteger = await util.getBigInteger();
5900
-
5901
- if (max.lt(min)) {
6071
+ function getRandomBigInteger(min, max) {
6072
+ if (max < min) {
5902
6073
  throw new Error('Illegal parameter value: max <= min');
5903
6074
  }
5904
6075
 
5905
- const modulus = max.sub(min);
5906
- const bytes = modulus.byteLength();
6076
+ const modulus = max - min;
6077
+ const bytes = byteLength(modulus);
5907
6078
 
5908
6079
  // Using a while loop is necessary to avoid bias introduced by the mod operation.
5909
6080
  // However, we request 64 extra random bits so that the bias is negligible.
5910
6081
  // Section B.1.1 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
5911
- const r = new BigInteger(getRandomBytes(bytes + 8));
5912
- return r.mod(modulus).add(min);
6082
+ const r = uint8ArrayToBigInt(getRandomBytes(bytes + 8));
6083
+ return mod$1(r, modulus) + min;
5913
6084
  }
5914
6085
 
5915
6086
  var random = /*#__PURE__*/Object.freeze({
@@ -5934,177 +6105,159 @@ var random = /*#__PURE__*/Object.freeze({
5934
6105
  // You should have received a copy of the GNU Lesser General Public
5935
6106
  // License along with this library; if not, write to the Free Software
5936
6107
  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5937
-
5938
-
6108
+ /**
6109
+ * @fileoverview Algorithms for probabilistic random prime generation
6110
+ * @module crypto/public_key/prime
6111
+ */
6112
+ const _1n$3 = BigInt(1);
5939
6113
  /**
5940
6114
  * Generate a probably prime random number
5941
- * @param {Integer} bits - Bit length of the prime
5942
- * @param {BigInteger} e - Optional RSA exponent to check against the prime
5943
- * @param {Integer} k - Optional number of iterations of Miller-Rabin test
5944
- * @returns BigInteger
5945
- * @async
6115
+ * @param bits - Bit length of the prime
6116
+ * @param e - Optional RSA exponent to check against the prime
6117
+ * @param k - Optional number of iterations of Miller-Rabin test
5946
6118
  */
5947
- async function randomProbablePrime(bits, e, k) {
5948
- const BigInteger = await util.getBigInteger();
5949
-
5950
- const one = new BigInteger(1);
5951
- const min = one.leftShift(new BigInteger(bits - 1));
5952
- const thirty = new BigInteger(30);
5953
- /*
5954
- * We can avoid any multiples of 3 and 5 by looking at n mod 30
5955
- * n mod 30 = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
5956
- * the next possible prime is mod 30:
5957
- * 1 7 7 7 7 7 7 11 11 11 11 13 13 17 17 17 17 19 19 23 23 23 23 29 29 29 29 29 29 1
5958
- */
5959
- const adds = [1, 6, 5, 4, 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 2];
5960
-
5961
- const n = await getRandomBigInteger(min, min.leftShift(one));
5962
- let i = n.mod(thirty).toNumber();
5963
-
5964
- do {
5965
- n.iadd(new BigInteger(adds[i]));
5966
- i = (i + adds[i]) % adds.length;
5967
- // If reached the maximum, go back to the minimum.
5968
- if (n.bitLength() > bits) {
5969
- n.imod(min.leftShift(one)).iadd(min);
5970
- i = n.mod(thirty).toNumber();
5971
- }
5972
- } while (!await isProbablePrime(n, e, k));
5973
- return n;
6119
+ function randomProbablePrime(bits, e, k) {
6120
+ const _30n = BigInt(30);
6121
+ const min = _1n$3 << BigInt(bits - 1);
6122
+ /*
6123
+ * We can avoid any multiples of 3 and 5 by looking at n mod 30
6124
+ * n mod 30 = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
6125
+ * the next possible prime is mod 30:
6126
+ * 1 7 7 7 7 7 7 11 11 11 11 13 13 17 17 17 17 19 19 23 23 23 23 29 29 29 29 29 29 1
6127
+ */
6128
+ const adds = [1, 6, 5, 4, 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 2];
6129
+ let n = getRandomBigInteger(min, min << _1n$3);
6130
+ let i = bigIntToNumber(mod$1(n, _30n));
6131
+ do {
6132
+ n += BigInt(adds[i]);
6133
+ i = (i + adds[i]) % adds.length;
6134
+ // If reached the maximum, go back to the minimum.
6135
+ if (bitLength(n) > bits) {
6136
+ n = mod$1(n, min << _1n$3);
6137
+ n += min;
6138
+ i = bigIntToNumber(mod$1(n, _30n));
6139
+ }
6140
+ } while (!isProbablePrime(n, e, k));
6141
+ return n;
5974
6142
  }
5975
-
5976
6143
  /**
5977
6144
  * Probabilistic primality testing
5978
- * @param {BigInteger} n - Number to test
5979
- * @param {BigInteger} e - Optional RSA exponent to check against the prime
5980
- * @param {Integer} k - Optional number of iterations of Miller-Rabin test
5981
- * @returns {boolean}
5982
- * @async
6145
+ * @param n - Number to test
6146
+ * @param e - Optional RSA exponent to check against the prime
6147
+ * @param k - Optional number of iterations of Miller-Rabin test
5983
6148
  */
5984
- async function isProbablePrime(n, e, k) {
5985
- if (e && !n.dec().gcd(e).isOne()) {
5986
- return false;
5987
- }
5988
- if (!await divisionTest(n)) {
5989
- return false;
5990
- }
5991
- if (!await fermat(n)) {
5992
- return false;
5993
- }
5994
- if (!await millerRabin(n, k)) {
5995
- return false;
5996
- }
5997
- // TODO implement the Lucas test
5998
- // See Section C.3.3 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
5999
- return true;
6149
+ function isProbablePrime(n, e, k) {
6150
+ if (e && gcd(n - _1n$3, e) !== _1n$3) {
6151
+ return false;
6152
+ }
6153
+ if (!divisionTest(n)) {
6154
+ return false;
6155
+ }
6156
+ if (!fermat(n)) {
6157
+ return false;
6158
+ }
6159
+ if (!millerRabin(n, k)) {
6160
+ return false;
6161
+ }
6162
+ // TODO implement the Lucas test
6163
+ // See Section C.3.3 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
6164
+ return true;
6000
6165
  }
6001
-
6002
6166
  /**
6003
6167
  * Tests whether n is probably prime or not using Fermat's test with b = 2.
6004
6168
  * Fails if b^(n-1) mod n != 1.
6005
- * @param {BigInteger} n - Number to test
6006
- * @param {BigInteger} b - Optional Fermat test base
6007
- * @returns {boolean}
6169
+ * @param n - Number to test
6170
+ * @param b - Optional Fermat test base
6008
6171
  */
6009
- async function fermat(n, b) {
6010
- const BigInteger = await util.getBigInteger();
6011
-
6012
- b = b || new BigInteger(2);
6013
- return b.modExp(n.dec(), n).isOne();
6172
+ function fermat(n, b = BigInt(2)) {
6173
+ return modExp(b, n - _1n$3, n) === _1n$3;
6014
6174
  }
6015
-
6016
- async function divisionTest(n) {
6017
- const BigInteger = await util.getBigInteger();
6018
-
6019
- return smallPrimes.every(m => {
6020
- return n.mod(new BigInteger(m)) !== 0;
6021
- });
6175
+ function divisionTest(n) {
6176
+ const _0n = BigInt(0);
6177
+ return smallPrimes.every(m => mod$1(n, m) !== _0n);
6022
6178
  }
6023
-
6024
6179
  // https://github.com/gpg/libgcrypt/blob/master/cipher/primegen.c
6025
6180
  const smallPrimes = [
6026
- 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
6027
- 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
6028
- 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
6029
- 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
6030
- 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
6031
- 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
6032
- 331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
6033
- 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
6034
- 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
6035
- 509, 521, 523, 541, 547, 557, 563, 569, 571, 577,
6036
- 587, 593, 599, 601, 607, 613, 617, 619, 631, 641,
6037
- 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
6038
- 709, 719, 727, 733, 739, 743, 751, 757, 761, 769,
6039
- 773, 787, 797, 809, 811, 821, 823, 827, 829, 839,
6040
- 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
6041
- 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
6042
- 991, 997, 1009, 1013, 1019, 1021, 1031, 1033,
6043
- 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091,
6044
- 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151,
6045
- 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213,
6046
- 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277,
6047
- 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307,
6048
- 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399,
6049
- 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451,
6050
- 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493,
6051
- 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559,
6052
- 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609,
6053
- 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667,
6054
- 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733,
6055
- 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789,
6056
- 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871,
6057
- 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931,
6058
- 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997,
6059
- 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053,
6060
- 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111,
6061
- 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161,
6062
- 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243,
6063
- 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297,
6064
- 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357,
6065
- 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411,
6066
- 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473,
6067
- 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551,
6068
- 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633,
6069
- 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687,
6070
- 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729,
6071
- 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791,
6072
- 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851,
6073
- 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917,
6074
- 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999,
6075
- 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061,
6076
- 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137,
6077
- 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209,
6078
- 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271,
6079
- 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331,
6080
- 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391,
6081
- 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467,
6082
- 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533,
6083
- 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583,
6084
- 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643,
6085
- 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709,
6086
- 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779,
6087
- 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851,
6088
- 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917,
6089
- 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989,
6090
- 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049,
6091
- 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111,
6092
- 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177,
6093
- 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243,
6094
- 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297,
6095
- 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391,
6096
- 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457,
6097
- 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519,
6098
- 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597,
6099
- 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657,
6100
- 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729,
6101
- 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799,
6102
- 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889,
6103
- 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951,
6104
- 4957, 4967, 4969, 4973, 4987, 4993, 4999
6105
- ];
6106
-
6107
-
6181
+ 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
6182
+ 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
6183
+ 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
6184
+ 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
6185
+ 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
6186
+ 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
6187
+ 331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
6188
+ 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
6189
+ 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
6190
+ 509, 521, 523, 541, 547, 557, 563, 569, 571, 577,
6191
+ 587, 593, 599, 601, 607, 613, 617, 619, 631, 641,
6192
+ 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
6193
+ 709, 719, 727, 733, 739, 743, 751, 757, 761, 769,
6194
+ 773, 787, 797, 809, 811, 821, 823, 827, 829, 839,
6195
+ 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
6196
+ 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
6197
+ 991, 997, 1009, 1013, 1019, 1021, 1031, 1033,
6198
+ 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091,
6199
+ 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151,
6200
+ 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213,
6201
+ 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277,
6202
+ 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307,
6203
+ 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399,
6204
+ 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451,
6205
+ 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493,
6206
+ 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559,
6207
+ 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609,
6208
+ 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667,
6209
+ 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733,
6210
+ 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789,
6211
+ 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871,
6212
+ 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931,
6213
+ 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997,
6214
+ 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053,
6215
+ 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111,
6216
+ 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161,
6217
+ 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243,
6218
+ 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297,
6219
+ 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357,
6220
+ 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411,
6221
+ 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473,
6222
+ 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551,
6223
+ 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633,
6224
+ 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687,
6225
+ 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729,
6226
+ 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791,
6227
+ 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851,
6228
+ 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917,
6229
+ 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999,
6230
+ 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061,
6231
+ 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137,
6232
+ 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209,
6233
+ 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271,
6234
+ 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331,
6235
+ 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391,
6236
+ 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467,
6237
+ 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533,
6238
+ 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583,
6239
+ 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643,
6240
+ 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709,
6241
+ 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779,
6242
+ 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851,
6243
+ 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917,
6244
+ 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989,
6245
+ 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049,
6246
+ 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111,
6247
+ 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177,
6248
+ 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243,
6249
+ 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297,
6250
+ 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391,
6251
+ 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457,
6252
+ 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519,
6253
+ 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597,
6254
+ 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657,
6255
+ 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729,
6256
+ 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799,
6257
+ 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889,
6258
+ 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951,
6259
+ 4957, 4967, 4969, 4973, 4987, 4993, 4999
6260
+ ].map(n => BigInt(n));
6108
6261
  // Miller-Rabin - Miller Rabin algorithm for primality test
6109
6262
  // Copyright Fedor Indutny, 2014.
6110
6263
  //
@@ -6128,63 +6281,51 @@ const smallPrimes = [
6128
6281
  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
6129
6282
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
6130
6283
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
6131
-
6132
6284
  // Adapted on Jan 2018 from version 4.0.1 at https://github.com/indutny/miller-rabin
6133
-
6134
6285
  // Sample syntax for Fixed-Base Miller-Rabin:
6135
6286
  // millerRabin(n, k, () => new BN(small_primes[Math.random() * small_primes.length | 0]))
6136
-
6137
6287
  /**
6138
6288
  * Tests whether n is probably prime or not using the Miller-Rabin test.
6139
6289
  * See HAC Remark 4.28.
6140
- * @param {BigInteger} n - Number to test
6141
- * @param {Integer} k - Optional number of iterations of Miller-Rabin test
6142
- * @param {Function} rand - Optional function to generate potential witnesses
6290
+ * @param n - Number to test
6291
+ * @param k - Optional number of iterations of Miller-Rabin test
6292
+ * @param rand - Optional function to generate potential witnesses
6143
6293
  * @returns {boolean}
6144
6294
  * @async
6145
6295
  */
6146
- async function millerRabin(n, k, rand) {
6147
- const BigInteger = await util.getBigInteger();
6148
-
6149
- const len = n.bitLength();
6150
-
6151
- if (!k) {
6152
- k = Math.max(1, (len / 48) | 0);
6153
- }
6154
-
6155
- const n1 = n.dec(); // n - 1
6156
-
6157
- // Find d and s, (n - 1) = (2 ^ s) * d;
6158
- let s = 0;
6159
- while (!n1.getBit(s)) { s++; }
6160
- const d = n.rightShift(new BigInteger(s));
6161
-
6162
- for (; k > 0; k--) {
6163
- const a = rand ? rand() : await getRandomBigInteger(new BigInteger(2), n1);
6164
-
6165
- let x = a.modExp(d, n);
6166
- if (x.isOne() || x.equal(n1)) {
6167
- continue;
6296
+ function millerRabin(n, k, rand) {
6297
+ const len = bitLength(n);
6298
+ if (!k) {
6299
+ k = Math.max(1, (len / 48) | 0);
6168
6300
  }
6169
-
6170
- let i;
6171
- for (i = 1; i < s; i++) {
6172
- x = x.mul(x).mod(n);
6173
-
6174
- if (x.isOne()) {
6175
- return false;
6176
- }
6177
- if (x.equal(n1)) {
6178
- break;
6179
- }
6180
- }
6181
-
6182
- if (i === s) {
6183
- return false;
6301
+ const n1 = n - _1n$3; // n - 1
6302
+ // Find d and s, (n - 1) = (2 ^ s) * d;
6303
+ let s = 0;
6304
+ while (!getBit(n1, s)) {
6305
+ s++;
6306
+ }
6307
+ const d = n >> BigInt(s);
6308
+ for (; k > 0; k--) {
6309
+ const a = getRandomBigInteger(BigInt(2), n1);
6310
+ let x = modExp(a, d, n);
6311
+ if (x === _1n$3 || x === n1) {
6312
+ continue;
6313
+ }
6314
+ let i;
6315
+ for (i = 1; i < s; i++) {
6316
+ x = mod$1(x * x, n);
6317
+ if (x === _1n$3) {
6318
+ return false;
6319
+ }
6320
+ if (x === n1) {
6321
+ break;
6322
+ }
6323
+ }
6324
+ if (i === s) {
6325
+ return false;
6326
+ }
6184
6327
  }
6185
- }
6186
-
6187
- return true;
6328
+ return true;
6188
6329
  }
6189
6330
 
6190
6331
  // GPG4Browsers - An OpenPGP implementation in javascript
@@ -6310,7 +6451,7 @@ function emeDecode(encoded, randomPayload) {
6310
6451
  * @param {Integer} emLen - Intended length in octets of the encoded message
6311
6452
  * @returns {Uint8Array} Encoded message.
6312
6453
  */
6313
- async function emsaEncode(algo, hashed, emLen) {
6454
+ function emsaEncode(algo, hashed, emLen) {
6314
6455
  let i;
6315
6456
  if (hashed.length !== hash.getHashByteLength(algo)) {
6316
6457
  throw new Error('Invalid hash length');
@@ -6367,6 +6508,7 @@ var pkcs1 = /*#__PURE__*/Object.freeze({
6367
6508
 
6368
6509
  const webCrypto$6 = util.getWebCrypto();
6369
6510
  const nodeCrypto$4 = util.getNodeCrypto();
6511
+ const _1n$2 = BigInt(1);
6370
6512
 
6371
6513
  /** Create signature
6372
6514
  * @param {module:enums.hash} hashAlgo - Hash algorithm
@@ -6480,16 +6622,14 @@ async function decrypt$4(data, n, e, d, p, q, u, randomPayload) {
6480
6622
  * @async
6481
6623
  */
6482
6624
  async function generate$5(bits, e) {
6483
- const BigInteger = await util.getBigInteger();
6484
-
6485
- e = new BigInteger(e);
6625
+ e = BigInt(e);
6486
6626
 
6487
6627
  // Native RSA keygen using Web Crypto
6488
6628
  if (util.getWebCrypto()) {
6489
6629
  const keyGenOpt = {
6490
6630
  name: 'RSASSA-PKCS1-v1_5',
6491
6631
  modulusLength: bits, // the specified keysize in bits
6492
- publicExponent: e.toUint8Array(), // take three bytes (max 65537) for exponent
6632
+ publicExponent: bigIntToUint8Array(e), // take three bytes (max 65537) for exponent
6493
6633
  hash: {
6494
6634
  name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify'
6495
6635
  }
@@ -6504,7 +6644,7 @@ async function generate$5(bits, e) {
6504
6644
  } else if (util.getNodeCrypto()) {
6505
6645
  const opts = {
6506
6646
  modulusLength: bits,
6507
- publicExponent: e.toNumber(),
6647
+ publicExponent: bigIntToNumber(e),
6508
6648
  publicKeyEncoding: { type: 'pkcs1', format: 'jwk' },
6509
6649
  privateKeyEncoding: { type: 'pkcs1', format: 'jwk' }
6510
6650
  };
@@ -6527,26 +6667,26 @@ async function generate$5(bits, e) {
6527
6667
  let q;
6528
6668
  let n;
6529
6669
  do {
6530
- q = await randomProbablePrime(bits - (bits >> 1), e, 40);
6531
- p = await randomProbablePrime(bits >> 1, e, 40);
6532
- n = p.mul(q);
6533
- } while (n.bitLength() !== bits);
6670
+ q = randomProbablePrime(bits - (bits >> 1), e, 40);
6671
+ p = randomProbablePrime(bits >> 1, e, 40);
6672
+ n = p * q;
6673
+ } while (bitLength(n) !== bits);
6534
6674
 
6535
- const phi = p.dec().imul(q.dec());
6675
+ const phi = (p - _1n$2) * (q - _1n$2);
6536
6676
 
6537
- if (q.lt(p)) {
6677
+ if (q < p) {
6538
6678
  [p, q] = [q, p];
6539
6679
  }
6540
6680
 
6541
6681
  return {
6542
- n: n.toUint8Array(),
6543
- e: e.toUint8Array(),
6544
- d: e.modInv(phi).toUint8Array(),
6545
- p: p.toUint8Array(),
6546
- q: q.toUint8Array(),
6682
+ n: bigIntToUint8Array(n),
6683
+ e: bigIntToUint8Array(e),
6684
+ d: bigIntToUint8Array(modInv(e, phi)),
6685
+ p: bigIntToUint8Array(p),
6686
+ q: bigIntToUint8Array(q),
6547
6687
  // dp: d.mod(p.subn(1)),
6548
6688
  // dq: d.mod(q.subn(1)),
6549
- u: p.modInv(q).toUint8Array()
6689
+ u: bigIntToUint8Array(modInv(p, q))
6550
6690
  };
6551
6691
  }
6552
6692
 
@@ -6562,26 +6702,24 @@ async function generate$5(bits, e) {
6562
6702
  * @async
6563
6703
  */
6564
6704
  async function validateParams$8(n, e, d, p, q, u) {
6565
- const BigInteger = await util.getBigInteger();
6566
-
6567
- n = new BigInteger(n);
6568
- p = new BigInteger(p);
6569
- q = new BigInteger(q);
6705
+ n = uint8ArrayToBigInt(n);
6706
+ p = uint8ArrayToBigInt(p);
6707
+ q = uint8ArrayToBigInt(q);
6570
6708
 
6571
6709
  // expect pq = n
6572
- if (!p.mul(q).equal(n)) {
6710
+ if ((p * q) !== n) {
6573
6711
  return false;
6574
6712
  }
6575
6713
 
6576
- const two = new BigInteger(2);
6714
+ const _2n = BigInt(2);
6577
6715
  // expect p*u = 1 mod q
6578
- u = new BigInteger(u);
6579
- if (!p.mul(u).mod(q).isOne()) {
6716
+ u = uint8ArrayToBigInt(u);
6717
+ if (mod$1(p * u, q) !== BigInt(1)) {
6580
6718
  return false;
6581
6719
  }
6582
6720
 
6583
- e = new BigInteger(e);
6584
- d = new BigInteger(d);
6721
+ e = uint8ArrayToBigInt(e);
6722
+ d = uint8ArrayToBigInt(d);
6585
6723
  /**
6586
6724
  * In RSA pkcs#1 the exponents (d, e) are inverses modulo lcm(p-1, q-1)
6587
6725
  * We check that [de = 1 mod (p-1)] and [de = 1 mod (q-1)]
@@ -6589,11 +6727,11 @@ async function validateParams$8(n, e, d, p, q, u) {
6589
6727
  *
6590
6728
  * We blind the multiplication with r, and check that rde = r mod lcm(p-1, q-1)
6591
6729
  */
6592
- const nSizeOver3 = new BigInteger(Math.floor(n.bitLength() / 3));
6593
- const r = await getRandomBigInteger(two, two.leftShift(nSizeOver3)); // r in [ 2, 2^{|n|/3} ) < p and q
6594
- const rde = r.mul(d).mul(e);
6730
+ const nSizeOver3 = BigInt(Math.floor(bitLength(n) / 3));
6731
+ const r = getRandomBigInteger(_2n, _2n << nSizeOver3); // r in [ 2, 2^{|n|/3} ) < p and q
6732
+ const rde = r * d * e;
6595
6733
 
6596
- const areInverses = rde.mod(p.dec()).equal(r) && rde.mod(q.dec()).equal(r);
6734
+ const areInverses = mod$1(rde, p - _1n$2) === r && mod$1(rde, q - _1n$2) === r;
6597
6735
  if (!areInverses) {
6598
6736
  return false;
6599
6737
  }
@@ -6602,15 +6740,13 @@ async function validateParams$8(n, e, d, p, q, u) {
6602
6740
  }
6603
6741
 
6604
6742
  async function bnSign(hashAlgo, n, d, hashed) {
6605
- const BigInteger = await util.getBigInteger();
6606
-
6607
- n = new BigInteger(n);
6608
- const m = new BigInteger(await emsaEncode(hashAlgo, hashed, n.byteLength()));
6609
- d = new BigInteger(d);
6610
- if (m.gte(n)) {
6743
+ n = uint8ArrayToBigInt(n);
6744
+ const m = uint8ArrayToBigInt(emsaEncode(hashAlgo, hashed, byteLength(n)));
6745
+ d = uint8ArrayToBigInt(d);
6746
+ if (m >= n) {
6611
6747
  throw new Error('Message size cannot exceed modulus size');
6612
6748
  }
6613
- return m.modExp(d, n).toUint8Array('be', n.byteLength());
6749
+ return bigIntToUint8Array(modExp(m, d, n), 'be', byteLength(n));
6614
6750
  }
6615
6751
 
6616
6752
  async function webSign$1(hashName, data, n, e, d, p, q, u) {
@@ -6640,16 +6776,14 @@ async function nodeSign$1(hashAlgo, data, n, e, d, p, q, u) {
6640
6776
  }
6641
6777
 
6642
6778
  async function bnVerify(hashAlgo, s, n, e, hashed) {
6643
- const BigInteger = await util.getBigInteger();
6644
-
6645
- n = new BigInteger(n);
6646
- s = new BigInteger(s);
6647
- e = new BigInteger(e);
6648
- if (s.gte(n)) {
6779
+ n = uint8ArrayToBigInt(n);
6780
+ s = uint8ArrayToBigInt(s);
6781
+ e = uint8ArrayToBigInt(e);
6782
+ if (s >= n) {
6649
6783
  throw new Error('Signature size cannot exceed modulus size');
6650
6784
  }
6651
- const EM1 = s.modExp(e, n).toUint8Array('be', n.byteLength());
6652
- const EM2 = await emsaEncode(hashAlgo, hashed, n.byteLength());
6785
+ const EM1 = bigIntToUint8Array(modExp(s, e, n), 'be', byteLength(n));
6786
+ const EM2 = emsaEncode(hashAlgo, hashed, byteLength(n));
6653
6787
  return util.equalsUint8Array(EM1, EM2);
6654
6788
  }
6655
6789
 
@@ -6671,7 +6805,7 @@ async function nodeVerify$1(hashAlgo, data, s, n, e) {
6671
6805
  verify.end();
6672
6806
 
6673
6807
  try {
6674
- return await verify.verify(key, s);
6808
+ return verify.verify(key, s);
6675
6809
  } catch (err) {
6676
6810
  return false;
6677
6811
  }
@@ -6685,15 +6819,13 @@ async function nodeEncrypt(data, n, e) {
6685
6819
  }
6686
6820
 
6687
6821
  async function bnEncrypt(data, n, e) {
6688
- const BigInteger = await util.getBigInteger();
6689
-
6690
- n = new BigInteger(n);
6691
- data = new BigInteger(emeEncode(data, n.byteLength()));
6692
- e = new BigInteger(e);
6693
- if (data.gte(n)) {
6822
+ n = uint8ArrayToBigInt(n);
6823
+ data = uint8ArrayToBigInt(emeEncode(data, byteLength(n)));
6824
+ e = uint8ArrayToBigInt(e);
6825
+ if (data >= n) {
6694
6826
  throw new Error('Message size cannot exceed modulus size');
6695
6827
  }
6696
- return data.modExp(e, n).toUint8Array('be', n.byteLength());
6828
+ return bigIntToUint8Array(modExp(data, e, n), 'be', byteLength(n));
6697
6829
  }
6698
6830
 
6699
6831
  async function nodeDecrypt(data, n, e, d, p, q, u) {
@@ -6708,36 +6840,32 @@ async function nodeDecrypt(data, n, e, d, p, q, u) {
6708
6840
  }
6709
6841
 
6710
6842
  async function bnDecrypt(data, n, e, d, p, q, u, randomPayload) {
6711
- const BigInteger = await util.getBigInteger();
6712
-
6713
- data = new BigInteger(data);
6714
- n = new BigInteger(n);
6715
- e = new BigInteger(e);
6716
- d = new BigInteger(d);
6717
- p = new BigInteger(p);
6718
- q = new BigInteger(q);
6719
- u = new BigInteger(u);
6720
- if (data.gte(n)) {
6843
+ data = uint8ArrayToBigInt(data);
6844
+ n = uint8ArrayToBigInt(n);
6845
+ e = uint8ArrayToBigInt(e);
6846
+ d = uint8ArrayToBigInt(d);
6847
+ p = uint8ArrayToBigInt(p);
6848
+ q = uint8ArrayToBigInt(q);
6849
+ u = uint8ArrayToBigInt(u);
6850
+ if (data >= n) {
6721
6851
  throw new Error('Data too large.');
6722
6852
  }
6723
- const dq = d.mod(q.dec()); // d mod (q-1)
6724
- const dp = d.mod(p.dec()); // d mod (p-1)
6725
-
6726
- const unblinder = (await getRandomBigInteger(new BigInteger(2), n)).mod(n);
6727
- const blinder = unblinder.modInv(n).modExp(e, n);
6728
- data = data.mul(blinder).mod(n);
6729
-
6853
+ const dq = mod$1(d, q - _1n$2); // d mod (q-1)
6854
+ const dp = mod$1(d, p - _1n$2); // d mod (p-1)
6730
6855
 
6731
- const mp = data.modExp(dp, p); // data**{d mod (q-1)} mod p
6732
- const mq = data.modExp(dq, q); // data**{d mod (p-1)} mod q
6733
- const h = u.mul(mq.sub(mp)).mod(q); // u * (mq-mp) mod q (operands already < q)
6856
+ const unblinder = getRandomBigInteger(BigInt(2), n);
6857
+ const blinder = modExp(modInv(unblinder, n), e, n);
6858
+ data = mod$1(data * blinder, n);
6734
6859
 
6735
- let result = h.mul(p).add(mp); // result < n due to relations above
6860
+ const mp = modExp(data, dp, p); // data**{d mod (q-1)} mod p
6861
+ const mq = modExp(data, dq, q); // data**{d mod (p-1)} mod q
6862
+ const h = mod$1(u * (mq - mp), q); // u * (mq-mp) mod q (operands already < q)
6736
6863
 
6737
- result = result.mul(unblinder).mod(n);
6864
+ let result = h * p + mp; // result < n due to relations above
6738
6865
 
6866
+ result = mod$1(result * unblinder, n);
6739
6867
 
6740
- return emeDecode(result.toUint8Array('be', n.byteLength()), randomPayload);
6868
+ return emeDecode(bigIntToUint8Array(result, 'be', byteLength(n)), randomPayload);
6741
6869
  }
6742
6870
 
6743
6871
  /** Convert Openpgp private key params to jwk key according to
@@ -6751,28 +6879,26 @@ async function bnDecrypt(data, n, e, d, p, q, u, randomPayload) {
6751
6879
  * @param {Uint8Array} u
6752
6880
  */
6753
6881
  async function privateToJWK$1(n, e, d, p, q, u) {
6754
- const BigInteger = await util.getBigInteger();
6755
-
6756
- const pNum = new BigInteger(p);
6757
- const qNum = new BigInteger(q);
6758
- const dNum = new BigInteger(d);
6759
-
6760
- let dq = dNum.mod(qNum.dec()); // d mod (q-1)
6761
- let dp = dNum.mod(pNum.dec()); // d mod (p-1)
6762
- dp = dp.toUint8Array();
6763
- dq = dq.toUint8Array();
6882
+ const pNum = uint8ArrayToBigInt(p);
6883
+ const qNum = uint8ArrayToBigInt(q);
6884
+ const dNum = uint8ArrayToBigInt(d);
6885
+
6886
+ let dq = mod$1(dNum, qNum - _1n$2); // d mod (q-1)
6887
+ let dp = mod$1(dNum, pNum - _1n$2); // d mod (p-1)
6888
+ dp = bigIntToUint8Array(dp);
6889
+ dq = bigIntToUint8Array(dq);
6764
6890
  return {
6765
6891
  kty: 'RSA',
6766
- n: uint8ArrayToB64(n, true),
6767
- e: uint8ArrayToB64(e, true),
6768
- d: uint8ArrayToB64(d, true),
6892
+ n: uint8ArrayToB64(n),
6893
+ e: uint8ArrayToB64(e),
6894
+ d: uint8ArrayToB64(d),
6769
6895
  // switch p and q
6770
- p: uint8ArrayToB64(q, true),
6771
- q: uint8ArrayToB64(p, true),
6896
+ p: uint8ArrayToB64(q),
6897
+ q: uint8ArrayToB64(p),
6772
6898
  // switch dp and dq
6773
- dp: uint8ArrayToB64(dq, true),
6774
- dq: uint8ArrayToB64(dp, true),
6775
- qi: uint8ArrayToB64(u, true),
6899
+ dp: uint8ArrayToB64(dq),
6900
+ dq: uint8ArrayToB64(dp),
6901
+ qi: uint8ArrayToB64(u),
6776
6902
  ext: true
6777
6903
  };
6778
6904
  }
@@ -6786,8 +6912,8 @@ async function privateToJWK$1(n, e, d, p, q, u) {
6786
6912
  function publicToJWK(n, e) {
6787
6913
  return {
6788
6914
  kty: 'RSA',
6789
- n: uint8ArrayToB64(n, true),
6790
- e: uint8ArrayToB64(e, true),
6915
+ n: uint8ArrayToB64(n),
6916
+ e: uint8ArrayToB64(e),
6791
6917
  ext: true
6792
6918
  };
6793
6919
  }
@@ -6796,7 +6922,7 @@ function publicToJWK(n, e) {
6796
6922
  function jwkToPrivate(jwk, e) {
6797
6923
  return {
6798
6924
  n: b64ToUint8Array(jwk.n),
6799
- e: e.toUint8Array(),
6925
+ e: bigIntToUint8Array(e),
6800
6926
  d: b64ToUint8Array(jwk.d),
6801
6927
  // switch p and q
6802
6928
  p: b64ToUint8Array(jwk.q),
@@ -6834,6 +6960,8 @@ var rsa = /*#__PURE__*/Object.freeze({
6834
6960
  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6835
6961
 
6836
6962
 
6963
+ const _1n$1 = BigInt(1);
6964
+
6837
6965
  /**
6838
6966
  * ElGamal Encryption function
6839
6967
  * Note that in OpenPGP, the message needs to be padded with PKCS#1 (same as RSA)
@@ -6845,21 +6973,19 @@ var rsa = /*#__PURE__*/Object.freeze({
6845
6973
  * @async
6846
6974
  */
6847
6975
  async function encrypt$3(data, p, g, y) {
6848
- const BigInteger = await util.getBigInteger();
6849
-
6850
- p = new BigInteger(p);
6851
- g = new BigInteger(g);
6852
- y = new BigInteger(y);
6976
+ p = uint8ArrayToBigInt(p);
6977
+ g = uint8ArrayToBigInt(g);
6978
+ y = uint8ArrayToBigInt(y);
6853
6979
 
6854
- const padded = emeEncode(data, p.byteLength());
6855
- const m = new BigInteger(padded);
6980
+ const padded = emeEncode(data, byteLength(p));
6981
+ const m = uint8ArrayToBigInt(padded);
6856
6982
 
6857
6983
  // OpenPGP uses a "special" version of ElGamal where g is generator of the full group Z/pZ*
6858
6984
  // hence g has order p-1, and to avoid that k = 0 mod p-1, we need to pick k in [1, p-2]
6859
- const k = await getRandomBigInteger(new BigInteger(1), p.dec());
6985
+ const k = getRandomBigInteger(_1n$1, p - _1n$1);
6860
6986
  return {
6861
- c1: g.modExp(k, p).toUint8Array(),
6862
- c2: y.modExp(k, p).imul(m).imod(p).toUint8Array()
6987
+ c1: bigIntToUint8Array(modExp(g, k, p)),
6988
+ c2: bigIntToUint8Array(mod$1(modExp(y, k, p) * m, p))
6863
6989
  };
6864
6990
  }
6865
6991
 
@@ -6876,15 +7002,13 @@ async function encrypt$3(data, p, g, y) {
6876
7002
  * @async
6877
7003
  */
6878
7004
  async function decrypt$3(c1, c2, p, x, randomPayload) {
6879
- const BigInteger = await util.getBigInteger();
6880
-
6881
- c1 = new BigInteger(c1);
6882
- c2 = new BigInteger(c2);
6883
- p = new BigInteger(p);
6884
- x = new BigInteger(x);
7005
+ c1 = uint8ArrayToBigInt(c1);
7006
+ c2 = uint8ArrayToBigInt(c2);
7007
+ p = uint8ArrayToBigInt(p);
7008
+ x = uint8ArrayToBigInt(x);
6885
7009
 
6886
- const padded = c1.modExp(x, p).modInv(p).imul(c2).imod(p);
6887
- return emeDecode(padded.toUint8Array('be', p.byteLength()), randomPayload);
7010
+ const padded = mod$1(modInv(modExp(c1, x, p), p) * c2, p);
7011
+ return emeDecode(bigIntToUint8Array(padded, 'be', byteLength(p)), randomPayload);
6888
7012
  }
6889
7013
 
6890
7014
  /**
@@ -6897,22 +7021,19 @@ async function decrypt$3(c1, c2, p, x, randomPayload) {
6897
7021
  * @async
6898
7022
  */
6899
7023
  async function validateParams$7(p, g, y, x) {
6900
- const BigInteger = await util.getBigInteger();
7024
+ p = uint8ArrayToBigInt(p);
7025
+ g = uint8ArrayToBigInt(g);
7026
+ y = uint8ArrayToBigInt(y);
6901
7027
 
6902
- p = new BigInteger(p);
6903
- g = new BigInteger(g);
6904
- y = new BigInteger(y);
6905
-
6906
- const one = new BigInteger(1);
6907
7028
  // Check that 1 < g < p
6908
- if (g.lte(one) || g.gte(p)) {
7029
+ if (g <= _1n$1 || g >= p) {
6909
7030
  return false;
6910
7031
  }
6911
7032
 
6912
7033
  // Expect p-1 to be large
6913
- const pSize = new BigInteger(p.bitLength());
6914
- const n1023 = new BigInteger(1023);
6915
- if (pSize.lt(n1023)) {
7034
+ const pSize = BigInt(bitLength(p));
7035
+ const _1023n = BigInt(1023);
7036
+ if (pSize < _1023n) {
6916
7037
  return false;
6917
7038
  }
6918
7039
 
@@ -6920,7 +7041,7 @@ async function validateParams$7(p, g, y, x) {
6920
7041
  * g should have order p-1
6921
7042
  * Check that g ** (p-1) = 1 mod p
6922
7043
  */
6923
- if (!g.modExp(p.dec(), p).isOne()) {
7044
+ if (modExp(g, p - _1n$1, p) !== _1n$1) {
6924
7045
  return false;
6925
7046
  }
6926
7047
 
@@ -6931,14 +7052,15 @@ async function validateParams$7(p, g, y, x) {
6931
7052
  * We just check g**i != 1 for all i up to a threshold
6932
7053
  */
6933
7054
  let res = g;
6934
- const i = new BigInteger(1);
6935
- const threshold = new BigInteger(2).leftShift(new BigInteger(17)); // we want order > threshold
6936
- while (i.lt(threshold)) {
6937
- res = res.mul(g).imod(p);
6938
- if (res.isOne()) {
7055
+ let i = BigInt(1);
7056
+ const _2n = BigInt(2);
7057
+ const threshold = _2n << BigInt(17); // we want order > threshold
7058
+ while (i < threshold) {
7059
+ res = mod$1(res * g, p);
7060
+ if (res === _1n$1) {
6939
7061
  return false;
6940
7062
  }
6941
- i.iinc();
7063
+ i++;
6942
7064
  }
6943
7065
 
6944
7066
  /**
@@ -6947,11 +7069,10 @@ async function validateParams$7(p, g, y, x) {
6947
7069
  *
6948
7070
  * Blinded exponentiation computes g**{r(p-1) + x} to compare to y
6949
7071
  */
6950
- x = new BigInteger(x);
6951
- const two = new BigInteger(2);
6952
- const r = await getRandomBigInteger(two.leftShift(pSize.dec()), two.leftShift(pSize)); // draw r of same size as p-1
6953
- const rqx = p.dec().imul(r).iadd(x);
6954
- if (!y.equal(g.modExp(rqx, p))) {
7072
+ x = uint8ArrayToBigInt(x);
7073
+ const r = getRandomBigInteger(_2n << (pSize - _1n$1), _2n << pSize); // draw r of same size as p-1
7074
+ const rqx = (p - _1n$1) * r + x;
7075
+ if (y !== modExp(g, rqx, p)) {
6955
7076
  return false;
6956
7077
  }
6957
7078
 
@@ -9095,8 +9216,8 @@ function rawPublicToJWK(payloadSize, name, publicKey) {
9095
9216
  const jwk = {
9096
9217
  kty: 'EC',
9097
9218
  crv: name,
9098
- x: uint8ArrayToB64(bufX, true),
9099
- y: uint8ArrayToB64(bufY, true),
9219
+ x: uint8ArrayToB64(bufX),
9220
+ y: uint8ArrayToB64(bufY),
9100
9221
  ext: true
9101
9222
  };
9102
9223
  return jwk;
@@ -9112,7 +9233,7 @@ function rawPublicToJWK(payloadSize, name, publicKey) {
9112
9233
  */
9113
9234
  function privateToJWK(payloadSize, name, publicKey, privateKey) {
9114
9235
  const jwk = rawPublicToJWK(payloadSize, name, publicKey);
9115
- jwk.d = uint8ArrayToB64(privateKey, true);
9236
+ jwk.d = uint8ArrayToB64(privateKey);
9116
9237
  return jwk;
9117
9238
  }
9118
9239
 
@@ -9180,8 +9301,8 @@ async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9180
9301
  // lowS: non-canonical sig: https://stackoverflow.com/questions/74338846/ecdsa-signature-verification-mismatch
9181
9302
  const signature = nobleCurve.sign(hashed, privateKey, { lowS: false });
9182
9303
  return {
9183
- r: signature.r.toUint8Array('be', curve.payloadSize),
9184
- s: signature.s.toUint8Array('be', curve.payloadSize)
9304
+ r: bigIntToUint8Array(signature.r, 'be', curve.payloadSize),
9305
+ s: bigIntToUint8Array(signature.s, 'be', curve.payloadSize)
9185
9306
  };
9186
9307
  }
9187
9308
 
@@ -9264,6 +9385,7 @@ async function validateParams$6(oid, Q, d) {
9264
9385
  const hashed = await hash.digest(hashAlgo, message);
9265
9386
  try {
9266
9387
  const signature = await sign$6(oid, hashAlgo, message, Q, d, hashed);
9388
+ // eslint-disable-next-line @typescript-eslint/return-await
9267
9389
  return await verify$6(oid, hashAlgo, signature, message, Q, hashed);
9268
9390
  } catch (err) {
9269
9391
  return false;
@@ -10522,6 +10644,9 @@ var elliptic = /*#__PURE__*/Object.freeze({
10522
10644
  https://tools.ietf.org/html/rfc4880#section-14
10523
10645
  */
10524
10646
 
10647
+ const _0n = BigInt(0);
10648
+ const _1n = BigInt(1);
10649
+
10525
10650
  /**
10526
10651
  * DSA Sign function
10527
10652
  * @param {Integer} hashAlgo
@@ -10534,26 +10659,24 @@ var elliptic = /*#__PURE__*/Object.freeze({
10534
10659
  * @async
10535
10660
  */
10536
10661
  async function sign$3(hashAlgo, hashed, g, p, q, x) {
10537
- const BigInteger = await util.getBigInteger();
10538
-
10539
- const one = new BigInteger(1);
10540
- p = new BigInteger(p);
10541
- q = new BigInteger(q);
10542
- g = new BigInteger(g);
10543
- x = new BigInteger(x);
10662
+ const _0n = BigInt(0);
10663
+ p = uint8ArrayToBigInt(p);
10664
+ q = uint8ArrayToBigInt(q);
10665
+ g = uint8ArrayToBigInt(g);
10666
+ x = uint8ArrayToBigInt(x);
10544
10667
 
10545
10668
  let k;
10546
10669
  let r;
10547
10670
  let s;
10548
10671
  let t;
10549
- g = g.mod(p);
10550
- x = x.mod(q);
10672
+ g = mod$1(g, p);
10673
+ x = mod$1(x, q);
10551
10674
  // If the output size of the chosen hash is larger than the number of
10552
10675
  // bits of q, the hash result is truncated to fit by taking the number
10553
10676
  // of leftmost bits equal to the number of bits of q. This (possibly
10554
10677
  // truncated) hash function result is treated as a number and used
10555
10678
  // directly in the DSA signature algorithm.
10556
- const h = new BigInteger(hashed.subarray(0, q.byteLength())).mod(q);
10679
+ const h = mod$1(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
10557
10680
  // FIPS-186-4, section 4.6:
10558
10681
  // The values of r and s shall be checked to determine if r = 0 or s = 0.
10559
10682
  // If either r = 0 or s = 0, a new value of k shall be generated, and the
@@ -10561,22 +10684,22 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
10561
10684
  // or s = 0 if signatures are generated properly.
10562
10685
  while (true) {
10563
10686
  // See Appendix B here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
10564
- k = await getRandomBigInteger(one, q); // returns in [1, q-1]
10565
- r = g.modExp(k, p).imod(q); // (g**k mod p) mod q
10566
- if (r.isZero()) {
10687
+ k = getRandomBigInteger(_1n, q); // returns in [1, q-1]
10688
+ r = mod$1(modExp(g, k, p), q); // (g**k mod p) mod q
10689
+ if (r === _0n) {
10567
10690
  continue;
10568
10691
  }
10569
- const xr = x.mul(r).imod(q);
10570
- t = h.add(xr).imod(q); // H(m) + x*r mod q
10571
- s = k.modInv(q).imul(t).imod(q); // k**-1 * (H(m) + x*r) mod q
10572
- if (s.isZero()) {
10692
+ const xr = mod$1(x * r, q);
10693
+ t = mod$1(h + xr, q); // H(m) + x*r mod q
10694
+ s = mod$1(modInv(k, q) * t, q); // k**-1 * (H(m) + x*r) mod q
10695
+ if (s === _0n) {
10573
10696
  continue;
10574
10697
  }
10575
10698
  break;
10576
10699
  }
10577
10700
  return {
10578
- r: r.toUint8Array('be', q.byteLength()),
10579
- s: s.toUint8Array('be', q.byteLength())
10701
+ r: bigIntToUint8Array(r, 'be', byteLength(p)),
10702
+ s: bigIntToUint8Array(s, 'be', byteLength(p))
10580
10703
  };
10581
10704
  }
10582
10705
 
@@ -10594,37 +10717,34 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
10594
10717
  * @async
10595
10718
  */
10596
10719
  async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
10597
- const BigInteger = await util.getBigInteger();
10598
-
10599
- const zero = new BigInteger(0);
10600
- r = new BigInteger(r);
10601
- s = new BigInteger(s);
10720
+ r = uint8ArrayToBigInt(r);
10721
+ s = uint8ArrayToBigInt(s);
10602
10722
 
10603
- p = new BigInteger(p);
10604
- q = new BigInteger(q);
10605
- g = new BigInteger(g);
10606
- y = new BigInteger(y);
10723
+ p = uint8ArrayToBigInt(p);
10724
+ q = uint8ArrayToBigInt(q);
10725
+ g = uint8ArrayToBigInt(g);
10726
+ y = uint8ArrayToBigInt(y);
10607
10727
 
10608
- if (r.lte(zero) || r.gte(q) ||
10609
- s.lte(zero) || s.gte(q)) {
10728
+ if (r <= _0n || r >= q ||
10729
+ s <= _0n || s >= q) {
10610
10730
  util.printDebug('invalid DSA Signature');
10611
10731
  return false;
10612
10732
  }
10613
- const h = new BigInteger(hashed.subarray(0, q.byteLength())).imod(q);
10614
- const w = s.modInv(q); // s**-1 mod q
10615
- if (w.isZero()) {
10733
+ const h = mod$1(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
10734
+ const w = modInv(s, q); // s**-1 mod q
10735
+ if (w === _0n) {
10616
10736
  util.printDebug('invalid DSA Signature');
10617
10737
  return false;
10618
10738
  }
10619
10739
 
10620
- g = g.mod(p);
10621
- y = y.mod(p);
10622
- const u1 = h.mul(w).imod(q); // H(m) * w mod q
10623
- const u2 = r.mul(w).imod(q); // r * w mod q
10624
- const t1 = g.modExp(u1, p); // g**u1 mod p
10625
- const t2 = y.modExp(u2, p); // y**u2 mod p
10626
- const v = t1.mul(t2).imod(p).imod(q); // (g**u1 * y**u2 mod p) mod q
10627
- return v.equal(r);
10740
+ g = mod$1(g, p);
10741
+ y = mod$1(y, p);
10742
+ const u1 = mod$1(h * w, q); // H(m) * w mod q
10743
+ const u2 = mod$1(r * w, q); // r * w mod q
10744
+ const t1 = modExp(g, u1, p); // g**u1 mod p
10745
+ const t2 = modExp(y, u2, p); // y**u2 mod p
10746
+ const v = mod$1(mod$1(t1 * t2, p), q); // (g**u1 * y**u2 mod p) mod q
10747
+ return v === r;
10628
10748
  }
10629
10749
 
10630
10750
  /**
@@ -10638,22 +10758,19 @@ async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
10638
10758
  * @async
10639
10759
  */
10640
10760
  async function validateParams$1(p, q, g, y, x) {
10641
- const BigInteger = await util.getBigInteger();
10642
-
10643
- p = new BigInteger(p);
10644
- q = new BigInteger(q);
10645
- g = new BigInteger(g);
10646
- y = new BigInteger(y);
10647
- const one = new BigInteger(1);
10761
+ p = uint8ArrayToBigInt(p);
10762
+ q = uint8ArrayToBigInt(q);
10763
+ g = uint8ArrayToBigInt(g);
10764
+ y = uint8ArrayToBigInt(y);
10648
10765
  // Check that 1 < g < p
10649
- if (g.lte(one) || g.gte(p)) {
10766
+ if (g <= _1n || g >= p) {
10650
10767
  return false;
10651
10768
  }
10652
10769
 
10653
10770
  /**
10654
10771
  * Check that subgroup order q divides p-1
10655
10772
  */
10656
- if (!p.dec().mod(q).isZero()) {
10773
+ if (mod$1(p - _1n, q) !== _0n) {
10657
10774
  return false;
10658
10775
  }
10659
10776
 
@@ -10661,16 +10778,16 @@ async function validateParams$1(p, q, g, y, x) {
10661
10778
  * g has order q
10662
10779
  * Check that g ** q = 1 mod p
10663
10780
  */
10664
- if (!g.modExp(q, p).isOne()) {
10781
+ if (modExp(g, q, p) !== _1n) {
10665
10782
  return false;
10666
10783
  }
10667
10784
 
10668
10785
  /**
10669
10786
  * Check q is large and probably prime (we mainly want to avoid small factors)
10670
10787
  */
10671
- const qSize = new BigInteger(q.bitLength());
10672
- const n150 = new BigInteger(150);
10673
- if (qSize.lt(n150) || !(await isProbablePrime(q, null, 32))) {
10788
+ const qSize = BigInt(bitLength(q));
10789
+ const _150n = BigInt(150);
10790
+ if (qSize < _150n || !isProbablePrime(q, null, 32)) {
10674
10791
  return false;
10675
10792
  }
10676
10793
 
@@ -10680,11 +10797,11 @@ async function validateParams$1(p, q, g, y, x) {
10680
10797
  *
10681
10798
  * Blinded exponentiation computes g**{rq + x} to compare to y
10682
10799
  */
10683
- x = new BigInteger(x);
10684
- const two = new BigInteger(2);
10685
- const r = await getRandomBigInteger(two.leftShift(qSize.dec()), two.leftShift(qSize)); // draw r of same size as q
10686
- const rqx = q.mul(r).add(x);
10687
- if (!y.equal(g.modExp(rqx, p))) {
10800
+ x = uint8ArrayToBigInt(x);
10801
+ const _2n = BigInt(2);
10802
+ const r = getRandomBigInteger(_2n << (qSize - _1n), _2n << qSize); // draw r of same size as q
10803
+ const rqx = q * r + x;
10804
+ if (y !== modExp(g, rqx, p)) {
10688
10805
  return false;
10689
10806
  }
10690
10807
 
@@ -16057,7 +16174,7 @@ async function runAEAD(packet, fn, key, data) {
16057
16174
  done = true;
16058
16175
  }
16059
16176
  cryptedBytes += chunk.length - tagLengthIfDecrypting;
16060
- // eslint-disable-next-line no-loop-func
16177
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
16061
16178
  latestPromise = latestPromise.then(() => cryptedPromise).then(async crypted => {
16062
16179
  await writer.ready;
16063
16180
  await writer.write(crypted);
@@ -17193,7 +17310,7 @@ class PublicSubkeyPacket extends PublicKeyPacket {
17193
17310
  * @param {Date} [date] - Creation date
17194
17311
  * @param {Object} [config] - Full configuration, defaults to openpgp.config
17195
17312
  */
17196
- // eslint-disable-next-line no-useless-constructor
17313
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
17197
17314
  constructor(date, config) {
17198
17315
  super(date, config);
17199
17316
  }
@@ -18098,7 +18215,7 @@ class PaddingPacket {
18098
18215
  * Read a padding packet
18099
18216
  * @param {Uint8Array | ReadableStream<Uint8Array>} bytes
18100
18217
  */
18101
- read(bytes) { // eslint-disable-line no-unused-vars
18218
+ read(bytes) { // eslint-disable-line @typescript-eslint/no-unused-vars
18102
18219
  // Padding packets are ignored, so this function is never called.
18103
18220
  }
18104
18221
 
@@ -19652,6 +19769,7 @@ class Key {
19652
19769
  }
19653
19770
  }
19654
19771
  if (!users.length) {
19772
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
19655
19773
  throw exception || new Error('Could not find primary user');
19656
19774
  }
19657
19775
  await Promise.all(users.map(async function (a) {
@@ -20562,7 +20680,12 @@ async function readKey({ armoredKey, binaryKey, config: config$1, ...rest }) {
20562
20680
  input = binaryKey;
20563
20681
  }
20564
20682
  const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config$1);
20565
- return createKey(packetlist);
20683
+ const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
20684
+ if (keyIndex.length === 0) {
20685
+ throw new Error('No key packet found');
20686
+ }
20687
+ const firstKeyPacketList = packetlist.slice(keyIndex[0], keyIndex[1]);
20688
+ return createKey(firstKeyPacketList);
20566
20689
  }
20567
20690
 
20568
20691
  /**
@@ -20599,7 +20722,15 @@ async function readPrivateKey({ armoredKey, binaryKey, config: config$1, ...rest
20599
20722
  input = binaryKey;
20600
20723
  }
20601
20724
  const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config$1);
20602
- return new PrivateKey(packetlist);
20725
+ const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
20726
+ for (let i = 0; i < keyIndex.length; i++) {
20727
+ if (packetlist[keyIndex[i]].constructor.tag === enums.packet.publicKey) {
20728
+ continue;
20729
+ }
20730
+ const firstPrivateKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
20731
+ return new PrivateKey(firstPrivateKeyList);
20732
+ }
20733
+ throw new Error('No secret key packet found');
20603
20734
  }
20604
20735
 
20605
20736
  /**
@@ -20678,15 +20809,18 @@ async function readPrivateKeys({ armoredKeys, binaryKeys, config: config$1 }) {
20678
20809
  }
20679
20810
  const keys = [];
20680
20811
  const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config$1);
20681
- const keyIndex = packetlist.indexOfTag(enums.packet.secretKey);
20682
- if (keyIndex.length === 0) {
20683
- throw new Error('No secret key packet found');
20684
- }
20812
+ const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
20685
20813
  for (let i = 0; i < keyIndex.length; i++) {
20814
+ if (packetlist[keyIndex[i]].constructor.tag === enums.packet.publicKey) {
20815
+ continue;
20816
+ }
20686
20817
  const oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
20687
20818
  const newKey = new PrivateKey(oneKeyList);
20688
20819
  keys.push(newKey);
20689
20820
  }
20821
+ if (keys.length === 0) {
20822
+ throw new Error('No secret key packet found');
20823
+ }
20690
20824
  return keys;
20691
20825
  }
20692
20826
 
@@ -22100,7 +22234,7 @@ async function encrypt({ message, encryptionKeys, signingKeys, passwords, sessio
22100
22234
  // serialize data
22101
22235
  const armor = format === 'armored';
22102
22236
  const data = armor ? message.armor(config$1) : message.write();
22103
- return convertStream(data);
22237
+ return await convertStream(data);
22104
22238
  } catch (err) {
22105
22239
  throw util.wrapError('Error encrypting message', err);
22106
22240
  }
@@ -22237,7 +22371,7 @@ async function sign({ message, signingKeys, format = 'armored', detached = false
22237
22371
  ]);
22238
22372
  });
22239
22373
  }
22240
- return convertStream(signature);
22374
+ return await convertStream(signature);
22241
22375
  } catch (err) {
22242
22376
  throw util.wrapError('Error signing message', err);
22243
22377
  }
@@ -22420,12 +22554,12 @@ async function decryptSessionKeys({ message, decryptionKeys, passwords, date = n
22420
22554
  */
22421
22555
  function checkString(data, name) {
22422
22556
  if (!util.isString(data)) {
22423
- throw new Error('Parameter [' + (name || 'data') + '] must be of type String');
22557
+ throw new Error('Parameter [' + (name ) + '] must be of type String');
22424
22558
  }
22425
22559
  }
22426
22560
  function checkBinary(data, name) {
22427
22561
  if (!util.isUint8Array(data)) {
22428
- throw new Error('Parameter [' + (name || 'data') + '] must be of type Uint8Array');
22562
+ throw new Error('Parameter [' + ('data') + '] must be of type Uint8Array');
22429
22563
  }
22430
22564
  }
22431
22565
  function checkMessage(message) {