Commit 85bb26e3a2 for openssl.org

commit 85bb26e3a2389ad643a4cc8b017327d1ea8ac6a5
Author: rezhboyu <evan9971@gmail.com>
Date:   Wed Mar 11 02:31:06 2026 +0800

    refactor: remove redundant p/q retrieval in ossl_rsa_fromdata

    The p and q parameters were being retrieved into local BIGNUM variables

    but never actually used. This change removes the excess retrieval to improve maintainability, following the discussion in PR #30298.

    Resolves #30340

    Reviewed-by: Paul Dale <paul.dale@oracle.com>
    Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
    Reviewed-by: Richard Levitte <levitte@openssl.org>
    Reviewed-by: Matt Caswell <matt@openssl.foundation>
    MergeDate: Thu Mar 12 10:32:24 2026
    (Merged from https://github.com/openssl/openssl/pull/30353)

diff --git a/crypto/rsa/rsa_backend.c b/crypto/rsa/rsa_backend.c
index 80d9c2132a..00b4880c80 100644
--- a/crypto/rsa/rsa_backend.c
+++ b/crypto/rsa/rsa_backend.c
@@ -64,9 +64,8 @@ static int collect_numbers(STACK_OF(BIGNUM) *numbers,
 int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[], int include_private)
 {
     const OSSL_PARAM *param_n, *param_e, *param_d = NULL;
-    const OSSL_PARAM *param_p, *param_q = NULL;
     const OSSL_PARAM *param_derive = NULL;
-    BIGNUM *p = NULL, *q = NULL, *n = NULL, *e = NULL, *d = NULL;
+    BIGNUM *n = NULL, *e = NULL, *d = NULL;
     STACK_OF(BIGNUM) *factors = NULL, *exps = NULL, *coeffs = NULL;
     int is_private = 0;
     int derive_from_pq = 0;
@@ -104,10 +103,8 @@ int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[], int include_private)
                 goto err;

             /* we need at minimum p, q */
-            param_p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR1);
-            param_q = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR2);
-            if ((param_p == NULL || !OSSL_PARAM_get_BN(param_p, &p))
-                || (param_q == NULL || !OSSL_PARAM_get_BN(param_q, &q))) {
+            if (OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR1) == NULL
+                || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR2) == NULL) {
                 ERR_raise(ERR_LIB_RSA, ERR_R_PASSED_NULL_PARAMETER);
                 goto err;
             }
@@ -234,8 +231,6 @@ int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[], int include_private)
         goto err;
     }

-    BN_clear_free(p);
-    BN_clear_free(q);
     sk_BIGNUM_free(factors);
     sk_BIGNUM_free(exps);
     sk_BIGNUM_free(coeffs);
@@ -246,8 +241,6 @@ err:
     BN_free(n);
     BN_free(e);
     BN_free(d);
-    BN_clear_free(p);
-    BN_clear_free(q);
     sk_BIGNUM_pop_free(factors, BN_clear_free);
     sk_BIGNUM_pop_free(exps, BN_clear_free);
     sk_BIGNUM_pop_free(coeffs, BN_clear_free);