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: #47515
PR-URL: #48053
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
  • Loading branch information
tniessen authored May 24, 2023
1 parent 6599cfe commit c3b84f1
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 c3b84f1

Please sign in to comment.