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: simplify calls to BN_bin2bn in prime gen #37169

Closed
wants to merge 1 commit into from
Closed
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
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