@protontech/openpgp 4.10.5 → 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.
Files changed (173) hide show
  1. package/README.md +311 -239
  2. package/dist/lightweight/bn.interface.min.mjs +3 -0
  3. package/dist/lightweight/bn.interface.min.mjs.map +1 -0
  4. package/dist/lightweight/bn.interface.mjs +340 -0
  5. package/dist/lightweight/bn.min.mjs +3 -0
  6. package/dist/lightweight/bn.min.mjs.map +1 -0
  7. package/dist/lightweight/bn.mjs +3434 -0
  8. package/dist/lightweight/elliptic.min.mjs +3 -0
  9. package/dist/lightweight/elliptic.min.mjs.map +1 -0
  10. package/dist/lightweight/elliptic.mjs +4313 -0
  11. package/dist/lightweight/openpgp.min.mjs +3 -0
  12. package/dist/lightweight/openpgp.min.mjs.map +1 -0
  13. package/dist/lightweight/openpgp.mjs +31375 -0
  14. package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
  15. package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
  16. package/dist/lightweight/ponyfill.es6.mjs +3831 -0
  17. package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
  18. package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
  19. package/dist/lightweight/web-streams-adapter.mjs +561 -0
  20. package/dist/node/openpgp.js +43943 -0
  21. package/dist/node/openpgp.min.js +17 -0
  22. package/dist/node/openpgp.min.js.map +1 -0
  23. package/dist/node/openpgp.min.mjs +17 -0
  24. package/dist/node/openpgp.min.mjs.map +1 -0
  25. package/dist/node/openpgp.mjs +43880 -0
  26. package/dist/openpgp.js +41080 -41565
  27. package/dist/openpgp.min.js +17 -2
  28. package/dist/openpgp.min.js.map +1 -0
  29. package/dist/openpgp.min.mjs +17 -0
  30. package/dist/openpgp.min.mjs.map +1 -0
  31. package/dist/openpgp.mjs +43868 -0
  32. package/lightweight/package.json +5 -0
  33. package/openpgp.d.ts +889 -0
  34. package/package.json +63 -57
  35. package/dist/compat/openpgp.js +0 -61067
  36. package/dist/compat/openpgp.min.js +0 -2
  37. package/dist/compat/openpgp.worker.js +0 -173
  38. package/dist/compat/openpgp.worker.min.js +0 -2
  39. package/dist/lightweight/elliptic.min.js +0 -5
  40. package/dist/lightweight/openpgp.js +0 -40024
  41. package/dist/lightweight/openpgp.min.js +0 -2
  42. package/dist/lightweight/openpgp.worker.js +0 -173
  43. package/dist/lightweight/openpgp.worker.min.js +0 -2
  44. package/dist/openpgp.worker.js +0 -173
  45. package/dist/openpgp.worker.min.js +0 -2
  46. package/src/cleartext.js +0 -220
  47. package/src/config/config.js +0 -224
  48. package/src/config/index.js +0 -7
  49. package/src/config/localStorage.js +0 -35
  50. package/src/crypto/aes_kw.js +0 -153
  51. package/src/crypto/cfb.js +0 -169
  52. package/src/crypto/cipher/aes.js +0 -27
  53. package/src/crypto/cipher/blowfish.js +0 -398
  54. package/src/crypto/cipher/cast5.js +0 -610
  55. package/src/crypto/cipher/des.js +0 -476
  56. package/src/crypto/cipher/index.js +0 -91
  57. package/src/crypto/cipher/twofish.js +0 -346
  58. package/src/crypto/cmac.js +0 -98
  59. package/src/crypto/crypto.js +0 -394
  60. package/src/crypto/eax.js +0 -172
  61. package/src/crypto/gcm.js +0 -141
  62. package/src/crypto/hash/index.js +0 -163
  63. package/src/crypto/hash/md5.js +0 -205
  64. package/src/crypto/index.js +0 -57
  65. package/src/crypto/ocb.js +0 -274
  66. package/src/crypto/pkcs1.js +0 -170
  67. package/src/crypto/pkcs5.js +0 -55
  68. package/src/crypto/public_key/dsa.js +0 -188
  69. package/src/crypto/public_key/elgamal.js +0 -137
  70. package/src/crypto/public_key/elliptic/curves.js +0 -385
  71. package/src/crypto/public_key/elliptic/ecdh.js +0 -414
  72. package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
  73. package/src/crypto/public_key/elliptic/eddsa.js +0 -119
  74. package/src/crypto/public_key/elliptic/index.js +0 -34
  75. package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
  76. package/src/crypto/public_key/index.js +0 -28
  77. package/src/crypto/public_key/prime.js +0 -275
  78. package/src/crypto/public_key/rsa.js +0 -597
  79. package/src/crypto/random.js +0 -145
  80. package/src/crypto/signature.js +0 -137
  81. package/src/encoding/armor.js +0 -433
  82. package/src/encoding/base64.js +0 -96
  83. package/src/enums.js +0 -493
  84. package/src/hkp.js +0 -89
  85. package/src/index.js +0 -161
  86. package/src/key/factory.js +0 -326
  87. package/src/key/helper.js +0 -363
  88. package/src/key/index.js +0 -32
  89. package/src/key/key.js +0 -890
  90. package/src/key/subkey.js +0 -187
  91. package/src/key/user.js +0 -230
  92. package/src/keyring/index.js +0 -12
  93. package/src/keyring/keyring.js +0 -229
  94. package/src/keyring/localstore.js +0 -119
  95. package/src/lightweight_helper.js +0 -26
  96. package/src/message.js +0 -825
  97. package/src/openpgp.js +0 -717
  98. package/src/packet/all_packets.js +0 -116
  99. package/src/packet/clone.js +0 -189
  100. package/src/packet/compressed.js +0 -194
  101. package/src/packet/index.js +0 -20
  102. package/src/packet/literal.js +0 -168
  103. package/src/packet/marker.js +0 -62
  104. package/src/packet/one_pass_signature.js +0 -156
  105. package/src/packet/packet.js +0 -300
  106. package/src/packet/packetlist.js +0 -232
  107. package/src/packet/public_key.js +0 -280
  108. package/src/packet/public_key_encrypted_session_key.js +0 -156
  109. package/src/packet/public_subkey.js +0 -44
  110. package/src/packet/secret_key.js +0 -448
  111. package/src/packet/secret_subkey.js +0 -41
  112. package/src/packet/signature.js +0 -782
  113. package/src/packet/sym_encrypted_aead_protected.js +0 -189
  114. package/src/packet/sym_encrypted_integrity_protected.js +0 -139
  115. package/src/packet/sym_encrypted_session_key.js +0 -204
  116. package/src/packet/symmetrically_encrypted.js +0 -118
  117. package/src/packet/trust.js +0 -35
  118. package/src/packet/user_attribute.js +0 -94
  119. package/src/packet/userid.js +0 -87
  120. package/src/polyfills.js +0 -64
  121. package/src/signature.js +0 -73
  122. package/src/type/ecdh_symkey.js +0 -69
  123. package/src/type/kdf_params.js +0 -114
  124. package/src/type/keyid.js +0 -110
  125. package/src/type/mpi.js +0 -138
  126. package/src/type/oid.js +0 -110
  127. package/src/type/s2k.js +0 -203
  128. package/src/util.js +0 -836
  129. package/src/wkd.js +0 -88
  130. package/src/worker/async_proxy.js +0 -190
  131. package/src/worker/worker.js +0 -167
  132. package/test/crypto/aes_kw.js +0 -57
  133. package/test/crypto/cipher/aes.js +0 -86
  134. package/test/crypto/cipher/blowfish.js +0 -58
  135. package/test/crypto/cipher/cast5.js +0 -25
  136. package/test/crypto/cipher/des.js +0 -143
  137. package/test/crypto/cipher/index.js +0 -7
  138. package/test/crypto/cipher/twofish.js +0 -71
  139. package/test/crypto/crypto.js +0 -383
  140. package/test/crypto/eax.js +0 -150
  141. package/test/crypto/ecdh.js +0 -359
  142. package/test/crypto/elliptic.js +0 -251
  143. package/test/crypto/elliptic_data.js +0 -102
  144. package/test/crypto/hash/index.js +0 -5
  145. package/test/crypto/hash/md5.js +0 -16
  146. package/test/crypto/hash/ripemd.js +0 -14
  147. package/test/crypto/hash/sha.js +0 -20
  148. package/test/crypto/index.js +0 -14
  149. package/test/crypto/ocb.js +0 -183
  150. package/test/crypto/pkcs5.js +0 -39
  151. package/test/crypto/random.js +0 -79
  152. package/test/crypto/rsa.js +0 -180
  153. package/test/crypto/validate.js +0 -387
  154. package/test/general/armor.js +0 -408
  155. package/test/general/brainpool.js +0 -360
  156. package/test/general/decompression.js +0 -60
  157. package/test/general/ecc_nist.js +0 -115
  158. package/test/general/ecc_secp256k1.js +0 -242
  159. package/test/general/forwarding.js +0 -43
  160. package/test/general/hkp.js +0 -165
  161. package/test/general/index.js +0 -20
  162. package/test/general/key.js +0 -3402
  163. package/test/general/keyring.js +0 -336
  164. package/test/general/oid.js +0 -39
  165. package/test/general/openpgp.js +0 -2542
  166. package/test/general/packet.js +0 -937
  167. package/test/general/signature.js +0 -1665
  168. package/test/general/streaming.js +0 -944
  169. package/test/general/testInputs.js +0 -18
  170. package/test/general/util.js +0 -183
  171. package/test/general/wkd.js +0 -48
  172. package/test/general/x25519.js +0 -556
  173. package/test/unittests.js +0 -64
@@ -1,224 +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
- * Global configuration values.
20
- * @requires enums
21
- */
22
-
23
- import enums from '../enums';
24
-
25
- export default {
26
- /**
27
- * @memberof module:config
28
- * @property {Integer} prefer_hash_algorithm Default hash algorithm {@link module:enums.hash}
29
- */
30
- prefer_hash_algorithm: enums.hash.sha256,
31
- /**
32
- * @memberof module:config
33
- * @property {Integer} encryption_cipher Default encryption cipher {@link module:enums.symmetric}
34
- */
35
- encryption_cipher: enums.symmetric.aes256,
36
- /**
37
- * @memberof module:config
38
- * @property {Integer} compression Default compression algorithm {@link module:enums.compression}
39
- */
40
- compression: enums.compression.uncompressed,
41
- /**
42
- * @memberof module:config
43
- * @property {Integer} deflate_level Default zip/zlib compression level, between 1 and 9
44
- */
45
- deflate_level: 6,
46
-
47
- /**
48
- * Use Authenticated Encryption with Additional Data (AEAD) protection for symmetric encryption.
49
- * **NOT INTEROPERABLE WITH OTHER OPENPGP IMPLEMENTATIONS**
50
- * **FUTURE OPENPGP.JS VERSIONS MAY BREAK COMPATIBILITY WHEN USING THIS OPTION**
51
- * @see {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-07|RFC4880bis-07}
52
- * @memberof module:config
53
- * @property {Boolean} aead_protect
54
- */
55
- aead_protect: false,
56
- /**
57
- * Default Authenticated Encryption with Additional Data (AEAD) encryption mode
58
- * Only has an effect when aead_protect is set to true.
59
- * @memberof module:config
60
- * @property {Integer} aead_mode Default AEAD mode {@link module:enums.aead}
61
- */
62
- aead_mode: enums.aead.eax,
63
- /**
64
- * Chunk Size Byte for Authenticated Encryption with Additional Data (AEAD) mode
65
- * Only has an effect when aead_protect is set to true.
66
- * Must be an integer value from 0 to 56.
67
- * @memberof module:config
68
- * @property {Integer} aead_chunk_size_byte
69
- */
70
- aead_chunk_size_byte: 12,
71
- /**
72
- * Use V5 keys.
73
- * **NOT INTEROPERABLE WITH OTHER OPENPGP IMPLEMENTATIONS**
74
- * **FUTURE OPENPGP.JS VERSIONS MAY BREAK COMPATIBILITY WHEN USING THIS OPTION**
75
- * @memberof module:config
76
- * @property {Boolean} v5_keys
77
- */
78
- v5_keys: false,
79
- /**
80
- * {@link https://tools.ietf.org/html/rfc4880#section-3.7.1.3|RFC4880 3.7.1.3}:
81
- * Iteration Count Byte for S2K (String to Key)
82
- * @memberof module:config
83
- * @property {Integer} s2k_iteration_count_byte
84
- */
85
- s2k_iteration_count_byte: 224,
86
- /** Use integrity protection for symmetric encryption
87
- * @memberof module:config
88
- * @property {Boolean} integrity_protect
89
- */
90
- integrity_protect: true,
91
- /**
92
- * @memberof module:config
93
- * @property {Boolean} ignore_mdc_error Fail on decrypt if message is not integrity protected
94
- */
95
- ignore_mdc_error: false,
96
- /**
97
- * @memberof module:config
98
- * @property {Boolean} allow_unauthenticated_stream Stream unauthenticated data before integrity has been checked
99
- */
100
- allow_unauthenticated_stream: false,
101
- /**
102
- * @memberof module:config
103
- * @property {Boolean} checksum_required Do not throw error when armor is missing a checksum
104
- */
105
- checksum_required: false,
106
- /**
107
- * @memberof module:config
108
- * @property {Boolean} rsa_blinding
109
- */
110
- rsa_blinding: true,
111
- /**
112
- * Work-around for rare GPG decryption bug when encrypting with multiple passwords.
113
- * **Slower and slightly less secure**
114
- * @memberof module:config
115
- * @property {Boolean} password_collision_check
116
- */
117
- password_collision_check: false,
118
- /**
119
- * @memberof module:config
120
- * @property {Boolean} revocations_expire If true, expired revocation signatures are ignored
121
- */
122
- revocations_expire: false,
123
-
124
- /**
125
- * @memberof module:config
126
- * @property {Boolean} use_native Use native Node.js crypto/zlib and WebCrypto APIs when available
127
- */
128
- use_native: true,
129
- /**
130
- * @memberof module:config
131
- * @property {Integer} min_bytes_for_web_crypto The minimum amount of bytes for which to use native WebCrypto APIs when available
132
- */
133
- min_bytes_for_web_crypto: 1000,
134
- /**
135
- * @memberof module:config
136
- * @property {Boolean} Use transferable objects between the Web Worker and main thread
137
- */
138
- zero_copy: false,
139
- /**
140
- * @memberof module:config
141
- * @property {Boolean} debug If enabled, debug messages will be printed
142
- */
143
- debug: false,
144
- /**
145
- * @memberof module:config
146
- * @property {Boolean} tolerant Ignore unsupported/unrecognizable packets instead of throwing an error
147
- */
148
- tolerant: true,
149
-
150
- /**
151
- * @memberof module:config
152
- * @property {Boolean} show_version Whether to include {@link module:config/config.versionstring} in armored messages
153
- */
154
- show_version: true,
155
- /**
156
- * @memberof module:config
157
- * @property {Boolean} show_comment Whether to include {@link module:config/config.commentstring} in armored messages
158
- */
159
- show_comment: true,
160
- /**
161
- * @memberof module:config
162
- * @property {String} versionstring A version string to be included in armored messages
163
- */
164
- versionstring: "OpenPGP.js VERSION",
165
- /**
166
- * @memberof module:config
167
- * @property {String} commentstring A comment string to be included in armored messages
168
- */
169
- commentstring: "https://openpgpjs.org",
170
-
171
- /**
172
- * @memberof module:config
173
- * @property {String} keyserver
174
- */
175
- keyserver: "https://keyserver.ubuntu.com",
176
- /**
177
- * @memberof module:config
178
- * @property {String} node_store
179
- */
180
- node_store: "./openpgp.store",
181
- /**
182
- * Max userid string length (used for parsing)
183
- * @memberof module:config
184
- * @property {Integer} max_userid_length
185
- */
186
- max_userid_length: 1024 * 5,
187
- /**
188
- * Contains notatations that are considered "known". Known notations do not trigger
189
- * validation error when the notation is marked as critical.
190
- * @memberof module:config
191
- * @property {Array} known_notations
192
- */
193
- known_notations: ["preferred-email-encoding@pgp.com", "pka-address@gnupg.org"],
194
- /**
195
- * @memberof module:config
196
- * @property {Boolean} use_indutny_elliptic Whether to use the indutny/elliptic library. When false, certain curves will not be supported.
197
- */
198
- use_indutny_elliptic: true,
199
- /**
200
- * @memberof module:config
201
- * @property {Boolean} external_indutny_elliptic Whether to lazily load the indutny/elliptic library from an external path on demand.
202
- */
203
- external_indutny_elliptic: false,
204
- /**
205
- * @memberof module:config
206
- * @property {String} indutny_elliptic_path The path to load the indutny/elliptic library from. Only has an effect if `config.external_indutny_elliptic` is true.
207
- */
208
- indutny_elliptic_path: './elliptic.min.js',
209
- /**
210
- * @memberof module:config
211
- * @property {Object} indutny_elliptic_fetch_options Options object to pass to `fetch` when loading the indutny/elliptic library. Only has an effect if `config.external_indutny_elliptic` is true.
212
- */
213
- indutny_elliptic_fetch_options: {},
214
- /**
215
- * @memberof module:config
216
- * @property {Set<Integer>} reject_hash_algorithms Reject insecure hash algorithms {@link module:enums.hash}
217
- */
218
- reject_hash_algorithms: new global.Set([enums.hash.md5, enums.hash.ripemd]),
219
- /**
220
- * @memberof module:config
221
- * @property {Set<Integer>} reject_message_hash_algorithms Reject insecure message hash algorithms {@link module:enums.hash}
222
- */
223
- reject_message_hash_algorithms: new global.Set([enums.hash.md5, enums.hash.ripemd, enums.hash.sha1])
224
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * @fileoverview This object contains global configuration values.
3
- * @see module:config/config
4
- * @module config
5
- */
6
-
7
- export { default } from './config.js';
@@ -1,35 +0,0 @@
1
- /**
2
- * @fileoverview Provides functions for storing and retrieving configuration from HTML5 local storage.
3
- * @module config/localStorage
4
- */
5
-
6
- /**
7
- * This object is used for storing and retrieving configuration from HTML5 local storage.
8
- * @constructor
9
- */
10
- function LocalStorage() {}
11
-
12
- /**
13
- * Reads the config out of the HTML5 local storage
14
- * and initializes the object config.
15
- * if config is null the default config will be used
16
- */
17
- LocalStorage.prototype.read = function () {
18
- const raw = global.localStorage.getItem("config");
19
- const cf = (raw === null ? null : JSON.parse(raw));
20
- if (cf === null) {
21
- this.config = this.default_config;
22
- this.write();
23
- } else {
24
- this.config = cf;
25
- }
26
- };
27
-
28
- /**
29
- * Writes the config to HTML5 local storage
30
- */
31
- LocalStorage.prototype.write = function () {
32
- global.localStorage.setItem("config", JSON.stringify(this.config));
33
- };
34
-
35
- export default LocalStorage;
@@ -1,153 +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
- * @fileoverview Implementation of RFC 3394 AES Key Wrap & Key Unwrap funcions
20
- * @see module:crypto/public_key/elliptic/ecdh
21
- * @requires crypto/cipher
22
- * @requires util
23
- * @module crypto/aes_kw
24
- */
25
-
26
- import cipher from './cipher';
27
- import util from '../util';
28
-
29
- function wrap(key, data) {
30
- const aes = new cipher["aes" + (key.length * 8)](key);
31
- const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
32
- const P = unpack(data);
33
- let A = IV;
34
- const R = P;
35
- const n = P.length / 2;
36
- const t = new Uint32Array([0, 0]);
37
- let B = new Uint32Array(4);
38
- for (let j = 0; j <= 5; ++j) {
39
- for (let i = 0; i < n; ++i) {
40
- t[1] = n * j + (1 + i);
41
- // B = A
42
- B[0] = A[0];
43
- B[1] = A[1];
44
- // B = A || R[i]
45
- B[2] = R[2 * i];
46
- B[3] = R[2 * i + 1];
47
- // B = AES(K, B)
48
- B = unpack(aes.encrypt(pack(B)));
49
- // A = MSB(64, B) ^ t
50
- A = B.subarray(0, 2);
51
- A[0] ^= t[0];
52
- A[1] ^= t[1];
53
- // R[i] = LSB(64, B)
54
- R[2 * i] = B[2];
55
- R[2 * i + 1] = B[3];
56
- }
57
- }
58
- return pack(A, R);
59
- }
60
-
61
- function unwrap(key, data) {
62
- const aes = new cipher["aes" + (key.length * 8)](key);
63
- const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
64
- const C = unpack(data);
65
- let A = C.subarray(0, 2);
66
- const R = C.subarray(2);
67
- const n = C.length / 2 - 1;
68
- const t = new Uint32Array([0, 0]);
69
- let B = new Uint32Array(4);
70
- for (let j = 5; j >= 0; --j) {
71
- for (let i = n - 1; i >= 0; --i) {
72
- t[1] = n * j + (i + 1);
73
- // B = A ^ t
74
- B[0] = A[0] ^ t[0];
75
- B[1] = A[1] ^ t[1];
76
- // B = (A ^ t) || R[i]
77
- B[2] = R[2 * i];
78
- B[3] = R[2 * i + 1];
79
- // B = AES-1(B)
80
- B = unpack(aes.decrypt(pack(B)));
81
- // A = MSB(64, B)
82
- A = B.subarray(0, 2);
83
- // R[i] = LSB(64, B)
84
- R[2 * i] = B[2];
85
- R[2 * i + 1] = B[3];
86
- }
87
- }
88
- if (A[0] === IV[0] && A[1] === IV[1]) {
89
- return pack(R);
90
- }
91
- throw new Error("Key Data Integrity failed");
92
- }
93
-
94
- function createArrayBuffer(data) {
95
- if (util.isString(data)) {
96
- const { length } = data;
97
- const buffer = new ArrayBuffer(length);
98
- const view = new Uint8Array(buffer);
99
- for (let j = 0; j < length; ++j) {
100
- view[j] = data.charCodeAt(j);
101
- }
102
- return buffer;
103
- }
104
- return new Uint8Array(data).buffer;
105
- }
106
-
107
- function unpack(data) {
108
- const { length } = data;
109
- const buffer = createArrayBuffer(data);
110
- const view = new DataView(buffer);
111
- const arr = new Uint32Array(length / 4);
112
- for (let i = 0; i < length / 4; ++i) {
113
- arr[i] = view.getUint32(4 * i);
114
- }
115
- return arr;
116
- }
117
-
118
- function pack() {
119
- let length = 0;
120
- for (let k = 0; k < arguments.length; ++k) {
121
- length += 4 * arguments[k].length;
122
- }
123
- const buffer = new ArrayBuffer(length);
124
- const view = new DataView(buffer);
125
- let offset = 0;
126
- for (let i = 0; i < arguments.length; ++i) {
127
- for (let j = 0; j < arguments[i].length; ++j) {
128
- view.setUint32(offset + 4 * j, arguments[i][j]);
129
- }
130
- offset += 4 * arguments[i].length;
131
- }
132
- return new Uint8Array(buffer);
133
- }
134
-
135
- export default {
136
- /**
137
- * AES key wrap
138
- * @function
139
- * @param {String} key
140
- * @param {String} data
141
- * @returns {Uint8Array}
142
- */
143
- wrap,
144
- /**
145
- * AES key unwrap
146
- * @function
147
- * @param {String} key
148
- * @param {String} data
149
- * @returns {Uint8Array}
150
- * @throws {Error}
151
- */
152
- unwrap
153
- };
package/src/crypto/cfb.js DELETED
@@ -1,169 +0,0 @@
1
- // Modified by ProtonTech AG
2
-
3
- // Modified by Recurity Labs GmbH
4
-
5
- // modified version of https://www.hanewin.net/encrypt/PGdecode.js:
6
-
7
- /* OpenPGP encryption using RSA/AES
8
- * Copyright 2005-2006 Herbert Hanewinkel, www.haneWIN.de
9
- * version 2.0, check www.haneWIN.de for the latest version
10
-
11
- * This software is provided as-is, without express or implied warranty.
12
- * Permission to use, copy, modify, distribute or sell this software, with or
13
- * without fee, for any purpose and by any individual or organization, is hereby
14
- * granted, provided that the above copyright notice and this paragraph appear
15
- * in all copies. Distribution as a part of an application or binary must
16
- * include the above copyright notice in the documentation and/or other
17
- * materials provided with the application or distribution.
18
- */
19
-
20
- /**
21
- * @requires web-stream-tools
22
- * @requires crypto/cipher
23
- * @requires util
24
- * @module crypto/cfb
25
- */
26
-
27
- import { AES_CFB } from 'asmcrypto.js/dist_es5/aes/cfb';
28
-
29
- import stream from 'web-stream-tools';
30
- import cipher from './cipher';
31
- import config from '../config';
32
- import util from '../util';
33
-
34
- const webCrypto = util.getWebCrypto();
35
- const nodeCrypto = util.getNodeCrypto();
36
- const Buffer = util.getNodeBuffer();
37
-
38
- const knownAlgos = nodeCrypto ? nodeCrypto.getCiphers() : [];
39
- const nodeAlgos = {
40
- idea: knownAlgos.includes('idea-cfb') ? 'idea-cfb' : undefined, /* Unused, not implemented */
41
- '3des': knownAlgos.includes('des-ede3-cfb') ? 'des-ede3-cfb' : undefined,
42
- tripledes: knownAlgos.includes('des-ede3-cfb') ? 'des-ede3-cfb' : undefined,
43
- cast5: knownAlgos.includes('cast5-cfb') ? 'cast5-cfb' : undefined,
44
- blowfish: knownAlgos.includes('bf-cfb') ? 'bf-cfb' : undefined,
45
- aes128: knownAlgos.includes('aes-128-cfb') ? 'aes-128-cfb' : undefined,
46
- aes192: knownAlgos.includes('aes-192-cfb') ? 'aes-192-cfb' : undefined,
47
- aes256: knownAlgos.includes('aes-256-cfb') ? 'aes-256-cfb' : undefined
48
- /* twofish is not implemented in OpenSSL */
49
- };
50
-
51
- export default {
52
- encrypt: function(algo, key, plaintext, iv) {
53
- if (util.getNodeCrypto() && nodeAlgos[algo]) { // Node crypto library.
54
- return nodeEncrypt(algo, key, plaintext, iv);
55
- }
56
- if (algo.substr(0, 3) === 'aes') {
57
- return aesEncrypt(algo, key, plaintext, iv);
58
- }
59
-
60
- const cipherfn = new cipher[algo](key);
61
- const block_size = cipherfn.blockSize;
62
-
63
- const blockc = iv.slice();
64
- let pt = new Uint8Array();
65
- const process = chunk => {
66
- if (chunk) {
67
- pt = util.concatUint8Array([pt, chunk]);
68
- }
69
- const ciphertext = new Uint8Array(pt.length);
70
- let i;
71
- let j = 0;
72
- while (chunk ? pt.length >= block_size : pt.length) {
73
- const encblock = cipherfn.encrypt(blockc);
74
- for (i = 0; i < block_size; i++) {
75
- blockc[i] = pt[i] ^ encblock[i];
76
- ciphertext[j++] = blockc[i];
77
- }
78
- pt = pt.subarray(block_size);
79
- }
80
- return ciphertext.subarray(0, j);
81
- };
82
- return stream.transform(plaintext, process, process);
83
- },
84
-
85
- decrypt: async function(algo, key, ciphertext, iv) {
86
- if (util.getNodeCrypto() && nodeAlgos[algo]) { // Node crypto library.
87
- return nodeDecrypt(algo, key, ciphertext, iv);
88
- }
89
- if (algo.substr(0, 3) === 'aes') {
90
- return aesDecrypt(algo, key, ciphertext, iv);
91
- }
92
-
93
- const cipherfn = new cipher[algo](key);
94
- const block_size = cipherfn.blockSize;
95
-
96
- let blockp = iv;
97
- let ct = new Uint8Array();
98
- const process = chunk => {
99
- if (chunk) {
100
- ct = util.concatUint8Array([ct, chunk]);
101
- }
102
- const plaintext = new Uint8Array(ct.length);
103
- let i;
104
- let j = 0;
105
- while (chunk ? ct.length >= block_size : ct.length) {
106
- const decblock = cipherfn.encrypt(blockp);
107
- blockp = ct;
108
- for (i = 0; i < block_size; i++) {
109
- plaintext[j++] = blockp[i] ^ decblock[i];
110
- }
111
- ct = ct.subarray(block_size);
112
- }
113
- return plaintext.subarray(0, j);
114
- };
115
- return stream.transform(ciphertext, process, process);
116
- }
117
- };
118
-
119
- function aesEncrypt(algo, key, pt, iv) {
120
- if (
121
- util.getWebCrypto() &&
122
- key.length !== 24 && // Chrome doesn't support 192 bit keys, see https://www.chromium.org/blink/webcrypto#TOC-AES-support
123
- !util.isStream(pt) &&
124
- pt.length >= 3000 * config.min_bytes_for_web_crypto // Default to a 3MB minimum. Chrome is pretty slow for small messages, see: https://bugs.chromium.org/p/chromium/issues/detail?id=701188#c2
125
- ) { // Web Crypto
126
- return webEncrypt(algo, key, pt, iv);
127
- }
128
- // asm.js fallback
129
- const cfb = new AES_CFB(key, iv);
130
- return stream.transform(pt, value => cfb.AES_Encrypt_process(value), () => cfb.AES_Encrypt_finish());
131
- }
132
-
133
- function aesDecrypt(algo, key, ct, iv) {
134
- if (util.isStream(ct)) {
135
- const cfb = new AES_CFB(key, iv);
136
- return stream.transform(ct, value => cfb.AES_Decrypt_process(value), () => cfb.AES_Decrypt_finish());
137
- }
138
- return AES_CFB.decrypt(ct, key, iv);
139
- }
140
-
141
- function xorMut(a, b) {
142
- for (let i = 0; i < a.length; i++) {
143
- a[i] = a[i] ^ b[i];
144
- }
145
- }
146
-
147
- async function webEncrypt(algo, key, pt, iv) {
148
- const ALGO = 'AES-CBC';
149
- const _key = await webCrypto.importKey('raw', key, { name: ALGO }, false, ['encrypt']);
150
- const { blockSize } = cipher[algo];
151
- const cbc_pt = util.concatUint8Array([new Uint8Array(blockSize), pt]);
152
- const ct = new Uint8Array(await webCrypto.encrypt({ name: ALGO, iv }, _key, cbc_pt)).subarray(0, pt.length);
153
- xorMut(ct, pt);
154
- return ct;
155
- }
156
-
157
- function nodeEncrypt(algo, key, pt, iv) {
158
- key = Buffer.from(key);
159
- iv = Buffer.from(iv);
160
- const cipherObj = new nodeCrypto.createCipheriv(nodeAlgos[algo], key, iv);
161
- return stream.transform(pt, value => new Uint8Array(cipherObj.update(Buffer.from(value))));
162
- }
163
-
164
- function nodeDecrypt(algo, key, ct, iv) {
165
- key = Buffer.from(key);
166
- iv = Buffer.from(iv);
167
- const decipherObj = new nodeCrypto.createDecipheriv(nodeAlgos[algo], key, iv);
168
- return stream.transform(ct, value => new Uint8Array(decipherObj.update(Buffer.from(value))));
169
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * @requires asmcrypto.js
3
- */
4
-
5
- import { AES_ECB } from 'asmcrypto.js/dist_es5/aes/ecb';
6
-
7
- // TODO use webCrypto or nodeCrypto when possible.
8
- function aes(length) {
9
- const C = function(key) {
10
- const aes_ecb = new AES_ECB(key);
11
-
12
- this.encrypt = function(block) {
13
- return aes_ecb.encrypt(block);
14
- };
15
-
16
- this.decrypt = function(block) {
17
- return aes_ecb.decrypt(block);
18
- };
19
- };
20
-
21
- C.blockSize = C.prototype.blockSize = 16;
22
- C.keySize = C.prototype.keySize = length / 8;
23
-
24
- return C;
25
- }
26
-
27
- export default aes;