From b2b995ec2d95a67b9c21012a25cadd94e15e6a17 Mon Sep 17 00:00:00 2001 From: Peiwei Hu Date: Sun, 27 Oct 2024 17:37:48 +0800 Subject: [PATCH] Fix multiple wrong use of BN_check_prime Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/25811) --- apps/prime.c | 8 ++++++-- test/bntest.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/prime.c b/apps/prime.c index a03909c411..23b7e462fc 100644 --- a/apps/prime.c +++ b/apps/prime.c @@ -145,10 +145,14 @@ opthelp: } BN_print(bio_out, bn); + r = BN_check_prime(bn, NULL, NULL); + if (r < 0) { + BIO_printf(bio_err, "Error checking prime\n"); + goto end; + } BIO_printf(bio_out, " (%s) %s prime\n", argv[0], - BN_check_prime(bn, NULL, NULL) - ? "is" : "is not"); + r == 1 ? "is" : "is not"); } } diff --git a/test/bntest.c b/test/bntest.c index 2c7b91fad9..3b3671a622 100644 --- a/test/bntest.c +++ b/test/bntest.c @@ -2703,7 +2703,7 @@ static int test_not_prime(int i) for (trial = 0; trial <= 1; ++trial) { if (!TEST_true(BN_set_word(r, not_primes[i])) - || !TEST_false(BN_check_prime(r, ctx, NULL))) + || !TEST_int_eq(BN_check_prime(r, ctx, NULL), 0)) goto err; }