/*
- * 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
* https://www.openssl.org/source/license.html
*/
-#include <openssl/core_numbers.h>
+/*
+ * DH low level APIs are deprecated for public use, but still ok for
+ * internal use.
+ */
+#include "internal/deprecated.h"
+
+#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/params.h>
#include "prov/bio.h"
#include "prov/implementations.h"
+#include "prov/provider_ctx.h"
#include "serializer_local.h"
-static OSSL_OP_serializer_newctx_fn dh_priv_newctx;
-static OSSL_OP_serializer_freectx_fn dh_priv_freectx;
-static OSSL_OP_serializer_set_ctx_params_fn dh_priv_set_ctx_params;
-static OSSL_OP_serializer_settable_ctx_params_fn dh_priv_settable_ctx_params;
-static OSSL_OP_serializer_serialize_data_fn dh_priv_der_data;
-static OSSL_OP_serializer_serialize_object_fn dh_priv_der;
-static OSSL_OP_serializer_serialize_data_fn dh_pem_priv_data;
-static OSSL_OP_serializer_serialize_object_fn dh_pem_priv;
+static OSSL_FUNC_serializer_newctx_fn dh_priv_newctx;
+static OSSL_FUNC_serializer_freectx_fn dh_priv_freectx;
+static OSSL_FUNC_serializer_set_ctx_params_fn dh_priv_set_ctx_params;
+static OSSL_FUNC_serializer_settable_ctx_params_fn dh_priv_settable_ctx_params;
+static OSSL_FUNC_serializer_serialize_data_fn dh_priv_der_data;
+static OSSL_FUNC_serializer_serialize_object_fn dh_priv_der;
+static OSSL_FUNC_serializer_serialize_data_fn dh_pem_priv_data;
+static OSSL_FUNC_serializer_serialize_object_fn dh_pem_priv;
-static OSSL_OP_serializer_newctx_fn dh_print_newctx;
-static OSSL_OP_serializer_freectx_fn dh_print_freectx;
-static OSSL_OP_serializer_serialize_data_fn dh_priv_print_data;
-static OSSL_OP_serializer_serialize_object_fn dh_priv_print;
+static OSSL_FUNC_serializer_newctx_fn dh_print_newctx;
+static OSSL_FUNC_serializer_freectx_fn dh_print_freectx;
+static OSSL_FUNC_serializer_serialize_data_fn dh_priv_print_data;
+static OSSL_FUNC_serializer_serialize_object_fn dh_priv_print;
/*
* Context used for private key serialization.
if (ctx != NULL) {
ctx->provctx = provctx;
- }
-
- /* -1 is the "whatever" indicator, i.e. the PKCS8 library default PBE */
- ctx->sc.pbe_nid = -1;
+ /* -1 is the "whatever" indicator, i.e. the PKCS8 library default PBE */
+ ctx->sc.pbe_nid = -1;
+ }
return ctx;
}
}
/* Private key : DER */
-static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
- OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
+static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
+ OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dh_priv_ctx_st *ctx = vctx;
- OSSL_OP_keymgmt_importkey_fn *dh_importkey =
- ossl_prov_get_dh_importkey();
+ OSSL_FUNC_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
+ OSSL_FUNC_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
+ OSSL_FUNC_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
int ok = 0;
- if (dh_importkey != NULL) {
- DH *dh = dh_importkey(ctx->provctx, params);
+ if (dh_import != NULL) {
+ DH *dh;
- ok = dh_priv_der(ctx, dh, out, cb, cbarg);
- DH_free(dh);
+ if ((dh = dh_new(ctx->provctx)) != NULL
+ && dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
+ && dh_priv_der(ctx, dh, out, cb, cbarg))
+ ok = 1;
+ dh_free(dh);
}
return ok;
}
-static int dh_priv_der(void *vctx, void *dh, BIO *out,
+static int dh_priv_der(void *vctx, void *dh, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dh_priv_ctx_st *ctx = vctx;
int ret;
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+
+ if (out == NULL)
+ return 0;
ctx->sc.cb = cb;
ctx->sc.cbarg = cbarg;
ossl_prov_prepare_dh_params,
ossl_prov_dh_priv_to_der,
&ctx->sc);
+ BIO_free(out);
return ret;
}
/* Private key : PEM */
-static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
- OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
+static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
+ OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dh_priv_ctx_st *ctx = vctx;
- OSSL_OP_keymgmt_importkey_fn *dh_importkey =
- ossl_prov_get_dh_importkey();
+ OSSL_FUNC_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
+ OSSL_FUNC_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
+ OSSL_FUNC_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
int ok = 0;
- if (dh_importkey != NULL) {
- DH *dh = dh_importkey(ctx, params);
+ if (dh_import != NULL) {
+ DH *dh;
- ok = dh_pem_priv(ctx->provctx, dh, out, cb, cbarg);
- DH_free(dh);
+ if ((dh = dh_new(ctx->provctx)) != NULL
+ && dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
+ && dh_pem_priv(ctx->provctx, dh, out, cb, cbarg))
+ ok = 1;
+ dh_free(dh);
}
return ok;
}
-static int dh_pem_priv(void *vctx, void *dh, BIO *out,
- OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
+static int dh_pem_priv(void *vctx, void *dh, OSSL_CORE_BIO *cout,
+ OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dh_priv_ctx_st *ctx = vctx;
int ret;
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+
+ if (out == NULL)
+ return 0;
ctx->sc.cb = cb;
ctx->sc.cbarg = cbarg;
ossl_prov_prepare_dh_params,
ossl_prov_dh_priv_to_der,
&ctx->sc);
+ BIO_free(out);
return ret;
}
{
}
-static int dh_priv_print_data(void *provctx, const OSSL_PARAM params[],
- BIO *out,
- OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
+static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
+ OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- OSSL_OP_keymgmt_importkey_fn *dh_importkey =
- ossl_prov_get_dh_importkey();
+ struct dh_priv_ctx_st *ctx = vctx;
+ OSSL_FUNC_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
+ OSSL_FUNC_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
+ OSSL_FUNC_keymgmt_import_fn *dh_import = ossl_prov_get_keymgmt_dh_import();
int ok = 0;
- if (dh_importkey != NULL) {
- DH *dh = dh_importkey(provctx, params); /* ctx == provctx */
+ if (dh_import != NULL) {
+ DH *dh;
- ok = dh_priv_print(provctx, dh, out, cb, cbarg);
- DH_free(dh);
+ if ((dh = dh_new(ctx->provctx)) != NULL
+ && dh_import(dh, OSSL_KEYMGMT_SELECT_KEYPAIR, params)
+ && dh_priv_print(ctx, dh, out, cb, cbarg))
+ ok = 1;
+ dh_free(dh);
}
return ok;
}
-static int dh_priv_print(void *ctx, void *dh, BIO *out,
- OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
+static int dh_priv_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
+ OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_print_dh(out, dh, dh_print_priv);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = ossl_prov_print_dh(out, dh, dh_print_priv);
+ BIO_free(out);
+
+ return ret;
}
const OSSL_DISPATCH dh_priv_der_serializer_functions[] = {