Fix error propagatation in BN_check_prime()

BN_check_prime() is supposed to return 0 for a composite number and -1
on error. Properly translate the return value of the internal function
ossl_bn_miller_rabin_is_prime(), where 0 means an error.

The confusion prevented BN_GENCB callbacks from aborting the primality
test or key generation routines utilizing this.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19314)
This commit is contained in:
Kazuki Yamaguchi 2022-09-30 20:33:08 +09:00 committed by Pauli
parent 47cd0e5b1f
commit 0b3867634f

View File

@ -308,9 +308,10 @@ static int bn_is_prime_int(const BIGNUM *w, int checks, BN_CTX *ctx,
goto err;
#endif
ret = ossl_bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);
if (!ret)
if (!ossl_bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status)) {
ret = -1;
goto err;
}
ret = (status == BN_PRIMETEST_PROBABLY_PRIME);
err:
#ifndef FIPS_MODULE