Make the naming scheme for dispatched functions more consistent
[oweals/openssl.git] / providers / implementations / serializers / serializer_dh.c
index 313fae0e30c6b572244951cc9f8a68634bd1d27d..03bb874a6411cb1d2f0641fc90445c36fa5b8891 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -7,24 +7,40 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include <openssl/dh.h>
+/*
+ * DH low level APIs are deprecated for public use, but still ok for
+ * internal use.
+ */
+#include "internal/deprecated.h"
+
 #include <openssl/err.h>
 #include "prov/bio.h"             /* ossl_prov_bio_printf() */
 #include "prov/implementations.h" /* rsa_keymgmt_functions */
 #include "prov/providercommonerr.h" /* PROV_R_BN_ERROR */
+#include "internal/ffc.h"
+#include "crypto/dh.h"
 #include "serializer_local.h"
 
-OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_dh_importkey(void)
+OSSL_FUNC_keymgmt_new_fn *ossl_prov_get_keymgmt_dh_new(void)
+{
+    return ossl_prov_get_keymgmt_new(dh_keymgmt_functions);
+}
+
+OSSL_FUNC_keymgmt_free_fn *ossl_prov_get_keymgmt_dh_free(void)
 {
-    return ossl_prov_get_importkey(dh_keymgmt_functions);
+    return ossl_prov_get_keymgmt_free(dh_keymgmt_functions);
+}
+
+OSSL_FUNC_keymgmt_import_fn *ossl_prov_get_keymgmt_dh_import(void)
+{
+    return ossl_prov_get_keymgmt_import(dh_keymgmt_functions);
 }
 
 int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
 {
     const char *type_label = NULL;
     const BIGNUM *priv_key = NULL, *pub_key = NULL;
-    const BIGNUM *p = NULL, *g = NULL;
-
+    const BIGNUM *p = NULL;
 
     switch (type) {
     case dh_print_priv:
@@ -51,35 +67,19 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
     }
 
     p = DH_get0_p(dh);
-    g = DH_get0_p(dh);
-    if (p == NULL || g == NULL)
+    if (p == NULL)
         goto null_err;
 
-    /*
-     * TODO(3.0): add printing of:
-     *
-     * - q (label "subgroup order:")
-     * - j (label "subgroup factor:")
-     * - seed (label "seed:")
-     * - counter (label "counter:")
-     *
-     * This can happen as soon as there are DH_get0_ functions for them.
-     */
-
-    if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
+    if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
         <= 0)
         goto err;
     if (priv_key != NULL
-        && !ossl_prov_print_labeled_bignum(out, "    private-key:", priv_key))
+        && !ossl_prov_print_labeled_bignum(out, "private-key:", priv_key))
         goto err;
     if (pub_key != NULL
-        && !ossl_prov_print_labeled_bignum(out, "    public-key:", pub_key))
-        goto err;
-    if (p != NULL
-        && !ossl_prov_print_labeled_bignum(out, "    prime:", p))
+        && !ossl_prov_print_labeled_bignum(out, "public-key:", pub_key))
         goto err;
-    if (g != NULL
-        && !ossl_prov_print_labeled_bignum(out, "    generator:", g))
+    if (!ffc_params_prov_print(out, dh_get0_params(dh)))
         goto err;
 
     return 1;
@@ -91,7 +91,7 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
 }
 
 int ossl_prov_prepare_dh_params(const void *dh, int nid,
-                                ASN1_STRING **pstr, int *pstrtype)
+                                void **pstr, int *pstrtype)
 {
     ASN1_STRING *params = ASN1_STRING_new();