diff options
author | Tobias Nießen <tniessen@tnie.de> | 2021-02-01 16:42:01 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-02-16 17:12:34 +0300 |
commit | bfe0b46d929c81b842ba54258c6a94d2bf22d0c8 (patch) | |
tree | 31af942a139773644b74ecfbf54acbbab9267a2a /src | |
parent | 745aad73dc47a7e2ac5105ca9ae8570fa28672be (diff) |
src: simplify calls to BN_bin2bn in prime gen
PR-URL: https://github.com/nodejs/node/pull/37169
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/crypto/crypto_random.cc | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/crypto/crypto_random.cc b/src/crypto/crypto_random.cc index e5722169486..ceac834cb94 100644 --- a/src/crypto/crypto_random.cc +++ b/src/crypto/crypto_random.cc @@ -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); |