Tolerate a null BN_CTX in BN_primality_test.
This used to work, but I broke it on accident in the recent rewrite. Change-Id: I06ab5e06eb0c0a6b67ecc97919654e386f3c2198 Reviewed-on: https://boringssl-review.googlesource.com/26984 Commit-Queue: David Benjamin <davidben@google.com> Commit-Queue: Martin Kreichgauer <martinkr@google.com> Reviewed-by: Martin Kreichgauer <martinkr@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
committed by
CQ bot account: commit-bot@chromium.org
parent
7a62ab1938
commit
ba9da449a4
@@ -2031,6 +2031,13 @@ TEST_F(BNTest, PrimeChecking) {
|
||||
&result_3, p.get(), BN_prime_checks, ctx(), nullptr /* callback */));
|
||||
EXPECT_EQ(bn_composite, result_3);
|
||||
}
|
||||
|
||||
// BN_primality_test works with null |BN_CTX|.
|
||||
ASSERT_TRUE(BN_set_word(p.get(), 5));
|
||||
ASSERT_TRUE(BN_primality_test(
|
||||
&is_probably_prime_1, p.get(), BN_prime_checks, nullptr /* ctx */,
|
||||
false /* do_trial_division */, nullptr /* callback */));
|
||||
EXPECT_EQ(1, is_probably_prime_1);
|
||||
}
|
||||
|
||||
TEST_F(BNTest, NumBitsWord) {
|
||||
|
||||
@@ -647,6 +647,15 @@ int BN_primality_test(int *is_probably_prime, const BIGNUM *w,
|
||||
iterations = BN_prime_checks_for_size(BN_num_bits(w));
|
||||
}
|
||||
|
||||
BN_CTX *new_ctx = NULL;
|
||||
if (ctx == NULL) {
|
||||
new_ctx = BN_CTX_new();
|
||||
if (new_ctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ctx = new_ctx;
|
||||
}
|
||||
|
||||
// See C.3.1 from FIPS 186-4.
|
||||
int ret = 0;
|
||||
BN_MONT_CTX *mont = NULL;
|
||||
@@ -792,6 +801,7 @@ int BN_primality_test(int *is_probably_prime, const BIGNUM *w,
|
||||
err:
|
||||
BN_MONT_CTX_free(mont);
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user