xref: /freebsd/crypto/openssl/doc/man7/provider-mac.pod (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
1=pod
2
3=head1 NAME
4
5provider-mac - The mac library E<lt>-E<gt> provider functions
6
7=head1 SYNOPSIS
8
9=for openssl multiple includes
10
11 #include <openssl/core_dispatch.h>
12 #include <openssl/core_names.h>
13
14 /*
15  * None of these are actual functions, but are displayed like this for
16  * the function signatures for functions that are offered as function
17  * pointers in OSSL_DISPATCH arrays.
18  */
19
20 /* Context management */
21 void *OSSL_FUNC_mac_newctx(void *provctx);
22 void OSSL_FUNC_mac_freectx(void *mctx);
23 void *OSSL_FUNC_mac_dupctx(void *src);
24
25 /* Encryption/decryption */
26 int OSSL_FUNC_mac_init(void *mctx, unsigned char *key, size_t keylen,
27                        const OSSL_PARAM params[]);
28 int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl);
29 int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
30
31 /* MAC parameter descriptors */
32 const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx);
33 const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx);
34 const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx);
35
36 /* MAC parameters */
37 int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]);
38 int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
39 int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
40
41=head1 DESCRIPTION
42
43This documentation is primarily aimed at provider authors. See L<provider(7)>
44for further information.
45
46The MAC operation enables providers to implement mac algorithms and make
47them available to applications via the API functions L<EVP_MAC_init(3)>,
48L<EVP_MAC_update(3)> and L<EVP_MAC_final(3)>.
49
50All "functions" mentioned here are passed as function pointers between
51F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via
52L<OSSL_ALGORITHM(3)> arrays that are returned by the provider's
53provider_query_operation() function
54(see L<provider-base(7)/Provider Functions>).
55
56All these "functions" have a corresponding function type definition
57named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
58function pointer from an L<OSSL_DISPATCH(3)> element named
59B<OSSL_FUNC_{name}>.
60For example, the "function" OSSL_FUNC_mac_newctx() has these:
61
62 typedef void *(OSSL_FUNC_mac_newctx_fn)(void *provctx);
63 static ossl_inline OSSL_FUNC_mac_newctx_fn
64     OSSL_FUNC_mac_newctx(const OSSL_DISPATCH *opf);
65
66L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as
67macros in L<openssl-core_dispatch.h(7)>, as follows:
68
69 OSSL_FUNC_mac_newctx               OSSL_FUNC_MAC_NEWCTX
70 OSSL_FUNC_mac_freectx              OSSL_FUNC_MAC_FREECTX
71 OSSL_FUNC_mac_dupctx               OSSL_FUNC_MAC_DUPCTX
72
73 OSSL_FUNC_mac_init                 OSSL_FUNC_MAC_INIT
74 OSSL_FUNC_mac_update               OSSL_FUNC_MAC_UPDATE
75 OSSL_FUNC_mac_final                OSSL_FUNC_MAC_FINAL
76
77 OSSL_FUNC_mac_get_params           OSSL_FUNC_MAC_GET_PARAMS
78 OSSL_FUNC_mac_get_ctx_params       OSSL_FUNC_MAC_GET_CTX_PARAMS
79 OSSL_FUNC_mac_set_ctx_params       OSSL_FUNC_MAC_SET_CTX_PARAMS
80
81 OSSL_FUNC_mac_gettable_params      OSSL_FUNC_MAC_GETTABLE_PARAMS
82 OSSL_FUNC_mac_gettable_ctx_params  OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
83 OSSL_FUNC_mac_settable_ctx_params  OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
84
85A mac algorithm implementation may not implement all of these functions.
86In order to be a consistent set of functions, at least the following functions
87must be implemented: OSSL_FUNC_mac_newctx(), OSSL_FUNC_mac_freectx(), OSSL_FUNC_mac_init(),
88OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final().
89All other functions are optional.
90
91=head2 Context Management Functions
92
93OSSL_FUNC_mac_newctx() should create and return a pointer to a provider side
94structure for holding context information during a mac operation.
95A pointer to this context will be passed back in a number of the other mac
96operation function calls.
97The parameter I<provctx> is the provider context generated during provider
98initialisation (see L<provider(7)>).
99
100OSSL_FUNC_mac_freectx() is passed a pointer to the provider side mac context in
101the I<mctx> parameter.
102If it receives NULL as I<mctx> value, it should not do anything other than
103return.
104This function should free any resources associated with that context.
105
106OSSL_FUNC_mac_dupctx() should duplicate the provider side mac context in the
107I<mctx> parameter and return the duplicate copy.
108
109=head2 Encryption/Decryption Functions
110
111OSSL_FUNC_mac_init() initialises a mac operation given a newly created provider
112side mac context in the I<mctx> parameter.  The I<params> are set before setting
113the MAC I<key> of I<keylen> bytes.
114
115OSSL_FUNC_mac_update() is called to supply data for MAC computation of a previously
116initialised mac operation.
117The I<mctx> parameter contains a pointer to a previously initialised provider
118side context.
119OSSL_FUNC_mac_update() may be called multiple times for a single mac operation.
120
121OSSL_FUNC_mac_final() completes the MAC computation started through previous
122OSSL_FUNC_mac_init() and OSSL_FUNC_mac_update() calls.
123The I<mctx> parameter contains a pointer to the provider side context.
124The resulting MAC should be written to I<out> and the amount of data written
125to I<*outl>, which should not exceed I<outsize> bytes.
126The same expectations apply to I<outsize> as documented for
127L<EVP_MAC_final(3)>.
128
129=head2 Mac Parameters
130
131See L<OSSL_PARAM(3)> for further details on the parameters structure used by
132these functions.
133
134OSSL_FUNC_mac_get_params() gets details of parameter values associated with the
135provider algorithm and stores them in I<params>.
136
137OSSL_FUNC_mac_set_ctx_params() sets mac parameters associated with the given
138provider side mac context I<mctx> to I<params>.
139Any parameter settings are additional to any that were previously set.
140Passing NULL for I<params> should return true.
141
142OSSL_FUNC_mac_get_ctx_params() gets details of currently set parameter values
143associated with the given provider side mac context I<mctx> and stores them
144in I<params>.
145Passing NULL for I<params> should return true.
146
147OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params(),
148and OSSL_FUNC_mac_settable_ctx_params() all return constant L<OSSL_PARAM(3)>
149arrays as descriptors of the parameters that OSSL_FUNC_mac_get_params(),
150OSSL_FUNC_mac_get_ctx_params(), and OSSL_FUNC_mac_set_ctx_params()
151can handle, respectively.  OSSL_FUNC_mac_gettable_ctx_params() and
152OSSL_FUNC_mac_settable_ctx_params() will return the parameters associated
153with the provider side context I<mctx> in its current state if it is
154not NULL.  Otherwise, they return the parameters associated with the
155provider side algorithm I<provctx>.
156
157All MAC implementations are expected to handle the following parameters:
158
159=over 4
160
161=item with OSSL_FUNC_set_ctx_params():
162
163=over 4
164
165=item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
166
167Sets the key in the associated MAC ctx.  This is identical to passing a I<key>
168argument to the OSSL_FUNC_mac_init() function.
169
170=back
171
172=item with OSSL_FUNC_get_params():
173
174=over 4
175
176=item "size" (B<OSSL_MAC_PARAM_SIZE>) <integer>
177
178Can be used to get the default MAC size (which might be the only allowable
179MAC size for the implementation).
180
181Note that some implementations allow setting the size that the resulting MAC
182should have as well, see the documentation of the implementation.
183
184=back
185
186=over 4
187
188=item "size" (B<OSSL_MAC_PARAM_BLOCK_SIZE>) <integer>
189
190Can be used to get the MAC block size (if supported by the algorithm).
191
192=back
193
194=back
195
196=head1 NOTES
197
198The MAC life-cycle is described in L<life_cycle-rand(7)>.  Providers should
199ensure that the various transitions listed there are supported.  At some point
200the EVP layer will begin enforcing the listed transitions.
201
202=head1 RETURN VALUES
203
204OSSL_FUNC_mac_newctx() and OSSL_FUNC_mac_dupctx() should return the newly created
205provider side mac context, or NULL on failure.
206
207OSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(), OSSL_FUNC_mac_get_params(),
208OSSL_FUNC_mac_get_ctx_params() and OSSL_FUNC_mac_set_ctx_params() should return 1 for
209success or 0 on error.
210
211OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params() and
212OSSL_FUNC_mac_settable_ctx_params() should return a constant L<OSSL_PARAM(3)>
213array, or NULL if none is offered.
214
215=head1 SEE ALSO
216
217L<provider(7)>,
218L<EVP_MAC-BLAKE2(7)>, L<EVP_MAC-CMAC(7)>, L<EVP_MAC-GMAC(7)>,
219L<EVP_MAC-HMAC(7)>, L<EVP_MAC-KMAC(7)>, L<EVP_MAC-Poly1305(7)>,
220L<EVP_MAC-Siphash(7)>,
221L<life_cycle-mac(7)>, L<EVP_MAC(3)>
222
223=head1 HISTORY
224
225The provider MAC interface was introduced in OpenSSL 3.0.
226
227=head1 COPYRIGHT
228
229Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
230
231Licensed under the Apache License 2.0 (the "License").  You may not use
232this file except in compliance with the License.  You can obtain a copy
233in the file LICENSE in the source distribution or at
234L<https://www.openssl.org/source/license.html>.
235
236=cut
237