Dont require CRT params on ossl_rsa_set0_all_params
authorNeil Horman <nhorman@openssl.org>
Tue, 10 Oct 2023 15:06:44 +0000 (11:06 -0400)
committerTomas Mraz <tomas@openssl.org>
Wed, 18 Oct 2023 16:08:02 +0000 (18:08 +0200)
Its not required that crt params be available in an RSA key, so don't
perform an error check on them

Fixes #29135

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22334)

crypto/rsa/rsa_lib.c

index db77a6fd49ee8e86f6a60e866cfcc0411f4ac12f..9548054da7bd7d743bae08256eac2b6f32193aaf 100644 (file)
@@ -757,18 +757,22 @@ int ossl_rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes,
         return 0;
 
     pnum = sk_BIGNUM_num(primes);
-    if (pnum < 2
-        || pnum != sk_BIGNUM_num(exps)
-        || pnum != sk_BIGNUM_num(coeffs) + 1)
+    if (pnum < 2)
         return 0;
 
     if (!RSA_set0_factors(r, sk_BIGNUM_value(primes, 0),
-                          sk_BIGNUM_value(primes, 1))
-        || !RSA_set0_crt_params(r, sk_BIGNUM_value(exps, 0),
-                                sk_BIGNUM_value(exps, 1),
-                                sk_BIGNUM_value(coeffs, 0)))
+                          sk_BIGNUM_value(primes, 1)))
         return 0;
 
+    if (pnum == sk_BIGNUM_num(exps)
+        && pnum == sk_BIGNUM_num(coeffs) + 1) {
+
+        if (!RSA_set0_crt_params(r, sk_BIGNUM_value(exps, 0),
+                                 sk_BIGNUM_value(exps, 1),
+                                 sk_BIGNUM_value(coeffs, 0)))
+        return 0;
+    }
+
 #ifndef FIPS_MODULE
     old_infos = r->prime_infos;
 #endif