2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/core_dispatch.h>
11 #include <openssl/types.h>
12 #include <openssl/safestack.h>
13 #include <openssl/encoder.h>
14 #include <openssl/decoder.h>
15 #include "internal/cryptlib.h"
16 #include "internal/passphrase.h"
17 #include "internal/refcount.h"
19 struct ossl_endecode_base_st
{
24 CRYPTO_REF_COUNT refcnt
;
28 struct ossl_encoder_st
{
29 struct ossl_endecode_base_st base
;
30 OSSL_FUNC_encoder_newctx_fn
*newctx
;
31 OSSL_FUNC_encoder_freectx_fn
*freectx
;
32 OSSL_FUNC_encoder_get_params_fn
*get_params
;
33 OSSL_FUNC_encoder_gettable_params_fn
*gettable_params
;
34 OSSL_FUNC_encoder_set_ctx_params_fn
*set_ctx_params
;
35 OSSL_FUNC_encoder_settable_ctx_params_fn
*settable_ctx_params
;
36 OSSL_FUNC_encoder_encode_fn
*encode
;
37 OSSL_FUNC_encoder_import_object_fn
*import_object
;
38 OSSL_FUNC_encoder_free_object_fn
*free_object
;
41 struct ossl_decoder_st
{
42 struct ossl_endecode_base_st base
;
43 OSSL_FUNC_decoder_newctx_fn
*newctx
;
44 OSSL_FUNC_decoder_freectx_fn
*freectx
;
45 OSSL_FUNC_decoder_get_params_fn
*get_params
;
46 OSSL_FUNC_decoder_gettable_params_fn
*gettable_params
;
47 OSSL_FUNC_decoder_set_ctx_params_fn
*set_ctx_params
;
48 OSSL_FUNC_decoder_settable_ctx_params_fn
*settable_ctx_params
;
49 OSSL_FUNC_decoder_does_selection_fn
*does_selection
;
50 OSSL_FUNC_decoder_decode_fn
*decode
;
51 OSSL_FUNC_decoder_export_object_fn
*export_object
;
54 struct ossl_encoder_instance_st
{
55 OSSL_ENCODER
*encoder
; /* Never NULL */
56 void *encoderctx
; /* Never NULL */
57 const char *input_type
; /* May be NULL */
58 const char *output_type
; /* Never NULL */
59 const char *output_structure
; /* May be NULL */
62 DEFINE_STACK_OF(OSSL_ENCODER_INSTANCE
)
64 void ossl_encoder_instance_free(OSSL_ENCODER_INSTANCE
*encoder_inst
);
66 struct ossl_encoder_ctx_st
{
68 * Select what parts of an object will be encoded. This selection is
69 * bit encoded, and the bits correspond to selection bits available with
70 * the provider side operation. For example, when encoding an EVP_PKEY,
71 * the OSSL_KEYMGMT_SELECT_ macros are used for this.
75 * The desired output type. The encoder implementation must have a
76 * gettable "output-type" parameter that this will match against.
78 const char *output_type
;
80 * The desired output structure, if that's relevant for the type of
81 * object being encoded. It may be used for selection of the starting
82 * encoder implementations in a chain.
84 const char *output_structure
;
87 * Decoders that are components of any current decoding path.
89 STACK_OF(OSSL_ENCODER_INSTANCE
) *encoder_insts
;
92 * The constructor and destructor of an object to pass to the first
95 OSSL_ENCODER_CONSTRUCT
*construct
;
96 OSSL_ENCODER_CLEANUP
*cleanup
;
99 /* For any function that needs a passphrase reader */
100 struct ossl_passphrase_data_st pwdata
;
103 struct ossl_decoder_instance_st
{
104 OSSL_DECODER
*decoder
; /* Never NULL */
105 void *decoderctx
; /* Never NULL */
106 const char *input_type
; /* Never NULL */
107 const char *input_structure
; /* May be NULL */
109 unsigned int flag_input_structure_was_set
: 1;
112 DEFINE_STACK_OF(OSSL_DECODER_INSTANCE
)
114 struct ossl_decoder_ctx_st
{
116 * The caller may know the input type of the data they pass. If not,
117 * this will remain NULL and the decoding functionality will start
118 * with trying to decode with any desencoder in |decoder_insts|,
119 * regardless of their respective input type.
121 const char *start_input_type
;
123 * The desired input structure, if that's relevant for the type of
124 * object being encoded. It may be used for selection of the ending
125 * decoder implementations in a chain, i.e. those chosen using the
126 * expected output data type.
128 const char *input_structure
;
130 * Select what parts of an object are expected. This may affect what
131 * decoder implementations are selected, because there are structures
132 * that look different depending on this selection; for example, EVP_PKEY
133 * objects often have different encoding structures for private keys,
134 * public keys and key parameters.
135 * This selection is bit encoded, and the bits correspond to selection
136 * bits available with the provider side operation. For example, when
137 * encoding an EVP_PKEY, the OSSL_KEYMGMT_SELECT_ macros are used for
143 * Decoders that are components of any current decoding path.
145 STACK_OF(OSSL_DECODER_INSTANCE
) *decoder_insts
;
148 * The constructors of a decoding, and its caller argument.
150 OSSL_DECODER_CONSTRUCT
*construct
;
151 OSSL_DECODER_CLEANUP
*cleanup
;
152 void *construct_data
;
154 /* For any function that needs a passphrase reader */
155 struct ossl_passphrase_data_st pwdata
;