pdfjs-dist 2.0.943 → 2.4.456
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.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
package/lib/core/crypto.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,26 +19,18 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.calculateSHA512 = exports.calculateSHA384 = exports.calculateSHA256 = exports.calculateMD5 = exports.PDF20 = exports.PDF17 = exports.CipherTransformFactory = exports.ARCFourCipher = exports.AES256Cipher = exports.AES128Cipher =
|
27
|
+
exports.calculateSHA512 = exports.calculateSHA384 = exports.calculateSHA256 = exports.calculateMD5 = exports.PDF20 = exports.PDF17 = exports.CipherTransformFactory = exports.ARCFourCipher = exports.AES256Cipher = exports.AES128Cipher = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var
|
31
|
+
var _primitives = require("./primitives.js");
|
32
32
|
|
33
|
-
var
|
34
|
-
|
35
|
-
var _stream = require('./stream');
|
36
|
-
|
37
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
38
|
-
|
39
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
40
|
-
|
41
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
33
|
+
var _stream = require("./stream.js");
|
42
34
|
|
43
35
|
var ARCFourCipher = function ARCFourCipherClosure() {
|
44
36
|
function ARCFourCipher(key) {
|
@@ -49,17 +41,21 @@ var ARCFourCipher = function ARCFourCipherClosure() {
|
|
49
41
|
j = 0,
|
50
42
|
tmp,
|
51
43
|
keyLength = key.length;
|
44
|
+
|
52
45
|
for (i = 0; i < 256; ++i) {
|
53
46
|
s[i] = i;
|
54
47
|
}
|
48
|
+
|
55
49
|
for (i = 0; i < 256; ++i) {
|
56
50
|
tmp = s[i];
|
57
|
-
j = j + tmp + key[i % keyLength] &
|
51
|
+
j = j + tmp + key[i % keyLength] & 0xff;
|
58
52
|
s[i] = s[j];
|
59
53
|
s[j] = tmp;
|
60
54
|
}
|
55
|
+
|
61
56
|
this.s = s;
|
62
57
|
}
|
58
|
+
|
63
59
|
ARCFourCipher.prototype = {
|
64
60
|
encryptBlock: function ARCFourCipher_encryptBlock(data) {
|
65
61
|
var i,
|
@@ -70,15 +66,17 @@ var ARCFourCipher = function ARCFourCipherClosure() {
|
|
70
66
|
b = this.b,
|
71
67
|
s = this.s;
|
72
68
|
var output = new Uint8Array(n);
|
69
|
+
|
73
70
|
for (i = 0; i < n; ++i) {
|
74
|
-
a = a + 1 &
|
71
|
+
a = a + 1 & 0xff;
|
75
72
|
tmp = s[a];
|
76
|
-
b = b + tmp &
|
73
|
+
b = b + tmp & 0xff;
|
77
74
|
tmp2 = s[b];
|
78
75
|
s[a] = tmp2;
|
79
76
|
s[b] = tmp;
|
80
|
-
output[i] = data[i] ^ s[tmp + tmp2 &
|
77
|
+
output[i] = data[i] ^ s[tmp + tmp2 & 0xff];
|
81
78
|
}
|
79
|
+
|
82
80
|
this.a = a;
|
83
81
|
this.b = b;
|
84
82
|
return output;
|
@@ -87,9 +85,13 @@ var ARCFourCipher = function ARCFourCipherClosure() {
|
|
87
85
|
ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
|
88
86
|
return ARCFourCipher;
|
89
87
|
}();
|
88
|
+
|
89
|
+
exports.ARCFourCipher = ARCFourCipher;
|
90
|
+
|
90
91
|
var calculateMD5 = function calculateMD5Closure() {
|
91
92
|
var r = new Uint8Array([7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
|
92
93
|
var k = new Int32Array([-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632, 643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979, 76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379, 718787259, -343485551]);
|
94
|
+
|
93
95
|
function hash(data, offset, length) {
|
94
96
|
var h0 = 1732584193,
|
95
97
|
h1 = -271733879,
|
@@ -98,33 +100,40 @@ var calculateMD5 = function calculateMD5Closure() {
|
|
98
100
|
var paddedLength = length + 72 & ~63;
|
99
101
|
var padded = new Uint8Array(paddedLength);
|
100
102
|
var i, j, n;
|
103
|
+
|
101
104
|
for (i = 0; i < length; ++i) {
|
102
105
|
padded[i] = data[offset++];
|
103
106
|
}
|
107
|
+
|
104
108
|
padded[i++] = 0x80;
|
105
109
|
n = paddedLength - 8;
|
110
|
+
|
106
111
|
while (i < n) {
|
107
112
|
padded[i++] = 0;
|
108
113
|
}
|
109
|
-
|
110
|
-
padded[i++] = length
|
111
|
-
padded[i++] = length >>
|
112
|
-
padded[i++] = length >>
|
113
|
-
padded[i++] = length
|
114
|
+
|
115
|
+
padded[i++] = length << 3 & 0xff;
|
116
|
+
padded[i++] = length >> 5 & 0xff;
|
117
|
+
padded[i++] = length >> 13 & 0xff;
|
118
|
+
padded[i++] = length >> 21 & 0xff;
|
119
|
+
padded[i++] = length >>> 29 & 0xff;
|
114
120
|
padded[i++] = 0;
|
115
121
|
padded[i++] = 0;
|
116
122
|
padded[i++] = 0;
|
117
123
|
var w = new Int32Array(16);
|
124
|
+
|
118
125
|
for (i = 0; i < paddedLength;) {
|
119
126
|
for (j = 0; j < 16; ++j, i += 4) {
|
120
127
|
w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
|
121
128
|
}
|
129
|
+
|
122
130
|
var a = h0,
|
123
131
|
b = h1,
|
124
132
|
c = h2,
|
125
133
|
d = h3,
|
126
134
|
f,
|
127
135
|
g;
|
136
|
+
|
128
137
|
for (j = 0; j < 64; ++j) {
|
129
138
|
if (j < 16) {
|
130
139
|
f = b & c | ~b & d;
|
@@ -139,6 +148,7 @@ var calculateMD5 = function calculateMD5Closure() {
|
|
139
148
|
f = c ^ (b | ~d);
|
140
149
|
g = 7 * j & 15;
|
141
150
|
}
|
151
|
+
|
142
152
|
var tmp = d,
|
143
153
|
rotateArg = a + f + k[j] + w[g] | 0,
|
144
154
|
rotate = r[j];
|
@@ -147,20 +157,27 @@ var calculateMD5 = function calculateMD5Closure() {
|
|
147
157
|
b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
|
148
158
|
a = tmp;
|
149
159
|
}
|
160
|
+
|
150
161
|
h0 = h0 + a | 0;
|
151
162
|
h1 = h1 + b | 0;
|
152
163
|
h2 = h2 + c | 0;
|
153
164
|
h3 = h3 + d | 0;
|
154
165
|
}
|
166
|
+
|
155
167
|
return new Uint8Array([h0 & 0xFF, h0 >> 8 & 0xFF, h0 >> 16 & 0xFF, h0 >>> 24 & 0xFF, h1 & 0xFF, h1 >> 8 & 0xFF, h1 >> 16 & 0xFF, h1 >>> 24 & 0xFF, h2 & 0xFF, h2 >> 8 & 0xFF, h2 >> 16 & 0xFF, h2 >>> 24 & 0xFF, h3 & 0xFF, h3 >> 8 & 0xFF, h3 >> 16 & 0xFF, h3 >>> 24 & 0xFF]);
|
156
168
|
}
|
169
|
+
|
157
170
|
return hash;
|
158
171
|
}();
|
172
|
+
|
173
|
+
exports.calculateMD5 = calculateMD5;
|
174
|
+
|
159
175
|
var Word64 = function Word64Closure() {
|
160
176
|
function Word64(highInteger, lowInteger) {
|
161
177
|
this.high = highInteger | 0;
|
162
178
|
this.low = lowInteger | 0;
|
163
179
|
}
|
180
|
+
|
164
181
|
Word64.prototype = {
|
165
182
|
and: function Word64_and(word) {
|
166
183
|
this.high &= word.high;
|
@@ -194,6 +211,7 @@ var Word64 = function Word64Closure() {
|
|
194
211
|
},
|
195
212
|
rotateRight: function Word64_rotateRight(places) {
|
196
213
|
var low, high;
|
214
|
+
|
197
215
|
if (places & 32) {
|
198
216
|
high = this.low;
|
199
217
|
low = this.high;
|
@@ -201,6 +219,7 @@ var Word64 = function Word64Closure() {
|
|
201
219
|
low = this.low;
|
202
220
|
high = this.high;
|
203
221
|
}
|
222
|
+
|
204
223
|
places &= 31;
|
205
224
|
this.low = low >>> places | high << 32 - places;
|
206
225
|
this.high = high >>> places | low << 32 - places;
|
@@ -212,21 +231,23 @@ var Word64 = function Word64Closure() {
|
|
212
231
|
add: function Word64_add(word) {
|
213
232
|
var lowAdd = (this.low >>> 0) + (word.low >>> 0);
|
214
233
|
var highAdd = (this.high >>> 0) + (word.high >>> 0);
|
215
|
-
|
234
|
+
|
235
|
+
if (lowAdd > 0xffffffff) {
|
216
236
|
highAdd += 1;
|
217
237
|
}
|
238
|
+
|
218
239
|
this.low = lowAdd | 0;
|
219
240
|
this.high = highAdd | 0;
|
220
241
|
},
|
221
242
|
copyTo: function Word64_copyTo(bytes, offset) {
|
222
|
-
bytes[offset] = this.high >>> 24 &
|
223
|
-
bytes[offset + 1] = this.high >> 16 &
|
224
|
-
bytes[offset + 2] = this.high >> 8 &
|
225
|
-
bytes[offset + 3] = this.high &
|
226
|
-
bytes[offset + 4] = this.low >>> 24 &
|
227
|
-
bytes[offset + 5] = this.low >> 16 &
|
228
|
-
bytes[offset + 6] = this.low >> 8 &
|
229
|
-
bytes[offset + 7] = this.low &
|
243
|
+
bytes[offset] = this.high >>> 24 & 0xff;
|
244
|
+
bytes[offset + 1] = this.high >> 16 & 0xff;
|
245
|
+
bytes[offset + 2] = this.high >> 8 & 0xff;
|
246
|
+
bytes[offset + 3] = this.high & 0xff;
|
247
|
+
bytes[offset + 4] = this.low >>> 24 & 0xff;
|
248
|
+
bytes[offset + 5] = this.low >> 16 & 0xff;
|
249
|
+
bytes[offset + 6] = this.low >> 8 & 0xff;
|
250
|
+
bytes[offset + 7] = this.low & 0xff;
|
230
251
|
},
|
231
252
|
assign: function Word64_assign(word) {
|
232
253
|
this.high = word.high;
|
@@ -235,29 +256,38 @@ var Word64 = function Word64Closure() {
|
|
235
256
|
};
|
236
257
|
return Word64;
|
237
258
|
}();
|
259
|
+
|
238
260
|
var calculateSHA256 = function calculateSHA256Closure() {
|
239
261
|
function rotr(x, n) {
|
240
262
|
return x >>> n | x << 32 - n;
|
241
263
|
}
|
264
|
+
|
242
265
|
function ch(x, y, z) {
|
243
266
|
return x & y ^ ~x & z;
|
244
267
|
}
|
268
|
+
|
245
269
|
function maj(x, y, z) {
|
246
270
|
return x & y ^ x & z ^ y & z;
|
247
271
|
}
|
272
|
+
|
248
273
|
function sigma(x) {
|
249
274
|
return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
|
250
275
|
}
|
276
|
+
|
251
277
|
function sigmaPrime(x) {
|
252
278
|
return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
|
253
279
|
}
|
280
|
+
|
254
281
|
function littleSigma(x) {
|
255
282
|
return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
|
256
283
|
}
|
284
|
+
|
257
285
|
function littleSigmaPrime(x) {
|
258
286
|
return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
|
259
287
|
}
|
288
|
+
|
260
289
|
var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
|
290
|
+
|
261
291
|
function hash(data, offset, length) {
|
262
292
|
var h0 = 0x6a09e667,
|
263
293
|
h1 = 0xbb67ae85,
|
@@ -270,31 +300,38 @@ var calculateSHA256 = function calculateSHA256Closure() {
|
|
270
300
|
var paddedLength = Math.ceil((length + 9) / 64) * 64;
|
271
301
|
var padded = new Uint8Array(paddedLength);
|
272
302
|
var i, j, n;
|
303
|
+
|
273
304
|
for (i = 0; i < length; ++i) {
|
274
305
|
padded[i] = data[offset++];
|
275
306
|
}
|
307
|
+
|
276
308
|
padded[i++] = 0x80;
|
277
309
|
n = paddedLength - 8;
|
310
|
+
|
278
311
|
while (i < n) {
|
279
312
|
padded[i++] = 0;
|
280
313
|
}
|
314
|
+
|
281
315
|
padded[i++] = 0;
|
282
316
|
padded[i++] = 0;
|
283
317
|
padded[i++] = 0;
|
284
|
-
padded[i++] = length >>> 29 &
|
285
|
-
padded[i++] = length >> 21 &
|
286
|
-
padded[i++] = length >> 13 &
|
287
|
-
padded[i++] = length >> 5 &
|
288
|
-
padded[i++] = length << 3 &
|
318
|
+
padded[i++] = length >>> 29 & 0xff;
|
319
|
+
padded[i++] = length >> 21 & 0xff;
|
320
|
+
padded[i++] = length >> 13 & 0xff;
|
321
|
+
padded[i++] = length >> 5 & 0xff;
|
322
|
+
padded[i++] = length << 3 & 0xff;
|
289
323
|
var w = new Uint32Array(64);
|
324
|
+
|
290
325
|
for (i = 0; i < paddedLength;) {
|
291
326
|
for (j = 0; j < 16; ++j) {
|
292
327
|
w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
|
293
328
|
i += 4;
|
294
329
|
}
|
330
|
+
|
295
331
|
for (j = 16; j < 64; ++j) {
|
296
332
|
w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
|
297
333
|
}
|
334
|
+
|
298
335
|
var a = h0,
|
299
336
|
b = h1,
|
300
337
|
c = h2,
|
@@ -305,6 +342,7 @@ var calculateSHA256 = function calculateSHA256Closure() {
|
|
305
342
|
h = h7,
|
306
343
|
t1,
|
307
344
|
t2;
|
345
|
+
|
308
346
|
for (j = 0; j < 64; ++j) {
|
309
347
|
t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
|
310
348
|
t2 = sigma(a) + maj(a, b, c);
|
@@ -317,6 +355,7 @@ var calculateSHA256 = function calculateSHA256Closure() {
|
|
317
355
|
b = a;
|
318
356
|
a = t1 + t2 | 0;
|
319
357
|
}
|
358
|
+
|
320
359
|
h0 = h0 + a | 0;
|
321
360
|
h1 = h1 + b | 0;
|
322
361
|
h2 = h2 + c | 0;
|
@@ -326,10 +365,15 @@ var calculateSHA256 = function calculateSHA256Closure() {
|
|
326
365
|
h6 = h6 + g | 0;
|
327
366
|
h7 = h7 + h | 0;
|
328
367
|
}
|
368
|
+
|
329
369
|
return new Uint8Array([h0 >> 24 & 0xFF, h0 >> 16 & 0xFF, h0 >> 8 & 0xFF, h0 & 0xFF, h1 >> 24 & 0xFF, h1 >> 16 & 0xFF, h1 >> 8 & 0xFF, h1 & 0xFF, h2 >> 24 & 0xFF, h2 >> 16 & 0xFF, h2 >> 8 & 0xFF, h2 & 0xFF, h3 >> 24 & 0xFF, h3 >> 16 & 0xFF, h3 >> 8 & 0xFF, h3 & 0xFF, h4 >> 24 & 0xFF, h4 >> 16 & 0xFF, h4 >> 8 & 0xFF, h4 & 0xFF, h5 >> 24 & 0xFF, h5 >> 16 & 0xFF, h5 >> 8 & 0xFF, h5 & 0xFF, h6 >> 24 & 0xFF, h6 >> 16 & 0xFF, h6 >> 8 & 0xFF, h6 & 0xFF, h7 >> 24 & 0xFF, h7 >> 16 & 0xFF, h7 >> 8 & 0xFF, h7 & 0xFF]);
|
330
370
|
}
|
371
|
+
|
331
372
|
return hash;
|
332
373
|
}();
|
374
|
+
|
375
|
+
exports.calculateSHA256 = calculateSHA256;
|
376
|
+
|
333
377
|
var calculateSHA512 = function calculateSHA512Closure() {
|
334
378
|
function ch(result, x, y, z, tmp) {
|
335
379
|
result.assign(x);
|
@@ -339,6 +383,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
339
383
|
tmp.and(z);
|
340
384
|
result.xor(tmp);
|
341
385
|
}
|
386
|
+
|
342
387
|
function maj(result, x, y, z, tmp) {
|
343
388
|
result.assign(x);
|
344
389
|
result.and(y);
|
@@ -349,6 +394,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
349
394
|
tmp.and(z);
|
350
395
|
result.xor(tmp);
|
351
396
|
}
|
397
|
+
|
352
398
|
function sigma(result, x, tmp) {
|
353
399
|
result.assign(x);
|
354
400
|
result.rotateRight(28);
|
@@ -359,6 +405,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
359
405
|
tmp.rotateRight(39);
|
360
406
|
result.xor(tmp);
|
361
407
|
}
|
408
|
+
|
362
409
|
function sigmaPrime(result, x, tmp) {
|
363
410
|
result.assign(x);
|
364
411
|
result.rotateRight(14);
|
@@ -369,6 +416,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
369
416
|
tmp.rotateRight(41);
|
370
417
|
result.xor(tmp);
|
371
418
|
}
|
419
|
+
|
372
420
|
function littleSigma(result, x, tmp) {
|
373
421
|
result.assign(x);
|
374
422
|
result.rotateRight(1);
|
@@ -379,6 +427,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
379
427
|
tmp.shiftRight(7);
|
380
428
|
result.xor(tmp);
|
381
429
|
}
|
430
|
+
|
382
431
|
function littleSigmaPrime(result, x, tmp) {
|
383
432
|
result.assign(x);
|
384
433
|
result.rotateRight(19);
|
@@ -389,10 +438,13 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
389
438
|
tmp.shiftRight(6);
|
390
439
|
result.xor(tmp);
|
391
440
|
}
|
441
|
+
|
392
442
|
var k = [new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd), new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc), new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019), new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118), new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe), new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2), new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1), new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694), new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3), new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65), new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483), new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5), new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210), new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4), new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725), new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70), new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926), new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df), new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8), new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b), new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001), new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30), new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910), new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8), new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53), new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8), new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb), new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3), new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60), new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec), new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9), new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b), new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207), new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178), new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6), new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b), new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493), new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c), new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a), new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
|
443
|
+
|
393
444
|
function hash(data, offset, length, mode384) {
|
394
445
|
mode384 = !!mode384;
|
395
446
|
var h0, h1, h2, h3, h4, h5, h6, h7;
|
447
|
+
|
396
448
|
if (!mode384) {
|
397
449
|
h0 = new Word64(0x6a09e667, 0xf3bcc908);
|
398
450
|
h1 = new Word64(0xbb67ae85, 0x84caa73b);
|
@@ -412,17 +464,22 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
412
464
|
h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
|
413
465
|
h7 = new Word64(0x47b5481d, 0xbefa4fa4);
|
414
466
|
}
|
467
|
+
|
415
468
|
var paddedLength = Math.ceil((length + 17) / 128) * 128;
|
416
469
|
var padded = new Uint8Array(paddedLength);
|
417
470
|
var i, j, n;
|
471
|
+
|
418
472
|
for (i = 0; i < length; ++i) {
|
419
473
|
padded[i] = data[offset++];
|
420
474
|
}
|
475
|
+
|
421
476
|
padded[i++] = 0x80;
|
422
477
|
n = paddedLength - 16;
|
478
|
+
|
423
479
|
while (i < n) {
|
424
480
|
padded[i++] = 0;
|
425
481
|
}
|
482
|
+
|
426
483
|
padded[i++] = 0;
|
427
484
|
padded[i++] = 0;
|
428
485
|
padded[i++] = 0;
|
@@ -434,15 +491,17 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
434
491
|
padded[i++] = 0;
|
435
492
|
padded[i++] = 0;
|
436
493
|
padded[i++] = 0;
|
437
|
-
padded[i++] = length >>> 29 &
|
438
|
-
padded[i++] = length >> 21 &
|
439
|
-
padded[i++] = length >> 13 &
|
440
|
-
padded[i++] = length >> 5 &
|
441
|
-
padded[i++] = length << 3 &
|
494
|
+
padded[i++] = length >>> 29 & 0xff;
|
495
|
+
padded[i++] = length >> 21 & 0xff;
|
496
|
+
padded[i++] = length >> 13 & 0xff;
|
497
|
+
padded[i++] = length >> 5 & 0xff;
|
498
|
+
padded[i++] = length << 3 & 0xff;
|
442
499
|
var w = new Array(80);
|
500
|
+
|
443
501
|
for (i = 0; i < 80; i++) {
|
444
502
|
w[i] = new Word64(0, 0);
|
445
503
|
}
|
504
|
+
|
446
505
|
var a = new Word64(0, 0),
|
447
506
|
b = new Word64(0, 0),
|
448
507
|
c = new Word64(0, 0);
|
@@ -456,12 +515,14 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
456
515
|
var tmp1 = new Word64(0, 0),
|
457
516
|
tmp2 = new Word64(0, 0),
|
458
517
|
tmp3;
|
518
|
+
|
459
519
|
for (i = 0; i < paddedLength;) {
|
460
520
|
for (j = 0; j < 16; ++j) {
|
461
521
|
w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
|
462
522
|
w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
|
463
523
|
i += 8;
|
464
524
|
}
|
525
|
+
|
465
526
|
for (j = 16; j < 80; ++j) {
|
466
527
|
tmp3 = w[j];
|
467
528
|
littleSigmaPrime(tmp3, w[j - 2], tmp2);
|
@@ -470,6 +531,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
470
531
|
tmp3.add(tmp1);
|
471
532
|
tmp3.add(w[j - 16]);
|
472
533
|
}
|
534
|
+
|
473
535
|
a.assign(h0);
|
474
536
|
b.assign(h1);
|
475
537
|
c.assign(h2);
|
@@ -478,6 +540,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
478
540
|
f.assign(h5);
|
479
541
|
g.assign(h6);
|
480
542
|
h.assign(h7);
|
543
|
+
|
481
544
|
for (j = 0; j < 80; ++j) {
|
482
545
|
t1.assign(h);
|
483
546
|
sigmaPrime(tmp1, e, tmp2);
|
@@ -502,6 +565,7 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
502
565
|
tmp3.add(t2);
|
503
566
|
a = tmp3;
|
504
567
|
}
|
568
|
+
|
505
569
|
h0.add(a);
|
506
570
|
h1.add(b);
|
507
571
|
h2.add(c);
|
@@ -511,7 +575,9 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
511
575
|
h6.add(g);
|
512
576
|
h7.add(h);
|
513
577
|
}
|
578
|
+
|
514
579
|
var result;
|
580
|
+
|
515
581
|
if (!mode384) {
|
516
582
|
result = new Uint8Array(64);
|
517
583
|
h0.copyTo(result, 0);
|
@@ -531,18 +597,28 @@ var calculateSHA512 = function calculateSHA512Closure() {
|
|
531
597
|
h4.copyTo(result, 32);
|
532
598
|
h5.copyTo(result, 40);
|
533
599
|
}
|
600
|
+
|
534
601
|
return result;
|
535
602
|
}
|
603
|
+
|
536
604
|
return hash;
|
537
605
|
}();
|
606
|
+
|
607
|
+
exports.calculateSHA512 = calculateSHA512;
|
608
|
+
|
538
609
|
var calculateSHA384 = function calculateSHA384Closure() {
|
539
610
|
function hash(data, offset, length) {
|
540
611
|
return calculateSHA512(data, offset, length, true);
|
541
612
|
}
|
613
|
+
|
542
614
|
return hash;
|
543
615
|
}();
|
616
|
+
|
617
|
+
exports.calculateSHA384 = calculateSHA384;
|
618
|
+
|
544
619
|
var NullCipher = function NullCipherClosure() {
|
545
620
|
function NullCipher() {}
|
621
|
+
|
546
622
|
NullCipher.prototype = {
|
547
623
|
decryptBlock: function NullCipher_decryptBlock(data) {
|
548
624
|
return data;
|
@@ -551,81 +627,43 @@ var NullCipher = function NullCipherClosure() {
|
|
551
627
|
return NullCipher;
|
552
628
|
}();
|
553
629
|
|
554
|
-
|
555
|
-
|
556
|
-
_classCallCheck(this, AESBaseCipher);
|
557
|
-
|
630
|
+
class AESBaseCipher {
|
631
|
+
constructor() {
|
558
632
|
if (this.constructor === AESBaseCipher) {
|
559
|
-
(0, _util.unreachable)(
|
633
|
+
(0, _util.unreachable)("Cannot initialize AESBaseCipher.");
|
560
634
|
}
|
635
|
+
|
561
636
|
this._s = new Uint8Array([0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16]);
|
562
637
|
this._inv_s = new Uint8Array([0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d]);
|
563
638
|
this._mix = new Uint32Array([0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927, 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45, 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb, 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381, 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf, 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66, 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28, 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012, 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec, 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e, 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd, 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7, 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89, 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b, 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815, 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f, 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa, 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8, 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36, 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c, 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742, 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea, 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4, 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e, 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360, 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502, 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87, 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd, 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3, 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621, 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f, 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55, 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26, 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844, 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba, 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480, 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce, 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67, 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929, 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713, 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed, 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f, 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
|
564
639
|
this._mixCol = new Uint8Array(256);
|
565
|
-
|
640
|
+
|
641
|
+
for (let i = 0; i < 256; i++) {
|
566
642
|
if (i < 128) {
|
567
643
|
this._mixCol[i] = i << 1;
|
568
644
|
} else {
|
569
645
|
this._mixCol[i] = i << 1 ^ 0x1b;
|
570
646
|
}
|
571
647
|
}
|
648
|
+
|
572
649
|
this.buffer = new Uint8Array(16);
|
573
650
|
this.bufferPosition = 0;
|
574
651
|
}
|
575
652
|
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
state[j] ^= key[k];
|
591
|
-
}
|
592
|
-
for (var i = this._cyclesOfRepetition - 1; i >= 1; --i) {
|
593
|
-
t = state[13];
|
594
|
-
state[13] = state[9];
|
595
|
-
state[9] = state[5];
|
596
|
-
state[5] = state[1];
|
597
|
-
state[1] = t;
|
598
|
-
t = state[14];
|
599
|
-
u = state[10];
|
600
|
-
state[14] = state[6];
|
601
|
-
state[10] = state[2];
|
602
|
-
state[6] = t;
|
603
|
-
state[2] = u;
|
604
|
-
t = state[15];
|
605
|
-
u = state[11];
|
606
|
-
v = state[7];
|
607
|
-
state[15] = state[3];
|
608
|
-
state[11] = t;
|
609
|
-
state[7] = u;
|
610
|
-
state[3] = v;
|
611
|
-
for (var _j = 0; _j < 16; ++_j) {
|
612
|
-
state[_j] = this._inv_s[state[_j]];
|
613
|
-
}
|
614
|
-
for (var _j2 = 0, _k = i * 16; _j2 < 16; ++_j2, ++_k) {
|
615
|
-
state[_j2] ^= key[_k];
|
616
|
-
}
|
617
|
-
for (var _j3 = 0; _j3 < 16; _j3 += 4) {
|
618
|
-
var s0 = this._mix[state[_j3]];
|
619
|
-
var s1 = this._mix[state[_j3 + 1]];
|
620
|
-
var s2 = this._mix[state[_j3 + 2]];
|
621
|
-
var s3 = this._mix[state[_j3 + 3]];
|
622
|
-
t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
|
623
|
-
state[_j3] = t >>> 24 & 0xFF;
|
624
|
-
state[_j3 + 1] = t >> 16 & 0xFF;
|
625
|
-
state[_j3 + 2] = t >> 8 & 0xFF;
|
626
|
-
state[_j3 + 3] = t & 0xFF;
|
627
|
-
}
|
628
|
-
}
|
653
|
+
_expandKey(cipherKey) {
|
654
|
+
(0, _util.unreachable)("Cannot call `_expandKey` on the base class");
|
655
|
+
}
|
656
|
+
|
657
|
+
_decrypt(input, key) {
|
658
|
+
let t, u, v;
|
659
|
+
const state = new Uint8Array(16);
|
660
|
+
state.set(input);
|
661
|
+
|
662
|
+
for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
|
663
|
+
state[j] ^= key[k];
|
664
|
+
}
|
665
|
+
|
666
|
+
for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) {
|
629
667
|
t = state[13];
|
630
668
|
state[13] = state[9];
|
631
669
|
state[9] = state[5];
|
@@ -644,64 +682,70 @@ var AESBaseCipher = function () {
|
|
644
682
|
state[11] = t;
|
645
683
|
state[7] = u;
|
646
684
|
state[3] = v;
|
647
|
-
|
648
|
-
|
649
|
-
state[
|
685
|
+
|
686
|
+
for (let j = 0; j < 16; ++j) {
|
687
|
+
state[j] = this._inv_s[state[j]];
|
650
688
|
}
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
key: '_encrypt',
|
655
|
-
value: function _encrypt(input, key) {
|
656
|
-
var s = this._s;
|
657
|
-
var t = void 0,
|
658
|
-
u = void 0,
|
659
|
-
v = void 0;
|
660
|
-
var state = new Uint8Array(16);
|
661
|
-
state.set(input);
|
662
|
-
for (var j = 0; j < 16; ++j) {
|
663
|
-
state[j] ^= key[j];
|
689
|
+
|
690
|
+
for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
|
691
|
+
state[j] ^= key[k];
|
664
692
|
}
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
state[
|
673
|
-
state[
|
674
|
-
|
675
|
-
|
676
|
-
state[2] = state[10];
|
677
|
-
state[6] = state[14];
|
678
|
-
state[10] = v;
|
679
|
-
state[14] = u;
|
680
|
-
v = state[3];
|
681
|
-
u = state[7];
|
682
|
-
t = state[11];
|
683
|
-
state[3] = state[15];
|
684
|
-
state[7] = v;
|
685
|
-
state[11] = u;
|
686
|
-
state[15] = t;
|
687
|
-
for (var _j6 = 0; _j6 < 16; _j6 += 4) {
|
688
|
-
var s0 = state[_j6 + 0];
|
689
|
-
var s1 = state[_j6 + 1];
|
690
|
-
var s2 = state[_j6 + 2];
|
691
|
-
var s3 = state[_j6 + 3];
|
692
|
-
t = s0 ^ s1 ^ s2 ^ s3;
|
693
|
-
state[_j6 + 0] ^= t ^ this._mixCol[s0 ^ s1];
|
694
|
-
state[_j6 + 1] ^= t ^ this._mixCol[s1 ^ s2];
|
695
|
-
state[_j6 + 2] ^= t ^ this._mixCol[s2 ^ s3];
|
696
|
-
state[_j6 + 3] ^= t ^ this._mixCol[s3 ^ s0];
|
697
|
-
}
|
698
|
-
for (var _j7 = 0, k = i * 16; _j7 < 16; ++_j7, ++k) {
|
699
|
-
state[_j7] ^= key[k];
|
700
|
-
}
|
693
|
+
|
694
|
+
for (let j = 0; j < 16; j += 4) {
|
695
|
+
const s0 = this._mix[state[j]];
|
696
|
+
const s1 = this._mix[state[j + 1]];
|
697
|
+
const s2 = this._mix[state[j + 2]];
|
698
|
+
const s3 = this._mix[state[j + 3]];
|
699
|
+
t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
|
700
|
+
state[j] = t >>> 24 & 0xff;
|
701
|
+
state[j + 1] = t >> 16 & 0xff;
|
702
|
+
state[j + 2] = t >> 8 & 0xff;
|
703
|
+
state[j + 3] = t & 0xff;
|
701
704
|
}
|
702
|
-
|
703
|
-
|
705
|
+
}
|
706
|
+
|
707
|
+
t = state[13];
|
708
|
+
state[13] = state[9];
|
709
|
+
state[9] = state[5];
|
710
|
+
state[5] = state[1];
|
711
|
+
state[1] = t;
|
712
|
+
t = state[14];
|
713
|
+
u = state[10];
|
714
|
+
state[14] = state[6];
|
715
|
+
state[10] = state[2];
|
716
|
+
state[6] = t;
|
717
|
+
state[2] = u;
|
718
|
+
t = state[15];
|
719
|
+
u = state[11];
|
720
|
+
v = state[7];
|
721
|
+
state[15] = state[3];
|
722
|
+
state[11] = t;
|
723
|
+
state[7] = u;
|
724
|
+
state[3] = v;
|
725
|
+
|
726
|
+
for (let j = 0; j < 16; ++j) {
|
727
|
+
state[j] = this._inv_s[state[j]];
|
728
|
+
state[j] ^= key[j];
|
729
|
+
}
|
730
|
+
|
731
|
+
return state;
|
732
|
+
}
|
733
|
+
|
734
|
+
_encrypt(input, key) {
|
735
|
+
const s = this._s;
|
736
|
+
let t, u, v;
|
737
|
+
const state = new Uint8Array(16);
|
738
|
+
state.set(input);
|
739
|
+
|
740
|
+
for (let j = 0; j < 16; ++j) {
|
741
|
+
state[j] ^= key[j];
|
742
|
+
}
|
743
|
+
|
744
|
+
for (let i = 1; i < this._cyclesOfRepetition; i++) {
|
745
|
+
for (let j = 0; j < 16; ++j) {
|
746
|
+
state[j] = s[state[j]];
|
704
747
|
}
|
748
|
+
|
705
749
|
v = state[1];
|
706
750
|
state[1] = state[5];
|
707
751
|
state[5] = state[9];
|
@@ -720,258 +764,314 @@ var AESBaseCipher = function () {
|
|
720
764
|
state[7] = v;
|
721
765
|
state[11] = u;
|
722
766
|
state[15] = t;
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
var result = [],
|
735
|
-
iv = this.iv;
|
736
|
-
for (var i = 0; i < sourceLength; ++i) {
|
737
|
-
buffer[bufferLength] = data[i];
|
738
|
-
++bufferLength;
|
739
|
-
if (bufferLength < 16) {
|
740
|
-
continue;
|
741
|
-
}
|
742
|
-
var plain = this._decrypt(buffer, this._key);
|
743
|
-
for (var j = 0; j < 16; ++j) {
|
744
|
-
plain[j] ^= iv[j];
|
745
|
-
}
|
746
|
-
iv = buffer;
|
747
|
-
result.push(plain);
|
748
|
-
buffer = new Uint8Array(16);
|
749
|
-
bufferLength = 0;
|
767
|
+
|
768
|
+
for (let j = 0; j < 16; j += 4) {
|
769
|
+
const s0 = state[j + 0];
|
770
|
+
const s1 = state[j + 1];
|
771
|
+
const s2 = state[j + 2];
|
772
|
+
const s3 = state[j + 3];
|
773
|
+
t = s0 ^ s1 ^ s2 ^ s3;
|
774
|
+
state[j + 0] ^= t ^ this._mixCol[s0 ^ s1];
|
775
|
+
state[j + 1] ^= t ^ this._mixCol[s1 ^ s2];
|
776
|
+
state[j + 2] ^= t ^ this._mixCol[s2 ^ s3];
|
777
|
+
state[j + 3] ^= t ^ this._mixCol[s3 ^ s0];
|
750
778
|
}
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
if (result.length === 0) {
|
755
|
-
return new Uint8Array(0);
|
779
|
+
|
780
|
+
for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
|
781
|
+
state[j] ^= key[k];
|
756
782
|
}
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
783
|
+
}
|
784
|
+
|
785
|
+
for (let j = 0; j < 16; ++j) {
|
786
|
+
state[j] = s[state[j]];
|
787
|
+
}
|
788
|
+
|
789
|
+
v = state[1];
|
790
|
+
state[1] = state[5];
|
791
|
+
state[5] = state[9];
|
792
|
+
state[9] = state[13];
|
793
|
+
state[13] = v;
|
794
|
+
v = state[2];
|
795
|
+
u = state[6];
|
796
|
+
state[2] = state[10];
|
797
|
+
state[6] = state[14];
|
798
|
+
state[10] = v;
|
799
|
+
state[14] = u;
|
800
|
+
v = state[3];
|
801
|
+
u = state[7];
|
802
|
+
t = state[11];
|
803
|
+
state[3] = state[15];
|
804
|
+
state[7] = v;
|
805
|
+
state[11] = u;
|
806
|
+
state[15] = t;
|
807
|
+
|
808
|
+
for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
|
809
|
+
state[j] ^= key[k];
|
810
|
+
}
|
811
|
+
|
812
|
+
return state;
|
813
|
+
}
|
814
|
+
|
815
|
+
_decryptBlock2(data, finalize) {
|
816
|
+
const sourceLength = data.length;
|
817
|
+
let buffer = this.buffer,
|
818
|
+
bufferLength = this.bufferPosition;
|
819
|
+
const result = [];
|
820
|
+
let iv = this.iv;
|
821
|
+
|
822
|
+
for (let i = 0; i < sourceLength; ++i) {
|
823
|
+
buffer[bufferLength] = data[i];
|
824
|
+
++bufferLength;
|
825
|
+
|
826
|
+
if (bufferLength < 16) {
|
827
|
+
continue;
|
771
828
|
}
|
772
|
-
|
773
|
-
|
774
|
-
|
829
|
+
|
830
|
+
const plain = this._decrypt(buffer, this._key);
|
831
|
+
|
832
|
+
for (let j = 0; j < 16; ++j) {
|
833
|
+
plain[j] ^= iv[j];
|
775
834
|
}
|
776
|
-
|
835
|
+
|
836
|
+
iv = buffer;
|
837
|
+
result.push(plain);
|
838
|
+
buffer = new Uint8Array(16);
|
839
|
+
bufferLength = 0;
|
777
840
|
}
|
778
|
-
}, {
|
779
|
-
key: 'decryptBlock',
|
780
|
-
value: function decryptBlock(data, finalize) {
|
781
|
-
var iv = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
782
841
|
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
842
|
+
this.buffer = buffer;
|
843
|
+
this.bufferLength = bufferLength;
|
844
|
+
this.iv = iv;
|
845
|
+
|
846
|
+
if (result.length === 0) {
|
847
|
+
return new Uint8Array(0);
|
848
|
+
}
|
849
|
+
|
850
|
+
let outputLength = 16 * result.length;
|
851
|
+
|
852
|
+
if (finalize) {
|
853
|
+
const lastBlock = result[result.length - 1];
|
854
|
+
let psLen = lastBlock[15];
|
855
|
+
|
856
|
+
if (psLen <= 16) {
|
857
|
+
for (let i = 15, ii = 16 - psLen; i >= ii; --i) {
|
858
|
+
if (lastBlock[i] !== psLen) {
|
859
|
+
psLen = 0;
|
860
|
+
break;
|
861
|
+
}
|
795
862
|
}
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
this.buffer = new Uint8Array(16);
|
800
|
-
this.bufferLength = 0;
|
801
|
-
this.decryptBlock = this._decryptBlock2;
|
802
|
-
return this.decryptBlock(data, finalize);
|
803
|
-
}
|
804
|
-
}, {
|
805
|
-
key: 'encrypt',
|
806
|
-
value: function encrypt(data, iv) {
|
807
|
-
var sourceLength = data.length;
|
808
|
-
var buffer = this.buffer,
|
809
|
-
bufferLength = this.bufferPosition;
|
810
|
-
var result = [];
|
811
|
-
if (!iv) {
|
812
|
-
iv = new Uint8Array(16);
|
863
|
+
|
864
|
+
outputLength -= psLen;
|
865
|
+
result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
|
813
866
|
}
|
814
|
-
|
867
|
+
}
|
868
|
+
|
869
|
+
const output = new Uint8Array(outputLength);
|
870
|
+
|
871
|
+
for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
|
872
|
+
output.set(result[i], j);
|
873
|
+
}
|
874
|
+
|
875
|
+
return output;
|
876
|
+
}
|
877
|
+
|
878
|
+
decryptBlock(data, finalize, iv = null) {
|
879
|
+
const sourceLength = data.length;
|
880
|
+
const buffer = this.buffer;
|
881
|
+
let bufferLength = this.bufferPosition;
|
882
|
+
|
883
|
+
if (iv) {
|
884
|
+
this.iv = iv;
|
885
|
+
} else {
|
886
|
+
for (let i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
|
815
887
|
buffer[bufferLength] = data[i];
|
816
|
-
++bufferLength;
|
817
|
-
if (bufferLength < 16) {
|
818
|
-
continue;
|
819
|
-
}
|
820
|
-
for (var j = 0; j < 16; ++j) {
|
821
|
-
buffer[j] ^= iv[j];
|
822
|
-
}
|
823
|
-
var cipher = this._encrypt(buffer, this._key);
|
824
|
-
iv = cipher;
|
825
|
-
result.push(cipher);
|
826
|
-
buffer = new Uint8Array(16);
|
827
|
-
bufferLength = 0;
|
828
888
|
}
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
if (result.length === 0) {
|
889
|
+
|
890
|
+
if (bufferLength < 16) {
|
891
|
+
this.bufferLength = bufferLength;
|
833
892
|
return new Uint8Array(0);
|
834
893
|
}
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
894
|
+
|
895
|
+
this.iv = buffer;
|
896
|
+
data = data.subarray(16);
|
897
|
+
}
|
898
|
+
|
899
|
+
this.buffer = new Uint8Array(16);
|
900
|
+
this.bufferLength = 0;
|
901
|
+
this.decryptBlock = this._decryptBlock2;
|
902
|
+
return this.decryptBlock(data, finalize);
|
903
|
+
}
|
904
|
+
|
905
|
+
encrypt(data, iv) {
|
906
|
+
const sourceLength = data.length;
|
907
|
+
let buffer = this.buffer,
|
908
|
+
bufferLength = this.bufferPosition;
|
909
|
+
const result = [];
|
910
|
+
|
911
|
+
if (!iv) {
|
912
|
+
iv = new Uint8Array(16);
|
913
|
+
}
|
914
|
+
|
915
|
+
for (let i = 0; i < sourceLength; ++i) {
|
916
|
+
buffer[bufferLength] = data[i];
|
917
|
+
++bufferLength;
|
918
|
+
|
919
|
+
if (bufferLength < 16) {
|
920
|
+
continue;
|
839
921
|
}
|
840
|
-
|
922
|
+
|
923
|
+
for (let j = 0; j < 16; ++j) {
|
924
|
+
buffer[j] ^= iv[j];
|
925
|
+
}
|
926
|
+
|
927
|
+
const cipher = this._encrypt(buffer, this._key);
|
928
|
+
|
929
|
+
iv = cipher;
|
930
|
+
result.push(cipher);
|
931
|
+
buffer = new Uint8Array(16);
|
932
|
+
bufferLength = 0;
|
841
933
|
}
|
842
|
-
}]);
|
843
934
|
|
844
|
-
|
845
|
-
|
935
|
+
this.buffer = buffer;
|
936
|
+
this.bufferLength = bufferLength;
|
937
|
+
this.iv = iv;
|
846
938
|
|
847
|
-
|
848
|
-
|
939
|
+
if (result.length === 0) {
|
940
|
+
return new Uint8Array(0);
|
941
|
+
}
|
849
942
|
|
850
|
-
|
851
|
-
|
943
|
+
const outputLength = 16 * result.length;
|
944
|
+
const output = new Uint8Array(outputLength);
|
852
945
|
|
853
|
-
|
946
|
+
for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
|
947
|
+
output.set(result[i], j);
|
948
|
+
}
|
854
949
|
|
855
|
-
|
856
|
-
_this._keySize = 160;
|
857
|
-
_this._rcon = new Uint8Array([0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d]);
|
858
|
-
_this._key = _this._expandKey(key);
|
859
|
-
return _this;
|
950
|
+
return output;
|
860
951
|
}
|
861
952
|
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
953
|
+
}
|
954
|
+
|
955
|
+
class AES128Cipher extends AESBaseCipher {
|
956
|
+
constructor(key) {
|
957
|
+
super();
|
958
|
+
this._cyclesOfRepetition = 10;
|
959
|
+
this._keySize = 160;
|
960
|
+
this._rcon = new Uint8Array([0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d]);
|
961
|
+
this._key = this._expandKey(key);
|
962
|
+
}
|
963
|
+
|
964
|
+
_expandKey(cipherKey) {
|
965
|
+
const b = 176;
|
966
|
+
const s = this._s;
|
967
|
+
const rcon = this._rcon;
|
968
|
+
const result = new Uint8Array(b);
|
969
|
+
result.set(cipherKey);
|
970
|
+
|
971
|
+
for (let j = 16, i = 1; j < b; ++i) {
|
972
|
+
let t1 = result[j - 3];
|
973
|
+
let t2 = result[j - 2];
|
974
|
+
let t3 = result[j - 1];
|
975
|
+
let t4 = result[j - 4];
|
976
|
+
t1 = s[t1];
|
977
|
+
t2 = s[t2];
|
978
|
+
t3 = s[t3];
|
979
|
+
t4 = s[t4];
|
980
|
+
t1 = t1 ^ rcon[i];
|
981
|
+
|
982
|
+
for (let n = 0; n < 4; ++n) {
|
983
|
+
result[j] = t1 ^= result[j - 16];
|
984
|
+
j++;
|
985
|
+
result[j] = t2 ^= result[j - 16];
|
986
|
+
j++;
|
987
|
+
result[j] = t3 ^= result[j - 16];
|
988
|
+
j++;
|
989
|
+
result[j] = t4 ^= result[j - 16];
|
990
|
+
j++;
|
890
991
|
}
|
891
|
-
return result;
|
892
992
|
}
|
893
|
-
}]);
|
894
|
-
|
895
|
-
return AES128Cipher;
|
896
|
-
}(AESBaseCipher);
|
897
993
|
|
898
|
-
|
899
|
-
|
994
|
+
return result;
|
995
|
+
}
|
900
996
|
|
901
|
-
|
902
|
-
_classCallCheck(this, AES256Cipher);
|
997
|
+
}
|
903
998
|
|
904
|
-
|
999
|
+
exports.AES128Cipher = AES128Cipher;
|
905
1000
|
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
1001
|
+
class AES256Cipher extends AESBaseCipher {
|
1002
|
+
constructor(key) {
|
1003
|
+
super();
|
1004
|
+
this._cyclesOfRepetition = 14;
|
1005
|
+
this._keySize = 224;
|
1006
|
+
this._key = this._expandKey(key);
|
910
1007
|
}
|
911
1008
|
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
t1 = t1 ^ r;
|
940
|
-
if ((r <<= 1) >= 256) {
|
941
|
-
r = (r ^ 0x1b) & 0xFF;
|
942
|
-
}
|
943
|
-
}
|
944
|
-
for (var n = 0; n < 4; ++n) {
|
945
|
-
result[j] = t1 ^= result[j - 32];
|
946
|
-
j++;
|
947
|
-
result[j] = t2 ^= result[j - 32];
|
948
|
-
j++;
|
949
|
-
result[j] = t3 ^= result[j - 32];
|
950
|
-
j++;
|
951
|
-
result[j] = t4 ^= result[j - 32];
|
952
|
-
j++;
|
1009
|
+
_expandKey(cipherKey) {
|
1010
|
+
const b = 240;
|
1011
|
+
const s = this._s;
|
1012
|
+
const result = new Uint8Array(b);
|
1013
|
+
result.set(cipherKey);
|
1014
|
+
let r = 1;
|
1015
|
+
let t1, t2, t3, t4;
|
1016
|
+
|
1017
|
+
for (let j = 32, i = 1; j < b; ++i) {
|
1018
|
+
if (j % 32 === 16) {
|
1019
|
+
t1 = s[t1];
|
1020
|
+
t2 = s[t2];
|
1021
|
+
t3 = s[t3];
|
1022
|
+
t4 = s[t4];
|
1023
|
+
} else if (j % 32 === 0) {
|
1024
|
+
t1 = result[j - 3];
|
1025
|
+
t2 = result[j - 2];
|
1026
|
+
t3 = result[j - 1];
|
1027
|
+
t4 = result[j - 4];
|
1028
|
+
t1 = s[t1];
|
1029
|
+
t2 = s[t2];
|
1030
|
+
t3 = s[t3];
|
1031
|
+
t4 = s[t4];
|
1032
|
+
t1 = t1 ^ r;
|
1033
|
+
|
1034
|
+
if ((r <<= 1) >= 256) {
|
1035
|
+
r = (r ^ 0x1b) & 0xff;
|
953
1036
|
}
|
954
1037
|
}
|
955
|
-
|
1038
|
+
|
1039
|
+
for (let n = 0; n < 4; ++n) {
|
1040
|
+
result[j] = t1 ^= result[j - 32];
|
1041
|
+
j++;
|
1042
|
+
result[j] = t2 ^= result[j - 32];
|
1043
|
+
j++;
|
1044
|
+
result[j] = t3 ^= result[j - 32];
|
1045
|
+
j++;
|
1046
|
+
result[j] = t4 ^= result[j - 32];
|
1047
|
+
j++;
|
1048
|
+
}
|
956
1049
|
}
|
957
|
-
}]);
|
958
1050
|
|
959
|
-
|
960
|
-
}
|
1051
|
+
return result;
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
exports.AES256Cipher = AES256Cipher;
|
961
1057
|
|
962
1058
|
var PDF17 = function PDF17Closure() {
|
963
1059
|
function compareByteArrays(array1, array2) {
|
964
1060
|
if (array1.length !== array2.length) {
|
965
1061
|
return false;
|
966
1062
|
}
|
1063
|
+
|
967
1064
|
for (var i = 0; i < array1.length; i++) {
|
968
1065
|
if (array1[i] !== array2[i]) {
|
969
1066
|
return false;
|
970
1067
|
}
|
971
1068
|
}
|
1069
|
+
|
972
1070
|
return true;
|
973
1071
|
}
|
1072
|
+
|
974
1073
|
function PDF17() {}
|
1074
|
+
|
975
1075
|
PDF17.prototype = {
|
976
1076
|
checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
|
977
1077
|
var hashData = new Uint8Array(password.length + 56);
|
@@ -1008,6 +1108,9 @@ var PDF17 = function PDF17Closure() {
|
|
1008
1108
|
};
|
1009
1109
|
return PDF17;
|
1010
1110
|
}();
|
1111
|
+
|
1112
|
+
exports.PDF17 = PDF17;
|
1113
|
+
|
1011
1114
|
var PDF20 = function PDF20Closure() {
|
1012
1115
|
function concatArrays(array1, array2) {
|
1013
1116
|
var t = new Uint8Array(array1.length + array2.length);
|
@@ -1015,27 +1118,33 @@ var PDF20 = function PDF20Closure() {
|
|
1015
1118
|
t.set(array2, array1.length);
|
1016
1119
|
return t;
|
1017
1120
|
}
|
1121
|
+
|
1018
1122
|
function calculatePDF20Hash(password, input, userBytes) {
|
1019
1123
|
var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
|
1020
1124
|
var e = [0];
|
1021
1125
|
var i = 0;
|
1126
|
+
|
1022
1127
|
while (i < 64 || e[e.length - 1] > i - 32) {
|
1023
1128
|
var arrayLength = password.length + k.length + userBytes.length;
|
1024
1129
|
var k1 = new Uint8Array(arrayLength * 64);
|
1025
1130
|
var array = concatArrays(password, k);
|
1026
1131
|
array = concatArrays(array, userBytes);
|
1132
|
+
|
1027
1133
|
for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
|
1028
1134
|
k1.set(array, pos);
|
1029
1135
|
}
|
1136
|
+
|
1030
1137
|
var cipher = new AES128Cipher(k.subarray(0, 16));
|
1031
1138
|
e = cipher.encrypt(k1, k.subarray(16, 32));
|
1032
1139
|
var remainder = 0;
|
1140
|
+
|
1033
1141
|
for (var z = 0; z < 16; z++) {
|
1034
1142
|
remainder *= 256 % 3;
|
1035
1143
|
remainder %= 3;
|
1036
1144
|
remainder += (e[z] >>> 0) % 3;
|
1037
1145
|
remainder %= 3;
|
1038
1146
|
}
|
1147
|
+
|
1039
1148
|
if (remainder === 0) {
|
1040
1149
|
k = calculateSHA256(e, 0, e.length);
|
1041
1150
|
} else if (remainder === 1) {
|
@@ -1043,22 +1152,29 @@ var PDF20 = function PDF20Closure() {
|
|
1043
1152
|
} else if (remainder === 2) {
|
1044
1153
|
k = calculateSHA512(e, 0, e.length);
|
1045
1154
|
}
|
1155
|
+
|
1046
1156
|
i++;
|
1047
1157
|
}
|
1158
|
+
|
1048
1159
|
return k.subarray(0, 32);
|
1049
1160
|
}
|
1161
|
+
|
1050
1162
|
function PDF20() {}
|
1163
|
+
|
1051
1164
|
function compareByteArrays(array1, array2) {
|
1052
1165
|
if (array1.length !== array2.length) {
|
1053
1166
|
return false;
|
1054
1167
|
}
|
1168
|
+
|
1055
1169
|
for (var i = 0; i < array1.length; i++) {
|
1056
1170
|
if (array1[i] !== array2[i]) {
|
1057
1171
|
return false;
|
1058
1172
|
}
|
1059
1173
|
}
|
1174
|
+
|
1060
1175
|
return true;
|
1061
1176
|
}
|
1177
|
+
|
1062
1178
|
PDF20.prototype = {
|
1063
1179
|
hash: function PDF20_hash(password, concatBytes, userBytes) {
|
1064
1180
|
return calculatePDF20Hash(password, concatBytes, userBytes);
|
@@ -1098,11 +1214,15 @@ var PDF20 = function PDF20Closure() {
|
|
1098
1214
|
};
|
1099
1215
|
return PDF20;
|
1100
1216
|
}();
|
1217
|
+
|
1218
|
+
exports.PDF20 = PDF20;
|
1219
|
+
|
1101
1220
|
var CipherTransform = function CipherTransformClosure() {
|
1102
1221
|
function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
|
1103
1222
|
this.StringCipherConstructor = stringCipherConstructor;
|
1104
1223
|
this.StreamCipherConstructor = streamCipherConstructor;
|
1105
1224
|
}
|
1225
|
+
|
1106
1226
|
CipherTransform.prototype = {
|
1107
1227
|
createStream: function CipherTransform_createStream(stream, length) {
|
1108
1228
|
var cipher = new this.StreamCipherConstructor();
|
@@ -1119,8 +1239,10 @@ var CipherTransform = function CipherTransformClosure() {
|
|
1119
1239
|
};
|
1120
1240
|
return CipherTransform;
|
1121
1241
|
}();
|
1242
|
+
|
1122
1243
|
var CipherTransformFactory = function CipherTransformFactoryClosure() {
|
1123
1244
|
var defaultPasswordBytes = new Uint8Array([0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41, 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08, 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80, 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
|
1245
|
+
|
1124
1246
|
function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
|
1125
1247
|
if (password) {
|
1126
1248
|
var passwordLength = Math.min(127, password.length);
|
@@ -1128,79 +1250,101 @@ var CipherTransformFactory = function CipherTransformFactoryClosure() {
|
|
1128
1250
|
} else {
|
1129
1251
|
password = [];
|
1130
1252
|
}
|
1253
|
+
|
1131
1254
|
var pdfAlgorithm;
|
1255
|
+
|
1132
1256
|
if (revision === 6) {
|
1133
1257
|
pdfAlgorithm = new PDF20();
|
1134
1258
|
} else {
|
1135
1259
|
pdfAlgorithm = new PDF17();
|
1136
1260
|
}
|
1261
|
+
|
1137
1262
|
if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
|
1138
1263
|
return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
|
1139
1264
|
} else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
|
1140
1265
|
return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
|
1141
1266
|
}
|
1267
|
+
|
1142
1268
|
return null;
|
1143
1269
|
}
|
1270
|
+
|
1144
1271
|
function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
|
1145
1272
|
var hashDataSize = 40 + ownerPassword.length + fileId.length;
|
1146
1273
|
var hashData = new Uint8Array(hashDataSize),
|
1147
1274
|
i = 0,
|
1148
1275
|
j,
|
1149
1276
|
n;
|
1277
|
+
|
1150
1278
|
if (password) {
|
1151
1279
|
n = Math.min(32, password.length);
|
1280
|
+
|
1152
1281
|
for (; i < n; ++i) {
|
1153
1282
|
hashData[i] = password[i];
|
1154
1283
|
}
|
1155
1284
|
}
|
1285
|
+
|
1156
1286
|
j = 0;
|
1287
|
+
|
1157
1288
|
while (i < 32) {
|
1158
1289
|
hashData[i++] = defaultPasswordBytes[j++];
|
1159
1290
|
}
|
1291
|
+
|
1160
1292
|
for (j = 0, n = ownerPassword.length; j < n; ++j) {
|
1161
1293
|
hashData[i++] = ownerPassword[j];
|
1162
1294
|
}
|
1163
|
-
|
1164
|
-
hashData[i++] = flags
|
1165
|
-
hashData[i++] = flags >>
|
1166
|
-
hashData[i++] = flags
|
1295
|
+
|
1296
|
+
hashData[i++] = flags & 0xff;
|
1297
|
+
hashData[i++] = flags >> 8 & 0xff;
|
1298
|
+
hashData[i++] = flags >> 16 & 0xff;
|
1299
|
+
hashData[i++] = flags >>> 24 & 0xff;
|
1300
|
+
|
1167
1301
|
for (j = 0, n = fileId.length; j < n; ++j) {
|
1168
1302
|
hashData[i++] = fileId[j];
|
1169
1303
|
}
|
1304
|
+
|
1170
1305
|
if (revision >= 4 && !encryptMetadata) {
|
1171
|
-
hashData[i++] =
|
1172
|
-
hashData[i++] =
|
1173
|
-
hashData[i++] =
|
1174
|
-
hashData[i++] =
|
1306
|
+
hashData[i++] = 0xff;
|
1307
|
+
hashData[i++] = 0xff;
|
1308
|
+
hashData[i++] = 0xff;
|
1309
|
+
hashData[i++] = 0xff;
|
1175
1310
|
}
|
1311
|
+
|
1176
1312
|
var hash = calculateMD5(hashData, 0, i);
|
1177
1313
|
var keyLengthInBytes = keyLength >> 3;
|
1314
|
+
|
1178
1315
|
if (revision >= 3) {
|
1179
1316
|
for (j = 0; j < 50; ++j) {
|
1180
1317
|
hash = calculateMD5(hash, 0, keyLengthInBytes);
|
1181
1318
|
}
|
1182
1319
|
}
|
1320
|
+
|
1183
1321
|
var encryptionKey = hash.subarray(0, keyLengthInBytes);
|
1184
1322
|
var cipher, checkData;
|
1323
|
+
|
1185
1324
|
if (revision >= 3) {
|
1186
1325
|
for (i = 0; i < 32; ++i) {
|
1187
1326
|
hashData[i] = defaultPasswordBytes[i];
|
1188
1327
|
}
|
1328
|
+
|
1189
1329
|
for (j = 0, n = fileId.length; j < n; ++j) {
|
1190
1330
|
hashData[i++] = fileId[j];
|
1191
1331
|
}
|
1332
|
+
|
1192
1333
|
cipher = new ARCFourCipher(encryptionKey);
|
1193
1334
|
checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
|
1194
1335
|
n = encryptionKey.length;
|
1195
1336
|
var derivedKey = new Uint8Array(n),
|
1196
1337
|
k;
|
1338
|
+
|
1197
1339
|
for (j = 1; j <= 19; ++j) {
|
1198
1340
|
for (k = 0; k < n; ++k) {
|
1199
1341
|
derivedKey[k] = encryptionKey[k] ^ j;
|
1200
1342
|
}
|
1343
|
+
|
1201
1344
|
cipher = new ARCFourCipher(derivedKey);
|
1202
1345
|
checkData = cipher.encryptBlock(checkData);
|
1203
1346
|
}
|
1347
|
+
|
1204
1348
|
for (j = 0, n = checkData.length; j < n; ++j) {
|
1205
1349
|
if (userPassword[j] !== checkData[j]) {
|
1206
1350
|
return null;
|
@@ -1209,43 +1353,55 @@ var CipherTransformFactory = function CipherTransformFactoryClosure() {
|
|
1209
1353
|
} else {
|
1210
1354
|
cipher = new ARCFourCipher(encryptionKey);
|
1211
1355
|
checkData = cipher.encryptBlock(defaultPasswordBytes);
|
1356
|
+
|
1212
1357
|
for (j = 0, n = checkData.length; j < n; ++j) {
|
1213
1358
|
if (userPassword[j] !== checkData[j]) {
|
1214
1359
|
return null;
|
1215
1360
|
}
|
1216
1361
|
}
|
1217
1362
|
}
|
1363
|
+
|
1218
1364
|
return encryptionKey;
|
1219
1365
|
}
|
1366
|
+
|
1220
1367
|
function decodeUserPassword(password, ownerPassword, revision, keyLength) {
|
1221
1368
|
var hashData = new Uint8Array(32),
|
1222
1369
|
i = 0,
|
1223
1370
|
j,
|
1224
1371
|
n;
|
1225
1372
|
n = Math.min(32, password.length);
|
1373
|
+
|
1226
1374
|
for (; i < n; ++i) {
|
1227
1375
|
hashData[i] = password[i];
|
1228
1376
|
}
|
1377
|
+
|
1229
1378
|
j = 0;
|
1379
|
+
|
1230
1380
|
while (i < 32) {
|
1231
1381
|
hashData[i++] = defaultPasswordBytes[j++];
|
1232
1382
|
}
|
1383
|
+
|
1233
1384
|
var hash = calculateMD5(hashData, 0, i);
|
1234
1385
|
var keyLengthInBytes = keyLength >> 3;
|
1386
|
+
|
1235
1387
|
if (revision >= 3) {
|
1236
1388
|
for (j = 0; j < 50; ++j) {
|
1237
1389
|
hash = calculateMD5(hash, 0, hash.length);
|
1238
1390
|
}
|
1239
1391
|
}
|
1392
|
+
|
1240
1393
|
var cipher, userPassword;
|
1394
|
+
|
1241
1395
|
if (revision >= 3) {
|
1242
1396
|
userPassword = ownerPassword;
|
1243
1397
|
var derivedKey = new Uint8Array(keyLengthInBytes),
|
1244
1398
|
k;
|
1399
|
+
|
1245
1400
|
for (j = 19; j >= 0; j--) {
|
1246
1401
|
for (k = 0; k < keyLengthInBytes; ++k) {
|
1247
1402
|
derivedKey[k] = hash[k] ^ j;
|
1248
1403
|
}
|
1404
|
+
|
1249
1405
|
cipher = new ARCFourCipher(derivedKey);
|
1250
1406
|
userPassword = cipher.encryptBlock(userPassword);
|
1251
1407
|
}
|
@@ -1253,166 +1409,197 @@ var CipherTransformFactory = function CipherTransformFactoryClosure() {
|
|
1253
1409
|
cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
|
1254
1410
|
userPassword = cipher.encryptBlock(ownerPassword);
|
1255
1411
|
}
|
1412
|
+
|
1256
1413
|
return userPassword;
|
1257
1414
|
}
|
1258
|
-
|
1415
|
+
|
1416
|
+
var identityName = _primitives.Name.get("Identity");
|
1417
|
+
|
1259
1418
|
function CipherTransformFactory(dict, fileId, password) {
|
1260
|
-
var filter = dict.get(
|
1261
|
-
|
1262
|
-
|
1419
|
+
var filter = dict.get("Filter");
|
1420
|
+
|
1421
|
+
if (!(0, _primitives.isName)(filter, "Standard")) {
|
1422
|
+
throw new _util.FormatError("unknown encryption method");
|
1263
1423
|
}
|
1424
|
+
|
1264
1425
|
this.dict = dict;
|
1265
|
-
var algorithm = dict.get(
|
1426
|
+
var algorithm = dict.get("V");
|
1427
|
+
|
1266
1428
|
if (!Number.isInteger(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
|
1267
|
-
throw new _util.FormatError(
|
1429
|
+
throw new _util.FormatError("unsupported encryption algorithm");
|
1268
1430
|
}
|
1431
|
+
|
1269
1432
|
this.algorithm = algorithm;
|
1270
|
-
var keyLength = dict.get(
|
1433
|
+
var keyLength = dict.get("Length");
|
1434
|
+
|
1271
1435
|
if (!keyLength) {
|
1272
1436
|
if (algorithm <= 3) {
|
1273
1437
|
keyLength = 40;
|
1274
1438
|
} else {
|
1275
|
-
var cfDict = dict.get(
|
1276
|
-
var streamCryptoName = dict.get(
|
1439
|
+
var cfDict = dict.get("CF");
|
1440
|
+
var streamCryptoName = dict.get("StmF");
|
1441
|
+
|
1277
1442
|
if ((0, _primitives.isDict)(cfDict) && (0, _primitives.isName)(streamCryptoName)) {
|
1278
1443
|
cfDict.suppressEncryption = true;
|
1279
1444
|
var handlerDict = cfDict.get(streamCryptoName.name);
|
1280
|
-
keyLength = handlerDict && handlerDict.get(
|
1445
|
+
keyLength = handlerDict && handlerDict.get("Length") || 128;
|
1446
|
+
|
1281
1447
|
if (keyLength < 40) {
|
1282
1448
|
keyLength <<= 3;
|
1283
1449
|
}
|
1284
1450
|
}
|
1285
1451
|
}
|
1286
1452
|
}
|
1453
|
+
|
1287
1454
|
if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
|
1288
|
-
throw new _util.FormatError(
|
1455
|
+
throw new _util.FormatError("invalid key length");
|
1289
1456
|
}
|
1290
|
-
|
1291
|
-
var
|
1292
|
-
var
|
1293
|
-
var
|
1294
|
-
var
|
1457
|
+
|
1458
|
+
var ownerPassword = (0, _util.stringToBytes)(dict.get("O")).subarray(0, 32);
|
1459
|
+
var userPassword = (0, _util.stringToBytes)(dict.get("U")).subarray(0, 32);
|
1460
|
+
var flags = dict.get("P");
|
1461
|
+
var revision = dict.get("R");
|
1462
|
+
var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get("EncryptMetadata") !== false;
|
1295
1463
|
this.encryptMetadata = encryptMetadata;
|
1296
1464
|
var fileIdBytes = (0, _util.stringToBytes)(fileId);
|
1297
1465
|
var passwordBytes;
|
1466
|
+
|
1298
1467
|
if (password) {
|
1299
1468
|
if (revision === 6) {
|
1300
1469
|
try {
|
1301
1470
|
password = (0, _util.utf8StringToString)(password);
|
1302
1471
|
} catch (ex) {
|
1303
|
-
(0, _util.warn)(
|
1472
|
+
(0, _util.warn)("CipherTransformFactory: " + "Unable to convert UTF8 encoded password.");
|
1304
1473
|
}
|
1305
1474
|
}
|
1475
|
+
|
1306
1476
|
passwordBytes = (0, _util.stringToBytes)(password);
|
1307
1477
|
}
|
1478
|
+
|
1308
1479
|
var encryptionKey;
|
1480
|
+
|
1309
1481
|
if (algorithm !== 5) {
|
1310
1482
|
encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
|
1311
1483
|
} else {
|
1312
|
-
var ownerValidationSalt = (0, _util.stringToBytes)(dict.get(
|
1313
|
-
var ownerKeySalt = (0, _util.stringToBytes)(dict.get(
|
1314
|
-
var uBytes = (0, _util.stringToBytes)(dict.get(
|
1315
|
-
var userValidationSalt = (0, _util.stringToBytes)(dict.get(
|
1316
|
-
var userKeySalt = (0, _util.stringToBytes)(dict.get(
|
1317
|
-
var ownerEncryption = (0, _util.stringToBytes)(dict.get(
|
1318
|
-
var userEncryption = (0, _util.stringToBytes)(dict.get(
|
1319
|
-
var perms = (0, _util.stringToBytes)(dict.get(
|
1484
|
+
var ownerValidationSalt = (0, _util.stringToBytes)(dict.get("O")).subarray(32, 40);
|
1485
|
+
var ownerKeySalt = (0, _util.stringToBytes)(dict.get("O")).subarray(40, 48);
|
1486
|
+
var uBytes = (0, _util.stringToBytes)(dict.get("U")).subarray(0, 48);
|
1487
|
+
var userValidationSalt = (0, _util.stringToBytes)(dict.get("U")).subarray(32, 40);
|
1488
|
+
var userKeySalt = (0, _util.stringToBytes)(dict.get("U")).subarray(40, 48);
|
1489
|
+
var ownerEncryption = (0, _util.stringToBytes)(dict.get("OE"));
|
1490
|
+
var userEncryption = (0, _util.stringToBytes)(dict.get("UE"));
|
1491
|
+
var perms = (0, _util.stringToBytes)(dict.get("Perms"));
|
1320
1492
|
encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
|
1321
1493
|
}
|
1494
|
+
|
1322
1495
|
if (!encryptionKey && !password) {
|
1323
|
-
throw new _util.PasswordException(
|
1496
|
+
throw new _util.PasswordException("No password given", _util.PasswordResponses.NEED_PASSWORD);
|
1324
1497
|
} else if (!encryptionKey && password) {
|
1325
1498
|
var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
|
1326
1499
|
encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
|
1327
1500
|
}
|
1501
|
+
|
1328
1502
|
if (!encryptionKey) {
|
1329
|
-
throw new _util.PasswordException(
|
1503
|
+
throw new _util.PasswordException("Incorrect Password", _util.PasswordResponses.INCORRECT_PASSWORD);
|
1330
1504
|
}
|
1505
|
+
|
1331
1506
|
this.encryptionKey = encryptionKey;
|
1507
|
+
|
1332
1508
|
if (algorithm >= 4) {
|
1333
|
-
var cf = dict.get(
|
1509
|
+
var cf = dict.get("CF");
|
1510
|
+
|
1334
1511
|
if ((0, _primitives.isDict)(cf)) {
|
1335
1512
|
cf.suppressEncryption = true;
|
1336
1513
|
}
|
1514
|
+
|
1337
1515
|
this.cf = cf;
|
1338
|
-
this.stmf = dict.get(
|
1339
|
-
this.strf = dict.get(
|
1340
|
-
this.eff = dict.get(
|
1516
|
+
this.stmf = dict.get("StmF") || identityName;
|
1517
|
+
this.strf = dict.get("StrF") || identityName;
|
1518
|
+
this.eff = dict.get("EFF") || this.stmf;
|
1341
1519
|
}
|
1342
1520
|
}
|
1521
|
+
|
1343
1522
|
function buildObjectKey(num, gen, encryptionKey, isAes) {
|
1344
1523
|
var key = new Uint8Array(encryptionKey.length + 9),
|
1345
1524
|
i,
|
1346
1525
|
n;
|
1526
|
+
|
1347
1527
|
for (i = 0, n = encryptionKey.length; i < n; ++i) {
|
1348
1528
|
key[i] = encryptionKey[i];
|
1349
1529
|
}
|
1350
|
-
|
1351
|
-
key[i++] = num
|
1352
|
-
key[i++] = num >>
|
1353
|
-
key[i++] =
|
1354
|
-
key[i++] = gen
|
1530
|
+
|
1531
|
+
key[i++] = num & 0xff;
|
1532
|
+
key[i++] = num >> 8 & 0xff;
|
1533
|
+
key[i++] = num >> 16 & 0xff;
|
1534
|
+
key[i++] = gen & 0xff;
|
1535
|
+
key[i++] = gen >> 8 & 0xff;
|
1536
|
+
|
1355
1537
|
if (isAes) {
|
1356
1538
|
key[i++] = 0x73;
|
1357
1539
|
key[i++] = 0x41;
|
1358
|
-
key[i++] =
|
1540
|
+
key[i++] = 0x6c;
|
1359
1541
|
key[i++] = 0x54;
|
1360
1542
|
}
|
1543
|
+
|
1361
1544
|
var hash = calculateMD5(key, 0, i);
|
1362
1545
|
return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
|
1363
1546
|
}
|
1547
|
+
|
1364
1548
|
function buildCipherConstructor(cf, name, num, gen, key) {
|
1365
1549
|
if (!(0, _primitives.isName)(name)) {
|
1366
|
-
throw new _util.FormatError(
|
1550
|
+
throw new _util.FormatError("Invalid crypt filter name.");
|
1367
1551
|
}
|
1552
|
+
|
1368
1553
|
var cryptFilter = cf.get(name.name);
|
1369
1554
|
var cfm;
|
1555
|
+
|
1370
1556
|
if (cryptFilter !== null && cryptFilter !== undefined) {
|
1371
|
-
cfm = cryptFilter.get(
|
1557
|
+
cfm = cryptFilter.get("CFM");
|
1372
1558
|
}
|
1373
|
-
|
1559
|
+
|
1560
|
+
if (!cfm || cfm.name === "None") {
|
1374
1561
|
return function cipherTransformFactoryBuildCipherConstructorNone() {
|
1375
1562
|
return new NullCipher();
|
1376
1563
|
};
|
1377
1564
|
}
|
1378
|
-
|
1565
|
+
|
1566
|
+
if (cfm.name === "V2") {
|
1379
1567
|
return function cipherTransformFactoryBuildCipherConstructorV2() {
|
1380
1568
|
return new ARCFourCipher(buildObjectKey(num, gen, key, false));
|
1381
1569
|
};
|
1382
1570
|
}
|
1383
|
-
|
1571
|
+
|
1572
|
+
if (cfm.name === "AESV2") {
|
1384
1573
|
return function cipherTransformFactoryBuildCipherConstructorAESV2() {
|
1385
1574
|
return new AES128Cipher(buildObjectKey(num, gen, key, true));
|
1386
1575
|
};
|
1387
1576
|
}
|
1388
|
-
|
1577
|
+
|
1578
|
+
if (cfm.name === "AESV3") {
|
1389
1579
|
return function cipherTransformFactoryBuildCipherConstructorAESV3() {
|
1390
1580
|
return new AES256Cipher(key);
|
1391
1581
|
};
|
1392
1582
|
}
|
1393
|
-
|
1583
|
+
|
1584
|
+
throw new _util.FormatError("Unknown crypto method");
|
1394
1585
|
}
|
1586
|
+
|
1395
1587
|
CipherTransformFactory.prototype = {
|
1396
1588
|
createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
|
1397
1589
|
if (this.algorithm === 4 || this.algorithm === 5) {
|
1398
1590
|
return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
|
1399
1591
|
}
|
1592
|
+
|
1400
1593
|
var key = buildObjectKey(num, gen, this.encryptionKey, false);
|
1594
|
+
|
1401
1595
|
var cipherConstructor = function buildCipherCipherConstructor() {
|
1402
1596
|
return new ARCFourCipher(key);
|
1403
1597
|
};
|
1598
|
+
|
1404
1599
|
return new CipherTransform(cipherConstructor, cipherConstructor);
|
1405
1600
|
}
|
1406
1601
|
};
|
1407
1602
|
return CipherTransformFactory;
|
1408
1603
|
}();
|
1409
|
-
|
1410
|
-
exports.
|
1411
|
-
exports.ARCFourCipher = ARCFourCipher;
|
1412
|
-
exports.CipherTransformFactory = CipherTransformFactory;
|
1413
|
-
exports.PDF17 = PDF17;
|
1414
|
-
exports.PDF20 = PDF20;
|
1415
|
-
exports.calculateMD5 = calculateMD5;
|
1416
|
-
exports.calculateSHA256 = calculateSHA256;
|
1417
|
-
exports.calculateSHA384 = calculateSHA384;
|
1418
|
-
exports.calculateSHA512 = calculateSHA512;
|
1604
|
+
|
1605
|
+
exports.CipherTransformFactory = CipherTransformFactory;
|