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
13 changes: 3 additions & 10 deletions src/crypto/crypto_aes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
} // namespace

AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
: mode(other.mode),
variant(other.variant),
: variant(other.variant),
cipher(other.cipher),
length(other.length),
iv(std::move(other.iv)),
Expand All @@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
}

void AESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
// If mode is sync, then the data in each of these properties
// is not owned by the AESCipherConfig, so we ignore it.
if (IsCryptoJobAsync(mode)) {
tracker->TrackFieldWithSize("iv", iv.size());
tracker->TrackFieldWithSize("additional_data", additional_data.size());
}
tracker->TraitTrackInline(iv, "iv");
tracker->TraitTrackInline(additional_data, "additional_data");
}

Maybe<void> AESCipherTraits::AdditionalConfig(
Expand All @@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
AESCipherConfig* params) {
Environment* env = Environment::GetCurrent(args);

params->mode = mode;

CHECK(args[offset]->IsUint32()); // Key Variant
params->variant =
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());
Expand Down
1 change: 0 additions & 1 deletion src/crypto/crypto_aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ enum class AESKeyVariant {
};

struct AESCipherConfig final : public MemoryRetainer {
CryptoJobMode mode;
AESKeyVariant variant;
ncrypto::Cipher cipher;
size_t length;
Expand Down
19 changes: 8 additions & 11 deletions src/crypto/crypto_argon2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ using v8::Uint32;
using v8::Value;

Argon2Config::Argon2Config(Argon2Config&& other) noexcept
: mode{other.mode},
key{std::move(other.key)},
: key{std::move(other.key)},
pass{std::move(other.pass)},
salt{std::move(other.salt)},
secret{std::move(other.secret)},
Expand All @@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
}

void Argon2Config::MemoryInfo(MemoryTracker* tracker) const {
if (key) tracker->TrackField("key", key);
if (IsCryptoJobAsync(mode)) {
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
tracker->TrackFieldWithSize("salt", salt.size());
tracker->TrackFieldWithSize("secret", secret.size());
tracker->TrackFieldWithSize("ad", ad.size());
}
if (key)
tracker->TrackField("key", key);
else
tracker->TraitTrackInline(pass, "pass");
tracker->TraitTrackInline(salt, "salt");
tracker->TraitTrackInline(secret, "secret");
tracker->TraitTrackInline(ad, "ad");
}

MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
Expand All @@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
Argon2Config* config) {
Environment* env = Environment::GetCurrent(args);

config->mode = mode;

CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
IsAnyBufferSource(args[offset])); // pass
ArrayBufferOrViewContents<char> salt(args[offset + 1]);
Expand Down
1 change: 0 additions & 1 deletion src/crypto/crypto_argon2.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace node::crypto {
// at least 16 bytes in length.

struct Argon2Config final : public MemoryRetainer {
CryptoJobMode mode;
KeyObjectData key;
ByteSource pass;
ByteSource salt;
Expand Down
12 changes: 3 additions & 9 deletions src/crypto/crypto_chacha20_poly1305.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,

ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
ChaCha20Poly1305CipherConfig&& other) noexcept
: mode(other.mode),
cipher(other.cipher),
: cipher(other.cipher),
iv(std::move(other.iv)),
additional_data(std::move(other.additional_data)) {}

Expand All @@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
}

void ChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
// If mode is sync, then the data in each of these properties
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
if (IsCryptoJobAsync(mode)) {
tracker->TrackFieldWithSize("iv", iv.size());
tracker->TrackFieldWithSize("additional_data", additional_data.size());
}
tracker->TraitTrackInline(iv, "iv");
tracker->TraitTrackInline(additional_data, "additional_data");
}

Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
Expand All @@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
ChaCha20Poly1305CipherConfig* params) {
Environment* env = Environment::GetCurrent(args);

params->mode = mode;
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;

#ifndef OPENSSL_IS_BORINGSSL
Expand Down
1 change: 0 additions & 1 deletion src/crypto/crypto_chacha20_poly1305.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace node::crypto {
constexpr unsigned kChaCha20Poly1305AuthTagLength = 16;

struct ChaCha20Poly1305CipherConfig final : public MemoryRetainer {
CryptoJobMode mode;
ncrypto::Cipher cipher;
ByteSource iv;
ByteSource additional_data;
Expand Down
5 changes: 2 additions & 3 deletions src/crypto/crypto_cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {

SET_SELF_SIZE(CipherJob)
void MemoryInfo(MemoryTracker* tracker) const override {
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
tracker->TrackFieldWithSize("in", in_.size());
tracker->TrackFieldWithSize("out", out_.size());
tracker->TraitTrackInline(in_, "in");
tracker->TraitTrackInline(out_, "out");
CryptoJob<CipherTraits>::MemoryInfo(tracker);
}

Expand Down
26 changes: 7 additions & 19 deletions src/crypto/crypto_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {

void Hash::MemoryInfo(MemoryTracker* tracker) const {
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
tracker->TraitTrackInline(digest_, "md");
}

#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
Expand Down Expand Up @@ -537,10 +537,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
}

HashConfig::HashConfig(HashConfig&& other) noexcept
: mode(other.mode),
in(std::move(other.in)),
digest(other.digest),
length(other.length) {}
: in(std::move(other.in)), digest(other.digest), length(other.length) {}

HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
if (&other == this) return *this;
Expand All @@ -549,8 +546,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
}

void HashConfig::MemoryInfo(MemoryTracker* tracker) const {
// If the Job is sync, then the HashConfig does not own the data.
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
tracker->TraitTrackInline(in, "in");
}

MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
Expand All @@ -566,8 +562,6 @@ Maybe<void> HashTraits::AdditionalConfig(
HashConfig* params) {
Environment* env = Environment::GetCurrent(args);

params->mode = mode;

CHECK(args[offset]->IsString()); // Hash algorithm
Utf8Value digest(env->isolate(), args[offset]);
params->digest = ncrypto::getDigestByName(*digest);
Expand Down Expand Up @@ -796,8 +790,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
} // namespace

CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
: mode(other.mode),
in(std::move(other.in)),
: in(std::move(other.in)),
function_name(std::move(other.function_name)),
customization(std::move(other.customization)),
variant(other.variant),
Expand All @@ -810,12 +803,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
}

void CShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
// If the Job is sync, then the CShakeConfig does not own the data.
if (IsCryptoJobAsync(mode)) {
tracker->TrackFieldWithSize("in", in.size());
tracker->TrackFieldWithSize("function_name", function_name.size());
tracker->TrackFieldWithSize("customization", customization.size());
}
tracker->TraitTrackInline(in, "in");
tracker->TraitTrackInline(function_name, "function_name");
tracker->TraitTrackInline(customization, "customization");
}

MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
Expand All @@ -831,8 +821,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
CShakeConfig* params) {
Environment* env = Environment::GetCurrent(args);

params->mode = mode;

CHECK(args[offset]->IsString()); // Algorithm name
Utf8Value algorithm_name(env->isolate(), args[offset]);
std::string_view algorithm_str = algorithm_name.ToStringView();
Expand Down
2 changes: 0 additions & 2 deletions src/crypto/crypto_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Hash final : public BaseObject {
};

struct HashConfig final : public MemoryRetainer {
CryptoJobMode mode;
ByteSource in;
const EVP_MD* digest;
unsigned int length;
Expand Down Expand Up @@ -108,7 +107,6 @@ struct CShakeParams final {
bool DeriveCShakeBits(const CShakeParams& params, ByteSource* out);

struct CShakeConfig final : public MemoryRetainer {
CryptoJobMode mode;
ByteSource in;
ByteSource function_name;
ByteSource customization;
Expand Down
18 changes: 7 additions & 11 deletions src/crypto/crypto_hkdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ using v8::Value;

namespace crypto {
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
: mode(other.mode),
length(other.length),
: length(other.length),
digest(other.digest),
key(std::move(other.key)),
key_data(std::move(other.key_data)),
Expand All @@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
HKDFConfig* params) {
Environment* env = Environment::GetCurrent(args);

params->mode = mode;

CHECK(args[offset]->IsString()); // Hash
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
IsAnyBufferSource(args[offset + 1])); // Key
Expand Down Expand Up @@ -140,13 +137,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
}

void HKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
if (key) tracker->TrackField("key", key);
// If the job is sync, then the HKDFConfig does not own the data
if (IsCryptoJobAsync(mode)) {
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
tracker->TrackFieldWithSize("salt", salt.size());
tracker->TrackFieldWithSize("info", info.size());
}
if (key)
tracker->TrackField("key", key);
else
tracker->TraitTrackInline(key_data, "key");
tracker->TraitTrackInline(salt, "salt");
tracker->TraitTrackInline(info, "info");
}

} // namespace crypto
Expand Down
1 change: 0 additions & 1 deletion src/crypto/crypto_hkdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace node {
namespace crypto {
struct HKDFConfig final : public MemoryRetainer {
CryptoJobMode mode;
size_t length;
ncrypto::Digest digest;
KeyObjectData key;
Expand Down
12 changes: 3 additions & 9 deletions src/crypto/crypto_hmac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) {
}

HmacConfig::HmacConfig(HmacConfig&& other) noexcept
: job_mode(other.job_mode),
mode(other.mode),
: mode(other.mode),
key(std::move(other.key)),
data(std::move(other.data)),
signature(std::move(other.signature)),
Expand All @@ -169,11 +168,8 @@ HmacConfig& HmacConfig::operator=(HmacConfig&& other) noexcept {

void HmacConfig::MemoryInfo(MemoryTracker* tracker) const {
tracker->TrackField("key", key);
// If the job is sync, then the HmacConfig does not own the data
if (IsCryptoJobAsync(job_mode)) {
tracker->TrackFieldWithSize("data", data.size());
tracker->TrackFieldWithSize("signature", signature.size());
}
tracker->TraitTrackInline(data, "data");
tracker->TraitTrackInline(signature, "signature");
}

Maybe<void> HmacTraits::AdditionalConfig(
Expand All @@ -183,8 +179,6 @@ Maybe<void> HmacTraits::AdditionalConfig(
HmacConfig* params) {
Environment* env = Environment::GetCurrent(args);

params->job_mode = mode;

CHECK(args[offset]->IsUint32()); // SignConfiguration::Mode
params->mode =
static_cast<SignConfiguration::Mode>(args[offset].As<Uint32>()->Value());
Expand Down
1 change: 0 additions & 1 deletion src/crypto/crypto_hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Hmac : public BaseObject {
};

struct HmacConfig final : public MemoryRetainer {
CryptoJobMode job_mode;
SignConfiguration::Mode mode;
KeyObjectData key;
ByteSource data;
Expand Down
Loading
Loading