Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: hide kMaxDigestMultiplier outside HKDF impl #46206

Merged
merged 1 commit into from Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/crypto/crypto_hkdf.cc
Expand Up @@ -87,6 +87,10 @@ Maybe<bool> HKDFTraits::AdditionalConfig(
: info.ToByteSource();

params->length = args[offset + 4].As<Uint32>()->Value();
// HKDF-Expand computes up to 255 HMAC blocks, each having as many bits as the
// output of the hash function. 255 is a hard limit because HKDF appends an
// 8-bit counter to each HMAC'd message, starting at 1.
constexpr size_t kMaxDigestMultiplier = 255;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It might be better suited to make this a static, but just as suggestion.

Copy link
Member Author

@tniessen tniessen Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was static before and I intentionally removed the keyword. Could you elaborate on why static would be beneficial here?

My understanding is that since kMaxDigestMultiplier is not ODR-used, not making it static allows the compiler to completely eliminate any storage space for it, but I might be wrong about this.

size_t max_length = EVP_MD_size(params->digest) * kMaxDigestMultiplier;
if (params->length > max_length) {
THROW_ERR_CRYPTO_INVALID_KEYLEN(env);
Expand Down
2 changes: 0 additions & 2 deletions src/crypto/crypto_hkdf.h
Expand Up @@ -11,8 +11,6 @@

namespace node {
namespace crypto {
static constexpr size_t kMaxDigestMultiplier = 255;

struct HKDFConfig final : public MemoryRetainer {
CryptoJobMode mode;
size_t length;
Expand Down