xref: /freebsd/crypto/openssl/doc/man7/provider-decoder.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1*b077aed3SPierre Pronchery=pod
2*b077aed3SPierre Pronchery
3*b077aed3SPierre Pronchery=head1 NAME
4*b077aed3SPierre Pronchery
5*b077aed3SPierre Proncheryprovider-decoder - The OSSL_DECODER library E<lt>-E<gt> provider functions
6*b077aed3SPierre Pronchery
7*b077aed3SPierre Pronchery=head1 SYNOPSIS
8*b077aed3SPierre Pronchery
9*b077aed3SPierre Pronchery #include <openssl/core_dispatch.h>
10*b077aed3SPierre Pronchery
11*b077aed3SPierre Pronchery /*
12*b077aed3SPierre Pronchery  * None of these are actual functions, but are displayed like this for
13*b077aed3SPierre Pronchery  * the function signatures for functions that are offered as function
14*b077aed3SPierre Pronchery  * pointers in OSSL_DISPATCH arrays.
15*b077aed3SPierre Pronchery  */
16*b077aed3SPierre Pronchery
17*b077aed3SPierre Pronchery /* Decoder parameter accessor and descriptor */
18*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_decoder_gettable_params(void *provctx);
19*b077aed3SPierre Pronchery int OSSL_FUNC_decoder_get_params(OSSL_PARAM params[]);
20*b077aed3SPierre Pronchery
21*b077aed3SPierre Pronchery /* Functions to construct / destruct / manipulate the decoder context */
22*b077aed3SPierre Pronchery void *OSSL_FUNC_decoder_newctx(void *provctx);
23*b077aed3SPierre Pronchery void OSSL_FUNC_decoder_freectx(void *ctx);
24*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_decoder_settable_ctx_params(void *provctx);
25*b077aed3SPierre Pronchery int OSSL_FUNC_decoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
26*b077aed3SPierre Pronchery
27*b077aed3SPierre Pronchery /* Functions to check selection support */
28*b077aed3SPierre Pronchery int OSSL_FUNC_decoder_does_selection(void *provctx, int selection);
29*b077aed3SPierre Pronchery
30*b077aed3SPierre Pronchery /* Functions to decode object data */
31*b077aed3SPierre Pronchery int OSSL_FUNC_decoder_decode(void *ctx, OSSL_CORE_BIO *in,
32*b077aed3SPierre Pronchery                              int selection,
33*b077aed3SPierre Pronchery                              OSSL_CALLBACK *data_cb, void *data_cbarg,
34*b077aed3SPierre Pronchery                              OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
35*b077aed3SPierre Pronchery
36*b077aed3SPierre Pronchery /* Functions to export a decoded object */
37*b077aed3SPierre Pronchery int OSSL_FUNC_decoder_export_object(void *ctx,
38*b077aed3SPierre Pronchery                                       const void *objref, size_t objref_sz,
39*b077aed3SPierre Pronchery                                       OSSL_CALLBACK *export_cb,
40*b077aed3SPierre Pronchery                                       void *export_cbarg);
41*b077aed3SPierre Pronchery
42*b077aed3SPierre Pronchery=head1 DESCRIPTION
43*b077aed3SPierre Pronchery
44*b077aed3SPierre ProncheryI<The term "decode" is used throughout this manual.  This includes but is
45*b077aed3SPierre Proncherynot limited to deserialization as individual decoders can also do
46*b077aed3SPierre Proncherydecoding into intermediate data formats.>
47*b077aed3SPierre Pronchery
48*b077aed3SPierre ProncheryThe DECODER operation is a generic method to create a provider-native
49*b077aed3SPierre Proncheryobject reference or intermediate decoded data from an encoded form
50*b077aed3SPierre Proncheryread from the given B<OSSL_CORE_BIO>. If the caller wants to decode
51*b077aed3SPierre Proncherydata from memory, it should provide a L<BIO_s_mem(3)> B<BIO>. The decoded
52*b077aed3SPierre Proncherydata or object reference is passed along with eventual metadata
53*b077aed3SPierre Proncheryto the I<metadata_cb> as L<OSSL_PARAM(3)> parameters.
54*b077aed3SPierre Pronchery
55*b077aed3SPierre ProncheryThe decoder doesn't need to know more about the B<OSSL_CORE_BIO>
56*b077aed3SPierre Proncherypointer than being able to pass it to the appropriate BIO upcalls (see
57*b077aed3SPierre ProncheryL<provider-base(7)/Core functions>).
58*b077aed3SPierre Pronchery
59*b077aed3SPierre ProncheryThe DECODER implementation may be part of a chain, where data is
60*b077aed3SPierre Proncherypassed from one to the next.  For example, there may be an
61*b077aed3SPierre Proncheryimplementation to decode an object from PEM to DER, and another one
62*b077aed3SPierre Proncherythat decodes DER to a provider-native object.
63*b077aed3SPierre Pronchery
64*b077aed3SPierre ProncheryThe last decoding step in the decoding chain is usually supposed to create
65*b077aed3SPierre Proncherya provider-native object referenced by an object reference. To import
66*b077aed3SPierre Proncherythat object into a different provider the OSSL_FUNC_decoder_export_object()
67*b077aed3SPierre Proncherycan be called as the final step of the decoding process.
68*b077aed3SPierre Pronchery
69*b077aed3SPierre ProncheryAll "functions" mentioned here are passed as function pointers between
70*b077aed3SPierre ProncheryF<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via
71*b077aed3SPierre ProncheryL<OSSL_ALGORITHM(3)> arrays that are returned by the provider's
72*b077aed3SPierre Proncheryprovider_query_operation() function
73*b077aed3SPierre Pronchery(see L<provider-base(7)/Provider Functions>).
74*b077aed3SPierre Pronchery
75*b077aed3SPierre ProncheryAll these "functions" have a corresponding function type definition
76*b077aed3SPierre Proncherynamed B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
77*b077aed3SPierre Proncheryfunction pointer from an L<OSSL_DISPATCH(3)> element named
78*b077aed3SPierre ProncheryB<OSSL_FUNC_{name}>.
79*b077aed3SPierre ProncheryFor example, the "function" OSSL_FUNC_decoder_decode() has these:
80*b077aed3SPierre Pronchery
81*b077aed3SPierre Pronchery typedef int
82*b077aed3SPierre Pronchery     (OSSL_FUNC_decoder_decode_fn)(void *ctx, OSSL_CORE_BIO *in,
83*b077aed3SPierre Pronchery                                   int selection,
84*b077aed3SPierre Pronchery                                   OSSL_CALLBACK *data_cb, void *data_cbarg,
85*b077aed3SPierre Pronchery                                   OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
86*b077aed3SPierre Pronchery static ossl_inline OSSL_FUNC_decoder_decode_fn*
87*b077aed3SPierre Pronchery     OSSL_FUNC_decoder_decode(const OSSL_DISPATCH *opf);
88*b077aed3SPierre Pronchery
89*b077aed3SPierre ProncheryL<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as
90*b077aed3SPierre Proncherymacros in L<openssl-core_dispatch.h(7)>, as follows:
91*b077aed3SPierre Pronchery
92*b077aed3SPierre Pronchery OSSL_FUNC_decoder_get_params          OSSL_FUNC_DECODER_GET_PARAMS
93*b077aed3SPierre Pronchery OSSL_FUNC_decoder_gettable_params     OSSL_FUNC_DECODER_GETTABLE_PARAMS
94*b077aed3SPierre Pronchery
95*b077aed3SPierre Pronchery OSSL_FUNC_decoder_newctx              OSSL_FUNC_DECODER_NEWCTX
96*b077aed3SPierre Pronchery OSSL_FUNC_decoder_freectx             OSSL_FUNC_DECODER_FREECTX
97*b077aed3SPierre Pronchery OSSL_FUNC_decoder_set_ctx_params      OSSL_FUNC_DECODER_SET_CTX_PARAMS
98*b077aed3SPierre Pronchery OSSL_FUNC_decoder_settable_ctx_params OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS
99*b077aed3SPierre Pronchery
100*b077aed3SPierre Pronchery OSSL_FUNC_decoder_does_selection      OSSL_FUNC_DECODER_DOES_SELECTION
101*b077aed3SPierre Pronchery
102*b077aed3SPierre Pronchery OSSL_FUNC_decoder_decode              OSSL_FUNC_DECODER_DECODE
103*b077aed3SPierre Pronchery
104*b077aed3SPierre Pronchery OSSL_FUNC_decoder_export_object       OSSL_FUNC_DECODER_EXPORT_OBJECT
105*b077aed3SPierre Pronchery
106*b077aed3SPierre Pronchery=head2 Names and properties
107*b077aed3SPierre Pronchery
108*b077aed3SPierre ProncheryThe name of an implementation should match the target type of object
109*b077aed3SPierre Proncheryit decodes. For example, an implementation that decodes an RSA key
110*b077aed3SPierre Proncheryshould be named "RSA". Likewise, an implementation that decodes DER data
111*b077aed3SPierre Proncheryfrom PEM input should be named "DER".
112*b077aed3SPierre Pronchery
113*b077aed3SPierre ProncheryProperties can be used to further specify details about an implementation:
114*b077aed3SPierre Pronchery
115*b077aed3SPierre Pronchery=over 4
116*b077aed3SPierre Pronchery
117*b077aed3SPierre Pronchery=item input
118*b077aed3SPierre Pronchery
119*b077aed3SPierre ProncheryThis property is used to specify what format of input the implementation
120*b077aed3SPierre Proncherycan decode.
121*b077aed3SPierre Pronchery
122*b077aed3SPierre ProncheryThis property is I<mandatory>.
123*b077aed3SPierre Pronchery
124*b077aed3SPierre ProncheryOpenSSL providers recognize the following input types:
125*b077aed3SPierre Pronchery
126*b077aed3SPierre Pronchery=over 4
127*b077aed3SPierre Pronchery
128*b077aed3SPierre Pronchery=item pem
129*b077aed3SPierre Pronchery
130*b077aed3SPierre ProncheryAn implementation with that input type decodes PEM formatted data.
131*b077aed3SPierre Pronchery
132*b077aed3SPierre Pronchery=item der
133*b077aed3SPierre Pronchery
134*b077aed3SPierre ProncheryAn implementation with that input type decodes DER formatted data.
135*b077aed3SPierre Pronchery
136*b077aed3SPierre Pronchery=item msblob
137*b077aed3SPierre Pronchery
138*b077aed3SPierre ProncheryAn implementation with that input type decodes MSBLOB formatted data.
139*b077aed3SPierre Pronchery
140*b077aed3SPierre Pronchery=item pvk
141*b077aed3SPierre Pronchery
142*b077aed3SPierre ProncheryAn implementation with that input type decodes PVK formatted data.
143*b077aed3SPierre Pronchery
144*b077aed3SPierre Pronchery=back
145*b077aed3SPierre Pronchery
146*b077aed3SPierre Pronchery=item structure
147*b077aed3SPierre Pronchery
148*b077aed3SPierre ProncheryThis property is used to specify the structure that the decoded data is
149*b077aed3SPierre Proncheryexpected to have.
150*b077aed3SPierre Pronchery
151*b077aed3SPierre ProncheryThis property is I<optional>.
152*b077aed3SPierre Pronchery
153*b077aed3SPierre ProncheryStructures currently recognised by built-in decoders:
154*b077aed3SPierre Pronchery
155*b077aed3SPierre Pronchery=over 4
156*b077aed3SPierre Pronchery
157*b077aed3SPierre Pronchery=item "type-specific"
158*b077aed3SPierre Pronchery
159*b077aed3SPierre ProncheryType specific structure.
160*b077aed3SPierre Pronchery
161*b077aed3SPierre Pronchery=item "pkcs8"
162*b077aed3SPierre Pronchery
163*b077aed3SPierre ProncheryStructure according to the PKCS#8 specification.
164*b077aed3SPierre Pronchery
165*b077aed3SPierre Pronchery=item "SubjectPublicKeyInfo"
166*b077aed3SPierre Pronchery
167*b077aed3SPierre ProncheryEncoding of public keys according to the Subject Public Key Info of RFC 5280.
168*b077aed3SPierre Pronchery
169*b077aed3SPierre Pronchery=back
170*b077aed3SPierre Pronchery
171*b077aed3SPierre Pronchery=back
172*b077aed3SPierre Pronchery
173*b077aed3SPierre ProncheryThe possible values of both these properties is open ended.  A provider may
174*b077aed3SPierre Proncheryvery well specify input types and structures that libcrypto doesn't know
175*b077aed3SPierre Proncheryanything about.
176*b077aed3SPierre Pronchery
177*b077aed3SPierre Pronchery=head2 Subset selections
178*b077aed3SPierre Pronchery
179*b077aed3SPierre ProncherySometimes, an object has more than one subset of data that is interesting to
180*b077aed3SPierre Proncherytreat separately or together.  It's possible to specify what subsets are to
181*b077aed3SPierre Proncherybe decoded, with a set of bits I<selection> that are passed in an B<int>.
182*b077aed3SPierre Pronchery
183*b077aed3SPierre ProncheryThis set of bits depend entirely on what kind of provider-side object is
184*b077aed3SPierre Proncheryto be decoded.  For example, those bits are assumed to be the same as those
185*b077aed3SPierre Proncheryused with L<provider-keymgmt(7)> (see L<provider-keymgmt(7)/Key Objects>) when
186*b077aed3SPierre Proncherythe object is an asymmetric keypair - e.g., B<OSSL_KEYMGMT_SELECT_PRIVATE_KEY>
187*b077aed3SPierre Proncheryif the object to be decoded is supposed to contain private key components.
188*b077aed3SPierre Pronchery
189*b077aed3SPierre ProncheryOSSL_FUNC_decoder_does_selection() should tell if a particular implementation
190*b077aed3SPierre Proncherysupports any of the combinations given by I<selection>.
191*b077aed3SPierre Pronchery
192*b077aed3SPierre Pronchery=head2 Context functions
193*b077aed3SPierre Pronchery
194*b077aed3SPierre ProncheryOSSL_FUNC_decoder_newctx() returns a context to be used with the rest of
195*b077aed3SPierre Proncherythe functions.
196*b077aed3SPierre Pronchery
197*b077aed3SPierre ProncheryOSSL_FUNC_decoder_freectx() frees the given I<ctx> as created by
198*b077aed3SPierre ProncheryOSSL_FUNC_decoder_newctx().
199*b077aed3SPierre Pronchery
200*b077aed3SPierre ProncheryOSSL_FUNC_decoder_set_ctx_params() sets context data according to parameters
201*b077aed3SPierre Proncheryfrom I<params> that it recognises.  Unrecognised parameters should be
202*b077aed3SPierre Proncheryignored.
203*b077aed3SPierre ProncheryPassing NULL for I<params> should return true.
204*b077aed3SPierre Pronchery
205*b077aed3SPierre ProncheryOSSL_FUNC_decoder_settable_ctx_params() returns a constant L<OSSL_PARAM(3)>
206*b077aed3SPierre Proncheryarray describing the parameters that OSSL_FUNC_decoder_set_ctx_params()
207*b077aed3SPierre Proncherycan handle.
208*b077aed3SPierre Pronchery
209*b077aed3SPierre ProncherySee L<OSSL_PARAM(3)> for further details on the parameters structure used by
210*b077aed3SPierre ProncheryOSSL_FUNC_decoder_set_ctx_params() and OSSL_FUNC_decoder_settable_ctx_params().
211*b077aed3SPierre Pronchery
212*b077aed3SPierre Pronchery=head2 Export function
213*b077aed3SPierre Pronchery
214*b077aed3SPierre ProncheryWhen a provider-native object is created by a decoder it would be unsuitable
215*b077aed3SPierre Proncheryfor direct use with a foreign provider. The export function allows for
216*b077aed3SPierre Proncheryexporting the object into that foreign provider if the foreign provider
217*b077aed3SPierre Proncherysupports the type of the object and provides an import function.
218*b077aed3SPierre Pronchery
219*b077aed3SPierre ProncheryOSSL_FUNC_decoder_export_object() should export the object of size I<objref_sz>
220*b077aed3SPierre Proncheryreferenced by I<objref> as an L<OSSL_PARAM(3)> array and pass that into the
221*b077aed3SPierre ProncheryI<export_cb> as well as the given I<export_cbarg>.
222*b077aed3SPierre Pronchery
223*b077aed3SPierre Pronchery=head2 Decoding functions
224*b077aed3SPierre Pronchery
225*b077aed3SPierre ProncheryOSSL_FUNC_decoder_decode() should decode the data as read from
226*b077aed3SPierre Proncherythe B<OSSL_CORE_BIO> I<in> to produce decoded data or an object to be
227*b077aed3SPierre Proncherypassed as reference in an L<OSSL_PARAM(3)> array along with possible other
228*b077aed3SPierre Proncherymetadata that was decoded from the input. This L<OSSL_PARAM(3)> array is
229*b077aed3SPierre Proncherythen passed to the I<data_cb> callback.  The I<selection> bits,
230*b077aed3SPierre Proncheryif relevant, should determine what the input data should contain.
231*b077aed3SPierre ProncheryThe decoding functions also take an L<OSSL_PASSPHRASE_CALLBACK(3)> function
232*b077aed3SPierre Proncherypointer along with a pointer to application data I<cbarg>, which should be
233*b077aed3SPierre Proncheryused when a pass phrase prompt is needed.
234*b077aed3SPierre Pronchery
235*b077aed3SPierre ProncheryIt's important to understand that the return value from this function is
236*b077aed3SPierre Proncheryinterpreted as follows:
237*b077aed3SPierre Pronchery
238*b077aed3SPierre Pronchery=over 4
239*b077aed3SPierre Pronchery
240*b077aed3SPierre Pronchery=item True (1)
241*b077aed3SPierre Pronchery
242*b077aed3SPierre ProncheryThis means "carry on the decoding process", and is meaningful even though
243*b077aed3SPierre Proncherythis function couldn't decode the input into anything, because there may be
244*b077aed3SPierre Proncheryanother decoder implementation that can decode it into something.
245*b077aed3SPierre Pronchery
246*b077aed3SPierre ProncheryThe I<data_cb> callback should never be called when this function can't
247*b077aed3SPierre Proncherydecode the input into anything.
248*b077aed3SPierre Pronchery
249*b077aed3SPierre Pronchery=item False (0)
250*b077aed3SPierre Pronchery
251*b077aed3SPierre ProncheryThis means "stop the decoding process", and is meaningful when the input
252*b077aed3SPierre Proncherycould be decoded into some sort of object that this function understands,
253*b077aed3SPierre Proncherybut further treatment of that object results into errors that won't be
254*b077aed3SPierre Proncherypossible for some other decoder implementation to get a different result.
255*b077aed3SPierre Pronchery
256*b077aed3SPierre Pronchery=back
257*b077aed3SPierre Pronchery
258*b077aed3SPierre ProncheryThe conditions to stop the decoding process are at the discretion of the
259*b077aed3SPierre Proncheryimplementation.
260*b077aed3SPierre Pronchery
261*b077aed3SPierre Pronchery=head2 Decoder operation parameters
262*b077aed3SPierre Pronchery
263*b077aed3SPierre ProncheryThere are currently no operation parameters currently recognised by the
264*b077aed3SPierre Proncherybuilt-in decoders.
265*b077aed3SPierre Pronchery
266*b077aed3SPierre ProncheryParameters currently recognised by the built-in pass phrase callback:
267*b077aed3SPierre Pronchery
268*b077aed3SPierre Pronchery=over 4
269*b077aed3SPierre Pronchery
270*b077aed3SPierre Pronchery=item "info" (B<OSSL_PASSPHRASE_PARAM_INFO>) <UTF8 string>
271*b077aed3SPierre Pronchery
272*b077aed3SPierre ProncheryA string of information that will become part of the pass phrase
273*b077aed3SPierre Proncheryprompt.  This could be used to give the user information on what kind
274*b077aed3SPierre Proncheryof object it's being prompted for.
275*b077aed3SPierre Pronchery
276*b077aed3SPierre Pronchery=back
277*b077aed3SPierre Pronchery
278*b077aed3SPierre Pronchery=head1 RETURN VALUES
279*b077aed3SPierre Pronchery
280*b077aed3SPierre ProncheryOSSL_FUNC_decoder_newctx() returns a pointer to a context, or NULL on
281*b077aed3SPierre Proncheryfailure.
282*b077aed3SPierre Pronchery
283*b077aed3SPierre ProncheryOSSL_FUNC_decoder_set_ctx_params() returns 1, unless a recognised
284*b077aed3SPierre Proncheryparameter was invalid or caused an error, for which 0 is returned.
285*b077aed3SPierre Pronchery
286*b077aed3SPierre ProncheryOSSL_FUNC_decoder_settable_ctx_params() returns a pointer to an array of
287*b077aed3SPierre Proncheryconstant L<OSSL_PARAM(3)> elements.
288*b077aed3SPierre Pronchery
289*b077aed3SPierre ProncheryOSSL_FUNC_decoder_does_selection() returns 1 if the decoder implementation
290*b077aed3SPierre Proncherysupports any of the I<selection> bits, otherwise 0.
291*b077aed3SPierre Pronchery
292*b077aed3SPierre ProncheryOSSL_FUNC_decoder_decode() returns 1 to signal that the decoding process
293*b077aed3SPierre Proncheryshould continue, or 0 to signal that it should stop.
294*b077aed3SPierre Pronchery
295*b077aed3SPierre Pronchery=head1 SEE ALSO
296*b077aed3SPierre Pronchery
297*b077aed3SPierre ProncheryL<provider(7)>
298*b077aed3SPierre Pronchery
299*b077aed3SPierre Pronchery=head1 HISTORY
300*b077aed3SPierre Pronchery
301*b077aed3SPierre ProncheryThe DECODER interface was introduced in OpenSSL 3.0.
302*b077aed3SPierre Pronchery
303*b077aed3SPierre Pronchery=head1 COPYRIGHT
304*b077aed3SPierre Pronchery
305*b077aed3SPierre ProncheryCopyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
306*b077aed3SPierre Pronchery
307*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
308*b077aed3SPierre Proncherythis file except in compliance with the License.  You can obtain a copy
309*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at
310*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
311*b077aed3SPierre Pronchery
312*b077aed3SPierre Pronchery=cut
313