Skip to content

Commit

Permalink
Rename OSSL_ENCODER_CTX_new_by_EVP_PKEY and OSSL_DECODER_CTX_new_by_E…
Browse files Browse the repository at this point in the history
…VP_PKEY

Additional renames done in encoder and decoder implementation
to follow the style.

Fixes #13622

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #14155)
  • Loading branch information
t8m committed Feb 17, 2021
1 parent e5ac413 commit fe75766
Show file tree
Hide file tree
Showing 34 changed files with 211 additions and 226 deletions.
22 changes: 11 additions & 11 deletions apps/dhparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ int dhparam_main(int argc, char **argv)
* We check that we got one of those key types afterwards.
*/
decoderctx
= OSSL_DECODER_CTX_new_by_EVP_PKEY(&tmppkey,
(informat == FORMAT_ASN1)
= OSSL_DECODER_CTX_new_for_pkey(&tmppkey,
(informat == FORMAT_ASN1)
? "DER" : "PEM",
NULL,
(informat == FORMAT_ASN1)
NULL,
(informat == FORMAT_ASN1)
? keytype : NULL,
OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
NULL, NULL);
OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
NULL, NULL);

if (decoderctx != NULL
&& !OSSL_DECODER_from_bio(decoderctx, in)
Expand Down Expand Up @@ -328,11 +328,11 @@ int dhparam_main(int argc, char **argv)

if (!noout) {
OSSL_ENCODER_CTX *ectx =
OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey,
OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
outformat == FORMAT_ASN1
? "DER" : "PEM",
NULL, NULL);
OSSL_ENCODER_CTX_new_for_pkey(pkey,
OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
outformat == FORMAT_ASN1
? "DER" : "PEM",
NULL, NULL);

if (ectx == NULL || !OSSL_ENCODER_to_bio(ectx, out)) {
OSSL_ENCODER_CTX_free(ectx);
Expand Down
4 changes: 2 additions & 2 deletions apps/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ int dsa_main(int argc, char **argv)
}

/* Perform the encoding */
ectx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection, output_type,
output_structure, NULL);
ectx = OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, output_type,
output_structure, NULL);
if (OSSL_ENCODER_CTX_get_num_encoders(ectx) == 0) {
BIO_printf(bio_err, "%s format not supported\n", output_type);
goto end;
Expand Down
6 changes: 3 additions & 3 deletions apps/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ int ec_main(int argc, char **argv)
assert(private);
}

ectx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(eckey, selection,
output_type, output_structure,
NULL);
ectx = OSSL_ENCODER_CTX_new_for_pkey(eckey, selection,
output_type, output_structure,
NULL);
if (enc != NULL) {
OSSL_ENCODER_CTX_set_cipher(ectx, EVP_CIPHER_name(enc), NULL);
if (passout != NULL)
Expand Down
4 changes: 2 additions & 2 deletions apps/ecparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ int ecparam_main(int argc, char **argv)
noout = 1;

if (!noout) {
ectx_params = OSSL_ENCODER_CTX_new_by_EVP_PKEY(
ectx_params = OSSL_ENCODER_CTX_new_for_pkey(
params_key, OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
outformat == FORMAT_ASN1 ? "DER" : "PEM", NULL, NULL);
if (!OSSL_ENCODER_to_bio(ectx_params, out)) {
Expand All @@ -317,7 +317,7 @@ int ecparam_main(int argc, char **argv)
goto end;
}
assert(private);
ectx_key = OSSL_ENCODER_CTX_new_by_EVP_PKEY(
ectx_key = OSSL_ENCODER_CTX_new_for_pkey(
key, OSSL_KEYMGMT_SELECT_ALL,
outformat == FORMAT_ASN1 ? "DER" : "PEM", NULL, NULL);
if (!OSSL_ENCODER_to_bio(ectx_key, out)) {
Expand Down
6 changes: 3 additions & 3 deletions apps/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ int rsa_main(int argc, char **argv)
}

/* Now, perform the encoding */
ectx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection,
output_type, output_structure,
NULL);
ectx = OSSL_ENCODER_CTX_new_for_pkey(pkey, selection,
output_type, output_structure,
NULL);
if (OSSL_ENCODER_CTX_get_num_encoders(ectx) == 0) {
BIO_printf(bio_err, "%s format not supported\n", output_type);
goto end;
Expand Down
4 changes: 2 additions & 2 deletions crypto/asn1/i2d_evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static int i2d_provided(const EVP_PKEY *a, int selection,
*/
size_t len = INT_MAX;

ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(a, selection, "DER",
*output_structures, NULL);
ctx = OSSL_ENCODER_CTX_new_for_pkey(a, selection, "DER",
*output_structures, NULL);
if (ctx == NULL)
return -1;
if (OSSL_ENCODER_to_data(ctx, pp, &len))
Expand Down
4 changes: 2 additions & 2 deletions crypto/cms/cms_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ static EVP_PKEY *pkey_type2param(int ptype, const void *pval,
OSSL_DECODER_CTX *ctx = NULL;
int selection = OSSL_KEYMGMT_SELECT_ALL_PARAMETERS;

ctx = OSSL_DECODER_CTX_new_by_EVP_PKEY(&pkey, "DER", NULL, "EC",
selection, libctx, propq);
ctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, "DER", NULL, "EC",
selection, libctx, propq);
if (ctx == NULL)
goto err;

Expand Down
46 changes: 23 additions & 23 deletions crypto/encode_decode/decoder_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx,
}

/*
* Support for OSSL_DECODER_CTX_new_by_EVP_PKEY:
* Support for OSSL_DECODER_CTX_new_for_pkey:
* The construct data, and collecting keymgmt information for it
*/

DEFINE_STACK_OF(EVP_KEYMGMT)

struct decoder_EVP_PKEY_data_st {
struct decoder_pkey_data_st {
OSSL_LIB_CTX *libctx;
char *propq;

char *object_type; /* recorded object data type, may be NULL */
void **object; /* Where the result should end up */
};

static int decoder_construct_EVP_PKEY(OSSL_DECODER_INSTANCE *decoder_inst,
const OSSL_PARAM *params,
void *construct_data)
static int decoder_construct_pkey(OSSL_DECODER_INSTANCE *decoder_inst,
const OSSL_PARAM *params,
void *construct_data)
{
struct decoder_EVP_PKEY_data_st *data = construct_data;
struct decoder_pkey_data_st *data = construct_data;
OSSL_DECODER *decoder = OSSL_DECODER_INSTANCE_get_decoder(decoder_inst);
void *decoderctx = OSSL_DECODER_INSTANCE_get_decoder_ctx(decoder_inst);
EVP_KEYMGMT *keymgmt = NULL;
Expand Down Expand Up @@ -159,9 +159,9 @@ static int decoder_construct_EVP_PKEY(OSSL_DECODER_INSTANCE *decoder_inst,
return (*data->object != NULL);
}

static void decoder_clean_EVP_PKEY_construct_arg(void *construct_data)
static void decoder_clean_pkey_construct_arg(void *construct_data)
{
struct decoder_EVP_PKEY_data_st *data = construct_data;
struct decoder_pkey_data_st *data = construct_data;

if (data != NULL) {
OPENSSL_free(data->propq);
Expand Down Expand Up @@ -269,12 +269,12 @@ static void collect_decoder(OSSL_DECODER *decoder, void *arg)
data->error_occured = 0; /* All is good now */
}

int ossl_decoder_ctx_setup_for_EVP_PKEY(OSSL_DECODER_CTX *ctx,
EVP_PKEY **pkey, const char *keytype,
OSSL_LIB_CTX *libctx,
const char *propquery)
int ossl_decoder_ctx_setup_for_pkey(OSSL_DECODER_CTX *ctx,
EVP_PKEY **pkey, const char *keytype,
OSSL_LIB_CTX *libctx,
const char *propquery)
{
struct decoder_EVP_PKEY_data_st *process_data = NULL;
struct decoder_pkey_data_st *process_data = NULL;
STACK_OF(EVP_KEYMGMT) *keymgmts = NULL;
STACK_OF(OPENSSL_CSTRING) *names = NULL;
int ok = 0;
Expand Down Expand Up @@ -327,27 +327,27 @@ int ossl_decoder_ctx_setup_for_EVP_PKEY(OSSL_DECODER_CTX *ctx,
}

if (OSSL_DECODER_CTX_get_num_decoders(ctx) != 0) {
if (!OSSL_DECODER_CTX_set_construct(ctx, decoder_construct_EVP_PKEY)
if (!OSSL_DECODER_CTX_set_construct(ctx, decoder_construct_pkey)
|| !OSSL_DECODER_CTX_set_construct_data(ctx, process_data)
|| !OSSL_DECODER_CTX_set_cleanup(ctx,
decoder_clean_EVP_PKEY_construct_arg))
decoder_clean_pkey_construct_arg))
goto err;

process_data = NULL; /* Avoid it being freed */
}

ok = 1;
err:
decoder_clean_EVP_PKEY_construct_arg(process_data);
decoder_clean_pkey_construct_arg(process_data);
return ok;
}

OSSL_DECODER_CTX *
OSSL_DECODER_CTX_new_by_EVP_PKEY(EVP_PKEY **pkey,
const char *input_type,
const char *input_structure,
const char *keytype, int selection,
OSSL_LIB_CTX *libctx, const char *propquery)
OSSL_DECODER_CTX_new_for_pkey(EVP_PKEY **pkey,
const char *input_type,
const char *input_structure,
const char *keytype, int selection,
OSSL_LIB_CTX *libctx, const char *propquery)
{
OSSL_DECODER_CTX *ctx = NULL;

Expand All @@ -367,8 +367,8 @@ OSSL_DECODER_CTX_new_by_EVP_PKEY(EVP_PKEY **pkey,
if (OSSL_DECODER_CTX_set_input_type(ctx, input_type)
&& OSSL_DECODER_CTX_set_input_structure(ctx, input_structure)
&& OSSL_DECODER_CTX_set_selection(ctx, selection)
&& ossl_decoder_ctx_setup_for_EVP_PKEY(ctx, pkey, keytype,
libctx, propquery)
&& ossl_decoder_ctx_setup_for_pkey(ctx, pkey, keytype,
libctx, propquery)
&& OSSL_DECODER_CTX_add_extra(ctx, libctx, propquery)) {
OSSL_TRACE_BEGIN(DECODER) {
BIO_printf(trc_out, "(ctx %p) Got %d decoders\n",
Expand Down
32 changes: 16 additions & 16 deletions crypto/encode_decode/encoder_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx,
}

/*
* Support for OSSL_ENCODER_CTX_new_by_TYPE:
* Support for OSSL_ENCODER_CTX_new_for_type:
* finding a suitable encoder
*/

Expand Down Expand Up @@ -162,7 +162,7 @@ static int encoder_import_cb(const OSSL_PARAM params[], void *arg)
}

static const void *
encoder_construct_EVP_PKEY(OSSL_ENCODER_INSTANCE *encoder_inst, void *arg)
encoder_construct_pkey(OSSL_ENCODER_INSTANCE *encoder_inst, void *arg)
{
struct construct_data_st *data = arg;

Expand All @@ -188,7 +188,7 @@ encoder_construct_EVP_PKEY(OSSL_ENCODER_INSTANCE *encoder_inst, void *arg)
return data->obj;
}

static void encoder_destruct_EVP_PKEY(void *arg)
static void encoder_destruct_pkey(void *arg)
{
struct construct_data_st *data = arg;

Expand All @@ -202,15 +202,15 @@ static void encoder_destruct_EVP_PKEY(void *arg)
}

/*
* OSSL_ENCODER_CTX_new_by_EVP_PKEY() returns a ctx with no encoder if
* OSSL_ENCODER_CTX_new_for_pkey() returns a ctx with no encoder if
* it couldn't find a suitable encoder. This allows a caller to detect if
* a suitable encoder was found, with OSSL_ENCODER_CTX_get_num_encoder(),
* and to use fallback methods if the result is NULL.
*/
static int ossl_encoder_ctx_setup_for_EVP_PKEY(OSSL_ENCODER_CTX *ctx,
const EVP_PKEY *pkey,
int selection,
const char *propquery)
static int ossl_encoder_ctx_setup_for_pkey(OSSL_ENCODER_CTX *ctx,
const EVP_PKEY *pkey,
int selection,
const char *propquery)
{
struct construct_data_st *data = NULL;
OSSL_LIB_CTX *libctx = NULL;
Expand Down Expand Up @@ -262,9 +262,9 @@ static int ossl_encoder_ctx_setup_for_EVP_PKEY(OSSL_ENCODER_CTX *ctx,
}

if (OSSL_ENCODER_CTX_get_num_encoders(ctx) != 0) {
if (!OSSL_ENCODER_CTX_set_construct(ctx, encoder_construct_EVP_PKEY)
if (!OSSL_ENCODER_CTX_set_construct(ctx, encoder_construct_pkey)
|| !OSSL_ENCODER_CTX_set_construct_data(ctx, data)
|| !OSSL_ENCODER_CTX_set_cleanup(ctx, encoder_destruct_EVP_PKEY))
|| !OSSL_ENCODER_CTX_set_cleanup(ctx, encoder_destruct_pkey))
goto err;

data->pk = pkey;
Expand All @@ -282,11 +282,11 @@ static int ossl_encoder_ctx_setup_for_EVP_PKEY(OSSL_ENCODER_CTX *ctx,
return ok;
}

OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_by_EVP_PKEY(const EVP_PKEY *pkey,
int selection,
const char *output_type,
const char *output_struct,
const char *propquery)
OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey,
int selection,
const char *output_type,
const char *output_struct,
const char *propquery)
{
OSSL_ENCODER_CTX *ctx = NULL;
OSSL_LIB_CTX *libctx = NULL;
Expand Down Expand Up @@ -325,7 +325,7 @@ OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_by_EVP_PKEY(const EVP_PKEY *pkey,
&& (output_struct == NULL
|| OSSL_ENCODER_CTX_set_output_structure(ctx, output_struct))
&& OSSL_ENCODER_CTX_set_selection(ctx, selection)
&& ossl_encoder_ctx_setup_for_EVP_PKEY(ctx, pkey, selection, propquery)
&& ossl_encoder_ctx_setup_for_pkey(ctx, pkey, selection, propquery)
&& OSSL_ENCODER_CTX_add_extra(ctx, libctx, propquery)) {
OSSL_TRACE_BEGIN(ENCODER) {
BIO_printf(trc_out, "(ctx %p) Got %d encoders\n",
Expand Down
6 changes: 3 additions & 3 deletions crypto/evp/evp_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey)
size_t derlen = 0;
const unsigned char *pp;

if ((ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection,
"DER", "pkcs8",
NULL)) == NULL
if ((ctx = OSSL_ENCODER_CTX_new_for_pkey(pkey, selection,
"DER", "pkcs8",
NULL)) == NULL
|| !OSSL_ENCODER_to_data(ctx, &der, &derlen))
goto error;

Expand Down
4 changes: 2 additions & 2 deletions crypto/evp/p_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,8 @@ static int print_pkey(const EVP_PKEY *pkey, BIO *out, int indent,
if (!print_set_indent(&out, &pop_f_prefix, &saved_indent, indent))
return 0;

ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection, "TEXT", NULL,
propquery);
ctx = OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "TEXT", NULL,
propquery);
if (OSSL_ENCODER_CTX_get_num_encoders(ctx) != 0)
ret = OSSL_ENCODER_to_bio(ctx, out);
OSSL_ENCODER_CTX_free(ctx);
Expand Down
2 changes: 1 addition & 1 deletion crypto/pem/pem_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u)
# endif

#endif
IMPLEMENT_PEM_provided_write(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
IMPLEMENT_PEM_provided_write(PUBKEY, EVP_PKEY, pkey, PEM_STRING_PUBLIC, PUBKEY)

0 comments on commit fe75766

Please sign in to comment.