Skip to content

Commit bfe0b46

Browse files
tniessendanielleadams
authored andcommitted
src: simplify calls to BN_bin2bn in prime gen
PR-URL: #37169 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 745aad7 commit bfe0b46

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/crypto/crypto_random.cc

+4-12
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,21 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
104104
bool safe = args[offset + 1]->IsTrue();
105105

106106
if (!args[offset + 2]->IsUndefined()) {
107-
params->add.reset(BN_secure_new());
107+
ArrayBufferOrViewContents<unsigned char> add(args[offset + 2]);
108+
params->add.reset(BN_bin2bn(add.data(), add.size(), nullptr));
108109
if (!params->add) {
109110
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
110111
return Nothing<bool>();
111112
}
112-
ArrayBufferOrViewContents<unsigned char> add(args[offset + 2]);
113-
if (BN_bin2bn(add.data(), add.size(), params->add.get()) == nullptr) {
114-
THROW_ERR_INVALID_ARG_VALUE(env, "invalid options.add");
115-
return Nothing<bool>();
116-
}
117113
}
118114

119115
if (!args[offset + 3]->IsUndefined()) {
120-
params->rem.reset(BN_secure_new());
116+
ArrayBufferOrViewContents<unsigned char> rem(args[offset + 3]);
117+
params->rem.reset(BN_bin2bn(rem.data(), rem.size(), nullptr));
121118
if (!params->rem) {
122119
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
123120
return Nothing<bool>();
124121
}
125-
ArrayBufferOrViewContents<unsigned char> rem(args[offset + 3]);
126-
if (BN_bin2bn(rem.data(), rem.size(), params->rem.get()) == nullptr) {
127-
THROW_ERR_INVALID_ARG_VALUE(env, "invalid options.rem");
128-
return Nothing<bool>();
129-
}
130122
}
131123

132124
int bits = static_cast<int>(size);

0 commit comments

Comments
 (0)