xref: /freebsd-src/crypto/openssl/doc/internal/man3/ossl_method_construct.pod (revision 44096ebd22ddd0081a357011714eff8963614b65)
1b077aed3SPierre Pronchery=pod
2b077aed3SPierre Pronchery
3b077aed3SPierre Pronchery=head1 NAME
4b077aed3SPierre Pronchery
5b077aed3SPierre ProncheryOSSL_METHOD_CONSTRUCT_METHOD, ossl_method_construct
6b077aed3SPierre Pronchery- generic method constructor
7b077aed3SPierre Pronchery
8b077aed3SPierre Pronchery=head1 SYNOPSIS
9b077aed3SPierre Pronchery
10b077aed3SPierre Pronchery #include "internal/core.h"
11b077aed3SPierre Pronchery
12b077aed3SPierre Pronchery struct ossl_method_construct_method_st {
13b077aed3SPierre Pronchery     /* Get a temporary store */
14b077aed3SPierre Pronchery     void *(*get_tmp_store)(void *data);
15b077aed3SPierre Pronchery     /* Get an already existing method from a store */
16b077aed3SPierre Pronchery     void *(*get)(void *store, const OSSL_PROVIDER *prov, void *data);
17b077aed3SPierre Pronchery     /* Store a method in a store */
18b077aed3SPierre Pronchery     int (*put)(void *store, void *method, const OSSL_PROVIDER *prov,
19b077aed3SPierre Pronchery                const char *name, const char *propdef, void *data);
20b077aed3SPierre Pronchery     /* Construct a new method */
21b077aed3SPierre Pronchery     void *(*construct)(const OSSL_ALGORITHM *algodef, OSSL_PROVIDER *prov,
22b077aed3SPierre Pronchery                        void *data);
23b077aed3SPierre Pronchery     /* Destruct a method */
24b077aed3SPierre Pronchery     void (*destruct)(void *method, void *data);
25b077aed3SPierre Pronchery };
26b077aed3SPierre Pronchery typedef struct ossl_method_construct_method OSSL_METHOD_CONSTRUCT_METHOD;
27b077aed3SPierre Pronchery
28b077aed3SPierre Pronchery void *ossl_method_construct(OSSL_LIB_CTX *ctx, int operation_id,
29b077aed3SPierre Pronchery                             OSSL_PROVIDER *prov, int force_cache,
30b077aed3SPierre Pronchery                             OSSL_METHOD_CONSTRUCT_METHOD *mcm, void *mcm_data);
31b077aed3SPierre Pronchery
32b077aed3SPierre Pronchery
33b077aed3SPierre Pronchery=head1 DESCRIPTION
34b077aed3SPierre Pronchery
35b077aed3SPierre ProncheryAll libcrypto subsystems that want to create their own methods based
36b077aed3SPierre Proncheryon provider dispatch tables need to do so in exactly the same way.
37b077aed3SPierre Proncheryossl_method_construct() does this while leaving it to the subsystems
38b077aed3SPierre Proncheryto define more precisely how the methods are created, stored, etc.
39b077aed3SPierre Pronchery
40b077aed3SPierre ProncheryIt's important to keep in mind that a method is identified by three things:
41b077aed3SPierre Pronchery
42b077aed3SPierre Pronchery=over 4
43b077aed3SPierre Pronchery
44b077aed3SPierre Pronchery=item The operation identity
45b077aed3SPierre Pronchery
46b077aed3SPierre Pronchery=item The name of the algorithm
47b077aed3SPierre Pronchery
48b077aed3SPierre Pronchery=item The properties associated with the algorithm implementation
49b077aed3SPierre Pronchery
50b077aed3SPierre Pronchery=back
51b077aed3SPierre Pronchery
52b077aed3SPierre Pronchery=head2 Functions
53b077aed3SPierre Pronchery
54b077aed3SPierre Proncheryossl_method_construct() creates a method by asking all available
55b077aed3SPierre Proncheryproviders for a dispatch table given an I<operation_id>, and then
56b077aed3SPierre Proncherycalling the appropriate functions given by the subsystem specific
57b077aed3SPierre Proncherymethod creator through I<mcm> and the data in I<mcm_data> (which is
58b077aed3SPierre Proncherypassed by ossl_method_construct()).
59b077aed3SPierre ProncheryIf I<prov> is not NULL, only that provider is considered, which is
60b077aed3SPierre Proncheryuseful in the case a method must be found in that particular
61b077aed3SPierre Proncheryprovider.
62b077aed3SPierre Pronchery
63b077aed3SPierre ProncheryThis function assumes that the subsystem method creator implements
64b077aed3SPierre Proncheryreference counting and acts accordingly (i.e. it will call the
65b077aed3SPierre Proncherysubsystem destruct() method to decrement the reference count when
66b077aed3SPierre Proncheryappropriate).
67b077aed3SPierre Pronchery
68b077aed3SPierre Pronchery=head2 Structures
69b077aed3SPierre Pronchery
70b077aed3SPierre ProncheryA central part of constructing a subsystem specific method is to give
71b077aed3SPierre Proncheryossl_method_construct a set of functions, all in the
72b077aed3SPierre ProncheryB<OSSL_METHOD_CONSTRUCT_METHOD> structure, which holds the following
73b077aed3SPierre Proncheryfunction pointers:
74b077aed3SPierre Pronchery
75b077aed3SPierre Pronchery=over 4
76b077aed3SPierre Pronchery
77b077aed3SPierre Pronchery=item get_tmp_store()
78b077aed3SPierre Pronchery
79b077aed3SPierre ProncheryCreate a temporary method store in the scope of the library context I<ctx>.
80b077aed3SPierre ProncheryThis store is used to temporarily store methods for easier lookup, for
81b077aed3SPierre Proncherywhen the provider doesn't want its dispatch table stored in a longer
82b077aed3SPierre Proncheryterm cache.
83b077aed3SPierre Pronchery
84b077aed3SPierre Pronchery=item get()
85b077aed3SPierre Pronchery
86b077aed3SPierre ProncheryLook up an already existing method from a store by name.
87b077aed3SPierre Pronchery
88b077aed3SPierre ProncheryThe store may be given with I<store>.
89b077aed3SPierre ProncheryNULL is a valid value and means that a subsystem default store
90b077aed3SPierre Proncherymust be used.
91b077aed3SPierre ProncheryThis default store should be stored in the library context I<libctx>.
92b077aed3SPierre Pronchery
93b077aed3SPierre ProncheryThe method to be looked up should be identified with data found in I<data>
94b077aed3SPierre Pronchery(which is the I<mcm_data> that was passed to ossl_construct_method()).
95b077aed3SPierre ProncheryIn other words, the ossl_method_construct() caller is entirely responsible
96*44096ebdSEnji Cooperfor ensuring the necessary data is made available.
97b077aed3SPierre Pronchery
98b077aed3SPierre ProncheryOptionally, I<prov> may be given as a search criterion, to narrow down the
99b077aed3SPierre Proncherysearch of a method belonging to just one provider.
100b077aed3SPierre Pronchery
101b077aed3SPierre ProncheryThis function is expected to increment the resulting method's reference count.
102b077aed3SPierre Pronchery
103b077aed3SPierre Pronchery=item put()
104b077aed3SPierre Pronchery
105b077aed3SPierre ProncheryPlaces the I<method> created by the construct() function (see below)
106b077aed3SPierre Proncheryin a store.
107b077aed3SPierre Pronchery
108b077aed3SPierre ProncheryThe store may be given with I<store>.
109b077aed3SPierre ProncheryNULL is a valid value and means that a subsystem default store
110b077aed3SPierre Proncherymust be used.
111b077aed3SPierre ProncheryThis default store should be stored in the library context I<libctx>.
112b077aed3SPierre Pronchery
113b077aed3SPierre ProncheryThe method should be associated with the given provider I<prov>,
114b077aed3SPierre ProncheryI<name> and property definition I<propdef> as well as any
115b077aed3SPierre Proncheryidentification data given through I<data> (which is the I<mcm_data>
116b077aed3SPierre Proncherythat was passed to ossl_construct_method()).
117b077aed3SPierre Pronchery
118b077aed3SPierre ProncheryThis function is expected to increment the I<method>'s reference count.
119b077aed3SPierre Pronchery
120b077aed3SPierre Pronchery=item construct()
121b077aed3SPierre Pronchery
122b077aed3SPierre ProncheryConstructs a subsystem method for the given I<name> and the given
123b077aed3SPierre Proncherydispatch table I<fns>.
124b077aed3SPierre Pronchery
125b077aed3SPierre ProncheryThe associated provider object I<prov> is passed as well, to make
126b077aed3SPierre Proncheryit possible for the subsystem constructor to keep a reference, which
127b077aed3SPierre Proncheryis recommended.
128b077aed3SPierre ProncheryIf such a reference is kept, the I<provider object> reference counter
129b077aed3SPierre Proncherymust be incremented, using ossl_provider_up_ref().
130b077aed3SPierre Pronchery
131b077aed3SPierre ProncheryThis function is expected to set the method's reference count to 1.
132b077aed3SPierre Pronchery
133b077aed3SPierre Pronchery=item destruct()
134b077aed3SPierre Pronchery
135b077aed3SPierre ProncheryDecrement the I<method>'s reference count, and destruct it when
136b077aed3SPierre Proncherythe reference count reaches zero.
137b077aed3SPierre Pronchery
138b077aed3SPierre Pronchery=back
139b077aed3SPierre Pronchery
140b077aed3SPierre Pronchery=head1 RETURN VALUES
141b077aed3SPierre Pronchery
142b077aed3SPierre Proncheryossl_method_construct() returns a constructed method on success, or
143b077aed3SPierre ProncheryNULL on error.
144b077aed3SPierre Pronchery
145b077aed3SPierre Pronchery=head1 HISTORY
146b077aed3SPierre Pronchery
147b077aed3SPierre ProncheryThis functionality was added to OpenSSL 3.0.
148b077aed3SPierre Pronchery
149b077aed3SPierre Pronchery=head1 COPYRIGHT
150b077aed3SPierre Pronchery
151*44096ebdSEnji CooperCopyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
152b077aed3SPierre Pronchery
153b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use this
154b077aed3SPierre Proncheryfile except in compliance with the License.  You can obtain a copy in the file
155b077aed3SPierre ProncheryLICENSE in the source distribution or at
156b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
157b077aed3SPierre Pronchery
158b077aed3SPierre Pronchery=cut
159