@protontech/openpgp 4.10.8 → 5.3.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/README.md +311 -239
- package/dist/lightweight/bn.interface.min.mjs +3 -0
- package/dist/lightweight/bn.interface.min.mjs.map +1 -0
- package/dist/lightweight/bn.interface.mjs +340 -0
- package/dist/lightweight/bn.min.mjs +3 -0
- package/dist/lightweight/bn.min.mjs.map +1 -0
- package/dist/lightweight/bn.mjs +3434 -0
- package/dist/lightweight/elliptic.min.mjs +3 -0
- package/dist/lightweight/elliptic.min.mjs.map +1 -0
- package/dist/lightweight/elliptic.mjs +4313 -0
- package/dist/lightweight/openpgp.min.mjs +3 -0
- package/dist/lightweight/openpgp.min.mjs.map +1 -0
- package/dist/lightweight/openpgp.mjs +31375 -0
- package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
- package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
- package/dist/lightweight/ponyfill.es6.mjs +3831 -0
- package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
- package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
- package/dist/lightweight/web-streams-adapter.mjs +561 -0
- package/dist/node/openpgp.js +43943 -0
- package/dist/node/openpgp.min.js +17 -0
- package/dist/node/openpgp.min.js.map +1 -0
- package/dist/node/openpgp.min.mjs +17 -0
- package/dist/node/openpgp.min.mjs.map +1 -0
- package/dist/node/openpgp.mjs +43880 -0
- package/dist/openpgp.js +41077 -41609
- package/dist/openpgp.min.js +17 -2
- package/dist/openpgp.min.js.map +1 -0
- package/dist/openpgp.min.mjs +17 -0
- package/dist/openpgp.min.mjs.map +1 -0
- package/dist/openpgp.mjs +43868 -0
- package/lightweight/package.json +5 -0
- package/openpgp.d.ts +889 -0
- package/package.json +63 -57
- package/dist/compat/openpgp.js +0 -61152
- package/dist/compat/openpgp.min.js +0 -2
- package/dist/compat/openpgp.worker.js +0 -173
- package/dist/compat/openpgp.worker.min.js +0 -2
- package/dist/lightweight/elliptic.min.js +0 -5
- package/dist/lightweight/openpgp.js +0 -40071
- package/dist/lightweight/openpgp.min.js +0 -2
- package/dist/lightweight/openpgp.worker.js +0 -173
- package/dist/lightweight/openpgp.worker.min.js +0 -2
- package/dist/openpgp.worker.js +0 -173
- package/dist/openpgp.worker.min.js +0 -2
- package/src/cleartext.js +0 -220
- package/src/config/config.js +0 -232
- package/src/config/index.js +0 -7
- package/src/config/localStorage.js +0 -35
- package/src/crypto/aes_kw.js +0 -153
- package/src/crypto/cfb.js +0 -169
- package/src/crypto/cipher/aes.js +0 -27
- package/src/crypto/cipher/blowfish.js +0 -398
- package/src/crypto/cipher/cast5.js +0 -610
- package/src/crypto/cipher/des.js +0 -476
- package/src/crypto/cipher/index.js +0 -91
- package/src/crypto/cipher/twofish.js +0 -346
- package/src/crypto/cmac.js +0 -98
- package/src/crypto/crypto.js +0 -394
- package/src/crypto/eax.js +0 -172
- package/src/crypto/gcm.js +0 -141
- package/src/crypto/hash/index.js +0 -163
- package/src/crypto/hash/md5.js +0 -205
- package/src/crypto/index.js +0 -57
- package/src/crypto/ocb.js +0 -274
- package/src/crypto/pkcs1.js +0 -170
- package/src/crypto/pkcs5.js +0 -55
- package/src/crypto/public_key/dsa.js +0 -188
- package/src/crypto/public_key/elgamal.js +0 -137
- package/src/crypto/public_key/elliptic/curves.js +0 -385
- package/src/crypto/public_key/elliptic/ecdh.js +0 -414
- package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
- package/src/crypto/public_key/elliptic/eddsa.js +0 -119
- package/src/crypto/public_key/elliptic/index.js +0 -34
- package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
- package/src/crypto/public_key/index.js +0 -28
- package/src/crypto/public_key/prime.js +0 -275
- package/src/crypto/public_key/rsa.js +0 -597
- package/src/crypto/random.js +0 -145
- package/src/crypto/signature.js +0 -137
- package/src/encoding/armor.js +0 -433
- package/src/encoding/base64.js +0 -96
- package/src/enums.js +0 -493
- package/src/hkp.js +0 -89
- package/src/index.js +0 -161
- package/src/key/factory.js +0 -326
- package/src/key/helper.js +0 -378
- package/src/key/index.js +0 -32
- package/src/key/key.js +0 -888
- package/src/key/subkey.js +0 -187
- package/src/key/user.js +0 -230
- package/src/keyring/index.js +0 -12
- package/src/keyring/keyring.js +0 -229
- package/src/keyring/localstore.js +0 -119
- package/src/lightweight_helper.js +0 -26
- package/src/message.js +0 -825
- package/src/openpgp.js +0 -717
- package/src/packet/all_packets.js +0 -116
- package/src/packet/clone.js +0 -189
- package/src/packet/compressed.js +0 -194
- package/src/packet/index.js +0 -20
- package/src/packet/literal.js +0 -168
- package/src/packet/marker.js +0 -62
- package/src/packet/one_pass_signature.js +0 -156
- package/src/packet/packet.js +0 -300
- package/src/packet/packetlist.js +0 -232
- package/src/packet/public_key.js +0 -280
- package/src/packet/public_key_encrypted_session_key.js +0 -161
- package/src/packet/public_subkey.js +0 -44
- package/src/packet/secret_key.js +0 -468
- package/src/packet/secret_subkey.js +0 -41
- package/src/packet/signature.js +0 -786
- package/src/packet/sym_encrypted_aead_protected.js +0 -189
- package/src/packet/sym_encrypted_integrity_protected.js +0 -139
- package/src/packet/sym_encrypted_session_key.js +0 -204
- package/src/packet/symmetrically_encrypted.js +0 -118
- package/src/packet/trust.js +0 -35
- package/src/packet/user_attribute.js +0 -94
- package/src/packet/userid.js +0 -87
- package/src/polyfills.js +0 -64
- package/src/signature.js +0 -73
- package/src/type/ecdh_symkey.js +0 -69
- package/src/type/kdf_params.js +0 -114
- package/src/type/keyid.js +0 -110
- package/src/type/mpi.js +0 -138
- package/src/type/oid.js +0 -110
- package/src/type/s2k.js +0 -203
- package/src/util.js +0 -836
- package/src/wkd.js +0 -84
- package/src/worker/async_proxy.js +0 -190
- package/src/worker/worker.js +0 -167
- package/test/crypto/aes_kw.js +0 -57
- package/test/crypto/cipher/aes.js +0 -86
- package/test/crypto/cipher/blowfish.js +0 -58
- package/test/crypto/cipher/cast5.js +0 -25
- package/test/crypto/cipher/des.js +0 -143
- package/test/crypto/cipher/index.js +0 -7
- package/test/crypto/cipher/twofish.js +0 -71
- package/test/crypto/crypto.js +0 -383
- package/test/crypto/eax.js +0 -150
- package/test/crypto/ecdh.js +0 -359
- package/test/crypto/elliptic.js +0 -251
- package/test/crypto/elliptic_data.js +0 -102
- package/test/crypto/hash/index.js +0 -5
- package/test/crypto/hash/md5.js +0 -16
- package/test/crypto/hash/ripemd.js +0 -14
- package/test/crypto/hash/sha.js +0 -20
- package/test/crypto/index.js +0 -14
- package/test/crypto/ocb.js +0 -183
- package/test/crypto/pkcs5.js +0 -39
- package/test/crypto/random.js +0 -79
- package/test/crypto/rsa.js +0 -180
- package/test/crypto/validate.js +0 -387
- package/test/general/armor.js +0 -408
- package/test/general/brainpool.js +0 -360
- package/test/general/decompression.js +0 -60
- package/test/general/ecc_nist.js +0 -115
- package/test/general/ecc_secp256k1.js +0 -242
- package/test/general/forwarding.js +0 -43
- package/test/general/hkp.js +0 -165
- package/test/general/index.js +0 -20
- package/test/general/key.js +0 -3491
- package/test/general/keyring.js +0 -336
- package/test/general/oid.js +0 -39
- package/test/general/openpgp.js +0 -2577
- package/test/general/packet.js +0 -950
- package/test/general/signature.js +0 -1715
- package/test/general/streaming.js +0 -944
- package/test/general/testInputs.js +0 -18
- package/test/general/util.js +0 -183
- package/test/general/wkd.js +0 -48
- package/test/general/x25519.js +0 -556
- package/test/unittests.js +0 -64
package/src/type/mpi.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2011 Recurity Labs GmbH
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
// Hint: We hold our MPIs as an array of octets in big endian format preceding a two
|
|
19
|
-
// octet scalar: MPI: [a,b,c,d,e,f]
|
|
20
|
-
// - MPI size: (a << 8) | b
|
|
21
|
-
// - MPI = c | d << 8 | e << ((MPI.length -2)*8) | f ((MPI.length -2)*8)
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Implementation of type MPI ({@link https://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2})
|
|
25
|
-
* Multiprecision integers (also called MPIs) are unsigned integers used
|
|
26
|
-
* to hold large integers such as the ones used in cryptographic
|
|
27
|
-
* calculations.
|
|
28
|
-
* An MPI consists of two pieces: a two-octet scalar that is the length
|
|
29
|
-
* of the MPI in bits followed by a string of octets that contain the
|
|
30
|
-
* actual integer.
|
|
31
|
-
* @requires bn.js
|
|
32
|
-
* @requires util
|
|
33
|
-
* @module type/mpi
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
import BN from 'bn.js';
|
|
37
|
-
import util from '../util';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @constructor
|
|
41
|
-
*/
|
|
42
|
-
function MPI(data) {
|
|
43
|
-
/** An implementation dependent integer */
|
|
44
|
-
if (data instanceof MPI) {
|
|
45
|
-
this.data = data.data;
|
|
46
|
-
} else if (BN.isBN(data)) {
|
|
47
|
-
this.fromBN(data);
|
|
48
|
-
} else if (util.isUint8Array(data)) {
|
|
49
|
-
this.fromUint8Array(data);
|
|
50
|
-
} else if (util.isString(data)) {
|
|
51
|
-
this.fromString(data);
|
|
52
|
-
} else {
|
|
53
|
-
this.data = null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Parsing function for a MPI ({@link https://tools.ietf.org/html/rfc4880#section-3.2|RFC 4880 3.2}).
|
|
59
|
-
* @param {Uint8Array} input Payload of MPI data
|
|
60
|
-
* @param {String} endian Endianness of the data; 'be' for big-endian or 'le' for little-endian
|
|
61
|
-
* @returns {Integer} Length of data read
|
|
62
|
-
*/
|
|
63
|
-
MPI.prototype.read = function (bytes, endian = 'be') {
|
|
64
|
-
if (util.isString(bytes)) {
|
|
65
|
-
bytes = util.str_to_Uint8Array(bytes);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const bits = (bytes[0] << 8) | bytes[1];
|
|
69
|
-
const bytelen = (bits + 7) >>> 3;
|
|
70
|
-
const payload = bytes.subarray(2, 2 + bytelen);
|
|
71
|
-
|
|
72
|
-
this.fromUint8Array(payload, endian);
|
|
73
|
-
|
|
74
|
-
return 2 + bytelen;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Converts the mpi object to a bytes as specified in
|
|
79
|
-
* {@link https://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2}
|
|
80
|
-
* @param {String} endian Endianness of the payload; 'be' for big-endian or 'le' for little-endian
|
|
81
|
-
* @param {Integer} length Length of the data part of the MPI
|
|
82
|
-
* @returns {Uint8Aray} mpi Byte representation
|
|
83
|
-
*/
|
|
84
|
-
MPI.prototype.write = function (endian, length) {
|
|
85
|
-
return util.Uint8Array_to_MPI(this.toUint8Array(endian, length));
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
MPI.prototype.bitLength = function () {
|
|
89
|
-
return (this.data.length - 1) * 8 + util.nbits(this.data[0]);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
MPI.prototype.byteLength = function () {
|
|
93
|
-
return this.data.length;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
MPI.prototype.toUint8Array = function (endian, length) {
|
|
97
|
-
endian = endian || 'be';
|
|
98
|
-
length = length || this.data.length;
|
|
99
|
-
|
|
100
|
-
const payload = new Uint8Array(length);
|
|
101
|
-
const start = endian === 'le' ? 0 : length - this.data.length;
|
|
102
|
-
payload.set(this.data, start);
|
|
103
|
-
if (endian === 'le') {
|
|
104
|
-
payload.reverse();
|
|
105
|
-
}
|
|
106
|
-
return payload;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
MPI.prototype.fromUint8Array = function (bytes, endian = 'be') {
|
|
110
|
-
this.data = new Uint8Array(bytes.length);
|
|
111
|
-
this.data.set(bytes);
|
|
112
|
-
|
|
113
|
-
if (endian === 'le') {
|
|
114
|
-
this.data.reverse();
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
MPI.prototype.toString = function () {
|
|
119
|
-
return util.Uint8Array_to_str(this.toUint8Array());
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
MPI.prototype.fromString = function (str, endian = 'be') {
|
|
123
|
-
this.fromUint8Array(util.str_to_Uint8Array(str), endian);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
MPI.prototype.toBN = function () {
|
|
127
|
-
return new BN(this.toUint8Array());
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
MPI.prototype.fromBN = function (bn) {
|
|
131
|
-
this.data = bn.toArrayLike(Uint8Array);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
MPI.fromClone = function (clone) {
|
|
135
|
-
return new MPI(clone.data);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export default MPI;
|
package/src/type/oid.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2015-2016 Decentral
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Wrapper to an OID value
|
|
20
|
-
*
|
|
21
|
-
* {@link https://tools.ietf.org/html/rfc6637#section-11|RFC6637, section 11}:
|
|
22
|
-
* The sequence of octets in the third column is the result of applying
|
|
23
|
-
* the Distinguished Encoding Rules (DER) to the ASN.1 Object Identifier
|
|
24
|
-
* with subsequent truncation. The truncation removes the two fields of
|
|
25
|
-
* encoded Object Identifier. The first omitted field is one octet
|
|
26
|
-
* representing the Object Identifier tag, and the second omitted field
|
|
27
|
-
* is the length of the Object Identifier body. For example, the
|
|
28
|
-
* complete ASN.1 DER encoding for the NIST P-256 curve OID is "06 08 2A
|
|
29
|
-
* 86 48 CE 3D 03 01 07", from which the first entry in the table above
|
|
30
|
-
* is constructed by omitting the first two octets. Only the truncated
|
|
31
|
-
* sequence of octets is the valid representation of a curve OID.
|
|
32
|
-
* @requires util
|
|
33
|
-
* @requires enums
|
|
34
|
-
* @module type/oid
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
import util from '../util';
|
|
38
|
-
import enums from '../enums';
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @constructor
|
|
42
|
-
*/
|
|
43
|
-
function OID(oid) {
|
|
44
|
-
if (oid instanceof OID) {
|
|
45
|
-
this.oid = oid.oid;
|
|
46
|
-
} else if (util.isArray(oid) ||
|
|
47
|
-
util.isUint8Array(oid)) {
|
|
48
|
-
oid = new Uint8Array(oid);
|
|
49
|
-
if (oid[0] === 0x06) { // DER encoded oid byte array
|
|
50
|
-
if (oid[1] !== oid.length - 2) {
|
|
51
|
-
throw new Error('Length mismatch in DER encoded oid');
|
|
52
|
-
}
|
|
53
|
-
oid = oid.subarray(2);
|
|
54
|
-
}
|
|
55
|
-
this.oid = oid;
|
|
56
|
-
} else {
|
|
57
|
-
this.oid = '';
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Method to read an OID object
|
|
63
|
-
* @param {Uint8Array} input Where to read the OID from
|
|
64
|
-
* @returns {Number} Number of read bytes
|
|
65
|
-
*/
|
|
66
|
-
OID.prototype.read = function (input) {
|
|
67
|
-
if (input.length >= 1) {
|
|
68
|
-
const length = input[0];
|
|
69
|
-
if (input.length >= 1 + length) {
|
|
70
|
-
this.oid = input.subarray(1, 1 + length);
|
|
71
|
-
return 1 + this.oid.length;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
throw new Error('Invalid oid');
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Serialize an OID object
|
|
79
|
-
* @returns {Uint8Array} Array with the serialized value the OID
|
|
80
|
-
*/
|
|
81
|
-
OID.prototype.write = function () {
|
|
82
|
-
return util.concatUint8Array([new Uint8Array([this.oid.length]), this.oid]);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Serialize an OID object as a hex string
|
|
87
|
-
* @returns {string} String with the hex value of the OID
|
|
88
|
-
*/
|
|
89
|
-
OID.prototype.toHex = function() {
|
|
90
|
-
return util.Uint8Array_to_hex(this.oid);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* If a known curve object identifier, return the canonical name of the curve
|
|
95
|
-
* @returns {string} String with the canonical name of the curve
|
|
96
|
-
*/
|
|
97
|
-
OID.prototype.getName = function() {
|
|
98
|
-
const hex = this.toHex();
|
|
99
|
-
if (enums.curve[hex]) {
|
|
100
|
-
return enums.write(enums.curve, hex);
|
|
101
|
-
} else {
|
|
102
|
-
throw new Error('Unknown curve object identifier.');
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
OID.fromClone = function (clone) {
|
|
107
|
-
return new OID(clone.oid);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export default OID;
|
package/src/type/s2k.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2011 Recurity Labs GmbH
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Implementation of the String-to-key specifier
|
|
20
|
-
*
|
|
21
|
-
* {@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC4880 3.7}:
|
|
22
|
-
* String-to-key (S2K) specifiers are used to convert passphrase strings
|
|
23
|
-
* into symmetric-key encryption/decryption keys. They are used in two
|
|
24
|
-
* places, currently: to encrypt the secret part of private keys in the
|
|
25
|
-
* private keyring, and to convert passphrases to encryption keys for
|
|
26
|
-
* symmetrically encrypted messages.
|
|
27
|
-
* @requires config
|
|
28
|
-
* @requires crypto
|
|
29
|
-
* @requires enums
|
|
30
|
-
* @requires util
|
|
31
|
-
* @module type/s2k
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
import config from '../config';
|
|
35
|
-
import crypto from '../crypto';
|
|
36
|
-
import enums from '../enums.js';
|
|
37
|
-
import util from '../util.js';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @constructor
|
|
41
|
-
*/
|
|
42
|
-
function S2K() {
|
|
43
|
-
/** @type {module:enums.hash} */
|
|
44
|
-
this.algorithm = 'sha256';
|
|
45
|
-
/** @type {module:enums.s2k} */
|
|
46
|
-
this.type = 'iterated';
|
|
47
|
-
/** @type {Integer} */
|
|
48
|
-
this.c = config.s2k_iteration_count_byte;
|
|
49
|
-
/** Eight bytes of salt in a binary string.
|
|
50
|
-
* @type {String}
|
|
51
|
-
*/
|
|
52
|
-
this.salt = null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
S2K.prototype.get_count = function () {
|
|
56
|
-
// Exponent bias, defined in RFC4880
|
|
57
|
-
const expbias = 6;
|
|
58
|
-
|
|
59
|
-
return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
|
|
64
|
-
* @param {String} input Payload of string-to-key specifier
|
|
65
|
-
* @returns {Integer} Actual length of the object
|
|
66
|
-
*/
|
|
67
|
-
S2K.prototype.read = function (bytes) {
|
|
68
|
-
let i = 0;
|
|
69
|
-
this.type = enums.read(enums.s2k, bytes[i++]);
|
|
70
|
-
this.algorithm = bytes[i++];
|
|
71
|
-
if (this.type !== 'gnu') {
|
|
72
|
-
this.algorithm = enums.read(enums.hash, this.algorithm);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
switch (this.type) {
|
|
76
|
-
case 'simple':
|
|
77
|
-
break;
|
|
78
|
-
|
|
79
|
-
case 'salted':
|
|
80
|
-
this.salt = bytes.subarray(i, i + 8);
|
|
81
|
-
i += 8;
|
|
82
|
-
break;
|
|
83
|
-
|
|
84
|
-
case 'iterated':
|
|
85
|
-
this.salt = bytes.subarray(i, i + 8);
|
|
86
|
-
i += 8;
|
|
87
|
-
|
|
88
|
-
// Octet 10: count, a one-octet, coded value
|
|
89
|
-
this.c = bytes[i++];
|
|
90
|
-
break;
|
|
91
|
-
|
|
92
|
-
case 'gnu':
|
|
93
|
-
if (util.Uint8Array_to_str(bytes.subarray(i, i + 3)) === "GNU") {
|
|
94
|
-
i += 3; // GNU
|
|
95
|
-
const gnuExtType = 1000 + bytes[i++];
|
|
96
|
-
if (gnuExtType === 1001) {
|
|
97
|
-
this.type = 'gnu-dummy';
|
|
98
|
-
// GnuPG extension mode 1001 -- don't write secret key at all
|
|
99
|
-
} else {
|
|
100
|
-
throw new Error("Unknown s2k gnu protection mode.");
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
throw new Error("Unknown s2k type.");
|
|
104
|
-
}
|
|
105
|
-
break;
|
|
106
|
-
|
|
107
|
-
default:
|
|
108
|
-
throw new Error("Unknown s2k type.");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return i;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Serializes s2k information
|
|
117
|
-
* @returns {Uint8Array} binary representation of s2k
|
|
118
|
-
*/
|
|
119
|
-
S2K.prototype.write = function () {
|
|
120
|
-
if (this.type === 'gnu-dummy') {
|
|
121
|
-
return new Uint8Array([101, 0, ...util.str_to_Uint8Array('GNU'), 1]);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const arr = [new Uint8Array([enums.write(enums.s2k, this.type), enums.write(enums.hash, this.algorithm)])];
|
|
125
|
-
|
|
126
|
-
switch (this.type) {
|
|
127
|
-
case 'simple':
|
|
128
|
-
break;
|
|
129
|
-
case 'salted':
|
|
130
|
-
arr.push(this.salt);
|
|
131
|
-
break;
|
|
132
|
-
case 'iterated':
|
|
133
|
-
arr.push(this.salt);
|
|
134
|
-
arr.push(new Uint8Array([this.c]));
|
|
135
|
-
break;
|
|
136
|
-
case 'gnu':
|
|
137
|
-
throw new Error("GNU s2k type not supported.");
|
|
138
|
-
default:
|
|
139
|
-
throw new Error("Unknown s2k type.");
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return util.concatUint8Array(arr);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Produces a key using the specified passphrase and the defined
|
|
147
|
-
* hashAlgorithm
|
|
148
|
-
* @param {String} passphrase Passphrase containing user input
|
|
149
|
-
* @returns {Uint8Array} Produced key with a length corresponding to
|
|
150
|
-
* hashAlgorithm hash length
|
|
151
|
-
*/
|
|
152
|
-
S2K.prototype.produce_key = async function (passphrase, numBytes) {
|
|
153
|
-
passphrase = util.encode_utf8(passphrase);
|
|
154
|
-
const algorithm = enums.write(enums.hash, this.algorithm);
|
|
155
|
-
|
|
156
|
-
const arr = [];
|
|
157
|
-
let rlength = 0;
|
|
158
|
-
|
|
159
|
-
let prefixlen = 0;
|
|
160
|
-
while (rlength < numBytes) {
|
|
161
|
-
let toHash;
|
|
162
|
-
switch (this.type) {
|
|
163
|
-
case 'simple':
|
|
164
|
-
toHash = util.concatUint8Array([new Uint8Array(prefixlen), passphrase]);
|
|
165
|
-
break;
|
|
166
|
-
case 'salted':
|
|
167
|
-
toHash = util.concatUint8Array([new Uint8Array(prefixlen), this.salt, passphrase]);
|
|
168
|
-
break;
|
|
169
|
-
case 'iterated': {
|
|
170
|
-
const data = util.concatUint8Array([this.salt, passphrase]);
|
|
171
|
-
let datalen = data.length;
|
|
172
|
-
const count = Math.max(this.get_count(), datalen);
|
|
173
|
-
toHash = new Uint8Array(prefixlen + count);
|
|
174
|
-
toHash.set(data, prefixlen);
|
|
175
|
-
for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
|
|
176
|
-
toHash.copyWithin(pos, prefixlen, pos);
|
|
177
|
-
}
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
case 'gnu':
|
|
181
|
-
throw new Error("GNU s2k type not supported.");
|
|
182
|
-
default:
|
|
183
|
-
throw new Error("Unknown s2k type.");
|
|
184
|
-
}
|
|
185
|
-
const result = await crypto.hash.digest(algorithm, toHash);
|
|
186
|
-
arr.push(result);
|
|
187
|
-
rlength += result.length;
|
|
188
|
-
prefixlen++;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return util.concatUint8Array(arr).subarray(0, numBytes);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
S2K.fromClone = function (clone) {
|
|
195
|
-
const s2k = new S2K();
|
|
196
|
-
s2k.algorithm = clone.algorithm;
|
|
197
|
-
s2k.type = clone.type;
|
|
198
|
-
s2k.c = clone.c;
|
|
199
|
-
s2k.salt = clone.salt;
|
|
200
|
-
return s2k;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
export default S2K;
|