DH: Move the code to set the DH sub-type
authorRichard Levitte <levitte@openssl.org>
Mon, 26 Oct 2020 12:59:09 +0000 (13:59 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 11 Nov 2020 10:42:06 +0000 (11:42 +0100)
It's been moved so the type is set by d2i_DHparams() and d2i_DHxparams()

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13248)

crypto/dh/dh_ameth.c
crypto/dh/dh_asn1.c

index 49e65e4d6c8db37bfcdedfe90a67ff4c90a82d11..1efbb403cbe73aa2dd462d90fabb86fe3e558242 100644 (file)
@@ -42,10 +42,6 @@ static DH *d2i_dhp(const EVP_PKEY *pkey, const unsigned char **pp,
     else
         dh = d2i_DHparams(NULL, pp, length);
 
-    if (dh != NULL) {
-        DH_clear_flags(dh, DH_FLAG_TYPE_MASK);
-        DH_set_flags(dh, is_dhx ? DH_FLAG_TYPE_DHX : DH_FLAG_TYPE_DH);
-    }
     return dh;
 }
 
index cf5c735a6ad577f61088b7b8541304483fbf37c5..81899de5d65778b06468e9c081ede599c961022b 100644 (file)
@@ -34,7 +34,11 @@ static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
         *pval = NULL;
         return 2;
     } else if (operation == ASN1_OP_D2I_POST) {
-        ((DH *)*pval)->dirty_cnt++;
+        DH *dh = (DH *)*pval;
+
+        DH_clear_flags(dh, DH_FLAG_TYPE_MASK);
+        DH_set_flags(dh, DH_FLAG_TYPE_DH);
+        dh->dirty_cnt++;
     }
     return 1;
 }
@@ -123,6 +127,8 @@ DH *d2i_DHxparams(DH **a, const unsigned char **pp, long length)
     }
 
     OPENSSL_free(dhx);
+    DH_clear_flags(dh, DH_FLAG_TYPE_MASK);
+    DH_set_flags(dh, DH_FLAG_TYPE_DHX);
     return dh;
 }