1PROVIDER-ENCODER(7ossl)             OpenSSL            PROVIDER-ENCODER(7ossl)
2
3
4

NAME

6       provider-encoder - The OSSL_ENCODER library <-> provider functions
7

SYNOPSIS

9        #include <openssl/core_dispatch.h>
10
11        /*
12         * None of these are actual functions, but are displayed like this for
13         * the function signatures for functions that are offered as function
14         * pointers in OSSL_DISPATCH arrays.
15         */
16
17        /* Encoder parameter accessor and descriptor */
18        const OSSL_PARAM *OSSL_FUNC_encoder_gettable_params(void *provctx);
19        int OSSL_FUNC_encoder_get_params(OSSL_PARAM params[]);
20
21        /* Functions to construct / destruct / manipulate the encoder context */
22        void *OSSL_FUNC_encoder_newctx(void *provctx);
23        void OSSL_FUNC_encoder_freectx(void *ctx);
24        int OSSL_FUNC_encoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
25        const OSSL_PARAM *OSSL_FUNC_encoder_settable_ctx_params(void *provctx);
26
27        /* Functions to check selection support */
28        int OSSL_FUNC_encoder_does_selection(void *provctx, int selection);
29
30        /* Functions to encode object data */
31        int OSSL_FUNC_encoder_encode(void *ctx, OSSL_CORE_BIO *out,
32                                     const void *obj_raw,
33                                     const OSSL_PARAM obj_abstract[],
34                                     int selection,
35                                     OSSL_PASSPHRASE_CALLBACK *cb,
36                                     void *cbarg);
37
38        /* Functions to import and free a temporary object to be encoded */
39        void *OSSL_FUNC_encoder_import_object(void *ctx, int selection,
40                                              const OSSL_PARAM params[]);
41        void OSSL_FUNC_encoder_free_object(void *obj);
42

DESCRIPTION

44       We use the wide term "encode" in this manual.  This includes but is not
45       limited to serialization.
46
47       The ENCODER operation is a generic method to encode a provider-native
48       object (obj_raw) or an object abstraction (object_abstract, see
49       provider-object(7)) into an encoded form, and write the result to the
50       given OSSL_CORE_BIO.  If the caller wants to get the encoded stream to
51       memory, it should provide a BIO_s_mem(3) BIO.
52
53       The encoder doesn't need to know more about the OSSL_CORE_BIO pointer
54       than being able to pass it to the appropriate BIO upcalls (see "Core
55       functions" in provider-base(7)).
56
57       The ENCODER implementation may be part of a chain, where data is passed
58       from one to the next.  For example, there may be an implementation to
59       encode an object to DER (that object is assumed to be provider-native
60       and thereby passed via obj_raw), and another one that encodes DER to
61       PEM (that one would receive the DER encoding via obj_abstract).
62
63       The encoding using the OSSL_PARAM(3) array form allows a encoder to be
64       used for data that's been exported from another provider, and thereby
65       allow them to exist independently of each other.
66
67       The encoding using a provider side object can only be safely used with
68       provider data coming from the same provider, for example keys with the
69       KEYMGMT provider.
70
71       All "functions" mentioned here are passed as function pointers between
72       libcrypto and the provider in OSSL_DISPATCH(3) arrays via
73       OSSL_ALGORITHM(3) arrays that are returned by the provider's
74       provider_query_operation() function (see "Provider Functions" in
75       provider-base(7)).
76
77       All these "functions" have a corresponding function type definition
78       named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
79       function pointer from an OSSL_DISPATCH(3) element named
80       OSSL_FUNC_{name}.  For example, the "function"
81       OSSL_FUNC_encoder_encode() has these:
82
83        typedef int
84            (OSSL_FUNC_encoder_encode_fn)(void *ctx, OSSL_CORE_BIO *out,
85                                          const void *obj_raw,
86                                          const OSSL_PARAM obj_abstract[],
87                                          int selection,
88                                          OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
89        static ossl_inline OSSL_FUNC_encoder_encode_fn
90            OSSL_FUNC_encoder_encode(const OSSL_DISPATCH *opf);
91
92       OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as
93       macros in openssl-core_dispatch.h(7), as follows:
94
95        OSSL_FUNC_encoder_get_params          OSSL_FUNC_ENCODER_GET_PARAMS
96        OSSL_FUNC_encoder_gettable_params     OSSL_FUNC_ENCODER_GETTABLE_PARAMS
97
98        OSSL_FUNC_encoder_newctx              OSSL_FUNC_ENCODER_NEWCTX
99        OSSL_FUNC_encoder_freectx             OSSL_FUNC_ENCODER_FREECTX
100        OSSL_FUNC_encoder_set_ctx_params      OSSL_FUNC_ENCODER_SET_CTX_PARAMS
101        OSSL_FUNC_encoder_settable_ctx_params OSSL_FUNC_ENCODER_SETTABLE_CTX_PARAMS
102
103        OSSL_FUNC_encoder_does_selection      OSSL_FUNC_ENCODER_DOES_SELECTION
104
105        OSSL_FUNC_encoder_encode              OSSL_FUNC_ENCODER_ENCODE
106
107        OSSL_FUNC_encoder_import_object       OSSL_FUNC_ENCODER_IMPORT_OBJECT
108        OSSL_FUNC_encoder_free_object         OSSL_FUNC_ENCODER_FREE_OBJECT
109
110   Names and properties
111       The name of an implementation should match the type of object it
112       handles.  For example, an implementation that encodes an RSA key should
113       be named "RSA".  Likewise, an implementation that further encodes DER
114       should be named "DER".
115
116       Properties can be used to further specify details about an
117       implementation:
118
119       output
120           This property is used to specify what type of output the
121           implementation produces.
122
123           This property is mandatory.
124
125           OpenSSL providers recognize the following output types:
126
127           text
128               An implementation with that output type outputs human readable
129               text, making that implementation suitable for "-text" output in
130               diverse openssl(1) commands.
131
132           pem An implementation with that output type outputs PEM formatted
133               data.
134
135           der An implementation with that output type outputs DER formatted
136               data.
137
138           msblob
139               An implementation with that output type outputs MSBLOB
140               formatted data.
141
142           pvk An implementation with that output type outputs PVK formatted
143               data.
144
145       structure
146           This property is used to specify the structure that is used for the
147           encoded object.  An example could be "pkcs8", to specify explicitly
148           that an object (presumably an asymmetric key pair, in this case)
149           will be wrapped in a PKCS#8 structure as part of the encoding.
150
151           This property is optional.
152
153       The possible values of both these properties is open ended.  A provider
154       may very well specify output types and structures that libcrypto
155       doesn't know anything about.
156
157   Subset selections
158       Sometimes, an object has more than one subset of data that is
159       interesting to treat separately or together.  It's possible to specify
160       what subsets are to be encoded, with a set of bits selection that are
161       passed in an int.
162
163       This set of bits depend entirely on what kind of provider-side object
164       is passed.  For example, those bits are assumed to be the same as those
165       used with provider-keymgmt(7) (see "Key Objects" in
166       provider-keymgmt(7)) when the object is an asymmetric keypair.
167
168       ENCODER implementations are free to regard the selection as a set of
169       hints, but must do so with care.  In the end, the output must make
170       sense, and if there's a corresponding decoder, the resulting decoded
171       object must match the original object that was encoded.
172
173       OSSL_FUNC_encoder_does_selection() should tell if a particular
174       implementation supports any of the combinations given by selection.
175
176   Context functions
177       OSSL_FUNC_encoder_newctx() returns a context to be used with the rest
178       of the functions.
179
180       OSSL_FUNC_encoder_freectx() frees the given ctx, if it was created by
181       OSSL_FUNC_encoder_newctx().
182
183       OSSL_FUNC_encoder_set_ctx_params() sets context data according to
184       parameters from params that it recognises.  Unrecognised parameters
185       should be ignored.  Passing NULL for params should return true.
186
187       OSSL_FUNC_encoder_settable_ctx_params() returns a constant
188       OSSL_PARAM(3) array describing the parameters that
189       OSSL_FUNC_encoder_set_ctx_params() can handle.
190
191       See OSSL_PARAM(3) for further details on the parameters structure used
192       by OSSL_FUNC_encoder_set_ctx_params() and
193       OSSL_FUNC_encoder_settable_ctx_params().
194
195   Import functions
196       A provider-native object may be associated with a foreign provider, and
197       may therefore be unsuitable for direct use with a given ENCODER
198       implementation.  Provided that the foreign provider's implementation to
199       handle the object has a function to export that object in OSSL_PARAM(3)
200       array form, the ENCODER implementation should be able to import that
201       array and create a suitable object to be passed to
202       OSSL_FUNC_encoder_encode()'s obj_raw.
203
204       OSSL_FUNC_encoder_import_object() should import the subset of params
205       given with selection to create a provider-native object that can be
206       passed as obj_raw to OSSL_FUNC_encoder_encode().
207
208       OSSL_FUNC_encoder_free_object() should free the object that was created
209       with OSSL_FUNC_encoder_import_object().
210
211   Encoding functions
212       OSSL_FUNC_encoder_encode() should take a provider-native object (in
213       obj_raw) or an object abstraction (in obj_abstract), and should output
214       the object in encoded form to the OSSL_CORE_BIO.  The selection bits,
215       if relevant, should determine in greater detail what will be output.
216       The encoding functions also take an OSSL_PASSPHRASE_CALLBACK(3)
217       function pointer along with a pointer to application data cbarg, which
218       should be used when a pass phrase prompt is needed.
219
220   Encoder operation parameters
221       Operation parameters currently recognised by built-in encoders are as
222       follows:
223
224       "cipher" (OSSL_ENCODER_PARAM_CIPHER) <UTF8 string>
225           The name of the encryption cipher to be used when generating
226           encrypted encoding.  This is used when encoding private keys, as
227           well as other objects that need protection.
228
229           If this name is invalid for the encoding implementation, the
230           implementation should refuse to perform the encoding, i.e.
231           OSSL_FUNC_encoder_encode_data() and
232           OSSL_FUNC_encoder_encode_object() should return an error.
233
234       "properties" (OSSL_ENCODER_PARAM_PROPERTIES) <UTF8 string>
235           The properties to be queried when trying to fetch the algorithm
236           given with the "cipher" parameter.  This must be given together
237           with the "cipher" parameter to be considered valid.
238
239           The encoding implementation isn't obligated to use this value.
240           However, it is recommended that implementations that do not handle
241           property strings return an error on receiving this parameter unless
242           its value NULL or the empty string.
243
244       "save-parameters" (OSSL_ENCODER_PARAM_SAVE_PARAMETERS) <integer>
245           If set to 0 disables saving of key domain parameters. Default is 1.
246           It currently has an effect only on DSA keys.
247
248       Parameters currently recognised by the built-in pass phrase callback:
249
250       "info" (OSSL_PASSPHRASE_PARAM_INFO) <UTF8 string>
251           A string of information that will become part of the pass phrase
252           prompt.  This could be used to give the user information on what
253           kind of object it's being prompted for.
254

RETURN VALUES

256       OSSL_FUNC_encoder_newctx() returns a pointer to a context, or NULL on
257       failure.
258
259       OSSL_FUNC_encoder_set_ctx_params() returns 1, unless a recognised
260       parameter was invalid or caused an error, for which 0 is returned.
261
262       OSSL_FUNC_encoder_settable_ctx_params() returns a pointer to an array
263       of constant OSSL_PARAM(3) elements.
264
265       OSSL_FUNC_encoder_does_selection() returns 1 if the encoder
266       implementation supports any of the selection bits, otherwise 0.
267
268       OSSL_FUNC_encoder_encode() returns 1 on success, or 0 on failure.
269

SEE ALSO

271       provider(7)
272

HISTORY

274       The ENCODER interface was introduced in OpenSSL 3.0.
275
277       Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
278
279       Licensed under the Apache License 2.0 (the "License").  You may not use
280       this file except in compliance with the License.  You can obtain a copy
281       in the file LICENSE in the source distribution or at
282       <https://www.openssl.org/source/license.html>.
283
284
285
2863.1.1                             2023-08-31           PROVIDER-ENCODER(7ossl)
Impressum