@protontech/openpgp 4.10.8 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +311 -239
- package/dist/lightweight/bn.interface.min.mjs +3 -0
- package/dist/lightweight/bn.interface.min.mjs.map +1 -0
- package/dist/lightweight/bn.interface.mjs +340 -0
- package/dist/lightweight/bn.min.mjs +3 -0
- package/dist/lightweight/bn.min.mjs.map +1 -0
- package/dist/lightweight/bn.mjs +3434 -0
- package/dist/lightweight/elliptic.min.mjs +3 -0
- package/dist/lightweight/elliptic.min.mjs.map +1 -0
- package/dist/lightweight/elliptic.mjs +4313 -0
- package/dist/lightweight/openpgp.min.mjs +3 -0
- package/dist/lightweight/openpgp.min.mjs.map +1 -0
- package/dist/lightweight/openpgp.mjs +31375 -0
- package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
- package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
- package/dist/lightweight/ponyfill.es6.mjs +3831 -0
- package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
- package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
- package/dist/lightweight/web-streams-adapter.mjs +561 -0
- package/dist/node/openpgp.js +43943 -0
- package/dist/node/openpgp.min.js +17 -0
- package/dist/node/openpgp.min.js.map +1 -0
- package/dist/node/openpgp.min.mjs +17 -0
- package/dist/node/openpgp.min.mjs.map +1 -0
- package/dist/node/openpgp.mjs +43880 -0
- package/dist/openpgp.js +41077 -41609
- package/dist/openpgp.min.js +17 -2
- package/dist/openpgp.min.js.map +1 -0
- package/dist/openpgp.min.mjs +17 -0
- package/dist/openpgp.min.mjs.map +1 -0
- package/dist/openpgp.mjs +43868 -0
- package/lightweight/package.json +5 -0
- package/openpgp.d.ts +889 -0
- package/package.json +63 -57
- package/dist/compat/openpgp.js +0 -61152
- package/dist/compat/openpgp.min.js +0 -2
- package/dist/compat/openpgp.worker.js +0 -173
- package/dist/compat/openpgp.worker.min.js +0 -2
- package/dist/lightweight/elliptic.min.js +0 -5
- package/dist/lightweight/openpgp.js +0 -40071
- package/dist/lightweight/openpgp.min.js +0 -2
- package/dist/lightweight/openpgp.worker.js +0 -173
- package/dist/lightweight/openpgp.worker.min.js +0 -2
- package/dist/openpgp.worker.js +0 -173
- package/dist/openpgp.worker.min.js +0 -2
- package/src/cleartext.js +0 -220
- package/src/config/config.js +0 -232
- package/src/config/index.js +0 -7
- package/src/config/localStorage.js +0 -35
- package/src/crypto/aes_kw.js +0 -153
- package/src/crypto/cfb.js +0 -169
- package/src/crypto/cipher/aes.js +0 -27
- package/src/crypto/cipher/blowfish.js +0 -398
- package/src/crypto/cipher/cast5.js +0 -610
- package/src/crypto/cipher/des.js +0 -476
- package/src/crypto/cipher/index.js +0 -91
- package/src/crypto/cipher/twofish.js +0 -346
- package/src/crypto/cmac.js +0 -98
- package/src/crypto/crypto.js +0 -394
- package/src/crypto/eax.js +0 -172
- package/src/crypto/gcm.js +0 -141
- package/src/crypto/hash/index.js +0 -163
- package/src/crypto/hash/md5.js +0 -205
- package/src/crypto/index.js +0 -57
- package/src/crypto/ocb.js +0 -274
- package/src/crypto/pkcs1.js +0 -170
- package/src/crypto/pkcs5.js +0 -55
- package/src/crypto/public_key/dsa.js +0 -188
- package/src/crypto/public_key/elgamal.js +0 -137
- package/src/crypto/public_key/elliptic/curves.js +0 -385
- package/src/crypto/public_key/elliptic/ecdh.js +0 -414
- package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
- package/src/crypto/public_key/elliptic/eddsa.js +0 -119
- package/src/crypto/public_key/elliptic/index.js +0 -34
- package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
- package/src/crypto/public_key/index.js +0 -28
- package/src/crypto/public_key/prime.js +0 -275
- package/src/crypto/public_key/rsa.js +0 -597
- package/src/crypto/random.js +0 -145
- package/src/crypto/signature.js +0 -137
- package/src/encoding/armor.js +0 -433
- package/src/encoding/base64.js +0 -96
- package/src/enums.js +0 -493
- package/src/hkp.js +0 -89
- package/src/index.js +0 -161
- package/src/key/factory.js +0 -326
- package/src/key/helper.js +0 -378
- package/src/key/index.js +0 -32
- package/src/key/key.js +0 -888
- package/src/key/subkey.js +0 -187
- package/src/key/user.js +0 -230
- package/src/keyring/index.js +0 -12
- package/src/keyring/keyring.js +0 -229
- package/src/keyring/localstore.js +0 -119
- package/src/lightweight_helper.js +0 -26
- package/src/message.js +0 -825
- package/src/openpgp.js +0 -717
- package/src/packet/all_packets.js +0 -116
- package/src/packet/clone.js +0 -189
- package/src/packet/compressed.js +0 -194
- package/src/packet/index.js +0 -20
- package/src/packet/literal.js +0 -168
- package/src/packet/marker.js +0 -62
- package/src/packet/one_pass_signature.js +0 -156
- package/src/packet/packet.js +0 -300
- package/src/packet/packetlist.js +0 -232
- package/src/packet/public_key.js +0 -280
- package/src/packet/public_key_encrypted_session_key.js +0 -161
- package/src/packet/public_subkey.js +0 -44
- package/src/packet/secret_key.js +0 -468
- package/src/packet/secret_subkey.js +0 -41
- package/src/packet/signature.js +0 -786
- package/src/packet/sym_encrypted_aead_protected.js +0 -189
- package/src/packet/sym_encrypted_integrity_protected.js +0 -139
- package/src/packet/sym_encrypted_session_key.js +0 -204
- package/src/packet/symmetrically_encrypted.js +0 -118
- package/src/packet/trust.js +0 -35
- package/src/packet/user_attribute.js +0 -94
- package/src/packet/userid.js +0 -87
- package/src/polyfills.js +0 -64
- package/src/signature.js +0 -73
- package/src/type/ecdh_symkey.js +0 -69
- package/src/type/kdf_params.js +0 -114
- package/src/type/keyid.js +0 -110
- package/src/type/mpi.js +0 -138
- package/src/type/oid.js +0 -110
- package/src/type/s2k.js +0 -203
- package/src/util.js +0 -836
- package/src/wkd.js +0 -84
- package/src/worker/async_proxy.js +0 -190
- package/src/worker/worker.js +0 -167
- package/test/crypto/aes_kw.js +0 -57
- package/test/crypto/cipher/aes.js +0 -86
- package/test/crypto/cipher/blowfish.js +0 -58
- package/test/crypto/cipher/cast5.js +0 -25
- package/test/crypto/cipher/des.js +0 -143
- package/test/crypto/cipher/index.js +0 -7
- package/test/crypto/cipher/twofish.js +0 -71
- package/test/crypto/crypto.js +0 -383
- package/test/crypto/eax.js +0 -150
- package/test/crypto/ecdh.js +0 -359
- package/test/crypto/elliptic.js +0 -251
- package/test/crypto/elliptic_data.js +0 -102
- package/test/crypto/hash/index.js +0 -5
- package/test/crypto/hash/md5.js +0 -16
- package/test/crypto/hash/ripemd.js +0 -14
- package/test/crypto/hash/sha.js +0 -20
- package/test/crypto/index.js +0 -14
- package/test/crypto/ocb.js +0 -183
- package/test/crypto/pkcs5.js +0 -39
- package/test/crypto/random.js +0 -79
- package/test/crypto/rsa.js +0 -180
- package/test/crypto/validate.js +0 -387
- package/test/general/armor.js +0 -408
- package/test/general/brainpool.js +0 -360
- package/test/general/decompression.js +0 -60
- package/test/general/ecc_nist.js +0 -115
- package/test/general/ecc_secp256k1.js +0 -242
- package/test/general/forwarding.js +0 -43
- package/test/general/hkp.js +0 -165
- package/test/general/index.js +0 -20
- package/test/general/key.js +0 -3491
- package/test/general/keyring.js +0 -336
- package/test/general/oid.js +0 -39
- package/test/general/openpgp.js +0 -2577
- package/test/general/packet.js +0 -950
- package/test/general/signature.js +0 -1715
- package/test/general/streaming.js +0 -944
- package/test/general/testInputs.js +0 -18
- package/test/general/util.js +0 -183
- package/test/general/wkd.js +0 -48
- package/test/general/x25519.js +0 -556
- package/test/unittests.js +0 -64
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-mixed-operators, no-fallthrough */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/* Modified by Recurity Labs GmbH
|
|
5
|
-
*
|
|
6
|
-
* Cipher.js
|
|
7
|
-
* A block-cipher algorithm implementation on JavaScript
|
|
8
|
-
* See Cipher.readme.txt for further information.
|
|
9
|
-
*
|
|
10
|
-
* Copyright(c) 2009 Atsushi Oka [ http://oka.nu/ ]
|
|
11
|
-
* This script file is distributed under the LGPL
|
|
12
|
-
*
|
|
13
|
-
* ACKNOWLEDGMENT
|
|
14
|
-
*
|
|
15
|
-
* The main subroutines are written by Michiel van Everdingen.
|
|
16
|
-
*
|
|
17
|
-
* Michiel van Everdingen
|
|
18
|
-
* http://home.versatel.nl/MAvanEverdingen/index.html
|
|
19
|
-
*
|
|
20
|
-
* All rights for these routines are reserved to Michiel van Everdingen.
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
25
|
-
//Math
|
|
26
|
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
27
|
-
|
|
28
|
-
const MAXINT = 0xFFFFFFFF;
|
|
29
|
-
|
|
30
|
-
function rotw(w, n) {
|
|
31
|
-
return (w << n | w >>> (32 - n)) & MAXINT;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getW(a, i) {
|
|
35
|
-
return a[i] | a[i + 1] << 8 | a[i + 2] << 16 | a[i + 3] << 24;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function setW(a, i, w) {
|
|
39
|
-
a.splice(i, 4, w & 0xFF, (w >>> 8) & 0xFF, (w >>> 16) & 0xFF, (w >>> 24) & 0xFF);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function getB(x, n) {
|
|
43
|
-
return (x >>> (n * 8)) & 0xFF;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
47
|
-
// Twofish
|
|
48
|
-
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
49
|
-
|
|
50
|
-
function createTwofish() {
|
|
51
|
-
//
|
|
52
|
-
let keyBytes = null;
|
|
53
|
-
let dataBytes = null;
|
|
54
|
-
let dataOffset = -1;
|
|
55
|
-
// var dataLength = -1;
|
|
56
|
-
// var idx2 = -1;
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
let tfsKey = [];
|
|
60
|
-
let tfsM = [
|
|
61
|
-
[],
|
|
62
|
-
[],
|
|
63
|
-
[],
|
|
64
|
-
[]
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
function tfsInit(key) {
|
|
68
|
-
keyBytes = key;
|
|
69
|
-
let i;
|
|
70
|
-
let a;
|
|
71
|
-
let b;
|
|
72
|
-
let c;
|
|
73
|
-
let d;
|
|
74
|
-
const meKey = [];
|
|
75
|
-
const moKey = [];
|
|
76
|
-
const inKey = [];
|
|
77
|
-
let kLen;
|
|
78
|
-
const sKey = [];
|
|
79
|
-
let f01;
|
|
80
|
-
let f5b;
|
|
81
|
-
let fef;
|
|
82
|
-
|
|
83
|
-
const q0 = [
|
|
84
|
-
[8, 1, 7, 13, 6, 15, 3, 2, 0, 11, 5, 9, 14, 12, 10, 4],
|
|
85
|
-
[2, 8, 11, 13, 15, 7, 6, 14, 3, 1, 9, 4, 0, 10, 12, 5]
|
|
86
|
-
];
|
|
87
|
-
const q1 = [
|
|
88
|
-
[14, 12, 11, 8, 1, 2, 3, 5, 15, 4, 10, 6, 7, 0, 9, 13],
|
|
89
|
-
[1, 14, 2, 11, 4, 12, 3, 7, 6, 13, 10, 5, 15, 9, 0, 8]
|
|
90
|
-
];
|
|
91
|
-
const q2 = [
|
|
92
|
-
[11, 10, 5, 14, 6, 13, 9, 0, 12, 8, 15, 3, 2, 4, 7, 1],
|
|
93
|
-
[4, 12, 7, 5, 1, 6, 9, 10, 0, 14, 13, 8, 2, 11, 3, 15]
|
|
94
|
-
];
|
|
95
|
-
const q3 = [
|
|
96
|
-
[13, 7, 15, 4, 1, 2, 6, 14, 9, 11, 3, 0, 8, 5, 12, 10],
|
|
97
|
-
[11, 9, 5, 1, 12, 3, 13, 14, 6, 4, 7, 15, 2, 0, 8, 10]
|
|
98
|
-
];
|
|
99
|
-
const ror4 = [0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15];
|
|
100
|
-
const ashx = [0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 5, 14, 7];
|
|
101
|
-
const q = [
|
|
102
|
-
[],
|
|
103
|
-
[]
|
|
104
|
-
];
|
|
105
|
-
const m = [
|
|
106
|
-
[],
|
|
107
|
-
[],
|
|
108
|
-
[],
|
|
109
|
-
[]
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
function ffm5b(x) {
|
|
113
|
-
return x ^ (x >> 2) ^ [0, 90, 180, 238][x & 3];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function ffmEf(x) {
|
|
117
|
-
return x ^ (x >> 1) ^ (x >> 2) ^ [0, 238, 180, 90][x & 3];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function mdsRem(p, q) {
|
|
121
|
-
let i;
|
|
122
|
-
let t;
|
|
123
|
-
let u;
|
|
124
|
-
for (i = 0; i < 8; i++) {
|
|
125
|
-
t = q >>> 24;
|
|
126
|
-
q = ((q << 8) & MAXINT) | p >>> 24;
|
|
127
|
-
p = (p << 8) & MAXINT;
|
|
128
|
-
u = t << 1;
|
|
129
|
-
if (t & 128) {
|
|
130
|
-
u ^= 333;
|
|
131
|
-
}
|
|
132
|
-
q ^= t ^ (u << 16);
|
|
133
|
-
u ^= t >>> 1;
|
|
134
|
-
if (t & 1) {
|
|
135
|
-
u ^= 166;
|
|
136
|
-
}
|
|
137
|
-
q ^= u << 24 | u << 8;
|
|
138
|
-
}
|
|
139
|
-
return q;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function qp(n, x) {
|
|
143
|
-
const a = x >> 4;
|
|
144
|
-
const b = x & 15;
|
|
145
|
-
const c = q0[n][a ^ b];
|
|
146
|
-
const d = q1[n][ror4[b] ^ ashx[a]];
|
|
147
|
-
return q3[n][ror4[d] ^ ashx[c]] << 4 | q2[n][c ^ d];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function hFun(x, key) {
|
|
151
|
-
let a = getB(x, 0);
|
|
152
|
-
let b = getB(x, 1);
|
|
153
|
-
let c = getB(x, 2);
|
|
154
|
-
let d = getB(x, 3);
|
|
155
|
-
switch (kLen) {
|
|
156
|
-
case 4:
|
|
157
|
-
a = q[1][a] ^ getB(key[3], 0);
|
|
158
|
-
b = q[0][b] ^ getB(key[3], 1);
|
|
159
|
-
c = q[0][c] ^ getB(key[3], 2);
|
|
160
|
-
d = q[1][d] ^ getB(key[3], 3);
|
|
161
|
-
case 3:
|
|
162
|
-
a = q[1][a] ^ getB(key[2], 0);
|
|
163
|
-
b = q[1][b] ^ getB(key[2], 1);
|
|
164
|
-
c = q[0][c] ^ getB(key[2], 2);
|
|
165
|
-
d = q[0][d] ^ getB(key[2], 3);
|
|
166
|
-
case 2:
|
|
167
|
-
a = q[0][q[0][a] ^ getB(key[1], 0)] ^ getB(key[0], 0);
|
|
168
|
-
b = q[0][q[1][b] ^ getB(key[1], 1)] ^ getB(key[0], 1);
|
|
169
|
-
c = q[1][q[0][c] ^ getB(key[1], 2)] ^ getB(key[0], 2);
|
|
170
|
-
d = q[1][q[1][d] ^ getB(key[1], 3)] ^ getB(key[0], 3);
|
|
171
|
-
}
|
|
172
|
-
return m[0][a] ^ m[1][b] ^ m[2][c] ^ m[3][d];
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
keyBytes = keyBytes.slice(0, 32);
|
|
176
|
-
i = keyBytes.length;
|
|
177
|
-
while (i !== 16 && i !== 24 && i !== 32) {
|
|
178
|
-
keyBytes[i++] = 0;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
for (i = 0; i < keyBytes.length; i += 4) {
|
|
182
|
-
inKey[i >> 2] = getW(keyBytes, i);
|
|
183
|
-
}
|
|
184
|
-
for (i = 0; i < 256; i++) {
|
|
185
|
-
q[0][i] = qp(0, i);
|
|
186
|
-
q[1][i] = qp(1, i);
|
|
187
|
-
}
|
|
188
|
-
for (i = 0; i < 256; i++) {
|
|
189
|
-
f01 = q[1][i];
|
|
190
|
-
f5b = ffm5b(f01);
|
|
191
|
-
fef = ffmEf(f01);
|
|
192
|
-
m[0][i] = f01 + (f5b << 8) + (fef << 16) + (fef << 24);
|
|
193
|
-
m[2][i] = f5b + (fef << 8) + (f01 << 16) + (fef << 24);
|
|
194
|
-
f01 = q[0][i];
|
|
195
|
-
f5b = ffm5b(f01);
|
|
196
|
-
fef = ffmEf(f01);
|
|
197
|
-
m[1][i] = fef + (fef << 8) + (f5b << 16) + (f01 << 24);
|
|
198
|
-
m[3][i] = f5b + (f01 << 8) + (fef << 16) + (f5b << 24);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
kLen = inKey.length / 2;
|
|
202
|
-
for (i = 0; i < kLen; i++) {
|
|
203
|
-
a = inKey[i + i];
|
|
204
|
-
meKey[i] = a;
|
|
205
|
-
b = inKey[i + i + 1];
|
|
206
|
-
moKey[i] = b;
|
|
207
|
-
sKey[kLen - i - 1] = mdsRem(a, b);
|
|
208
|
-
}
|
|
209
|
-
for (i = 0; i < 40; i += 2) {
|
|
210
|
-
a = 0x1010101 * i;
|
|
211
|
-
b = a + 0x1010101;
|
|
212
|
-
a = hFun(a, meKey);
|
|
213
|
-
b = rotw(hFun(b, moKey), 8);
|
|
214
|
-
tfsKey[i] = (a + b) & MAXINT;
|
|
215
|
-
tfsKey[i + 1] = rotw(a + 2 * b, 9);
|
|
216
|
-
}
|
|
217
|
-
for (i = 0; i < 256; i++) {
|
|
218
|
-
a = b = c = d = i;
|
|
219
|
-
switch (kLen) {
|
|
220
|
-
case 4:
|
|
221
|
-
a = q[1][a] ^ getB(sKey[3], 0);
|
|
222
|
-
b = q[0][b] ^ getB(sKey[3], 1);
|
|
223
|
-
c = q[0][c] ^ getB(sKey[3], 2);
|
|
224
|
-
d = q[1][d] ^ getB(sKey[3], 3);
|
|
225
|
-
case 3:
|
|
226
|
-
a = q[1][a] ^ getB(sKey[2], 0);
|
|
227
|
-
b = q[1][b] ^ getB(sKey[2], 1);
|
|
228
|
-
c = q[0][c] ^ getB(sKey[2], 2);
|
|
229
|
-
d = q[0][d] ^ getB(sKey[2], 3);
|
|
230
|
-
case 2:
|
|
231
|
-
tfsM[0][i] = m[0][q[0][q[0][a] ^ getB(sKey[1], 0)] ^ getB(sKey[0], 0)];
|
|
232
|
-
tfsM[1][i] = m[1][q[0][q[1][b] ^ getB(sKey[1], 1)] ^ getB(sKey[0], 1)];
|
|
233
|
-
tfsM[2][i] = m[2][q[1][q[0][c] ^ getB(sKey[1], 2)] ^ getB(sKey[0], 2)];
|
|
234
|
-
tfsM[3][i] = m[3][q[1][q[1][d] ^ getB(sKey[1], 3)] ^ getB(sKey[0], 3)];
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function tfsG0(x) {
|
|
240
|
-
return tfsM[0][getB(x, 0)] ^ tfsM[1][getB(x, 1)] ^ tfsM[2][getB(x, 2)] ^ tfsM[3][getB(x, 3)];
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function tfsG1(x) {
|
|
244
|
-
return tfsM[0][getB(x, 3)] ^ tfsM[1][getB(x, 0)] ^ tfsM[2][getB(x, 1)] ^ tfsM[3][getB(x, 2)];
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function tfsFrnd(r, blk) {
|
|
248
|
-
let a = tfsG0(blk[0]);
|
|
249
|
-
let b = tfsG1(blk[1]);
|
|
250
|
-
blk[2] = rotw(blk[2] ^ (a + b + tfsKey[4 * r + 8]) & MAXINT, 31);
|
|
251
|
-
blk[3] = rotw(blk[3], 1) ^ (a + 2 * b + tfsKey[4 * r + 9]) & MAXINT;
|
|
252
|
-
a = tfsG0(blk[2]);
|
|
253
|
-
b = tfsG1(blk[3]);
|
|
254
|
-
blk[0] = rotw(blk[0] ^ (a + b + tfsKey[4 * r + 10]) & MAXINT, 31);
|
|
255
|
-
blk[1] = rotw(blk[1], 1) ^ (a + 2 * b + tfsKey[4 * r + 11]) & MAXINT;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function tfsIrnd(i, blk) {
|
|
259
|
-
let a = tfsG0(blk[0]);
|
|
260
|
-
let b = tfsG1(blk[1]);
|
|
261
|
-
blk[2] = rotw(blk[2], 1) ^ (a + b + tfsKey[4 * i + 10]) & MAXINT;
|
|
262
|
-
blk[3] = rotw(blk[3] ^ (a + 2 * b + tfsKey[4 * i + 11]) & MAXINT, 31);
|
|
263
|
-
a = tfsG0(blk[2]);
|
|
264
|
-
b = tfsG1(blk[3]);
|
|
265
|
-
blk[0] = rotw(blk[0], 1) ^ (a + b + tfsKey[4 * i + 8]) & MAXINT;
|
|
266
|
-
blk[1] = rotw(blk[1] ^ (a + 2 * b + tfsKey[4 * i + 9]) & MAXINT, 31);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function tfsClose() {
|
|
270
|
-
tfsKey = [];
|
|
271
|
-
tfsM = [
|
|
272
|
-
[],
|
|
273
|
-
[],
|
|
274
|
-
[],
|
|
275
|
-
[]
|
|
276
|
-
];
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function tfsEncrypt(data, offset) {
|
|
280
|
-
dataBytes = data;
|
|
281
|
-
dataOffset = offset;
|
|
282
|
-
const blk = [getW(dataBytes, dataOffset) ^ tfsKey[0],
|
|
283
|
-
getW(dataBytes, dataOffset + 4) ^ tfsKey[1],
|
|
284
|
-
getW(dataBytes, dataOffset + 8) ^ tfsKey[2],
|
|
285
|
-
getW(dataBytes, dataOffset + 12) ^ tfsKey[3]];
|
|
286
|
-
for (let j = 0; j < 8; j++) {
|
|
287
|
-
tfsFrnd(j, blk);
|
|
288
|
-
}
|
|
289
|
-
setW(dataBytes, dataOffset, blk[2] ^ tfsKey[4]);
|
|
290
|
-
setW(dataBytes, dataOffset + 4, blk[3] ^ tfsKey[5]);
|
|
291
|
-
setW(dataBytes, dataOffset + 8, blk[0] ^ tfsKey[6]);
|
|
292
|
-
setW(dataBytes, dataOffset + 12, blk[1] ^ tfsKey[7]);
|
|
293
|
-
dataOffset += 16;
|
|
294
|
-
return dataBytes;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function tfsDecrypt(data, offset) {
|
|
298
|
-
dataBytes = data;
|
|
299
|
-
dataOffset = offset;
|
|
300
|
-
const blk = [getW(dataBytes, dataOffset) ^ tfsKey[4],
|
|
301
|
-
getW(dataBytes, dataOffset + 4) ^ tfsKey[5],
|
|
302
|
-
getW(dataBytes, dataOffset + 8) ^ tfsKey[6],
|
|
303
|
-
getW(dataBytes, dataOffset + 12) ^ tfsKey[7]];
|
|
304
|
-
for (let j = 7; j >= 0; j--) {
|
|
305
|
-
tfsIrnd(j, blk);
|
|
306
|
-
}
|
|
307
|
-
setW(dataBytes, dataOffset, blk[2] ^ tfsKey[0]);
|
|
308
|
-
setW(dataBytes, dataOffset + 4, blk[3] ^ tfsKey[1]);
|
|
309
|
-
setW(dataBytes, dataOffset + 8, blk[0] ^ tfsKey[2]);
|
|
310
|
-
setW(dataBytes, dataOffset + 12, blk[1] ^ tfsKey[3]);
|
|
311
|
-
dataOffset += 16;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// added by Recurity Labs
|
|
315
|
-
|
|
316
|
-
function tfsFinal() {
|
|
317
|
-
return dataBytes;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
name: "twofish",
|
|
322
|
-
blocksize: 128 / 8,
|
|
323
|
-
open: tfsInit,
|
|
324
|
-
close: tfsClose,
|
|
325
|
-
encrypt: tfsEncrypt,
|
|
326
|
-
decrypt: tfsDecrypt,
|
|
327
|
-
// added by Recurity Labs
|
|
328
|
-
finalize: tfsFinal
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// added by Recurity Labs
|
|
333
|
-
|
|
334
|
-
function TF(key) {
|
|
335
|
-
this.tf = createTwofish();
|
|
336
|
-
this.tf.open(Array.from(key), 0);
|
|
337
|
-
|
|
338
|
-
this.encrypt = function(block) {
|
|
339
|
-
return this.tf.encrypt(Array.from(block), 0);
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
TF.keySize = TF.prototype.keySize = 32;
|
|
344
|
-
TF.blockSize = TF.prototype.blockSize = 16;
|
|
345
|
-
|
|
346
|
-
export default TF;
|
package/src/crypto/cmac.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview This module implements AES-CMAC on top of
|
|
3
|
-
* native AES-CBC using either the WebCrypto API or Node.js' crypto API.
|
|
4
|
-
* @requires asmcrypto.js
|
|
5
|
-
* @requires util
|
|
6
|
-
* @module crypto/cmac
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { AES_CBC } from 'asmcrypto.js/dist_es5/aes/cbc';
|
|
10
|
-
import util from '../util';
|
|
11
|
-
|
|
12
|
-
const webCrypto = util.getWebCrypto();
|
|
13
|
-
const nodeCrypto = util.getNodeCrypto();
|
|
14
|
-
const Buffer = util.getNodeBuffer();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* This implementation of CMAC is based on the description of OMAC in
|
|
19
|
-
* http://web.cs.ucdavis.edu/~rogaway/papers/eax.pdf. As per that
|
|
20
|
-
* document:
|
|
21
|
-
*
|
|
22
|
-
* We have made a small modification to the OMAC algorithm as it was
|
|
23
|
-
* originally presented, changing one of its two constants.
|
|
24
|
-
* Specifically, the constant 4 at line 85 was the constant 1/2 (the
|
|
25
|
-
* multiplicative inverse of 2) in the original definition of OMAC [14].
|
|
26
|
-
* The OMAC authors indicate that they will promulgate this modification
|
|
27
|
-
* [15], which slightly simplifies implementations.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
const blockLength = 16;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* xor `padding` into the end of `data`. This function implements "the
|
|
35
|
-
* operation xor→ [which] xors the shorter string into the end of longer
|
|
36
|
-
* one". Since data is always as least as long as padding, we can
|
|
37
|
-
* simplify the implementation.
|
|
38
|
-
* @param {Uint8Array} data
|
|
39
|
-
* @param {Uint8Array} padding
|
|
40
|
-
*/
|
|
41
|
-
function rightXorMut(data, padding) {
|
|
42
|
-
const offset = data.length - blockLength;
|
|
43
|
-
for (let i = 0; i < blockLength; i++) {
|
|
44
|
-
data[i + offset] ^= padding[i];
|
|
45
|
-
}
|
|
46
|
-
return data;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function pad(data, padding, padding2) {
|
|
50
|
-
// if |M| in {n, 2n, 3n, ...}
|
|
51
|
-
if (data.length && data.length % blockLength === 0) {
|
|
52
|
-
// then return M xor→ B,
|
|
53
|
-
return rightXorMut(data, padding);
|
|
54
|
-
}
|
|
55
|
-
// else return (M || 10^(n−1−(|M| mod n))) xor→ P
|
|
56
|
-
const padded = new Uint8Array(data.length + (blockLength - data.length % blockLength));
|
|
57
|
-
padded.set(data);
|
|
58
|
-
padded[data.length] = 0b10000000;
|
|
59
|
-
return rightXorMut(padded, padding2);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const zeroBlock = new Uint8Array(blockLength);
|
|
63
|
-
|
|
64
|
-
export default async function CMAC(key) {
|
|
65
|
-
const cbc = await CBC(key);
|
|
66
|
-
|
|
67
|
-
// L ← E_K(0^n); B ← 2L; P ← 4L
|
|
68
|
-
const padding = util.double(await cbc(zeroBlock));
|
|
69
|
-
const padding2 = util.double(padding);
|
|
70
|
-
|
|
71
|
-
return async function(data) {
|
|
72
|
-
// return CBC_K(pad(M; B, P))
|
|
73
|
-
return (await cbc(pad(data, padding, padding2))).subarray(-blockLength);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function CBC(key) {
|
|
78
|
-
if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
|
79
|
-
key = await webCrypto.importKey('raw', key, { name: 'AES-CBC', length: key.length * 8 }, false, ['encrypt']);
|
|
80
|
-
return async function(pt) {
|
|
81
|
-
const ct = await webCrypto.encrypt({ name: 'AES-CBC', iv: zeroBlock, length: blockLength * 8 }, key, pt);
|
|
82
|
-
return new Uint8Array(ct).subarray(0, ct.byteLength - blockLength);
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
if (util.getNodeCrypto()) { // Node crypto library
|
|
86
|
-
key = Buffer.from(key);
|
|
87
|
-
return async function(pt) {
|
|
88
|
-
pt = Buffer.from(pt);
|
|
89
|
-
const en = new nodeCrypto.createCipheriv('aes-' + (key.length * 8) + '-cbc', key, zeroBlock);
|
|
90
|
-
const ct = en.update(pt);
|
|
91
|
-
return new Uint8Array(ct);
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
// asm.js fallback
|
|
95
|
-
return async function(pt) {
|
|
96
|
-
return AES_CBC.encrypt(pt, key, false, zeroBlock);
|
|
97
|
-
};
|
|
98
|
-
}
|