summaryrefslogtreecommitdiffstats
path: root/providers/implementations
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-05-06 12:29:57 +0100
committerMatt Caswell <matt@openssl.org>2020-05-16 17:10:03 +0100
commitd40b42ab4c8a88740a2cc2a20c709fe869c4dd1e (patch)
tree0dfa4439f3de544d7e52abf56c578e10e5346458 /providers/implementations
parent827f04d5105e9bec0af214c42b8ad799fba5bb0d (diff)
Maintain strict type discipline between the core and providers
A provider could be linked against a different version of libcrypto than the version of libcrypto that loaded the provider. Different versions of libcrypto could define opaque types differently. It must never occur that a type created in one libcrypto is used directly by the other libcrypto. This will cause crashes. We can "cheat" for "built-in" providers that are part of libcrypto itself, because we know that the two libcrypto versions are the same - but not for other providers. To ensure this does not occur we use different types names for the handful of opaque types that are passed between the core and providers. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/11758)
Diffstat (limited to 'providers/implementations')
-rw-r--r--providers/implementations/serializers/serializer_common.c32
-rw-r--r--providers/implementations/serializers/serializer_dh.c2
-rw-r--r--providers/implementations/serializers/serializer_dh_param.c48
-rw-r--r--providers/implementations/serializers/serializer_dh_priv.c37
-rw-r--r--providers/implementations/serializers/serializer_dh_pub.c60
-rw-r--r--providers/implementations/serializers/serializer_dsa.c3
-rw-r--r--providers/implementations/serializers/serializer_dsa_param.c49
-rw-r--r--providers/implementations/serializers/serializer_dsa_priv.c58
-rw-r--r--providers/implementations/serializers/serializer_dsa_pub.c53
-rw-r--r--providers/implementations/serializers/serializer_ec.c10
-rw-r--r--providers/implementations/serializers/serializer_ec_param.c55
-rw-r--r--providers/implementations/serializers/serializer_ec_priv.c63
-rw-r--r--providers/implementations/serializers/serializer_ec_pub.c53
-rw-r--r--providers/implementations/serializers/serializer_ecx.c2
-rw-r--r--providers/implementations/serializers/serializer_ecx_priv.c38
-rw-r--r--providers/implementations/serializers/serializer_ecx_pub.c59
-rw-r--r--providers/implementations/serializers/serializer_ffc_params.c8
-rw-r--r--providers/implementations/serializers/serializer_rsa.c54
-rw-r--r--providers/implementations/serializers/serializer_rsa_priv.c36
-rw-r--r--providers/implementations/serializers/serializer_rsa_pub.c61
20 files changed, 572 insertions, 209 deletions
diff --git a/providers/implementations/serializers/serializer_common.c b/providers/implementations/serializers/serializer_common.c
index 2dbbe6b37c..75c1ddc245 100644
--- a/providers/implementations/serializers/serializer_common.c
+++ b/providers/implementations/serializers/serializer_common.c
@@ -178,7 +178,7 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
}
if (BN_is_zero(bn))
- return ossl_prov_bio_printf(out, "%s%s0\n", label, post_label_spc);
+ return BIO_printf(out, "%s%s0\n", label, post_label_spc);
if (BN_num_bytes(bn) <= BN_BYTES) {
BN_ULONG *words = bn_get_words(bn);
@@ -186,10 +186,8 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
if (BN_is_negative(bn))
neg = "-";
- return ossl_prov_bio_printf(out,
- "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
- label, post_label_spc, neg, words[0],
- neg, words[0]);
+ return BIO_printf(out, "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
+ label, post_label_spc, neg, words[0], neg, words[0]);
}
hex_str = BN_bn2hex(bn);
@@ -198,18 +196,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
++p;
neg = " (Negative)";
}
- if (ossl_prov_bio_printf(out, "%s%s\n", label, neg) <= 0)
+ if (BIO_printf(out, "%s%s\n", label, neg) <= 0)
goto err;
/* Keep track of how many bytes we have printed out so far */
bytes = 0;
- if (ossl_prov_bio_printf(out, "%s", spaces) <= 0)
+ if (BIO_printf(out, "%s", spaces) <= 0)
goto err;
/* Add a leading 00 if the top bit is set */
if (*p >= '8') {
- if (ossl_prov_bio_printf(out, "%02x", 0) <= 0)
+ if (BIO_printf(out, "%02x", 0) <= 0)
goto err;
++bytes;
use_sep = 1;
@@ -217,18 +215,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
while (*p != '\0') {
/* Do a newline after every 15 hex bytes + add the space indent */
if ((bytes % 15) == 0 && bytes > 0) {
- if (ossl_prov_bio_printf(out, ":\n%s", spaces) <= 0)
+ if (BIO_printf(out, ":\n%s", spaces) <= 0)
goto err;
use_sep = 0; /* The first byte on the next line doesnt have a : */
}
- if (ossl_prov_bio_printf(out, "%s%c%c", use_sep ? ":" : "",
- ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0)
+ if (BIO_printf(out, "%s%c%c", use_sep ? ":" : "",
+ ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0)
goto err;
++bytes;
p += 2;
use_sep = 1;
}
- if (ossl_prov_bio_printf(out, "\n") <= 0)
+ if (BIO_printf(out, "\n") <= 0)
goto err;
ret = 1;
err:
@@ -244,22 +242,22 @@ int ossl_prov_print_labeled_buf(BIO *out, const char *label,
{
size_t i;
- if (ossl_prov_bio_printf(out, "%s\n", label) <= 0)
+ if (BIO_printf(out, "%s\n", label) <= 0)
return 0;
for (i = 0; i < buflen; i++) {
if ((i % LABELED_BUF_PRINT_WIDTH) == 0) {
- if (i > 0 && ossl_prov_bio_printf(out, "\n") <= 0)
+ if (i > 0 && BIO_printf(out, "\n") <= 0)
return 0;
- if (ossl_prov_bio_printf(out, " ") <= 0)
+ if (BIO_printf(out, " ") <= 0)
return 0;
}
- if (ossl_prov_bio_printf(out, "%02x%s", buf[i],
+ if (BIO_printf(out, "%02x%s", buf[i],
(i == buflen - 1) ? "" : ":") <= 0)
return 0;
}
- if (ossl_prov_bio_printf(out, "\n") <= 0)
+ if (BIO_printf(out, "\n") <= 0)
return 0;
return 1;
diff --git a/providers/implementations/serializers/serializer_dh.c b/providers/implementations/serializers/serializer_dh.c
index 2b616b2ef1..df92017ba3 100644
--- a/providers/implementations/serializers/serializer_dh.c
+++ b/providers/implementations/serializers/serializer_dh.c
@@ -70,7 +70,7 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
if (p == NULL)
goto null_err;
- 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
diff --git a/providers/implementations/serializers/serializer_dh_param.c b/providers/implementations/serializers/serializer_dh_param.c
index 5e06178590..4acf5caec6 100644
--- a/providers/implementations/serializers/serializer_dh_param.c
+++ b/providers/implementations/serializers/serializer_dh_param.c
@@ -21,6 +21,7 @@
#include "prov/bio.h"
#include "prov/implementations.h"
#include "prov/providercommonerr.h"
+#include "prov/provider_ctx.h"
#include "serializer_local.h"
static OSSL_OP_serializer_newctx_fn dh_param_newctx;
@@ -48,7 +49,8 @@ static void dh_param_freectx(void *ctx)
}
/* Public key : DER */
-static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dh_param_der_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
@@ -69,14 +71,23 @@ static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_param_der(void *ctx, void *dh, BIO *out,
+static int dh_param_der(void *ctx, void *dh, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return i2d_DHparams_bio(out, dh);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+ ret = i2d_DHparams_bio(out, dh);
+ BIO_free(out);
+
+ return ret;
}
/* Public key : PEM */
-static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
@@ -97,13 +108,23 @@ static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_param_pem(void *ctx, void *dh, BIO *out,
+static int dh_param_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return PEM_write_bio_DHparams(out, dh);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = PEM_write_bio_DHparams(out, dh);
+ BIO_free(out);
+
+ return ret;
}
-static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dh_param_print_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
@@ -124,10 +145,19 @@ static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_param_print(void *ctx, void *dh, BIO *out,
+static int dh_param_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_print_dh(out, dh, dh_print_params);
+ 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_params);
+ BIO_free(out);
+
+ return ret;
}
const OSSL_DISPATCH dh_param_der_serializer_functions[] = {
diff --git a/providers/implementations/serializers/serializer_dh_priv.c b/providers/implementations/serializers/serializer_dh_priv.c
index 99d529b052..c37eb40297 100644
--- a/providers/implementations/serializers/serializer_dh_priv.c
+++ b/providers/implementations/serializers/serializer_dh_priv.c
@@ -22,6 +22,7 @@
#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;
@@ -117,7 +118,8 @@ static int dh_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
}
/* Private key : DER */
-static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+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;
@@ -138,11 +140,15 @@ static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
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;
@@ -151,12 +157,14 @@ static int dh_priv_der(void *vctx, void *dh, BIO *out,
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,
+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;
@@ -177,11 +185,15 @@ static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_pem_priv(void *vctx, void *dh, BIO *out,
+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;
@@ -190,6 +202,7 @@ static int dh_pem_priv(void *vctx, void *dh, BIO *out,
ossl_prov_prepare_dh_params,
ossl_prov_dh_priv_to_der,
&ctx->sc);
+ BIO_free(out);
return ret;
}
@@ -206,7 +219,8 @@ static void dh_print_freectx(void *ctx)
{
}
-static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dh_priv_ctx_st *ctx = vctx;
@@ -227,10 +241,19 @@ static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_priv_print(void *ctx, void *dh, BIO *out,
+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[] = {
diff --git a/providers/implementations/serializers/serializer_dh_pub.c b/providers/implementations/serializers/serializer_dh_pub.c
index b787f7c08a..d1b60d87c5 100644
--- a/providers/implementations/serializers/serializer_dh_pub.c
+++ b/providers/implementations/serializers/serializer_dh_pub.c
@@ -21,6 +21,7 @@
#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_pub_newctx;
@@ -48,7 +49,8 @@ static void dh_pub_freectx(void *ctx)
}
/* Public key : DER */
-static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
@@ -69,17 +71,27 @@ static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_pub_der(void *ctx, void *dh, BIO *out,
+static int dh_pub_der(void *ctx, void *dh, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH,
- ossl_prov_prepare_dh_params,
- ossl_prov_dh_pub_to_der);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH,
+ ossl_prov_prepare_dh_params,
+ ossl_prov_dh_pub_to_der);
+ BIO_free(out);
+
+ return ret;
}
/* Public key : PEM */
-static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
- OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
+static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
+ OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
@@ -99,17 +111,26 @@ static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_pub_pem(void *ctx, void *dh, BIO *out,
+static int dh_pub_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH,
- ossl_prov_prepare_dh_params,
- ossl_prov_dh_pub_to_der);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+ ret = ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH,
+ ossl_prov_prepare_dh_params,
+ ossl_prov_dh_pub_to_der);
+ BIO_free(out);
+
+ return ret;
}
-static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
- OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
+static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
+ OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
@@ -129,10 +150,19 @@ static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dh_pub_print(void *ctx, void *dh, BIO *out,
+static int dh_pub_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_print_dh(out, dh, dh_print_pub);
+ 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_pub);
+ BIO_free(out);
+
+ return ret;
}
const OSSL_DISPATCH dh_pub_der_serializer_functions[] = {
diff --git a/providers/implementations/serializers/serializer_dsa.c b/providers/implementations/serializers/serializer_dsa.c
index 7ee0bc739b..dea7a18eda 100644
--- a/providers/implementations/serializers/serializer_dsa.c
+++ b/providers/implementations/serializers/serializer_dsa.c
@@ -73,8 +73,7 @@ int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type)
if (p == NULL)
goto null_err;
- if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label,
- BN_num_bits(p)) <= 0)
+ 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, "priv:", priv_key))
diff --git a/providers/implementations/serializers/serializer_dsa_param.c b/providers/implementations/serializers/serializer_dsa_param.c
index 720c390341..23a6d1d25d 100644
--- a/providers/implementations/serializers/serializer_dsa_param.c
+++ b/providers/implementations/serializers/serializer_dsa_param.c
@@ -21,6 +21,7 @@
#include "prov/bio.h"
#include "prov/implementations.h"
#include "prov/providercommonerr.h"
+#include "prov/provider_ctx.h"
#include "serializer_local.h"
static OSSL_OP_serializer_newctx_fn dsa_param_newctx;
@@ -48,7 +49,8 @@ static void dsa_param_freectx(void *ctx)
}
/* Public key : DER */
-static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
@@ -69,14 +71,24 @@ static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dsa_param_der(void *ctx, void *dsa, BIO *out,
+static int dsa_param_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return i2d_DSAparams_bio(out, dsa);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = i2d_DSAparams_bio(out, dsa);
+ BIO_free(out);
+
+ return ret;
}
/* Public key : PEM */
-static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
@@ -97,13 +109,23 @@ static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dsa_param_pem(void *ctx, void *dsa, BIO *out,
+static int dsa_param_pem(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return PEM_write_bio_DSAparams(out, dsa);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = PEM_write_bio_DSAparams(out, dsa);
+ BIO_free(out);
+
+ return ret;
}
-static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
@@ -124,10 +146,19 @@ static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dsa_param_print(void *ctx, void *dsa, BIO *out,
+static int dsa_param_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_print_dsa(out, dsa, dsa_print_params);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = ossl_prov_print_dsa(out, dsa, dsa_print_params);
+ BIO_free(out);
+
+ return ret;
}
const OSSL_DISPATCH dsa_param_der_serializer_functions[] = {
diff --git a/providers/implementations/serializers/serializer_dsa_priv.c b/providers/implementations/serializers/serializer_dsa_priv.c
index 7fdc1567ee..cb9136140d 100644
--- a/providers/implementations/serializers/serializer_dsa_priv.c
+++ b/providers/implementations/serializers/serializer_dsa_priv.c
@@ -22,6 +22,7 @@
#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 dsa_priv_newctx;
@@ -117,7 +118,8 @@ static int dsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
}
/* Private key : DER */
-static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dsa_priv_ctx_st *ctx = vctx;
@@ -138,22 +140,31 @@ static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dsa_priv_der(void *vctx, void *dsa, BIO *out,
+static int dsa_priv_der(void *vctx, void *dsa, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dsa_priv_ctx_st *ctx = vctx;
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
ctx->sc.cb = cb;
ctx->sc.cbarg = cbarg;
- return ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA,
- ossl_prov_prepare_dsa_params,
- ossl_prov_dsa_priv_to_der,
- &ctx->sc);
+ ret = ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA,
+ ossl_prov_prepare_dsa_params,
+ ossl_prov_dsa_priv_to_der,
+ &ctx->sc);
+ BIO_free(out);
+
+ return ret;
}
/* Private key : PEM */
-static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dsa_priv_ctx_st *ctx = vctx;
@@ -174,18 +185,26 @@ static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dsa_pem_priv(void *vctx, void *dsa, BIO *out,
+static int dsa_pem_priv(void *vctx, void *dsa, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dsa_priv_ctx_st *ctx = vctx;
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
ctx->sc.cb = cb;
ctx->sc.cbarg = cbarg;
- return ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA,
- ossl_prov_prepare_dsa_params,
- ossl_prov_dsa_priv_to_der,
- &ctx->sc);
+ ret = ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA,
+ ossl_prov_prepare_dsa_params,
+ ossl_prov_dsa_priv_to_der,
+ &ctx->sc);
+ BIO_free(out);
+
+ return ret;
}
/*
@@ -201,7 +220,7 @@ static void dsa_print_freectx(void *ctx)
}
static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
- BIO *out,
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct dsa_priv_ctx_st *ctx = vctx;
@@ -222,10 +241,19 @@ static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
return ok;
}
-static int dsa_priv_print(void *ctx, void *dsa, BIO *out,
+static int dsa_priv_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_print_dsa(out, dsa, dsa_print_priv);
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = ossl_prov_print_dsa(out, dsa, dsa_print_priv);
+ BIO_free(out);
+
+ return ret;
}
const OSSL_DISPATCH dsa_priv_der_serializer_functions[] = {
diff --git a/providers/implementations/serializers/serializer_dsa_pub.c b/providers/implementations/serializers/serializer_dsa_pub.c
index 46e5c7167b..5c5e61f13d 100644
--- a/providers/implementations/serializers/serializer_dsa_pub.c
+++ b/providers/implementations/serializers/serializer_dsa_pub.c
@@ -21,6 +21,7 @@
#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 dsa_pub_newctx;
@@ -48,7 +49,8 @@ static void dsa_pub_freectx(void *ctx)
}
/* Public key : DER */
-static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
@@ -69,7 +71,7 @@ static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
+static int dsa_pub_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
/*
@@ -77,8 +79,13 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
* in crypto/dsa/dsa_ameth.c
*/
int save_parameters = 1;
+ BIO *out = bio_new_from_core_bio(ctx, cout);
+ int ret;
- return
+ if (out == NULL)
+ return 0;
+
+ ret =
save_parameters
? ossl_prov_write_pub_der_from_obj(out, dsa, EVP_PKEY_DSA,
ossl_prov_prepare_all_dsa_params,
@@ -87,10 +94,14 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
ossl_prov_prepare_dsa_params,
ossl_prov_dsa_pub_to_der);
+ BIO_free(out);
+
+ return ret;
}
/* Public key : PEM */
-static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
@@ -111,15 +122,26 @@ static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
return ok;
}
-static int dsa_pub_pem(void *ctx, void *dsa, BIO *out,
+static int dsa_pub_pem(void *ctx, void *d