Skip to content

Commit

Permalink
src: simplify calls to BN_bin2bn in prime gen
Browse files Browse the repository at this point in the history
PR-URL: #37169
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
tniessen authored and danielleadams committed Feb 16, 2021
1 parent 745aad7 commit bfe0b46
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/crypto/crypto_random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,21 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
bool safe = args[offset + 1]->IsTrue();

if (!args[offset + 2]->IsUndefined()) {
params->add.reset(BN_secure_new());
ArrayBufferOrViewContents<unsigned char> add(args[offset + 2]);
params->add.reset(BN_bin2bn(add.data(), add.size(), nullptr));
if (!params->add) {
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
return Nothing<bool>();
}
ArrayBufferOrViewContents<unsigned char> add(args[offset + 2]);
if (BN_bin2bn(add.data(), add.size(), params->add.get()) == nullptr) {
THROW_ERR_INVALID_ARG_VALUE(env, "invalid options.add");
return Nothing<bool>();
}
}

if (!args[offset + 3]->IsUndefined()) {
params->rem.reset(BN_secure_new());
ArrayBufferOrViewContents<unsigned char> rem(args[offset + 3]);
params->rem.reset(BN_bin2bn(rem.data(), rem.size(), nullptr));
if (!params->rem) {
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
return Nothing<bool>();
}
ArrayBufferOrViewContents<unsigned char> rem(args[offset + 3]);
if (BN_bin2bn(rem.data(), rem.size(), params->rem.get()) == nullptr) {
THROW_ERR_INVALID_ARG_VALUE(env, "invalid options.rem");
return Nothing<bool>();
}
}

int bits = static_cast<int>(size);
Expand Down

0 comments on commit bfe0b46

Please sign in to comment.