rsa_get0_all_params(): Allow zero CRT params
authorRichard Levitte <levitte@openssl.org>
Mon, 2 Dec 2019 10:25:47 +0000 (11:25 +0100)
committerRichard Levitte <levitte@openssl.org>
Sat, 22 Feb 2020 00:07:15 +0000 (01:07 +0100)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/10557)

crypto/rsa/rsa_ameth.c
crypto/rsa/rsa_lib.c

index 71aa435bd72b1aa81abe53f56c75707b0dcb3af3..f34eacf552b2478c2fd25b92ed62e704da326cf7 100644 (file)
@@ -1120,7 +1120,13 @@ static int rsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
         numexps = sk_BIGNUM_const_num(exps);
         numcoeffs = sk_BIGNUM_const_num(coeffs);
 
-        if (numprimes < 2 || numexps < 2 || numcoeffs < 1)
+        /*
+         * It's permisssible to have zero primes, i.e. no CRT params.
+         * Otherwise, there must be at least two, as many exponents,
+         * and one coefficient less.
+         */
+        if (numprimes != 0
+            && (numprimes < 2 || numexps < 2 || numcoeffs < 1))
             goto err;
 
         /* assert that an OSSL_PARAM_BLD has enough space. */
index 39d7f5f54afbd0d8e6dbbc82f780734d63302eb9..08ce8b4ef81efd4d4f7cf36eed9cb6457eee5d1c 100644 (file)
@@ -780,6 +780,10 @@ int rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes,
     if (r == NULL)
         return 0;
 
+    /* If |p| is NULL, there are no CRT parameters */
+    if (RSA_get0_p(r) == NULL)
+        return 1;
+
     sk_BIGNUM_const_push(primes, RSA_get0_p(r));
     sk_BIGNUM_const_push(primes, RSA_get0_q(r));
     sk_BIGNUM_const_push(exps, RSA_get0_dmp1(r));