]>
Commit | Line | Data |
---|---|---|
ece9304c | 1 | /* |
3c2bdd7d | 2 | * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. |
ece9304c RL |
3 | * |
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 | |
8 | */ | |
9 | ||
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" | |
a517edec | 16 | #include "internal/passphrase.h" |
9379bf94 | 17 | #include "internal/property.h" |
ece9304c RL |
18 | #include "internal/refcount.h" |
19 | ||
bd7a6f16 | 20 | struct ossl_endecode_base_st { |
ece9304c RL |
21 | OSSL_PROVIDER *prov; |
22 | int id; | |
49664117 | 23 | char *name; |
ece9304c | 24 | const char *propdef; |
309a78aa | 25 | const char *description; |
9379bf94 | 26 | OSSL_PROPERTY_LIST *parsed_propdef; |
ece9304c RL |
27 | |
28 | CRYPTO_REF_COUNT refcnt; | |
29 | CRYPTO_RWLOCK *lock; | |
30 | }; | |
31 | ||
32 | struct ossl_encoder_st { | |
bd7a6f16 | 33 | struct ossl_endecode_base_st base; |
ece9304c RL |
34 | OSSL_FUNC_encoder_newctx_fn *newctx; |
35 | OSSL_FUNC_encoder_freectx_fn *freectx; | |
b8975c68 RL |
36 | OSSL_FUNC_encoder_get_params_fn *get_params; |
37 | OSSL_FUNC_encoder_gettable_params_fn *gettable_params; | |
ece9304c RL |
38 | OSSL_FUNC_encoder_set_ctx_params_fn *set_ctx_params; |
39 | OSSL_FUNC_encoder_settable_ctx_params_fn *settable_ctx_params; | |
cd861ab7 | 40 | OSSL_FUNC_encoder_does_selection_fn *does_selection; |
b8975c68 RL |
41 | OSSL_FUNC_encoder_encode_fn *encode; |
42 | OSSL_FUNC_encoder_import_object_fn *import_object; | |
43 | OSSL_FUNC_encoder_free_object_fn *free_object; | |
ece9304c RL |
44 | }; |
45 | ||
46 | struct ossl_decoder_st { | |
bd7a6f16 | 47 | struct ossl_endecode_base_st base; |
ece9304c RL |
48 | OSSL_FUNC_decoder_newctx_fn *newctx; |
49 | OSSL_FUNC_decoder_freectx_fn *freectx; | |
50 | OSSL_FUNC_decoder_get_params_fn *get_params; | |
51 | OSSL_FUNC_decoder_gettable_params_fn *gettable_params; | |
52 | OSSL_FUNC_decoder_set_ctx_params_fn *set_ctx_params; | |
53 | OSSL_FUNC_decoder_settable_ctx_params_fn *settable_ctx_params; | |
67c91ca2 | 54 | OSSL_FUNC_decoder_does_selection_fn *does_selection; |
ece9304c RL |
55 | OSSL_FUNC_decoder_decode_fn *decode; |
56 | OSSL_FUNC_decoder_export_object_fn *export_object; | |
57 | }; | |
58 | ||
b8975c68 | 59 | struct ossl_encoder_instance_st { |
8a98a507 RL |
60 | OSSL_ENCODER *encoder; /* Never NULL */ |
61 | void *encoderctx; /* Never NULL */ | |
8a98a507 RL |
62 | const char *output_type; /* Never NULL */ |
63 | const char *output_structure; /* May be NULL */ | |
b8975c68 RL |
64 | }; |
65 | ||
66 | DEFINE_STACK_OF(OSSL_ENCODER_INSTANCE) | |
ece9304c | 67 | |
b8975c68 RL |
68 | void ossl_encoder_instance_free(OSSL_ENCODER_INSTANCE *encoder_inst); |
69 | ||
70 | struct ossl_encoder_ctx_st { | |
b8975c68 RL |
71 | /* |
72 | * Select what parts of an object will be encoded. This selection is | |
73 | * bit encoded, and the bits correspond to selection bits available with | |
74 | * the provider side operation. For example, when encoding an EVP_PKEY, | |
75 | * the OSSL_KEYMGMT_SELECT_ macros are used for this. | |
76 | */ | |
ece9304c | 77 | int selection; |
8a98a507 RL |
78 | /* |
79 | * The desired output type. The encoder implementation must have a | |
80 | * gettable "output-type" parameter that this will match against. | |
81 | */ | |
82 | const char *output_type; | |
83 | /* | |
84 | * The desired output structure, if that's relevant for the type of | |
85 | * object being encoded. It may be used for selection of the starting | |
86 | * encoder implementations in a chain. | |
87 | */ | |
88 | const char *output_structure; | |
ece9304c | 89 | |
b8975c68 RL |
90 | /* |
91 | * Decoders that are components of any current decoding path. | |
92 | */ | |
93 | STACK_OF(OSSL_ENCODER_INSTANCE) *encoder_insts; | |
94 | ||
95 | /* | |
96 | * The constructor and destructor of an object to pass to the first | |
97 | * encoder in a chain. | |
ece9304c | 98 | */ |
b8975c68 RL |
99 | OSSL_ENCODER_CONSTRUCT *construct; |
100 | OSSL_ENCODER_CLEANUP *cleanup; | |
101 | void *construct_data; | |
ece9304c RL |
102 | |
103 | /* For any function that needs a passphrase reader */ | |
a517edec | 104 | struct ossl_passphrase_data_st pwdata; |
ece9304c RL |
105 | }; |
106 | ||
107 | struct ossl_decoder_instance_st { | |
bd7a6f16 RL |
108 | OSSL_DECODER *decoder; /* Never NULL */ |
109 | void *decoderctx; /* Never NULL */ | |
ece9304c | 110 | const char *input_type; /* Never NULL */ |
ebfdb63d RL |
111 | const char *input_structure; /* May be NULL */ |
112 | ||
113 | unsigned int flag_input_structure_was_set : 1; | |
ece9304c RL |
114 | }; |
115 | ||
116 | DEFINE_STACK_OF(OSSL_DECODER_INSTANCE) | |
117 | ||
118 | struct ossl_decoder_ctx_st { | |
119 | /* | |
120 | * The caller may know the input type of the data they pass. If not, | |
121 | * this will remain NULL and the decoding functionality will start | |
122 | * with trying to decode with any desencoder in |decoder_insts|, | |
123 | * regardless of their respective input type. | |
124 | */ | |
125 | const char *start_input_type; | |
ebfdb63d RL |
126 | /* |
127 | * The desired input structure, if that's relevant for the type of | |
128 | * object being encoded. It may be used for selection of the ending | |
129 | * decoder implementations in a chain, i.e. those chosen using the | |
130 | * expected output data type. | |
131 | */ | |
132 | const char *input_structure; | |
133 | /* | |
134 | * Select what parts of an object are expected. This may affect what | |
135 | * decoder implementations are selected, because there are structures | |
136 | * that look different depending on this selection; for example, EVP_PKEY | |
137 | * objects often have different encoding structures for private keys, | |
138 | * public keys and key parameters. | |
139 | * This selection is bit encoded, and the bits correspond to selection | |
140 | * bits available with the provider side operation. For example, when | |
141 | * encoding an EVP_PKEY, the OSSL_KEYMGMT_SELECT_ macros are used for | |
142 | * this. | |
143 | */ | |
144 | int selection; | |
ece9304c RL |
145 | |
146 | /* | |
147 | * Decoders that are components of any current decoding path. | |
148 | */ | |
149 | STACK_OF(OSSL_DECODER_INSTANCE) *decoder_insts; | |
150 | ||
151 | /* | |
152 | * The constructors of a decoding, and its caller argument. | |
153 | */ | |
154 | OSSL_DECODER_CONSTRUCT *construct; | |
155 | OSSL_DECODER_CLEANUP *cleanup; | |
156 | void *construct_data; | |
157 | ||
158 | /* For any function that needs a passphrase reader */ | |
a517edec | 159 | struct ossl_passphrase_data_st pwdata; |
ece9304c | 160 | }; |
9379bf94 RL |
161 | |
162 | const OSSL_PROPERTY_LIST * | |
163 | ossl_decoder_parsed_properties(const OSSL_DECODER *decoder); | |
e982e04f RL |
164 | const OSSL_PROPERTY_LIST * |
165 | ossl_encoder_parsed_properties(const OSSL_ENCODER *encoder); |