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

RETURN VALUES

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

SEE ALSO

269       provider(7)
270

HISTORY

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