aboutsummaryrefslogtreecommitdiff
path: root/crypto/encode_decode/encoder_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/encode_decode/encoder_lib.c')
-rw-r--r--crypto/encode_decode/encoder_lib.c252
1 files changed, 129 insertions, 123 deletions
diff --git a/crypto/encode_decode/encoder_lib.c b/crypto/encode_decode/encoder_lib.c
index 59d0c885a3e4..753db526209c 100644
--- a/crypto/encode_decode/encoder_lib.c
+++ b/crypto/encode_decode/encoder_lib.c
@@ -24,22 +24,22 @@
#include "encoder_local.h"
/* Number of octets per line */
-#define LABELED_BUF_PRINT_WIDTH 15
+#define LABELED_BUF_PRINT_WIDTH 15
-# ifdef SIXTY_FOUR_BIT_LONG
-# define BN_FMTu "%lu"
-# define BN_FMTx "%lx"
-# endif
+#ifdef SIXTY_FOUR_BIT_LONG
+#define BN_FMTu "%lu"
+#define BN_FMTx "%lx"
+#endif
-# ifdef SIXTY_FOUR_BIT
-# define BN_FMTu "%llu"
-# define BN_FMTx "%llx"
-# endif
+#ifdef SIXTY_FOUR_BIT
+#define BN_FMTu "%llu"
+#define BN_FMTx "%llx"
+#endif
-# ifdef THIRTY_TWO_BIT
-# define BN_FMTu "%u"
-# define BN_FMTx "%x"
-# endif
+#ifdef THIRTY_TWO_BIT
+#define BN_FMTu "%u"
+#define BN_FMTx "%x"
+#endif
struct encoder_process_data_st {
OSSL_ENCODER_CTX *ctx;
@@ -51,7 +51,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;
@@ -76,9 +76,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;
}
@@ -117,7 +117,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;
@@ -184,7 +184,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);
@@ -196,7 +196,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);
@@ -208,7 +208,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;
@@ -234,8 +234,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;
}
@@ -244,10 +244,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;
}
@@ -260,7 +260,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;
}
@@ -278,27 +278,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_CRYPTO_LIB);
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;
}
@@ -319,8 +320,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;
@@ -329,7 +329,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);
@@ -337,7 +337,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;
}
@@ -350,7 +350,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);
@@ -361,7 +361,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);
@@ -372,7 +372,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);
@@ -424,14 +424,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;
}
@@ -442,19 +441,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;
@@ -462,12 +455,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
@@ -479,23 +474,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;
}
}
@@ -508,14 +508,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;
}
@@ -546,11 +549,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 recursion 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);
}
/*
@@ -560,11 +565,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 */
@@ -590,9 +597,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);
@@ -617,21 +623,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;
}
@@ -651,23 +653,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);
@@ -726,7 +730,7 @@ int ossl_bio_print_labeled_bignum(BIO *out, const char *label, const BIGNUM *bn)
neg = "-";
return BIO_printf(out, "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
- label, post_label_spc, neg, words[0], neg, words[0]);
+ label, post_label_spc, neg, words[0], neg, words[0]);
}
hex_str = BN_bn2hex(bn);
@@ -762,8 +766,9 @@ int ossl_bio_print_labeled_bignum(BIO *out, const char *label, const BIGNUM *bn)
use_sep = 0; /* The first byte on the next line doesn't have a : */
}
if (BIO_printf(out, "%s%c%c", use_sep ? ":" : "",
- tolower((unsigned char)p[0]),
- tolower((unsigned char)p[1])) <= 0)
+ tolower((unsigned char)p[0]),
+ tolower((unsigned char)p[1]))
+ <= 0)
goto err;
++bytes;
p += 2;
@@ -778,7 +783,7 @@ err:
}
int ossl_bio_print_labeled_buf(BIO *out, const char *label,
- const unsigned char *buf, size_t buflen)
+ const unsigned char *buf, size_t buflen)
{
size_t i;
@@ -794,7 +799,8 @@ int ossl_bio_print_labeled_buf(BIO *out, const char *label,
}
if (BIO_printf(out, "%02x%s", buf[i],
- (i == buflen - 1) ? "" : ":") <= 0)
+ (i == buflen - 1) ? "" : ":")
+ <= 0)
return 0;
}
if (BIO_printf(out, "\n") <= 0)