From 73c02a6201d08afb4ad5055fc3906e1d4504b578 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 2 Jun 2021 06:32:00 +0200 Subject: [PATCH] ENCODER: Drop OSSL_ENCODER_PARAM_INPUT_TYPE This was a poor substitute for using the name of the decoder implementation, and since there is functionality to get the latter now, this parameter can be dropped. Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15570) --- crypto/encode_decode/encoder_lib.c | 31 +++++++------------ crypto/encode_decode/encoder_local.h | 1 - doc/man3/OSSL_ENCODER_CTX.pod | 11 ------- doc/man7/provider-encoder.pod | 9 ------ include/openssl/core_names.h | 1 - include/openssl/encoder.h | 2 -- .../encode_decode/encode_key2any.c | 12 ++----- .../encode_decode/encode_key2text.c | 12 ++----- util/libcrypto.num | 1 - 9 files changed, 15 insertions(+), 65 deletions(-) diff --git a/crypto/encode_decode/encoder_lib.c b/crypto/encode_decode/encoder_lib.c index 4481773610..d90ce72528 100644 --- a/crypto/encode_decode/encoder_lib.c +++ b/crypto/encode_decode/encoder_lib.c @@ -36,6 +36,8 @@ struct encoder_process_data_st { OSSL_ENCODER_INSTANCE *prev_encoder_inst; unsigned char *running_output; size_t running_output_length; + /* Data type = the name of the first succeeding encoder implementation */ + const char *data_type; }; static int encoder_process(struct encoder_process_data_st *data); @@ -207,10 +209,7 @@ static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_OUTPUT_STRUCTURE, (char **)&encoder_inst->output_structure, 0); - params[2] = - OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_INPUT_TYPE, - (char **)&encoder_inst->input_type, 0); - params[3] = OSSL_PARAM_construct_end(); + params[2] = OSSL_PARAM_construct_end(); if (!encoder->get_params(params) || !OSSL_PARAM_modified(¶ms[0])) @@ -260,8 +259,8 @@ static int ossl_encoder_ctx_add_encoder_inst(OSSL_ENCODER_CTX *ctx, "(ctx %p) Added encoder instance %p (encoder %p) with:\n", (void *)ctx, (void *)ei, (void *)ei->encoder); BIO_printf(trc_out, - " output type: %s, output structure: %s, input type :%s\n", - ei->output_type, ei->output_structure, ei->input_type); + " output type: %s, output structure: %s\n", + ei->output_type, ei->output_structure); } OSSL_TRACE_END(ENCODER); } return ok; @@ -362,14 +361,6 @@ OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst) return encoder_inst->encoderctx; } -const char * -OSSL_ENCODER_INSTANCE_get_input_type(OSSL_ENCODER_INSTANCE *encoder_inst) -{ - if (encoder_inst == NULL) - return NULL; - return encoder_inst->input_type; -} - const char * OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst) { @@ -566,6 +557,9 @@ static int encoder_process(struct encoder_process_data_st *data) data->ctx->construct(current_encoder_inst, data->ctx->construct_data); + /* Also set the data type, using the encoder implementation name */ + data->data_type = OSSL_ENCODER_get0_name(current_encoder); + /* Assume that the constructor recorded an error */ if (original_data != NULL) ok = 1; @@ -586,15 +580,12 @@ static int encoder_process(struct encoder_process_data_st *data) */ OSSL_PARAM *abstract_p = abstract; - const char *prev_input_type = - OSSL_ENCODER_INSTANCE_get_input_type(data->prev_encoder_inst); const char *prev_output_structure = OSSL_ENCODER_INSTANCE_get_output_structure(data->prev_encoder_inst); - if (prev_input_type != NULL) - *abstract_p++ = - OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, - (char *)prev_input_type, 0); + *abstract_p++ = + OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, + (char *)data->data_type, 0); if (prev_output_structure != NULL) *abstract_p++ = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_STRUCTURE, diff --git a/crypto/encode_decode/encoder_local.h b/crypto/encode_decode/encoder_local.h index 0678fc2014..44bd39b757 100644 --- a/crypto/encode_decode/encoder_local.h +++ b/crypto/encode_decode/encoder_local.h @@ -59,7 +59,6 @@ struct ossl_decoder_st { struct ossl_encoder_instance_st { OSSL_ENCODER *encoder; /* Never NULL */ void *encoderctx; /* Never NULL */ - const char *input_type; /* May be NULL */ const char *output_type; /* Never NULL */ const char *output_structure; /* May be NULL */ }; diff --git a/doc/man3/OSSL_ENCODER_CTX.pod b/doc/man3/OSSL_ENCODER_CTX.pod index d4ea01060f..9dc9b71ab1 100644 --- a/doc/man3/OSSL_ENCODER_CTX.pod +++ b/doc/man3/OSSL_ENCODER_CTX.pod @@ -16,7 +16,6 @@ OSSL_ENCODER_CTX_get_num_encoders, OSSL_ENCODER_INSTANCE, OSSL_ENCODER_INSTANCE_get_encoder, OSSL_ENCODER_INSTANCE_get_encoder_ctx, -OSSL_ENCODER_INSTANCE_get_input_type, OSSL_ENCODER_INSTANCE_get_output_type, OSSL_ENCODER_INSTANCE_get_output_structure, OSSL_ENCODER_CONSTRUCT, @@ -55,8 +54,6 @@ OSSL_ENCODER_CTX_set_cleanup void * OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst); const char * - OSSL_ENCODER_INSTANCE_get_input_type(OSSL_ENCODER_INSTANCE *encoder_inst); - const char * OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst); const char * OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst); @@ -161,14 +158,6 @@ implementation of the encoder instance I. OSSL_ENCODER_INSTANCE_get_encoder_ctx() can be used to get the encoder implementation's provider context of the encoder instance I. -OSSL_ENCODER_INSTANCE_get_input_type() can be used to get the input type for -the encoder implementation of the encoder instance I. -This may be NULL. - -OSSL_ENCODER_INSTANCE_get_output_type() can be used to get the output type -for the encoder implementation of the encoder instance I. -This will never be NULL. - OSSL_ENCODER_INSTANCE_get_output_type() can be used to get the output type for the encoder implementation of the encoder instance I. This will never be NULL. diff --git a/doc/man7/provider-encoder.pod b/doc/man7/provider-encoder.pod index 9032036a6e..2f2e8ef6c6 100644 --- a/doc/man7/provider-encoder.pod +++ b/doc/man7/provider-encoder.pod @@ -247,15 +247,6 @@ determine how it fits in a chain of encoders: =over 4 -=item "input-type" (B) - -This is used to specify a distinct type name for the object passed as -I to OSSL_FUNC_encoder_encode. - -This parameter is an optional parameter, to be used if the name of the -implementation can be ambiguous because of aliases, and something more -deterministic is needed. - =item "output-type" (B) This is used to specify the output type for an ENCODER implementation. diff --git a/include/openssl/core_names.h b/include/openssl/core_names.h index 5bb284d658..5fa2225071 100644 --- a/include/openssl/core_names.h +++ b/include/openssl/core_names.h @@ -468,7 +468,6 @@ extern "C" { */ #define OSSL_ENCODER_PARAM_CIPHER OSSL_ALG_PARAM_CIPHER #define OSSL_ENCODER_PARAM_PROPERTIES OSSL_ALG_PARAM_PROPERTIES -#define OSSL_ENCODER_PARAM_INPUT_TYPE "input-type" #define OSSL_ENCODER_PARAM_OUTPUT_TYPE "output-type" #define OSSL_ENCODER_PARAM_OUTPUT_STRUCTURE "output-structure" /* Currently PVK only, but reusable for others as needed */ diff --git a/include/openssl/encoder.h b/include/openssl/encoder.h index e62e33fc89..c37a6f16f2 100644 --- a/include/openssl/encoder.h +++ b/include/openssl/encoder.h @@ -84,8 +84,6 @@ OSSL_ENCODER_INSTANCE_get_encoder(OSSL_ENCODER_INSTANCE *encoder_inst); void * OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst); const char * -OSSL_ENCODER_INSTANCE_get_input_type(OSSL_ENCODER_INSTANCE *encoder_inst); -const char * OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst); const char * OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst); diff --git a/providers/implementations/encode_decode/encode_key2any.c b/providers/implementations/encode_decode/encode_key2any.c index 8d32c64fbf..7efd88caee 100644 --- a/providers/implementations/encode_decode/encode_key2any.c +++ b/providers/implementations/encode_decode/encode_key2any.c @@ -884,13 +884,11 @@ static void key2any_freectx(void *vctx) static const OSSL_PARAM *key2any_gettable_params(void *provctx, int structure) { static const OSSL_PARAM gettables[] = { - { OSSL_ENCODER_PARAM_INPUT_TYPE, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 }, { OSSL_ENCODER_PARAM_OUTPUT_TYPE, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 }, OSSL_PARAM_END, }; static const OSSL_PARAM gettables_w_structure[] = { - { OSSL_ENCODER_PARAM_INPUT_TYPE, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 }, { OSSL_ENCODER_PARAM_OUTPUT_TYPE, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 }, { OSSL_ENCODER_PARAM_OUTPUT_STRUCTURE, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 }, OSSL_PARAM_END, @@ -899,16 +897,11 @@ static const OSSL_PARAM *key2any_gettable_params(void *provctx, int structure) return structure ? gettables_w_structure : gettables; } -static int key2any_get_params(OSSL_PARAM params[], const char *input_type, - const char *output_type, +static int key2any_get_params(OSSL_PARAM params[], const char *output_type, const char *output_struct) { OSSL_PARAM *p; - p = OSSL_PARAM_locate(params, OSSL_ENCODER_PARAM_INPUT_TYPE); - if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, input_type)) - return 0; - p = OSSL_PARAM_locate(params, OSSL_ENCODER_PARAM_OUTPUT_TYPE); if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, output_type)) return 0; @@ -1234,8 +1227,7 @@ static int key2any_encode(struct key2any_ctx_st *ctx, OSSL_CORE_BIO *cout, static int \ impl##_to_##kind##_##output##_get_params(OSSL_PARAM params[]) \ { \ - return key2any_get_params(params, impl##_input_type, \ - output##_output_type, \ + return key2any_get_params(params, output##_output_type, \ kind##_output_structure); \ } \ static void * \ diff --git a/providers/implementations/encode_decode/encode_key2text.c b/providers/implementations/encode_decode/encode_key2text.c index 9bdbe52656..6adbacaca6 100644 --- a/providers/implementations/encode_decode/encode_key2text.c +++ b/providers/implementations/encode_decode/encode_key2text.c @@ -805,14 +805,10 @@ static const OSSL_PARAM *key2text_gettable_params(void *provctx) return gettables; } -static int key2text_get_params(OSSL_PARAM params[], const char *input_type) +static int key2text_get_params(OSSL_PARAM params[]) { OSSL_PARAM *p; - p = OSSL_PARAM_locate(params, OSSL_ENCODER_PARAM_INPUT_TYPE); - if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, input_type)) - return 0; - p = OSSL_PARAM_locate(params, OSSL_ENCODER_PARAM_OUTPUT_TYPE); if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "TEXT")) return 0; @@ -847,10 +843,6 @@ static int key2text_encode(void *vctx, const void *key, int selection, impl##2text_free_object; \ static OSSL_FUNC_encoder_encode_fn impl##2text_encode; \ \ - static int impl##2text_get_params(OSSL_PARAM params[]) \ - { \ - return key2text_get_params(params, impl##_input_type); \ - } \ static void *impl##2text_import_object(void *ctx, int selection, \ const OSSL_PARAM params[]) \ { \ @@ -884,7 +876,7 @@ static int key2text_encode(void *vctx, const void *key, int selection, { OSSL_FUNC_ENCODER_GETTABLE_PARAMS, \ (void (*)(void))key2text_gettable_params }, \ { OSSL_FUNC_ENCODER_GET_PARAMS, \ - (void (*)(void))impl##2text_get_params }, \ + (void (*)(void))key2text_get_params }, \ { OSSL_FUNC_ENCODER_IMPORT_OBJECT, \ (void (*)(void))impl##2text_import_object }, \ { OSSL_FUNC_ENCODER_FREE_OBJECT, \ diff --git a/util/libcrypto.num b/util/libcrypto.num index 5c36c4d44a..182cd2b158 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -5249,7 +5249,6 @@ OSSL_ENCODER_CTX_get_num_encoders ? 3_0_0 EXIST::FUNCTION: OSSL_ENCODER_CTX_set_selection ? 3_0_0 EXIST::FUNCTION: OSSL_ENCODER_INSTANCE_get_encoder ? 3_0_0 EXIST::FUNCTION: OSSL_ENCODER_INSTANCE_get_encoder_ctx ? 3_0_0 EXIST::FUNCTION: -OSSL_ENCODER_INSTANCE_get_input_type ? 3_0_0 EXIST::FUNCTION: OSSL_ENCODER_INSTANCE_get_output_type ? 3_0_0 EXIST::FUNCTION: OSSL_ENCODER_CTX_set_construct ? 3_0_0 EXIST::FUNCTION: OSSL_ENCODER_CTX_set_construct_data ? 3_0_0 EXIST::FUNCTION: -- 2.39.5