@protontech/openpgp 4.10.5 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +311 -239
  2. package/dist/lightweight/bn.interface.min.mjs +3 -0
  3. package/dist/lightweight/bn.interface.min.mjs.map +1 -0
  4. package/dist/lightweight/bn.interface.mjs +340 -0
  5. package/dist/lightweight/bn.min.mjs +3 -0
  6. package/dist/lightweight/bn.min.mjs.map +1 -0
  7. package/dist/lightweight/bn.mjs +3434 -0
  8. package/dist/lightweight/elliptic.min.mjs +3 -0
  9. package/dist/lightweight/elliptic.min.mjs.map +1 -0
  10. package/dist/lightweight/elliptic.mjs +4313 -0
  11. package/dist/lightweight/openpgp.min.mjs +3 -0
  12. package/dist/lightweight/openpgp.min.mjs.map +1 -0
  13. package/dist/lightweight/openpgp.mjs +31375 -0
  14. package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
  15. package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
  16. package/dist/lightweight/ponyfill.es6.mjs +3831 -0
  17. package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
  18. package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
  19. package/dist/lightweight/web-streams-adapter.mjs +561 -0
  20. package/dist/node/openpgp.js +43943 -0
  21. package/dist/node/openpgp.min.js +17 -0
  22. package/dist/node/openpgp.min.js.map +1 -0
  23. package/dist/node/openpgp.min.mjs +17 -0
  24. package/dist/node/openpgp.min.mjs.map +1 -0
  25. package/dist/node/openpgp.mjs +43880 -0
  26. package/dist/openpgp.js +41080 -41565
  27. package/dist/openpgp.min.js +17 -2
  28. package/dist/openpgp.min.js.map +1 -0
  29. package/dist/openpgp.min.mjs +17 -0
  30. package/dist/openpgp.min.mjs.map +1 -0
  31. package/dist/openpgp.mjs +43868 -0
  32. package/lightweight/package.json +5 -0
  33. package/openpgp.d.ts +889 -0
  34. package/package.json +63 -57
  35. package/dist/compat/openpgp.js +0 -61067
  36. package/dist/compat/openpgp.min.js +0 -2
  37. package/dist/compat/openpgp.worker.js +0 -173
  38. package/dist/compat/openpgp.worker.min.js +0 -2
  39. package/dist/lightweight/elliptic.min.js +0 -5
  40. package/dist/lightweight/openpgp.js +0 -40024
  41. package/dist/lightweight/openpgp.min.js +0 -2
  42. package/dist/lightweight/openpgp.worker.js +0 -173
  43. package/dist/lightweight/openpgp.worker.min.js +0 -2
  44. package/dist/openpgp.worker.js +0 -173
  45. package/dist/openpgp.worker.min.js +0 -2
  46. package/src/cleartext.js +0 -220
  47. package/src/config/config.js +0 -224
  48. package/src/config/index.js +0 -7
  49. package/src/config/localStorage.js +0 -35
  50. package/src/crypto/aes_kw.js +0 -153
  51. package/src/crypto/cfb.js +0 -169
  52. package/src/crypto/cipher/aes.js +0 -27
  53. package/src/crypto/cipher/blowfish.js +0 -398
  54. package/src/crypto/cipher/cast5.js +0 -610
  55. package/src/crypto/cipher/des.js +0 -476
  56. package/src/crypto/cipher/index.js +0 -91
  57. package/src/crypto/cipher/twofish.js +0 -346
  58. package/src/crypto/cmac.js +0 -98
  59. package/src/crypto/crypto.js +0 -394
  60. package/src/crypto/eax.js +0 -172
  61. package/src/crypto/gcm.js +0 -141
  62. package/src/crypto/hash/index.js +0 -163
  63. package/src/crypto/hash/md5.js +0 -205
  64. package/src/crypto/index.js +0 -57
  65. package/src/crypto/ocb.js +0 -274
  66. package/src/crypto/pkcs1.js +0 -170
  67. package/src/crypto/pkcs5.js +0 -55
  68. package/src/crypto/public_key/dsa.js +0 -188
  69. package/src/crypto/public_key/elgamal.js +0 -137
  70. package/src/crypto/public_key/elliptic/curves.js +0 -385
  71. package/src/crypto/public_key/elliptic/ecdh.js +0 -414
  72. package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
  73. package/src/crypto/public_key/elliptic/eddsa.js +0 -119
  74. package/src/crypto/public_key/elliptic/index.js +0 -34
  75. package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
  76. package/src/crypto/public_key/index.js +0 -28
  77. package/src/crypto/public_key/prime.js +0 -275
  78. package/src/crypto/public_key/rsa.js +0 -597
  79. package/src/crypto/random.js +0 -145
  80. package/src/crypto/signature.js +0 -137
  81. package/src/encoding/armor.js +0 -433
  82. package/src/encoding/base64.js +0 -96
  83. package/src/enums.js +0 -493
  84. package/src/hkp.js +0 -89
  85. package/src/index.js +0 -161
  86. package/src/key/factory.js +0 -326
  87. package/src/key/helper.js +0 -363
  88. package/src/key/index.js +0 -32
  89. package/src/key/key.js +0 -890
  90. package/src/key/subkey.js +0 -187
  91. package/src/key/user.js +0 -230
  92. package/src/keyring/index.js +0 -12
  93. package/src/keyring/keyring.js +0 -229
  94. package/src/keyring/localstore.js +0 -119
  95. package/src/lightweight_helper.js +0 -26
  96. package/src/message.js +0 -825
  97. package/src/openpgp.js +0 -717
  98. package/src/packet/all_packets.js +0 -116
  99. package/src/packet/clone.js +0 -189
  100. package/src/packet/compressed.js +0 -194
  101. package/src/packet/index.js +0 -20
  102. package/src/packet/literal.js +0 -168
  103. package/src/packet/marker.js +0 -62
  104. package/src/packet/one_pass_signature.js +0 -156
  105. package/src/packet/packet.js +0 -300
  106. package/src/packet/packetlist.js +0 -232
  107. package/src/packet/public_key.js +0 -280
  108. package/src/packet/public_key_encrypted_session_key.js +0 -156
  109. package/src/packet/public_subkey.js +0 -44
  110. package/src/packet/secret_key.js +0 -448
  111. package/src/packet/secret_subkey.js +0 -41
  112. package/src/packet/signature.js +0 -782
  113. package/src/packet/sym_encrypted_aead_protected.js +0 -189
  114. package/src/packet/sym_encrypted_integrity_protected.js +0 -139
  115. package/src/packet/sym_encrypted_session_key.js +0 -204
  116. package/src/packet/symmetrically_encrypted.js +0 -118
  117. package/src/packet/trust.js +0 -35
  118. package/src/packet/user_attribute.js +0 -94
  119. package/src/packet/userid.js +0 -87
  120. package/src/polyfills.js +0 -64
  121. package/src/signature.js +0 -73
  122. package/src/type/ecdh_symkey.js +0 -69
  123. package/src/type/kdf_params.js +0 -114
  124. package/src/type/keyid.js +0 -110
  125. package/src/type/mpi.js +0 -138
  126. package/src/type/oid.js +0 -110
  127. package/src/type/s2k.js +0 -203
  128. package/src/util.js +0 -836
  129. package/src/wkd.js +0 -88
  130. package/src/worker/async_proxy.js +0 -190
  131. package/src/worker/worker.js +0 -167
  132. package/test/crypto/aes_kw.js +0 -57
  133. package/test/crypto/cipher/aes.js +0 -86
  134. package/test/crypto/cipher/blowfish.js +0 -58
  135. package/test/crypto/cipher/cast5.js +0 -25
  136. package/test/crypto/cipher/des.js +0 -143
  137. package/test/crypto/cipher/index.js +0 -7
  138. package/test/crypto/cipher/twofish.js +0 -71
  139. package/test/crypto/crypto.js +0 -383
  140. package/test/crypto/eax.js +0 -150
  141. package/test/crypto/ecdh.js +0 -359
  142. package/test/crypto/elliptic.js +0 -251
  143. package/test/crypto/elliptic_data.js +0 -102
  144. package/test/crypto/hash/index.js +0 -5
  145. package/test/crypto/hash/md5.js +0 -16
  146. package/test/crypto/hash/ripemd.js +0 -14
  147. package/test/crypto/hash/sha.js +0 -20
  148. package/test/crypto/index.js +0 -14
  149. package/test/crypto/ocb.js +0 -183
  150. package/test/crypto/pkcs5.js +0 -39
  151. package/test/crypto/random.js +0 -79
  152. package/test/crypto/rsa.js +0 -180
  153. package/test/crypto/validate.js +0 -387
  154. package/test/general/armor.js +0 -408
  155. package/test/general/brainpool.js +0 -360
  156. package/test/general/decompression.js +0 -60
  157. package/test/general/ecc_nist.js +0 -115
  158. package/test/general/ecc_secp256k1.js +0 -242
  159. package/test/general/forwarding.js +0 -43
  160. package/test/general/hkp.js +0 -165
  161. package/test/general/index.js +0 -20
  162. package/test/general/key.js +0 -3402
  163. package/test/general/keyring.js +0 -336
  164. package/test/general/oid.js +0 -39
  165. package/test/general/openpgp.js +0 -2542
  166. package/test/general/packet.js +0 -937
  167. package/test/general/signature.js +0 -1665
  168. package/test/general/streaming.js +0 -944
  169. package/test/general/testInputs.js +0 -18
  170. package/test/general/util.js +0 -183
  171. package/test/general/wkd.js +0 -48
  172. package/test/general/x25519.js +0 -556
  173. package/test/unittests.js +0 -64
@@ -1,476 +0,0 @@
1
- //Paul Tero, July 2001
2
- //http://www.tero.co.uk/des/
3
- //
4
- //Optimised for performance with large blocks by Michael Hayworth, November 2001
5
- //http://www.netdealing.com
6
- //
7
- // Modified by Recurity Labs GmbH
8
-
9
- //THIS SOFTWARE IS PROVIDED "AS IS" AND
10
- //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
11
- //IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
12
- //ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
13
- //FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
14
- //DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
15
- //OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
16
- //HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
17
- //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
18
- //OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
19
- //SUCH DAMAGE.
20
-
21
- //des
22
- //this takes the key, the message, and whether to encrypt or decrypt
23
-
24
- function des(keys, message, encrypt, mode, iv, padding) {
25
- //declaring this locally speeds things up a bit
26
- const spfunction1 = [
27
- 0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404, 0x4, 0x10000, 0x400, 0x1010400,
28
- 0x1010404, 0x400, 0x1000404, 0x1010004, 0x1000000, 0x4, 0x404, 0x1000400, 0x1000400, 0x10400, 0x10400, 0x1010000,
29
- 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004, 0x10004, 0, 0x404, 0x10404, 0x1000000, 0x10000, 0x1010404, 0x4,
30
- 0x1010000, 0x1010400, 0x1000000, 0x1000000, 0x400, 0x1010004, 0x10000, 0x10400, 0x1000004, 0x400, 0x4, 0x1000404,
31
- 0x10404, 0x1010404, 0x10004, 0x1010000, 0x1000404, 0x1000004, 0x404, 0x10404, 0x1010400, 0x404, 0x1000400,
32
- 0x1000400, 0, 0x10004, 0x10400, 0, 0x1010004
33
- ];
34
- const spfunction2 = [
35
- -0x7fef7fe0, -0x7fff8000, 0x8000, 0x108020, 0x100000, 0x20, -0x7fefffe0, -0x7fff7fe0,
36
- -0x7fffffe0, -0x7fef7fe0, -0x7fef8000, -0x80000000, -0x7fff8000, 0x100000, 0x20, -0x7fefffe0, 0x108000, 0x100020,
37
- -0x7fff7fe0, 0, -0x80000000, 0x8000, 0x108020, -0x7ff00000, 0x100020, -0x7fffffe0, 0, 0x108000, 0x8020, -0x7fef8000,
38
- -0x7ff00000, 0x8020, 0, 0x108020, -0x7fefffe0, 0x100000, -0x7fff7fe0, -0x7ff00000, -0x7fef8000, 0x8000, -0x7ff00000,
39
- -0x7fff8000, 0x20, -0x7fef7fe0, 0x108020, 0x20, 0x8000, -0x80000000, 0x8020, -0x7fef8000, 0x100000, -0x7fffffe0,
40
- 0x100020, -0x7fff7fe0, -0x7fffffe0, 0x100020, 0x108000, 0, -0x7fff8000, 0x8020, -0x80000000, -0x7fefffe0,
41
- -0x7fef7fe0, 0x108000
42
- ];
43
- const spfunction3 = [
44
- 0x208, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200, 0x20008, 0x8000008,
45
- 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 0x208, 0x8000000, 0x8, 0x8020200, 0x200, 0x20200, 0x8020000,
46
- 0x8020008, 0x20208, 0x8000208, 0x20200, 0x20000, 0x8000208, 0x8, 0x8020208, 0x200, 0x8000000, 0x8020200, 0x8000000,
47
- 0x20008, 0x208, 0x20000, 0x8020200, 0x8000200, 0, 0x200, 0x20008, 0x8020208, 0x8000200, 0x8000008, 0x200, 0,
48
- 0x8020008, 0x8000208, 0x20000, 0x8000000, 0x8020208, 0x8, 0x20208, 0x20200, 0x8000008, 0x8020000, 0x8000208, 0x208,
49
- 0x8020000, 0x20208, 0x8, 0x8020008, 0x20200
50
- ];
51
- const spfunction4 = [
52
- 0x802001, 0x2081, 0x2081, 0x80, 0x802080, 0x800081, 0x800001, 0x2001, 0, 0x802000,
53
- 0x802000, 0x802081, 0x81, 0, 0x800080, 0x800001, 0x1, 0x2000, 0x800000, 0x802001, 0x80, 0x800000, 0x2001, 0x2080,
54
- 0x800081, 0x1, 0x2080, 0x800080, 0x2000, 0x802080, 0x802081, 0x81, 0x800080, 0x800001, 0x802000, 0x802081, 0x81, 0,
55
- 0, 0x802000, 0x2080, 0x800080, 0x800081, 0x1, 0x802001, 0x2081, 0x2081, 0x80, 0x802081, 0x81, 0x1, 0x2000, 0x800001,
56
- 0x2001, 0x802080, 0x800081, 0x2001, 0x2080, 0x800000, 0x802001, 0x80, 0x800000, 0x2000, 0x802080
57
- ];
58
- const spfunction5 = [
59
- 0x100, 0x2080100, 0x2080000, 0x42000100, 0x80000, 0x100, 0x40000000, 0x2080000,
60
- 0x40080100, 0x80000, 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100, 0x40000000, 0x2000000, 0x40080000,
61
- 0x40080000, 0, 0x40000100, 0x42080100, 0x42080100, 0x2000100, 0x42080000, 0x40000100, 0, 0x42000000, 0x2080100,
62
- 0x2000000, 0x42000000, 0x80100, 0x80000, 0x42000100, 0x100, 0x2000000, 0x40000000, 0x2080000, 0x42000100,
63
- 0x40080100, 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 0x100, 0x2000000, 0x42080000, 0x42080100,
64
- 0x80100, 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000, 0x42000000, 0x80100, 0x2000100, 0x40000100, 0x80000, 0,
65
- 0x40080000, 0x2080100, 0x40000100
66
- ];
67
- const spfunction6 = [
68
- 0x20000010, 0x20400000, 0x4000, 0x20404010, 0x20400000, 0x10, 0x20404010, 0x400000,
69
- 0x20004000, 0x404010, 0x400000, 0x20000010, 0x400010, 0x20004000, 0x20000000, 0x4010, 0, 0x400010, 0x20004010,
70
- 0x4000, 0x404000, 0x20004010, 0x10, 0x20400010, 0x20400010, 0, 0x404010, 0x20404000, 0x4010, 0x404000, 0x20404000,
71
- 0x20000000, 0x20004000, 0x10, 0x20400010, 0x404000, 0x20404010, 0x400000, 0x4010, 0x20000010, 0x400000, 0x20004000,
72
- 0x20000000, 0x4010, 0x20000010, 0x20404010, 0x404000, 0x20400000, 0x404010, 0x20404000, 0, 0x20400010, 0x10, 0x4000,
73
- 0x20400000, 0x404010, 0x4000, 0x400010, 0x20004010, 0, 0x20404000, 0x20000000, 0x400010, 0x20004010
74
- ];
75
- const spfunction7 = [
76
- 0x200000, 0x4200002, 0x4000802, 0, 0x800, 0x4000802, 0x200802, 0x4200800, 0x4200802,
77
- 0x200000, 0, 0x4000002, 0x2, 0x4000000, 0x4200002, 0x802, 0x4000800, 0x200802, 0x200002, 0x4000800, 0x4000002,
78
- 0x4200000, 0x4200800, 0x200002, 0x4200000, 0x800, 0x802, 0x4200802, 0x200800, 0x2, 0x4000000, 0x200800, 0x4000000,
79
- 0x200800, 0x200000, 0x4000802, 0x4000802, 0x4200002, 0x4200002, 0x2, 0x200002, 0x4000000, 0x4000800, 0x200000,
80
- 0x4200800, 0x802, 0x200802, 0x4200800, 0x802, 0x4000002, 0x4200802, 0x4200000, 0x200800, 0, 0x2, 0x4200802, 0,
81
- 0x200802, 0x4200000, 0x800, 0x4000002, 0x4000800, 0x800, 0x200002
82
- ];
83
- const spfunction8 = [
84
- 0x10001040, 0x1000, 0x40000, 0x10041040, 0x10000000, 0x10001040, 0x40, 0x10000000,
85
- 0x40040, 0x10040000, 0x10041040, 0x41000, 0x10041000, 0x41040, 0x1000, 0x40, 0x10040000, 0x10000040, 0x10001000,
86
- 0x1040, 0x41000, 0x40040, 0x10040040, 0x10041000, 0x1040, 0, 0, 0x10040040, 0x10000040, 0x10001000, 0x41040,
87
- 0x40000, 0x41040, 0x40000, 0x10041000, 0x1000, 0x40, 0x10040040, 0x1000, 0x41040, 0x10001000, 0x40, 0x10000040,
88
- 0x10040000, 0x10040040, 0x10000000, 0x40000, 0x10001040, 0, 0x10041040, 0x40040, 0x10000040, 0x10040000, 0x10001000,
89
- 0x10001040, 0, 0x10041040, 0x41000, 0x41000, 0x1040, 0x1040, 0x40040, 0x10000000, 0x10041000
90
- ];
91
-
92
- //create the 16 or 48 subkeys we will need
93
- let m = 0;
94
- let i;
95
- let j;
96
- let temp;
97
- let right1;
98
- let right2;
99
- let left;
100
- let right;
101
- let looping;
102
- let cbcleft;
103
- let cbcleft2;
104
- let cbcright;
105
- let cbcright2;
106
- let endloop;
107
- let loopinc;
108
- let len = message.length;
109
-
110
- //set up the loops for single and triple des
111
- const iterations = keys.length === 32 ? 3 : 9; //single or triple des
112
- if (iterations === 3) {
113
- looping = encrypt ? [0, 32, 2] : [30, -2, -2];
114
- } else {
115
- looping = encrypt ? [0, 32, 2, 62, 30, -2, 64, 96, 2] : [94, 62, -2, 32, 64, 2, 30, -2, -2];
116
- }
117
-
118
- //pad the message depending on the padding parameter
119
- //only add padding if encrypting - note that you need to use the same padding option for both encrypt and decrypt
120
- if (encrypt) {
121
- message = des_addPadding(message, padding);
122
- len = message.length;
123
- }
124
-
125
- //store the result here
126
- let result = new Uint8Array(len);
127
- let k = 0;
128
-
129
- if (mode === 1) { //CBC mode
130
- cbcleft = (iv[m++] << 24) | (iv[m++] << 16) | (iv[m++] << 8) | iv[m++];
131
- cbcright = (iv[m++] << 24) | (iv[m++] << 16) | (iv[m++] << 8) | iv[m++];
132
- m = 0;
133
- }
134
-
135
- //loop through each 64 bit chunk of the message
136
- while (m < len) {
137
- left = (message[m++] << 24) | (message[m++] << 16) | (message[m++] << 8) | message[m++];
138
- right = (message[m++] << 24) | (message[m++] << 16) | (message[m++] << 8) | message[m++];
139
-
140
- //for Cipher Block Chaining mode, xor the message with the previous result
141
- if (mode === 1) {
142
- if (encrypt) {
143
- left ^= cbcleft;
144
- right ^= cbcright;
145
- } else {
146
- cbcleft2 = cbcleft;
147
- cbcright2 = cbcright;
148
- cbcleft = left;
149
- cbcright = right;
150
- }
151
- }
152
-
153
- //first each 64 but chunk of the message must be permuted according to IP
154
- temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
155
- right ^= temp;
156
- left ^= (temp << 4);
157
- temp = ((left >>> 16) ^ right) & 0x0000ffff;
158
- right ^= temp;
159
- left ^= (temp << 16);
160
- temp = ((right >>> 2) ^ left) & 0x33333333;
161
- left ^= temp;
162
- right ^= (temp << 2);
163
- temp = ((right >>> 8) ^ left) & 0x00ff00ff;
164
- left ^= temp;
165
- right ^= (temp << 8);
166
- temp = ((left >>> 1) ^ right) & 0x55555555;
167
- right ^= temp;
168
- left ^= (temp << 1);
169
-
170
- left = ((left << 1) | (left >>> 31));
171
- right = ((right << 1) | (right >>> 31));
172
-
173
- //do this either 1 or 3 times for each chunk of the message
174
- for (j = 0; j < iterations; j += 3) {
175
- endloop = looping[j + 1];
176
- loopinc = looping[j + 2];
177
- //now go through and perform the encryption or decryption
178
- for (i = looping[j]; i !== endloop; i += loopinc) { //for efficiency
179
- right1 = right ^ keys[i];
180
- right2 = ((right >>> 4) | (right << 28)) ^ keys[i + 1];
181
- //the result is attained by passing these bytes through the S selection functions
182
- temp = left;
183
- left = right;
184
- right = temp ^ (spfunction2[(right1 >>> 24) & 0x3f] | spfunction4[(right1 >>> 16) & 0x3f] | spfunction6[(right1 >>>
185
- 8) & 0x3f] | spfunction8[right1 & 0x3f] | spfunction1[(right2 >>> 24) & 0x3f] | spfunction3[(right2 >>> 16) &
186
- 0x3f] | spfunction5[(right2 >>> 8) & 0x3f] | spfunction7[right2 & 0x3f]);
187
- }
188
- temp = left;
189
- left = right;
190
- right = temp; //unreverse left and right
191
- } //for either 1 or 3 iterations
192
-
193
- //move then each one bit to the right
194
- left = ((left >>> 1) | (left << 31));
195
- right = ((right >>> 1) | (right << 31));
196
-
197
- //now perform IP-1, which is IP in the opposite direction
198
- temp = ((left >>> 1) ^ right) & 0x55555555;
199
- right ^= temp;
200
- left ^= (temp << 1);
201
- temp = ((right >>> 8) ^ left) & 0x00ff00ff;
202
- left ^= temp;
203
- right ^= (temp << 8);
204
- temp = ((right >>> 2) ^ left) & 0x33333333;
205
- left ^= temp;
206
- right ^= (temp << 2);
207
- temp = ((left >>> 16) ^ right) & 0x0000ffff;
208
- right ^= temp;
209
- left ^= (temp << 16);
210
- temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
211
- right ^= temp;
212
- left ^= (temp << 4);
213
-
214
- //for Cipher Block Chaining mode, xor the message with the previous result
215
- if (mode === 1) {
216
- if (encrypt) {
217
- cbcleft = left;
218
- cbcright = right;
219
- } else {
220
- left ^= cbcleft2;
221
- right ^= cbcright2;
222
- }
223
- }
224
-
225
- result[k++] = (left >>> 24);
226
- result[k++] = ((left >>> 16) & 0xff);
227
- result[k++] = ((left >>> 8) & 0xff);
228
- result[k++] = (left & 0xff);
229
- result[k++] = (right >>> 24);
230
- result[k++] = ((right >>> 16) & 0xff);
231
- result[k++] = ((right >>> 8) & 0xff);
232
- result[k++] = (right & 0xff);
233
- } //for every 8 characters, or 64 bits in the message
234
-
235
- //only remove padding if decrypting - note that you need to use the same padding option for both encrypt and decrypt
236
- if (!encrypt) {
237
- result = des_removePadding(result, padding);
238
- }
239
-
240
- return result;
241
- } //end of des
242
-
243
-
244
- //des_createKeys
245
- //this takes as input a 64 bit key (even though only 56 bits are used)
246
- //as an array of 2 integers, and returns 16 48 bit keys
247
-
248
- function des_createKeys(key) {
249
- //declaring this locally speeds things up a bit
250
- const pc2bytes0 = [
251
- 0, 0x4, 0x20000000, 0x20000004, 0x10000, 0x10004, 0x20010000, 0x20010004, 0x200, 0x204,
252
- 0x20000200, 0x20000204, 0x10200, 0x10204, 0x20010200, 0x20010204
253
- ];
254
- const pc2bytes1 = [
255
- 0, 0x1, 0x100000, 0x100001, 0x4000000, 0x4000001, 0x4100000, 0x4100001, 0x100, 0x101, 0x100100,
256
- 0x100101, 0x4000100, 0x4000101, 0x4100100, 0x4100101
257
- ];
258
- const pc2bytes2 = [
259
- 0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808, 0, 0x8, 0x800, 0x808,
260
- 0x1000000, 0x1000008, 0x1000800, 0x1000808
261
- ];
262
- const pc2bytes3 = [
263
- 0, 0x200000, 0x8000000, 0x8200000, 0x2000, 0x202000, 0x8002000, 0x8202000, 0x20000, 0x220000,
264
- 0x8020000, 0x8220000, 0x22000, 0x222000, 0x8022000, 0x8222000
265
- ];
266
- const pc2bytes4 = [
267
- 0, 0x40000, 0x10, 0x40010, 0, 0x40000, 0x10, 0x40010, 0x1000, 0x41000, 0x1010, 0x41010, 0x1000,
268
- 0x41000, 0x1010, 0x41010
269
- ];
270
- const pc2bytes5 = [
271
- 0, 0x400, 0x20, 0x420, 0, 0x400, 0x20, 0x420, 0x2000000, 0x2000400, 0x2000020, 0x2000420,
272
- 0x2000000, 0x2000400, 0x2000020, 0x2000420
273
- ];
274
- const pc2bytes6 = [
275
- 0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002, 0, 0x10000000,
276
- 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002
277
- ];
278
- const pc2bytes7 = [
279
- 0, 0x10000, 0x800, 0x10800, 0x20000000, 0x20010000, 0x20000800, 0x20010800, 0x20000, 0x30000,
280
- 0x20800, 0x30800, 0x20020000, 0x20030000, 0x20020800, 0x20030800
281
- ];
282
- const pc2bytes8 = [
283
- 0, 0x40000, 0, 0x40000, 0x2, 0x40002, 0x2, 0x40002, 0x2000000, 0x2040000, 0x2000000, 0x2040000,
284
- 0x2000002, 0x2040002, 0x2000002, 0x2040002
285
- ];
286
- const pc2bytes9 = [
287
- 0, 0x10000000, 0x8, 0x10000008, 0, 0x10000000, 0x8, 0x10000008, 0x400, 0x10000400, 0x408,
288
- 0x10000408, 0x400, 0x10000400, 0x408, 0x10000408
289
- ];
290
- const pc2bytes10 = [
291
- 0, 0x20, 0, 0x20, 0x100000, 0x100020, 0x100000, 0x100020, 0x2000, 0x2020, 0x2000, 0x2020,
292
- 0x102000, 0x102020, 0x102000, 0x102020
293
- ];
294
- const pc2bytes11 = [
295
- 0, 0x1000000, 0x200, 0x1000200, 0x200000, 0x1200000, 0x200200, 0x1200200, 0x4000000, 0x5000000,
296
- 0x4000200, 0x5000200, 0x4200000, 0x5200000, 0x4200200, 0x5200200
297
- ];
298
- const pc2bytes12 = [
299
- 0, 0x1000, 0x8000000, 0x8001000, 0x80000, 0x81000, 0x8080000, 0x8081000, 0x10, 0x1010,
300
- 0x8000010, 0x8001010, 0x80010, 0x81010, 0x8080010, 0x8081010
301
- ];
302
- const pc2bytes13 = [0, 0x4, 0x100, 0x104, 0, 0x4, 0x100, 0x104, 0x1, 0x5, 0x101, 0x105, 0x1, 0x5, 0x101, 0x105];
303
-
304
- //how many iterations (1 for des, 3 for triple des)
305
- const iterations = key.length > 8 ? 3 : 1; //changed by Paul 16/6/2007 to use Triple DES for 9+ byte keys
306
- //stores the return keys
307
- const keys = new Array(32 * iterations);
308
- //now define the left shifts which need to be done
309
- const shifts = [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0];
310
- //other variables
311
- let lefttemp;
312
- let righttemp;
313
- let m = 0;
314
- let n = 0;
315
- let temp;
316
-
317
- for (let j = 0; j < iterations; j++) { //either 1 or 3 iterations
318
- let left = (key[m++] << 24) | (key[m++] << 16) | (key[m++] << 8) | key[m++];
319
- let right = (key[m++] << 24) | (key[m++] << 16) | (key[m++] << 8) | key[m++];
320
-
321
- temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
322
- right ^= temp;
323
- left ^= (temp << 4);
324
- temp = ((right >>> -16) ^ left) & 0x0000ffff;
325
- left ^= temp;
326
- right ^= (temp << -16);
327
- temp = ((left >>> 2) ^ right) & 0x33333333;
328
- right ^= temp;
329
- left ^= (temp << 2);
330
- temp = ((right >>> -16) ^ left) & 0x0000ffff;
331
- left ^= temp;
332
- right ^= (temp << -16);
333
- temp = ((left >>> 1) ^ right) & 0x55555555;
334
- right ^= temp;
335
- left ^= (temp << 1);
336
- temp = ((right >>> 8) ^ left) & 0x00ff00ff;
337
- left ^= temp;
338
- right ^= (temp << 8);
339
- temp = ((left >>> 1) ^ right) & 0x55555555;
340
- right ^= temp;
341
- left ^= (temp << 1);
342
-
343
- //the right side needs to be shifted and to get the last four bits of the left side
344
- temp = (left << 8) | ((right >>> 20) & 0x000000f0);
345
- //left needs to be put upside down
346
- left = (right << 24) | ((right << 8) & 0xff0000) | ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0);
347
- right = temp;
348
-
349
- //now go through and perform these shifts on the left and right keys
350
- for (let i = 0; i < shifts.length; i++) {
351
- //shift the keys either one or two bits to the left
352
- if (shifts[i]) {
353
- left = (left << 2) | (left >>> 26);
354
- right = (right << 2) | (right >>> 26);
355
- } else {
356
- left = (left << 1) | (left >>> 27);
357
- right = (right << 1) | (right >>> 27);
358
- }
359
- left &= -0xf;
360
- right &= -0xf;
361
-
362
- //now apply PC-2, in such a way that E is easier when encrypting or decrypting
363
- //this conversion will look like PC-2 except only the last 6 bits of each byte are used
364
- //rather than 48 consecutive bits and the order of lines will be according to
365
- //how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7
366
- lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf] | pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[(
367
- left >>> 16) & 0xf] | pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf] | pc2bytes6[(left >>> 4) &
368
- 0xf];
369
- righttemp = pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf] | pc2bytes9[(right >>> 20) & 0xf] |
370
- pc2bytes10[(right >>> 16) & 0xf] | pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf] |
371
- pc2bytes13[(right >>> 4) & 0xf];
372
- temp = ((righttemp >>> 16) ^ lefttemp) & 0x0000ffff;
373
- keys[n++] = lefttemp ^ temp;
374
- keys[n++] = righttemp ^ (temp << 16);
375
- }
376
- } //for each iterations
377
- //return the keys we've created
378
- return keys;
379
- } //end of des_createKeys
380
-
381
-
382
- function des_addPadding(message, padding) {
383
- const padLength = 8 - (message.length % 8);
384
-
385
- let pad;
386
- if (padding === 2 && (padLength < 8)) { //pad the message with spaces
387
- pad = " ".charCodeAt(0);
388
- } else if (padding === 1) { //PKCS7 padding
389
- pad = padLength;
390
- } else if (!padding && (padLength < 8)) { //pad the message out with null bytes
391
- pad = 0;
392
- } else if (padLength === 8) {
393
- return message;
394
- } else {
395
- throw new Error('des: invalid padding');
396
- }
397
-
398
- const paddedMessage = new Uint8Array(message.length + padLength);
399
- for (let i = 0; i < message.length; i++) {
400
- paddedMessage[i] = message[i];
401
- }
402
- for (let j = 0; j < padLength; j++) {
403
- paddedMessage[message.length + j] = pad;
404
- }
405
-
406
- return paddedMessage;
407
- }
408
-
409
- function des_removePadding(message, padding) {
410
- let padLength = null;
411
- let pad;
412
- if (padding === 2) { // space padded
413
- pad = " ".charCodeAt(0);
414
- } else if (padding === 1) { // PKCS7
415
- padLength = message[message.length - 1];
416
- } else if (!padding) { // null padding
417
- pad = 0;
418
- } else {
419
- throw new Error('des: invalid padding');
420
- }
421
-
422
- if (!padLength) {
423
- padLength = 1;
424
- while (message[message.length - padLength] === pad) {
425
- padLength++;
426
- }
427
- padLength--;
428
- }
429
-
430
- return message.subarray(0, message.length - padLength);
431
- }
432
-
433
- // added by Recurity Labs
434
-
435
- function TripleDES(key) {
436
- this.key = [];
437
-
438
- for (let i = 0; i < 3; i++) {
439
- this.key.push(new Uint8Array(key.subarray(i * 8, (i * 8) + 8)));
440
- }
441
-
442
- this.encrypt = function(block) {
443
- return des(
444
- des_createKeys(this.key[2]),
445
- des(
446
- des_createKeys(this.key[1]),
447
- des(
448
- des_createKeys(this.key[0]),
449
- block, true, 0, null, null
450
- ),
451
- false, 0, null, null
452
- ), true, 0, null, null
453
- );
454
- };
455
- }
456
-
457
- TripleDES.keySize = TripleDES.prototype.keySize = 24;
458
- TripleDES.blockSize = TripleDES.prototype.blockSize = 8;
459
-
460
- // This is "original" DES
461
-
462
- function DES(key) {
463
- this.key = key;
464
-
465
- this.encrypt = function(block, padding) {
466
- const keys = des_createKeys(this.key);
467
- return des(keys, block, true, 0, null, padding);
468
- };
469
-
470
- this.decrypt = function(block, padding) {
471
- const keys = des_createKeys(this.key);
472
- return des(keys, block, false, 0, null, padding);
473
- };
474
- }
475
-
476
- export default { DES, TripleDES };
@@ -1,91 +0,0 @@
1
- /**
2
- * @fileoverview Symmetric cryptography functions
3
- * @requires crypto/cipher/aes
4
- * @requires crypto/cipher/des
5
- * @requires crypto/cipher/cast5
6
- * @requires crypto/cipher/twofish
7
- * @requires crypto/cipher/blowfish
8
- * @module crypto/cipher
9
- */
10
-
11
- import aes from './aes';
12
- import des from './des.js';
13
- import cast5 from './cast5';
14
- import twofish from './twofish';
15
- import blowfish from './blowfish';
16
-
17
- export default {
18
- /**
19
- * AES-128 encryption and decryption (ID 7)
20
- * @function
21
- * @param {String} key 128-bit key
22
- * @see {@link https://github.com/asmcrypto/asmcrypto.js|asmCrypto}
23
- * @see {@link https://csrc.nist.gov/publications/fips/fips197/fips-197.pdf|NIST FIPS-197}
24
- * @returns {Object}
25
- * @requires asmcrypto.js
26
- */
27
- aes128: aes(128),
28
- /**
29
- * AES-128 Block Cipher (ID 8)
30
- * @function
31
- * @param {String} key 192-bit key
32
- * @see {@link https://github.com/asmcrypto/asmcrypto.js|asmCrypto}
33
- * @see {@link https://csrc.nist.gov/publications/fips/fips197/fips-197.pdf|NIST FIPS-197}
34
- * @returns {Object}
35
- * @requires asmcrypto.js
36
- */
37
- aes192: aes(192),
38
- /**
39
- * AES-128 Block Cipher (ID 9)
40
- * @function
41
- * @param {String} key 256-bit key
42
- * @see {@link https://github.com/asmcrypto/asmcrypto.js|asmCrypto}
43
- * @see {@link https://csrc.nist.gov/publications/fips/fips197/fips-197.pdf|NIST FIPS-197}
44
- * @returns {Object}
45
- * @requires asmcrypto.js
46
- */
47
- aes256: aes(256),
48
- // Not in OpenPGP specifications
49
- des: des.DES,
50
- /**
51
- * Triple DES Block Cipher (ID 2)
52
- * @function
53
- * @param {String} key 192-bit key
54
- * @see {@link https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-67r2.pdf|NIST SP 800-67}
55
- * @returns {Object}
56
- */
57
- tripledes: des.TripleDES,
58
- '3des': des.TripleDES,
59
- /**
60
- * CAST-128 Block Cipher (ID 3)
61
- * @function
62
- * @param {String} key 128-bit key
63
- * @see {@link https://tools.ietf.org/html/rfc2144|The CAST-128 Encryption Algorithm}
64
- * @returns {Object}
65
- */
66
- cast5: cast5,
67
- /**
68
- * Twofish Block Cipher (ID 10)
69
- * @function
70
- * @param {String} key 256-bit key
71
- * @see {@link https://tools.ietf.org/html/rfc4880#ref-TWOFISH|TWOFISH}
72
- * @returns {Object}
73
- */
74
- twofish: twofish,
75
- /**
76
- * Blowfish Block Cipher (ID 4)
77
- * @function
78
- * @param {String} key 128-bit key
79
- * @see {@link https://tools.ietf.org/html/rfc4880#ref-BLOWFISH|BLOWFISH}
80
- * @returns {Object}
81
- */
82
- blowfish: blowfish,
83
- /**
84
- * Not implemented
85
- * @function
86
- * @throws {Error}
87
- */
88
- idea: function() {
89
- throw new Error('IDEA symmetric-key algorithm not implemented');
90
- }
91
- };