Skip to content

Commit

Permalink
src: remove INT_MAX asserts in SecretKeyGenTraits
Browse files Browse the repository at this point in the history
Now that CSPRNG() does not silently fail when the length exceeds
INT_MAX anymore, there is no need for the two relevant assertions
in SecretKeyGenTraits anymore.

Refs: nodejs#47515
  • Loading branch information
tniessen committed May 17, 2023
1 parent 62fd6bc commit 68d7197
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/crypto/crypto_keygen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,13 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
SecretKeyGenConfig* params) {
CHECK(args[*offset]->IsUint32());
uint32_t bits = args[*offset].As<Uint32>()->Value();
static_assert(std::numeric_limits<decltype(bits)>::max() / CHAR_BIT <=
INT_MAX);
params->length = bits / CHAR_BIT;
*offset += 1;
return Just(true);
}

KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(
Environment* env,
SecretKeyGenConfig* params) {
CHECK_LE(params->length, INT_MAX);
KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(Environment* env,
SecretKeyGenConfig* params) {
ByteSource::Builder bytes(params->length);
if (CSPRNG(bytes.data<unsigned char>(), params->length).is_err())
return KeyGenJobStatus::FAILED;
Expand Down

0 comments on commit 68d7197

Please sign in to comment.