@protontech/openpgp 6.0.0 → 6.0.2-patch.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 +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 +11 -11
- package/dist/lightweight/noble_curves.min.mjs.map +1 -1
- package/dist/lightweight/noble_curves.mjs +260 -158
- package/dist/lightweight/noble_hashes.min.mjs +2 -2
- package/dist/lightweight/noble_hashes.min.mjs.map +1 -1
- package/dist/lightweight/noble_hashes.mjs +3 -2
- package/dist/lightweight/noble_post_quantum.min.mjs +5 -0
- package/dist/lightweight/noble_post_quantum.min.mjs.map +1 -0
- package/dist/lightweight/noble_post_quantum.mjs +1002 -0
- package/dist/lightweight/openpgp.min.mjs +4 -4
- package/dist/lightweight/openpgp.min.mjs.map +1 -1
- package/dist/lightweight/openpgp.mjs +626 -111
- package/dist/lightweight/seek-bzip.min.mjs +1 -1
- package/dist/lightweight/seek-bzip.mjs +1 -1
- package/dist/lightweight/sha3.min.mjs +3 -3
- package/dist/lightweight/sha3.min.mjs.map +1 -1
- package/dist/lightweight/sha3.mjs +27 -456
- package/dist/lightweight/sha512.min.mjs +3 -0
- package/dist/lightweight/sha512.min.mjs.map +1 -0
- package/dist/lightweight/sha512.mjs +436 -0
- package/dist/node/openpgp.cjs +2247 -621
- package/dist/node/openpgp.min.cjs +16 -14
- package/dist/node/openpgp.min.cjs.map +1 -1
- package/dist/node/openpgp.min.mjs +16 -14
- package/dist/node/openpgp.min.mjs.map +1 -1
- package/dist/node/openpgp.mjs +2247 -621
- package/dist/openpgp.js +2247 -621
- package/dist/openpgp.min.js +16 -14
- package/dist/openpgp.min.js.map +1 -1
- package/dist/openpgp.min.mjs +16 -14
- package/dist/openpgp.min.mjs.map +1 -1
- package/dist/openpgp.mjs +2247 -621
- package/openpgp.d.ts +7 -11
- package/package.json +5 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! OpenPGP.js v6.0.0 - 2024-11-
|
|
1
|
+
/*! OpenPGP.js v6.0.2-patch.0 - 2024-11-27 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
|
|
2
2
|
const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
3
3
|
|
|
4
4
|
const doneWritingPromise = Symbol('doneWritingPromise');
|
|
@@ -1047,6 +1047,11 @@ var enums = {
|
|
|
1047
1047
|
ed25519: 27,
|
|
1048
1048
|
/** Ed448 (Sign only) */
|
|
1049
1049
|
ed448: 28,
|
|
1050
|
+
/** Post-quantum ML-KEM-768 + X25519 (Encrypt only) */
|
|
1051
|
+
pqc_mlkem_x25519: 105,
|
|
1052
|
+
/** Post-quantum ML-DSA-64 + Ed25519 (Sign only) */
|
|
1053
|
+
pqc_mldsa_ed25519: 107,
|
|
1054
|
+
|
|
1050
1055
|
/** Persistent symmetric keys: encryption algorithm */
|
|
1051
1056
|
aead: 100,
|
|
1052
1057
|
/** Persistent symmetric keys: authentication algorithm */
|
|
@@ -1682,7 +1687,7 @@ var config = {
|
|
|
1682
1687
|
* @memberof module:config
|
|
1683
1688
|
* @property {String} versionString A version string to be included in armored messages
|
|
1684
1689
|
*/
|
|
1685
|
-
versionString: 'OpenPGP.js 6.0.0',
|
|
1690
|
+
versionString: 'OpenPGP.js 6.0.2-patch.0',
|
|
1686
1691
|
/**
|
|
1687
1692
|
* @memberof module:config
|
|
1688
1693
|
* @property {String} commentString A comment string to be included in armored messages
|
|
@@ -3823,7 +3828,7 @@ function applySbox(sbox2, s0, s1, s2, s3) {
|
|
|
3823
3828
|
return (sbox2[(s0 & 0xff) | (s1 & 0xff00)] |
|
|
3824
3829
|
(sbox2[((s2 >>> 16) & 0xff) | ((s3 >>> 16) & 0xff00)] << 16));
|
|
3825
3830
|
}
|
|
3826
|
-
function encrypt$
|
|
3831
|
+
function encrypt$7(xk, s0, s1, s2, s3) {
|
|
3827
3832
|
const { sbox2, T01, T23 } = tableEncoding;
|
|
3828
3833
|
let k = 0;
|
|
3829
3834
|
(s0 ^= xk[k++]), (s1 ^= xk[k++]), (s2 ^= xk[k++]), (s3 ^= xk[k++]);
|
|
@@ -3843,7 +3848,7 @@ function encrypt$6(xk, s0, s1, s2, s3) {
|
|
|
3843
3848
|
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
3844
3849
|
}
|
|
3845
3850
|
// Can't be merged with encrypt: arg positions for apply0123 / applySbox are different
|
|
3846
|
-
function decrypt$
|
|
3851
|
+
function decrypt$7(xk, s0, s1, s2, s3) {
|
|
3847
3852
|
const { sbox2, T01, T23 } = tableDecoding;
|
|
3848
3853
|
let k = 0;
|
|
3849
3854
|
(s0 ^= xk[k++]), (s1 ^= xk[k++]), (s2 ^= xk[k++]), (s3 ^= xk[k++]);
|
|
@@ -3881,7 +3886,7 @@ function ctrCounter(xk, nonce, src, dst) {
|
|
|
3881
3886
|
const ctr = nonce;
|
|
3882
3887
|
const c32 = u32$1(ctr);
|
|
3883
3888
|
// Fill block (empty, ctr=0)
|
|
3884
|
-
let { s0, s1, s2, s3 } = encrypt$
|
|
3889
|
+
let { s0, s1, s2, s3 } = encrypt$7(xk, c32[0], c32[1], c32[2], c32[3]);
|
|
3885
3890
|
const src32 = u32$1(src);
|
|
3886
3891
|
const dst32 = u32$1(dst);
|
|
3887
3892
|
// process blocks
|
|
@@ -3897,7 +3902,7 @@ function ctrCounter(xk, nonce, src, dst) {
|
|
|
3897
3902
|
ctr[i] = carry & 0xff;
|
|
3898
3903
|
carry >>>= 8;
|
|
3899
3904
|
}
|
|
3900
|
-
({ s0, s1, s2, s3 } = encrypt$
|
|
3905
|
+
({ s0, s1, s2, s3 } = encrypt$7(xk, c32[0], c32[1], c32[2], c32[3]));
|
|
3901
3906
|
}
|
|
3902
3907
|
// leftovers (less than block)
|
|
3903
3908
|
// It's possible to handle > u32 fast, but is it worth it?
|
|
@@ -3927,7 +3932,7 @@ function ctr32(xk, isLE, nonce, src, dst) {
|
|
|
3927
3932
|
const srcLen = src.length;
|
|
3928
3933
|
// Fill block (empty, ctr=0)
|
|
3929
3934
|
let ctrNum = view.getUint32(ctrPos, isLE); // read current counter value
|
|
3930
|
-
let { s0, s1, s2, s3 } = encrypt$
|
|
3935
|
+
let { s0, s1, s2, s3 } = encrypt$7(xk, c32[0], c32[1], c32[2], c32[3]);
|
|
3931
3936
|
// process blocks
|
|
3932
3937
|
for (let i = 0; i + 4 <= src32.length; i += 4) {
|
|
3933
3938
|
dst32[i + 0] = src32[i + 0] ^ s0;
|
|
@@ -3936,7 +3941,7 @@ function ctr32(xk, isLE, nonce, src, dst) {
|
|
|
3936
3941
|
dst32[i + 3] = src32[i + 3] ^ s3;
|
|
3937
3942
|
ctrNum = (ctrNum + 1) >>> 0; // u32 wrap
|
|
3938
3943
|
view.setUint32(ctrPos, ctrNum, isLE);
|
|
3939
|
-
({ s0, s1, s2, s3 } = encrypt$
|
|
3944
|
+
({ s0, s1, s2, s3 } = encrypt$7(xk, c32[0], c32[1], c32[2], c32[3]));
|
|
3940
3945
|
}
|
|
3941
3946
|
// leftovers (less than a block)
|
|
3942
3947
|
const start = BLOCK_SIZE * Math.floor(src32.length / BLOCK_SIZE32);
|
|
@@ -4048,13 +4053,13 @@ const cbc = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cbc(key, iv,
|
|
|
4048
4053
|
let i = 0;
|
|
4049
4054
|
for (; i + 4 <= b.length;) {
|
|
4050
4055
|
(s0 ^= b[i + 0]), (s1 ^= b[i + 1]), (s2 ^= b[i + 2]), (s3 ^= b[i + 3]);
|
|
4051
|
-
({ s0, s1, s2, s3 } = encrypt$
|
|
4056
|
+
({ s0, s1, s2, s3 } = encrypt$7(xk, s0, s1, s2, s3));
|
|
4052
4057
|
(o[i++] = s0), (o[i++] = s1), (o[i++] = s2), (o[i++] = s3);
|
|
4053
4058
|
}
|
|
4054
4059
|
if (pcks5) {
|
|
4055
4060
|
const tmp32 = padPCKS(plaintext.subarray(i * 4));
|
|
4056
4061
|
(s0 ^= tmp32[0]), (s1 ^= tmp32[1]), (s2 ^= tmp32[2]), (s3 ^= tmp32[3]);
|
|
4057
|
-
({ s0, s1, s2, s3 } = encrypt$
|
|
4062
|
+
({ s0, s1, s2, s3 } = encrypt$7(xk, s0, s1, s2, s3));
|
|
4058
4063
|
(o[i++] = s0), (o[i++] = s1), (o[i++] = s2), (o[i++] = s3);
|
|
4059
4064
|
}
|
|
4060
4065
|
clean(...toClean);
|
|
@@ -4079,7 +4084,7 @@ const cbc = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cbc(key, iv,
|
|
|
4079
4084
|
// prettier-ignore
|
|
4080
4085
|
const ps0 = s0, ps1 = s1, ps2 = s2, ps3 = s3;
|
|
4081
4086
|
(s0 = b[i + 0]), (s1 = b[i + 1]), (s2 = b[i + 2]), (s3 = b[i + 3]);
|
|
4082
|
-
const { s0: o0, s1: o1, s2: o2, s3: o3 } = decrypt$
|
|
4087
|
+
const { s0: o0, s1: o1, s2: o2, s3: o3 } = decrypt$7(xk, s0, s1, s2, s3);
|
|
4083
4088
|
(o[i++] = o0 ^ ps0), (o[i++] = o1 ^ ps1), (o[i++] = o2 ^ ps2), (o[i++] = o3 ^ ps3);
|
|
4084
4089
|
}
|
|
4085
4090
|
clean(...toClean);
|
|
@@ -4112,7 +4117,7 @@ const cfb$1 = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cfb(key, i
|
|
|
4112
4117
|
// prettier-ignore
|
|
4113
4118
|
let s0 = n32[0], s1 = n32[1], s2 = n32[2], s3 = n32[3];
|
|
4114
4119
|
for (let i = 0; i + 4 <= src32.length;) {
|
|
4115
|
-
const { s0: e0, s1: e1, s2: e2, s3: e3 } = encrypt$
|
|
4120
|
+
const { s0: e0, s1: e1, s2: e2, s3: e3 } = encrypt$7(xk, s0, s1, s2, s3);
|
|
4116
4121
|
dst32[i + 0] = src32[i + 0] ^ e0;
|
|
4117
4122
|
dst32[i + 1] = src32[i + 1] ^ e1;
|
|
4118
4123
|
dst32[i + 2] = src32[i + 2] ^ e2;
|
|
@@ -4122,7 +4127,7 @@ const cfb$1 = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cfb(key, i
|
|
|
4122
4127
|
// leftovers (less than block)
|
|
4123
4128
|
const start = BLOCK_SIZE * Math.floor(src32.length / BLOCK_SIZE32);
|
|
4124
4129
|
if (start < srcLen) {
|
|
4125
|
-
({ s0, s1, s2, s3 } = encrypt$
|
|
4130
|
+
({ s0, s1, s2, s3 } = encrypt$7(xk, s0, s1, s2, s3));
|
|
4126
4131
|
const buf = u8$1(new Uint32Array([s0, s1, s2, s3]));
|
|
4127
4132
|
for (let i = start, pos = 0; i < srcLen; i++, pos++)
|
|
4128
4133
|
dst[i] = src[i] ^ buf[pos];
|
|
@@ -4243,7 +4248,7 @@ function encryptBlock(xk, block) {
|
|
|
4243
4248
|
if (!isBytes32(xk))
|
|
4244
4249
|
throw new Error('_encryptBlock accepts result of expandKeyLE');
|
|
4245
4250
|
const b32 = u32$1(block);
|
|
4246
|
-
let { s0, s1, s2, s3 } = encrypt$
|
|
4251
|
+
let { s0, s1, s2, s3 } = encrypt$7(xk, b32[0], b32[1], b32[2], b32[3]);
|
|
4247
4252
|
(b32[0] = s0), (b32[1] = s1), (b32[2] = s2), (b32[3] = s3);
|
|
4248
4253
|
return block;
|
|
4249
4254
|
}
|
|
@@ -4252,7 +4257,7 @@ function decryptBlock(xk, block) {
|
|
|
4252
4257
|
if (!isBytes32(xk))
|
|
4253
4258
|
throw new Error('_decryptBlock accepts result of expandKeyLE');
|
|
4254
4259
|
const b32 = u32$1(block);
|
|
4255
|
-
let { s0, s1, s2, s3 } = decrypt$
|
|
4260
|
+
let { s0, s1, s2, s3 } = decrypt$7(xk, b32[0], b32[1], b32[2], b32[3]);
|
|
4256
4261
|
(b32[0] = s0), (b32[1] = s1), (b32[2] = s2), (b32[3] = s3);
|
|
4257
4262
|
return block;
|
|
4258
4263
|
}
|
|
@@ -4293,7 +4298,7 @@ const AESW = {
|
|
|
4293
4298
|
let a0 = o32[0], a1 = o32[1]; // A
|
|
4294
4299
|
for (let j = 0, ctr = 1; j < 6; j++) {
|
|
4295
4300
|
for (let pos = 2; pos < o32.length; pos += 2, ctr++) {
|
|
4296
|
-
const { s0, s1, s2, s3 } = encrypt$
|
|
4301
|
+
const { s0, s1, s2, s3 } = encrypt$7(xk, a0, a1, o32[pos], o32[pos + 1]);
|
|
4297
4302
|
// A = MSB(64, B) ^ t where t = (n*j)+i
|
|
4298
4303
|
(a0 = s0), (a1 = s1 ^ byteSwap(ctr)), (o32[pos] = s2), (o32[pos + 1] = s3);
|
|
4299
4304
|
}
|
|
@@ -4316,7 +4321,7 @@ const AESW = {
|
|
|
4316
4321
|
for (let j = 0, ctr = chunks * 6; j < 6; j++) {
|
|
4317
4322
|
for (let pos = chunks * 2; pos >= 1; pos -= 2, ctr--) {
|
|
4318
4323
|
a1 ^= byteSwap(ctr);
|
|
4319
|
-
const { s0, s1, s2, s3 } = decrypt$
|
|
4324
|
+
const { s0, s1, s2, s3 } = decrypt$7(xk, a0, a1, o32[pos], o32[pos + 1]);
|
|
4320
4325
|
(a0 = s0), (a1 = s1), (o32[pos] = s2), (o32[pos + 1] = s3);
|
|
4321
4326
|
}
|
|
4322
4327
|
}
|
|
@@ -4363,8 +4368,8 @@ const aeskw = wrapCipher({ blockSize: 8 }, (kek) => ({
|
|
|
4363
4368
|
const unsafe = {
|
|
4364
4369
|
expandKeyLE,
|
|
4365
4370
|
expandKeyDecLE,
|
|
4366
|
-
encrypt: encrypt$
|
|
4367
|
-
decrypt: decrypt$
|
|
4371
|
+
encrypt: encrypt$7,
|
|
4372
|
+
decrypt: decrypt$7,
|
|
4368
4373
|
encryptBlock,
|
|
4369
4374
|
decryptBlock,
|
|
4370
4375
|
ctrCounter,
|
|
@@ -4398,7 +4403,7 @@ const nodeAlgos = {
|
|
|
4398
4403
|
* @param {Object} config - full configuration, defaults to openpgp.config
|
|
4399
4404
|
* @returns MaybeStream<Uint8Array>
|
|
4400
4405
|
*/
|
|
4401
|
-
async function encrypt$
|
|
4406
|
+
async function encrypt$6(algo, key, plaintext, iv, config) {
|
|
4402
4407
|
const algoName = enums.read(enums.symmetric, algo);
|
|
4403
4408
|
if (util.getNodeCrypto() && nodeAlgos[algoName]) { // Node crypto library.
|
|
4404
4409
|
return nodeEncrypt$1(algo, key, plaintext, iv);
|
|
@@ -4441,7 +4446,7 @@ async function encrypt$5(algo, key, plaintext, iv, config) {
|
|
|
4441
4446
|
* @param {Uint8Array} iv
|
|
4442
4447
|
* @returns MaybeStream<Uint8Array>
|
|
4443
4448
|
*/
|
|
4444
|
-
async function decrypt$
|
|
4449
|
+
async function decrypt$6(algo, key, ciphertext, iv) {
|
|
4445
4450
|
const algoName = enums.read(enums.symmetric, algo);
|
|
4446
4451
|
if (nodeCrypto$a && nodeAlgos[algoName]) { // Node crypto library.
|
|
4447
4452
|
return nodeDecrypt$1(algo, key, ciphertext, iv);
|
|
@@ -4716,8 +4721,8 @@ function nodeDecrypt$1(algo, key, ct, iv) {
|
|
|
4716
4721
|
|
|
4717
4722
|
var cfb = /*#__PURE__*/Object.freeze({
|
|
4718
4723
|
__proto__: null,
|
|
4719
|
-
decrypt: decrypt$
|
|
4720
|
-
encrypt: encrypt$
|
|
4724
|
+
decrypt: decrypt$6,
|
|
4725
|
+
encrypt: encrypt$6
|
|
4721
4726
|
});
|
|
4722
4727
|
|
|
4723
4728
|
/**
|
|
@@ -6095,7 +6100,7 @@ const _1n$3 = BigInt(1);
|
|
|
6095
6100
|
* @returns {Promise<Uint8Array>} RSA Signature.
|
|
6096
6101
|
* @async
|
|
6097
6102
|
*/
|
|
6098
|
-
async function sign$
|
|
6103
|
+
async function sign$a(hashAlgo, data, n, e, d, p, q, u, hashed) {
|
|
6099
6104
|
if (hash.getHashByteLength(hashAlgo) >= n.length) {
|
|
6100
6105
|
// Throw here instead of `emsaEncode` below, to provide a clearer and consistent error
|
|
6101
6106
|
// e.g. if a 512-bit RSA key is used with a SHA-512 digest.
|
|
@@ -6129,7 +6134,7 @@ async function sign$7(hashAlgo, data, n, e, d, p, q, u, hashed) {
|
|
|
6129
6134
|
* @returns {Boolean}
|
|
6130
6135
|
* @async
|
|
6131
6136
|
*/
|
|
6132
|
-
async function verify$
|
|
6137
|
+
async function verify$b(hashAlgo, data, s, n, e, hashed) {
|
|
6133
6138
|
if (data && !util.isStream(data)) {
|
|
6134
6139
|
if (util.getWebCrypto()) {
|
|
6135
6140
|
try {
|
|
@@ -6152,7 +6157,7 @@ async function verify$8(hashAlgo, data, s, n, e, hashed) {
|
|
|
6152
6157
|
* @returns {Promise<Uint8Array>} RSA Ciphertext.
|
|
6153
6158
|
* @async
|
|
6154
6159
|
*/
|
|
6155
|
-
async function encrypt$
|
|
6160
|
+
async function encrypt$5(data, n, e) {
|
|
6156
6161
|
if (util.getNodeCrypto()) {
|
|
6157
6162
|
return nodeEncrypt(data, n, e);
|
|
6158
6163
|
}
|
|
@@ -6174,7 +6179,7 @@ async function encrypt$4(data, n, e) {
|
|
|
6174
6179
|
* @throws {Error} on decryption error, unless `randomPayload` is given
|
|
6175
6180
|
* @async
|
|
6176
6181
|
*/
|
|
6177
|
-
async function decrypt$
|
|
6182
|
+
async function decrypt$5(data, n, e, d, p, q, u, randomPayload) {
|
|
6178
6183
|
// Node v18.19.1, 20.11.1 and 21.6.2 have disabled support for PKCS#1 decryption,
|
|
6179
6184
|
// and we want to avoid checking the error type to decide if the random payload
|
|
6180
6185
|
// should indeed be returned.
|
|
@@ -6201,7 +6206,7 @@ async function decrypt$4(data, n, e, d, p, q, u, randomPayload) {
|
|
|
6201
6206
|
* RSA private prime p, RSA private prime q, u = p ** -1 mod q
|
|
6202
6207
|
* @async
|
|
6203
6208
|
*/
|
|
6204
|
-
async function generate$
|
|
6209
|
+
async function generate$b(bits, e) {
|
|
6205
6210
|
e = BigInt(e);
|
|
6206
6211
|
|
|
6207
6212
|
// Native RSA keygen using Web Crypto
|
|
@@ -6281,7 +6286,7 @@ async function generate$5(bits, e) {
|
|
|
6281
6286
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
6282
6287
|
* @async
|
|
6283
6288
|
*/
|
|
6284
|
-
async function validateParams$
|
|
6289
|
+
async function validateParams$e(n, e, d, p, q, u) {
|
|
6285
6290
|
n = uint8ArrayToBigInt(n);
|
|
6286
6291
|
p = uint8ArrayToBigInt(p);
|
|
6287
6292
|
q = uint8ArrayToBigInt(q);
|
|
@@ -6511,12 +6516,12 @@ function jwkToPrivate(jwk, e) {
|
|
|
6511
6516
|
|
|
6512
6517
|
var rsa = /*#__PURE__*/Object.freeze({
|
|
6513
6518
|
__proto__: null,
|
|
6514
|
-
decrypt: decrypt$
|
|
6515
|
-
encrypt: encrypt$
|
|
6516
|
-
generate: generate$
|
|
6517
|
-
sign: sign$
|
|
6518
|
-
validateParams: validateParams$
|
|
6519
|
-
verify: verify$
|
|
6519
|
+
decrypt: decrypt$5,
|
|
6520
|
+
encrypt: encrypt$5,
|
|
6521
|
+
generate: generate$b,
|
|
6522
|
+
sign: sign$a,
|
|
6523
|
+
validateParams: validateParams$e,
|
|
6524
|
+
verify: verify$b
|
|
6520
6525
|
});
|
|
6521
6526
|
|
|
6522
6527
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
@@ -6549,7 +6554,7 @@ const _1n$2 = BigInt(1);
|
|
|
6549
6554
|
* @returns {Promise<{ c1: Uint8Array, c2: Uint8Array }>}
|
|
6550
6555
|
* @async
|
|
6551
6556
|
*/
|
|
6552
|
-
async function encrypt$
|
|
6557
|
+
async function encrypt$4(data, p, g, y) {
|
|
6553
6558
|
p = uint8ArrayToBigInt(p);
|
|
6554
6559
|
g = uint8ArrayToBigInt(g);
|
|
6555
6560
|
y = uint8ArrayToBigInt(y);
|
|
@@ -6578,7 +6583,7 @@ async function encrypt$3(data, p, g, y) {
|
|
|
6578
6583
|
* @throws {Error} on decryption error, unless `randomPayload` is given
|
|
6579
6584
|
* @async
|
|
6580
6585
|
*/
|
|
6581
|
-
async function decrypt$
|
|
6586
|
+
async function decrypt$4(c1, c2, p, x, randomPayload) {
|
|
6582
6587
|
c1 = uint8ArrayToBigInt(c1);
|
|
6583
6588
|
c2 = uint8ArrayToBigInt(c2);
|
|
6584
6589
|
p = uint8ArrayToBigInt(p);
|
|
@@ -6597,7 +6602,7 @@ async function decrypt$3(c1, c2, p, x, randomPayload) {
|
|
|
6597
6602
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
6598
6603
|
* @async
|
|
6599
6604
|
*/
|
|
6600
|
-
async function validateParams$
|
|
6605
|
+
async function validateParams$d(p, g, y, x) {
|
|
6601
6606
|
p = uint8ArrayToBigInt(p);
|
|
6602
6607
|
g = uint8ArrayToBigInt(g);
|
|
6603
6608
|
y = uint8ArrayToBigInt(y);
|
|
@@ -6658,9 +6663,9 @@ async function validateParams$7(p, g, y, x) {
|
|
|
6658
6663
|
|
|
6659
6664
|
var elgamal = /*#__PURE__*/Object.freeze({
|
|
6660
6665
|
__proto__: null,
|
|
6661
|
-
decrypt: decrypt$
|
|
6662
|
-
encrypt: encrypt$
|
|
6663
|
-
validateParams: validateParams$
|
|
6666
|
+
decrypt: decrypt$4,
|
|
6667
|
+
encrypt: encrypt$4,
|
|
6668
|
+
validateParams: validateParams$d
|
|
6664
6669
|
});
|
|
6665
6670
|
|
|
6666
6671
|
// declare const globalThis: Record<string, any> | undefined;
|
|
@@ -9141,7 +9146,7 @@ function finishVerification(publicKey, r, SB, hashed) {
|
|
|
9141
9146
|
const RkA = ExtendedPoint.fromAffine(r).add(kA);
|
|
9142
9147
|
return RkA.subtract(SB).multiplyUnsafe(CURVE.h).equals(ExtendedPoint.ZERO);
|
|
9143
9148
|
}
|
|
9144
|
-
async function verify$
|
|
9149
|
+
async function verify$a(sig, message, publicKey) {
|
|
9145
9150
|
const { r, SB, msg, pub } = prepareVerification(sig, message, publicKey);
|
|
9146
9151
|
const hashed = await utils.sha512(r.toRawBytes(), pub.toRawBytes(), msg);
|
|
9147
9152
|
return finishVerification(pub, r, SB, hashed);
|
|
@@ -9240,7 +9245,7 @@ Object.defineProperties(utils, {
|
|
|
9240
9245
|
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
9241
9246
|
* @returns {Promise<{ A: Uint8Array, seed: Uint8Array }>}
|
|
9242
9247
|
*/
|
|
9243
|
-
async function generate$
|
|
9248
|
+
async function generate$a(algo) {
|
|
9244
9249
|
switch (algo) {
|
|
9245
9250
|
case enums.publicKey.ed25519:
|
|
9246
9251
|
try {
|
|
@@ -9255,7 +9260,11 @@ async function generate$4(algo) {
|
|
|
9255
9260
|
seed: b64ToUint8Array(privateKey.d, true)
|
|
9256
9261
|
};
|
|
9257
9262
|
} catch (err) {
|
|
9258
|
-
if (
|
|
9263
|
+
if (
|
|
9264
|
+
err.name !== 'NotSupportedError' &&
|
|
9265
|
+
err.name !== 'OperationError' && // Temporary (hopefully) fix for WebKit on Linux
|
|
9266
|
+
err.name !== 'SyntaxError' // Temporary fix for Palemoon throwing 'SyntaxError'
|
|
9267
|
+
) {
|
|
9259
9268
|
throw err;
|
|
9260
9269
|
}
|
|
9261
9270
|
const seed = getRandomBytes(getPayloadSize$1(algo));
|
|
@@ -9287,7 +9296,7 @@ async function generate$4(algo) {
|
|
|
9287
9296
|
* }>} Signature of the message
|
|
9288
9297
|
* @async
|
|
9289
9298
|
*/
|
|
9290
|
-
async function sign$
|
|
9299
|
+
async function sign$9(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
9291
9300
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$2(algo))) {
|
|
9292
9301
|
// Enforce digest sizes:
|
|
9293
9302
|
// - Ed25519: https://www.rfc-editor.org/rfc/rfc9580.html#section-5.2.3.4-4
|
|
@@ -9307,7 +9316,7 @@ async function sign$6(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
9307
9316
|
|
|
9308
9317
|
return { RS: signature };
|
|
9309
9318
|
} catch (err) {
|
|
9310
|
-
if (err.name !== 'NotSupportedError') {
|
|
9319
|
+
if (err.name !== 'NotSupportedError' && err.name !== 'SyntaxError') { // Temporary fix for Palemoon throwing 'SyntaxError'
|
|
9311
9320
|
throw err;
|
|
9312
9321
|
}
|
|
9313
9322
|
const secretKey = util.concatUint8Array([privateKey, publicKey]);
|
|
@@ -9337,7 +9346,7 @@ async function sign$6(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
9337
9346
|
* @returns {Boolean}
|
|
9338
9347
|
* @async
|
|
9339
9348
|
*/
|
|
9340
|
-
async function verify$
|
|
9349
|
+
async function verify$9(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
9341
9350
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$2(algo))) {
|
|
9342
9351
|
// Enforce digest sizes:
|
|
9343
9352
|
// - Ed25519: https://www.rfc-editor.org/rfc/rfc9580.html#section-5.2.3.4-4
|
|
@@ -9353,10 +9362,10 @@ async function verify$6(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
|
9353
9362
|
const verified = await webCrypto.verify('Ed25519', key, RS, hashed);
|
|
9354
9363
|
return verified;
|
|
9355
9364
|
} catch (err) {
|
|
9356
|
-
if (err.name !== 'NotSupportedError') {
|
|
9365
|
+
if (err.name !== 'NotSupportedError' && err.name !== 'SyntaxError') { // Temporary fix for Palemoon throwing 'SyntaxError'
|
|
9357
9366
|
throw err;
|
|
9358
9367
|
}
|
|
9359
|
-
return verify$
|
|
9368
|
+
return verify$a(RS, hashed, publicKey);
|
|
9360
9369
|
}
|
|
9361
9370
|
|
|
9362
9371
|
case enums.publicKey.ed448: {
|
|
@@ -9376,7 +9385,7 @@ async function verify$6(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
|
9376
9385
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
9377
9386
|
* @async
|
|
9378
9387
|
*/
|
|
9379
|
-
async function validateParams$
|
|
9388
|
+
async function validateParams$c(algo, A, seed) {
|
|
9380
9389
|
switch (algo) {
|
|
9381
9390
|
case enums.publicKey.ed25519: {
|
|
9382
9391
|
/**
|
|
@@ -9453,12 +9462,12 @@ const privateKeyToJWK = (algo, publicKey, privateKey) => {
|
|
|
9453
9462
|
|
|
9454
9463
|
var eddsa = /*#__PURE__*/Object.freeze({
|
|
9455
9464
|
__proto__: null,
|
|
9456
|
-
generate: generate$
|
|
9465
|
+
generate: generate$a,
|
|
9457
9466
|
getPayloadSize: getPayloadSize$1,
|
|
9458
9467
|
getPreferredHashAlgo: getPreferredHashAlgo$2,
|
|
9459
|
-
sign: sign$
|
|
9460
|
-
validateParams: validateParams$
|
|
9461
|
-
verify: verify$
|
|
9468
|
+
sign: sign$9,
|
|
9469
|
+
validateParams: validateParams$c,
|
|
9470
|
+
verify: verify$9
|
|
9462
9471
|
});
|
|
9463
9472
|
|
|
9464
9473
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -9589,7 +9598,7 @@ const HKDF_INFO = {
|
|
|
9589
9598
|
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
9590
9599
|
* @returns {Promise<{ A: Uint8Array, k: Uint8Array }>}
|
|
9591
9600
|
*/
|
|
9592
|
-
async function generate$
|
|
9601
|
+
async function generate$9(algo) {
|
|
9593
9602
|
switch (algo) {
|
|
9594
9603
|
case enums.publicKey.x25519: {
|
|
9595
9604
|
// k stays in little-endian, unlike legacy ECDH over curve25519
|
|
@@ -9617,7 +9626,7 @@ async function generate$3(algo) {
|
|
|
9617
9626
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
9618
9627
|
* @async
|
|
9619
9628
|
*/
|
|
9620
|
-
async function validateParams$
|
|
9629
|
+
async function validateParams$b(algo, A, k) {
|
|
9621
9630
|
switch (algo) {
|
|
9622
9631
|
case enums.publicKey.x25519: {
|
|
9623
9632
|
/**
|
|
@@ -9654,7 +9663,7 @@ async function validateParams$5(algo, A, k) {
|
|
|
9654
9663
|
* }>} ephemeral public key (K_A) and encrypted key
|
|
9655
9664
|
* @async
|
|
9656
9665
|
*/
|
|
9657
|
-
async function encrypt$
|
|
9666
|
+
async function encrypt$3(algo, data, recipientA) {
|
|
9658
9667
|
const { ephemeralPublicKey, sharedSecret } = await generateEphemeralEncryptionMaterial(algo, recipientA);
|
|
9659
9668
|
const hkdfInput = util.concatUint8Array([
|
|
9660
9669
|
ephemeralPublicKey,
|
|
@@ -9693,7 +9702,7 @@ async function encrypt$2(algo, data, recipientA) {
|
|
|
9693
9702
|
* @returns {Promise<Uint8Array>} decrypted session key data
|
|
9694
9703
|
* @async
|
|
9695
9704
|
*/
|
|
9696
|
-
async function decrypt$
|
|
9705
|
+
async function decrypt$3(algo, ephemeralPublicKey, wrappedKey, A, k) {
|
|
9697
9706
|
const sharedSecret = await recomputeSharedSecret(algo, ephemeralPublicKey, A, k);
|
|
9698
9707
|
const hkdfInput = util.concatUint8Array([
|
|
9699
9708
|
ephemeralPublicKey,
|
|
@@ -9794,13 +9803,13 @@ function assertNonZeroArray(sharedSecret) {
|
|
|
9794
9803
|
|
|
9795
9804
|
var ecdh_x = /*#__PURE__*/Object.freeze({
|
|
9796
9805
|
__proto__: null,
|
|
9797
|
-
decrypt: decrypt$
|
|
9798
|
-
encrypt: encrypt$
|
|
9799
|
-
generate: generate$
|
|
9806
|
+
decrypt: decrypt$3,
|
|
9807
|
+
encrypt: encrypt$3,
|
|
9808
|
+
generate: generate$9,
|
|
9800
9809
|
generateEphemeralEncryptionMaterial: generateEphemeralEncryptionMaterial,
|
|
9801
9810
|
getPayloadSize: getPayloadSize,
|
|
9802
9811
|
recomputeSharedSecret: recomputeSharedSecret,
|
|
9803
|
-
validateParams: validateParams$
|
|
9812
|
+
validateParams: validateParams$b
|
|
9804
9813
|
});
|
|
9805
9814
|
|
|
9806
9815
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -9976,7 +9985,7 @@ class CurveWithOID {
|
|
|
9976
9985
|
return nodeGenKeyPair(this.name);
|
|
9977
9986
|
case 'curve25519Legacy': {
|
|
9978
9987
|
// the private key must be stored in big endian and already clamped: https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-13.html#section-5.5.5.6.1.1-3
|
|
9979
|
-
const { k, A } = await generate$
|
|
9988
|
+
const { k, A } = await generate$9(enums.publicKey.x25519);
|
|
9980
9989
|
const privateKey = k.slice().reverse();
|
|
9981
9990
|
privateKey[0] = (privateKey[0] & 127) | 64;
|
|
9982
9991
|
privateKey[31] &= 248;
|
|
@@ -9984,7 +9993,7 @@ class CurveWithOID {
|
|
|
9984
9993
|
return { publicKey, privateKey };
|
|
9985
9994
|
}
|
|
9986
9995
|
case 'ed25519Legacy': {
|
|
9987
|
-
const { seed: privateKey, A } = await generate$
|
|
9996
|
+
const { seed: privateKey, A } = await generate$a(enums.publicKey.ed25519);
|
|
9988
9997
|
const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), A]);
|
|
9989
9998
|
return { publicKey, privateKey };
|
|
9990
9999
|
}
|
|
@@ -9994,7 +10003,7 @@ class CurveWithOID {
|
|
|
9994
10003
|
}
|
|
9995
10004
|
}
|
|
9996
10005
|
|
|
9997
|
-
async function generate$
|
|
10006
|
+
async function generate$8(curveName) {
|
|
9998
10007
|
const curve = new CurveWithOID(curveName);
|
|
9999
10008
|
const { oid, hash, cipher } = curve;
|
|
10000
10009
|
const keyPair = await curve.genKeyPair();
|
|
@@ -10212,7 +10221,7 @@ const nodeCrypto$2 = util.getNodeCrypto();
|
|
|
10212
10221
|
* }>} Signature of the message
|
|
10213
10222
|
* @async
|
|
10214
10223
|
*/
|
|
10215
|
-
async function sign$
|
|
10224
|
+
async function sign$8(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
10216
10225
|
const curve = new CurveWithOID(oid);
|
|
10217
10226
|
checkPublicPointEnconding(curve, publicKey);
|
|
10218
10227
|
if (message && !util.isStream(message)) {
|
|
@@ -10259,7 +10268,7 @@ async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
10259
10268
|
* @returns {Boolean}
|
|
10260
10269
|
* @async
|
|
10261
10270
|
*/
|
|
10262
|
-
async function verify$
|
|
10271
|
+
async function verify$8(oid, hashAlgo, signature, message, publicKey, hashed) {
|
|
10263
10272
|
const curve = new CurveWithOID(oid);
|
|
10264
10273
|
checkPublicPointEnconding(curve, publicKey);
|
|
10265
10274
|
// See https://github.com/openpgpjs/openpgpjs/pull/948.
|
|
@@ -10310,7 +10319,7 @@ async function verify$5(oid, hashAlgo, signature, message, publicKey, hashed) {
|
|
|
10310
10319
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
10311
10320
|
* @async
|
|
10312
10321
|
*/
|
|
10313
|
-
async function validateParams$
|
|
10322
|
+
async function validateParams$a(oid, Q, d) {
|
|
10314
10323
|
const curve = new CurveWithOID(oid);
|
|
10315
10324
|
// Reject curves x25519 and ed25519
|
|
10316
10325
|
if (curve.keyType !== enums.publicKey.ecdsa) {
|
|
@@ -10326,9 +10335,9 @@ async function validateParams$4(oid, Q, d) {
|
|
|
10326
10335
|
const hashAlgo = enums.hash.sha256;
|
|
10327
10336
|
const hashed = await hash.digest(hashAlgo, message);
|
|
10328
10337
|
try {
|
|
10329
|
-
const signature = await sign$
|
|
10338
|
+
const signature = await sign$8(oid, hashAlgo, message, Q, d, hashed);
|
|
10330
10339
|
// eslint-disable-next-line @typescript-eslint/return-await
|
|
10331
|
-
return await verify$
|
|
10340
|
+
return await verify$8(oid, hashAlgo, signature, message, Q, hashed);
|
|
10332
10341
|
} catch (err) {
|
|
10333
10342
|
return false;
|
|
10334
10343
|
}
|
|
@@ -10459,9 +10468,9 @@ async function nodeVerify(curve, hashAlgo, { r, s }, message, publicKey) {
|
|
|
10459
10468
|
|
|
10460
10469
|
var ecdsa = /*#__PURE__*/Object.freeze({
|
|
10461
10470
|
__proto__: null,
|
|
10462
|
-
sign: sign$
|
|
10463
|
-
validateParams: validateParams$
|
|
10464
|
-
verify: verify$
|
|
10471
|
+
sign: sign$8,
|
|
10472
|
+
validateParams: validateParams$a,
|
|
10473
|
+
verify: verify$8
|
|
10465
10474
|
});
|
|
10466
10475
|
|
|
10467
10476
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -10496,7 +10505,7 @@ var ecdsa = /*#__PURE__*/Object.freeze({
|
|
|
10496
10505
|
* }>} Signature of the message
|
|
10497
10506
|
* @async
|
|
10498
10507
|
*/
|
|
10499
|
-
async function sign$
|
|
10508
|
+
async function sign$7(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
10500
10509
|
const curve = new CurveWithOID(oid);
|
|
10501
10510
|
checkPublicPointEnconding(curve, publicKey);
|
|
10502
10511
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
@@ -10505,7 +10514,7 @@ async function sign$4(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
10505
10514
|
// and https://www.rfc-editor.org/rfc/rfc9580.html#section-5.2.3.3-3
|
|
10506
10515
|
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
10507
10516
|
}
|
|
10508
|
-
const { RS: signature } = await sign$
|
|
10517
|
+
const { RS: signature } = await sign$9(enums.publicKey.ed25519, hashAlgo, message, publicKey.subarray(1), privateKey, hashed);
|
|
10509
10518
|
// EdDSA signature params are returned in little-endian format
|
|
10510
10519
|
return {
|
|
10511
10520
|
r: signature.subarray(0, 32),
|
|
@@ -10525,7 +10534,7 @@ async function sign$4(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
10525
10534
|
* @returns {Boolean}
|
|
10526
10535
|
* @async
|
|
10527
10536
|
*/
|
|
10528
|
-
async function verify$
|
|
10537
|
+
async function verify$7(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
10529
10538
|
const curve = new CurveWithOID(oid);
|
|
10530
10539
|
checkPublicPointEnconding(curve, publicKey);
|
|
10531
10540
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
@@ -10535,7 +10544,7 @@ async function verify$4(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
|
10535
10544
|
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
10536
10545
|
}
|
|
10537
10546
|
const RS = util.concatUint8Array([r, s]);
|
|
10538
|
-
return verify$
|
|
10547
|
+
return verify$9(enums.publicKey.ed25519, hashAlgo, { RS }, m, publicKey.subarray(1), hashed);
|
|
10539
10548
|
}
|
|
10540
10549
|
/**
|
|
10541
10550
|
* Validate legacy EdDSA parameters
|
|
@@ -10545,7 +10554,7 @@ async function verify$4(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
|
10545
10554
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
10546
10555
|
* @async
|
|
10547
10556
|
*/
|
|
10548
|
-
async function validateParams$
|
|
10557
|
+
async function validateParams$9(oid, Q, k) {
|
|
10549
10558
|
// Check whether the given curve is supported
|
|
10550
10559
|
if (oid.getName() !== enums.curve.ed25519Legacy) {
|
|
10551
10560
|
return false;
|
|
@@ -10563,9 +10572,9 @@ async function validateParams$3(oid, Q, k) {
|
|
|
10563
10572
|
|
|
10564
10573
|
var eddsa_legacy = /*#__PURE__*/Object.freeze({
|
|
10565
10574
|
__proto__: null,
|
|
10566
|
-
sign: sign$
|
|
10567
|
-
validateParams: validateParams$
|
|
10568
|
-
verify: verify$
|
|
10575
|
+
sign: sign$7,
|
|
10576
|
+
validateParams: validateParams$9,
|
|
10577
|
+
verify: verify$7
|
|
10569
10578
|
});
|
|
10570
10579
|
|
|
10571
10580
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -10660,7 +10669,7 @@ const nodeCrypto$1 = util.getNodeCrypto();
|
|
|
10660
10669
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
10661
10670
|
* @async
|
|
10662
10671
|
*/
|
|
10663
|
-
async function validateParams$
|
|
10672
|
+
async function validateParams$8(oid, Q, d) {
|
|
10664
10673
|
return validateStandardParams(enums.publicKey.ecdh, oid, Q, d);
|
|
10665
10674
|
}
|
|
10666
10675
|
|
|
@@ -10743,7 +10752,7 @@ async function genPublicEphemeralKey(curve, Q) {
|
|
|
10743
10752
|
* @returns {Promise<{publicKey: Uint8Array, wrappedKey: Uint8Array}>}
|
|
10744
10753
|
* @async
|
|
10745
10754
|
*/
|
|
10746
|
-
async function encrypt$
|
|
10755
|
+
async function encrypt$2(oid, kdfParams, data, Q, fingerprint) {
|
|
10747
10756
|
const m = encode(data);
|
|
10748
10757
|
|
|
10749
10758
|
const curve = new CurveWithOID(oid);
|
|
@@ -10808,7 +10817,7 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
|
|
|
10808
10817
|
* @returns {Promise<Uint8Array>} Value derived from session key.
|
|
10809
10818
|
* @async
|
|
10810
10819
|
*/
|
|
10811
|
-
async function decrypt$
|
|
10820
|
+
async function decrypt$2(oid, kdfParams, V, C, Q, d, fingerprint) {
|
|
10812
10821
|
const curve = new CurveWithOID(oid);
|
|
10813
10822
|
checkPublicPointEnconding(curve, Q);
|
|
10814
10823
|
checkPublicPointEnconding(curve, V);
|
|
@@ -10982,9 +10991,9 @@ async function nodePublicEphemeralKey(curve, Q) {
|
|
|
10982
10991
|
|
|
10983
10992
|
var ecdh = /*#__PURE__*/Object.freeze({
|
|
10984
10993
|
__proto__: null,
|
|
10985
|
-
decrypt: decrypt$
|
|
10986
|
-
encrypt: encrypt$
|
|
10987
|
-
validateParams: validateParams$
|
|
10994
|
+
decrypt: decrypt$2,
|
|
10995
|
+
encrypt: encrypt$2,
|
|
10996
|
+
validateParams: validateParams$8
|
|
10988
10997
|
});
|
|
10989
10998
|
|
|
10990
10999
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -11012,7 +11021,7 @@ var elliptic = /*#__PURE__*/Object.freeze({
|
|
|
11012
11021
|
ecdsa: ecdsa,
|
|
11013
11022
|
eddsa: eddsa,
|
|
11014
11023
|
eddsaLegacy: eddsa_legacy,
|
|
11015
|
-
generate: generate$
|
|
11024
|
+
generate: generate$8,
|
|
11016
11025
|
getPreferredHashAlgo: getPreferredHashAlgo$1
|
|
11017
11026
|
});
|
|
11018
11027
|
|
|
@@ -11054,7 +11063,7 @@ const _1n = BigInt(1);
|
|
|
11054
11063
|
* @returns {Promise<{ r: Uint8Array, s: Uint8Array }>}
|
|
11055
11064
|
* @async
|
|
11056
11065
|
*/
|
|
11057
|
-
async function sign$
|
|
11066
|
+
async function sign$6(hashAlgo, hashed, g, p, q, x) {
|
|
11058
11067
|
const _0n = BigInt(0);
|
|
11059
11068
|
p = uint8ArrayToBigInt(p);
|
|
11060
11069
|
q = uint8ArrayToBigInt(q);
|
|
@@ -11112,7 +11121,7 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
|
|
|
11112
11121
|
* @returns {boolean}
|
|
11113
11122
|
* @async
|
|
11114
11123
|
*/
|
|
11115
|
-
async function verify$
|
|
11124
|
+
async function verify$6(hashAlgo, r, s, hashed, g, p, q, y) {
|
|
11116
11125
|
r = uint8ArrayToBigInt(r);
|
|
11117
11126
|
s = uint8ArrayToBigInt(s);
|
|
11118
11127
|
|
|
@@ -11153,7 +11162,7 @@ async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
|
|
|
11153
11162
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
11154
11163
|
* @async
|
|
11155
11164
|
*/
|
|
11156
|
-
async function validateParams$
|
|
11165
|
+
async function validateParams$7(p, q, g, y, x) {
|
|
11157
11166
|
p = uint8ArrayToBigInt(p);
|
|
11158
11167
|
q = uint8ArrayToBigInt(q);
|
|
11159
11168
|
g = uint8ArrayToBigInt(g);
|
|
@@ -11206,9 +11215,9 @@ async function validateParams$1(p, q, g, y, x) {
|
|
|
11206
11215
|
|
|
11207
11216
|
var dsa = /*#__PURE__*/Object.freeze({
|
|
11208
11217
|
__proto__: null,
|
|
11209
|
-
sign: sign$
|
|
11210
|
-
validateParams: validateParams$
|
|
11211
|
-
verify: verify$
|
|
11218
|
+
sign: sign$6,
|
|
11219
|
+
validateParams: validateParams$7,
|
|
11220
|
+
verify: verify$6
|
|
11212
11221
|
});
|
|
11213
11222
|
|
|
11214
11223
|
const supportedHashAlgos = new Set([enums.hash.sha1, enums.hash.sha256, enums.hash.sha512]);
|
|
@@ -11216,7 +11225,7 @@ const supportedHashAlgos = new Set([enums.hash.sha1, enums.hash.sha256, enums.ha
|
|
|
11216
11225
|
const webCrypto = util.getWebCrypto();
|
|
11217
11226
|
const nodeCrypto = util.getNodeCrypto();
|
|
11218
11227
|
|
|
11219
|
-
async function generate$
|
|
11228
|
+
async function generate$7(hashAlgo) {
|
|
11220
11229
|
if (!supportedHashAlgos.has(hashAlgo)) {
|
|
11221
11230
|
throw new Error('Unsupported hash algorithm.');
|
|
11222
11231
|
}
|
|
@@ -11235,7 +11244,7 @@ async function generate$1(hashAlgo) {
|
|
|
11235
11244
|
return new Uint8Array(exportedKey);
|
|
11236
11245
|
}
|
|
11237
11246
|
|
|
11238
|
-
async function sign$
|
|
11247
|
+
async function sign$5(hashAlgo, key, data) {
|
|
11239
11248
|
if (!supportedHashAlgos.has(hashAlgo)) {
|
|
11240
11249
|
throw new Error('Unsupported hash algorithm.');
|
|
11241
11250
|
}
|
|
@@ -11256,7 +11265,7 @@ async function sign$2(hashAlgo, key, data) {
|
|
|
11256
11265
|
return new Uint8Array(mac);
|
|
11257
11266
|
}
|
|
11258
11267
|
|
|
11259
|
-
async function verify$
|
|
11268
|
+
async function verify$5(hashAlgo, key, mac, data) {
|
|
11260
11269
|
if (!supportedHashAlgos.has(hashAlgo)) {
|
|
11261
11270
|
throw new Error('Unsupported hash algorithm.');
|
|
11262
11271
|
}
|
|
@@ -11277,12 +11286,390 @@ async function verify$2(hashAlgo, key, mac, data) {
|
|
|
11277
11286
|
}
|
|
11278
11287
|
|
|
11279
11288
|
var hmac = /*#__PURE__*/Object.freeze({
|
|
11289
|
+
__proto__: null,
|
|
11290
|
+
generate: generate$7,
|
|
11291
|
+
sign: sign$5,
|
|
11292
|
+
verify: verify$5
|
|
11293
|
+
});
|
|
11294
|
+
|
|
11295
|
+
async function generate$6(algo) {
|
|
11296
|
+
switch (algo) {
|
|
11297
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11298
|
+
const { A, k } = await generate$9(enums.publicKey.x25519);
|
|
11299
|
+
return {
|
|
11300
|
+
eccPublicKey: A,
|
|
11301
|
+
eccSecretKey: k
|
|
11302
|
+
};
|
|
11303
|
+
}
|
|
11304
|
+
default:
|
|
11305
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11306
|
+
}
|
|
11307
|
+
}
|
|
11308
|
+
|
|
11309
|
+
async function encaps$1(eccAlgo, eccRecipientPublicKey) {
|
|
11310
|
+
switch (eccAlgo) {
|
|
11311
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11312
|
+
const { ephemeralPublicKey: eccCipherText, sharedSecret: eccSharedSecret } = await generateEphemeralEncryptionMaterial(enums.publicKey.x25519, eccRecipientPublicKey);
|
|
11313
|
+
const eccKeyShare = await hash.sha3_256(util.concatUint8Array([
|
|
11314
|
+
eccSharedSecret,
|
|
11315
|
+
eccCipherText,
|
|
11316
|
+
eccRecipientPublicKey
|
|
11317
|
+
]));
|
|
11318
|
+
return {
|
|
11319
|
+
eccCipherText,
|
|
11320
|
+
eccKeyShare
|
|
11321
|
+
};
|
|
11322
|
+
}
|
|
11323
|
+
default:
|
|
11324
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11325
|
+
}
|
|
11326
|
+
}
|
|
11327
|
+
|
|
11328
|
+
async function decaps$1(eccAlgo, eccCipherText, eccSecretKey, eccPublicKey) {
|
|
11329
|
+
switch (eccAlgo) {
|
|
11330
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11331
|
+
const eccSharedSecret = await recomputeSharedSecret(enums.publicKey.x25519, eccCipherText, eccPublicKey, eccSecretKey);
|
|
11332
|
+
const eccKeyShare = await hash.sha3_256(util.concatUint8Array([
|
|
11333
|
+
eccSharedSecret,
|
|
11334
|
+
eccCipherText,
|
|
11335
|
+
eccPublicKey
|
|
11336
|
+
]));
|
|
11337
|
+
return eccKeyShare;
|
|
11338
|
+
}
|
|
11339
|
+
default:
|
|
11340
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11341
|
+
}
|
|
11342
|
+
}
|
|
11343
|
+
|
|
11344
|
+
async function validateParams$6(algo, eccPublicKey, eccSecretKey) {
|
|
11345
|
+
switch (algo) {
|
|
11346
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
11347
|
+
return validateParams$b(enums.publicKey.x25519, eccPublicKey, eccSecretKey);
|
|
11348
|
+
default:
|
|
11349
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11350
|
+
}
|
|
11351
|
+
}
|
|
11352
|
+
|
|
11353
|
+
async function generate$5(algo) {
|
|
11354
|
+
switch (algo) {
|
|
11355
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11356
|
+
const mlkemSeed = getRandomBytes(64);
|
|
11357
|
+
const { mlkemSecretKey, mlkemPublicKey } = await expandSecretSeed$1(algo, mlkemSeed);
|
|
11358
|
+
|
|
11359
|
+
return { mlkemSeed, mlkemSecretKey, mlkemPublicKey };
|
|
11360
|
+
}
|
|
11361
|
+
default:
|
|
11362
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11363
|
+
}
|
|
11364
|
+
}
|
|
11365
|
+
|
|
11366
|
+
/**
|
|
11367
|
+
* Expand ML-KEM secret seed and retrieve the secret and public key material
|
|
11368
|
+
* @param {module:enums.publicKey} algo - Public key algorithm
|
|
11369
|
+
* @param {Uint8Array} seed - secret seed to expand
|
|
11370
|
+
* @returns {Promise<{ mlkemPublicKey: Uint8Array, mlkemSecretKey: Uint8Array }>}
|
|
11371
|
+
*/
|
|
11372
|
+
async function expandSecretSeed$1(algo, seed) {
|
|
11373
|
+
switch (algo) {
|
|
11374
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11375
|
+
const { ml_kem768 } = await import('./noble_post_quantum.mjs');
|
|
11376
|
+
const { publicKey: encapsulationKey, secretKey: decapsulationKey } = ml_kem768.keygen(seed);
|
|
11377
|
+
|
|
11378
|
+
return { mlkemPublicKey: encapsulationKey, mlkemSecretKey: decapsulationKey };
|
|
11379
|
+
}
|
|
11380
|
+
default:
|
|
11381
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11382
|
+
}
|
|
11383
|
+
}
|
|
11384
|
+
|
|
11385
|
+
async function encaps(algo, mlkemRecipientPublicKey) {
|
|
11386
|
+
switch (algo) {
|
|
11387
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11388
|
+
const { ml_kem768 } = await import('./noble_post_quantum.mjs');
|
|
11389
|
+
const { cipherText: mlkemCipherText, sharedSecret: mlkemKeyShare } = ml_kem768.encapsulate(mlkemRecipientPublicKey);
|
|
11390
|
+
|
|
11391
|
+
return { mlkemCipherText, mlkemKeyShare };
|
|
11392
|
+
}
|
|
11393
|
+
default:
|
|
11394
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11395
|
+
}
|
|
11396
|
+
}
|
|
11397
|
+
|
|
11398
|
+
async function decaps(algo, mlkemCipherText, mlkemSecretKey) {
|
|
11399
|
+
switch (algo) {
|
|
11400
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11401
|
+
const { ml_kem768 } = await import('./noble_post_quantum.mjs');
|
|
11402
|
+
const mlkemKeyShare = ml_kem768.decapsulate(mlkemCipherText, mlkemSecretKey);
|
|
11403
|
+
|
|
11404
|
+
return mlkemKeyShare;
|
|
11405
|
+
}
|
|
11406
|
+
default:
|
|
11407
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11408
|
+
}
|
|
11409
|
+
}
|
|
11410
|
+
|
|
11411
|
+
async function validateParams$5(algo, mlkemPublicKey, mlkemSeed) {
|
|
11412
|
+
switch (algo) {
|
|
11413
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11414
|
+
const { mlkemPublicKey: expectedPublicKey } = await expandSecretSeed$1(algo, mlkemSeed);
|
|
11415
|
+
return util.equalsUint8Array(mlkemPublicKey, expectedPublicKey);
|
|
11416
|
+
}
|
|
11417
|
+
default:
|
|
11418
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11419
|
+
}
|
|
11420
|
+
}
|
|
11421
|
+
|
|
11422
|
+
async function generate$4(algo) {
|
|
11423
|
+
const { eccPublicKey, eccSecretKey } = await generate$6(algo);
|
|
11424
|
+
const { mlkemPublicKey, mlkemSeed, mlkemSecretKey } = await generate$5(algo);
|
|
11425
|
+
|
|
11426
|
+
return { eccPublicKey, eccSecretKey, mlkemPublicKey, mlkemSeed, mlkemSecretKey };
|
|
11427
|
+
}
|
|
11428
|
+
|
|
11429
|
+
async function encrypt$1(algo, eccPublicKey, mlkemPublicKey, sessioneKeyData) {
|
|
11430
|
+
const { eccKeyShare, eccCipherText } = await encaps$1(algo, eccPublicKey);
|
|
11431
|
+
const { mlkemKeyShare, mlkemCipherText } = await encaps(algo, mlkemPublicKey);
|
|
11432
|
+
const kek = await multiKeyCombine(algo, eccKeyShare, eccCipherText, eccPublicKey, mlkemKeyShare, mlkemCipherText, mlkemPublicKey);
|
|
11433
|
+
const wrappedKey = await wrap(enums.symmetric.aes256, kek, sessioneKeyData); // C
|
|
11434
|
+
return { eccCipherText, mlkemCipherText, wrappedKey };
|
|
11435
|
+
}
|
|
11436
|
+
|
|
11437
|
+
async function decrypt$1(algo, eccCipherText, mlkemCipherText, eccSecretKey, eccPublicKey, mlkemSecretKey, mlkemPublicKey, encryptedSessionKeyData) {
|
|
11438
|
+
const eccKeyShare = await decaps$1(algo, eccCipherText, eccSecretKey, eccPublicKey);
|
|
11439
|
+
const mlkemKeyShare = await decaps(algo, mlkemCipherText, mlkemSecretKey);
|
|
11440
|
+
const kek = await multiKeyCombine(algo, eccKeyShare, eccCipherText, eccPublicKey, mlkemKeyShare, mlkemCipherText, mlkemPublicKey);
|
|
11441
|
+
const sessionKey = await unwrap(enums.symmetric.aes256, kek, encryptedSessionKeyData);
|
|
11442
|
+
return sessionKey;
|
|
11443
|
+
}
|
|
11444
|
+
|
|
11445
|
+
async function multiKeyCombine(algo, ecdhKeyShare, ecdhCipherText, ecdhPublicKey, mlkemKeyShare, mlkemCipherText, mlkemPublicKey) {
|
|
11446
|
+
// LAMPS-aligned and NIST compatible combiner, proposed in: https://mailarchive.ietf.org/arch/msg/openpgp/NMTCy707LICtxIhP3Xt1U5C8MF0/
|
|
11447
|
+
// 2a. KDF(mlkemSS || tradSS || tradCT || tradPK || Domain)
|
|
11448
|
+
// where Domain is "Domain" for LAMPS, and "mlkemCT || mlkemPK || algId" for OpenPGP
|
|
11449
|
+
const encData = util.concatUint8Array([
|
|
11450
|
+
mlkemKeyShare,
|
|
11451
|
+
ecdhKeyShare,
|
|
11452
|
+
ecdhCipherText,
|
|
11453
|
+
ecdhPublicKey,
|
|
11454
|
+
// domSep
|
|
11455
|
+
mlkemCipherText,
|
|
11456
|
+
mlkemPublicKey,
|
|
11457
|
+
new Uint8Array([algo])
|
|
11458
|
+
]);
|
|
11459
|
+
|
|
11460
|
+
const kek = await hash.digest(enums.hash.sha3_256, encData);
|
|
11461
|
+
return kek;
|
|
11462
|
+
}
|
|
11463
|
+
|
|
11464
|
+
async function validateParams$4(algo, eccPublicKey, eccSecretKey, mlkemPublicKey, mlkemSeed) {
|
|
11465
|
+
const eccValidationPromise = validateParams$6(algo, eccPublicKey, eccSecretKey);
|
|
11466
|
+
const mlkemValidationPromise = validateParams$5(algo, mlkemPublicKey, mlkemSeed);
|
|
11467
|
+
const valid = await eccValidationPromise && await mlkemValidationPromise;
|
|
11468
|
+
return valid;
|
|
11469
|
+
}
|
|
11470
|
+
|
|
11471
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
11472
|
+
__proto__: null,
|
|
11473
|
+
decrypt: decrypt$1,
|
|
11474
|
+
encrypt: encrypt$1,
|
|
11475
|
+
generate: generate$4,
|
|
11476
|
+
mlkemExpandSecretSeed: expandSecretSeed$1,
|
|
11477
|
+
validateParams: validateParams$4
|
|
11478
|
+
});
|
|
11479
|
+
|
|
11480
|
+
async function generate$3(algo) {
|
|
11481
|
+
switch (algo) {
|
|
11482
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11483
|
+
const mldsaSeed = getRandomBytes(32);
|
|
11484
|
+
const { mldsaSecretKey, mldsaPublicKey } = await expandSecretSeed(algo, mldsaSeed);
|
|
11485
|
+
|
|
11486
|
+
return { mldsaSeed, mldsaSecretKey, mldsaPublicKey };
|
|
11487
|
+
}
|
|
11488
|
+
default:
|
|
11489
|
+
throw new Error('Unsupported signature algorithm');
|
|
11490
|
+
}
|
|
11491
|
+
}
|
|
11492
|
+
|
|
11493
|
+
/**
|
|
11494
|
+
* Expand ML-DSA secret seed and retrieve the secret and public key material
|
|
11495
|
+
* @param {module:enums.publicKey} algo - Public key algorithm
|
|
11496
|
+
* @param {Uint8Array} seed - secret seed to expand
|
|
11497
|
+
* @returns {Promise<{ mldsaPublicKey: Uint8Array, mldsaSecretKey: Uint8Array }>}
|
|
11498
|
+
*/
|
|
11499
|
+
async function expandSecretSeed(algo, seed) {
|
|
11500
|
+
switch (algo) {
|
|
11501
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11502
|
+
const { ml_dsa65 } = await import('./noble_post_quantum.mjs');
|
|
11503
|
+
const { secretKey: mldsaSecretKey, publicKey: mldsaPublicKey } = ml_dsa65.keygen(seed);
|
|
11504
|
+
|
|
11505
|
+
return { mldsaSecretKey, mldsaPublicKey };
|
|
11506
|
+
}
|
|
11507
|
+
default:
|
|
11508
|
+
throw new Error('Unsupported signature algorithm');
|
|
11509
|
+
}
|
|
11510
|
+
}
|
|
11511
|
+
|
|
11512
|
+
async function sign$4(algo, mldsaSecretKey, dataDigest) {
|
|
11513
|
+
switch (algo) {
|
|
11514
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11515
|
+
const { ml_dsa65 } = await import('./noble_post_quantum.mjs');
|
|
11516
|
+
const mldsaSignature = ml_dsa65.sign(mldsaSecretKey, dataDigest);
|
|
11517
|
+
return { mldsaSignature };
|
|
11518
|
+
}
|
|
11519
|
+
default:
|
|
11520
|
+
throw new Error('Unsupported signature algorithm');
|
|
11521
|
+
}
|
|
11522
|
+
}
|
|
11523
|
+
|
|
11524
|
+
async function verify$4(algo, mldsaPublicKey, dataDigest, mldsaSignature) {
|
|
11525
|
+
switch (algo) {
|
|
11526
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11527
|
+
const { ml_dsa65 } = await import('./noble_post_quantum.mjs');
|
|
11528
|
+
return ml_dsa65.verify(mldsaPublicKey, dataDigest, mldsaSignature);
|
|
11529
|
+
}
|
|
11530
|
+
default:
|
|
11531
|
+
throw new Error('Unsupported signature algorithm');
|
|
11532
|
+
}
|
|
11533
|
+
}
|
|
11534
|
+
|
|
11535
|
+
async function validateParams$3(algo, mldsaPublicKey, mldsaSeed) {
|
|
11536
|
+
switch (algo) {
|
|
11537
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11538
|
+
const { mldsaPublicKey: expectedPublicKey } = await expandSecretSeed(algo, mldsaSeed);
|
|
11539
|
+
return util.equalsUint8Array(mldsaPublicKey, expectedPublicKey);
|
|
11540
|
+
}
|
|
11541
|
+
default:
|
|
11542
|
+
throw new Error('Unsupported signature algorithm');
|
|
11543
|
+
}
|
|
11544
|
+
}
|
|
11545
|
+
|
|
11546
|
+
async function generate$2(algo) {
|
|
11547
|
+
switch (algo) {
|
|
11548
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11549
|
+
const { A, seed } = await generate$a(enums.publicKey.ed25519);
|
|
11550
|
+
return {
|
|
11551
|
+
eccPublicKey: A,
|
|
11552
|
+
eccSecretKey: seed
|
|
11553
|
+
};
|
|
11554
|
+
}
|
|
11555
|
+
default:
|
|
11556
|
+
throw new Error('Unsupported signature algorithm');
|
|
11557
|
+
}
|
|
11558
|
+
}
|
|
11559
|
+
|
|
11560
|
+
async function sign$3(signatureAlgo, hashAlgo, eccSecretKey, eccPublicKey, dataDigest) {
|
|
11561
|
+
switch (signatureAlgo) {
|
|
11562
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11563
|
+
const { RS: eccSignature } = await sign$9(enums.publicKey.ed25519, hashAlgo, null, eccPublicKey, eccSecretKey, dataDigest);
|
|
11564
|
+
|
|
11565
|
+
return { eccSignature };
|
|
11566
|
+
}
|
|
11567
|
+
default:
|
|
11568
|
+
throw new Error('Unsupported signature algorithm');
|
|
11569
|
+
}
|
|
11570
|
+
}
|
|
11571
|
+
|
|
11572
|
+
async function verify$3(signatureAlgo, hashAlgo, eccPublicKey, dataDigest, eccSignature) {
|
|
11573
|
+
switch (signatureAlgo) {
|
|
11574
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
11575
|
+
return verify$9(enums.publicKey.ed25519, hashAlgo, { RS: eccSignature }, null, eccPublicKey, dataDigest);
|
|
11576
|
+
default:
|
|
11577
|
+
throw new Error('Unsupported signature algorithm');
|
|
11578
|
+
}
|
|
11579
|
+
}
|
|
11580
|
+
|
|
11581
|
+
async function validateParams$2(algo, eccPublicKey, eccSecretKey) {
|
|
11582
|
+
switch (algo) {
|
|
11583
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
11584
|
+
return validateParams$c(enums.publicKey.ed25519, eccPublicKey, eccSecretKey);
|
|
11585
|
+
default:
|
|
11586
|
+
throw new Error('Unsupported signature algorithm');
|
|
11587
|
+
}
|
|
11588
|
+
}
|
|
11589
|
+
|
|
11590
|
+
async function generate$1(algo) {
|
|
11591
|
+
switch (algo) {
|
|
11592
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11593
|
+
const { eccSecretKey, eccPublicKey } = await generate$2(algo);
|
|
11594
|
+
const { mldsaSeed, mldsaSecretKey, mldsaPublicKey } = await generate$3(algo);
|
|
11595
|
+
return { eccSecretKey, eccPublicKey, mldsaSeed, mldsaSecretKey, mldsaPublicKey };
|
|
11596
|
+
}
|
|
11597
|
+
default:
|
|
11598
|
+
throw new Error('Unsupported signature algorithm');
|
|
11599
|
+
}
|
|
11600
|
+
}
|
|
11601
|
+
|
|
11602
|
+
async function sign$2(signatureAlgo, hashAlgo, eccSecretKey, eccPublicKey, mldsaSecretKey, dataDigest) {
|
|
11603
|
+
if (hashAlgo !== getRequiredHashAlgo(signatureAlgo)) {
|
|
11604
|
+
// The signature hash algo MUST be set to the specified algorithm, see
|
|
11605
|
+
// https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
11606
|
+
throw new Error('Unexpected hash algorithm for PQC signature');
|
|
11607
|
+
}
|
|
11608
|
+
|
|
11609
|
+
switch (signatureAlgo) {
|
|
11610
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11611
|
+
const { eccSignature } = await sign$3(signatureAlgo, hashAlgo, eccSecretKey, eccPublicKey, dataDigest);
|
|
11612
|
+
const { mldsaSignature } = await sign$4(signatureAlgo, mldsaSecretKey, dataDigest);
|
|
11613
|
+
|
|
11614
|
+
return { eccSignature, mldsaSignature };
|
|
11615
|
+
}
|
|
11616
|
+
default:
|
|
11617
|
+
throw new Error('Unsupported signature algorithm');
|
|
11618
|
+
}
|
|
11619
|
+
}
|
|
11620
|
+
|
|
11621
|
+
async function verify$2(signatureAlgo, hashAlgo, eccPublicKey, mldsaPublicKey, dataDigest, { eccSignature, mldsaSignature }) {
|
|
11622
|
+
if (hashAlgo !== getRequiredHashAlgo(signatureAlgo)) {
|
|
11623
|
+
// The signature hash algo MUST be set to the specified algorithm, see
|
|
11624
|
+
// https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
11625
|
+
throw new Error('Unexpected hash algorithm for PQC signature');
|
|
11626
|
+
}
|
|
11627
|
+
|
|
11628
|
+
switch (signatureAlgo) {
|
|
11629
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11630
|
+
const eccVerifiedPromise = verify$3(signatureAlgo, hashAlgo, eccPublicKey, dataDigest, eccSignature);
|
|
11631
|
+
const mldsaVerifiedPromise = verify$4(signatureAlgo, mldsaPublicKey, dataDigest, mldsaSignature);
|
|
11632
|
+
const verified = await eccVerifiedPromise && await mldsaVerifiedPromise;
|
|
11633
|
+
return verified;
|
|
11634
|
+
}
|
|
11635
|
+
default:
|
|
11636
|
+
throw new Error('Unsupported signature algorithm');
|
|
11637
|
+
}
|
|
11638
|
+
}
|
|
11639
|
+
|
|
11640
|
+
function getRequiredHashAlgo(signatureAlgo) {
|
|
11641
|
+
// See https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
11642
|
+
switch (signatureAlgo) {
|
|
11643
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
11644
|
+
return enums.hash.sha3_256;
|
|
11645
|
+
default:
|
|
11646
|
+
throw new Error('Unsupported signature algorithm');
|
|
11647
|
+
}
|
|
11648
|
+
}
|
|
11649
|
+
|
|
11650
|
+
async function validateParams$1(algo, eccPublicKey, eccSecretKey, mldsaPublicKey, mldsaSeed) {
|
|
11651
|
+
const eccValidationPromise = validateParams$2(algo, eccPublicKey, eccSecretKey);
|
|
11652
|
+
const mldsaValidationPromise = validateParams$3(algo, mldsaPublicKey, mldsaSeed);
|
|
11653
|
+
const valid = await eccValidationPromise && await mldsaValidationPromise;
|
|
11654
|
+
return valid;
|
|
11655
|
+
}
|
|
11656
|
+
|
|
11657
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
11280
11658
|
__proto__: null,
|
|
11281
11659
|
generate: generate$1,
|
|
11660
|
+
getRequiredHashAlgo: getRequiredHashAlgo,
|
|
11661
|
+
mldsaExpandSecretSeed: expandSecretSeed,
|
|
11282
11662
|
sign: sign$2,
|
|
11663
|
+
validateParams: validateParams$1,
|
|
11283
11664
|
verify: verify$2
|
|
11284
11665
|
});
|
|
11285
11666
|
|
|
11667
|
+
var postQuantum = /*#__PURE__*/Object.freeze({
|
|
11668
|
+
__proto__: null,
|
|
11669
|
+
kem: index$1,
|
|
11670
|
+
signature: index
|
|
11671
|
+
});
|
|
11672
|
+
|
|
11286
11673
|
/**
|
|
11287
11674
|
* @fileoverview Asymmetric cryptography functions
|
|
11288
11675
|
* @module crypto/public_key
|
|
@@ -11299,7 +11686,9 @@ var publicKey = {
|
|
|
11299
11686
|
/** @see module:crypto/public_key/dsa */
|
|
11300
11687
|
dsa: dsa,
|
|
11301
11688
|
/** @see module:crypto/public_key/hmac */
|
|
11302
|
-
hmac: hmac
|
|
11689
|
+
hmac: hmac,
|
|
11690
|
+
/** @see module:crypto/public_key/post_quantum */
|
|
11691
|
+
postQuantum
|
|
11303
11692
|
};
|
|
11304
11693
|
|
|
11305
11694
|
class ShortByteString {
|
|
@@ -11398,6 +11787,12 @@ function parseSignatureParams(algo, signature) {
|
|
|
11398
11787
|
const mac = new ShortByteString(); read += mac.read(signature.subarray(read));
|
|
11399
11788
|
return { read, signatureParams: { mac } };
|
|
11400
11789
|
}
|
|
11790
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11791
|
+
const eccSignatureSize = 2 * publicKey.elliptic.eddsa.getPayloadSize(enums.publicKey.ed25519);
|
|
11792
|
+
const eccSignature = util.readExactSubarray(signature, read, read + eccSignatureSize); read += eccSignature.length;
|
|
11793
|
+
const mldsaSignature = util.readExactSubarray(signature, read, read + 3309); read += mldsaSignature.length;
|
|
11794
|
+
return { read, signatureParams: { eccSignature, mldsaSignature } };
|
|
11795
|
+
}
|
|
11401
11796
|
default:
|
|
11402
11797
|
throw new UnsupportedError('Unknown signature algorithm.');
|
|
11403
11798
|
}
|
|
@@ -11462,6 +11857,10 @@ async function verify$1(algo, hashAlgo, signature, publicParams, privateParams,
|
|
|
11462
11857
|
const { keyMaterial } = privateParams;
|
|
11463
11858
|
return publicKey.hmac.verify(algo.getValue(), keyMaterial, signature.mac.data, hashed);
|
|
11464
11859
|
}
|
|
11860
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11861
|
+
const { eccPublicKey, mldsaPublicKey } = publicParams;
|
|
11862
|
+
return publicKey.postQuantum.signature.verify(algo, hashAlgo, eccPublicKey, mldsaPublicKey, hashed, signature);
|
|
11863
|
+
}
|
|
11465
11864
|
default:
|
|
11466
11865
|
throw new Error('Unknown signature algorithm.');
|
|
11467
11866
|
}
|
|
@@ -11523,6 +11922,11 @@ async function sign$1(algo, hashAlgo, publicKeyParams, privateKeyParams, data, h
|
|
|
11523
11922
|
const mac = await publicKey.hmac.sign(algo.getValue(), keyMaterial, hashed);
|
|
11524
11923
|
return { mac: new ShortByteString(mac) };
|
|
11525
11924
|
}
|
|
11925
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11926
|
+
const { eccPublicKey } = publicKeyParams;
|
|
11927
|
+
const { eccSecretKey, mldsaSecretKey } = privateKeyParams;
|
|
11928
|
+
return publicKey.postQuantum.signature.sign(algo, hashAlgo, eccSecretKey, eccPublicKey, mldsaSecretKey, hashed);
|
|
11929
|
+
}
|
|
11526
11930
|
default:
|
|
11527
11931
|
throw new Error('Unknown signature algorithm.');
|
|
11528
11932
|
}
|
|
@@ -11862,6 +12266,12 @@ async function publicKeyEncrypt(keyAlgo, symmetricAlgo, publicParams, privatePar
|
|
|
11862
12266
|
const c = await modeInstance.encrypt(data, iv, new Uint8Array());
|
|
11863
12267
|
return { aeadMode: new AEADEnum(aeadMode), iv, c: new ShortByteString(c) };
|
|
11864
12268
|
}
|
|
12269
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12270
|
+
const { eccPublicKey, mlkemPublicKey } = publicParams;
|
|
12271
|
+
const { eccCipherText, mlkemCipherText, wrappedKey } = await publicKey.postQuantum.kem.encrypt(keyAlgo, eccPublicKey, mlkemPublicKey, data);
|
|
12272
|
+
const C = ECDHXSymmetricKey.fromObject({ algorithm: symmetricAlgo, wrappedKey });
|
|
12273
|
+
return { eccCipherText, mlkemCipherText, C };
|
|
12274
|
+
}
|
|
11865
12275
|
default:
|
|
11866
12276
|
return [];
|
|
11867
12277
|
}
|
|
@@ -11881,8 +12291,8 @@ async function publicKeyEncrypt(keyAlgo, symmetricAlgo, publicParams, privatePar
|
|
|
11881
12291
|
* @throws {Error} on sensitive decryption error, unless `randomPayload` is given
|
|
11882
12292
|
* @async
|
|
11883
12293
|
*/
|
|
11884
|
-
async function publicKeyDecrypt(
|
|
11885
|
-
switch (
|
|
12294
|
+
async function publicKeyDecrypt(keyAlgo, publicKeyParams, privateKeyParams, sessionKeyParams, fingerprint, randomPayload) {
|
|
12295
|
+
switch (keyAlgo) {
|
|
11886
12296
|
case enums.publicKey.rsaEncryptSign:
|
|
11887
12297
|
case enums.publicKey.rsaEncrypt: {
|
|
11888
12298
|
const { c } = sessionKeyParams;
|
|
@@ -11912,7 +12322,7 @@ async function publicKeyDecrypt(algo, publicKeyParams, privateKeyParams, session
|
|
|
11912
12322
|
throw new Error('AES session key expected');
|
|
11913
12323
|
}
|
|
11914
12324
|
return publicKey.elliptic.ecdhX.decrypt(
|
|
11915
|
-
|
|
12325
|
+
keyAlgo, ephemeralPublicKey, C.wrappedKey, A, k);
|
|
11916
12326
|
}
|
|
11917
12327
|
case enums.publicKey.aead: {
|
|
11918
12328
|
const { cipher: algo } = publicKeyParams;
|
|
@@ -11925,6 +12335,12 @@ async function publicKeyDecrypt(algo, publicKeyParams, privateKeyParams, session
|
|
|
11925
12335
|
const modeInstance = await mode(algoValue, keyMaterial);
|
|
11926
12336
|
return modeInstance.decrypt(c.data, iv, new Uint8Array());
|
|
11927
12337
|
}
|
|
12338
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12339
|
+
const { eccSecretKey, mlkemSecretKey } = privateKeyParams;
|
|
12340
|
+
const { eccPublicKey, mlkemPublicKey } = publicKeyParams;
|
|
12341
|
+
const { eccCipherText, mlkemCipherText, C } = sessionKeyParams;
|
|
12342
|
+
return publicKey.postQuantum.kem.decrypt(keyAlgo, eccCipherText, mlkemCipherText, eccSecretKey, eccPublicKey, mlkemSecretKey, mlkemPublicKey, C.wrappedKey);
|
|
12343
|
+
}
|
|
11928
12344
|
default:
|
|
11929
12345
|
throw new Error('Unknown public key encryption algorithm.');
|
|
11930
12346
|
}
|
|
@@ -11996,6 +12412,16 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
11996
12412
|
const digest = bytes.subarray(read, read + digestLength); read += digestLength;
|
|
11997
12413
|
return { read: read, publicParams: { cipher: algo, digest } };
|
|
11998
12414
|
}
|
|
12415
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12416
|
+
const eccPublicKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.x25519)); read += eccPublicKey.length;
|
|
12417
|
+
const mlkemPublicKey = util.readExactSubarray(bytes, read, read + 1184); read += mlkemPublicKey.length;
|
|
12418
|
+
return { read, publicParams: { eccPublicKey, mlkemPublicKey } };
|
|
12419
|
+
}
|
|
12420
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
12421
|
+
const eccPublicKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.ed25519)); read += eccPublicKey.length;
|
|
12422
|
+
const mldsaPublicKey = util.readExactSubarray(bytes, read, read + 1952); read += mldsaPublicKey.length;
|
|
12423
|
+
return { read, publicParams: { eccPublicKey, mldsaPublicKey } };
|
|
12424
|
+
}
|
|
11999
12425
|
default:
|
|
12000
12426
|
throw new UnsupportedError('Unknown public key encryption algorithm.');
|
|
12001
12427
|
}
|
|
@@ -12008,7 +12434,7 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
12008
12434
|
* @param {Object} publicParams - (ECC and symmetric only) public params, needed to format some private params
|
|
12009
12435
|
* @returns {{ read: Number, privateParams: Object }} Number of read bytes plus the key parameters referenced by name.
|
|
12010
12436
|
*/
|
|
12011
|
-
function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
12437
|
+
async function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
12012
12438
|
let read = 0;
|
|
12013
12439
|
switch (algo) {
|
|
12014
12440
|
case enums.publicKey.rsaEncrypt:
|
|
@@ -12067,6 +12493,18 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
|
12067
12493
|
const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
|
|
12068
12494
|
return { read, privateParams: { hashSeed, keyMaterial } };
|
|
12069
12495
|
}
|
|
12496
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12497
|
+
const eccSecretKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.x25519)); read += eccSecretKey.length;
|
|
12498
|
+
const mlkemSeed = util.readExactSubarray(bytes, read, read + 64); read += mlkemSeed.length;
|
|
12499
|
+
const { mlkemSecretKey } = await publicKey.postQuantum.kem.mlkemExpandSecretSeed(algo, mlkemSeed);
|
|
12500
|
+
return { read, privateParams: { eccSecretKey, mlkemSecretKey, mlkemSeed } };
|
|
12501
|
+
}
|
|
12502
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
12503
|
+
const eccSecretKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.ed25519)); read += eccSecretKey.length;
|
|
12504
|
+
const mldsaSeed = util.readExactSubarray(bytes, read, read + 32); read += mldsaSeed.length;
|
|
12505
|
+
const { mldsaSecretKey } = await publicKey.postQuantum.signature.mldsaExpandSecretSeed(algo, mldsaSeed);
|
|
12506
|
+
return { read, privateParams: { eccSecretKey, mldsaSecretKey, mldsaSeed } };
|
|
12507
|
+
}
|
|
12070
12508
|
default:
|
|
12071
12509
|
throw new UnsupportedError('Unknown public key encryption algorithm.');
|
|
12072
12510
|
}
|
|
@@ -12130,6 +12568,12 @@ function parseEncSessionKeyParams(algo, bytes) {
|
|
|
12130
12568
|
|
|
12131
12569
|
return { aeadMode, iv, c };
|
|
12132
12570
|
}
|
|
12571
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12572
|
+
const eccCipherText = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.x25519)); read += eccCipherText.length;
|
|
12573
|
+
const mlkemCipherText = util.readExactSubarray(bytes, read, read + 1088); read += mlkemCipherText.length;
|
|
12574
|
+
const C = new ECDHXSymmetricKey(); C.read(bytes.subarray(read));
|
|
12575
|
+
return { eccCipherText, mlkemCipherText, C }; // eccCipherText || mlkemCipherText || len(C) || C
|
|
12576
|
+
}
|
|
12133
12577
|
default:
|
|
12134
12578
|
throw new UnsupportedError('Unknown public key encryption algorithm.');
|
|
12135
12579
|
}
|
|
@@ -12149,9 +12593,21 @@ function serializeParams(algo, params) {
|
|
|
12149
12593
|
enums.publicKey.ed448,
|
|
12150
12594
|
enums.publicKey.x448,
|
|
12151
12595
|
enums.publicKey.aead,
|
|
12152
|
-
enums.publicKey.hmac
|
|
12596
|
+
enums.publicKey.hmac,
|
|
12597
|
+
enums.publicKey.pqc_mlkem_x25519,
|
|
12598
|
+
enums.publicKey.pqc_mldsa_ed25519
|
|
12153
12599
|
]);
|
|
12600
|
+
|
|
12601
|
+
const excludedFields = {
|
|
12602
|
+
[enums.publicKey.pqc_mlkem_x25519]: new Set(['mlkemSecretKey']), // only `mlkemSeed` is serialized
|
|
12603
|
+
[enums.publicKey.pqc_mldsa_ed25519]: new Set(['mldsaSecretKey']) // only `mldsaSeed` is serialized
|
|
12604
|
+
};
|
|
12605
|
+
|
|
12154
12606
|
const orderedParams = Object.keys(params).map(name => {
|
|
12607
|
+
if (excludedFields[algo]?.has(name)) {
|
|
12608
|
+
return new Uint8Array();
|
|
12609
|
+
}
|
|
12610
|
+
|
|
12155
12611
|
const param = params[name];
|
|
12156
12612
|
if (!util.isUint8Array(param)) return param.write();
|
|
12157
12613
|
return algosWithNativeRepresentation.has(algo) ? param : util.uint8ArrayToMPI(param);
|
|
@@ -12216,6 +12672,16 @@ async function generateParams(algo, bits, oid, symmetric) {
|
|
|
12216
12672
|
const keyMaterial = generateSessionKey$1(symmetric);
|
|
12217
12673
|
return createSymmetricParams(keyMaterial, new SymAlgoEnum(symmetric));
|
|
12218
12674
|
}
|
|
12675
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
12676
|
+
return publicKey.postQuantum.kem.generate(algo).then(({ eccSecretKey, eccPublicKey, mlkemSeed, mlkemSecretKey, mlkemPublicKey }) => ({
|
|
12677
|
+
privateParams: { eccSecretKey, mlkemSeed, mlkemSecretKey },
|
|
12678
|
+
publicParams: { eccPublicKey, mlkemPublicKey }
|
|
12679
|
+
}));
|
|
12680
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
12681
|
+
return publicKey.postQuantum.signature.generate(algo).then(({ eccSecretKey, eccPublicKey, mldsaSeed, mldsaSecretKey, mldsaPublicKey }) => ({
|
|
12682
|
+
privateParams: { eccSecretKey, mldsaSeed, mldsaSecretKey },
|
|
12683
|
+
publicParams: { eccPublicKey, mldsaPublicKey }
|
|
12684
|
+
}));
|
|
12219
12685
|
case enums.publicKey.dsa:
|
|
12220
12686
|
case enums.publicKey.elgamal:
|
|
12221
12687
|
throw new Error('Unsupported algorithm for key generation.');
|
|
@@ -12307,6 +12773,16 @@ async function validateParams(algo, publicParams, privateParams) {
|
|
|
12307
12773
|
return keySize === keyMaterial.length &&
|
|
12308
12774
|
util.equalsUint8Array(digest, await hash.sha256(hashSeed));
|
|
12309
12775
|
}
|
|
12776
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12777
|
+
const { eccSecretKey, mlkemSeed } = privateParams;
|
|
12778
|
+
const { eccPublicKey, mlkemPublicKey } = publicParams;
|
|
12779
|
+
return publicKey.postQuantum.kem.validateParams(algo, eccPublicKey, eccSecretKey, mlkemPublicKey, mlkemSeed);
|
|
12780
|
+
}
|
|
12781
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
12782
|
+
const { eccSecretKey, mldsaSeed } = privateParams;
|
|
12783
|
+
const { eccPublicKey, mldsaPublicKey } = publicParams;
|
|
12784
|
+
return publicKey.postQuantum.signature.validateParams(algo, eccPublicKey, eccSecretKey, mldsaPublicKey, mldsaSeed);
|
|
12785
|
+
}
|
|
12310
12786
|
default:
|
|
12311
12787
|
throw new Error('Unknown public key algorithm.');
|
|
12312
12788
|
}
|
|
@@ -15943,6 +16419,12 @@ class AEADEncryptedDataPacket {
|
|
|
15943
16419
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
15944
16420
|
|
|
15945
16421
|
|
|
16422
|
+
const algosWithV3CleartextSessionKeyAlgorithm = new Set([
|
|
16423
|
+
enums.publicKey.x25519,
|
|
16424
|
+
enums.publicKey.x448,
|
|
16425
|
+
enums.publicKey.pqc_mlkem_x25519
|
|
16426
|
+
]);
|
|
16427
|
+
|
|
15946
16428
|
/**
|
|
15947
16429
|
* Public-Key Encrypted Session Key Packets (Tag 1)
|
|
15948
16430
|
*
|
|
@@ -16050,7 +16532,7 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
16050
16532
|
}
|
|
16051
16533
|
this.publicKeyAlgorithm = bytes[offset++];
|
|
16052
16534
|
this.encrypted = mod.parseEncSessionKeyParams(this.publicKeyAlgorithm, bytes.subarray(offset));
|
|
16053
|
-
if (
|
|
16535
|
+
if (algosWithV3CleartextSessionKeyAlgorithm.has(this.publicKeyAlgorithm)) {
|
|
16054
16536
|
if (this.version === 3) {
|
|
16055
16537
|
this.sessionKeyAlgorithm = enums.write(enums.symmetric, this.encrypted.C.algorithm);
|
|
16056
16538
|
} else if (this.encrypted.C.algorithm !== null) {
|
|
@@ -16133,7 +16615,7 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
16133
16615
|
|
|
16134
16616
|
if (this.version === 3) {
|
|
16135
16617
|
// v3 Montgomery curves have cleartext cipher algo
|
|
16136
|
-
const hasEncryptedAlgo =
|
|
16618
|
+
const hasEncryptedAlgo = !algosWithV3CleartextSessionKeyAlgorithm.has(this.publicKeyAlgorithm);
|
|
16137
16619
|
this.sessionKeyAlgorithm = hasEncryptedAlgo ? sessionKeyAlgorithm : this.sessionKeyAlgorithm;
|
|
16138
16620
|
|
|
16139
16621
|
if (sessionKey.length !== mod.getCipherParams(this.sessionKeyAlgorithm).keySize) {
|
|
@@ -16160,6 +16642,7 @@ function encodeSessionKey(version, keyAlgo, cipherAlgo, sessionKeyData) {
|
|
|
16160
16642
|
]);
|
|
16161
16643
|
case enums.publicKey.x25519:
|
|
16162
16644
|
case enums.publicKey.x448:
|
|
16645
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
16163
16646
|
return sessionKeyData;
|
|
16164
16647
|
default:
|
|
16165
16648
|
throw new Error('Unsupported public key algorithm');
|
|
@@ -16208,6 +16691,7 @@ function decodeSessionKey(version, keyAlgo, decryptedData, randomSessionKey) {
|
|
|
16208
16691
|
}
|
|
16209
16692
|
case enums.publicKey.x25519:
|
|
16210
16693
|
case enums.publicKey.x448:
|
|
16694
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
16211
16695
|
return {
|
|
16212
16696
|
sessionKeyAlgorithm: null,
|
|
16213
16697
|
sessionKey: decryptedData
|
|
@@ -16573,6 +17057,14 @@ class PublicKeyPacket {
|
|
|
16573
17057
|
) {
|
|
16574
17058
|
throw new Error('Legacy curve25519 cannot be used with v6 keys');
|
|
16575
17059
|
}
|
|
17060
|
+
// The composite ML-DSA + EdDSA schemes MUST be used only with v6 keys.
|
|
17061
|
+
// The composite ML-KEM + ECDH schemes MUST be used only with v6 keys.
|
|
17062
|
+
if (this.version !== 6 && (
|
|
17063
|
+
this.algorithm === enums.publicKey.pqc_mldsa_ed25519 ||
|
|
17064
|
+
this.algorithm === enums.publicKey.pqc_mlkem_x25519
|
|
17065
|
+
)) {
|
|
17066
|
+
throw new Error('Unexpected key version: ML-DSA and ML-KEM algorithms can only be used with v6 keys');
|
|
17067
|
+
}
|
|
16576
17068
|
this.publicParams = publicParams;
|
|
16577
17069
|
pos += read;
|
|
16578
17070
|
|
|
@@ -17256,7 +17748,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17256
17748
|
}
|
|
17257
17749
|
}
|
|
17258
17750
|
try {
|
|
17259
|
-
const { read, privateParams } = mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
17751
|
+
const { read, privateParams } = await mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
17260
17752
|
if (read < cleartext.length) {
|
|
17261
17753
|
throw new Error('Error reading MPIs');
|
|
17262
17754
|
}
|
|
@@ -17514,7 +18006,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17514
18006
|
}
|
|
17515
18007
|
|
|
17516
18008
|
try {
|
|
17517
|
-
const { privateParams } = mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
18009
|
+
const { privateParams } = await mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
17518
18010
|
this.privateParams = privateParams;
|
|
17519
18011
|
} catch (err) {
|
|
17520
18012
|
throw new Error('Error reading MPIs');
|
|
@@ -17567,6 +18059,12 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17567
18059
|
)) {
|
|
17568
18060
|
throw new Error(`Cannot generate v6 keys of type 'ecc' with curve ${curve}. Generate a key of type 'curve25519' instead`);
|
|
17569
18061
|
}
|
|
18062
|
+
if (this.version !== 6 && (
|
|
18063
|
+
this.algorithm === enums.publicKey.pqc_mldsa_ed25519 ||
|
|
18064
|
+
this.algorithm === enums.publicKey.pqc_mlkem_x25519
|
|
18065
|
+
)) {
|
|
18066
|
+
throw new Error(`Cannot generate v${this.version} keys of type 'pqc'. Generate a v6 key instead`);
|
|
18067
|
+
}
|
|
17570
18068
|
const { privateParams, publicParams } = await mod.generateParams(this.algorithm, bits, curve, symmetric);
|
|
17571
18069
|
this.privateParams = privateParams;
|
|
17572
18070
|
this.publicParams = publicParams;
|
|
@@ -18069,6 +18567,12 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
18069
18567
|
* @async
|
|
18070
18568
|
*/
|
|
18071
18569
|
async function getPreferredHashAlgo(targetKeys, signingKeyPacket, date = new Date(), targetUserIDs = [], config) {
|
|
18570
|
+
if (signingKeyPacket.algorithm === enums.publicKey.pqc_mldsa_ed25519) {
|
|
18571
|
+
// For PQC, the returned hash algo MUST be set to the specified algorithm, see
|
|
18572
|
+
// https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
18573
|
+
return mod.publicKey.postQuantum.signature.getRequiredHashAlgo(signingKeyPacket.algorithm);
|
|
18574
|
+
}
|
|
18575
|
+
|
|
18072
18576
|
/**
|
|
18073
18577
|
* If `preferredSenderAlgo` appears in the prefs of all recipients, we pick it; otherwise, we use the
|
|
18074
18578
|
* strongest supported algo (`defaultAlgo` is always implicitly supported by all keys).
|
|
@@ -18355,6 +18859,13 @@ function sanitizeKeyOptions(options, subkeyDefaults = {}) {
|
|
|
18355
18859
|
}
|
|
18356
18860
|
|
|
18357
18861
|
switch (options.type) {
|
|
18862
|
+
case 'pqc':
|
|
18863
|
+
if (options.sign) {
|
|
18864
|
+
options.algorithm = enums.publicKey.pqc_mldsa_ed25519;
|
|
18865
|
+
} else {
|
|
18866
|
+
options.algorithm = enums.publicKey.pqc_mlkem_x25519;
|
|
18867
|
+
}
|
|
18868
|
+
break;
|
|
18358
18869
|
case 'ecc': // NB: this case also handles legacy eddsa and x25519 keys, based on `options.curve`
|
|
18359
18870
|
try {
|
|
18360
18871
|
options.curve = enums.write(enums.curve, options.curve);
|
|
@@ -18413,6 +18924,7 @@ function validateSigningKeyPacket(keyPacket, signature, config) {
|
|
|
18413
18924
|
case enums.publicKey.ed25519:
|
|
18414
18925
|
case enums.publicKey.ed448:
|
|
18415
18926
|
case enums.publicKey.hmac:
|
|
18927
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
18416
18928
|
if (!signature.keyFlags && !config.allowMissingKeyFlags) {
|
|
18417
18929
|
throw new Error('None of the key flags is set: consider passing `config.allowMissingKeyFlags`');
|
|
18418
18930
|
}
|
|
@@ -18432,6 +18944,7 @@ function validateEncryptionKeyPacket(keyPacket, signature, config) {
|
|
|
18432
18944
|
case enums.publicKey.x25519:
|
|
18433
18945
|
case enums.publicKey.x448:
|
|
18434
18946
|
case enums.publicKey.aead:
|
|
18947
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
18435
18948
|
if (!signature.keyFlags && !config.allowMissingKeyFlags) {
|
|
18436
18949
|
throw new Error('None of the key flags is set: consider passing `config.allowMissingKeyFlags`');
|
|
18437
18950
|
}
|
|
@@ -18454,7 +18967,8 @@ function validateDecryptionKeyPacket(keyPacket, signature, config) {
|
|
|
18454
18967
|
case enums.publicKey.elgamal:
|
|
18455
18968
|
case enums.publicKey.ecdh:
|
|
18456
18969
|
case enums.publicKey.x25519:
|
|
18457
|
-
case enums.publicKey.x448:
|
|
18970
|
+
case enums.publicKey.x448:
|
|
18971
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
18458
18972
|
const isValidSigningKeyPacket = !signature.keyFlags || (signature.keyFlags[0] & enums.keyFlags.signData) !== 0;
|
|
18459
18973
|
if (isValidSigningKeyPacket && config.allowInsecureDecryptionWithSigningKeys) {
|
|
18460
18974
|
// This is only relevant for RSA keys, all other signing algorithms cannot decrypt
|
|
@@ -20267,10 +20781,9 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
|
|
|
20267
20781
|
});
|
|
20268
20782
|
}
|
|
20269
20783
|
signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
|
|
20270
|
-
// prefer fast asm.js implementations (SHA-256)
|
|
20271
|
-
enums.hash.sha256,
|
|
20272
20784
|
enums.hash.sha512,
|
|
20273
|
-
|
|
20785
|
+
enums.hash.sha256,
|
|
20786
|
+
...(secretKeyPacket.version === 6 ? [enums.hash.sha3_512, enums.hash.sha3_256] : [])
|
|
20274
20787
|
], config.preferredHashAlgorithm);
|
|
20275
20788
|
signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
|
|
20276
20789
|
enums.compression.uncompressed,
|
|
@@ -22026,6 +22539,7 @@ async function decrypt({ message, decryptionKeys, passwords, sessionKeys, verifi
|
|
|
22026
22539
|
result.data,
|
|
22027
22540
|
fromAsync(async () => {
|
|
22028
22541
|
await util.anyPromise(result.signatures.map(sig => sig.verified));
|
|
22542
|
+
return format === 'binary' ? new Uint8Array() : '';
|
|
22029
22543
|
})
|
|
22030
22544
|
]);
|
|
22031
22545
|
}
|
|
@@ -22157,6 +22671,7 @@ async function verify({ message, verificationKeys, expectSigned = false, format
|
|
|
22157
22671
|
result.data,
|
|
22158
22672
|
fromAsync(async () => {
|
|
22159
22673
|
await util.anyPromise(result.signatures.map(sig => sig.verified));
|
|
22674
|
+
return format === 'binary' ? new Uint8Array() : '';
|
|
22160
22675
|
})
|
|
22161
22676
|
]);
|
|
22162
22677
|
}
|