diff options
author | Richard Levitte <levitte@openssl.org> | 2021-06-02 06:37:43 +0200 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-06-05 20:30:47 +1000 |
commit | e982e04f5dd12ee2546344b3a26fd0e55f59f5cb (patch) | |
tree | becb767d40a55957103c0e365a00c2dc4aeb0018 /crypto | |
parent | 73c02a6201d08afb4ad5055fc3906e1d4504b578 (diff) |
ENCODER: use property definitions instead of getting implementation parameters
The OSSL_ENCODER library used to ask each encoder implementation for
certain data in form of parameters to place them correctly in the
encoder chain, if at all. These parameters were duplicates of
properties of those same implementations, and therefore unnecessarily
redundant.
Now that we have functionality to query property definition values,
those duplicates are no longer needed, and are therefore not looked at
any more.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15570)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/encode_decode/encoder_lib.c | 57 | ||||
-rw-r--r-- | crypto/encode_decode/encoder_local.h | 2 | ||||
-rw-r--r-- | crypto/encode_decode/encoder_meth.c | 19 |
3 files changed, 51 insertions, 27 deletions
diff --git a/crypto/encode_decode/encoder_lib.c b/crypto/encode_decode/encoder_lib.c index d90ce72528..cb47e8bc71 100644 --- a/crypto/encode_decode/encoder_lib.c +++ b/crypto/encode_decode/encoder_lib.c @@ -16,6 +16,7 @@ #include <openssl/provider.h> #include <openssl/trace.h> #include "internal/bio.h" +#include "internal/provider.h" #include "encoder_local.h" struct encoder_process_data_st { @@ -180,46 +181,54 @@ static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, void *encoderctx) { OSSL_ENCODER_INSTANCE *encoder_inst = NULL; - OSSL_PARAM params[4]; + const OSSL_PROVIDER *prov; + OSSL_LIB_CTX *libctx; + const OSSL_PROPERTY_LIST *props; + const OSSL_PROPERTY_DEFINITION *prop; if (!ossl_assert(encoder != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); return 0; } - if (encoder->get_params == NULL) { - ERR_raise(ERR_LIB_OSSL_ENCODER, - OSSL_ENCODER_R_MISSING_GET_PARAMS); - return 0; - } - if ((encoder_inst = OPENSSL_zalloc(sizeof(*encoder_inst))) == NULL) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_MALLOC_FAILURE); return 0; } - /* - * Cache the input and output types for this encoder. The output type - * is mandatory. - */ - params[0] = - OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_OUTPUT_TYPE, - (char **)&encoder_inst->output_type, 0); - params[1] = - OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_OUTPUT_STRUCTURE, - (char **)&encoder_inst->output_structure, - 0); - params[2] = OSSL_PARAM_construct_end(); - - if (!encoder->get_params(params) - || !OSSL_PARAM_modified(¶ms[0])) - goto err; - if (!OSSL_ENCODER_up_ref(encoder)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_INTERNAL_ERROR); goto err; } + prov = OSSL_ENCODER_get0_provider(encoder); + libctx = ossl_provider_libctx(prov); + props = ossl_encoder_parsed_properties(encoder); + if (props == NULL) { + ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROPERTY_DEFINITION, + "there are no property definitions with encoder %s", + OSSL_ENCODER_get0_name(encoder)); + goto err; + } + + /* The "output" property is mandatory */ + prop = ossl_property_find_property(props, libctx, "output"); + encoder_inst->output_type = ossl_property_get_string_value(libctx, prop); + if (encoder_inst->output_type == NULL) { + ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROPERTY_DEFINITION, + "the mandatory 'output' property is missing " + "for encoder %s (properties: %s)", + OSSL_ENCODER_get0_name(encoder), + OSSL_ENCODER_get0_properties(encoder)); + goto err; + } + + /* The "structure" property is optional */ + prop = ossl_property_find_property(props, libctx, "structure"); + if (prop != NULL) + encoder_inst->output_structure + = ossl_property_get_string_value(libctx, prop); + encoder_inst->encoder = encoder; encoder_inst->encoderctx = encoderctx; return encoder_inst; diff --git a/crypto/encode_decode/encoder_local.h b/crypto/encode_decode/encoder_local.h index 44bd39b757..a0b10dcd5e 100644 --- a/crypto/encode_decode/encoder_local.h +++ b/crypto/encode_decode/encoder_local.h @@ -161,3 +161,5 @@ struct ossl_decoder_ctx_st { const OSSL_PROPERTY_LIST * ossl_decoder_parsed_properties(const OSSL_DECODER *decoder); +const OSSL_PROPERTY_LIST * +ossl_encoder_parsed_properties(const OSSL_ENCODER *encoder); diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c index 81cebb2659..d50f1dcd0b 100644 --- a/crypto/encode_decode/encoder_meth.c +++ b/crypto/encode_decode/encoder_meth.c @@ -59,6 +59,7 @@ void OSSL_ENCODER_free(OSSL_ENCODER *encoder) if (ref > 0) return; OPENSSL_free(encoder->base.name); + ossl_property_free(encoder->base.parsed_propdef); ossl_provider_free(encoder->base.prov); CRYPTO_THREAD_lock_free(encoder->base.lock); OPENSSL_free(encoder); @@ -166,6 +167,7 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, { OSSL_ENCODER *encoder = NULL; const OSSL_DISPATCH *fns = algodef->implementation; + OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov); if ((encoder = ossl_encoder_new()) == NULL) return NULL; @@ -176,6 +178,8 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, } encoder->base.propdef = algodef->property_definition; encoder->base.description = algodef->algorithm_description; + encoder->base.parsed_propdef + = ossl_parse_property(libctx, algodef->property_definition); for (; fns->function_id != 0; fns++) { switch (fns->function_id) { @@ -239,9 +243,7 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, || (encoder->newctx != NULL && encoder->freectx != NULL) || (encoder->import_object != NULL && encoder->free_object != NULL) || (encoder->import_object == NULL && encoder->free_object == NULL)) - || encoder->encode == NULL - || encoder->gettable_params == NULL - || encoder->get_params == NULL) { + || encoder->encode == NULL) { OSSL_ENCODER_free(encoder); ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_INVALID_PROVIDER_FUNCTIONS); return NULL; @@ -433,6 +435,17 @@ const char *OSSL_ENCODER_get0_properties(const OSSL_ENCODER *encoder) return encoder->base.propdef; } +const OSSL_PROPERTY_LIST * +ossl_encoder_parsed_properties(const OSSL_ENCODER *encoder) +{ + if (!ossl_assert(encoder != NULL)) { + ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); + return 0; + } + + return encoder->base.parsed_propdef; +} + int ossl_encoder_get_number(const OSSL_ENCODER *encoder) { if (!ossl_assert(encoder != NULL)) { |