Don't (re-)initialize the FFC_PARAMs in dh_init and dsa_init
authorMatthias St. Pierre <matthias.st.pierre@ncp-e.com>
Mon, 2 Oct 2023 10:10:01 +0000 (12:10 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 4 Oct 2023 10:22:04 +0000 (12:22 +0200)
The initialization was introduced in commit dc8de3e6f1ee and
changes the behaviour of the `init` method for DSA and DH
between 1.1.1 and 3.0, while the behaviour for RSA and EC_KEY
remains unchanged.

The initialization is not necessary in 3.x and master imho and
breaks the use-case of intercepting the methods of an existing
key.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22185)

crypto/dh/dh_key.c
crypto/dh/dh_lib.c
crypto/dsa/dsa_lib.c
crypto/dsa/dsa_ossl.c

index bc26cee303e970e2eccc6a082e37bc5a325a9786..8ab75e06d719e03005dfcb98ed7bd2ce0f01b8d9 100644 (file)
@@ -194,7 +194,6 @@ static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
 static int dh_init(DH *dh)
 {
     dh->flags |= DH_FLAG_CACHE_MONT_P;
-    ossl_ffc_params_init(&dh->params);
     dh->dirty_cnt++;
     return 1;
 }
index e2eb53961cb6593d070d20824de2bbf8ac50343e..9d5a6b0b6c2baa7951fdf770ce70057cdfba023b 100644 (file)
@@ -119,6 +119,8 @@ static DH *dh_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx)
         goto err;
 #endif /* FIPS_MODULE */
 
+    ossl_ffc_params_init(&ret->params);
+
     if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
         ERR_raise(ERR_LIB_DH, ERR_R_INIT_FAIL);
         goto err;
index b18fda33782705c055c245f193d7d05df38acb91..7997c2ac25e459d04acf71828864ed3ac3a5f939 100644 (file)
@@ -179,6 +179,8 @@ static DSA *dsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx)
         goto err;
 #endif
 
+    ossl_ffc_params_init(&ret->params);
+
     if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
         ERR_raise(ERR_LIB_DSA, ERR_R_INIT_FAIL);
         goto err;
index 29e2a8057250b16d40c0b7a9595e4496869433f7..234362b6d7499b9ab7098a14a51e0c2e6318d7e2 100644 (file)
@@ -462,7 +462,6 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len,
 static int dsa_init(DSA *dsa)
 {
     dsa->flags |= DSA_FLAG_CACHE_MONT_P;
-    ossl_ffc_params_init(&dsa->params);
     dsa->dirty_cnt++;
     return 1;
 }