diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:30:35 +0000 |
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:30:35 +0000 |
| commit | 677808048e318ef0c4ad69c0c2cc8d82167bffbe (patch) | |
| tree | bef7f1ad0365b42b56b6b8082996024b8483b96b /crypto/encode_decode | |
| parent | 12b8f7324509729dbf5c06c0e8fbc4723d3eefb3 (diff) | |
Diffstat (limited to 'crypto/encode_decode')
| -rw-r--r-- | crypto/encode_decode/decoder_err.c | 14 | ||||
| -rw-r--r-- | crypto/encode_decode/decoder_lib.c | 361 | ||||
| -rw-r--r-- | crypto/encode_decode/decoder_meth.c | 90 | ||||
| -rw-r--r-- | crypto/encode_decode/decoder_pkey.c | 173 | ||||
| -rw-r--r-- | crypto/encode_decode/encoder_err.c | 14 | ||||
| -rw-r--r-- | crypto/encode_decode/encoder_lib.c | 216 | ||||
| -rw-r--r-- | crypto/encode_decode/encoder_local.h | 12 | ||||
| -rw-r--r-- | crypto/encode_decode/encoder_meth.c | 100 | ||||
| -rw-r--r-- | crypto/encode_decode/encoder_pkey.c | 93 |
9 files changed, 552 insertions, 521 deletions
diff --git a/crypto/encode_decode/decoder_err.c b/crypto/encode_decode/decoder_err.c index 88324a1d5078..9e6556a1467d 100644 --- a/crypto/encode_decode/decoder_err.c +++ b/crypto/encode_decode/decoder_err.c @@ -15,13 +15,13 @@ #ifndef OPENSSL_NO_ERR static const ERR_STRING_DATA OSSL_DECODER_str_reasons[] = { - {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_COULD_NOT_DECODE_OBJECT), - "could not decode object"}, - {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_DECODER_NOT_FOUND), - "decoder not found"}, - {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_MISSING_GET_PARAMS), - "missing get params"}, - {0, NULL} + { ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_COULD_NOT_DECODE_OBJECT), + "could not decode object" }, + { ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_DECODER_NOT_FOUND), + "decoder not found" }, + { ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_MISSING_GET_PARAMS), + "missing get params" }, + { 0, NULL } }; #endif diff --git a/crypto/encode_decode/decoder_lib.c b/crypto/encode_decode/decoder_lib.c index 2e4b7ed60b9c..c7d6687197e6 100644 --- a/crypto/encode_decode/decoder_lib.c +++ b/crypto/encode_decode/decoder_lib.c @@ -57,9 +57,9 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) if (OSSL_DECODER_CTX_get_num_decoders(ctx) == 0) { ERR_raise_data(ERR_LIB_OSSL_DECODER, OSSL_DECODER_R_DECODER_NOT_FOUND, - "No decoders were found. For standard decoders you need " - "at least one of the default or base providers " - "available. Did you forget to load them?"); + "No decoders were found. For standard decoders you need " + "at least one of the default or base providers " + "available. Did you forget to load them?"); return 0; } @@ -83,14 +83,16 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) if (!data.flag_construct_called) { const char *spaces = ctx->start_input_type != NULL && ctx->input_structure != NULL - ? " " : ""; + ? " " + : ""; const char *input_type_label = ctx->start_input_type != NULL ? "Input type: " : ""; const char *input_structure_label = ctx->input_structure != NULL ? "Input structure: " : ""; const char *comma = ctx->start_input_type != NULL && ctx->input_structure != NULL - ? ", " : ""; + ? ", " + : ""; const char *input_type = ctx->start_input_type != NULL ? ctx->start_input_type : ""; const char *input_structure @@ -99,9 +101,9 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) if (ERR_peek_last_error() == lasterr || ERR_peek_error() == 0) /* Prevent spurious decoding error but add at least something */ ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_UNSUPPORTED, - "No supported data to decode. %s%s%s%s%s%s", - spaces, input_type_label, input_type, comma, - input_structure_label, input_structure); + "No supported data to decode. %s%s%s%s%s%s", + spaces, input_type_label, input_type, comma, + input_structure_label, input_structure); ok = 0; } @@ -142,7 +144,7 @@ int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *fp) #endif int OSSL_DECODER_from_data(OSSL_DECODER_CTX *ctx, const unsigned char **pdata, - size_t *pdata_len) + size_t *pdata_len) { BIO *membio; int ret = 0; @@ -178,7 +180,7 @@ int OSSL_DECODER_CTX_set_selection(OSSL_DECODER_CTX *ctx, int selection) } int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx, - const char *input_type) + const char *input_type) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -194,7 +196,7 @@ int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx, } int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx, - const char *input_structure) + const char *input_structure) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -210,7 +212,7 @@ int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx, } OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, - void *decoderctx) + void *decoderctx) { OSSL_DECODER_INSTANCE *decoder_inst = NULL; const OSSL_PROVIDER *prov; @@ -233,8 +235,8 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, props = ossl_decoder_parsed_properties(decoder); if (props == NULL) { ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROPERTY_DEFINITION, - "there are no property definitions with decoder %s", - OSSL_DECODER_get0_name(decoder)); + "there are no property definitions with decoder %s", + OSSL_DECODER_get0_name(decoder)); goto err; } @@ -243,10 +245,10 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, decoder_inst->input_type = ossl_property_get_string_value(libctx, prop); if (decoder_inst->input_type == NULL) { ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROPERTY_DEFINITION, - "the mandatory 'input' property is missing " - "for decoder %s (properties: %s)", - OSSL_DECODER_get0_name(decoder), - OSSL_DECODER_get0_properties(decoder)); + "the mandatory 'input' property is missing " + "for decoder %s (properties: %s)", + OSSL_DECODER_get0_name(decoder), + OSSL_DECODER_get0_properties(decoder)); goto err; } @@ -264,7 +266,7 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, decoder_inst->decoder = decoder; decoder_inst->decoderctx = decoderctx; return decoder_inst; - err: +err: ossl_decoder_instance_free(decoder_inst); return NULL; } @@ -282,27 +284,28 @@ void ossl_decoder_instance_free(OSSL_DECODER_INSTANCE *decoder_inst) } int ossl_decoder_ctx_add_decoder_inst(OSSL_DECODER_CTX *ctx, - OSSL_DECODER_INSTANCE *di) + OSSL_DECODER_INSTANCE *di) { int ok; if (ctx->decoder_insts == NULL - && (ctx->decoder_insts = - sk_OSSL_DECODER_INSTANCE_new_null()) == NULL) { + && (ctx->decoder_insts = sk_OSSL_DECODER_INSTANCE_new_null()) == NULL) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_MALLOC_FAILURE); return 0; } ok = (sk_OSSL_DECODER_INSTANCE_push(ctx->decoder_insts, di) > 0); if (ok) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) Added decoder instance %p for decoder %p\n" - " %s with %s\n", - (void *)ctx, (void *)di, (void *)di->decoder, - OSSL_DECODER_get0_name(di->decoder), - OSSL_DECODER_get0_properties(di->decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) Added decoder instance %p for decoder %p\n" + " %s with %s\n", + (void *)ctx, (void *)di, (void *)di->decoder, + OSSL_DECODER_get0_name(di->decoder), + OSSL_DECODER_get0_properties(di->decoder)); + } + OSSL_TRACE_END(DECODER); } return ok; } @@ -323,8 +326,7 @@ int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder) provctx = OSSL_PROVIDER_get0_provider_ctx(prov); if ((decoderctx = decoder->newctx(provctx)) == NULL - || (decoder_inst = - ossl_decoder_instance_new(decoder, decoderctx)) == NULL) + || (decoder_inst = ossl_decoder_instance_new(decoder, decoderctx)) == NULL) goto err; /* Avoid double free of decoderctx on further errors */ decoderctx = NULL; @@ -333,7 +335,7 @@ int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder) goto err; return 1; - err: +err: ossl_decoder_instance_free(decoder_inst); if (decoderctx != NULL) decoder->freectx(decoderctx); @@ -347,9 +349,10 @@ struct collect_extra_decoder_data_st { * 0 to check that the decoder's input type is the same as the decoder name * 1 to check that the decoder's input type differs from the decoder name */ - enum { IS_SAME = 0, IS_DIFFERENT = 1 } type_check; + enum { IS_SAME = 0, + IS_DIFFERENT = 1 } type_check; size_t w_prev_start, w_prev_end; /* "previous" decoders */ - size_t w_new_start, w_new_end; /* "new" decoders */ + size_t w_new_start, w_new_end; /* "new" decoders */ }; DEFINE_STACK_OF(OSSL_DECODER) @@ -359,7 +362,7 @@ static void collect_all_decoders(OSSL_DECODER *decoder, void *arg) STACK_OF(OSSL_DECODER) *skdecoders = arg; if (OSSL_DECODER_up_ref(decoder) - && !sk_OSSL_DECODER_push(skdecoders, decoder)) + && !sk_OSSL_DECODER_push(skdecoders, decoder)) OSSL_DECODER_free(decoder); } @@ -374,14 +377,16 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) void *decoderctx = NULL; OSSL_DECODER_INSTANCE *di = NULL; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) [%d] Checking out decoder %p:\n" - " %s with %s\n", - (void *)data->ctx, data->type_check, (void *)decoder, - OSSL_DECODER_get0_name(decoder), - OSSL_DECODER_get0_properties(decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) [%d] Checking out decoder %p:\n" + " %s with %s\n", + (void *)data->ctx, data->type_check, (void *)decoder, + OSSL_DECODER_get0_name(decoder), + OSSL_DECODER_get0_properties(decoder)); + } + OSSL_TRACE_END(DECODER); /* * Check that we don't already have this decoder in our stack, @@ -389,15 +394,16 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) * we have added in the current window. */ for (j = data->w_prev_start; j < data->w_new_end; j++) { - OSSL_DECODER_INSTANCE *check_inst = - sk_OSSL_DECODER_INSTANCE_value(data->ctx->decoder_insts, j); + OSSL_DECODER_INSTANCE *check_inst = sk_OSSL_DECODER_INSTANCE_value(data->ctx->decoder_insts, j); if (decoder->base.algodef == check_inst->decoder->base.algodef) { /* We found it, so don't do anything more */ - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - " REJECTED: already exists in the chain\n"); - } OSSL_TRACE_END(DECODER); + " REJECTED: already exists in the chain\n"); + } + OSSL_TRACE_END(DECODER); return; } } @@ -414,24 +420,28 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) case IS_SAME: /* If it differs, this is not a decoder to add for now. */ if (!OSSL_DECODER_is_a(decoder, - OSSL_DECODER_INSTANCE_get_input_type(di))) { + OSSL_DECODER_INSTANCE_get_input_type(di))) { ossl_decoder_instance_free(di); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - " REJECTED: input type doesn't match output type\n"); - } OSSL_TRACE_END(DECODER); + " REJECTED: input type doesn't match output type\n"); + } + OSSL_TRACE_END(DECODER); return; } break; case IS_DIFFERENT: /* If it's the same, this is not a decoder to add for now. */ if (OSSL_DECODER_is_a(decoder, - OSSL_DECODER_INSTANCE_get_input_type(di))) { + OSSL_DECODER_INSTANCE_get_input_type(di))) { ossl_decoder_instance_free(di); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - " REJECTED: input type matches output type\n"); - } OSSL_TRACE_END(DECODER); + " REJECTED: input type matches output type\n"); + } + OSSL_TRACE_END(DECODER); return; } break; @@ -451,7 +461,7 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) } int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, - OSSL_LIB_CTX *libctx, const char *propq) + OSSL_LIB_CTX *libctx, const char *propq) { /* * This function goes through existing decoder methods in @@ -494,11 +504,12 @@ int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, if (ctx->decoder_insts == NULL) return 1; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, "(ctx %p) Looking for extra decoders\n", - (void *)ctx); - } OSSL_TRACE_END(DECODER); - + (void *)ctx); + } + OSSL_TRACE_END(DECODER); skdecoders = sk_OSSL_DECODER_new_null(); if (skdecoders == NULL) { @@ -525,19 +536,17 @@ int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, * 1. All decoders that a different name than their input type. */ for (data.type_check = IS_SAME; - data.type_check <= IS_DIFFERENT; - data.type_check++) { + data.type_check <= IS_DIFFERENT; + data.type_check++) { for (i = data.w_prev_start; i < data.w_prev_end; i++) { - OSSL_DECODER_INSTANCE *decoder_inst = - sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); + OSSL_DECODER_INSTANCE *decoder_inst = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); data.output_type = OSSL_DECODER_INSTANCE_get_input_type(decoder_inst); - for (j = 0; j < numdecoders; j++) collect_extra_decoder(sk_OSSL_DECODER_value(skdecoders, j), - &data); + &data); } } /* How many were added in this iteration */ @@ -562,7 +571,7 @@ int OSSL_DECODER_CTX_get_num_decoders(OSSL_DECODER_CTX *ctx) } int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx, - OSSL_DECODER_CONSTRUCT *construct) + OSSL_DECODER_CONSTRUCT *construct) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -573,7 +582,7 @@ int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx, } int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx, - void *construct_data) + void *construct_data) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -584,7 +593,7 @@ int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx, } int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx, - OSSL_DECODER_CLEANUP *cleanup) + OSSL_DECODER_CLEANUP *cleanup) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -618,16 +627,16 @@ OSSL_DECODER_CTX_get_cleanup(OSSL_DECODER_CTX *ctx) } int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst, - void *reference, size_t reference_sz, - OSSL_CALLBACK *export_cb, void *export_cbarg) + void *reference, size_t reference_sz, + OSSL_CALLBACK *export_cb, void *export_cbarg) { OSSL_DECODER *decoder = NULL; void *decoderctx = NULL; if (!(ossl_assert(decoder_inst != NULL) - && ossl_assert(reference != NULL) - && ossl_assert(export_cb != NULL) - && ossl_assert(export_cbarg != NULL))) { + && ossl_assert(reference != NULL) + && ossl_assert(export_cb != NULL) + && ossl_assert(export_cbarg != NULL))) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); return 0; } @@ -635,7 +644,7 @@ int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst, decoder = OSSL_DECODER_INSTANCE_get_decoder(decoder_inst); decoderctx = OSSL_DECODER_INSTANCE_get_decoder_ctx(decoder_inst); return decoder->export_object(decoderctx, reference, reference_sz, - export_cb, export_cbarg); + export_cb, export_cbarg); } OSSL_DECODER * @@ -664,7 +673,7 @@ OSSL_DECODER_INSTANCE_get_input_type(OSSL_DECODER_INSTANCE *decoder_inst) const char * OSSL_DECODER_INSTANCE_get_input_structure(OSSL_DECODER_INSTANCE *decoder_inst, - int *was_set) + int *was_set) { if (decoder_inst == NULL) return NULL; @@ -699,49 +708,53 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) new_data.recursion = data->recursion + 1; #define LEVEL_STR ">>>>>>>>>>>>>>>>" -#define LEVEL (new_data.recursion < sizeof(LEVEL_STR) \ - ? &LEVEL_STR[sizeof(LEVEL_STR) - new_data.recursion - 1] \ - : LEVEL_STR "...") +#define LEVEL (new_data.recursion < sizeof(LEVEL_STR) \ + ? &LEVEL_STR[sizeof(LEVEL_STR) - new_data.recursion - 1] \ + : LEVEL_STR "...") if (params == NULL) { /* First iteration, where we prepare for what is to come */ - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) starting to walk the decoder chain\n", - (void *)new_data.ctx); - } OSSL_TRACE_END(DECODER); + "(ctx %p) starting to walk the decoder chain\n", + (void *)new_data.ctx); + } + OSSL_TRACE_END(DECODER); - data->current_decoder_inst_index = - OSSL_DECODER_CTX_get_num_decoders(ctx); + data->current_decoder_inst_index = OSSL_DECODER_CTX_get_num_decoders(ctx); bio = data->bio; } else { const OSSL_PARAM *p; const char *trace_data_structure; - decoder_inst = - sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, - data->current_decoder_inst_index); + decoder_inst = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, + data->current_decoder_inst_index); decoder = OSSL_DECODER_INSTANCE_get_decoder(decoder_inst); data->flag_construct_called = 0; if (ctx->construct != NULL) { int rv; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s Running constructor\n", - (void *)new_data.ctx, LEVEL); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s Running constructor\n", + (void *)new_data.ctx, LEVEL); + } + OSSL_TRACE_END(DECODER); rv = ctx->construct(decoder_inst, params, ctx->construct_data); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s Running constructor => %d\n", - (void *)new_data.ctx, LEVEL, rv); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s Running constructor => %d\n", + (void *)new_data.ctx, LEVEL, rv); + } + OSSL_TRACE_END(DECODER); ok = (rv > 0); if (ok) { @@ -794,15 +807,18 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) && OPENSSL_strcasecmp(data_structure, "type-specific") == 0) data_structure = NULL; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s incoming from previous decoder (%p):\n" - " data type: %s, data structure: %s%s\n", - (void *)new_data.ctx, LEVEL, (void *)decoder, - data_type, trace_data_structure, - (trace_data_structure == data_structure - ? "" : " (dropped)")); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s incoming from previous decoder (%p):\n" + " data type: %s, data structure: %s%s\n", + (void *)new_data.ctx, LEVEL, (void *)decoder, + data_type, trace_data_structure, + (trace_data_structure == data_structure + ? "" + : " (dropped)")); + } + OSSL_TRACE_END(DECODER); } /* @@ -823,28 +839,25 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) } for (i = data->current_decoder_inst_index; i-- > 0;) { - OSSL_DECODER_INSTANCE *new_decoder_inst = - sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); - OSSL_DECODER *new_decoder = - OSSL_DECODER_INSTANCE_get_decoder(new_decoder_inst); - void *new_decoderctx = - OSSL_DECODER_INSTANCE_get_decoder_ctx(new_decoder_inst); - const char *new_input_type = - OSSL_DECODER_INSTANCE_get_input_type(new_decoder_inst); - int n_i_s_was_set = 0; /* We don't care here */ - const char *new_input_structure = - OSSL_DECODER_INSTANCE_get_input_structure(new_decoder_inst, - &n_i_s_was_set); + OSSL_DECODER_INSTANCE *new_decoder_inst = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); + OSSL_DECODER *new_decoder = OSSL_DECODER_INSTANCE_get_decoder(new_decoder_inst); + void *new_decoderctx = OSSL_DECODER_INSTANCE_get_decoder_ctx(new_decoder_inst); + const char *new_input_type = OSSL_DECODER_INSTANCE_get_input_type(new_decoder_inst); + int n_i_s_was_set = 0; /* We don't care here */ + const char *new_input_structure = OSSL_DECODER_INSTANCE_get_input_structure(new_decoder_inst, + &n_i_s_was_set); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] Considering decoder instance %p (decoder %p):\n" - " %s with %s\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - (void *)new_decoder_inst, (void *)new_decoder, - OSSL_DECODER_get0_name(new_decoder), - OSSL_DECODER_get0_properties(new_decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] Considering decoder instance %p (decoder %p):\n" + " %s with %s\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + (void *)new_decoder_inst, (void *)new_decoder, + OSSL_DECODER_get0_name(new_decoder), + OSSL_DECODER_get0_properties(new_decoder)); + } + OSSL_TRACE_END(DECODER); /* * If |decoder| is NULL, it means we've just started, and the caller @@ -853,12 +866,14 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) */ if (decoder == NULL && ctx->start_input_type != NULL && OPENSSL_strcasecmp(ctx->start_input_type, new_input_type) != 0) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the start input type '%s' doesn't match the input type of the considered decoder, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - ctx->start_input_type); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the start input type '%s' doesn't match the input type of the considered decoder, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + ctx->start_input_type); + } + OSSL_TRACE_END(DECODER); continue; } @@ -869,12 +884,14 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) * for the decoder we're currently considering. */ if (decoder != NULL && !OSSL_DECODER_is_a(decoder, new_input_type)) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the input type doesn't match the name of the previous decoder (%p), skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - (void *)decoder); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the input type doesn't match the name of the previous decoder (%p), skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + (void *)decoder); + } + OSSL_TRACE_END(DECODER); continue; } @@ -883,11 +900,13 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) * if that matches the decoder we're currently considering. */ if (data_type != NULL && !OSSL_DECODER_is_a(new_decoder, data_type)) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the previous decoder's data type doesn't match the name of the considered decoder, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the previous decoder's data type doesn't match the name of the considered decoder, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i); + } + OSSL_TRACE_END(DECODER); continue; } @@ -899,12 +918,15 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) if (data_structure != NULL && (new_input_structure == NULL || OPENSSL_strcasecmp(data_structure, - new_input_structure) != 0)) { - OSSL_TRACE_BEGIN(DECODER) { + new_input_structure) + != 0)) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure of the considered decoder, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure of the considered decoder, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i); + } + OSSL_TRACE_END(DECODER); continue; } @@ -919,12 +941,15 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) && new_input_structure != NULL) { data->flag_input_structure_checked = 1; if (OPENSSL_strcasecmp(new_input_structure, - ctx->input_structure) != 0) { - OSSL_TRACE_BEGIN(DECODER) { + ctx->input_structure) + != 0) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure given by the user, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure given by the user, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i); + } + OSSL_TRACE_END(DECODER); continue; } } @@ -944,12 +969,14 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) goto end; /* Recurse */ - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] Running decoder instance %p\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - (void *)new_decoder_inst); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] Running decoder instance %p\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + (void *)new_decoder_inst); + } + OSSL_TRACE_END(DECODER); /* * We only care about errors reported from decoder implementations @@ -961,20 +988,22 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) new_data.flag_input_structure_checked = data->flag_input_structure_checked; ok = new_decoder->decode(new_decoderctx, cbio, - new_data.ctx->selection, - decoder_process, &new_data, - ossl_pw_passphrase_callback_dec, - &new_data.ctx->pwdata); + new_data.ctx->selection, + decoder_process, &new_data, + ossl_pw_passphrase_callback_dec, + &new_data.ctx->pwdata); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] Running decoder instance %p => %d" - " (recursed further: %s, construct called: %s)\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - (void *)new_decoder_inst, ok, - new_data.flag_next_level_called ? "yes" : "no", - new_data.flag_construct_called ? "yes" : "no"); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] Running decoder instance %p => %d" + " (recursed further: %s, construct called: %s)\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + (void *)new_decoder_inst, ok, + new_data.flag_next_level_called ? "yes" : "no", + new_data.flag_construct_called ? "yes" : "no"); + } + OSSL_TRACE_END(DECODER); data->flag_construct_called = new_data.flag_construct_called; @@ -993,7 +1022,7 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) break; } - end: +end: ossl_core_bio_free(cbio); BIO_free(new_data.bio); return ok; diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c index 56899a926981..ee6f30ecd953 100644 --- a/crypto/encode_decode/decoder_meth.c +++ b/crypto/encode_decode/decoder_meth.c @@ -76,7 +76,6 @@ static void *decoder_store_new(OSSL_LIB_CTX *ctx) return ossl_method_store_new(ctx); } - static const OSSL_LIB_CTX_METHOD decoder_store_method = { /* We want decoder_store to be cleaned up before the provider store */ OSSL_LIB_CTX_METHOD_PRIORITY_2, @@ -87,9 +86,9 @@ static const OSSL_LIB_CTX_METHOD decoder_store_method = { /* Data to be passed through ossl_method_construct() */ struct decoder_data_st { OSSL_LIB_CTX *libctx; - int id; /* For get_decoder_from_store() */ - const char *names; /* For get_decoder_from_store() */ - const char *propquery; /* For get_decoder_from_store() */ + int id; /* For get_decoder_from_store() */ + const char *names; /* For get_decoder_from_store() */ + const char *propquery; /* For get_decoder_from_store() */ OSSL_METHOD_STORE *tmp_store; /* For get_tmp_decoder_store() */ @@ -121,7 +120,7 @@ static void dealloc_tmp_decoder_store(void *store) static OSSL_METHOD_STORE *get_decoder_store(OSSL_LIB_CTX *libctx) { return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_DECODER_STORE_INDEX, - &decoder_store_method); + &decoder_store_method); } static int reserve_decoder_store(void *store, void *data) @@ -148,7 +147,7 @@ static int unreserve_decoder_store(void *store, void *data) /* Get decoder methods from a store, or put one in */ static void *get_decoder_from_store(void *store, const OSSL_PROVIDER **prov, - void *data) + void *data) { struct decoder_data_st *methdata = data; void *method = NULL; @@ -183,9 +182,9 @@ static void *get_decoder_from_store(void *store, const OSSL_PROVIDER **prov, } static int put_decoder_in_store(void *store, void *method, - const OSSL_PROVIDER *prov, - const char *names, const char *propdef, - void *data) + const OSSL_PROVIDER *prov, + const char *names, const char *propdef, + void *data) { struct decoder_data_st *methdata = data; OSSL_NAMEMAP *namemap; @@ -212,13 +211,13 @@ static int put_decoder_in_store(void *store, void *method, return 0; return ossl_method_store_add(store, prov, id, propdef, method, - (int (*)(void *))OSSL_DECODER_up_ref, - (void (*)(void *))OSSL_DECODER_free); + (int (*)(void *))OSSL_DECODER_up_ref, + (void (*)(void *))OSSL_DECODER_free); } /* Create and populate a decoder method */ void *ossl_decoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, - OSSL_PROVIDER *prov) + OSSL_PROVIDER *prov) { OSSL_DECODER *decoder = NULL; const OSSL_DISPATCH *fns = algodef->implementation; @@ -233,7 +232,8 @@ void *ossl_decoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, } decoder->base.algodef = algodef; if ((decoder->base.parsed_propdef - = ossl_parse_property(libctx, algodef->property_definition)) == NULL) { + = ossl_parse_property(libctx, algodef->property_definition)) + == NULL) { OSSL_DECODER_free(decoder); return NULL; } @@ -250,28 +250,23 @@ void *ossl_decoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, break; case OSSL_FUNC_DECODER_GET_PARAMS: if (decoder->get_params == NULL) - decoder->get_params = - OSSL_FUNC_decoder_get_params(fns); + decoder->get_params = OSSL_FUNC_decoder_get_params(fns); break; case OSSL_FUNC_DECODER_GETTABLE_PARAMS: if (decoder->gettable_params == NULL) - decoder->gettable_params = - OSSL_FUNC_decoder_gettable_params(fns); + decoder->gettable_params = OSSL_FUNC_decoder_gettable_params(fns); break; case OSSL_FUNC_DECODER_SET_CTX_PARAMS: if (decoder->set_ctx_params == NULL) - decoder->set_ctx_params = - OSSL_FUNC_decoder_set_ctx_params(fns); + decoder->set_ctx_params = OSSL_FUNC_decoder_set_ctx_params(fns); break; case OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS: if (decoder->settable_ctx_params == NULL) - decoder->settable_ctx_params = - OSSL_FUNC_decoder_settable_ctx_params(fns); + decoder->settable_ctx_params = OSSL_FUNC_decoder_settable_ctx_params(fns); break; case OSSL_FUNC_DECODER_DOES_SELECTION: if (decoder->does_selection == NULL) - decoder->does_selection = - OSSL_FUNC_decoder_does_selection(fns); + decoder->does_selection = OSSL_FUNC_decoder_does_selection(fns); break; case OSSL_FUNC_DECODER_DECODE: if (decoder->decode == NULL) @@ -289,7 +284,7 @@ void *ossl_decoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, * You must have at least one of the encoding driver functions. */ if (!((decoder->newctx == NULL && decoder->freectx == NULL) - || (decoder->newctx != NULL && decoder->freectx != NULL)) + || (decoder->newctx != NULL && decoder->freectx != NULL)) || decoder->decode == NULL) { OSSL_DECODER_free(decoder); ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROVIDER_FUNCTIONS); @@ -305,14 +300,13 @@ void *ossl_decoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, return decoder; } - /* * The core fetching functionality passes the names of the implementation. * This function is responsible to getting an identity number for them, * then call ossl_decoder_from_algorithm() with that identity number. */ static void *construct_decoder(const OSSL_ALGORITHM *algodef, - OSSL_PROVIDER *prov, void *data) + OSSL_PROVIDER *prov, void *data) { /* * This function is only called if get_decoder_from_store() returned @@ -360,7 +354,7 @@ static void free_decoder(void *method) /* Fetching support. Can fetch by numeric identity or by name */ static OSSL_DECODER * inner_ossl_decoder_fetch(struct decoder_data_st *methdata, int id, - const char *name, const char *properties) + const char *name, const char *properties) { OSSL_METHOD_STORE *store = get_decoder_store(methdata->libctx); OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx); @@ -410,8 +404,9 @@ inner_ossl_decoder_fetch(struct decoder_data_st *methdata, int id, methdata->propquery = propq; methdata->flag_construct_error_occurred = 0; if ((method = ossl_method_construct(methdata->libctx, OSSL_OP_DECODER, - &prov, 0 /* !force_cache */, - &mcm, methdata)) != NULL) { + &prov, 0 /* !force_cache */, + &mcm, methdata)) + != NULL) { /* * If construction did create a method for us, we know that * there is a correct name_id and meth_id, since those have @@ -422,7 +417,7 @@ inner_ossl_decoder_fetch(struct decoder_data_st *methdata, int id, id = ossl_namemap_name2num(namemap, name); if (id != 0) ossl_method_store_cache_set(store, prov, id, propq, method, - up_ref_decoder, free_decoder); + up_ref_decoder, free_decoder); } /* @@ -438,17 +433,17 @@ inner_ossl_decoder_fetch(struct decoder_data_st *methdata, int id, if (name == NULL) name = ossl_namemap_num2name(namemap, id, 0); ERR_raise_data(ERR_LIB_OSSL_DECODER, code, - "%s, Name (%s : %d), Properties (%s)", - ossl_lib_ctx_get_descriptor(methdata->libctx), - name == NULL ? "<null>" : name, id, - properties == NULL ? "<null>" : properties); + "%s, Name (%s : %d), Properties (%s)", + ossl_lib_ctx_get_descriptor(methdata->libctx), + name == NULL ? "<null>" : name, id, + properties == NULL ? "<null>" : properties); } return method; } OSSL_DECODER *OSSL_DECODER_fetch(OSSL_LIB_CTX *libctx, const char *name, - const char *properties) + const char *properties) { struct decoder_data_st methdata; void *method; @@ -461,7 +456,7 @@ OSSL_DECODER *OSSL_DECODER_fetch(OSSL_LIB_CTX *libctx, const char *name, } OSSL_DECODER *ossl_decoder_fetch_by_number(OSSL_LIB_CTX *libctx, int id, - const char *properties) + const char *properties) { struct decoder_data_st methdata; void *method; @@ -571,9 +566,9 @@ static void do_one(ossl_unused int id, void *method, void *arg) } void OSSL_DECODER_do_all_provided(OSSL_LIB_CTX *libctx, - void (*user_fn)(OSSL_DECODER *decoder, - void *arg), - void *user_arg) + void (*user_fn)(OSSL_DECODER *decoder, + void *arg), + void *user_arg) { struct decoder_data_st methdata; struct do_one_data_st data; @@ -591,8 +586,8 @@ void OSSL_DECODER_do_all_provided(OSSL_LIB_CTX *libctx, } int OSSL_DECODER_names_do_all(const OSSL_DECODER *decoder, - void (*fn)(const char *name, void *data), - void *data) + void (*fn)(const char *name, void *data), + void *data) { if (decoder == NULL) return 0; @@ -657,7 +652,7 @@ OSSL_DECODER_CTX *OSSL_DECODER_CTX_new(void) } int OSSL_DECODER_CTX_set_params(OSSL_DECODER_CTX *ctx, - const OSSL_PARAM params[]) + const OSSL_PARAM params[]) { int ok = 1; size_t i; @@ -673,12 +668,9 @@ int OSSL_DECODER_CTX_set_params(OSSL_DECODER_CTX *ctx, l = OSSL_DECODER_CTX_get_num_decoders(ctx); for (i = 0; i < l; i++) { - OSSL_DECODER_INSTANCE *decoder_inst = - sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); - OSSL_DECODER *decoder = - OSSL_DECODER_INSTANCE_get_decoder(decoder_inst); - OSSL_DECODER *decoderctx = - OSSL_DECODER_INSTANCE_get_decoder_ctx(decoder_inst); + OSSL_DECODER_INSTANCE *decoder_inst = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); + OSSL_DECODER *decoder = OSSL_DECODER_INSTANCE_get_decoder(decoder_inst); + OSSL_DECODER *decoderctx = OSSL_DECODER_INSTANCE_get_decoder_ctx(decoder_inst); if (decoderctx == NULL || decoder->set_ctx_params == NULL) continue; @@ -694,7 +686,7 @@ void OSSL_DECODER_CTX_free(OSSL_DECODER_CTX *ctx) if (ctx->cleanup != NULL) ctx->cleanup(ctx->construct_data); sk_OSSL_DECODER_INSTANCE_pop_free(ctx->decoder_insts, - ossl_decoder_instance_free); + ossl_decoder_instance_free); ossl_pw_clear_passphrase_data(&ctx->pwdata); OPENSSL_free(ctx); } diff --git a/crypto/encode_decode/decoder_pkey.c b/crypto/encode_decode/decoder_pkey.c index ad5e2805319b..38fa7e5b5db5 100644 --- a/crypto/encode_decode/decoder_pkey.c +++ b/crypto/encode_decode/decoder_pkey.c @@ -20,28 +20,28 @@ #include "encoder_local.h" int OSSL_DECODER_CTX_set_passphrase(OSSL_DECODER_CTX *ctx, - const unsigned char *kstr, - size_t klen) + const unsigned char *kstr, + size_t klen) { return ossl_pw_set_passphrase(&ctx->pwdata, kstr, klen); } int OSSL_DECODER_CTX_set_passphrase_ui(OSSL_DECODER_CTX *ctx, - const UI_METHOD *ui_method, - void *ui_data) + const UI_METHOD *ui_method, + void *ui_data) { return ossl_pw_set_ui_method(&ctx->pwdata, ui_method, ui_data); } int OSSL_DECODER_CTX_set_pem_password_cb(OSSL_DECODER_CTX *ctx, - pem_password_cb *cb, void *cbarg) + pem_password_cb *cb, void *cbarg) { return ossl_pw_set_pem_password_cb(&ctx->pwdata, cb, cbarg); } int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx, - OSSL_PASSPHRASE_CALLBACK *cb, - void *cbarg) + OSSL_PASSPHRASE_CALLBACK *cb, + void *cbarg) { return ossl_pw_set_ossl_passphrase_cb(&ctx->pwdata, cb, cbarg); } @@ -59,13 +59,13 @@ struct decoder_pkey_data_st { int selection; STACK_OF(EVP_KEYMGMT) *keymgmts; - char *object_type; /* recorded object data type, may be NULL */ - void **object; /* Where the result should end up */ + char *object_type; /* recorded object data type, may be NULL */ + void **object; /* Where the result should end up */ }; static int decoder_construct_pkey(OSSL_DECODER_INSTANCE *decoder_inst, - const OSSL_PARAM *params, - void *construct_data) + const OSSL_PARAM *params, + void *construct_data) { struct decoder_pkey_data_st *data = construct_data; OSSL_DECODER *decoder = OSSL_DECODER_INSTANCE_get_decoder(decoder_inst); @@ -126,8 +126,9 @@ static int decoder_construct_pkey(OSSL_DECODER_INSTANCE *decoder_inst, if (!EVP_KEYMGMT_up_ref(keymgmt)) return 0; } else if ((keymgmt = EVP_KEYMGMT_fetch(data->libctx, - data->object_type, - data->propq)) != NULL) { + data->object_type, + data->propq)) + != NULL) { keymgmt_prov = EVP_KEYMGMT_get0_provider(keymgmt); } @@ -161,9 +162,9 @@ static int decoder_construct_pkey(OSSL_DECODER_INSTANCE *decoder_inst, * |import_data.keydata| is as much an indicator. */ (void)decoder->export_object(decoderctx, - object_ref, object_ref_sz, - &evp_keymgmt_util_try_import, - &import_data); + object_ref, object_ref_sz, + &evp_keymgmt_util_try_import, + &import_data); keydata = import_data.keydata; import_data.keydata = NULL; } @@ -213,7 +214,7 @@ static void collect_keymgmt(EVP_KEYMGMT *keymgmt, void *arg) if (!EVP_KEYMGMT_up_ref(keymgmt) /* ref++ */) return; if (sk_EVP_KEYMGMT_push(keymgmts, keymgmt) <= 0) { - EVP_KEYMGMT_free(keymgmt); /* ref-- */ + EVP_KEYMGMT_free(keymgmt); /* ref-- */ return; } } @@ -223,7 +224,7 @@ struct collect_decoder_data_st { OSSL_DECODER_CTX *ctx; int total; - unsigned int error_occurred:1; + unsigned int error_occurred : 1; }; static void collect_decoder(OSSL_DECODER *decoder, void *arg) @@ -248,17 +249,19 @@ static void collect_decoder(OSSL_DECODER *decoder, void *arg) * it's seen as taking anything. */ if (decoder->does_selection != NULL - && !decoder->does_selection(provctx, data->ctx->selection)) + && !decoder->does_selection(provctx, data->ctx->selection)) return; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) Checking out decoder %p:\n" - " %s with %s\n", - (void *)data->ctx, (void *)decoder, - OSSL_DECODER_get0_name(decoder), - OSSL_DECODER_get0_properties(decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) Checking out decoder %p:\n" + " %s with %s\n", + (void *)data->ctx, (void *)decoder, + OSSL_DECODER_get0_name(decoder), + OSSL_DECODER_get0_properties(decoder)); + } + OSSL_TRACE_END(DECODER); end_i = sk_OPENSSL_CSTRING_num(data->names); for (i = 0; i < end_i; i++) { @@ -278,14 +281,16 @@ static void collect_decoder(OSSL_DECODER *decoder, void *arg) return; } - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) Checking out decoder %p:\n" - " %s with %s\n", - (void *)data->ctx, (void *)decoder, - OSSL_DECODER_get0_name(decoder), - OSSL_DECODER_get0_properties(decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) Checking out decoder %p:\n" + " %s with %s\n", + (void *)data->ctx, (void *)decoder, + OSSL_DECODER_get0_name(decoder), + OSSL_DECODER_get0_properties(decoder)); + } + OSSL_TRACE_END(DECODER); if (!ossl_decoder_ctx_add_decoder_inst(data->ctx, di)) { ossl_decoder_instance_free(di); @@ -304,9 +309,9 @@ static void collect_decoder(OSSL_DECODER *decoder, void *arg) } int ossl_decoder_ctx_setup_for_pkey(OSSL_DECODER_CTX *ctx, - EVP_PKEY **pkey, const char *keytype, - OSSL_LIB_CTX *libctx, - const char *propquery) + EVP_PKEY **pkey, const char *keytype, + OSSL_LIB_CTX *libctx, + const char *propquery) { struct decoder_pkey_data_st *process_data = NULL; STACK_OF(OPENSSL_CSTRING) *names = NULL; @@ -317,21 +322,23 @@ int ossl_decoder_ctx_setup_for_pkey(OSSL_DECODER_CTX *ctx, int i, end; if (keytype != NULL - && (strcmp(keytype, "id-ecPublicKey") == 0 - || strcmp(keytype, "1.2.840.10045.2.1") == 0)) + && (strcmp(keytype, "id-ecPublicKey") == 0 + || strcmp(keytype, "1.2.840.10045.2.1") == 0)) isecoid = 1; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) Looking for decoders producing %s%s%s%s%s%s\n", - (void *)ctx, - keytype != NULL ? keytype : "", - keytype != NULL ? " keys" : "keys of any type", - input_type != NULL ? " from " : "", - input_type != NULL ? input_type : "", - input_structure != NULL ? " with " : "", - input_structure != NULL ? input_structure : ""); - } OSSL_TRACE_END(DECODER); + "(ctx %p) Looking for decoders producing %s%s%s%s%s%s\n", + (void *)ctx, + keytype != NULL ? keytype : "", + keytype != NULL ? " keys" : "keys of any type", + input_type != NULL ? " from " : "", + input_type != NULL ? input_type : "", + input_structure != NULL ? " with " : "", + input_structure != NULL ? input_structure : ""); + } + OSSL_TRACE_END(DECODER); if ((process_data = OPENSSL_zalloc(sizeof(*process_data))) == NULL || (propquery != NULL @@ -348,7 +355,7 @@ int ossl_decoder_ctx_setup_for_pkey(OSSL_DECODER_CTX *ctx, /* First, find all keymgmts to form goals */ EVP_KEYMGMT_do_all_provided(libctx, collect_keymgmt, - process_data->keymgmts); + process_data->keymgmts); /* Then, we collect all the keymgmt names */ end = sk_EVP_KEYMGMT_num(process_data->keymgmts); @@ -363,8 +370,8 @@ int ossl_decoder_ctx_setup_for_pkey(OSSL_DECODER_CTX *ctx, * we have seen that OID we try both key types */ if (keytype == NULL - || EVP_KEYMGMT_is_a(keymgmt, keytype) - || (isecoid && EVP_KEYMGMT_is_a(keymgmt, "SM2"))) { + || EVP_KEYMGMT_is_a(keymgmt, keytype) + || (isecoid && EVP_KEYMGMT_is_a(keymgmt, "SM2"))) { if (!EVP_KEYMGMT_names_do_all(keymgmt, collect_name, names)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_INTERNAL_ERROR); goto err; @@ -372,54 +379,60 @@ int ossl_decoder_ctx_setup_for_pkey(OSSL_DECODER_CTX *ctx, } } - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { end = sk_OPENSSL_CSTRING_num(names); BIO_printf(trc_out, - " Found %d keytypes (possibly with duplicates)", - end); + " Found %d keytypes (possibly with duplicates)", + end); for (i = 0; i < end; i++) BIO_printf(trc_out, "%s%s", - i == 0 ? ": " : ", ", - sk_OPENSSL_CSTRING_value(names, i)); + i == 0 ? ": " : ", ", + sk_OPENSSL_CSTRING_value(names, i)); BIO_printf(trc_out, "\n"); - } OSSL_TRACE_END(DECODER); + } + OSSL_TRACE_END(DECODER); /* * Finally, find all decoders that have any keymgmt of the collected * keymgmt names */ { - struct collect_decoder_data_st collect_decoder_data = { NULL, }; + struct collect_decoder_data_st collect_decoder_data = { + NULL, + }; collect_decoder_data.names = names; collect_decoder_data.ctx = ctx; OSSL_DECODER_do_all_provided(libctx, - collect_decoder, &collect_decoder_data); + collect_decoder, &collect_decoder_data); sk_OPENSSL_CSTRING_free(names); names = NULL; if (collect_decoder_data.error_occurred) goto err; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) Got %d decoders producing keys\n", - (void *)ctx, collect_decoder_data.total); - } OSSL_TRACE_END(DECODER); + "(ctx %p) Got %d decoders producing keys\n", + (void *)ctx, collect_decoder_data.total); + } + OSSL_TRACE_END(DECODER); } if (OSSL_DECODER_CTX_get_num_decoders(ctx) != 0) { 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_pkey_construct_arg)) + decoder_clean_pkey_construct_arg)) goto err; process_data = NULL; /* Avoid it being freed */ } ok = 1; - err: +err: decoder_clean_pkey_construct_arg(process_data); sk_OPENSSL_CSTRING_free(names); @@ -428,10 +441,10 @@ int ossl_decoder_ctx_setup_for_pkey(OSSL_DECODER_CTX *ctx, OSSL_DECODER_CTX * 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) + 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; @@ -440,24 +453,28 @@ OSSL_DECODER_CTX_new_for_pkey(EVP_PKEY **pkey, return NULL; } - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) Looking for %s decoders with selection %d\n", - (void *)ctx, keytype, selection); + "(ctx %p) Looking for %s decoders with selection %d\n", + (void *)ctx, keytype, selection); BIO_printf(trc_out, " input type: %s, input structure: %s\n", - input_type, input_structure); - } OSSL_TRACE_END(DECODER); + input_type, input_structure); + } + OSSL_TRACE_END(DECODER); 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_pkey(ctx, pkey, keytype, - libctx, propquery) + libctx, propquery) && OSSL_DECODER_CTX_add_extra(ctx, libctx, propquery)) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, "(ctx %p) Got %d decoders\n", - (void *)ctx, OSSL_DECODER_CTX_get_num_decoders(ctx)); - } OSSL_TRACE_END(DECODER); + (void *)ctx, OSSL_DECODER_CTX_get_num_decoders(ctx)); + } + OSSL_TRACE_END(DECODER); return ctx; } diff --git a/crypto/encode_decode/encoder_err.c b/crypto/encode_decode/encoder_err.c index a904e87ef2e7..79b12f9c31df 100644 --- a/crypto/encode_decode/encoder_err.c +++ b/crypto/encode_decode/encoder_err.c @@ -15,13 +15,13 @@ #ifndef OPENSSL_NO_ERR static const ERR_STRING_DATA OSSL_ENCODER_str_reasons[] = { - {ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_ENCODER_NOT_FOUND), - "encoder not found"}, - {ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_INCORRECT_PROPERTY_QUERY), - "incorrect property query"}, - {ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_MISSING_GET_PARAMS), - "missing get params"}, - {0, NULL} + { ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_ENCODER_NOT_FOUND), + "encoder not found" }, + { ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_INCORRECT_PROPERTY_QUERY), + "incorrect property query" }, + { ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_MISSING_GET_PARAMS), + "missing get params" }, + { 0, NULL } }; #endif diff --git a/crypto/encode_decode/encoder_lib.c b/crypto/encode_decode/encoder_lib.c index a88332b79d52..b3eead4b85c3 100644 --- a/crypto/encode_decode/encoder_lib.c +++ b/crypto/encode_decode/encoder_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2026 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -28,7 +28,7 @@ struct encoder_process_data_st { int current_encoder_inst_index; /* Processing data passed down through recursion */ - int level; /* Recursion level */ + int level; /* Recursion level */ OSSL_ENCODER_INSTANCE *next_encoder_inst; int count_output_structure; @@ -53,9 +53,9 @@ int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out) if (data.current_encoder_inst_index == 0) { ERR_raise_data(ERR_LIB_OSSL_ENCODER, OSSL_ENCODER_R_ENCODER_NOT_FOUND, - "No encoders were found. For standard encoders you need " - "at least one of the default or base providers " - "available. Did you forget to load them?"); + "No encoders were found. For standard encoders you need " + "at least one of the default or base providers " + "available. Did you forget to load them?"); return 0; } @@ -94,7 +94,7 @@ int OSSL_ENCODER_to_fp(OSSL_ENCODER_CTX *ctx, FILE *fp) #endif int OSSL_ENCODER_to_data(OSSL_ENCODER_CTX *ctx, unsigned char **pdata, - size_t *pdata_len) + size_t *pdata_len) { BIO *out; BUF_MEM *buf = NULL; @@ -161,7 +161,7 @@ int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection) } int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx, - const char *output_type) + const char *output_type) { if (!ossl_assert(ctx != NULL) || !ossl_assert(output_type != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); @@ -173,7 +173,7 @@ int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx, } int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx, - const char *output_structure) + const char *output_structure) { if (!ossl_assert(ctx != NULL) || !ossl_assert(output_structure != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); @@ -185,7 +185,7 @@ int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx, } static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, - void *encoderctx) + void *encoderctx) { OSSL_ENCODER_INSTANCE *encoder_inst = NULL; const OSSL_PROVIDER *prov; @@ -213,8 +213,8 @@ static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, 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)); + "there are no property definitions with encoder %s", + OSSL_ENCODER_get0_name(encoder)); goto err; } @@ -223,10 +223,10 @@ static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, 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)); + "the mandatory 'output' property is missing " + "for encoder %s (properties: %s)", + OSSL_ENCODER_get0_name(encoder), + OSSL_ENCODER_get0_properties(encoder)); goto err; } @@ -239,7 +239,7 @@ static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, encoder_inst->encoder = encoder; encoder_inst->encoderctx = encoderctx; return encoder_inst; - err: +err: ossl_encoder_instance_free(encoder_inst); return NULL; } @@ -257,27 +257,28 @@ void ossl_encoder_instance_free(OSSL_ENCODER_INSTANCE *encoder_inst) } static int ossl_encoder_ctx_add_encoder_inst(OSSL_ENCODER_CTX *ctx, - OSSL_ENCODER_INSTANCE *ei) + OSSL_ENCODER_INSTANCE *ei) { int ok; if (ctx->encoder_insts == NULL - && (ctx->encoder_insts = - sk_OSSL_ENCODER_INSTANCE_new_null()) == NULL) { + && (ctx->encoder_insts = sk_OSSL_ENCODER_INSTANCE_new_null()) == NULL) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_MALLOC_FAILURE); return 0; } ok = (sk_OSSL_ENCODER_INSTANCE_push(ctx->encoder_insts, ei) > 0); if (ok) { - OSSL_TRACE_BEGIN(ENCODER) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "(ctx %p) Added encoder instance %p (encoder %p):\n" - " %s with %s\n", - (void *)ctx, (void *)ei, (void *)ei->encoder, - OSSL_ENCODER_get0_name(ei->encoder), - OSSL_ENCODER_get0_properties(ei->encoder)); - } OSSL_TRACE_END(ENCODER); + "(ctx %p) Added encoder instance %p (encoder %p):\n" + " %s with %s\n", + (void *)ctx, (void *)ei, (void *)ei->encoder, + OSSL_ENCODER_get0_name(ei->encoder), + OSSL_ENCODER_get0_properties(ei->encoder)); + } + OSSL_TRACE_END(ENCODER); } return ok; } @@ -298,8 +299,7 @@ int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder) provctx = OSSL_PROVIDER_get0_provider_ctx(prov); if ((encoderctx = encoder->newctx(provctx)) == NULL - || (encoder_inst = - ossl_encoder_instance_new(encoder, encoderctx)) == NULL) + || (encoder_inst = ossl_encoder_instance_new(encoder, encoderctx)) == NULL) goto err; /* Avoid double free of encoderctx on further errors */ encoderctx = NULL; @@ -308,7 +308,7 @@ int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder) goto err; return 1; - err: +err: ossl_encoder_instance_free(encoder_inst); if (encoderctx != NULL) encoder->freectx(encoderctx); @@ -316,7 +316,7 @@ int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder) } int OSSL_ENCODER_CTX_add_extra(OSSL_ENCODER_CTX *ctx, - OSSL_LIB_CTX *libctx, const char *propq) + OSSL_LIB_CTX *libctx, const char *propq) { return 1; } @@ -329,7 +329,7 @@ int OSSL_ENCODER_CTX_get_num_encoders(OSSL_ENCODER_CTX *ctx) } int OSSL_ENCODER_CTX_set_construct(OSSL_ENCODER_CTX *ctx, - OSSL_ENCODER_CONSTRUCT *construct) + OSSL_ENCODER_CONSTRUCT *construct) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); @@ -340,7 +340,7 @@ int OSSL_ENCODER_CTX_set_construct(OSSL_ENCODER_CTX *ctx, } int OSSL_ENCODER_CTX_set_construct_data(OSSL_ENCODER_CTX *ctx, - void *construct_data) + void *construct_data) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); @@ -351,7 +351,7 @@ int OSSL_ENCODER_CTX_set_construct_data(OSSL_ENCODER_CTX *ctx, } int OSSL_ENCODER_CTX_set_cleanup(OSSL_ENCODER_CTX *ctx, - OSSL_ENCODER_CLEANUP *cleanup) + OSSL_ENCODER_CLEANUP *cleanup) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); @@ -403,14 +403,13 @@ static int encoder_process(struct encoder_process_data_st *data) OSSL_PARAM abstract[10]; const OSSL_PARAM *current_abstract = NULL; int i; - int ok = -1; /* -1 signifies that the lookup loop gave nothing */ + int ok = -1; /* -1 signifies that the lookup loop gave nothing */ int top = 0; if (data->next_encoder_inst == NULL) { /* First iteration, where we prepare for what is to come */ - data->count_output_structure = - data->ctx->output_structure == NULL ? -1 : 0; + data->count_output_structure = data->ctx->output_structure == NULL ? -1 : 0; top = 1; } @@ -421,19 +420,13 @@ static int encoder_process(struct encoder_process_data_st *data) struct encoder_process_data_st new_data; if (!top) - next_encoder = - OSSL_ENCODER_INSTANCE_get_encoder(data->next_encoder_inst); + next_encoder = OSSL_ENCODER_INSTANCE_get_encoder(data->next_encoder_inst); - current_encoder_inst = - sk_OSSL_ENCODER_INSTANCE_value(data->ctx->encoder_insts, i); - current_encoder = - OSSL_ENCODER_INSTANCE_get_encoder(current_encoder_inst); - current_encoder_ctx = - OSSL_ENCODER_INSTANCE_get_encoder_ctx(current_encoder_inst); - current_output_type = - OSSL_ENCODER_INSTANCE_get_output_type(current_encoder_inst); - current_output_structure = - OSSL_ENCODER_INSTANCE_get_output_structure(current_encoder_inst); + current_encoder_inst = sk_OSSL_ENCODER_INSTANCE_value(data->ctx->encoder_insts, i); + current_encoder = OSSL_ENCODER_INSTANCE_get_encoder(current_encoder_inst); + current_encoder_ctx = OSSL_ENCODER_INSTANCE_get_encoder_ctx(current_encoder_inst); + current_output_type = OSSL_ENCODER_INSTANCE_get_output_type(current_encoder_inst); + current_output_structure = OSSL_ENCODER_INSTANCE_get_output_structure(current_encoder_inst); memset(&new_data, 0, sizeof(new_data)); new_data.ctx = data->ctx; new_data.current_encoder_inst_index = i; @@ -441,12 +434,14 @@ static int encoder_process(struct encoder_process_data_st *data) new_data.count_output_structure = data->count_output_structure; new_data.level = data->level + 1; - OSSL_TRACE_BEGIN(ENCODER) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "[%d] (ctx %p) Considering encoder instance %p (encoder %p)\n", - data->level, (void *)data->ctx, - (void *)current_encoder_inst, (void *)current_encoder); - } OSSL_TRACE_END(ENCODER); + "[%d] (ctx %p) Considering encoder instance %p (encoder %p)\n", + data->level, (void *)data->ctx, + (void *)current_encoder_inst, (void *)current_encoder); + } + OSSL_TRACE_END(ENCODER); /* * If this is the top call, we check if the output type of the current @@ -458,23 +453,28 @@ static int encoder_process(struct encoder_process_data_st *data) if (top) { if (data->ctx->output_type != NULL && OPENSSL_strcasecmp(current_output_type, - data->ctx->output_type) != 0) { - OSSL_TRACE_BEGIN(ENCODER) { + data->ctx->output_type) + != 0) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "[%d] Skipping because current encoder output type (%s) != desired output type (%s)\n", - data->level, - current_output_type, data->ctx->output_type); - } OSSL_TRACE_END(ENCODER); + "[%d] Skipping because current encoder output type (%s) != desired output type (%s)\n", + data->level, + current_output_type, data->ctx->output_type); + } + OSSL_TRACE_END(ENCODER); continue; } } else { if (!OSSL_ENCODER_is_a(next_encoder, current_output_type)) { - OSSL_TRACE_BEGIN(ENCODER) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "[%d] Skipping because current encoder output type (%s) != name of encoder %p\n", - data->level, - current_output_type, (void *)next_encoder); - } OSSL_TRACE_END(ENCODER); + "[%d] Skipping because current encoder output type (%s) != name of encoder %p\n", + data->level, + current_output_type, (void *)next_encoder); + } + OSSL_TRACE_END(ENCODER); continue; } } @@ -487,14 +487,17 @@ static int encoder_process(struct encoder_process_data_st *data) if (data->ctx->output_structure != NULL && current_output_structure != NULL) { if (OPENSSL_strcasecmp(data->ctx->output_structure, - current_output_structure) != 0) { - OSSL_TRACE_BEGIN(ENCODER) { + current_output_structure) + != 0) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "[%d] Skipping because current encoder output structure (%s) != ctx output structure (%s)\n", - data->level, - current_output_structure, - data->ctx->output_structure); - } OSSL_TRACE_END(ENCODER); + "[%d] Skipping because current encoder output structure (%s) != ctx output structure (%s)\n", + data->level, + current_output_structure, + data->ctx->output_structure); + } + OSSL_TRACE_END(ENCODER); continue; } @@ -525,11 +528,13 @@ static int encoder_process(struct encoder_process_data_st *data) if (ok != 0) break; - OSSL_TRACE_BEGIN(ENCODER) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "[%d] Skipping because recusion level %d failed\n", - data->level, new_data.level); - } OSSL_TRACE_END(ENCODER); + "[%d] Skipping because recursion level %d failed\n", + data->level, new_data.level); + } + OSSL_TRACE_END(ENCODER); } /* @@ -539,11 +544,13 @@ static int encoder_process(struct encoder_process_data_st *data) if (i < 0) { ok = -1; - OSSL_TRACE_BEGIN(ENCODER) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "[%d] (ctx %p) No suitable encoder found\n", - data->level, (void *)data->ctx); - } OSSL_TRACE_END(ENCODER); + "[%d] (ctx %p) No suitable encoder found\n", + data->level, (void *)data->ctx); + } + OSSL_TRACE_END(ENCODER); } else { /* Preparations */ @@ -569,9 +576,8 @@ static int encoder_process(struct encoder_process_data_st *data) if (data->count_output_structure == 0) return 0; - original_data = - data->ctx->construct(current_encoder_inst, - data->ctx->construct_data); + original_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); @@ -596,21 +602,17 @@ static int encoder_process(struct encoder_process_data_st *data) */ OSSL_PARAM *abstract_p = abstract; - const char *prev_output_structure = - OSSL_ENCODER_INSTANCE_get_output_structure(data->prev_encoder_inst); + const char *prev_output_structure = OSSL_ENCODER_INSTANCE_get_output_structure(data->prev_encoder_inst); - *abstract_p++ = - OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, - (char *)data->data_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, - (char *)prev_output_structure, - 0); - *abstract_p++ = - OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_DATA, - data->running_output, - data->running_output_length); + *abstract_p++ = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_STRUCTURE, + (char *)prev_output_structure, + 0); + *abstract_p++ = OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_DATA, + data->running_output, + data->running_output_length); *abstract_p = OSSL_PARAM_construct_end(); current_abstract = abstract; } @@ -630,23 +632,25 @@ static int encoder_process(struct encoder_process_data_st *data) if (top) current_out = data->bio; else if ((current_out = allocated_out = BIO_new(BIO_s_mem())) - == NULL) - ok = 0; /* Assume BIO_new() recorded an error */ + == NULL) + ok = 0; /* Assume BIO_new() recorded an error */ if (ok) ok = (cbio = ossl_core_bio_new_from_bio(current_out)) != NULL; if (ok) { ok = current_encoder->encode(current_encoder_ctx, cbio, - original_data, current_abstract, - data->ctx->selection, - ossl_pw_passphrase_callback_enc, - &data->ctx->pwdata); - OSSL_TRACE_BEGIN(ENCODER) { + original_data, current_abstract, + data->ctx->selection, + ossl_pw_passphrase_callback_enc, + &data->ctx->pwdata); + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "[%d] (ctx %p) Running encoder instance %p => %d\n", - data->level, (void *)data->ctx, - (void *)current_encoder_inst, ok); - } OSSL_TRACE_END(ENCODER); + "[%d] (ctx %p) Running encoder instance %p => %d\n", + data->level, (void *)data->ctx, + (void *)current_encoder_inst, ok); + } + OSSL_TRACE_END(ENCODER); } ossl_core_bio_free(cbio); diff --git a/crypto/encode_decode/encoder_local.h b/crypto/encode_decode/encoder_local.h index c1885ffc771f..d55c02702357 100644 --- a/crypto/encode_decode/encoder_local.h +++ b/crypto/encode_decode/encoder_local.h @@ -56,9 +56,9 @@ struct ossl_decoder_st { }; struct ossl_encoder_instance_st { - OSSL_ENCODER *encoder; /* Never NULL */ - void *encoderctx; /* Never NULL */ - const char *output_type; /* Never NULL */ + OSSL_ENCODER *encoder; /* Never NULL */ + void *encoderctx; /* Never NULL */ + const char *output_type; /* Never NULL */ const char *output_structure; /* May be NULL */ }; @@ -104,9 +104,9 @@ struct ossl_encoder_ctx_st { }; struct ossl_decoder_instance_st { - OSSL_DECODER *decoder; /* Never NULL */ - void *decoderctx; /* Never NULL */ - const char *input_type; /* Never NULL */ + OSSL_DECODER *decoder; /* Never NULL */ + void *decoderctx; /* Never NULL */ + const char *input_type; /* Never NULL */ const char *input_structure; /* May be NULL */ unsigned int flag_input_structure_was_set : 1; diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c index 89e7b6abf855..803e74840228 100644 --- a/crypto/encode_decode/encoder_meth.c +++ b/crypto/encode_decode/encoder_meth.c @@ -76,7 +76,6 @@ static void *encoder_store_new(OSSL_LIB_CTX *ctx) return ossl_method_store_new(ctx); } - static const OSSL_LIB_CTX_METHOD encoder_store_method = { /* We want encoder_store to be cleaned up before the provider store */ OSSL_LIB_CTX_METHOD_PRIORITY_2, @@ -87,9 +86,9 @@ static const OSSL_LIB_CTX_METHOD encoder_store_method = { /* Data to be passed through ossl_method_construct() */ struct encoder_data_st { OSSL_LIB_CTX *libctx; - int id; /* For get_encoder_from_store() */ - const char *names; /* For get_encoder_from_store() */ - const char *propquery; /* For get_encoder_from_store() */ + int id; /* For get_encoder_from_store() */ + const char *names; /* For get_encoder_from_store() */ + const char *propquery; /* For get_encoder_from_store() */ OSSL_METHOD_STORE *tmp_store; /* For get_tmp_encoder_store() */ @@ -121,7 +120,7 @@ static void dealloc_tmp_encoder_store(void *store) static OSSL_METHOD_STORE *get_encoder_store(OSSL_LIB_CTX *libctx) { return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_ENCODER_STORE_INDEX, - &encoder_store_method); + &encoder_store_method); } static int reserve_encoder_store(void *store, void *data) @@ -148,7 +147,7 @@ static int unreserve_encoder_store(void *store, void *data) /* Get encoder methods from a store, or put one in */ static void *get_encoder_from_store(void *store, const OSSL_PROVIDER **prov, - void *data) + void *data) { struct encoder_data_st *methdata = data; void *method = NULL; @@ -183,9 +182,9 @@ static void *get_encoder_from_store(void *store, const OSSL_PROVIDER **prov, } static int put_encoder_in_store(void *store, void *method, - const OSSL_PROVIDER *prov, - const char *names, const char *propdef, - void *data) + const OSSL_PROVIDER *prov, + const char *names, const char *propdef, + void *data) { struct encoder_data_st *methdata = data; OSSL_NAMEMAP *namemap; @@ -212,13 +211,13 @@ static int put_encoder_in_store(void *store, void *method, return 0; return ossl_method_store_add(store, prov, id, propdef, method, - (int (*)(void *))OSSL_ENCODER_up_ref, - (void (*)(void *))OSSL_ENCODER_free); + (int (*)(void *))OSSL_ENCODER_up_ref, + (void (*)(void *))OSSL_ENCODER_free); } /* Create and populate a encoder method */ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, - OSSL_PROVIDER *prov) + OSSL_PROVIDER *prov) { OSSL_ENCODER *encoder = NULL; const OSSL_DISPATCH *fns = algodef->implementation; @@ -233,7 +232,8 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, } encoder->base.algodef = algodef; if ((encoder->base.parsed_propdef - = ossl_parse_property(libctx, algodef->property_definition)) == NULL) { + = ossl_parse_property(libctx, algodef->property_definition)) + == NULL) { OSSL_ENCODER_free(encoder); return NULL; } @@ -242,38 +242,31 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, switch (fns->function_id) { case OSSL_FUNC_ENCODER_NEWCTX: if (encoder->newctx == NULL) - encoder->newctx = - OSSL_FUNC_encoder_newctx(fns); + encoder->newctx = OSSL_FUNC_encoder_newctx(fns); break; case OSSL_FUNC_ENCODER_FREECTX: if (encoder->freectx == NULL) - encoder->freectx = - OSSL_FUNC_encoder_freectx(fns); + encoder->freectx = OSSL_FUNC_encoder_freectx(fns); break; case OSSL_FUNC_ENCODER_GET_PARAMS: if (encoder->get_params == NULL) - encoder->get_params = - OSSL_FUNC_encoder_get_params(fns); + encoder->get_params = OSSL_FUNC_encoder_get_params(fns); break; case OSSL_FUNC_ENCODER_GETTABLE_PARAMS: if (encoder->gettable_params == NULL) - encoder->gettable_params = - OSSL_FUNC_encoder_gettable_params(fns); + encoder->gettable_params = OSSL_FUNC_encoder_gettable_params(fns); break; case OSSL_FUNC_ENCODER_SET_CTX_PARAMS: if (encoder->set_ctx_params == NULL) - encoder->set_ctx_params = - OSSL_FUNC_encoder_set_ctx_params(fns); + encoder->set_ctx_params = OSSL_FUNC_encoder_set_ctx_params(fns); break; case OSSL_FUNC_ENCODER_SETTABLE_CTX_PARAMS: if (encoder->settable_ctx_params == NULL) - encoder->settable_ctx_params = - OSSL_FUNC_encoder_settable_ctx_params(fns); + encoder->settable_ctx_params = OSSL_FUNC_encoder_settable_ctx_params(fns); break; case OSSL_FUNC_ENCODER_DOES_SELECTION: if (encoder->does_selection == NULL) - encoder->does_selection = - OSSL_FUNC_encoder_does_selection(fns); + encoder->does_selection = OSSL_FUNC_encoder_does_selection(fns); break; case OSSL_FUNC_ENCODER_ENCODE: if (encoder->encode == NULL) @@ -281,13 +274,11 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, break; case OSSL_FUNC_ENCODER_IMPORT_OBJECT: if (encoder->import_object == NULL) - encoder->import_object = - OSSL_FUNC_encoder_import_object(fns); + encoder->import_object = OSSL_FUNC_encoder_import_object(fns); break; case OSSL_FUNC_ENCODER_FREE_OBJECT: if (encoder->free_object == NULL) - encoder->free_object = - OSSL_FUNC_encoder_free_object(fns); + encoder->free_object = OSSL_FUNC_encoder_free_object(fns); break; } } @@ -297,9 +288,9 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, * You must have the encoding driver functions. */ if (!((encoder->newctx == NULL && encoder->freectx == NULL) - || (encoder->newctx != NULL && encoder->freectx != NULL) - || (encoder->import_object != NULL && encoder->free_object != NULL) - || (encoder->import_object == NULL && encoder->free_object == NULL)) + || (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) { OSSL_ENCODER_free(encoder); ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_INVALID_PROVIDER_FUNCTIONS); @@ -315,14 +306,13 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef, return encoder; } - /* * The core fetching functionality passes the names of the implementation. * This function is responsible to getting an identity number for them, * then call encoder_from_algorithm() with that identity number. */ static void *construct_encoder(const OSSL_ALGORITHM *algodef, - OSSL_PROVIDER *prov, void *data) + OSSL_PROVIDER *prov, void *data) { /* * This function is only called if get_encoder_from_store() returned @@ -370,7 +360,7 @@ static void free_encoder(void *method) /* Fetching support. Can fetch by numeric identity or by name */ static OSSL_ENCODER * inner_ossl_encoder_fetch(struct encoder_data_st *methdata, int id, - const char *name, const char *properties) + const char *name, const char *properties) { OSSL_METHOD_STORE *store = get_encoder_store(methdata->libctx); OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx); @@ -420,8 +410,9 @@ inner_ossl_encoder_fetch(struct encoder_data_st *methdata, int id, methdata->propquery = propq; methdata->flag_construct_error_occurred = 0; if ((method = ossl_method_construct(methdata->libctx, OSSL_OP_ENCODER, - &prov, 0 /* !force_cache */, - &mcm, methdata)) != NULL) { + &prov, 0 /* !force_cache */, + &mcm, methdata)) + != NULL) { /* * If construction did create a method for us, we know that * there is a correct name_id and meth_id, since those have @@ -431,7 +422,7 @@ inner_ossl_encoder_fetch(struct encoder_data_st *methdata, int id, if (id == 0) id = ossl_namemap_name2num(namemap, name); ossl_method_store_cache_set(store, prov, id, propq, method, - up_ref_encoder, free_encoder); + up_ref_encoder, free_encoder); } /* @@ -447,17 +438,17 @@ inner_ossl_encoder_fetch(struct encoder_data_st *methdata, int id, if (name == NULL) name = ossl_namemap_num2name(namemap, id, 0); ERR_raise_data(ERR_LIB_OSSL_ENCODER, code, - "%s, Name (%s : %d), Properties (%s)", - ossl_lib_ctx_get_descriptor(methdata->libctx), - name == NULL ? "<null>" : name, id, - properties == NULL ? "<null>" : properties); + "%s, Name (%s : %d), Properties (%s)", + ossl_lib_ctx_get_descriptor(methdata->libctx), + name == NULL ? "<null>" : name, id, + properties == NULL ? "<null>" : properties); } return method; } OSSL_ENCODER *OSSL_ENCODER_fetch(OSSL_LIB_CTX *libctx, const char *name, - const char *properties) + const char *properties) { struct encoder_data_st methdata; void *method; @@ -470,7 +461,7 @@ OSSL_ENCODER *OSSL_ENCODER_fetch(OSSL_LIB_CTX *libctx, const char *name, } OSSL_ENCODER *ossl_encoder_fetch_by_number(OSSL_LIB_CTX *libctx, int id, - const char *properties) + const char *properties) { struct encoder_data_st methdata; void *method; @@ -580,9 +571,9 @@ static void do_one(ossl_unused int id, void *method, void *arg) } void OSSL_ENCODER_do_all_provided(OSSL_LIB_CTX *libctx, - void (*user_fn)(OSSL_ENCODER *encoder, - void *arg), - void *user_arg) + void (*user_fn)(OSSL_ENCODER *encoder, + void *arg), + void *user_arg) { struct encoder_data_st methdata; struct do_one_data_st data; @@ -600,8 +591,8 @@ void OSSL_ENCODER_do_all_provided(OSSL_LIB_CTX *libctx, } int OSSL_ENCODER_names_do_all(const OSSL_ENCODER *encoder, - void (*fn)(const char *name, void *data), - void *data) + void (*fn)(const char *name, void *data), + void *data) { if (encoder == NULL) return 0; @@ -659,7 +650,7 @@ OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new(void) } int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx, - const OSSL_PARAM params[]) + const OSSL_PARAM params[]) { int ok = 1; size_t i; @@ -675,8 +666,7 @@ int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx, l = OSSL_ENCODER_CTX_get_num_encoders(ctx); for (i = 0; i < l; i++) { - OSSL_ENCODER_INSTANCE *encoder_inst = - sk_OSSL_ENCODER_INSTANCE_value(ctx->encoder_insts, i); + OSSL_ENCODER_INSTANCE *encoder_inst = sk_OSSL_ENCODER_INSTANCE_value(ctx->encoder_insts, i); OSSL_ENCODER *encoder = OSSL_ENCODER_INSTANCE_get_encoder(encoder_inst); void *encoderctx = OSSL_ENCODER_INSTANCE_get_encoder_ctx(encoder_inst); @@ -692,7 +682,7 @@ void OSSL_ENCODER_CTX_free(OSSL_ENCODER_CTX *ctx) { if (ctx != NULL) { sk_OSSL_ENCODER_INSTANCE_pop_free(ctx->encoder_insts, - ossl_encoder_instance_free); + ossl_encoder_instance_free); OPENSSL_free(ctx->construct_data); ossl_pw_clear_passphrase_data(&ctx->pwdata); OPENSSL_free(ctx); diff --git a/crypto/encode_decode/encoder_pkey.c b/crypto/encode_decode/encoder_pkey.c index b372170db256..640978793e7f 100644 --- a/crypto/encode_decode/encoder_pkey.c +++ b/crypto/encode_decode/encoder_pkey.c @@ -23,44 +23,42 @@ DEFINE_STACK_OF(OSSL_ENCODER) int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx, - const char *cipher_name, - const char *propquery) + const char *cipher_name, + const char *propquery) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END }; - params[0] = - OSSL_PARAM_construct_utf8_string(OSSL_ENCODER_PARAM_CIPHER, - (void *)cipher_name, 0); - params[1] = - OSSL_PARAM_construct_utf8_string(OSSL_ENCODER_PARAM_PROPERTIES, - (void *)propquery, 0); + params[0] = OSSL_PARAM_construct_utf8_string(OSSL_ENCODER_PARAM_CIPHER, + (void *)cipher_name, 0); + params[1] = OSSL_PARAM_construct_utf8_string(OSSL_ENCODER_PARAM_PROPERTIES, + (void *)propquery, 0); return OSSL_ENCODER_CTX_set_params(ctx, params); } int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx, - const unsigned char *kstr, - size_t klen) + const unsigned char *kstr, + size_t klen) { return ossl_pw_set_passphrase(&ctx->pwdata, kstr, klen); } int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx, - const UI_METHOD *ui_method, - void *ui_data) + const UI_METHOD *ui_method, + void *ui_data) { return ossl_pw_set_ui_method(&ctx->pwdata, ui_method, ui_data); } int OSSL_ENCODER_CTX_set_pem_password_cb(OSSL_ENCODER_CTX *ctx, - pem_password_cb *cb, void *cbarg) + pem_password_cb *cb, void *cbarg) { return ossl_pw_set_pem_password_cb(&ctx->pwdata, cb, cbarg); } int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx, - OSSL_PASSPHRASE_CALLBACK *cb, - void *cbarg) + OSSL_PASSPHRASE_CALLBACK *cb, + void *cbarg) { return ossl_pw_set_ossl_passphrase_cb(&ctx->pwdata, cb, cbarg); } @@ -77,7 +75,7 @@ struct collected_encoder_st { const OSSL_PROVIDER *keymgmt_prov; OSSL_ENCODER_CTX *ctx; - unsigned int flag_find_same_provider:1; + unsigned int flag_find_same_provider : 1; int error_occurred; }; @@ -90,7 +88,7 @@ static void collect_encoder(OSSL_ENCODER *encoder, void *arg) if (data->error_occurred) return; - data->error_occurred = 1; /* Assume the worst */ + data->error_occurred = 1; /* Assume the worst */ if (data->names == NULL) return; @@ -122,12 +120,12 @@ static void collect_encoder(OSSL_ENCODER *encoder, void *arg) break; } - data->error_occurred = 0; /* All is good now */ + data->error_occurred = 0; /* All is good now */ } struct collected_names_st { STACK_OF(OPENSSL_CSTRING) *names; - unsigned int error_occurred:1; + unsigned int error_occurred : 1; }; static void collect_name(const char *name, void *arg) @@ -137,12 +135,12 @@ static void collect_name(const char *name, void *arg) if (data->error_occurred) return; - data->error_occurred = 1; /* Assume the worst */ + data->error_occurred = 1; /* Assume the worst */ if (sk_OPENSSL_CSTRING_push(data->names, name) <= 0) return; - data->error_occurred = 0; /* All is good now */ + data->error_occurred = 0; /* All is good now */ } /* @@ -167,8 +165,7 @@ static int encoder_import_cb(const OSSL_PARAM params[], void *arg) OSSL_ENCODER *encoder = OSSL_ENCODER_INSTANCE_get_encoder(encoder_inst); void *encoderctx = OSSL_ENCODER_INSTANCE_get_encoder_ctx(encoder_inst); - construct_data->constructed_obj = - encoder->import_object(encoderctx, construct_data->selection, params); + construct_data->constructed_obj = encoder->import_object(encoderctx, construct_data->selection, params); return (construct_data->constructed_obj != NULL); } @@ -179,8 +176,7 @@ encoder_construct_pkey(OSSL_ENCODER_INSTANCE *encoder_inst, void *arg) struct construct_data_st *data = arg; if (data->obj == NULL) { - OSSL_ENCODER *encoder = - OSSL_ENCODER_INSTANCE_get_encoder(encoder_inst); + OSSL_ENCODER *encoder = OSSL_ENCODER_INSTANCE_get_encoder(encoder_inst); const EVP_PKEY *pk = data->pk; const OSSL_PROVIDER *k_prov = EVP_KEYMGMT_get0_provider(pk->keymgmt); const OSSL_PROVIDER *e_prov = OSSL_ENCODER_get0_provider(encoder); @@ -193,7 +189,7 @@ encoder_construct_pkey(OSSL_ENCODER_INSTANCE *encoder_inst, void *arg) data->encoder_inst = encoder_inst; if (!evp_keymgmt_export(pk->keymgmt, pk->keydata, selection, - &encoder_import_cb, data)) + &encoder_import_cb, data)) return NULL; data->obj = data->constructed_obj; } else { @@ -210,8 +206,7 @@ static void encoder_destruct_pkey(void *arg) int match = (data->obj == data->constructed_obj); if (data->encoder_inst != NULL) { - OSSL_ENCODER *encoder = - OSSL_ENCODER_INSTANCE_get_encoder(data->encoder_inst); + OSSL_ENCODER *encoder = OSSL_ENCODER_INSTANCE_get_encoder(data->encoder_inst); encoder->free_object(data->constructed_obj); } @@ -227,9 +222,9 @@ static void encoder_destruct_pkey(void *arg) * and to use fallback methods if the result is NULL. */ static int ossl_encoder_ctx_setup_for_pkey(OSSL_ENCODER_CTX *ctx, - const EVP_PKEY *pkey, - int selection, - const char *propquery) + const EVP_PKEY *pkey, + int selection, + const char *propquery) { struct construct_data_st *data = NULL; const OSSL_PROVIDER *prov = NULL; @@ -309,11 +304,11 @@ static int ossl_encoder_ctx_setup_for_pkey(OSSL_ENCODER_CTX *ctx, data->pk = pkey; data->selection = selection; - data = NULL; /* Avoid it being freed */ + data = NULL; /* Avoid it being freed */ } ok = 1; - err: +err: if (data != NULL) { OSSL_ENCODER_CTX_set_construct_data(ctx, NULL); OPENSSL_free(data); @@ -322,10 +317,10 @@ static int ossl_encoder_ctx_setup_for_pkey(OSSL_ENCODER_CTX *ctx, } 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) + int selection, + const char *output_type, + const char *output_struct, + const char *propquery) { OSSL_ENCODER_CTX *ctx = NULL; OSSL_LIB_CTX *libctx = NULL; @@ -337,7 +332,7 @@ OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey, if (!evp_pkey_is_assigned(pkey)) { ERR_raise_data(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_INVALID_ARGUMENT, - "The passed EVP_PKEY must be assigned a key"); + "The passed EVP_PKEY must be assigned a key"); return NULL; } @@ -352,13 +347,15 @@ OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey, libctx = ossl_provider_libctx(prov); } - OSSL_TRACE_BEGIN(ENCODER) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, - "(ctx %p) Looking for %s encoders with selection %d\n", - (void *)ctx, EVP_PKEY_get0_type_name(pkey), selection); + "(ctx %p) Looking for %s encoders with selection %d\n", + (void *)ctx, EVP_PKEY_get0_type_name(pkey), selection); BIO_printf(trc_out, " output type: %s, output structure: %s\n", - output_type, output_struct); - } OSSL_TRACE_END(ENCODER); + output_type, output_struct); + } + OSSL_TRACE_END(ENCODER); if (OSSL_ENCODER_CTX_set_output_type(ctx, output_type) && (output_struct == NULL @@ -370,14 +367,16 @@ OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey, int save_parameters = pkey->save_parameters; params[0] = OSSL_PARAM_construct_int(OSSL_ENCODER_PARAM_SAVE_PARAMETERS, - &save_parameters); + &save_parameters); /* ignoring error as this is only auxiliary parameter */ (void)OSSL_ENCODER_CTX_set_params(ctx, params); - OSSL_TRACE_BEGIN(ENCODER) { + OSSL_TRACE_BEGIN(ENCODER) + { BIO_printf(trc_out, "(ctx %p) Got %d encoders\n", - (void *)ctx, OSSL_ENCODER_CTX_get_num_encoders(ctx)); - } OSSL_TRACE_END(ENCODER); + (void *)ctx, OSSL_ENCODER_CTX_get_num_encoders(ctx)); + } + OSSL_TRACE_END(ENCODER); return ctx; } |
