@encharm/cws 4.5.3 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/CLAUDE.md +83 -0
  3. package/README.md +20 -4
  4. package/binding.gyp +8 -2
  5. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  8. package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
  9. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node127.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node137.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node147.node +0 -0
  13. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node127.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node147.node +0 -0
  17. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node127.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node147.node +0 -0
  21. package/dist/client.d.ts +1 -0
  22. package/dist/client.js +15 -1
  23. package/dist/index.d.ts +6 -1
  24. package/dist/index.js +2 -0
  25. package/dist/server.d.ts +1 -0
  26. package/dist/server.js +16 -2
  27. package/dist/shared.d.ts +1 -0
  28. package/dist/shared.js +3 -2
  29. package/package.json +1 -1
  30. package/src/Addon.cpp +4 -1
  31. package/src/Addon.h +80 -15
  32. package/src/Extensions.cpp +7 -1
  33. package/src/Extensions.h +2 -1
  34. package/src/Group.cpp +1 -1
  35. package/src/Group.h +4 -1
  36. package/src/HTTPSocket.cpp +1 -1
  37. package/src/Hub.cpp +11 -76
  38. package/src/Hub.h +12 -10
  39. package/src/Networking.h +11 -0
  40. package/src/Socket.h +201 -6
  41. package/src/WebSocket.cpp +8 -5
  42. package/src/Zlib.cpp +138 -0
  43. package/src/Zlib.h +38 -0
  44. package/src/cSNode.cpp +2 -0
  45. package/src/cSNode.h +4 -0
  46. package/src/headers/26/acorn_version.h +6 -0
  47. package/src/headers/26/aliased_buffer-inl.h +264 -0
  48. package/src/headers/26/aliased_buffer.h +205 -0
  49. package/src/headers/26/aliased_struct-inl.h +143 -0
  50. package/src/headers/26/aliased_struct.h +248 -0
  51. package/src/headers/26/amaro_version.h +6 -0
  52. package/src/headers/26/async_context_frame.h +33 -0
  53. package/src/headers/26/async_wrap-inl.h +123 -0
  54. package/src/headers/26/async_wrap.h +254 -0
  55. package/src/headers/26/base_object-inl.h +333 -0
  56. package/src/headers/26/base_object.h +339 -0
  57. package/src/headers/26/base_object_types.h +76 -0
  58. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  59. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  60. package/src/headers/26/builtin_info.h +57 -0
  61. package/src/headers/26/callback_queue-inl.h +97 -0
  62. package/src/headers/26/callback_queue.h +79 -0
  63. package/src/headers/26/cares_wrap.h +475 -0
  64. package/src/headers/26/cleanup_queue-inl.h +36 -0
  65. package/src/headers/26/cleanup_queue.h +79 -0
  66. package/src/headers/26/compile_cache.h +134 -0
  67. package/src/headers/26/connect_wrap.h +26 -0
  68. package/src/headers/26/connection_wrap.h +30 -0
  69. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  70. package/src/headers/26/cppgc_helpers.h +162 -0
  71. package/src/headers/26/crypto/crypto_aes.h +107 -0
  72. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  73. package/src/headers/26/crypto/crypto_bio.h +193 -0
  74. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  75. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  76. package/src/headers/26/crypto/crypto_common.h +48 -0
  77. package/src/headers/26/crypto/crypto_context.h +219 -0
  78. package/src/headers/26/crypto/crypto_dh.h +104 -0
  79. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  80. package/src/headers/26/crypto/crypto_ec.h +102 -0
  81. package/src/headers/26/crypto/crypto_hash.h +157 -0
  82. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  83. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  84. package/src/headers/26/crypto/crypto_kem.h +131 -0
  85. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  86. package/src/headers/26/crypto/crypto_keys.h +366 -0
  87. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  88. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  89. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  90. package/src/headers/26/crypto/crypto_random.h +127 -0
  91. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  92. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  93. package/src/headers/26/crypto/crypto_sig.h +159 -0
  94. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  95. package/src/headers/26/crypto/crypto_timing.h +20 -0
  96. package/src/headers/26/crypto/crypto_tls.h +342 -0
  97. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  98. package/src/headers/26/crypto/crypto_util.h +775 -0
  99. package/src/headers/26/crypto/crypto_x509.h +140 -0
  100. package/src/headers/26/dataqueue/queue.h +311 -0
  101. package/src/headers/26/debug_utils-inl.h +291 -0
  102. package/src/headers/26/debug_utils.h +200 -0
  103. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  104. package/src/headers/26/embedded_data.h +17 -0
  105. package/src/headers/26/encoding_binding.h +59 -0
  106. package/src/headers/26/env-inl.h +956 -0
  107. package/src/headers/26/env.h +1294 -0
  108. package/src/headers/26/env_properties.h +562 -0
  109. package/src/headers/26/ffi/data.h +30 -0
  110. package/src/headers/26/ffi/fast.h +96 -0
  111. package/src/headers/26/ffi/jit_memory.h +26 -0
  112. package/src/headers/26/ffi/types.h +99 -0
  113. package/src/headers/26/handle_wrap.h +123 -0
  114. package/src/headers/26/histogram-inl.h +211 -0
  115. package/src/headers/26/histogram.h +474 -0
  116. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  117. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  118. package/src/headers/26/inspector/io_agent.h +30 -0
  119. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  120. package/src/headers/26/inspector/network_agent.h +110 -0
  121. package/src/headers/26/inspector/network_inspector.h +45 -0
  122. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  123. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  124. package/src/headers/26/inspector/node_json.h +24 -0
  125. package/src/headers/26/inspector/node_string.h +101 -0
  126. package/src/headers/26/inspector/notification_emitter.h +38 -0
  127. package/src/headers/26/inspector/protocol_helper.h +27 -0
  128. package/src/headers/26/inspector/runtime_agent.h +41 -0
  129. package/src/headers/26/inspector/storage_agent.h +33 -0
  130. package/src/headers/26/inspector/target_agent.h +59 -0
  131. package/src/headers/26/inspector/target_manager.h +70 -0
  132. package/src/headers/26/inspector/tracing_agent.h +43 -0
  133. package/src/headers/26/inspector/worker_agent.h +40 -0
  134. package/src/headers/26/inspector/worker_inspector.h +124 -0
  135. package/src/headers/26/inspector_agent.h +168 -0
  136. package/src/headers/26/inspector_io.h +78 -0
  137. package/src/headers/26/inspector_profiler.h +149 -0
  138. package/src/headers/26/inspector_socket.h +60 -0
  139. package/src/headers/26/inspector_socket_server.h +110 -0
  140. package/src/headers/26/js_native_api.h +634 -0
  141. package/src/headers/26/js_native_api_types.h +244 -0
  142. package/src/headers/26/js_native_api_v8.h +485 -0
  143. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  144. package/src/headers/26/js_stream.h +57 -0
  145. package/src/headers/26/json_utils.h +172 -0
  146. package/src/headers/26/large_pages/node_large_page.h +34 -0
  147. package/src/headers/26/lru_cache-inl.h +69 -0
  148. package/src/headers/26/memory_tracker-inl.h +461 -0
  149. package/src/headers/26/memory_tracker.h +341 -0
  150. package/src/headers/26/module_wrap.h +231 -0
  151. package/src/headers/26/ncrypto.h +2008 -0
  152. package/src/headers/26/node.h +1693 -0
  153. package/src/headers/26/node_api.h +265 -0
  154. package/src/headers/26/node_api_internals.h +48 -0
  155. package/src/headers/26/node_api_types.h +58 -0
  156. package/src/headers/26/node_binding.h +170 -0
  157. package/src/headers/26/node_blob.h +160 -0
  158. package/src/headers/26/node_bob-inl.h +36 -0
  159. package/src/headers/26/node_bob.h +107 -0
  160. package/src/headers/26/node_buffer.h +92 -0
  161. package/src/headers/26/node_builtins.h +239 -0
  162. package/src/headers/26/node_concepts.h +46 -0
  163. package/src/headers/26/node_config_file.h +77 -0
  164. package/src/headers/26/node_constants.h +82 -0
  165. package/src/headers/26/node_context_data.h +171 -0
  166. package/src/headers/26/node_contextify.h +261 -0
  167. package/src/headers/26/node_crypto.h +66 -0
  168. package/src/headers/26/node_debug.h +30 -0
  169. package/src/headers/26/node_diagnostics_channel.h +121 -0
  170. package/src/headers/26/node_dir.h +52 -0
  171. package/src/headers/26/node_dotenv.h +45 -0
  172. package/src/headers/26/node_errors.h +378 -0
  173. package/src/headers/26/node_exit_code.h +54 -0
  174. package/src/headers/26/node_external_reference.h +171 -0
  175. package/src/headers/26/node_ffi.h +212 -0
  176. package/src/headers/26/node_file-inl.h +421 -0
  177. package/src/headers/26/node_file.h +561 -0
  178. package/src/headers/26/node_file_utils.h +39 -0
  179. package/src/headers/26/node_hash.h +212 -0
  180. package/src/headers/26/node_http2.h +1202 -0
  181. package/src/headers/26/node_http2_state.h +159 -0
  182. package/src/headers/26/node_http_common-inl.h +199 -0
  183. package/src/headers/26/node_http_common.h +535 -0
  184. package/src/headers/26/node_i18n.h +132 -0
  185. package/src/headers/26/node_internals.h +485 -0
  186. package/src/headers/26/node_locks.h +184 -0
  187. package/src/headers/26/node_main_instance.h +67 -0
  188. package/src/headers/26/node_mem-inl.h +113 -0
  189. package/src/headers/26/node_mem.h +45 -0
  190. package/src/headers/26/node_messaging.h +389 -0
  191. package/src/headers/26/node_metadata.h +172 -0
  192. package/src/headers/26/node_modules.h +102 -0
  193. package/src/headers/26/node_mutex.h +323 -0
  194. package/src/headers/26/node_object_wrap.h +145 -0
  195. package/src/headers/26/node_options-inl.h +524 -0
  196. package/src/headers/26/node_options.h +710 -0
  197. package/src/headers/26/node_perf.h +167 -0
  198. package/src/headers/26/node_perf_common.h +103 -0
  199. package/src/headers/26/node_platform.h +290 -0
  200. package/src/headers/26/node_process-inl.h +26 -0
  201. package/src/headers/26/node_process.h +112 -0
  202. package/src/headers/26/node_profiling.h +38 -0
  203. package/src/headers/26/node_realm-inl.h +156 -0
  204. package/src/headers/26/node_realm.h +236 -0
  205. package/src/headers/26/node_report.h +43 -0
  206. package/src/headers/26/node_revert.h +82 -0
  207. package/src/headers/26/node_root_certs.h +2937 -0
  208. package/src/headers/26/node_sea.h +101 -0
  209. package/src/headers/26/node_shadow_realm.h +46 -0
  210. package/src/headers/26/node_snapshot_builder.h +57 -0
  211. package/src/headers/26/node_snapshotable.h +167 -0
  212. package/src/headers/26/node_sockaddr-inl.h +248 -0
  213. package/src/headers/26/node_sockaddr.h +459 -0
  214. package/src/headers/26/node_sqlite.h +607 -0
  215. package/src/headers/26/node_stat_watcher.h +73 -0
  216. package/src/headers/26/node_task_runner.h +92 -0
  217. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  218. package/src/headers/26/node_threadsafe_cow.h +105 -0
  219. package/src/headers/26/node_union_bytes.h +81 -0
  220. package/src/headers/26/node_url.h +101 -0
  221. package/src/headers/26/node_url_pattern.h +118 -0
  222. package/src/headers/26/node_v8.h +78 -0
  223. package/src/headers/26/node_v8_embedder.h +26 -0
  224. package/src/headers/26/node_v8_platform-inl.h +96 -0
  225. package/src/headers/26/node_version.h +116 -0
  226. package/src/headers/26/node_wasi.h +184 -0
  227. package/src/headers/26/node_wasm_web_api.h +55 -0
  228. package/src/headers/26/node_watchdog.h +164 -0
  229. package/src/headers/26/node_webstorage.h +62 -0
  230. package/src/headers/26/node_worker.h +162 -0
  231. package/src/headers/26/path.h +36 -0
  232. package/src/headers/26/permission/boolean_permission.h +50 -0
  233. package/src/headers/26/permission/fs_permission.h +192 -0
  234. package/src/headers/26/permission/permission.h +155 -0
  235. package/src/headers/26/permission/permission_base.h +79 -0
  236. package/src/headers/26/pipe_wrap.h +80 -0
  237. package/src/headers/26/quic/application.h +279 -0
  238. package/src/headers/26/quic/arena.h +373 -0
  239. package/src/headers/26/quic/bindingdata.h +440 -0
  240. package/src/headers/26/quic/cid.h +127 -0
  241. package/src/headers/26/quic/data.h +358 -0
  242. package/src/headers/26/quic/defs.h +417 -0
  243. package/src/headers/26/quic/endpoint.h +519 -0
  244. package/src/headers/26/quic/guard.h +5 -0
  245. package/src/headers/26/quic/http3.h +25 -0
  246. package/src/headers/26/quic/packet.h +166 -0
  247. package/src/headers/26/quic/preferredaddress.h +72 -0
  248. package/src/headers/26/quic/session.h +770 -0
  249. package/src/headers/26/quic/session_manager.h +107 -0
  250. package/src/headers/26/quic/sessionticket.h +110 -0
  251. package/src/headers/26/quic/streams.h +518 -0
  252. package/src/headers/26/quic/tlscontext.h +353 -0
  253. package/src/headers/26/quic/tokens.h +263 -0
  254. package/src/headers/26/quic/transportparams.h +184 -0
  255. package/src/headers/26/req_wrap-inl.h +175 -0
  256. package/src/headers/26/req_wrap.h +79 -0
  257. package/src/headers/26/spawn_sync.h +243 -0
  258. package/src/headers/26/stream_base-inl.h +170 -0
  259. package/src/headers/26/stream_base.h +487 -0
  260. package/src/headers/26/stream_pipe.h +76 -0
  261. package/src/headers/26/stream_wrap.h +137 -0
  262. package/src/headers/26/string_bytes.h +114 -0
  263. package/src/headers/26/string_decoder-inl.h +31 -0
  264. package/src/headers/26/string_decoder.h +49 -0
  265. package/src/headers/26/tcp_wrap.h +138 -0
  266. package/src/headers/26/threadpoolwork-inl.h +70 -0
  267. package/src/headers/26/timer_wrap-inl.h +32 -0
  268. package/src/headers/26/timer_wrap.h +87 -0
  269. package/src/headers/26/timers.h +70 -0
  270. package/src/headers/26/tracing/agent.h +125 -0
  271. package/src/headers/26/tracing/agent_legacy.h +146 -0
  272. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  273. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  274. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  275. package/src/headers/26/tracing/trace_event.h +27 -0
  276. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  277. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  278. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  279. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  280. package/src/headers/26/tracing/traced_value.h +167 -0
  281. package/src/headers/26/tty_wrap.h +65 -0
  282. package/src/headers/26/udp_wrap.h +231 -0
  283. package/src/headers/26/undici_version.h +6 -0
  284. package/src/headers/26/util-inl.h +788 -0
  285. package/src/headers/26/util.h +1207 -0
  286. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  287. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  288. package/src/headers/26/v8-fast-api-calls.h +784 -0
  289. package/src/headers/26/v8-inspector-protocol.h +13 -0
  290. package/src/headers/26/v8-inspector.h +458 -0
  291. package/src/headers/26/v8-metrics.h +273 -0
  292. package/src/headers/26/v8-trace-categories.h +28 -0
  293. package/src/headers/26/v8-unwinder-state.h +30 -0
  294. package/src/headers/26/v8-util.h +549 -0
  295. package/src/headers/26/v8-value-serializer-version.h +24 -0
  296. package/src/headers/26/v8-version-string.h +38 -0
  297. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  298. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  299. package/src/headers/26/zlib_version.h +6 -0
  300. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
  301. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
  302. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
  303. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
  304. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
  305. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
@@ -0,0 +1,366 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_KEYS_H_
2
+ #define SRC_CRYPTO_CRYPTO_KEYS_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "crypto/crypto_util.h"
7
+ #include "base_object.h"
8
+ #include "env.h"
9
+ #include "memory_tracker.h"
10
+ #include "node_buffer.h"
11
+ #include "node_worker.h"
12
+ #include "v8.h"
13
+
14
+ #include <openssl/evp.h>
15
+
16
+ #include <cstdint>
17
+ #include <memory>
18
+ #include <string>
19
+
20
+ namespace node::crypto {
21
+ enum KeyType {
22
+ kKeyTypeSecret,
23
+ kKeyTypePublic,
24
+ kKeyTypePrivate
25
+ };
26
+
27
+ enum KeyEncodingContext {
28
+ kKeyContextInput,
29
+ kKeyContextExport,
30
+ kKeyContextGenerate
31
+ };
32
+
33
+ enum class ParseKeyResult {
34
+ kParseKeyNotRecognized =
35
+ static_cast<int>(ncrypto::EVPKeyPointer::PKParseError::NOT_RECOGNIZED),
36
+ kParseKeyNeedPassphrase =
37
+ static_cast<int>(ncrypto::EVPKeyPointer::PKParseError::NEED_PASSPHRASE),
38
+ kParseKeyFailed =
39
+ static_cast<int>(ncrypto::EVPKeyPointer::PKParseError::FAILED),
40
+ kParseKeyOk,
41
+ };
42
+
43
+ // Objects of this class can safely be shared among threads.
44
+ class KeyObjectData final : public MemoryRetainer {
45
+ public:
46
+ static KeyObjectData CreateSecret(ByteSource key);
47
+
48
+ static KeyObjectData CreateAsymmetric(KeyType type,
49
+ ncrypto::EVPKeyPointer&& pkey);
50
+
51
+ KeyObjectData(std::nullptr_t = nullptr);
52
+
53
+ inline operator bool() const { return data_ != nullptr; }
54
+
55
+ KeyType GetKeyType() const;
56
+
57
+ // These functions allow unprotected access to the raw key material and should
58
+ // only be used to implement cryptographic operations requiring the key.
59
+ const ncrypto::EVPKeyPointer& GetAsymmetricKey() const;
60
+ const char* GetSymmetricKey() const;
61
+ size_t GetSymmetricKeySize() const;
62
+
63
+ void MemoryInfo(MemoryTracker* tracker) const override;
64
+ SET_MEMORY_INFO_NAME(KeyObjectData)
65
+ SET_SELF_SIZE(KeyObjectData)
66
+
67
+ Mutex& mutex() const;
68
+
69
+ static v8::Maybe<ncrypto::EVPKeyPointer::PublicKeyEncodingConfig>
70
+ GetPublicKeyEncodingFromJs(const v8::FunctionCallbackInfo<v8::Value>& args,
71
+ unsigned int* offset,
72
+ KeyEncodingContext context);
73
+
74
+ static KeyObjectData GetPrivateKeyFromJs(
75
+ const v8::FunctionCallbackInfo<v8::Value>& args,
76
+ unsigned int* offset,
77
+ bool allow_key_object);
78
+
79
+ static KeyObjectData GetPublicOrPrivateKeyFromJs(
80
+ const v8::FunctionCallbackInfo<v8::Value>& args,
81
+ unsigned int* offset,
82
+ bool allow_private_key_store = false);
83
+
84
+ static v8::Maybe<ncrypto::EVPKeyPointer::PrivateKeyEncodingConfig>
85
+ GetPrivateKeyEncodingFromJs(const v8::FunctionCallbackInfo<v8::Value>& args,
86
+ unsigned int* offset,
87
+ KeyEncodingContext context);
88
+
89
+ bool ToEncodedPublicKey(
90
+ Environment* env,
91
+ const ncrypto::EVPKeyPointer::PublicKeyEncodingConfig& config,
92
+ v8::Local<v8::Value>* out);
93
+
94
+ bool ToEncodedPrivateKey(
95
+ Environment* env,
96
+ const ncrypto::EVPKeyPointer::PrivateKeyEncodingConfig& config,
97
+ v8::Local<v8::Value>* out);
98
+
99
+ inline KeyObjectData addRef() const {
100
+ return KeyObjectData(key_type_, mutex_, data_);
101
+ }
102
+
103
+ inline KeyObjectData addRefWithType(KeyType type) const {
104
+ return KeyObjectData(type, mutex_, data_);
105
+ }
106
+
107
+ private:
108
+ explicit KeyObjectData(ByteSource symmetric_key);
109
+ explicit KeyObjectData(KeyType type, ncrypto::EVPKeyPointer&& pkey);
110
+
111
+ static KeyObjectData GetParsedKey(KeyType type,
112
+ Environment* env,
113
+ ncrypto::EVPKeyPointer&& pkey,
114
+ ParseKeyResult ret,
115
+ const char* default_msg);
116
+
117
+ KeyType key_type_;
118
+ mutable std::shared_ptr<Mutex> mutex_;
119
+
120
+ struct Data final : public MemoryRetainer {
121
+ const ByteSource symmetric_key;
122
+ const ncrypto::EVPKeyPointer asymmetric_key;
123
+ explicit Data(ByteSource symmetric_key)
124
+ : symmetric_key(std::move(symmetric_key)) {}
125
+ explicit Data(ncrypto::EVPKeyPointer asymmetric_key)
126
+ : asymmetric_key(std::move(asymmetric_key)) {}
127
+
128
+ void MemoryInfo(MemoryTracker* tracker) const override;
129
+ SET_MEMORY_INFO_NAME(KeyObjectData::Data)
130
+ SET_SELF_SIZE(Data)
131
+ };
132
+ std::shared_ptr<Data> data_;
133
+
134
+ KeyObjectData(KeyType type,
135
+ std::shared_ptr<Mutex> mutex,
136
+ std::shared_ptr<Data> data)
137
+ : key_type_(type), mutex_(std::move(mutex)), data_(std::move(data)) {}
138
+ };
139
+
140
+ class KeyObjectHandle : public BaseObject {
141
+ public:
142
+ static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
143
+ static v8::Local<v8::Function> Initialize(Environment* env);
144
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
145
+
146
+ static v8::MaybeLocal<v8::Object> Create(Environment* env,
147
+ const KeyObjectData& data);
148
+
149
+ // TODO(tniessen): track the memory used by OpenSSL types
150
+ SET_NO_MEMORY_INFO()
151
+ SET_MEMORY_INFO_NAME(KeyObjectHandle)
152
+ SET_SELF_SIZE(KeyObjectHandle)
153
+
154
+ const KeyObjectData& Data();
155
+
156
+ protected:
157
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
158
+
159
+ static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
160
+ static void GetKeyType(const v8::FunctionCallbackInfo<v8::Value>& args);
161
+ static void GetKeyDetail(const v8::FunctionCallbackInfo<v8::Value>& args);
162
+ static void Equals(const v8::FunctionCallbackInfo<v8::Value>& args);
163
+
164
+ static void ExportJWK(const v8::FunctionCallbackInfo<v8::Value>& args);
165
+
166
+ static void GetAsymmetricKeyType(
167
+ const v8::FunctionCallbackInfo<v8::Value>& args);
168
+ v8::Local<v8::Value> GetAsymmetricKeyType() const;
169
+
170
+ static void CheckEcKeyData(const v8::FunctionCallbackInfo<v8::Value>& args);
171
+ bool CheckEcKeyData() const;
172
+
173
+ static void GetSymmetricKeySize(
174
+ const v8::FunctionCallbackInfo<v8::Value>& args);
175
+
176
+ static void Export(const v8::FunctionCallbackInfo<v8::Value>& args);
177
+
178
+ static void RawPublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
179
+ static void RawPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
180
+ static void ExportECPublicRaw(
181
+ const v8::FunctionCallbackInfo<v8::Value>& args);
182
+ static void ExportECPrivateRaw(
183
+ const v8::FunctionCallbackInfo<v8::Value>& args);
184
+ static void RawSeed(const v8::FunctionCallbackInfo<v8::Value>& args);
185
+
186
+ v8::MaybeLocal<v8::Value> ExportSecretKey() const;
187
+ v8::MaybeLocal<v8::Value> ExportPublicKey(
188
+ const ncrypto::EVPKeyPointer::PublicKeyEncodingConfig& config) const;
189
+ v8::MaybeLocal<v8::Value> ExportPrivateKey(
190
+ const ncrypto::EVPKeyPointer::PrivateKeyEncodingConfig& config) const;
191
+
192
+ KeyObjectHandle(Environment* env,
193
+ v8::Local<v8::Object> wrap);
194
+
195
+ private:
196
+ KeyObjectData data_;
197
+ };
198
+
199
+ // NativeKeyObject is the native base class for the Node.js-specific
200
+ // `KeyObject`. It holds the underlying KeyObjectData for structured
201
+ // cloning and exposes the native hidden slot tuple that JS needs:
202
+ // [type enum, KeyObjectHandle]. JS primes a per-instance private-field
203
+ // cache from that result and lazily appends derived metadata there.
204
+ class NativeKeyObject : public BaseObject {
205
+ public:
206
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
207
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
208
+
209
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
210
+ static void CreateNativeKeyObjectClass(
211
+ const v8::FunctionCallbackInfo<v8::Value>& args);
212
+
213
+ // True if `value` is a real NativeKeyObject instance. Uses the
214
+ // FunctionTemplate stored on the Environment as a brand check.
215
+ // Used by `GetSlots` to validate its receiver.
216
+ static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
217
+
218
+ // Returns [type, handle] in one call so JS can prime a per-instance cache
219
+ // on first access. Derived metadata is not returned from native here.
220
+ static void GetSlots(const v8::FunctionCallbackInfo<v8::Value>& args);
221
+
222
+ SET_NO_MEMORY_INFO()
223
+ SET_MEMORY_INFO_NAME(NativeKeyObject)
224
+ SET_SELF_SIZE(NativeKeyObject)
225
+
226
+ class KeyObjectTransferData : public worker::TransferData {
227
+ public:
228
+ explicit KeyObjectTransferData(const KeyObjectData& data)
229
+ : data_(data.addRef()) {}
230
+
231
+ BaseObjectPtr<BaseObject> Deserialize(
232
+ Environment* env,
233
+ v8::Local<v8::Context> context,
234
+ std::unique_ptr<worker::TransferData> self) override;
235
+
236
+ SET_MEMORY_INFO_NAME(KeyObjectTransferData)
237
+ SET_SELF_SIZE(KeyObjectTransferData)
238
+ SET_NO_MEMORY_INFO()
239
+
240
+ private:
241
+ KeyObjectData data_;
242
+ };
243
+
244
+ BaseObject::TransferMode GetTransferMode() const override;
245
+ std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
246
+
247
+ private:
248
+ NativeKeyObject(Environment* env,
249
+ v8::Local<v8::Object> wrap,
250
+ const KeyObjectData& handle_data)
251
+ : BaseObject(env, wrap), handle_data_(handle_data.addRef()) {
252
+ MakeWeak();
253
+ }
254
+
255
+ KeyObjectData handle_data_;
256
+ };
257
+
258
+ // NativeCryptoKey is the native base class for the Web Crypto
259
+ // `CryptoKey`. It holds the internal slots - `[[type]]` as an enum,
260
+ // `[[extractable]]`, `[[algorithm]]`, `[[usages]]` as a mask, and the
261
+ // underlying KeyObjectData. The public `type`, `extractable`,
262
+ // `algorithm`, and `usages` accessors on `CryptoKey.prototype` are
263
+ // user-configurable per Web IDL, so internal consumers read these
264
+ // values directly from the C++ side via a single `GetSlots` call
265
+ // which returns all slots at once; JS primes a per-instance cache
266
+ // from that result.
267
+ class NativeCryptoKey : public BaseObject {
268
+ public:
269
+ enum InternalFields {
270
+ kAlgorithmField = BaseObject::kInternalFieldCount,
271
+ kInternalFieldCount,
272
+ };
273
+
274
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
275
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
276
+
277
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
278
+ static void CreateCryptoKeyClass(
279
+ const v8::FunctionCallbackInfo<v8::Value>& args);
280
+
281
+ static v8::MaybeLocal<v8::Value> Create(Environment* env,
282
+ const KeyObjectData& data,
283
+ v8::Local<v8::Value> algorithm,
284
+ uint32_t usages_mask,
285
+ bool extractable);
286
+
287
+ // True if `value` is a real NativeCryptoKey instance. Uses the
288
+ // FunctionTemplate stored on the Environment as a brand check.
289
+ // Used by `GetSlots` to validate its receiver.
290
+ static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
291
+
292
+ // Returns [type, extractable, algorithm, usages mask, handle] in one call
293
+ // so JS can prime a per-instance cache on first access.
294
+ static void GetSlots(const v8::FunctionCallbackInfo<v8::Value>& args);
295
+
296
+ void MemoryInfo(MemoryTracker* tracker) const override;
297
+ SET_MEMORY_INFO_NAME(NativeCryptoKey)
298
+ SET_SELF_SIZE(NativeCryptoKey)
299
+
300
+ class CryptoKeyTransferData : public worker::TransferData {
301
+ public:
302
+ CryptoKeyTransferData(const KeyObjectData& data,
303
+ v8::Global<v8::Object>&& algorithm,
304
+ uint32_t usages_mask,
305
+ bool extractable)
306
+ : data_(data.addRef()),
307
+ algorithm_(std::move(algorithm)),
308
+ usages_mask_(usages_mask),
309
+ extractable_(extractable) {}
310
+
311
+ BaseObjectPtr<BaseObject> Deserialize(
312
+ Environment* env,
313
+ v8::Local<v8::Context> context,
314
+ std::unique_ptr<worker::TransferData> self) override;
315
+
316
+ v8::Maybe<bool> FinalizeTransferWrite(
317
+ v8::Local<v8::Context> context,
318
+ v8::ValueSerializer* serializer) override;
319
+
320
+ void MemoryInfo(MemoryTracker* tracker) const override;
321
+ SET_MEMORY_INFO_NAME(CryptoKeyTransferData)
322
+ SET_SELF_SIZE(CryptoKeyTransferData)
323
+
324
+ private:
325
+ KeyObjectData data_;
326
+ v8::Global<v8::Object> algorithm_;
327
+ uint32_t usages_mask_;
328
+ bool extractable_;
329
+ };
330
+
331
+ BaseObject::TransferMode GetTransferMode() const override;
332
+ std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
333
+ v8::Maybe<void> FinalizeTransferRead(
334
+ v8::Local<v8::Context> context,
335
+ v8::ValueDeserializer* deserializer) override;
336
+
337
+ const KeyObjectData& handle_data() const { return handle_data_; }
338
+
339
+ private:
340
+ NativeCryptoKey(Environment* env,
341
+ v8::Local<v8::Object> wrap,
342
+ const KeyObjectData& handle_data)
343
+ : BaseObject(env, wrap), handle_data_(handle_data.addRef()) {
344
+ MakeWeak();
345
+ }
346
+
347
+ KeyObjectData handle_data_;
348
+ uint32_t usages_mask_ = 0;
349
+ bool extractable_ = false;
350
+ };
351
+
352
+ enum WebCryptoKeyFormat {
353
+ kWebCryptoKeyFormatRaw,
354
+ kWebCryptoKeyFormatPKCS8,
355
+ kWebCryptoKeyFormatSPKI,
356
+ kWebCryptoKeyFormatJWK
357
+ };
358
+
359
+ namespace Keys {
360
+ void Initialize(Environment* env, v8::Local<v8::Object> target);
361
+ void RegisterExternalReferences(ExternalReferenceRegistry* registry);
362
+ } // namespace Keys
363
+ } // namespace node::crypto
364
+
365
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
366
+ #endif // SRC_CRYPTO_CRYPTO_KEYS_H_
@@ -0,0 +1,79 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_KMAC_H_
2
+ #define SRC_CRYPTO_CRYPTO_KMAC_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <string>
7
+ #include "crypto/crypto_keys.h"
8
+ #include "crypto/crypto_sig.h"
9
+ #include "crypto/crypto_util.h"
10
+
11
+ namespace node::crypto {
12
+
13
+ #if OPENSSL_WITH_EVP_MAC
14
+
15
+ enum class KmacVariant { KMAC128, KMAC256 };
16
+
17
+ struct KmacConfig final : public MemoryRetainer {
18
+ SignConfiguration::Mode mode;
19
+ KeyObjectData key;
20
+ ByteSource data;
21
+ ByteSource signature;
22
+ ByteSource customization;
23
+ KmacVariant variant;
24
+ size_t key_length; // Key length in bits
25
+ uint32_t length; // Output length in bits
26
+
27
+ KmacConfig() = default;
28
+
29
+ explicit KmacConfig(KmacConfig&& other) noexcept;
30
+
31
+ KmacConfig& operator=(KmacConfig&& other) noexcept;
32
+
33
+ void MemoryInfo(MemoryTracker* tracker) const override;
34
+ SET_MEMORY_INFO_NAME(KmacConfig)
35
+ SET_SELF_SIZE(KmacConfig)
36
+ };
37
+
38
+ struct KmacTraits final {
39
+ using AdditionalParameters = KmacConfig;
40
+ static constexpr const char* JobName = "KmacJob";
41
+ static constexpr AsyncWrap::ProviderType Provider =
42
+ AsyncWrap::PROVIDER_SIGNREQUEST;
43
+
44
+ static v8::Maybe<void> AdditionalConfig(
45
+ CryptoJobMode mode,
46
+ const v8::FunctionCallbackInfo<v8::Value>& args,
47
+ unsigned int offset,
48
+ KmacConfig* params);
49
+
50
+ static bool DeriveBits(Environment* env,
51
+ const KmacConfig& params,
52
+ ByteSource* out,
53
+ CryptoJobMode mode,
54
+ CryptoErrorStore* errors);
55
+
56
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
57
+ const KmacConfig& params,
58
+ ByteSource* out);
59
+ };
60
+
61
+ using KmacJob = DeriveBitsJob<KmacTraits>;
62
+
63
+ namespace Kmac {
64
+ void Initialize(Environment* env, v8::Local<v8::Object> target);
65
+ void RegisterExternalReferences(ExternalReferenceRegistry* registry);
66
+ } // namespace Kmac
67
+
68
+ #else
69
+ // If there is no KMAC support, provide empty namespace functions.
70
+ namespace Kmac {
71
+ void Initialize(Environment* env, v8::Local<v8::Object> target) {}
72
+ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {}
73
+ } // namespace Kmac
74
+ #endif // OPENSSL_WITH_EVP_MAC
75
+
76
+ } // namespace node::crypto
77
+
78
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
79
+ #endif // SRC_CRYPTO_CRYPTO_KMAC_H_
@@ -0,0 +1,76 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_PBKDF2_H_
2
+ #define SRC_CRYPTO_CRYPTO_PBKDF2_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "async_wrap.h"
7
+ #include "crypto/crypto_keys.h"
8
+ #include "crypto/crypto_util.h"
9
+ #include "env.h"
10
+ #include "memory_tracker.h"
11
+ #include "v8.h"
12
+
13
+ namespace node {
14
+ namespace crypto {
15
+ // PBKDF2 is a pseudo-random key derivation scheme defined
16
+ // in https://tools.ietf.org/html/rfc8018
17
+ //
18
+ // The algorithm takes as input a password and salt
19
+ // (both of which may, but should not be zero-length),
20
+ // a number of iterations, a hash digest algorithm, and
21
+ // an output length.
22
+ //
23
+ // The salt should be as unique as possible, and should
24
+ // be at least 16 bytes in length.
25
+ //
26
+ // The iteration count should be as high as possible.
27
+
28
+ struct PBKDF2Config final : public MemoryRetainer {
29
+ KeyObjectData key;
30
+ ByteSource pass;
31
+ ByteSource salt;
32
+ int32_t iterations;
33
+ int32_t length;
34
+ ncrypto::Digest digest;
35
+
36
+ PBKDF2Config() = default;
37
+
38
+ explicit PBKDF2Config(PBKDF2Config&& other) noexcept;
39
+
40
+ PBKDF2Config& operator=(PBKDF2Config&& other) noexcept;
41
+
42
+ void MemoryInfo(MemoryTracker* tracker) const override;
43
+ SET_MEMORY_INFO_NAME(PBKDF2Config)
44
+ SET_SELF_SIZE(PBKDF2Config)
45
+ };
46
+
47
+ struct PBKDF2Traits final {
48
+ using AdditionalParameters = PBKDF2Config;
49
+ static constexpr const char* JobName = "PBKDF2Job";
50
+ static constexpr AsyncWrap::ProviderType Provider =
51
+ AsyncWrap::PROVIDER_PBKDF2REQUEST;
52
+
53
+ static v8::Maybe<void> AdditionalConfig(
54
+ CryptoJobMode mode,
55
+ const v8::FunctionCallbackInfo<v8::Value>& args,
56
+ unsigned int offset,
57
+ PBKDF2Config* params);
58
+
59
+ static bool DeriveBits(Environment* env,
60
+ const PBKDF2Config& params,
61
+ ByteSource* out,
62
+ CryptoJobMode mode,
63
+ CryptoErrorStore* errors);
64
+
65
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
66
+ const PBKDF2Config& params,
67
+ ByteSource* out);
68
+ };
69
+
70
+ using PBKDF2Job = DeriveBitsJob<PBKDF2Traits>;
71
+
72
+ } // namespace crypto
73
+ } // namespace node
74
+
75
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
76
+ #endif // SRC_CRYPTO_CRYPTO_PBKDF2_H_
@@ -0,0 +1,39 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_PQC_H_
2
+ #define SRC_CRYPTO_CRYPTO_PQC_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "crypto/crypto_keys.h"
7
+ #include "env.h"
8
+ #include "v8.h"
9
+
10
+ namespace node {
11
+ namespace crypto {
12
+ #if OPENSSL_WITH_PQC
13
+ bool ExportJwkPqcKey(Environment* env,
14
+ const KeyObjectData& key,
15
+ v8::Local<v8::Object> target);
16
+
17
+ KeyObjectData ImportJWKPqcKey(Environment* env, v8::Local<v8::Object> jwk);
18
+
19
+ // Returns true for PQC algorithms that support raw private key export/import.
20
+ bool IsPqcRawPrivateKeyId(int id);
21
+ // Returns true if the given EVP_PKEY id is a PQC algorithm known to Node.
22
+ bool IsPqcKeyId(int id);
23
+ // Returns true for PQC algorithms that carry the private key as a seed
24
+ // (ML-DSA, ML-KEM). Returns false for algorithms that use the expanded
25
+ // private key (SLH-DSA), or for non-PQC ids.
26
+ bool IsPqcSeedKeyId(int id);
27
+ // Returns true for PQC signature algorithms (ML-DSA, SLH-DSA). Returns false
28
+ // for ML-KEM or for non-PQC ids.
29
+ bool IsPqcSignatureKeyId(int id);
30
+ // Returns the EVP_PKEY id for the given PQC algorithm name, or NID_undef.
31
+ int GetPqcNidFromName(const char* name);
32
+ // Returns the JS asymmetricKeyType string for a PQC id, or undefined.
33
+ v8::Local<v8::Value> GetPqcAsymmetricKeyType(Environment* env, int id);
34
+ #endif
35
+ } // namespace crypto
36
+ } // namespace node
37
+
38
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
39
+ #endif // SRC_CRYPTO_CRYPTO_PQC_H_
@@ -0,0 +1,127 @@
1
+ #ifndef SRC_CRYPTO_CRYPTO_RANDOM_H_
2
+ #define SRC_CRYPTO_CRYPTO_RANDOM_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object.h"
7
+ #include "crypto/crypto_util.h"
8
+ #include "env.h"
9
+ #include "memory_tracker.h"
10
+ #include "node_internals.h"
11
+ #include "v8.h"
12
+
13
+ namespace node {
14
+ namespace crypto {
15
+ struct RandomBytesConfig final : public MemoryRetainer {
16
+ unsigned char* buffer;
17
+ size_t size;
18
+ SET_NO_MEMORY_INFO()
19
+ SET_MEMORY_INFO_NAME(RandomBytesConfig)
20
+ SET_SELF_SIZE(RandomBytesConfig)
21
+ };
22
+
23
+ struct RandomBytesTraits final {
24
+ using AdditionalParameters = RandomBytesConfig;
25
+ static constexpr const char* JobName = "RandomBytesJob";
26
+ static constexpr AsyncWrap::ProviderType Provider =
27
+ AsyncWrap::PROVIDER_RANDOMBYTESREQUEST;
28
+
29
+ static v8::Maybe<void> AdditionalConfig(
30
+ CryptoJobMode mode,
31
+ const v8::FunctionCallbackInfo<v8::Value>& args,
32
+ unsigned int offset,
33
+ RandomBytesConfig* params);
34
+
35
+ static bool DeriveBits(Environment* env,
36
+ const RandomBytesConfig& params,
37
+ ByteSource* out_,
38
+ CryptoJobMode mode,
39
+ CryptoErrorStore* errors);
40
+
41
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
42
+ const RandomBytesConfig& params,
43
+ ByteSource* unused);
44
+ };
45
+
46
+ using RandomBytesJob = DeriveBitsJob<RandomBytesTraits>;
47
+
48
+ struct RandomPrimeConfig final : public MemoryRetainer {
49
+ ncrypto::BignumPointer prime;
50
+ ncrypto::BignumPointer rem;
51
+ ncrypto::BignumPointer add;
52
+ int bits;
53
+ bool safe;
54
+ void MemoryInfo(MemoryTracker* tracker) const override;
55
+ SET_MEMORY_INFO_NAME(RandomPrimeConfig)
56
+ SET_SELF_SIZE(RandomPrimeConfig)
57
+ };
58
+
59
+ struct RandomPrimeTraits final {
60
+ using AdditionalParameters = RandomPrimeConfig;
61
+ static constexpr const char* JobName = "RandomPrimeJob";
62
+ static constexpr AsyncWrap::ProviderType Provider =
63
+ AsyncWrap::PROVIDER_RANDOMPRIMEREQUEST;
64
+
65
+ static v8::Maybe<void> AdditionalConfig(
66
+ CryptoJobMode mode,
67
+ const v8::FunctionCallbackInfo<v8::Value>& args,
68
+ unsigned int offset,
69
+ RandomPrimeConfig* params);
70
+
71
+ static bool DeriveBits(Environment* env,
72
+ const RandomPrimeConfig& params,
73
+ ByteSource* out_,
74
+ CryptoJobMode mode,
75
+ CryptoErrorStore* errors);
76
+
77
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
78
+ const RandomPrimeConfig& params,
79
+ ByteSource* unused);
80
+ };
81
+
82
+ using RandomPrimeJob = DeriveBitsJob<RandomPrimeTraits>;
83
+
84
+ struct CheckPrimeConfig final : public MemoryRetainer {
85
+ ncrypto::BignumPointer candidate;
86
+ int checks = 1;
87
+
88
+ void MemoryInfo(MemoryTracker* tracker) const override;
89
+ SET_MEMORY_INFO_NAME(CheckPrimeConfig)
90
+ SET_SELF_SIZE(CheckPrimeConfig)
91
+ };
92
+
93
+ struct CheckPrimeTraits final {
94
+ using AdditionalParameters = CheckPrimeConfig;
95
+ static constexpr const char* JobName = "CheckPrimeJob";
96
+
97
+ static constexpr AsyncWrap::ProviderType Provider =
98
+ AsyncWrap::PROVIDER_CHECKPRIMEREQUEST;
99
+
100
+ static v8::Maybe<void> AdditionalConfig(
101
+ CryptoJobMode mode,
102
+ const v8::FunctionCallbackInfo<v8::Value>& args,
103
+ unsigned int offset,
104
+ CheckPrimeConfig* params);
105
+
106
+ static bool DeriveBits(Environment* env,
107
+ const CheckPrimeConfig& params,
108
+ ByteSource* out,
109
+ CryptoJobMode mode,
110
+ CryptoErrorStore* errors);
111
+
112
+ static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
113
+ const CheckPrimeConfig& params,
114
+ ByteSource* out);
115
+ };
116
+
117
+ using CheckPrimeJob = DeriveBitsJob<CheckPrimeTraits>;
118
+
119
+ namespace Random {
120
+ void Initialize(Environment* env, v8::Local<v8::Object> target);
121
+ void RegisterExternalReferences(ExternalReferenceRegistry* registry);
122
+ } // namespace Random
123
+ } // namespace crypto
124
+ } // namespace node
125
+
126
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
127
+ #endif // SRC_CRYPTO_CRYPTO_RANDOM_H_