Latest update.
This commit is contained in:
@@ -10,7 +10,10 @@ $ECX_GOAL=../../libimplementations.a
|
||||
$EC_GOAL=../../libimplementations.a
|
||||
|
||||
SOURCE[$SERIALIZER_GOAL]=serializer_common.c
|
||||
|
||||
SOURCE[$RSA_GOAL]=serializer_rsa.c serializer_rsa_priv.c serializer_rsa_pub.c
|
||||
DEPEND[serializer_rsa.o]=../../common/include/prov/der_rsa.h
|
||||
|
||||
IF[{- !$disabled{"dh"} || !$disabled{"dsa"} -}]
|
||||
SOURCE[$FFC_GOAL]=serializer_ffc_params.c
|
||||
ENDIF
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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[] = {
|
||||
|
||||
@@ -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[] = {
|
||||
|
||||
@@ -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[] = {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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[] = {
|
||||
|
||||
@@ -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[] = {
|
||||
|
||||
@@ -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 *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_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, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_pub_to_der);
|
||||
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pub_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();
|
||||
@@ -140,10 +162,19 @@ static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pub_print(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, 0);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dsa(out, dsa, 0);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -31,15 +31,13 @@ static int ossl_prov_print_ec_param(BIO *out, const EC_GROUP *group)
|
||||
if (curve_nid == NID_undef)
|
||||
return 0;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: %s\n", "ASN1 OID",
|
||||
OBJ_nid2sn(curve_nid)) <= 0)
|
||||
if (BIO_printf(out, "%s: %s\n", "ASN1 OID", OBJ_nid2sn(curve_nid)) <= 0)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0): Only named curves are currently supported */
|
||||
curve_name = EC_curve_nid2nist(curve_nid);
|
||||
return (curve_name == NULL
|
||||
|| ossl_prov_bio_printf(out, "%s: %s\n", "NIST CURVE",
|
||||
curve_name) > 0);
|
||||
|| BIO_printf(out, "%s: %s\n", "NIST CURVE", curve_name) > 0);
|
||||
}
|
||||
|
||||
int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type)
|
||||
@@ -86,8 +84,8 @@ int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label,
|
||||
EC_GROUP_order_bits(group)) <= 0)
|
||||
if (BIO_printf(out, "%s: (%d bit)\n", type_label,
|
||||
EC_GROUP_order_bits(group)) <= 0)
|
||||
goto err;
|
||||
if (priv != NULL
|
||||
&& !ossl_prov_print_labeled_buf(out, "priv:", priv, priv_len))
|
||||
|
||||
@@ -15,6 +15,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 ec_param_newctx;
|
||||
@@ -39,8 +40,9 @@ static void ec_param_freectx(void *vctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -62,15 +64,25 @@ static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_der(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey));
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey));
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -92,14 +104,24 @@ static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_pem(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey));
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey));
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -121,10 +143,19 @@ static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_params);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_params);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_param_der_serializer_functions[] = {
|
||||
|
||||
@@ -16,6 +16,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 ec_priv_newctx;
|
||||
@@ -111,8 +112,9 @@ static int ec_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -134,23 +136,32 @@ static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_priv_der(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_priv_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_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, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -172,18 +183,26 @@ static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pem_priv(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pem_priv(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_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, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -198,7 +217,8 @@ static void ec_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
@@ -221,10 +241,19 @@ static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_priv_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_priv_print(void *ctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_priv);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -14,6 +14,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 ec_pub_newctx;
|
||||
@@ -41,7 +42,8 @@ static void ec_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -64,16 +66,26 @@ static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_der(void *ctx, void *eckey, BIO *out,
|
||||
static int ec_pub_der(void *ctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
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, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -96,15 +108,25 @@ static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_pem(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pub_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -127,10 +149,19 @@ static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pub_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_pub);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -86,7 +86,7 @@ int ossl_prov_print_ecx(BIO *out, ECX_KEY *ecxkey, enum ecx_print_type type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s:\n", type_label) <= 0)
|
||||
if (BIO_printf(out, "%s:\n", type_label) <= 0)
|
||||
return 0;
|
||||
if (type == ecx_print_priv
|
||||
&& !ossl_prov_print_labeled_buf(out, "priv:", ecxkey->privkey,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_priv_newctx;
|
||||
@@ -134,7 +135,8 @@ static int ecx_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -157,13 +159,17 @@ static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
|
||||
static int ecx_priv_der(void *vctx, void *vecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
ECX_KEY *ecxkey = vecxkey;
|
||||
int ret;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -173,12 +179,14 @@ static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -201,12 +209,16 @@ static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_priv_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -216,11 +228,13 @@ static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -243,10 +257,20 @@ static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_print(void *ctx, void *ecxkey, BIO *out,
|
||||
static int ecx_priv_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define MAKE_SERIALIZER_FUNCTIONS(alg, type) \
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_pub_newctx;
|
||||
@@ -76,7 +77,8 @@ static void ecx_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -99,19 +101,28 @@ static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_der(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_der(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
return ossl_prov_write_pub_der_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -134,19 +145,27 @@ static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
return ossl_prov_write_pub_pem_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -169,10 +188,20 @@ static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_print(void *ctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_ecx(out, ecxkey, ecx_print_pub);
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define MAKE_SERIALIZER_FUNCTIONS(alg, type) \
|
||||
|
||||
@@ -20,7 +20,7 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
|
||||
|
||||
if (name == NULL)
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "GROUP: %s\n", name) <= 0)
|
||||
if (BIO_printf(out, "GROUP: %s\n", name) <= 0)
|
||||
goto err;
|
||||
return 1;
|
||||
#else
|
||||
@@ -46,15 +46,15 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->gindex != -1) {
|
||||
if (ossl_prov_bio_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
|
||||
if (BIO_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->pcounter != -1) {
|
||||
if (ossl_prov_bio_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
|
||||
if (BIO_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->h != 0) {
|
||||
if (ossl_prov_bio_printf(out, "h: %d\n", ffc->h) <= 0)
|
||||
if (BIO_printf(out, "h: %d\n", ffc->h) <= 0)
|
||||
goto err;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -82,6 +82,14 @@ int ossl_prov_prepare_all_dsa_params(const void *dsa, int nid,
|
||||
int ossl_prov_dsa_pub_to_der(const void *dsa, unsigned char **pder);
|
||||
int ossl_prov_dsa_priv_to_der(const void *dsa, unsigned char **pder);
|
||||
|
||||
/*
|
||||
* ossl_prov_prepare_rsa_params() is designed to work with the ossl_prov_write_
|
||||
* functions, hence 'void *rsa' rather than 'RSA *rsa'.
|
||||
*/
|
||||
int ossl_prov_prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype);
|
||||
int ossl_prov_rsa_type_to_evp(const RSA *rsa);
|
||||
|
||||
int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
const BIGNUM *bn);
|
||||
int ossl_prov_print_labeled_buf(BIO *out, const char *label,
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "internal/packet.h"
|
||||
#include "crypto/rsa.h" /* rsa_get0_all_params() */
|
||||
#include "prov/bio.h" /* ossl_prov_bio_printf() */
|
||||
#include "prov/der_rsa.h" /* DER_w_RSASSA_PSS_params() */
|
||||
#include "prov/implementations.h" /* rsa_keymgmt_functions */
|
||||
#include "serializer_local.h"
|
||||
|
||||
@@ -37,6 +39,7 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null();
|
||||
RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
int ret = 0;
|
||||
|
||||
if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL)
|
||||
@@ -46,15 +49,14 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
rsa_get0_all_params(rsa, factors, exps, coeffs);
|
||||
|
||||
if (priv && rsa_d != NULL) {
|
||||
if (ossl_prov_bio_printf(out, "Private-Key: (%d bit, %d primes)\n",
|
||||
BN_num_bits(rsa_n),
|
||||
sk_BIGNUM_const_num(factors)) <= 0)
|
||||
if (BIO_printf(out, "Private-Key: (%d bit, %d primes)\n",
|
||||
BN_num_bits(rsa_n),
|
||||
sk_BIGNUM_const_num(factors)) <= 0)
|
||||
goto err;
|
||||
modulus_label = "modulus:";
|
||||
exponent_label = "publicExponent:";
|
||||
} else {
|
||||
if (ossl_prov_bio_printf(out, "Public-Key: (%d bit)\n",
|
||||
BN_num_bits(rsa_n)) <= 0)
|
||||
if (BIO_printf(out, "Public-Key: (%d bit)\n", BN_num_bits(rsa_n)) <= 0)
|
||||
goto err;
|
||||
modulus_label = "Modulus:";
|
||||
exponent_label = "Exponent:";
|
||||
@@ -84,18 +86,18 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
sk_BIGNUM_const_value(coeffs, 0)))
|
||||
goto err;
|
||||
for (i = 2; i < sk_BIGNUM_const_num(factors); i++) {
|
||||
if (ossl_prov_bio_printf(out, "prime%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "prime%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(factors,
|
||||
i)))
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "exponent%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "exponent%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(exps, i)))
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "coefficient%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "coefficient%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(coeffs,
|
||||
@@ -103,6 +105,60 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
if (!rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
if (BIO_printf(out, "(INVALID PSS PARAMETERS)\n") <= 0)
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
if (rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
if (BIO_printf(out, "No PSS parameter restrictions\n") <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
int hashalg_nid = rsa_pss_params_30_hashalg(pss_params);
|
||||
int maskgenalg_nid = rsa_pss_params_30_maskgenalg(pss_params);
|
||||
int maskgenhashalg_nid =
|
||||
rsa_pss_params_30_maskgenhashalg(pss_params);
|
||||
int saltlen = rsa_pss_params_30_saltlen(pss_params);
|
||||
int trailerfield = rsa_pss_params_30_trailerfield(pss_params);
|
||||
|
||||
if (BIO_printf(out, "PSS parameter restrictions:\n") <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Hash Algorithm: %s%s\n",
|
||||
rsa_oaeppss_nid2name(hashalg_nid),
|
||||
(hashalg_nid == NID_sha1
|
||||
? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Mask Algorithm: %s with %s%s\n",
|
||||
rsa_mgf_nid2name(maskgenalg_nid),
|
||||
rsa_oaeppss_nid2name(maskgenhashalg_nid),
|
||||
(maskgenalg_nid == NID_mgf1
|
||||
&& maskgenhashalg_nid == NID_sha1
|
||||
? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Minimum Salt Length: %d%s\n",
|
||||
saltlen,
|
||||
(saltlen == 20 ? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
/*
|
||||
* TODO(3.0) Should we show the ASN.1 trailerField value, or
|
||||
* the actual trailerfield byte (i.e. 0xBC for 1)?
|
||||
* crypto/rsa/rsa_ameth.c isn't very clear on that, as it
|
||||
* does display 0xBC when the default applies, but the ASN.1
|
||||
* trailerField value otherwise...
|
||||
*/
|
||||
if (BIO_printf(out, " Trailer Field: 0x%x%s\n",
|
||||
trailerfield,
|
||||
(trailerfield == 1 ? " (default)" : ""))
|
||||
<= 0)
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
sk_BIGNUM_const_free(factors);
|
||||
@@ -110,3 +166,90 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
sk_BIGNUM_const_free(coeffs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper functions to prepare RSA-PSS params for serialization. We would
|
||||
* have simply written the whole AlgorithmIdentifier, but existing libcrypto
|
||||
* functionality doesn't allow that.
|
||||
*/
|
||||
|
||||
int ossl_prov_prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype)
|
||||
{
|
||||
const RSA_PSS_PARAMS_30 *pss = rsa_get0_pss_params_30((RSA *)rsa);
|
||||
|
||||
*pstr = NULL;
|
||||
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
/* If plain RSA, the parameters shall be NULL */
|
||||
*pstrtype = V_ASN1_NULL;
|
||||
return 1;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
if (rsa_pss_params_30_is_unrestricted(pss)) {
|
||||
*pstrtype = V_ASN1_UNDEF;
|
||||
} else {
|
||||
ASN1_STRING *astr = NULL;
|
||||
WPACKET pkt;
|
||||
unsigned char *str = NULL;
|
||||
size_t str_sz = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
if (!WPACKET_init_null_der(&pkt))
|
||||
goto err;
|
||||
break;
|
||||
case 1:
|
||||
if ((str = OPENSSL_malloc(str_sz)) == NULL
|
||||
|| !WPACKET_init_der(&pkt, str, str_sz)) {
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!DER_w_RSASSA_PSS_params(&pkt, -1, pss)
|
||||
|| !WPACKET_finish(&pkt))
|
||||
goto err;
|
||||
WPACKET_get_total_written(&pkt, &str_sz);
|
||||
WPACKET_cleanup(&pkt);
|
||||
|
||||
/*
|
||||
* If no PSS parameters are going to be written, there's no
|
||||
* point going for another iteration.
|
||||
* This saves us from getting |str| allocated just to have it
|
||||
* immediately de-allocated.
|
||||
*/
|
||||
if (str_sz == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((astr = ASN1_STRING_new()) == NULL)
|
||||
goto err;
|
||||
*pstrtype = V_ASN1_SEQUENCE;
|
||||
ASN1_STRING_set0(astr, str, (int)str_sz);
|
||||
*pstr = astr;
|
||||
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_free(str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Currently unsupported RSA key type */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ossl_prov_rsa_type_to_evp(const RSA *rsa)
|
||||
{
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
return EVP_PKEY_RSA;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
return EVP_PKEY_RSA_PSS;
|
||||
}
|
||||
|
||||
/* Currently unsupported RSA key type */
|
||||
return EVP_PKEY_NONE;
|
||||
}
|
||||
@@ -15,9 +15,11 @@
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/safestack.h>
|
||||
#include "crypto/rsa.h"
|
||||
#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 rsa_priv_newctx;
|
||||
@@ -43,34 +45,6 @@ struct rsa_priv_ctx_st {
|
||||
struct pkcs8_encrypt_ctx_st sc;
|
||||
};
|
||||
|
||||
/* Helper functions to prepare RSA-PSS params for serialization */
|
||||
|
||||
static int prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype)
|
||||
{
|
||||
const RSA_PSS_PARAMS *pss = RSA_get0_pss_params(rsa);
|
||||
*pstr = NULL;
|
||||
|
||||
/* If RSA it's just NULL type */
|
||||
if (nid != EVP_PKEY_RSA_PSS) {
|
||||
*pstrtype = V_ASN1_NULL;
|
||||
return 1;
|
||||
}
|
||||
/* If no PSS parameters we omit parameters entirely */
|
||||
if (pss == NULL) {
|
||||
*pstrtype = V_ASN1_UNDEF;
|
||||
return 1;
|
||||
}
|
||||
/* Encode PSS parameters */
|
||||
if (ASN1_item_pack((void *)pss, ASN1_ITEM_rptr(RSA_PSS_PARAMS),
|
||||
(ASN1_STRING **)pstr)
|
||||
== NULL)
|
||||
return 0;
|
||||
|
||||
*pstrtype = V_ASN1_SEQUENCE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Private key : context */
|
||||
static void *rsa_priv_newctx(void *provctx)
|
||||
{
|
||||
@@ -140,7 +114,8 @@ static int rsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -161,25 +136,32 @@ static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_priv_der(void *vctx, void *rsa, BIO *out,
|
||||
static int rsa_priv_der(void *vctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_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;
|
||||
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, rsa, EVP_PKEY_RSA,
|
||||
prepare_rsa_params,
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPrivateKey,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -200,19 +182,25 @@ static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pem_priv(void *vctx, void *rsa, BIO *out,
|
||||
static int rsa_pem_priv(void *vctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_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;
|
||||
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, rsa, EVP_PKEY_RSA,
|
||||
prepare_rsa_params,
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPrivateKey,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -230,7 +218,7 @@ static void rsa_print_freectx(void *ctx)
|
||||
}
|
||||
|
||||
static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -251,10 +239,19 @@ static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_priv_print(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_priv_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_rsa(out, rsa, 1);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_rsa(out, rsa, 1);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -15,6 +15,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 rsa_pub_newctx;
|
||||
@@ -42,7 +43,8 @@ static void rsa_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -63,14 +65,27 @@ static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_der(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_der(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_RSA_PUBKEY_bio(out, rsa);
|
||||
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, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPublicKey);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -91,13 +106,26 @@ static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_pem(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_pem(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_RSA_PUBKEY(out, rsa);
|
||||
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, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPublicKey);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -118,10 +146,19 @@ static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_print(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_rsa(out, rsa, 0);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_rsa(out, rsa, 0);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_pub_der_serializer_functions[] = {
|
||||
|
||||
Reference in New Issue
Block a user