@protontech/openpgp 6.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +619 -108
- 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 +2240 -618
- 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 +2240 -618
- package/dist/openpgp.js +2240 -618
- 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 +2240 -618
- package/openpgp.d.ts +3 -9
- package/package.json +5 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! OpenPGP.js v6.0.
|
|
1
|
+
/*! OpenPGP.js v6.0.1 - 2024-11-25 - 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.
|
|
1690
|
+
versionString: 'OpenPGP.js 6.0.1',
|
|
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 {
|
|
@@ -9287,7 +9292,7 @@ async function generate$4(algo) {
|
|
|
9287
9292
|
* }>} Signature of the message
|
|
9288
9293
|
* @async
|
|
9289
9294
|
*/
|
|
9290
|
-
async function sign$
|
|
9295
|
+
async function sign$9(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
9291
9296
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$2(algo))) {
|
|
9292
9297
|
// Enforce digest sizes:
|
|
9293
9298
|
// - Ed25519: https://www.rfc-editor.org/rfc/rfc9580.html#section-5.2.3.4-4
|
|
@@ -9337,7 +9342,7 @@ async function sign$6(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
9337
9342
|
* @returns {Boolean}
|
|
9338
9343
|
* @async
|
|
9339
9344
|
*/
|
|
9340
|
-
async function verify$
|
|
9345
|
+
async function verify$9(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
9341
9346
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$2(algo))) {
|
|
9342
9347
|
// Enforce digest sizes:
|
|
9343
9348
|
// - Ed25519: https://www.rfc-editor.org/rfc/rfc9580.html#section-5.2.3.4-4
|
|
@@ -9356,7 +9361,7 @@ async function verify$6(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
|
9356
9361
|
if (err.name !== 'NotSupportedError') {
|
|
9357
9362
|
throw err;
|
|
9358
9363
|
}
|
|
9359
|
-
return verify$
|
|
9364
|
+
return verify$a(RS, hashed, publicKey);
|
|
9360
9365
|
}
|
|
9361
9366
|
|
|
9362
9367
|
case enums.publicKey.ed448: {
|
|
@@ -9376,7 +9381,7 @@ async function verify$6(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
|
9376
9381
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
9377
9382
|
* @async
|
|
9378
9383
|
*/
|
|
9379
|
-
async function validateParams$
|
|
9384
|
+
async function validateParams$c(algo, A, seed) {
|
|
9380
9385
|
switch (algo) {
|
|
9381
9386
|
case enums.publicKey.ed25519: {
|
|
9382
9387
|
/**
|
|
@@ -9453,12 +9458,12 @@ const privateKeyToJWK = (algo, publicKey, privateKey) => {
|
|
|
9453
9458
|
|
|
9454
9459
|
var eddsa = /*#__PURE__*/Object.freeze({
|
|
9455
9460
|
__proto__: null,
|
|
9456
|
-
generate: generate$
|
|
9461
|
+
generate: generate$a,
|
|
9457
9462
|
getPayloadSize: getPayloadSize$1,
|
|
9458
9463
|
getPreferredHashAlgo: getPreferredHashAlgo$2,
|
|
9459
|
-
sign: sign$
|
|
9460
|
-
validateParams: validateParams$
|
|
9461
|
-
verify: verify$
|
|
9464
|
+
sign: sign$9,
|
|
9465
|
+
validateParams: validateParams$c,
|
|
9466
|
+
verify: verify$9
|
|
9462
9467
|
});
|
|
9463
9468
|
|
|
9464
9469
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -9589,7 +9594,7 @@ const HKDF_INFO = {
|
|
|
9589
9594
|
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
9590
9595
|
* @returns {Promise<{ A: Uint8Array, k: Uint8Array }>}
|
|
9591
9596
|
*/
|
|
9592
|
-
async function generate$
|
|
9597
|
+
async function generate$9(algo) {
|
|
9593
9598
|
switch (algo) {
|
|
9594
9599
|
case enums.publicKey.x25519: {
|
|
9595
9600
|
// k stays in little-endian, unlike legacy ECDH over curve25519
|
|
@@ -9617,7 +9622,7 @@ async function generate$3(algo) {
|
|
|
9617
9622
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
9618
9623
|
* @async
|
|
9619
9624
|
*/
|
|
9620
|
-
async function validateParams$
|
|
9625
|
+
async function validateParams$b(algo, A, k) {
|
|
9621
9626
|
switch (algo) {
|
|
9622
9627
|
case enums.publicKey.x25519: {
|
|
9623
9628
|
/**
|
|
@@ -9654,7 +9659,7 @@ async function validateParams$5(algo, A, k) {
|
|
|
9654
9659
|
* }>} ephemeral public key (K_A) and encrypted key
|
|
9655
9660
|
* @async
|
|
9656
9661
|
*/
|
|
9657
|
-
async function encrypt$
|
|
9662
|
+
async function encrypt$3(algo, data, recipientA) {
|
|
9658
9663
|
const { ephemeralPublicKey, sharedSecret } = await generateEphemeralEncryptionMaterial(algo, recipientA);
|
|
9659
9664
|
const hkdfInput = util.concatUint8Array([
|
|
9660
9665
|
ephemeralPublicKey,
|
|
@@ -9693,7 +9698,7 @@ async function encrypt$2(algo, data, recipientA) {
|
|
|
9693
9698
|
* @returns {Promise<Uint8Array>} decrypted session key data
|
|
9694
9699
|
* @async
|
|
9695
9700
|
*/
|
|
9696
|
-
async function decrypt$
|
|
9701
|
+
async function decrypt$3(algo, ephemeralPublicKey, wrappedKey, A, k) {
|
|
9697
9702
|
const sharedSecret = await recomputeSharedSecret(algo, ephemeralPublicKey, A, k);
|
|
9698
9703
|
const hkdfInput = util.concatUint8Array([
|
|
9699
9704
|
ephemeralPublicKey,
|
|
@@ -9794,13 +9799,13 @@ function assertNonZeroArray(sharedSecret) {
|
|
|
9794
9799
|
|
|
9795
9800
|
var ecdh_x = /*#__PURE__*/Object.freeze({
|
|
9796
9801
|
__proto__: null,
|
|
9797
|
-
decrypt: decrypt$
|
|
9798
|
-
encrypt: encrypt$
|
|
9799
|
-
generate: generate$
|
|
9802
|
+
decrypt: decrypt$3,
|
|
9803
|
+
encrypt: encrypt$3,
|
|
9804
|
+
generate: generate$9,
|
|
9800
9805
|
generateEphemeralEncryptionMaterial: generateEphemeralEncryptionMaterial,
|
|
9801
9806
|
getPayloadSize: getPayloadSize,
|
|
9802
9807
|
recomputeSharedSecret: recomputeSharedSecret,
|
|
9803
|
-
validateParams: validateParams$
|
|
9808
|
+
validateParams: validateParams$b
|
|
9804
9809
|
});
|
|
9805
9810
|
|
|
9806
9811
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -9976,7 +9981,7 @@ class CurveWithOID {
|
|
|
9976
9981
|
return nodeGenKeyPair(this.name);
|
|
9977
9982
|
case 'curve25519Legacy': {
|
|
9978
9983
|
// 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$
|
|
9984
|
+
const { k, A } = await generate$9(enums.publicKey.x25519);
|
|
9980
9985
|
const privateKey = k.slice().reverse();
|
|
9981
9986
|
privateKey[0] = (privateKey[0] & 127) | 64;
|
|
9982
9987
|
privateKey[31] &= 248;
|
|
@@ -9984,7 +9989,7 @@ class CurveWithOID {
|
|
|
9984
9989
|
return { publicKey, privateKey };
|
|
9985
9990
|
}
|
|
9986
9991
|
case 'ed25519Legacy': {
|
|
9987
|
-
const { seed: privateKey, A } = await generate$
|
|
9992
|
+
const { seed: privateKey, A } = await generate$a(enums.publicKey.ed25519);
|
|
9988
9993
|
const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), A]);
|
|
9989
9994
|
return { publicKey, privateKey };
|
|
9990
9995
|
}
|
|
@@ -9994,7 +9999,7 @@ class CurveWithOID {
|
|
|
9994
9999
|
}
|
|
9995
10000
|
}
|
|
9996
10001
|
|
|
9997
|
-
async function generate$
|
|
10002
|
+
async function generate$8(curveName) {
|
|
9998
10003
|
const curve = new CurveWithOID(curveName);
|
|
9999
10004
|
const { oid, hash, cipher } = curve;
|
|
10000
10005
|
const keyPair = await curve.genKeyPair();
|
|
@@ -10212,7 +10217,7 @@ const nodeCrypto$2 = util.getNodeCrypto();
|
|
|
10212
10217
|
* }>} Signature of the message
|
|
10213
10218
|
* @async
|
|
10214
10219
|
*/
|
|
10215
|
-
async function sign$
|
|
10220
|
+
async function sign$8(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
10216
10221
|
const curve = new CurveWithOID(oid);
|
|
10217
10222
|
checkPublicPointEnconding(curve, publicKey);
|
|
10218
10223
|
if (message && !util.isStream(message)) {
|
|
@@ -10259,7 +10264,7 @@ async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
10259
10264
|
* @returns {Boolean}
|
|
10260
10265
|
* @async
|
|
10261
10266
|
*/
|
|
10262
|
-
async function verify$
|
|
10267
|
+
async function verify$8(oid, hashAlgo, signature, message, publicKey, hashed) {
|
|
10263
10268
|
const curve = new CurveWithOID(oid);
|
|
10264
10269
|
checkPublicPointEnconding(curve, publicKey);
|
|
10265
10270
|
// See https://github.com/openpgpjs/openpgpjs/pull/948.
|
|
@@ -10310,7 +10315,7 @@ async function verify$5(oid, hashAlgo, signature, message, publicKey, hashed) {
|
|
|
10310
10315
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
10311
10316
|
* @async
|
|
10312
10317
|
*/
|
|
10313
|
-
async function validateParams$
|
|
10318
|
+
async function validateParams$a(oid, Q, d) {
|
|
10314
10319
|
const curve = new CurveWithOID(oid);
|
|
10315
10320
|
// Reject curves x25519 and ed25519
|
|
10316
10321
|
if (curve.keyType !== enums.publicKey.ecdsa) {
|
|
@@ -10326,9 +10331,9 @@ async function validateParams$4(oid, Q, d) {
|
|
|
10326
10331
|
const hashAlgo = enums.hash.sha256;
|
|
10327
10332
|
const hashed = await hash.digest(hashAlgo, message);
|
|
10328
10333
|
try {
|
|
10329
|
-
const signature = await sign$
|
|
10334
|
+
const signature = await sign$8(oid, hashAlgo, message, Q, d, hashed);
|
|
10330
10335
|
// eslint-disable-next-line @typescript-eslint/return-await
|
|
10331
|
-
return await verify$
|
|
10336
|
+
return await verify$8(oid, hashAlgo, signature, message, Q, hashed);
|
|
10332
10337
|
} catch (err) {
|
|
10333
10338
|
return false;
|
|
10334
10339
|
}
|
|
@@ -10459,9 +10464,9 @@ async function nodeVerify(curve, hashAlgo, { r, s }, message, publicKey) {
|
|
|
10459
10464
|
|
|
10460
10465
|
var ecdsa = /*#__PURE__*/Object.freeze({
|
|
10461
10466
|
__proto__: null,
|
|
10462
|
-
sign: sign$
|
|
10463
|
-
validateParams: validateParams$
|
|
10464
|
-
verify: verify$
|
|
10467
|
+
sign: sign$8,
|
|
10468
|
+
validateParams: validateParams$a,
|
|
10469
|
+
verify: verify$8
|
|
10465
10470
|
});
|
|
10466
10471
|
|
|
10467
10472
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -10496,7 +10501,7 @@ var ecdsa = /*#__PURE__*/Object.freeze({
|
|
|
10496
10501
|
* }>} Signature of the message
|
|
10497
10502
|
* @async
|
|
10498
10503
|
*/
|
|
10499
|
-
async function sign$
|
|
10504
|
+
async function sign$7(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
10500
10505
|
const curve = new CurveWithOID(oid);
|
|
10501
10506
|
checkPublicPointEnconding(curve, publicKey);
|
|
10502
10507
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
@@ -10505,7 +10510,7 @@ async function sign$4(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
10505
10510
|
// and https://www.rfc-editor.org/rfc/rfc9580.html#section-5.2.3.3-3
|
|
10506
10511
|
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
10507
10512
|
}
|
|
10508
|
-
const { RS: signature } = await sign$
|
|
10513
|
+
const { RS: signature } = await sign$9(enums.publicKey.ed25519, hashAlgo, message, publicKey.subarray(1), privateKey, hashed);
|
|
10509
10514
|
// EdDSA signature params are returned in little-endian format
|
|
10510
10515
|
return {
|
|
10511
10516
|
r: signature.subarray(0, 32),
|
|
@@ -10525,7 +10530,7 @@ async function sign$4(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
10525
10530
|
* @returns {Boolean}
|
|
10526
10531
|
* @async
|
|
10527
10532
|
*/
|
|
10528
|
-
async function verify$
|
|
10533
|
+
async function verify$7(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
10529
10534
|
const curve = new CurveWithOID(oid);
|
|
10530
10535
|
checkPublicPointEnconding(curve, publicKey);
|
|
10531
10536
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
@@ -10535,7 +10540,7 @@ async function verify$4(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
|
10535
10540
|
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
10536
10541
|
}
|
|
10537
10542
|
const RS = util.concatUint8Array([r, s]);
|
|
10538
|
-
return verify$
|
|
10543
|
+
return verify$9(enums.publicKey.ed25519, hashAlgo, { RS }, m, publicKey.subarray(1), hashed);
|
|
10539
10544
|
}
|
|
10540
10545
|
/**
|
|
10541
10546
|
* Validate legacy EdDSA parameters
|
|
@@ -10545,7 +10550,7 @@ async function verify$4(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
|
10545
10550
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
10546
10551
|
* @async
|
|
10547
10552
|
*/
|
|
10548
|
-
async function validateParams$
|
|
10553
|
+
async function validateParams$9(oid, Q, k) {
|
|
10549
10554
|
// Check whether the given curve is supported
|
|
10550
10555
|
if (oid.getName() !== enums.curve.ed25519Legacy) {
|
|
10551
10556
|
return false;
|
|
@@ -10563,9 +10568,9 @@ async function validateParams$3(oid, Q, k) {
|
|
|
10563
10568
|
|
|
10564
10569
|
var eddsa_legacy = /*#__PURE__*/Object.freeze({
|
|
10565
10570
|
__proto__: null,
|
|
10566
|
-
sign: sign$
|
|
10567
|
-
validateParams: validateParams$
|
|
10568
|
-
verify: verify$
|
|
10571
|
+
sign: sign$7,
|
|
10572
|
+
validateParams: validateParams$9,
|
|
10573
|
+
verify: verify$7
|
|
10569
10574
|
});
|
|
10570
10575
|
|
|
10571
10576
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -10660,7 +10665,7 @@ const nodeCrypto$1 = util.getNodeCrypto();
|
|
|
10660
10665
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
10661
10666
|
* @async
|
|
10662
10667
|
*/
|
|
10663
|
-
async function validateParams$
|
|
10668
|
+
async function validateParams$8(oid, Q, d) {
|
|
10664
10669
|
return validateStandardParams(enums.publicKey.ecdh, oid, Q, d);
|
|
10665
10670
|
}
|
|
10666
10671
|
|
|
@@ -10743,7 +10748,7 @@ async function genPublicEphemeralKey(curve, Q) {
|
|
|
10743
10748
|
* @returns {Promise<{publicKey: Uint8Array, wrappedKey: Uint8Array}>}
|
|
10744
10749
|
* @async
|
|
10745
10750
|
*/
|
|
10746
|
-
async function encrypt$
|
|
10751
|
+
async function encrypt$2(oid, kdfParams, data, Q, fingerprint) {
|
|
10747
10752
|
const m = encode(data);
|
|
10748
10753
|
|
|
10749
10754
|
const curve = new CurveWithOID(oid);
|
|
@@ -10808,7 +10813,7 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
|
|
|
10808
10813
|
* @returns {Promise<Uint8Array>} Value derived from session key.
|
|
10809
10814
|
* @async
|
|
10810
10815
|
*/
|
|
10811
|
-
async function decrypt$
|
|
10816
|
+
async function decrypt$2(oid, kdfParams, V, C, Q, d, fingerprint) {
|
|
10812
10817
|
const curve = new CurveWithOID(oid);
|
|
10813
10818
|
checkPublicPointEnconding(curve, Q);
|
|
10814
10819
|
checkPublicPointEnconding(curve, V);
|
|
@@ -10982,9 +10987,9 @@ async function nodePublicEphemeralKey(curve, Q) {
|
|
|
10982
10987
|
|
|
10983
10988
|
var ecdh = /*#__PURE__*/Object.freeze({
|
|
10984
10989
|
__proto__: null,
|
|
10985
|
-
decrypt: decrypt$
|
|
10986
|
-
encrypt: encrypt$
|
|
10987
|
-
validateParams: validateParams$
|
|
10990
|
+
decrypt: decrypt$2,
|
|
10991
|
+
encrypt: encrypt$2,
|
|
10992
|
+
validateParams: validateParams$8
|
|
10988
10993
|
});
|
|
10989
10994
|
|
|
10990
10995
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -11012,7 +11017,7 @@ var elliptic = /*#__PURE__*/Object.freeze({
|
|
|
11012
11017
|
ecdsa: ecdsa,
|
|
11013
11018
|
eddsa: eddsa,
|
|
11014
11019
|
eddsaLegacy: eddsa_legacy,
|
|
11015
|
-
generate: generate$
|
|
11020
|
+
generate: generate$8,
|
|
11016
11021
|
getPreferredHashAlgo: getPreferredHashAlgo$1
|
|
11017
11022
|
});
|
|
11018
11023
|
|
|
@@ -11054,7 +11059,7 @@ const _1n = BigInt(1);
|
|
|
11054
11059
|
* @returns {Promise<{ r: Uint8Array, s: Uint8Array }>}
|
|
11055
11060
|
* @async
|
|
11056
11061
|
*/
|
|
11057
|
-
async function sign$
|
|
11062
|
+
async function sign$6(hashAlgo, hashed, g, p, q, x) {
|
|
11058
11063
|
const _0n = BigInt(0);
|
|
11059
11064
|
p = uint8ArrayToBigInt(p);
|
|
11060
11065
|
q = uint8ArrayToBigInt(q);
|
|
@@ -11112,7 +11117,7 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
|
|
|
11112
11117
|
* @returns {boolean}
|
|
11113
11118
|
* @async
|
|
11114
11119
|
*/
|
|
11115
|
-
async function verify$
|
|
11120
|
+
async function verify$6(hashAlgo, r, s, hashed, g, p, q, y) {
|
|
11116
11121
|
r = uint8ArrayToBigInt(r);
|
|
11117
11122
|
s = uint8ArrayToBigInt(s);
|
|
11118
11123
|
|
|
@@ -11153,7 +11158,7 @@ async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
|
|
|
11153
11158
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
11154
11159
|
* @async
|
|
11155
11160
|
*/
|
|
11156
|
-
async function validateParams$
|
|
11161
|
+
async function validateParams$7(p, q, g, y, x) {
|
|
11157
11162
|
p = uint8ArrayToBigInt(p);
|
|
11158
11163
|
q = uint8ArrayToBigInt(q);
|
|
11159
11164
|
g = uint8ArrayToBigInt(g);
|
|
@@ -11206,9 +11211,9 @@ async function validateParams$1(p, q, g, y, x) {
|
|
|
11206
11211
|
|
|
11207
11212
|
var dsa = /*#__PURE__*/Object.freeze({
|
|
11208
11213
|
__proto__: null,
|
|
11209
|
-
sign: sign$
|
|
11210
|
-
validateParams: validateParams$
|
|
11211
|
-
verify: verify$
|
|
11214
|
+
sign: sign$6,
|
|
11215
|
+
validateParams: validateParams$7,
|
|
11216
|
+
verify: verify$6
|
|
11212
11217
|
});
|
|
11213
11218
|
|
|
11214
11219
|
const supportedHashAlgos = new Set([enums.hash.sha1, enums.hash.sha256, enums.hash.sha512]);
|
|
@@ -11216,7 +11221,7 @@ const supportedHashAlgos = new Set([enums.hash.sha1, enums.hash.sha256, enums.ha
|
|
|
11216
11221
|
const webCrypto = util.getWebCrypto();
|
|
11217
11222
|
const nodeCrypto = util.getNodeCrypto();
|
|
11218
11223
|
|
|
11219
|
-
async function generate$
|
|
11224
|
+
async function generate$7(hashAlgo) {
|
|
11220
11225
|
if (!supportedHashAlgos.has(hashAlgo)) {
|
|
11221
11226
|
throw new Error('Unsupported hash algorithm.');
|
|
11222
11227
|
}
|
|
@@ -11235,7 +11240,7 @@ async function generate$1(hashAlgo) {
|
|
|
11235
11240
|
return new Uint8Array(exportedKey);
|
|
11236
11241
|
}
|
|
11237
11242
|
|
|
11238
|
-
async function sign$
|
|
11243
|
+
async function sign$5(hashAlgo, key, data) {
|
|
11239
11244
|
if (!supportedHashAlgos.has(hashAlgo)) {
|
|
11240
11245
|
throw new Error('Unsupported hash algorithm.');
|
|
11241
11246
|
}
|
|
@@ -11256,7 +11261,7 @@ async function sign$2(hashAlgo, key, data) {
|
|
|
11256
11261
|
return new Uint8Array(mac);
|
|
11257
11262
|
}
|
|
11258
11263
|
|
|
11259
|
-
async function verify$
|
|
11264
|
+
async function verify$5(hashAlgo, key, mac, data) {
|
|
11260
11265
|
if (!supportedHashAlgos.has(hashAlgo)) {
|
|
11261
11266
|
throw new Error('Unsupported hash algorithm.');
|
|
11262
11267
|
}
|
|
@@ -11277,12 +11282,390 @@ async function verify$2(hashAlgo, key, mac, data) {
|
|
|
11277
11282
|
}
|
|
11278
11283
|
|
|
11279
11284
|
var hmac = /*#__PURE__*/Object.freeze({
|
|
11285
|
+
__proto__: null,
|
|
11286
|
+
generate: generate$7,
|
|
11287
|
+
sign: sign$5,
|
|
11288
|
+
verify: verify$5
|
|
11289
|
+
});
|
|
11290
|
+
|
|
11291
|
+
async function generate$6(algo) {
|
|
11292
|
+
switch (algo) {
|
|
11293
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11294
|
+
const { A, k } = await generate$9(enums.publicKey.x25519);
|
|
11295
|
+
return {
|
|
11296
|
+
eccPublicKey: A,
|
|
11297
|
+
eccSecretKey: k
|
|
11298
|
+
};
|
|
11299
|
+
}
|
|
11300
|
+
default:
|
|
11301
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11302
|
+
}
|
|
11303
|
+
}
|
|
11304
|
+
|
|
11305
|
+
async function encaps$1(eccAlgo, eccRecipientPublicKey) {
|
|
11306
|
+
switch (eccAlgo) {
|
|
11307
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11308
|
+
const { ephemeralPublicKey: eccCipherText, sharedSecret: eccSharedSecret } = await generateEphemeralEncryptionMaterial(enums.publicKey.x25519, eccRecipientPublicKey);
|
|
11309
|
+
const eccKeyShare = await hash.sha3_256(util.concatUint8Array([
|
|
11310
|
+
eccSharedSecret,
|
|
11311
|
+
eccCipherText,
|
|
11312
|
+
eccRecipientPublicKey
|
|
11313
|
+
]));
|
|
11314
|
+
return {
|
|
11315
|
+
eccCipherText,
|
|
11316
|
+
eccKeyShare
|
|
11317
|
+
};
|
|
11318
|
+
}
|
|
11319
|
+
default:
|
|
11320
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11321
|
+
}
|
|
11322
|
+
}
|
|
11323
|
+
|
|
11324
|
+
async function decaps$1(eccAlgo, eccCipherText, eccSecretKey, eccPublicKey) {
|
|
11325
|
+
switch (eccAlgo) {
|
|
11326
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11327
|
+
const eccSharedSecret = await recomputeSharedSecret(enums.publicKey.x25519, eccCipherText, eccPublicKey, eccSecretKey);
|
|
11328
|
+
const eccKeyShare = await hash.sha3_256(util.concatUint8Array([
|
|
11329
|
+
eccSharedSecret,
|
|
11330
|
+
eccCipherText,
|
|
11331
|
+
eccPublicKey
|
|
11332
|
+
]));
|
|
11333
|
+
return eccKeyShare;
|
|
11334
|
+
}
|
|
11335
|
+
default:
|
|
11336
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11337
|
+
}
|
|
11338
|
+
}
|
|
11339
|
+
|
|
11340
|
+
async function validateParams$6(algo, eccPublicKey, eccSecretKey) {
|
|
11341
|
+
switch (algo) {
|
|
11342
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
11343
|
+
return validateParams$b(enums.publicKey.x25519, eccPublicKey, eccSecretKey);
|
|
11344
|
+
default:
|
|
11345
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11346
|
+
}
|
|
11347
|
+
}
|
|
11348
|
+
|
|
11349
|
+
async function generate$5(algo) {
|
|
11350
|
+
switch (algo) {
|
|
11351
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11352
|
+
const mlkemSeed = getRandomBytes(64);
|
|
11353
|
+
const { mlkemSecretKey, mlkemPublicKey } = await expandSecretSeed$1(algo, mlkemSeed);
|
|
11354
|
+
|
|
11355
|
+
return { mlkemSeed, mlkemSecretKey, mlkemPublicKey };
|
|
11356
|
+
}
|
|
11357
|
+
default:
|
|
11358
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11359
|
+
}
|
|
11360
|
+
}
|
|
11361
|
+
|
|
11362
|
+
/**
|
|
11363
|
+
* Expand ML-KEM secret seed and retrieve the secret and public key material
|
|
11364
|
+
* @param {module:enums.publicKey} algo - Public key algorithm
|
|
11365
|
+
* @param {Uint8Array} seed - secret seed to expand
|
|
11366
|
+
* @returns {Promise<{ mlkemPublicKey: Uint8Array, mlkemSecretKey: Uint8Array }>}
|
|
11367
|
+
*/
|
|
11368
|
+
async function expandSecretSeed$1(algo, seed) {
|
|
11369
|
+
switch (algo) {
|
|
11370
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11371
|
+
const { ml_kem768 } = await import('./noble_post_quantum.mjs');
|
|
11372
|
+
const { publicKey: encapsulationKey, secretKey: decapsulationKey } = ml_kem768.keygen(seed);
|
|
11373
|
+
|
|
11374
|
+
return { mlkemPublicKey: encapsulationKey, mlkemSecretKey: decapsulationKey };
|
|
11375
|
+
}
|
|
11376
|
+
default:
|
|
11377
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11378
|
+
}
|
|
11379
|
+
}
|
|
11380
|
+
|
|
11381
|
+
async function encaps(algo, mlkemRecipientPublicKey) {
|
|
11382
|
+
switch (algo) {
|
|
11383
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11384
|
+
const { ml_kem768 } = await import('./noble_post_quantum.mjs');
|
|
11385
|
+
const { cipherText: mlkemCipherText, sharedSecret: mlkemKeyShare } = ml_kem768.encapsulate(mlkemRecipientPublicKey);
|
|
11386
|
+
|
|
11387
|
+
return { mlkemCipherText, mlkemKeyShare };
|
|
11388
|
+
}
|
|
11389
|
+
default:
|
|
11390
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11391
|
+
}
|
|
11392
|
+
}
|
|
11393
|
+
|
|
11394
|
+
async function decaps(algo, mlkemCipherText, mlkemSecretKey) {
|
|
11395
|
+
switch (algo) {
|
|
11396
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11397
|
+
const { ml_kem768 } = await import('./noble_post_quantum.mjs');
|
|
11398
|
+
const mlkemKeyShare = ml_kem768.decapsulate(mlkemCipherText, mlkemSecretKey);
|
|
11399
|
+
|
|
11400
|
+
return mlkemKeyShare;
|
|
11401
|
+
}
|
|
11402
|
+
default:
|
|
11403
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
|
|
11407
|
+
async function validateParams$5(algo, mlkemPublicKey, mlkemSeed) {
|
|
11408
|
+
switch (algo) {
|
|
11409
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
11410
|
+
const { mlkemPublicKey: expectedPublicKey } = await expandSecretSeed$1(algo, mlkemSeed);
|
|
11411
|
+
return util.equalsUint8Array(mlkemPublicKey, expectedPublicKey);
|
|
11412
|
+
}
|
|
11413
|
+
default:
|
|
11414
|
+
throw new Error('Unsupported KEM algorithm');
|
|
11415
|
+
}
|
|
11416
|
+
}
|
|
11417
|
+
|
|
11418
|
+
async function generate$4(algo) {
|
|
11419
|
+
const { eccPublicKey, eccSecretKey } = await generate$6(algo);
|
|
11420
|
+
const { mlkemPublicKey, mlkemSeed, mlkemSecretKey } = await generate$5(algo);
|
|
11421
|
+
|
|
11422
|
+
return { eccPublicKey, eccSecretKey, mlkemPublicKey, mlkemSeed, mlkemSecretKey };
|
|
11423
|
+
}
|
|
11424
|
+
|
|
11425
|
+
async function encrypt$1(algo, eccPublicKey, mlkemPublicKey, sessioneKeyData) {
|
|
11426
|
+
const { eccKeyShare, eccCipherText } = await encaps$1(algo, eccPublicKey);
|
|
11427
|
+
const { mlkemKeyShare, mlkemCipherText } = await encaps(algo, mlkemPublicKey);
|
|
11428
|
+
const kek = await multiKeyCombine(algo, eccKeyShare, eccCipherText, eccPublicKey, mlkemKeyShare, mlkemCipherText, mlkemPublicKey);
|
|
11429
|
+
const wrappedKey = await wrap(enums.symmetric.aes256, kek, sessioneKeyData); // C
|
|
11430
|
+
return { eccCipherText, mlkemCipherText, wrappedKey };
|
|
11431
|
+
}
|
|
11432
|
+
|
|
11433
|
+
async function decrypt$1(algo, eccCipherText, mlkemCipherText, eccSecretKey, eccPublicKey, mlkemSecretKey, mlkemPublicKey, encryptedSessionKeyData) {
|
|
11434
|
+
const eccKeyShare = await decaps$1(algo, eccCipherText, eccSecretKey, eccPublicKey);
|
|
11435
|
+
const mlkemKeyShare = await decaps(algo, mlkemCipherText, mlkemSecretKey);
|
|
11436
|
+
const kek = await multiKeyCombine(algo, eccKeyShare, eccCipherText, eccPublicKey, mlkemKeyShare, mlkemCipherText, mlkemPublicKey);
|
|
11437
|
+
const sessionKey = await unwrap(enums.symmetric.aes256, kek, encryptedSessionKeyData);
|
|
11438
|
+
return sessionKey;
|
|
11439
|
+
}
|
|
11440
|
+
|
|
11441
|
+
async function multiKeyCombine(algo, ecdhKeyShare, ecdhCipherText, ecdhPublicKey, mlkemKeyShare, mlkemCipherText, mlkemPublicKey) {
|
|
11442
|
+
// LAMPS-aligned and NIST compatible combiner, proposed in: https://mailarchive.ietf.org/arch/msg/openpgp/NMTCy707LICtxIhP3Xt1U5C8MF0/
|
|
11443
|
+
// 2a. KDF(mlkemSS || tradSS || tradCT || tradPK || Domain)
|
|
11444
|
+
// where Domain is "Domain" for LAMPS, and "mlkemCT || mlkemPK || algId" for OpenPGP
|
|
11445
|
+
const encData = util.concatUint8Array([
|
|
11446
|
+
mlkemKeyShare,
|
|
11447
|
+
ecdhKeyShare,
|
|
11448
|
+
ecdhCipherText,
|
|
11449
|
+
ecdhPublicKey,
|
|
11450
|
+
// domSep
|
|
11451
|
+
mlkemCipherText,
|
|
11452
|
+
mlkemPublicKey,
|
|
11453
|
+
new Uint8Array([algo])
|
|
11454
|
+
]);
|
|
11455
|
+
|
|
11456
|
+
const kek = await hash.digest(enums.hash.sha3_256, encData);
|
|
11457
|
+
return kek;
|
|
11458
|
+
}
|
|
11459
|
+
|
|
11460
|
+
async function validateParams$4(algo, eccPublicKey, eccSecretKey, mlkemPublicKey, mlkemSeed) {
|
|
11461
|
+
const eccValidationPromise = validateParams$6(algo, eccPublicKey, eccSecretKey);
|
|
11462
|
+
const mlkemValidationPromise = validateParams$5(algo, mlkemPublicKey, mlkemSeed);
|
|
11463
|
+
const valid = await eccValidationPromise && await mlkemValidationPromise;
|
|
11464
|
+
return valid;
|
|
11465
|
+
}
|
|
11466
|
+
|
|
11467
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
11468
|
+
__proto__: null,
|
|
11469
|
+
decrypt: decrypt$1,
|
|
11470
|
+
encrypt: encrypt$1,
|
|
11471
|
+
generate: generate$4,
|
|
11472
|
+
mlkemExpandSecretSeed: expandSecretSeed$1,
|
|
11473
|
+
validateParams: validateParams$4
|
|
11474
|
+
});
|
|
11475
|
+
|
|
11476
|
+
async function generate$3(algo) {
|
|
11477
|
+
switch (algo) {
|
|
11478
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11479
|
+
const mldsaSeed = getRandomBytes(32);
|
|
11480
|
+
const { mldsaSecretKey, mldsaPublicKey } = await expandSecretSeed(algo, mldsaSeed);
|
|
11481
|
+
|
|
11482
|
+
return { mldsaSeed, mldsaSecretKey, mldsaPublicKey };
|
|
11483
|
+
}
|
|
11484
|
+
default:
|
|
11485
|
+
throw new Error('Unsupported signature algorithm');
|
|
11486
|
+
}
|
|
11487
|
+
}
|
|
11488
|
+
|
|
11489
|
+
/**
|
|
11490
|
+
* Expand ML-DSA secret seed and retrieve the secret and public key material
|
|
11491
|
+
* @param {module:enums.publicKey} algo - Public key algorithm
|
|
11492
|
+
* @param {Uint8Array} seed - secret seed to expand
|
|
11493
|
+
* @returns {Promise<{ mldsaPublicKey: Uint8Array, mldsaSecretKey: Uint8Array }>}
|
|
11494
|
+
*/
|
|
11495
|
+
async function expandSecretSeed(algo, seed) {
|
|
11496
|
+
switch (algo) {
|
|
11497
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11498
|
+
const { ml_dsa65 } = await import('./noble_post_quantum.mjs');
|
|
11499
|
+
const { secretKey: mldsaSecretKey, publicKey: mldsaPublicKey } = ml_dsa65.keygen(seed);
|
|
11500
|
+
|
|
11501
|
+
return { mldsaSecretKey, mldsaPublicKey };
|
|
11502
|
+
}
|
|
11503
|
+
default:
|
|
11504
|
+
throw new Error('Unsupported signature algorithm');
|
|
11505
|
+
}
|
|
11506
|
+
}
|
|
11507
|
+
|
|
11508
|
+
async function sign$4(algo, mldsaSecretKey, dataDigest) {
|
|
11509
|
+
switch (algo) {
|
|
11510
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11511
|
+
const { ml_dsa65 } = await import('./noble_post_quantum.mjs');
|
|
11512
|
+
const mldsaSignature = ml_dsa65.sign(mldsaSecretKey, dataDigest);
|
|
11513
|
+
return { mldsaSignature };
|
|
11514
|
+
}
|
|
11515
|
+
default:
|
|
11516
|
+
throw new Error('Unsupported signature algorithm');
|
|
11517
|
+
}
|
|
11518
|
+
}
|
|
11519
|
+
|
|
11520
|
+
async function verify$4(algo, mldsaPublicKey, dataDigest, mldsaSignature) {
|
|
11521
|
+
switch (algo) {
|
|
11522
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11523
|
+
const { ml_dsa65 } = await import('./noble_post_quantum.mjs');
|
|
11524
|
+
return ml_dsa65.verify(mldsaPublicKey, dataDigest, mldsaSignature);
|
|
11525
|
+
}
|
|
11526
|
+
default:
|
|
11527
|
+
throw new Error('Unsupported signature algorithm');
|
|
11528
|
+
}
|
|
11529
|
+
}
|
|
11530
|
+
|
|
11531
|
+
async function validateParams$3(algo, mldsaPublicKey, mldsaSeed) {
|
|
11532
|
+
switch (algo) {
|
|
11533
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11534
|
+
const { mldsaPublicKey: expectedPublicKey } = await expandSecretSeed(algo, mldsaSeed);
|
|
11535
|
+
return util.equalsUint8Array(mldsaPublicKey, expectedPublicKey);
|
|
11536
|
+
}
|
|
11537
|
+
default:
|
|
11538
|
+
throw new Error('Unsupported signature algorithm');
|
|
11539
|
+
}
|
|
11540
|
+
}
|
|
11541
|
+
|
|
11542
|
+
async function generate$2(algo) {
|
|
11543
|
+
switch (algo) {
|
|
11544
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11545
|
+
const { A, seed } = await generate$a(enums.publicKey.ed25519);
|
|
11546
|
+
return {
|
|
11547
|
+
eccPublicKey: A,
|
|
11548
|
+
eccSecretKey: seed
|
|
11549
|
+
};
|
|
11550
|
+
}
|
|
11551
|
+
default:
|
|
11552
|
+
throw new Error('Unsupported signature algorithm');
|
|
11553
|
+
}
|
|
11554
|
+
}
|
|
11555
|
+
|
|
11556
|
+
async function sign$3(signatureAlgo, hashAlgo, eccSecretKey, eccPublicKey, dataDigest) {
|
|
11557
|
+
switch (signatureAlgo) {
|
|
11558
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11559
|
+
const { RS: eccSignature } = await sign$9(enums.publicKey.ed25519, hashAlgo, null, eccPublicKey, eccSecretKey, dataDigest);
|
|
11560
|
+
|
|
11561
|
+
return { eccSignature };
|
|
11562
|
+
}
|
|
11563
|
+
default:
|
|
11564
|
+
throw new Error('Unsupported signature algorithm');
|
|
11565
|
+
}
|
|
11566
|
+
}
|
|
11567
|
+
|
|
11568
|
+
async function verify$3(signatureAlgo, hashAlgo, eccPublicKey, dataDigest, eccSignature) {
|
|
11569
|
+
switch (signatureAlgo) {
|
|
11570
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
11571
|
+
return verify$9(enums.publicKey.ed25519, hashAlgo, { RS: eccSignature }, null, eccPublicKey, dataDigest);
|
|
11572
|
+
default:
|
|
11573
|
+
throw new Error('Unsupported signature algorithm');
|
|
11574
|
+
}
|
|
11575
|
+
}
|
|
11576
|
+
|
|
11577
|
+
async function validateParams$2(algo, eccPublicKey, eccSecretKey) {
|
|
11578
|
+
switch (algo) {
|
|
11579
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
11580
|
+
return validateParams$c(enums.publicKey.ed25519, eccPublicKey, eccSecretKey);
|
|
11581
|
+
default:
|
|
11582
|
+
throw new Error('Unsupported signature algorithm');
|
|
11583
|
+
}
|
|
11584
|
+
}
|
|
11585
|
+
|
|
11586
|
+
async function generate$1(algo) {
|
|
11587
|
+
switch (algo) {
|
|
11588
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11589
|
+
const { eccSecretKey, eccPublicKey } = await generate$2(algo);
|
|
11590
|
+
const { mldsaSeed, mldsaSecretKey, mldsaPublicKey } = await generate$3(algo);
|
|
11591
|
+
return { eccSecretKey, eccPublicKey, mldsaSeed, mldsaSecretKey, mldsaPublicKey };
|
|
11592
|
+
}
|
|
11593
|
+
default:
|
|
11594
|
+
throw new Error('Unsupported signature algorithm');
|
|
11595
|
+
}
|
|
11596
|
+
}
|
|
11597
|
+
|
|
11598
|
+
async function sign$2(signatureAlgo, hashAlgo, eccSecretKey, eccPublicKey, mldsaSecretKey, dataDigest) {
|
|
11599
|
+
if (hashAlgo !== getRequiredHashAlgo(signatureAlgo)) {
|
|
11600
|
+
// The signature hash algo MUST be set to the specified algorithm, see
|
|
11601
|
+
// https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
11602
|
+
throw new Error('Unexpected hash algorithm for PQC signature');
|
|
11603
|
+
}
|
|
11604
|
+
|
|
11605
|
+
switch (signatureAlgo) {
|
|
11606
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11607
|
+
const { eccSignature } = await sign$3(signatureAlgo, hashAlgo, eccSecretKey, eccPublicKey, dataDigest);
|
|
11608
|
+
const { mldsaSignature } = await sign$4(signatureAlgo, mldsaSecretKey, dataDigest);
|
|
11609
|
+
|
|
11610
|
+
return { eccSignature, mldsaSignature };
|
|
11611
|
+
}
|
|
11612
|
+
default:
|
|
11613
|
+
throw new Error('Unsupported signature algorithm');
|
|
11614
|
+
}
|
|
11615
|
+
}
|
|
11616
|
+
|
|
11617
|
+
async function verify$2(signatureAlgo, hashAlgo, eccPublicKey, mldsaPublicKey, dataDigest, { eccSignature, mldsaSignature }) {
|
|
11618
|
+
if (hashAlgo !== getRequiredHashAlgo(signatureAlgo)) {
|
|
11619
|
+
// The signature hash algo MUST be set to the specified algorithm, see
|
|
11620
|
+
// https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
11621
|
+
throw new Error('Unexpected hash algorithm for PQC signature');
|
|
11622
|
+
}
|
|
11623
|
+
|
|
11624
|
+
switch (signatureAlgo) {
|
|
11625
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11626
|
+
const eccVerifiedPromise = verify$3(signatureAlgo, hashAlgo, eccPublicKey, dataDigest, eccSignature);
|
|
11627
|
+
const mldsaVerifiedPromise = verify$4(signatureAlgo, mldsaPublicKey, dataDigest, mldsaSignature);
|
|
11628
|
+
const verified = await eccVerifiedPromise && await mldsaVerifiedPromise;
|
|
11629
|
+
return verified;
|
|
11630
|
+
}
|
|
11631
|
+
default:
|
|
11632
|
+
throw new Error('Unsupported signature algorithm');
|
|
11633
|
+
}
|
|
11634
|
+
}
|
|
11635
|
+
|
|
11636
|
+
function getRequiredHashAlgo(signatureAlgo) {
|
|
11637
|
+
// See https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
11638
|
+
switch (signatureAlgo) {
|
|
11639
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
11640
|
+
return enums.hash.sha3_256;
|
|
11641
|
+
default:
|
|
11642
|
+
throw new Error('Unsupported signature algorithm');
|
|
11643
|
+
}
|
|
11644
|
+
}
|
|
11645
|
+
|
|
11646
|
+
async function validateParams$1(algo, eccPublicKey, eccSecretKey, mldsaPublicKey, mldsaSeed) {
|
|
11647
|
+
const eccValidationPromise = validateParams$2(algo, eccPublicKey, eccSecretKey);
|
|
11648
|
+
const mldsaValidationPromise = validateParams$3(algo, mldsaPublicKey, mldsaSeed);
|
|
11649
|
+
const valid = await eccValidationPromise && await mldsaValidationPromise;
|
|
11650
|
+
return valid;
|
|
11651
|
+
}
|
|
11652
|
+
|
|
11653
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
11280
11654
|
__proto__: null,
|
|
11281
11655
|
generate: generate$1,
|
|
11656
|
+
getRequiredHashAlgo: getRequiredHashAlgo,
|
|
11657
|
+
mldsaExpandSecretSeed: expandSecretSeed,
|
|
11282
11658
|
sign: sign$2,
|
|
11659
|
+
validateParams: validateParams$1,
|
|
11283
11660
|
verify: verify$2
|
|
11284
11661
|
});
|
|
11285
11662
|
|
|
11663
|
+
var postQuantum = /*#__PURE__*/Object.freeze({
|
|
11664
|
+
__proto__: null,
|
|
11665
|
+
kem: index$1,
|
|
11666
|
+
signature: index
|
|
11667
|
+
});
|
|
11668
|
+
|
|
11286
11669
|
/**
|
|
11287
11670
|
* @fileoverview Asymmetric cryptography functions
|
|
11288
11671
|
* @module crypto/public_key
|
|
@@ -11299,7 +11682,9 @@ var publicKey = {
|
|
|
11299
11682
|
/** @see module:crypto/public_key/dsa */
|
|
11300
11683
|
dsa: dsa,
|
|
11301
11684
|
/** @see module:crypto/public_key/hmac */
|
|
11302
|
-
hmac: hmac
|
|
11685
|
+
hmac: hmac,
|
|
11686
|
+
/** @see module:crypto/public_key/post_quantum */
|
|
11687
|
+
postQuantum
|
|
11303
11688
|
};
|
|
11304
11689
|
|
|
11305
11690
|
class ShortByteString {
|
|
@@ -11398,6 +11783,12 @@ function parseSignatureParams(algo, signature) {
|
|
|
11398
11783
|
const mac = new ShortByteString(); read += mac.read(signature.subarray(read));
|
|
11399
11784
|
return { read, signatureParams: { mac } };
|
|
11400
11785
|
}
|
|
11786
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11787
|
+
const eccSignatureSize = 2 * publicKey.elliptic.eddsa.getPayloadSize(enums.publicKey.ed25519);
|
|
11788
|
+
const eccSignature = util.readExactSubarray(signature, read, read + eccSignatureSize); read += eccSignature.length;
|
|
11789
|
+
const mldsaSignature = util.readExactSubarray(signature, read, read + 3309); read += mldsaSignature.length;
|
|
11790
|
+
return { read, signatureParams: { eccSignature, mldsaSignature } };
|
|
11791
|
+
}
|
|
11401
11792
|
default:
|
|
11402
11793
|
throw new UnsupportedError('Unknown signature algorithm.');
|
|
11403
11794
|
}
|
|
@@ -11462,6 +11853,10 @@ async function verify$1(algo, hashAlgo, signature, publicParams, privateParams,
|
|
|
11462
11853
|
const { keyMaterial } = privateParams;
|
|
11463
11854
|
return publicKey.hmac.verify(algo.getValue(), keyMaterial, signature.mac.data, hashed);
|
|
11464
11855
|
}
|
|
11856
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11857
|
+
const { eccPublicKey, mldsaPublicKey } = publicParams;
|
|
11858
|
+
return publicKey.postQuantum.signature.verify(algo, hashAlgo, eccPublicKey, mldsaPublicKey, hashed, signature);
|
|
11859
|
+
}
|
|
11465
11860
|
default:
|
|
11466
11861
|
throw new Error('Unknown signature algorithm.');
|
|
11467
11862
|
}
|
|
@@ -11523,6 +11918,11 @@ async function sign$1(algo, hashAlgo, publicKeyParams, privateKeyParams, data, h
|
|
|
11523
11918
|
const mac = await publicKey.hmac.sign(algo.getValue(), keyMaterial, hashed);
|
|
11524
11919
|
return { mac: new ShortByteString(mac) };
|
|
11525
11920
|
}
|
|
11921
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
11922
|
+
const { eccPublicKey } = publicKeyParams;
|
|
11923
|
+
const { eccSecretKey, mldsaSecretKey } = privateKeyParams;
|
|
11924
|
+
return publicKey.postQuantum.signature.sign(algo, hashAlgo, eccSecretKey, eccPublicKey, mldsaSecretKey, hashed);
|
|
11925
|
+
}
|
|
11526
11926
|
default:
|
|
11527
11927
|
throw new Error('Unknown signature algorithm.');
|
|
11528
11928
|
}
|
|
@@ -11862,6 +12262,12 @@ async function publicKeyEncrypt(keyAlgo, symmetricAlgo, publicParams, privatePar
|
|
|
11862
12262
|
const c = await modeInstance.encrypt(data, iv, new Uint8Array());
|
|
11863
12263
|
return { aeadMode: new AEADEnum(aeadMode), iv, c: new ShortByteString(c) };
|
|
11864
12264
|
}
|
|
12265
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12266
|
+
const { eccPublicKey, mlkemPublicKey } = publicParams;
|
|
12267
|
+
const { eccCipherText, mlkemCipherText, wrappedKey } = await publicKey.postQuantum.kem.encrypt(keyAlgo, eccPublicKey, mlkemPublicKey, data);
|
|
12268
|
+
const C = ECDHXSymmetricKey.fromObject({ algorithm: symmetricAlgo, wrappedKey });
|
|
12269
|
+
return { eccCipherText, mlkemCipherText, C };
|
|
12270
|
+
}
|
|
11865
12271
|
default:
|
|
11866
12272
|
return [];
|
|
11867
12273
|
}
|
|
@@ -11881,8 +12287,8 @@ async function publicKeyEncrypt(keyAlgo, symmetricAlgo, publicParams, privatePar
|
|
|
11881
12287
|
* @throws {Error} on sensitive decryption error, unless `randomPayload` is given
|
|
11882
12288
|
* @async
|
|
11883
12289
|
*/
|
|
11884
|
-
async function publicKeyDecrypt(
|
|
11885
|
-
switch (
|
|
12290
|
+
async function publicKeyDecrypt(keyAlgo, publicKeyParams, privateKeyParams, sessionKeyParams, fingerprint, randomPayload) {
|
|
12291
|
+
switch (keyAlgo) {
|
|
11886
12292
|
case enums.publicKey.rsaEncryptSign:
|
|
11887
12293
|
case enums.publicKey.rsaEncrypt: {
|
|
11888
12294
|
const { c } = sessionKeyParams;
|
|
@@ -11912,7 +12318,7 @@ async function publicKeyDecrypt(algo, publicKeyParams, privateKeyParams, session
|
|
|
11912
12318
|
throw new Error('AES session key expected');
|
|
11913
12319
|
}
|
|
11914
12320
|
return publicKey.elliptic.ecdhX.decrypt(
|
|
11915
|
-
|
|
12321
|
+
keyAlgo, ephemeralPublicKey, C.wrappedKey, A, k);
|
|
11916
12322
|
}
|
|
11917
12323
|
case enums.publicKey.aead: {
|
|
11918
12324
|
const { cipher: algo } = publicKeyParams;
|
|
@@ -11925,6 +12331,12 @@ async function publicKeyDecrypt(algo, publicKeyParams, privateKeyParams, session
|
|
|
11925
12331
|
const modeInstance = await mode(algoValue, keyMaterial);
|
|
11926
12332
|
return modeInstance.decrypt(c.data, iv, new Uint8Array());
|
|
11927
12333
|
}
|
|
12334
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12335
|
+
const { eccSecretKey, mlkemSecretKey } = privateKeyParams;
|
|
12336
|
+
const { eccPublicKey, mlkemPublicKey } = publicKeyParams;
|
|
12337
|
+
const { eccCipherText, mlkemCipherText, C } = sessionKeyParams;
|
|
12338
|
+
return publicKey.postQuantum.kem.decrypt(keyAlgo, eccCipherText, mlkemCipherText, eccSecretKey, eccPublicKey, mlkemSecretKey, mlkemPublicKey, C.wrappedKey);
|
|
12339
|
+
}
|
|
11928
12340
|
default:
|
|
11929
12341
|
throw new Error('Unknown public key encryption algorithm.');
|
|
11930
12342
|
}
|
|
@@ -11996,6 +12408,16 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
11996
12408
|
const digest = bytes.subarray(read, read + digestLength); read += digestLength;
|
|
11997
12409
|
return { read: read, publicParams: { cipher: algo, digest } };
|
|
11998
12410
|
}
|
|
12411
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12412
|
+
const eccPublicKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.x25519)); read += eccPublicKey.length;
|
|
12413
|
+
const mlkemPublicKey = util.readExactSubarray(bytes, read, read + 1184); read += mlkemPublicKey.length;
|
|
12414
|
+
return { read, publicParams: { eccPublicKey, mlkemPublicKey } };
|
|
12415
|
+
}
|
|
12416
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
12417
|
+
const eccPublicKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.ed25519)); read += eccPublicKey.length;
|
|
12418
|
+
const mldsaPublicKey = util.readExactSubarray(bytes, read, read + 1952); read += mldsaPublicKey.length;
|
|
12419
|
+
return { read, publicParams: { eccPublicKey, mldsaPublicKey } };
|
|
12420
|
+
}
|
|
11999
12421
|
default:
|
|
12000
12422
|
throw new UnsupportedError('Unknown public key encryption algorithm.');
|
|
12001
12423
|
}
|
|
@@ -12008,7 +12430,7 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
12008
12430
|
* @param {Object} publicParams - (ECC and symmetric only) public params, needed to format some private params
|
|
12009
12431
|
* @returns {{ read: Number, privateParams: Object }} Number of read bytes plus the key parameters referenced by name.
|
|
12010
12432
|
*/
|
|
12011
|
-
function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
12433
|
+
async function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
12012
12434
|
let read = 0;
|
|
12013
12435
|
switch (algo) {
|
|
12014
12436
|
case enums.publicKey.rsaEncrypt:
|
|
@@ -12067,6 +12489,18 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
|
12067
12489
|
const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
|
|
12068
12490
|
return { read, privateParams: { hashSeed, keyMaterial } };
|
|
12069
12491
|
}
|
|
12492
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12493
|
+
const eccSecretKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.x25519)); read += eccSecretKey.length;
|
|
12494
|
+
const mlkemSeed = util.readExactSubarray(bytes, read, read + 64); read += mlkemSeed.length;
|
|
12495
|
+
const { mlkemSecretKey } = await publicKey.postQuantum.kem.mlkemExpandSecretSeed(algo, mlkemSeed);
|
|
12496
|
+
return { read, privateParams: { eccSecretKey, mlkemSecretKey, mlkemSeed } };
|
|
12497
|
+
}
|
|
12498
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
12499
|
+
const eccSecretKey = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.ed25519)); read += eccSecretKey.length;
|
|
12500
|
+
const mldsaSeed = util.readExactSubarray(bytes, read, read + 32); read += mldsaSeed.length;
|
|
12501
|
+
const { mldsaSecretKey } = await publicKey.postQuantum.signature.mldsaExpandSecretSeed(algo, mldsaSeed);
|
|
12502
|
+
return { read, privateParams: { eccSecretKey, mldsaSecretKey, mldsaSeed } };
|
|
12503
|
+
}
|
|
12070
12504
|
default:
|
|
12071
12505
|
throw new UnsupportedError('Unknown public key encryption algorithm.');
|
|
12072
12506
|
}
|
|
@@ -12130,6 +12564,12 @@ function parseEncSessionKeyParams(algo, bytes) {
|
|
|
12130
12564
|
|
|
12131
12565
|
return { aeadMode, iv, c };
|
|
12132
12566
|
}
|
|
12567
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12568
|
+
const eccCipherText = util.readExactSubarray(bytes, read, read + getCurvePayloadSize(enums.publicKey.x25519)); read += eccCipherText.length;
|
|
12569
|
+
const mlkemCipherText = util.readExactSubarray(bytes, read, read + 1088); read += mlkemCipherText.length;
|
|
12570
|
+
const C = new ECDHXSymmetricKey(); C.read(bytes.subarray(read));
|
|
12571
|
+
return { eccCipherText, mlkemCipherText, C }; // eccCipherText || mlkemCipherText || len(C) || C
|
|
12572
|
+
}
|
|
12133
12573
|
default:
|
|
12134
12574
|
throw new UnsupportedError('Unknown public key encryption algorithm.');
|
|
12135
12575
|
}
|
|
@@ -12149,9 +12589,21 @@ function serializeParams(algo, params) {
|
|
|
12149
12589
|
enums.publicKey.ed448,
|
|
12150
12590
|
enums.publicKey.x448,
|
|
12151
12591
|
enums.publicKey.aead,
|
|
12152
|
-
enums.publicKey.hmac
|
|
12592
|
+
enums.publicKey.hmac,
|
|
12593
|
+
enums.publicKey.pqc_mlkem_x25519,
|
|
12594
|
+
enums.publicKey.pqc_mldsa_ed25519
|
|
12153
12595
|
]);
|
|
12596
|
+
|
|
12597
|
+
const excludedFields = {
|
|
12598
|
+
[enums.publicKey.pqc_mlkem_x25519]: new Set(['mlkemSecretKey']), // only `mlkemSeed` is serialized
|
|
12599
|
+
[enums.publicKey.pqc_mldsa_ed25519]: new Set(['mldsaSecretKey']) // only `mldsaSeed` is serialized
|
|
12600
|
+
};
|
|
12601
|
+
|
|
12154
12602
|
const orderedParams = Object.keys(params).map(name => {
|
|
12603
|
+
if (excludedFields[algo]?.has(name)) {
|
|
12604
|
+
return new Uint8Array();
|
|
12605
|
+
}
|
|
12606
|
+
|
|
12155
12607
|
const param = params[name];
|
|
12156
12608
|
if (!util.isUint8Array(param)) return param.write();
|
|
12157
12609
|
return algosWithNativeRepresentation.has(algo) ? param : util.uint8ArrayToMPI(param);
|
|
@@ -12216,6 +12668,16 @@ async function generateParams(algo, bits, oid, symmetric) {
|
|
|
12216
12668
|
const keyMaterial = generateSessionKey$1(symmetric);
|
|
12217
12669
|
return createSymmetricParams(keyMaterial, new SymAlgoEnum(symmetric));
|
|
12218
12670
|
}
|
|
12671
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
12672
|
+
return publicKey.postQuantum.kem.generate(algo).then(({ eccSecretKey, eccPublicKey, mlkemSeed, mlkemSecretKey, mlkemPublicKey }) => ({
|
|
12673
|
+
privateParams: { eccSecretKey, mlkemSeed, mlkemSecretKey },
|
|
12674
|
+
publicParams: { eccPublicKey, mlkemPublicKey }
|
|
12675
|
+
}));
|
|
12676
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
12677
|
+
return publicKey.postQuantum.signature.generate(algo).then(({ eccSecretKey, eccPublicKey, mldsaSeed, mldsaSecretKey, mldsaPublicKey }) => ({
|
|
12678
|
+
privateParams: { eccSecretKey, mldsaSeed, mldsaSecretKey },
|
|
12679
|
+
publicParams: { eccPublicKey, mldsaPublicKey }
|
|
12680
|
+
}));
|
|
12219
12681
|
case enums.publicKey.dsa:
|
|
12220
12682
|
case enums.publicKey.elgamal:
|
|
12221
12683
|
throw new Error('Unsupported algorithm for key generation.');
|
|
@@ -12307,6 +12769,16 @@ async function validateParams(algo, publicParams, privateParams) {
|
|
|
12307
12769
|
return keySize === keyMaterial.length &&
|
|
12308
12770
|
util.equalsUint8Array(digest, await hash.sha256(hashSeed));
|
|
12309
12771
|
}
|
|
12772
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
12773
|
+
const { eccSecretKey, mlkemSeed } = privateParams;
|
|
12774
|
+
const { eccPublicKey, mlkemPublicKey } = publicParams;
|
|
12775
|
+
return publicKey.postQuantum.kem.validateParams(algo, eccPublicKey, eccSecretKey, mlkemPublicKey, mlkemSeed);
|
|
12776
|
+
}
|
|
12777
|
+
case enums.publicKey.pqc_mldsa_ed25519: {
|
|
12778
|
+
const { eccSecretKey, mldsaSeed } = privateParams;
|
|
12779
|
+
const { eccPublicKey, mldsaPublicKey } = publicParams;
|
|
12780
|
+
return publicKey.postQuantum.signature.validateParams(algo, eccPublicKey, eccSecretKey, mldsaPublicKey, mldsaSeed);
|
|
12781
|
+
}
|
|
12310
12782
|
default:
|
|
12311
12783
|
throw new Error('Unknown public key algorithm.');
|
|
12312
12784
|
}
|
|
@@ -15943,6 +16415,12 @@ class AEADEncryptedDataPacket {
|
|
|
15943
16415
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
15944
16416
|
|
|
15945
16417
|
|
|
16418
|
+
const algosWithV3CleartextSessionKeyAlgorithm = new Set([
|
|
16419
|
+
enums.publicKey.x25519,
|
|
16420
|
+
enums.publicKey.x448,
|
|
16421
|
+
enums.publicKey.pqc_mlkem_x25519
|
|
16422
|
+
]);
|
|
16423
|
+
|
|
15946
16424
|
/**
|
|
15947
16425
|
* Public-Key Encrypted Session Key Packets (Tag 1)
|
|
15948
16426
|
*
|
|
@@ -16050,7 +16528,7 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
16050
16528
|
}
|
|
16051
16529
|
this.publicKeyAlgorithm = bytes[offset++];
|
|
16052
16530
|
this.encrypted = mod.parseEncSessionKeyParams(this.publicKeyAlgorithm, bytes.subarray(offset));
|
|
16053
|
-
if (
|
|
16531
|
+
if (algosWithV3CleartextSessionKeyAlgorithm.has(this.publicKeyAlgorithm)) {
|
|
16054
16532
|
if (this.version === 3) {
|
|
16055
16533
|
this.sessionKeyAlgorithm = enums.write(enums.symmetric, this.encrypted.C.algorithm);
|
|
16056
16534
|
} else if (this.encrypted.C.algorithm !== null) {
|
|
@@ -16133,7 +16611,7 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
16133
16611
|
|
|
16134
16612
|
if (this.version === 3) {
|
|
16135
16613
|
// v3 Montgomery curves have cleartext cipher algo
|
|
16136
|
-
const hasEncryptedAlgo =
|
|
16614
|
+
const hasEncryptedAlgo = !algosWithV3CleartextSessionKeyAlgorithm.has(this.publicKeyAlgorithm);
|
|
16137
16615
|
this.sessionKeyAlgorithm = hasEncryptedAlgo ? sessionKeyAlgorithm : this.sessionKeyAlgorithm;
|
|
16138
16616
|
|
|
16139
16617
|
if (sessionKey.length !== mod.getCipherParams(this.sessionKeyAlgorithm).keySize) {
|
|
@@ -16160,6 +16638,7 @@ function encodeSessionKey(version, keyAlgo, cipherAlgo, sessionKeyData) {
|
|
|
16160
16638
|
]);
|
|
16161
16639
|
case enums.publicKey.x25519:
|
|
16162
16640
|
case enums.publicKey.x448:
|
|
16641
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
16163
16642
|
return sessionKeyData;
|
|
16164
16643
|
default:
|
|
16165
16644
|
throw new Error('Unsupported public key algorithm');
|
|
@@ -16208,6 +16687,7 @@ function decodeSessionKey(version, keyAlgo, decryptedData, randomSessionKey) {
|
|
|
16208
16687
|
}
|
|
16209
16688
|
case enums.publicKey.x25519:
|
|
16210
16689
|
case enums.publicKey.x448:
|
|
16690
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
16211
16691
|
return {
|
|
16212
16692
|
sessionKeyAlgorithm: null,
|
|
16213
16693
|
sessionKey: decryptedData
|
|
@@ -16573,6 +17053,14 @@ class PublicKeyPacket {
|
|
|
16573
17053
|
) {
|
|
16574
17054
|
throw new Error('Legacy curve25519 cannot be used with v6 keys');
|
|
16575
17055
|
}
|
|
17056
|
+
// The composite ML-DSA + EdDSA schemes MUST be used only with v6 keys.
|
|
17057
|
+
// The composite ML-KEM + ECDH schemes MUST be used only with v6 keys.
|
|
17058
|
+
if (this.version !== 6 && (
|
|
17059
|
+
this.algorithm === enums.publicKey.pqc_mldsa_ed25519 ||
|
|
17060
|
+
this.algorithm === enums.publicKey.pqc_mlkem_x25519
|
|
17061
|
+
)) {
|
|
17062
|
+
throw new Error('Unexpected key version: ML-DSA and ML-KEM algorithms can only be used with v6 keys');
|
|
17063
|
+
}
|
|
16576
17064
|
this.publicParams = publicParams;
|
|
16577
17065
|
pos += read;
|
|
16578
17066
|
|
|
@@ -17256,7 +17744,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17256
17744
|
}
|
|
17257
17745
|
}
|
|
17258
17746
|
try {
|
|
17259
|
-
const { read, privateParams } = mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
17747
|
+
const { read, privateParams } = await mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
17260
17748
|
if (read < cleartext.length) {
|
|
17261
17749
|
throw new Error('Error reading MPIs');
|
|
17262
17750
|
}
|
|
@@ -17514,7 +18002,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17514
18002
|
}
|
|
17515
18003
|
|
|
17516
18004
|
try {
|
|
17517
|
-
const { privateParams } = mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
18005
|
+
const { privateParams } = await mod.parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
|
|
17518
18006
|
this.privateParams = privateParams;
|
|
17519
18007
|
} catch (err) {
|
|
17520
18008
|
throw new Error('Error reading MPIs');
|
|
@@ -17567,6 +18055,12 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
17567
18055
|
)) {
|
|
17568
18056
|
throw new Error(`Cannot generate v6 keys of type 'ecc' with curve ${curve}. Generate a key of type 'curve25519' instead`);
|
|
17569
18057
|
}
|
|
18058
|
+
if (this.version !== 6 && (
|
|
18059
|
+
this.algorithm === enums.publicKey.pqc_mldsa_ed25519 ||
|
|
18060
|
+
this.algorithm === enums.publicKey.pqc_mlkem_x25519
|
|
18061
|
+
)) {
|
|
18062
|
+
throw new Error(`Cannot generate v${this.version} keys of type 'pqc'. Generate a v6 key instead`);
|
|
18063
|
+
}
|
|
17570
18064
|
const { privateParams, publicParams } = await mod.generateParams(this.algorithm, bits, curve, symmetric);
|
|
17571
18065
|
this.privateParams = privateParams;
|
|
17572
18066
|
this.publicParams = publicParams;
|
|
@@ -18069,6 +18563,12 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
18069
18563
|
* @async
|
|
18070
18564
|
*/
|
|
18071
18565
|
async function getPreferredHashAlgo(targetKeys, signingKeyPacket, date = new Date(), targetUserIDs = [], config) {
|
|
18566
|
+
if (signingKeyPacket.algorithm === enums.publicKey.pqc_mldsa_ed25519) {
|
|
18567
|
+
// For PQC, the returned hash algo MUST be set to the specified algorithm, see
|
|
18568
|
+
// https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-pqc#section-5.2.1.
|
|
18569
|
+
return mod.publicKey.postQuantum.signature.getRequiredHashAlgo(signingKeyPacket.algorithm);
|
|
18570
|
+
}
|
|
18571
|
+
|
|
18072
18572
|
/**
|
|
18073
18573
|
* If `preferredSenderAlgo` appears in the prefs of all recipients, we pick it; otherwise, we use the
|
|
18074
18574
|
* strongest supported algo (`defaultAlgo` is always implicitly supported by all keys).
|
|
@@ -18355,6 +18855,13 @@ function sanitizeKeyOptions(options, subkeyDefaults = {}) {
|
|
|
18355
18855
|
}
|
|
18356
18856
|
|
|
18357
18857
|
switch (options.type) {
|
|
18858
|
+
case 'pqc':
|
|
18859
|
+
if (options.sign) {
|
|
18860
|
+
options.algorithm = enums.publicKey.pqc_mldsa_ed25519;
|
|
18861
|
+
} else {
|
|
18862
|
+
options.algorithm = enums.publicKey.pqc_mlkem_x25519;
|
|
18863
|
+
}
|
|
18864
|
+
break;
|
|
18358
18865
|
case 'ecc': // NB: this case also handles legacy eddsa and x25519 keys, based on `options.curve`
|
|
18359
18866
|
try {
|
|
18360
18867
|
options.curve = enums.write(enums.curve, options.curve);
|
|
@@ -18413,6 +18920,7 @@ function validateSigningKeyPacket(keyPacket, signature, config) {
|
|
|
18413
18920
|
case enums.publicKey.ed25519:
|
|
18414
18921
|
case enums.publicKey.ed448:
|
|
18415
18922
|
case enums.publicKey.hmac:
|
|
18923
|
+
case enums.publicKey.pqc_mldsa_ed25519:
|
|
18416
18924
|
if (!signature.keyFlags && !config.allowMissingKeyFlags) {
|
|
18417
18925
|
throw new Error('None of the key flags is set: consider passing `config.allowMissingKeyFlags`');
|
|
18418
18926
|
}
|
|
@@ -18432,6 +18940,7 @@ function validateEncryptionKeyPacket(keyPacket, signature, config) {
|
|
|
18432
18940
|
case enums.publicKey.x25519:
|
|
18433
18941
|
case enums.publicKey.x448:
|
|
18434
18942
|
case enums.publicKey.aead:
|
|
18943
|
+
case enums.publicKey.pqc_mlkem_x25519:
|
|
18435
18944
|
if (!signature.keyFlags && !config.allowMissingKeyFlags) {
|
|
18436
18945
|
throw new Error('None of the key flags is set: consider passing `config.allowMissingKeyFlags`');
|
|
18437
18946
|
}
|
|
@@ -18454,7 +18963,8 @@ function validateDecryptionKeyPacket(keyPacket, signature, config) {
|
|
|
18454
18963
|
case enums.publicKey.elgamal:
|
|
18455
18964
|
case enums.publicKey.ecdh:
|
|
18456
18965
|
case enums.publicKey.x25519:
|
|
18457
|
-
case enums.publicKey.x448:
|
|
18966
|
+
case enums.publicKey.x448:
|
|
18967
|
+
case enums.publicKey.pqc_mlkem_x25519: {
|
|
18458
18968
|
const isValidSigningKeyPacket = !signature.keyFlags || (signature.keyFlags[0] & enums.keyFlags.signData) !== 0;
|
|
18459
18969
|
if (isValidSigningKeyPacket && config.allowInsecureDecryptionWithSigningKeys) {
|
|
18460
18970
|
// This is only relevant for RSA keys, all other signing algorithms cannot decrypt
|
|
@@ -20267,10 +20777,9 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
|
|
|
20267
20777
|
});
|
|
20268
20778
|
}
|
|
20269
20779
|
signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
|
|
20270
|
-
// prefer fast asm.js implementations (SHA-256)
|
|
20271
|
-
enums.hash.sha256,
|
|
20272
20780
|
enums.hash.sha512,
|
|
20273
|
-
|
|
20781
|
+
enums.hash.sha256,
|
|
20782
|
+
...(secretKeyPacket.version === 6 ? [enums.hash.sha3_512, enums.hash.sha3_256] : [])
|
|
20274
20783
|
], config.preferredHashAlgorithm);
|
|
20275
20784
|
signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
|
|
20276
20785
|
enums.compression.uncompressed,
|
|
@@ -22026,6 +22535,7 @@ async function decrypt({ message, decryptionKeys, passwords, sessionKeys, verifi
|
|
|
22026
22535
|
result.data,
|
|
22027
22536
|
fromAsync(async () => {
|
|
22028
22537
|
await util.anyPromise(result.signatures.map(sig => sig.verified));
|
|
22538
|
+
return format === 'binary' ? new Uint8Array() : '';
|
|
22029
22539
|
})
|
|
22030
22540
|
]);
|
|
22031
22541
|
}
|
|
@@ -22157,6 +22667,7 @@ async function verify({ message, verificationKeys, expectSigned = false, format
|
|
|
22157
22667
|
result.data,
|
|
22158
22668
|
fromAsync(async () => {
|
|
22159
22669
|
await util.anyPromise(result.signatures.map(sig => sig.verified));
|
|
22670
|
+
return format === 'binary' ? new Uint8Array() : '';
|
|
22160
22671
|
})
|
|
22161
22672
|
]);
|
|
22162
22673
|
}
|