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:23:00 +0000 (12:23 +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)

(cherry picked from commit 706512ecbc31585d447b53c3aa89acdf6951f996)

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

index 4e9705beef733be699a249432217baefcc846ff1..fb9ef5dd7c5e48cf6db6278380d904b51e8ce1fc 100644 (file)
@@ -190,7 +190,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 29cda5d7bfa845272f45aaa71d55321e28146ea6..57ea2ee49243f3de22d71b42f0784ff88698ff1e 100644 (file)
@@ -116,6 +116,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 ccc70165921764f6d34a4fafa93a4242b4d68934..ebe3685d46020d2bb90756082e845e877864e9f6 100644 (file)
@@ -176,6 +176,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 62f7c70149f4fb305986264714c80373fd8c8ad5..8fd66a950e37399af9e11fd2f4a97665b3dc4e7d 100644 (file)
@@ -441,7 +441,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;
 }