@protontech/openpgp 6.0.0-beta.1 → 6.0.0-beta.2
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/README.md +2 -2
- package/dist/lightweight/argon2id.min.mjs +1 -1
- package/dist/lightweight/argon2id.mjs +1 -1
- package/dist/lightweight/legacy_ciphers.min.mjs +1 -1
- package/dist/lightweight/legacy_ciphers.mjs +1 -1
- package/dist/lightweight/noble_curves.min.mjs +1 -1
- package/dist/lightweight/noble_curves.mjs +1 -1
- package/dist/lightweight/noble_hashes.min.mjs +1 -1
- package/dist/lightweight/noble_hashes.mjs +1 -1
- package/dist/lightweight/openpgp.min.mjs +3 -2
- package/dist/lightweight/openpgp.min.mjs.map +1 -1
- package/dist/lightweight/openpgp.mjs +1011 -168
- package/dist/lightweight/sha3.min.mjs +1 -1
- package/dist/lightweight/sha3.mjs +1 -1
- package/dist/node/openpgp.cjs +985 -134
- package/dist/node/openpgp.min.cjs +12 -11
- package/dist/node/openpgp.min.cjs.map +1 -1
- package/dist/node/openpgp.min.mjs +12 -11
- package/dist/node/openpgp.min.mjs.map +1 -1
- package/dist/node/openpgp.mjs +984 -134
- package/dist/openpgp.js +1011 -168
- package/dist/openpgp.min.js +12 -11
- package/dist/openpgp.min.js.map +1 -1
- package/dist/openpgp.min.mjs +12 -11
- package/dist/openpgp.min.mjs.map +1 -1
- package/dist/openpgp.mjs +1011 -168
- package/openpgp.d.ts +8 -1
- package/package.json +6 -5
package/dist/node/openpgp.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/*! OpenPGP.js v6.0.0-beta.
|
|
1
|
+
/*! OpenPGP.js v6.0.0-beta.2 - 2024-07-05 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
5
5
|
|
|
6
6
|
var module$1 = require('module');
|
|
7
7
|
var nc = require('node:crypto');
|
|
8
|
+
var nodeCrypto$b = require('crypto');
|
|
8
9
|
|
|
9
10
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
11
|
function _interopNamespaceDefault(e) {
|
|
@@ -25,6 +26,7 @@ function _interopNamespaceDefault(e) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
var nc__namespace = /*#__PURE__*/_interopNamespaceDefault(nc);
|
|
29
|
+
var nodeCrypto__namespace = /*#__PURE__*/_interopNamespaceDefault(nodeCrypto$b);
|
|
28
30
|
|
|
29
31
|
const doneWritingPromise = Symbol('doneWritingPromise');
|
|
30
32
|
const doneWritingResolve = Symbol('doneWritingResolve');
|
|
@@ -568,9 +570,10 @@ function transformRaw(input, options) {
|
|
|
568
570
|
* @param {Function} cancel
|
|
569
571
|
* @returns {TransformStream}
|
|
570
572
|
*/
|
|
571
|
-
function transformWithCancel(
|
|
573
|
+
function transformWithCancel(customCancel) {
|
|
572
574
|
let pulled = false;
|
|
573
|
-
let
|
|
575
|
+
let cancelled = false;
|
|
576
|
+
let backpressureChangePromiseResolve, backpressureChangePromiseReject;
|
|
574
577
|
let outputController;
|
|
575
578
|
return {
|
|
576
579
|
readable: new ReadableStream({
|
|
@@ -584,16 +587,29 @@ function transformWithCancel(cancel) {
|
|
|
584
587
|
pulled = true;
|
|
585
588
|
}
|
|
586
589
|
},
|
|
587
|
-
cancel
|
|
590
|
+
async cancel(reason) {
|
|
591
|
+
cancelled = true;
|
|
592
|
+
if (customCancel) {
|
|
593
|
+
await customCancel(reason);
|
|
594
|
+
}
|
|
595
|
+
if (backpressureChangePromiseReject) {
|
|
596
|
+
backpressureChangePromiseReject(reason);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
588
599
|
}, {highWaterMark: 0}),
|
|
589
600
|
writable: new WritableStream({
|
|
590
601
|
write: async function(chunk) {
|
|
602
|
+
if (cancelled) {
|
|
603
|
+
throw new Error('Stream is cancelled');
|
|
604
|
+
}
|
|
591
605
|
outputController.enqueue(chunk);
|
|
592
606
|
if (!pulled) {
|
|
593
|
-
await new Promise(resolve => {
|
|
607
|
+
await new Promise((resolve, reject) => {
|
|
594
608
|
backpressureChangePromiseResolve = resolve;
|
|
609
|
+
backpressureChangePromiseReject = reject;
|
|
595
610
|
});
|
|
596
611
|
backpressureChangePromiseResolve = null;
|
|
612
|
+
backpressureChangePromiseReject = null;
|
|
597
613
|
} else {
|
|
598
614
|
pulled = false;
|
|
599
615
|
}
|
|
@@ -1529,6 +1545,14 @@ var config = {
|
|
|
1529
1545
|
* @property {Boolean} v6Keys
|
|
1530
1546
|
*/
|
|
1531
1547
|
v6Keys: false,
|
|
1548
|
+
/**
|
|
1549
|
+
* Enable parsing v5 keys and v5 signatures (which is different from the AEAD-encrypted SEIPDv2 packet).
|
|
1550
|
+
* These are non-standard entities, which in the crypto-refresh have been superseded
|
|
1551
|
+
* by v6 keys and v6 signatures, respectively.
|
|
1552
|
+
* However, generation of v5 entities was supported behind config flag in OpenPGP.js v5, and some other libraries,
|
|
1553
|
+
* hence parsing them might be necessary in some cases.
|
|
1554
|
+
*/
|
|
1555
|
+
enableParsingV5Entities: false,
|
|
1532
1556
|
/**
|
|
1533
1557
|
* S2K (String to Key) type, used for key derivation in the context of secret key encryption
|
|
1534
1558
|
* and password-encrypted data. Weaker s2k options are not allowed.
|
|
@@ -1685,7 +1709,7 @@ var config = {
|
|
|
1685
1709
|
* @memberof module:config
|
|
1686
1710
|
* @property {String} versionString A version string to be included in armored messages
|
|
1687
1711
|
*/
|
|
1688
|
-
versionString: 'OpenPGP.js 6.0.0-beta.
|
|
1712
|
+
versionString: 'OpenPGP.js 6.0.0-beta.2',
|
|
1689
1713
|
/**
|
|
1690
1714
|
* @memberof module:config
|
|
1691
1715
|
* @property {String} commentString A comment string to be included in armored messages
|
|
@@ -5858,8 +5882,8 @@ var mode = {
|
|
|
5858
5882
|
};
|
|
5859
5883
|
|
|
5860
5884
|
// Operations are not constant time, but we try and limit timing leakage where we can
|
|
5861
|
-
const _0n$
|
|
5862
|
-
const _1n$
|
|
5885
|
+
const _0n$9 = BigInt(0);
|
|
5886
|
+
const _1n$e = BigInt(1);
|
|
5863
5887
|
function uint8ArrayToBigInt(bytes) {
|
|
5864
5888
|
const hexAlphabet = '0123456789ABCDEF';
|
|
5865
5889
|
let s = '';
|
|
@@ -5868,9 +5892,9 @@ function uint8ArrayToBigInt(bytes) {
|
|
|
5868
5892
|
});
|
|
5869
5893
|
return BigInt('0x0' + s);
|
|
5870
5894
|
}
|
|
5871
|
-
function mod$
|
|
5895
|
+
function mod$3(a, m) {
|
|
5872
5896
|
const reduced = a % m;
|
|
5873
|
-
return reduced < _0n$
|
|
5897
|
+
return reduced < _0n$9 ? reduced + m : reduced;
|
|
5874
5898
|
}
|
|
5875
5899
|
/**
|
|
5876
5900
|
* Compute modular exponentiation using square and multiply
|
|
@@ -5880,19 +5904,19 @@ function mod$2(a, m) {
|
|
|
5880
5904
|
* @returns {BigInt} b ** e mod n.
|
|
5881
5905
|
*/
|
|
5882
5906
|
function modExp(b, e, n) {
|
|
5883
|
-
if (n === _0n$
|
|
5907
|
+
if (n === _0n$9)
|
|
5884
5908
|
throw Error('Modulo cannot be zero');
|
|
5885
|
-
if (n === _1n$
|
|
5909
|
+
if (n === _1n$e)
|
|
5886
5910
|
return BigInt(0);
|
|
5887
|
-
if (e < _0n$
|
|
5911
|
+
if (e < _0n$9)
|
|
5888
5912
|
throw Error('Unsopported negative exponent');
|
|
5889
5913
|
let exp = e;
|
|
5890
5914
|
let x = b;
|
|
5891
5915
|
x %= n;
|
|
5892
5916
|
let r = BigInt(1);
|
|
5893
|
-
while (exp > _0n$
|
|
5894
|
-
const lsb = exp & _1n$
|
|
5895
|
-
exp >>= _1n$
|
|
5917
|
+
while (exp > _0n$9) {
|
|
5918
|
+
const lsb = exp & _1n$e;
|
|
5919
|
+
exp >>= _1n$e; // e / 2
|
|
5896
5920
|
// Always compute multiplication step, to reduce timing leakage
|
|
5897
5921
|
const rx = (r * x) % n;
|
|
5898
5922
|
// Update r only if lsb is 1 (odd exponent)
|
|
@@ -5902,7 +5926,7 @@ function modExp(b, e, n) {
|
|
|
5902
5926
|
return r;
|
|
5903
5927
|
}
|
|
5904
5928
|
function abs(x) {
|
|
5905
|
-
return x >= _0n$
|
|
5929
|
+
return x >= _0n$9 ? x : -x;
|
|
5906
5930
|
}
|
|
5907
5931
|
/**
|
|
5908
5932
|
* Extended Eucleadian algorithm (http://anh.cs.luc.edu/331/notes/xgcd.pdf)
|
|
@@ -5922,9 +5946,9 @@ function _egcd(aInput, bInput) {
|
|
|
5922
5946
|
// See https://math.stackexchange.com/questions/37806/extended-euclidean-algorithm-with-negative-numbers
|
|
5923
5947
|
let a = abs(aInput);
|
|
5924
5948
|
let b = abs(bInput);
|
|
5925
|
-
const aNegated = aInput < _0n$
|
|
5926
|
-
const bNegated = bInput < _0n$
|
|
5927
|
-
while (b !== _0n$
|
|
5949
|
+
const aNegated = aInput < _0n$9;
|
|
5950
|
+
const bNegated = bInput < _0n$9;
|
|
5951
|
+
while (b !== _0n$9) {
|
|
5928
5952
|
const q = a / b;
|
|
5929
5953
|
let tmp = x;
|
|
5930
5954
|
x = xPrev - q * x;
|
|
@@ -5952,10 +5976,10 @@ function _egcd(aInput, bInput) {
|
|
|
5952
5976
|
*/
|
|
5953
5977
|
function modInv(a, n) {
|
|
5954
5978
|
const { gcd, x } = _egcd(a, n);
|
|
5955
|
-
if (gcd !== _1n$
|
|
5979
|
+
if (gcd !== _1n$e) {
|
|
5956
5980
|
throw new Error('Inverse does not exist');
|
|
5957
5981
|
}
|
|
5958
|
-
return mod$
|
|
5982
|
+
return mod$3(x + n, n);
|
|
5959
5983
|
}
|
|
5960
5984
|
/**
|
|
5961
5985
|
* Compute greatest common divisor between this and n
|
|
@@ -5966,7 +5990,7 @@ function modInv(a, n) {
|
|
|
5966
5990
|
function gcd(aInput, bInput) {
|
|
5967
5991
|
let a = aInput;
|
|
5968
5992
|
let b = bInput;
|
|
5969
|
-
while (b !== _0n$
|
|
5993
|
+
while (b !== _0n$9) {
|
|
5970
5994
|
const tmp = b;
|
|
5971
5995
|
b = a % b;
|
|
5972
5996
|
a = tmp;
|
|
@@ -5993,8 +6017,8 @@ function bigIntToNumber(x) {
|
|
|
5993
6017
|
* @returns {Number} Bit value.
|
|
5994
6018
|
*/
|
|
5995
6019
|
function getBit(x, i) {
|
|
5996
|
-
const bit = (x >> BigInt(i)) & _1n$
|
|
5997
|
-
return bit === _0n$
|
|
6020
|
+
const bit = (x >> BigInt(i)) & _1n$e;
|
|
6021
|
+
return bit === _0n$9 ? 0 : 1;
|
|
5998
6022
|
}
|
|
5999
6023
|
/**
|
|
6000
6024
|
* Compute bit length
|
|
@@ -6002,11 +6026,11 @@ function getBit(x, i) {
|
|
|
6002
6026
|
function bitLength(x) {
|
|
6003
6027
|
// -1n >> -1n is -1n
|
|
6004
6028
|
// 1n >> 1n is 0n
|
|
6005
|
-
const target = x < _0n$
|
|
6029
|
+
const target = x < _0n$9 ? BigInt(-1) : _0n$9;
|
|
6006
6030
|
let bitlen = 1;
|
|
6007
6031
|
let tmp = x;
|
|
6008
6032
|
// eslint-disable-next-line no-cond-assign
|
|
6009
|
-
while ((tmp >>= _1n$
|
|
6033
|
+
while ((tmp >>= _1n$e) !== target) {
|
|
6010
6034
|
bitlen++;
|
|
6011
6035
|
}
|
|
6012
6036
|
return bitlen;
|
|
@@ -6015,7 +6039,7 @@ function bitLength(x) {
|
|
|
6015
6039
|
* Compute byte length
|
|
6016
6040
|
*/
|
|
6017
6041
|
function byteLength(x) {
|
|
6018
|
-
const target = x < _0n$
|
|
6042
|
+
const target = x < _0n$9 ? BigInt(-1) : _0n$9;
|
|
6019
6043
|
const _8n = BigInt(8);
|
|
6020
6044
|
let len = 1;
|
|
6021
6045
|
let tmp = x;
|
|
@@ -6110,7 +6134,7 @@ function getRandomBigInteger(min, max) {
|
|
|
6110
6134
|
// However, we request 64 extra random bits so that the bias is negligible.
|
|
6111
6135
|
// Section B.1.1 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
|
|
6112
6136
|
const r = uint8ArrayToBigInt(getRandomBytes(bytes + 8));
|
|
6113
|
-
return mod$
|
|
6137
|
+
return mod$3(r, modulus) + min;
|
|
6114
6138
|
}
|
|
6115
6139
|
|
|
6116
6140
|
var random = /*#__PURE__*/Object.freeze({
|
|
@@ -6139,7 +6163,7 @@ var random = /*#__PURE__*/Object.freeze({
|
|
|
6139
6163
|
* @fileoverview Algorithms for probabilistic random prime generation
|
|
6140
6164
|
* @module crypto/public_key/prime
|
|
6141
6165
|
*/
|
|
6142
|
-
const _1n$
|
|
6166
|
+
const _1n$d = BigInt(1);
|
|
6143
6167
|
/**
|
|
6144
6168
|
* Generate a probably prime random number
|
|
6145
6169
|
* @param bits - Bit length of the prime
|
|
@@ -6148,7 +6172,7 @@ const _1n$c = BigInt(1);
|
|
|
6148
6172
|
*/
|
|
6149
6173
|
function randomProbablePrime(bits, e, k) {
|
|
6150
6174
|
const _30n = BigInt(30);
|
|
6151
|
-
const min = _1n$
|
|
6175
|
+
const min = _1n$d << BigInt(bits - 1);
|
|
6152
6176
|
/*
|
|
6153
6177
|
* We can avoid any multiples of 3 and 5 by looking at n mod 30
|
|
6154
6178
|
* n mod 30 = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
|
@@ -6156,16 +6180,16 @@ function randomProbablePrime(bits, e, k) {
|
|
|
6156
6180
|
* 1 7 7 7 7 7 7 11 11 11 11 13 13 17 17 17 17 19 19 23 23 23 23 29 29 29 29 29 29 1
|
|
6157
6181
|
*/
|
|
6158
6182
|
const adds = [1, 6, 5, 4, 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 2];
|
|
6159
|
-
let n = getRandomBigInteger(min, min << _1n$
|
|
6160
|
-
let i = bigIntToNumber(mod$
|
|
6183
|
+
let n = getRandomBigInteger(min, min << _1n$d);
|
|
6184
|
+
let i = bigIntToNumber(mod$3(n, _30n));
|
|
6161
6185
|
do {
|
|
6162
6186
|
n += BigInt(adds[i]);
|
|
6163
6187
|
i = (i + adds[i]) % adds.length;
|
|
6164
6188
|
// If reached the maximum, go back to the minimum.
|
|
6165
6189
|
if (bitLength(n) > bits) {
|
|
6166
|
-
n = mod$
|
|
6190
|
+
n = mod$3(n, min << _1n$d);
|
|
6167
6191
|
n += min;
|
|
6168
|
-
i = bigIntToNumber(mod$
|
|
6192
|
+
i = bigIntToNumber(mod$3(n, _30n));
|
|
6169
6193
|
}
|
|
6170
6194
|
} while (!isProbablePrime(n, e, k));
|
|
6171
6195
|
return n;
|
|
@@ -6177,7 +6201,7 @@ function randomProbablePrime(bits, e, k) {
|
|
|
6177
6201
|
* @param k - Optional number of iterations of Miller-Rabin test
|
|
6178
6202
|
*/
|
|
6179
6203
|
function isProbablePrime(n, e, k) {
|
|
6180
|
-
if (e && gcd(n - _1n$
|
|
6204
|
+
if (e && gcd(n - _1n$d, e) !== _1n$d) {
|
|
6181
6205
|
return false;
|
|
6182
6206
|
}
|
|
6183
6207
|
if (!divisionTest(n)) {
|
|
@@ -6200,11 +6224,11 @@ function isProbablePrime(n, e, k) {
|
|
|
6200
6224
|
* @param b - Optional Fermat test base
|
|
6201
6225
|
*/
|
|
6202
6226
|
function fermat(n, b = BigInt(2)) {
|
|
6203
|
-
return modExp(b, n - _1n$
|
|
6227
|
+
return modExp(b, n - _1n$d, n) === _1n$d;
|
|
6204
6228
|
}
|
|
6205
6229
|
function divisionTest(n) {
|
|
6206
6230
|
const _0n = BigInt(0);
|
|
6207
|
-
return smallPrimes.every(m => mod$
|
|
6231
|
+
return smallPrimes.every(m => mod$3(n, m) !== _0n);
|
|
6208
6232
|
}
|
|
6209
6233
|
// https://github.com/gpg/libgcrypt/blob/master/cipher/primegen.c
|
|
6210
6234
|
const smallPrimes = [
|
|
@@ -6328,7 +6352,7 @@ function millerRabin(n, k, rand) {
|
|
|
6328
6352
|
if (!k) {
|
|
6329
6353
|
k = Math.max(1, (len / 48) | 0);
|
|
6330
6354
|
}
|
|
6331
|
-
const n1 = n - _1n$
|
|
6355
|
+
const n1 = n - _1n$d; // n - 1
|
|
6332
6356
|
// Find d and s, (n - 1) = (2 ^ s) * d;
|
|
6333
6357
|
let s = 0;
|
|
6334
6358
|
while (!getBit(n1, s)) {
|
|
@@ -6338,13 +6362,13 @@ function millerRabin(n, k, rand) {
|
|
|
6338
6362
|
for (; k > 0; k--) {
|
|
6339
6363
|
const a = getRandomBigInteger(BigInt(2), n1);
|
|
6340
6364
|
let x = modExp(a, d, n);
|
|
6341
|
-
if (x === _1n$
|
|
6365
|
+
if (x === _1n$d || x === n1) {
|
|
6342
6366
|
continue;
|
|
6343
6367
|
}
|
|
6344
6368
|
let i;
|
|
6345
6369
|
for (i = 1; i < s; i++) {
|
|
6346
|
-
x = mod$
|
|
6347
|
-
if (x === _1n$
|
|
6370
|
+
x = mod$3(x * x, n);
|
|
6371
|
+
if (x === _1n$d) {
|
|
6348
6372
|
return false;
|
|
6349
6373
|
}
|
|
6350
6374
|
if (x === n1) {
|
|
@@ -6538,7 +6562,7 @@ var pkcs1 = /*#__PURE__*/Object.freeze({
|
|
|
6538
6562
|
|
|
6539
6563
|
const webCrypto$6 = util.getWebCrypto();
|
|
6540
6564
|
const nodeCrypto$4 = util.getNodeCrypto();
|
|
6541
|
-
const _1n$
|
|
6565
|
+
const _1n$c = BigInt(1);
|
|
6542
6566
|
|
|
6543
6567
|
/** Create signature
|
|
6544
6568
|
* @param {module:enums.hash} hashAlgo - Hash algorithm
|
|
@@ -6579,7 +6603,7 @@ async function sign$7(hashAlgo, data, n, e, d, p, q, u, hashed) {
|
|
|
6579
6603
|
* @returns {Boolean}
|
|
6580
6604
|
* @async
|
|
6581
6605
|
*/
|
|
6582
|
-
async function verify$
|
|
6606
|
+
async function verify$8(hashAlgo, data, s, n, e, hashed) {
|
|
6583
6607
|
if (data && !util.isStream(data)) {
|
|
6584
6608
|
if (util.getWebCrypto()) {
|
|
6585
6609
|
try {
|
|
@@ -6702,7 +6726,7 @@ async function generate$5(bits, e) {
|
|
|
6702
6726
|
n = p * q;
|
|
6703
6727
|
} while (bitLength(n) !== bits);
|
|
6704
6728
|
|
|
6705
|
-
const phi = (p - _1n$
|
|
6729
|
+
const phi = (p - _1n$c) * (q - _1n$c);
|
|
6706
6730
|
|
|
6707
6731
|
if (q < p) {
|
|
6708
6732
|
[p, q] = [q, p];
|
|
@@ -6744,7 +6768,7 @@ async function validateParams$9(n, e, d, p, q, u) {
|
|
|
6744
6768
|
const _2n = BigInt(2);
|
|
6745
6769
|
// expect p*u = 1 mod q
|
|
6746
6770
|
u = uint8ArrayToBigInt(u);
|
|
6747
|
-
if (mod$
|
|
6771
|
+
if (mod$3(p * u, q) !== BigInt(1)) {
|
|
6748
6772
|
return false;
|
|
6749
6773
|
}
|
|
6750
6774
|
|
|
@@ -6761,7 +6785,7 @@ async function validateParams$9(n, e, d, p, q, u) {
|
|
|
6761
6785
|
const r = getRandomBigInteger(_2n, _2n << nSizeOver3); // r in [ 2, 2^{|n|/3} ) < p and q
|
|
6762
6786
|
const rde = r * d * e;
|
|
6763
6787
|
|
|
6764
|
-
const areInverses = mod$
|
|
6788
|
+
const areInverses = mod$3(rde, p - _1n$c) === r && mod$3(rde, q - _1n$c) === r;
|
|
6765
6789
|
if (!areInverses) {
|
|
6766
6790
|
return false;
|
|
6767
6791
|
}
|
|
@@ -6880,20 +6904,20 @@ async function bnDecrypt(data, n, e, d, p, q, u, randomPayload) {
|
|
|
6880
6904
|
if (data >= n) {
|
|
6881
6905
|
throw new Error('Data too large.');
|
|
6882
6906
|
}
|
|
6883
|
-
const dq = mod$
|
|
6884
|
-
const dp = mod$
|
|
6907
|
+
const dq = mod$3(d, q - _1n$c); // d mod (q-1)
|
|
6908
|
+
const dp = mod$3(d, p - _1n$c); // d mod (p-1)
|
|
6885
6909
|
|
|
6886
6910
|
const unblinder = getRandomBigInteger(BigInt(2), n);
|
|
6887
6911
|
const blinder = modExp(modInv(unblinder, n), e, n);
|
|
6888
|
-
data = mod$
|
|
6912
|
+
data = mod$3(data * blinder, n);
|
|
6889
6913
|
|
|
6890
6914
|
const mp = modExp(data, dp, p); // data**{d mod (q-1)} mod p
|
|
6891
6915
|
const mq = modExp(data, dq, q); // data**{d mod (p-1)} mod q
|
|
6892
|
-
const h = mod$
|
|
6916
|
+
const h = mod$3(u * (mq - mp), q); // u * (mq-mp) mod q (operands already < q)
|
|
6893
6917
|
|
|
6894
6918
|
let result = h * p + mp; // result < n due to relations above
|
|
6895
6919
|
|
|
6896
|
-
result = mod$
|
|
6920
|
+
result = mod$3(result * unblinder, n);
|
|
6897
6921
|
|
|
6898
6922
|
return emeDecode(bigIntToUint8Array(result, 'be', byteLength(n)), randomPayload);
|
|
6899
6923
|
}
|
|
@@ -6913,8 +6937,8 @@ async function privateToJWK$1(n, e, d, p, q, u) {
|
|
|
6913
6937
|
const qNum = uint8ArrayToBigInt(q);
|
|
6914
6938
|
const dNum = uint8ArrayToBigInt(d);
|
|
6915
6939
|
|
|
6916
|
-
let dq = mod$
|
|
6917
|
-
let dp = mod$
|
|
6940
|
+
let dq = mod$3(dNum, qNum - _1n$c); // d mod (q-1)
|
|
6941
|
+
let dp = mod$3(dNum, pNum - _1n$c); // d mod (p-1)
|
|
6918
6942
|
dp = bigIntToUint8Array(dp);
|
|
6919
6943
|
dq = bigIntToUint8Array(dq);
|
|
6920
6944
|
return {
|
|
@@ -6969,7 +6993,7 @@ var rsa = /*#__PURE__*/Object.freeze({
|
|
|
6969
6993
|
generate: generate$5,
|
|
6970
6994
|
sign: sign$7,
|
|
6971
6995
|
validateParams: validateParams$9,
|
|
6972
|
-
verify: verify$
|
|
6996
|
+
verify: verify$8
|
|
6973
6997
|
});
|
|
6974
6998
|
|
|
6975
6999
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
@@ -6990,7 +7014,7 @@ var rsa = /*#__PURE__*/Object.freeze({
|
|
|
6990
7014
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
6991
7015
|
|
|
6992
7016
|
|
|
6993
|
-
const _1n$
|
|
7017
|
+
const _1n$b = BigInt(1);
|
|
6994
7018
|
|
|
6995
7019
|
/**
|
|
6996
7020
|
* ElGamal Encryption function
|
|
@@ -7012,10 +7036,10 @@ async function encrypt$3(data, p, g, y) {
|
|
|
7012
7036
|
|
|
7013
7037
|
// OpenPGP uses a "special" version of ElGamal where g is generator of the full group Z/pZ*
|
|
7014
7038
|
// hence g has order p-1, and to avoid that k = 0 mod p-1, we need to pick k in [1, p-2]
|
|
7015
|
-
const k = getRandomBigInteger(_1n$
|
|
7039
|
+
const k = getRandomBigInteger(_1n$b, p - _1n$b);
|
|
7016
7040
|
return {
|
|
7017
7041
|
c1: bigIntToUint8Array(modExp(g, k, p)),
|
|
7018
|
-
c2: bigIntToUint8Array(mod$
|
|
7042
|
+
c2: bigIntToUint8Array(mod$3(modExp(y, k, p) * m, p))
|
|
7019
7043
|
};
|
|
7020
7044
|
}
|
|
7021
7045
|
|
|
@@ -7037,7 +7061,7 @@ async function decrypt$3(c1, c2, p, x, randomPayload) {
|
|
|
7037
7061
|
p = uint8ArrayToBigInt(p);
|
|
7038
7062
|
x = uint8ArrayToBigInt(x);
|
|
7039
7063
|
|
|
7040
|
-
const padded = mod$
|
|
7064
|
+
const padded = mod$3(modInv(modExp(c1, x, p), p) * c2, p);
|
|
7041
7065
|
return emeDecode(bigIntToUint8Array(padded, 'be', byteLength(p)), randomPayload);
|
|
7042
7066
|
}
|
|
7043
7067
|
|
|
@@ -7056,7 +7080,7 @@ async function validateParams$8(p, g, y, x) {
|
|
|
7056
7080
|
y = uint8ArrayToBigInt(y);
|
|
7057
7081
|
|
|
7058
7082
|
// Check that 1 < g < p
|
|
7059
|
-
if (g <= _1n$
|
|
7083
|
+
if (g <= _1n$b || g >= p) {
|
|
7060
7084
|
return false;
|
|
7061
7085
|
}
|
|
7062
7086
|
|
|
@@ -7071,7 +7095,7 @@ async function validateParams$8(p, g, y, x) {
|
|
|
7071
7095
|
* g should have order p-1
|
|
7072
7096
|
* Check that g ** (p-1) = 1 mod p
|
|
7073
7097
|
*/
|
|
7074
|
-
if (modExp(g, p - _1n$
|
|
7098
|
+
if (modExp(g, p - _1n$b, p) !== _1n$b) {
|
|
7075
7099
|
return false;
|
|
7076
7100
|
}
|
|
7077
7101
|
|
|
@@ -7086,8 +7110,8 @@ async function validateParams$8(p, g, y, x) {
|
|
|
7086
7110
|
const _2n = BigInt(2);
|
|
7087
7111
|
const threshold = _2n << BigInt(17); // we want order > threshold
|
|
7088
7112
|
while (i < threshold) {
|
|
7089
|
-
res = mod$
|
|
7090
|
-
if (res === _1n$
|
|
7113
|
+
res = mod$3(res * g, p);
|
|
7114
|
+
if (res === _1n$b) {
|
|
7091
7115
|
return false;
|
|
7092
7116
|
}
|
|
7093
7117
|
i++;
|
|
@@ -7100,8 +7124,8 @@ async function validateParams$8(p, g, y, x) {
|
|
|
7100
7124
|
* Blinded exponentiation computes g**{r(p-1) + x} to compare to y
|
|
7101
7125
|
*/
|
|
7102
7126
|
x = uint8ArrayToBigInt(x);
|
|
7103
|
-
const r = getRandomBigInteger(_2n << (pSize - _1n$
|
|
7104
|
-
const rqx = (p - _1n$
|
|
7127
|
+
const r = getRandomBigInteger(_2n << (pSize - _1n$b), _2n << pSize); // draw r of same size as p-1
|
|
7128
|
+
const rqx = (p - _1n$b) * r + x;
|
|
7105
7129
|
if (y !== modExp(g, rqx, p)) {
|
|
7106
7130
|
return false;
|
|
7107
7131
|
}
|
|
@@ -7118,7 +7142,7 @@ var elgamal = /*#__PURE__*/Object.freeze({
|
|
|
7118
7142
|
|
|
7119
7143
|
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
|
7120
7144
|
// See utils.ts for details.
|
|
7121
|
-
const crypto$
|
|
7145
|
+
const crypto$4 =
|
|
7122
7146
|
nc__namespace && typeof nc__namespace === 'object' && 'webcrypto' in nc__namespace ? nc__namespace.webcrypto : undefined;
|
|
7123
7147
|
|
|
7124
7148
|
const nacl = {};
|
|
@@ -8481,13 +8505,13 @@ nacl.setPRNG = function(fn) {
|
|
|
8481
8505
|
(function() {
|
|
8482
8506
|
// Initialize PRNG if environment provides CSPRNG.
|
|
8483
8507
|
// If not, methods calling randombytes will throw.
|
|
8484
|
-
if (crypto$
|
|
8508
|
+
if (crypto$4 && crypto$4.getRandomValues) {
|
|
8485
8509
|
// Browsers and Node v16+
|
|
8486
8510
|
var QUOTA = 65536;
|
|
8487
8511
|
nacl.setPRNG(function(x, n) {
|
|
8488
8512
|
var i, v = new Uint8Array(n);
|
|
8489
8513
|
for (i = 0; i < n; i += QUOTA) {
|
|
8490
|
-
crypto$
|
|
8514
|
+
crypto$4.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
8491
8515
|
}
|
|
8492
8516
|
for (i = 0; i < n; i++) x[i] = v[i];
|
|
8493
8517
|
cleanup(v);
|
|
@@ -8965,7 +8989,8 @@ const curves = {
|
|
|
8965
8989
|
node: nodeCurves[enums.curve.nistP256],
|
|
8966
8990
|
web: webCurves[enums.curve.nistP256],
|
|
8967
8991
|
payloadSize: 32,
|
|
8968
|
-
sharedSize: 256
|
|
8992
|
+
sharedSize: 256,
|
|
8993
|
+
wireFormatLeadingByte: 0x04
|
|
8969
8994
|
},
|
|
8970
8995
|
[enums.curve.nistP384]: {
|
|
8971
8996
|
oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22],
|
|
@@ -8975,7 +9000,8 @@ const curves = {
|
|
|
8975
9000
|
node: nodeCurves[enums.curve.nistP384],
|
|
8976
9001
|
web: webCurves[enums.curve.nistP384],
|
|
8977
9002
|
payloadSize: 48,
|
|
8978
|
-
sharedSize: 384
|
|
9003
|
+
sharedSize: 384,
|
|
9004
|
+
wireFormatLeadingByte: 0x04
|
|
8979
9005
|
},
|
|
8980
9006
|
[enums.curve.nistP521]: {
|
|
8981
9007
|
oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x23],
|
|
@@ -8985,7 +9011,8 @@ const curves = {
|
|
|
8985
9011
|
node: nodeCurves[enums.curve.nistP521],
|
|
8986
9012
|
web: webCurves[enums.curve.nistP521],
|
|
8987
9013
|
payloadSize: 66,
|
|
8988
|
-
sharedSize: 528
|
|
9014
|
+
sharedSize: 528,
|
|
9015
|
+
wireFormatLeadingByte: 0x04
|
|
8989
9016
|
},
|
|
8990
9017
|
[enums.curve.secp256k1]: {
|
|
8991
9018
|
oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x0A],
|
|
@@ -8993,14 +9020,16 @@ const curves = {
|
|
|
8993
9020
|
hash: enums.hash.sha256,
|
|
8994
9021
|
cipher: enums.symmetric.aes128,
|
|
8995
9022
|
node: nodeCurves[enums.curve.secp256k1],
|
|
8996
|
-
payloadSize: 32
|
|
9023
|
+
payloadSize: 32,
|
|
9024
|
+
wireFormatLeadingByte: 0x04
|
|
8997
9025
|
},
|
|
8998
9026
|
[enums.curve.ed25519Legacy]: {
|
|
8999
9027
|
oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
|
|
9000
9028
|
keyType: enums.publicKey.eddsaLegacy,
|
|
9001
9029
|
hash: enums.hash.sha512,
|
|
9002
9030
|
node: false, // nodeCurves.ed25519 TODO
|
|
9003
|
-
payloadSize: 32
|
|
9031
|
+
payloadSize: 32,
|
|
9032
|
+
wireFormatLeadingByte: 0x40
|
|
9004
9033
|
},
|
|
9005
9034
|
[enums.curve.curve25519Legacy]: {
|
|
9006
9035
|
oid: [0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01],
|
|
@@ -9008,7 +9037,8 @@ const curves = {
|
|
|
9008
9037
|
hash: enums.hash.sha256,
|
|
9009
9038
|
cipher: enums.symmetric.aes128,
|
|
9010
9039
|
node: false, // nodeCurves.curve25519 TODO
|
|
9011
|
-
payloadSize: 32
|
|
9040
|
+
payloadSize: 32,
|
|
9041
|
+
wireFormatLeadingByte: 0x40
|
|
9012
9042
|
},
|
|
9013
9043
|
[enums.curve.brainpoolP256r1]: {
|
|
9014
9044
|
oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07],
|
|
@@ -9016,7 +9046,8 @@ const curves = {
|
|
|
9016
9046
|
hash: enums.hash.sha256,
|
|
9017
9047
|
cipher: enums.symmetric.aes128,
|
|
9018
9048
|
node: nodeCurves[enums.curve.brainpoolP256r1],
|
|
9019
|
-
payloadSize: 32
|
|
9049
|
+
payloadSize: 32,
|
|
9050
|
+
wireFormatLeadingByte: 0x04
|
|
9020
9051
|
},
|
|
9021
9052
|
[enums.curve.brainpoolP384r1]: {
|
|
9022
9053
|
oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B],
|
|
@@ -9024,7 +9055,8 @@ const curves = {
|
|
|
9024
9055
|
hash: enums.hash.sha384,
|
|
9025
9056
|
cipher: enums.symmetric.aes192,
|
|
9026
9057
|
node: nodeCurves[enums.curve.brainpoolP384r1],
|
|
9027
|
-
payloadSize: 48
|
|
9058
|
+
payloadSize: 48,
|
|
9059
|
+
wireFormatLeadingByte: 0x04
|
|
9028
9060
|
},
|
|
9029
9061
|
[enums.curve.brainpoolP512r1]: {
|
|
9030
9062
|
oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D],
|
|
@@ -9032,7 +9064,8 @@ const curves = {
|
|
|
9032
9064
|
hash: enums.hash.sha512,
|
|
9033
9065
|
cipher: enums.symmetric.aes256,
|
|
9034
9066
|
node: nodeCurves[enums.curve.brainpoolP512r1],
|
|
9035
|
-
payloadSize: 64
|
|
9067
|
+
payloadSize: 64,
|
|
9068
|
+
wireFormatLeadingByte: 0x04
|
|
9036
9069
|
}
|
|
9037
9070
|
};
|
|
9038
9071
|
|
|
@@ -9056,6 +9089,7 @@ class CurveWithOID {
|
|
|
9056
9089
|
this.web = params.web;
|
|
9057
9090
|
this.payloadSize = params.payloadSize;
|
|
9058
9091
|
this.sharedSize = params.sharedSize;
|
|
9092
|
+
this.wireFormatLeadingByte = params.wireFormatLeadingByte;
|
|
9059
9093
|
if (this.web && util.getWebCrypto()) {
|
|
9060
9094
|
this.type = 'web';
|
|
9061
9095
|
} else if (this.node && util.getNodeCrypto()) {
|
|
@@ -9071,7 +9105,7 @@ class CurveWithOID {
|
|
|
9071
9105
|
switch (this.type) {
|
|
9072
9106
|
case 'web':
|
|
9073
9107
|
try {
|
|
9074
|
-
return await webGenKeyPair(this.name);
|
|
9108
|
+
return await webGenKeyPair(this.name, this.wireFormatLeadingByte);
|
|
9075
9109
|
} catch (err) {
|
|
9076
9110
|
util.printDebugError('Browser did not support generating ec key ' + err.message);
|
|
9077
9111
|
return jsGenKeyPair(this.name);
|
|
@@ -9084,13 +9118,13 @@ class CurveWithOID {
|
|
|
9084
9118
|
privateKey[31] &= 248;
|
|
9085
9119
|
const secretKey = privateKey.slice().reverse();
|
|
9086
9120
|
const { publicKey: rawPublicKey } = nacl.box.keyPair.fromSecretKey(secretKey);
|
|
9087
|
-
const publicKey = util.concatUint8Array([new Uint8Array([
|
|
9121
|
+
const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), rawPublicKey]);
|
|
9088
9122
|
return { publicKey, privateKey };
|
|
9089
9123
|
}
|
|
9090
9124
|
case 'ed25519Legacy': {
|
|
9091
9125
|
const privateKey = getRandomBytes(32);
|
|
9092
9126
|
const keyPair = nacl.sign.keyPair.fromSeed(privateKey);
|
|
9093
|
-
const publicKey = util.concatUint8Array([new Uint8Array([
|
|
9127
|
+
const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), keyPair.publicKey]);
|
|
9094
9128
|
return { publicKey, privateKey };
|
|
9095
9129
|
}
|
|
9096
9130
|
default:
|
|
@@ -9176,6 +9210,20 @@ async function validateStandardParams(algo, oid, Q, d) {
|
|
|
9176
9210
|
return true;
|
|
9177
9211
|
}
|
|
9178
9212
|
|
|
9213
|
+
/**
|
|
9214
|
+
* Check whether the public point has a valid encoding.
|
|
9215
|
+
* NB: this function does not check e.g. whether the point belongs to the curve.
|
|
9216
|
+
*/
|
|
9217
|
+
function checkPublicPointEnconding(curve, V) {
|
|
9218
|
+
const { payloadSize, wireFormatLeadingByte, name: curveName } = curve;
|
|
9219
|
+
|
|
9220
|
+
const pointSize = (curveName === enums.curve.curve25519Legacy || curveName === enums.curve.ed25519Legacy) ? payloadSize : payloadSize * 2;
|
|
9221
|
+
|
|
9222
|
+
if (V[0] !== wireFormatLeadingByte || V.length !== pointSize + 1) {
|
|
9223
|
+
throw new Error('Invalid point encoding');
|
|
9224
|
+
}
|
|
9225
|
+
}
|
|
9226
|
+
|
|
9179
9227
|
//////////////////////////
|
|
9180
9228
|
// //
|
|
9181
9229
|
// Helper functions //
|
|
@@ -9188,7 +9236,7 @@ async function jsGenKeyPair(name) {
|
|
|
9188
9236
|
return { publicKey, privateKey };
|
|
9189
9237
|
}
|
|
9190
9238
|
|
|
9191
|
-
async function webGenKeyPair(name) {
|
|
9239
|
+
async function webGenKeyPair(name, wireFormatLeadingByte) {
|
|
9192
9240
|
// Note: keys generated with ECDSA and ECDH are structurally equivalent
|
|
9193
9241
|
const webCryptoKey = await webCrypto$5.generateKey({ name: 'ECDSA', namedCurve: webCurves[name] }, true, ['sign', 'verify']);
|
|
9194
9242
|
|
|
@@ -9196,7 +9244,7 @@ async function webGenKeyPair(name) {
|
|
|
9196
9244
|
const publicKey = await webCrypto$5.exportKey('jwk', webCryptoKey.publicKey);
|
|
9197
9245
|
|
|
9198
9246
|
return {
|
|
9199
|
-
publicKey: jwkToRawPublic(publicKey),
|
|
9247
|
+
publicKey: jwkToRawPublic(publicKey, wireFormatLeadingByte),
|
|
9200
9248
|
privateKey: b64ToUint8Array(privateKey.d)
|
|
9201
9249
|
};
|
|
9202
9250
|
}
|
|
@@ -9222,11 +9270,11 @@ async function nodeGenKeyPair(name) {
|
|
|
9222
9270
|
*
|
|
9223
9271
|
* @returns {Uint8Array} Raw public key.
|
|
9224
9272
|
*/
|
|
9225
|
-
function jwkToRawPublic(jwk) {
|
|
9273
|
+
function jwkToRawPublic(jwk, wireFormatLeadingByte) {
|
|
9226
9274
|
const bufX = b64ToUint8Array(jwk.x);
|
|
9227
9275
|
const bufY = b64ToUint8Array(jwk.y);
|
|
9228
9276
|
const publicKey = new Uint8Array(bufX.length + bufY.length + 1);
|
|
9229
|
-
publicKey[0] =
|
|
9277
|
+
publicKey[0] = wireFormatLeadingByte;
|
|
9230
9278
|
publicKey.set(bufX, 1);
|
|
9231
9279
|
publicKey.set(bufY, bufX.length + 1);
|
|
9232
9280
|
return publicKey;
|
|
@@ -9305,6 +9353,7 @@ const nodeCrypto$2 = util.getNodeCrypto();
|
|
|
9305
9353
|
*/
|
|
9306
9354
|
async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
9307
9355
|
const curve = new CurveWithOID(oid);
|
|
9356
|
+
checkPublicPointEnconding(curve, publicKey);
|
|
9308
9357
|
if (message && !util.isStream(message)) {
|
|
9309
9358
|
const keyPair = { publicKey, privateKey };
|
|
9310
9359
|
switch (curve.type) {
|
|
@@ -9349,8 +9398,9 @@ async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
9349
9398
|
* @returns {Boolean}
|
|
9350
9399
|
* @async
|
|
9351
9400
|
*/
|
|
9352
|
-
async function verify$
|
|
9401
|
+
async function verify$7(oid, hashAlgo, signature, message, publicKey, hashed) {
|
|
9353
9402
|
const curve = new CurveWithOID(oid);
|
|
9403
|
+
checkPublicPointEnconding(curve, publicKey);
|
|
9354
9404
|
// See https://github.com/openpgpjs/openpgpjs/pull/948.
|
|
9355
9405
|
// NB: the impact was more likely limited to Brainpool curves, since thanks
|
|
9356
9406
|
// to WebCrypto availability, NIST curve should not have been affected.
|
|
@@ -9417,7 +9467,7 @@ async function validateParams$7(oid, Q, d) {
|
|
|
9417
9467
|
try {
|
|
9418
9468
|
const signature = await sign$6(oid, hashAlgo, message, Q, d, hashed);
|
|
9419
9469
|
// eslint-disable-next-line @typescript-eslint/return-await
|
|
9420
|
-
return await verify$
|
|
9470
|
+
return await verify$7(oid, hashAlgo, signature, message, Q, hashed);
|
|
9421
9471
|
} catch (err) {
|
|
9422
9472
|
return false;
|
|
9423
9473
|
}
|
|
@@ -9550,7 +9600,766 @@ var ecdsa = /*#__PURE__*/Object.freeze({
|
|
|
9550
9600
|
__proto__: null,
|
|
9551
9601
|
sign: sign$6,
|
|
9552
9602
|
validateParams: validateParams$7,
|
|
9553
|
-
verify: verify$
|
|
9603
|
+
verify: verify$7
|
|
9604
|
+
});
|
|
9605
|
+
|
|
9606
|
+
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
|
9607
|
+
const _0n$8 = BigInt(0);
|
|
9608
|
+
const _1n$a = BigInt(1);
|
|
9609
|
+
const _2n$6 = BigInt(2);
|
|
9610
|
+
const _8n$2 = BigInt(8);
|
|
9611
|
+
const CU_O = BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989');
|
|
9612
|
+
const CURVE$1 = Object.freeze({
|
|
9613
|
+
a: BigInt(-1),
|
|
9614
|
+
d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
|
|
9615
|
+
P: BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819949'),
|
|
9616
|
+
l: CU_O,
|
|
9617
|
+
n: CU_O,
|
|
9618
|
+
h: BigInt(8),
|
|
9619
|
+
Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
|
|
9620
|
+
Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
|
|
9621
|
+
});
|
|
9622
|
+
const POW_2_256 = BigInt('0x10000000000000000000000000000000000000000000000000000000000000000');
|
|
9623
|
+
const SQRT_M1 = BigInt('19681161376707505956807079304988542015446066515923890162744021073123829784752');
|
|
9624
|
+
BigInt('6853475219497561581579357271197624642482790079785650197046958215289687604742');
|
|
9625
|
+
const SQRT_AD_MINUS_ONE = BigInt('25063068953384623474111414158702152701244531502492656460079210482610430750235');
|
|
9626
|
+
const INVSQRT_A_MINUS_D = BigInt('54469307008909316920995813868745141605393597292927456921205312896311721017578');
|
|
9627
|
+
const ONE_MINUS_D_SQ = BigInt('1159843021668779879193775521855586647937357759715417654439879720876111806838');
|
|
9628
|
+
const D_MINUS_ONE_SQ = BigInt('40440834346308536858101042469323190826248399146238708352240133220865137265952');
|
|
9629
|
+
class ExtendedPoint {
|
|
9630
|
+
constructor(x, y, z, t) {
|
|
9631
|
+
this.x = x;
|
|
9632
|
+
this.y = y;
|
|
9633
|
+
this.z = z;
|
|
9634
|
+
this.t = t;
|
|
9635
|
+
}
|
|
9636
|
+
static fromAffine(p) {
|
|
9637
|
+
if (!(p instanceof Point)) {
|
|
9638
|
+
throw new TypeError('ExtendedPoint#fromAffine: expected Point');
|
|
9639
|
+
}
|
|
9640
|
+
if (p.equals(Point.ZERO))
|
|
9641
|
+
return ExtendedPoint.ZERO;
|
|
9642
|
+
return new ExtendedPoint(p.x, p.y, _1n$a, mod$2(p.x * p.y));
|
|
9643
|
+
}
|
|
9644
|
+
static toAffineBatch(points) {
|
|
9645
|
+
const toInv = invertBatch(points.map((p) => p.z));
|
|
9646
|
+
return points.map((p, i) => p.toAffine(toInv[i]));
|
|
9647
|
+
}
|
|
9648
|
+
static normalizeZ(points) {
|
|
9649
|
+
return this.toAffineBatch(points).map(this.fromAffine);
|
|
9650
|
+
}
|
|
9651
|
+
equals(other) {
|
|
9652
|
+
assertExtPoint(other);
|
|
9653
|
+
const { x: X1, y: Y1, z: Z1 } = this;
|
|
9654
|
+
const { x: X2, y: Y2, z: Z2 } = other;
|
|
9655
|
+
const X1Z2 = mod$2(X1 * Z2);
|
|
9656
|
+
const X2Z1 = mod$2(X2 * Z1);
|
|
9657
|
+
const Y1Z2 = mod$2(Y1 * Z2);
|
|
9658
|
+
const Y2Z1 = mod$2(Y2 * Z1);
|
|
9659
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
9660
|
+
}
|
|
9661
|
+
negate() {
|
|
9662
|
+
return new ExtendedPoint(mod$2(-this.x), this.y, this.z, mod$2(-this.t));
|
|
9663
|
+
}
|
|
9664
|
+
double() {
|
|
9665
|
+
const { x: X1, y: Y1, z: Z1 } = this;
|
|
9666
|
+
const { a } = CURVE$1;
|
|
9667
|
+
const A = mod$2(X1 * X1);
|
|
9668
|
+
const B = mod$2(Y1 * Y1);
|
|
9669
|
+
const C = mod$2(_2n$6 * mod$2(Z1 * Z1));
|
|
9670
|
+
const D = mod$2(a * A);
|
|
9671
|
+
const x1y1 = X1 + Y1;
|
|
9672
|
+
const E = mod$2(mod$2(x1y1 * x1y1) - A - B);
|
|
9673
|
+
const G = D + B;
|
|
9674
|
+
const F = G - C;
|
|
9675
|
+
const H = D - B;
|
|
9676
|
+
const X3 = mod$2(E * F);
|
|
9677
|
+
const Y3 = mod$2(G * H);
|
|
9678
|
+
const T3 = mod$2(E * H);
|
|
9679
|
+
const Z3 = mod$2(F * G);
|
|
9680
|
+
return new ExtendedPoint(X3, Y3, Z3, T3);
|
|
9681
|
+
}
|
|
9682
|
+
add(other) {
|
|
9683
|
+
assertExtPoint(other);
|
|
9684
|
+
const { x: X1, y: Y1, z: Z1, t: T1 } = this;
|
|
9685
|
+
const { x: X2, y: Y2, z: Z2, t: T2 } = other;
|
|
9686
|
+
const A = mod$2((Y1 - X1) * (Y2 + X2));
|
|
9687
|
+
const B = mod$2((Y1 + X1) * (Y2 - X2));
|
|
9688
|
+
const F = mod$2(B - A);
|
|
9689
|
+
if (F === _0n$8)
|
|
9690
|
+
return this.double();
|
|
9691
|
+
const C = mod$2(Z1 * _2n$6 * T2);
|
|
9692
|
+
const D = mod$2(T1 * _2n$6 * Z2);
|
|
9693
|
+
const E = D + C;
|
|
9694
|
+
const G = B + A;
|
|
9695
|
+
const H = D - C;
|
|
9696
|
+
const X3 = mod$2(E * F);
|
|
9697
|
+
const Y3 = mod$2(G * H);
|
|
9698
|
+
const T3 = mod$2(E * H);
|
|
9699
|
+
const Z3 = mod$2(F * G);
|
|
9700
|
+
return new ExtendedPoint(X3, Y3, Z3, T3);
|
|
9701
|
+
}
|
|
9702
|
+
subtract(other) {
|
|
9703
|
+
return this.add(other.negate());
|
|
9704
|
+
}
|
|
9705
|
+
precomputeWindow(W) {
|
|
9706
|
+
const windows = 1 + 256 / W;
|
|
9707
|
+
const points = [];
|
|
9708
|
+
let p = this;
|
|
9709
|
+
let base = p;
|
|
9710
|
+
for (let window = 0; window < windows; window++) {
|
|
9711
|
+
base = p;
|
|
9712
|
+
points.push(base);
|
|
9713
|
+
for (let i = 1; i < 2 ** (W - 1); i++) {
|
|
9714
|
+
base = base.add(p);
|
|
9715
|
+
points.push(base);
|
|
9716
|
+
}
|
|
9717
|
+
p = base.double();
|
|
9718
|
+
}
|
|
9719
|
+
return points;
|
|
9720
|
+
}
|
|
9721
|
+
wNAF(n, affinePoint) {
|
|
9722
|
+
if (!affinePoint && this.equals(ExtendedPoint.BASE))
|
|
9723
|
+
affinePoint = Point.BASE;
|
|
9724
|
+
const W = (affinePoint && affinePoint._WINDOW_SIZE) || 1;
|
|
9725
|
+
if (256 % W) {
|
|
9726
|
+
throw new Error('Point#wNAF: Invalid precomputation window, must be power of 2');
|
|
9727
|
+
}
|
|
9728
|
+
let precomputes = affinePoint && pointPrecomputes.get(affinePoint);
|
|
9729
|
+
if (!precomputes) {
|
|
9730
|
+
precomputes = this.precomputeWindow(W);
|
|
9731
|
+
if (affinePoint && W !== 1) {
|
|
9732
|
+
precomputes = ExtendedPoint.normalizeZ(precomputes);
|
|
9733
|
+
pointPrecomputes.set(affinePoint, precomputes);
|
|
9734
|
+
}
|
|
9735
|
+
}
|
|
9736
|
+
let p = ExtendedPoint.ZERO;
|
|
9737
|
+
let f = ExtendedPoint.BASE;
|
|
9738
|
+
const windows = 1 + 256 / W;
|
|
9739
|
+
const windowSize = 2 ** (W - 1);
|
|
9740
|
+
const mask = BigInt(2 ** W - 1);
|
|
9741
|
+
const maxNumber = 2 ** W;
|
|
9742
|
+
const shiftBy = BigInt(W);
|
|
9743
|
+
for (let window = 0; window < windows; window++) {
|
|
9744
|
+
const offset = window * windowSize;
|
|
9745
|
+
let wbits = Number(n & mask);
|
|
9746
|
+
n >>= shiftBy;
|
|
9747
|
+
if (wbits > windowSize) {
|
|
9748
|
+
wbits -= maxNumber;
|
|
9749
|
+
n += _1n$a;
|
|
9750
|
+
}
|
|
9751
|
+
const offset1 = offset;
|
|
9752
|
+
const offset2 = offset + Math.abs(wbits) - 1;
|
|
9753
|
+
const cond1 = window % 2 !== 0;
|
|
9754
|
+
const cond2 = wbits < 0;
|
|
9755
|
+
if (wbits === 0) {
|
|
9756
|
+
f = f.add(constTimeNegate(cond1, precomputes[offset1]));
|
|
9757
|
+
}
|
|
9758
|
+
else {
|
|
9759
|
+
p = p.add(constTimeNegate(cond2, precomputes[offset2]));
|
|
9760
|
+
}
|
|
9761
|
+
}
|
|
9762
|
+
return ExtendedPoint.normalizeZ([p, f])[0];
|
|
9763
|
+
}
|
|
9764
|
+
multiply(scalar, affinePoint) {
|
|
9765
|
+
return this.wNAF(normalizeScalar(scalar, CURVE$1.l), affinePoint);
|
|
9766
|
+
}
|
|
9767
|
+
multiplyUnsafe(scalar) {
|
|
9768
|
+
let n = normalizeScalar(scalar, CURVE$1.l, false);
|
|
9769
|
+
const G = ExtendedPoint.BASE;
|
|
9770
|
+
const P0 = ExtendedPoint.ZERO;
|
|
9771
|
+
if (n === _0n$8)
|
|
9772
|
+
return P0;
|
|
9773
|
+
if (this.equals(P0) || n === _1n$a)
|
|
9774
|
+
return this;
|
|
9775
|
+
if (this.equals(G))
|
|
9776
|
+
return this.wNAF(n);
|
|
9777
|
+
let p = P0;
|
|
9778
|
+
let d = this;
|
|
9779
|
+
while (n > _0n$8) {
|
|
9780
|
+
if (n & _1n$a)
|
|
9781
|
+
p = p.add(d);
|
|
9782
|
+
d = d.double();
|
|
9783
|
+
n >>= _1n$a;
|
|
9784
|
+
}
|
|
9785
|
+
return p;
|
|
9786
|
+
}
|
|
9787
|
+
isSmallOrder() {
|
|
9788
|
+
return this.multiplyUnsafe(CURVE$1.h).equals(ExtendedPoint.ZERO);
|
|
9789
|
+
}
|
|
9790
|
+
isTorsionFree() {
|
|
9791
|
+
let p = this.multiplyUnsafe(CURVE$1.l / _2n$6).double();
|
|
9792
|
+
if (CURVE$1.l % _2n$6)
|
|
9793
|
+
p = p.add(this);
|
|
9794
|
+
return p.equals(ExtendedPoint.ZERO);
|
|
9795
|
+
}
|
|
9796
|
+
toAffine(invZ) {
|
|
9797
|
+
const { x, y, z } = this;
|
|
9798
|
+
const is0 = this.equals(ExtendedPoint.ZERO);
|
|
9799
|
+
if (invZ == null)
|
|
9800
|
+
invZ = is0 ? _8n$2 : invert$1(z);
|
|
9801
|
+
const ax = mod$2(x * invZ);
|
|
9802
|
+
const ay = mod$2(y * invZ);
|
|
9803
|
+
const zz = mod$2(z * invZ);
|
|
9804
|
+
if (is0)
|
|
9805
|
+
return Point.ZERO;
|
|
9806
|
+
if (zz !== _1n$a)
|
|
9807
|
+
throw new Error('invZ was invalid');
|
|
9808
|
+
return new Point(ax, ay);
|
|
9809
|
+
}
|
|
9810
|
+
fromRistrettoBytes() {
|
|
9811
|
+
legacyRist();
|
|
9812
|
+
}
|
|
9813
|
+
toRistrettoBytes() {
|
|
9814
|
+
legacyRist();
|
|
9815
|
+
}
|
|
9816
|
+
fromRistrettoHash() {
|
|
9817
|
+
legacyRist();
|
|
9818
|
+
}
|
|
9819
|
+
}
|
|
9820
|
+
ExtendedPoint.BASE = new ExtendedPoint(CURVE$1.Gx, CURVE$1.Gy, _1n$a, mod$2(CURVE$1.Gx * CURVE$1.Gy));
|
|
9821
|
+
ExtendedPoint.ZERO = new ExtendedPoint(_0n$8, _1n$a, _1n$a, _0n$8);
|
|
9822
|
+
function constTimeNegate(condition, item) {
|
|
9823
|
+
const neg = item.negate();
|
|
9824
|
+
return condition ? neg : item;
|
|
9825
|
+
}
|
|
9826
|
+
function assertExtPoint(other) {
|
|
9827
|
+
if (!(other instanceof ExtendedPoint))
|
|
9828
|
+
throw new TypeError('ExtendedPoint expected');
|
|
9829
|
+
}
|
|
9830
|
+
function assertRstPoint(other) {
|
|
9831
|
+
if (!(other instanceof RistrettoPoint))
|
|
9832
|
+
throw new TypeError('RistrettoPoint expected');
|
|
9833
|
+
}
|
|
9834
|
+
function legacyRist() {
|
|
9835
|
+
throw new Error('Legacy method: switch to RistrettoPoint');
|
|
9836
|
+
}
|
|
9837
|
+
class RistrettoPoint {
|
|
9838
|
+
constructor(ep) {
|
|
9839
|
+
this.ep = ep;
|
|
9840
|
+
}
|
|
9841
|
+
static calcElligatorRistrettoMap(r0) {
|
|
9842
|
+
const { d } = CURVE$1;
|
|
9843
|
+
const r = mod$2(SQRT_M1 * r0 * r0);
|
|
9844
|
+
const Ns = mod$2((r + _1n$a) * ONE_MINUS_D_SQ);
|
|
9845
|
+
let c = BigInt(-1);
|
|
9846
|
+
const D = mod$2((c - d * r) * mod$2(r + d));
|
|
9847
|
+
let { isValid: Ns_D_is_sq, value: s } = uvRatio$1(Ns, D);
|
|
9848
|
+
let s_ = mod$2(s * r0);
|
|
9849
|
+
if (!edIsNegative(s_))
|
|
9850
|
+
s_ = mod$2(-s_);
|
|
9851
|
+
if (!Ns_D_is_sq)
|
|
9852
|
+
s = s_;
|
|
9853
|
+
if (!Ns_D_is_sq)
|
|
9854
|
+
c = r;
|
|
9855
|
+
const Nt = mod$2(c * (r - _1n$a) * D_MINUS_ONE_SQ - D);
|
|
9856
|
+
const s2 = s * s;
|
|
9857
|
+
const W0 = mod$2((s + s) * D);
|
|
9858
|
+
const W1 = mod$2(Nt * SQRT_AD_MINUS_ONE);
|
|
9859
|
+
const W2 = mod$2(_1n$a - s2);
|
|
9860
|
+
const W3 = mod$2(_1n$a + s2);
|
|
9861
|
+
return new ExtendedPoint(mod$2(W0 * W3), mod$2(W2 * W1), mod$2(W1 * W3), mod$2(W0 * W2));
|
|
9862
|
+
}
|
|
9863
|
+
static hashToCurve(hex) {
|
|
9864
|
+
hex = ensureBytes$1(hex, 64);
|
|
9865
|
+
const r1 = bytes255ToNumberLE(hex.slice(0, 32));
|
|
9866
|
+
const R1 = this.calcElligatorRistrettoMap(r1);
|
|
9867
|
+
const r2 = bytes255ToNumberLE(hex.slice(32, 64));
|
|
9868
|
+
const R2 = this.calcElligatorRistrettoMap(r2);
|
|
9869
|
+
return new RistrettoPoint(R1.add(R2));
|
|
9870
|
+
}
|
|
9871
|
+
static fromHex(hex) {
|
|
9872
|
+
hex = ensureBytes$1(hex, 32);
|
|
9873
|
+
const { a, d } = CURVE$1;
|
|
9874
|
+
const emsg = 'RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint';
|
|
9875
|
+
const s = bytes255ToNumberLE(hex);
|
|
9876
|
+
if (!equalBytes$1(numberTo32BytesLE(s), hex) || edIsNegative(s))
|
|
9877
|
+
throw new Error(emsg);
|
|
9878
|
+
const s2 = mod$2(s * s);
|
|
9879
|
+
const u1 = mod$2(_1n$a + a * s2);
|
|
9880
|
+
const u2 = mod$2(_1n$a - a * s2);
|
|
9881
|
+
const u1_2 = mod$2(u1 * u1);
|
|
9882
|
+
const u2_2 = mod$2(u2 * u2);
|
|
9883
|
+
const v = mod$2(a * d * u1_2 - u2_2);
|
|
9884
|
+
const { isValid, value: I } = invertSqrt(mod$2(v * u2_2));
|
|
9885
|
+
const Dx = mod$2(I * u2);
|
|
9886
|
+
const Dy = mod$2(I * Dx * v);
|
|
9887
|
+
let x = mod$2((s + s) * Dx);
|
|
9888
|
+
if (edIsNegative(x))
|
|
9889
|
+
x = mod$2(-x);
|
|
9890
|
+
const y = mod$2(u1 * Dy);
|
|
9891
|
+
const t = mod$2(x * y);
|
|
9892
|
+
if (!isValid || edIsNegative(t) || y === _0n$8)
|
|
9893
|
+
throw new Error(emsg);
|
|
9894
|
+
return new RistrettoPoint(new ExtendedPoint(x, y, _1n$a, t));
|
|
9895
|
+
}
|
|
9896
|
+
toRawBytes() {
|
|
9897
|
+
let { x, y, z, t } = this.ep;
|
|
9898
|
+
const u1 = mod$2(mod$2(z + y) * mod$2(z - y));
|
|
9899
|
+
const u2 = mod$2(x * y);
|
|
9900
|
+
const u2sq = mod$2(u2 * u2);
|
|
9901
|
+
const { value: invsqrt } = invertSqrt(mod$2(u1 * u2sq));
|
|
9902
|
+
const D1 = mod$2(invsqrt * u1);
|
|
9903
|
+
const D2 = mod$2(invsqrt * u2);
|
|
9904
|
+
const zInv = mod$2(D1 * D2 * t);
|
|
9905
|
+
let D;
|
|
9906
|
+
if (edIsNegative(t * zInv)) {
|
|
9907
|
+
let _x = mod$2(y * SQRT_M1);
|
|
9908
|
+
let _y = mod$2(x * SQRT_M1);
|
|
9909
|
+
x = _x;
|
|
9910
|
+
y = _y;
|
|
9911
|
+
D = mod$2(D1 * INVSQRT_A_MINUS_D);
|
|
9912
|
+
}
|
|
9913
|
+
else {
|
|
9914
|
+
D = D2;
|
|
9915
|
+
}
|
|
9916
|
+
if (edIsNegative(x * zInv))
|
|
9917
|
+
y = mod$2(-y);
|
|
9918
|
+
let s = mod$2((z - y) * D);
|
|
9919
|
+
if (edIsNegative(s))
|
|
9920
|
+
s = mod$2(-s);
|
|
9921
|
+
return numberTo32BytesLE(s);
|
|
9922
|
+
}
|
|
9923
|
+
toHex() {
|
|
9924
|
+
return bytesToHex$1(this.toRawBytes());
|
|
9925
|
+
}
|
|
9926
|
+
toString() {
|
|
9927
|
+
return this.toHex();
|
|
9928
|
+
}
|
|
9929
|
+
equals(other) {
|
|
9930
|
+
assertRstPoint(other);
|
|
9931
|
+
const a = this.ep;
|
|
9932
|
+
const b = other.ep;
|
|
9933
|
+
const one = mod$2(a.x * b.y) === mod$2(a.y * b.x);
|
|
9934
|
+
const two = mod$2(a.y * b.y) === mod$2(a.x * b.x);
|
|
9935
|
+
return one || two;
|
|
9936
|
+
}
|
|
9937
|
+
add(other) {
|
|
9938
|
+
assertRstPoint(other);
|
|
9939
|
+
return new RistrettoPoint(this.ep.add(other.ep));
|
|
9940
|
+
}
|
|
9941
|
+
subtract(other) {
|
|
9942
|
+
assertRstPoint(other);
|
|
9943
|
+
return new RistrettoPoint(this.ep.subtract(other.ep));
|
|
9944
|
+
}
|
|
9945
|
+
multiply(scalar) {
|
|
9946
|
+
return new RistrettoPoint(this.ep.multiply(scalar));
|
|
9947
|
+
}
|
|
9948
|
+
multiplyUnsafe(scalar) {
|
|
9949
|
+
return new RistrettoPoint(this.ep.multiplyUnsafe(scalar));
|
|
9950
|
+
}
|
|
9951
|
+
}
|
|
9952
|
+
RistrettoPoint.BASE = new RistrettoPoint(ExtendedPoint.BASE);
|
|
9953
|
+
RistrettoPoint.ZERO = new RistrettoPoint(ExtendedPoint.ZERO);
|
|
9954
|
+
const pointPrecomputes = new WeakMap();
|
|
9955
|
+
class Point {
|
|
9956
|
+
constructor(x, y) {
|
|
9957
|
+
this.x = x;
|
|
9958
|
+
this.y = y;
|
|
9959
|
+
}
|
|
9960
|
+
_setWindowSize(windowSize) {
|
|
9961
|
+
this._WINDOW_SIZE = windowSize;
|
|
9962
|
+
pointPrecomputes.delete(this);
|
|
9963
|
+
}
|
|
9964
|
+
static fromHex(hex, strict = true) {
|
|
9965
|
+
const { d, P } = CURVE$1;
|
|
9966
|
+
hex = ensureBytes$1(hex, 32);
|
|
9967
|
+
const normed = hex.slice();
|
|
9968
|
+
normed[31] = hex[31] & ~0x80;
|
|
9969
|
+
const y = bytesToNumberLE$1(normed);
|
|
9970
|
+
if (strict && y >= P)
|
|
9971
|
+
throw new Error('Expected 0 < hex < P');
|
|
9972
|
+
if (!strict && y >= POW_2_256)
|
|
9973
|
+
throw new Error('Expected 0 < hex < 2**256');
|
|
9974
|
+
const y2 = mod$2(y * y);
|
|
9975
|
+
const u = mod$2(y2 - _1n$a);
|
|
9976
|
+
const v = mod$2(d * y2 + _1n$a);
|
|
9977
|
+
let { isValid, value: x } = uvRatio$1(u, v);
|
|
9978
|
+
if (!isValid)
|
|
9979
|
+
throw new Error('Point.fromHex: invalid y coordinate');
|
|
9980
|
+
const isXOdd = (x & _1n$a) === _1n$a;
|
|
9981
|
+
const isLastByteOdd = (hex[31] & 0x80) !== 0;
|
|
9982
|
+
if (isLastByteOdd !== isXOdd) {
|
|
9983
|
+
x = mod$2(-x);
|
|
9984
|
+
}
|
|
9985
|
+
return new Point(x, y);
|
|
9986
|
+
}
|
|
9987
|
+
static async fromPrivateKey(privateKey) {
|
|
9988
|
+
return (await getExtendedPublicKey(privateKey)).point;
|
|
9989
|
+
}
|
|
9990
|
+
toRawBytes() {
|
|
9991
|
+
const bytes = numberTo32BytesLE(this.y);
|
|
9992
|
+
bytes[31] |= this.x & _1n$a ? 0x80 : 0;
|
|
9993
|
+
return bytes;
|
|
9994
|
+
}
|
|
9995
|
+
toHex() {
|
|
9996
|
+
return bytesToHex$1(this.toRawBytes());
|
|
9997
|
+
}
|
|
9998
|
+
toX25519() {
|
|
9999
|
+
const { y } = this;
|
|
10000
|
+
const u = mod$2((_1n$a + y) * invert$1(_1n$a - y));
|
|
10001
|
+
return numberTo32BytesLE(u);
|
|
10002
|
+
}
|
|
10003
|
+
isTorsionFree() {
|
|
10004
|
+
return ExtendedPoint.fromAffine(this).isTorsionFree();
|
|
10005
|
+
}
|
|
10006
|
+
equals(other) {
|
|
10007
|
+
return this.x === other.x && this.y === other.y;
|
|
10008
|
+
}
|
|
10009
|
+
negate() {
|
|
10010
|
+
return new Point(mod$2(-this.x), this.y);
|
|
10011
|
+
}
|
|
10012
|
+
add(other) {
|
|
10013
|
+
return ExtendedPoint.fromAffine(this).add(ExtendedPoint.fromAffine(other)).toAffine();
|
|
10014
|
+
}
|
|
10015
|
+
subtract(other) {
|
|
10016
|
+
return this.add(other.negate());
|
|
10017
|
+
}
|
|
10018
|
+
multiply(scalar) {
|
|
10019
|
+
return ExtendedPoint.fromAffine(this).multiply(scalar, this).toAffine();
|
|
10020
|
+
}
|
|
10021
|
+
}
|
|
10022
|
+
Point.BASE = new Point(CURVE$1.Gx, CURVE$1.Gy);
|
|
10023
|
+
Point.ZERO = new Point(_0n$8, _1n$a);
|
|
10024
|
+
let Signature$1 = class Signature {
|
|
10025
|
+
constructor(r, s) {
|
|
10026
|
+
this.r = r;
|
|
10027
|
+
this.s = s;
|
|
10028
|
+
this.assertValidity();
|
|
10029
|
+
}
|
|
10030
|
+
static fromHex(hex) {
|
|
10031
|
+
const bytes = ensureBytes$1(hex, 64);
|
|
10032
|
+
const r = Point.fromHex(bytes.slice(0, 32), false);
|
|
10033
|
+
const s = bytesToNumberLE$1(bytes.slice(32, 64));
|
|
10034
|
+
return new Signature(r, s);
|
|
10035
|
+
}
|
|
10036
|
+
assertValidity() {
|
|
10037
|
+
const { r, s } = this;
|
|
10038
|
+
if (!(r instanceof Point))
|
|
10039
|
+
throw new Error('Expected Point instance');
|
|
10040
|
+
normalizeScalar(s, CURVE$1.l, false);
|
|
10041
|
+
return this;
|
|
10042
|
+
}
|
|
10043
|
+
toRawBytes() {
|
|
10044
|
+
const u8 = new Uint8Array(64);
|
|
10045
|
+
u8.set(this.r.toRawBytes());
|
|
10046
|
+
u8.set(numberTo32BytesLE(this.s), 32);
|
|
10047
|
+
return u8;
|
|
10048
|
+
}
|
|
10049
|
+
toHex() {
|
|
10050
|
+
return bytesToHex$1(this.toRawBytes());
|
|
10051
|
+
}
|
|
10052
|
+
};
|
|
10053
|
+
function concatBytes$2(...arrays) {
|
|
10054
|
+
if (!arrays.every((a) => a instanceof Uint8Array))
|
|
10055
|
+
throw new Error('Expected Uint8Array list');
|
|
10056
|
+
if (arrays.length === 1)
|
|
10057
|
+
return arrays[0];
|
|
10058
|
+
const length = arrays.reduce((a, arr) => a + arr.length, 0);
|
|
10059
|
+
const result = new Uint8Array(length);
|
|
10060
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
10061
|
+
const arr = arrays[i];
|
|
10062
|
+
result.set(arr, pad);
|
|
10063
|
+
pad += arr.length;
|
|
10064
|
+
}
|
|
10065
|
+
return result;
|
|
10066
|
+
}
|
|
10067
|
+
const hexes$1 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
|
|
10068
|
+
function bytesToHex$1(uint8a) {
|
|
10069
|
+
if (!(uint8a instanceof Uint8Array))
|
|
10070
|
+
throw new Error('Uint8Array expected');
|
|
10071
|
+
let hex = '';
|
|
10072
|
+
for (let i = 0; i < uint8a.length; i++) {
|
|
10073
|
+
hex += hexes$1[uint8a[i]];
|
|
10074
|
+
}
|
|
10075
|
+
return hex;
|
|
10076
|
+
}
|
|
10077
|
+
function hexToBytes$1(hex) {
|
|
10078
|
+
if (typeof hex !== 'string') {
|
|
10079
|
+
throw new TypeError('hexToBytes: expected string, got ' + typeof hex);
|
|
10080
|
+
}
|
|
10081
|
+
if (hex.length % 2)
|
|
10082
|
+
throw new Error('hexToBytes: received invalid unpadded hex');
|
|
10083
|
+
const array = new Uint8Array(hex.length / 2);
|
|
10084
|
+
for (let i = 0; i < array.length; i++) {
|
|
10085
|
+
const j = i * 2;
|
|
10086
|
+
const hexByte = hex.slice(j, j + 2);
|
|
10087
|
+
const byte = Number.parseInt(hexByte, 16);
|
|
10088
|
+
if (Number.isNaN(byte) || byte < 0)
|
|
10089
|
+
throw new Error('Invalid byte sequence');
|
|
10090
|
+
array[i] = byte;
|
|
10091
|
+
}
|
|
10092
|
+
return array;
|
|
10093
|
+
}
|
|
10094
|
+
function numberTo32BytesBE(num) {
|
|
10095
|
+
const length = 32;
|
|
10096
|
+
const hex = num.toString(16).padStart(length * 2, '0');
|
|
10097
|
+
return hexToBytes$1(hex);
|
|
10098
|
+
}
|
|
10099
|
+
function numberTo32BytesLE(num) {
|
|
10100
|
+
return numberTo32BytesBE(num).reverse();
|
|
10101
|
+
}
|
|
10102
|
+
function edIsNegative(num) {
|
|
10103
|
+
return (mod$2(num) & _1n$a) === _1n$a;
|
|
10104
|
+
}
|
|
10105
|
+
function bytesToNumberLE$1(uint8a) {
|
|
10106
|
+
if (!(uint8a instanceof Uint8Array))
|
|
10107
|
+
throw new Error('Expected Uint8Array');
|
|
10108
|
+
return BigInt('0x' + bytesToHex$1(Uint8Array.from(uint8a).reverse()));
|
|
10109
|
+
}
|
|
10110
|
+
const MAX_255B = BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
10111
|
+
function bytes255ToNumberLE(bytes) {
|
|
10112
|
+
return mod$2(bytesToNumberLE$1(bytes) & MAX_255B);
|
|
10113
|
+
}
|
|
10114
|
+
function mod$2(a, b = CURVE$1.P) {
|
|
10115
|
+
const res = a % b;
|
|
10116
|
+
return res >= _0n$8 ? res : b + res;
|
|
10117
|
+
}
|
|
10118
|
+
function invert$1(number, modulo = CURVE$1.P) {
|
|
10119
|
+
if (number === _0n$8 || modulo <= _0n$8) {
|
|
10120
|
+
throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
|
|
10121
|
+
}
|
|
10122
|
+
let a = mod$2(number, modulo);
|
|
10123
|
+
let b = modulo;
|
|
10124
|
+
let x = _0n$8, u = _1n$a;
|
|
10125
|
+
while (a !== _0n$8) {
|
|
10126
|
+
const q = b / a;
|
|
10127
|
+
const r = b % a;
|
|
10128
|
+
const m = x - u * q;
|
|
10129
|
+
b = a, a = r, x = u, u = m;
|
|
10130
|
+
}
|
|
10131
|
+
const gcd = b;
|
|
10132
|
+
if (gcd !== _1n$a)
|
|
10133
|
+
throw new Error('invert: does not exist');
|
|
10134
|
+
return mod$2(x, modulo);
|
|
10135
|
+
}
|
|
10136
|
+
function invertBatch(nums, p = CURVE$1.P) {
|
|
10137
|
+
const tmp = new Array(nums.length);
|
|
10138
|
+
const lastMultiplied = nums.reduce((acc, num, i) => {
|
|
10139
|
+
if (num === _0n$8)
|
|
10140
|
+
return acc;
|
|
10141
|
+
tmp[i] = acc;
|
|
10142
|
+
return mod$2(acc * num, p);
|
|
10143
|
+
}, _1n$a);
|
|
10144
|
+
const inverted = invert$1(lastMultiplied, p);
|
|
10145
|
+
nums.reduceRight((acc, num, i) => {
|
|
10146
|
+
if (num === _0n$8)
|
|
10147
|
+
return acc;
|
|
10148
|
+
tmp[i] = mod$2(acc * tmp[i], p);
|
|
10149
|
+
return mod$2(acc * num, p);
|
|
10150
|
+
}, inverted);
|
|
10151
|
+
return tmp;
|
|
10152
|
+
}
|
|
10153
|
+
function pow2$1(x, power) {
|
|
10154
|
+
const { P } = CURVE$1;
|
|
10155
|
+
let res = x;
|
|
10156
|
+
while (power-- > _0n$8) {
|
|
10157
|
+
res *= res;
|
|
10158
|
+
res %= P;
|
|
10159
|
+
}
|
|
10160
|
+
return res;
|
|
10161
|
+
}
|
|
10162
|
+
function pow_2_252_3(x) {
|
|
10163
|
+
const { P } = CURVE$1;
|
|
10164
|
+
const _5n = BigInt(5);
|
|
10165
|
+
const _10n = BigInt(10);
|
|
10166
|
+
const _20n = BigInt(20);
|
|
10167
|
+
const _40n = BigInt(40);
|
|
10168
|
+
const _80n = BigInt(80);
|
|
10169
|
+
const x2 = (x * x) % P;
|
|
10170
|
+
const b2 = (x2 * x) % P;
|
|
10171
|
+
const b4 = (pow2$1(b2, _2n$6) * b2) % P;
|
|
10172
|
+
const b5 = (pow2$1(b4, _1n$a) * x) % P;
|
|
10173
|
+
const b10 = (pow2$1(b5, _5n) * b5) % P;
|
|
10174
|
+
const b20 = (pow2$1(b10, _10n) * b10) % P;
|
|
10175
|
+
const b40 = (pow2$1(b20, _20n) * b20) % P;
|
|
10176
|
+
const b80 = (pow2$1(b40, _40n) * b40) % P;
|
|
10177
|
+
const b160 = (pow2$1(b80, _80n) * b80) % P;
|
|
10178
|
+
const b240 = (pow2$1(b160, _80n) * b80) % P;
|
|
10179
|
+
const b250 = (pow2$1(b240, _10n) * b10) % P;
|
|
10180
|
+
const pow_p_5_8 = (pow2$1(b250, _2n$6) * x) % P;
|
|
10181
|
+
return { pow_p_5_8, b2 };
|
|
10182
|
+
}
|
|
10183
|
+
function uvRatio$1(u, v) {
|
|
10184
|
+
const v3 = mod$2(v * v * v);
|
|
10185
|
+
const v7 = mod$2(v3 * v3 * v);
|
|
10186
|
+
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
10187
|
+
let x = mod$2(u * v3 * pow);
|
|
10188
|
+
const vx2 = mod$2(v * x * x);
|
|
10189
|
+
const root1 = x;
|
|
10190
|
+
const root2 = mod$2(x * SQRT_M1);
|
|
10191
|
+
const useRoot1 = vx2 === u;
|
|
10192
|
+
const useRoot2 = vx2 === mod$2(-u);
|
|
10193
|
+
const noRoot = vx2 === mod$2(-u * SQRT_M1);
|
|
10194
|
+
if (useRoot1)
|
|
10195
|
+
x = root1;
|
|
10196
|
+
if (useRoot2 || noRoot)
|
|
10197
|
+
x = root2;
|
|
10198
|
+
if (edIsNegative(x))
|
|
10199
|
+
x = mod$2(-x);
|
|
10200
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
10201
|
+
}
|
|
10202
|
+
function invertSqrt(number) {
|
|
10203
|
+
return uvRatio$1(_1n$a, number);
|
|
10204
|
+
}
|
|
10205
|
+
function modlLE(hash) {
|
|
10206
|
+
return mod$2(bytesToNumberLE$1(hash), CURVE$1.l);
|
|
10207
|
+
}
|
|
10208
|
+
function equalBytes$1(b1, b2) {
|
|
10209
|
+
if (b1.length !== b2.length) {
|
|
10210
|
+
return false;
|
|
10211
|
+
}
|
|
10212
|
+
for (let i = 0; i < b1.length; i++) {
|
|
10213
|
+
if (b1[i] !== b2[i]) {
|
|
10214
|
+
return false;
|
|
10215
|
+
}
|
|
10216
|
+
}
|
|
10217
|
+
return true;
|
|
10218
|
+
}
|
|
10219
|
+
function ensureBytes$1(hex, expectedLength) {
|
|
10220
|
+
const bytes = hex instanceof Uint8Array ? Uint8Array.from(hex) : hexToBytes$1(hex);
|
|
10221
|
+
if (typeof expectedLength === 'number' && bytes.length !== expectedLength)
|
|
10222
|
+
throw new Error(`Expected ${expectedLength} bytes`);
|
|
10223
|
+
return bytes;
|
|
10224
|
+
}
|
|
10225
|
+
function normalizeScalar(num, max, strict = true) {
|
|
10226
|
+
if (!max)
|
|
10227
|
+
throw new TypeError('Specify max value');
|
|
10228
|
+
if (typeof num === 'number' && Number.isSafeInteger(num))
|
|
10229
|
+
num = BigInt(num);
|
|
10230
|
+
if (typeof num === 'bigint' && num < max) {
|
|
10231
|
+
if (strict) {
|
|
10232
|
+
if (_0n$8 < num)
|
|
10233
|
+
return num;
|
|
10234
|
+
}
|
|
10235
|
+
else {
|
|
10236
|
+
if (_0n$8 <= num)
|
|
10237
|
+
return num;
|
|
10238
|
+
}
|
|
10239
|
+
}
|
|
10240
|
+
throw new TypeError('Expected valid scalar: 0 < scalar < max');
|
|
10241
|
+
}
|
|
10242
|
+
function adjustBytes25519(bytes) {
|
|
10243
|
+
bytes[0] &= 248;
|
|
10244
|
+
bytes[31] &= 127;
|
|
10245
|
+
bytes[31] |= 64;
|
|
10246
|
+
return bytes;
|
|
10247
|
+
}
|
|
10248
|
+
function checkPrivateKey(key) {
|
|
10249
|
+
key =
|
|
10250
|
+
typeof key === 'bigint' || typeof key === 'number'
|
|
10251
|
+
? numberTo32BytesBE(normalizeScalar(key, POW_2_256))
|
|
10252
|
+
: ensureBytes$1(key);
|
|
10253
|
+
if (key.length !== 32)
|
|
10254
|
+
throw new Error(`Expected 32 bytes`);
|
|
10255
|
+
return key;
|
|
10256
|
+
}
|
|
10257
|
+
function getKeyFromHash(hashed) {
|
|
10258
|
+
const head = adjustBytes25519(hashed.slice(0, 32));
|
|
10259
|
+
const prefix = hashed.slice(32, 64);
|
|
10260
|
+
const scalar = modlLE(head);
|
|
10261
|
+
const point = Point.BASE.multiply(scalar);
|
|
10262
|
+
const pointBytes = point.toRawBytes();
|
|
10263
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
10264
|
+
}
|
|
10265
|
+
let _sha512Sync;
|
|
10266
|
+
async function getExtendedPublicKey(key) {
|
|
10267
|
+
return getKeyFromHash(await utils.sha512(checkPrivateKey(key)));
|
|
10268
|
+
}
|
|
10269
|
+
function prepareVerification(sig, message, publicKey) {
|
|
10270
|
+
message = ensureBytes$1(message);
|
|
10271
|
+
if (!(publicKey instanceof Point))
|
|
10272
|
+
publicKey = Point.fromHex(publicKey, false);
|
|
10273
|
+
const { r, s } = sig instanceof Signature$1 ? sig.assertValidity() : Signature$1.fromHex(sig);
|
|
10274
|
+
const SB = ExtendedPoint.BASE.multiplyUnsafe(s);
|
|
10275
|
+
return { r, s, SB, pub: publicKey, msg: message };
|
|
10276
|
+
}
|
|
10277
|
+
function finishVerification(publicKey, r, SB, hashed) {
|
|
10278
|
+
const k = modlLE(hashed);
|
|
10279
|
+
const kA = ExtendedPoint.fromAffine(publicKey).multiplyUnsafe(k);
|
|
10280
|
+
const RkA = ExtendedPoint.fromAffine(r).add(kA);
|
|
10281
|
+
return RkA.subtract(SB).multiplyUnsafe(CURVE$1.h).equals(ExtendedPoint.ZERO);
|
|
10282
|
+
}
|
|
10283
|
+
async function verify$6(sig, message, publicKey) {
|
|
10284
|
+
const { r, SB, msg, pub } = prepareVerification(sig, message, publicKey);
|
|
10285
|
+
const hashed = await utils.sha512(r.toRawBytes(), pub.toRawBytes(), msg);
|
|
10286
|
+
return finishVerification(pub, r, SB, hashed);
|
|
10287
|
+
}
|
|
10288
|
+
Point.BASE._setWindowSize(8);
|
|
10289
|
+
const crypto$3 = {
|
|
10290
|
+
node: nodeCrypto__namespace,
|
|
10291
|
+
web: typeof self === 'object' && 'crypto' in self ? self.crypto : undefined,
|
|
10292
|
+
};
|
|
10293
|
+
const utils = {
|
|
10294
|
+
bytesToHex: bytesToHex$1,
|
|
10295
|
+
hexToBytes: hexToBytes$1,
|
|
10296
|
+
concatBytes: concatBytes$2,
|
|
10297
|
+
getExtendedPublicKey,
|
|
10298
|
+
mod: mod$2,
|
|
10299
|
+
invert: invert$1,
|
|
10300
|
+
TORSION_SUBGROUP: [
|
|
10301
|
+
'0100000000000000000000000000000000000000000000000000000000000000',
|
|
10302
|
+
'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a',
|
|
10303
|
+
'0000000000000000000000000000000000000000000000000000000000000080',
|
|
10304
|
+
'26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05',
|
|
10305
|
+
'ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f',
|
|
10306
|
+
'26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85',
|
|
10307
|
+
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
10308
|
+
'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa',
|
|
10309
|
+
],
|
|
10310
|
+
hashToPrivateScalar: (hash) => {
|
|
10311
|
+
hash = ensureBytes$1(hash);
|
|
10312
|
+
if (hash.length < 40 || hash.length > 1024)
|
|
10313
|
+
throw new Error('Expected 40-1024 bytes of private key as per FIPS 186');
|
|
10314
|
+
return mod$2(bytesToNumberLE$1(hash), CURVE$1.l - _1n$a) + _1n$a;
|
|
10315
|
+
},
|
|
10316
|
+
randomBytes: (bytesLength = 32) => {
|
|
10317
|
+
if (crypto$3.web) {
|
|
10318
|
+
return crypto$3.web.getRandomValues(new Uint8Array(bytesLength));
|
|
10319
|
+
}
|
|
10320
|
+
else if (crypto$3.node) {
|
|
10321
|
+
const { randomBytes } = crypto$3.node;
|
|
10322
|
+
return new Uint8Array(randomBytes(bytesLength).buffer);
|
|
10323
|
+
}
|
|
10324
|
+
else {
|
|
10325
|
+
throw new Error("The environment doesn't have randomBytes function");
|
|
10326
|
+
}
|
|
10327
|
+
},
|
|
10328
|
+
randomPrivateKey: () => {
|
|
10329
|
+
return utils.randomBytes(32);
|
|
10330
|
+
},
|
|
10331
|
+
sha512: async (...messages) => {
|
|
10332
|
+
const message = concatBytes$2(...messages);
|
|
10333
|
+
if (crypto$3.web) {
|
|
10334
|
+
const buffer = await crypto$3.web.subtle.digest('SHA-512', message.buffer);
|
|
10335
|
+
return new Uint8Array(buffer);
|
|
10336
|
+
}
|
|
10337
|
+
else if (crypto$3.node) {
|
|
10338
|
+
return Uint8Array.from(crypto$3.node.createHash('sha512').update(message).digest());
|
|
10339
|
+
}
|
|
10340
|
+
else {
|
|
10341
|
+
throw new Error("The environment doesn't have sha512 function");
|
|
10342
|
+
}
|
|
10343
|
+
},
|
|
10344
|
+
precompute(windowSize = 8, point = Point.BASE) {
|
|
10345
|
+
const cached = point.equals(Point.BASE) ? point : new Point(point.x, point.y);
|
|
10346
|
+
cached._setWindowSize(windowSize);
|
|
10347
|
+
cached.multiply(_2n$6);
|
|
10348
|
+
return cached;
|
|
10349
|
+
},
|
|
10350
|
+
sha512Sync: undefined,
|
|
10351
|
+
};
|
|
10352
|
+
Object.defineProperties(utils, {
|
|
10353
|
+
sha512Sync: {
|
|
10354
|
+
configurable: false,
|
|
10355
|
+
get() {
|
|
10356
|
+
return _sha512Sync;
|
|
10357
|
+
},
|
|
10358
|
+
set(val) {
|
|
10359
|
+
if (!_sha512Sync)
|
|
10360
|
+
_sha512Sync = val;
|
|
10361
|
+
},
|
|
10362
|
+
},
|
|
9554
10363
|
});
|
|
9555
10364
|
|
|
9556
10365
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -9586,6 +10395,8 @@ var ecdsa = /*#__PURE__*/Object.freeze({
|
|
|
9586
10395
|
* @async
|
|
9587
10396
|
*/
|
|
9588
10397
|
async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
10398
|
+
const curve = new CurveWithOID(oid);
|
|
10399
|
+
checkPublicPointEnconding(curve, publicKey);
|
|
9589
10400
|
if (hash$1.getHashByteLength(hashAlgo) < hash$1.getHashByteLength(enums.hash.sha256)) {
|
|
9590
10401
|
// see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
|
|
9591
10402
|
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
@@ -9612,11 +10423,13 @@ async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
9612
10423
|
* @async
|
|
9613
10424
|
*/
|
|
9614
10425
|
async function verify$5(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
10426
|
+
const curve = new CurveWithOID(oid);
|
|
10427
|
+
checkPublicPointEnconding(curve, publicKey);
|
|
9615
10428
|
if (hash$1.getHashByteLength(hashAlgo) < hash$1.getHashByteLength(enums.hash.sha256)) {
|
|
9616
10429
|
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
9617
10430
|
}
|
|
9618
10431
|
const signature = util.concatUint8Array([r, s]);
|
|
9619
|
-
return
|
|
10432
|
+
return verify$6(signature, hashed, publicKey.subarray(1));
|
|
9620
10433
|
}
|
|
9621
10434
|
/**
|
|
9622
10435
|
* Validate legacy EdDSA parameters
|
|
@@ -9742,7 +10555,7 @@ async function verify$4(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
|
9742
10555
|
}
|
|
9743
10556
|
switch (algo) {
|
|
9744
10557
|
case enums.publicKey.ed25519:
|
|
9745
|
-
return
|
|
10558
|
+
return verify$6(RS, hashed, publicKey);
|
|
9746
10559
|
case enums.publicKey.ed448: {
|
|
9747
10560
|
const ed448 = await util.getNobleCurve(enums.publicKey.ed448);
|
|
9748
10561
|
return ed448.verify(RS, hashed, publicKey);
|
|
@@ -10106,7 +10919,7 @@ function buildEcdhParam(public_algo, oid, kdfParams, fingerprint) {
|
|
|
10106
10919
|
new Uint8Array([public_algo]),
|
|
10107
10920
|
kdfParams.write(true),
|
|
10108
10921
|
util.stringToUint8Array('Anonymous Sender '),
|
|
10109
|
-
kdfParams.replacementFingerprint || fingerprint
|
|
10922
|
+
kdfParams.replacementFingerprint || fingerprint
|
|
10110
10923
|
]);
|
|
10111
10924
|
}
|
|
10112
10925
|
|
|
@@ -10148,7 +10961,7 @@ async function genPublicEphemeralKey(curve, Q) {
|
|
|
10148
10961
|
const d = getRandomBytes(32);
|
|
10149
10962
|
const { secretKey, sharedKey } = await genPrivateEphemeralKey(curve, Q, null, d);
|
|
10150
10963
|
let { publicKey } = nacl.box.keyPair.fromSecretKey(secretKey);
|
|
10151
|
-
publicKey = util.concatUint8Array([new Uint8Array([
|
|
10964
|
+
publicKey = util.concatUint8Array([new Uint8Array([curve.wireFormatLeadingByte]), publicKey]);
|
|
10152
10965
|
return { publicKey, sharedKey }; // Note: sharedKey is little-endian here, unlike below
|
|
10153
10966
|
}
|
|
10154
10967
|
case 'web':
|
|
@@ -10176,7 +10989,7 @@ async function genPublicEphemeralKey(curve, Q) {
|
|
|
10176
10989
|
* @param {module:type/kdf_params} kdfParams - KDF params including cipher and algorithm to use
|
|
10177
10990
|
* @param {Uint8Array} data - Unpadded session key data
|
|
10178
10991
|
* @param {Uint8Array} Q - Recipient public key
|
|
10179
|
-
* @param {Uint8Array} fingerprint - Recipient fingerprint
|
|
10992
|
+
* @param {Uint8Array} fingerprint - Recipient fingerprint, already truncated depending on the key version
|
|
10180
10993
|
* @returns {Promise<{publicKey: Uint8Array, wrappedKey: Uint8Array}>}
|
|
10181
10994
|
* @async
|
|
10182
10995
|
*/
|
|
@@ -10184,6 +10997,7 @@ async function encrypt$2(oid, kdfParams, data, Q, fingerprint) {
|
|
|
10184
10997
|
const m = encode(data);
|
|
10185
10998
|
|
|
10186
10999
|
const curve = new CurveWithOID(oid);
|
|
11000
|
+
checkPublicPointEnconding(curve, Q);
|
|
10187
11001
|
const { publicKey, sharedKey } = await genPublicEphemeralKey(curve, Q);
|
|
10188
11002
|
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
|
|
10189
11003
|
const { keySize } = getCipherParams(kdfParams.cipher);
|
|
@@ -10240,12 +11054,14 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
|
|
|
10240
11054
|
* @param {Uint8Array} C - Encrypted and wrapped value derived from session key
|
|
10241
11055
|
* @param {Uint8Array} Q - Recipient public key
|
|
10242
11056
|
* @param {Uint8Array} d - Recipient private key
|
|
10243
|
-
* @param {Uint8Array} fingerprint - Recipient fingerprint
|
|
11057
|
+
* @param {Uint8Array} fingerprint - Recipient fingerprint, already truncated depending on the key version
|
|
10244
11058
|
* @returns {Promise<Uint8Array>} Value derived from session key.
|
|
10245
11059
|
* @async
|
|
10246
11060
|
*/
|
|
10247
11061
|
async function decrypt$2(oid, kdfParams, V, C, Q, d, fingerprint) {
|
|
10248
11062
|
const curve = new CurveWithOID(oid);
|
|
11063
|
+
checkPublicPointEnconding(curve, Q);
|
|
11064
|
+
checkPublicPointEnconding(curve, V);
|
|
10249
11065
|
const { sharedKey } = await genPrivateEphemeralKey(curve, V, Q, d);
|
|
10250
11066
|
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
|
|
10251
11067
|
const { keySize } = getCipherParams(kdfParams.cipher);
|
|
@@ -10377,7 +11193,7 @@ async function webPublicEphemeralKey(curve, Q) {
|
|
|
10377
11193
|
);
|
|
10378
11194
|
[s, p] = await Promise.all([s, p]);
|
|
10379
11195
|
const sharedKey = new Uint8Array(s);
|
|
10380
|
-
const publicKey = new Uint8Array(jwkToRawPublic(p));
|
|
11196
|
+
const publicKey = new Uint8Array(jwkToRawPublic(p, curve.wireFormatLeadingByte));
|
|
10381
11197
|
return { publicKey, sharedKey };
|
|
10382
11198
|
}
|
|
10383
11199
|
|
|
@@ -10700,14 +11516,14 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
|
|
|
10700
11516
|
let r;
|
|
10701
11517
|
let s;
|
|
10702
11518
|
let t;
|
|
10703
|
-
g = mod$
|
|
10704
|
-
x = mod$
|
|
11519
|
+
g = mod$3(g, p);
|
|
11520
|
+
x = mod$3(x, q);
|
|
10705
11521
|
// If the output size of the chosen hash is larger than the number of
|
|
10706
11522
|
// bits of q, the hash result is truncated to fit by taking the number
|
|
10707
11523
|
// of leftmost bits equal to the number of bits of q. This (possibly
|
|
10708
11524
|
// truncated) hash function result is treated as a number and used
|
|
10709
11525
|
// directly in the DSA signature algorithm.
|
|
10710
|
-
const h = mod$
|
|
11526
|
+
const h = mod$3(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
|
|
10711
11527
|
// FIPS-186-4, section 4.6:
|
|
10712
11528
|
// The values of r and s shall be checked to determine if r = 0 or s = 0.
|
|
10713
11529
|
// If either r = 0 or s = 0, a new value of k shall be generated, and the
|
|
@@ -10716,13 +11532,13 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
|
|
|
10716
11532
|
while (true) {
|
|
10717
11533
|
// See Appendix B here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
|
|
10718
11534
|
k = getRandomBigInteger(_1n$9, q); // returns in [1, q-1]
|
|
10719
|
-
r = mod$
|
|
11535
|
+
r = mod$3(modExp(g, k, p), q); // (g**k mod p) mod q
|
|
10720
11536
|
if (r === _0n) {
|
|
10721
11537
|
continue;
|
|
10722
11538
|
}
|
|
10723
|
-
const xr = mod$
|
|
10724
|
-
t = mod$
|
|
10725
|
-
s = mod$
|
|
11539
|
+
const xr = mod$3(x * r, q);
|
|
11540
|
+
t = mod$3(h + xr, q); // H(m) + x*r mod q
|
|
11541
|
+
s = mod$3(modInv(k, q) * t, q); // k**-1 * (H(m) + x*r) mod q
|
|
10726
11542
|
if (s === _0n) {
|
|
10727
11543
|
continue;
|
|
10728
11544
|
}
|
|
@@ -10761,20 +11577,20 @@ async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
|
|
|
10761
11577
|
util.printDebug('invalid DSA Signature');
|
|
10762
11578
|
return false;
|
|
10763
11579
|
}
|
|
10764
|
-
const h = mod$
|
|
11580
|
+
const h = mod$3(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
|
|
10765
11581
|
const w = modInv(s, q); // s**-1 mod q
|
|
10766
11582
|
if (w === _0n$7) {
|
|
10767
11583
|
util.printDebug('invalid DSA Signature');
|
|
10768
11584
|
return false;
|
|
10769
11585
|
}
|
|
10770
11586
|
|
|
10771
|
-
g = mod$
|
|
10772
|
-
y = mod$
|
|
10773
|
-
const u1 = mod$
|
|
10774
|
-
const u2 = mod$
|
|
11587
|
+
g = mod$3(g, p);
|
|
11588
|
+
y = mod$3(y, p);
|
|
11589
|
+
const u1 = mod$3(h * w, q); // H(m) * w mod q
|
|
11590
|
+
const u2 = mod$3(r * w, q); // r * w mod q
|
|
10775
11591
|
const t1 = modExp(g, u1, p); // g**u1 mod p
|
|
10776
11592
|
const t2 = modExp(y, u2, p); // y**u2 mod p
|
|
10777
|
-
const v = mod$
|
|
11593
|
+
const v = mod$3(mod$3(t1 * t2, p), q); // (g**u1 * y**u2 mod p) mod q
|
|
10778
11594
|
return v === r;
|
|
10779
11595
|
}
|
|
10780
11596
|
|
|
@@ -10801,7 +11617,7 @@ async function validateParams$2(p, q, g, y, x) {
|
|
|
10801
11617
|
/**
|
|
10802
11618
|
* Check that subgroup order q divides p-1
|
|
10803
11619
|
*/
|
|
10804
|
-
if (mod$
|
|
11620
|
+
if (mod$3(p - _1n$9, q) !== _0n$7) {
|
|
10805
11621
|
return false;
|
|
10806
11622
|
}
|
|
10807
11623
|
|
|
@@ -11598,6 +12414,9 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
11598
12414
|
case enums.publicKey.eddsaLegacy: {
|
|
11599
12415
|
const oid = new OID(); read += oid.read(bytes);
|
|
11600
12416
|
checkSupportedCurve(oid);
|
|
12417
|
+
if (oid.getName() !== enums.curve.ed25519Legacy) {
|
|
12418
|
+
throw new Error('Unexpected OID for eddsaLegacy');
|
|
12419
|
+
}
|
|
11601
12420
|
let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
|
|
11602
12421
|
Q = util.leftPad(Q, 33);
|
|
11603
12422
|
return { read: read, publicParams: { oid, Q } };
|
|
@@ -11661,6 +12480,9 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
|
11661
12480
|
}
|
|
11662
12481
|
case enums.publicKey.eddsaLegacy: {
|
|
11663
12482
|
const payloadSize = getCurvePayloadSize(algo, publicParams.oid);
|
|
12483
|
+
if (publicParams.oid.getName() !== enums.curve.ed25519Legacy) {
|
|
12484
|
+
throw new Error('Unexpected OID for eddsaLegacy');
|
|
12485
|
+
}
|
|
11664
12486
|
let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
|
|
11665
12487
|
seed = util.leftPad(seed, payloadSize);
|
|
11666
12488
|
return { read, privateParams: { seed } };
|
|
@@ -14499,6 +15321,7 @@ class SignaturePacket {
|
|
|
14499
15321
|
|
|
14500
15322
|
this.signatureData = null;
|
|
14501
15323
|
this.unhashedSubpackets = [];
|
|
15324
|
+
this.unknownSubpackets = [];
|
|
14502
15325
|
this.signedHashValue = null;
|
|
14503
15326
|
this.salt = null;
|
|
14504
15327
|
|
|
@@ -14548,9 +15371,12 @@ class SignaturePacket {
|
|
|
14548
15371
|
* @param {String} bytes - Payload of a tag 2 packet
|
|
14549
15372
|
* @returns {SignaturePacket} Object representation.
|
|
14550
15373
|
*/
|
|
14551
|
-
read(bytes) {
|
|
15374
|
+
read(bytes, config$1 = config) {
|
|
14552
15375
|
let i = 0;
|
|
14553
15376
|
this.version = bytes[i++];
|
|
15377
|
+
if (this.version === 5 && !config$1.enableParsingV5Entities) {
|
|
15378
|
+
throw new UnsupportedError('Support for v5 entities is disabled; turn on `config.enableParsingV5Entities` if needed');
|
|
15379
|
+
}
|
|
14554
15380
|
|
|
14555
15381
|
if (this.version !== 4 && this.version !== 5 && this.version !== 6) {
|
|
14556
15382
|
throw new UnsupportedError(`Version ${this.version} of the signature packet is unsupported.`);
|
|
@@ -14827,10 +15653,8 @@ class SignaturePacket {
|
|
|
14827
15653
|
* @returns {Uint8Array} Subpacket data.
|
|
14828
15654
|
*/
|
|
14829
15655
|
writeUnhashedSubPackets() {
|
|
14830
|
-
const arr =
|
|
14831
|
-
|
|
14832
|
-
arr.push(writeSimpleLength(data.length));
|
|
14833
|
-
arr.push(data);
|
|
15656
|
+
const arr = this.unhashedSubpackets.map(({ type, critical, body }) => {
|
|
15657
|
+
return writeSubPacket(type, critical, body);
|
|
14834
15658
|
});
|
|
14835
15659
|
|
|
14836
15660
|
const result = util.concat(arr);
|
|
@@ -14839,7 +15663,7 @@ class SignaturePacket {
|
|
|
14839
15663
|
return util.concat([length, result]);
|
|
14840
15664
|
}
|
|
14841
15665
|
|
|
14842
|
-
//
|
|
15666
|
+
// Signature subpackets
|
|
14843
15667
|
readSubPacket(bytes, hashed = true) {
|
|
14844
15668
|
let mypos = 0;
|
|
14845
15669
|
|
|
@@ -14847,15 +15671,19 @@ class SignaturePacket {
|
|
|
14847
15671
|
const critical = !!(bytes[mypos] & 0x80);
|
|
14848
15672
|
const type = bytes[mypos] & 0x7F;
|
|
14849
15673
|
|
|
15674
|
+
mypos++;
|
|
15675
|
+
|
|
14850
15676
|
if (!hashed) {
|
|
14851
|
-
this.unhashedSubpackets.push(
|
|
15677
|
+
this.unhashedSubpackets.push({
|
|
15678
|
+
type,
|
|
15679
|
+
critical,
|
|
15680
|
+
body: bytes.subarray(mypos, bytes.length)
|
|
15681
|
+
});
|
|
14852
15682
|
if (!allowedUnhashedSubpackets.has(type)) {
|
|
14853
15683
|
return;
|
|
14854
15684
|
}
|
|
14855
15685
|
}
|
|
14856
15686
|
|
|
14857
|
-
mypos++;
|
|
14858
|
-
|
|
14859
15687
|
// subpacket type
|
|
14860
15688
|
switch (type) {
|
|
14861
15689
|
case enums.signatureSubpacket.signatureCreationTime:
|
|
@@ -15027,14 +15855,13 @@ class SignaturePacket {
|
|
|
15027
15855
|
this.preferredCipherSuites.push([bytes[i], bytes[i + 1]]);
|
|
15028
15856
|
}
|
|
15029
15857
|
break;
|
|
15030
|
-
default:
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
}
|
|
15858
|
+
default:
|
|
15859
|
+
this.unknownSubpackets.push({
|
|
15860
|
+
type,
|
|
15861
|
+
critical,
|
|
15862
|
+
body: bytes.subarray(mypos, bytes.length)
|
|
15863
|
+
});
|
|
15864
|
+
break;
|
|
15038
15865
|
}
|
|
15039
15866
|
}
|
|
15040
15867
|
|
|
@@ -15234,6 +16061,11 @@ class SignaturePacket {
|
|
|
15234
16061
|
[enums.signature.binary, enums.signature.text].includes(this.signatureType)) {
|
|
15235
16062
|
throw new Error('Insecure message hash algorithm: ' + enums.read(enums.hash, this.hashAlgorithm).toUpperCase());
|
|
15236
16063
|
}
|
|
16064
|
+
this.unknownSubpackets.forEach(({ type, critical }) => {
|
|
16065
|
+
if (critical) {
|
|
16066
|
+
throw new Error(`Unknown critical signature subpacket type ${type}`);
|
|
16067
|
+
}
|
|
16068
|
+
});
|
|
15237
16069
|
this.rawNotations.forEach(({ name, critical }) => {
|
|
15238
16070
|
if (critical && (config$1.knownNotations.indexOf(name) < 0)) {
|
|
15239
16071
|
throw new Error(`Unknown critical notation: ${name}`);
|
|
@@ -16533,10 +17365,11 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
16533
17365
|
// No symmetric encryption algorithm identifier is passed to the public-key algorithm for a
|
|
16534
17366
|
// v6 PKESK packet, as it is included in the v2 SEIPD packet.
|
|
16535
17367
|
const sessionKeyAlgorithm = this.version === 3 ? this.sessionKeyAlgorithm : null;
|
|
17368
|
+
const fingerprint = key.version === 5 ? key.getFingerprintBytes().subarray(0, 20) : key.getFingerprintBytes();
|
|
16536
17369
|
const encoded = encodeSessionKey(this.version, algo, sessionKeyAlgorithm, this.sessionKey);
|
|
16537
17370
|
const privateParams = algo === enums.publicKey.aead ? key.privateParams : null;
|
|
16538
17371
|
this.encrypted = await mod$1.publicKeyEncrypt(
|
|
16539
|
-
algo, sessionKeyAlgorithm, key.publicParams, privateParams, encoded,
|
|
17372
|
+
algo, sessionKeyAlgorithm, key.publicParams, privateParams, encoded, fingerprint);
|
|
16540
17373
|
}
|
|
16541
17374
|
|
|
16542
17375
|
/**
|
|
@@ -16556,7 +17389,8 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
16556
17389
|
const randomPayload = randomSessionKey ?
|
|
16557
17390
|
encodeSessionKey(this.version, this.publicKeyAlgorithm, randomSessionKey.sessionKeyAlgorithm, randomSessionKey.sessionKey) :
|
|
16558
17391
|
null;
|
|
16559
|
-
const
|
|
17392
|
+
const fingerprint = key.version === 5 ? key.getFingerprintBytes().subarray(0, 20) : key.getFingerprintBytes();
|
|
17393
|
+
const decryptedData = await mod$1.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, fingerprint, randomPayload);
|
|
16560
17394
|
|
|
16561
17395
|
const { sessionKey, sessionKeyAlgorithm } = decodeSessionKey(this.version, this.publicKeyAlgorithm, decryptedData, randomSessionKey);
|
|
16562
17396
|
|
|
@@ -16961,10 +17795,13 @@ class PublicKeyPacket {
|
|
|
16961
17795
|
* @returns {Object} This object with attributes set by the parser
|
|
16962
17796
|
* @async
|
|
16963
17797
|
*/
|
|
16964
|
-
async read(bytes) {
|
|
17798
|
+
async read(bytes, config$1 = config) {
|
|
16965
17799
|
let pos = 0;
|
|
16966
17800
|
// A one-octet version number (4, 5 or 6).
|
|
16967
17801
|
this.version = bytes[pos++];
|
|
17802
|
+
if (this.version === 5 && !config$1.enableParsingV5Entities) {
|
|
17803
|
+
throw new UnsupportedError('Support for parsing v5 entities is disabled; turn on `config.enableParsingV5Entities` if needed');
|
|
17804
|
+
}
|
|
16968
17805
|
|
|
16969
17806
|
if (this.version === 4 || this.version === 5 || this.version === 6) {
|
|
16970
17807
|
// - A four-octet number denoting the time that the key was created.
|
|
@@ -17556,7 +18393,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17556
18393
|
*/
|
|
17557
18394
|
async read(bytes, config$1 = config) {
|
|
17558
18395
|
// - A Public-Key or Public-Subkey packet, as described above.
|
|
17559
|
-
let i = await this.readPublicKey(bytes);
|
|
18396
|
+
let i = await this.readPublicKey(bytes, config$1);
|
|
17560
18397
|
const startOfSecretKeyData = i;
|
|
17561
18398
|
|
|
17562
18399
|
// - One octet indicating string-to-key usage conventions. Zero
|
|
@@ -17846,13 +18683,13 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17846
18683
|
|
|
17847
18684
|
if (config$1.aeadProtect) {
|
|
17848
18685
|
this.s2kUsage = 253;
|
|
17849
|
-
this.aead =
|
|
18686
|
+
this.aead = config$1.preferredAEADAlgorithm;
|
|
17850
18687
|
const mode = mod$1.getAEADMode(this.aead);
|
|
17851
18688
|
this.isLegacyAEAD = this.version === 5; // v4 is always re-encrypted with standard format instead.
|
|
17852
18689
|
this.usedModernAEAD = !this.isLegacyAEAD; // legacy AEAD does not guarantee integrity of public key material
|
|
17853
18690
|
|
|
17854
18691
|
const serializedPacketTag = writeTag(this.constructor.tag);
|
|
17855
|
-
const key = await produceEncryptionKey(this.version, this.s2k, passphrase, this.symmetric, this.aead, serializedPacketTag);
|
|
18692
|
+
const key = await produceEncryptionKey(this.version, this.s2k, passphrase, this.symmetric, this.aead, serializedPacketTag, this.isLegacyAEAD);
|
|
17856
18693
|
|
|
17857
18694
|
const modeInstance = await mode(this.symmetric, key);
|
|
17858
18695
|
this.iv = this.isLegacyAEAD ? mod$1.random.getRandomBytes(blockSize) : mod$1.random.getRandomBytes(mode.ivLength);
|
|
@@ -18022,6 +18859,12 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
18022
18859
|
* @returns encryption key
|
|
18023
18860
|
*/
|
|
18024
18861
|
async function produceEncryptionKey(keyVersion, s2k, passphrase, cipherAlgo, aeadMode, serializedPacketTag, isLegacyAEAD) {
|
|
18862
|
+
if (s2k.type === 'argon2' && !aeadMode) {
|
|
18863
|
+
throw new Error('Using Argon2 S2K without AEAD is not allowed');
|
|
18864
|
+
}
|
|
18865
|
+
if (s2k.type === 'simple' && keyVersion === 6) {
|
|
18866
|
+
throw new Error('Using Simple S2K with version 6 keys is not allowed');
|
|
18867
|
+
}
|
|
18025
18868
|
const { keySize } = mod$1.getCipherParams(cipherAlgo);
|
|
18026
18869
|
const derivedKey = await s2k.produceKey(passphrase, keySize);
|
|
18027
18870
|
if (!aeadMode || keyVersion === 5 || isLegacyAEAD) {
|
|
@@ -18400,6 +19243,8 @@ async function generateSecretKey(options, config) {
|
|
|
18400
19243
|
* Returns the valid and non-expired signature that has the latest creation date, while ignoring signatures created in the future.
|
|
18401
19244
|
* @param {Array<SignaturePacket>} signatures - List of signatures
|
|
18402
19245
|
* @param {PublicKeyPacket|PublicSubkeyPacket} publicKey - Public key packet to verify the signature
|
|
19246
|
+
* @param {module:enums.signature} signatureType - Signature type to determine how to hash the data (NB: for userID signatures,
|
|
19247
|
+
* `enums.signatures.certGeneric` should be given regardless of the actual trust level)
|
|
18403
19248
|
* @param {Date} date - Use the given date instead of the current time
|
|
18404
19249
|
* @param {Object} config - full configuration
|
|
18405
19250
|
* @returns {Promise<SignaturePacket>} The latest valid signature.
|
|
@@ -18648,8 +19493,14 @@ async function isDataRevoked(primaryKey, signatureType, dataToVerify, revocation
|
|
|
18648
19493
|
// `verifyAllCertifications`.)
|
|
18649
19494
|
!signature || revocationSignature.issuerKeyID.equals(signature.issuerKeyID)
|
|
18650
19495
|
) {
|
|
19496
|
+
const isHardRevocation = ![
|
|
19497
|
+
enums.reasonForRevocation.keyRetired,
|
|
19498
|
+
enums.reasonForRevocation.keySuperseded,
|
|
19499
|
+
enums.reasonForRevocation.userIDInvalid
|
|
19500
|
+
].includes(revocationSignature.reasonForRevocationFlag);
|
|
19501
|
+
|
|
18651
19502
|
await revocationSignature.verify(
|
|
18652
|
-
key, signatureType, dataToVerify, date, false, config
|
|
19503
|
+
key, signatureType, dataToVerify, isHardRevocation ? null : date, false, config
|
|
18653
19504
|
);
|
|
18654
19505
|
|
|
18655
19506
|
// TODO get an identifier of the revoked object instead
|
|
@@ -20636,7 +21487,7 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
|
|
|
20636
21487
|
key: secretKeyPacket
|
|
20637
21488
|
};
|
|
20638
21489
|
const signatureProperties = secretKeyPacket.version !== 6 ? getKeySignatureProperties() : {};
|
|
20639
|
-
signatureProperties.signatureType = enums.signature.
|
|
21490
|
+
signatureProperties.signatureType = enums.signature.certPositive;
|
|
20640
21491
|
if (index === 0) {
|
|
20641
21492
|
signatureProperties.isPrimaryUserID = true;
|
|
20642
21493
|
}
|
|
@@ -22461,7 +23312,7 @@ async function verify({ message, verificationKeys, expectSigned = false, format
|
|
|
22461
23312
|
result.signatures = await message.verify(verificationKeys, date, config$1);
|
|
22462
23313
|
}
|
|
22463
23314
|
result.data = format === 'binary' ? message.getLiteralData() : message.getText();
|
|
22464
|
-
if (message.fromStream) linkStreams(result, message);
|
|
23315
|
+
if (message.fromStream && !signature) linkStreams(result, message);
|
|
22465
23316
|
if (expectSigned) {
|
|
22466
23317
|
if (result.signatures.length === 0) {
|
|
22467
23318
|
throw new Error('Message is not signed');
|