@jait/gateway 0.1.256 → 0.1.258

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 (205) hide show
  1. package/dist/routes/preview.d.ts.map +1 -1
  2. package/dist/routes/preview.js +41 -2
  3. package/dist/routes/preview.js.map +1 -1
  4. package/dist/security/sandbox-manager.d.ts +8 -0
  5. package/dist/security/sandbox-manager.d.ts.map +1 -1
  6. package/dist/security/sandbox-manager.js +131 -2
  7. package/dist/security/sandbox-manager.js.map +1 -1
  8. package/dist/services/live-view-manager.d.ts +25 -0
  9. package/dist/services/live-view-manager.d.ts.map +1 -0
  10. package/dist/services/live-view-manager.js +178 -0
  11. package/dist/services/live-view-manager.js.map +1 -0
  12. package/dist/services/preview.d.ts +21 -2
  13. package/dist/services/preview.d.ts.map +1 -1
  14. package/dist/services/preview.js +140 -2
  15. package/dist/services/preview.js.map +1 -1
  16. package/dist/surfaces/browser.d.ts +51 -1
  17. package/dist/surfaces/browser.d.ts.map +1 -1
  18. package/dist/surfaces/browser.js +238 -20
  19. package/dist/surfaces/browser.js.map +1 -1
  20. package/dist/tools/preview-tools.d.ts.map +1 -1
  21. package/dist/tools/preview-tools.js +6 -3
  22. package/dist/tools/preview-tools.js.map +1 -1
  23. package/package.json +1 -1
  24. package/web-dist/assets/{_basePickBy-B5ojxQyY.js → _basePickBy-B1Q85huU.js} +1 -1
  25. package/web-dist/assets/{_baseUniq-BVcMC3e3.js → _baseUniq-xbSl0CM3.js} +1 -1
  26. package/web-dist/assets/{arc-B8rKyks5.js → arc-BPQiaftr.js} +1 -1
  27. package/web-dist/assets/{architectureDiagram-2XIMDMQ5-D5Rn0_M_.js → architectureDiagram-2XIMDMQ5-DAG0yXkD.js} +1 -1
  28. package/web-dist/assets/{blockDiagram-WCTKOSBZ-Dn0EedHT.js → blockDiagram-WCTKOSBZ-BHwTxFpO.js} +1 -1
  29. package/web-dist/assets/{c4Diagram-IC4MRINW-BYTFS9YT.js → c4Diagram-IC4MRINW-DSo8jOax.js} +1 -1
  30. package/web-dist/assets/channel-D0UG72Sd.js +1 -0
  31. package/web-dist/assets/{chunk-4BX2VUAB-c51Qw6zZ.js → chunk-4BX2VUAB-BvHzmUEU.js} +1 -1
  32. package/web-dist/assets/{chunk-55IACEB6-BLJEbYZY.js → chunk-55IACEB6-DRwUUfw9.js} +1 -1
  33. package/web-dist/assets/{chunk-FMBD7UC4-BTQRsQCz.js → chunk-FMBD7UC4-C-og1AV4.js} +1 -1
  34. package/web-dist/assets/{chunk-JSJVCQXG-BCQCgV3v.js → chunk-JSJVCQXG-DQ_Nx-12.js} +1 -1
  35. package/web-dist/assets/{chunk-KX2RTZJC-BdxNziNu.js → chunk-KX2RTZJC-DJt22pKX.js} +1 -1
  36. package/web-dist/assets/{chunk-NQ4KR5QH-DvtJCn0C.js → chunk-NQ4KR5QH-DwqccJna.js} +1 -1
  37. package/web-dist/assets/{chunk-QZHKN3VN-Bv5UUhJr.js → chunk-QZHKN3VN-t2Z5FHem.js} +1 -1
  38. package/web-dist/assets/{chunk-WL4C6EOR-DgCZzsOT.js → chunk-WL4C6EOR-DhnNywRj.js} +1 -1
  39. package/web-dist/assets/classDiagram-VBA2DB6C-Dnib5gxK.js +1 -0
  40. package/web-dist/assets/classDiagram-v2-RAHNMMFH-Dnib5gxK.js +1 -0
  41. package/web-dist/assets/clone-jMsfbHCu.js +1 -0
  42. package/web-dist/assets/{cose-bilkent-S5V4N54A-CmDdGIef.js → cose-bilkent-S5V4N54A-CLw8R8jY.js} +1 -1
  43. package/web-dist/assets/{dagre-KLK3FWXG-BzeF6p1D.js → dagre-KLK3FWXG-DG-8BOX_.js} +1 -1
  44. package/web-dist/assets/{diagram-E7M64L7V-lDeWArgl.js → diagram-E7M64L7V-I6Ok2sG0.js} +1 -1
  45. package/web-dist/assets/{diagram-IFDJBPK2-BguEZbUg.js → diagram-IFDJBPK2-ertAk1QG.js} +1 -1
  46. package/web-dist/assets/{diagram-P4PSJMXO-CnTxg2wa.js → diagram-P4PSJMXO-B9Yr9iab.js} +1 -1
  47. package/web-dist/assets/{erDiagram-INFDFZHY-D2aGee-H.js → erDiagram-INFDFZHY-BMva8gYu.js} +1 -1
  48. package/web-dist/assets/{flowDiagram-PKNHOUZH-DYPu_lOt.js → flowDiagram-PKNHOUZH-D1dJMWaL.js} +1 -1
  49. package/web-dist/assets/{ganttDiagram-A5KZAMGK-D-9aApiK.js → ganttDiagram-A5KZAMGK-qRDi6l_-.js} +1 -1
  50. package/web-dist/assets/{gitGraphDiagram-K3NZZRJ6-CGHZTbqZ.js → gitGraphDiagram-K3NZZRJ6-X8idci3H.js} +1 -1
  51. package/web-dist/assets/{graph-xl1n4wd4.js → graph-6RqPLKMD.js} +1 -1
  52. package/web-dist/assets/{index-CNdW3yYd.js → index-B0GgFn4l.js} +306 -306
  53. package/web-dist/assets/{index-qWyAYgAD.css → index-DFW3_r8A.css} +1 -1
  54. package/web-dist/assets/{infoDiagram-LFFYTUFH-JQ1DhuIN.js → infoDiagram-LFFYTUFH-CMk_Yj9c.js} +1 -1
  55. package/web-dist/assets/{ishikawaDiagram-PHBUUO56-BiQo9puY.js → ishikawaDiagram-PHBUUO56-CwBIr6E2.js} +1 -1
  56. package/web-dist/assets/{journeyDiagram-4ABVD52K-BWvVCFKb.js → journeyDiagram-4ABVD52K-BgD5iS1h.js} +1 -1
  57. package/web-dist/assets/{kanban-definition-K7BYSVSG-B1pZvgm7.js → kanban-definition-K7BYSVSG-CzjxHzou.js} +1 -1
  58. package/web-dist/assets/{layout-C_VnOnT4.js → layout-b5fe_UxD.js} +1 -1
  59. package/web-dist/assets/{linear-BeBoVpvX.js → linear-ChI_4a9O.js} +1 -1
  60. package/web-dist/assets/{mindmap-definition-YRQLILUH-B3U5ZJAw.js → mindmap-definition-YRQLILUH-e_vvWWg8.js} +1 -1
  61. package/web-dist/assets/{pieDiagram-SKSYHLDU-B9JMxGDx.js → pieDiagram-SKSYHLDU-CJtQ5J0D.js} +1 -1
  62. package/web-dist/assets/{quadrantDiagram-337W2JSQ-DNAEOevf.js → quadrantDiagram-337W2JSQ-Cf_x_2ej.js} +1 -1
  63. package/web-dist/assets/{requirementDiagram-Z7DCOOCP-Dcgzabvl.js → requirementDiagram-Z7DCOOCP-DCQvoqk_.js} +1 -1
  64. package/web-dist/assets/{sankeyDiagram-WA2Y5GQK-BDcQVCtL.js → sankeyDiagram-WA2Y5GQK-D2eB9_Im.js} +1 -1
  65. package/web-dist/assets/{sequenceDiagram-2WXFIKYE-5kY7GmoR.js → sequenceDiagram-2WXFIKYE-Ccyyepsb.js} +1 -1
  66. package/web-dist/assets/{stateDiagram-RAJIS63D-BwQlMlEC.js → stateDiagram-RAJIS63D-DPMGShy8.js} +1 -1
  67. package/web-dist/assets/stateDiagram-v2-FVOUBMTO-BmvKM7hT.js +1 -0
  68. package/web-dist/assets/{timeline-definition-YZTLITO2-BE0IDpJe.js → timeline-definition-YZTLITO2-CHBPr8N4.js} +1 -1
  69. package/web-dist/assets/{treemap-KZPCXAKY-CHwtWAgO.js → treemap-KZPCXAKY-DnqeIQgk.js} +1 -1
  70. package/web-dist/assets/{vennDiagram-LZ73GAT5-ByqFK92_.js → vennDiagram-LZ73GAT5-BRIzanhU.js} +1 -1
  71. package/web-dist/assets/{xychartDiagram-JWTSCODW-BdCa1f3c.js → xychartDiagram-JWTSCODW-qjjqxrk2.js} +1 -1
  72. package/web-dist/index.html +2 -2
  73. package/web-dist/noVNC/LICENSE.txt +62 -0
  74. package/web-dist/noVNC/app/error-handler.js +79 -0
  75. package/web-dist/noVNC/app/images/alt.svg +92 -0
  76. package/web-dist/noVNC/app/images/clipboard.svg +106 -0
  77. package/web-dist/noVNC/app/images/connect.svg +96 -0
  78. package/web-dist/noVNC/app/images/ctrl.svg +96 -0
  79. package/web-dist/noVNC/app/images/ctrlaltdel.svg +100 -0
  80. package/web-dist/noVNC/app/images/disconnect.svg +94 -0
  81. package/web-dist/noVNC/app/images/drag.svg +76 -0
  82. package/web-dist/noVNC/app/images/error.svg +81 -0
  83. package/web-dist/noVNC/app/images/esc.svg +92 -0
  84. package/web-dist/noVNC/app/images/expander.svg +69 -0
  85. package/web-dist/noVNC/app/images/fullscreen.svg +93 -0
  86. package/web-dist/noVNC/app/images/handle.svg +82 -0
  87. package/web-dist/noVNC/app/images/handle_bg.svg +172 -0
  88. package/web-dist/noVNC/app/images/icons/Makefile +42 -0
  89. package/web-dist/noVNC/app/images/icons/novnc-icon-sm.svg +163 -0
  90. package/web-dist/noVNC/app/images/icons/novnc-icon.svg +163 -0
  91. package/web-dist/noVNC/app/images/icons/novnc-ios-120.png +0 -0
  92. package/web-dist/noVNC/app/images/icons/novnc-ios-152.png +0 -0
  93. package/web-dist/noVNC/app/images/icons/novnc-ios-167.png +0 -0
  94. package/web-dist/noVNC/app/images/icons/novnc-ios-180.png +0 -0
  95. package/web-dist/noVNC/app/images/icons/novnc-ios-40.png +0 -0
  96. package/web-dist/noVNC/app/images/icons/novnc-ios-58.png +0 -0
  97. package/web-dist/noVNC/app/images/icons/novnc-ios-60.png +0 -0
  98. package/web-dist/noVNC/app/images/icons/novnc-ios-80.png +0 -0
  99. package/web-dist/noVNC/app/images/icons/novnc-ios-87.png +0 -0
  100. package/web-dist/noVNC/app/images/icons/novnc-ios-icon.svg +183 -0
  101. package/web-dist/noVNC/app/images/icons/novnc.ico +0 -0
  102. package/web-dist/noVNC/app/images/info.svg +81 -0
  103. package/web-dist/noVNC/app/images/keyboard.svg +88 -0
  104. package/web-dist/noVNC/app/images/power.svg +87 -0
  105. package/web-dist/noVNC/app/images/settings.svg +76 -0
  106. package/web-dist/noVNC/app/images/tab.svg +86 -0
  107. package/web-dist/noVNC/app/images/toggleextrakeys.svg +90 -0
  108. package/web-dist/noVNC/app/images/warning.svg +81 -0
  109. package/web-dist/noVNC/app/images/windows.svg +65 -0
  110. package/web-dist/noVNC/app/locale/README +1 -0
  111. package/web-dist/noVNC/app/locale/cs.json +71 -0
  112. package/web-dist/noVNC/app/locale/de.json +74 -0
  113. package/web-dist/noVNC/app/locale/el.json +100 -0
  114. package/web-dist/noVNC/app/locale/es.json +68 -0
  115. package/web-dist/noVNC/app/locale/fr.json +82 -0
  116. package/web-dist/noVNC/app/locale/hu.json +80 -0
  117. package/web-dist/noVNC/app/locale/it.json +68 -0
  118. package/web-dist/noVNC/app/locale/ja.json +81 -0
  119. package/web-dist/noVNC/app/locale/ko.json +70 -0
  120. package/web-dist/noVNC/app/locale/nl.json +95 -0
  121. package/web-dist/noVNC/app/locale/pl.json +80 -0
  122. package/web-dist/noVNC/app/locale/pt_BR.json +72 -0
  123. package/web-dist/noVNC/app/locale/ru.json +72 -0
  124. package/web-dist/noVNC/app/locale/sv.json +83 -0
  125. package/web-dist/noVNC/app/locale/tr.json +69 -0
  126. package/web-dist/noVNC/app/locale/uk.json +81 -0
  127. package/web-dist/noVNC/app/locale/zh_CN.json +93 -0
  128. package/web-dist/noVNC/app/locale/zh_TW.json +69 -0
  129. package/web-dist/noVNC/app/localization.js +206 -0
  130. package/web-dist/noVNC/app/sounds/CREDITS +4 -0
  131. package/web-dist/noVNC/app/sounds/bell.mp3 +0 -0
  132. package/web-dist/noVNC/app/sounds/bell.oga +0 -0
  133. package/web-dist/noVNC/app/styles/Orbitron700.ttf +0 -0
  134. package/web-dist/noVNC/app/styles/Orbitron700.woff +0 -0
  135. package/web-dist/noVNC/app/styles/base.css +927 -0
  136. package/web-dist/noVNC/app/styles/constants.css +30 -0
  137. package/web-dist/noVNC/app/styles/input.css +628 -0
  138. package/web-dist/noVNC/app/ui.js +1873 -0
  139. package/web-dist/noVNC/app/wakelock.js +199 -0
  140. package/web-dist/noVNC/app/webutil.js +250 -0
  141. package/web-dist/noVNC/core/base64.js +104 -0
  142. package/web-dist/noVNC/core/clipboard.js +72 -0
  143. package/web-dist/noVNC/core/crypto/aes.js +178 -0
  144. package/web-dist/noVNC/core/crypto/bigint.js +34 -0
  145. package/web-dist/noVNC/core/crypto/crypto.js +90 -0
  146. package/web-dist/noVNC/core/crypto/des.js +330 -0
  147. package/web-dist/noVNC/core/crypto/dh.js +55 -0
  148. package/web-dist/noVNC/core/crypto/md5.js +82 -0
  149. package/web-dist/noVNC/core/crypto/rsa.js +132 -0
  150. package/web-dist/noVNC/core/decoders/copyrect.js +27 -0
  151. package/web-dist/noVNC/core/decoders/h264.js +321 -0
  152. package/web-dist/noVNC/core/decoders/hextile.js +181 -0
  153. package/web-dist/noVNC/core/decoders/jpeg.js +161 -0
  154. package/web-dist/noVNC/core/decoders/raw.js +59 -0
  155. package/web-dist/noVNC/core/decoders/rre.js +44 -0
  156. package/web-dist/noVNC/core/decoders/tight.js +393 -0
  157. package/web-dist/noVNC/core/decoders/tightpng.js +27 -0
  158. package/web-dist/noVNC/core/decoders/zlib.js +51 -0
  159. package/web-dist/noVNC/core/decoders/zrle.js +185 -0
  160. package/web-dist/noVNC/core/deflator.js +84 -0
  161. package/web-dist/noVNC/core/display.js +578 -0
  162. package/web-dist/noVNC/core/encodings.js +54 -0
  163. package/web-dist/noVNC/core/inflator.js +65 -0
  164. package/web-dist/noVNC/core/input/domkeytable.js +311 -0
  165. package/web-dist/noVNC/core/input/fixedkeys.js +129 -0
  166. package/web-dist/noVNC/core/input/gesturehandler.js +567 -0
  167. package/web-dist/noVNC/core/input/keyboard.js +294 -0
  168. package/web-dist/noVNC/core/input/keysym.js +616 -0
  169. package/web-dist/noVNC/core/input/keysymdef.js +688 -0
  170. package/web-dist/noVNC/core/input/util.js +191 -0
  171. package/web-dist/noVNC/core/input/vkeys.js +116 -0
  172. package/web-dist/noVNC/core/input/xtscancodes.js +173 -0
  173. package/web-dist/noVNC/core/ra2.js +312 -0
  174. package/web-dist/noVNC/core/rfb.js +3426 -0
  175. package/web-dist/noVNC/core/util/browser.js +266 -0
  176. package/web-dist/noVNC/core/util/cursor.js +249 -0
  177. package/web-dist/noVNC/core/util/element.js +32 -0
  178. package/web-dist/noVNC/core/util/events.js +138 -0
  179. package/web-dist/noVNC/core/util/eventtarget.js +35 -0
  180. package/web-dist/noVNC/core/util/int.js +15 -0
  181. package/web-dist/noVNC/core/util/logging.js +56 -0
  182. package/web-dist/noVNC/core/util/strings.js +28 -0
  183. package/web-dist/noVNC/core/websock.js +369 -0
  184. package/web-dist/noVNC/defaults.json +1 -0
  185. package/web-dist/noVNC/mandatory.json +1 -0
  186. package/web-dist/noVNC/vendor/pako/LICENSE +21 -0
  187. package/web-dist/noVNC/vendor/pako/README.md +6 -0
  188. package/web-dist/noVNC/vendor/pako/lib/utils/common.js +45 -0
  189. package/web-dist/noVNC/vendor/pako/lib/zlib/adler32.js +27 -0
  190. package/web-dist/noVNC/vendor/pako/lib/zlib/constants.js +47 -0
  191. package/web-dist/noVNC/vendor/pako/lib/zlib/crc32.js +36 -0
  192. package/web-dist/noVNC/vendor/pako/lib/zlib/deflate.js +1846 -0
  193. package/web-dist/noVNC/vendor/pako/lib/zlib/gzheader.js +35 -0
  194. package/web-dist/noVNC/vendor/pako/lib/zlib/inffast.js +324 -0
  195. package/web-dist/noVNC/vendor/pako/lib/zlib/inflate.js +1527 -0
  196. package/web-dist/noVNC/vendor/pako/lib/zlib/inftrees.js +322 -0
  197. package/web-dist/noVNC/vendor/pako/lib/zlib/messages.js +11 -0
  198. package/web-dist/noVNC/vendor/pako/lib/zlib/trees.js +1195 -0
  199. package/web-dist/noVNC/vendor/pako/lib/zlib/zstream.js +24 -0
  200. package/web-dist/noVNC/vnc_lite.html +180 -0
  201. package/web-dist/assets/channel-DlBBaM6I.js +0 -1
  202. package/web-dist/assets/classDiagram-VBA2DB6C-DixDm16f.js +0 -1
  203. package/web-dist/assets/classDiagram-v2-RAHNMMFH-DixDm16f.js +0 -1
  204. package/web-dist/assets/clone-DEDCKaxV.js +0 -1
  205. package/web-dist/assets/stateDiagram-v2-FVOUBMTO-Bdpt0e9f.js +0 -1
@@ -0,0 +1,178 @@
1
+ export class AESECBCipher {
2
+ constructor() {
3
+ this._key = null;
4
+ }
5
+
6
+ get algorithm() {
7
+ return { name: "AES-ECB" };
8
+ }
9
+
10
+ static async importKey(key, _algorithm, extractable, keyUsages) {
11
+ const cipher = new AESECBCipher;
12
+ await cipher._importKey(key, extractable, keyUsages);
13
+ return cipher;
14
+ }
15
+
16
+ async _importKey(key, extractable, keyUsages) {
17
+ this._key = await window.crypto.subtle.importKey(
18
+ "raw", key, {name: "AES-CBC"}, extractable, keyUsages);
19
+ }
20
+
21
+ async encrypt(_algorithm, plaintext) {
22
+ const x = new Uint8Array(plaintext);
23
+ if (x.length % 16 !== 0 || this._key === null) {
24
+ return null;
25
+ }
26
+ const n = x.length / 16;
27
+ for (let i = 0; i < n; i++) {
28
+ const y = new Uint8Array(await window.crypto.subtle.encrypt({
29
+ name: "AES-CBC",
30
+ iv: new Uint8Array(16),
31
+ }, this._key, x.slice(i * 16, i * 16 + 16))).slice(0, 16);
32
+ x.set(y, i * 16);
33
+ }
34
+ return x;
35
+ }
36
+ }
37
+
38
+ export class AESEAXCipher {
39
+ constructor() {
40
+ this._rawKey = null;
41
+ this._ctrKey = null;
42
+ this._cbcKey = null;
43
+ this._zeroBlock = new Uint8Array(16);
44
+ this._prefixBlock0 = this._zeroBlock;
45
+ this._prefixBlock1 = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
46
+ this._prefixBlock2 = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]);
47
+ }
48
+
49
+ get algorithm() {
50
+ return { name: "AES-EAX" };
51
+ }
52
+
53
+ async _encryptBlock(block) {
54
+ const encrypted = await window.crypto.subtle.encrypt({
55
+ name: "AES-CBC",
56
+ iv: this._zeroBlock,
57
+ }, this._cbcKey, block);
58
+ return new Uint8Array(encrypted).slice(0, 16);
59
+ }
60
+
61
+ async _initCMAC() {
62
+ const k1 = await this._encryptBlock(this._zeroBlock);
63
+ const k2 = new Uint8Array(16);
64
+ const v = k1[0] >>> 6;
65
+ for (let i = 0; i < 15; i++) {
66
+ k2[i] = (k1[i + 1] >> 6) | (k1[i] << 2);
67
+ k1[i] = (k1[i + 1] >> 7) | (k1[i] << 1);
68
+ }
69
+ const lut = [0x0, 0x87, 0x0e, 0x89];
70
+ k2[14] ^= v >>> 1;
71
+ k2[15] = (k1[15] << 2) ^ lut[v];
72
+ k1[15] = (k1[15] << 1) ^ lut[v >> 1];
73
+ this._k1 = k1;
74
+ this._k2 = k2;
75
+ }
76
+
77
+ async _encryptCTR(data, counter) {
78
+ const encrypted = await window.crypto.subtle.encrypt({
79
+ name: "AES-CTR",
80
+ counter: counter,
81
+ length: 128
82
+ }, this._ctrKey, data);
83
+ return new Uint8Array(encrypted);
84
+ }
85
+
86
+ async _decryptCTR(data, counter) {
87
+ const decrypted = await window.crypto.subtle.decrypt({
88
+ name: "AES-CTR",
89
+ counter: counter,
90
+ length: 128
91
+ }, this._ctrKey, data);
92
+ return new Uint8Array(decrypted);
93
+ }
94
+
95
+ async _computeCMAC(data, prefixBlock) {
96
+ if (prefixBlock.length !== 16) {
97
+ return null;
98
+ }
99
+ const n = Math.floor(data.length / 16);
100
+ const m = Math.ceil(data.length / 16);
101
+ const r = data.length - n * 16;
102
+ const cbcData = new Uint8Array((m + 1) * 16);
103
+ cbcData.set(prefixBlock);
104
+ cbcData.set(data, 16);
105
+ if (r === 0) {
106
+ for (let i = 0; i < 16; i++) {
107
+ cbcData[n * 16 + i] ^= this._k1[i];
108
+ }
109
+ } else {
110
+ cbcData[(n + 1) * 16 + r] = 0x80;
111
+ for (let i = 0; i < 16; i++) {
112
+ cbcData[(n + 1) * 16 + i] ^= this._k2[i];
113
+ }
114
+ }
115
+ let cbcEncrypted = await window.crypto.subtle.encrypt({
116
+ name: "AES-CBC",
117
+ iv: this._zeroBlock,
118
+ }, this._cbcKey, cbcData);
119
+
120
+ cbcEncrypted = new Uint8Array(cbcEncrypted);
121
+ const mac = cbcEncrypted.slice(cbcEncrypted.length - 32, cbcEncrypted.length - 16);
122
+ return mac;
123
+ }
124
+
125
+ static async importKey(key, _algorithm, _extractable, _keyUsages) {
126
+ const cipher = new AESEAXCipher;
127
+ await cipher._importKey(key);
128
+ return cipher;
129
+ }
130
+
131
+ async _importKey(key) {
132
+ this._rawKey = key;
133
+ this._ctrKey = await window.crypto.subtle.importKey(
134
+ "raw", key, {name: "AES-CTR"}, false, ["encrypt", "decrypt"]);
135
+ this._cbcKey = await window.crypto.subtle.importKey(
136
+ "raw", key, {name: "AES-CBC"}, false, ["encrypt"]);
137
+ await this._initCMAC();
138
+ }
139
+
140
+ async encrypt(algorithm, message) {
141
+ const ad = algorithm.additionalData;
142
+ const nonce = algorithm.iv;
143
+ const nCMAC = await this._computeCMAC(nonce, this._prefixBlock0);
144
+ const encrypted = await this._encryptCTR(message, nCMAC);
145
+ const adCMAC = await this._computeCMAC(ad, this._prefixBlock1);
146
+ const mac = await this._computeCMAC(encrypted, this._prefixBlock2);
147
+ for (let i = 0; i < 16; i++) {
148
+ mac[i] ^= nCMAC[i] ^ adCMAC[i];
149
+ }
150
+ const res = new Uint8Array(16 + encrypted.length);
151
+ res.set(encrypted);
152
+ res.set(mac, encrypted.length);
153
+ return res;
154
+ }
155
+
156
+ async decrypt(algorithm, data) {
157
+ const encrypted = data.slice(0, data.length - 16);
158
+ const ad = algorithm.additionalData;
159
+ const nonce = algorithm.iv;
160
+ const mac = data.slice(data.length - 16);
161
+ const nCMAC = await this._computeCMAC(nonce, this._prefixBlock0);
162
+ const adCMAC = await this._computeCMAC(ad, this._prefixBlock1);
163
+ const computedMac = await this._computeCMAC(encrypted, this._prefixBlock2);
164
+ for (let i = 0; i < 16; i++) {
165
+ computedMac[i] ^= nCMAC[i] ^ adCMAC[i];
166
+ }
167
+ if (computedMac.length !== mac.length) {
168
+ return null;
169
+ }
170
+ for (let i = 0; i < mac.length; i++) {
171
+ if (computedMac[i] !== mac[i]) {
172
+ return null;
173
+ }
174
+ }
175
+ const res = await this._decryptCTR(encrypted, nCMAC);
176
+ return res;
177
+ }
178
+ }
@@ -0,0 +1,34 @@
1
+ export function modPow(b, e, m) {
2
+ let r = 1n;
3
+ b = b % m;
4
+ while (e > 0n) {
5
+ if ((e & 1n) === 1n) {
6
+ r = (r * b) % m;
7
+ }
8
+ e = e >> 1n;
9
+ b = (b * b) % m;
10
+ }
11
+ return r;
12
+ }
13
+
14
+ export function bigIntToU8Array(bigint, padLength=0) {
15
+ let hex = bigint.toString(16);
16
+ if (padLength === 0) {
17
+ padLength = Math.ceil(hex.length / 2);
18
+ }
19
+ hex = hex.padStart(padLength * 2, '0');
20
+ const length = hex.length / 2;
21
+ const arr = new Uint8Array(length);
22
+ for (let i = 0; i < length; i++) {
23
+ arr[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
24
+ }
25
+ return arr;
26
+ }
27
+
28
+ export function u8ArrayToBigInt(arr) {
29
+ let hex = '0x';
30
+ for (let i = 0; i < arr.length; i++) {
31
+ hex += arr[i].toString(16).padStart(2, '0');
32
+ }
33
+ return BigInt(hex);
34
+ }
@@ -0,0 +1,90 @@
1
+ import { AESECBCipher, AESEAXCipher } from "./aes.js";
2
+ import { DESCBCCipher, DESECBCipher } from "./des.js";
3
+ import { RSACipher } from "./rsa.js";
4
+ import { DHCipher } from "./dh.js";
5
+ import { MD5 } from "./md5.js";
6
+
7
+ // A single interface for the cryptographic algorithms not supported by SubtleCrypto.
8
+ // Both synchronous and asynchronous implmentations are allowed.
9
+ class LegacyCrypto {
10
+ constructor() {
11
+ this._algorithms = {
12
+ "AES-ECB": AESECBCipher,
13
+ "AES-EAX": AESEAXCipher,
14
+ "DES-ECB": DESECBCipher,
15
+ "DES-CBC": DESCBCCipher,
16
+ "RSA-PKCS1-v1_5": RSACipher,
17
+ "DH": DHCipher,
18
+ "MD5": MD5,
19
+ };
20
+ }
21
+
22
+ encrypt(algorithm, key, data) {
23
+ if (key.algorithm.name !== algorithm.name) {
24
+ throw new Error("algorithm does not match");
25
+ }
26
+ if (typeof key.encrypt !== "function") {
27
+ throw new Error("key does not support encryption");
28
+ }
29
+ return key.encrypt(algorithm, data);
30
+ }
31
+
32
+ decrypt(algorithm, key, data) {
33
+ if (key.algorithm.name !== algorithm.name) {
34
+ throw new Error("algorithm does not match");
35
+ }
36
+ if (typeof key.decrypt !== "function") {
37
+ throw new Error("key does not support encryption");
38
+ }
39
+ return key.decrypt(algorithm, data);
40
+ }
41
+
42
+ importKey(format, keyData, algorithm, extractable, keyUsages) {
43
+ if (format !== "raw") {
44
+ throw new Error("key format is not supported");
45
+ }
46
+ const alg = this._algorithms[algorithm.name];
47
+ if (typeof alg === "undefined" || typeof alg.importKey !== "function") {
48
+ throw new Error("algorithm is not supported");
49
+ }
50
+ return alg.importKey(keyData, algorithm, extractable, keyUsages);
51
+ }
52
+
53
+ generateKey(algorithm, extractable, keyUsages) {
54
+ const alg = this._algorithms[algorithm.name];
55
+ if (typeof alg === "undefined" || typeof alg.generateKey !== "function") {
56
+ throw new Error("algorithm is not supported");
57
+ }
58
+ return alg.generateKey(algorithm, extractable, keyUsages);
59
+ }
60
+
61
+ exportKey(format, key) {
62
+ if (format !== "raw") {
63
+ throw new Error("key format is not supported");
64
+ }
65
+ if (typeof key.exportKey !== "function") {
66
+ throw new Error("key does not support exportKey");
67
+ }
68
+ return key.exportKey();
69
+ }
70
+
71
+ digest(algorithm, data) {
72
+ const alg = this._algorithms[algorithm];
73
+ if (typeof alg !== "function") {
74
+ throw new Error("algorithm is not supported");
75
+ }
76
+ return alg(data);
77
+ }
78
+
79
+ deriveBits(algorithm, key, length) {
80
+ if (key.algorithm.name !== algorithm.name) {
81
+ throw new Error("algorithm does not match");
82
+ }
83
+ if (typeof key.deriveBits !== "function") {
84
+ throw new Error("key does not support deriveBits");
85
+ }
86
+ return key.deriveBits(algorithm, length);
87
+ }
88
+ }
89
+
90
+ export default new LegacyCrypto;
@@ -0,0 +1,330 @@
1
+ /*
2
+ * Ported from Flashlight VNC ActionScript implementation:
3
+ * http://www.wizhelp.com/flashlight-vnc/
4
+ *
5
+ * Full attribution follows:
6
+ *
7
+ * -------------------------------------------------------------------------
8
+ *
9
+ * This DES class has been extracted from package Acme.Crypto for use in VNC.
10
+ * The unnecessary odd parity code has been removed.
11
+ *
12
+ * These changes are:
13
+ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
14
+ *
15
+ * This software is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
+ *
19
+
20
+ * DesCipher - the DES encryption method
21
+ *
22
+ * The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
23
+ *
24
+ * Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
25
+ *
26
+ * Permission to use, copy, modify, and distribute this software
27
+ * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
28
+ * without fee is hereby granted, provided that this copyright notice is kept
29
+ * intact.
30
+ *
31
+ * WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
32
+ * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
33
+ * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
34
+ * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
35
+ * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
36
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
37
+ *
38
+ * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
39
+ * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
40
+ * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
41
+ * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
42
+ * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
43
+ * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
44
+ * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
45
+ * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
46
+ * HIGH RISK ACTIVITIES.
47
+ *
48
+ *
49
+ * The rest is:
50
+ *
51
+ * Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
52
+ *
53
+ * Redistribution and use in source and binary forms, with or without
54
+ * modification, are permitted provided that the following conditions
55
+ * are met:
56
+ * 1. Redistributions of source code must retain the above copyright
57
+ * notice, this list of conditions and the following disclaimer.
58
+ * 2. Redistributions in binary form must reproduce the above copyright
59
+ * notice, this list of conditions and the following disclaimer in the
60
+ * documentation and/or other materials provided with the distribution.
61
+ *
62
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
63
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
66
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72
+ * SUCH DAMAGE.
73
+ *
74
+ * Visit the ACME Labs Java page for up-to-date versions of this and other
75
+ * fine Java utilities: http://www.acme.com/java/
76
+ */
77
+
78
+ /* eslint-disable comma-spacing */
79
+
80
+ // Tables, permutations, S-boxes, etc.
81
+ const PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
82
+ 25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
83
+ 50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
84
+ totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28];
85
+
86
+ const z = 0x0;
87
+ let a,b,c,d,e,f;
88
+ a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
89
+ const SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
90
+ z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
91
+ a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
92
+ c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
93
+ a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
94
+ const SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
95
+ a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
96
+ z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
97
+ z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
98
+ a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
99
+ const SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
100
+ b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
101
+ c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
102
+ b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
103
+ a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
104
+ const SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
105
+ z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
106
+ b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
107
+ c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
108
+ a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
109
+ const SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
110
+ a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
111
+ z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
112
+ c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
113
+ a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
114
+ const SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
115
+ z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
116
+ b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
117
+ a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
118
+ a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
119
+ const SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
120
+ b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
121
+ b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
122
+ z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
123
+ a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
124
+ const SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
125
+ c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
126
+ a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
127
+ z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
128
+
129
+ /* eslint-enable comma-spacing */
130
+
131
+ class DES {
132
+ constructor(password) {
133
+ this.keys = [];
134
+
135
+ // Set the key.
136
+ const pc1m = [], pcr = [], kn = [];
137
+
138
+ for (let j = 0, l = 56; j < 56; ++j, l -= 8) {
139
+ l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
140
+ const m = l & 0x7;
141
+ pc1m[j] = ((password[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
142
+ }
143
+
144
+ for (let i = 0; i < 16; ++i) {
145
+ const m = i << 1;
146
+ const n = m + 1;
147
+ kn[m] = kn[n] = 0;
148
+ for (let o = 28; o < 59; o += 28) {
149
+ for (let j = o - 28; j < o; ++j) {
150
+ const l = j + totrot[i];
151
+ pcr[j] = l < o ? pc1m[l] : pc1m[l - 28];
152
+ }
153
+ }
154
+ for (let j = 0; j < 24; ++j) {
155
+ if (pcr[PC2[j]] !== 0) {
156
+ kn[m] |= 1 << (23 - j);
157
+ }
158
+ if (pcr[PC2[j + 24]] !== 0) {
159
+ kn[n] |= 1 << (23 - j);
160
+ }
161
+ }
162
+ }
163
+
164
+ // cookey
165
+ for (let i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
166
+ const raw0 = kn[rawi++];
167
+ const raw1 = kn[rawi++];
168
+ this.keys[KnLi] = (raw0 & 0x00fc0000) << 6;
169
+ this.keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
170
+ this.keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
171
+ this.keys[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
172
+ ++KnLi;
173
+ this.keys[KnLi] = (raw0 & 0x0003f000) << 12;
174
+ this.keys[KnLi] |= (raw0 & 0x0000003f) << 16;
175
+ this.keys[KnLi] |= (raw1 & 0x0003f000) >>> 4;
176
+ this.keys[KnLi] |= (raw1 & 0x0000003f);
177
+ ++KnLi;
178
+ }
179
+ }
180
+
181
+ // Encrypt 8 bytes of text
182
+ enc8(text) {
183
+ const b = text.slice();
184
+ let l, r, x; // left, right, accumulator
185
+
186
+ // Squash 8 bytes to 2 ints
187
+ l = b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3];
188
+ r = b[4]<<24 | b[5]<<16 | b[6]<<8 | b[7];
189
+
190
+ x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
191
+ r ^= x;
192
+ l ^= (x << 4);
193
+ x = ((l >>> 16) ^ r) & 0x0000ffff;
194
+ r ^= x;
195
+ l ^= (x << 16);
196
+ x = ((r >>> 2) ^ l) & 0x33333333;
197
+ l ^= x;
198
+ r ^= (x << 2);
199
+ x = ((r >>> 8) ^ l) & 0x00ff00ff;
200
+ l ^= x;
201
+ r ^= (x << 8);
202
+ r = (r << 1) | ((r >>> 31) & 1);
203
+ x = (l ^ r) & 0xaaaaaaaa;
204
+ l ^= x;
205
+ r ^= x;
206
+ l = (l << 1) | ((l >>> 31) & 1);
207
+
208
+ for (let i = 0, keysi = 0; i < 8; ++i) {
209
+ x = (r << 28) | (r >>> 4);
210
+ x ^= this.keys[keysi++];
211
+ let fval = SP7[x & 0x3f];
212
+ fval |= SP5[(x >>> 8) & 0x3f];
213
+ fval |= SP3[(x >>> 16) & 0x3f];
214
+ fval |= SP1[(x >>> 24) & 0x3f];
215
+ x = r ^ this.keys[keysi++];
216
+ fval |= SP8[x & 0x3f];
217
+ fval |= SP6[(x >>> 8) & 0x3f];
218
+ fval |= SP4[(x >>> 16) & 0x3f];
219
+ fval |= SP2[(x >>> 24) & 0x3f];
220
+ l ^= fval;
221
+ x = (l << 28) | (l >>> 4);
222
+ x ^= this.keys[keysi++];
223
+ fval = SP7[x & 0x3f];
224
+ fval |= SP5[(x >>> 8) & 0x3f];
225
+ fval |= SP3[(x >>> 16) & 0x3f];
226
+ fval |= SP1[(x >>> 24) & 0x3f];
227
+ x = l ^ this.keys[keysi++];
228
+ fval |= SP8[x & 0x0000003f];
229
+ fval |= SP6[(x >>> 8) & 0x3f];
230
+ fval |= SP4[(x >>> 16) & 0x3f];
231
+ fval |= SP2[(x >>> 24) & 0x3f];
232
+ r ^= fval;
233
+ }
234
+
235
+ r = (r << 31) | (r >>> 1);
236
+ x = (l ^ r) & 0xaaaaaaaa;
237
+ l ^= x;
238
+ r ^= x;
239
+ l = (l << 31) | (l >>> 1);
240
+ x = ((l >>> 8) ^ r) & 0x00ff00ff;
241
+ r ^= x;
242
+ l ^= (x << 8);
243
+ x = ((l >>> 2) ^ r) & 0x33333333;
244
+ r ^= x;
245
+ l ^= (x << 2);
246
+ x = ((r >>> 16) ^ l) & 0x0000ffff;
247
+ l ^= x;
248
+ r ^= (x << 16);
249
+ x = ((r >>> 4) ^ l) & 0x0f0f0f0f;
250
+ l ^= x;
251
+ r ^= (x << 4);
252
+
253
+ // Spread ints to bytes
254
+ x = [r, l];
255
+ for (let i = 0; i < 8; i++) {
256
+ b[i] = (x[i>>>2] >>> (8 * (3 - (i % 4)))) % 256;
257
+ if (b[i] < 0) { b[i] += 256; } // unsigned
258
+ }
259
+ return b;
260
+ }
261
+ }
262
+
263
+ export class DESECBCipher {
264
+ constructor() {
265
+ this._cipher = null;
266
+ }
267
+
268
+ get algorithm() {
269
+ return { name: "DES-ECB" };
270
+ }
271
+
272
+ static importKey(key, _algorithm, _extractable, _keyUsages) {
273
+ const cipher = new DESECBCipher;
274
+ cipher._importKey(key);
275
+ return cipher;
276
+ }
277
+
278
+ _importKey(key, _extractable, _keyUsages) {
279
+ this._cipher = new DES(key);
280
+ }
281
+
282
+ encrypt(_algorithm, plaintext) {
283
+ const x = new Uint8Array(plaintext);
284
+ if (x.length % 8 !== 0 || this._cipher === null) {
285
+ return null;
286
+ }
287
+ const n = x.length / 8;
288
+ for (let i = 0; i < n; i++) {
289
+ x.set(this._cipher.enc8(x.slice(i * 8, i * 8 + 8)), i * 8);
290
+ }
291
+ return x;
292
+ }
293
+ }
294
+
295
+ export class DESCBCCipher {
296
+ constructor() {
297
+ this._cipher = null;
298
+ }
299
+
300
+ get algorithm() {
301
+ return { name: "DES-CBC" };
302
+ }
303
+
304
+ static importKey(key, _algorithm, _extractable, _keyUsages) {
305
+ const cipher = new DESCBCCipher;
306
+ cipher._importKey(key);
307
+ return cipher;
308
+ }
309
+
310
+ _importKey(key) {
311
+ this._cipher = new DES(key);
312
+ }
313
+
314
+ encrypt(algorithm, plaintext) {
315
+ const x = new Uint8Array(plaintext);
316
+ let y = new Uint8Array(algorithm.iv);
317
+ if (x.length % 8 !== 0 || this._cipher === null) {
318
+ return null;
319
+ }
320
+ const n = x.length / 8;
321
+ for (let i = 0; i < n; i++) {
322
+ for (let j = 0; j < 8; j++) {
323
+ y[j] ^= plaintext[i * 8 + j];
324
+ }
325
+ y = this._cipher.enc8(y);
326
+ x.set(y, i * 8);
327
+ }
328
+ return x;
329
+ }
330
+ }
@@ -0,0 +1,55 @@
1
+ import { modPow, bigIntToU8Array, u8ArrayToBigInt } from "./bigint.js";
2
+
3
+ class DHPublicKey {
4
+ constructor(key) {
5
+ this._key = key;
6
+ }
7
+
8
+ get algorithm() {
9
+ return { name: "DH" };
10
+ }
11
+
12
+ exportKey() {
13
+ return this._key;
14
+ }
15
+ }
16
+
17
+ export class DHCipher {
18
+ constructor() {
19
+ this._g = null;
20
+ this._p = null;
21
+ this._gBigInt = null;
22
+ this._pBigInt = null;
23
+ this._privateKey = null;
24
+ }
25
+
26
+ get algorithm() {
27
+ return { name: "DH" };
28
+ }
29
+
30
+ static generateKey(algorithm, _extractable) {
31
+ const cipher = new DHCipher;
32
+ cipher._generateKey(algorithm);
33
+ return { privateKey: cipher, publicKey: new DHPublicKey(cipher._publicKey) };
34
+ }
35
+
36
+ _generateKey(algorithm) {
37
+ const g = algorithm.g;
38
+ const p = algorithm.p;
39
+ this._keyBytes = p.length;
40
+ this._gBigInt = u8ArrayToBigInt(g);
41
+ this._pBigInt = u8ArrayToBigInt(p);
42
+ this._privateKey = window.crypto.getRandomValues(new Uint8Array(this._keyBytes));
43
+ this._privateKeyBigInt = u8ArrayToBigInt(this._privateKey);
44
+ this._publicKey = bigIntToU8Array(modPow(
45
+ this._gBigInt, this._privateKeyBigInt, this._pBigInt), this._keyBytes);
46
+ }
47
+
48
+ deriveBits(algorithm, length) {
49
+ const bytes = Math.ceil(length / 8);
50
+ const pkey = new Uint8Array(algorithm.public);
51
+ const len = bytes > this._keyBytes ? bytes : this._keyBytes;
52
+ const secret = modPow(u8ArrayToBigInt(pkey), this._privateKeyBigInt, this._pBigInt);
53
+ return bigIntToU8Array(secret, len).slice(0, len);
54
+ }
55
+ }