crypto: skip secret key mutex allocation

Secret key bytes are immutable after KeyObjectData construction. AES,
ChaCha20-Poly1305, MAC, and KDF jobs read those bytes without acquiring
KeyObjectData::mutex(), and secret-key export and equality do the same.

Do not allocate a shared mutex that none of these operations uses.
Asymmetric key mutex initialization remains eager so copies continue to
share the same lock while asymmetric acquisitions remain.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66413
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Filip Skokan authored and Antoine du Hamel committed 2026-11-11 17:28:03 +01:00
1 parent 24f9a39d6a
commit c1ed8024f0
1 file changed
-1
-1
View File
@@ -1047,7 +1047,6 @@ KeyObjectData::KeyObjectData(std::nullptr_t)
KeyObjectData::KeyObjectData(ByteSource symmetric_key)
: key_type_(KeyType::kKeyTypeSecret),
mutex_(std::make_shared<Mutex>()),
data_(std::make_shared<Data>(std::move(symmetric_key))) {}
KeyObjectData::KeyObjectData(KeyType type, EVPKeyPointer&& pkey)