@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.
- package/dist/lightweight/argon2id.min.mjs +3 -0
- package/dist/lightweight/argon2id.min.mjs.map +1 -0
- package/dist/lightweight/{index.mjs → argon2id.mjs} +6 -7
- package/dist/lightweight/bn.interface.min.mjs +1 -1
- package/dist/lightweight/bn.interface.mjs +1 -1
- package/dist/lightweight/bn.min.mjs +1 -1
- package/dist/lightweight/bn.mjs +1 -1
- package/dist/lightweight/elliptic.min.mjs +1 -1
- package/dist/lightweight/elliptic.mjs +1 -1
- package/dist/lightweight/openpgp.min.mjs +2 -2
- package/dist/lightweight/openpgp.min.mjs.map +1 -1
- package/dist/lightweight/openpgp.mjs +379 -171
- package/dist/lightweight/ponyfill.es6.min.mjs +1 -1
- package/dist/lightweight/ponyfill.es6.mjs +1 -1
- package/dist/lightweight/web-streams-adapter.min.mjs +1 -1
- package/dist/lightweight/web-streams-adapter.mjs +1 -1
- package/dist/node/openpgp.js +1100 -180
- package/dist/node/openpgp.min.js +3 -3
- package/dist/node/openpgp.min.js.map +1 -1
- package/dist/node/openpgp.min.mjs +3 -3
- package/dist/node/openpgp.min.mjs.map +1 -1
- package/dist/node/openpgp.mjs +1100 -180
- package/dist/openpgp.js +1085 -171
- package/dist/openpgp.min.js +3 -3
- package/dist/openpgp.min.js.map +1 -1
- package/dist/openpgp.min.mjs +3 -3
- package/dist/openpgp.min.mjs.map +1 -1
- package/dist/openpgp.mjs +1085 -171
- package/openpgp.d.ts +10 -0
- package/package.json +3 -1
- package/dist/lightweight/index.min.mjs +0 -3
- package/dist/lightweight/index.min.mjs.map +0 -1
package/dist/openpgp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! OpenPGP.js v5.
|
|
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
|
var openpgp = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -2306,6 +2306,7 @@ var openpgp = (function (exports) {
|
|
|
2306
2306
|
simple: 0,
|
|
2307
2307
|
salted: 1,
|
|
2308
2308
|
iterated: 3,
|
|
2309
|
+
argon2: 4,
|
|
2309
2310
|
gnu: 101
|
|
2310
2311
|
},
|
|
2311
2312
|
|
|
@@ -2770,12 +2771,41 @@ var openpgp = (function (exports) {
|
|
|
2770
2771
|
*/
|
|
2771
2772
|
v5Keys: false,
|
|
2772
2773
|
/**
|
|
2773
|
-
*
|
|
2774
|
-
*
|
|
2774
|
+
* S2K (String to Key) type, used for key derivation in the context of secret key encryption
|
|
2775
|
+
* and password-encrypted data. Weaker s2k options are not allowed.
|
|
2776
|
+
* Note: Argon2 is the strongest option but not all OpenPGP implementations are compatible with it
|
|
2777
|
+
* (pending standardisation).
|
|
2778
|
+
* @memberof module:config
|
|
2779
|
+
* @property {enums.s2k.argon2|enums.s2k.iterated} s2kType {@link module:enums.s2k}
|
|
2780
|
+
*/
|
|
2781
|
+
s2kType: enums.s2k.iterated,
|
|
2782
|
+
/**
|
|
2783
|
+
* {@link https://tools.ietf.org/html/rfc4880#section-3.7.1.3| RFC4880 3.7.1.3}:
|
|
2784
|
+
* Iteration Count Byte for Iterated and Salted S2K (String to Key).
|
|
2785
|
+
* Only relevant if `config.s2kType` is set to `enums.s2k.iterated`.
|
|
2786
|
+
* Note: this is the exponent value, not the final number of iterations (refer to specs for more details).
|
|
2775
2787
|
* @memberof module:config
|
|
2776
2788
|
* @property {Integer} s2kIterationCountByte
|
|
2777
2789
|
*/
|
|
2778
2790
|
s2kIterationCountByte: 224,
|
|
2791
|
+
/**
|
|
2792
|
+
* {@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}:
|
|
2793
|
+
* Argon2 parameters for S2K (String to Key).
|
|
2794
|
+
* Only relevant if `config.s2kType` is set to `enums.s2k.argon2`.
|
|
2795
|
+
* Default settings correspond to the second recommendation from RFC9106 ("uniformly safe option"),
|
|
2796
|
+
* to ensure compatibility with memory-constrained environments.
|
|
2797
|
+
* For more details on the choice of parameters, see https://tools.ietf.org/html/rfc9106#section-4.
|
|
2798
|
+
* @memberof module:config
|
|
2799
|
+
* @property {Object} params
|
|
2800
|
+
* @property {Integer} params.passes - number of iterations t
|
|
2801
|
+
* @property {Integer} params.parallelism - degree of parallelism p
|
|
2802
|
+
* @property {Integer} params.memoryExponent - one-octet exponent indicating the memory size, which will be: 2**memoryExponent kibibytes.
|
|
2803
|
+
*/
|
|
2804
|
+
s2kArgon2Params: {
|
|
2805
|
+
passes: 3,
|
|
2806
|
+
parallelism: 4, // lanes
|
|
2807
|
+
memoryExponent: 16 // 64 MiB of RAM
|
|
2808
|
+
},
|
|
2779
2809
|
/**
|
|
2780
2810
|
* Allow decryption of messages without integrity protection.
|
|
2781
2811
|
* This is an **insecure** setting:
|
|
@@ -2885,7 +2915,7 @@ var openpgp = (function (exports) {
|
|
|
2885
2915
|
* @memberof module:config
|
|
2886
2916
|
* @property {String} versionString A version string to be included in armored messages
|
|
2887
2917
|
*/
|
|
2888
|
-
versionString: 'OpenPGP.js 5.
|
|
2918
|
+
versionString: 'OpenPGP.js 5.8.0-0',
|
|
2889
2919
|
/**
|
|
2890
2920
|
* @memberof module:config
|
|
2891
2921
|
* @property {String} commentString A comment string to be included in armored messages
|
|
@@ -15872,6 +15902,339 @@ var openpgp = (function (exports) {
|
|
|
15872
15902
|
|
|
15873
15903
|
Object.assign(mod, crypto$1);
|
|
15874
15904
|
|
|
15905
|
+
const ARGON2_TYPE = 0x02; // id
|
|
15906
|
+
const ARGON2_VERSION = 0x13;
|
|
15907
|
+
const ARGON2_SALT_SIZE = 16;
|
|
15908
|
+
|
|
15909
|
+
class Argon2OutOfMemoryError extends Error {
|
|
15910
|
+
constructor(...params) {
|
|
15911
|
+
super(...params);
|
|
15912
|
+
|
|
15913
|
+
if (Error.captureStackTrace) {
|
|
15914
|
+
Error.captureStackTrace(this, Argon2OutOfMemoryError);
|
|
15915
|
+
}
|
|
15916
|
+
|
|
15917
|
+
this.name = 'Argon2OutOfMemoryError';
|
|
15918
|
+
}
|
|
15919
|
+
}
|
|
15920
|
+
|
|
15921
|
+
// cache argon wasm module
|
|
15922
|
+
let loadArgonWasmModule;
|
|
15923
|
+
let argon2Promise;
|
|
15924
|
+
// reload wasm module above this treshold, to deallocated used memory
|
|
15925
|
+
const ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = 2 << 19;
|
|
15926
|
+
|
|
15927
|
+
class Argon2S2K {
|
|
15928
|
+
/**
|
|
15929
|
+
* @param {Object} [config] - Full configuration, defaults to openpgp.config
|
|
15930
|
+
*/
|
|
15931
|
+
constructor(config$1 = config) {
|
|
15932
|
+
const { passes, parallelism, memoryExponent } = config$1.s2kArgon2Params;
|
|
15933
|
+
|
|
15934
|
+
this.type = 'argon2';
|
|
15935
|
+
/** @type {Uint8Array} 16 bytes of salt */
|
|
15936
|
+
this.salt = null;
|
|
15937
|
+
/** @type {Integer} number of passes */
|
|
15938
|
+
this.t = passes;
|
|
15939
|
+
/** @type {Integer} degree of parallelism (lanes) */
|
|
15940
|
+
this.p = parallelism;
|
|
15941
|
+
/** @type {Integer} exponent indicating memory size */
|
|
15942
|
+
this.encodedM = memoryExponent;
|
|
15943
|
+
}
|
|
15944
|
+
|
|
15945
|
+
generateSalt() {
|
|
15946
|
+
this.salt = mod.random.getRandomBytes(ARGON2_SALT_SIZE);
|
|
15947
|
+
}
|
|
15948
|
+
|
|
15949
|
+
/**
|
|
15950
|
+
* Parsing function for argon2 string-to-key specifier.
|
|
15951
|
+
* @param {Uint8Array} bytes - Payload of argon2 string-to-key specifier
|
|
15952
|
+
* @returns {Integer} Actual length of the object.
|
|
15953
|
+
*/
|
|
15954
|
+
read(bytes) {
|
|
15955
|
+
let i = 0;
|
|
15956
|
+
|
|
15957
|
+
this.salt = bytes.subarray(i, i + 16);
|
|
15958
|
+
i += 16;
|
|
15959
|
+
|
|
15960
|
+
this.t = bytes[i++];
|
|
15961
|
+
this.p = bytes[i++];
|
|
15962
|
+
this.encodedM = bytes[i++]; // memory size exponent, one-octect
|
|
15963
|
+
|
|
15964
|
+
return i;
|
|
15965
|
+
}
|
|
15966
|
+
|
|
15967
|
+
/**
|
|
15968
|
+
* Serializes s2k information
|
|
15969
|
+
* @returns {Uint8Array} Binary representation of s2k.
|
|
15970
|
+
*/
|
|
15971
|
+
write() {
|
|
15972
|
+
const arr = [
|
|
15973
|
+
new Uint8Array([enums.write(enums.s2k, this.type)]),
|
|
15974
|
+
this.salt,
|
|
15975
|
+
new Uint8Array([this.t, this.p, this.encodedM])
|
|
15976
|
+
];
|
|
15977
|
+
|
|
15978
|
+
return util.concatUint8Array(arr);
|
|
15979
|
+
}
|
|
15980
|
+
|
|
15981
|
+
/**
|
|
15982
|
+
* Produces a key using the specified passphrase and the defined
|
|
15983
|
+
* hashAlgorithm
|
|
15984
|
+
* @param {String} passphrase - Passphrase containing user input
|
|
15985
|
+
* @returns {Promise<Uint8Array>} Produced key with a length corresponding to `keySize`
|
|
15986
|
+
* @throws {Argon2OutOfMemoryError|Errors}
|
|
15987
|
+
* @async
|
|
15988
|
+
*/
|
|
15989
|
+
async produceKey(passphrase, keySize) {
|
|
15990
|
+
const decodedM = 2 << (this.encodedM - 1);
|
|
15991
|
+
|
|
15992
|
+
try {
|
|
15993
|
+
if (!argon2Promise) { // first load
|
|
15994
|
+
loadArgonWasmModule = loadArgonWasmModule || (await Promise.resolve().then(function () { return index; })).default;
|
|
15995
|
+
argon2Promise = loadArgonWasmModule();
|
|
15996
|
+
}
|
|
15997
|
+
// important to keep local ref to argon2 in case the module is reloaded by another instance
|
|
15998
|
+
const argon2 = await argon2Promise;
|
|
15999
|
+
|
|
16000
|
+
const passwordBytes = util.encodeUTF8(passphrase);
|
|
16001
|
+
const hash = argon2({
|
|
16002
|
+
version: ARGON2_VERSION,
|
|
16003
|
+
type: ARGON2_TYPE,
|
|
16004
|
+
password: passwordBytes,
|
|
16005
|
+
salt: this.salt,
|
|
16006
|
+
tagLength: keySize,
|
|
16007
|
+
memorySize: decodedM,
|
|
16008
|
+
parallelism: this.p,
|
|
16009
|
+
passes: this.t
|
|
16010
|
+
});
|
|
16011
|
+
|
|
16012
|
+
// a lot of memory was used, reload to deallocate
|
|
16013
|
+
if (decodedM > ARGON2_WASM_MEMORY_THRESHOLD_RELOAD) {
|
|
16014
|
+
// it will be awaited if needed at the next `produceKey` invocation
|
|
16015
|
+
argon2Promise = loadArgonWasmModule();
|
|
16016
|
+
}
|
|
16017
|
+
return hash;
|
|
16018
|
+
} catch (e) {
|
|
16019
|
+
if (e.message && (
|
|
16020
|
+
e.message.includes('Unable to grow instance memory') || // Chrome
|
|
16021
|
+
e.message.includes('failed to grow memory') || // Firefox
|
|
16022
|
+
e.message.includes('WebAssembly.Memory.grow') || // Safari
|
|
16023
|
+
e.message.includes('Out of memory') // Safari iOS
|
|
16024
|
+
)) {
|
|
16025
|
+
throw new Argon2OutOfMemoryError('Could not allocate required memory for Argon2');
|
|
16026
|
+
} else {
|
|
16027
|
+
throw e;
|
|
16028
|
+
}
|
|
16029
|
+
}
|
|
16030
|
+
}
|
|
16031
|
+
}
|
|
16032
|
+
|
|
16033
|
+
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
16034
|
+
|
|
16035
|
+
class GenericS2K {
|
|
16036
|
+
/**
|
|
16037
|
+
* @param {Object} [config] - Full configuration, defaults to openpgp.config
|
|
16038
|
+
*/
|
|
16039
|
+
constructor(s2kType, config$1 = config) {
|
|
16040
|
+
/**
|
|
16041
|
+
* Hash function identifier, or 0 for gnu-dummy keys
|
|
16042
|
+
* @type {module:enums.hash | 0}
|
|
16043
|
+
*/
|
|
16044
|
+
this.algorithm = enums.hash.sha256;
|
|
16045
|
+
/**
|
|
16046
|
+
* enums.s2k identifier or 'gnu-dummy'
|
|
16047
|
+
* @type {String}
|
|
16048
|
+
*/
|
|
16049
|
+
this.type = enums.read(enums.s2k, s2kType);
|
|
16050
|
+
/** @type {Integer} */
|
|
16051
|
+
this.c = config$1.s2kIterationCountByte;
|
|
16052
|
+
/** Eight bytes of salt in a binary string.
|
|
16053
|
+
* @type {Uint8Array}
|
|
16054
|
+
*/
|
|
16055
|
+
this.salt = null;
|
|
16056
|
+
}
|
|
16057
|
+
|
|
16058
|
+
generateSalt() {
|
|
16059
|
+
switch (this.type) {
|
|
16060
|
+
case 'salted':
|
|
16061
|
+
case 'iterated':
|
|
16062
|
+
this.salt = mod.random.getRandomBytes(8);
|
|
16063
|
+
}
|
|
16064
|
+
}
|
|
16065
|
+
|
|
16066
|
+
getCount() {
|
|
16067
|
+
// Exponent bias, defined in RFC4880
|
|
16068
|
+
const expbias = 6;
|
|
16069
|
+
|
|
16070
|
+
return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
|
|
16071
|
+
}
|
|
16072
|
+
|
|
16073
|
+
/**
|
|
16074
|
+
* Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
|
|
16075
|
+
* @param {Uint8Array} bytes - Payload of string-to-key specifier
|
|
16076
|
+
* @returns {Integer} Actual length of the object.
|
|
16077
|
+
*/
|
|
16078
|
+
read(bytes) {
|
|
16079
|
+
let i = 0;
|
|
16080
|
+
this.algorithm = bytes[i++];
|
|
16081
|
+
|
|
16082
|
+
switch (this.type) {
|
|
16083
|
+
case 'simple':
|
|
16084
|
+
break;
|
|
16085
|
+
|
|
16086
|
+
case 'salted':
|
|
16087
|
+
this.salt = bytes.subarray(i, i + 8);
|
|
16088
|
+
i += 8;
|
|
16089
|
+
break;
|
|
16090
|
+
|
|
16091
|
+
case 'iterated':
|
|
16092
|
+
this.salt = bytes.subarray(i, i + 8);
|
|
16093
|
+
i += 8;
|
|
16094
|
+
|
|
16095
|
+
// Octet 10: count, a one-octet, coded value
|
|
16096
|
+
this.c = bytes[i++];
|
|
16097
|
+
break;
|
|
16098
|
+
case 'gnu':
|
|
16099
|
+
if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === 'GNU') {
|
|
16100
|
+
i += 3; // GNU
|
|
16101
|
+
const gnuExtType = 1000 + bytes[i++];
|
|
16102
|
+
if (gnuExtType === 1001) {
|
|
16103
|
+
this.type = 'gnu-dummy';
|
|
16104
|
+
// GnuPG extension mode 1001 -- don't write secret key at all
|
|
16105
|
+
} else {
|
|
16106
|
+
throw new Error('Unknown s2k gnu protection mode.');
|
|
16107
|
+
}
|
|
16108
|
+
} else {
|
|
16109
|
+
throw new Error('Unknown s2k type.');
|
|
16110
|
+
}
|
|
16111
|
+
break;
|
|
16112
|
+
|
|
16113
|
+
default:
|
|
16114
|
+
throw new Error('Unknown s2k type.');
|
|
16115
|
+
}
|
|
16116
|
+
|
|
16117
|
+
return i;
|
|
16118
|
+
}
|
|
16119
|
+
|
|
16120
|
+
/**
|
|
16121
|
+
* Serializes s2k information
|
|
16122
|
+
* @returns {Uint8Array} Binary representation of s2k.
|
|
16123
|
+
*/
|
|
16124
|
+
write() {
|
|
16125
|
+
if (this.type === 'gnu-dummy') {
|
|
16126
|
+
return new Uint8Array([101, 0, ...util.stringToUint8Array('GNU'), 1]);
|
|
16127
|
+
}
|
|
16128
|
+
const arr = [new Uint8Array([enums.write(enums.s2k, this.type), this.algorithm])];
|
|
16129
|
+
|
|
16130
|
+
switch (this.type) {
|
|
16131
|
+
case 'simple':
|
|
16132
|
+
break;
|
|
16133
|
+
case 'salted':
|
|
16134
|
+
arr.push(this.salt);
|
|
16135
|
+
break;
|
|
16136
|
+
case 'iterated':
|
|
16137
|
+
arr.push(this.salt);
|
|
16138
|
+
arr.push(new Uint8Array([this.c]));
|
|
16139
|
+
break;
|
|
16140
|
+
case 'gnu':
|
|
16141
|
+
throw new Error('GNU s2k type not supported.');
|
|
16142
|
+
default:
|
|
16143
|
+
throw new Error('Unknown s2k type.');
|
|
16144
|
+
}
|
|
16145
|
+
|
|
16146
|
+
return util.concatUint8Array(arr);
|
|
16147
|
+
}
|
|
16148
|
+
|
|
16149
|
+
/**
|
|
16150
|
+
* Produces a key using the specified passphrase and the defined
|
|
16151
|
+
* hashAlgorithm
|
|
16152
|
+
* @param {String} passphrase - Passphrase containing user input
|
|
16153
|
+
* @returns {Promise<Uint8Array>} Produced key with a length corresponding to.
|
|
16154
|
+
* hashAlgorithm hash length
|
|
16155
|
+
* @async
|
|
16156
|
+
*/
|
|
16157
|
+
async produceKey(passphrase, numBytes) {
|
|
16158
|
+
passphrase = util.encodeUTF8(passphrase);
|
|
16159
|
+
|
|
16160
|
+
const arr = [];
|
|
16161
|
+
let rlength = 0;
|
|
16162
|
+
|
|
16163
|
+
let prefixlen = 0;
|
|
16164
|
+
while (rlength < numBytes) {
|
|
16165
|
+
let toHash;
|
|
16166
|
+
switch (this.type) {
|
|
16167
|
+
case 'simple':
|
|
16168
|
+
toHash = util.concatUint8Array([new Uint8Array(prefixlen), passphrase]);
|
|
16169
|
+
break;
|
|
16170
|
+
case 'salted':
|
|
16171
|
+
toHash = util.concatUint8Array([new Uint8Array(prefixlen), this.salt, passphrase]);
|
|
16172
|
+
break;
|
|
16173
|
+
case 'iterated': {
|
|
16174
|
+
const data = util.concatUint8Array([this.salt, passphrase]);
|
|
16175
|
+
let datalen = data.length;
|
|
16176
|
+
const count = Math.max(this.getCount(), datalen);
|
|
16177
|
+
toHash = new Uint8Array(prefixlen + count);
|
|
16178
|
+
toHash.set(data, prefixlen);
|
|
16179
|
+
for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
|
|
16180
|
+
toHash.copyWithin(pos, prefixlen, pos);
|
|
16181
|
+
}
|
|
16182
|
+
break;
|
|
16183
|
+
}
|
|
16184
|
+
case 'gnu':
|
|
16185
|
+
throw new Error('GNU s2k type not supported.');
|
|
16186
|
+
default:
|
|
16187
|
+
throw new Error('Unknown s2k type.');
|
|
16188
|
+
}
|
|
16189
|
+
const result = await mod.hash.digest(this.algorithm, toHash);
|
|
16190
|
+
arr.push(result);
|
|
16191
|
+
rlength += result.length;
|
|
16192
|
+
prefixlen++;
|
|
16193
|
+
}
|
|
16194
|
+
|
|
16195
|
+
return util.concatUint8Array(arr).subarray(0, numBytes);
|
|
16196
|
+
}
|
|
16197
|
+
}
|
|
16198
|
+
|
|
16199
|
+
const allowedS2KTypesForEncryption = new Set([enums.s2k.argon2, enums.s2k.iterated]);
|
|
16200
|
+
|
|
16201
|
+
/**
|
|
16202
|
+
* Instantiate a new S2K instance of the given type
|
|
16203
|
+
* @param {module:enums.s2k} type
|
|
16204
|
+
* @oaram {Object} [config]
|
|
16205
|
+
* @returns {Object} New s2k object
|
|
16206
|
+
* @throws {Error} for unknown or unsupported types
|
|
16207
|
+
*/
|
|
16208
|
+
function newS2KFromType(type, config$1 = config) {
|
|
16209
|
+
switch (type) {
|
|
16210
|
+
case enums.s2k.argon2:
|
|
16211
|
+
return new Argon2S2K(config$1);
|
|
16212
|
+
case enums.s2k.iterated:
|
|
16213
|
+
case enums.s2k.gnu:
|
|
16214
|
+
case enums.s2k.salted:
|
|
16215
|
+
case enums.s2k.simple:
|
|
16216
|
+
return new GenericS2K(type, config$1);
|
|
16217
|
+
default:
|
|
16218
|
+
throw new Error(`Unsupported S2K type ${type}`);
|
|
16219
|
+
}
|
|
16220
|
+
}
|
|
16221
|
+
|
|
16222
|
+
/**
|
|
16223
|
+
* Instantiate a new S2K instance based on the config settings
|
|
16224
|
+
* @oaram {Object} config
|
|
16225
|
+
* @returns {Object} New s2k object
|
|
16226
|
+
* @throws {Error} for unknown or unsupported types
|
|
16227
|
+
*/
|
|
16228
|
+
function newS2KFromConfig(config) {
|
|
16229
|
+
const { s2kType } = config;
|
|
16230
|
+
|
|
16231
|
+
if (!allowedS2KTypesForEncryption.has(s2kType)) {
|
|
16232
|
+
throw new Error('The provided `config.s2kType` value is not allowed');
|
|
16233
|
+
}
|
|
16234
|
+
|
|
16235
|
+
return newS2KFromType(s2kType, config);
|
|
16236
|
+
}
|
|
16237
|
+
|
|
15875
16238
|
var TYPED_OK = typeof Uint8Array !== "undefined" &&
|
|
15876
16239
|
typeof Uint16Array !== "undefined" &&
|
|
15877
16240
|
typeof Int32Array !== "undefined";
|
|
@@ -24693,166 +25056,6 @@ var openpgp = (function (exports) {
|
|
|
24693
25056
|
|
|
24694
25057
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
24695
25058
|
|
|
24696
|
-
class S2K {
|
|
24697
|
-
/**
|
|
24698
|
-
* @param {Object} [config] - Full configuration, defaults to openpgp.config
|
|
24699
|
-
*/
|
|
24700
|
-
constructor(config$1 = config) {
|
|
24701
|
-
/**
|
|
24702
|
-
* Hash function identifier, or 0 for gnu-dummy keys
|
|
24703
|
-
* @type {module:enums.hash | 0}
|
|
24704
|
-
*/
|
|
24705
|
-
this.algorithm = enums.hash.sha256;
|
|
24706
|
-
/**
|
|
24707
|
-
* enums.s2k identifier or 'gnu-dummy'
|
|
24708
|
-
* @type {String}
|
|
24709
|
-
*/
|
|
24710
|
-
this.type = 'iterated';
|
|
24711
|
-
/** @type {Integer} */
|
|
24712
|
-
this.c = config$1.s2kIterationCountByte;
|
|
24713
|
-
/** Eight bytes of salt in a binary string.
|
|
24714
|
-
* @type {Uint8Array}
|
|
24715
|
-
*/
|
|
24716
|
-
this.salt = null;
|
|
24717
|
-
}
|
|
24718
|
-
|
|
24719
|
-
getCount() {
|
|
24720
|
-
// Exponent bias, defined in RFC4880
|
|
24721
|
-
const expbias = 6;
|
|
24722
|
-
|
|
24723
|
-
return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
|
|
24724
|
-
}
|
|
24725
|
-
|
|
24726
|
-
/**
|
|
24727
|
-
* Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
|
|
24728
|
-
* @param {Uint8Array} bytes - Payload of string-to-key specifier
|
|
24729
|
-
* @returns {Integer} Actual length of the object.
|
|
24730
|
-
*/
|
|
24731
|
-
read(bytes) {
|
|
24732
|
-
let i = 0;
|
|
24733
|
-
this.type = enums.read(enums.s2k, bytes[i++]);
|
|
24734
|
-
this.algorithm = bytes[i++];
|
|
24735
|
-
|
|
24736
|
-
switch (this.type) {
|
|
24737
|
-
case 'simple':
|
|
24738
|
-
break;
|
|
24739
|
-
|
|
24740
|
-
case 'salted':
|
|
24741
|
-
this.salt = bytes.subarray(i, i + 8);
|
|
24742
|
-
i += 8;
|
|
24743
|
-
break;
|
|
24744
|
-
|
|
24745
|
-
case 'iterated':
|
|
24746
|
-
this.salt = bytes.subarray(i, i + 8);
|
|
24747
|
-
i += 8;
|
|
24748
|
-
|
|
24749
|
-
// Octet 10: count, a one-octet, coded value
|
|
24750
|
-
this.c = bytes[i++];
|
|
24751
|
-
break;
|
|
24752
|
-
|
|
24753
|
-
case 'gnu':
|
|
24754
|
-
if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === 'GNU') {
|
|
24755
|
-
i += 3; // GNU
|
|
24756
|
-
const gnuExtType = 1000 + bytes[i++];
|
|
24757
|
-
if (gnuExtType === 1001) {
|
|
24758
|
-
this.type = 'gnu-dummy';
|
|
24759
|
-
// GnuPG extension mode 1001 -- don't write secret key at all
|
|
24760
|
-
} else {
|
|
24761
|
-
throw new Error('Unknown s2k gnu protection mode.');
|
|
24762
|
-
}
|
|
24763
|
-
} else {
|
|
24764
|
-
throw new Error('Unknown s2k type.');
|
|
24765
|
-
}
|
|
24766
|
-
break;
|
|
24767
|
-
|
|
24768
|
-
default:
|
|
24769
|
-
throw new Error('Unknown s2k type.');
|
|
24770
|
-
}
|
|
24771
|
-
|
|
24772
|
-
return i;
|
|
24773
|
-
}
|
|
24774
|
-
|
|
24775
|
-
/**
|
|
24776
|
-
* Serializes s2k information
|
|
24777
|
-
* @returns {Uint8Array} Binary representation of s2k.
|
|
24778
|
-
*/
|
|
24779
|
-
write() {
|
|
24780
|
-
if (this.type === 'gnu-dummy') {
|
|
24781
|
-
return new Uint8Array([101, 0, ...util.stringToUint8Array('GNU'), 1]);
|
|
24782
|
-
}
|
|
24783
|
-
const arr = [new Uint8Array([enums.write(enums.s2k, this.type), this.algorithm])];
|
|
24784
|
-
|
|
24785
|
-
switch (this.type) {
|
|
24786
|
-
case 'simple':
|
|
24787
|
-
break;
|
|
24788
|
-
case 'salted':
|
|
24789
|
-
arr.push(this.salt);
|
|
24790
|
-
break;
|
|
24791
|
-
case 'iterated':
|
|
24792
|
-
arr.push(this.salt);
|
|
24793
|
-
arr.push(new Uint8Array([this.c]));
|
|
24794
|
-
break;
|
|
24795
|
-
case 'gnu':
|
|
24796
|
-
throw new Error('GNU s2k type not supported.');
|
|
24797
|
-
default:
|
|
24798
|
-
throw new Error('Unknown s2k type.');
|
|
24799
|
-
}
|
|
24800
|
-
|
|
24801
|
-
return util.concatUint8Array(arr);
|
|
24802
|
-
}
|
|
24803
|
-
|
|
24804
|
-
/**
|
|
24805
|
-
* Produces a key using the specified passphrase and the defined
|
|
24806
|
-
* hashAlgorithm
|
|
24807
|
-
* @param {String} passphrase - Passphrase containing user input
|
|
24808
|
-
* @returns {Promise<Uint8Array>} Produced key with a length corresponding to.
|
|
24809
|
-
* hashAlgorithm hash length
|
|
24810
|
-
* @async
|
|
24811
|
-
*/
|
|
24812
|
-
async produceKey(passphrase, numBytes) {
|
|
24813
|
-
passphrase = util.encodeUTF8(passphrase);
|
|
24814
|
-
|
|
24815
|
-
const arr = [];
|
|
24816
|
-
let rlength = 0;
|
|
24817
|
-
|
|
24818
|
-
let prefixlen = 0;
|
|
24819
|
-
while (rlength < numBytes) {
|
|
24820
|
-
let toHash;
|
|
24821
|
-
switch (this.type) {
|
|
24822
|
-
case 'simple':
|
|
24823
|
-
toHash = util.concatUint8Array([new Uint8Array(prefixlen), passphrase]);
|
|
24824
|
-
break;
|
|
24825
|
-
case 'salted':
|
|
24826
|
-
toHash = util.concatUint8Array([new Uint8Array(prefixlen), this.salt, passphrase]);
|
|
24827
|
-
break;
|
|
24828
|
-
case 'iterated': {
|
|
24829
|
-
const data = util.concatUint8Array([this.salt, passphrase]);
|
|
24830
|
-
let datalen = data.length;
|
|
24831
|
-
const count = Math.max(this.getCount(), datalen);
|
|
24832
|
-
toHash = new Uint8Array(prefixlen + count);
|
|
24833
|
-
toHash.set(data, prefixlen);
|
|
24834
|
-
for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
|
|
24835
|
-
toHash.copyWithin(pos, prefixlen, pos);
|
|
24836
|
-
}
|
|
24837
|
-
break;
|
|
24838
|
-
}
|
|
24839
|
-
case 'gnu':
|
|
24840
|
-
throw new Error('GNU s2k type not supported.');
|
|
24841
|
-
default:
|
|
24842
|
-
throw new Error('Unknown s2k type.');
|
|
24843
|
-
}
|
|
24844
|
-
const result = await mod.hash.digest(this.algorithm, toHash);
|
|
24845
|
-
arr.push(result);
|
|
24846
|
-
rlength += result.length;
|
|
24847
|
-
prefixlen++;
|
|
24848
|
-
}
|
|
24849
|
-
|
|
24850
|
-
return util.concatUint8Array(arr).subarray(0, numBytes);
|
|
24851
|
-
}
|
|
24852
|
-
}
|
|
24853
|
-
|
|
24854
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
24855
|
-
|
|
24856
25059
|
/**
|
|
24857
25060
|
* Symmetric-Key Encrypted Session Key Packets (Tag 3)
|
|
24858
25061
|
*
|
|
@@ -24920,7 +25123,8 @@ var openpgp = (function (exports) {
|
|
|
24920
25123
|
}
|
|
24921
25124
|
|
|
24922
25125
|
// A string-to-key (S2K) specifier, length as defined above.
|
|
24923
|
-
|
|
25126
|
+
const s2kType = bytes[offset++];
|
|
25127
|
+
this.s2k = newS2KFromType(s2kType);
|
|
24924
25128
|
offset += this.s2k.read(bytes.subarray(offset, bytes.length));
|
|
24925
25129
|
|
|
24926
25130
|
if (this.version === 5) {
|
|
@@ -25009,8 +25213,8 @@ var openpgp = (function (exports) {
|
|
|
25009
25213
|
|
|
25010
25214
|
this.sessionKeyEncryptionAlgorithm = algo;
|
|
25011
25215
|
|
|
25012
|
-
this.s2k =
|
|
25013
|
-
this.s2k.
|
|
25216
|
+
this.s2k = newS2KFromConfig(config$1);
|
|
25217
|
+
this.s2k.generateSalt();
|
|
25014
25218
|
|
|
25015
25219
|
const { blockSize, keySize } = mod.getCipher(algo);
|
|
25016
25220
|
const encryptionKey = await this.s2k.produceKey(passphrase, keySize);
|
|
@@ -25636,7 +25840,8 @@ var openpgp = (function (exports) {
|
|
|
25636
25840
|
// - [Optional] If string-to-key usage octet was 255, 254, or 253, a
|
|
25637
25841
|
// string-to-key specifier. The length of the string-to-key
|
|
25638
25842
|
// specifier is implied by its type, as described above.
|
|
25639
|
-
|
|
25843
|
+
const s2kType = bytes[i++];
|
|
25844
|
+
this.s2k = newS2KFromType(s2kType);
|
|
25640
25845
|
i += this.s2k.read(bytes.subarray(i, bytes.length));
|
|
25641
25846
|
|
|
25642
25847
|
if (this.s2k.type === 'gnu-dummy') {
|
|
@@ -25774,7 +25979,7 @@ var openpgp = (function (exports) {
|
|
|
25774
25979
|
}
|
|
25775
25980
|
this.isEncrypted = null;
|
|
25776
25981
|
this.keyMaterial = null;
|
|
25777
|
-
this.s2k =
|
|
25982
|
+
this.s2k = newS2KFromType(enums.s2k.gnu, config$1);
|
|
25778
25983
|
this.s2k.algorithm = 0;
|
|
25779
25984
|
this.s2k.c = 0;
|
|
25780
25985
|
this.s2k.type = 'gnu-dummy';
|
|
@@ -25805,8 +26010,8 @@ var openpgp = (function (exports) {
|
|
|
25805
26010
|
throw new Error('A non-empty passphrase is required for key encryption.');
|
|
25806
26011
|
}
|
|
25807
26012
|
|
|
25808
|
-
this.s2k =
|
|
25809
|
-
this.s2k.
|
|
26013
|
+
this.s2k = newS2KFromConfig(config$1);
|
|
26014
|
+
this.s2k.generateSalt();
|
|
25810
26015
|
const cleartext = mod.serializeParams(this.algorithm, this.privateParams);
|
|
25811
26016
|
this.symmetric = enums.symmetric.aes256;
|
|
25812
26017
|
const key = await produceEncryptionKey(this.s2k, passphrase, this.symmetric);
|
|
@@ -29684,6 +29889,9 @@ var openpgp = (function (exports) {
|
|
|
29684
29889
|
decryptedSessionKeyPackets.push(skeskPacket);
|
|
29685
29890
|
} catch (err) {
|
|
29686
29891
|
util.printDebugError(err);
|
|
29892
|
+
if (err instanceof Argon2OutOfMemoryError) {
|
|
29893
|
+
exception = err;
|
|
29894
|
+
}
|
|
29687
29895
|
}
|
|
29688
29896
|
}));
|
|
29689
29897
|
}));
|
|
@@ -43831,6 +44039,712 @@ var openpgp = (function (exports) {
|
|
|
43831
44039
|
__moduleExports: elliptic_1
|
|
43832
44040
|
});
|
|
43833
44041
|
|
|
44042
|
+
// Adapted from the reference implementation in RFC7693
|
|
44043
|
+
// Initial port to Javascript by https://github.com/dcposch and https://github.com/emilbayes
|
|
44044
|
+
|
|
44045
|
+
// Uint64 values are represented using two Uint32s, stored as little endian
|
|
44046
|
+
// NB: Uint32Arrays endianness depends on the underlying system, so for interoperability, conversions between Uint8Array and Uint32Arrays
|
|
44047
|
+
// need to be manually handled
|
|
44048
|
+
|
|
44049
|
+
// 64-bit unsigned addition (little endian, in place)
|
|
44050
|
+
// Sets a[i,i+1] += b[j,j+1]
|
|
44051
|
+
// `a` and `b` must be Uint32Array(2)
|
|
44052
|
+
function ADD64 (a, i, b, j) {
|
|
44053
|
+
a[i] += b[j];
|
|
44054
|
+
a[i+1] += b[j+1] + (a[i] < b[j]); // add carry
|
|
44055
|
+
}
|
|
44056
|
+
|
|
44057
|
+
// Increment 64-bit little-endian unsigned value by `c` (in place)
|
|
44058
|
+
// `a` must be Uint32Array(2)
|
|
44059
|
+
function INC64 (a, c) {
|
|
44060
|
+
a[0] += c;
|
|
44061
|
+
a[1] += (a[0] < c);
|
|
44062
|
+
}
|
|
44063
|
+
|
|
44064
|
+
// G Mixing function
|
|
44065
|
+
// The ROTRs are inlined for speed
|
|
44066
|
+
function G (v, m, a, b, c, d, ix, iy) {
|
|
44067
|
+
ADD64(v, a, v, b); // v[a,a+1] += v[b,b+1]
|
|
44068
|
+
ADD64(v, a, m, ix); // v[a, a+1] += x ... x0
|
|
44069
|
+
|
|
44070
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
44071
|
+
let xor0 = v[d] ^ v[a];
|
|
44072
|
+
let xor1 = v[d + 1] ^ v[a + 1];
|
|
44073
|
+
v[d] = xor1;
|
|
44074
|
+
v[d + 1] = xor0;
|
|
44075
|
+
|
|
44076
|
+
ADD64(v, c, v, d);
|
|
44077
|
+
|
|
44078
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
44079
|
+
xor0 = v[b] ^ v[c];
|
|
44080
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
44081
|
+
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
44082
|
+
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
44083
|
+
|
|
44084
|
+
ADD64(v, a, v, b);
|
|
44085
|
+
ADD64(v, a, m, iy);
|
|
44086
|
+
|
|
44087
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
44088
|
+
xor0 = v[d] ^ v[a];
|
|
44089
|
+
xor1 = v[d + 1] ^ v[a + 1];
|
|
44090
|
+
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
44091
|
+
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
44092
|
+
|
|
44093
|
+
ADD64(v, c, v, d);
|
|
44094
|
+
|
|
44095
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
44096
|
+
xor0 = v[b] ^ v[c];
|
|
44097
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
44098
|
+
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
44099
|
+
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
44100
|
+
}
|
|
44101
|
+
|
|
44102
|
+
// Initialization Vector
|
|
44103
|
+
const BLAKE2B_IV32 = new Uint32Array([
|
|
44104
|
+
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
44105
|
+
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
44106
|
+
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
44107
|
+
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
44108
|
+
]);
|
|
44109
|
+
|
|
44110
|
+
// These are offsets into a Uint64 buffer.
|
|
44111
|
+
// Multiply them all by 2 to make them offsets into a Uint32 buffer
|
|
44112
|
+
const SIGMA = new Uint8Array([
|
|
44113
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
44114
|
+
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
44115
|
+
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
44116
|
+
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
44117
|
+
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
44118
|
+
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
44119
|
+
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
44120
|
+
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
44121
|
+
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
44122
|
+
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
44123
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
44124
|
+
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
44125
|
+
].map(x => x * 2));
|
|
44126
|
+
|
|
44127
|
+
// Compression function. 'last' flag indicates last block.
|
|
44128
|
+
// Note: we're representing 16 uint64s as 32 uint32s
|
|
44129
|
+
function compress(S, last) {
|
|
44130
|
+
const v = new Uint32Array(32);
|
|
44131
|
+
const m = new Uint32Array(S.b.buffer, S.b.byteOffset, 32);
|
|
44132
|
+
|
|
44133
|
+
// init work variables
|
|
44134
|
+
for (let i = 0; i < 16; i++) {
|
|
44135
|
+
v[i] = S.h[i];
|
|
44136
|
+
v[i + 16] = BLAKE2B_IV32[i];
|
|
44137
|
+
}
|
|
44138
|
+
|
|
44139
|
+
// low 64 bits of offset
|
|
44140
|
+
v[24] ^= S.t0[0];
|
|
44141
|
+
v[25] ^= S.t0[1];
|
|
44142
|
+
// high 64 bits not supported (`t1`), offset may not be higher than 2**53-1
|
|
44143
|
+
|
|
44144
|
+
// if last block
|
|
44145
|
+
const f0 = last ? 0xFFFFFFFF : 0;
|
|
44146
|
+
v[28] ^= f0;
|
|
44147
|
+
v[29] ^= f0;
|
|
44148
|
+
|
|
44149
|
+
// twelve rounds of mixing
|
|
44150
|
+
for (let i = 0; i < 12; i++) {
|
|
44151
|
+
// ROUND(r)
|
|
44152
|
+
const i16 = i << 4;
|
|
44153
|
+
G(v, m, 0, 8, 16, 24, SIGMA[i16 + 0], SIGMA[i16 + 1]);
|
|
44154
|
+
G(v, m, 2, 10, 18, 26, SIGMA[i16 + 2], SIGMA[i16 + 3]);
|
|
44155
|
+
G(v, m, 4, 12, 20, 28, SIGMA[i16 + 4], SIGMA[i16 + 5]);
|
|
44156
|
+
G(v, m, 6, 14, 22, 30, SIGMA[i16 + 6], SIGMA[i16 + 7]);
|
|
44157
|
+
G(v, m, 0, 10, 20, 30, SIGMA[i16 + 8], SIGMA[i16 + 9]);
|
|
44158
|
+
G(v, m, 2, 12, 22, 24, SIGMA[i16 + 10], SIGMA[i16 + 11]);
|
|
44159
|
+
G(v, m, 4, 14, 16, 26, SIGMA[i16 + 12], SIGMA[i16 + 13]);
|
|
44160
|
+
G(v, m, 6, 8, 18, 28, SIGMA[i16 + 14], SIGMA[i16 + 15]);
|
|
44161
|
+
}
|
|
44162
|
+
|
|
44163
|
+
for (let i = 0; i < 16; i++) {
|
|
44164
|
+
S.h[i] ^= v[i] ^ v[i + 16];
|
|
44165
|
+
}
|
|
44166
|
+
}
|
|
44167
|
+
|
|
44168
|
+
// Creates a BLAKE2b hashing context
|
|
44169
|
+
// Requires an output length between 1 and 64 bytes
|
|
44170
|
+
// Takes an optional Uint8Array key
|
|
44171
|
+
class Blake2b {
|
|
44172
|
+
constructor(outlen, key, salt, personal) {
|
|
44173
|
+
const params = new Uint8Array(64);
|
|
44174
|
+
// 0: outlen, keylen, fanout, depth
|
|
44175
|
+
// 4: leaf length, sequential mode
|
|
44176
|
+
// 8: node offset
|
|
44177
|
+
// 12: node offset
|
|
44178
|
+
// 16: node depth, inner length, rfu
|
|
44179
|
+
// 20: rfu
|
|
44180
|
+
// 24: rfu
|
|
44181
|
+
// 28: rfu
|
|
44182
|
+
// 32: salt
|
|
44183
|
+
// 36: salt
|
|
44184
|
+
// 40: salt
|
|
44185
|
+
// 44: salt
|
|
44186
|
+
// 48: personal
|
|
44187
|
+
// 52: personal
|
|
44188
|
+
// 56: personal
|
|
44189
|
+
// 60: personal
|
|
44190
|
+
|
|
44191
|
+
// init internal state
|
|
44192
|
+
this.S = {
|
|
44193
|
+
b: new Uint8Array(BLOCKBYTES),
|
|
44194
|
+
h: new Uint32Array(OUTBYTES_MAX / 4),
|
|
44195
|
+
t0: new Uint32Array(2), // input counter `t`, lower 64-bits only
|
|
44196
|
+
c: 0, // `fill`, pointer within buffer, up to `BLOCKBYTES`
|
|
44197
|
+
outlen // output length in bytes
|
|
44198
|
+
};
|
|
44199
|
+
|
|
44200
|
+
// init parameter block
|
|
44201
|
+
params[0] = outlen;
|
|
44202
|
+
if (key) params[1] = key.length;
|
|
44203
|
+
params[2] = 1; // fanout
|
|
44204
|
+
params[3] = 1; // depth
|
|
44205
|
+
if (salt) params.set(salt, 32);
|
|
44206
|
+
if (personal) params.set(personal, 48);
|
|
44207
|
+
const params32 = new Uint32Array(params.buffer, params.byteOffset, params.length / Uint32Array.BYTES_PER_ELEMENT);
|
|
44208
|
+
|
|
44209
|
+
// initialize hash state
|
|
44210
|
+
for (let i = 0; i < 16; i++) {
|
|
44211
|
+
this.S.h[i] = BLAKE2B_IV32[i] ^ params32[i];
|
|
44212
|
+
}
|
|
44213
|
+
|
|
44214
|
+
// key the hash, if applicable
|
|
44215
|
+
if (key) {
|
|
44216
|
+
const block = new Uint8Array(BLOCKBYTES);
|
|
44217
|
+
block.set(key);
|
|
44218
|
+
this.update(block);
|
|
44219
|
+
}
|
|
44220
|
+
}
|
|
44221
|
+
|
|
44222
|
+
// Updates a BLAKE2b streaming hash
|
|
44223
|
+
// Requires Uint8Array (byte array)
|
|
44224
|
+
update(input) {
|
|
44225
|
+
if (!(input instanceof Uint8Array)) throw new Error('Input must be Uint8Array or Buffer')
|
|
44226
|
+
// for (let i = 0; i < input.length; i++) {
|
|
44227
|
+
// if (this.S.c === BLOCKBYTES) { // buffer full
|
|
44228
|
+
// INC64(this.S.t0, this.S.c) // add counters
|
|
44229
|
+
// compress(this.S, false)
|
|
44230
|
+
// this.S.c = 0 // empty buffer
|
|
44231
|
+
// }
|
|
44232
|
+
// this.S.b[this.S.c++] = input[i]
|
|
44233
|
+
// }
|
|
44234
|
+
let i = 0;
|
|
44235
|
+
while(i < input.length) {
|
|
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
|
+
let left = BLOCKBYTES - this.S.c;
|
|
44242
|
+
this.S.b.set(input.subarray(i, i + left), this.S.c); // end index can be out of bounds
|
|
44243
|
+
const fill = Math.min(left, input.length - i);
|
|
44244
|
+
this.S.c += fill;
|
|
44245
|
+
i += fill;
|
|
44246
|
+
}
|
|
44247
|
+
return this
|
|
44248
|
+
}
|
|
44249
|
+
|
|
44250
|
+
/**
|
|
44251
|
+
* Return a BLAKE2b hash, either filling the given Uint8Array or allocating a new one
|
|
44252
|
+
* @param {Uint8Array} [prealloc] - optional preallocated buffer
|
|
44253
|
+
* @returns {ArrayBuffer} message digest
|
|
44254
|
+
*/
|
|
44255
|
+
digest(prealloc) {
|
|
44256
|
+
INC64(this.S.t0, this.S.c); // mark last block offset
|
|
44257
|
+
|
|
44258
|
+
// final block, padded
|
|
44259
|
+
this.S.b.fill(0, this.S.c);
|
|
44260
|
+
this.S.c = BLOCKBYTES;
|
|
44261
|
+
compress(this.S, true);
|
|
44262
|
+
|
|
44263
|
+
const out = prealloc || new Uint8Array(this.S.outlen);
|
|
44264
|
+
for (let i = 0; i < this.S.outlen; i++) {
|
|
44265
|
+
// must be loaded individually since default Uint32 endianness is platform dependant
|
|
44266
|
+
out[i] = this.S.h[i >> 2] >> (8 * (i & 3));
|
|
44267
|
+
}
|
|
44268
|
+
this.S.h = null; // prevent calling `update` after `digest`
|
|
44269
|
+
return out.buffer;
|
|
44270
|
+
}
|
|
44271
|
+
}
|
|
44272
|
+
|
|
44273
|
+
|
|
44274
|
+
function createHash(outlen, key, salt, personal) {
|
|
44275
|
+
if (outlen > OUTBYTES_MAX) throw new Error(`outlen must be at most ${OUTBYTES_MAX} (given: ${outlen})`)
|
|
44276
|
+
if (key) {
|
|
44277
|
+
if (!(key instanceof Uint8Array)) throw new Error('key must be Uint8Array or Buffer')
|
|
44278
|
+
if (key.length > KEYBYTES_MAX) throw new Error(`key size must be at most ${KEYBYTES_MAX} (given: ${key.length})`)
|
|
44279
|
+
}
|
|
44280
|
+
if (salt) {
|
|
44281
|
+
if (!(salt instanceof Uint8Array)) throw new Error('salt must be Uint8Array or Buffer')
|
|
44282
|
+
if (salt.length !== SALTBYTES) throw new Error(`salt must be exactly ${SALTBYTES} (given: ${salt.length}`)
|
|
44283
|
+
}
|
|
44284
|
+
if (personal) {
|
|
44285
|
+
if (!(personal instanceof Uint8Array)) throw new Error('personal must be Uint8Array or Buffer')
|
|
44286
|
+
if (personal.length !== PERSONALBYTES) throw new Error(`salt must be exactly ${PERSONALBYTES} (given: ${personal.length}`)
|
|
44287
|
+
}
|
|
44288
|
+
|
|
44289
|
+
return new Blake2b(outlen, key, salt, personal)
|
|
44290
|
+
}
|
|
44291
|
+
|
|
44292
|
+
const OUTBYTES_MAX = 64;
|
|
44293
|
+
const KEYBYTES_MAX = 64;
|
|
44294
|
+
const SALTBYTES = 16;
|
|
44295
|
+
const PERSONALBYTES = 16;
|
|
44296
|
+
const BLOCKBYTES = 128;
|
|
44297
|
+
|
|
44298
|
+
const TYPE$2 = 2; // Argon2id
|
|
44299
|
+
const VERSION$4 = 0x13;
|
|
44300
|
+
const TAGBYTES_MAX = 0xFFFFFFFF; // Math.pow(2, 32) - 1;
|
|
44301
|
+
const TAGBYTES_MIN = 4; // Math.pow(2, 32) - 1;
|
|
44302
|
+
const SALTBYTES_MAX = 0xFFFFFFFF; // Math.pow(2, 32) - 1;
|
|
44303
|
+
const SALTBYTES_MIN = 8;
|
|
44304
|
+
const passwordBYTES_MAX = 0xFFFFFFFF;// Math.pow(2, 32) - 1;
|
|
44305
|
+
const passwordBYTES_MIN = 8;
|
|
44306
|
+
const MEMBYTES_MAX = 0xFFFFFFFF;// Math.pow(2, 32) - 1;
|
|
44307
|
+
const ADBYTES_MAX = 0xFFFFFFFF; // Math.pow(2, 32) - 1; // associated data (optional)
|
|
44308
|
+
const SECRETBYTES_MAX = 32; // key (optional)
|
|
44309
|
+
|
|
44310
|
+
const ARGON2_BLOCK_SIZE = 1024;
|
|
44311
|
+
const ARGON2_PREHASH_DIGEST_LENGTH = 64;
|
|
44312
|
+
|
|
44313
|
+
const isLittleEndian$1 = new Uint8Array(new Uint16Array([0xabcd]).buffer)[0] === 0xcd;
|
|
44314
|
+
|
|
44315
|
+
// store n as a little-endian 32-bit Uint8Array inside buf (at buf[i:i+3])
|
|
44316
|
+
function LE32(buf, n, i) {
|
|
44317
|
+
buf[i+0] = n;
|
|
44318
|
+
buf[i+1] = n >> 8;
|
|
44319
|
+
buf[i+2] = n >> 16;
|
|
44320
|
+
buf[i+3] = n >> 24;
|
|
44321
|
+
return buf;
|
|
44322
|
+
}
|
|
44323
|
+
|
|
44324
|
+
/**
|
|
44325
|
+
* Store n as a 64-bit LE number in the given buffer (from buf[i] to buf[i+7])
|
|
44326
|
+
* @param {Uint8Array} buf
|
|
44327
|
+
* @param {Number} n
|
|
44328
|
+
* @param {Number} i
|
|
44329
|
+
*/
|
|
44330
|
+
function LE64(buf, n, i) {
|
|
44331
|
+
if (n > Number.MAX_SAFE_INTEGER) throw new Error("LE64: large numbers unsupported");
|
|
44332
|
+
// ECMAScript standard has engines convert numbers to 32-bit integers for bitwise operations
|
|
44333
|
+
// shifting by 32 or more bits is not supported (https://stackoverflow.com/questions/6729122/javascript-bit-shift-number-wraps)
|
|
44334
|
+
// so we manually extract each byte
|
|
44335
|
+
let remainder = n;
|
|
44336
|
+
for (let offset = i; offset < i+7; offset++) { // last byte can be ignored as it would overflow MAX_SAFE_INTEGER
|
|
44337
|
+
buf[offset] = remainder; // implicit & 0xff
|
|
44338
|
+
remainder = (remainder - buf[offset]) / 256;
|
|
44339
|
+
}
|
|
44340
|
+
return buf;
|
|
44341
|
+
}
|
|
44342
|
+
|
|
44343
|
+
/**
|
|
44344
|
+
* Variable-Length Hash Function H'
|
|
44345
|
+
* @param {Number} outlen - T
|
|
44346
|
+
* @param {Uint8Array} X - value to hash
|
|
44347
|
+
* @param {Uint8Array} res - output buffer, of length `outlength` or larger
|
|
44348
|
+
*/
|
|
44349
|
+
function H_(outlen, X, res) {
|
|
44350
|
+
const V = new Uint8Array(64); // no need to keep around all V_i
|
|
44351
|
+
|
|
44352
|
+
const V1_in = new Uint8Array(4 + X.length);
|
|
44353
|
+
LE32(V1_in, outlen, 0);
|
|
44354
|
+
V1_in.set(X, 4);
|
|
44355
|
+
if (outlen <= 64) {
|
|
44356
|
+
// H'^T(A) = H^T(LE32(T)||A)
|
|
44357
|
+
createHash(outlen).update(V1_in).digest(res);
|
|
44358
|
+
return res
|
|
44359
|
+
}
|
|
44360
|
+
|
|
44361
|
+
const r = Math.ceil(outlen / 32) - 2;
|
|
44362
|
+
|
|
44363
|
+
// Let V_i be a 64-byte block and W_i be its first 32 bytes.
|
|
44364
|
+
// V_1 = H^(64)(LE32(T)||A)
|
|
44365
|
+
// V_2 = H^(64)(V_1)
|
|
44366
|
+
// ...
|
|
44367
|
+
// V_r = H^(64)(V_{r-1})
|
|
44368
|
+
// V_{r+1} = H^(T-32*r)(V_{r})
|
|
44369
|
+
// H'^T(X) = W_1 || W_2 || ... || W_r || V_{r+1}
|
|
44370
|
+
for (let i = 0; i < r; i++) {
|
|
44371
|
+
createHash(64).update(i === 0 ? V1_in : V).digest(V);
|
|
44372
|
+
// store W_i in result buffer already
|
|
44373
|
+
res.set(V.subarray(0, 32), i*32);
|
|
44374
|
+
}
|
|
44375
|
+
// V_{r+1}
|
|
44376
|
+
const V_r1 = new Uint8Array(createHash(outlen - 32*r).update(V).digest());
|
|
44377
|
+
res.set(V_r1, r*32);
|
|
44378
|
+
|
|
44379
|
+
return res;
|
|
44380
|
+
}
|
|
44381
|
+
|
|
44382
|
+
// compute buf = xs ^ ys
|
|
44383
|
+
function XOR(wasmContext, buf, xs, ys) {
|
|
44384
|
+
wasmContext.fn.XOR(
|
|
44385
|
+
buf.byteOffset,
|
|
44386
|
+
xs.byteOffset,
|
|
44387
|
+
ys.byteOffset,
|
|
44388
|
+
);
|
|
44389
|
+
return buf
|
|
44390
|
+
}
|
|
44391
|
+
|
|
44392
|
+
/**
|
|
44393
|
+
* @param {Uint8Array} X (read-only)
|
|
44394
|
+
* @param {Uint8Array} Y (read-only)
|
|
44395
|
+
* @param {Uint8Array} R - output buffer
|
|
44396
|
+
* @returns
|
|
44397
|
+
*/
|
|
44398
|
+
function G$1(wasmContext, X, Y, R) {
|
|
44399
|
+
wasmContext.fn.G(
|
|
44400
|
+
X.byteOffset,
|
|
44401
|
+
Y.byteOffset,
|
|
44402
|
+
R.byteOffset,
|
|
44403
|
+
wasmContext.refs.gZ.byteOffset
|
|
44404
|
+
);
|
|
44405
|
+
return R;
|
|
44406
|
+
}
|
|
44407
|
+
|
|
44408
|
+
function G2(wasmContext, X, Y, R) {
|
|
44409
|
+
wasmContext.fn.G2(
|
|
44410
|
+
X.byteOffset,
|
|
44411
|
+
Y.byteOffset,
|
|
44412
|
+
R.byteOffset,
|
|
44413
|
+
wasmContext.refs.gZ.byteOffset
|
|
44414
|
+
);
|
|
44415
|
+
return R;
|
|
44416
|
+
}
|
|
44417
|
+
|
|
44418
|
+
// Generator for data-independent J1, J2. Each `next()` invocation returns a new pair of values.
|
|
44419
|
+
function* makePRNG(wasmContext, pass, lane, slice, m_, totalPasses, segmentLength, segmentOffset) {
|
|
44420
|
+
// For each segment, we do the following. First, we compute the value Z as:
|
|
44421
|
+
// Z= ( LE64(r) || LE64(l) || LE64(sl) || LE64(m') || LE64(t) || LE64(y) )
|
|
44422
|
+
wasmContext.refs.prngTmp.fill(0);
|
|
44423
|
+
const Z = wasmContext.refs.prngTmp.subarray(0, 6 * 8);
|
|
44424
|
+
LE64(Z, pass, 0);
|
|
44425
|
+
LE64(Z, lane, 8);
|
|
44426
|
+
LE64(Z, slice, 16);
|
|
44427
|
+
LE64(Z, m_, 24);
|
|
44428
|
+
LE64(Z, totalPasses, 32);
|
|
44429
|
+
LE64(Z, TYPE$2, 40);
|
|
44430
|
+
|
|
44431
|
+
// Then we compute q/(128*SL) 1024-byte values
|
|
44432
|
+
// G( ZERO(1024),
|
|
44433
|
+
// G( ZERO(1024), Z || LE64(1) || ZERO(968) ) ),
|
|
44434
|
+
// ...,
|
|
44435
|
+
// G( ZERO(1024),
|
|
44436
|
+
// G( ZERO(1024), Z || LE64(q/(128*SL)) || ZERO(968) )),
|
|
44437
|
+
for(let i = 1; i <= segmentLength; i++) {
|
|
44438
|
+
// tmp.set(Z); // no need to re-copy
|
|
44439
|
+
LE64(wasmContext.refs.prngTmp, i, Z.length); // tmp.set(ZER0968) not necessary, memory already zeroed
|
|
44440
|
+
const g2 = G2(wasmContext, wasmContext.refs.ZERO1024, wasmContext.refs.prngTmp, wasmContext.refs.prngR );
|
|
44441
|
+
|
|
44442
|
+
// each invocation of G^2 outputs 1024 bytes that are to be partitioned into 8-bytes values, take as X1 || X2
|
|
44443
|
+
// NB: the first generated pair must be used for the first block of the segment, and so on.
|
|
44444
|
+
// Hence, if some blocks are skipped (e.g. during the first pass), the corresponding J1J2 are discarded based on the given segmentOffset.
|
|
44445
|
+
for(let k = i === 1 ? segmentOffset*8 : 0; k < g2.length; k += 8) {
|
|
44446
|
+
yield g2.subarray(k, k+8);
|
|
44447
|
+
}
|
|
44448
|
+
}
|
|
44449
|
+
return [];
|
|
44450
|
+
}
|
|
44451
|
+
|
|
44452
|
+
function validateParams$7({ type, version, tagLength, password, salt, ad, secret, parallelism, memorySize, passes }) {
|
|
44453
|
+
const assertLength = (name, value, min, max) => {
|
|
44454
|
+
if (value < min || value > max) { throw new Error(`${name} size should be between ${min} and ${max} bytes`); }
|
|
44455
|
+
};
|
|
44456
|
+
|
|
44457
|
+
if (type !== TYPE$2 || version !== VERSION$4) throw new Error('Unsupported type or version');
|
|
44458
|
+
assertLength('password', password, passwordBYTES_MIN, passwordBYTES_MAX);
|
|
44459
|
+
assertLength('salt', salt, SALTBYTES_MIN, SALTBYTES_MAX);
|
|
44460
|
+
assertLength('tag', tagLength, TAGBYTES_MIN, TAGBYTES_MAX);
|
|
44461
|
+
assertLength('memory', memorySize, 8*parallelism, MEMBYTES_MAX);
|
|
44462
|
+
// optional fields
|
|
44463
|
+
ad && assertLength('associated data', ad, 0, ADBYTES_MAX);
|
|
44464
|
+
secret && assertLength('secret', secret, 0, SECRETBYTES_MAX);
|
|
44465
|
+
|
|
44466
|
+
return { type, version, tagLength, password, salt, ad, secret, lanes: parallelism, memorySize, passes };
|
|
44467
|
+
}
|
|
44468
|
+
|
|
44469
|
+
const KB = 1024;
|
|
44470
|
+
const WASM_PAGE_SIZE = 64 * KB;
|
|
44471
|
+
|
|
44472
|
+
function argon2id(params, { memory, instance: wasmInstance }) {
|
|
44473
|
+
if (!isLittleEndian$1) throw new Error('BigEndian system not supported'); // optmisations assume LE system
|
|
44474
|
+
|
|
44475
|
+
const ctx = validateParams$7({ type: TYPE$2, version: VERSION$4, ...params });
|
|
44476
|
+
|
|
44477
|
+
const { G:wasmG, G2:wasmG2, xor:wasmXOR, getLZ:wasmLZ } = wasmInstance.exports;
|
|
44478
|
+
const wasmRefs = {};
|
|
44479
|
+
const wasmFn = {};
|
|
44480
|
+
wasmFn.G = wasmG;
|
|
44481
|
+
wasmFn.G2 = wasmG2;
|
|
44482
|
+
wasmFn.XOR = wasmXOR;
|
|
44483
|
+
|
|
44484
|
+
// The actual number of blocks is m', which is m rounded down to the nearest multiple of 4*p.
|
|
44485
|
+
const m_ = 4 * ctx.lanes * Math.floor(ctx.memorySize / (4 * ctx.lanes));
|
|
44486
|
+
const requiredMemory = m_ * ARGON2_BLOCK_SIZE + 10 * KB; // Additional KBs for utility references
|
|
44487
|
+
if (memory.buffer.byteLength < requiredMemory) {
|
|
44488
|
+
const missing = Math.ceil((requiredMemory - memory.buffer.byteLength) / WASM_PAGE_SIZE);
|
|
44489
|
+
// If enough memory is available, the `memory.buffer` is internally detached and the reference updated.
|
|
44490
|
+
// Otherwise, the operation fails, and the original memory can still be used.
|
|
44491
|
+
memory.grow(missing);
|
|
44492
|
+
}
|
|
44493
|
+
|
|
44494
|
+
let offset = 0;
|
|
44495
|
+
// Init wasm memory needed in other functions
|
|
44496
|
+
wasmRefs.gZ = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+= wasmRefs.gZ.length;
|
|
44497
|
+
wasmRefs.prngR = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+=wasmRefs.prngR.length;
|
|
44498
|
+
wasmRefs.prngTmp = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+=wasmRefs.prngTmp.length;
|
|
44499
|
+
wasmRefs.ZERO1024 = new Uint8Array(memory.buffer, offset, 1024); offset+=wasmRefs.ZERO1024.length;
|
|
44500
|
+
// Init wasm memory needed locally
|
|
44501
|
+
const lz = new Uint32Array(memory.buffer, offset, 2); offset+=lz.length * Uint32Array.BYTES_PER_ELEMENT;
|
|
44502
|
+
const wasmContext = { fn: wasmFn, refs: wasmRefs };
|
|
44503
|
+
const newBlock = new Uint8Array(memory.buffer, offset, ARGON2_BLOCK_SIZE); offset+=newBlock.length;
|
|
44504
|
+
const blockMemory = new Uint8Array(memory.buffer, offset, ctx.memorySize * ARGON2_BLOCK_SIZE);
|
|
44505
|
+
const allocatedMemory = new Uint8Array(memory.buffer, 0, offset);
|
|
44506
|
+
|
|
44507
|
+
// 1. Establish H_0
|
|
44508
|
+
const H0 = getH0(ctx);
|
|
44509
|
+
|
|
44510
|
+
// 2. Allocate the memory as m' 1024-byte blocks
|
|
44511
|
+
// For p lanes, the memory is organized in a matrix B[i][j] of blocks with p rows (lanes) and q = m' / p columns.
|
|
44512
|
+
const q = m_ / ctx.lanes;
|
|
44513
|
+
const B = new Array(ctx.lanes).fill(null).map(() => new Array(q));
|
|
44514
|
+
const initBlock = (i, j) => {
|
|
44515
|
+
B[i][j] = blockMemory.subarray(i*q*1024 + j*1024, (i*q*1024 + j*1024) + ARGON2_BLOCK_SIZE);
|
|
44516
|
+
return B[i][j];
|
|
44517
|
+
};
|
|
44518
|
+
|
|
44519
|
+
for (let i = 0; i < ctx.lanes; i++) {
|
|
44520
|
+
// const LEi = LE0; // since p = 1 for us
|
|
44521
|
+
const tmp = new Uint8Array(H0.length + 8);
|
|
44522
|
+
// 3. Compute B[i][0] for all i ranging from (and including) 0 to (not including) p
|
|
44523
|
+
// B[i][0] = H'^(1024)(H_0 || LE32(0) || LE32(i))
|
|
44524
|
+
tmp.set(H0); LE32(tmp, 0, H0.length); LE32(tmp, i, H0.length + 4);
|
|
44525
|
+
H_(ARGON2_BLOCK_SIZE, tmp, initBlock(i, 0));
|
|
44526
|
+
// 4. Compute B[i][1] for all i ranging from (and including) 0 to (not including) p
|
|
44527
|
+
// B[i][1] = H'^(1024)(H_0 || LE32(1) || LE32(i))
|
|
44528
|
+
LE32(tmp, 1, H0.length);
|
|
44529
|
+
H_(ARGON2_BLOCK_SIZE, tmp, initBlock(i, 1));
|
|
44530
|
+
}
|
|
44531
|
+
|
|
44532
|
+
// 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
|
|
44533
|
+
// to (not including) q. The computation MUST proceed slicewise (Section 3.4) : first, blocks from slice 0 are computed for all lanes
|
|
44534
|
+
// (in an arbitrary order of lanes), then blocks from slice 1 are computed, etc.
|
|
44535
|
+
const SL = 4; // vertical slices
|
|
44536
|
+
const segmentLength = q / SL;
|
|
44537
|
+
for (let pass = 0; pass < ctx.passes; pass++) {
|
|
44538
|
+
// 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
|
|
44539
|
+
for (let sl = 0; sl < SL; sl++) {
|
|
44540
|
+
const isDataIndependent = pass === 0 && sl <= 1;
|
|
44541
|
+
for (let i = 0; i < ctx.lanes; i++) { // lane
|
|
44542
|
+
// On the first slice of the first pass, blocks 0 and 1 are already filled
|
|
44543
|
+
let segmentOffset = sl === 0 && pass === 0 ? 2 : 0;
|
|
44544
|
+
// no need to generate all J1J2s, use iterator/generator that creates the value on the fly (to save memory)
|
|
44545
|
+
const PRNG = isDataIndependent ? makePRNG(wasmContext, pass, i, sl, m_, ctx.passes, segmentLength, segmentOffset) : null;
|
|
44546
|
+
for (segmentOffset; segmentOffset < segmentLength; segmentOffset++) {
|
|
44547
|
+
const j = sl * segmentLength + segmentOffset;
|
|
44548
|
+
const prevBlock = j > 0 ? B[i][j-1] : B[i][q-1]; // B[i][(j-1) mod q]
|
|
44549
|
+
|
|
44550
|
+
// we can assume the PRNG is never done
|
|
44551
|
+
const J1J2 = isDataIndependent ? PRNG.next().value : prevBlock; // .subarray(0, 8) not required since we only pass the byteOffset to wasm
|
|
44552
|
+
// The block indices l and z are determined for each i, j differently for Argon2d, Argon2i, and Argon2id.
|
|
44553
|
+
wasmLZ(lz.byteOffset, J1J2.byteOffset, i, ctx.lanes, pass, sl, segmentOffset, SL, segmentLength);
|
|
44554
|
+
const l = lz[0]; const z = lz[1];
|
|
44555
|
+
// for (let i = 0; i < p; i++ )
|
|
44556
|
+
// B[i][j] = G(B[i][j-1], B[l][z])
|
|
44557
|
+
// The block indices l and z are determined for each i, j differently for Argon2d, Argon2i, and Argon2id.
|
|
44558
|
+
if (pass === 0) initBlock(i, j);
|
|
44559
|
+
G$1(wasmContext, prevBlock, B[l][z], pass > 0 ? newBlock : B[i][j]);
|
|
44560
|
+
|
|
44561
|
+
// 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
|
|
44562
|
+
if (pass > 0) XOR(wasmContext, B[i][j], newBlock, B[i][j]);
|
|
44563
|
+
}
|
|
44564
|
+
}
|
|
44565
|
+
}
|
|
44566
|
+
}
|
|
44567
|
+
|
|
44568
|
+
// 7. After t steps have been iterated, the final block C is computed as the XOR of the last column:
|
|
44569
|
+
// C = B[0][q-1] XOR B[1][q-1] XOR ... XOR B[p-1][q-1]
|
|
44570
|
+
const C = B[0][q-1];
|
|
44571
|
+
for(let i = 1; i < ctx.lanes; i++) {
|
|
44572
|
+
XOR(wasmContext, C, C, B[i][q-1]);
|
|
44573
|
+
}
|
|
44574
|
+
|
|
44575
|
+
const tag = H_(ctx.tagLength, C, new Uint8Array(ctx.tagLength));
|
|
44576
|
+
// clear memory since the module might be cached
|
|
44577
|
+
allocatedMemory.fill(0); // clear sensitive contents
|
|
44578
|
+
memory.grow(0); // allow deallocation
|
|
44579
|
+
// 8. The output tag is computed as H'^T(C).
|
|
44580
|
+
return tag;
|
|
44581
|
+
|
|
44582
|
+
}
|
|
44583
|
+
|
|
44584
|
+
function getH0(ctx) {
|
|
44585
|
+
const H = createHash(ARGON2_PREHASH_DIGEST_LENGTH);
|
|
44586
|
+
const ZERO32 = new Uint8Array(4);
|
|
44587
|
+
const params = new Uint8Array(24);
|
|
44588
|
+
LE32(params, ctx.lanes, 0);
|
|
44589
|
+
LE32(params, ctx.tagLength, 4);
|
|
44590
|
+
LE32(params, ctx.memorySize, 8);
|
|
44591
|
+
LE32(params, ctx.passes, 12);
|
|
44592
|
+
LE32(params, ctx.version, 16);
|
|
44593
|
+
LE32(params, ctx.type, 20);
|
|
44594
|
+
|
|
44595
|
+
const toHash = [params];
|
|
44596
|
+
if (ctx.password) {
|
|
44597
|
+
toHash.push(LE32(new Uint8Array(4), ctx.password.length, 0));
|
|
44598
|
+
toHash.push(ctx.password);
|
|
44599
|
+
} else {
|
|
44600
|
+
toHash.push(ZERO32); // context.password.length
|
|
44601
|
+
}
|
|
44602
|
+
|
|
44603
|
+
if (ctx.salt) {
|
|
44604
|
+
toHash.push(LE32(new Uint8Array(4), ctx.salt.length, 0));
|
|
44605
|
+
toHash.push(ctx.salt);
|
|
44606
|
+
} else {
|
|
44607
|
+
toHash.push(ZERO32); // context.salt.length
|
|
44608
|
+
}
|
|
44609
|
+
|
|
44610
|
+
if (ctx.secret) {
|
|
44611
|
+
toHash.push(LE32(new Uint8Array(4), ctx.secret.length, 0));
|
|
44612
|
+
toHash.push(ctx.secret);
|
|
44613
|
+
// todo clear secret?
|
|
44614
|
+
} else {
|
|
44615
|
+
toHash.push(ZERO32); // context.secret.length
|
|
44616
|
+
}
|
|
44617
|
+
|
|
44618
|
+
if (ctx.ad) {
|
|
44619
|
+
toHash.push(LE32(new Uint8Array(4), ctx.ad.length, 0));
|
|
44620
|
+
toHash.push(ctx.ad);
|
|
44621
|
+
} else {
|
|
44622
|
+
toHash.push(ZERO32); // context.ad.length
|
|
44623
|
+
}
|
|
44624
|
+
H.update(concatArrays(toHash));
|
|
44625
|
+
|
|
44626
|
+
const outputBuffer = H.digest();
|
|
44627
|
+
return new Uint8Array(outputBuffer);
|
|
44628
|
+
}
|
|
44629
|
+
|
|
44630
|
+
function concatArrays(arrays) {
|
|
44631
|
+
if (arrays.length === 1) return arrays[0];
|
|
44632
|
+
|
|
44633
|
+
let totalLength = 0;
|
|
44634
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
44635
|
+
if (!(arrays[i] instanceof Uint8Array)) {
|
|
44636
|
+
throw new Error('concatArrays: Data must be in the form of a Uint8Array');
|
|
44637
|
+
}
|
|
44638
|
+
|
|
44639
|
+
totalLength += arrays[i].length;
|
|
44640
|
+
}
|
|
44641
|
+
|
|
44642
|
+
const result = new Uint8Array(totalLength);
|
|
44643
|
+
let pos = 0;
|
|
44644
|
+
arrays.forEach((element) => {
|
|
44645
|
+
result.set(element, pos);
|
|
44646
|
+
pos += element.length;
|
|
44647
|
+
});
|
|
44648
|
+
|
|
44649
|
+
return result;
|
|
44650
|
+
}
|
|
44651
|
+
|
|
44652
|
+
let isSIMDSupported;
|
|
44653
|
+
async function wasmLoader(memory, getSIMD, getNonSIMD) {
|
|
44654
|
+
const importObject = { env: { memory } };
|
|
44655
|
+
if (isSIMDSupported === undefined) {
|
|
44656
|
+
try {
|
|
44657
|
+
isSIMDSupported = true; // will be overwritten in the catch
|
|
44658
|
+
return await getSIMD(importObject);
|
|
44659
|
+
} catch(e) {
|
|
44660
|
+
isSIMDSupported = false;
|
|
44661
|
+
}
|
|
44662
|
+
}
|
|
44663
|
+
|
|
44664
|
+
const loader = isSIMDSupported ? getSIMD : getNonSIMD;
|
|
44665
|
+
return loader(importObject);
|
|
44666
|
+
}
|
|
44667
|
+
|
|
44668
|
+
async function setupWasm(getSIMD, getNonSIMD) {
|
|
44669
|
+
const memory = new WebAssembly.Memory({
|
|
44670
|
+
// in pages of 64KiB each
|
|
44671
|
+
// these values need to be compatible with those declared when building in `build-wasm`
|
|
44672
|
+
initial: 1040, // 65MB
|
|
44673
|
+
maximum: 65536, // 4GB
|
|
44674
|
+
});
|
|
44675
|
+
const wasmModule = await wasmLoader(memory, getSIMD, getNonSIMD);
|
|
44676
|
+
|
|
44677
|
+
/**
|
|
44678
|
+
* Argon2id hash function
|
|
44679
|
+
* @callback computeHash
|
|
44680
|
+
* @param {Object} params
|
|
44681
|
+
* @param {Uint8Array} params.password - password
|
|
44682
|
+
* @param {Uint8Array} params.salt - salt
|
|
44683
|
+
* @param {Integer} params.parallelism
|
|
44684
|
+
* @param {Integer} params.passes
|
|
44685
|
+
* @param {Integer} params.memorySize - in kibibytes
|
|
44686
|
+
* @param {Integer} params.tagLength - output tag length
|
|
44687
|
+
* @param {Uint8Array} [params.ad] - associated data (optional)
|
|
44688
|
+
* @param {Uint8Array} [params.secret] - secret data (optional)
|
|
44689
|
+
* @return {Uint8Array} argon2id hash
|
|
44690
|
+
*/
|
|
44691
|
+
const computeHash = (params) => argon2id(params, { instance: wasmModule.instance, memory });
|
|
44692
|
+
|
|
44693
|
+
return computeHash;
|
|
44694
|
+
}
|
|
44695
|
+
|
|
44696
|
+
function _loadWasmModule (sync, filepath, src, imports) {
|
|
44697
|
+
function _instantiateOrCompile(source, imports, stream) {
|
|
44698
|
+
var instantiateFunc = stream ? WebAssembly.instantiateStreaming : WebAssembly.instantiate;
|
|
44699
|
+
var compileFunc = stream ? WebAssembly.compileStreaming : WebAssembly.compile;
|
|
44700
|
+
|
|
44701
|
+
if (imports) {
|
|
44702
|
+
return instantiateFunc(source, imports)
|
|
44703
|
+
} else {
|
|
44704
|
+
return compileFunc(source)
|
|
44705
|
+
}
|
|
44706
|
+
}
|
|
44707
|
+
|
|
44708
|
+
|
|
44709
|
+
var buf = null;
|
|
44710
|
+
if (filepath) {
|
|
44711
|
+
|
|
44712
|
+
return _instantiateOrCompile(fetch(filepath), imports, true);
|
|
44713
|
+
|
|
44714
|
+
}
|
|
44715
|
+
|
|
44716
|
+
|
|
44717
|
+
var raw = globalThis.atob(src);
|
|
44718
|
+
var rawLength = raw.length;
|
|
44719
|
+
buf = new Uint8Array(new ArrayBuffer(rawLength));
|
|
44720
|
+
for(var i = 0; i < rawLength; i++) {
|
|
44721
|
+
buf[i] = raw.charCodeAt(i);
|
|
44722
|
+
}
|
|
44723
|
+
|
|
44724
|
+
|
|
44725
|
+
|
|
44726
|
+
if(sync) {
|
|
44727
|
+
var mod = new WebAssembly.Module(buf);
|
|
44728
|
+
return imports ? new WebAssembly.Instance(mod, imports) : mod
|
|
44729
|
+
} else {
|
|
44730
|
+
return _instantiateOrCompile(buf, imports, false)
|
|
44731
|
+
}
|
|
44732
|
+
}
|
|
44733
|
+
|
|
44734
|
+
function wasmSIMD(imports){return _loadWasmModule(0, null, 'AGFzbQEAAAABKwdgBH9/f38AYAABf2AAAGADf39/AGAJf39/f39/f39/AX9gAX8AYAF/AX8CEwEDZW52Bm1lbW9yeQIBkAiAgAQDCgkCAwAABAEFBgEEBQFwAQICBgkBfwFBkIjAAgsHfQoDeG9yAAEBRwACAkcyAAMFZ2V0TFoABBlfX2luZGlyZWN0X2Z1bmN0aW9uX3RhYmxlAQALX2luaXRpYWxpemUAABBfX2Vycm5vX2xvY2F0aW9uAAgJc3RhY2tTYXZlAAUMc3RhY2tSZXN0b3JlAAYKc3RhY2tBbGxvYwAHCQcBAEEBCwEACs0gCQMAAQtYAQJ/A0AgACAEQQR0IgNqIAIgA2r9AAQAIAEgA2r9AAQA/VH9CwQAIAAgA0EQciIDaiACIANq/QAEACABIANq/QAEAP1R/QsEACAEQQJqIgRBwABHDQALC7ceAgt7A38DQCADIBFBBHQiD2ogASAPav0ABAAgACAPav0ABAD9USIF/QsEACACIA9qIAX9CwQAIAMgD0EQciIPaiABIA9q/QAEACAAIA9q/QAEAP1RIgX9CwQAIAIgD2ogBf0LBAAgEUECaiI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IgQgBP0NAAECAwQFBgcQERITFBUWF/0NCAkKCwwNDg8YGRobHB0eH/0LBIAGIAAgBCAFIAX9DQABAgMEBQYHEBESExQVFhf9DQgJCgsMDQ4PGBkaGxwdHh/9CwSAByAAIAQgCP3OASAEIAT9DQABAgMICQoLAAECAwgJCgsgCCAI/Q0AAQIDCAkKCwABAgMICQoL/d4BQQH9ywH9zgEiBP0LBIAEIAAgBSAJ/c4BIAUgBf0NAAECAwgJCgsAAQIDCAkKCyAJIAn9DQABAgMICQoLAAECAwgJCgv93gFBAf3LAf3OASIJ/QsEgAUgACAEIAf9USIFQQH9ywEgBUE//c0B/VAiBSAJIAr9USIEQQH9ywEgBEE//c0B/VAiBCAE/Q0AAQIDBAUGBxAREhMUFRYX/Q0ICQoLDA0ODxgZGhscHR4f/QsEgAIgACAEIAUgBf0NAAECAwQFBgcQERITFBUWF/0NCAkKCwwNDg8YGRobHB0eH/0LBIADIBBBAWoiEEEIRw0AC0EAIRADQCACIBBBBHQiAGoiASAAIANq/QAEACAB/QAEAP1R/QsEACACIABBEHIiAWoiDyABIANq/QAEACAP/QAEAP1R/QsEACACIABBIHIiAWoiDyABIANq/QAEACAP/QAEAP1R/QsEACACIABBMHIiAGoiASAAIANq/QAEACAB/QAEAP1R/QsEACAQQQRqIhBBwABHDQALCxYAIAAgASACIAMQAiAAIAIgAiADEAILewIBfwF+IAIhCSABNQIAIQogBCAFcgRAIAEoAgQgA3AhCQsgACAJNgIAIAAgB0EBayAFIAQbIAhsIAZBAWtBAEF/IAYbIAIgCUYbaiIBIAVBAWogCGxBACAEG2ogAa0gCiAKfkIgiH5CIIinQX9zaiAHIAhscDYCBCAACwQAIwALBgAgACQACxAAIwAgAGtBcHEiACQAIAALBQBBgAgL', imports)}
|
|
44735
|
+
|
|
44736
|
+
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+fCIRNwMAIAEgESABKQMAhUIBiTcDAAvdCAEPfwNAIAIgBUEDdCIGaiABIAZqKQMAIAAgBmopAwCFNwMAIAIgBkEIciIGaiABIAZqKQMAIAAgBmopAwCFNwMAIAVBAmoiBUGAAUcNAAsDQCADIARBA3QiAGogACACaikDADcDACADIARBAXIiAEEDdCIBaiABIAJqKQMANwMAIAMgBEECciIBQQN0IgVqIAIgBWopAwA3AwAgAyAEQQNyIgVBA3QiBmogAiAGaikDADcDACADIARBBHIiBkEDdCIHaiACIAdqKQMANwMAIAMgBEEFciIHQQN0IghqIAIgCGopAwA3AwAgAyAEQQZyIghBA3QiCWogAiAJaikDADcDACADIARBB3IiCUEDdCIKaiACIApqKQMANwMAIAMgBEEIciIKQQN0IgtqIAIgC2opAwA3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AxADC3sCAX8BfiACIQkgATUCACEKIAQgBXIEQCABKAIEIANwIQkLIAAgCTYCACAAIAdBAWsgBSAEGyAIbCAGQQFrQQBBfyAGGyACIAlGG2oiASAFQQFqIAhsQQAgBBtqIAGtIAogCn5CIIh+QiCIp0F/c2ogByAIbHA2AgQgAAsEACMACwYAIAAkAAsQACMAIABrQXBxIgAkACAACwUAQYAICw==', imports)}
|
|
44737
|
+
|
|
44738
|
+
const loadWasm = async () => setupWasm(
|
|
44739
|
+
(instanceObject) => wasmSIMD(instanceObject),
|
|
44740
|
+
(instanceObject) => wasmNonSIMD(instanceObject),
|
|
44741
|
+
);
|
|
44742
|
+
|
|
44743
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
44744
|
+
__proto__: null,
|
|
44745
|
+
'default': loadWasm
|
|
44746
|
+
});
|
|
44747
|
+
|
|
43834
44748
|
exports.AEADEncryptedDataPacket = AEADEncryptedDataPacket;
|
|
43835
44749
|
exports.CleartextMessage = CleartextMessage;
|
|
43836
44750
|
exports.CompressedDataPacket = CompressedDataPacket;
|