@protontech/openpgp 5.7.0 → 5.8.0-0

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.
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v5.7.0 - 2023-03-06 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v5.8.0-0 - 2023-03-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
  import buffer from 'buffer';
@@ -2110,14 +2110,14 @@ const util = {
2110
2110
  * provided with the application or distribution.
2111
2111
  */
2112
2112
 
2113
- const Buffer = util.getNodeBuffer();
2113
+ const Buffer$1 = util.getNodeBuffer();
2114
2114
 
2115
2115
  let encodeChunk;
2116
2116
  let decodeChunk;
2117
- if (Buffer) {
2118
- encodeChunk = buf => Buffer.from(buf).toString('base64');
2117
+ if (Buffer$1) {
2118
+ encodeChunk = buf => Buffer$1.from(buf).toString('base64');
2119
2119
  decodeChunk = str => {
2120
- const b = Buffer.from(str, 'base64');
2120
+ const b = Buffer$1.from(str, 'base64');
2121
2121
  return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
2122
2122
  };
2123
2123
  } else {
@@ -2309,6 +2309,7 @@ var enums = {
2309
2309
  simple: 0,
2310
2310
  salted: 1,
2311
2311
  iterated: 3,
2312
+ argon2: 4,
2312
2313
  gnu: 101
2313
2314
  },
2314
2315
 
@@ -2773,12 +2774,41 @@ var config = {
2773
2774
  */
2774
2775
  v5Keys: false,
2775
2776
  /**
2776
- * {@link https://tools.ietf.org/html/rfc4880#section-3.7.1.3|RFC4880 3.7.1.3}:
2777
- * Iteration Count Byte for S2K (String to Key)
2777
+ * S2K (String to Key) type, used for key derivation in the context of secret key encryption
2778
+ * and password-encrypted data. Weaker s2k options are not allowed.
2779
+ * Note: Argon2 is the strongest option but not all OpenPGP implementations are compatible with it
2780
+ * (pending standardisation).
2781
+ * @memberof module:config
2782
+ * @property {enums.s2k.argon2|enums.s2k.iterated} s2kType {@link module:enums.s2k}
2783
+ */
2784
+ s2kType: enums.s2k.iterated,
2785
+ /**
2786
+ * {@link https://tools.ietf.org/html/rfc4880#section-3.7.1.3| RFC4880 3.7.1.3}:
2787
+ * Iteration Count Byte for Iterated and Salted S2K (String to Key).
2788
+ * Only relevant if `config.s2kType` is set to `enums.s2k.iterated`.
2789
+ * Note: this is the exponent value, not the final number of iterations (refer to specs for more details).
2778
2790
  * @memberof module:config
2779
2791
  * @property {Integer} s2kIterationCountByte
2780
2792
  */
2781
2793
  s2kIterationCountByte: 224,
2794
+ /**
2795
+ * {@link https://tools.ietf.org/html/draft-ietf-openpgp-crypto-refresh-07.html#section-3.7.1.4| draft-crypto-refresh 3.7.1.4}:
2796
+ * Argon2 parameters for S2K (String to Key).
2797
+ * Only relevant if `config.s2kType` is set to `enums.s2k.argon2`.
2798
+ * Default settings correspond to the second recommendation from RFC9106 ("uniformly safe option"),
2799
+ * to ensure compatibility with memory-constrained environments.
2800
+ * For more details on the choice of parameters, see https://tools.ietf.org/html/rfc9106#section-4.
2801
+ * @memberof module:config
2802
+ * @property {Object} params
2803
+ * @property {Integer} params.passes - number of iterations t
2804
+ * @property {Integer} params.parallelism - degree of parallelism p
2805
+ * @property {Integer} params.memoryExponent - one-octet exponent indicating the memory size, which will be: 2**memoryExponent kibibytes.
2806
+ */
2807
+ s2kArgon2Params: {
2808
+ passes: 3,
2809
+ parallelism: 4, // lanes
2810
+ memoryExponent: 16 // 64 MiB of RAM
2811
+ },
2782
2812
  /**
2783
2813
  * Allow decryption of messages without integrity protection.
2784
2814
  * This is an **insecure** setting:
@@ -2888,7 +2918,7 @@ var config = {
2888
2918
  * @memberof module:config
2889
2919
  * @property {String} versionString A version string to be included in armored messages
2890
2920
  */
2891
- versionString: 'OpenPGP.js 5.7.0',
2921
+ versionString: 'OpenPGP.js 5.8.0-0',
2892
2922
  /**
2893
2923
  * @memberof module:config
2894
2924
  * @property {String} commentString A comment string to be included in armored messages
@@ -10236,7 +10266,7 @@ async function CBC(key) {
10236
10266
 
10237
10267
  const webCrypto$3 = util.getWebCrypto();
10238
10268
  const nodeCrypto$3 = util.getNodeCrypto();
10239
- const Buffer$1 = util.getNodeBuffer();
10269
+ const Buffer$2 = util.getNodeBuffer();
10240
10270
 
10241
10271
 
10242
10272
  const blockLength$1 = 16;
@@ -10268,7 +10298,7 @@ async function CTR(key) {
10268
10298
  if (util.getNodeCrypto()) { // Node crypto library
10269
10299
  return async function(pt, iv) {
10270
10300
  const en = new nodeCrypto$3.createCipheriv('aes-' + (key.length * 8) + '-ctr', key, iv);
10271
- const ct = Buffer$1.concat([en.update(pt), en.final()]);
10301
+ const ct = Buffer$2.concat([en.update(pt), en.final()]);
10272
10302
  return new Uint8Array(ct);
10273
10303
  };
10274
10304
  }
@@ -10905,7 +10935,7 @@ class AES_GCM {
10905
10935
 
10906
10936
  const webCrypto$4 = util.getWebCrypto();
10907
10937
  const nodeCrypto$4 = util.getNodeCrypto();
10908
- const Buffer$2 = util.getNodeBuffer();
10938
+ const Buffer$3 = util.getNodeBuffer();
10909
10939
 
10910
10940
  const blockLength$3 = 16;
10911
10941
  const ivLength$2 = 12; // size of the IV in bytes
@@ -10951,7 +10981,7 @@ async function GCM(cipher, key) {
10951
10981
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
10952
10982
  const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10953
10983
  en.setAAD(adata);
10954
- const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
10984
+ const ct = Buffer$3.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
10955
10985
  return new Uint8Array(ct);
10956
10986
  },
10957
10987
 
@@ -10959,7 +10989,7 @@ async function GCM(cipher, key) {
10959
10989
  const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10960
10990
  de.setAAD(adata);
10961
10991
  de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
10962
- const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
10992
+ const pt = Buffer$3.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
10963
10993
  return new Uint8Array(pt);
10964
10994
  }
10965
10995
  };
@@ -15881,6 +15911,339 @@ const mod = {
15881
15911
 
15882
15912
  Object.assign(mod, crypto$1);
15883
15913
 
15914
+ const ARGON2_TYPE = 0x02; // id
15915
+ const ARGON2_VERSION = 0x13;
15916
+ const ARGON2_SALT_SIZE = 16;
15917
+
15918
+ class Argon2OutOfMemoryError extends Error {
15919
+ constructor(...params) {
15920
+ super(...params);
15921
+
15922
+ if (Error.captureStackTrace) {
15923
+ Error.captureStackTrace(this, Argon2OutOfMemoryError);
15924
+ }
15925
+
15926
+ this.name = 'Argon2OutOfMemoryError';
15927
+ }
15928
+ }
15929
+
15930
+ // cache argon wasm module
15931
+ let loadArgonWasmModule;
15932
+ let argon2Promise;
15933
+ // reload wasm module above this treshold, to deallocated used memory
15934
+ const ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = 2 << 19;
15935
+
15936
+ class Argon2S2K {
15937
+ /**
15938
+ * @param {Object} [config] - Full configuration, defaults to openpgp.config
15939
+ */
15940
+ constructor(config$1 = config) {
15941
+ const { passes, parallelism, memoryExponent } = config$1.s2kArgon2Params;
15942
+
15943
+ this.type = 'argon2';
15944
+ /** @type {Uint8Array} 16 bytes of salt */
15945
+ this.salt = null;
15946
+ /** @type {Integer} number of passes */
15947
+ this.t = passes;
15948
+ /** @type {Integer} degree of parallelism (lanes) */
15949
+ this.p = parallelism;
15950
+ /** @type {Integer} exponent indicating memory size */
15951
+ this.encodedM = memoryExponent;
15952
+ }
15953
+
15954
+ generateSalt() {
15955
+ this.salt = mod.random.getRandomBytes(ARGON2_SALT_SIZE);
15956
+ }
15957
+
15958
+ /**
15959
+ * Parsing function for argon2 string-to-key specifier.
15960
+ * @param {Uint8Array} bytes - Payload of argon2 string-to-key specifier
15961
+ * @returns {Integer} Actual length of the object.
15962
+ */
15963
+ read(bytes) {
15964
+ let i = 0;
15965
+
15966
+ this.salt = bytes.subarray(i, i + 16);
15967
+ i += 16;
15968
+
15969
+ this.t = bytes[i++];
15970
+ this.p = bytes[i++];
15971
+ this.encodedM = bytes[i++]; // memory size exponent, one-octect
15972
+
15973
+ return i;
15974
+ }
15975
+
15976
+ /**
15977
+ * Serializes s2k information
15978
+ * @returns {Uint8Array} Binary representation of s2k.
15979
+ */
15980
+ write() {
15981
+ const arr = [
15982
+ new Uint8Array([enums.write(enums.s2k, this.type)]),
15983
+ this.salt,
15984
+ new Uint8Array([this.t, this.p, this.encodedM])
15985
+ ];
15986
+
15987
+ return util.concatUint8Array(arr);
15988
+ }
15989
+
15990
+ /**
15991
+ * Produces a key using the specified passphrase and the defined
15992
+ * hashAlgorithm
15993
+ * @param {String} passphrase - Passphrase containing user input
15994
+ * @returns {Promise<Uint8Array>} Produced key with a length corresponding to `keySize`
15995
+ * @throws {Argon2OutOfMemoryError|Errors}
15996
+ * @async
15997
+ */
15998
+ async produceKey(passphrase, keySize) {
15999
+ const decodedM = 2 << (this.encodedM - 1);
16000
+
16001
+ try {
16002
+ if (!argon2Promise) { // first load
16003
+ loadArgonWasmModule = loadArgonWasmModule || (await Promise.resolve().then(function () { return index; })).default;
16004
+ argon2Promise = loadArgonWasmModule();
16005
+ }
16006
+ // important to keep local ref to argon2 in case the module is reloaded by another instance
16007
+ const argon2 = await argon2Promise;
16008
+
16009
+ const passwordBytes = util.encodeUTF8(passphrase);
16010
+ const hash = argon2({
16011
+ version: ARGON2_VERSION,
16012
+ type: ARGON2_TYPE,
16013
+ password: passwordBytes,
16014
+ salt: this.salt,
16015
+ tagLength: keySize,
16016
+ memorySize: decodedM,
16017
+ parallelism: this.p,
16018
+ passes: this.t
16019
+ });
16020
+
16021
+ // a lot of memory was used, reload to deallocate
16022
+ if (decodedM > ARGON2_WASM_MEMORY_THRESHOLD_RELOAD) {
16023
+ // it will be awaited if needed at the next `produceKey` invocation
16024
+ argon2Promise = loadArgonWasmModule();
16025
+ }
16026
+ return hash;
16027
+ } catch (e) {
16028
+ if (e.message && (
16029
+ e.message.includes('Unable to grow instance memory') || // Chrome
16030
+ e.message.includes('failed to grow memory') || // Firefox
16031
+ e.message.includes('WebAssembly.Memory.grow') || // Safari
16032
+ e.message.includes('Out of memory') // Safari iOS
16033
+ )) {
16034
+ throw new Argon2OutOfMemoryError('Could not allocate required memory for Argon2');
16035
+ } else {
16036
+ throw e;
16037
+ }
16038
+ }
16039
+ }
16040
+ }
16041
+
16042
+ // GPG4Browsers - An OpenPGP implementation in javascript
16043
+
16044
+ class GenericS2K {
16045
+ /**
16046
+ * @param {Object} [config] - Full configuration, defaults to openpgp.config
16047
+ */
16048
+ constructor(s2kType, config$1 = config) {
16049
+ /**
16050
+ * Hash function identifier, or 0 for gnu-dummy keys
16051
+ * @type {module:enums.hash | 0}
16052
+ */
16053
+ this.algorithm = enums.hash.sha256;
16054
+ /**
16055
+ * enums.s2k identifier or 'gnu-dummy'
16056
+ * @type {String}
16057
+ */
16058
+ this.type = enums.read(enums.s2k, s2kType);
16059
+ /** @type {Integer} */
16060
+ this.c = config$1.s2kIterationCountByte;
16061
+ /** Eight bytes of salt in a binary string.
16062
+ * @type {Uint8Array}
16063
+ */
16064
+ this.salt = null;
16065
+ }
16066
+
16067
+ generateSalt() {
16068
+ switch (this.type) {
16069
+ case 'salted':
16070
+ case 'iterated':
16071
+ this.salt = mod.random.getRandomBytes(8);
16072
+ }
16073
+ }
16074
+
16075
+ getCount() {
16076
+ // Exponent bias, defined in RFC4880
16077
+ const expbias = 6;
16078
+
16079
+ return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
16080
+ }
16081
+
16082
+ /**
16083
+ * Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
16084
+ * @param {Uint8Array} bytes - Payload of string-to-key specifier
16085
+ * @returns {Integer} Actual length of the object.
16086
+ */
16087
+ read(bytes) {
16088
+ let i = 0;
16089
+ this.algorithm = bytes[i++];
16090
+
16091
+ switch (this.type) {
16092
+ case 'simple':
16093
+ break;
16094
+
16095
+ case 'salted':
16096
+ this.salt = bytes.subarray(i, i + 8);
16097
+ i += 8;
16098
+ break;
16099
+
16100
+ case 'iterated':
16101
+ this.salt = bytes.subarray(i, i + 8);
16102
+ i += 8;
16103
+
16104
+ // Octet 10: count, a one-octet, coded value
16105
+ this.c = bytes[i++];
16106
+ break;
16107
+ case 'gnu':
16108
+ if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === 'GNU') {
16109
+ i += 3; // GNU
16110
+ const gnuExtType = 1000 + bytes[i++];
16111
+ if (gnuExtType === 1001) {
16112
+ this.type = 'gnu-dummy';
16113
+ // GnuPG extension mode 1001 -- don't write secret key at all
16114
+ } else {
16115
+ throw new Error('Unknown s2k gnu protection mode.');
16116
+ }
16117
+ } else {
16118
+ throw new Error('Unknown s2k type.');
16119
+ }
16120
+ break;
16121
+
16122
+ default:
16123
+ throw new Error('Unknown s2k type.');
16124
+ }
16125
+
16126
+ return i;
16127
+ }
16128
+
16129
+ /**
16130
+ * Serializes s2k information
16131
+ * @returns {Uint8Array} Binary representation of s2k.
16132
+ */
16133
+ write() {
16134
+ if (this.type === 'gnu-dummy') {
16135
+ return new Uint8Array([101, 0, ...util.stringToUint8Array('GNU'), 1]);
16136
+ }
16137
+ const arr = [new Uint8Array([enums.write(enums.s2k, this.type), this.algorithm])];
16138
+
16139
+ switch (this.type) {
16140
+ case 'simple':
16141
+ break;
16142
+ case 'salted':
16143
+ arr.push(this.salt);
16144
+ break;
16145
+ case 'iterated':
16146
+ arr.push(this.salt);
16147
+ arr.push(new Uint8Array([this.c]));
16148
+ break;
16149
+ case 'gnu':
16150
+ throw new Error('GNU s2k type not supported.');
16151
+ default:
16152
+ throw new Error('Unknown s2k type.');
16153
+ }
16154
+
16155
+ return util.concatUint8Array(arr);
16156
+ }
16157
+
16158
+ /**
16159
+ * Produces a key using the specified passphrase and the defined
16160
+ * hashAlgorithm
16161
+ * @param {String} passphrase - Passphrase containing user input
16162
+ * @returns {Promise<Uint8Array>} Produced key with a length corresponding to.
16163
+ * hashAlgorithm hash length
16164
+ * @async
16165
+ */
16166
+ async produceKey(passphrase, numBytes) {
16167
+ passphrase = util.encodeUTF8(passphrase);
16168
+
16169
+ const arr = [];
16170
+ let rlength = 0;
16171
+
16172
+ let prefixlen = 0;
16173
+ while (rlength < numBytes) {
16174
+ let toHash;
16175
+ switch (this.type) {
16176
+ case 'simple':
16177
+ toHash = util.concatUint8Array([new Uint8Array(prefixlen), passphrase]);
16178
+ break;
16179
+ case 'salted':
16180
+ toHash = util.concatUint8Array([new Uint8Array(prefixlen), this.salt, passphrase]);
16181
+ break;
16182
+ case 'iterated': {
16183
+ const data = util.concatUint8Array([this.salt, passphrase]);
16184
+ let datalen = data.length;
16185
+ const count = Math.max(this.getCount(), datalen);
16186
+ toHash = new Uint8Array(prefixlen + count);
16187
+ toHash.set(data, prefixlen);
16188
+ for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
16189
+ toHash.copyWithin(pos, prefixlen, pos);
16190
+ }
16191
+ break;
16192
+ }
16193
+ case 'gnu':
16194
+ throw new Error('GNU s2k type not supported.');
16195
+ default:
16196
+ throw new Error('Unknown s2k type.');
16197
+ }
16198
+ const result = await mod.hash.digest(this.algorithm, toHash);
16199
+ arr.push(result);
16200
+ rlength += result.length;
16201
+ prefixlen++;
16202
+ }
16203
+
16204
+ return util.concatUint8Array(arr).subarray(0, numBytes);
16205
+ }
16206
+ }
16207
+
16208
+ const allowedS2KTypesForEncryption = new Set([enums.s2k.argon2, enums.s2k.iterated]);
16209
+
16210
+ /**
16211
+ * Instantiate a new S2K instance of the given type
16212
+ * @param {module:enums.s2k} type
16213
+ * @oaram {Object} [config]
16214
+ * @returns {Object} New s2k object
16215
+ * @throws {Error} for unknown or unsupported types
16216
+ */
16217
+ function newS2KFromType(type, config$1 = config) {
16218
+ switch (type) {
16219
+ case enums.s2k.argon2:
16220
+ return new Argon2S2K(config$1);
16221
+ case enums.s2k.iterated:
16222
+ case enums.s2k.gnu:
16223
+ case enums.s2k.salted:
16224
+ case enums.s2k.simple:
16225
+ return new GenericS2K(type, config$1);
16226
+ default:
16227
+ throw new Error(`Unsupported S2K type ${type}`);
16228
+ }
16229
+ }
16230
+
16231
+ /**
16232
+ * Instantiate a new S2K instance based on the config settings
16233
+ * @oaram {Object} config
16234
+ * @returns {Object} New s2k object
16235
+ * @throws {Error} for unknown or unsupported types
16236
+ */
16237
+ function newS2KFromConfig(config) {
16238
+ const { s2kType } = config;
16239
+
16240
+ if (!allowedS2KTypesForEncryption.has(s2kType)) {
16241
+ throw new Error('The provided `config.s2kType` value is not allowed');
16242
+ }
16243
+
16244
+ return newS2KFromType(s2kType, config);
16245
+ }
16246
+
15884
16247
  var TYPED_OK = typeof Uint8Array !== "undefined" &&
15885
16248
  typeof Uint16Array !== "undefined" &&
15886
16249
  typeof Int32Array !== "undefined";
@@ -24702,166 +25065,6 @@ class PublicKeyEncryptedSessionKeyPacket {
24702
25065
 
24703
25066
  // GPG4Browsers - An OpenPGP implementation in javascript
24704
25067
 
24705
- class S2K {
24706
- /**
24707
- * @param {Object} [config] - Full configuration, defaults to openpgp.config
24708
- */
24709
- constructor(config$1 = config) {
24710
- /**
24711
- * Hash function identifier, or 0 for gnu-dummy keys
24712
- * @type {module:enums.hash | 0}
24713
- */
24714
- this.algorithm = enums.hash.sha256;
24715
- /**
24716
- * enums.s2k identifier or 'gnu-dummy'
24717
- * @type {String}
24718
- */
24719
- this.type = 'iterated';
24720
- /** @type {Integer} */
24721
- this.c = config$1.s2kIterationCountByte;
24722
- /** Eight bytes of salt in a binary string.
24723
- * @type {Uint8Array}
24724
- */
24725
- this.salt = null;
24726
- }
24727
-
24728
- getCount() {
24729
- // Exponent bias, defined in RFC4880
24730
- const expbias = 6;
24731
-
24732
- return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
24733
- }
24734
-
24735
- /**
24736
- * Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
24737
- * @param {Uint8Array} bytes - Payload of string-to-key specifier
24738
- * @returns {Integer} Actual length of the object.
24739
- */
24740
- read(bytes) {
24741
- let i = 0;
24742
- this.type = enums.read(enums.s2k, bytes[i++]);
24743
- this.algorithm = bytes[i++];
24744
-
24745
- switch (this.type) {
24746
- case 'simple':
24747
- break;
24748
-
24749
- case 'salted':
24750
- this.salt = bytes.subarray(i, i + 8);
24751
- i += 8;
24752
- break;
24753
-
24754
- case 'iterated':
24755
- this.salt = bytes.subarray(i, i + 8);
24756
- i += 8;
24757
-
24758
- // Octet 10: count, a one-octet, coded value
24759
- this.c = bytes[i++];
24760
- break;
24761
-
24762
- case 'gnu':
24763
- if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === 'GNU') {
24764
- i += 3; // GNU
24765
- const gnuExtType = 1000 + bytes[i++];
24766
- if (gnuExtType === 1001) {
24767
- this.type = 'gnu-dummy';
24768
- // GnuPG extension mode 1001 -- don't write secret key at all
24769
- } else {
24770
- throw new Error('Unknown s2k gnu protection mode.');
24771
- }
24772
- } else {
24773
- throw new Error('Unknown s2k type.');
24774
- }
24775
- break;
24776
-
24777
- default:
24778
- throw new Error('Unknown s2k type.');
24779
- }
24780
-
24781
- return i;
24782
- }
24783
-
24784
- /**
24785
- * Serializes s2k information
24786
- * @returns {Uint8Array} Binary representation of s2k.
24787
- */
24788
- write() {
24789
- if (this.type === 'gnu-dummy') {
24790
- return new Uint8Array([101, 0, ...util.stringToUint8Array('GNU'), 1]);
24791
- }
24792
- const arr = [new Uint8Array([enums.write(enums.s2k, this.type), this.algorithm])];
24793
-
24794
- switch (this.type) {
24795
- case 'simple':
24796
- break;
24797
- case 'salted':
24798
- arr.push(this.salt);
24799
- break;
24800
- case 'iterated':
24801
- arr.push(this.salt);
24802
- arr.push(new Uint8Array([this.c]));
24803
- break;
24804
- case 'gnu':
24805
- throw new Error('GNU s2k type not supported.');
24806
- default:
24807
- throw new Error('Unknown s2k type.');
24808
- }
24809
-
24810
- return util.concatUint8Array(arr);
24811
- }
24812
-
24813
- /**
24814
- * Produces a key using the specified passphrase and the defined
24815
- * hashAlgorithm
24816
- * @param {String} passphrase - Passphrase containing user input
24817
- * @returns {Promise<Uint8Array>} Produced key with a length corresponding to.
24818
- * hashAlgorithm hash length
24819
- * @async
24820
- */
24821
- async produceKey(passphrase, numBytes) {
24822
- passphrase = util.encodeUTF8(passphrase);
24823
-
24824
- const arr = [];
24825
- let rlength = 0;
24826
-
24827
- let prefixlen = 0;
24828
- while (rlength < numBytes) {
24829
- let toHash;
24830
- switch (this.type) {
24831
- case 'simple':
24832
- toHash = util.concatUint8Array([new Uint8Array(prefixlen), passphrase]);
24833
- break;
24834
- case 'salted':
24835
- toHash = util.concatUint8Array([new Uint8Array(prefixlen), this.salt, passphrase]);
24836
- break;
24837
- case 'iterated': {
24838
- const data = util.concatUint8Array([this.salt, passphrase]);
24839
- let datalen = data.length;
24840
- const count = Math.max(this.getCount(), datalen);
24841
- toHash = new Uint8Array(prefixlen + count);
24842
- toHash.set(data, prefixlen);
24843
- for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
24844
- toHash.copyWithin(pos, prefixlen, pos);
24845
- }
24846
- break;
24847
- }
24848
- case 'gnu':
24849
- throw new Error('GNU s2k type not supported.');
24850
- default:
24851
- throw new Error('Unknown s2k type.');
24852
- }
24853
- const result = await mod.hash.digest(this.algorithm, toHash);
24854
- arr.push(result);
24855
- rlength += result.length;
24856
- prefixlen++;
24857
- }
24858
-
24859
- return util.concatUint8Array(arr).subarray(0, numBytes);
24860
- }
24861
- }
24862
-
24863
- // GPG4Browsers - An OpenPGP implementation in javascript
24864
-
24865
25068
  /**
24866
25069
  * Symmetric-Key Encrypted Session Key Packets (Tag 3)
24867
25070
  *
@@ -24929,7 +25132,8 @@ class SymEncryptedSessionKeyPacket {
24929
25132
  }
24930
25133
 
24931
25134
  // A string-to-key (S2K) specifier, length as defined above.
24932
- this.s2k = new S2K();
25135
+ const s2kType = bytes[offset++];
25136
+ this.s2k = newS2KFromType(s2kType);
24933
25137
  offset += this.s2k.read(bytes.subarray(offset, bytes.length));
24934
25138
 
24935
25139
  if (this.version === 5) {
@@ -25018,8 +25222,8 @@ class SymEncryptedSessionKeyPacket {
25018
25222
 
25019
25223
  this.sessionKeyEncryptionAlgorithm = algo;
25020
25224
 
25021
- this.s2k = new S2K(config$1);
25022
- this.s2k.salt = mod.random.getRandomBytes(8);
25225
+ this.s2k = newS2KFromConfig(config$1);
25226
+ this.s2k.generateSalt();
25023
25227
 
25024
25228
  const { blockSize, keySize } = mod.getCipher(algo);
25025
25229
  const encryptionKey = await this.s2k.produceKey(passphrase, keySize);
@@ -25645,7 +25849,8 @@ class SecretKeyPacket extends PublicKeyPacket {
25645
25849
  // - [Optional] If string-to-key usage octet was 255, 254, or 253, a
25646
25850
  // string-to-key specifier. The length of the string-to-key
25647
25851
  // specifier is implied by its type, as described above.
25648
- this.s2k = new S2K();
25852
+ const s2kType = bytes[i++];
25853
+ this.s2k = newS2KFromType(s2kType);
25649
25854
  i += this.s2k.read(bytes.subarray(i, bytes.length));
25650
25855
 
25651
25856
  if (this.s2k.type === 'gnu-dummy') {
@@ -25783,7 +25988,7 @@ class SecretKeyPacket extends PublicKeyPacket {
25783
25988
  }
25784
25989
  this.isEncrypted = null;
25785
25990
  this.keyMaterial = null;
25786
- this.s2k = new S2K(config$1);
25991
+ this.s2k = newS2KFromType(enums.s2k.gnu, config$1);
25787
25992
  this.s2k.algorithm = 0;
25788
25993
  this.s2k.c = 0;
25789
25994
  this.s2k.type = 'gnu-dummy';
@@ -25814,8 +26019,8 @@ class SecretKeyPacket extends PublicKeyPacket {
25814
26019
  throw new Error('A non-empty passphrase is required for key encryption.');
25815
26020
  }
25816
26021
 
25817
- this.s2k = new S2K(config$1);
25818
- this.s2k.salt = mod.random.getRandomBytes(8);
26022
+ this.s2k = newS2KFromConfig(config$1);
26023
+ this.s2k.generateSalt();
25819
26024
  const cleartext = mod.serializeParams(this.algorithm, this.privateParams);
25820
26025
  this.symmetric = enums.symmetric.aes256;
25821
26026
  const key = await produceEncryptionKey(this.s2k, passphrase, this.symmetric);
@@ -29693,6 +29898,9 @@ class Message {
29693
29898
  decryptedSessionKeyPackets.push(skeskPacket);
29694
29899
  } catch (err) {
29695
29900
  util.printDebugError(err);
29901
+ if (err instanceof Argon2OutOfMemoryError) {
29902
+ exception = err;
29903
+ }
29696
29904
  }
29697
29905
  }));
29698
29906
  }));
@@ -43840,4 +44048,716 @@ var elliptic$1 = /*#__PURE__*/Object.freeze({
43840
44048
  __moduleExports: elliptic_1
43841
44049
  });
43842
44050
 
44051
+ // Adapted from the reference implementation in RFC7693
44052
+ // Initial port to Javascript by https://github.com/dcposch and https://github.com/emilbayes
44053
+
44054
+ // Uint64 values are represented using two Uint32s, stored as little endian
44055
+ // NB: Uint32Arrays endianness depends on the underlying system, so for interoperability, conversions between Uint8Array and Uint32Arrays
44056
+ // need to be manually handled
44057
+
44058
+ // 64-bit unsigned addition (little endian, in place)
44059
+ // Sets a[i,i+1] += b[j,j+1]
44060
+ // `a` and `b` must be Uint32Array(2)
44061
+ function ADD64 (a, i, b, j) {
44062
+ a[i] += b[j];
44063
+ a[i+1] += b[j+1] + (a[i] < b[j]); // add carry
44064
+ }
44065
+
44066
+ // Increment 64-bit little-endian unsigned value by `c` (in place)
44067
+ // `a` must be Uint32Array(2)
44068
+ function INC64 (a, c) {
44069
+ a[0] += c;
44070
+ a[1] += (a[0] < c);
44071
+ }
44072
+
44073
+ // G Mixing function
44074
+ // The ROTRs are inlined for speed
44075
+ function G (v, m, a, b, c, d, ix, iy) {
44076
+ ADD64(v, a, v, b); // v[a,a+1] += v[b,b+1]
44077
+ ADD64(v, a, m, ix); // v[a, a+1] += x ... x0
44078
+
44079
+ // v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
44080
+ let xor0 = v[d] ^ v[a];
44081
+ let xor1 = v[d + 1] ^ v[a + 1];
44082
+ v[d] = xor1;
44083
+ v[d + 1] = xor0;
44084
+
44085
+ ADD64(v, c, v, d);
44086
+
44087
+ // v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
44088
+ xor0 = v[b] ^ v[c];
44089
+ xor1 = v[b + 1] ^ v[c + 1];
44090
+ v[b] = (xor0 >>> 24) ^ (xor1 << 8);
44091
+ v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
44092
+
44093
+ ADD64(v, a, v, b);
44094
+ ADD64(v, a, m, iy);
44095
+
44096
+ // v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
44097
+ xor0 = v[d] ^ v[a];
44098
+ xor1 = v[d + 1] ^ v[a + 1];
44099
+ v[d] = (xor0 >>> 16) ^ (xor1 << 16);
44100
+ v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
44101
+
44102
+ ADD64(v, c, v, d);
44103
+
44104
+ // v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
44105
+ xor0 = v[b] ^ v[c];
44106
+ xor1 = v[b + 1] ^ v[c + 1];
44107
+ v[b] = (xor1 >>> 31) ^ (xor0 << 1);
44108
+ v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
44109
+ }
44110
+
44111
+ // Initialization Vector
44112
+ const BLAKE2B_IV32 = new Uint32Array([
44113
+ 0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
44114
+ 0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
44115
+ 0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
44116
+ 0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
44117
+ ]);
44118
+
44119
+ // These are offsets into a Uint64 buffer.
44120
+ // Multiply them all by 2 to make them offsets into a Uint32 buffer
44121
+ const SIGMA = new Uint8Array([
44122
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
44123
+ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
44124
+ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
44125
+ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
44126
+ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
44127
+ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
44128
+ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
44129
+ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
44130
+ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
44131
+ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
44132
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
44133
+ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
44134
+ ].map(x => x * 2));
44135
+
44136
+ // Compression function. 'last' flag indicates last block.
44137
+ // Note: we're representing 16 uint64s as 32 uint32s
44138
+ function compress(S, last) {
44139
+ const v = new Uint32Array(32);
44140
+ const m = new Uint32Array(S.b.buffer, S.b.byteOffset, 32);
44141
+
44142
+ // init work variables
44143
+ for (let i = 0; i < 16; i++) {
44144
+ v[i] = S.h[i];
44145
+ v[i + 16] = BLAKE2B_IV32[i];
44146
+ }
44147
+
44148
+ // low 64 bits of offset
44149
+ v[24] ^= S.t0[0];
44150
+ v[25] ^= S.t0[1];
44151
+ // high 64 bits not supported (`t1`), offset may not be higher than 2**53-1
44152
+
44153
+ // if last block
44154
+ const f0 = last ? 0xFFFFFFFF : 0;
44155
+ v[28] ^= f0;
44156
+ v[29] ^= f0;
44157
+
44158
+ // twelve rounds of mixing
44159
+ for (let i = 0; i < 12; i++) {
44160
+ // ROUND(r)
44161
+ const i16 = i << 4;
44162
+ G(v, m, 0, 8, 16, 24, SIGMA[i16 + 0], SIGMA[i16 + 1]);
44163
+ G(v, m, 2, 10, 18, 26, SIGMA[i16 + 2], SIGMA[i16 + 3]);
44164
+ G(v, m, 4, 12, 20, 28, SIGMA[i16 + 4], SIGMA[i16 + 5]);
44165
+ G(v, m, 6, 14, 22, 30, SIGMA[i16 + 6], SIGMA[i16 + 7]);
44166
+ G(v, m, 0, 10, 20, 30, SIGMA[i16 + 8], SIGMA[i16 + 9]);
44167
+ G(v, m, 2, 12, 22, 24, SIGMA[i16 + 10], SIGMA[i16 + 11]);
44168
+ G(v, m, 4, 14, 16, 26, SIGMA[i16 + 12], SIGMA[i16 + 13]);
44169
+ G(v, m, 6, 8, 18, 28, SIGMA[i16 + 14], SIGMA[i16 + 15]);
44170
+ }
44171
+
44172
+ for (let i = 0; i < 16; i++) {
44173
+ S.h[i] ^= v[i] ^ v[i + 16];
44174
+ }
44175
+ }
44176
+
44177
+ // Creates a BLAKE2b hashing context
44178
+ // Requires an output length between 1 and 64 bytes
44179
+ // Takes an optional Uint8Array key
44180
+ class Blake2b {
44181
+ constructor(outlen, key, salt, personal) {
44182
+ const params = new Uint8Array(64);
44183
+ // 0: outlen, keylen, fanout, depth
44184
+ // 4: leaf length, sequential mode
44185
+ // 8: node offset
44186
+ // 12: node offset
44187
+ // 16: node depth, inner length, rfu
44188
+ // 20: rfu
44189
+ // 24: rfu
44190
+ // 28: rfu
44191
+ // 32: salt
44192
+ // 36: salt
44193
+ // 40: salt
44194
+ // 44: salt
44195
+ // 48: personal
44196
+ // 52: personal
44197
+ // 56: personal
44198
+ // 60: personal
44199
+
44200
+ // init internal state
44201
+ this.S = {
44202
+ b: new Uint8Array(BLOCKBYTES),
44203
+ h: new Uint32Array(OUTBYTES_MAX / 4),
44204
+ t0: new Uint32Array(2), // input counter `t`, lower 64-bits only
44205
+ c: 0, // `fill`, pointer within buffer, up to `BLOCKBYTES`
44206
+ outlen // output length in bytes
44207
+ };
44208
+
44209
+ // init parameter block
44210
+ params[0] = outlen;
44211
+ if (key) params[1] = key.length;
44212
+ params[2] = 1; // fanout
44213
+ params[3] = 1; // depth
44214
+ if (salt) params.set(salt, 32);
44215
+ if (personal) params.set(personal, 48);
44216
+ const params32 = new Uint32Array(params.buffer, params.byteOffset, params.length / Uint32Array.BYTES_PER_ELEMENT);
44217
+
44218
+ // initialize hash state
44219
+ for (let i = 0; i < 16; i++) {
44220
+ this.S.h[i] = BLAKE2B_IV32[i] ^ params32[i];
44221
+ }
44222
+
44223
+ // key the hash, if applicable
44224
+ if (key) {
44225
+ const block = new Uint8Array(BLOCKBYTES);
44226
+ block.set(key);
44227
+ this.update(block);
44228
+ }
44229
+ }
44230
+
44231
+ // Updates a BLAKE2b streaming hash
44232
+ // Requires Uint8Array (byte array)
44233
+ update(input) {
44234
+ if (!(input instanceof Uint8Array)) throw new Error('Input must be Uint8Array or Buffer')
44235
+ // for (let i = 0; i < input.length; i++) {
44236
+ // if (this.S.c === BLOCKBYTES) { // buffer full
44237
+ // INC64(this.S.t0, this.S.c) // add counters
44238
+ // compress(this.S, false)
44239
+ // this.S.c = 0 // empty buffer
44240
+ // }
44241
+ // this.S.b[this.S.c++] = input[i]
44242
+ // }
44243
+ let i = 0;
44244
+ while(i < input.length) {
44245
+ if (this.S.c === BLOCKBYTES) { // buffer full
44246
+ INC64(this.S.t0, this.S.c); // add counters
44247
+ compress(this.S, false);
44248
+ this.S.c = 0; // empty buffer
44249
+ }
44250
+ let left = BLOCKBYTES - this.S.c;
44251
+ this.S.b.set(input.subarray(i, i + left), this.S.c); // end index can be out of bounds
44252
+ const fill = Math.min(left, input.length - i);
44253
+ this.S.c += fill;
44254
+ i += fill;
44255
+ }
44256
+ return this
44257
+ }
44258
+
44259
+ /**
44260
+ * Return a BLAKE2b hash, either filling the given Uint8Array or allocating a new one
44261
+ * @param {Uint8Array} [prealloc] - optional preallocated buffer
44262
+ * @returns {ArrayBuffer} message digest
44263
+ */
44264
+ digest(prealloc) {
44265
+ INC64(this.S.t0, this.S.c); // mark last block offset
44266
+
44267
+ // final block, padded
44268
+ this.S.b.fill(0, this.S.c);
44269
+ this.S.c = BLOCKBYTES;
44270
+ compress(this.S, true);
44271
+
44272
+ const out = prealloc || new Uint8Array(this.S.outlen);
44273
+ for (let i = 0; i < this.S.outlen; i++) {
44274
+ // must be loaded individually since default Uint32 endianness is platform dependant
44275
+ out[i] = this.S.h[i >> 2] >> (8 * (i & 3));
44276
+ }
44277
+ this.S.h = null; // prevent calling `update` after `digest`
44278
+ return out.buffer;
44279
+ }
44280
+ }
44281
+
44282
+
44283
+ function createHash(outlen, key, salt, personal) {
44284
+ if (outlen > OUTBYTES_MAX) throw new Error(`outlen must be at most ${OUTBYTES_MAX} (given: ${outlen})`)
44285
+ if (key) {
44286
+ if (!(key instanceof Uint8Array)) throw new Error('key must be Uint8Array or Buffer')
44287
+ if (key.length > KEYBYTES_MAX) throw new Error(`key size must be at most ${KEYBYTES_MAX} (given: ${key.length})`)
44288
+ }
44289
+ if (salt) {
44290
+ if (!(salt instanceof Uint8Array)) throw new Error('salt must be Uint8Array or Buffer')
44291
+ if (salt.length !== SALTBYTES) throw new Error(`salt must be exactly ${SALTBYTES} (given: ${salt.length}`)
44292
+ }
44293
+ if (personal) {
44294
+ if (!(personal instanceof Uint8Array)) throw new Error('personal must be Uint8Array or Buffer')
44295
+ if (personal.length !== PERSONALBYTES) throw new Error(`salt must be exactly ${PERSONALBYTES} (given: ${personal.length}`)
44296
+ }
44297
+
44298
+ return new Blake2b(outlen, key, salt, personal)
44299
+ }
44300
+
44301
+ const OUTBYTES_MAX = 64;
44302
+ const KEYBYTES_MAX = 64;
44303
+ const SALTBYTES = 16;
44304
+ const PERSONALBYTES = 16;
44305
+ const BLOCKBYTES = 128;
44306
+
44307
+ const TYPE$2 = 2; // Argon2id
44308
+ const VERSION$4 = 0x13;
44309
+ const TAGBYTES_MAX = 0xFFFFFFFF; // Math.pow(2, 32) - 1;
44310
+ const TAGBYTES_MIN = 4; // Math.pow(2, 32) - 1;
44311
+ const SALTBYTES_MAX = 0xFFFFFFFF; // Math.pow(2, 32) - 1;
44312
+ const SALTBYTES_MIN = 8;
44313
+ const passwordBYTES_MAX = 0xFFFFFFFF;// Math.pow(2, 32) - 1;
44314
+ const passwordBYTES_MIN = 8;
44315
+ const MEMBYTES_MAX = 0xFFFFFFFF;// Math.pow(2, 32) - 1;
44316
+ const ADBYTES_MAX = 0xFFFFFFFF; // Math.pow(2, 32) - 1; // associated data (optional)
44317
+ const SECRETBYTES_MAX = 32; // key (optional)
44318
+
44319
+ const ARGON2_BLOCK_SIZE = 1024;
44320
+ const ARGON2_PREHASH_DIGEST_LENGTH = 64;
44321
+
44322
+ const isLittleEndian$1 = new Uint8Array(new Uint16Array([0xabcd]).buffer)[0] === 0xcd;
44323
+
44324
+ // store n as a little-endian 32-bit Uint8Array inside buf (at buf[i:i+3])
44325
+ function LE32(buf, n, i) {
44326
+ buf[i+0] = n;
44327
+ buf[i+1] = n >> 8;
44328
+ buf[i+2] = n >> 16;
44329
+ buf[i+3] = n >> 24;
44330
+ return buf;
44331
+ }
44332
+
44333
+ /**
44334
+ * Store n as a 64-bit LE number in the given buffer (from buf[i] to buf[i+7])
44335
+ * @param {Uint8Array} buf
44336
+ * @param {Number} n
44337
+ * @param {Number} i
44338
+ */
44339
+ function LE64(buf, n, i) {
44340
+ if (n > Number.MAX_SAFE_INTEGER) throw new Error("LE64: large numbers unsupported");
44341
+ // ECMAScript standard has engines convert numbers to 32-bit integers for bitwise operations
44342
+ // shifting by 32 or more bits is not supported (https://stackoverflow.com/questions/6729122/javascript-bit-shift-number-wraps)
44343
+ // so we manually extract each byte
44344
+ let remainder = n;
44345
+ for (let offset = i; offset < i+7; offset++) { // last byte can be ignored as it would overflow MAX_SAFE_INTEGER
44346
+ buf[offset] = remainder; // implicit & 0xff
44347
+ remainder = (remainder - buf[offset]) / 256;
44348
+ }
44349
+ return buf;
44350
+ }
44351
+
44352
+ /**
44353
+ * Variable-Length Hash Function H'
44354
+ * @param {Number} outlen - T
44355
+ * @param {Uint8Array} X - value to hash
44356
+ * @param {Uint8Array} res - output buffer, of length `outlength` or larger
44357
+ */
44358
+ function H_(outlen, X, res) {
44359
+ const V = new Uint8Array(64); // no need to keep around all V_i
44360
+
44361
+ const V1_in = new Uint8Array(4 + X.length);
44362
+ LE32(V1_in, outlen, 0);
44363
+ V1_in.set(X, 4);
44364
+ if (outlen <= 64) {
44365
+ // H'^T(A) = H^T(LE32(T)||A)
44366
+ createHash(outlen).update(V1_in).digest(res);
44367
+ return res
44368
+ }
44369
+
44370
+ const r = Math.ceil(outlen / 32) - 2;
44371
+
44372
+ // Let V_i be a 64-byte block and W_i be its first 32 bytes.
44373
+ // V_1 = H^(64)(LE32(T)||A)
44374
+ // V_2 = H^(64)(V_1)
44375
+ // ...
44376
+ // V_r = H^(64)(V_{r-1})
44377
+ // V_{r+1} = H^(T-32*r)(V_{r})
44378
+ // H'^T(X) = W_1 || W_2 || ... || W_r || V_{r+1}
44379
+ for (let i = 0; i < r; i++) {
44380
+ createHash(64).update(i === 0 ? V1_in : V).digest(V);
44381
+ // store W_i in result buffer already
44382
+ res.set(V.subarray(0, 32), i*32);
44383
+ }
44384
+ // V_{r+1}
44385
+ const V_r1 = new Uint8Array(createHash(outlen - 32*r).update(V).digest());
44386
+ res.set(V_r1, r*32);
44387
+
44388
+ return res;
44389
+ }
44390
+
44391
+ // compute buf = xs ^ ys
44392
+ function XOR(wasmContext, buf, xs, ys) {
44393
+ wasmContext.fn.XOR(
44394
+ buf.byteOffset,
44395
+ xs.byteOffset,
44396
+ ys.byteOffset,
44397
+ );
44398
+ return buf
44399
+ }
44400
+
44401
+ /**
44402
+ * @param {Uint8Array} X (read-only)
44403
+ * @param {Uint8Array} Y (read-only)
44404
+ * @param {Uint8Array} R - output buffer
44405
+ * @returns
44406
+ */
44407
+ function G$1(wasmContext, X, Y, R) {
44408
+ wasmContext.fn.G(
44409
+ X.byteOffset,
44410
+ Y.byteOffset,
44411
+ R.byteOffset,
44412
+ wasmContext.refs.gZ.byteOffset
44413
+ );
44414
+ return R;
44415
+ }
44416
+
44417
+ function G2(wasmContext, X, Y, R) {
44418
+ wasmContext.fn.G2(
44419
+ X.byteOffset,
44420
+ Y.byteOffset,
44421
+ R.byteOffset,
44422
+ wasmContext.refs.gZ.byteOffset
44423
+ );
44424
+ return R;
44425
+ }
44426
+
44427
+ // Generator for data-independent J1, J2. Each `next()` invocation returns a new pair of values.
44428
+ function* makePRNG(wasmContext, pass, lane, slice, m_, totalPasses, segmentLength, segmentOffset) {
44429
+ // For each segment, we do the following. First, we compute the value Z as:
44430
+ // Z= ( LE64(r) || LE64(l) || LE64(sl) || LE64(m') || LE64(t) || LE64(y) )
44431
+ wasmContext.refs.prngTmp.fill(0);
44432
+ const Z = wasmContext.refs.prngTmp.subarray(0, 6 * 8);
44433
+ LE64(Z, pass, 0);
44434
+ LE64(Z, lane, 8);
44435
+ LE64(Z, slice, 16);
44436
+ LE64(Z, m_, 24);
44437
+ LE64(Z, totalPasses, 32);
44438
+ LE64(Z, TYPE$2, 40);
44439
+
44440
+ // Then we compute q/(128*SL) 1024-byte values
44441
+ // G( ZERO(1024),
44442
+ // G( ZERO(1024), Z || LE64(1) || ZERO(968) ) ),
44443
+ // ...,
44444
+ // G( ZERO(1024),
44445
+ // G( ZERO(1024), Z || LE64(q/(128*SL)) || ZERO(968) )),
44446
+ for(let i = 1; i <= segmentLength; i++) {
44447
+ // tmp.set(Z); // no need to re-copy
44448
+ LE64(wasmContext.refs.prngTmp, i, Z.length); // tmp.set(ZER0968) not necessary, memory already zeroed
44449
+ const g2 = G2(wasmContext, wasmContext.refs.ZERO1024, wasmContext.refs.prngTmp, wasmContext.refs.prngR );
44450
+
44451
+ // each invocation of G^2 outputs 1024 bytes that are to be partitioned into 8-bytes values, take as X1 || X2
44452
+ // NB: the first generated pair must be used for the first block of the segment, and so on.
44453
+ // Hence, if some blocks are skipped (e.g. during the first pass), the corresponding J1J2 are discarded based on the given segmentOffset.
44454
+ for(let k = i === 1 ? segmentOffset*8 : 0; k < g2.length; k += 8) {
44455
+ yield g2.subarray(k, k+8);
44456
+ }
44457
+ }
44458
+ return [];
44459
+ }
44460
+
44461
+ function validateParams$7({ type, version, tagLength, password, salt, ad, secret, parallelism, memorySize, passes }) {
44462
+ const assertLength = (name, value, min, max) => {
44463
+ if (value < min || value > max) { throw new Error(`${name} size should be between ${min} and ${max} bytes`); }
44464
+ };
44465
+
44466
+ if (type !== TYPE$2 || version !== VERSION$4) throw new Error('Unsupported type or version');
44467
+ assertLength('password', password, passwordBYTES_MIN, passwordBYTES_MAX);
44468
+ assertLength('salt', salt, SALTBYTES_MIN, SALTBYTES_MAX);
44469
+ assertLength('tag', tagLength, TAGBYTES_MIN, TAGBYTES_MAX);
44470
+ assertLength('memory', memorySize, 8*parallelism, MEMBYTES_MAX);
44471
+ // optional fields
44472
+ ad && assertLength('associated data', ad, 0, ADBYTES_MAX);
44473
+ secret && assertLength('secret', secret, 0, SECRETBYTES_MAX);
44474
+
44475
+ return { type, version, tagLength, password, salt, ad, secret, lanes: parallelism, memorySize, passes };
44476
+ }
44477
+
44478
+ const KB = 1024;
44479
+ const WASM_PAGE_SIZE = 64 * KB;
44480
+
44481
+ function argon2id(params, { memory, instance: wasmInstance }) {
44482
+ if (!isLittleEndian$1) throw new Error('BigEndian system not supported'); // optmisations assume LE system
44483
+
44484
+ const ctx = validateParams$7({ type: TYPE$2, version: VERSION$4, ...params });
44485
+
44486
+ const { G:wasmG, G2:wasmG2, xor:wasmXOR, getLZ:wasmLZ } = wasmInstance.exports;
44487
+ const wasmRefs = {};
44488
+ const wasmFn = {};
44489
+ wasmFn.G = wasmG;
44490
+ wasmFn.G2 = wasmG2;
44491
+ wasmFn.XOR = wasmXOR;
44492
+
44493
+ // The actual number of blocks is m', which is m rounded down to the nearest multiple of 4*p.
44494
+ const m_ = 4 * ctx.lanes * Math.floor(ctx.memorySize / (4 * ctx.lanes));
44495
+ const requiredMemory = m_ * ARGON2_BLOCK_SIZE + 10 * KB; // Additional KBs for utility references
44496
+ if (memory.buffer.byteLength < requiredMemory) {
44497
+ const missing = Math.ceil((requiredMemory - memory.buffer.byteLength) / WASM_PAGE_SIZE);
44498
+ // If enough memory is available, the `memory.buffer` is internally detached and the reference updated.
44499
+ // Otherwise, the operation fails, and the original memory can still be used.
44500
+ memory.grow(missing);
44501
+ }
44502
+
44503
+ let offset = 0;
44504
+ // Init wasm memory needed in other functions
44505
+ wasmRefs.gZ = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+= wasmRefs.gZ.length;
44506
+ wasmRefs.prngR = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+=wasmRefs.prngR.length;
44507
+ wasmRefs.prngTmp = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+=wasmRefs.prngTmp.length;
44508
+ wasmRefs.ZERO1024 = new Uint8Array(memory.buffer, offset, 1024); offset+=wasmRefs.ZERO1024.length;
44509
+ // Init wasm memory needed locally
44510
+ const lz = new Uint32Array(memory.buffer, offset, 2); offset+=lz.length * Uint32Array.BYTES_PER_ELEMENT;
44511
+ const wasmContext = { fn: wasmFn, refs: wasmRefs };
44512
+ const newBlock = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+=newBlock.length;
44513
+ const blockMemory = new Uint8Array(memory.buffer, offset, ctx.memorySize * ARGON2_BLOCK_SIZE);
44514
+ const allocatedMemory = new Uint8Array(memory.buffer, 0, offset);
44515
+
44516
+ // 1. Establish H_0
44517
+ const H0 = getH0(ctx);
44518
+
44519
+ // 2. Allocate the memory as m' 1024-byte blocks
44520
+ // For p lanes, the memory is organized in a matrix B[i][j] of blocks with p rows (lanes) and q = m' / p columns.
44521
+ const q = m_ / ctx.lanes;
44522
+ const B = new Array(ctx.lanes).fill(null).map(() => new Array(q));
44523
+ const initBlock = (i, j) => {
44524
+ B[i][j] = blockMemory.subarray(i*q*1024 + j*1024, (i*q*1024 + j*1024) + ARGON2_BLOCK_SIZE);
44525
+ return B[i][j];
44526
+ };
44527
+
44528
+ for (let i = 0; i < ctx.lanes; i++) {
44529
+ // const LEi = LE0; // since p = 1 for us
44530
+ const tmp = new Uint8Array(H0.length + 8);
44531
+ // 3. Compute B[i][0] for all i ranging from (and including) 0 to (not including) p
44532
+ // B[i][0] = H'^(1024)(H_0 || LE32(0) || LE32(i))
44533
+ tmp.set(H0); LE32(tmp, 0, H0.length); LE32(tmp, i, H0.length + 4);
44534
+ H_(ARGON2_BLOCK_SIZE, tmp, initBlock(i, 0));
44535
+ // 4. Compute B[i][1] for all i ranging from (and including) 0 to (not including) p
44536
+ // B[i][1] = H'^(1024)(H_0 || LE32(1) || LE32(i))
44537
+ LE32(tmp, 1, H0.length);
44538
+ H_(ARGON2_BLOCK_SIZE, tmp, initBlock(i, 1));
44539
+ }
44540
+
44541
+ // 5. Compute B[i][j] for all i ranging from (and including) 0 to (not including) p and for all j ranging from (and including) 2
44542
+ // to (not including) q. The computation MUST proceed slicewise (Section 3.4) : first, blocks from slice 0 are computed for all lanes
44543
+ // (in an arbitrary order of lanes), then blocks from slice 1 are computed, etc.
44544
+ const SL = 4; // vertical slices
44545
+ const segmentLength = q / SL;
44546
+ for (let pass = 0; pass < ctx.passes; pass++) {
44547
+ // The intersection of a slice and a lane is called a segment, which has a length of q/SL. Segments of the same slice can be computed in parallel
44548
+ for (let sl = 0; sl < SL; sl++) {
44549
+ const isDataIndependent = pass === 0 && sl <= 1;
44550
+ for (let i = 0; i < ctx.lanes; i++) { // lane
44551
+ // On the first slice of the first pass, blocks 0 and 1 are already filled
44552
+ let segmentOffset = sl === 0 && pass === 0 ? 2 : 0;
44553
+ // no need to generate all J1J2s, use iterator/generator that creates the value on the fly (to save memory)
44554
+ const PRNG = isDataIndependent ? makePRNG(wasmContext, pass, i, sl, m_, ctx.passes, segmentLength, segmentOffset) : null;
44555
+ for (segmentOffset; segmentOffset < segmentLength; segmentOffset++) {
44556
+ const j = sl * segmentLength + segmentOffset;
44557
+ const prevBlock = j > 0 ? B[i][j-1] : B[i][q-1]; // B[i][(j-1) mod q]
44558
+
44559
+ // we can assume the PRNG is never done
44560
+ const J1J2 = isDataIndependent ? PRNG.next().value : prevBlock; // .subarray(0, 8) not required since we only pass the byteOffset to wasm
44561
+ // The block indices l and z are determined for each i, j differently for Argon2d, Argon2i, and Argon2id.
44562
+ wasmLZ(lz.byteOffset, J1J2.byteOffset, i, ctx.lanes, pass, sl, segmentOffset, SL, segmentLength);
44563
+ const l = lz[0]; const z = lz[1];
44564
+ // for (let i = 0; i < p; i++ )
44565
+ // B[i][j] = G(B[i][j-1], B[l][z])
44566
+ // The block indices l and z are determined for each i, j differently for Argon2d, Argon2i, and Argon2id.
44567
+ if (pass === 0) initBlock(i, j);
44568
+ G$1(wasmContext, prevBlock, B[l][z], pass > 0 ? newBlock : B[i][j]);
44569
+
44570
+ // 6. If the number of passes t is larger than 1, we repeat step 5. However, blocks are computed differently as the old value is XORed with the new one
44571
+ if (pass > 0) XOR(wasmContext, B[i][j], newBlock, B[i][j]);
44572
+ }
44573
+ }
44574
+ }
44575
+ }
44576
+
44577
+ // 7. After t steps have been iterated, the final block C is computed as the XOR of the last column:
44578
+ // C = B[0][q-1] XOR B[1][q-1] XOR ... XOR B[p-1][q-1]
44579
+ const C = B[0][q-1];
44580
+ for(let i = 1; i < ctx.lanes; i++) {
44581
+ XOR(wasmContext, C, C, B[i][q-1]);
44582
+ }
44583
+
44584
+ const tag = H_(ctx.tagLength, C, new Uint8Array(ctx.tagLength));
44585
+ // clear memory since the module might be cached
44586
+ allocatedMemory.fill(0); // clear sensitive contents
44587
+ memory.grow(0); // allow deallocation
44588
+ // 8. The output tag is computed as H'^T(C).
44589
+ return tag;
44590
+
44591
+ }
44592
+
44593
+ function getH0(ctx) {
44594
+ const H = createHash(ARGON2_PREHASH_DIGEST_LENGTH);
44595
+ const ZERO32 = new Uint8Array(4);
44596
+ const params = new Uint8Array(24);
44597
+ LE32(params, ctx.lanes, 0);
44598
+ LE32(params, ctx.tagLength, 4);
44599
+ LE32(params, ctx.memorySize, 8);
44600
+ LE32(params, ctx.passes, 12);
44601
+ LE32(params, ctx.version, 16);
44602
+ LE32(params, ctx.type, 20);
44603
+
44604
+ const toHash = [params];
44605
+ if (ctx.password) {
44606
+ toHash.push(LE32(new Uint8Array(4), ctx.password.length, 0));
44607
+ toHash.push(ctx.password);
44608
+ } else {
44609
+ toHash.push(ZERO32); // context.password.length
44610
+ }
44611
+
44612
+ if (ctx.salt) {
44613
+ toHash.push(LE32(new Uint8Array(4), ctx.salt.length, 0));
44614
+ toHash.push(ctx.salt);
44615
+ } else {
44616
+ toHash.push(ZERO32); // context.salt.length
44617
+ }
44618
+
44619
+ if (ctx.secret) {
44620
+ toHash.push(LE32(new Uint8Array(4), ctx.secret.length, 0));
44621
+ toHash.push(ctx.secret);
44622
+ // todo clear secret?
44623
+ } else {
44624
+ toHash.push(ZERO32); // context.secret.length
44625
+ }
44626
+
44627
+ if (ctx.ad) {
44628
+ toHash.push(LE32(new Uint8Array(4), ctx.ad.length, 0));
44629
+ toHash.push(ctx.ad);
44630
+ } else {
44631
+ toHash.push(ZERO32); // context.ad.length
44632
+ }
44633
+ H.update(concatArrays(toHash));
44634
+
44635
+ const outputBuffer = H.digest();
44636
+ return new Uint8Array(outputBuffer);
44637
+ }
44638
+
44639
+ function concatArrays(arrays) {
44640
+ if (arrays.length === 1) return arrays[0];
44641
+
44642
+ let totalLength = 0;
44643
+ for (let i = 0; i < arrays.length; i++) {
44644
+ if (!(arrays[i] instanceof Uint8Array)) {
44645
+ throw new Error('concatArrays: Data must be in the form of a Uint8Array');
44646
+ }
44647
+
44648
+ totalLength += arrays[i].length;
44649
+ }
44650
+
44651
+ const result = new Uint8Array(totalLength);
44652
+ let pos = 0;
44653
+ arrays.forEach((element) => {
44654
+ result.set(element, pos);
44655
+ pos += element.length;
44656
+ });
44657
+
44658
+ return result;
44659
+ }
44660
+
44661
+ let isSIMDSupported;
44662
+ async function wasmLoader(memory, getSIMD, getNonSIMD) {
44663
+ const importObject = { env: { memory } };
44664
+ if (isSIMDSupported === undefined) {
44665
+ try {
44666
+ isSIMDSupported = true; // will be overwritten in the catch
44667
+ return await getSIMD(importObject);
44668
+ } catch(e) {
44669
+ isSIMDSupported = false;
44670
+ }
44671
+ }
44672
+
44673
+ const loader = isSIMDSupported ? getSIMD : getNonSIMD;
44674
+ return loader(importObject);
44675
+ }
44676
+
44677
+ async function setupWasm(getSIMD, getNonSIMD) {
44678
+ const memory = new WebAssembly.Memory({
44679
+ // in pages of 64KiB each
44680
+ // these values need to be compatible with those declared when building in `build-wasm`
44681
+ initial: 1040, // 65MB
44682
+ maximum: 65536, // 4GB
44683
+ });
44684
+ const wasmModule = await wasmLoader(memory, getSIMD, getNonSIMD);
44685
+
44686
+ /**
44687
+ * Argon2id hash function
44688
+ * @callback computeHash
44689
+ * @param {Object} params
44690
+ * @param {Uint8Array} params.password - password
44691
+ * @param {Uint8Array} params.salt - salt
44692
+ * @param {Integer} params.parallelism
44693
+ * @param {Integer} params.passes
44694
+ * @param {Integer} params.memorySize - in kibibytes
44695
+ * @param {Integer} params.tagLength - output tag length
44696
+ * @param {Uint8Array} [params.ad] - associated data (optional)
44697
+ * @param {Uint8Array} [params.secret] - secret data (optional)
44698
+ * @return {Uint8Array} argon2id hash
44699
+ */
44700
+ const computeHash = (params) => argon2id(params, { instance: wasmModule.instance, memory });
44701
+
44702
+ return computeHash;
44703
+ }
44704
+
44705
+ function _loadWasmModule (sync, filepath, src, imports) {
44706
+ function _instantiateOrCompile(source, imports, stream) {
44707
+ var instantiateFunc = stream ? WebAssembly.instantiateStreaming : WebAssembly.instantiate;
44708
+ var compileFunc = stream ? WebAssembly.compileStreaming : WebAssembly.compile;
44709
+
44710
+ if (imports) {
44711
+ return instantiateFunc(source, imports)
44712
+ } else {
44713
+ return compileFunc(source)
44714
+ }
44715
+ }
44716
+
44717
+
44718
+ var buf = null;
44719
+ if (filepath) {
44720
+
44721
+ var fs = require("fs");
44722
+ var path = require("path");
44723
+
44724
+ return new Promise((resolve, reject) => {
44725
+ fs.readFile(path.resolve(__dirname, filepath), (error, buffer) => {
44726
+ if (error != null) {
44727
+ reject(error);
44728
+ } else {
44729
+ resolve(_instantiateOrCompile(buffer, imports, false));
44730
+ }
44731
+ });
44732
+ });
44733
+
44734
+ }
44735
+
44736
+
44737
+ buf = Buffer.from(src, 'base64');
44738
+
44739
+
44740
+
44741
+ if(sync) {
44742
+ var mod = new WebAssembly.Module(buf);
44743
+ return imports ? new WebAssembly.Instance(mod, imports) : mod
44744
+ } else {
44745
+ return _instantiateOrCompile(buf, imports, false)
44746
+ }
44747
+ }
44748
+
44749
+ function wasmSIMD(imports){return _loadWasmModule(0, null, 'AGFzbQEAAAABKwdgBH9/f38AYAABf2AAAGADf39/AGAJf39/f39/f39/AX9gAX8AYAF/AX8CEwEDZW52Bm1lbW9yeQIBkAiAgAQDCgkCAwAABAEFBgEEBQFwAQICBgkBfwFBkIjAAgsHfQoDeG9yAAEBRwACAkcyAAMFZ2V0TFoABBlfX2luZGlyZWN0X2Z1bmN0aW9uX3RhYmxlAQALX2luaXRpYWxpemUAABBfX2Vycm5vX2xvY2F0aW9uAAgJc3RhY2tTYXZlAAUMc3RhY2tSZXN0b3JlAAYKc3RhY2tBbGxvYwAHCQcBAEEBCwEACs0gCQMAAQtYAQJ/A0AgACAEQQR0IgNqIAIgA2r9AAQAIAEgA2r9AAQA/VH9CwQAIAAgA0EQciIDa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DYCBCAACwQAIwALBgAgACQACxAAIwAgAGtBcHEiACQAIAALBQBBgAgL', imports)}
44750
+
44751
+ function wasmNonSIMD(imports){return _loadWasmModule(0, null, 'AGFzbQEAAAABPwhgBH9/f38AYAABf2AAAGADf39/AGARf39/f39/f39/f39/f39/f38AYAl/f39/f39/f38Bf2ABfwBgAX8BfwITAQNlbnYGbWVtb3J5AgGQCICABAMLCgIDBAAABQEGBwEEBQFwAQICBgkBfwFBkIjAAgsHfQoDeG9yAAEBRwADAkcyAAQFZ2V0TFoABRlfX2luZGlyZWN0X2Z1bmN0aW9uX3RhYmxlAQALX2luaXRpYWxpemUAABBfX2Vycm5vX2xvY2F0aW9uAAkJc3RhY2tTYXZlAAYMc3RhY2tSZXN0b3JlAAcKc3RhY2tBbGxvYwAICQcBAEEBCwEACssaCgMAAQtQAQJ/A0AgACAEQQN0IgNqIAIgA2opAwAgASADaikDAIU3AwAgACADQQhyIgNqIAIgA2opAwAgASADaikDAIU3AwAgBEECaiIEQYABRw0ACwveDwICfgF/IAAgAUEDdGoiEyATKQMAIhEgACAFQQN0aiIBKQMAIhJ8IBFCAYZC/v///x+DIBJC/////w+DfnwiETcDACAAIA1BA3RqIgUgESAFKQMAhUIgiSIRNwMAIAAgCUEDdGoiCSARIAkpAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAEgESABKQMAhUIoiSIRNwMAIBMgESATKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACAFIBEgBSkDAIVCMIkiETcDACAJIBEgCSkDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgASARIAEpAwCFQgGJNwMAIAAgAkEDdGoiDSANKQMAIhEgACAGQQN0aiICKQMAIhJ8IBFCAYZC/v///x+DIBJC/////w+DfnwiETcDACAAIA5BA3RqIgYgESAGKQMAhUIgiSIRNwMAIAAgCkEDdGoiCiARIAopAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAIgESACKQMAhUIoiSIRNwMAIA0gESANKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACAGIBEgBikDAIVCMIkiETcDACAKIBEgCikDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgAiARIAIpAwCFQgGJNwMAIAAgA0EDdGoiDiAOKQMAIhEgACAHQQN0aiIDKQMAIhJ8IBFCAYZC/v///x+DIBJC/////w+DfnwiETcDACAAIA9BA3RqIgcgESAHKQMAhUIgiSIRNwMAIAAgC0EDdGoiCyARIAspAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAMgESADKQMAhUIoiSIRNwMAIA4gESAOKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACAHIBEgBykDAIVCMIkiETcDACALIBEgCykDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgAyARIAMpAwCFQgGJNwMAIAAgBEEDdGoiDyAPKQMAIhEgACAIQQN0aiIEKQMAIhJ8IBFCAYZC/v///x+DIBJC/////w+DfnwiETcDACAAIBBBA3RqIgggESAIKQMAhUIgiSIRNwMAIAAgDEEDdGoiACARIAApAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAQgESAEKQMAhUIoiSIRNwMAIA8gESAPKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACAIIBEgCCkDAIVCMIkiETcDACAAIBEgACkDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgBCARIAQpAwCFQgGJNwMAIBMgEykDACIRIAIpAwAiEnwgEUIBhkL+////H4MgEkL/////D4N+fCIRNwMAIAggESAIKQMAhUIgiSIRNwMAIAsgESALKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACACIBEgAikDAIVCKIkiETcDACATIBEgEykDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgCCARIAgpAwCFQjCJIhE3AwAgCyARIAspAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAIgESACKQMAhUIBiTcDACANIA0pAwAiESADKQMAIhJ8IBFCAYZC/v///x+DIBJC/////w+DfnwiETcDACAFIBEgBSkDAIVCIIkiETcDACAAIBEgACkDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgAyARIAMpAwCFQiiJIhE3AwAgDSARIA0pAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAUgESAFKQMAhUIwiSIRNwMAIAAgESAAKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACADIBEgAykDAIVCAYk3AwAgDiAOKQMAIhEgBCkDACISfCARQgGGQv7///8fgyASQv////8Pg358IhE3AwAgBiARIAYpAwCFQiCJIhE3AwAgCSARIAkpAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAQgESAEKQMAhUIoiSIRNwMAIA4gESAOKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACAGIBEgBikDAIVCMIkiETcDACAJIBEgCSkDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgBCARIAQpAwCFQgGJNwMAIA8gDykDACIRIAEpAwAiEnwgEUIBhkL+////H4MgEkL/////D4N+fCIRNwMAIAcgESAHKQMAhUIgiSIRNwMAIAogESAKKQMAIhJ8IBFC/////w+DIBJCAYZC/v///x+DfnwiETcDACABIBEgASkDAIVCKIkiETcDACAPIBEgDykDACISfCARQv////8PgyASQgGGQv7///8fg358IhE3AwAgByARIAcpAwCFQjCJIhE3AwAgCiARIAopAwAiEnwgEUL/////D4MgEkIBhkL+////H4N+fCIRNwMAIAEgESABKQMAhUIBiTcDAAvdCAEPfwNAIAIgBUEDdCIGaiABIAZqKQMAIAAgBmopAwCFNwMAIAIgBkEIciIGaiABIAZqKQMAIAAgBmopAwCFNwMAIAVBAmoiBUGAAUcNAAsDQCADIARBA3QiAGogACACaikDADcDACADIARBAXIiAEEDdCIBaiABIAJqKQMANwMAIAMgBEECciIBQQN0IgVqIAIgBWopAwA3AwAgAyAEQQNyIgVBA3Qi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A2opAwAgBCkDAIU3AwAgAiAAQQhyIgRqIgUgAyAEaikDACAFKQMAhTcDACACIABBEHIiBGoiBSADIARqKQMAIAUpAwCFNwMAIAIgAEEYciIAaiIEIAAgA2opAwAgBCkDAIU3AwAgAUEEaiIBQYABRw0ACwsWACAAIAEgAiADEAMgACACIAIgAxADC3sCAX8BfiACIQkgATUCACEKIAQgBXIEQCABKAIEIANwIQkLIAAgCTYCACAAIAdBAWsgBSAEGyAIbCAGQQFrQQBBfyAGGyACIAlGG2oiASAFQQFqIAhsQQAgBBtqIAGtIAogCn5CIIh+QiCIp0F/c2ogByAIbHA2AgQgAAsEACMACwYAIAAkAAsQACMAIABrQXBxIgAkACAACwUAQYAICw==', imports)}
44752
+
44753
+ const loadWasm = async () => setupWasm(
44754
+ (instanceObject) => wasmSIMD(instanceObject),
44755
+ (instanceObject) => wasmNonSIMD(instanceObject),
44756
+ );
44757
+
44758
+ var index = /*#__PURE__*/Object.freeze({
44759
+ __proto__: null,
44760
+ 'default': loadWasm
44761
+ });
44762
+
43843
44763
  export { AEADEncryptedDataPacket, CleartextMessage, CompressedDataPacket, LiteralDataPacket, MarkerPacket, Message, OnePassSignaturePacket, PacketList, PrivateKey, PublicKey, PublicKeyEncryptedSessionKeyPacket, PublicKeyPacket, PublicSubkeyPacket, SecretKeyPacket, SecretSubkeyPacket, Signature, SignaturePacket, Subkey, SymEncryptedIntegrityProtectedDataPacket, SymEncryptedSessionKeyPacket, SymmetricallyEncryptedDataPacket, TrustPacket, UnparseablePacket, UserAttributePacket, UserIDPacket, armor, config, createCleartextMessage, createMessage, decrypt$4 as decrypt, decryptKey, decryptSessionKeys, encrypt$4 as encrypt, encryptKey, encryptSessionKey, enums, generateKey, generateSessionKey$1 as generateSessionKey, readCleartextMessage, readKey, readKeys, readMessage, readPrivateKey, readPrivateKeys, readSignature, reformatKey, revokeKey, sign$5 as sign, unarmor, verify$5 as verify };