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 Node.js GitHub Bot committed 2026-10-07 13:36:34 +00:00
1 parent aa8d6b9384
commit bacbcdcf0a
1 file changed
-1
-1
View File
@@ -1053,7 +1053,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)