Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/crypto/crypto_dh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ void ComputeSecret(const FunctionCallbackInfo<Value>& args) {
}

auto dp = dh.computeSecret(key);
if (!dp) {
return THROW_ERR_CRYPTO_OPERATION_FAILED(env,
"Failed to compute shared secret");
}

Local<Value> buffer;
if (DataPointerToBuffer(env, std::move(dp)).ToLocal(&buffer)) {
Expand All @@ -354,8 +358,8 @@ void SetPublicKey(const FunctionCallbackInfo<Value>& args) {
if (!buf.CheckSizeInt32()) [[unlikely]]
return THROW_ERR_OUT_OF_RANGE(env, "buf is too big");
BignumPointer num(buf.data(), buf.size());
CHECK(num);
CHECK(dh.setPublicKey(std::move(num)));
if (!num || !dh.setPublicKey(std::move(num)))
return THROW_ERR_INVALID_ARG_VALUE(env, "Invalid public key");
}

void SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
Expand All @@ -368,8 +372,8 @@ void SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
if (!buf.CheckSizeInt32()) [[unlikely]]
return THROW_ERR_OUT_OF_RANGE(env, "buf is too big");
BignumPointer num(buf.data(), buf.size());
CHECK(num);
CHECK(dh.setPrivateKey(std::move(num)));
if (!num || !dh.setPrivateKey(std::move(num)))
return THROW_ERR_INVALID_ARG_VALUE(env, "Invalid private key");
}

void Check(const FunctionCallbackInfo<Value>& args) {
Expand Down
5 changes: 4 additions & 1 deletion src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,13 @@ 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)
: key_type_(type), data_(std::make_shared<Data>(std::move(pkey))) {}
: key_type_(type),
mutex_(std::make_shared<Mutex>()),
data_(std::make_shared<Data>(std::move(pkey))) {}

void KeyObjectData::Data::MemoryInfo(MemoryTracker* tracker) const {
if (asymmetric_key) {
Expand Down
12 changes: 10 additions & 2 deletions src/crypto/crypto_turboshake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,11 @@ bool TurboShakeTraits::DeriveBits(Environment* env,
CryptoJobMode mode,
CryptoErrorStore* errors) {
CHECK_GT(params.output_length, 0);
char* buf = MallocOpenSSL<char>(params.output_length);
char* buf = static_cast<char*>(OPENSSL_malloc(params.output_length));
if (buf == nullptr) {
errors->Insert(NodeCryptoError::ALLOCATION_FAILED);
return false;
}

const uint8_t* input = reinterpret_cast<const uint8_t*>(params.data.data());
size_t input_len = params.data.size();
Expand Down Expand Up @@ -595,7 +599,11 @@ bool KangarooTwelveTraits::DeriveBits(Environment* env,
return false;
}

char* buf = MallocOpenSSL<char>(params.output_length);
char* buf = static_cast<char*>(OPENSSL_malloc(params.output_length));
if (buf == nullptr) {
errors->Insert(NodeCryptoError::ALLOCATION_FAILED);
return false;
}

switch (params.variant) {
case KangarooTwelveVariant::KT128:
Expand Down
Loading