@jscrypto/classic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +89 -0
- package/dist/adapter/crypto-js.d.ts +19 -0
- package/dist/adapter/crypto-js.d.ts.map +1 -0
- package/dist/adapter/crypto-js.js +49 -0
- package/dist/adapter/crypto-js.js.map +1 -0
- package/dist/ciphers/aes.d.ts +4 -0
- package/dist/ciphers/aes.d.ts.map +1 -0
- package/dist/ciphers/aes.js +23 -0
- package/dist/ciphers/aes.js.map +1 -0
- package/dist/ciphers/des.d.ts +4 -0
- package/dist/ciphers/des.d.ts.map +1 -0
- package/dist/ciphers/des.js +23 -0
- package/dist/ciphers/des.js.map +1 -0
- package/dist/ciphers/rc4.d.ts +8 -0
- package/dist/ciphers/rc4.d.ts.map +1 -0
- package/dist/ciphers/rc4.js +98 -0
- package/dist/ciphers/rc4.js.map +1 -0
- package/dist/ciphers/triple-des.d.ts +4 -0
- package/dist/ciphers/triple-des.d.ts.map +1 -0
- package/dist/ciphers/triple-des.js +23 -0
- package/dist/ciphers/triple-des.js.map +1 -0
- package/dist/formats/openssl.d.ts +4 -0
- package/dist/formats/openssl.d.ts.map +1 -0
- package/dist/formats/openssl.js +34 -0
- package/dist/formats/openssl.js.map +1 -0
- package/dist/index.cjs +948 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +892 -0
- package/dist/index.mjs.map +7 -0
- package/dist/jscrypto-classic.iife.js +8012 -0
- package/dist/jscrypto-classic.iife.js.map +7 -0
- package/dist/jscrypto-classic.iife.min.js +28 -0
- package/dist/jscrypto-classic.iife.min.js.map +7 -0
- package/dist/jscrypto-classic.umd.js +8023 -0
- package/dist/jscrypto-classic.umd.js.map +7 -0
- package/dist/jscrypto-classic.umd.min.js +39 -0
- package/dist/jscrypto-classic.umd.min.js.map +7 -0
- package/dist/kdfs/evpkdf.d.ts +11 -0
- package/dist/kdfs/evpkdf.d.ts.map +1 -0
- package/dist/kdfs/evpkdf.js +46 -0
- package/dist/kdfs/evpkdf.js.map +1 -0
- package/dist/kdfs/pbkdf2.d.ts +11 -0
- package/dist/kdfs/pbkdf2.d.ts.map +1 -0
- package/dist/kdfs/pbkdf2.js +44 -0
- package/dist/kdfs/pbkdf2.js.map +1 -0
- package/dist/modes/cbc.d.ts +3 -0
- package/dist/modes/cbc.d.ts.map +1 -0
- package/dist/modes/cbc.js +56 -0
- package/dist/modes/cbc.js.map +1 -0
- package/dist/modes/cfb.d.ts +3 -0
- package/dist/modes/cfb.d.ts.map +1 -0
- package/dist/modes/cfb.js +51 -0
- package/dist/modes/cfb.js.map +1 -0
- package/dist/modes/ctr.d.ts +3 -0
- package/dist/modes/ctr.d.ts.map +1 -0
- package/dist/modes/ctr.js +46 -0
- package/dist/modes/ctr.js.map +1 -0
- package/dist/modes/ecb.d.ts +3 -0
- package/dist/modes/ecb.d.ts.map +1 -0
- package/dist/modes/ecb.js +46 -0
- package/dist/modes/ecb.js.map +1 -0
- package/dist/modes/gcm.d.ts +3 -0
- package/dist/modes/gcm.d.ts.map +1 -0
- package/dist/modes/gcm.js +14 -0
- package/dist/modes/gcm.js.map +1 -0
- package/dist/modes/ofb.d.ts +3 -0
- package/dist/modes/ofb.d.ts.map +1 -0
- package/dist/modes/ofb.js +38 -0
- package/dist/modes/ofb.js.map +1 -0
- package/dist/paddings/ansi-x923.d.ts +3 -0
- package/dist/paddings/ansi-x923.d.ts.map +1 -0
- package/dist/paddings/ansi-x923.js +36 -0
- package/dist/paddings/ansi-x923.js.map +1 -0
- package/dist/paddings/iso10126.d.ts +3 -0
- package/dist/paddings/iso10126.d.ts.map +1 -0
- package/dist/paddings/iso10126.js +45 -0
- package/dist/paddings/iso10126.js.map +1 -0
- package/dist/paddings/iso97971.d.ts +3 -0
- package/dist/paddings/iso97971.d.ts.map +1 -0
- package/dist/paddings/iso97971.js +35 -0
- package/dist/paddings/iso97971.js.map +1 -0
- package/dist/paddings/none.d.ts +3 -0
- package/dist/paddings/none.d.ts.map +1 -0
- package/dist/paddings/none.js +17 -0
- package/dist/paddings/none.js.map +1 -0
- package/dist/paddings/pkcs7.d.ts +3 -0
- package/dist/paddings/pkcs7.d.ts.map +1 -0
- package/dist/paddings/pkcs7.js +27 -0
- package/dist/paddings/pkcs7.js.map +1 -0
- package/dist/paddings/zero.d.ts +3 -0
- package/dist/paddings/zero.d.ts.map +1 -0
- package/dist/paddings/zero.js +24 -0
- package/dist/paddings/zero.js.map +1 -0
- package/dist/preset.d.ts +5 -0
- package/dist/preset.d.ts.map +1 -0
- package/dist/preset.js +55 -0
- package/dist/preset.js.map +1 -0
- package/package.json +46 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,948 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @jscrypto/classic v0.1.0
|
|
3
|
+
* Copyright 2026 Chen, Yi-Cyuan
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
|
|
35
|
+
// packages/classic/src/index.ts
|
|
36
|
+
var index_exports = {};
|
|
37
|
+
__export(index_exports, {
|
|
38
|
+
CryptoJS: () => import_crypto_js.default,
|
|
39
|
+
OPENSSL_SALTED_MAGIC: () => OPENSSL_SALTED_MAGIC,
|
|
40
|
+
aes: () => aes,
|
|
41
|
+
ansiX923: () => ansiX923,
|
|
42
|
+
bytesToWordArray: () => bytesToWordArray,
|
|
43
|
+
bytesToWords: () => bytesToWords,
|
|
44
|
+
cbc: () => cbc,
|
|
45
|
+
cfb: () => cfb,
|
|
46
|
+
classicPreset: () => classicPreset,
|
|
47
|
+
createAesCipher: () => createAesCipher,
|
|
48
|
+
createClassicRegistry: () => createClassicRegistry,
|
|
49
|
+
createCryptoJsBlockCipher: () => createCryptoJsBlockCipher,
|
|
50
|
+
createDesCipher: () => createDesCipher,
|
|
51
|
+
createRc4Transform: () => createRc4Transform,
|
|
52
|
+
createTripleDesCipher: () => createTripleDesCipher,
|
|
53
|
+
ctr: () => ctr,
|
|
54
|
+
deriveEvpKdf: () => deriveEvpKdf,
|
|
55
|
+
derivePbkdf2: () => derivePbkdf2,
|
|
56
|
+
des: () => des,
|
|
57
|
+
ecb: () => ecb,
|
|
58
|
+
evpKdf: () => evpKdf,
|
|
59
|
+
gcm: () => gcm,
|
|
60
|
+
iso10126: () => iso10126,
|
|
61
|
+
iso97971: () => iso97971,
|
|
62
|
+
noPadding: () => noPadding,
|
|
63
|
+
ofb: () => ofb,
|
|
64
|
+
opensslFormat: () => opensslFormat,
|
|
65
|
+
pbkdf2: () => pbkdf2,
|
|
66
|
+
pkcs7: () => pkcs7,
|
|
67
|
+
rc4: () => rc4,
|
|
68
|
+
rc4Drop: () => rc4Drop,
|
|
69
|
+
registry: () => registry,
|
|
70
|
+
tripleDes: () => tripleDes,
|
|
71
|
+
wordArrayToBytes: () => wordArrayToBytes,
|
|
72
|
+
wordsToBytes: () => wordsToBytes,
|
|
73
|
+
zeroPadding: () => zeroPadding
|
|
74
|
+
});
|
|
75
|
+
module.exports = __toCommonJS(index_exports);
|
|
76
|
+
|
|
77
|
+
// packages/classic/src/adapter/crypto-js.ts
|
|
78
|
+
var import_crypto_js = __toESM(require("crypto-js"), 1);
|
|
79
|
+
function createCryptoJsBlockCipher(options) {
|
|
80
|
+
const { name, key, blockSize, algorithm } = options;
|
|
81
|
+
const keyWords = bytesToWordArray(key);
|
|
82
|
+
const encryptor = algorithm.createEncryptor(keyWords);
|
|
83
|
+
const decryptor = algorithm.createDecryptor(keyWords);
|
|
84
|
+
return {
|
|
85
|
+
blockSize,
|
|
86
|
+
encryptBlock(block) {
|
|
87
|
+
assertBlock(block, blockSize, name);
|
|
88
|
+
const words = bytesToWords(block);
|
|
89
|
+
encryptor.encryptBlock(words, 0);
|
|
90
|
+
return wordsToBytes(words, blockSize);
|
|
91
|
+
},
|
|
92
|
+
decryptBlock(block) {
|
|
93
|
+
assertBlock(block, blockSize, name);
|
|
94
|
+
const words = bytesToWords(block);
|
|
95
|
+
decryptor.decryptBlock(words, 0);
|
|
96
|
+
return wordsToBytes(words, blockSize);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function assertBlock(block, blockSize, name) {
|
|
101
|
+
if (block.length !== blockSize) {
|
|
102
|
+
throw new Error(`${name} block must be ${blockSize * 8} bits.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function bytesToWordArray(bytes) {
|
|
106
|
+
return import_crypto_js.default.lib.WordArray.create(bytesToWords(bytes), bytes.length);
|
|
107
|
+
}
|
|
108
|
+
function bytesToWords(bytes) {
|
|
109
|
+
const words = [];
|
|
110
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
111
|
+
words[i >>> 2] |= bytes[i] << 24 - i % 4 * 8;
|
|
112
|
+
}
|
|
113
|
+
return words;
|
|
114
|
+
}
|
|
115
|
+
function wordArrayToBytes(wordArray) {
|
|
116
|
+
return wordsToBytes(wordArray.words, wordArray.sigBytes);
|
|
117
|
+
}
|
|
118
|
+
function wordsToBytes(words, length) {
|
|
119
|
+
const bytes = new Uint8Array(length);
|
|
120
|
+
for (let i = 0; i < length; i++) {
|
|
121
|
+
bytes[i] = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
122
|
+
}
|
|
123
|
+
return bytes;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// packages/classic/src/ciphers/aes.ts
|
|
127
|
+
var aes = {
|
|
128
|
+
kind: "cipher",
|
|
129
|
+
name: "AES",
|
|
130
|
+
type: "block",
|
|
131
|
+
blockSize: 16,
|
|
132
|
+
keySizes: [16, 24, 32],
|
|
133
|
+
create(key) {
|
|
134
|
+
return createAesCipher(key);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function createAesCipher(key) {
|
|
138
|
+
if (![16, 24, 32].includes(key.length)) {
|
|
139
|
+
throw new Error("AES key must be 128, 192, or 256 bits.");
|
|
140
|
+
}
|
|
141
|
+
return createCryptoJsBlockCipher({
|
|
142
|
+
name: "AES",
|
|
143
|
+
key,
|
|
144
|
+
blockSize: 16,
|
|
145
|
+
algorithm: import_crypto_js.default.algo.AES
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// packages/classic/src/ciphers/des.ts
|
|
150
|
+
var des = {
|
|
151
|
+
kind: "cipher",
|
|
152
|
+
name: "DES",
|
|
153
|
+
type: "block",
|
|
154
|
+
blockSize: 8,
|
|
155
|
+
keySizes: [8],
|
|
156
|
+
create(key) {
|
|
157
|
+
return createDesCipher(key);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
function createDesCipher(key) {
|
|
161
|
+
if (key.length !== 8) {
|
|
162
|
+
throw new Error("DES key must be 64 bits.");
|
|
163
|
+
}
|
|
164
|
+
return createCryptoJsBlockCipher({
|
|
165
|
+
name: "DES",
|
|
166
|
+
key,
|
|
167
|
+
blockSize: 8,
|
|
168
|
+
algorithm: import_crypto_js.default.algo.DES
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// packages/classic/src/ciphers/rc4.ts
|
|
173
|
+
var rc4 = {
|
|
174
|
+
kind: "cipher",
|
|
175
|
+
name: "RC4",
|
|
176
|
+
type: "stream",
|
|
177
|
+
createEncryptor({ key, options }) {
|
|
178
|
+
return createRc4Transform(key, getDrop(options, 0));
|
|
179
|
+
},
|
|
180
|
+
createDecryptor({ key, options }) {
|
|
181
|
+
return createRc4Transform(key, getDrop(options, 0));
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var rc4Drop = {
|
|
185
|
+
kind: "cipher",
|
|
186
|
+
name: "RC4Drop",
|
|
187
|
+
type: "stream",
|
|
188
|
+
createEncryptor({ key, options }) {
|
|
189
|
+
return createRc4Transform(key, getDrop(options, 192));
|
|
190
|
+
},
|
|
191
|
+
createDecryptor({ key, options }) {
|
|
192
|
+
return createRc4Transform(key, getDrop(options, 192));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function createRc4Transform(key, drop = 0) {
|
|
196
|
+
assertKey(key);
|
|
197
|
+
assertDrop(drop);
|
|
198
|
+
const state = createInitialState(key);
|
|
199
|
+
for (let n = 0; n < drop; n++) {
|
|
200
|
+
nextByte(state);
|
|
201
|
+
}
|
|
202
|
+
let finalized = false;
|
|
203
|
+
const processInput = (input) => {
|
|
204
|
+
const output = new Uint8Array(input.length);
|
|
205
|
+
for (let i = 0; i < input.length; i++) {
|
|
206
|
+
output[i] = input[i] ^ nextByte(state);
|
|
207
|
+
}
|
|
208
|
+
return output;
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
process(input) {
|
|
212
|
+
assertNotFinalized(finalized);
|
|
213
|
+
return processInput(input);
|
|
214
|
+
},
|
|
215
|
+
finalize(input = new Uint8Array()) {
|
|
216
|
+
assertNotFinalized(finalized);
|
|
217
|
+
finalized = true;
|
|
218
|
+
return input.length === 0 ? new Uint8Array() : processInput(input);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function createInitialState(key) {
|
|
223
|
+
const s = new Uint8Array(256);
|
|
224
|
+
for (let i = 0; i < s.length; i++) {
|
|
225
|
+
s[i] = i;
|
|
226
|
+
}
|
|
227
|
+
let j = 0;
|
|
228
|
+
for (let i = 0; i < s.length; i++) {
|
|
229
|
+
j = j + s[i] + key[i % key.length] & 255;
|
|
230
|
+
swap(s, i, j);
|
|
231
|
+
}
|
|
232
|
+
return { s, i: 0, j: 0 };
|
|
233
|
+
}
|
|
234
|
+
function nextByte(state) {
|
|
235
|
+
const { s } = state;
|
|
236
|
+
state.i = state.i + 1 & 255;
|
|
237
|
+
state.j = state.j + s[state.i] & 255;
|
|
238
|
+
swap(s, state.i, state.j);
|
|
239
|
+
return s[s[state.i] + s[state.j] & 255];
|
|
240
|
+
}
|
|
241
|
+
function swap(bytes, a, b) {
|
|
242
|
+
const value = bytes[a];
|
|
243
|
+
bytes[a] = bytes[b];
|
|
244
|
+
bytes[b] = value;
|
|
245
|
+
}
|
|
246
|
+
function getDrop(options, defaultDrop) {
|
|
247
|
+
if (!isRc4Options(options) || options.drop === void 0) {
|
|
248
|
+
return defaultDrop;
|
|
249
|
+
}
|
|
250
|
+
return options.drop;
|
|
251
|
+
}
|
|
252
|
+
function isRc4Options(options) {
|
|
253
|
+
return typeof options === "object" && options !== null;
|
|
254
|
+
}
|
|
255
|
+
function assertKey(key) {
|
|
256
|
+
if (key.length < 5) {
|
|
257
|
+
throw new Error("RC4 key should be greater or equal than 40 bits.");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function assertDrop(drop) {
|
|
261
|
+
if (!Number.isInteger(drop) || drop < 0) {
|
|
262
|
+
throw new RangeError("RC4 drop must be a non-negative integer.");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function assertNotFinalized(finalized) {
|
|
266
|
+
if (finalized) {
|
|
267
|
+
throw new Error("Transform is already finalized.");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// packages/classic/src/ciphers/triple-des.ts
|
|
272
|
+
var tripleDes = {
|
|
273
|
+
kind: "cipher",
|
|
274
|
+
name: "TripleDES",
|
|
275
|
+
type: "block",
|
|
276
|
+
blockSize: 8,
|
|
277
|
+
keySizes: [16, 24],
|
|
278
|
+
create(key) {
|
|
279
|
+
return createTripleDesCipher(key);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
function createTripleDesCipher(key) {
|
|
283
|
+
if (![16, 24].includes(key.length)) {
|
|
284
|
+
throw new Error("Triple DES key must be 128 or 192 bits.");
|
|
285
|
+
}
|
|
286
|
+
return createCryptoJsBlockCipher({
|
|
287
|
+
name: "Triple DES",
|
|
288
|
+
key,
|
|
289
|
+
blockSize: 8,
|
|
290
|
+
algorithm: import_crypto_js.default.algo.TripleDES
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// packages/classic/src/formats/openssl.ts
|
|
295
|
+
var import_core = require("@jscrypto/core");
|
|
296
|
+
var OPENSSL_SALTED_MAGIC = new Uint8Array([
|
|
297
|
+
83,
|
|
298
|
+
97,
|
|
299
|
+
108,
|
|
300
|
+
116,
|
|
301
|
+
101,
|
|
302
|
+
100,
|
|
303
|
+
95,
|
|
304
|
+
95
|
|
305
|
+
]);
|
|
306
|
+
var opensslFormat = {
|
|
307
|
+
kind: "format",
|
|
308
|
+
name: "OpenSSL",
|
|
309
|
+
mediaType: "application/octet-stream",
|
|
310
|
+
stringify({ ciphertext, salt }) {
|
|
311
|
+
if (!salt) {
|
|
312
|
+
return ciphertext.slice();
|
|
313
|
+
}
|
|
314
|
+
assertSalt(salt);
|
|
315
|
+
return (0, import_core.concatBytes)(OPENSSL_SALTED_MAGIC, salt, ciphertext);
|
|
316
|
+
},
|
|
317
|
+
parse(input) {
|
|
318
|
+
if (!hasSaltHeader(input)) {
|
|
319
|
+
return { ciphertext: input.slice() };
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
salt: input.slice(OPENSSL_SALTED_MAGIC.length, OPENSSL_SALTED_MAGIC.length + 8),
|
|
323
|
+
ciphertext: input.slice(OPENSSL_SALTED_MAGIC.length + 8)
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
function hasSaltHeader(input) {
|
|
328
|
+
return input.length >= 16 && (0, import_core.equalBytes)(input.subarray(0, OPENSSL_SALTED_MAGIC.length), OPENSSL_SALTED_MAGIC);
|
|
329
|
+
}
|
|
330
|
+
function assertSalt(salt) {
|
|
331
|
+
if (salt.length !== 8) {
|
|
332
|
+
throw new Error("OpenSSL salt must be 64 bits.");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// packages/classic/src/kdfs/evpkdf.ts
|
|
337
|
+
var evpKdf = {
|
|
338
|
+
kind: "kdf",
|
|
339
|
+
name: "EvpKDF",
|
|
340
|
+
derive(params) {
|
|
341
|
+
return deriveEvpKdf(params);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
function deriveEvpKdf(params) {
|
|
345
|
+
assertPositiveInteger(params.length, "EvpKDF length");
|
|
346
|
+
if (params.iterations !== void 0) {
|
|
347
|
+
assertPositiveInteger(params.iterations, "EvpKDF iterations");
|
|
348
|
+
}
|
|
349
|
+
const options = {
|
|
350
|
+
keySize: params.length / 4,
|
|
351
|
+
iterations: params.iterations ?? 1
|
|
352
|
+
};
|
|
353
|
+
const hasher = getHasher(params.hash);
|
|
354
|
+
if (hasher) {
|
|
355
|
+
options.hasher = hasher;
|
|
356
|
+
}
|
|
357
|
+
const derived = import_crypto_js.default.EvpKDF(toCryptoJsInput(params.passphrase), toCryptoJsInput(params.salt), options);
|
|
358
|
+
return wordArrayToBytes(derived);
|
|
359
|
+
}
|
|
360
|
+
function toCryptoJsInput(input) {
|
|
361
|
+
return typeof input === "string" ? input : bytesToWordArray(input);
|
|
362
|
+
}
|
|
363
|
+
function getHasher(hash) {
|
|
364
|
+
if (!hash) {
|
|
365
|
+
return void 0;
|
|
366
|
+
}
|
|
367
|
+
const hasher = import_crypto_js.default.algo[normalizeHashName(hash)];
|
|
368
|
+
if (!hasher) {
|
|
369
|
+
throw new Error(`Unsupported EvpKDF hash: ${hash}`);
|
|
370
|
+
}
|
|
371
|
+
return hasher;
|
|
372
|
+
}
|
|
373
|
+
function normalizeHashName(hash) {
|
|
374
|
+
return hash.replaceAll("-", "").toUpperCase();
|
|
375
|
+
}
|
|
376
|
+
function assertPositiveInteger(value, label) {
|
|
377
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
378
|
+
throw new RangeError(`${label} must be a positive integer.`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// packages/classic/src/kdfs/pbkdf2.ts
|
|
383
|
+
var pbkdf2 = {
|
|
384
|
+
kind: "kdf",
|
|
385
|
+
name: "PBKDF2",
|
|
386
|
+
derive(params) {
|
|
387
|
+
return derivePbkdf2(params);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
function derivePbkdf2(params) {
|
|
391
|
+
assertPositiveInteger2(params.iterations, "PBKDF2 iterations");
|
|
392
|
+
assertPositiveInteger2(params.length, "PBKDF2 length");
|
|
393
|
+
const options = {
|
|
394
|
+
keySize: params.length / 4,
|
|
395
|
+
iterations: params.iterations
|
|
396
|
+
};
|
|
397
|
+
const hasher = getHasher2(params.hash);
|
|
398
|
+
if (hasher) {
|
|
399
|
+
options.hasher = hasher;
|
|
400
|
+
}
|
|
401
|
+
const derived = import_crypto_js.default.PBKDF2(toCryptoJsInput2(params.passphrase), toCryptoJsInput2(params.salt), options);
|
|
402
|
+
return wordArrayToBytes(derived);
|
|
403
|
+
}
|
|
404
|
+
function toCryptoJsInput2(input) {
|
|
405
|
+
return typeof input === "string" ? input : bytesToWordArray(input);
|
|
406
|
+
}
|
|
407
|
+
function getHasher2(hash) {
|
|
408
|
+
if (!hash) {
|
|
409
|
+
return void 0;
|
|
410
|
+
}
|
|
411
|
+
const hasher = import_crypto_js.default.algo[normalizeHashName2(hash)];
|
|
412
|
+
if (!hasher) {
|
|
413
|
+
throw new Error(`Unsupported PBKDF2 hash: ${hash}`);
|
|
414
|
+
}
|
|
415
|
+
return hasher;
|
|
416
|
+
}
|
|
417
|
+
function normalizeHashName2(hash) {
|
|
418
|
+
return hash.replaceAll("-", "").toUpperCase();
|
|
419
|
+
}
|
|
420
|
+
function assertPositiveInteger2(value, label) {
|
|
421
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
422
|
+
throw new RangeError(`${label} must be a positive integer.`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// packages/classic/src/modes/cbc.ts
|
|
427
|
+
var import_core2 = require("@jscrypto/core");
|
|
428
|
+
var cbc = {
|
|
429
|
+
kind: "mode",
|
|
430
|
+
name: "CBC",
|
|
431
|
+
requiresPadding: true,
|
|
432
|
+
createEncryptor({ cipher, iv }) {
|
|
433
|
+
(0, import_core2.assertIv)(cipher.blockSize, iv, "CBC");
|
|
434
|
+
return createCbcEncryptor(cipher, iv);
|
|
435
|
+
},
|
|
436
|
+
createDecryptor({ cipher, iv }) {
|
|
437
|
+
(0, import_core2.assertIv)(cipher.blockSize, iv, "CBC");
|
|
438
|
+
return createCbcDecryptor(cipher, iv);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
function createCbcEncryptor(cipher, iv) {
|
|
442
|
+
let previous = iv;
|
|
443
|
+
return {
|
|
444
|
+
process(input) {
|
|
445
|
+
assertBlockMultiple(cipher.blockSize, input);
|
|
446
|
+
const output = new Uint8Array(input.length);
|
|
447
|
+
for (let offset = 0; offset < input.length; offset += cipher.blockSize) {
|
|
448
|
+
const block = (0, import_core2.xorBytes)(input.subarray(offset, offset + cipher.blockSize), previous);
|
|
449
|
+
const encrypted = cipher.encryptBlock(block);
|
|
450
|
+
output.set(encrypted, offset);
|
|
451
|
+
previous = encrypted;
|
|
452
|
+
}
|
|
453
|
+
return output;
|
|
454
|
+
},
|
|
455
|
+
finalize(input = new Uint8Array()) {
|
|
456
|
+
return input.length === 0 ? new Uint8Array() : this.process(input);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function createCbcDecryptor(cipher, iv) {
|
|
461
|
+
let previous = iv;
|
|
462
|
+
return {
|
|
463
|
+
process(input) {
|
|
464
|
+
assertBlockMultiple(cipher.blockSize, input);
|
|
465
|
+
const output = new Uint8Array(input.length);
|
|
466
|
+
for (let offset = 0; offset < input.length; offset += cipher.blockSize) {
|
|
467
|
+
const block = input.subarray(offset, offset + cipher.blockSize);
|
|
468
|
+
const decrypted = cipher.decryptBlock(block);
|
|
469
|
+
output.set((0, import_core2.xorBytes)(decrypted, previous), offset);
|
|
470
|
+
previous = block.slice();
|
|
471
|
+
}
|
|
472
|
+
return output;
|
|
473
|
+
},
|
|
474
|
+
finalize(input = new Uint8Array()) {
|
|
475
|
+
return input.length === 0 ? new Uint8Array() : this.process(input);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function assertBlockMultiple(blockSize, input) {
|
|
480
|
+
(0, import_core2.assertBlockMultiple)(input, blockSize, "CBC");
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// packages/classic/src/modes/cfb.ts
|
|
484
|
+
var import_core3 = require("@jscrypto/core");
|
|
485
|
+
var cfb = {
|
|
486
|
+
kind: "mode",
|
|
487
|
+
name: "CFB",
|
|
488
|
+
requiresPadding: false,
|
|
489
|
+
createEncryptor({ cipher, iv }) {
|
|
490
|
+
(0, import_core3.assertIv)(cipher.blockSize, iv, "CFB");
|
|
491
|
+
return createCfbEncryptor(cipher, iv);
|
|
492
|
+
},
|
|
493
|
+
createDecryptor({ cipher, iv }) {
|
|
494
|
+
(0, import_core3.assertIv)(cipher.blockSize, iv, "CFB");
|
|
495
|
+
return createCfbDecryptor(cipher, iv);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
function createCfbEncryptor(cipher, iv) {
|
|
499
|
+
return createCfbTransform(cipher, iv, true);
|
|
500
|
+
}
|
|
501
|
+
function createCfbDecryptor(cipher, iv) {
|
|
502
|
+
return createCfbTransform(cipher, iv, false);
|
|
503
|
+
}
|
|
504
|
+
function createCfbTransform(cipher, iv, encrypting) {
|
|
505
|
+
let feedback = iv.slice();
|
|
506
|
+
let nextFeedback = new Uint8Array(cipher.blockSize);
|
|
507
|
+
let keystream = new Uint8Array(cipher.blockSize);
|
|
508
|
+
let position = 0;
|
|
509
|
+
return {
|
|
510
|
+
process(input) {
|
|
511
|
+
const output = new Uint8Array(input.length);
|
|
512
|
+
for (let i = 0; i < input.length; i++) {
|
|
513
|
+
if (position === 0) {
|
|
514
|
+
keystream = cipher.encryptBlock(feedback);
|
|
515
|
+
}
|
|
516
|
+
const inputByte = input[i];
|
|
517
|
+
const outputByte = inputByte ^ keystream[position];
|
|
518
|
+
output[i] = outputByte;
|
|
519
|
+
nextFeedback[position] = encrypting ? outputByte : inputByte;
|
|
520
|
+
position++;
|
|
521
|
+
if (position === cipher.blockSize) {
|
|
522
|
+
feedback = nextFeedback;
|
|
523
|
+
nextFeedback = new Uint8Array(cipher.blockSize);
|
|
524
|
+
position = 0;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return output;
|
|
528
|
+
},
|
|
529
|
+
finalize(input = new Uint8Array()) {
|
|
530
|
+
return input.length === 0 ? new Uint8Array() : this.process(input);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// packages/classic/src/modes/ctr.ts
|
|
536
|
+
var import_core4 = require("@jscrypto/core");
|
|
537
|
+
var ctr = {
|
|
538
|
+
kind: "mode",
|
|
539
|
+
name: "CTR",
|
|
540
|
+
requiresPadding: false,
|
|
541
|
+
createEncryptor({ cipher, iv }) {
|
|
542
|
+
(0, import_core4.assertIv)(cipher.blockSize, iv, "CTR");
|
|
543
|
+
return createCtrTransform(cipher, iv);
|
|
544
|
+
},
|
|
545
|
+
createDecryptor({ cipher, iv }) {
|
|
546
|
+
(0, import_core4.assertIv)(cipher.blockSize, iv, "CTR");
|
|
547
|
+
return createCtrTransform(cipher, iv);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
function createCtrTransform(cipher, iv) {
|
|
551
|
+
const counter = iv.slice();
|
|
552
|
+
let keystream = new Uint8Array(cipher.blockSize);
|
|
553
|
+
let position = cipher.blockSize;
|
|
554
|
+
return {
|
|
555
|
+
process(input) {
|
|
556
|
+
const output = new Uint8Array(input.length);
|
|
557
|
+
for (let i = 0; i < input.length; i++) {
|
|
558
|
+
if (position === cipher.blockSize) {
|
|
559
|
+
keystream = cipher.encryptBlock(counter);
|
|
560
|
+
incrementCounter(counter);
|
|
561
|
+
position = 0;
|
|
562
|
+
}
|
|
563
|
+
output[i] = input[i] ^ keystream[position];
|
|
564
|
+
position++;
|
|
565
|
+
}
|
|
566
|
+
return output;
|
|
567
|
+
},
|
|
568
|
+
finalize(input = new Uint8Array()) {
|
|
569
|
+
return input.length === 0 ? new Uint8Array() : this.process(input);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
function incrementCounter(counter) {
|
|
574
|
+
for (let i = counter.length - 1; i >= 0; i--) {
|
|
575
|
+
counter[i] = counter[i] + 1 & 255;
|
|
576
|
+
if (counter[i] !== 0) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// packages/classic/src/modes/ecb.ts
|
|
583
|
+
var import_core5 = require("@jscrypto/core");
|
|
584
|
+
var ecb = {
|
|
585
|
+
kind: "mode",
|
|
586
|
+
name: "ECB",
|
|
587
|
+
requiresPadding: true,
|
|
588
|
+
createEncryptor({ cipher }) {
|
|
589
|
+
return createEcbEncryptor(cipher);
|
|
590
|
+
},
|
|
591
|
+
createDecryptor({ cipher }) {
|
|
592
|
+
return createEcbDecryptor(cipher);
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
function createEcbEncryptor(cipher) {
|
|
596
|
+
return {
|
|
597
|
+
process(input) {
|
|
598
|
+
assertBlockMultiple2(cipher.blockSize, input);
|
|
599
|
+
const output = new Uint8Array(input.length);
|
|
600
|
+
for (let offset = 0; offset < input.length; offset += cipher.blockSize) {
|
|
601
|
+
output.set(cipher.encryptBlock(input.subarray(offset, offset + cipher.blockSize)), offset);
|
|
602
|
+
}
|
|
603
|
+
return output;
|
|
604
|
+
},
|
|
605
|
+
finalize(input = new Uint8Array()) {
|
|
606
|
+
return input.length === 0 ? new Uint8Array() : this.process(input);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function createEcbDecryptor(cipher) {
|
|
611
|
+
return {
|
|
612
|
+
process(input) {
|
|
613
|
+
assertBlockMultiple2(cipher.blockSize, input);
|
|
614
|
+
const output = new Uint8Array(input.length);
|
|
615
|
+
for (let offset = 0; offset < input.length; offset += cipher.blockSize) {
|
|
616
|
+
output.set(cipher.decryptBlock(input.subarray(offset, offset + cipher.blockSize)), offset);
|
|
617
|
+
}
|
|
618
|
+
return output;
|
|
619
|
+
},
|
|
620
|
+
finalize(input = new Uint8Array()) {
|
|
621
|
+
return input.length === 0 ? new Uint8Array() : this.process(input);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
function assertBlockMultiple2(blockSize, input) {
|
|
626
|
+
(0, import_core5.assertBlockMultiple)(input, blockSize, "ECB");
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// packages/classic/src/modes/gcm.ts
|
|
630
|
+
var gcm = {
|
|
631
|
+
kind: "mode",
|
|
632
|
+
name: "GCM",
|
|
633
|
+
aead: true,
|
|
634
|
+
requiredBlockSize: 16,
|
|
635
|
+
requiresPadding: false,
|
|
636
|
+
createEncryptor() {
|
|
637
|
+
throw new Error("GCM mode is not implemented yet.");
|
|
638
|
+
},
|
|
639
|
+
createDecryptor() {
|
|
640
|
+
throw new Error("GCM mode is not implemented yet.");
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// packages/classic/src/modes/ofb.ts
|
|
645
|
+
var import_core6 = require("@jscrypto/core");
|
|
646
|
+
var ofb = {
|
|
647
|
+
kind: "mode",
|
|
648
|
+
name: "OFB",
|
|
649
|
+
requiresPadding: false,
|
|
650
|
+
createEncryptor({ cipher, iv }) {
|
|
651
|
+
(0, import_core6.assertIv)(cipher.blockSize, iv, "OFB");
|
|
652
|
+
return createOfbTransform(cipher, iv);
|
|
653
|
+
},
|
|
654
|
+
createDecryptor({ cipher, iv }) {
|
|
655
|
+
(0, import_core6.assertIv)(cipher.blockSize, iv, "OFB");
|
|
656
|
+
return createOfbTransform(cipher, iv);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
function createOfbTransform(cipher, iv) {
|
|
660
|
+
let feedback = iv.slice();
|
|
661
|
+
let keystream = new Uint8Array(cipher.blockSize);
|
|
662
|
+
let position = cipher.blockSize;
|
|
663
|
+
return {
|
|
664
|
+
process(input) {
|
|
665
|
+
const output = new Uint8Array(input.length);
|
|
666
|
+
for (let i = 0; i < input.length; i++) {
|
|
667
|
+
if (position === cipher.blockSize) {
|
|
668
|
+
feedback = cipher.encryptBlock(feedback);
|
|
669
|
+
keystream = feedback;
|
|
670
|
+
position = 0;
|
|
671
|
+
}
|
|
672
|
+
output[i] = input[i] ^ keystream[position];
|
|
673
|
+
position++;
|
|
674
|
+
}
|
|
675
|
+
return output;
|
|
676
|
+
},
|
|
677
|
+
finalize(input = new Uint8Array()) {
|
|
678
|
+
return input.length === 0 ? new Uint8Array() : this.process(input);
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// packages/classic/src/paddings/ansi-x923.ts
|
|
684
|
+
var import_core7 = require("@jscrypto/core");
|
|
685
|
+
var ansiX923 = {
|
|
686
|
+
kind: "padding",
|
|
687
|
+
name: "AnsiX923",
|
|
688
|
+
pad(input, blockSize) {
|
|
689
|
+
assertBlockSize(blockSize);
|
|
690
|
+
const paddingLength = getPaddingLength(input.length, blockSize);
|
|
691
|
+
const output = new Uint8Array(input.length + paddingLength);
|
|
692
|
+
output.set(input);
|
|
693
|
+
output[output.length - 1] = paddingLength;
|
|
694
|
+
return output;
|
|
695
|
+
},
|
|
696
|
+
unpad(input, blockSize) {
|
|
697
|
+
assertPaddedInput(input, blockSize);
|
|
698
|
+
const paddingLength = input[input.length - 1];
|
|
699
|
+
if (paddingLength === 0 || paddingLength > blockSize || paddingLength > input.length) {
|
|
700
|
+
throw new Error("Invalid ANSI X9.23 padding.");
|
|
701
|
+
}
|
|
702
|
+
for (let i = input.length - paddingLength; i < input.length - 1; i++) {
|
|
703
|
+
if (input[i] !== 0) {
|
|
704
|
+
throw new Error("Invalid ANSI X9.23 padding.");
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
return input.slice(0, input.length - paddingLength);
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
function assertBlockSize(blockSize) {
|
|
711
|
+
(0, import_core7.assertBlockSize)(blockSize, { max: 255 });
|
|
712
|
+
}
|
|
713
|
+
function assertPaddedInput(input, blockSize) {
|
|
714
|
+
(0, import_core7.assertPaddedInput)(input, blockSize, "ANSI X9.23", { max: 255 });
|
|
715
|
+
}
|
|
716
|
+
function getPaddingLength(inputLength, blockSize) {
|
|
717
|
+
return (0, import_core7.getBlockPaddingLength)(inputLength, blockSize);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// packages/classic/src/paddings/iso10126.ts
|
|
721
|
+
var import_core8 = require("@jscrypto/core");
|
|
722
|
+
var iso10126 = {
|
|
723
|
+
kind: "padding",
|
|
724
|
+
name: "Iso10126",
|
|
725
|
+
pad(input, blockSize) {
|
|
726
|
+
assertBlockSize2(blockSize);
|
|
727
|
+
const paddingLength = getPaddingLength2(input.length, blockSize);
|
|
728
|
+
const output = new Uint8Array(input.length + paddingLength);
|
|
729
|
+
output.set(input);
|
|
730
|
+
fillRandom(output.subarray(input.length, output.length - 1));
|
|
731
|
+
output[output.length - 1] = paddingLength;
|
|
732
|
+
return output;
|
|
733
|
+
},
|
|
734
|
+
unpad(input, blockSize) {
|
|
735
|
+
assertPaddedInput2(input, blockSize);
|
|
736
|
+
const paddingLength = input[input.length - 1];
|
|
737
|
+
if (paddingLength === 0 || paddingLength > blockSize || paddingLength > input.length) {
|
|
738
|
+
throw new Error("Invalid ISO 10126 padding.");
|
|
739
|
+
}
|
|
740
|
+
return input.slice(0, input.length - paddingLength);
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
function assertBlockSize2(blockSize) {
|
|
744
|
+
(0, import_core8.assertBlockSize)(blockSize, { max: 255 });
|
|
745
|
+
}
|
|
746
|
+
function assertPaddedInput2(input, blockSize) {
|
|
747
|
+
(0, import_core8.assertPaddedInput)(input, blockSize, "ISO 10126", { max: 255 });
|
|
748
|
+
}
|
|
749
|
+
function getPaddingLength2(inputLength, blockSize) {
|
|
750
|
+
return (0, import_core8.getBlockPaddingLength)(inputLength, blockSize);
|
|
751
|
+
}
|
|
752
|
+
function fillRandom(bytes) {
|
|
753
|
+
if (bytes.length === 0) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
const crypto = globalThis;
|
|
757
|
+
crypto.crypto?.getRandomValues(bytes);
|
|
758
|
+
if (bytes.some((byte) => byte !== 0)) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
762
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// packages/classic/src/paddings/iso97971.ts
|
|
767
|
+
var import_core9 = require("@jscrypto/core");
|
|
768
|
+
var iso97971 = {
|
|
769
|
+
kind: "padding",
|
|
770
|
+
name: "Iso97971",
|
|
771
|
+
pad(input, blockSize) {
|
|
772
|
+
assertBlockSize3(blockSize);
|
|
773
|
+
const paddingLength = getPaddingLength3(input.length, blockSize);
|
|
774
|
+
const output = new Uint8Array(input.length + paddingLength);
|
|
775
|
+
output.set(input);
|
|
776
|
+
output[input.length] = 128;
|
|
777
|
+
return output;
|
|
778
|
+
},
|
|
779
|
+
unpad(input, blockSize) {
|
|
780
|
+
assertPaddedInput3(input, blockSize);
|
|
781
|
+
let index = input.length - 1;
|
|
782
|
+
while (index >= 0 && input[index] === 0) {
|
|
783
|
+
index--;
|
|
784
|
+
}
|
|
785
|
+
if (index < 0 || input[index] !== 128) {
|
|
786
|
+
throw new Error("Invalid ISO/IEC 9797-1 padding.");
|
|
787
|
+
}
|
|
788
|
+
return input.slice(0, index);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
function assertBlockSize3(blockSize) {
|
|
792
|
+
(0, import_core9.assertBlockSize)(blockSize);
|
|
793
|
+
}
|
|
794
|
+
function assertPaddedInput3(input, blockSize) {
|
|
795
|
+
(0, import_core9.assertPaddedInput)(input, blockSize, "ISO/IEC 9797-1");
|
|
796
|
+
}
|
|
797
|
+
function getPaddingLength3(inputLength, blockSize) {
|
|
798
|
+
const remainder = (inputLength + 1) % blockSize;
|
|
799
|
+
return 1 + (remainder === 0 ? 0 : blockSize - remainder);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// packages/classic/src/paddings/none.ts
|
|
803
|
+
var import_core10 = require("@jscrypto/core");
|
|
804
|
+
var noPadding = {
|
|
805
|
+
kind: "padding",
|
|
806
|
+
name: "NoPadding",
|
|
807
|
+
pad(input, blockSize) {
|
|
808
|
+
assertMultiple(input, blockSize);
|
|
809
|
+
return input.slice();
|
|
810
|
+
},
|
|
811
|
+
unpad(input, blockSize) {
|
|
812
|
+
assertMultiple(input, blockSize);
|
|
813
|
+
return input.slice();
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
function assertMultiple(input, blockSize) {
|
|
817
|
+
(0, import_core10.assertBlockMultiple)(input, blockSize, "NoPadding");
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// packages/classic/src/paddings/pkcs7.ts
|
|
821
|
+
var import_core11 = require("@jscrypto/core");
|
|
822
|
+
var pkcs7 = {
|
|
823
|
+
kind: "padding",
|
|
824
|
+
name: "Pkcs7",
|
|
825
|
+
pad(input, blockSize) {
|
|
826
|
+
(0, import_core11.assertBlockSize)(blockSize, { max: 255 });
|
|
827
|
+
const paddingLength = (0, import_core11.getBlockPaddingLength)(input.length, blockSize);
|
|
828
|
+
const output = new Uint8Array(input.length + paddingLength);
|
|
829
|
+
output.set(input);
|
|
830
|
+
output.fill(paddingLength, input.length);
|
|
831
|
+
return output;
|
|
832
|
+
},
|
|
833
|
+
unpad(input, blockSize) {
|
|
834
|
+
(0, import_core11.assertPaddedInput)(input, blockSize, "PKCS#7", { max: 255 });
|
|
835
|
+
const paddingLength = input[input.length - 1];
|
|
836
|
+
if (paddingLength === 0 || paddingLength > blockSize || paddingLength > input.length) {
|
|
837
|
+
throw new Error("Invalid PKCS#7 padding.");
|
|
838
|
+
}
|
|
839
|
+
for (let i = input.length - paddingLength; i < input.length; i++) {
|
|
840
|
+
if (input[i] !== paddingLength) {
|
|
841
|
+
throw new Error("Invalid PKCS#7 padding.");
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return input.slice(0, input.length - paddingLength);
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
// packages/classic/src/paddings/zero.ts
|
|
849
|
+
var zeroPadding = {
|
|
850
|
+
kind: "padding",
|
|
851
|
+
name: "ZeroPadding",
|
|
852
|
+
pad(input, blockSize) {
|
|
853
|
+
if (!Number.isInteger(blockSize) || blockSize <= 0) {
|
|
854
|
+
throw new RangeError("blockSize must be a positive integer.");
|
|
855
|
+
}
|
|
856
|
+
const remainder = input.length % blockSize;
|
|
857
|
+
if (remainder === 0) {
|
|
858
|
+
return input.slice();
|
|
859
|
+
}
|
|
860
|
+
const output = new Uint8Array(input.length + blockSize - remainder);
|
|
861
|
+
output.set(input);
|
|
862
|
+
return output;
|
|
863
|
+
},
|
|
864
|
+
unpad(input) {
|
|
865
|
+
let end = input.length;
|
|
866
|
+
while (end > 0 && input[end - 1] === 0) {
|
|
867
|
+
end--;
|
|
868
|
+
}
|
|
869
|
+
return input.slice(0, end);
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// packages/classic/src/preset.ts
|
|
874
|
+
var import_core12 = require("@jscrypto/core");
|
|
875
|
+
function classicPreset() {
|
|
876
|
+
return {
|
|
877
|
+
kind: "preset",
|
|
878
|
+
name: "classic",
|
|
879
|
+
components() {
|
|
880
|
+
return [
|
|
881
|
+
aes,
|
|
882
|
+
des,
|
|
883
|
+
rc4,
|
|
884
|
+
rc4Drop,
|
|
885
|
+
tripleDes,
|
|
886
|
+
cbc,
|
|
887
|
+
cfb,
|
|
888
|
+
ctr,
|
|
889
|
+
ecb,
|
|
890
|
+
gcm,
|
|
891
|
+
ofb,
|
|
892
|
+
pkcs7,
|
|
893
|
+
noPadding,
|
|
894
|
+
ansiX923,
|
|
895
|
+
iso10126,
|
|
896
|
+
iso97971,
|
|
897
|
+
zeroPadding,
|
|
898
|
+
pbkdf2,
|
|
899
|
+
evpKdf,
|
|
900
|
+
opensslFormat
|
|
901
|
+
];
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
function createClassicRegistry() {
|
|
906
|
+
return (0, import_core12.createRegistry)().use(classicPreset());
|
|
907
|
+
}
|
|
908
|
+
var registry = createClassicRegistry();
|
|
909
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
910
|
+
0 && (module.exports = {
|
|
911
|
+
CryptoJS,
|
|
912
|
+
OPENSSL_SALTED_MAGIC,
|
|
913
|
+
aes,
|
|
914
|
+
ansiX923,
|
|
915
|
+
bytesToWordArray,
|
|
916
|
+
bytesToWords,
|
|
917
|
+
cbc,
|
|
918
|
+
cfb,
|
|
919
|
+
classicPreset,
|
|
920
|
+
createAesCipher,
|
|
921
|
+
createClassicRegistry,
|
|
922
|
+
createCryptoJsBlockCipher,
|
|
923
|
+
createDesCipher,
|
|
924
|
+
createRc4Transform,
|
|
925
|
+
createTripleDesCipher,
|
|
926
|
+
ctr,
|
|
927
|
+
deriveEvpKdf,
|
|
928
|
+
derivePbkdf2,
|
|
929
|
+
des,
|
|
930
|
+
ecb,
|
|
931
|
+
evpKdf,
|
|
932
|
+
gcm,
|
|
933
|
+
iso10126,
|
|
934
|
+
iso97971,
|
|
935
|
+
noPadding,
|
|
936
|
+
ofb,
|
|
937
|
+
opensslFormat,
|
|
938
|
+
pbkdf2,
|
|
939
|
+
pkcs7,
|
|
940
|
+
rc4,
|
|
941
|
+
rc4Drop,
|
|
942
|
+
registry,
|
|
943
|
+
tripleDes,
|
|
944
|
+
wordArrayToBytes,
|
|
945
|
+
wordsToBytes,
|
|
946
|
+
zeroPadding
|
|
947
|
+
});
|
|
948
|
+
//# sourceMappingURL=index.cjs.map
|